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.

252174 lines
6.3MB

  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 1
  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 1
  152. #endif
  153. #ifndef JUCE_OPENGL
  154. #define JUCE_OPENGL 1
  155. #endif
  156. #ifndef JUCE_USE_FLAC
  157. #define JUCE_USE_FLAC 1
  158. #endif
  159. #ifndef JUCE_USE_OGGVORBIS
  160. #define JUCE_USE_OGGVORBIS 1
  161. #endif
  162. #if (! defined (JUCE_USE_CDBURNER)) && ! (JUCE_WINDOWS && ! JUCE_MSVC)
  163. #define JUCE_USE_CDBURNER 1
  164. #endif
  165. #ifndef JUCE_USE_CDREADER
  166. #define JUCE_USE_CDREADER 1
  167. #endif
  168. #if JUCE_QUICKTIME && ! defined (JUCE_USE_CAMERA)
  169. // #define JUCE_USE_CAMERA 1
  170. #endif
  171. #ifndef JUCE_ENABLE_REPAINT_DEBUGGING
  172. // #define JUCE_ENABLE_REPAINT_DEBUGGING 1
  173. #endif
  174. #ifndef JUCE_USE_XINERAMA
  175. #define JUCE_USE_XINERAMA 1
  176. #endif
  177. #ifndef JUCE_USE_XSHM
  178. #define JUCE_USE_XSHM 1
  179. #endif
  180. #ifndef JUCE_USE_XRENDER
  181. //#define JUCE_USE_XRENDER 1
  182. #endif
  183. #ifndef JUCE_PLUGINHOST_VST
  184. // #define JUCE_PLUGINHOST_VST 1
  185. #endif
  186. #ifndef JUCE_PLUGINHOST_AU
  187. // #define JUCE_PLUGINHOST_AU 1
  188. #endif
  189. #ifndef JUCE_ONLY_BUILD_CORE_LIBRARY
  190. //#define JUCE_ONLY_BUILD_CORE_LIBRARY 1
  191. #endif
  192. #ifndef JUCE_WEB_BROWSER
  193. #define JUCE_WEB_BROWSER 1
  194. #endif
  195. #ifndef JUCE_SUPPORT_CARBON
  196. #define JUCE_SUPPORT_CARBON 1
  197. #endif
  198. #ifndef JUCE_INCLUDE_ZLIB_CODE
  199. #define JUCE_INCLUDE_ZLIB_CODE 1
  200. #endif
  201. #ifndef JUCE_INCLUDE_FLAC_CODE
  202. #define JUCE_INCLUDE_FLAC_CODE 1
  203. #endif
  204. #ifndef JUCE_INCLUDE_OGGVORBIS_CODE
  205. #define JUCE_INCLUDE_OGGVORBIS_CODE 1
  206. #endif
  207. #ifndef JUCE_INCLUDE_PNGLIB_CODE
  208. #define JUCE_INCLUDE_PNGLIB_CODE 1
  209. #endif
  210. #ifndef JUCE_INCLUDE_JPEGLIB_CODE
  211. #define JUCE_INCLUDE_JPEGLIB_CODE 1
  212. #endif
  213. #ifndef JUCE_CHECK_MEMORY_LEAKS
  214. #define JUCE_CHECK_MEMORY_LEAKS 1
  215. #endif
  216. #ifndef JUCE_CATCH_UNHANDLED_EXCEPTIONS
  217. #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1
  218. #endif
  219. // If only building the core classes, we can explicitly turn off some features to avoid including them:
  220. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  221. #undef JUCE_QUICKTIME
  222. #define JUCE_QUICKTIME 0
  223. #undef JUCE_OPENGL
  224. #define JUCE_OPENGL 0
  225. #undef JUCE_USE_CDBURNER
  226. #define JUCE_USE_CDBURNER 0
  227. #undef JUCE_USE_CDREADER
  228. #define JUCE_USE_CDREADER 0
  229. #undef JUCE_WEB_BROWSER
  230. #define JUCE_WEB_BROWSER 0
  231. #undef JUCE_PLUGINHOST_AU
  232. #define JUCE_PLUGINHOST_AU 0
  233. #undef JUCE_PLUGINHOST_VST
  234. #define JUCE_PLUGINHOST_VST 0
  235. #endif
  236. #endif
  237. /*** End of inlined file: juce_Config.h ***/
  238. // FORCE_AMALGAMATOR_INCLUDE
  239. #ifndef JUCE_BUILD_CORE
  240. #define JUCE_BUILD_CORE 1
  241. #endif
  242. #ifndef JUCE_BUILD_MISC
  243. #define JUCE_BUILD_MISC 1
  244. #endif
  245. #ifndef JUCE_BUILD_GUI
  246. #define JUCE_BUILD_GUI 1
  247. #endif
  248. #ifndef JUCE_BUILD_NATIVE
  249. #define JUCE_BUILD_NATIVE 1
  250. #endif
  251. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  252. #undef JUCE_BUILD_MISC
  253. #undef JUCE_BUILD_GUI
  254. #endif
  255. //==============================================================================
  256. #if JUCE_BUILD_NATIVE || JUCE_BUILD_CORE || (JUCE_BUILD_MISC && (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_AU))
  257. #if JUCE_WINDOWS
  258. /*** Start of inlined file: juce_win32_NativeIncludes.h ***/
  259. #ifndef __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  260. #define __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  261. #ifndef STRICT
  262. #define STRICT 1
  263. #endif
  264. #undef WIN32_LEAN_AND_MEAN
  265. #define WIN32_LEAN_AND_MEAN 1
  266. #ifdef _MSC_VER
  267. #pragma warning (push)
  268. #pragma warning (disable : 4100 4201 4514 4312 4995)
  269. #endif
  270. #define _WIN32_WINNT 0x0500
  271. #define _UNICODE 1
  272. #define UNICODE 1
  273. #ifndef _WIN32_IE
  274. #define _WIN32_IE 0x0400
  275. #endif
  276. #include <windows.h>
  277. #include <windowsx.h>
  278. #include <commdlg.h>
  279. #include <shellapi.h>
  280. #include <mmsystem.h>
  281. #include <vfw.h>
  282. #include <tchar.h>
  283. #include <stddef.h>
  284. #include <ctime>
  285. #include <wininet.h>
  286. #include <nb30.h>
  287. #include <iphlpapi.h>
  288. #include <mapi.h>
  289. #include <float.h>
  290. #include <process.h>
  291. #include <Exdisp.h>
  292. #include <exdispid.h>
  293. #include <shlobj.h>
  294. #if ! JUCE_MINGW
  295. #include <crtdbg.h>
  296. #include <comutil.h>
  297. #endif
  298. #if JUCE_OPENGL
  299. #include <gl/gl.h>
  300. #endif
  301. #undef PACKED
  302. #if JUCE_ASIO
  303. #include "iasiodrv.h"
  304. #endif
  305. #if JUCE_USE_CDBURNER
  306. #include <imapi.h>
  307. #include <imapierror.h>
  308. #endif
  309. #if JUCE_USE_CAMERA
  310. #include <dshow.h>
  311. #include <qedit.h>
  312. #include <dshowasf.h>
  313. #endif
  314. #if JUCE_WASAPI
  315. #include <MMReg.h>
  316. #include <mmdeviceapi.h>
  317. #include <Audioclient.h>
  318. #include <Avrt.h>
  319. #include <functiondiscoverykeys.h>
  320. #endif
  321. #if JUCE_QUICKTIME
  322. #include <Movies.h>
  323. #include <QTML.h>
  324. #include <QuickTimeComponents.h>
  325. #include <MediaHandlers.h>
  326. #include <ImageCodec.h>
  327. #import <QTOLibrary.dll>
  328. #import <QTOControl.dll>
  329. #endif
  330. #ifdef _MSC_VER
  331. #pragma warning (pop)
  332. #endif
  333. template <class T>
  334. class ComSmartPtr
  335. {
  336. public:
  337. ComSmartPtr() throw() : p (0) {}
  338. ComSmartPtr (T* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); }
  339. ComSmartPtr (const ComSmartPtr<T>& p_) : p (p_.p) { if (p != 0) p->AddRef(); }
  340. ~ComSmartPtr() { if (p != 0) p->Release(); }
  341. operator T*() const throw() { return p; }
  342. T& operator*() const throw() { return *p; }
  343. T** operator&() throw() { return &p; }
  344. T* operator->() const throw() { return p; }
  345. T* operator= (T* const newP)
  346. {
  347. if (newP != 0)
  348. newP->AddRef();
  349. if (p != 0)
  350. p->Release();
  351. p = newP;
  352. return newP;
  353. }
  354. T* operator= (const ComSmartPtr<T>& newP) { return operator= (newP.p); }
  355. HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext)
  356. {
  357. #ifndef __MINGW32__
  358. operator= (0);
  359. return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof(T), (void**) &p);
  360. #else
  361. return S_FALSE;
  362. #endif
  363. }
  364. T* p;
  365. };
  366. #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  367. /*** End of inlined file: juce_win32_NativeIncludes.h ***/
  368. #elif JUCE_LINUX
  369. /*** Start of inlined file: juce_linux_NativeIncludes.h ***/
  370. #ifndef __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  371. #define __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  372. #include <sched.h>
  373. #include <pthread.h>
  374. #include <sys/time.h>
  375. #include <errno.h>
  376. #include <sys/stat.h>
  377. #include <sys/dir.h>
  378. #include <sys/ptrace.h>
  379. #include <sys/vfs.h>
  380. #include <sys/wait.h>
  381. #include <fnmatch.h>
  382. #include <utime.h>
  383. #include <pwd.h>
  384. #include <fcntl.h>
  385. #include <dlfcn.h>
  386. #include <netdb.h>
  387. #include <arpa/inet.h>
  388. #include <netinet/in.h>
  389. #include <sys/types.h>
  390. #include <sys/ioctl.h>
  391. #include <sys/socket.h>
  392. #include <linux/if.h>
  393. #include <sys/sysinfo.h>
  394. #include <sys/file.h>
  395. #include <signal.h>
  396. #include <ft2build.h>
  397. #include FT_FREETYPE_H
  398. #include <X11/Xlib.h>
  399. #include <X11/Xatom.h>
  400. #include <X11/Xresource.h>
  401. #include <X11/Xutil.h>
  402. #include <X11/Xmd.h>
  403. #include <X11/keysym.h>
  404. #include <X11/cursorfont.h>
  405. #if JUCE_USE_XINERAMA
  406. #include <X11/extensions/Xinerama.h>
  407. #endif
  408. #if JUCE_USE_XSHM
  409. #include <X11/extensions/XShm.h>
  410. #include <sys/shm.h>
  411. #include <sys/ipc.h>
  412. #endif
  413. #if JUCE_USE_XRENDER
  414. // If you're missing these headers, try installing the libxrender-dev and libxcomposite-dev
  415. #include <X11/extensions/Xrender.h>
  416. #include <X11/extensions/Xcomposite.h>
  417. #endif
  418. #if JUCE_OPENGL
  419. #include <GL/glx.h>
  420. #endif
  421. #undef KeyPress
  422. #if JUCE_ALSA
  423. #include <alsa/asoundlib.h>
  424. #endif
  425. #if JUCE_JACK
  426. #include <jack/jack.h>
  427. //#include <jack/transport.h>
  428. #endif
  429. #undef SIZEOF
  430. #endif // __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  431. /*** End of inlined file: juce_linux_NativeIncludes.h ***/
  432. #elif JUCE_MAC || JUCE_IPHONE
  433. /*** Start of inlined file: juce_mac_NativeIncludes.h ***/
  434. #ifndef __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  435. #define __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  436. #define USE_COREGRAPHICS_RENDERING 1
  437. #if JUCE_IPHONE
  438. #import <Foundation/Foundation.h>
  439. #import <UIKit/UIKit.h>
  440. #import <AudioToolbox/AudioToolbox.h>
  441. #import <AVFoundation/AVFoundation.h>
  442. #import <CoreData/CoreData.h>
  443. #import <MobileCoreServices/MobileCoreServices.h>
  444. #include <sys/fcntl.h>
  445. #else
  446. #import <Cocoa/Cocoa.h>
  447. #import <CoreAudio/HostTime.h>
  448. #import <CoreAudio/AudioHardware.h>
  449. #import <CoreMIDI/MIDIServices.h>
  450. #import <QTKit/QTKit.h>
  451. #import <WebKit/WebKit.h>
  452. #import <DiscRecording/DiscRecording.h>
  453. #import <IOKit/IOKitLib.h>
  454. #import <IOKit/IOCFPlugIn.h>
  455. #import <IOKit/hid/IOHIDLib.h>
  456. #import <IOKit/hid/IOHIDKeys.h>
  457. #import <IOKit/pwr_mgt/IOPMLib.h>
  458. #include <Carbon/Carbon.h>
  459. #include <sys/dir.h>
  460. #include <sys/socket.h>
  461. #endif
  462. #include <sys/sysctl.h>
  463. #include <sys/stat.h>
  464. #include <sys/param.h>
  465. #include <sys/mount.h>
  466. #include <fnmatch.h>
  467. #include <utime.h>
  468. #include <dlfcn.h>
  469. #include <ifaddrs.h>
  470. #include <net/if_dl.h>
  471. #include <mach/mach_time.h>
  472. #if MACOS_10_4_OR_EARLIER
  473. #include <GLUT/glut.h>
  474. #endif
  475. #if ! CGFLOAT_DEFINED
  476. #define CGFloat float
  477. #endif
  478. #endif // __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  479. /*** End of inlined file: juce_mac_NativeIncludes.h ***/
  480. #else
  481. #error "Unknown platform!"
  482. #endif
  483. #endif
  484. //==============================================================================
  485. #define DONT_SET_USING_JUCE_NAMESPACE 1
  486. #undef max
  487. #undef min
  488. #define NO_DUMMY_DECL
  489. #if JUCE_BUILD_NATIVE
  490. #include "juce_amalgamated.h" // FORCE_AMALGAMATOR_INCLUDE
  491. #endif
  492. #if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  493. #pragma warning (disable: 4309 4305)
  494. #endif
  495. #if JUCE_MAC && JUCE_32BIT && JUCE_SUPPORT_CARBON && JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  496. BEGIN_JUCE_NAMESPACE
  497. /*** Start of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  498. #ifndef __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  499. #define __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  500. class CarbonViewWrapperComponent : public Component,
  501. public ComponentMovementWatcher,
  502. public Timer
  503. {
  504. public:
  505. CarbonViewWrapperComponent()
  506. : ComponentMovementWatcher (this),
  507. wrapperWindow (0),
  508. embeddedView (0),
  509. recursiveResize (false)
  510. {
  511. }
  512. virtual ~CarbonViewWrapperComponent()
  513. {
  514. jassert (embeddedView == 0); // must call deleteWindow() in the subclass's destructor!
  515. }
  516. virtual HIViewRef attachView (WindowRef windowRef, HIViewRef rootView) = 0;
  517. virtual void removeView (HIViewRef embeddedView) = 0;
  518. virtual void mouseDown (int x, int y) {}
  519. virtual void paint() {}
  520. virtual bool getEmbeddedViewSize (int& w, int& h)
  521. {
  522. if (embeddedView == 0)
  523. return false;
  524. HIRect bounds;
  525. HIViewGetBounds (embeddedView, &bounds);
  526. w = jmax (1, roundToInt (bounds.size.width));
  527. h = jmax (1, roundToInt (bounds.size.height));
  528. return true;
  529. }
  530. void createWindow()
  531. {
  532. if (wrapperWindow == 0)
  533. {
  534. Rect r;
  535. r.left = getScreenX();
  536. r.top = getScreenY();
  537. r.right = r.left + getWidth();
  538. r.bottom = r.top + getHeight();
  539. CreateNewWindow (kDocumentWindowClass,
  540. (WindowAttributes) (kWindowStandardHandlerAttribute | kWindowCompositingAttribute
  541. | kWindowNoShadowAttribute | kWindowNoTitleBarAttribute),
  542. &r, &wrapperWindow);
  543. jassert (wrapperWindow != 0);
  544. if (wrapperWindow == 0)
  545. return;
  546. NSWindow* carbonWindow = [[NSWindow alloc] initWithWindowRef: wrapperWindow];
  547. NSWindow* ownerWindow = [((NSView*) getWindowHandle()) window];
  548. [ownerWindow addChildWindow: carbonWindow
  549. ordered: NSWindowAbove];
  550. embeddedView = attachView (wrapperWindow, HIViewGetRoot (wrapperWindow));
  551. EventTypeSpec windowEventTypes[] = { { kEventClassWindow, kEventWindowGetClickActivation },
  552. { kEventClassWindow, kEventWindowHandleDeactivate } };
  553. EventHandlerUPP upp = NewEventHandlerUPP (carbonEventCallback);
  554. InstallWindowEventHandler (wrapperWindow, upp,
  555. sizeof (windowEventTypes) / sizeof (EventTypeSpec),
  556. windowEventTypes, this, &eventHandlerRef);
  557. setOurSizeToEmbeddedViewSize();
  558. setEmbeddedWindowToOurSize();
  559. creationTime = Time::getCurrentTime();
  560. }
  561. }
  562. void deleteWindow()
  563. {
  564. removeView (embeddedView);
  565. embeddedView = 0;
  566. if (wrapperWindow != 0)
  567. {
  568. RemoveEventHandler (eventHandlerRef);
  569. DisposeWindow (wrapperWindow);
  570. wrapperWindow = 0;
  571. }
  572. }
  573. void setOurSizeToEmbeddedViewSize()
  574. {
  575. int w, h;
  576. if (getEmbeddedViewSize (w, h))
  577. {
  578. if (w != getWidth() || h != getHeight())
  579. {
  580. startTimer (50);
  581. setSize (w, h);
  582. if (getParentComponent() != 0)
  583. getParentComponent()->setSize (w, h);
  584. }
  585. else
  586. {
  587. startTimer (jlimit (50, 500, getTimerInterval() + 20));
  588. }
  589. }
  590. else
  591. {
  592. stopTimer();
  593. }
  594. }
  595. void setEmbeddedWindowToOurSize()
  596. {
  597. if (! recursiveResize)
  598. {
  599. recursiveResize = true;
  600. if (embeddedView != 0)
  601. {
  602. HIRect r;
  603. r.origin.x = 0;
  604. r.origin.y = 0;
  605. r.size.width = (float) getWidth();
  606. r.size.height = (float) getHeight();
  607. HIViewSetFrame (embeddedView, &r);
  608. }
  609. if (wrapperWindow != 0)
  610. {
  611. Rect wr;
  612. wr.left = getScreenX();
  613. wr.top = getScreenY();
  614. wr.right = wr.left + getWidth();
  615. wr.bottom = wr.top + getHeight();
  616. SetWindowBounds (wrapperWindow, kWindowContentRgn, &wr);
  617. ShowWindow (wrapperWindow);
  618. }
  619. recursiveResize = false;
  620. }
  621. }
  622. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  623. {
  624. setEmbeddedWindowToOurSize();
  625. }
  626. void componentPeerChanged()
  627. {
  628. deleteWindow();
  629. createWindow();
  630. }
  631. void componentVisibilityChanged (Component&)
  632. {
  633. if (isShowing())
  634. createWindow();
  635. else
  636. deleteWindow();
  637. setEmbeddedWindowToOurSize();
  638. }
  639. static void recursiveHIViewRepaint (HIViewRef view)
  640. {
  641. HIViewSetNeedsDisplay (view, true);
  642. HIViewRef child = HIViewGetFirstSubview (view);
  643. while (child != 0)
  644. {
  645. recursiveHIViewRepaint (child);
  646. child = HIViewGetNextView (child);
  647. }
  648. }
  649. void timerCallback()
  650. {
  651. setOurSizeToEmbeddedViewSize();
  652. // To avoid strange overpainting problems when the UI is first opened, we'll
  653. // repaint it a few times during the first second that it's on-screen..
  654. if ((Time::getCurrentTime() - creationTime).inMilliseconds() < 1000)
  655. recursiveHIViewRepaint (HIViewGetRoot (wrapperWindow));
  656. }
  657. OSStatus carbonEventHandler (EventHandlerCallRef nextHandlerRef,
  658. EventRef event)
  659. {
  660. switch (GetEventKind (event))
  661. {
  662. case kEventWindowHandleDeactivate:
  663. ActivateWindow (wrapperWindow, TRUE);
  664. break;
  665. case kEventWindowGetClickActivation:
  666. {
  667. getTopLevelComponent()->toFront (false);
  668. ClickActivationResult howToHandleClick = kActivateAndHandleClick;
  669. SetEventParameter (event, kEventParamClickActivation, typeClickActivationResult,
  670. sizeof (ClickActivationResult), &howToHandleClick);
  671. HIViewSetNeedsDisplay (embeddedView, true);
  672. }
  673. break;
  674. }
  675. return noErr;
  676. }
  677. static pascal OSStatus carbonEventCallback (EventHandlerCallRef nextHandlerRef,
  678. EventRef event, void* userData)
  679. {
  680. return ((CarbonViewWrapperComponent*) userData)->carbonEventHandler (nextHandlerRef, event);
  681. }
  682. protected:
  683. WindowRef wrapperWindow;
  684. HIViewRef embeddedView;
  685. bool recursiveResize;
  686. Time creationTime;
  687. EventHandlerRef eventHandlerRef;
  688. };
  689. #endif // __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  690. /*** End of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  691. END_JUCE_NAMESPACE
  692. #endif
  693. #define JUCE_AMALGAMATED_TEMPLATE 1
  694. //==============================================================================
  695. #if JUCE_BUILD_CORE
  696. /*** Start of inlined file: juce_FileLogger.cpp ***/
  697. BEGIN_JUCE_NAMESPACE
  698. FileLogger::FileLogger (const File& logFile_,
  699. const String& welcomeMessage,
  700. const int maxInitialFileSizeBytes)
  701. : logFile (logFile_)
  702. {
  703. if (maxInitialFileSizeBytes >= 0)
  704. trimFileSize (maxInitialFileSizeBytes);
  705. if (! logFile_.exists())
  706. {
  707. // do this so that the parent directories get created..
  708. logFile_.create();
  709. }
  710. logStream = logFile_.createOutputStream (256);
  711. jassert (logStream != 0);
  712. String welcome;
  713. welcome << "\r\n**********************************************************\r\n"
  714. << welcomeMessage
  715. << "\r\nLog started: " << Time::getCurrentTime().toString (true, true)
  716. << "\r\n";
  717. logMessage (welcome);
  718. }
  719. FileLogger::~FileLogger()
  720. {
  721. }
  722. void FileLogger::logMessage (const String& message)
  723. {
  724. if (logStream != 0)
  725. {
  726. DBG (message);
  727. const ScopedLock sl (logLock);
  728. (*logStream) << message << T("\r\n");
  729. logStream->flush();
  730. }
  731. }
  732. void FileLogger::trimFileSize (int maxFileSizeBytes) const
  733. {
  734. if (maxFileSizeBytes <= 0)
  735. {
  736. logFile.deleteFile();
  737. }
  738. else
  739. {
  740. const int64 fileSize = logFile.getSize();
  741. if (fileSize > maxFileSizeBytes)
  742. {
  743. ScopedPointer <FileInputStream> in (logFile.createInputStream());
  744. jassert (in != 0);
  745. if (in != 0)
  746. {
  747. in->setPosition (fileSize - maxFileSizeBytes);
  748. String content;
  749. {
  750. MemoryBlock contentToSave;
  751. contentToSave.setSize (maxFileSizeBytes + 4);
  752. contentToSave.fillWith (0);
  753. in->read (contentToSave.getData(), maxFileSizeBytes);
  754. in = 0;
  755. content = contentToSave.toString();
  756. }
  757. int newStart = 0;
  758. while (newStart < fileSize
  759. && content[newStart] != '\n'
  760. && content[newStart] != '\r')
  761. ++newStart;
  762. logFile.deleteFile();
  763. logFile.appendText (content.substring (newStart), false, false);
  764. }
  765. }
  766. }
  767. }
  768. FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirectoryName,
  769. const String& logFileName,
  770. const String& welcomeMessage,
  771. const int maxInitialFileSizeBytes)
  772. {
  773. #if JUCE_MAC
  774. File logFile ("~/Library/Logs");
  775. logFile = logFile.getChildFile (logFileSubDirectoryName)
  776. .getChildFile (logFileName);
  777. #else
  778. File logFile (File::getSpecialLocation (File::userApplicationDataDirectory));
  779. if (logFile.isDirectory())
  780. {
  781. logFile = logFile.getChildFile (logFileSubDirectoryName)
  782. .getChildFile (logFileName);
  783. }
  784. #endif
  785. return new FileLogger (logFile, welcomeMessage, maxInitialFileSizeBytes);
  786. }
  787. END_JUCE_NAMESPACE
  788. /*** End of inlined file: juce_FileLogger.cpp ***/
  789. /*** Start of inlined file: juce_Logger.cpp ***/
  790. BEGIN_JUCE_NAMESPACE
  791. Logger::Logger()
  792. {
  793. }
  794. Logger::~Logger()
  795. {
  796. }
  797. static Logger* currentLogger = 0;
  798. void Logger::setCurrentLogger (Logger* const newLogger,
  799. const bool deleteOldLogger)
  800. {
  801. Logger* const oldLogger = currentLogger;
  802. currentLogger = newLogger;
  803. if (deleteOldLogger)
  804. delete oldLogger;
  805. }
  806. void Logger::writeToLog (const String& message)
  807. {
  808. if (currentLogger != 0)
  809. currentLogger->logMessage (message);
  810. else
  811. outputDebugString (message);
  812. }
  813. #if JUCE_LOG_ASSERTIONS
  814. void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw()
  815. {
  816. String m ("JUCE Assertion failure in ");
  817. m << filename << ", line " << lineNum;
  818. Logger::writeToLog (m);
  819. }
  820. #endif
  821. END_JUCE_NAMESPACE
  822. /*** End of inlined file: juce_Logger.cpp ***/
  823. /*** Start of inlined file: juce_Random.cpp ***/
  824. BEGIN_JUCE_NAMESPACE
  825. Random::Random (const int64 seedValue) throw()
  826. : seed (seedValue)
  827. {
  828. }
  829. Random::~Random() throw()
  830. {
  831. }
  832. void Random::setSeed (const int64 newSeed) throw()
  833. {
  834. seed = newSeed;
  835. }
  836. void Random::combineSeed (const int64 seedValue) throw()
  837. {
  838. seed ^= nextInt64() ^ seedValue;
  839. }
  840. void Random::setSeedRandomly()
  841. {
  842. combineSeed ((int64) (pointer_sized_int) this);
  843. combineSeed (Time::getMillisecondCounter());
  844. combineSeed (Time::getHighResolutionTicks());
  845. combineSeed (Time::getHighResolutionTicksPerSecond());
  846. combineSeed (Time::currentTimeMillis());
  847. }
  848. int Random::nextInt() throw()
  849. {
  850. seed = (seed * literal64bit (0x5deece66d) + 11) & literal64bit (0xffffffffffff);
  851. return (int) (seed >> 16);
  852. }
  853. int Random::nextInt (const int maxValue) throw()
  854. {
  855. jassert (maxValue > 0);
  856. return (nextInt() & 0x7fffffff) % maxValue;
  857. }
  858. int64 Random::nextInt64() throw()
  859. {
  860. return (((int64) nextInt()) << 32) | (int64) (uint64) (uint32) nextInt();
  861. }
  862. bool Random::nextBool() throw()
  863. {
  864. return (nextInt() & 0x80000000) != 0;
  865. }
  866. float Random::nextFloat() throw()
  867. {
  868. return ((uint32) nextInt()) / (float) 0xffffffff;
  869. }
  870. double Random::nextDouble() throw()
  871. {
  872. return ((uint32) nextInt()) / (double) 0xffffffff;
  873. }
  874. const BitArray Random::nextLargeNumber (const BitArray& maximumValue) throw()
  875. {
  876. BitArray n;
  877. do
  878. {
  879. fillBitsRandomly (n, 0, maximumValue.getHighestBit() + 1);
  880. }
  881. while (n.compare (maximumValue) >= 0);
  882. return n;
  883. }
  884. void Random::fillBitsRandomly (BitArray& arrayToChange, int startBit, int numBits) throw()
  885. {
  886. arrayToChange.setBit (startBit + numBits - 1, true); // to force the array to pre-allocate space
  887. while ((startBit & 31) != 0 && numBits > 0)
  888. {
  889. arrayToChange.setBit (startBit++, nextBool());
  890. --numBits;
  891. }
  892. while (numBits >= 32)
  893. {
  894. arrayToChange.setBitRangeAsInt (startBit, 32, (unsigned int) nextInt());
  895. startBit += 32;
  896. numBits -= 32;
  897. }
  898. while (--numBits >= 0)
  899. arrayToChange.setBit (startBit + numBits, nextBool());
  900. }
  901. Random& Random::getSystemRandom() throw()
  902. {
  903. static Random sysRand (1);
  904. return sysRand;
  905. }
  906. END_JUCE_NAMESPACE
  907. /*** End of inlined file: juce_Random.cpp ***/
  908. /*** Start of inlined file: juce_RelativeTime.cpp ***/
  909. BEGIN_JUCE_NAMESPACE
  910. RelativeTime::RelativeTime (const double seconds_) throw()
  911. : seconds (seconds_)
  912. {
  913. }
  914. RelativeTime::RelativeTime (const RelativeTime& other) throw()
  915. : seconds (other.seconds)
  916. {
  917. }
  918. RelativeTime::~RelativeTime() throw()
  919. {
  920. }
  921. const RelativeTime RelativeTime::milliseconds (const int milliseconds) throw()
  922. {
  923. return RelativeTime (milliseconds * 0.001);
  924. }
  925. const RelativeTime RelativeTime::milliseconds (const int64 milliseconds) throw()
  926. {
  927. return RelativeTime (milliseconds * 0.001);
  928. }
  929. const RelativeTime RelativeTime::minutes (const double numberOfMinutes) throw()
  930. {
  931. return RelativeTime (numberOfMinutes * 60.0);
  932. }
  933. const RelativeTime RelativeTime::hours (const double numberOfHours) throw()
  934. {
  935. return RelativeTime (numberOfHours * (60.0 * 60.0));
  936. }
  937. const RelativeTime RelativeTime::days (const double numberOfDays) throw()
  938. {
  939. return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0));
  940. }
  941. const RelativeTime RelativeTime::weeks (const double numberOfWeeks) throw()
  942. {
  943. return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0));
  944. }
  945. int64 RelativeTime::inMilliseconds() const throw()
  946. {
  947. return (int64)(seconds * 1000.0);
  948. }
  949. double RelativeTime::inMinutes() const throw()
  950. {
  951. return seconds / 60.0;
  952. }
  953. double RelativeTime::inHours() const throw()
  954. {
  955. return seconds / (60.0 * 60.0);
  956. }
  957. double RelativeTime::inDays() const throw()
  958. {
  959. return seconds / (60.0 * 60.0 * 24.0);
  960. }
  961. double RelativeTime::inWeeks() const throw()
  962. {
  963. return seconds / (60.0 * 60.0 * 24.0 * 7.0);
  964. }
  965. const String RelativeTime::getDescription (const String& returnValueForZeroTime) const throw()
  966. {
  967. if (seconds < 0.001 && seconds > -0.001)
  968. return returnValueForZeroTime;
  969. String result;
  970. if (seconds < 0)
  971. result = T("-");
  972. int fieldsShown = 0;
  973. int n = abs ((int) inWeeks());
  974. if (n > 0)
  975. {
  976. result << n << ((n == 1) ? TRANS(" week ")
  977. : TRANS(" weeks "));
  978. ++fieldsShown;
  979. }
  980. n = abs ((int) inDays()) % 7;
  981. if (n > 0)
  982. {
  983. result << n << ((n == 1) ? TRANS(" day ")
  984. : TRANS(" days "));
  985. ++fieldsShown;
  986. }
  987. if (fieldsShown < 2)
  988. {
  989. n = abs ((int) inHours()) % 24;
  990. if (n > 0)
  991. {
  992. result << n << ((n == 1) ? TRANS(" hr ")
  993. : TRANS(" hrs "));
  994. ++fieldsShown;
  995. }
  996. if (fieldsShown < 2)
  997. {
  998. n = abs ((int) inMinutes()) % 60;
  999. if (n > 0)
  1000. {
  1001. result << n << ((n == 1) ? TRANS(" min ")
  1002. : TRANS(" mins "));
  1003. ++fieldsShown;
  1004. }
  1005. if (fieldsShown < 2)
  1006. {
  1007. n = abs ((int) inSeconds()) % 60;
  1008. if (n > 0)
  1009. {
  1010. result << n << ((n == 1) ? TRANS(" sec ")
  1011. : TRANS(" secs "));
  1012. ++fieldsShown;
  1013. }
  1014. if (fieldsShown < 1)
  1015. {
  1016. n = abs ((int) inMilliseconds()) % 1000;
  1017. if (n > 0)
  1018. {
  1019. result << n << TRANS(" ms");
  1020. ++fieldsShown;
  1021. }
  1022. }
  1023. }
  1024. }
  1025. }
  1026. return result.trimEnd();
  1027. }
  1028. RelativeTime& RelativeTime::operator= (const RelativeTime& other) throw()
  1029. {
  1030. seconds = other.seconds;
  1031. return *this;
  1032. }
  1033. bool RelativeTime::operator== (const RelativeTime& other) const throw()
  1034. {
  1035. return seconds == other.seconds;
  1036. }
  1037. bool RelativeTime::operator!= (const RelativeTime& other) const throw()
  1038. {
  1039. return seconds != other.seconds;
  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. const RelativeTime RelativeTime::operator+ (const RelativeTime& timeToAdd) const throw()
  1058. {
  1059. return RelativeTime (seconds + timeToAdd.seconds);
  1060. }
  1061. const RelativeTime RelativeTime::operator- (const RelativeTime& timeToSubtract) const throw()
  1062. {
  1063. return RelativeTime (seconds - timeToSubtract.seconds);
  1064. }
  1065. const RelativeTime RelativeTime::operator+ (const double secondsToAdd) const throw()
  1066. {
  1067. return RelativeTime (seconds + secondsToAdd);
  1068. }
  1069. const RelativeTime RelativeTime::operator- (const double secondsToSubtract) const throw()
  1070. {
  1071. return RelativeTime (seconds - secondsToSubtract);
  1072. }
  1073. const RelativeTime& RelativeTime::operator+= (const RelativeTime& timeToAdd) throw()
  1074. {
  1075. seconds += timeToAdd.seconds;
  1076. return *this;
  1077. }
  1078. const RelativeTime& RelativeTime::operator-= (const RelativeTime& timeToSubtract) throw()
  1079. {
  1080. seconds -= timeToSubtract.seconds;
  1081. return *this;
  1082. }
  1083. const RelativeTime& RelativeTime::operator+= (const double secondsToAdd) throw()
  1084. {
  1085. seconds += secondsToAdd;
  1086. return *this;
  1087. }
  1088. const RelativeTime& RelativeTime::operator-= (const double secondsToSubtract) throw()
  1089. {
  1090. seconds -= secondsToSubtract;
  1091. return *this;
  1092. }
  1093. END_JUCE_NAMESPACE
  1094. /*** End of inlined file: juce_RelativeTime.cpp ***/
  1095. /*** Start of inlined file: juce_SystemStats.cpp ***/
  1096. BEGIN_JUCE_NAMESPACE
  1097. void juce_initialiseStrings();
  1098. const String SystemStats::getJUCEVersion() throw()
  1099. {
  1100. return "JUCE v" + String (JUCE_MAJOR_VERSION)
  1101. + "." + String (JUCE_MINOR_VERSION)
  1102. + "." + String (JUCE_BUILDNUMBER);
  1103. }
  1104. static bool juceInitialisedNonGUI = false;
  1105. void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI()
  1106. {
  1107. if (! juceInitialisedNonGUI)
  1108. {
  1109. #if JUCE_MAC || JUCE_IPHONE
  1110. const ScopedAutoReleasePool pool;
  1111. #endif
  1112. #ifdef JUCE_DEBUG
  1113. {
  1114. // Some simple test code to keep an eye on things and make sure these functions
  1115. // work ok on all platforms. Let me know if any of these assertions fail!
  1116. static_jassert (sizeof (pointer_sized_int) == sizeof (void*));
  1117. char a1[7];
  1118. jassert (numElementsInArray(a1) == 7);
  1119. int a2[3];
  1120. jassert (numElementsInArray(a2) == 3);
  1121. int n = 1;
  1122. Atomic::increment (n);
  1123. jassert (Atomic::incrementAndReturn (n) == 3);
  1124. Atomic::decrement (n);
  1125. jassert (Atomic::decrementAndReturn (n) == 1);
  1126. jassert (ByteOrder::swap ((uint16) 0x1122) == 0x2211);
  1127. jassert (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211);
  1128. // Some quick stream tests..
  1129. int randomInt = Random::getSystemRandom().nextInt();
  1130. int64 randomInt64 = Random::getSystemRandom().nextInt64();
  1131. double randomDouble = Random::getSystemRandom().nextDouble();
  1132. String randomString;
  1133. for (int i = 50; --i >= 0;)
  1134. randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff);
  1135. MemoryOutputStream mo;
  1136. mo.writeInt (randomInt);
  1137. mo.writeIntBigEndian (randomInt);
  1138. mo.writeCompressedInt (randomInt);
  1139. mo.writeString (randomString);
  1140. mo.writeInt64 (randomInt64);
  1141. mo.writeInt64BigEndian (randomInt64);
  1142. mo.writeDouble (randomDouble);
  1143. mo.writeDoubleBigEndian (randomDouble);
  1144. MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
  1145. jassert (mi.readInt() == randomInt);
  1146. jassert (mi.readIntBigEndian() == randomInt);
  1147. jassert (mi.readCompressedInt() == randomInt);
  1148. jassert (mi.readString() == randomString);
  1149. jassert (mi.readInt64() == randomInt64);
  1150. jassert (mi.readInt64BigEndian() == randomInt64);
  1151. jassert (mi.readDouble() == randomDouble);
  1152. jassert (mi.readDoubleBigEndian() == randomDouble);
  1153. }
  1154. #endif
  1155. // Now the real initialisation..
  1156. juceInitialisedNonGUI = true;
  1157. DBG (SystemStats::getJUCEVersion());
  1158. juce_initialiseStrings();
  1159. SystemStats::initialiseStats();
  1160. Random::getSystemRandom().setSeedRandomly(); // (mustn't call this before initialiseStats() because it relies on the time being set up)
  1161. }
  1162. }
  1163. #if JUCE_WINDOWS
  1164. // This is imported from the sockets code..
  1165. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  1166. extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib;
  1167. #endif
  1168. #if JUCE_DEBUG
  1169. extern void juce_CheckForDanglingStreams();
  1170. #endif
  1171. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI()
  1172. {
  1173. if (juceInitialisedNonGUI)
  1174. {
  1175. #if JUCE_MAC || JUCE_IPHONE
  1176. const ScopedAutoReleasePool pool;
  1177. #endif
  1178. #if JUCE_WINDOWS
  1179. // need to shut down sockets if they were used..
  1180. if (juce_CloseWin32SocketLib != 0)
  1181. (*juce_CloseWin32SocketLib)();
  1182. #endif
  1183. LocalisedStrings::setCurrentMappings (0);
  1184. Thread::stopAllThreads (3000);
  1185. #if JUCE_DEBUG
  1186. juce_CheckForDanglingStreams();
  1187. #endif
  1188. juceInitialisedNonGUI = false;
  1189. }
  1190. }
  1191. #ifdef JUCE_DLL
  1192. void* juce_Malloc (const int size)
  1193. {
  1194. return malloc (size);
  1195. }
  1196. void* juce_Calloc (const int size)
  1197. {
  1198. return calloc (1, size);
  1199. }
  1200. void* juce_Realloc (void* const block, const int size)
  1201. {
  1202. return realloc (block, size);
  1203. }
  1204. void juce_Free (void* const block)
  1205. {
  1206. free (block);
  1207. }
  1208. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  1209. void* juce_DebugMalloc (const int size, const char* file, const int line)
  1210. {
  1211. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  1212. }
  1213. void* juce_DebugCalloc (const int size, const char* file, const int line)
  1214. {
  1215. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  1216. }
  1217. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  1218. {
  1219. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  1220. }
  1221. void juce_DebugFree (void* const block)
  1222. {
  1223. _free_dbg (block, _NORMAL_BLOCK);
  1224. }
  1225. #endif
  1226. #endif
  1227. END_JUCE_NAMESPACE
  1228. /*** End of inlined file: juce_SystemStats.cpp ***/
  1229. /*** Start of inlined file: juce_Time.cpp ***/
  1230. #ifdef _MSC_VER
  1231. #pragma warning (disable: 4514)
  1232. #pragma warning (push)
  1233. #endif
  1234. #ifndef JUCE_WINDOWS
  1235. #include <sys/time.h>
  1236. #else
  1237. #include <ctime>
  1238. #endif
  1239. #include <sys/timeb.h>
  1240. BEGIN_JUCE_NAMESPACE
  1241. #ifdef _MSC_VER
  1242. #pragma warning (pop)
  1243. #ifdef _INC_TIME_INL
  1244. #define USE_NEW_SECURE_TIME_FNS
  1245. #endif
  1246. #endif
  1247. static void millisToLocal (const int64 millis, struct tm& result) throw()
  1248. {
  1249. const int64 seconds = millis / 1000;
  1250. if (seconds < literal64bit (86400) || seconds >= literal64bit (2145916800))
  1251. {
  1252. // use extended maths for dates beyond 1970 to 2037..
  1253. const int timeZoneAdjustment = 31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000);
  1254. const int64 jdm = seconds + timeZoneAdjustment + literal64bit (210866803200);
  1255. const int days = (int) (jdm / literal64bit (86400));
  1256. const int a = 32044 + days;
  1257. const int b = (4 * a + 3) / 146097;
  1258. const int c = a - (b * 146097) / 4;
  1259. const int d = (4 * c + 3) / 1461;
  1260. const int e = c - (d * 1461) / 4;
  1261. const int m = (5 * e + 2) / 153;
  1262. result.tm_mday = e - (153 * m + 2) / 5 + 1;
  1263. result.tm_mon = m + 2 - 12 * (m / 10);
  1264. result.tm_year = b * 100 + d - 6700 + (m / 10);
  1265. result.tm_wday = (days + 1) % 7;
  1266. result.tm_yday = -1;
  1267. int t = (int) (jdm % literal64bit (86400));
  1268. result.tm_hour = t / 3600;
  1269. t %= 3600;
  1270. result.tm_min = t / 60;
  1271. result.tm_sec = t % 60;
  1272. result.tm_isdst = -1;
  1273. }
  1274. else
  1275. {
  1276. time_t now = (time_t) (seconds);
  1277. #if JUCE_WINDOWS
  1278. #ifdef USE_NEW_SECURE_TIME_FNS
  1279. if (now >= 0 && now <= 0x793406fff)
  1280. localtime_s (&result, &now);
  1281. else
  1282. zeromem (&result, sizeof (result));
  1283. #else
  1284. result = *localtime (&now);
  1285. #endif
  1286. #else
  1287. // more thread-safe
  1288. localtime_r (&now, &result);
  1289. #endif
  1290. }
  1291. }
  1292. Time::Time() throw()
  1293. : millisSinceEpoch (0)
  1294. {
  1295. }
  1296. Time::Time (const Time& other) throw()
  1297. : millisSinceEpoch (other.millisSinceEpoch)
  1298. {
  1299. }
  1300. Time::Time (const int64 ms) throw()
  1301. : millisSinceEpoch (ms)
  1302. {
  1303. }
  1304. Time::Time (const int year,
  1305. const int month,
  1306. const int day,
  1307. const int hours,
  1308. const int minutes,
  1309. const int seconds,
  1310. const int milliseconds,
  1311. const bool useLocalTime) throw()
  1312. {
  1313. jassert (year > 100); // year must be a 4-digit version
  1314. if (year < 1971 || year >= 2038 || ! useLocalTime)
  1315. {
  1316. // use extended maths for dates beyond 1970 to 2037..
  1317. const int timeZoneAdjustment = useLocalTime ? (31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000))
  1318. : 0;
  1319. const int a = (13 - month) / 12;
  1320. const int y = year + 4800 - a;
  1321. const int jd = day + (153 * (month + 12 * a - 2) + 2) / 5
  1322. + (y * 365) + (y / 4) - (y / 100) + (y / 400)
  1323. - 32045;
  1324. const int64 s = ((int64) jd) * literal64bit (86400) - literal64bit (210866803200);
  1325. millisSinceEpoch = 1000 * (s + (hours * 3600 + minutes * 60 + seconds - timeZoneAdjustment))
  1326. + milliseconds;
  1327. }
  1328. else
  1329. {
  1330. struct tm t;
  1331. t.tm_year = year - 1900;
  1332. t.tm_mon = month;
  1333. t.tm_mday = day;
  1334. t.tm_hour = hours;
  1335. t.tm_min = minutes;
  1336. t.tm_sec = seconds;
  1337. t.tm_isdst = -1;
  1338. millisSinceEpoch = 1000 * (int64) mktime (&t);
  1339. if (millisSinceEpoch < 0)
  1340. millisSinceEpoch = 0;
  1341. else
  1342. millisSinceEpoch += milliseconds;
  1343. }
  1344. }
  1345. Time::~Time() throw()
  1346. {
  1347. }
  1348. Time& Time::operator= (const Time& other) throw()
  1349. {
  1350. millisSinceEpoch = other.millisSinceEpoch;
  1351. return *this;
  1352. }
  1353. int64 Time::currentTimeMillis() throw()
  1354. {
  1355. static uint32 lastCounterResult = 0xffffffff;
  1356. static int64 correction = 0;
  1357. const uint32 now = getMillisecondCounter();
  1358. // check the counter hasn't wrapped (also triggered the first time this function is called)
  1359. if (now < lastCounterResult)
  1360. {
  1361. // double-check it's actually wrapped, in case multi-cpu machines have timers that drift a bit.
  1362. if (lastCounterResult == 0xffffffff || now < lastCounterResult - 10)
  1363. {
  1364. // get the time once using normal library calls, and store the difference needed to
  1365. // turn the millisecond counter into a real time.
  1366. #if JUCE_WINDOWS
  1367. struct _timeb t;
  1368. #ifdef USE_NEW_SECURE_TIME_FNS
  1369. _ftime_s (&t);
  1370. #else
  1371. _ftime (&t);
  1372. #endif
  1373. correction = (((int64) t.time) * 1000 + t.millitm) - now;
  1374. #else
  1375. struct timeval tv;
  1376. struct timezone tz;
  1377. gettimeofday (&tv, &tz);
  1378. correction = (((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000) - now;
  1379. #endif
  1380. }
  1381. }
  1382. lastCounterResult = now;
  1383. return correction + now;
  1384. }
  1385. uint32 juce_millisecondsSinceStartup() throw();
  1386. static uint32 lastMSCounterValue = 0;
  1387. uint32 Time::getMillisecondCounter() throw()
  1388. {
  1389. const uint32 now = juce_millisecondsSinceStartup();
  1390. if (now < lastMSCounterValue)
  1391. {
  1392. // in multi-threaded apps this might be called concurrently, so
  1393. // make sure that our last counter value only increases and doesn't
  1394. // go backwards..
  1395. if (now < lastMSCounterValue - 1000)
  1396. lastMSCounterValue = now;
  1397. }
  1398. else
  1399. {
  1400. lastMSCounterValue = now;
  1401. }
  1402. return now;
  1403. }
  1404. uint32 Time::getApproximateMillisecondCounter() throw()
  1405. {
  1406. jassert (lastMSCounterValue != 0);
  1407. return lastMSCounterValue;
  1408. }
  1409. void Time::waitForMillisecondCounter (const uint32 targetTime) throw()
  1410. {
  1411. for (;;)
  1412. {
  1413. const uint32 now = getMillisecondCounter();
  1414. if (now >= targetTime)
  1415. break;
  1416. const int toWait = targetTime - now;
  1417. if (toWait > 2)
  1418. {
  1419. Thread::sleep (jmin (20, toWait >> 1));
  1420. }
  1421. else
  1422. {
  1423. // xxx should consider using mutex_pause on the mac as it apparently
  1424. // makes it seem less like a spinlock and avoids lowering the thread pri.
  1425. for (int i = 10; --i >= 0;)
  1426. Thread::yield();
  1427. }
  1428. }
  1429. }
  1430. double Time::highResolutionTicksToSeconds (const int64 ticks) throw()
  1431. {
  1432. return ticks / (double) getHighResolutionTicksPerSecond();
  1433. }
  1434. int64 Time::secondsToHighResolutionTicks (const double seconds) throw()
  1435. {
  1436. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  1437. }
  1438. const Time JUCE_CALLTYPE Time::getCurrentTime() throw()
  1439. {
  1440. return Time (currentTimeMillis());
  1441. }
  1442. const String Time::toString (const bool includeDate,
  1443. const bool includeTime,
  1444. const bool includeSeconds,
  1445. const bool use24HourClock) const throw()
  1446. {
  1447. String result;
  1448. if (includeDate)
  1449. {
  1450. result << getDayOfMonth() << ' '
  1451. << getMonthName (true) << ' '
  1452. << getYear();
  1453. if (includeTime)
  1454. result << ' ';
  1455. }
  1456. if (includeTime)
  1457. {
  1458. const int mins = getMinutes();
  1459. result << (use24HourClock ? getHours() : getHoursInAmPmFormat())
  1460. << (mins < 10 ? ":0" : ":") << mins;
  1461. if (includeSeconds)
  1462. {
  1463. const int secs = getSeconds();
  1464. result << (secs < 10 ? ":0" : ":") << secs;
  1465. }
  1466. if (! use24HourClock)
  1467. result << (isAfternoon() ? "pm" : "am");
  1468. }
  1469. return result.trimEnd();
  1470. }
  1471. const String Time::formatted (const tchar* const format) const throw()
  1472. {
  1473. String buffer;
  1474. int bufferSize = 128;
  1475. buffer.preallocateStorage (bufferSize);
  1476. struct tm t;
  1477. millisToLocal (millisSinceEpoch, t);
  1478. while (CharacterFunctions::ftime ((tchar*) (const tchar*) buffer, bufferSize, format, &t) <= 0)
  1479. {
  1480. bufferSize += 128;
  1481. buffer.preallocateStorage (bufferSize);
  1482. }
  1483. return buffer;
  1484. }
  1485. int Time::getYear() const throw()
  1486. {
  1487. struct tm t;
  1488. millisToLocal (millisSinceEpoch, t);
  1489. return t.tm_year + 1900;
  1490. }
  1491. int Time::getMonth() const throw()
  1492. {
  1493. struct tm t;
  1494. millisToLocal (millisSinceEpoch, t);
  1495. return t.tm_mon;
  1496. }
  1497. int Time::getDayOfMonth() const throw()
  1498. {
  1499. struct tm t;
  1500. millisToLocal (millisSinceEpoch, t);
  1501. return t.tm_mday;
  1502. }
  1503. int Time::getDayOfWeek() const throw()
  1504. {
  1505. struct tm t;
  1506. millisToLocal (millisSinceEpoch, t);
  1507. return t.tm_wday;
  1508. }
  1509. int Time::getHours() const throw()
  1510. {
  1511. struct tm t;
  1512. millisToLocal (millisSinceEpoch, t);
  1513. return t.tm_hour;
  1514. }
  1515. int Time::getHoursInAmPmFormat() const throw()
  1516. {
  1517. const int hours = getHours();
  1518. if (hours == 0)
  1519. return 12;
  1520. else if (hours <= 12)
  1521. return hours;
  1522. else
  1523. return hours - 12;
  1524. }
  1525. bool Time::isAfternoon() const throw()
  1526. {
  1527. return getHours() >= 12;
  1528. }
  1529. static int extendedModulo (const int64 value, const int modulo) throw()
  1530. {
  1531. return (int) (value >= 0 ? (value % modulo)
  1532. : (value - ((value / modulo) + 1) * modulo));
  1533. }
  1534. int Time::getMinutes() const throw()
  1535. {
  1536. struct tm t;
  1537. millisToLocal (millisSinceEpoch, t);
  1538. return t.tm_min;
  1539. }
  1540. int Time::getSeconds() const throw()
  1541. {
  1542. return extendedModulo (millisSinceEpoch / 1000, 60);
  1543. }
  1544. int Time::getMilliseconds() const throw()
  1545. {
  1546. return extendedModulo (millisSinceEpoch, 1000);
  1547. }
  1548. bool Time::isDaylightSavingTime() const throw()
  1549. {
  1550. struct tm t;
  1551. millisToLocal (millisSinceEpoch, t);
  1552. return t.tm_isdst != 0;
  1553. }
  1554. const String Time::getTimeZone() const throw()
  1555. {
  1556. String zone[2];
  1557. #if JUCE_WINDOWS
  1558. _tzset();
  1559. #ifdef USE_NEW_SECURE_TIME_FNS
  1560. {
  1561. char name [128];
  1562. size_t length;
  1563. for (int i = 0; i < 2; ++i)
  1564. {
  1565. zeromem (name, sizeof (name));
  1566. _get_tzname (&length, name, 127, i);
  1567. zone[i] = name;
  1568. }
  1569. }
  1570. #else
  1571. const char** const zonePtr = (const char**) _tzname;
  1572. zone[0] = zonePtr[0];
  1573. zone[1] = zonePtr[1];
  1574. #endif
  1575. #else
  1576. tzset();
  1577. const char** const zonePtr = (const char**) tzname;
  1578. zone[0] = zonePtr[0];
  1579. zone[1] = zonePtr[1];
  1580. #endif
  1581. if (isDaylightSavingTime())
  1582. {
  1583. zone[0] = zone[1];
  1584. if (zone[0].length() > 3
  1585. && zone[0].containsIgnoreCase (T("daylight"))
  1586. && zone[0].contains (T("GMT")))
  1587. zone[0] = "BST";
  1588. }
  1589. return zone[0].substring (0, 3);
  1590. }
  1591. const String Time::getMonthName (const bool threeLetterVersion) const throw()
  1592. {
  1593. return getMonthName (getMonth(), threeLetterVersion);
  1594. }
  1595. const String Time::getWeekdayName (const bool threeLetterVersion) const throw()
  1596. {
  1597. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  1598. }
  1599. const String Time::getMonthName (int monthNumber,
  1600. const bool threeLetterVersion) throw()
  1601. {
  1602. const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  1603. const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  1604. monthNumber %= 12;
  1605. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  1606. : longMonthNames [monthNumber]);
  1607. }
  1608. const String Time::getWeekdayName (int day,
  1609. const bool threeLetterVersion) throw()
  1610. {
  1611. const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  1612. const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  1613. day %= 7;
  1614. return TRANS (threeLetterVersion ? shortDayNames [day]
  1615. : longDayNames [day]);
  1616. }
  1617. END_JUCE_NAMESPACE
  1618. /*** End of inlined file: juce_Time.cpp ***/
  1619. /*** Start of inlined file: juce_BitArray.cpp ***/
  1620. BEGIN_JUCE_NAMESPACE
  1621. BitArray::BitArray() throw()
  1622. : numValues (4),
  1623. highestBit (-1),
  1624. negative (false)
  1625. {
  1626. values.calloc (numValues + 1);
  1627. }
  1628. BitArray::BitArray (const int value) throw()
  1629. : numValues (4),
  1630. highestBit (31),
  1631. negative (value < 0)
  1632. {
  1633. values.calloc (numValues + 1);
  1634. values[0] = abs (value);
  1635. highestBit = getHighestBit();
  1636. }
  1637. BitArray::BitArray (int64 value) throw()
  1638. : numValues (4),
  1639. highestBit (63),
  1640. negative (value < 0)
  1641. {
  1642. values.calloc (numValues + 1);
  1643. if (value < 0)
  1644. value = -value;
  1645. values[0] = (unsigned int) value;
  1646. values[1] = (unsigned int) (value >> 32);
  1647. highestBit = getHighestBit();
  1648. }
  1649. BitArray::BitArray (const unsigned int value) throw()
  1650. : numValues (4),
  1651. highestBit (31),
  1652. negative (false)
  1653. {
  1654. values.calloc (numValues + 1);
  1655. values[0] = value;
  1656. highestBit = getHighestBit();
  1657. }
  1658. BitArray::BitArray (const BitArray& other) throw()
  1659. : numValues (jmax (4, (other.highestBit >> 5) + 1)),
  1660. highestBit (other.getHighestBit()),
  1661. negative (other.negative)
  1662. {
  1663. values.malloc (numValues + 1);
  1664. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1665. }
  1666. BitArray::~BitArray() throw()
  1667. {
  1668. }
  1669. BitArray& BitArray::operator= (const BitArray& other) throw()
  1670. {
  1671. if (this != &other)
  1672. {
  1673. highestBit = other.getHighestBit();
  1674. numValues = jmax (4, (highestBit >> 5) + 1);
  1675. negative = other.negative;
  1676. values.malloc (numValues + 1);
  1677. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1678. }
  1679. return *this;
  1680. }
  1681. // result == 0 = the same
  1682. // result < 0 = this number is smaller
  1683. // result > 0 = this number is bigger
  1684. int BitArray::compare (const BitArray& other) const throw()
  1685. {
  1686. if (isNegative() == other.isNegative())
  1687. {
  1688. const int absComp = compareAbsolute (other);
  1689. return isNegative() ? -absComp : absComp;
  1690. }
  1691. else
  1692. {
  1693. return isNegative() ? -1 : 1;
  1694. }
  1695. }
  1696. int BitArray::compareAbsolute (const BitArray& other) const throw()
  1697. {
  1698. const int h1 = getHighestBit();
  1699. const int h2 = other.getHighestBit();
  1700. if (h1 > h2)
  1701. return 1;
  1702. else if (h1 < h2)
  1703. return -1;
  1704. for (int i = (h1 >> 5) + 1; --i >= 0;)
  1705. if (values[i] != other.values[i])
  1706. return (values[i] > other.values[i]) ? 1 : -1;
  1707. return 0;
  1708. }
  1709. bool BitArray::operator== (const BitArray& other) const throw()
  1710. {
  1711. return compare (other) == 0;
  1712. }
  1713. bool BitArray::operator!= (const BitArray& other) const throw()
  1714. {
  1715. return compare (other) != 0;
  1716. }
  1717. bool BitArray::operator[] (const int bit) const throw()
  1718. {
  1719. return bit >= 0 && bit <= highestBit
  1720. && ((values [bit >> 5] & (1 << (bit & 31))) != 0);
  1721. }
  1722. bool BitArray::isEmpty() const throw()
  1723. {
  1724. return getHighestBit() < 0;
  1725. }
  1726. void BitArray::clear() throw()
  1727. {
  1728. if (numValues > 16)
  1729. {
  1730. numValues = 4;
  1731. values.calloc (numValues + 1);
  1732. }
  1733. else
  1734. {
  1735. zeromem (values, sizeof (unsigned int) * (numValues + 1));
  1736. }
  1737. highestBit = -1;
  1738. negative = false;
  1739. }
  1740. void BitArray::setBit (const int bit) throw()
  1741. {
  1742. if (bit >= 0)
  1743. {
  1744. if (bit > highestBit)
  1745. {
  1746. ensureSize (bit >> 5);
  1747. highestBit = bit;
  1748. }
  1749. values [bit >> 5] |= (1 << (bit & 31));
  1750. }
  1751. }
  1752. void BitArray::setBit (const int bit,
  1753. const bool shouldBeSet) throw()
  1754. {
  1755. if (shouldBeSet)
  1756. setBit (bit);
  1757. else
  1758. clearBit (bit);
  1759. }
  1760. void BitArray::clearBit (const int bit) throw()
  1761. {
  1762. if (bit >= 0 && bit <= highestBit)
  1763. values [bit >> 5] &= ~(1 << (bit & 31));
  1764. }
  1765. void BitArray::setRange (int startBit,
  1766. int numBits,
  1767. const bool shouldBeSet) throw()
  1768. {
  1769. while (--numBits >= 0)
  1770. setBit (startBit++, shouldBeSet);
  1771. }
  1772. void BitArray::insertBit (const int bit,
  1773. const bool shouldBeSet) throw()
  1774. {
  1775. if (bit >= 0)
  1776. shiftBits (1, bit);
  1777. setBit (bit, shouldBeSet);
  1778. }
  1779. void BitArray::andWith (const BitArray& other) throw()
  1780. {
  1781. // this operation will only work with the absolute values
  1782. jassert (isNegative() == other.isNegative());
  1783. int n = numValues;
  1784. while (n > other.numValues)
  1785. values[--n] = 0;
  1786. while (--n >= 0)
  1787. values[n] &= other.values[n];
  1788. if (other.highestBit < highestBit)
  1789. highestBit = other.highestBit;
  1790. highestBit = getHighestBit();
  1791. }
  1792. void BitArray::orWith (const BitArray& other) throw()
  1793. {
  1794. if (other.highestBit < 0)
  1795. return;
  1796. // this operation will only work with the absolute values
  1797. jassert (isNegative() == other.isNegative());
  1798. ensureSize (other.highestBit >> 5);
  1799. int n = (other.highestBit >> 5) + 1;
  1800. while (--n >= 0)
  1801. values[n] |= other.values[n];
  1802. if (other.highestBit > highestBit)
  1803. highestBit = other.highestBit;
  1804. highestBit = getHighestBit();
  1805. }
  1806. void BitArray::xorWith (const BitArray& other) throw()
  1807. {
  1808. if (other.highestBit < 0)
  1809. return;
  1810. // this operation will only work with the absolute values
  1811. jassert (isNegative() == other.isNegative());
  1812. ensureSize (other.highestBit >> 5);
  1813. int n = (other.highestBit >> 5) + 1;
  1814. while (--n >= 0)
  1815. values[n] ^= other.values[n];
  1816. if (other.highestBit > highestBit)
  1817. highestBit = other.highestBit;
  1818. highestBit = getHighestBit();
  1819. }
  1820. void BitArray::add (const BitArray& other) throw()
  1821. {
  1822. if (other.isNegative())
  1823. {
  1824. BitArray o (other);
  1825. o.negate();
  1826. subtract (o);
  1827. return;
  1828. }
  1829. if (isNegative())
  1830. {
  1831. if (compareAbsolute (other) < 0)
  1832. {
  1833. BitArray temp (*this);
  1834. temp.negate();
  1835. *this = other;
  1836. subtract (temp);
  1837. }
  1838. else
  1839. {
  1840. negate();
  1841. subtract (other);
  1842. negate();
  1843. }
  1844. return;
  1845. }
  1846. if (other.highestBit > highestBit)
  1847. highestBit = other.highestBit;
  1848. ++highestBit;
  1849. const int numInts = (highestBit >> 5) + 1;
  1850. ensureSize (numInts);
  1851. int64 remainder = 0;
  1852. for (int i = 0; i <= numInts; ++i)
  1853. {
  1854. if (i < numValues)
  1855. remainder += values[i];
  1856. if (i < other.numValues)
  1857. remainder += other.values[i];
  1858. values[i] = (unsigned int) remainder;
  1859. remainder >>= 32;
  1860. }
  1861. jassert (remainder == 0);
  1862. highestBit = getHighestBit();
  1863. }
  1864. void BitArray::subtract (const BitArray& other) throw()
  1865. {
  1866. if (other.isNegative())
  1867. {
  1868. BitArray o (other);
  1869. o.negate();
  1870. add (o);
  1871. return;
  1872. }
  1873. if (! isNegative())
  1874. {
  1875. if (compareAbsolute (other) < 0)
  1876. {
  1877. BitArray temp (*this);
  1878. *this = other;
  1879. subtract (temp);
  1880. negate();
  1881. return;
  1882. }
  1883. }
  1884. else
  1885. {
  1886. negate();
  1887. add (other);
  1888. negate();
  1889. return;
  1890. }
  1891. const int numInts = (highestBit >> 5) + 1;
  1892. const int maxOtherInts = (other.highestBit >> 5) + 1;
  1893. int64 amountToSubtract = 0;
  1894. for (int i = 0; i <= numInts; ++i)
  1895. {
  1896. if (i <= maxOtherInts)
  1897. amountToSubtract += (int64)other.values[i];
  1898. if (values[i] >= amountToSubtract)
  1899. {
  1900. values[i] = (unsigned int) (values[i] - amountToSubtract);
  1901. amountToSubtract = 0;
  1902. }
  1903. else
  1904. {
  1905. const int64 n = ((int64) values[i] + (((int64) 1) << 32)) - amountToSubtract;
  1906. values[i] = (unsigned int) n;
  1907. amountToSubtract = 1;
  1908. }
  1909. }
  1910. }
  1911. void BitArray::multiplyBy (const BitArray& other) throw()
  1912. {
  1913. BitArray total;
  1914. highestBit = getHighestBit();
  1915. const bool wasNegative = isNegative();
  1916. setNegative (false);
  1917. for (int i = 0; i <= highestBit; ++i)
  1918. {
  1919. if (operator[](i))
  1920. {
  1921. BitArray n (other);
  1922. n.setNegative (false);
  1923. n.shiftBits (i);
  1924. total.add (n);
  1925. }
  1926. }
  1927. *this = total;
  1928. negative = wasNegative ^ other.isNegative();
  1929. }
  1930. void BitArray::divideBy (const BitArray& divisor, BitArray& remainder) throw()
  1931. {
  1932. jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
  1933. const int divHB = divisor.getHighestBit();
  1934. const int ourHB = getHighestBit();
  1935. if (divHB < 0 || ourHB < 0)
  1936. {
  1937. // division by zero
  1938. remainder.clear();
  1939. clear();
  1940. }
  1941. else
  1942. {
  1943. remainder = *this;
  1944. remainder.setNegative (false);
  1945. const bool wasNegative = isNegative();
  1946. clear();
  1947. BitArray temp (divisor);
  1948. temp.setNegative (false);
  1949. int leftShift = ourHB - divHB;
  1950. temp.shiftBits (leftShift);
  1951. while (leftShift >= 0)
  1952. {
  1953. if (remainder.compareAbsolute (temp) >= 0)
  1954. {
  1955. remainder.subtract (temp);
  1956. setBit (leftShift);
  1957. }
  1958. if (--leftShift >= 0)
  1959. temp.shiftBits (-1);
  1960. }
  1961. negative = wasNegative ^ divisor.isNegative();
  1962. remainder.setNegative (wasNegative);
  1963. }
  1964. }
  1965. void BitArray::modulo (const BitArray& divisor) throw()
  1966. {
  1967. BitArray remainder;
  1968. divideBy (divisor, remainder);
  1969. *this = remainder;
  1970. }
  1971. static const BitArray simpleGCD (BitArray* m, BitArray* n) throw()
  1972. {
  1973. while (! m->isEmpty())
  1974. {
  1975. if (n->compareAbsolute (*m) > 0)
  1976. swapVariables (m, n);
  1977. m->subtract (*n);
  1978. }
  1979. return *n;
  1980. }
  1981. const BitArray BitArray::findGreatestCommonDivisor (BitArray n) const throw()
  1982. {
  1983. BitArray m (*this);
  1984. while (! n.isEmpty())
  1985. {
  1986. if (abs (m.getHighestBit() - n.getHighestBit()) <= 16)
  1987. return simpleGCD (&m, &n);
  1988. BitArray temp1 (m), temp2;
  1989. temp1.divideBy (n, temp2);
  1990. m = n;
  1991. n = temp2;
  1992. }
  1993. return m;
  1994. }
  1995. void BitArray::exponentModulo (const BitArray& exponent,
  1996. const BitArray& modulus) throw()
  1997. {
  1998. BitArray exp (exponent);
  1999. exp.modulo (modulus);
  2000. BitArray value (*this);
  2001. value.modulo (modulus);
  2002. clear();
  2003. setBit (0);
  2004. while (! exp.isEmpty())
  2005. {
  2006. if (exp [0])
  2007. {
  2008. multiplyBy (value);
  2009. this->modulo (modulus);
  2010. }
  2011. value.multiplyBy (value);
  2012. value.modulo (modulus);
  2013. exp.shiftBits (-1);
  2014. }
  2015. }
  2016. void BitArray::inverseModulo (const BitArray& modulus) throw()
  2017. {
  2018. const BitArray one (1);
  2019. if (modulus == one || modulus.isNegative())
  2020. {
  2021. clear();
  2022. return;
  2023. }
  2024. if (isNegative() || compareAbsolute (modulus) >= 0)
  2025. this->modulo (modulus);
  2026. if (*this == one)
  2027. return;
  2028. if (! (*this)[0])
  2029. {
  2030. // not invertible
  2031. clear();
  2032. return;
  2033. }
  2034. BitArray a1 (modulus);
  2035. BitArray a2 (*this);
  2036. BitArray b1 (modulus);
  2037. BitArray b2 (1);
  2038. while (a2 != one)
  2039. {
  2040. BitArray temp1, temp2, multiplier (a1);
  2041. multiplier.divideBy (a2, temp1);
  2042. temp1 = a2;
  2043. temp1.multiplyBy (multiplier);
  2044. temp2 = a1;
  2045. temp2.subtract (temp1);
  2046. a1 = a2;
  2047. a2 = temp2;
  2048. temp1 = b2;
  2049. temp1.multiplyBy (multiplier);
  2050. temp2 = b1;
  2051. temp2.subtract (temp1);
  2052. b1 = b2;
  2053. b2 = temp2;
  2054. }
  2055. while (b2.isNegative())
  2056. b2.add (modulus);
  2057. b2.modulo (modulus);
  2058. *this = b2;
  2059. }
  2060. void BitArray::shiftBits (int bits, const int startBit) throw()
  2061. {
  2062. if (highestBit < 0)
  2063. return;
  2064. if (startBit > 0)
  2065. {
  2066. if (bits < 0)
  2067. {
  2068. // right shift
  2069. for (int i = startBit; i <= highestBit; ++i)
  2070. setBit (i, operator[] (i - bits));
  2071. highestBit = getHighestBit();
  2072. }
  2073. else if (bits > 0)
  2074. {
  2075. // left shift
  2076. for (int i = highestBit + 1; --i >= startBit;)
  2077. setBit (i + bits, operator[] (i));
  2078. while (--bits >= 0)
  2079. clearBit (bits + startBit);
  2080. }
  2081. }
  2082. else
  2083. {
  2084. if (bits < 0)
  2085. {
  2086. // right shift
  2087. bits = -bits;
  2088. if (bits > highestBit)
  2089. {
  2090. clear();
  2091. }
  2092. else
  2093. {
  2094. const int wordsToMove = bits >> 5;
  2095. int top = 1 + (highestBit >> 5) - wordsToMove;
  2096. highestBit -= bits;
  2097. if (wordsToMove > 0)
  2098. {
  2099. int i;
  2100. for (i = 0; i < top; ++i)
  2101. values [i] = values [i + wordsToMove];
  2102. for (i = 0; i < wordsToMove; ++i)
  2103. values [top + i] = 0;
  2104. bits &= 31;
  2105. }
  2106. if (bits != 0)
  2107. {
  2108. const int invBits = 32 - bits;
  2109. --top;
  2110. for (int i = 0; i < top; ++i)
  2111. values[i] = (values[i] >> bits) | (values [i + 1] << invBits);
  2112. values[top] = (values[top] >> bits);
  2113. }
  2114. highestBit = getHighestBit();
  2115. }
  2116. }
  2117. else if (bits > 0)
  2118. {
  2119. // left shift
  2120. ensureSize (((highestBit + bits) >> 5) + 1);
  2121. const int wordsToMove = bits >> 5;
  2122. int top = 1 + (highestBit >> 5);
  2123. highestBit += bits;
  2124. if (wordsToMove > 0)
  2125. {
  2126. int i;
  2127. for (i = top; --i >= 0;)
  2128. values [i + wordsToMove] = values [i];
  2129. for (i = 0; i < wordsToMove; ++i)
  2130. values [i] = 0;
  2131. bits &= 31;
  2132. }
  2133. if (bits != 0)
  2134. {
  2135. const int invBits = 32 - bits;
  2136. for (int i = top + 1 + wordsToMove; --i > wordsToMove;)
  2137. values[i] = (values[i] << bits) | (values [i - 1] >> invBits);
  2138. values [wordsToMove] = values [wordsToMove] << bits;
  2139. }
  2140. highestBit = getHighestBit();
  2141. }
  2142. }
  2143. }
  2144. const BitArray BitArray::getBitRange (int startBit, int numBits) const throw()
  2145. {
  2146. BitArray r;
  2147. numBits = jmin (numBits, getHighestBit() + 1 - startBit);
  2148. r.ensureSize (numBits >> 5);
  2149. r.highestBit = numBits;
  2150. int i = 0;
  2151. while (numBits > 0)
  2152. {
  2153. r.values[i++] = getBitRangeAsInt (startBit, jmin (32, numBits));
  2154. numBits -= 32;
  2155. startBit += 32;
  2156. }
  2157. r.highestBit = r.getHighestBit();
  2158. return r;
  2159. }
  2160. int BitArray::getBitRangeAsInt (const int startBit, int numBits) const throw()
  2161. {
  2162. if (numBits > 32)
  2163. {
  2164. jassertfalse // use getBitRange() if you need more than 32 bits..
  2165. numBits = 32;
  2166. }
  2167. numBits = jmin (numBits, highestBit + 1 - startBit);
  2168. if (numBits <= 0)
  2169. return 0;
  2170. const int pos = startBit >> 5;
  2171. const int offset = startBit & 31;
  2172. const int endSpace = 32 - numBits;
  2173. uint32 n = ((uint32) values [pos]) >> offset;
  2174. if (offset > endSpace)
  2175. n |= ((uint32) values [pos + 1]) << (32 - offset);
  2176. return (int) (n & (((uint32) 0xffffffff) >> endSpace));
  2177. }
  2178. void BitArray::setBitRangeAsInt (const int startBit, int numBits, unsigned int valueToSet) throw()
  2179. {
  2180. if (numBits > 32)
  2181. {
  2182. jassertfalse
  2183. numBits = 32;
  2184. }
  2185. for (int i = 0; i < numBits; ++i)
  2186. {
  2187. setBit (startBit + i, (valueToSet & 1) != 0);
  2188. valueToSet >>= 1;
  2189. }
  2190. }
  2191. bool BitArray::isNegative() const throw()
  2192. {
  2193. return negative && ! isEmpty();
  2194. }
  2195. void BitArray::setNegative (const bool neg) throw()
  2196. {
  2197. negative = neg;
  2198. }
  2199. void BitArray::negate() throw()
  2200. {
  2201. negative = (! negative) && ! isEmpty();
  2202. }
  2203. int BitArray::countNumberOfSetBits() const throw()
  2204. {
  2205. int total = 0;
  2206. for (int i = (highestBit >> 5) + 1; --i >= 0;)
  2207. {
  2208. unsigned int n = values[i];
  2209. if (n == 0xffffffff)
  2210. {
  2211. total += 32;
  2212. }
  2213. else
  2214. {
  2215. while (n != 0)
  2216. {
  2217. total += (n & 1);
  2218. n >>= 1;
  2219. }
  2220. }
  2221. }
  2222. return total;
  2223. }
  2224. int BitArray::getHighestBit() const throw()
  2225. {
  2226. for (int i = highestBit + 1; --i >= 0;)
  2227. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  2228. return i;
  2229. return -1;
  2230. }
  2231. int BitArray::findNextSetBit (int i) const throw()
  2232. {
  2233. for (; i <= highestBit; ++i)
  2234. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  2235. return i;
  2236. return -1;
  2237. }
  2238. int BitArray::findNextClearBit (int i) const throw()
  2239. {
  2240. for (; i <= highestBit; ++i)
  2241. if ((values [i >> 5] & (1 << (i & 31))) == 0)
  2242. break;
  2243. return i;
  2244. }
  2245. void BitArray::ensureSize (const int numVals) throw()
  2246. {
  2247. if (numVals + 2 >= numValues)
  2248. {
  2249. int oldSize = numValues;
  2250. numValues = ((numVals + 2) * 3) / 2;
  2251. values.realloc (numValues + 1);
  2252. while (oldSize < numValues)
  2253. values [oldSize++] = 0;
  2254. }
  2255. }
  2256. const String BitArray::toString (const int base, const int minimumNumCharacters) const throw()
  2257. {
  2258. String s;
  2259. BitArray v (*this);
  2260. if (base == 2 || base == 8 || base == 16)
  2261. {
  2262. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2263. static const tchar* const hexDigits = T("0123456789abcdef");
  2264. for (;;)
  2265. {
  2266. const int remainder = v.getBitRangeAsInt (0, bits);
  2267. v.shiftBits (-bits);
  2268. if (remainder == 0 && v.isEmpty())
  2269. break;
  2270. s = String::charToString (hexDigits [remainder]) + s;
  2271. }
  2272. }
  2273. else if (base == 10)
  2274. {
  2275. const BitArray ten (10);
  2276. BitArray remainder;
  2277. for (;;)
  2278. {
  2279. v.divideBy (ten, remainder);
  2280. if (remainder.isEmpty() && v.isEmpty())
  2281. break;
  2282. s = String (remainder.getBitRangeAsInt (0, 8)) + s;
  2283. }
  2284. }
  2285. else
  2286. {
  2287. jassertfalse // can't do the specified base
  2288. return String::empty;
  2289. }
  2290. s = s.paddedLeft ('0', minimumNumCharacters);
  2291. return isNegative() ? T("-") + s : s;
  2292. }
  2293. void BitArray::parseString (const String& text,
  2294. const int base) throw()
  2295. {
  2296. clear();
  2297. const tchar* t = (const tchar*) text;
  2298. if (base == 2 || base == 8 || base == 16)
  2299. {
  2300. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2301. for (;;)
  2302. {
  2303. const tchar c = *t++;
  2304. const int digit = CharacterFunctions::getHexDigitValue (c);
  2305. if (((unsigned int) digit) < (unsigned int) base)
  2306. {
  2307. shiftBits (bits);
  2308. add (digit);
  2309. }
  2310. else if (c == 0)
  2311. {
  2312. break;
  2313. }
  2314. }
  2315. }
  2316. else if (base == 10)
  2317. {
  2318. const BitArray ten ((unsigned int) 10);
  2319. for (;;)
  2320. {
  2321. const tchar c = *t++;
  2322. if (c >= T('0') && c <= T('9'))
  2323. {
  2324. multiplyBy (ten);
  2325. add ((int) (c - T('0')));
  2326. }
  2327. else if (c == 0)
  2328. {
  2329. break;
  2330. }
  2331. }
  2332. }
  2333. setNegative (text.trimStart().startsWithChar (T('-')));
  2334. }
  2335. const MemoryBlock BitArray::toMemoryBlock() const throw()
  2336. {
  2337. const int numBytes = (getHighestBit() + 8) >> 3;
  2338. MemoryBlock mb ((size_t) numBytes);
  2339. for (int i = 0; i < numBytes; ++i)
  2340. mb[i] = (uint8) getBitRangeAsInt (i << 3, 8);
  2341. return mb;
  2342. }
  2343. void BitArray::loadFromMemoryBlock (const MemoryBlock& data) throw()
  2344. {
  2345. clear();
  2346. for (int i = (int) data.getSize(); --i >= 0;)
  2347. this->setBitRangeAsInt ((int) (i << 3), 8, data [i]);
  2348. }
  2349. END_JUCE_NAMESPACE
  2350. /*** End of inlined file: juce_BitArray.cpp ***/
  2351. /*** Start of inlined file: juce_MemoryBlock.cpp ***/
  2352. BEGIN_JUCE_NAMESPACE
  2353. MemoryBlock::MemoryBlock() throw()
  2354. : size (0)
  2355. {
  2356. }
  2357. MemoryBlock::MemoryBlock (const size_t initialSize,
  2358. const bool initialiseToZero) throw()
  2359. {
  2360. if (initialSize > 0)
  2361. {
  2362. size = initialSize;
  2363. data.allocate (initialSize, initialiseToZero);
  2364. }
  2365. else
  2366. {
  2367. size = 0;
  2368. }
  2369. }
  2370. MemoryBlock::MemoryBlock (const MemoryBlock& other) throw()
  2371. : size (other.size)
  2372. {
  2373. if (size > 0)
  2374. {
  2375. jassert (other.data != 0);
  2376. data.malloc (size);
  2377. memcpy (data, other.data, size);
  2378. }
  2379. }
  2380. MemoryBlock::MemoryBlock (const void* const dataToInitialiseFrom,
  2381. const size_t sizeInBytes) throw()
  2382. : size (jmax ((size_t) 0, sizeInBytes))
  2383. {
  2384. jassert (sizeInBytes >= 0);
  2385. if (size > 0)
  2386. {
  2387. jassert (dataToInitialiseFrom != 0); // non-zero size, but a zero pointer passed-in?
  2388. data.malloc (size);
  2389. if (dataToInitialiseFrom != 0)
  2390. memcpy (data, dataToInitialiseFrom, size);
  2391. }
  2392. }
  2393. MemoryBlock::~MemoryBlock() throw()
  2394. {
  2395. jassert (size >= 0); // should never happen
  2396. jassert (size == 0 || data != 0); // non-zero size but no data allocated?
  2397. }
  2398. MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) throw()
  2399. {
  2400. if (this != &other)
  2401. {
  2402. setSize (other.size, false);
  2403. memcpy (data, other.data, size);
  2404. }
  2405. return *this;
  2406. }
  2407. bool MemoryBlock::operator== (const MemoryBlock& other) const throw()
  2408. {
  2409. return matches (other.data, other.size);
  2410. }
  2411. bool MemoryBlock::operator!= (const MemoryBlock& other) const throw()
  2412. {
  2413. return ! operator== (other);
  2414. }
  2415. bool MemoryBlock::matches (const void* dataToCompare, size_t dataSize) const throw()
  2416. {
  2417. return size == dataSize
  2418. && memcmp (data, dataToCompare, size) == 0;
  2419. }
  2420. // this will resize the block to this size
  2421. void MemoryBlock::setSize (const size_t newSize,
  2422. const bool initialiseToZero) throw()
  2423. {
  2424. if (size != newSize)
  2425. {
  2426. if (newSize <= 0)
  2427. {
  2428. data.free();
  2429. size = 0;
  2430. }
  2431. else
  2432. {
  2433. if (data != 0)
  2434. {
  2435. data.realloc (newSize);
  2436. if (initialiseToZero && (newSize > size))
  2437. zeromem (data + size, newSize - size);
  2438. }
  2439. else
  2440. {
  2441. data.allocate (newSize, initialiseToZero);
  2442. }
  2443. size = newSize;
  2444. }
  2445. }
  2446. }
  2447. void MemoryBlock::ensureSize (const size_t minimumSize,
  2448. const bool initialiseToZero) throw()
  2449. {
  2450. if (size < minimumSize)
  2451. setSize (minimumSize, initialiseToZero);
  2452. }
  2453. void MemoryBlock::swapWith (MemoryBlock& other) throw()
  2454. {
  2455. swapVariables (size, other.size);
  2456. data.swapWith (other.data);
  2457. }
  2458. void MemoryBlock::fillWith (const uint8 value) throw()
  2459. {
  2460. memset (data, (int) value, size);
  2461. }
  2462. void MemoryBlock::append (const void* const srcData,
  2463. const size_t numBytes) throw()
  2464. {
  2465. if (numBytes > 0)
  2466. {
  2467. const size_t oldSize = size;
  2468. setSize (size + numBytes);
  2469. memcpy (data + oldSize, srcData, numBytes);
  2470. }
  2471. }
  2472. void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) throw()
  2473. {
  2474. const char* d = static_cast<const char*> (src);
  2475. if (offset < 0)
  2476. {
  2477. d -= offset;
  2478. num -= offset;
  2479. offset = 0;
  2480. }
  2481. if (offset + num > size)
  2482. num = size - offset;
  2483. if (num > 0)
  2484. memcpy (data + offset, d, num);
  2485. }
  2486. void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const throw()
  2487. {
  2488. char* d = static_cast<char*> (dst);
  2489. if (offset < 0)
  2490. {
  2491. zeromem (d, -offset);
  2492. d -= offset;
  2493. num += offset;
  2494. offset = 0;
  2495. }
  2496. if (offset + num > size)
  2497. {
  2498. const size_t newNum = size - offset;
  2499. zeromem (d + newNum, num - newNum);
  2500. num = newNum;
  2501. }
  2502. if (num > 0)
  2503. memcpy (d, data + offset, num);
  2504. }
  2505. void MemoryBlock::removeSection (size_t startByte, size_t numBytesToRemove) throw()
  2506. {
  2507. if (startByte < 0)
  2508. {
  2509. numBytesToRemove += startByte;
  2510. startByte = 0;
  2511. }
  2512. if (startByte + numBytesToRemove >= size)
  2513. {
  2514. setSize (startByte);
  2515. }
  2516. else if (numBytesToRemove > 0)
  2517. {
  2518. memmove (data + startByte,
  2519. data + startByte + numBytesToRemove,
  2520. size - (startByte + numBytesToRemove));
  2521. setSize (size - numBytesToRemove);
  2522. }
  2523. }
  2524. const String MemoryBlock::toString() const throw()
  2525. {
  2526. return String ((const char*) data, size);
  2527. }
  2528. int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const throw()
  2529. {
  2530. int res = 0;
  2531. size_t byte = bitRangeStart >> 3;
  2532. int offsetInByte = bitRangeStart & 7;
  2533. size_t bitsSoFar = 0;
  2534. while (numBits > 0 && (size_t) byte < size)
  2535. {
  2536. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2537. const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte;
  2538. res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar);
  2539. bitsSoFar += bitsThisTime;
  2540. numBits -= bitsThisTime;
  2541. ++byte;
  2542. offsetInByte = 0;
  2543. }
  2544. return res;
  2545. }
  2546. void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) throw()
  2547. {
  2548. size_t byte = bitRangeStart >> 3;
  2549. int offsetInByte = bitRangeStart & 7;
  2550. unsigned int mask = ~((((unsigned int) 0xffffffff) << (32 - numBits)) >> (32 - numBits));
  2551. while (numBits > 0 && (size_t) byte < size)
  2552. {
  2553. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2554. const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int) 0xffffffff) >> offsetInByte) << offsetInByte);
  2555. const unsigned int tempBits = bitsToSet << offsetInByte;
  2556. data[byte] = (char) ((data[byte] & tempMask) | tempBits);
  2557. ++byte;
  2558. numBits -= bitsThisTime;
  2559. bitsToSet >>= bitsThisTime;
  2560. mask >>= bitsThisTime;
  2561. offsetInByte = 0;
  2562. }
  2563. }
  2564. void MemoryBlock::loadFromHexString (const String& hex) throw()
  2565. {
  2566. ensureSize (hex.length() >> 1);
  2567. char* dest = data;
  2568. int i = 0;
  2569. for (;;)
  2570. {
  2571. int byte = 0;
  2572. for (int loop = 2; --loop >= 0;)
  2573. {
  2574. byte <<= 4;
  2575. for (;;)
  2576. {
  2577. const juce_wchar c = hex [i++];
  2578. if (c >= T('0') && c <= T('9'))
  2579. {
  2580. byte |= c - T('0');
  2581. break;
  2582. }
  2583. else if (c >= T('a') && c <= T('z'))
  2584. {
  2585. byte |= c - (T('a') - 10);
  2586. break;
  2587. }
  2588. else if (c >= T('A') && c <= T('Z'))
  2589. {
  2590. byte |= c - (T('A') - 10);
  2591. break;
  2592. }
  2593. else if (c == 0)
  2594. {
  2595. setSize (static_cast <size_t> (dest - data));
  2596. return;
  2597. }
  2598. }
  2599. }
  2600. *dest++ = (char) byte;
  2601. }
  2602. }
  2603. static const char* const encodingTable
  2604. = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
  2605. const String MemoryBlock::toBase64Encoding() const throw()
  2606. {
  2607. const size_t numChars = ((size << 3) + 5) / 6;
  2608. String destString ((unsigned int) size); // store the length, followed by a '.', and then the data.
  2609. const int initialLen = destString.length();
  2610. destString.preallocateStorage (initialLen + 2 + numChars);
  2611. tchar* d = const_cast <tchar*> (((const tchar*) destString) + initialLen);
  2612. *d++ = T('.');
  2613. for (size_t i = 0; i < numChars; ++i)
  2614. *d++ = encodingTable [getBitRange (i * 6, 6)];
  2615. *d++ = 0;
  2616. return destString;
  2617. }
  2618. bool MemoryBlock::fromBase64Encoding (const String& s) throw()
  2619. {
  2620. const int startPos = s.indexOfChar (T('.')) + 1;
  2621. if (startPos <= 0)
  2622. return false;
  2623. const int numBytesNeeded = s.substring (0, startPos - 1).getIntValue();
  2624. setSize (numBytesNeeded, true);
  2625. const int numChars = s.length() - startPos;
  2626. const tchar* const srcChars = ((const tchar*) s) + startPos;
  2627. int pos = 0;
  2628. for (int i = 0; i < numChars; ++i)
  2629. {
  2630. const char c = (char) srcChars[i];
  2631. for (int j = 0; j < 64; ++j)
  2632. {
  2633. if (encodingTable[j] == c)
  2634. {
  2635. setBitRange (pos, 6, j);
  2636. pos += 6;
  2637. break;
  2638. }
  2639. }
  2640. }
  2641. return true;
  2642. }
  2643. END_JUCE_NAMESPACE
  2644. /*** End of inlined file: juce_MemoryBlock.cpp ***/
  2645. /*** Start of inlined file: juce_PropertySet.cpp ***/
  2646. BEGIN_JUCE_NAMESPACE
  2647. PropertySet::PropertySet (const bool ignoreCaseOfKeyNames) throw()
  2648. : properties (ignoreCaseOfKeyNames),
  2649. fallbackProperties (0),
  2650. ignoreCaseOfKeys (ignoreCaseOfKeyNames)
  2651. {
  2652. }
  2653. PropertySet::PropertySet (const PropertySet& other) throw()
  2654. : properties (other.properties),
  2655. fallbackProperties (other.fallbackProperties),
  2656. ignoreCaseOfKeys (other.ignoreCaseOfKeys)
  2657. {
  2658. }
  2659. PropertySet& PropertySet::operator= (const PropertySet& other) throw()
  2660. {
  2661. properties = other.properties;
  2662. fallbackProperties = other.fallbackProperties;
  2663. ignoreCaseOfKeys = other.ignoreCaseOfKeys;
  2664. propertyChanged();
  2665. return *this;
  2666. }
  2667. PropertySet::~PropertySet()
  2668. {
  2669. }
  2670. void PropertySet::clear()
  2671. {
  2672. const ScopedLock sl (lock);
  2673. if (properties.size() > 0)
  2674. {
  2675. properties.clear();
  2676. propertyChanged();
  2677. }
  2678. }
  2679. const String PropertySet::getValue (const String& keyName,
  2680. const String& defaultValue) const throw()
  2681. {
  2682. const ScopedLock sl (lock);
  2683. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2684. if (index >= 0)
  2685. return properties.getAllValues() [index];
  2686. return fallbackProperties != 0 ? fallbackProperties->getValue (keyName, defaultValue)
  2687. : defaultValue;
  2688. }
  2689. int PropertySet::getIntValue (const String& keyName,
  2690. const int defaultValue) const throw()
  2691. {
  2692. const ScopedLock sl (lock);
  2693. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2694. if (index >= 0)
  2695. return properties.getAllValues() [index].getIntValue();
  2696. return fallbackProperties != 0 ? fallbackProperties->getIntValue (keyName, defaultValue)
  2697. : defaultValue;
  2698. }
  2699. double PropertySet::getDoubleValue (const String& keyName,
  2700. const double defaultValue) const throw()
  2701. {
  2702. const ScopedLock sl (lock);
  2703. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2704. if (index >= 0)
  2705. return properties.getAllValues()[index].getDoubleValue();
  2706. return fallbackProperties != 0 ? fallbackProperties->getDoubleValue (keyName, defaultValue)
  2707. : defaultValue;
  2708. }
  2709. bool PropertySet::getBoolValue (const String& keyName,
  2710. const bool defaultValue) const throw()
  2711. {
  2712. const ScopedLock sl (lock);
  2713. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2714. if (index >= 0)
  2715. return properties.getAllValues() [index].getIntValue() != 0;
  2716. return fallbackProperties != 0 ? fallbackProperties->getBoolValue (keyName, defaultValue)
  2717. : defaultValue;
  2718. }
  2719. XmlElement* PropertySet::getXmlValue (const String& keyName) const
  2720. {
  2721. XmlDocument doc (getValue (keyName));
  2722. return doc.getDocumentElement();
  2723. }
  2724. void PropertySet::setValue (const String& keyName,
  2725. const String& value) throw()
  2726. {
  2727. jassert (keyName.isNotEmpty()); // shouldn't use an empty key name!
  2728. if (keyName.isNotEmpty())
  2729. {
  2730. const ScopedLock sl (lock);
  2731. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2732. if (index < 0 || properties.getAllValues() [index] != value)
  2733. {
  2734. properties.set (keyName, value);
  2735. propertyChanged();
  2736. }
  2737. }
  2738. }
  2739. void PropertySet::removeValue (const String& keyName) throw()
  2740. {
  2741. if (keyName.isNotEmpty())
  2742. {
  2743. const ScopedLock sl (lock);
  2744. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2745. if (index >= 0)
  2746. {
  2747. properties.remove (keyName);
  2748. propertyChanged();
  2749. }
  2750. }
  2751. }
  2752. void PropertySet::setValue (const String& keyName, const tchar* const value) throw()
  2753. {
  2754. setValue (keyName, String (value));
  2755. }
  2756. void PropertySet::setValue (const String& keyName, const int value) throw()
  2757. {
  2758. setValue (keyName, String (value));
  2759. }
  2760. void PropertySet::setValue (const String& keyName, const double value) throw()
  2761. {
  2762. setValue (keyName, String (value));
  2763. }
  2764. void PropertySet::setValue (const String& keyName, const bool value) throw()
  2765. {
  2766. setValue (keyName, String ((value) ? T("1") : T("0")));
  2767. }
  2768. void PropertySet::setValue (const String& keyName, const XmlElement* const xml)
  2769. {
  2770. setValue (keyName, (xml == 0) ? String::empty
  2771. : xml->createDocument (String::empty, true));
  2772. }
  2773. bool PropertySet::containsKey (const String& keyName) const throw()
  2774. {
  2775. const ScopedLock sl (lock);
  2776. return properties.getAllKeys().contains (keyName, ignoreCaseOfKeys);
  2777. }
  2778. void PropertySet::setFallbackPropertySet (PropertySet* fallbackProperties_) throw()
  2779. {
  2780. const ScopedLock sl (lock);
  2781. fallbackProperties = fallbackProperties_;
  2782. }
  2783. XmlElement* PropertySet::createXml (const String& nodeName) const throw()
  2784. {
  2785. const ScopedLock sl (lock);
  2786. XmlElement* const xml = new XmlElement (nodeName);
  2787. for (int i = 0; i < properties.getAllKeys().size(); ++i)
  2788. {
  2789. XmlElement* const e = xml->createNewChildElement ("VALUE");
  2790. e->setAttribute (T("name"), properties.getAllKeys()[i]);
  2791. e->setAttribute (T("val"), properties.getAllValues()[i]);
  2792. }
  2793. return xml;
  2794. }
  2795. void PropertySet::restoreFromXml (const XmlElement& xml) throw()
  2796. {
  2797. const ScopedLock sl (lock);
  2798. clear();
  2799. forEachXmlChildElementWithTagName (xml, e, T("VALUE"))
  2800. {
  2801. if (e->hasAttribute (T("name"))
  2802. && e->hasAttribute (T("val")))
  2803. {
  2804. properties.set (e->getStringAttribute (T("name")),
  2805. e->getStringAttribute (T("val")));
  2806. }
  2807. }
  2808. if (properties.size() > 0)
  2809. propertyChanged();
  2810. }
  2811. void PropertySet::propertyChanged()
  2812. {
  2813. }
  2814. END_JUCE_NAMESPACE
  2815. /*** End of inlined file: juce_PropertySet.cpp ***/
  2816. /*** Start of inlined file: juce_Variant.cpp ***/
  2817. BEGIN_JUCE_NAMESPACE
  2818. var::var() throw()
  2819. : type (voidType)
  2820. {
  2821. value.doubleValue = 0;
  2822. }
  2823. var::~var() throw()
  2824. {
  2825. if (type == stringType)
  2826. delete value.stringValue;
  2827. else if (type == objectType && value.objectValue != 0)
  2828. value.objectValue->decReferenceCount();
  2829. }
  2830. const var var::null;
  2831. var::var (const var& valueToCopy)
  2832. : type (valueToCopy.type),
  2833. value (valueToCopy.value)
  2834. {
  2835. if (type == stringType)
  2836. value.stringValue = new String (*(value.stringValue));
  2837. else if (type == objectType && value.objectValue != 0)
  2838. value.objectValue->incReferenceCount();
  2839. }
  2840. var::var (const int value_) throw()
  2841. : type (intType)
  2842. {
  2843. value.intValue = value_;
  2844. }
  2845. var::var (const bool value_) throw()
  2846. : type (boolType)
  2847. {
  2848. value.boolValue = value_;
  2849. }
  2850. var::var (const double value_) throw()
  2851. : type (doubleType)
  2852. {
  2853. value.doubleValue = value_;
  2854. }
  2855. var::var (const String& value_)
  2856. : type (stringType)
  2857. {
  2858. value.stringValue = new String (value_);
  2859. }
  2860. var::var (const char* const value_)
  2861. : type (stringType)
  2862. {
  2863. value.stringValue = new String (value_);
  2864. }
  2865. var::var (const juce_wchar* const value_)
  2866. : type (stringType)
  2867. {
  2868. value.stringValue = new String (value_);
  2869. }
  2870. var::var (DynamicObject* const object)
  2871. : type (objectType)
  2872. {
  2873. value.objectValue = object;
  2874. if (object != 0)
  2875. object->incReferenceCount();
  2876. }
  2877. var::var (MethodFunction method_) throw()
  2878. : type (methodType)
  2879. {
  2880. value.methodValue = method_;
  2881. }
  2882. void var::swapWith (var& other) throw()
  2883. {
  2884. swapVariables (type, other.type);
  2885. swapVariables (value, other.value);
  2886. }
  2887. var& var::operator= (const var& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2888. var& var::operator= (int value_) { var newValue (value_); swapWith (newValue); return *this; }
  2889. var& var::operator= (bool value_) { var newValue (value_); swapWith (newValue); return *this; }
  2890. var& var::operator= (double value_) { var newValue (value_); swapWith (newValue); return *this; }
  2891. var& var::operator= (const char* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2892. var& var::operator= (const juce_wchar* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2893. var& var::operator= (const String& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2894. var& var::operator= (DynamicObject* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2895. var& var::operator= (MethodFunction value_) { var newValue (value_); swapWith (newValue); return *this; }
  2896. var::operator int() const
  2897. {
  2898. switch (type)
  2899. {
  2900. case voidType: break;
  2901. case intType: return value.intValue;
  2902. case boolType: return value.boolValue ? 1 : 0;
  2903. case doubleType: return static_cast <int> (value.doubleValue);
  2904. case stringType: return value.stringValue->getIntValue();
  2905. case objectType: break;
  2906. default: jassertfalse; break;
  2907. }
  2908. return 0;
  2909. }
  2910. var::operator bool() const
  2911. {
  2912. switch (type)
  2913. {
  2914. case voidType: break;
  2915. case intType: return value.intValue != 0;
  2916. case boolType: return value.boolValue;
  2917. case doubleType: return value.doubleValue != 0;
  2918. case stringType: return value.stringValue->getIntValue() != 0
  2919. || value.stringValue->trim().equalsIgnoreCase (T("true"))
  2920. || value.stringValue->trim().equalsIgnoreCase (T("yes"));
  2921. case objectType: return value.objectValue != 0;
  2922. default: jassertfalse; break;
  2923. }
  2924. return false;
  2925. }
  2926. var::operator float() const
  2927. {
  2928. return (float) operator double();
  2929. }
  2930. var::operator double() const
  2931. {
  2932. switch (type)
  2933. {
  2934. case voidType: break;
  2935. case intType: return value.intValue;
  2936. case boolType: return value.boolValue ? 1.0 : 0.0;
  2937. case doubleType: return value.doubleValue;
  2938. case stringType: return value.stringValue->getDoubleValue();
  2939. case objectType: break;
  2940. default: jassertfalse; break;
  2941. }
  2942. return 0.0;
  2943. }
  2944. const String var::toString() const
  2945. {
  2946. switch (type)
  2947. {
  2948. case voidType: return String::empty;
  2949. case intType: return String (value.intValue);
  2950. case boolType: return value.boolValue ? T("1") : T("0");
  2951. case doubleType: return String (value.doubleValue);
  2952. case stringType: return *(value.stringValue);
  2953. case objectType: return "Object 0x" + String::toHexString ((int) (pointer_sized_int) value.objectValue);
  2954. case methodType: return "Method";
  2955. default: jassertfalse; break;
  2956. }
  2957. return String::empty;
  2958. }
  2959. var::operator const String() const
  2960. {
  2961. return toString();
  2962. }
  2963. DynamicObject* var::getObject() const
  2964. {
  2965. return type == objectType ? value.objectValue : 0;
  2966. }
  2967. bool var::equals (const var& other) const throw()
  2968. {
  2969. switch (type)
  2970. {
  2971. case voidType: return other.isVoid();
  2972. case intType: return value.intValue == static_cast <int> (other);
  2973. case boolType: return value.boolValue == static_cast <bool> (other);
  2974. case doubleType: return value.doubleValue == static_cast <double> (other);
  2975. case stringType: return (*(value.stringValue)) == other.toString();
  2976. case objectType: return value.objectValue == other.getObject();
  2977. case methodType: return value.methodValue == other.value.methodValue && other.isMethod();
  2978. default: jassertfalse; break;
  2979. }
  2980. return false;
  2981. }
  2982. bool operator== (const var& v1, const var& v2) throw() { return v1.equals (v2); }
  2983. bool operator!= (const var& v1, const var& v2) throw() { return ! v1.equals (v2); }
  2984. bool operator== (const var& v1, const String& v2) throw() { return v1.toString() == v2; }
  2985. bool operator!= (const var& v1, const String& v2) throw() { return v1.toString() != v2; }
  2986. void var::writeToStream (OutputStream& output) const
  2987. {
  2988. switch (type)
  2989. {
  2990. case voidType: output.writeCompressedInt (0); break;
  2991. case intType: output.writeCompressedInt (5); output.writeByte (1); output.writeInt (value.intValue); break;
  2992. case boolType: output.writeCompressedInt (1); output.writeByte (value.boolValue ? 2 : 3); break;
  2993. case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break;
  2994. case stringType:
  2995. {
  2996. const int len = value.stringValue->getNumBytesAsUTF8() + 1;
  2997. output.writeCompressedInt (len + 1);
  2998. output.writeByte (5);
  2999. HeapBlock<char> temp (len);
  3000. value.stringValue->copyToUTF8 (temp, len);
  3001. output.write (temp, len);
  3002. break;
  3003. }
  3004. case objectType:
  3005. case methodType: output.writeCompressedInt (0); jassertfalse; break; // Can't write an object to a stream!
  3006. default: jassertfalse; break; // Is this a corrupted object?
  3007. }
  3008. }
  3009. const var var::readFromStream (InputStream& input)
  3010. {
  3011. const int numBytes = input.readCompressedInt();
  3012. if (numBytes > 0)
  3013. {
  3014. switch (input.readByte())
  3015. {
  3016. case 1: return var (input.readInt());
  3017. case 2: return var (true);
  3018. case 3: return var (false);
  3019. case 4: return var (input.readDouble());
  3020. case 5:
  3021. {
  3022. MemoryBlock mb;
  3023. input.readIntoMemoryBlock (mb, numBytes - 1);
  3024. return var (String::fromUTF8 ((const char*) mb.getData(), (int) mb.getSize()));
  3025. }
  3026. default: input.skipNextBytes (numBytes - 1); break;
  3027. }
  3028. }
  3029. return var::null;
  3030. }
  3031. const var var::operator[] (const var::identifier& propertyName) const
  3032. {
  3033. if (type == objectType && value.objectValue != 0)
  3034. return value.objectValue->getProperty (propertyName);
  3035. return var::null;
  3036. }
  3037. const var var::invoke (const var::identifier& method, const var* arguments, int numArguments) const
  3038. {
  3039. if (type == objectType && value.objectValue != 0)
  3040. return value.objectValue->invokeMethod (method, arguments, numArguments);
  3041. return var::null;
  3042. }
  3043. const var var::invoke (const var& targetObject, const var* arguments, int numArguments) const
  3044. {
  3045. if (isMethod())
  3046. {
  3047. DynamicObject* const target = targetObject.getObject();
  3048. if (target != 0)
  3049. return (target->*(value.methodValue)) (arguments, numArguments);
  3050. }
  3051. return var::null;
  3052. }
  3053. const var var::call (const var::identifier& method) const
  3054. {
  3055. return invoke (method, 0, 0);
  3056. }
  3057. const var var::call (const var::identifier& method, const var& arg1) const
  3058. {
  3059. return invoke (method, &arg1, 1);
  3060. }
  3061. const var var::call (const var::identifier& method, const var& arg1, const var& arg2) const
  3062. {
  3063. var args[] = { arg1, arg2 };
  3064. return invoke (method, args, 2);
  3065. }
  3066. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3)
  3067. {
  3068. var args[] = { arg1, arg2, arg3 };
  3069. return invoke (method, args, 3);
  3070. }
  3071. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
  3072. {
  3073. var args[] = { arg1, arg2, arg3, arg4 };
  3074. return invoke (method, args, 4);
  3075. }
  3076. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
  3077. {
  3078. var args[] = { arg1, arg2, arg3, arg4, arg5 };
  3079. return invoke (method, args, 5);
  3080. }
  3081. var::identifier::identifier() throw()
  3082. : hashCode (0)
  3083. {
  3084. }
  3085. var::identifier::identifier (const String& name_)
  3086. : name (name_),
  3087. hashCode (name_.hashCode())
  3088. {
  3089. /* An identifier string must be suitable for use as a script variable or XML
  3090. attribute, so it can only contain this limited set of characters.. */
  3091. jassert (name.containsOnly (T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) && name.isNotEmpty());
  3092. }
  3093. var::identifier::identifier (const char* const name_)
  3094. : name (name_),
  3095. hashCode (name.hashCode())
  3096. {
  3097. /* An identifier string must be suitable for use as a script variable or XML
  3098. attribute, so it can only contain this limited set of characters.. */
  3099. jassert (name.containsOnly (T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) && name.isNotEmpty());
  3100. }
  3101. var::identifier::~identifier()
  3102. {
  3103. }
  3104. END_JUCE_NAMESPACE
  3105. /*** End of inlined file: juce_Variant.cpp ***/
  3106. /*** Start of inlined file: juce_NamedValueSet.cpp ***/
  3107. BEGIN_JUCE_NAMESPACE
  3108. NamedValueSet::NamedValue::NamedValue() throw()
  3109. {
  3110. }
  3111. inline NamedValueSet::NamedValue::NamedValue (const var::identifier& name_, const var& value_)
  3112. : name (name_), value (value_)
  3113. {
  3114. }
  3115. NamedValueSet::NamedValueSet() throw()
  3116. {
  3117. }
  3118. NamedValueSet::NamedValueSet (const NamedValueSet& other)
  3119. : values (other.values)
  3120. {
  3121. }
  3122. NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other)
  3123. {
  3124. values = other.values;
  3125. return *this;
  3126. }
  3127. NamedValueSet::~NamedValueSet()
  3128. {
  3129. }
  3130. int NamedValueSet::size() const throw()
  3131. {
  3132. return values.size();
  3133. }
  3134. const var& NamedValueSet::operator[] (const var::identifier& name) const
  3135. {
  3136. for (int i = values.size(); --i >= 0;)
  3137. {
  3138. const NamedValue& v = values.getReference(i);
  3139. if (v.name == name)
  3140. return v.value;
  3141. }
  3142. return var::null;
  3143. }
  3144. const var NamedValueSet::getWithDefault (const var::identifier& name, const var& defaultReturnValue) const
  3145. {
  3146. const var* v = getItem (name);
  3147. return v != 0 ? *v : defaultReturnValue;
  3148. }
  3149. var* NamedValueSet::getItem (const var::identifier& name) const
  3150. {
  3151. for (int i = values.size(); --i >= 0;)
  3152. {
  3153. NamedValue& v = values.getReference(i);
  3154. if (v.name == name)
  3155. return &(v.value);
  3156. }
  3157. return 0;
  3158. }
  3159. bool NamedValueSet::set (const var::identifier& name, const var& newValue)
  3160. {
  3161. for (int i = values.size(); --i >= 0;)
  3162. {
  3163. NamedValue& v = values.getReference(i);
  3164. if (v.name == name)
  3165. {
  3166. if (v.value == newValue)
  3167. return false;
  3168. v.value = newValue;
  3169. return true;
  3170. }
  3171. }
  3172. values.add (NamedValue (name, newValue));
  3173. return true;
  3174. }
  3175. bool NamedValueSet::contains (const var::identifier& name) const
  3176. {
  3177. return getItem (name) != 0;
  3178. }
  3179. bool NamedValueSet::remove (const var::identifier& name)
  3180. {
  3181. for (int i = values.size(); --i >= 0;)
  3182. {
  3183. if (values.getReference(i).name == name)
  3184. {
  3185. values.remove (i);
  3186. return true;
  3187. }
  3188. }
  3189. return false;
  3190. }
  3191. const var::identifier NamedValueSet::getName (int index) const
  3192. {
  3193. jassert (((unsigned int) index) < (unsigned int) values.size());
  3194. return values [index].name;
  3195. }
  3196. void NamedValueSet::clear()
  3197. {
  3198. values.clear();
  3199. }
  3200. END_JUCE_NAMESPACE
  3201. /*** End of inlined file: juce_NamedValueSet.cpp ***/
  3202. /*** Start of inlined file: juce_DynamicObject.cpp ***/
  3203. BEGIN_JUCE_NAMESPACE
  3204. DynamicObject::DynamicObject()
  3205. {
  3206. }
  3207. DynamicObject::~DynamicObject()
  3208. {
  3209. }
  3210. bool DynamicObject::hasProperty (const var::identifier& propertyName) const
  3211. {
  3212. var* const v = properties.getItem (propertyName);
  3213. return v != 0 && ! v->isMethod();
  3214. }
  3215. const var DynamicObject::getProperty (const var::identifier& propertyName) const
  3216. {
  3217. return properties [propertyName];
  3218. }
  3219. void DynamicObject::setProperty (const var::identifier& propertyName, const var& newValue)
  3220. {
  3221. properties.set (propertyName, newValue);
  3222. }
  3223. void DynamicObject::removeProperty (const var::identifier& propertyName)
  3224. {
  3225. properties.remove (propertyName);
  3226. }
  3227. bool DynamicObject::hasMethod (const var::identifier& methodName) const
  3228. {
  3229. return getProperty (methodName).isMethod();
  3230. }
  3231. const var DynamicObject::invokeMethod (const var::identifier& methodName,
  3232. const var* parameters,
  3233. int numParameters)
  3234. {
  3235. return properties [methodName].invoke (var (this), parameters, numParameters);
  3236. }
  3237. void DynamicObject::setMethod (const var::identifier& name,
  3238. var::MethodFunction methodFunction)
  3239. {
  3240. properties.set (name, var (methodFunction));
  3241. }
  3242. void DynamicObject::clear()
  3243. {
  3244. properties.clear();
  3245. }
  3246. END_JUCE_NAMESPACE
  3247. /*** End of inlined file: juce_DynamicObject.cpp ***/
  3248. /*** Start of inlined file: juce_BlowFish.cpp ***/
  3249. BEGIN_JUCE_NAMESPACE
  3250. static const uint32 initialPValues [18] =
  3251. {
  3252. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
  3253. 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  3254. 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
  3255. 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  3256. 0x9216d5d9, 0x8979fb1b
  3257. };
  3258. static const uint32 initialSValues [4 * 256] =
  3259. {
  3260. 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
  3261. 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
  3262. 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
  3263. 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
  3264. 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
  3265. 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  3266. 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
  3267. 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
  3268. 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
  3269. 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
  3270. 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
  3271. 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  3272. 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
  3273. 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
  3274. 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
  3275. 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
  3276. 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
  3277. 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  3278. 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
  3279. 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
  3280. 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
  3281. 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
  3282. 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
  3283. 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  3284. 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
  3285. 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
  3286. 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
  3287. 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
  3288. 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
  3289. 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  3290. 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
  3291. 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
  3292. 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
  3293. 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
  3294. 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
  3295. 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  3296. 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
  3297. 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
  3298. 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
  3299. 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
  3300. 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
  3301. 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  3302. 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
  3303. 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
  3304. 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
  3305. 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
  3306. 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
  3307. 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  3308. 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
  3309. 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
  3310. 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
  3311. 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
  3312. 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
  3313. 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  3314. 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
  3315. 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
  3316. 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
  3317. 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
  3318. 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
  3319. 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  3320. 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
  3321. 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
  3322. 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
  3323. 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  3324. 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
  3325. 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
  3326. 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
  3327. 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
  3328. 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
  3329. 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  3330. 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
  3331. 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
  3332. 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
  3333. 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
  3334. 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
  3335. 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  3336. 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
  3337. 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
  3338. 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
  3339. 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
  3340. 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
  3341. 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  3342. 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
  3343. 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
  3344. 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
  3345. 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
  3346. 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
  3347. 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  3348. 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
  3349. 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
  3350. 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
  3351. 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
  3352. 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
  3353. 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  3354. 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
  3355. 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
  3356. 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
  3357. 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
  3358. 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
  3359. 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  3360. 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
  3361. 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
  3362. 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
  3363. 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
  3364. 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
  3365. 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  3366. 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
  3367. 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
  3368. 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
  3369. 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
  3370. 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
  3371. 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  3372. 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
  3373. 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
  3374. 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
  3375. 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
  3376. 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
  3377. 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  3378. 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
  3379. 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
  3380. 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
  3381. 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
  3382. 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
  3383. 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  3384. 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
  3385. 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
  3386. 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
  3387. 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  3388. 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
  3389. 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
  3390. 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
  3391. 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
  3392. 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
  3393. 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  3394. 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
  3395. 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
  3396. 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
  3397. 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
  3398. 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
  3399. 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  3400. 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
  3401. 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
  3402. 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
  3403. 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
  3404. 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
  3405. 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  3406. 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
  3407. 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
  3408. 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
  3409. 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
  3410. 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
  3411. 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  3412. 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
  3413. 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
  3414. 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
  3415. 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
  3416. 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
  3417. 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  3418. 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
  3419. 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
  3420. 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
  3421. 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
  3422. 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
  3423. 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  3424. 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
  3425. 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
  3426. 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
  3427. 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
  3428. 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
  3429. 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  3430. 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
  3431. 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
  3432. 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
  3433. 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
  3434. 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
  3435. 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  3436. 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
  3437. 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
  3438. 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
  3439. 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
  3440. 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
  3441. 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  3442. 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
  3443. 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
  3444. 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
  3445. 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
  3446. 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
  3447. 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  3448. 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
  3449. 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
  3450. 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
  3451. 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  3452. 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
  3453. 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
  3454. 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
  3455. 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
  3456. 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
  3457. 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  3458. 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
  3459. 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
  3460. 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
  3461. 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
  3462. 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
  3463. 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  3464. 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
  3465. 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
  3466. 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
  3467. 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
  3468. 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
  3469. 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  3470. 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
  3471. 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
  3472. 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
  3473. 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
  3474. 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
  3475. 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  3476. 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
  3477. 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
  3478. 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
  3479. 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
  3480. 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
  3481. 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  3482. 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
  3483. 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
  3484. 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
  3485. 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
  3486. 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
  3487. 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  3488. 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
  3489. 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
  3490. 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
  3491. 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
  3492. 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
  3493. 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  3494. 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
  3495. 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
  3496. 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
  3497. 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
  3498. 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
  3499. 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  3500. 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
  3501. 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
  3502. 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
  3503. 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
  3504. 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
  3505. 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  3506. 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
  3507. 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
  3508. 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
  3509. 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
  3510. 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
  3511. 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  3512. 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
  3513. 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
  3514. 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
  3515. 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
  3516. };
  3517. BlowFish::BlowFish (const uint8* keyData, int keyBytes)
  3518. {
  3519. memcpy (p, initialPValues, sizeof (p));
  3520. int i, j;
  3521. for (i = 4; --i >= 0;)
  3522. {
  3523. s[i].malloc (256);
  3524. memcpy (s[i], initialSValues + i * 256, 256 * sizeof (uint32));
  3525. }
  3526. j = 0;
  3527. for (i = 0; i < 18; ++i)
  3528. {
  3529. uint32 d = 0;
  3530. for (int k = 0; k < 4; ++k)
  3531. {
  3532. d = (d << 8) | keyData[j];
  3533. if (++j >= keyBytes)
  3534. j = 0;
  3535. }
  3536. p[i] = initialPValues[i] ^ d;
  3537. }
  3538. uint32 l = 0, r = 0;
  3539. for (i = 0; i < 18; i += 2)
  3540. {
  3541. encrypt (l, r);
  3542. p[i] = l;
  3543. p[i + 1] = r;
  3544. }
  3545. for (i = 0; i < 4; ++i)
  3546. {
  3547. for (j = 0; j < 256; j += 2)
  3548. {
  3549. encrypt (l, r);
  3550. s[i][j] = l;
  3551. s[i][j + 1] = r;
  3552. }
  3553. }
  3554. }
  3555. BlowFish::BlowFish (const BlowFish& other)
  3556. {
  3557. for (int i = 4; --i >= 0;)
  3558. s[i].malloc (256);
  3559. operator= (other);
  3560. }
  3561. BlowFish& BlowFish::operator= (const BlowFish& other)
  3562. {
  3563. memcpy (p, other.p, sizeof (p));
  3564. for (int i = 4; --i >= 0;)
  3565. memcpy (s[i], other.s[i], 256 * sizeof (uint32));
  3566. return *this;
  3567. }
  3568. BlowFish::~BlowFish()
  3569. {
  3570. }
  3571. uint32 BlowFish::F (uint32 x) const
  3572. {
  3573. uint16 a, b, c, d;
  3574. uint32 y;
  3575. d = (uint16) (x & 0xff);
  3576. x >>= 8;
  3577. c = (uint16) (x & 0xff);
  3578. x >>= 8;
  3579. b = (uint16) (x & 0xff);
  3580. x >>= 8;
  3581. a = (uint16) (x & 0xff);
  3582. y = s[0][a] + s[1][b];
  3583. y = y ^ s[2][c];
  3584. y = y + s[3][d];
  3585. return y;
  3586. }
  3587. void BlowFish::encrypt (uint32& data1,
  3588. uint32& data2) const
  3589. {
  3590. uint32 l = data1;
  3591. uint32 r = data2;
  3592. for (int i = 0; i < 16; ++i)
  3593. {
  3594. l = l ^ p[i];
  3595. r = F (l) ^ r;
  3596. const uint32 temp = l;
  3597. l = r;
  3598. r = temp;
  3599. }
  3600. const uint32 temp = l;
  3601. l = r;
  3602. r = temp;
  3603. r = r ^ p[16];
  3604. l = l ^ p[17];
  3605. data1 = l;
  3606. data2 = r;
  3607. }
  3608. void BlowFish::decrypt (uint32& data1,
  3609. uint32& data2) const
  3610. {
  3611. uint32 l = data1;
  3612. uint32 r = data2;
  3613. for (int i = 17; i > 1; --i)
  3614. {
  3615. l =l ^ p[i];
  3616. r = F (l) ^ r;
  3617. const uint32 temp = l;
  3618. l = r;
  3619. r = temp;
  3620. }
  3621. const uint32 temp = l;
  3622. l = r;
  3623. r = temp;
  3624. r = r ^ p[1];
  3625. l = l ^ p[0];
  3626. data1 = l;
  3627. data2 = r;
  3628. }
  3629. END_JUCE_NAMESPACE
  3630. /*** End of inlined file: juce_BlowFish.cpp ***/
  3631. /*** Start of inlined file: juce_MD5.cpp ***/
  3632. BEGIN_JUCE_NAMESPACE
  3633. MD5::MD5()
  3634. {
  3635. zerostruct (result);
  3636. }
  3637. MD5::MD5 (const MD5& other)
  3638. {
  3639. memcpy (result, other.result, sizeof (result));
  3640. }
  3641. MD5& MD5::operator= (const MD5& other)
  3642. {
  3643. memcpy (result, other.result, sizeof (result));
  3644. return *this;
  3645. }
  3646. MD5::MD5 (const MemoryBlock& data)
  3647. {
  3648. ProcessContext context;
  3649. context.processBlock ((const uint8*) data.getData(), data.getSize());
  3650. context.finish (result);
  3651. }
  3652. MD5::MD5 (const char* data, const size_t numBytes)
  3653. {
  3654. ProcessContext context;
  3655. context.processBlock ((const uint8*) data, numBytes);
  3656. context.finish (result);
  3657. }
  3658. MD5::MD5 (const String& text)
  3659. {
  3660. ProcessContext context;
  3661. const int len = text.length();
  3662. const juce_wchar* const t = text;
  3663. for (int i = 0; i < len; ++i)
  3664. {
  3665. // force the string into integer-sized unicode characters, to try to make it
  3666. // get the same results on all platforms + compilers.
  3667. uint32 unicodeChar = (uint32) t[i];
  3668. ByteOrder::swapIfBigEndian (unicodeChar);
  3669. context.processBlock ((const uint8*) &unicodeChar,
  3670. sizeof (unicodeChar));
  3671. }
  3672. context.finish (result);
  3673. }
  3674. void MD5::processStream (InputStream& input, int64 numBytesToRead)
  3675. {
  3676. ProcessContext context;
  3677. if (numBytesToRead < 0)
  3678. numBytesToRead = std::numeric_limits<int64>::max();
  3679. while (numBytesToRead > 0)
  3680. {
  3681. char tempBuffer [512];
  3682. const int bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
  3683. if (bytesRead <= 0)
  3684. break;
  3685. numBytesToRead -= bytesRead;
  3686. context.processBlock ((const uint8*) tempBuffer, bytesRead);
  3687. }
  3688. context.finish (result);
  3689. }
  3690. MD5::MD5 (InputStream& input, int64 numBytesToRead)
  3691. {
  3692. processStream (input, numBytesToRead);
  3693. }
  3694. MD5::MD5 (const File& file)
  3695. {
  3696. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  3697. if (fin != 0)
  3698. processStream (*fin, -1);
  3699. else
  3700. zerostruct (result);
  3701. }
  3702. MD5::~MD5()
  3703. {
  3704. }
  3705. namespace MD5Functions
  3706. {
  3707. static void encode (uint8* const output, const uint32* const input, const int numBytes) throw()
  3708. {
  3709. uint32* const o = (uint32*) output;
  3710. for (int i = 0; i < (numBytes >> 2); ++i)
  3711. o[i] = ByteOrder::swapIfBigEndian (input [i]);
  3712. }
  3713. static void decode (uint32* const output, const uint8* const input, const int numBytes) throw()
  3714. {
  3715. for (int i = 0; i < (numBytes >> 2); ++i)
  3716. output[i] = ByteOrder::littleEndianInt ((const char*) input + (i << 2));
  3717. }
  3718. static inline uint32 F (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & y) | (~x & z); }
  3719. static inline uint32 G (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & z) | (y & ~z); }
  3720. static inline uint32 H (const uint32 x, const uint32 y, const uint32 z) throw() { return x ^ y ^ z; }
  3721. static inline uint32 I (const uint32 x, const uint32 y, const uint32 z) throw() { return y ^ (x | ~z); }
  3722. static inline uint32 rotateLeft (const uint32 x, const uint32 n) throw() { return (x << n) | (x >> (32 - n)); }
  3723. static void FF (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3724. {
  3725. a += F (b, c, d) + x + ac;
  3726. a = rotateLeft (a, s) + b;
  3727. }
  3728. static void GG (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3729. {
  3730. a += G (b, c, d) + x + ac;
  3731. a = rotateLeft (a, s) + b;
  3732. }
  3733. static void HH (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3734. {
  3735. a += H (b, c, d) + x + ac;
  3736. a = rotateLeft (a, s) + b;
  3737. }
  3738. static void II (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3739. {
  3740. a += I (b, c, d) + x + ac;
  3741. a = rotateLeft (a, s) + b;
  3742. }
  3743. }
  3744. MD5::ProcessContext::ProcessContext()
  3745. {
  3746. state[0] = 0x67452301;
  3747. state[1] = 0xefcdab89;
  3748. state[2] = 0x98badcfe;
  3749. state[3] = 0x10325476;
  3750. count[0] = 0;
  3751. count[1] = 0;
  3752. }
  3753. void MD5::ProcessContext::processBlock (const uint8* const data, size_t dataSize)
  3754. {
  3755. int bufferPos = ((count[0] >> 3) & 0x3F);
  3756. count[0] += (uint32) (dataSize << 3);
  3757. if (count[0] < ((uint32) dataSize << 3))
  3758. count[1]++;
  3759. count[1] += (uint32) (dataSize >> 29);
  3760. const size_t spaceLeft = 64 - bufferPos;
  3761. size_t i = 0;
  3762. if (dataSize >= spaceLeft)
  3763. {
  3764. memcpy (buffer + bufferPos, data, spaceLeft);
  3765. transform (buffer);
  3766. i = spaceLeft;
  3767. while (i + 64 <= dataSize)
  3768. {
  3769. transform (data + i);
  3770. i += 64;
  3771. }
  3772. bufferPos = 0;
  3773. }
  3774. memcpy (buffer + bufferPos, data + i, dataSize - i);
  3775. }
  3776. void MD5::ProcessContext::finish (uint8* const result)
  3777. {
  3778. unsigned char encodedLength[8];
  3779. MD5Functions::encode (encodedLength, count, 8);
  3780. // Pad out to 56 mod 64.
  3781. const int index = (uint32) ((count[0] >> 3) & 0x3f);
  3782. const int paddingLength = (index < 56) ? (56 - index)
  3783. : (120 - index);
  3784. uint8 paddingBuffer [64];
  3785. zeromem (paddingBuffer, paddingLength);
  3786. paddingBuffer [0] = 0x80;
  3787. processBlock (paddingBuffer, paddingLength);
  3788. processBlock (encodedLength, 8);
  3789. MD5Functions::encode (result, state, sizeof (result));
  3790. zerostruct (buffer);
  3791. }
  3792. void MD5::ProcessContext::transform (const uint8* const bufferToTransform)
  3793. {
  3794. using namespace MD5Functions;
  3795. uint32 a = state[0];
  3796. uint32 b = state[1];
  3797. uint32 c = state[2];
  3798. uint32 d = state[3];
  3799. uint32 x[16];
  3800. decode (x, bufferToTransform, 64);
  3801. enum Constants
  3802. {
  3803. S11 = 7, S12 = 12, S13 = 17, S14 = 22, S21 = 5, S22 = 9, S23 = 14, S24 = 20,
  3804. S31 = 4, S32 = 11, S33 = 16, S34 = 23, S41 = 6, S42 = 10, S43 = 15, S44 = 21
  3805. };
  3806. FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  3807. FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  3808. FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  3809. FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  3810. FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  3811. FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  3812. FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  3813. FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  3814. FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  3815. FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  3816. FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  3817. FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  3818. FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  3819. FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  3820. FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  3821. FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  3822. GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  3823. GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  3824. GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  3825. GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  3826. GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  3827. GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
  3828. GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  3829. GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  3830. GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  3831. GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  3832. GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  3833. GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  3834. GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  3835. GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  3836. GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  3837. GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  3838. HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  3839. HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  3840. HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  3841. HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  3842. HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  3843. HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  3844. HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  3845. HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  3846. HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  3847. HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  3848. HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  3849. HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
  3850. HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  3851. HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  3852. HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  3853. HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  3854. II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  3855. II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  3856. II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  3857. II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  3858. II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  3859. II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  3860. II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  3861. II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  3862. II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  3863. II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  3864. II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  3865. II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  3866. II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  3867. II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  3868. II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  3869. II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  3870. state[0] += a;
  3871. state[1] += b;
  3872. state[2] += c;
  3873. state[3] += d;
  3874. zerostruct (x);
  3875. }
  3876. const MemoryBlock MD5::getRawChecksumData() const
  3877. {
  3878. return MemoryBlock (result, sizeof (result));
  3879. }
  3880. const String MD5::toHexString() const
  3881. {
  3882. return String::toHexString (result, sizeof (result), 0);
  3883. }
  3884. bool MD5::operator== (const MD5& other) const
  3885. {
  3886. return memcmp (result, other.result, sizeof (result)) == 0;
  3887. }
  3888. bool MD5::operator!= (const MD5& other) const
  3889. {
  3890. return ! operator== (other);
  3891. }
  3892. END_JUCE_NAMESPACE
  3893. /*** End of inlined file: juce_MD5.cpp ***/
  3894. /*** Start of inlined file: juce_Primes.cpp ***/
  3895. BEGIN_JUCE_NAMESPACE
  3896. namespace PrimesHelpers
  3897. {
  3898. static void createSmallSieve (const int numBits, BitArray& result) throw()
  3899. {
  3900. result.setBit (numBits);
  3901. result.clearBit (numBits); // to enlarge the array
  3902. result.setBit (0);
  3903. int n = 2;
  3904. do
  3905. {
  3906. for (int i = n + n; i < numBits; i += n)
  3907. result.setBit (i);
  3908. n = result.findNextClearBit (n + 1);
  3909. }
  3910. while (n <= (numBits >> 1));
  3911. }
  3912. static void bigSieve (const BitArray& base,
  3913. const int numBits,
  3914. BitArray& result,
  3915. const BitArray& smallSieve,
  3916. const int smallSieveSize) throw()
  3917. {
  3918. jassert (! base[0]); // must be even!
  3919. result.setBit (numBits);
  3920. result.clearBit (numBits); // to enlarge the array
  3921. int index = smallSieve.findNextClearBit (0);
  3922. do
  3923. {
  3924. const int prime = (index << 1) + 1;
  3925. BitArray r (base);
  3926. BitArray remainder;
  3927. r.divideBy (prime, remainder);
  3928. int i = prime - remainder.getBitRangeAsInt (0, 32);
  3929. if (r.isEmpty())
  3930. i += prime;
  3931. if ((i & 1) == 0)
  3932. i += prime;
  3933. i = (i - 1) >> 1;
  3934. while (i < numBits)
  3935. {
  3936. result.setBit (i);
  3937. i += prime;
  3938. }
  3939. index = smallSieve.findNextClearBit (index + 1);
  3940. }
  3941. while (index < smallSieveSize);
  3942. }
  3943. static bool findCandidate (const BitArray& base,
  3944. const BitArray& sieve,
  3945. const int numBits,
  3946. BitArray& result,
  3947. const int certainty) throw()
  3948. {
  3949. for (int i = 0; i < numBits; ++i)
  3950. {
  3951. if (! sieve[i])
  3952. {
  3953. result = base;
  3954. result.add (BitArray ((unsigned int) ((i << 1) + 1)));
  3955. if (Primes::isProbablyPrime (result, certainty))
  3956. return true;
  3957. }
  3958. }
  3959. return false;
  3960. }
  3961. }
  3962. const BitArray Primes::createProbablePrime (const int bitLength,
  3963. const int certainty,
  3964. const int* randomSeeds,
  3965. int numRandomSeeds) throw()
  3966. {
  3967. using namespace PrimesHelpers;
  3968. int defaultSeeds [16];
  3969. if (numRandomSeeds <= 0)
  3970. {
  3971. randomSeeds = defaultSeeds;
  3972. numRandomSeeds = numElementsInArray (defaultSeeds);
  3973. Random r (0);
  3974. for (int j = 10; --j >= 0;)
  3975. {
  3976. r.setSeedRandomly();
  3977. for (int i = numRandomSeeds; --i >= 0;)
  3978. defaultSeeds[i] ^= r.nextInt() ^ Random::getSystemRandom().nextInt();
  3979. }
  3980. }
  3981. BitArray smallSieve;
  3982. const int smallSieveSize = 15000;
  3983. createSmallSieve (smallSieveSize, smallSieve);
  3984. BitArray p;
  3985. for (int i = numRandomSeeds; --i >= 0;)
  3986. {
  3987. BitArray p2;
  3988. Random r (randomSeeds[i]);
  3989. r.fillBitsRandomly (p2, 0, bitLength);
  3990. p.xorWith (p2);
  3991. }
  3992. p.setBit (bitLength - 1);
  3993. p.clearBit (0);
  3994. const int searchLen = jmax (1024, (bitLength / 20) * 64);
  3995. while (p.getHighestBit() < bitLength)
  3996. {
  3997. p.add (2 * searchLen);
  3998. BitArray sieve;
  3999. bigSieve (p, searchLen, sieve,
  4000. smallSieve, smallSieveSize);
  4001. BitArray candidate;
  4002. if (findCandidate (p, sieve, searchLen, candidate, certainty))
  4003. return candidate;
  4004. }
  4005. jassertfalse
  4006. return BitArray();
  4007. }
  4008. static bool passesMillerRabin (const BitArray& n, int iterations) throw()
  4009. {
  4010. using namespace PrimesHelpers;
  4011. const BitArray one (1);
  4012. const BitArray two (2);
  4013. BitArray nMinusOne (n);
  4014. nMinusOne.subtract (one);
  4015. BitArray d (nMinusOne);
  4016. const int s = d.findNextSetBit (0);
  4017. d.shiftBits (-s);
  4018. BitArray smallPrimes;
  4019. int numBitsInSmallPrimes = 0;
  4020. for (;;)
  4021. {
  4022. numBitsInSmallPrimes += 256;
  4023. createSmallSieve (numBitsInSmallPrimes, smallPrimes);
  4024. const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits();
  4025. if (numPrimesFound > iterations + 1)
  4026. break;
  4027. }
  4028. int smallPrime = 2;
  4029. while (--iterations >= 0)
  4030. {
  4031. smallPrime = smallPrimes.findNextClearBit (smallPrime + 1);
  4032. BitArray r (smallPrime);
  4033. //r.createRandomNumber (nMinusOne);
  4034. r.exponentModulo (d, n);
  4035. if (! (r == one || r == nMinusOne))
  4036. {
  4037. for (int j = 0; j < s; ++j)
  4038. {
  4039. r.exponentModulo (two, n);
  4040. if (r == nMinusOne)
  4041. break;
  4042. }
  4043. if (r != nMinusOne)
  4044. return false;
  4045. }
  4046. }
  4047. return true;
  4048. }
  4049. bool Primes::isProbablyPrime (const BitArray& number,
  4050. const int certainty) throw()
  4051. {
  4052. if (! number[0])
  4053. return false;
  4054. if (number.getHighestBit() <= 10)
  4055. {
  4056. const int num = number.getBitRangeAsInt (0, 10);
  4057. for (int i = num / 2; --i > 1;)
  4058. if (num % i == 0)
  4059. return false;
  4060. return true;
  4061. }
  4062. else
  4063. {
  4064. const BitArray screen (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23);
  4065. if (number.findGreatestCommonDivisor (screen) != BitArray (1))
  4066. return false;
  4067. return passesMillerRabin (number, certainty);
  4068. }
  4069. }
  4070. END_JUCE_NAMESPACE
  4071. /*** End of inlined file: juce_Primes.cpp ***/
  4072. /*** Start of inlined file: juce_RSAKey.cpp ***/
  4073. BEGIN_JUCE_NAMESPACE
  4074. RSAKey::RSAKey() throw()
  4075. {
  4076. }
  4077. RSAKey::RSAKey (const String& s) throw()
  4078. {
  4079. if (s.containsChar (T(',')))
  4080. {
  4081. part1.parseString (s.upToFirstOccurrenceOf (T(","), false, false), 16);
  4082. part2.parseString (s.fromFirstOccurrenceOf (T(","), false, false), 16);
  4083. }
  4084. else
  4085. {
  4086. // the string needs to be two hex numbers, comma-separated..
  4087. jassertfalse;
  4088. }
  4089. }
  4090. RSAKey::~RSAKey() throw()
  4091. {
  4092. }
  4093. const String RSAKey::toString() const throw()
  4094. {
  4095. return part1.toString (16) + T(",") + part2.toString (16);
  4096. }
  4097. bool RSAKey::applyToValue (BitArray& value) const throw()
  4098. {
  4099. if (part1.isEmpty() || part2.isEmpty()
  4100. || value.compare (0) <= 0)
  4101. {
  4102. jassertfalse // using an uninitialised key
  4103. value.clear();
  4104. return false;
  4105. }
  4106. BitArray result;
  4107. while (! value.isEmpty())
  4108. {
  4109. result.multiplyBy (part2);
  4110. BitArray remainder;
  4111. value.divideBy (part2, remainder);
  4112. remainder.exponentModulo (part1, part2);
  4113. result.add (remainder);
  4114. }
  4115. value = result;
  4116. return true;
  4117. }
  4118. static const BitArray findBestCommonDivisor (const BitArray& p,
  4119. const BitArray& q) throw()
  4120. {
  4121. const BitArray one (1);
  4122. // try 3, 5, 9, 17, etc first because these only contain 2 bits and so
  4123. // are fast to divide + multiply
  4124. for (int i = 2; i <= 65536; i *= 2)
  4125. {
  4126. const BitArray e (1 + i);
  4127. if (e.findGreatestCommonDivisor (p) == one
  4128. && e.findGreatestCommonDivisor (q) == one)
  4129. {
  4130. return e;
  4131. }
  4132. }
  4133. BitArray e (4);
  4134. while (! (e.findGreatestCommonDivisor (p) == one
  4135. && e.findGreatestCommonDivisor (q) == one))
  4136. {
  4137. e.add (one);
  4138. }
  4139. return e;
  4140. }
  4141. void RSAKey::createKeyPair (RSAKey& publicKey,
  4142. RSAKey& privateKey,
  4143. const int numBits,
  4144. const int* randomSeeds,
  4145. const int numRandomSeeds) throw()
  4146. {
  4147. jassert (numBits > 16); // not much point using less than this..
  4148. BitArray p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds));
  4149. BitArray q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds, numRandomSeeds));
  4150. BitArray n (p);
  4151. n.multiplyBy (q); // n = pq
  4152. const BitArray one (1);
  4153. p.subtract (one);
  4154. q.subtract (one);
  4155. BitArray m (p);
  4156. m.multiplyBy (q); // m = (p - 1)(q - 1)
  4157. const BitArray e (findBestCommonDivisor (p, q));
  4158. BitArray d (e);
  4159. d.inverseModulo (m);
  4160. publicKey.part1 = e;
  4161. publicKey.part2 = n;
  4162. privateKey.part1 = d;
  4163. privateKey.part2 = n;
  4164. }
  4165. END_JUCE_NAMESPACE
  4166. /*** End of inlined file: juce_RSAKey.cpp ***/
  4167. /*** Start of inlined file: juce_InputStream.cpp ***/
  4168. BEGIN_JUCE_NAMESPACE
  4169. char InputStream::readByte()
  4170. {
  4171. char temp = 0;
  4172. read (&temp, 1);
  4173. return temp;
  4174. }
  4175. bool InputStream::readBool()
  4176. {
  4177. return readByte() != 0;
  4178. }
  4179. short InputStream::readShort()
  4180. {
  4181. char temp [2];
  4182. if (read (temp, 2) == 2)
  4183. return (short) ByteOrder::littleEndianShort (temp);
  4184. else
  4185. return 0;
  4186. }
  4187. short InputStream::readShortBigEndian()
  4188. {
  4189. char temp [2];
  4190. if (read (temp, 2) == 2)
  4191. return (short) ByteOrder::bigEndianShort (temp);
  4192. else
  4193. return 0;
  4194. }
  4195. int InputStream::readInt()
  4196. {
  4197. char temp [4];
  4198. if (read (temp, 4) == 4)
  4199. return (int) ByteOrder::littleEndianInt (temp);
  4200. else
  4201. return 0;
  4202. }
  4203. int InputStream::readIntBigEndian()
  4204. {
  4205. char temp [4];
  4206. if (read (temp, 4) == 4)
  4207. return (int) ByteOrder::bigEndianInt (temp);
  4208. else
  4209. return 0;
  4210. }
  4211. int InputStream::readCompressedInt()
  4212. {
  4213. const unsigned char sizeByte = readByte();
  4214. if (sizeByte == 0)
  4215. return 0;
  4216. const int numBytes = (sizeByte & 0x7f);
  4217. if (numBytes > 4)
  4218. {
  4219. jassertfalse // trying to read corrupt data - this method must only be used
  4220. // to read data that was written by OutputStream::writeCompressedInt()
  4221. return 0;
  4222. }
  4223. char bytes[4] = { 0, 0, 0, 0 };
  4224. if (read (bytes, numBytes) != numBytes)
  4225. return 0;
  4226. const int num = (int) ByteOrder::littleEndianInt (bytes);
  4227. return (sizeByte >> 7) ? -num : num;
  4228. }
  4229. int64 InputStream::readInt64()
  4230. {
  4231. char temp [8];
  4232. if (read (temp, 8) == 8)
  4233. return (int64) ByteOrder::swapIfBigEndian (*(uint64*) temp);
  4234. else
  4235. return 0;
  4236. }
  4237. int64 InputStream::readInt64BigEndian()
  4238. {
  4239. char temp [8];
  4240. if (read (temp, 8) == 8)
  4241. return (int64) ByteOrder::swapIfLittleEndian (*(uint64*) temp);
  4242. else
  4243. return 0;
  4244. }
  4245. float InputStream::readFloat()
  4246. {
  4247. union { int asInt; float asFloat; } n;
  4248. n.asInt = readInt();
  4249. return n.asFloat;
  4250. }
  4251. float InputStream::readFloatBigEndian()
  4252. {
  4253. union { int asInt; float asFloat; } n;
  4254. n.asInt = readIntBigEndian();
  4255. return n.asFloat;
  4256. }
  4257. double InputStream::readDouble()
  4258. {
  4259. union { int64 asInt; double asDouble; } n;
  4260. n.asInt = readInt64();
  4261. return n.asDouble;
  4262. }
  4263. double InputStream::readDoubleBigEndian()
  4264. {
  4265. union { int64 asInt; double asDouble; } n;
  4266. n.asInt = readInt64BigEndian();
  4267. return n.asDouble;
  4268. }
  4269. const String InputStream::readString()
  4270. {
  4271. MemoryBlock buffer (256);
  4272. char* data = (char*) buffer.getData();
  4273. size_t i = 0;
  4274. while ((data[i] = readByte()) != 0)
  4275. {
  4276. if (++i >= buffer.getSize())
  4277. {
  4278. buffer.setSize (buffer.getSize() + 512);
  4279. data = (char*) buffer.getData();
  4280. }
  4281. }
  4282. return String::fromUTF8 (data, (int) i);
  4283. }
  4284. const String InputStream::readNextLine()
  4285. {
  4286. MemoryBlock buffer (256);
  4287. char* data = (char*) buffer.getData();
  4288. size_t i = 0;
  4289. while ((data[i] = readByte()) != 0)
  4290. {
  4291. if (data[i] == '\n')
  4292. break;
  4293. if (data[i] == '\r')
  4294. {
  4295. const int64 lastPos = getPosition();
  4296. if (readByte() != '\n')
  4297. setPosition (lastPos);
  4298. break;
  4299. }
  4300. if (++i >= buffer.getSize())
  4301. {
  4302. buffer.setSize (buffer.getSize() + 512);
  4303. data = (char*) buffer.getData();
  4304. }
  4305. }
  4306. return String::fromUTF8 (data, (int) i);
  4307. }
  4308. int InputStream::readIntoMemoryBlock (MemoryBlock& block,
  4309. int numBytes)
  4310. {
  4311. const int64 totalLength = getTotalLength();
  4312. if (totalLength >= 0)
  4313. {
  4314. const int totalBytesRemaining = (int) jmin ((int64) 0x7fffffff,
  4315. totalLength - getPosition());
  4316. if (numBytes < 0)
  4317. numBytes = totalBytesRemaining;
  4318. else if (numBytes > 0)
  4319. numBytes = jmin (numBytes, totalBytesRemaining);
  4320. else
  4321. return 0;
  4322. }
  4323. const size_t originalBlockSize = block.getSize();
  4324. int totalBytesRead = 0;
  4325. if (numBytes > 0)
  4326. {
  4327. // know how many bytes we want, so we can resize the block first..
  4328. block.setSize (originalBlockSize + numBytes, false);
  4329. totalBytesRead = read (((char*) block.getData()) + originalBlockSize, numBytes);
  4330. }
  4331. else
  4332. {
  4333. // read until end of stram..
  4334. const int chunkSize = 32768;
  4335. for (;;)
  4336. {
  4337. block.ensureSize (originalBlockSize + totalBytesRead + chunkSize, false);
  4338. const int bytesJustIn = read (((char*) block.getData())
  4339. + originalBlockSize
  4340. + totalBytesRead,
  4341. chunkSize);
  4342. if (bytesJustIn == 0)
  4343. break;
  4344. totalBytesRead += bytesJustIn;
  4345. }
  4346. }
  4347. // trim off any excess left at the end
  4348. block.setSize (originalBlockSize + totalBytesRead, false);
  4349. return totalBytesRead;
  4350. }
  4351. const String InputStream::readEntireStreamAsString()
  4352. {
  4353. MemoryBlock mb;
  4354. const int size = readIntoMemoryBlock (mb);
  4355. return String::createStringFromData ((const char*) mb.getData(), size);
  4356. }
  4357. void InputStream::skipNextBytes (int64 numBytesToSkip)
  4358. {
  4359. if (numBytesToSkip > 0)
  4360. {
  4361. const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384);
  4362. HeapBlock <char> temp (skipBufferSize);
  4363. while (numBytesToSkip > 0 && ! isExhausted())
  4364. numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize));
  4365. }
  4366. }
  4367. END_JUCE_NAMESPACE
  4368. /*** End of inlined file: juce_InputStream.cpp ***/
  4369. /*** Start of inlined file: juce_OutputStream.cpp ***/
  4370. BEGIN_JUCE_NAMESPACE
  4371. #if JUCE_DEBUG
  4372. static CriticalSection activeStreamLock;
  4373. static VoidArray activeStreams;
  4374. void juce_CheckForDanglingStreams()
  4375. {
  4376. /*
  4377. It's always a bad idea to leak any object, but if you're leaking output
  4378. streams, then there's a good chance that you're failing to flush a file
  4379. to disk properly, which could result in corrupted data and other similar
  4380. nastiness..
  4381. */
  4382. jassert (activeStreams.size() == 0);
  4383. };
  4384. #endif
  4385. OutputStream::OutputStream()
  4386. {
  4387. #if JUCE_DEBUG
  4388. const ScopedLock sl (activeStreamLock);
  4389. activeStreams.add (this);
  4390. #endif
  4391. }
  4392. OutputStream::~OutputStream()
  4393. {
  4394. #if JUCE_DEBUG
  4395. const ScopedLock sl (activeStreamLock);
  4396. activeStreams.removeValue (this);
  4397. #endif
  4398. }
  4399. void OutputStream::writeBool (bool b)
  4400. {
  4401. writeByte ((b) ? (char) 1
  4402. : (char) 0);
  4403. }
  4404. void OutputStream::writeByte (char byte)
  4405. {
  4406. write (&byte, 1);
  4407. }
  4408. void OutputStream::writeShort (short value)
  4409. {
  4410. const unsigned short v = ByteOrder::swapIfBigEndian ((unsigned short) value);
  4411. write (&v, 2);
  4412. }
  4413. void OutputStream::writeShortBigEndian (short value)
  4414. {
  4415. const unsigned short v = ByteOrder::swapIfLittleEndian ((unsigned short) value);
  4416. write (&v, 2);
  4417. }
  4418. void OutputStream::writeInt (int value)
  4419. {
  4420. const unsigned int v = ByteOrder::swapIfBigEndian ((unsigned int) value);
  4421. write (&v, 4);
  4422. }
  4423. void OutputStream::writeIntBigEndian (int value)
  4424. {
  4425. const unsigned int v = ByteOrder::swapIfLittleEndian ((unsigned int) value);
  4426. write (&v, 4);
  4427. }
  4428. void OutputStream::writeCompressedInt (int value)
  4429. {
  4430. unsigned int un = (value < 0) ? (unsigned int) -value
  4431. : (unsigned int) value;
  4432. uint8 data[5];
  4433. int num = 0;
  4434. while (un > 0)
  4435. {
  4436. data[++num] = (uint8) un;
  4437. un >>= 8;
  4438. }
  4439. data[0] = (uint8) num;
  4440. if (value < 0)
  4441. data[0] |= 0x80;
  4442. write (data, num + 1);
  4443. }
  4444. void OutputStream::writeInt64 (int64 value)
  4445. {
  4446. const uint64 v = ByteOrder::swapIfBigEndian ((uint64) value);
  4447. write (&v, 8);
  4448. }
  4449. void OutputStream::writeInt64BigEndian (int64 value)
  4450. {
  4451. const uint64 v = ByteOrder::swapIfLittleEndian ((uint64) value);
  4452. write (&v, 8);
  4453. }
  4454. void OutputStream::writeFloat (float value)
  4455. {
  4456. union { int asInt; float asFloat; } n;
  4457. n.asFloat = value;
  4458. writeInt (n.asInt);
  4459. }
  4460. void OutputStream::writeFloatBigEndian (float value)
  4461. {
  4462. union { int asInt; float asFloat; } n;
  4463. n.asFloat = value;
  4464. writeIntBigEndian (n.asInt);
  4465. }
  4466. void OutputStream::writeDouble (double value)
  4467. {
  4468. union { int64 asInt; double asDouble; } n;
  4469. n.asDouble = value;
  4470. writeInt64 (n.asInt);
  4471. }
  4472. void OutputStream::writeDoubleBigEndian (double value)
  4473. {
  4474. union { int64 asInt; double asDouble; } n;
  4475. n.asDouble = value;
  4476. writeInt64BigEndian (n.asInt);
  4477. }
  4478. void OutputStream::writeString (const String& text)
  4479. {
  4480. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  4481. // if lots of large, persistent strings were to be written to streams).
  4482. const int numBytes = text.getNumBytesAsUTF8() + 1;
  4483. HeapBlock<char> temp (numBytes);
  4484. text.copyToUTF8 (temp, numBytes);
  4485. write (temp, numBytes);
  4486. }
  4487. void OutputStream::writeText (const String& text, const bool asUnicode,
  4488. const bool writeUnicodeHeaderBytes)
  4489. {
  4490. if (asUnicode)
  4491. {
  4492. if (writeUnicodeHeaderBytes)
  4493. write ("\x0ff\x0fe", 2);
  4494. const juce_wchar* src = (const juce_wchar*) text;
  4495. bool lastCharWasReturn = false;
  4496. while (*src != 0)
  4497. {
  4498. if (*src == L'\n' && ! lastCharWasReturn)
  4499. writeShort ((short) L'\r');
  4500. lastCharWasReturn = (*src == L'\r');
  4501. writeShort ((short) *src++);
  4502. }
  4503. }
  4504. else
  4505. {
  4506. const char* src = text.toUTF8();
  4507. const char* t = src;
  4508. for (;;)
  4509. {
  4510. if (*t == '\n')
  4511. {
  4512. if (t > src)
  4513. write (src, (int) (t - src));
  4514. write ("\r\n", 2);
  4515. src = t + 1;
  4516. }
  4517. else if (*t == '\r')
  4518. {
  4519. if (t[1] == '\n')
  4520. ++t;
  4521. }
  4522. else if (*t == 0)
  4523. {
  4524. if (t > src)
  4525. write (src, (int) (t - src));
  4526. break;
  4527. }
  4528. ++t;
  4529. }
  4530. }
  4531. }
  4532. int OutputStream::writeFromInputStream (InputStream& source, int numBytesToWrite)
  4533. {
  4534. if (numBytesToWrite < 0)
  4535. numBytesToWrite = 0x7fffffff;
  4536. int numWritten = 0;
  4537. while (numBytesToWrite > 0 && ! source.isExhausted())
  4538. {
  4539. char buffer [8192];
  4540. const int num = source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer)));
  4541. if (num == 0)
  4542. break;
  4543. write (buffer, num);
  4544. numBytesToWrite -= num;
  4545. numWritten += num;
  4546. }
  4547. return numWritten;
  4548. }
  4549. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const int number)
  4550. {
  4551. return stream << String (number);
  4552. }
  4553. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const double number)
  4554. {
  4555. return stream << String (number);
  4556. }
  4557. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char character)
  4558. {
  4559. stream.writeByte (character);
  4560. return stream;
  4561. }
  4562. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char* const text)
  4563. {
  4564. stream.write (text, (int) strlen (text));
  4565. return stream;
  4566. }
  4567. END_JUCE_NAMESPACE
  4568. /*** End of inlined file: juce_OutputStream.cpp ***/
  4569. /*** Start of inlined file: juce_DirectoryIterator.cpp ***/
  4570. BEGIN_JUCE_NAMESPACE
  4571. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4572. bool* isDirectory, bool* isHidden, int64* fileSize,
  4573. Time* modTime, Time* creationTime, bool* isReadOnly);
  4574. bool juce_findFileNext (void* handle, String& resultFile,
  4575. bool* isDirectory, bool* isHidden, int64* fileSize,
  4576. Time* modTime, Time* creationTime, bool* isReadOnly);
  4577. void juce_findFileClose (void* handle);
  4578. DirectoryIterator::DirectoryIterator (const File& directory,
  4579. bool isRecursive,
  4580. const String& wc,
  4581. const int whatToLookFor_)
  4582. : wildCard (wc),
  4583. index (-1),
  4584. whatToLookFor (whatToLookFor_)
  4585. {
  4586. // you have to specify the type of files you're looking for!
  4587. jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
  4588. jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
  4589. String path (directory.getFullPathName());
  4590. if (! path.endsWithChar (File::separator))
  4591. path += File::separator;
  4592. String filename;
  4593. bool isDirectory, isHidden;
  4594. void* const handle = juce_findFileStart (path,
  4595. isRecursive ? T("*") : wc,
  4596. filename, &isDirectory, &isHidden, 0, 0, 0, 0);
  4597. if (handle != 0)
  4598. {
  4599. do
  4600. {
  4601. if (! filename.containsOnly (T(".")))
  4602. {
  4603. bool addToList = false;
  4604. if (isDirectory)
  4605. {
  4606. if (isRecursive
  4607. && ((whatToLookFor_ & File::ignoreHiddenFiles) == 0
  4608. || ! isHidden))
  4609. {
  4610. dirsFound.add (File (path + filename, 0));
  4611. }
  4612. addToList = (whatToLookFor_ & File::findDirectories) != 0;
  4613. }
  4614. else
  4615. {
  4616. addToList = (whatToLookFor_ & File::findFiles) != 0;
  4617. }
  4618. // if it's recursive, we're not relying on the OS iterator
  4619. // to do the wildcard match, so do it now..
  4620. if (isRecursive && addToList)
  4621. addToList = filename.matchesWildcard (wc, true);
  4622. if (addToList && (whatToLookFor_ & File::ignoreHiddenFiles) != 0)
  4623. addToList = ! isHidden;
  4624. if (addToList)
  4625. filesFound.add (File (path + filename, 0));
  4626. }
  4627. } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0));
  4628. juce_findFileClose (handle);
  4629. }
  4630. }
  4631. DirectoryIterator::~DirectoryIterator()
  4632. {
  4633. }
  4634. bool DirectoryIterator::next()
  4635. {
  4636. if (subIterator != 0)
  4637. {
  4638. if (subIterator->next())
  4639. return true;
  4640. subIterator = 0;
  4641. }
  4642. if (index >= filesFound.size() + dirsFound.size() - 1)
  4643. return false;
  4644. ++index;
  4645. if (index >= filesFound.size())
  4646. {
  4647. subIterator = new DirectoryIterator (dirsFound.getReference (index - filesFound.size()),
  4648. true, wildCard, whatToLookFor);
  4649. return next();
  4650. }
  4651. return true;
  4652. }
  4653. const File DirectoryIterator::getFile() const
  4654. {
  4655. if (subIterator != 0)
  4656. return subIterator->getFile();
  4657. return filesFound [index];
  4658. }
  4659. float DirectoryIterator::getEstimatedProgress() const
  4660. {
  4661. if (filesFound.size() + dirsFound.size() == 0)
  4662. {
  4663. return 0.0f;
  4664. }
  4665. else
  4666. {
  4667. const float detailedIndex = (subIterator != 0) ? index + subIterator->getEstimatedProgress()
  4668. : (float) index;
  4669. return detailedIndex / (filesFound.size() + dirsFound.size());
  4670. }
  4671. }
  4672. END_JUCE_NAMESPACE
  4673. /*** End of inlined file: juce_DirectoryIterator.cpp ***/
  4674. /*** Start of inlined file: juce_File.cpp ***/
  4675. #ifdef _MSC_VER
  4676. #pragma warning (disable: 4514)
  4677. #pragma warning (push)
  4678. #endif
  4679. #if ! JUCE_WINDOWS
  4680. #include <pwd.h>
  4681. #endif
  4682. BEGIN_JUCE_NAMESPACE
  4683. #ifdef _MSC_VER
  4684. #pragma warning (pop)
  4685. #endif
  4686. void* juce_fileOpen (const String& path, bool forWriting);
  4687. void juce_fileClose (void* handle);
  4688. int juce_fileWrite (void* handle, const void* buffer, int size);
  4689. int64 juce_fileGetPosition (void* handle);
  4690. int64 juce_fileSetPosition (void* handle, int64 pos);
  4691. void juce_fileFlush (void* handle);
  4692. bool juce_fileExists (const String& fileName, const bool dontCountDirectories);
  4693. bool juce_isDirectory (const String& fileName);
  4694. int64 juce_getFileSize (const String& fileName);
  4695. bool juce_canWriteToFile (const String& fileName);
  4696. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly);
  4697. void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime);
  4698. bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime);
  4699. bool juce_deleteFile (const String& fileName);
  4700. bool juce_copyFile (const String& source, const String& dest);
  4701. bool juce_moveFile (const String& source, const String& dest);
  4702. // this must also create all paths involved in the directory.
  4703. void juce_createDirectory (const String& fileName);
  4704. bool juce_launchFile (const String& fileName, const String& parameters);
  4705. const StringArray juce_getFileSystemRoots();
  4706. const String juce_getVolumeLabel (const String& filenameOnVolume, int& volumeSerialNumber);
  4707. // starts a directory search operation with a wildcard, returning a handle for
  4708. // use in calls to juce_findFileNext.
  4709. // juce_firstResultFile gets the name of the file (not the whole pathname) and
  4710. // the other pointers, if non-null, are set based on the properties of the file.
  4711. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4712. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  4713. Time* creationTime, bool* isReadOnly);
  4714. // returns false when no more files are found
  4715. bool juce_findFileNext (void* handle, String& resultFile,
  4716. bool* isDirectory, bool* isHidden, int64* fileSize,
  4717. Time* modTime, Time* creationTime, bool* isReadOnly);
  4718. void juce_findFileClose (void* handle);
  4719. static const String juce_addTrailingSeparator (const String& path)
  4720. {
  4721. return path.endsWithChar (File::separator) ? path
  4722. : path + File::separator;
  4723. }
  4724. static const String parseAbsolutePath (String path)
  4725. {
  4726. if (path.isEmpty())
  4727. return String::empty;
  4728. #if JUCE_WINDOWS
  4729. // Windows..
  4730. path = path.replaceCharacter (T('/'), T('\\'));
  4731. if (path.startsWithChar (File::separator))
  4732. {
  4733. if (path[1] != File::separator)
  4734. {
  4735. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4736. If you're trying to parse a string that may be either a relative path or an absolute path,
  4737. you MUST provide a context against which the partial path can be evaluated - you can do
  4738. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4739. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4740. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4741. */
  4742. jassertfalse
  4743. path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
  4744. }
  4745. }
  4746. else if (path.indexOfChar (T(':')) < 0)
  4747. {
  4748. if (path.isEmpty())
  4749. return String::empty;
  4750. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4751. If you're trying to parse a string that may be either a relative path or an absolute path,
  4752. you MUST provide a context against which the partial path can be evaluated - you can do
  4753. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4754. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4755. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4756. */
  4757. jassertfalse
  4758. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4759. }
  4760. #else
  4761. // Mac or Linux..
  4762. path = path.replaceCharacter (T('\\'), T('/'));
  4763. if (path.startsWithChar (T('~')))
  4764. {
  4765. const char* homeDir = 0;
  4766. if (path[1] == File::separator || path[1] == 0)
  4767. {
  4768. // expand a name of the form "~/abc"
  4769. path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
  4770. + path.substring (1);
  4771. }
  4772. else
  4773. {
  4774. // expand a name of type "~dave/abc"
  4775. const String userName (path.substring (1).upToFirstOccurrenceOf (T("/"), false, false));
  4776. struct passwd* const pw = getpwnam (userName.toUTF8());
  4777. if (pw != 0)
  4778. {
  4779. String home (homeDir);
  4780. if (home.endsWithChar (File::separator))
  4781. home [home.length() - 1] = 0;
  4782. path = String (pw->pw_dir)
  4783. + path.substring (userName.length());
  4784. }
  4785. }
  4786. }
  4787. else if (! path.startsWithChar (File::separator))
  4788. {
  4789. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4790. If you're trying to parse a string that may be either a relative path or an absolute path,
  4791. you MUST provide a context against which the partial path can be evaluated - you can do
  4792. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4793. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4794. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4795. */
  4796. jassert (path.startsWith (T("./"))); // (assume that a path "./xyz" is deliberately intended to be relative to the CWD)
  4797. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4798. }
  4799. #endif
  4800. int len = path.length();
  4801. while (--len > 0 && path [len] == File::separator)
  4802. path [len] = 0;
  4803. return path;
  4804. }
  4805. const File File::nonexistent;
  4806. File::File (const String& fullPathName)
  4807. : fullPath (parseAbsolutePath (fullPathName))
  4808. {
  4809. }
  4810. File::File (const String& path, int)
  4811. : fullPath (path)
  4812. {
  4813. }
  4814. const File File::createFileWithoutCheckingPath (const String& path)
  4815. {
  4816. return File (path, 0);
  4817. }
  4818. File::File (const File& other)
  4819. : fullPath (other.fullPath)
  4820. {
  4821. }
  4822. File& File::operator= (const String& newPath)
  4823. {
  4824. fullPath = parseAbsolutePath (newPath);
  4825. return *this;
  4826. }
  4827. File& File::operator= (const File& other)
  4828. {
  4829. fullPath = other.fullPath;
  4830. return *this;
  4831. }
  4832. #if JUCE_LINUX
  4833. #define NAMES_ARE_CASE_SENSITIVE 1
  4834. #endif
  4835. bool File::areFileNamesCaseSensitive()
  4836. {
  4837. #if NAMES_ARE_CASE_SENSITIVE
  4838. return true;
  4839. #else
  4840. return false;
  4841. #endif
  4842. }
  4843. bool File::operator== (const File& other) const
  4844. {
  4845. // case-insensitive on Windows, but not on linux.
  4846. #if NAMES_ARE_CASE_SENSITIVE
  4847. return fullPath == other.fullPath;
  4848. #else
  4849. return fullPath.equalsIgnoreCase (other.fullPath);
  4850. #endif
  4851. }
  4852. bool File::operator!= (const File& other) const
  4853. {
  4854. return ! operator== (other);
  4855. }
  4856. bool File::exists() const
  4857. {
  4858. return juce_fileExists (fullPath, false);
  4859. }
  4860. bool File::existsAsFile() const
  4861. {
  4862. return juce_fileExists (fullPath, true);
  4863. }
  4864. bool File::isDirectory() const
  4865. {
  4866. return juce_isDirectory (fullPath);
  4867. }
  4868. bool File::hasWriteAccess() const
  4869. {
  4870. if (exists())
  4871. return juce_canWriteToFile (fullPath);
  4872. #if ! JUCE_WINDOWS
  4873. else if ((! isDirectory()) && fullPath.containsChar (separator))
  4874. return getParentDirectory().hasWriteAccess();
  4875. else
  4876. return false;
  4877. #else
  4878. // on windows, it seems that even read-only directories can still be written into,
  4879. // so checking the parent directory's permissions would return the wrong result..
  4880. else
  4881. return true;
  4882. #endif
  4883. }
  4884. bool File::setReadOnly (const bool shouldBeReadOnly,
  4885. const bool applyRecursively) const
  4886. {
  4887. bool worked = true;
  4888. if (applyRecursively && isDirectory())
  4889. {
  4890. Array <File> subFiles;
  4891. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4892. for (int i = subFiles.size(); --i >= 0;)
  4893. worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked;
  4894. }
  4895. return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked;
  4896. }
  4897. bool File::deleteFile() const
  4898. {
  4899. return (! exists())
  4900. || juce_deleteFile (fullPath);
  4901. }
  4902. bool File::deleteRecursively() const
  4903. {
  4904. bool worked = true;
  4905. if (isDirectory())
  4906. {
  4907. Array<File> subFiles;
  4908. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4909. for (int i = subFiles.size(); --i >= 0;)
  4910. worked = subFiles.getReference(i).deleteRecursively() && worked;
  4911. }
  4912. return deleteFile() && worked;
  4913. }
  4914. bool File::moveFileTo (const File& newFile) const
  4915. {
  4916. if (newFile.fullPath == fullPath)
  4917. return true;
  4918. #if ! NAMES_ARE_CASE_SENSITIVE
  4919. if (*this != newFile)
  4920. #endif
  4921. if (! newFile.deleteFile())
  4922. return false;
  4923. return juce_moveFile (fullPath, newFile.fullPath);
  4924. }
  4925. bool File::copyFileTo (const File& newFile) const
  4926. {
  4927. if (*this == newFile)
  4928. return true;
  4929. if (! newFile.deleteFile())
  4930. return false;
  4931. return juce_copyFile (fullPath, newFile.fullPath);
  4932. }
  4933. bool File::copyDirectoryTo (const File& newDirectory) const
  4934. {
  4935. if (isDirectory() && newDirectory.createDirectory())
  4936. {
  4937. Array<File> subFiles;
  4938. findChildFiles (subFiles, File::findFiles, false);
  4939. int i;
  4940. for (i = 0; i < subFiles.size(); ++i)
  4941. if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4942. return false;
  4943. subFiles.clear();
  4944. findChildFiles (subFiles, File::findDirectories, false);
  4945. for (i = 0; i < subFiles.size(); ++i)
  4946. if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4947. return false;
  4948. return true;
  4949. }
  4950. return false;
  4951. }
  4952. const String File::getPathUpToLastSlash() const
  4953. {
  4954. const int lastSlash = fullPath.lastIndexOfChar (separator);
  4955. if (lastSlash > 0)
  4956. return fullPath.substring (0, lastSlash);
  4957. else if (lastSlash == 0)
  4958. return separatorString;
  4959. else
  4960. return fullPath;
  4961. }
  4962. const File File::getParentDirectory() const
  4963. {
  4964. return File (getPathUpToLastSlash());
  4965. }
  4966. const String File::getFileName() const
  4967. {
  4968. return fullPath.substring (fullPath.lastIndexOfChar (separator) + 1);
  4969. }
  4970. int File::hashCode() const
  4971. {
  4972. return fullPath.hashCode();
  4973. }
  4974. int64 File::hashCode64() const
  4975. {
  4976. return fullPath.hashCode64();
  4977. }
  4978. const String File::getFileNameWithoutExtension() const
  4979. {
  4980. const int lastSlash = fullPath.lastIndexOfChar (separator) + 1;
  4981. const int lastDot = fullPath.lastIndexOfChar (T('.'));
  4982. if (lastDot > lastSlash)
  4983. return fullPath.substring (lastSlash, lastDot);
  4984. else
  4985. return fullPath.substring (lastSlash);
  4986. }
  4987. bool File::isAChildOf (const File& potentialParent) const
  4988. {
  4989. if (potentialParent == File::nonexistent)
  4990. return false;
  4991. const String ourPath (getPathUpToLastSlash());
  4992. #if NAMES_ARE_CASE_SENSITIVE
  4993. if (potentialParent.fullPath == ourPath)
  4994. #else
  4995. if (potentialParent.fullPath.equalsIgnoreCase (ourPath))
  4996. #endif
  4997. {
  4998. return true;
  4999. }
  5000. else if (potentialParent.fullPath.length() >= ourPath.length())
  5001. {
  5002. return false;
  5003. }
  5004. else
  5005. {
  5006. return getParentDirectory().isAChildOf (potentialParent);
  5007. }
  5008. }
  5009. bool File::isAbsolutePath (const String& path)
  5010. {
  5011. return path.startsWithChar (T('/')) || path.startsWithChar (T('\\'))
  5012. #if JUCE_WINDOWS
  5013. || (path.isNotEmpty() && ((const String&) path)[1] == T(':'));
  5014. #else
  5015. || path.startsWithChar (T('~'));
  5016. #endif
  5017. }
  5018. const File File::getChildFile (String relativePath) const
  5019. {
  5020. if (isAbsolutePath (relativePath))
  5021. {
  5022. // the path is really absolute..
  5023. return File (relativePath);
  5024. }
  5025. else
  5026. {
  5027. // it's relative, so remove any ../ or ./ bits at the start.
  5028. String path (fullPath);
  5029. if (relativePath[0] == T('.'))
  5030. {
  5031. #if JUCE_WINDOWS
  5032. relativePath = relativePath.replaceCharacter (T('/'), T('\\')).trimStart();
  5033. #else
  5034. relativePath = relativePath.replaceCharacter (T('\\'), T('/')).trimStart();
  5035. #endif
  5036. while (relativePath[0] == T('.'))
  5037. {
  5038. if (relativePath[1] == T('.'))
  5039. {
  5040. if (relativePath [2] == 0 || relativePath[2] == separator)
  5041. {
  5042. const int lastSlash = path.lastIndexOfChar (separator);
  5043. if (lastSlash >= 0)
  5044. path = path.substring (0, lastSlash);
  5045. relativePath = relativePath.substring (3);
  5046. }
  5047. else
  5048. {
  5049. break;
  5050. }
  5051. }
  5052. else if (relativePath[1] == separator)
  5053. {
  5054. relativePath = relativePath.substring (2);
  5055. }
  5056. else
  5057. {
  5058. break;
  5059. }
  5060. }
  5061. }
  5062. return File (juce_addTrailingSeparator (path) + relativePath);
  5063. }
  5064. }
  5065. const File File::getSiblingFile (const String& fileName) const
  5066. {
  5067. return getParentDirectory().getChildFile (fileName);
  5068. }
  5069. int64 File::getSize() const
  5070. {
  5071. return juce_getFileSize (fullPath);
  5072. }
  5073. const String File::descriptionOfSizeInBytes (const int64 bytes)
  5074. {
  5075. if (bytes == 1)
  5076. {
  5077. return "1 byte";
  5078. }
  5079. else if (bytes < 1024)
  5080. {
  5081. return String ((int) bytes) + " bytes";
  5082. }
  5083. else if (bytes < 1024 * 1024)
  5084. {
  5085. return String (bytes / 1024.0, 1) + " KB";
  5086. }
  5087. else if (bytes < 1024 * 1024 * 1024)
  5088. {
  5089. return String (bytes / (1024.0 * 1024.0), 1) + " MB";
  5090. }
  5091. else
  5092. {
  5093. return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB";
  5094. }
  5095. }
  5096. bool File::create() const
  5097. {
  5098. if (! exists())
  5099. {
  5100. const File parentDir (getParentDirectory());
  5101. if (parentDir == *this || ! parentDir.createDirectory())
  5102. return false;
  5103. void* const fh = juce_fileOpen (fullPath, true);
  5104. if (fh == 0)
  5105. return false;
  5106. juce_fileClose (fh);
  5107. }
  5108. return true;
  5109. }
  5110. bool File::createDirectory() const
  5111. {
  5112. if (! isDirectory())
  5113. {
  5114. const File parentDir (getParentDirectory());
  5115. if (parentDir == *this || ! parentDir.createDirectory())
  5116. return false;
  5117. String dir (fullPath);
  5118. while (dir.endsWithChar (separator))
  5119. dir [dir.length() - 1] = 0;
  5120. juce_createDirectory (dir);
  5121. return isDirectory();
  5122. }
  5123. return true;
  5124. }
  5125. const Time File::getCreationTime() const
  5126. {
  5127. int64 m, a, c;
  5128. juce_getFileTimes (fullPath, m, a, c);
  5129. return Time (c);
  5130. }
  5131. bool File::setCreationTime (const Time& t) const
  5132. {
  5133. return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds());
  5134. }
  5135. const Time File::getLastModificationTime() const
  5136. {
  5137. int64 m, a, c;
  5138. juce_getFileTimes (fullPath, m, a, c);
  5139. return Time (m);
  5140. }
  5141. bool File::setLastModificationTime (const Time& t) const
  5142. {
  5143. return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0);
  5144. }
  5145. const Time File::getLastAccessTime() const
  5146. {
  5147. int64 m, a, c;
  5148. juce_getFileTimes (fullPath, m, a, c);
  5149. return Time (a);
  5150. }
  5151. bool File::setLastAccessTime (const Time& t) const
  5152. {
  5153. return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0);
  5154. }
  5155. bool File::loadFileAsData (MemoryBlock& destBlock) const
  5156. {
  5157. if (! existsAsFile())
  5158. return false;
  5159. FileInputStream in (*this);
  5160. return getSize() == in.readIntoMemoryBlock (destBlock);
  5161. }
  5162. const String File::loadFileAsString() const
  5163. {
  5164. if (! existsAsFile())
  5165. return String::empty;
  5166. FileInputStream in (*this);
  5167. return in.readEntireStreamAsString();
  5168. }
  5169. static inline bool fileTypeMatches (const int whatToLookFor,
  5170. const bool isDir,
  5171. const bool isHidden)
  5172. {
  5173. return (whatToLookFor & (isDir ? File::findDirectories
  5174. : File::findFiles)) != 0
  5175. && ((! isHidden)
  5176. || (whatToLookFor & File::ignoreHiddenFiles) == 0);
  5177. }
  5178. int File::findChildFiles (Array<File>& results,
  5179. const int whatToLookFor,
  5180. const bool searchRecursively,
  5181. const String& wildCardPattern) const
  5182. {
  5183. // you have to specify the type of files you're looking for!
  5184. jassert ((whatToLookFor & (findFiles | findDirectories)) != 0);
  5185. int total = 0;
  5186. // find child files or directories in this directory first..
  5187. if (isDirectory())
  5188. {
  5189. const String path (juce_addTrailingSeparator (fullPath));
  5190. String filename;
  5191. bool itemIsDirectory, itemIsHidden;
  5192. void* const handle = juce_findFileStart (path, wildCardPattern, filename,
  5193. &itemIsDirectory, &itemIsHidden,
  5194. 0, 0, 0, 0);
  5195. if (handle != 0)
  5196. {
  5197. do
  5198. {
  5199. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5200. && ! filename.containsOnly (T(".")))
  5201. {
  5202. results.add (File (path + filename, 0));
  5203. ++total;
  5204. }
  5205. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5206. juce_findFileClose (handle);
  5207. }
  5208. }
  5209. else
  5210. {
  5211. // trying to search for files inside a non-directory?
  5212. //jassertfalse
  5213. }
  5214. // and recurse down if required.
  5215. if (searchRecursively)
  5216. {
  5217. Array<File> subDirectories;
  5218. findChildFiles (subDirectories, File::findDirectories, false);
  5219. for (int i = 0; i < subDirectories.size(); ++i)
  5220. {
  5221. total += subDirectories.getReference(i).findChildFiles (results, whatToLookFor,
  5222. true, wildCardPattern);
  5223. }
  5224. }
  5225. return total;
  5226. }
  5227. int File::getNumberOfChildFiles (const int whatToLookFor,
  5228. const String& wildCardPattern) const
  5229. {
  5230. // you have to specify the type of files you're looking for!
  5231. jassert (whatToLookFor > 0 && whatToLookFor <= 3);
  5232. int count = 0;
  5233. if (isDirectory())
  5234. {
  5235. String filename;
  5236. bool itemIsDirectory, itemIsHidden;
  5237. void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename,
  5238. &itemIsDirectory, &itemIsHidden,
  5239. 0, 0, 0, 0);
  5240. if (handle != 0)
  5241. {
  5242. do
  5243. {
  5244. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5245. && ! filename.containsOnly (T(".")))
  5246. {
  5247. ++count;
  5248. }
  5249. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5250. juce_findFileClose (handle);
  5251. }
  5252. }
  5253. else
  5254. {
  5255. // trying to search for files inside a non-directory?
  5256. jassertfalse
  5257. }
  5258. return count;
  5259. }
  5260. bool File::containsSubDirectories() const
  5261. {
  5262. bool result = false;
  5263. if (isDirectory())
  5264. {
  5265. String filename;
  5266. bool itemIsDirectory, itemIsHidden;
  5267. void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath),
  5268. T("*"), filename,
  5269. &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0);
  5270. if (handle != 0)
  5271. {
  5272. do
  5273. {
  5274. if (itemIsDirectory)
  5275. {
  5276. result = true;
  5277. break;
  5278. }
  5279. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5280. juce_findFileClose (handle);
  5281. }
  5282. }
  5283. return result;
  5284. }
  5285. const File File::getNonexistentChildFile (const String& prefix_,
  5286. const String& suffix,
  5287. bool putNumbersInBrackets) const
  5288. {
  5289. File f (getChildFile (prefix_ + suffix));
  5290. if (f.exists())
  5291. {
  5292. int num = 2;
  5293. String prefix (prefix_);
  5294. // remove any bracketed numbers that may already be on the end..
  5295. if (prefix.trim().endsWithChar (T(')')))
  5296. {
  5297. putNumbersInBrackets = true;
  5298. const int openBracks = prefix.lastIndexOfChar (T('('));
  5299. const int closeBracks = prefix.lastIndexOfChar (T(')'));
  5300. if (openBracks > 0
  5301. && closeBracks > openBracks
  5302. && prefix.substring (openBracks + 1, closeBracks).containsOnly (T("0123456789")))
  5303. {
  5304. num = prefix.substring (openBracks + 1, closeBracks).getIntValue() + 1;
  5305. prefix = prefix.substring (0, openBracks);
  5306. }
  5307. }
  5308. // also use brackets if it ends in a digit.
  5309. putNumbersInBrackets = putNumbersInBrackets
  5310. || CharacterFunctions::isDigit (prefix.getLastCharacter());
  5311. do
  5312. {
  5313. if (putNumbersInBrackets)
  5314. f = getChildFile (prefix + T('(') + String (num++) + T(')') + suffix);
  5315. else
  5316. f = getChildFile (prefix + String (num++) + suffix);
  5317. } while (f.exists());
  5318. }
  5319. return f;
  5320. }
  5321. const File File::getNonexistentSibling (const bool putNumbersInBrackets) const
  5322. {
  5323. if (exists())
  5324. {
  5325. return getParentDirectory()
  5326. .getNonexistentChildFile (getFileNameWithoutExtension(),
  5327. getFileExtension(),
  5328. putNumbersInBrackets);
  5329. }
  5330. else
  5331. {
  5332. return *this;
  5333. }
  5334. }
  5335. const String File::getFileExtension() const
  5336. {
  5337. String ext;
  5338. if (! isDirectory())
  5339. {
  5340. const int indexOfDot = fullPath.lastIndexOfChar (T('.'));
  5341. if (indexOfDot > fullPath.lastIndexOfChar (separator))
  5342. ext = fullPath.substring (indexOfDot);
  5343. }
  5344. return ext;
  5345. }
  5346. bool File::hasFileExtension (const String& possibleSuffix) const
  5347. {
  5348. if (possibleSuffix.isEmpty())
  5349. return fullPath.lastIndexOfChar (T('.')) <= fullPath.lastIndexOfChar (separator);
  5350. const int semicolon = possibleSuffix.indexOfChar (0, T(';'));
  5351. if (semicolon >= 0)
  5352. {
  5353. return hasFileExtension (possibleSuffix.substring (0, semicolon).trimEnd())
  5354. || hasFileExtension (possibleSuffix.substring (semicolon + 1).trimStart());
  5355. }
  5356. else
  5357. {
  5358. if (fullPath.endsWithIgnoreCase (possibleSuffix))
  5359. {
  5360. if (possibleSuffix.startsWithChar (T('.')))
  5361. return true;
  5362. const int dotPos = fullPath.length() - possibleSuffix.length() - 1;
  5363. if (dotPos >= 0)
  5364. return fullPath [dotPos] == T('.');
  5365. }
  5366. }
  5367. return false;
  5368. }
  5369. const File File::withFileExtension (const String& newExtension) const
  5370. {
  5371. if (fullPath.isEmpty())
  5372. return File::nonexistent;
  5373. String filePart (getFileName());
  5374. int i = filePart.lastIndexOfChar (T('.'));
  5375. if (i < 0)
  5376. i = filePart.length();
  5377. String newExt (newExtension);
  5378. if (newExt.isNotEmpty() && ! newExt.startsWithChar (T('.')))
  5379. newExt = T(".") + newExt;
  5380. return getSiblingFile (filePart.substring (0, i) + newExt);
  5381. }
  5382. bool File::startAsProcess (const String& parameters) const
  5383. {
  5384. return exists()
  5385. && juce_launchFile (fullPath, parameters);
  5386. }
  5387. FileInputStream* File::createInputStream() const
  5388. {
  5389. if (existsAsFile())
  5390. return new FileInputStream (*this);
  5391. else
  5392. return 0;
  5393. }
  5394. FileOutputStream* File::createOutputStream (const int bufferSize) const
  5395. {
  5396. ScopedPointer <FileOutputStream> out (new FileOutputStream (*this, bufferSize));
  5397. if (out->failedToOpen())
  5398. return 0;
  5399. return out.release();
  5400. }
  5401. bool File::appendData (const void* const dataToAppend,
  5402. const int numberOfBytes) const
  5403. {
  5404. if (numberOfBytes > 0)
  5405. {
  5406. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5407. if (out == 0)
  5408. return false;
  5409. out->write (dataToAppend, numberOfBytes);
  5410. }
  5411. return true;
  5412. }
  5413. bool File::replaceWithData (const void* const dataToWrite,
  5414. const int numberOfBytes) const
  5415. {
  5416. jassert (numberOfBytes >= 0); // a negative number of bytes??
  5417. if (numberOfBytes <= 0)
  5418. return deleteFile();
  5419. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5420. tempFile.getFile().appendData (dataToWrite, numberOfBytes);
  5421. return tempFile.overwriteTargetFileWithTemporary();
  5422. }
  5423. bool File::appendText (const String& text,
  5424. const bool asUnicode,
  5425. const bool writeUnicodeHeaderBytes) const
  5426. {
  5427. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5428. if (out != 0)
  5429. {
  5430. out->writeText (text, asUnicode, writeUnicodeHeaderBytes);
  5431. return true;
  5432. }
  5433. return false;
  5434. }
  5435. bool File::replaceWithText (const String& textToWrite,
  5436. const bool asUnicode,
  5437. const bool writeUnicodeHeaderBytes) const
  5438. {
  5439. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5440. tempFile.getFile().appendText (textToWrite, asUnicode, writeUnicodeHeaderBytes);
  5441. return tempFile.overwriteTargetFileWithTemporary();
  5442. }
  5443. const String File::createLegalPathName (const String& original)
  5444. {
  5445. String s (original);
  5446. String start;
  5447. if (s[1] == T(':'))
  5448. {
  5449. start = s.substring (0, 2);
  5450. s = s.substring (2);
  5451. }
  5452. return start + s.removeCharacters (T("\"#@,;:<>*^|?"))
  5453. .substring (0, 1024);
  5454. }
  5455. const String File::createLegalFileName (const String& original)
  5456. {
  5457. String s (original.removeCharacters (T("\"#@,;:<>*^|?\\/")));
  5458. const int maxLength = 128; // only the length of the filename, not the whole path
  5459. const int len = s.length();
  5460. if (len > maxLength)
  5461. {
  5462. const int lastDot = s.lastIndexOfChar (T('.'));
  5463. if (lastDot > jmax (0, len - 12))
  5464. {
  5465. s = s.substring (0, maxLength - (len - lastDot))
  5466. + s.substring (lastDot);
  5467. }
  5468. else
  5469. {
  5470. s = s.substring (0, maxLength);
  5471. }
  5472. }
  5473. return s;
  5474. }
  5475. const String File::getRelativePathFrom (const File& dir) const
  5476. {
  5477. String thisPath (fullPath);
  5478. {
  5479. int len = thisPath.length();
  5480. while (--len >= 0 && thisPath [len] == File::separator)
  5481. thisPath [len] = 0;
  5482. }
  5483. String dirPath (juce_addTrailingSeparator ((dir.existsAsFile()) ? dir.getParentDirectory().getFullPathName()
  5484. : dir.fullPath));
  5485. const int len = jmin (thisPath.length(), dirPath.length());
  5486. int commonBitLength = 0;
  5487. for (int i = 0; i < len; ++i)
  5488. {
  5489. #if NAMES_ARE_CASE_SENSITIVE
  5490. if (thisPath[i] != dirPath[i])
  5491. #else
  5492. if (CharacterFunctions::toLowerCase (thisPath[i])
  5493. != CharacterFunctions::toLowerCase (dirPath[i]))
  5494. #endif
  5495. {
  5496. break;
  5497. }
  5498. ++commonBitLength;
  5499. }
  5500. while (commonBitLength > 0 && thisPath [commonBitLength - 1] != File::separator)
  5501. --commonBitLength;
  5502. // if the only common bit is the root, then just return the full path..
  5503. if (commonBitLength <= 0
  5504. || (commonBitLength == 1 && thisPath [1] == File::separator))
  5505. return fullPath;
  5506. thisPath = thisPath.substring (commonBitLength);
  5507. dirPath = dirPath.substring (commonBitLength);
  5508. while (dirPath.isNotEmpty())
  5509. {
  5510. #if JUCE_WINDOWS
  5511. thisPath = T("..\\") + thisPath;
  5512. #else
  5513. thisPath = T("../") + thisPath;
  5514. #endif
  5515. const int sep = dirPath.indexOfChar (separator);
  5516. if (sep >= 0)
  5517. dirPath = dirPath.substring (sep + 1);
  5518. else
  5519. dirPath = String::empty;
  5520. }
  5521. return thisPath;
  5522. }
  5523. void File::findFileSystemRoots (Array<File>& destArray)
  5524. {
  5525. const StringArray roots (juce_getFileSystemRoots());
  5526. for (int i = 0; i < roots.size(); ++i)
  5527. destArray.add (File (roots[i]));
  5528. }
  5529. const String File::getVolumeLabel() const
  5530. {
  5531. int serialNum;
  5532. return juce_getVolumeLabel (fullPath, serialNum);
  5533. }
  5534. int File::getVolumeSerialNumber() const
  5535. {
  5536. int serialNum;
  5537. juce_getVolumeLabel (fullPath, serialNum);
  5538. return serialNum;
  5539. }
  5540. const File File::createTempFile (const String& fileNameEnding)
  5541. {
  5542. const File tempFile (getSpecialLocation (tempDirectory)
  5543. .getChildFile (T("temp_") + String (Random::getSystemRandom().nextInt()))
  5544. .withFileExtension (fileNameEnding));
  5545. if (tempFile.exists())
  5546. return createTempFile (fileNameEnding);
  5547. else
  5548. return tempFile;
  5549. }
  5550. END_JUCE_NAMESPACE
  5551. /*** End of inlined file: juce_File.cpp ***/
  5552. /*** Start of inlined file: juce_FileInputStream.cpp ***/
  5553. BEGIN_JUCE_NAMESPACE
  5554. void* juce_fileOpen (const String& path, bool forWriting);
  5555. void juce_fileClose (void* handle);
  5556. int juce_fileRead (void* handle, void* buffer, int size);
  5557. int64 juce_fileSetPosition (void* handle, int64 pos);
  5558. FileInputStream::FileInputStream (const File& f)
  5559. : file (f),
  5560. currentPosition (0),
  5561. needToSeek (true)
  5562. {
  5563. totalSize = f.getSize();
  5564. fileHandle = juce_fileOpen (f.getFullPathName(), false);
  5565. }
  5566. FileInputStream::~FileInputStream()
  5567. {
  5568. juce_fileClose (fileHandle);
  5569. }
  5570. int64 FileInputStream::getTotalLength()
  5571. {
  5572. return totalSize;
  5573. }
  5574. int FileInputStream::read (void* buffer, int bytesToRead)
  5575. {
  5576. int num = 0;
  5577. if (needToSeek)
  5578. {
  5579. if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
  5580. return 0;
  5581. needToSeek = false;
  5582. }
  5583. num = juce_fileRead (fileHandle, buffer, bytesToRead);
  5584. currentPosition += num;
  5585. return num;
  5586. }
  5587. bool FileInputStream::isExhausted()
  5588. {
  5589. return currentPosition >= totalSize;
  5590. }
  5591. int64 FileInputStream::getPosition()
  5592. {
  5593. return currentPosition;
  5594. }
  5595. bool FileInputStream::setPosition (int64 pos)
  5596. {
  5597. pos = jlimit ((int64) 0, totalSize, pos);
  5598. needToSeek |= (currentPosition != pos);
  5599. currentPosition = pos;
  5600. return true;
  5601. }
  5602. END_JUCE_NAMESPACE
  5603. /*** End of inlined file: juce_FileInputStream.cpp ***/
  5604. /*** Start of inlined file: juce_FileOutputStream.cpp ***/
  5605. BEGIN_JUCE_NAMESPACE
  5606. void* juce_fileOpen (const String& path, bool forWriting);
  5607. void juce_fileClose (void* handle);
  5608. int juce_fileWrite (void* handle, const void* buffer, int size);
  5609. void juce_fileFlush (void* handle);
  5610. int64 juce_fileGetPosition (void* handle);
  5611. int64 juce_fileSetPosition (void* handle, int64 pos);
  5612. FileOutputStream::FileOutputStream (const File& f,
  5613. const int bufferSize_)
  5614. : file (f),
  5615. bufferSize (bufferSize_),
  5616. bytesInBuffer (0)
  5617. {
  5618. fileHandle = juce_fileOpen (f.getFullPathName(), true);
  5619. if (fileHandle != 0)
  5620. {
  5621. currentPosition = juce_fileGetPosition (fileHandle);
  5622. if (currentPosition < 0)
  5623. {
  5624. jassertfalse
  5625. juce_fileClose (fileHandle);
  5626. fileHandle = 0;
  5627. }
  5628. }
  5629. buffer.malloc (jmax (bufferSize_, 16));
  5630. }
  5631. FileOutputStream::~FileOutputStream()
  5632. {
  5633. flush();
  5634. juce_fileClose (fileHandle);
  5635. }
  5636. int64 FileOutputStream::getPosition()
  5637. {
  5638. return currentPosition;
  5639. }
  5640. bool FileOutputStream::setPosition (int64 newPosition)
  5641. {
  5642. if (newPosition != currentPosition)
  5643. {
  5644. flush();
  5645. currentPosition = juce_fileSetPosition (fileHandle, newPosition);
  5646. }
  5647. return newPosition == currentPosition;
  5648. }
  5649. void FileOutputStream::flush()
  5650. {
  5651. if (bytesInBuffer > 0)
  5652. {
  5653. juce_fileWrite (fileHandle, buffer, bytesInBuffer);
  5654. bytesInBuffer = 0;
  5655. }
  5656. juce_fileFlush (fileHandle);
  5657. }
  5658. bool FileOutputStream::write (const void* const src, const int numBytes)
  5659. {
  5660. if (bytesInBuffer + numBytes < bufferSize)
  5661. {
  5662. memcpy (buffer + bytesInBuffer, src, numBytes);
  5663. bytesInBuffer += numBytes;
  5664. currentPosition += numBytes;
  5665. }
  5666. else
  5667. {
  5668. if (bytesInBuffer > 0)
  5669. {
  5670. // flush the reservoir
  5671. const bool wroteOk = (juce_fileWrite (fileHandle, buffer, bytesInBuffer) == bytesInBuffer);
  5672. bytesInBuffer = 0;
  5673. if (! wroteOk)
  5674. return false;
  5675. }
  5676. if (numBytes < bufferSize)
  5677. {
  5678. memcpy (buffer + bytesInBuffer, src, numBytes);
  5679. bytesInBuffer += numBytes;
  5680. currentPosition += numBytes;
  5681. }
  5682. else
  5683. {
  5684. const int bytesWritten = juce_fileWrite (fileHandle, src, numBytes);
  5685. currentPosition += bytesWritten;
  5686. return bytesWritten == numBytes;
  5687. }
  5688. }
  5689. return true;
  5690. }
  5691. END_JUCE_NAMESPACE
  5692. /*** End of inlined file: juce_FileOutputStream.cpp ***/
  5693. /*** Start of inlined file: juce_FileSearchPath.cpp ***/
  5694. BEGIN_JUCE_NAMESPACE
  5695. FileSearchPath::FileSearchPath()
  5696. {
  5697. }
  5698. FileSearchPath::FileSearchPath (const String& path)
  5699. {
  5700. init (path);
  5701. }
  5702. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  5703. : directories (other.directories)
  5704. {
  5705. }
  5706. FileSearchPath::~FileSearchPath()
  5707. {
  5708. }
  5709. FileSearchPath& FileSearchPath::operator= (const String& path)
  5710. {
  5711. init (path);
  5712. return *this;
  5713. }
  5714. void FileSearchPath::init (const String& path)
  5715. {
  5716. directories.clear();
  5717. directories.addTokens (path, T(";"), T("\""));
  5718. directories.trim();
  5719. directories.removeEmptyStrings();
  5720. for (int i = directories.size(); --i >= 0;)
  5721. directories.set (i, directories[i].unquoted());
  5722. }
  5723. int FileSearchPath::getNumPaths() const
  5724. {
  5725. return directories.size();
  5726. }
  5727. const File FileSearchPath::operator[] (const int index) const
  5728. {
  5729. return File (directories [index]);
  5730. }
  5731. const String FileSearchPath::toString() const
  5732. {
  5733. StringArray directories2 (directories);
  5734. for (int i = directories2.size(); --i >= 0;)
  5735. if (directories2[i].containsChar (T(';')))
  5736. directories2.set (i, directories2[i].quoted());
  5737. return directories2.joinIntoString (T(";"));
  5738. }
  5739. void FileSearchPath::add (const File& dir, const int insertIndex)
  5740. {
  5741. directories.insert (insertIndex, dir.getFullPathName());
  5742. }
  5743. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  5744. {
  5745. for (int i = 0; i < directories.size(); ++i)
  5746. if (File (directories[i]) == dir)
  5747. return;
  5748. add (dir);
  5749. }
  5750. void FileSearchPath::remove (const int index)
  5751. {
  5752. directories.remove (index);
  5753. }
  5754. void FileSearchPath::addPath (const FileSearchPath& other)
  5755. {
  5756. for (int i = 0; i < other.getNumPaths(); ++i)
  5757. addIfNotAlreadyThere (other[i]);
  5758. }
  5759. void FileSearchPath::removeRedundantPaths()
  5760. {
  5761. for (int i = directories.size(); --i >= 0;)
  5762. {
  5763. const File d1 (directories[i]);
  5764. for (int j = directories.size(); --j >= 0;)
  5765. {
  5766. const File d2 (directories[j]);
  5767. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  5768. {
  5769. directories.remove (i);
  5770. break;
  5771. }
  5772. }
  5773. }
  5774. }
  5775. void FileSearchPath::removeNonExistentPaths()
  5776. {
  5777. for (int i = directories.size(); --i >= 0;)
  5778. if (! File (directories[i]).isDirectory())
  5779. directories.remove (i);
  5780. }
  5781. int FileSearchPath::findChildFiles (Array<File>& results,
  5782. const int whatToLookFor,
  5783. const bool searchRecursively,
  5784. const String& wildCardPattern) const
  5785. {
  5786. int total = 0;
  5787. for (int i = 0; i < directories.size(); ++i)
  5788. total += operator[] (i).findChildFiles (results,
  5789. whatToLookFor,
  5790. searchRecursively,
  5791. wildCardPattern);
  5792. return total;
  5793. }
  5794. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  5795. const bool checkRecursively) const
  5796. {
  5797. for (int i = directories.size(); --i >= 0;)
  5798. {
  5799. const File d (directories[i]);
  5800. if (checkRecursively)
  5801. {
  5802. if (fileToCheck.isAChildOf (d))
  5803. return true;
  5804. }
  5805. else
  5806. {
  5807. if (fileToCheck.getParentDirectory() == d)
  5808. return true;
  5809. }
  5810. }
  5811. return false;
  5812. }
  5813. END_JUCE_NAMESPACE
  5814. /*** End of inlined file: juce_FileSearchPath.cpp ***/
  5815. /*** Start of inlined file: juce_NamedPipe.cpp ***/
  5816. BEGIN_JUCE_NAMESPACE
  5817. NamedPipe::NamedPipe()
  5818. : internal (0)
  5819. {
  5820. }
  5821. NamedPipe::~NamedPipe()
  5822. {
  5823. close();
  5824. }
  5825. bool NamedPipe::openExisting (const String& pipeName)
  5826. {
  5827. currentPipeName = pipeName;
  5828. return openInternal (pipeName, false);
  5829. }
  5830. bool NamedPipe::createNewPipe (const String& pipeName)
  5831. {
  5832. currentPipeName = pipeName;
  5833. return openInternal (pipeName, true);
  5834. }
  5835. bool NamedPipe::isOpen() const
  5836. {
  5837. return internal != 0;
  5838. }
  5839. const String NamedPipe::getName() const
  5840. {
  5841. return currentPipeName;
  5842. }
  5843. // other methods for this class are implemented in the platform-specific files
  5844. END_JUCE_NAMESPACE
  5845. /*** End of inlined file: juce_NamedPipe.cpp ***/
  5846. /*** Start of inlined file: juce_TemporaryFile.cpp ***/
  5847. BEGIN_JUCE_NAMESPACE
  5848. TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
  5849. {
  5850. createTempFile (File::getSpecialLocation (File::tempDirectory),
  5851. T("temp_") + String (Random::getSystemRandom().nextInt()),
  5852. suffix,
  5853. optionFlags);
  5854. }
  5855. TemporaryFile::TemporaryFile (const File& targetFile_, const int optionFlags)
  5856. : targetFile (targetFile_)
  5857. {
  5858. // If you use this constructor, you need to give it a valid target file!
  5859. jassert (targetFile != File::nonexistent);
  5860. createTempFile (targetFile.getParentDirectory(),
  5861. targetFile.getFileNameWithoutExtension() + T("_temp") + String (Random::getSystemRandom().nextInt()),
  5862. targetFile.getFileExtension(),
  5863. optionFlags);
  5864. }
  5865. void TemporaryFile::createTempFile (const File& parentDirectory, String name,
  5866. const String& suffix, const int optionFlags)
  5867. {
  5868. if ((optionFlags & useHiddenFile) != 0)
  5869. name = T(".") + name;
  5870. temporaryFile = parentDirectory.getNonexistentChildFile (name, suffix, (optionFlags & putNumbersInBrackets) != 0);
  5871. }
  5872. TemporaryFile::~TemporaryFile()
  5873. {
  5874. // Have a few attempts at deleting the file before giving up..
  5875. for (int i = 5; --i >= 0;)
  5876. {
  5877. if (temporaryFile.deleteFile())
  5878. return;
  5879. Thread::sleep (50);
  5880. }
  5881. // Failed to delete our temporary file! Check that you've deleted all the
  5882. // file output streams that were using it!
  5883. jassertfalse;
  5884. }
  5885. bool TemporaryFile::overwriteTargetFileWithTemporary() const
  5886. {
  5887. // This method only works if you created this object with the constructor
  5888. // that takes a target file!
  5889. jassert (targetFile != File::nonexistent);
  5890. if (temporaryFile.exists())
  5891. {
  5892. // Have a few attempts at overwriting the file before giving up..
  5893. for (int i = 5; --i >= 0;)
  5894. {
  5895. if (temporaryFile.moveFileTo (targetFile))
  5896. return true;
  5897. Thread::sleep (100);
  5898. }
  5899. // Failed to overwrite the new file! Make sure you've not left any
  5900. // file streams hanging around when you call this method!
  5901. jassertfalse
  5902. }
  5903. else
  5904. {
  5905. // There's no temporary file to use. If your write failed, you should
  5906. // probably check, and not bother calling this method.
  5907. jassertfalse
  5908. }
  5909. return false;
  5910. }
  5911. END_JUCE_NAMESPACE
  5912. /*** End of inlined file: juce_TemporaryFile.cpp ***/
  5913. /*** Start of inlined file: juce_Socket.cpp ***/
  5914. #if JUCE_WINDOWS
  5915. #include <winsock2.h>
  5916. #ifdef _MSC_VER
  5917. #pragma warning (disable : 4127 4389 4018)
  5918. #endif
  5919. #else
  5920. #if JUCE_LINUX
  5921. #include <sys/types.h>
  5922. #include <sys/socket.h>
  5923. #include <sys/errno.h>
  5924. #include <unistd.h>
  5925. #include <netinet/in.h>
  5926. #elif (MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4) && ! JUCE_IPHONE
  5927. #include <CoreServices/CoreServices.h>
  5928. #endif
  5929. #include <fcntl.h>
  5930. #include <netdb.h>
  5931. #include <arpa/inet.h>
  5932. #include <netinet/tcp.h>
  5933. #endif
  5934. BEGIN_JUCE_NAMESPACE
  5935. #if defined (JUCE_LINUX) || defined (JUCE_MAC) || defined (JUCE_IPHONE)
  5936. typedef socklen_t juce_socklen_t;
  5937. #else
  5938. typedef int juce_socklen_t;
  5939. #endif
  5940. #if JUCE_WINDOWS
  5941. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  5942. juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0;
  5943. static void initWin32Sockets()
  5944. {
  5945. static CriticalSection lock;
  5946. const ScopedLock sl (lock);
  5947. if (juce_CloseWin32SocketLib == 0)
  5948. {
  5949. WSADATA wsaData;
  5950. const WORD wVersionRequested = MAKEWORD (1, 1);
  5951. WSAStartup (wVersionRequested, &wsaData);
  5952. juce_CloseWin32SocketLib = &WSACleanup;
  5953. }
  5954. }
  5955. #endif
  5956. static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw()
  5957. {
  5958. const int sndBufSize = 65536;
  5959. const int rcvBufSize = 65536;
  5960. const int one = 1;
  5961. return handle > 0
  5962. && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0
  5963. && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0
  5964. && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0)
  5965. : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0));
  5966. }
  5967. static bool bindSocketToPort (const int handle, const int port) throw()
  5968. {
  5969. if (handle <= 0 || port <= 0)
  5970. return false;
  5971. struct sockaddr_in servTmpAddr;
  5972. zerostruct (servTmpAddr);
  5973. servTmpAddr.sin_family = PF_INET;
  5974. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  5975. servTmpAddr.sin_port = htons ((uint16) port);
  5976. return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0;
  5977. }
  5978. static int readSocket (const int handle,
  5979. void* const destBuffer, const int maxBytesToRead,
  5980. bool volatile& connected,
  5981. const bool blockUntilSpecifiedAmountHasArrived) throw()
  5982. {
  5983. int bytesRead = 0;
  5984. while (bytesRead < maxBytesToRead)
  5985. {
  5986. int bytesThisTime;
  5987. #if JUCE_WINDOWS
  5988. bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
  5989. #else
  5990. while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0
  5991. && errno == EINTR
  5992. && connected)
  5993. {
  5994. }
  5995. #endif
  5996. if (bytesThisTime <= 0 || ! connected)
  5997. {
  5998. if (bytesRead == 0)
  5999. bytesRead = -1;
  6000. break;
  6001. }
  6002. bytesRead += bytesThisTime;
  6003. if (! blockUntilSpecifiedAmountHasArrived)
  6004. break;
  6005. }
  6006. return bytesRead;
  6007. }
  6008. static int waitForReadiness (const int handle, const bool forReading,
  6009. const int timeoutMsecs) throw()
  6010. {
  6011. struct timeval timeout;
  6012. struct timeval* timeoutp;
  6013. if (timeoutMsecs >= 0)
  6014. {
  6015. timeout.tv_sec = timeoutMsecs / 1000;
  6016. timeout.tv_usec = (timeoutMsecs % 1000) * 1000;
  6017. timeoutp = &timeout;
  6018. }
  6019. else
  6020. {
  6021. timeoutp = 0;
  6022. }
  6023. fd_set rset, wset;
  6024. FD_ZERO (&rset);
  6025. FD_SET (handle, &rset);
  6026. FD_ZERO (&wset);
  6027. FD_SET (handle, &wset);
  6028. fd_set* const prset = forReading ? &rset : 0;
  6029. fd_set* const pwset = forReading ? 0 : &wset;
  6030. #if JUCE_WINDOWS
  6031. if (select (handle + 1, prset, pwset, 0, timeoutp) < 0)
  6032. return -1;
  6033. #else
  6034. {
  6035. int result;
  6036. while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0
  6037. && errno == EINTR)
  6038. {
  6039. }
  6040. if (result < 0)
  6041. return -1;
  6042. }
  6043. #endif
  6044. {
  6045. int opt;
  6046. juce_socklen_t len = sizeof (opt);
  6047. if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0
  6048. || opt != 0)
  6049. return -1;
  6050. }
  6051. if ((forReading && FD_ISSET (handle, &rset))
  6052. || ((! forReading) && FD_ISSET (handle, &wset)))
  6053. return 1;
  6054. return 0;
  6055. }
  6056. static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw()
  6057. {
  6058. #if JUCE_WINDOWS
  6059. u_long nonBlocking = shouldBlock ? 0 : 1;
  6060. if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0)
  6061. return false;
  6062. #else
  6063. int socketFlags = fcntl (handle, F_GETFL, 0);
  6064. if (socketFlags == -1)
  6065. return false;
  6066. if (shouldBlock)
  6067. socketFlags &= ~O_NONBLOCK;
  6068. else
  6069. socketFlags |= O_NONBLOCK;
  6070. if (fcntl (handle, F_SETFL, socketFlags) != 0)
  6071. return false;
  6072. #endif
  6073. return true;
  6074. }
  6075. static bool connectSocket (int volatile& handle,
  6076. const bool isDatagram,
  6077. void** serverAddress,
  6078. const String& hostName,
  6079. const int portNumber,
  6080. const int timeOutMillisecs) throw()
  6081. {
  6082. struct hostent* const hostEnt = gethostbyname (hostName.toUTF8());
  6083. if (hostEnt == 0)
  6084. return false;
  6085. struct in_addr targetAddress;
  6086. memcpy (&targetAddress.s_addr,
  6087. *(hostEnt->h_addr_list),
  6088. sizeof (targetAddress.s_addr));
  6089. struct sockaddr_in servTmpAddr;
  6090. zerostruct (servTmpAddr);
  6091. servTmpAddr.sin_family = PF_INET;
  6092. servTmpAddr.sin_addr = targetAddress;
  6093. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6094. if (handle < 0)
  6095. handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
  6096. if (handle < 0)
  6097. return false;
  6098. if (isDatagram)
  6099. {
  6100. *serverAddress = new struct sockaddr_in();
  6101. *((struct sockaddr_in*) *serverAddress) = servTmpAddr;
  6102. return true;
  6103. }
  6104. setSocketBlockingState (handle, false);
  6105. const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in));
  6106. if (result < 0)
  6107. {
  6108. #if JUCE_WINDOWS
  6109. if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
  6110. #else
  6111. if (errno == EINPROGRESS)
  6112. #endif
  6113. {
  6114. if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
  6115. {
  6116. setSocketBlockingState (handle, true);
  6117. return false;
  6118. }
  6119. }
  6120. }
  6121. setSocketBlockingState (handle, true);
  6122. resetSocketOptions (handle, false, false);
  6123. return true;
  6124. }
  6125. StreamingSocket::StreamingSocket()
  6126. : portNumber (0),
  6127. handle (-1),
  6128. connected (false),
  6129. isListener (false)
  6130. {
  6131. #if JUCE_WINDOWS
  6132. initWin32Sockets();
  6133. #endif
  6134. }
  6135. StreamingSocket::StreamingSocket (const String& hostName_,
  6136. const int portNumber_,
  6137. const int handle_)
  6138. : hostName (hostName_),
  6139. portNumber (portNumber_),
  6140. handle (handle_),
  6141. connected (true),
  6142. isListener (false)
  6143. {
  6144. #if JUCE_WINDOWS
  6145. initWin32Sockets();
  6146. #endif
  6147. resetSocketOptions (handle_, false, false);
  6148. }
  6149. StreamingSocket::~StreamingSocket()
  6150. {
  6151. close();
  6152. }
  6153. int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6154. {
  6155. return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6156. : -1;
  6157. }
  6158. int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6159. {
  6160. if (isListener || ! connected)
  6161. return -1;
  6162. #if JUCE_WINDOWS
  6163. return send (handle, (const char*) sourceBuffer, numBytesToWrite, 0);
  6164. #else
  6165. int result;
  6166. while ((result = (int) ::write (handle, sourceBuffer, numBytesToWrite)) < 0
  6167. && errno == EINTR)
  6168. {
  6169. }
  6170. return result;
  6171. #endif
  6172. }
  6173. int StreamingSocket::waitUntilReady (const bool readyForReading,
  6174. const int timeoutMsecs) const
  6175. {
  6176. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6177. : -1;
  6178. }
  6179. bool StreamingSocket::bindToPort (const int port)
  6180. {
  6181. return bindSocketToPort (handle, port);
  6182. }
  6183. bool StreamingSocket::connect (const String& remoteHostName,
  6184. const int remotePortNumber,
  6185. const int timeOutMillisecs)
  6186. {
  6187. if (isListener)
  6188. {
  6189. jassertfalse // a listener socket can't connect to another one!
  6190. return false;
  6191. }
  6192. if (connected)
  6193. close();
  6194. hostName = remoteHostName;
  6195. portNumber = remotePortNumber;
  6196. isListener = false;
  6197. connected = connectSocket (handle, false, 0, remoteHostName,
  6198. remotePortNumber, timeOutMillisecs);
  6199. if (! (connected && resetSocketOptions (handle, false, false)))
  6200. {
  6201. close();
  6202. return false;
  6203. }
  6204. return true;
  6205. }
  6206. void StreamingSocket::close()
  6207. {
  6208. #if JUCE_WINDOWS
  6209. closesocket (handle);
  6210. connected = false;
  6211. #else
  6212. if (connected)
  6213. {
  6214. connected = false;
  6215. if (isListener)
  6216. {
  6217. // need to do this to interrupt the accept() function..
  6218. StreamingSocket temp;
  6219. temp.connect ("localhost", portNumber, 1000);
  6220. }
  6221. }
  6222. ::close (handle);
  6223. #endif
  6224. hostName = String::empty;
  6225. portNumber = 0;
  6226. handle = -1;
  6227. isListener = false;
  6228. }
  6229. bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName)
  6230. {
  6231. if (connected)
  6232. close();
  6233. hostName = "listener";
  6234. portNumber = newPortNumber;
  6235. isListener = true;
  6236. struct sockaddr_in servTmpAddr;
  6237. zerostruct (servTmpAddr);
  6238. servTmpAddr.sin_family = PF_INET;
  6239. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6240. if (localHostName.isNotEmpty())
  6241. servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8());
  6242. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6243. handle = (int) socket (AF_INET, SOCK_STREAM, 0);
  6244. if (handle < 0)
  6245. return false;
  6246. const int reuse = 1;
  6247. setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
  6248. if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
  6249. || listen (handle, SOMAXCONN) < 0)
  6250. {
  6251. close();
  6252. return false;
  6253. }
  6254. connected = true;
  6255. return true;
  6256. }
  6257. StreamingSocket* StreamingSocket::waitForNextConnection() const
  6258. {
  6259. jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
  6260. // prepare this socket as a listener.
  6261. if (connected && isListener)
  6262. {
  6263. struct sockaddr address;
  6264. juce_socklen_t len = sizeof (sockaddr);
  6265. const int newSocket = (int) accept (handle, &address, &len);
  6266. if (newSocket >= 0 && connected)
  6267. return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6268. portNumber, newSocket);
  6269. }
  6270. return 0;
  6271. }
  6272. bool StreamingSocket::isLocal() const throw()
  6273. {
  6274. return hostName == T("127.0.0.1");
  6275. }
  6276. DatagramSocket::DatagramSocket (const int localPortNumber, const bool allowBroadcast_)
  6277. : portNumber (0),
  6278. handle (-1),
  6279. connected (true),
  6280. allowBroadcast (allowBroadcast_),
  6281. serverAddress (0)
  6282. {
  6283. #if JUCE_WINDOWS
  6284. initWin32Sockets();
  6285. #endif
  6286. handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
  6287. bindToPort (localPortNumber);
  6288. }
  6289. DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_,
  6290. const int handle_, const int localPortNumber)
  6291. : hostName (hostName_),
  6292. portNumber (portNumber_),
  6293. handle (handle_),
  6294. connected (true),
  6295. allowBroadcast (false),
  6296. serverAddress (0)
  6297. {
  6298. #if JUCE_WINDOWS
  6299. initWin32Sockets();
  6300. #endif
  6301. resetSocketOptions (handle_, true, allowBroadcast);
  6302. bindToPort (localPortNumber);
  6303. }
  6304. DatagramSocket::~DatagramSocket()
  6305. {
  6306. close();
  6307. delete ((struct sockaddr_in*) serverAddress);
  6308. serverAddress = 0;
  6309. }
  6310. void DatagramSocket::close()
  6311. {
  6312. #if JUCE_WINDOWS
  6313. closesocket (handle);
  6314. connected = false;
  6315. #else
  6316. connected = false;
  6317. ::close (handle);
  6318. #endif
  6319. hostName = String::empty;
  6320. portNumber = 0;
  6321. handle = -1;
  6322. }
  6323. bool DatagramSocket::bindToPort (const int port)
  6324. {
  6325. return bindSocketToPort (handle, port);
  6326. }
  6327. bool DatagramSocket::connect (const String& remoteHostName,
  6328. const int remotePortNumber,
  6329. const int timeOutMillisecs)
  6330. {
  6331. if (connected)
  6332. close();
  6333. hostName = remoteHostName;
  6334. portNumber = remotePortNumber;
  6335. connected = connectSocket (handle, true, &serverAddress,
  6336. remoteHostName, remotePortNumber,
  6337. timeOutMillisecs);
  6338. if (! (connected && resetSocketOptions (handle, true, allowBroadcast)))
  6339. {
  6340. close();
  6341. return false;
  6342. }
  6343. return true;
  6344. }
  6345. DatagramSocket* DatagramSocket::waitForNextConnection() const
  6346. {
  6347. struct sockaddr address;
  6348. juce_socklen_t len = sizeof (sockaddr);
  6349. while (waitUntilReady (true, -1) == 1)
  6350. {
  6351. char buf[1];
  6352. if (recvfrom (handle, buf, 0, 0, &address, &len) > 0)
  6353. {
  6354. return new DatagramSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6355. ntohs (((struct sockaddr_in*) &address)->sin_port),
  6356. -1, -1);
  6357. }
  6358. }
  6359. return 0;
  6360. }
  6361. int DatagramSocket::waitUntilReady (const bool readyForReading,
  6362. const int timeoutMsecs) const
  6363. {
  6364. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6365. : -1;
  6366. }
  6367. int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6368. {
  6369. return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6370. : -1;
  6371. }
  6372. int DatagramSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6373. {
  6374. // You need to call connect() first to set the server address..
  6375. jassert (serverAddress != 0 && connected);
  6376. return connected ? (int) sendto (handle, (const char*) sourceBuffer,
  6377. numBytesToWrite, 0,
  6378. (const struct sockaddr*) serverAddress,
  6379. sizeof (struct sockaddr_in))
  6380. : -1;
  6381. }
  6382. bool DatagramSocket::isLocal() const throw()
  6383. {
  6384. return hostName == T("127.0.0.1");
  6385. }
  6386. END_JUCE_NAMESPACE
  6387. /*** End of inlined file: juce_Socket.cpp ***/
  6388. /*** Start of inlined file: juce_URL.cpp ***/
  6389. BEGIN_JUCE_NAMESPACE
  6390. URL::URL()
  6391. {
  6392. }
  6393. URL::URL (const String& url_)
  6394. : url (url_)
  6395. {
  6396. int i = url.indexOfChar (T('?'));
  6397. if (i >= 0)
  6398. {
  6399. do
  6400. {
  6401. const int nextAmp = url.indexOfChar (i + 1, T('&'));
  6402. const int equalsPos = url.indexOfChar (i + 1, T('='));
  6403. if (equalsPos > i + 1)
  6404. {
  6405. if (nextAmp < 0)
  6406. {
  6407. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6408. removeEscapeChars (url.substring (equalsPos + 1)));
  6409. }
  6410. else if (nextAmp > 0 && equalsPos < nextAmp)
  6411. {
  6412. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6413. removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
  6414. }
  6415. }
  6416. i = nextAmp;
  6417. }
  6418. while (i >= 0);
  6419. url = url.upToFirstOccurrenceOf (T("?"), false, false);
  6420. }
  6421. }
  6422. URL::URL (const URL& other)
  6423. : url (other.url),
  6424. postData (other.postData),
  6425. parameters (other.parameters),
  6426. filesToUpload (other.filesToUpload),
  6427. mimeTypes (other.mimeTypes)
  6428. {
  6429. }
  6430. URL& URL::operator= (const URL& other)
  6431. {
  6432. url = other.url;
  6433. postData = other.postData;
  6434. parameters = other.parameters;
  6435. filesToUpload = other.filesToUpload;
  6436. mimeTypes = other.mimeTypes;
  6437. return *this;
  6438. }
  6439. URL::~URL()
  6440. {
  6441. }
  6442. static const String getMangledParameters (const StringPairArray& parameters)
  6443. {
  6444. String p;
  6445. for (int i = 0; i < parameters.size(); ++i)
  6446. {
  6447. if (i > 0)
  6448. p += T("&");
  6449. p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
  6450. << T("=")
  6451. << URL::addEscapeChars (parameters.getAllValues() [i], true);
  6452. }
  6453. return p;
  6454. }
  6455. const String URL::toString (const bool includeGetParameters) const
  6456. {
  6457. if (includeGetParameters && parameters.size() > 0)
  6458. return url + T("?") + getMangledParameters (parameters);
  6459. else
  6460. return url;
  6461. }
  6462. bool URL::isWellFormed() const
  6463. {
  6464. //xxx TODO
  6465. return url.isNotEmpty();
  6466. }
  6467. static int findStartOfDomain (const String& url)
  6468. {
  6469. int i = 0;
  6470. while (CharacterFunctions::isLetterOrDigit (url[i])
  6471. || CharacterFunctions::indexOfChar (T("+-."), url[i], false) >= 0)
  6472. ++i;
  6473. return url[i] == T(':') ? i + 1 : 0;
  6474. }
  6475. const String URL::getDomain() const
  6476. {
  6477. int start = findStartOfDomain (url);
  6478. while (url[start] == T('/'))
  6479. ++start;
  6480. const int end1 = url.indexOfChar (start, T('/'));
  6481. const int end2 = url.indexOfChar (start, T(':'));
  6482. const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2)
  6483. : jmin (end1, end2);
  6484. return url.substring (start, end);
  6485. }
  6486. const String URL::getSubPath() const
  6487. {
  6488. int start = findStartOfDomain (url);
  6489. while (url[start] == T('/'))
  6490. ++start;
  6491. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6492. return startOfPath <= 0 ? String::empty
  6493. : url.substring (startOfPath);
  6494. }
  6495. const String URL::getScheme() const
  6496. {
  6497. return url.substring (0, findStartOfDomain (url) - 1);
  6498. }
  6499. const URL URL::withNewSubPath (const String& newPath) const
  6500. {
  6501. int start = findStartOfDomain (url);
  6502. while (url[start] == T('/'))
  6503. ++start;
  6504. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6505. URL u (*this);
  6506. if (startOfPath > 0)
  6507. u.url = url.substring (0, startOfPath);
  6508. if (! u.url.endsWithChar (T('/')))
  6509. u.url << '/';
  6510. if (newPath.startsWithChar (T('/')))
  6511. u.url << newPath.substring (1);
  6512. else
  6513. u.url << newPath;
  6514. return u;
  6515. }
  6516. bool URL::isProbablyAWebsiteURL (const String& possibleURL)
  6517. {
  6518. if (possibleURL.startsWithIgnoreCase (T("http:"))
  6519. || possibleURL.startsWithIgnoreCase (T("ftp:")))
  6520. return true;
  6521. if (possibleURL.startsWithIgnoreCase (T("file:"))
  6522. || possibleURL.containsChar (T('@'))
  6523. || possibleURL.endsWithChar (T('.'))
  6524. || (! possibleURL.containsChar (T('.'))))
  6525. return false;
  6526. if (possibleURL.startsWithIgnoreCase (T("www."))
  6527. && possibleURL.substring (5).containsChar (T('.')))
  6528. return true;
  6529. const char* commonTLDs[] = { "com", "net", "org", "uk", "de", "fr", "jp" };
  6530. for (int i = 0; i < numElementsInArray (commonTLDs); ++i)
  6531. if ((possibleURL + T("/")).containsIgnoreCase (T(".") + String (commonTLDs[i]) + T("/")))
  6532. return true;
  6533. return false;
  6534. }
  6535. bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
  6536. {
  6537. const int atSign = possibleEmailAddress.indexOfChar (T('@'));
  6538. return atSign > 0
  6539. && possibleEmailAddress.lastIndexOfChar (T('.')) > (atSign + 1)
  6540. && (! possibleEmailAddress.endsWithChar (T('.')));
  6541. }
  6542. void* juce_openInternetFile (const String& url,
  6543. const String& headers,
  6544. const MemoryBlock& optionalPostData,
  6545. const bool isPost,
  6546. URL::OpenStreamProgressCallback* callback,
  6547. void* callbackContext,
  6548. int timeOutMs);
  6549. void juce_closeInternetFile (void* handle);
  6550. int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
  6551. int juce_seekInInternetFile (void* handle, int newPosition);
  6552. int64 juce_getInternetFileContentLength (void* handle);
  6553. class WebInputStream : public InputStream
  6554. {
  6555. public:
  6556. WebInputStream (const URL& url,
  6557. const bool isPost_,
  6558. URL::OpenStreamProgressCallback* const progressCallback_,
  6559. void* const progressCallbackContext_,
  6560. const String& extraHeaders,
  6561. int timeOutMs_)
  6562. : position (0),
  6563. finished (false),
  6564. isPost (isPost_),
  6565. progressCallback (progressCallback_),
  6566. progressCallbackContext (progressCallbackContext_),
  6567. timeOutMs (timeOutMs_)
  6568. {
  6569. server = url.toString (! isPost);
  6570. if (isPost_)
  6571. createHeadersAndPostData (url);
  6572. headers += extraHeaders;
  6573. if (! headers.endsWithChar (T('\n')))
  6574. headers << "\r\n";
  6575. handle = juce_openInternetFile (server, headers, postData, isPost,
  6576. progressCallback_, progressCallbackContext_,
  6577. timeOutMs);
  6578. }
  6579. ~WebInputStream()
  6580. {
  6581. juce_closeInternetFile (handle);
  6582. }
  6583. bool isError() const
  6584. {
  6585. return handle == 0;
  6586. }
  6587. int64 getTotalLength()
  6588. {
  6589. return juce_getInternetFileContentLength (handle);
  6590. }
  6591. bool isExhausted()
  6592. {
  6593. return finished;
  6594. }
  6595. int read (void* dest, int bytes)
  6596. {
  6597. if (finished || isError())
  6598. {
  6599. return 0;
  6600. }
  6601. else
  6602. {
  6603. const int bytesRead = juce_readFromInternetFile (handle, dest, bytes);
  6604. position += bytesRead;
  6605. if (bytesRead == 0)
  6606. finished = true;
  6607. return bytesRead;
  6608. }
  6609. }
  6610. int64 getPosition()
  6611. {
  6612. return position;
  6613. }
  6614. bool setPosition (int64 wantedPos)
  6615. {
  6616. if (wantedPos != position)
  6617. {
  6618. finished = false;
  6619. const int actualPos = juce_seekInInternetFile (handle, (int) wantedPos);
  6620. if (actualPos == wantedPos)
  6621. {
  6622. position = wantedPos;
  6623. }
  6624. else
  6625. {
  6626. if (wantedPos < position)
  6627. {
  6628. juce_closeInternetFile (handle);
  6629. position = 0;
  6630. finished = false;
  6631. handle = juce_openInternetFile (server, headers, postData, isPost,
  6632. progressCallback, progressCallbackContext,
  6633. timeOutMs);
  6634. }
  6635. skipNextBytes (wantedPos - position);
  6636. }
  6637. }
  6638. return true;
  6639. }
  6640. juce_UseDebuggingNewOperator
  6641. private:
  6642. String server, headers;
  6643. MemoryBlock postData;
  6644. int64 position;
  6645. bool finished;
  6646. const bool isPost;
  6647. void* handle;
  6648. URL::OpenStreamProgressCallback* const progressCallback;
  6649. void* const progressCallbackContext;
  6650. const int timeOutMs;
  6651. void createHeadersAndPostData (const URL& url)
  6652. {
  6653. if (url.getFilesToUpload().size() > 0)
  6654. {
  6655. // need to upload some files, so do it as multi-part...
  6656. String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
  6657. headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
  6658. appendUTF8ToPostData ("--" + boundary);
  6659. int i;
  6660. for (i = 0; i < url.getParameters().size(); ++i)
  6661. {
  6662. String s;
  6663. s << "\r\nContent-Disposition: form-data; name=\""
  6664. << url.getParameters().getAllKeys() [i]
  6665. << "\"\r\n\r\n"
  6666. << url.getParameters().getAllValues() [i]
  6667. << "\r\n--"
  6668. << boundary;
  6669. appendUTF8ToPostData (s);
  6670. }
  6671. for (i = 0; i < url.getFilesToUpload().size(); ++i)
  6672. {
  6673. const File f (url.getFilesToUpload().getAllValues() [i]);
  6674. const String paramName (url.getFilesToUpload().getAllKeys() [i]);
  6675. String s;
  6676. s << "\r\nContent-Disposition: form-data; name=\""
  6677. << paramName
  6678. << "\"; filename=\""
  6679. << f.getFileName()
  6680. << "\"\r\n";
  6681. const String mimeType (url.getMimeTypesOfUploadFiles()
  6682. .getValue (paramName, String::empty));
  6683. if (mimeType.isNotEmpty())
  6684. s << "Content-Type: " << mimeType << "\r\n";
  6685. s << "Content-Transfer-Encoding: binary\r\n\r\n";
  6686. appendUTF8ToPostData (s);
  6687. f.loadFileAsData (postData);
  6688. s = "\r\n--" + boundary;
  6689. appendUTF8ToPostData (s);
  6690. }
  6691. appendUTF8ToPostData ("--\r\n");
  6692. }
  6693. else
  6694. {
  6695. appendUTF8ToPostData (getMangledParameters (url.getParameters()));
  6696. appendUTF8ToPostData (url.getPostData());
  6697. // just a short text attachment, so use simple url encoding..
  6698. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
  6699. + String ((unsigned int) postData.getSize())
  6700. + "\r\n";
  6701. }
  6702. }
  6703. void appendUTF8ToPostData (const String& text)
  6704. {
  6705. postData.append (text.toUTF8(),
  6706. (int) strlen (text.toUTF8()));
  6707. }
  6708. WebInputStream (const WebInputStream&);
  6709. WebInputStream& operator= (const WebInputStream&);
  6710. };
  6711. InputStream* URL::createInputStream (const bool usePostCommand,
  6712. OpenStreamProgressCallback* const progressCallback,
  6713. void* const progressCallbackContext,
  6714. const String& extraHeaders,
  6715. const int timeOutMs) const
  6716. {
  6717. ScopedPointer <WebInputStream> wi (new WebInputStream (*this, usePostCommand,
  6718. progressCallback, progressCallbackContext,
  6719. extraHeaders,
  6720. timeOutMs));
  6721. return wi->isError() ? 0 : wi.release();
  6722. }
  6723. bool URL::readEntireBinaryStream (MemoryBlock& destData,
  6724. const bool usePostCommand) const
  6725. {
  6726. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6727. if (in != 0)
  6728. {
  6729. in->readIntoMemoryBlock (destData, -1);
  6730. return true;
  6731. }
  6732. return false;
  6733. }
  6734. const String URL::readEntireTextStream (const bool usePostCommand) const
  6735. {
  6736. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6737. if (in != 0)
  6738. return in->readEntireStreamAsString();
  6739. return String::empty;
  6740. }
  6741. XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
  6742. {
  6743. XmlDocument doc (readEntireTextStream (usePostCommand));
  6744. return doc.getDocumentElement();
  6745. }
  6746. const URL URL::withParameter (const String& parameterName,
  6747. const String& parameterValue) const
  6748. {
  6749. URL u (*this);
  6750. u.parameters.set (parameterName, parameterValue);
  6751. return u;
  6752. }
  6753. const URL URL::withFileToUpload (const String& parameterName,
  6754. const File& fileToUpload,
  6755. const String& mimeType) const
  6756. {
  6757. jassert (mimeType.isNotEmpty()); // You need to supply a mime type!
  6758. URL u (*this);
  6759. u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
  6760. u.mimeTypes.set (parameterName, mimeType);
  6761. return u;
  6762. }
  6763. const URL URL::withPOSTData (const String& postData_) const
  6764. {
  6765. URL u (*this);
  6766. u.postData = postData_;
  6767. return u;
  6768. }
  6769. const StringPairArray& URL::getParameters() const
  6770. {
  6771. return parameters;
  6772. }
  6773. const StringPairArray& URL::getFilesToUpload() const
  6774. {
  6775. return filesToUpload;
  6776. }
  6777. const StringPairArray& URL::getMimeTypesOfUploadFiles() const
  6778. {
  6779. return mimeTypes;
  6780. }
  6781. const String URL::removeEscapeChars (const String& s)
  6782. {
  6783. const int len = s.length();
  6784. HeapBlock <char> resultUTF8 (len * 4);
  6785. char* r = resultUTF8;
  6786. for (int i = 0; i < len; ++i)
  6787. {
  6788. char c = (char) s[i];
  6789. if (c == 0)
  6790. break;
  6791. if (c == '+')
  6792. {
  6793. c = ' ';
  6794. }
  6795. else if (c == '%')
  6796. {
  6797. c = (char) s.substring (i + 1, i + 3).getHexValue32();
  6798. i += 2;
  6799. }
  6800. *r++ = c;
  6801. }
  6802. return String::fromUTF8 (resultUTF8);
  6803. }
  6804. const String URL::addEscapeChars (const String& s, const bool isParameter)
  6805. {
  6806. String result;
  6807. result.preallocateStorage (s.length() + 8);
  6808. const char* utf8 = s.toUTF8();
  6809. const char* legalChars = isParameter ? "_-.*!'()"
  6810. : "_-$.*!'(),";
  6811. while (*utf8 != 0)
  6812. {
  6813. const char c = *utf8++;
  6814. if (CharacterFunctions::isLetterOrDigit (c)
  6815. || CharacterFunctions::indexOfChar (legalChars, c, false) >= 0)
  6816. {
  6817. result << c;
  6818. }
  6819. else
  6820. {
  6821. const int v = (int) (uint8) c;
  6822. if (v < 0x10)
  6823. result << T("%0");
  6824. else
  6825. result << T('%');
  6826. result << String::toHexString (v);
  6827. }
  6828. }
  6829. return result;
  6830. }
  6831. extern bool juce_launchFile (const String& fileName, const String& parameters);
  6832. bool URL::launchInDefaultBrowser() const
  6833. {
  6834. String u (toString (true));
  6835. if (u.contains (T("@")) && ! u.contains (T(":")))
  6836. u = "mailto:" + u;
  6837. return juce_launchFile (u, String::empty);
  6838. }
  6839. END_JUCE_NAMESPACE
  6840. /*** End of inlined file: juce_URL.cpp ***/
  6841. /*** Start of inlined file: juce_BufferedInputStream.cpp ***/
  6842. BEGIN_JUCE_NAMESPACE
  6843. BufferedInputStream::BufferedInputStream (InputStream* const source_,
  6844. const int bufferSize_,
  6845. const bool deleteSourceWhenDestroyed)
  6846. : source (source_),
  6847. sourceToDelete (deleteSourceWhenDestroyed ? source_ : 0),
  6848. bufferSize (jmax (256, bufferSize_)),
  6849. position (source_->getPosition()),
  6850. lastReadPos (0),
  6851. bufferOverlap (128)
  6852. {
  6853. const int sourceSize = (int) source_->getTotalLength();
  6854. if (sourceSize >= 0)
  6855. bufferSize = jmin (jmax (32, sourceSize), bufferSize);
  6856. bufferStart = position;
  6857. buffer.malloc (bufferSize);
  6858. }
  6859. BufferedInputStream::~BufferedInputStream()
  6860. {
  6861. }
  6862. int64 BufferedInputStream::getTotalLength()
  6863. {
  6864. return source->getTotalLength();
  6865. }
  6866. int64 BufferedInputStream::getPosition()
  6867. {
  6868. return position;
  6869. }
  6870. bool BufferedInputStream::setPosition (int64 newPosition)
  6871. {
  6872. position = jmax ((int64) 0, newPosition);
  6873. return true;
  6874. }
  6875. bool BufferedInputStream::isExhausted()
  6876. {
  6877. return (position >= lastReadPos)
  6878. && source->isExhausted();
  6879. }
  6880. void BufferedInputStream::ensureBuffered()
  6881. {
  6882. const int64 bufferEndOverlap = lastReadPos - bufferOverlap;
  6883. if (position < bufferStart || position >= bufferEndOverlap)
  6884. {
  6885. int bytesRead;
  6886. if (position < lastReadPos
  6887. && position >= bufferEndOverlap
  6888. && position >= bufferStart)
  6889. {
  6890. const int bytesToKeep = (int) (lastReadPos - position);
  6891. memmove (buffer, buffer + (int) (position - bufferStart), bytesToKeep);
  6892. bufferStart = position;
  6893. bytesRead = source->read (buffer + bytesToKeep,
  6894. bufferSize - bytesToKeep);
  6895. lastReadPos += bytesRead;
  6896. bytesRead += bytesToKeep;
  6897. }
  6898. else
  6899. {
  6900. bufferStart = position;
  6901. source->setPosition (bufferStart);
  6902. bytesRead = source->read (buffer, bufferSize);
  6903. lastReadPos = bufferStart + bytesRead;
  6904. }
  6905. while (bytesRead < bufferSize)
  6906. buffer [bytesRead++] = 0;
  6907. }
  6908. }
  6909. int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
  6910. {
  6911. if (position >= bufferStart
  6912. && position + maxBytesToRead <= lastReadPos)
  6913. {
  6914. memcpy (destBuffer, buffer + (int) (position - bufferStart), maxBytesToRead);
  6915. position += maxBytesToRead;
  6916. return maxBytesToRead;
  6917. }
  6918. else
  6919. {
  6920. if (position < bufferStart || position >= lastReadPos)
  6921. ensureBuffered();
  6922. int bytesRead = 0;
  6923. while (maxBytesToRead > 0)
  6924. {
  6925. const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
  6926. if (bytesAvailable > 0)
  6927. {
  6928. memcpy (destBuffer, buffer + (int) (position - bufferStart), bytesAvailable);
  6929. maxBytesToRead -= bytesAvailable;
  6930. bytesRead += bytesAvailable;
  6931. position += bytesAvailable;
  6932. destBuffer = (void*) (((char*) destBuffer) + bytesAvailable);
  6933. }
  6934. const int64 oldLastReadPos = lastReadPos;
  6935. ensureBuffered();
  6936. if (oldLastReadPos == lastReadPos)
  6937. break; // if ensureBuffered() failed to read any more data, bail out
  6938. if (isExhausted())
  6939. break;
  6940. }
  6941. return bytesRead;
  6942. }
  6943. }
  6944. const String BufferedInputStream::readString()
  6945. {
  6946. if (position >= bufferStart
  6947. && position < lastReadPos)
  6948. {
  6949. const int maxChars = (int) (lastReadPos - position);
  6950. const char* const src = buffer + (int) (position - bufferStart);
  6951. for (int i = 0; i < maxChars; ++i)
  6952. {
  6953. if (src[i] == 0)
  6954. {
  6955. position += i + 1;
  6956. return String::fromUTF8 (src, i);
  6957. }
  6958. }
  6959. }
  6960. return InputStream::readString();
  6961. }
  6962. END_JUCE_NAMESPACE
  6963. /*** End of inlined file: juce_BufferedInputStream.cpp ***/
  6964. /*** Start of inlined file: juce_FileInputSource.cpp ***/
  6965. BEGIN_JUCE_NAMESPACE
  6966. FileInputSource::FileInputSource (const File& file_)
  6967. : file (file_)
  6968. {
  6969. }
  6970. FileInputSource::~FileInputSource()
  6971. {
  6972. }
  6973. InputStream* FileInputSource::createInputStream()
  6974. {
  6975. return file.createInputStream();
  6976. }
  6977. InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath)
  6978. {
  6979. return file.getSiblingFile (relatedItemPath).createInputStream();
  6980. }
  6981. int64 FileInputSource::hashCode() const
  6982. {
  6983. return file.hashCode();
  6984. }
  6985. END_JUCE_NAMESPACE
  6986. /*** End of inlined file: juce_FileInputSource.cpp ***/
  6987. /*** Start of inlined file: juce_MemoryInputStream.cpp ***/
  6988. BEGIN_JUCE_NAMESPACE
  6989. MemoryInputStream::MemoryInputStream (const void* const sourceData,
  6990. const size_t sourceDataSize,
  6991. const bool keepInternalCopy)
  6992. : data ((const char*) sourceData),
  6993. dataSize (sourceDataSize),
  6994. position (0)
  6995. {
  6996. if (keepInternalCopy)
  6997. {
  6998. internalCopy.append (data, sourceDataSize);
  6999. data = (const char*) internalCopy.getData();
  7000. }
  7001. }
  7002. MemoryInputStream::~MemoryInputStream()
  7003. {
  7004. }
  7005. int64 MemoryInputStream::getTotalLength()
  7006. {
  7007. return dataSize;
  7008. }
  7009. int MemoryInputStream::read (void* buffer, int howMany)
  7010. {
  7011. jassert (howMany >= 0);
  7012. const int num = jmin (howMany, (int) (dataSize - position));
  7013. memcpy (buffer, data + position, num);
  7014. position += num;
  7015. return (int) num;
  7016. }
  7017. bool MemoryInputStream::isExhausted()
  7018. {
  7019. return (position >= dataSize);
  7020. }
  7021. bool MemoryInputStream::setPosition (int64 pos)
  7022. {
  7023. position = (int) jlimit ((int64) 0, (int64) dataSize, pos);
  7024. return true;
  7025. }
  7026. int64 MemoryInputStream::getPosition()
  7027. {
  7028. return position;
  7029. }
  7030. END_JUCE_NAMESPACE
  7031. /*** End of inlined file: juce_MemoryInputStream.cpp ***/
  7032. /*** Start of inlined file: juce_MemoryOutputStream.cpp ***/
  7033. BEGIN_JUCE_NAMESPACE
  7034. MemoryOutputStream::MemoryOutputStream (const size_t initialSize,
  7035. const size_t blockSizeToIncreaseBy,
  7036. MemoryBlock* const memoryBlockToWriteTo) throw()
  7037. : data (memoryBlockToWriteTo),
  7038. position (0),
  7039. size (0),
  7040. blockSize (jmax ((size_t) 16, blockSizeToIncreaseBy))
  7041. {
  7042. if (data == 0)
  7043. dataToDelete = data = new MemoryBlock (initialSize);
  7044. else
  7045. data->setSize (initialSize, false);
  7046. }
  7047. MemoryOutputStream::~MemoryOutputStream() throw()
  7048. {
  7049. flush();
  7050. }
  7051. void MemoryOutputStream::flush()
  7052. {
  7053. if (dataToDelete == 0)
  7054. data->setSize (size, false);
  7055. }
  7056. void MemoryOutputStream::reset() throw()
  7057. {
  7058. position = 0;
  7059. size = 0;
  7060. }
  7061. bool MemoryOutputStream::write (const void* buffer, int howMany)
  7062. {
  7063. if (howMany > 0)
  7064. {
  7065. size_t storageNeeded = position + howMany;
  7066. if (storageNeeded >= data->getSize())
  7067. {
  7068. // if we need more space, increase the block by at least 10%..
  7069. storageNeeded += jmax (blockSize, storageNeeded / 10);
  7070. storageNeeded = storageNeeded - (storageNeeded % blockSize) + blockSize;
  7071. data->ensureSize (storageNeeded);
  7072. }
  7073. data->copyFrom (buffer, (int) position, howMany);
  7074. position += howMany;
  7075. size = jmax (size, position);
  7076. }
  7077. return true;
  7078. }
  7079. const char* MemoryOutputStream::getData() const throw()
  7080. {
  7081. if (data->getSize() > size)
  7082. ((char*) data->getData()) [size] = 0;
  7083. return (const char*) data->getData();
  7084. }
  7085. size_t MemoryOutputStream::getDataSize() const throw()
  7086. {
  7087. return size;
  7088. }
  7089. int64 MemoryOutputStream::getPosition()
  7090. {
  7091. return position;
  7092. }
  7093. bool MemoryOutputStream::setPosition (int64 newPosition)
  7094. {
  7095. if (newPosition <= (int64) size)
  7096. {
  7097. // ok to seek backwards
  7098. position = jlimit ((size_t) 0, size, (size_t) newPosition);
  7099. return true;
  7100. }
  7101. else
  7102. {
  7103. // trying to make it bigger isn't a good thing to do..
  7104. return false;
  7105. }
  7106. }
  7107. END_JUCE_NAMESPACE
  7108. /*** End of inlined file: juce_MemoryOutputStream.cpp ***/
  7109. /*** Start of inlined file: juce_SubregionStream.cpp ***/
  7110. BEGIN_JUCE_NAMESPACE
  7111. SubregionStream::SubregionStream (InputStream* const sourceStream,
  7112. const int64 startPositionInSourceStream_,
  7113. const int64 lengthOfSourceStream_,
  7114. const bool deleteSourceWhenDestroyed) throw()
  7115. : source (sourceStream),
  7116. startPositionInSourceStream (startPositionInSourceStream_),
  7117. lengthOfSourceStream (lengthOfSourceStream_)
  7118. {
  7119. if (deleteSourceWhenDestroyed)
  7120. sourceToDelete = source;
  7121. setPosition (0);
  7122. }
  7123. SubregionStream::~SubregionStream() throw()
  7124. {
  7125. }
  7126. int64 SubregionStream::getTotalLength()
  7127. {
  7128. const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
  7129. return (lengthOfSourceStream >= 0) ? jmin (lengthOfSourceStream, srcLen)
  7130. : srcLen;
  7131. }
  7132. int64 SubregionStream::getPosition()
  7133. {
  7134. return source->getPosition() - startPositionInSourceStream;
  7135. }
  7136. bool SubregionStream::setPosition (int64 newPosition)
  7137. {
  7138. return source->setPosition (jmax ((int64) 0, newPosition + startPositionInSourceStream));
  7139. }
  7140. int SubregionStream::read (void* destBuffer, int maxBytesToRead)
  7141. {
  7142. if (lengthOfSourceStream < 0)
  7143. {
  7144. return source->read (destBuffer, maxBytesToRead);
  7145. }
  7146. else
  7147. {
  7148. maxBytesToRead = (int) jmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
  7149. if (maxBytesToRead <= 0)
  7150. return 0;
  7151. return source->read (destBuffer, maxBytesToRead);
  7152. }
  7153. }
  7154. bool SubregionStream::isExhausted()
  7155. {
  7156. if (lengthOfSourceStream >= 0)
  7157. return (getPosition() >= lengthOfSourceStream) || source->isExhausted();
  7158. else
  7159. return source->isExhausted();
  7160. }
  7161. END_JUCE_NAMESPACE
  7162. /*** End of inlined file: juce_SubregionStream.cpp ***/
  7163. /*** Start of inlined file: juce_PerformanceCounter.cpp ***/
  7164. BEGIN_JUCE_NAMESPACE
  7165. PerformanceCounter::PerformanceCounter (const String& name_,
  7166. int runsPerPrintout,
  7167. const File& loggingFile)
  7168. : name (name_),
  7169. numRuns (0),
  7170. runsPerPrint (runsPerPrintout),
  7171. totalTime (0),
  7172. outputFile (loggingFile)
  7173. {
  7174. if (outputFile != File::nonexistent)
  7175. {
  7176. String s ("**** Counter for \"");
  7177. s << name_ << "\" started at: "
  7178. << Time::getCurrentTime().toString (true, true)
  7179. << "\r\n";
  7180. outputFile.appendText (s, false, false);
  7181. }
  7182. }
  7183. PerformanceCounter::~PerformanceCounter()
  7184. {
  7185. printStatistics();
  7186. }
  7187. void PerformanceCounter::start()
  7188. {
  7189. started = Time::getHighResolutionTicks();
  7190. }
  7191. void PerformanceCounter::stop()
  7192. {
  7193. const int64 now = Time::getHighResolutionTicks();
  7194. totalTime += 1000.0 * Time::highResolutionTicksToSeconds (now - started);
  7195. if (++numRuns == runsPerPrint)
  7196. printStatistics();
  7197. }
  7198. void PerformanceCounter::printStatistics()
  7199. {
  7200. if (numRuns > 0)
  7201. {
  7202. String s ("Performance count for \"");
  7203. s << name << "\" - average over " << numRuns << " run(s) = ";
  7204. const int micros = (int) (totalTime * (1000.0 / numRuns));
  7205. if (micros > 10000)
  7206. s << (micros/1000) << " millisecs";
  7207. else
  7208. s << micros << " microsecs";
  7209. s << ", total = " << String (totalTime / 1000, 5) << " seconds";
  7210. Logger::outputDebugString (s);
  7211. s << "\r\n";
  7212. if (outputFile != File::nonexistent)
  7213. outputFile.appendText (s, false, false);
  7214. numRuns = 0;
  7215. totalTime = 0;
  7216. }
  7217. }
  7218. END_JUCE_NAMESPACE
  7219. /*** End of inlined file: juce_PerformanceCounter.cpp ***/
  7220. /*** Start of inlined file: juce_Uuid.cpp ***/
  7221. BEGIN_JUCE_NAMESPACE
  7222. Uuid::Uuid()
  7223. {
  7224. // Mix up any available MAC addresses with some time-based pseudo-random numbers
  7225. // to make it very very unlikely that two UUIDs will ever be the same..
  7226. static int64 macAddresses[2];
  7227. static bool hasCheckedMacAddresses = false;
  7228. if (! hasCheckedMacAddresses)
  7229. {
  7230. hasCheckedMacAddresses = true;
  7231. SystemStats::getMACAddresses (macAddresses, 2);
  7232. }
  7233. value.asInt64[0] = macAddresses[0];
  7234. value.asInt64[1] = macAddresses[1];
  7235. // We'll use both a local RNG that is re-seeded, plus the shared RNG,
  7236. // whose seed will carry over between calls to this method.
  7237. Random r (macAddresses[0] ^ macAddresses[1]
  7238. ^ Random::getSystemRandom().nextInt64());
  7239. for (int i = 4; --i >= 0;)
  7240. {
  7241. r.setSeedRandomly(); // calling this repeatedly improves randomness
  7242. value.asInt[i] ^= r.nextInt();
  7243. value.asInt[i] ^= Random::getSystemRandom().nextInt();
  7244. }
  7245. }
  7246. Uuid::~Uuid() throw()
  7247. {
  7248. }
  7249. Uuid::Uuid (const Uuid& other)
  7250. : value (other.value)
  7251. {
  7252. }
  7253. Uuid& Uuid::operator= (const Uuid& other)
  7254. {
  7255. value = other.value;
  7256. return *this;
  7257. }
  7258. bool Uuid::operator== (const Uuid& other) const
  7259. {
  7260. return memcmp (value.asBytes, other.value.asBytes, 16) == 0;
  7261. }
  7262. bool Uuid::operator!= (const Uuid& other) const
  7263. {
  7264. return ! operator== (other);
  7265. }
  7266. bool Uuid::isNull() const throw()
  7267. {
  7268. return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0);
  7269. }
  7270. const String Uuid::toString() const
  7271. {
  7272. return String::toHexString (value.asBytes, 16, 0);
  7273. }
  7274. Uuid::Uuid (const String& uuidString)
  7275. {
  7276. operator= (uuidString);
  7277. }
  7278. Uuid& Uuid::operator= (const String& uuidString)
  7279. {
  7280. int destIndex = 0;
  7281. int i = 0;
  7282. for (;;)
  7283. {
  7284. int byte = 0;
  7285. for (int loop = 2; --loop >= 0;)
  7286. {
  7287. byte <<= 4;
  7288. for (;;)
  7289. {
  7290. const tchar c = uuidString [i++];
  7291. if (c >= T('0') && c <= T('9'))
  7292. {
  7293. byte |= c - T('0');
  7294. break;
  7295. }
  7296. else if (c >= T('a') && c <= T('z'))
  7297. {
  7298. byte |= c - (T('a') - 10);
  7299. break;
  7300. }
  7301. else if (c >= T('A') && c <= T('Z'))
  7302. {
  7303. byte |= c - (T('A') - 10);
  7304. break;
  7305. }
  7306. else if (c == 0)
  7307. {
  7308. while (destIndex < 16)
  7309. value.asBytes [destIndex++] = 0;
  7310. return *this;
  7311. }
  7312. }
  7313. }
  7314. value.asBytes [destIndex++] = (uint8) byte;
  7315. }
  7316. }
  7317. Uuid::Uuid (const uint8* const rawData)
  7318. {
  7319. operator= (rawData);
  7320. }
  7321. Uuid& Uuid::operator= (const uint8* const rawData)
  7322. {
  7323. if (rawData != 0)
  7324. memcpy (value.asBytes, rawData, 16);
  7325. else
  7326. zeromem (value.asBytes, 16);
  7327. return *this;
  7328. }
  7329. END_JUCE_NAMESPACE
  7330. /*** End of inlined file: juce_Uuid.cpp ***/
  7331. /*** Start of inlined file: juce_ZipFile.cpp ***/
  7332. BEGIN_JUCE_NAMESPACE
  7333. class ZipFile::ZipEntryInfo
  7334. {
  7335. public:
  7336. ZipFile::ZipEntry entry;
  7337. int streamOffset;
  7338. int compressedSize;
  7339. bool compressed;
  7340. };
  7341. class ZipFile::ZipInputStream : public InputStream
  7342. {
  7343. public:
  7344. ZipInputStream (ZipFile& file_, ZipFile::ZipEntryInfo& zei)
  7345. : file (file_),
  7346. zipEntryInfo (zei),
  7347. pos (0),
  7348. headerSize (0),
  7349. inputStream (0)
  7350. {
  7351. inputStream = file_.inputStream;
  7352. if (file_.inputSource != 0)
  7353. {
  7354. inputStream = file.inputSource->createInputStream();
  7355. }
  7356. else
  7357. {
  7358. #ifdef JUCE_DEBUG
  7359. file_.numOpenStreams++;
  7360. #endif
  7361. }
  7362. char buffer [30];
  7363. if (inputStream != 0
  7364. && inputStream->setPosition (zei.streamOffset)
  7365. && inputStream->read (buffer, 30) == 30
  7366. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  7367. {
  7368. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  7369. + ByteOrder::littleEndianShort (buffer + 28);
  7370. }
  7371. }
  7372. ~ZipInputStream() throw()
  7373. {
  7374. #ifdef JUCE_DEBUG
  7375. if (inputStream != 0 && inputStream == file.inputStream)
  7376. file.numOpenStreams--;
  7377. #endif
  7378. if (inputStream != file.inputStream)
  7379. delete inputStream;
  7380. }
  7381. int64 getTotalLength() throw()
  7382. {
  7383. return zipEntryInfo.compressedSize;
  7384. }
  7385. int read (void* buffer, int howMany) throw()
  7386. {
  7387. if (headerSize <= 0)
  7388. return 0;
  7389. howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
  7390. if (inputStream == 0)
  7391. return 0;
  7392. int num;
  7393. if (inputStream == file.inputStream)
  7394. {
  7395. const ScopedLock sl (file.lock);
  7396. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7397. num = inputStream->read (buffer, howMany);
  7398. }
  7399. else
  7400. {
  7401. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7402. num = inputStream->read (buffer, howMany);
  7403. }
  7404. pos += num;
  7405. return num;
  7406. }
  7407. bool isExhausted() throw()
  7408. {
  7409. return headerSize <= 0 || pos >= zipEntryInfo.compressedSize;
  7410. }
  7411. int64 getPosition() throw()
  7412. {
  7413. return pos;
  7414. }
  7415. bool setPosition (int64 newPos) throw()
  7416. {
  7417. pos = jlimit ((int64) 0, (int64) zipEntryInfo.compressedSize, newPos);
  7418. return true;
  7419. }
  7420. private:
  7421. ZipFile& file;
  7422. ZipEntryInfo zipEntryInfo;
  7423. int64 pos;
  7424. int headerSize;
  7425. InputStream* inputStream;
  7426. ZipInputStream (const ZipInputStream&);
  7427. ZipInputStream& operator= (const ZipInputStream&);
  7428. };
  7429. ZipFile::ZipFile (InputStream* const source_,
  7430. const bool deleteStreamWhenDestroyed) throw()
  7431. : inputStream (source_)
  7432. #ifdef JUCE_DEBUG
  7433. , numOpenStreams (0)
  7434. #endif
  7435. {
  7436. if (deleteStreamWhenDestroyed)
  7437. streamToDelete = inputStream;
  7438. init();
  7439. }
  7440. ZipFile::ZipFile (const File& file)
  7441. : inputStream (0)
  7442. #ifdef JUCE_DEBUG
  7443. , numOpenStreams (0)
  7444. #endif
  7445. {
  7446. inputSource = new FileInputSource (file);
  7447. init();
  7448. }
  7449. ZipFile::ZipFile (InputSource* const inputSource_)
  7450. : inputStream (0),
  7451. inputSource (inputSource_)
  7452. #ifdef JUCE_DEBUG
  7453. , numOpenStreams (0)
  7454. #endif
  7455. {
  7456. init();
  7457. }
  7458. ZipFile::~ZipFile() throw()
  7459. {
  7460. #ifdef JUCE_DEBUG
  7461. entries.clear();
  7462. // If you hit this assertion, it means you've created a stream to read
  7463. // one of the items in the zipfile, but you've forgotten to delete that
  7464. // stream object before deleting the file.. Streams can't be kept open
  7465. // after the file is deleted because they need to share the input
  7466. // stream that the file uses to read itself.
  7467. jassert (numOpenStreams == 0);
  7468. #endif
  7469. }
  7470. int ZipFile::getNumEntries() const throw()
  7471. {
  7472. return entries.size();
  7473. }
  7474. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const throw()
  7475. {
  7476. ZipEntryInfo* const zei = (ZipEntryInfo*) entries [index];
  7477. return (zei != 0) ? &(zei->entry)
  7478. : 0;
  7479. }
  7480. int ZipFile::getIndexOfFileName (const String& fileName) const throw()
  7481. {
  7482. for (int i = 0; i < entries.size(); ++i)
  7483. if (entries.getUnchecked (i)->entry.filename == fileName)
  7484. return i;
  7485. return -1;
  7486. }
  7487. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const throw()
  7488. {
  7489. return getEntry (getIndexOfFileName (fileName));
  7490. }
  7491. InputStream* ZipFile::createStreamForEntry (const int index)
  7492. {
  7493. ZipEntryInfo* const zei = entries[index];
  7494. InputStream* stream = 0;
  7495. if (zei != 0)
  7496. {
  7497. stream = new ZipInputStream (*this, *zei);
  7498. if (zei->compressed)
  7499. {
  7500. stream = new GZIPDecompressorInputStream (stream, true, true,
  7501. zei->entry.uncompressedSize);
  7502. // (much faster to unzip in big blocks using a buffer..)
  7503. stream = new BufferedInputStream (stream, 32768, true);
  7504. }
  7505. }
  7506. return stream;
  7507. }
  7508. class ZipFile::ZipFilenameComparator
  7509. {
  7510. public:
  7511. int compareElements (const ZipFile::ZipEntryInfo* first, const ZipFile::ZipEntryInfo* second)
  7512. {
  7513. return first->entry.filename.compare (second->entry.filename);
  7514. }
  7515. };
  7516. void ZipFile::sortEntriesByFilename()
  7517. {
  7518. ZipFilenameComparator sorter;
  7519. entries.sort (sorter);
  7520. }
  7521. void ZipFile::init()
  7522. {
  7523. ScopedPointer <InputStream> toDelete;
  7524. InputStream* in = inputStream;
  7525. if (inputSource != 0)
  7526. {
  7527. in = inputSource->createInputStream();
  7528. toDelete = in;
  7529. }
  7530. if (in != 0)
  7531. {
  7532. int numEntries = 0;
  7533. int pos = findEndOfZipEntryTable (in, numEntries);
  7534. if (pos >= 0 && pos < in->getTotalLength())
  7535. {
  7536. const int size = (int) (in->getTotalLength() - pos);
  7537. in->setPosition (pos);
  7538. MemoryBlock headerData;
  7539. if (in->readIntoMemoryBlock (headerData, size) == size)
  7540. {
  7541. pos = 0;
  7542. for (int i = 0; i < numEntries; ++i)
  7543. {
  7544. if (pos + 46 > size)
  7545. break;
  7546. const char* const buffer = ((const char*) headerData.getData()) + pos;
  7547. const int fileNameLen = ByteOrder::littleEndianShort (buffer + 28);
  7548. if (pos + 46 + fileNameLen > size)
  7549. break;
  7550. ZipEntryInfo* const zei = new ZipEntryInfo();
  7551. zei->entry.filename = String::fromUTF8 (buffer + 46, fileNameLen);
  7552. const int time = ByteOrder::littleEndianShort (buffer + 12);
  7553. const int date = ByteOrder::littleEndianShort (buffer + 14);
  7554. const int year = 1980 + (date >> 9);
  7555. const int month = ((date >> 5) & 15) - 1;
  7556. const int day = date & 31;
  7557. const int hours = time >> 11;
  7558. const int minutes = (time >> 5) & 63;
  7559. const int seconds = (time & 31) << 1;
  7560. zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
  7561. zei->compressed = ByteOrder::littleEndianShort (buffer + 10) != 0;
  7562. zei->compressedSize = ByteOrder::littleEndianInt (buffer + 20);
  7563. zei->entry.uncompressedSize = ByteOrder::littleEndianInt (buffer + 24);
  7564. zei->streamOffset = ByteOrder::littleEndianInt (buffer + 42);
  7565. entries.add (zei);
  7566. pos += 46 + fileNameLen
  7567. + ByteOrder::littleEndianShort (buffer + 30)
  7568. + ByteOrder::littleEndianShort (buffer + 32);
  7569. }
  7570. }
  7571. }
  7572. }
  7573. }
  7574. int ZipFile::findEndOfZipEntryTable (InputStream* input, int& numEntries)
  7575. {
  7576. BufferedInputStream in (input, 8192, false);
  7577. in.setPosition (in.getTotalLength());
  7578. int64 pos = in.getPosition();
  7579. const int64 lowestPos = jmax ((int64) 0, pos - 1024);
  7580. char buffer [32];
  7581. zeromem (buffer, sizeof (buffer));
  7582. while (pos > lowestPos)
  7583. {
  7584. in.setPosition (pos - 22);
  7585. pos = in.getPosition();
  7586. memcpy (buffer + 22, buffer, 4);
  7587. if (in.read (buffer, 22) != 22)
  7588. return 0;
  7589. for (int i = 0; i < 22; ++i)
  7590. {
  7591. if (ByteOrder::littleEndianInt (buffer + i) == 0x06054b50)
  7592. {
  7593. in.setPosition (pos + i);
  7594. in.read (buffer, 22);
  7595. numEntries = ByteOrder::littleEndianShort (buffer + 10);
  7596. return ByteOrder::littleEndianInt (buffer + 16);
  7597. }
  7598. }
  7599. }
  7600. return 0;
  7601. }
  7602. void ZipFile::uncompressTo (const File& targetDirectory,
  7603. const bool shouldOverwriteFiles)
  7604. {
  7605. for (int i = 0; i < entries.size(); ++i)
  7606. {
  7607. const ZipEntry& zei = entries.getUnchecked(i)->entry;
  7608. const File targetFile (targetDirectory.getChildFile (zei.filename));
  7609. if (zei.filename.endsWithChar (T('/')))
  7610. {
  7611. targetFile.createDirectory(); // (entry is a directory, not a file)
  7612. }
  7613. else
  7614. {
  7615. ScopedPointer <InputStream> in (createStreamForEntry (i));
  7616. if (in != 0)
  7617. {
  7618. if (shouldOverwriteFiles)
  7619. targetFile.deleteFile();
  7620. if ((! targetFile.exists())
  7621. && targetFile.getParentDirectory().createDirectory())
  7622. {
  7623. ScopedPointer <FileOutputStream> out (targetFile.createOutputStream());
  7624. if (out != 0)
  7625. {
  7626. out->writeFromInputStream (*in, -1);
  7627. out = 0;
  7628. targetFile.setCreationTime (zei.fileTime);
  7629. targetFile.setLastModificationTime (zei.fileTime);
  7630. targetFile.setLastAccessTime (zei.fileTime);
  7631. }
  7632. }
  7633. }
  7634. }
  7635. }
  7636. }
  7637. END_JUCE_NAMESPACE
  7638. /*** End of inlined file: juce_ZipFile.cpp ***/
  7639. /*** Start of inlined file: juce_CharacterFunctions.cpp ***/
  7640. #ifdef _MSC_VER
  7641. #pragma warning (disable: 4514 4996)
  7642. #pragma warning (push)
  7643. #endif
  7644. #include <cwctype>
  7645. #include <cctype>
  7646. #include <ctime>
  7647. #ifdef _MSC_VER
  7648. #pragma warning (pop)
  7649. #endif
  7650. BEGIN_JUCE_NAMESPACE
  7651. int CharacterFunctions::length (const char* const s) throw()
  7652. {
  7653. return (int) strlen (s);
  7654. }
  7655. int CharacterFunctions::length (const juce_wchar* const s) throw()
  7656. {
  7657. return (int) wcslen (s);
  7658. }
  7659. void CharacterFunctions::copy (char* dest, const char* src, const int maxChars) throw()
  7660. {
  7661. strncpy (dest, src, maxChars);
  7662. }
  7663. void CharacterFunctions::copy (juce_wchar* dest, const juce_wchar* src, int maxChars) throw()
  7664. {
  7665. wcsncpy (dest, src, maxChars);
  7666. }
  7667. void CharacterFunctions::copy (juce_wchar* dest, const char* src, const int maxChars) throw()
  7668. {
  7669. mbstowcs (dest, src, maxChars);
  7670. }
  7671. void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxChars) throw()
  7672. {
  7673. wcstombs (dest, src, maxChars);
  7674. }
  7675. int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
  7676. {
  7677. return (int) wcstombs (0, src, 0);
  7678. }
  7679. void CharacterFunctions::append (char* dest, const char* src) throw()
  7680. {
  7681. strcat (dest, src);
  7682. }
  7683. void CharacterFunctions::append (juce_wchar* dest, const juce_wchar* src) throw()
  7684. {
  7685. wcscat (dest, src);
  7686. }
  7687. int CharacterFunctions::compare (const char* const s1, const char* const s2) throw()
  7688. {
  7689. return strcmp (s1, s2);
  7690. }
  7691. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2) throw()
  7692. {
  7693. jassert (s1 != 0 && s2 != 0);
  7694. return wcscmp (s1, s2);
  7695. }
  7696. int CharacterFunctions::compare (const char* const s1, const char* const s2, const int maxChars) throw()
  7697. {
  7698. jassert (s1 != 0 && s2 != 0);
  7699. return strncmp (s1, s2, maxChars);
  7700. }
  7701. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7702. {
  7703. jassert (s1 != 0 && s2 != 0);
  7704. return wcsncmp (s1, s2, maxChars);
  7705. }
  7706. int CharacterFunctions::compare (const juce_wchar* s1, const char* s2) throw()
  7707. {
  7708. jassert (s1 != 0 && s2 != 0);
  7709. for (;;)
  7710. {
  7711. const int diff = (int) (*s1 - (juce_wchar) (unsigned char) *s2);
  7712. if (diff != 0)
  7713. return diff;
  7714. else if (*s1 == 0)
  7715. break;
  7716. ++s1;
  7717. ++s2;
  7718. }
  7719. return 0;
  7720. }
  7721. int CharacterFunctions::compare (const char* s1, const juce_wchar* s2) throw()
  7722. {
  7723. return -compare (s2, s1);
  7724. }
  7725. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw()
  7726. {
  7727. jassert (s1 != 0 && s2 != 0);
  7728. #if JUCE_WIN32
  7729. return stricmp (s1, s2);
  7730. #else
  7731. return strcasecmp (s1, s2);
  7732. #endif
  7733. }
  7734. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw()
  7735. {
  7736. jassert (s1 != 0 && s2 != 0);
  7737. #if JUCE_WIN32
  7738. return _wcsicmp (s1, s2);
  7739. #else
  7740. for (;;)
  7741. {
  7742. if (*s1 != *s2)
  7743. {
  7744. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7745. if (diff != 0)
  7746. return diff < 0 ? -1 : 1;
  7747. }
  7748. else if (*s1 == 0)
  7749. break;
  7750. ++s1;
  7751. ++s2;
  7752. }
  7753. return 0;
  7754. #endif
  7755. }
  7756. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw()
  7757. {
  7758. jassert (s1 != 0 && s2 != 0);
  7759. #if JUCE_WIN32
  7760. return strnicmp (s1, s2, maxChars);
  7761. #else
  7762. return strncasecmp (s1, s2, maxChars);
  7763. #endif
  7764. }
  7765. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7766. {
  7767. jassert (s1 != 0 && s2 != 0);
  7768. #if JUCE_WIN32
  7769. return _wcsnicmp (s1, s2, maxChars);
  7770. #else
  7771. while (--maxChars >= 0)
  7772. {
  7773. if (*s1 != *s2)
  7774. {
  7775. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7776. if (diff != 0)
  7777. return diff < 0 ? -1 : 1;
  7778. }
  7779. else if (*s1 == 0)
  7780. break;
  7781. ++s1;
  7782. ++s2;
  7783. }
  7784. return 0;
  7785. #endif
  7786. }
  7787. const char* CharacterFunctions::find (const char* const haystack, const char* const needle) throw()
  7788. {
  7789. return strstr (haystack, needle);
  7790. }
  7791. const juce_wchar* CharacterFunctions::find (const juce_wchar* haystack, const juce_wchar* const needle) throw()
  7792. {
  7793. return wcsstr (haystack, needle);
  7794. }
  7795. int CharacterFunctions::indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw()
  7796. {
  7797. if (haystack != 0)
  7798. {
  7799. int i = 0;
  7800. if (ignoreCase)
  7801. {
  7802. const char n1 = toLowerCase (needle);
  7803. const char n2 = toUpperCase (needle);
  7804. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7805. {
  7806. while (haystack[i] != 0)
  7807. {
  7808. if (haystack[i] == n1 || haystack[i] == n2)
  7809. return i;
  7810. ++i;
  7811. }
  7812. return -1;
  7813. }
  7814. jassert (n1 == needle);
  7815. }
  7816. while (haystack[i] != 0)
  7817. {
  7818. if (haystack[i] == needle)
  7819. return i;
  7820. ++i;
  7821. }
  7822. }
  7823. return -1;
  7824. }
  7825. int CharacterFunctions::indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw()
  7826. {
  7827. if (haystack != 0)
  7828. {
  7829. int i = 0;
  7830. if (ignoreCase)
  7831. {
  7832. const juce_wchar n1 = toLowerCase (needle);
  7833. const juce_wchar n2 = toUpperCase (needle);
  7834. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7835. {
  7836. while (haystack[i] != 0)
  7837. {
  7838. if (haystack[i] == n1 || haystack[i] == n2)
  7839. return i;
  7840. ++i;
  7841. }
  7842. return -1;
  7843. }
  7844. jassert (n1 == needle);
  7845. }
  7846. while (haystack[i] != 0)
  7847. {
  7848. if (haystack[i] == needle)
  7849. return i;
  7850. ++i;
  7851. }
  7852. }
  7853. return -1;
  7854. }
  7855. int CharacterFunctions::indexOfCharFast (const char* const haystack, const char needle) throw()
  7856. {
  7857. jassert (haystack != 0);
  7858. int i = 0;
  7859. while (haystack[i] != 0)
  7860. {
  7861. if (haystack[i] == needle)
  7862. return i;
  7863. ++i;
  7864. }
  7865. return -1;
  7866. }
  7867. int CharacterFunctions::indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw()
  7868. {
  7869. jassert (haystack != 0);
  7870. int i = 0;
  7871. while (haystack[i] != 0)
  7872. {
  7873. if (haystack[i] == needle)
  7874. return i;
  7875. ++i;
  7876. }
  7877. return -1;
  7878. }
  7879. int CharacterFunctions::getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw()
  7880. {
  7881. return allowedChars == 0 ? 0 : (int) strspn (text, allowedChars);
  7882. }
  7883. int CharacterFunctions::getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw()
  7884. {
  7885. if (allowedChars == 0)
  7886. return 0;
  7887. int i = 0;
  7888. for (;;)
  7889. {
  7890. if (indexOfCharFast (allowedChars, text[i]) < 0)
  7891. break;
  7892. ++i;
  7893. }
  7894. return i;
  7895. }
  7896. int CharacterFunctions::ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw()
  7897. {
  7898. return (int) strftime (dest, maxChars, format, tm);
  7899. }
  7900. int CharacterFunctions::ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw()
  7901. {
  7902. return (int) wcsftime (dest, maxChars, format, tm);
  7903. }
  7904. int CharacterFunctions::getIntValue (const char* const s) throw()
  7905. {
  7906. return atoi (s);
  7907. }
  7908. int CharacterFunctions::getIntValue (const juce_wchar* s) throw()
  7909. {
  7910. #if JUCE_WIN32
  7911. return _wtoi (s);
  7912. #else
  7913. int v = 0;
  7914. while (isWhitespace (*s))
  7915. ++s;
  7916. const bool isNeg = *s == T('-');
  7917. if (isNeg)
  7918. ++s;
  7919. for (;;)
  7920. {
  7921. const wchar_t c = *s++;
  7922. if (c >= T('0') && c <= T('9'))
  7923. v = v * 10 + (int) (c - T('0'));
  7924. else
  7925. break;
  7926. }
  7927. return isNeg ? -v : v;
  7928. #endif
  7929. }
  7930. int64 CharacterFunctions::getInt64Value (const char* s) throw()
  7931. {
  7932. #if JUCE_LINUX
  7933. return atoll (s);
  7934. #elif defined (JUCE_WIN32)
  7935. return _atoi64 (s);
  7936. #else
  7937. int64 v = 0;
  7938. while (isWhitespace (*s))
  7939. ++s;
  7940. const bool isNeg = *s == T('-');
  7941. if (isNeg)
  7942. ++s;
  7943. for (;;)
  7944. {
  7945. const char c = *s++;
  7946. if (c >= '0' && c <= '9')
  7947. v = v * 10 + (int64) (c - '0');
  7948. else
  7949. break;
  7950. }
  7951. return isNeg ? -v : v;
  7952. #endif
  7953. }
  7954. int64 CharacterFunctions::getInt64Value (const juce_wchar* s) throw()
  7955. {
  7956. #if JUCE_WIN32
  7957. return _wtoi64 (s);
  7958. #else
  7959. int64 v = 0;
  7960. while (isWhitespace (*s))
  7961. ++s;
  7962. const bool isNeg = *s == T('-');
  7963. if (isNeg)
  7964. ++s;
  7965. for (;;)
  7966. {
  7967. const juce_wchar c = *s++;
  7968. if (c >= T('0') && c <= T('9'))
  7969. v = v * 10 + (int64) (c - T('0'));
  7970. else
  7971. break;
  7972. }
  7973. return isNeg ? -v : v;
  7974. #endif
  7975. }
  7976. static double juce_mulexp10 (const double value, int exponent) throw()
  7977. {
  7978. if (exponent == 0)
  7979. return value;
  7980. if (value == 0)
  7981. return 0;
  7982. const bool negative = (exponent < 0);
  7983. if (negative)
  7984. exponent = -exponent;
  7985. double result = 1.0, power = 10.0;
  7986. for (int bit = 1; exponent != 0; bit <<= 1)
  7987. {
  7988. if ((exponent & bit) != 0)
  7989. {
  7990. exponent ^= bit;
  7991. result *= power;
  7992. if (exponent == 0)
  7993. break;
  7994. }
  7995. power *= power;
  7996. }
  7997. return negative ? (value / result) : (value * result);
  7998. }
  7999. template <class CharType>
  8000. double juce_atof (const CharType* const original) throw()
  8001. {
  8002. double result[3] = { 0, 0, 0 }, accumulator[2] = { 0, 0 };
  8003. int exponentAdjustment[2] = { 0, 0 }, exponentAccumulator[2] = { -1, -1 };
  8004. int exponent = 0, decPointIndex = 0, digit = 0;
  8005. int lastDigit = 0, numSignificantDigits = 0;
  8006. bool isNegative = false, digitsFound = false;
  8007. const int maxSignificantDigits = 15 + 2;
  8008. const CharType* s = original;
  8009. while (CharacterFunctions::isWhitespace (*s))
  8010. ++s;
  8011. switch (*s)
  8012. {
  8013. case '-': isNegative = true; // fall-through..
  8014. case '+': ++s;
  8015. }
  8016. if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I')
  8017. return atof (String (original).toUTF8()); // Let the c library deal with NAN and INF
  8018. for (;;)
  8019. {
  8020. if (CharacterFunctions::isDigit (*s))
  8021. {
  8022. lastDigit = digit;
  8023. digit = *s++ - '0';
  8024. digitsFound = true;
  8025. if (decPointIndex != 0)
  8026. exponentAdjustment[1]++;
  8027. if (numSignificantDigits == 0 && digit == 0)
  8028. continue;
  8029. if (++numSignificantDigits > maxSignificantDigits)
  8030. {
  8031. if (digit > 5)
  8032. ++accumulator [decPointIndex];
  8033. else if (digit == 5 && (lastDigit & 1) != 0)
  8034. ++accumulator [decPointIndex];
  8035. if (decPointIndex > 0)
  8036. exponentAdjustment[1]--;
  8037. else
  8038. exponentAdjustment[0]++;
  8039. while (CharacterFunctions::isDigit (*s))
  8040. {
  8041. ++s;
  8042. if (decPointIndex == 0)
  8043. exponentAdjustment[0]++;
  8044. }
  8045. }
  8046. else
  8047. {
  8048. const double maxAccumulatorValue = (double) ((std::numeric_limits<unsigned int>::max() - 9) / 10);
  8049. if (accumulator [decPointIndex] > maxAccumulatorValue)
  8050. {
  8051. result [decPointIndex] = juce_mulexp10 (result [decPointIndex], exponentAccumulator [decPointIndex])
  8052. + accumulator [decPointIndex];
  8053. accumulator [decPointIndex] = 0;
  8054. exponentAccumulator [decPointIndex] = 0;
  8055. }
  8056. accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
  8057. exponentAccumulator [decPointIndex]++;
  8058. }
  8059. }
  8060. else if (decPointIndex == 0 && *s == '.')
  8061. {
  8062. ++s;
  8063. decPointIndex = 1;
  8064. if (numSignificantDigits > maxSignificantDigits)
  8065. {
  8066. while (CharacterFunctions::isDigit (*s))
  8067. ++s;
  8068. break;
  8069. }
  8070. }
  8071. else
  8072. {
  8073. break;
  8074. }
  8075. }
  8076. result[0] = juce_mulexp10 (result[0], exponentAccumulator[0]) + accumulator[0];
  8077. if (decPointIndex != 0)
  8078. result[1] = juce_mulexp10 (result[1], exponentAccumulator[1]) + accumulator[1];
  8079. if ((*s == 'e' || *s == 'E') && digitsFound)
  8080. {
  8081. bool negativeExponent = false;
  8082. switch (*++s)
  8083. {
  8084. case '-': negativeExponent = true; // fall-through..
  8085. case '+': ++s;
  8086. }
  8087. while (CharacterFunctions::isDigit (*s))
  8088. exponent = (exponent * 10) + (*s++ - '0');
  8089. if (negativeExponent)
  8090. exponent = -exponent;
  8091. }
  8092. double r = juce_mulexp10 (result[0], exponent + exponentAdjustment[0]);
  8093. if (decPointIndex != 0)
  8094. r += juce_mulexp10 (result[1], exponent - exponentAdjustment[1]);
  8095. return isNegative ? -r : r;
  8096. }
  8097. double CharacterFunctions::getDoubleValue (const char* const s) throw()
  8098. {
  8099. return juce_atof <char> (s);
  8100. }
  8101. double CharacterFunctions::getDoubleValue (const juce_wchar* const s) throw()
  8102. {
  8103. return juce_atof <juce_wchar> (s);
  8104. }
  8105. char CharacterFunctions::toUpperCase (const char character) throw()
  8106. {
  8107. return (char) toupper (character);
  8108. }
  8109. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) throw()
  8110. {
  8111. return towupper (character);
  8112. }
  8113. void CharacterFunctions::toUpperCase (char* s) throw()
  8114. {
  8115. #if JUCE_WIN32
  8116. strupr (s);
  8117. #else
  8118. while (*s != 0)
  8119. {
  8120. *s = toUpperCase (*s);
  8121. ++s;
  8122. }
  8123. #endif
  8124. }
  8125. void CharacterFunctions::toUpperCase (juce_wchar* s) throw()
  8126. {
  8127. #if JUCE_WIN32
  8128. _wcsupr (s);
  8129. #else
  8130. while (*s != 0)
  8131. {
  8132. *s = toUpperCase (*s);
  8133. ++s;
  8134. }
  8135. #endif
  8136. }
  8137. bool CharacterFunctions::isUpperCase (const char character) throw()
  8138. {
  8139. return isupper (character) != 0;
  8140. }
  8141. bool CharacterFunctions::isUpperCase (const juce_wchar character) throw()
  8142. {
  8143. #if JUCE_WIN32
  8144. return iswupper (character) != 0;
  8145. #else
  8146. return toLowerCase (character) != character;
  8147. #endif
  8148. }
  8149. char CharacterFunctions::toLowerCase (const char character) throw()
  8150. {
  8151. return (char) tolower (character);
  8152. }
  8153. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) throw()
  8154. {
  8155. return towlower (character);
  8156. }
  8157. void CharacterFunctions::toLowerCase (char* s) throw()
  8158. {
  8159. #if JUCE_WIN32
  8160. strlwr (s);
  8161. #else
  8162. while (*s != 0)
  8163. {
  8164. *s = toLowerCase (*s);
  8165. ++s;
  8166. }
  8167. #endif
  8168. }
  8169. void CharacterFunctions::toLowerCase (juce_wchar* s) throw()
  8170. {
  8171. #if JUCE_WIN32
  8172. _wcslwr (s);
  8173. #else
  8174. while (*s != 0)
  8175. {
  8176. *s = toLowerCase (*s);
  8177. ++s;
  8178. }
  8179. #endif
  8180. }
  8181. bool CharacterFunctions::isLowerCase (const char character) throw()
  8182. {
  8183. return islower (character) != 0;
  8184. }
  8185. bool CharacterFunctions::isLowerCase (const juce_wchar character) throw()
  8186. {
  8187. #if JUCE_WIN32
  8188. return iswlower (character) != 0;
  8189. #else
  8190. return toUpperCase (character) != character;
  8191. #endif
  8192. }
  8193. bool CharacterFunctions::isWhitespace (const char character) throw()
  8194. {
  8195. return character == T(' ') || (character <= 13 && character >= 9);
  8196. }
  8197. bool CharacterFunctions::isWhitespace (const juce_wchar character) throw()
  8198. {
  8199. return iswspace (character) != 0;
  8200. }
  8201. bool CharacterFunctions::isDigit (const char character) throw()
  8202. {
  8203. return (character >= '0' && character <= '9');
  8204. }
  8205. bool CharacterFunctions::isDigit (const juce_wchar character) throw()
  8206. {
  8207. return iswdigit (character) != 0;
  8208. }
  8209. bool CharacterFunctions::isLetter (const char character) throw()
  8210. {
  8211. return (character >= 'a' && character <= 'z')
  8212. || (character >= 'A' && character <= 'Z');
  8213. }
  8214. bool CharacterFunctions::isLetter (const juce_wchar character) throw()
  8215. {
  8216. return iswalpha (character) != 0;
  8217. }
  8218. bool CharacterFunctions::isLetterOrDigit (const char character) throw()
  8219. {
  8220. return (character >= 'a' && character <= 'z')
  8221. || (character >= 'A' && character <= 'Z')
  8222. || (character >= '0' && character <= '9');
  8223. }
  8224. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
  8225. {
  8226. return iswalnum (character) != 0;
  8227. }
  8228. int CharacterFunctions::getHexDigitValue (const juce_wchar digit) throw()
  8229. {
  8230. if (digit >= '0' && digit <= '9')
  8231. return digit - '0';
  8232. else if (digit >= 'a' && digit <= 'f')
  8233. return digit - ('a' - 10);
  8234. else if (digit >= 'A' && digit <= 'F')
  8235. return digit - ('A' - 10);
  8236. return -1;
  8237. }
  8238. int CharacterFunctions::printf (char* const dest, const int maxLength, const char* const format, ...) throw()
  8239. {
  8240. va_list list;
  8241. va_start (list, format);
  8242. return vprintf (dest, maxLength, format, list);
  8243. }
  8244. int CharacterFunctions::printf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, ...) throw()
  8245. {
  8246. va_list list;
  8247. va_start (list, format);
  8248. return vprintf (dest, maxLength, format, list);
  8249. }
  8250. int CharacterFunctions::vprintf (char* const dest, const int maxLength, const char* const format, va_list& args) throw()
  8251. {
  8252. #if JUCE_WIN32
  8253. return (int) _vsnprintf (dest, maxLength, format, args);
  8254. #else
  8255. return (int) vsnprintf (dest, maxLength, format, args);
  8256. #endif
  8257. }
  8258. int CharacterFunctions::vprintf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, va_list& args) throw()
  8259. {
  8260. #if defined (JUCE_WIN32)
  8261. return (int) _vsnwprintf (dest, maxLength, format, args);
  8262. #else
  8263. return (int) vswprintf (dest, maxLength, format, args);
  8264. #endif
  8265. }
  8266. END_JUCE_NAMESPACE
  8267. /*** End of inlined file: juce_CharacterFunctions.cpp ***/
  8268. /*** Start of inlined file: juce_LocalisedStrings.cpp ***/
  8269. BEGIN_JUCE_NAMESPACE
  8270. LocalisedStrings::LocalisedStrings (const String& fileContents)
  8271. {
  8272. loadFromText (fileContents);
  8273. }
  8274. LocalisedStrings::LocalisedStrings (const File& fileToLoad)
  8275. {
  8276. loadFromText (fileToLoad.loadFileAsString());
  8277. }
  8278. LocalisedStrings::~LocalisedStrings()
  8279. {
  8280. }
  8281. const String LocalisedStrings::translate (const String& text) const
  8282. {
  8283. return translations.getValue (text, text);
  8284. }
  8285. static int findCloseQuote (const String& text, int startPos)
  8286. {
  8287. tchar lastChar = 0;
  8288. for (;;)
  8289. {
  8290. const tchar c = text [startPos];
  8291. if (c == 0 || (c == T('"') && lastChar != T('\\')))
  8292. break;
  8293. lastChar = c;
  8294. ++startPos;
  8295. }
  8296. return startPos;
  8297. }
  8298. static const String unescapeString (const String& s)
  8299. {
  8300. return s.replace (T("\\\""), T("\""))
  8301. .replace (T("\\\'"), T("\'"))
  8302. .replace (T("\\t"), T("\t"))
  8303. .replace (T("\\r"), T("\r"))
  8304. .replace (T("\\n"), T("\n"));
  8305. }
  8306. void LocalisedStrings::loadFromText (const String& fileContents)
  8307. {
  8308. StringArray lines;
  8309. lines.addLines (fileContents);
  8310. for (int i = 0; i < lines.size(); ++i)
  8311. {
  8312. String line (lines[i].trim());
  8313. if (line.startsWithChar (T('"')))
  8314. {
  8315. int closeQuote = findCloseQuote (line, 1);
  8316. const String originalText (unescapeString (line.substring (1, closeQuote)));
  8317. if (originalText.isNotEmpty())
  8318. {
  8319. const int openingQuote = findCloseQuote (line, closeQuote + 1);
  8320. closeQuote = findCloseQuote (line, openingQuote + 1);
  8321. const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
  8322. if (newText.isNotEmpty())
  8323. translations.set (originalText, newText);
  8324. }
  8325. }
  8326. else if (line.startsWithIgnoreCase (T("language:")))
  8327. {
  8328. languageName = line.substring (9).trim();
  8329. }
  8330. else if (line.startsWithIgnoreCase (T("countries:")))
  8331. {
  8332. countryCodes.addTokens (line.substring (10).trim(), true);
  8333. countryCodes.trim();
  8334. countryCodes.removeEmptyStrings();
  8335. }
  8336. }
  8337. }
  8338. void LocalisedStrings::setIgnoresCase (const bool shouldIgnoreCase)
  8339. {
  8340. translations.setIgnoresCase (shouldIgnoreCase);
  8341. }
  8342. static CriticalSection currentMappingsLock;
  8343. static LocalisedStrings* currentMappings = 0;
  8344. void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
  8345. {
  8346. const ScopedLock sl (currentMappingsLock);
  8347. delete currentMappings;
  8348. currentMappings = newTranslations;
  8349. }
  8350. LocalisedStrings* LocalisedStrings::getCurrentMappings()
  8351. {
  8352. return currentMappings;
  8353. }
  8354. const String LocalisedStrings::translateWithCurrentMappings (const String& text)
  8355. {
  8356. const ScopedLock sl (currentMappingsLock);
  8357. if (currentMappings != 0)
  8358. return currentMappings->translate (text);
  8359. return text;
  8360. }
  8361. const String LocalisedStrings::translateWithCurrentMappings (const char* text)
  8362. {
  8363. return translateWithCurrentMappings (String (text));
  8364. }
  8365. END_JUCE_NAMESPACE
  8366. /*** End of inlined file: juce_LocalisedStrings.cpp ***/
  8367. /*** Start of inlined file: juce_String.cpp ***/
  8368. #ifdef _MSC_VER
  8369. #pragma warning (disable: 4514)
  8370. #pragma warning (push)
  8371. #endif
  8372. #include <locale>
  8373. #if JUCE_MSVC
  8374. #include <float.h>
  8375. #endif
  8376. BEGIN_JUCE_NAMESPACE
  8377. #ifdef _MSC_VER
  8378. #pragma warning (pop)
  8379. #endif
  8380. #if defined (JUCE_STRINGS_ARE_UNICODE) && ! JUCE_STRINGS_ARE_UNICODE
  8381. #error "JUCE_STRINGS_ARE_UNICODE is deprecated! All strings are now unicode by default."
  8382. #endif
  8383. static const char* const emptyCharString = "\0\0\0\0JUCE";
  8384. static const int safeEmptyStringRefCount = 0x3fffffff;
  8385. String::InternalRefCountedStringHolder String::emptyString = { safeEmptyStringRefCount, 0, { 0 } };
  8386. static tchar decimalPoint = T('.');
  8387. void juce_initialiseStrings()
  8388. {
  8389. decimalPoint = String::fromUTF8 (localeconv()->decimal_point) [0];
  8390. }
  8391. void String::createInternal (const int numChars) throw()
  8392. {
  8393. jassert (numChars > 0);
  8394. text = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8395. + numChars * sizeof (tchar));
  8396. text->refCount = 1;
  8397. text->allocatedNumChars = numChars;
  8398. text->text[0] = 0;
  8399. }
  8400. void String::createInternal (const tchar* const t, const tchar* const textEnd) throw()
  8401. {
  8402. jassert (*(textEnd - 1) == 0); // must have a null terminator
  8403. const int numChars = (int) (textEnd - t);
  8404. createInternal (numChars - 1);
  8405. memcpy (text->text, t, numChars * sizeof (tchar));
  8406. }
  8407. void String::appendInternal (const tchar* const newText,
  8408. const int numExtraChars) throw()
  8409. {
  8410. if (numExtraChars > 0)
  8411. {
  8412. const int oldLen = CharacterFunctions::length (text->text);
  8413. const int newTotalLen = oldLen + numExtraChars;
  8414. if (text->refCount > 1)
  8415. {
  8416. // it's in use by other strings as well, so we need to make a private copy before messing with it..
  8417. InternalRefCountedStringHolder* const newTextHolder
  8418. = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8419. + newTotalLen * sizeof (tchar));
  8420. newTextHolder->refCount = 1;
  8421. newTextHolder->allocatedNumChars = newTotalLen;
  8422. memcpy (newTextHolder->text, text->text, oldLen * sizeof (tchar));
  8423. memcpy (newTextHolder->text + oldLen, newText, numExtraChars * sizeof (tchar));
  8424. InternalRefCountedStringHolder* const old = text;
  8425. text = newTextHolder;
  8426. if (Atomic::decrementAndReturn (old->refCount) == 0)
  8427. juce_free (old);
  8428. }
  8429. else
  8430. {
  8431. // no other strings using it, so just expand it if needed..
  8432. if (newTotalLen > text->allocatedNumChars)
  8433. {
  8434. text = (InternalRefCountedStringHolder*)
  8435. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8436. + newTotalLen * sizeof (tchar));
  8437. text->allocatedNumChars = newTotalLen;
  8438. }
  8439. memcpy (text->text + oldLen, newText, numExtraChars * sizeof (tchar));
  8440. }
  8441. text->text [newTotalLen] = 0;
  8442. }
  8443. }
  8444. void String::dupeInternalIfMultiplyReferenced() throw()
  8445. {
  8446. if (text->refCount > 1)
  8447. {
  8448. InternalRefCountedStringHolder* const old = text;
  8449. const int len = old->allocatedNumChars;
  8450. InternalRefCountedStringHolder* const newTextHolder
  8451. = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8452. + len * sizeof (tchar));
  8453. newTextHolder->refCount = 1;
  8454. newTextHolder->allocatedNumChars = len;
  8455. memcpy (newTextHolder->text, old->text, (len + 1) * sizeof (tchar));
  8456. text = newTextHolder;
  8457. if (Atomic::decrementAndReturn (old->refCount) == 0)
  8458. juce_free (old);
  8459. }
  8460. }
  8461. const String String::empty;
  8462. String::String() throw()
  8463. : text (&emptyString)
  8464. {
  8465. }
  8466. String::String (const String& other) throw()
  8467. : text (other.text)
  8468. {
  8469. Atomic::increment (text->refCount);
  8470. }
  8471. String::String (const int numChars,
  8472. const int /*dummyVariable*/) throw()
  8473. {
  8474. createInternal (numChars);
  8475. }
  8476. String::String (const char* const t) throw()
  8477. {
  8478. if (t != 0 && *t != 0)
  8479. {
  8480. const int len = CharacterFunctions::length (t);
  8481. createInternal (len);
  8482. CharacterFunctions::copy (text->text, t, len + 1);
  8483. }
  8484. else
  8485. {
  8486. text = &emptyString;
  8487. emptyString.refCount = safeEmptyStringRefCount;
  8488. }
  8489. }
  8490. String::String (const juce_wchar* const t) throw()
  8491. {
  8492. if (t != 0 && *t != 0)
  8493. {
  8494. const int len = CharacterFunctions::length (t);
  8495. createInternal (len);
  8496. memcpy (text->text, t, (len + 1) * sizeof (tchar));
  8497. }
  8498. else
  8499. {
  8500. text = &emptyString;
  8501. emptyString.refCount = safeEmptyStringRefCount;
  8502. }
  8503. }
  8504. String::String (const char* const t,
  8505. const size_t maxChars) throw()
  8506. {
  8507. int i;
  8508. for (i = 0; (size_t) i < maxChars; ++i)
  8509. if (t[i] == 0)
  8510. break;
  8511. if (i > 0)
  8512. {
  8513. createInternal (i);
  8514. CharacterFunctions::copy (text->text, t, i);
  8515. text->text [i] = 0;
  8516. }
  8517. else
  8518. {
  8519. text = &emptyString;
  8520. emptyString.refCount = safeEmptyStringRefCount;
  8521. }
  8522. }
  8523. String::String (const juce_wchar* const t,
  8524. const size_t maxChars) throw()
  8525. {
  8526. int i;
  8527. for (i = 0; (size_t) i < maxChars; ++i)
  8528. if (t[i] == 0)
  8529. break;
  8530. if (i > 0)
  8531. {
  8532. createInternal (i);
  8533. memcpy (text->text, t, i * sizeof (tchar));
  8534. text->text [i] = 0;
  8535. }
  8536. else
  8537. {
  8538. text = &emptyString;
  8539. emptyString.refCount = safeEmptyStringRefCount;
  8540. }
  8541. }
  8542. const String String::charToString (const juce_wchar character) throw()
  8543. {
  8544. tchar temp[2];
  8545. temp[0] = character;
  8546. temp[1] = 0;
  8547. return String (temp);
  8548. }
  8549. namespace IntToCharConverters
  8550. {
  8551. // pass in a pointer to the END of a buffer..
  8552. static tchar* int64ToString (tchar* t, const int64 n) throw()
  8553. {
  8554. *--t = 0;
  8555. int64 v = (n >= 0) ? n : -n;
  8556. do
  8557. {
  8558. *--t = (tchar) (T('0') + (int) (v % 10));
  8559. v /= 10;
  8560. } while (v > 0);
  8561. if (n < 0)
  8562. *--t = T('-');
  8563. return t;
  8564. }
  8565. static tchar* uint64ToString (tchar* t, int64 v) throw()
  8566. {
  8567. *--t = 0;
  8568. do
  8569. {
  8570. *--t = (tchar) (T('0') + (int) (v % 10));
  8571. v /= 10;
  8572. } while (v > 0);
  8573. return t;
  8574. }
  8575. static tchar* intToString (tchar* t, const int n) throw()
  8576. {
  8577. if (n == (int) 0x80000000) // (would cause an overflow)
  8578. return int64ToString (t, n);
  8579. *--t = 0;
  8580. int v = abs (n);
  8581. do
  8582. {
  8583. *--t = (tchar) (T('0') + (v % 10));
  8584. v /= 10;
  8585. } while (v > 0);
  8586. if (n < 0)
  8587. *--t = T('-');
  8588. return t;
  8589. }
  8590. static tchar* uintToString (tchar* t, unsigned int v) throw()
  8591. {
  8592. *--t = 0;
  8593. do
  8594. {
  8595. *--t = (tchar) (T('0') + (v % 10));
  8596. v /= 10;
  8597. } while (v > 0);
  8598. return t;
  8599. }
  8600. }
  8601. String::String (const int number) throw()
  8602. {
  8603. tchar buffer [16];
  8604. tchar* const end = buffer + numElementsInArray (buffer);
  8605. createInternal (IntToCharConverters::intToString (end, number), end);
  8606. }
  8607. String::String (const unsigned int number) throw()
  8608. {
  8609. tchar buffer [16];
  8610. tchar* const end = buffer + numElementsInArray (buffer);
  8611. createInternal (IntToCharConverters::uintToString (end, number), end);
  8612. }
  8613. String::String (const short number) throw()
  8614. {
  8615. tchar buffer [16];
  8616. tchar* const end = buffer + numElementsInArray (buffer);
  8617. createInternal (IntToCharConverters::intToString (end, (int) number), end);
  8618. }
  8619. String::String (const unsigned short number) throw()
  8620. {
  8621. tchar buffer [16];
  8622. tchar* const end = buffer + numElementsInArray (buffer);
  8623. createInternal (IntToCharConverters::uintToString (end, (unsigned int) number), end);
  8624. }
  8625. String::String (const int64 number) throw()
  8626. {
  8627. tchar buffer [32];
  8628. tchar* const end = buffer + numElementsInArray (buffer);
  8629. createInternal (IntToCharConverters::int64ToString (end, number), end);
  8630. }
  8631. String::String (const uint64 number) throw()
  8632. {
  8633. tchar buffer [32];
  8634. tchar* const end = buffer + numElementsInArray (buffer);
  8635. createInternal (IntToCharConverters::uint64ToString (end, number), end);
  8636. }
  8637. // a double-to-string routine that actually uses the number of dec. places you asked for
  8638. // without resorting to exponent notation if the number's too big or small (which is what printf does).
  8639. void String::doubleToStringWithDecPlaces (double n, int numDecPlaces) throw()
  8640. {
  8641. const int bufSize = 80;
  8642. tchar buffer [bufSize];
  8643. int len;
  8644. tchar* t;
  8645. if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20)
  8646. {
  8647. int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5);
  8648. t = buffer + bufSize;
  8649. *--t = (tchar) 0;
  8650. while (numDecPlaces >= 0 || v > 0)
  8651. {
  8652. if (numDecPlaces == 0)
  8653. *--t = decimalPoint;
  8654. *--t = (tchar) (T('0') + (v % 10));
  8655. v /= 10;
  8656. --numDecPlaces;
  8657. }
  8658. if (n < 0)
  8659. *--t = T('-');
  8660. len = (int) ((buffer + bufSize) - t);
  8661. }
  8662. else
  8663. {
  8664. len = CharacterFunctions::printf (buffer, bufSize, T("%.9g"), n) + 1;
  8665. t = buffer;
  8666. }
  8667. if (len > 1)
  8668. {
  8669. jassert (len < numElementsInArray (buffer));
  8670. createInternal (len - 1);
  8671. memcpy (text->text, t, len * sizeof (tchar));
  8672. }
  8673. else
  8674. {
  8675. jassert (*t == 0);
  8676. text = &emptyString;
  8677. emptyString.refCount = safeEmptyStringRefCount;
  8678. }
  8679. }
  8680. String::String (const float number,
  8681. const int numberOfDecimalPlaces) throw()
  8682. {
  8683. doubleToStringWithDecPlaces ((double) number,
  8684. numberOfDecimalPlaces);
  8685. }
  8686. String::String (const double number,
  8687. const int numberOfDecimalPlaces) throw()
  8688. {
  8689. doubleToStringWithDecPlaces (number,
  8690. numberOfDecimalPlaces);
  8691. }
  8692. String::~String() throw()
  8693. {
  8694. emptyString.refCount = safeEmptyStringRefCount;
  8695. if (Atomic::decrementAndReturn (text->refCount) == 0)
  8696. juce_free (text);
  8697. }
  8698. void String::preallocateStorage (const size_t numChars) throw()
  8699. {
  8700. if (numChars > (size_t) text->allocatedNumChars)
  8701. {
  8702. dupeInternalIfMultiplyReferenced();
  8703. text = (InternalRefCountedStringHolder*) juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8704. + numChars * sizeof (tchar));
  8705. text->allocatedNumChars = (int) numChars;
  8706. }
  8707. }
  8708. int String::length() const throw()
  8709. {
  8710. return CharacterFunctions::length (text->text);
  8711. }
  8712. int String::hashCode() const throw()
  8713. {
  8714. const tchar* t = text->text;
  8715. int result = 0;
  8716. while (*t != (tchar) 0)
  8717. result = 31 * result + *t++;
  8718. return result;
  8719. }
  8720. int64 String::hashCode64() const throw()
  8721. {
  8722. const tchar* t = text->text;
  8723. int64 result = 0;
  8724. while (*t != (tchar) 0)
  8725. result = 101 * result + *t++;
  8726. return result;
  8727. }
  8728. String& String::operator= (const String& other) throw()
  8729. {
  8730. if (this != &other)
  8731. {
  8732. InternalRefCountedStringHolder* newText = other.text;
  8733. Atomic::increment (newText->refCount);
  8734. InternalRefCountedStringHolder* oldText
  8735. = (InternalRefCountedStringHolder*) Atomic::swapPointers ((void* volatile*) &text, newText);
  8736. if (Atomic::decrementAndReturn (oldText->refCount) == 0)
  8737. juce_free (oldText);
  8738. }
  8739. return *this;
  8740. }
  8741. bool JUCE_CALLTYPE operator== (const String& string1, const String& string2) throw()
  8742. {
  8743. return string1.compare (string2) == 0;
  8744. }
  8745. bool JUCE_CALLTYPE operator== (const String& string1, const char* string2) throw()
  8746. {
  8747. return string1.compare (string2) == 0;
  8748. }
  8749. bool JUCE_CALLTYPE operator== (const String& string1, const juce_wchar* string2) throw()
  8750. {
  8751. return string1.compare (string2) == 0;
  8752. }
  8753. bool JUCE_CALLTYPE operator!= (const String& string1, const String& string2) throw()
  8754. {
  8755. return string1.compare (string2) != 0;
  8756. }
  8757. bool JUCE_CALLTYPE operator!= (const String& string1, const char* string2) throw()
  8758. {
  8759. return string1.compare (string2) != 0;
  8760. }
  8761. bool JUCE_CALLTYPE operator!= (const String& string1, const juce_wchar* string2) throw()
  8762. {
  8763. return string1.compare (string2) != 0;
  8764. }
  8765. bool JUCE_CALLTYPE operator> (const String& string1, const String& string2) throw()
  8766. {
  8767. return string1.compare (string2) > 0;
  8768. }
  8769. bool JUCE_CALLTYPE operator< (const String& string1, const String& string2) throw()
  8770. {
  8771. return string1.compare (string2) < 0;
  8772. }
  8773. bool JUCE_CALLTYPE operator>= (const String& string1, const String& string2) throw()
  8774. {
  8775. return string1.compare (string2) >= 0;
  8776. }
  8777. bool JUCE_CALLTYPE operator<= (const String& string1, const String& string2) throw()
  8778. {
  8779. return string1.compare (string2) <= 0;
  8780. }
  8781. bool String::equalsIgnoreCase (const tchar* t) const throw()
  8782. {
  8783. return t != 0 ? CharacterFunctions::compareIgnoreCase (text->text, t) == 0
  8784. : isEmpty();
  8785. }
  8786. bool String::equalsIgnoreCase (const String& other) const throw()
  8787. {
  8788. return text == other.text
  8789. || CharacterFunctions::compareIgnoreCase (text->text, other.text->text) == 0;
  8790. }
  8791. int String::compare (const String& other) const throw()
  8792. {
  8793. return (text == other.text) ? 0 : CharacterFunctions::compare (text->text, other.text->text);
  8794. }
  8795. int String::compare (const char* other) const throw()
  8796. {
  8797. return other == 0 ? isEmpty() : CharacterFunctions::compare (text->text, other);
  8798. }
  8799. int String::compare (const juce_wchar* other) const throw()
  8800. {
  8801. return other == 0 ? isEmpty() : CharacterFunctions::compare (text->text, other);
  8802. }
  8803. int String::compareIgnoreCase (const String& other) const throw()
  8804. {
  8805. return (text == other.text) ? 0 : CharacterFunctions::compareIgnoreCase (text->text, other.text->text);
  8806. }
  8807. int String::compareLexicographically (const String& other) const throw()
  8808. {
  8809. const tchar* s1 = text->text;
  8810. while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1))
  8811. ++s1;
  8812. const tchar* s2 = other.text->text;
  8813. while (*s2 != 0 && ! CharacterFunctions::isLetterOrDigit (*s2))
  8814. ++s2;
  8815. return CharacterFunctions::compareIgnoreCase (s1, s2);
  8816. }
  8817. String& String::operator+= (const tchar* const t)
  8818. {
  8819. if (t != 0)
  8820. appendInternal (t, CharacterFunctions::length (t));
  8821. return *this;
  8822. }
  8823. String& String::operator+= (const String& other)
  8824. {
  8825. if (isEmpty())
  8826. operator= (other);
  8827. else
  8828. appendInternal (other.text->text, other.length());
  8829. return *this;
  8830. }
  8831. String& String::operator+= (const char ch)
  8832. {
  8833. const tchar asString[] = { (tchar) ch, 0 };
  8834. return operator+= ((const tchar*) asString);
  8835. }
  8836. String& String::operator+= (const juce_wchar ch)
  8837. {
  8838. const tchar asString[] = { (tchar) ch, 0 };
  8839. return operator+= ((const tchar*) asString);
  8840. }
  8841. String& String::operator+= (const int number)
  8842. {
  8843. tchar buffer [16];
  8844. tchar* const end = buffer + numElementsInArray (buffer);
  8845. tchar* const start = IntToCharConverters::intToString (end, number);
  8846. appendInternal (start, end - start);
  8847. return *this;
  8848. }
  8849. String& String::operator+= (const unsigned int number)
  8850. {
  8851. tchar buffer [16];
  8852. tchar* const end = buffer + numElementsInArray (buffer);
  8853. tchar* const start = IntToCharConverters::uintToString (end, number);
  8854. appendInternal (start, end - start);
  8855. return *this;
  8856. }
  8857. void String::append (const tchar* const other, const int howMany)
  8858. {
  8859. if (howMany > 0)
  8860. {
  8861. int i;
  8862. for (i = 0; i < howMany; ++i)
  8863. if (other[i] == 0)
  8864. break;
  8865. appendInternal (other, i);
  8866. }
  8867. }
  8868. const String JUCE_CALLTYPE operator+ (const char* const string1, const String& string2)
  8869. {
  8870. String s (string1);
  8871. return s += string2;
  8872. }
  8873. const String JUCE_CALLTYPE operator+ (const juce_wchar* const string1, const String& string2)
  8874. {
  8875. String s (string1);
  8876. return s += string2;
  8877. }
  8878. const String JUCE_CALLTYPE operator+ (const char string1, const String& string2)
  8879. {
  8880. return String::charToString (string1) + string2;
  8881. }
  8882. const String JUCE_CALLTYPE operator+ (const juce_wchar string1, const String& string2)
  8883. {
  8884. return String::charToString (string1) + string2;
  8885. }
  8886. const String JUCE_CALLTYPE operator+ (String string1, const String& string2)
  8887. {
  8888. return string1 += string2;
  8889. }
  8890. const String JUCE_CALLTYPE operator+ (String string1, const char* const string2)
  8891. {
  8892. return string1 += string2;
  8893. }
  8894. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar* const string2)
  8895. {
  8896. return string1 += string2;
  8897. }
  8898. const String JUCE_CALLTYPE operator+ (String string1, const char string2)
  8899. {
  8900. return string1 += string2;
  8901. }
  8902. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar string2)
  8903. {
  8904. return string1 += string2;
  8905. }
  8906. String& JUCE_CALLTYPE operator<< (String& string1, const char characterToAppend)
  8907. {
  8908. return string1 += characterToAppend;
  8909. }
  8910. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar characterToAppend)
  8911. {
  8912. return string1 += characterToAppend;
  8913. }
  8914. String& JUCE_CALLTYPE operator<< (String& string1, const char* const string2)
  8915. {
  8916. return string1 += string2;
  8917. }
  8918. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar* const string2)
  8919. {
  8920. return string1 += string2;
  8921. }
  8922. String& JUCE_CALLTYPE operator<< (String& string1, const String& string2)
  8923. {
  8924. return string1 += string2;
  8925. }
  8926. String& JUCE_CALLTYPE operator<< (String& string1, const short number)
  8927. {
  8928. return string1 += (int) number;
  8929. }
  8930. String& JUCE_CALLTYPE operator<< (String& string1, const int number)
  8931. {
  8932. return string1 += number;
  8933. }
  8934. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned int number)
  8935. {
  8936. return string1 += number;
  8937. }
  8938. String& JUCE_CALLTYPE operator<< (String& string1, const long number)
  8939. {
  8940. return string1 += (int) number;
  8941. }
  8942. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned long number)
  8943. {
  8944. return string1 += (unsigned int) number;
  8945. }
  8946. String& JUCE_CALLTYPE operator<< (String& string1, const float number)
  8947. {
  8948. return string1 += String (number);
  8949. }
  8950. String& JUCE_CALLTYPE operator<< (String& string1, const double number)
  8951. {
  8952. return string1 += String (number);
  8953. }
  8954. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const String& text)
  8955. {
  8956. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  8957. // if lots of large, persistent strings were to be written to streams).
  8958. const int numBytes = text.getNumBytesAsUTF8();
  8959. HeapBlock<char> temp (numBytes + 1);
  8960. text.copyToUTF8 (temp, numBytes + 1);
  8961. stream.write (temp, numBytes);
  8962. return stream;
  8963. }
  8964. int String::indexOfChar (const tchar character) const throw()
  8965. {
  8966. const tchar* t = text->text;
  8967. for (;;)
  8968. {
  8969. if (*t == character)
  8970. return (int) (t - text->text);
  8971. if (*t++ == 0)
  8972. return -1;
  8973. }
  8974. }
  8975. int String::lastIndexOfChar (const tchar character) const throw()
  8976. {
  8977. for (int i = CharacterFunctions::length (text->text); --i >= 0;)
  8978. if (text->text[i] == character)
  8979. return i;
  8980. return -1;
  8981. }
  8982. int String::indexOf (const tchar* const t) const throw()
  8983. {
  8984. const tchar* const r = CharacterFunctions::find (text->text, t);
  8985. return (r == 0) ? -1
  8986. : (int) (r - text->text);
  8987. }
  8988. int String::indexOfChar (const int startIndex,
  8989. const tchar character) const throw()
  8990. {
  8991. if (startIndex >= 0 && startIndex >= CharacterFunctions::length (text->text))
  8992. return -1;
  8993. const tchar* t = text->text + jmax (0, startIndex);
  8994. for (;;)
  8995. {
  8996. if (*t == character)
  8997. return (int) (t - text->text);
  8998. if (*t++ == 0)
  8999. return -1;
  9000. }
  9001. }
  9002. int String::indexOfAnyOf (const tchar* const charactersToLookFor,
  9003. const int startIndex,
  9004. const bool ignoreCase) const throw()
  9005. {
  9006. if (charactersToLookFor == 0
  9007. || (startIndex >= 0 && startIndex >= CharacterFunctions::length (text->text)))
  9008. return -1;
  9009. const tchar* t = text->text + jmax (0, startIndex);
  9010. while (*t != 0)
  9011. {
  9012. if (CharacterFunctions::indexOfChar (charactersToLookFor, *t, ignoreCase) >= 0)
  9013. return (int) (t - text->text);
  9014. ++t;
  9015. }
  9016. return -1;
  9017. }
  9018. int String::indexOf (const int startIndex,
  9019. const tchar* const other) const throw()
  9020. {
  9021. if (other == 0 || startIndex >= CharacterFunctions::length (text->text))
  9022. return -1;
  9023. const tchar* const found = CharacterFunctions::find (text->text + jmax (0, startIndex),
  9024. other);
  9025. return (found == 0) ? -1
  9026. : (int) (found - text->text);
  9027. }
  9028. int String::indexOfIgnoreCase (const tchar* const other) const throw()
  9029. {
  9030. if (other != 0 && *other != 0)
  9031. {
  9032. const int len = CharacterFunctions::length (other);
  9033. const int end = CharacterFunctions::length (text->text) - len;
  9034. for (int i = 0; i <= end; ++i)
  9035. if (CharacterFunctions::compareIgnoreCase (text->text + i, other, len) == 0)
  9036. return i;
  9037. }
  9038. return -1;
  9039. }
  9040. int String::indexOfIgnoreCase (const int startIndex,
  9041. const tchar* const other) const throw()
  9042. {
  9043. if (other != 0 && *other != 0)
  9044. {
  9045. const int len = CharacterFunctions::length (other);
  9046. const int end = length() - len;
  9047. for (int i = jmax (0, startIndex); i <= end; ++i)
  9048. if (CharacterFunctions::compareIgnoreCase (text->text + i, other, len) == 0)
  9049. return i;
  9050. }
  9051. return -1;
  9052. }
  9053. int String::lastIndexOf (const tchar* const other) const throw()
  9054. {
  9055. if (other != 0 && *other != 0)
  9056. {
  9057. const int len = CharacterFunctions::length (other);
  9058. int i = length() - len;
  9059. if (i >= 0)
  9060. {
  9061. const tchar* n = text->text + i;
  9062. while (i >= 0)
  9063. {
  9064. if (CharacterFunctions::compare (n--, other, len) == 0)
  9065. return i;
  9066. --i;
  9067. }
  9068. }
  9069. }
  9070. return -1;
  9071. }
  9072. int String::lastIndexOfIgnoreCase (const tchar* const other) const throw()
  9073. {
  9074. if (other != 0 && *other != 0)
  9075. {
  9076. const int len = CharacterFunctions::length (other);
  9077. int i = length() - len;
  9078. if (i >= 0)
  9079. {
  9080. const tchar* n = text->text + i;
  9081. while (i >= 0)
  9082. {
  9083. if (CharacterFunctions::compareIgnoreCase (n--, other, len) == 0)
  9084. return i;
  9085. --i;
  9086. }
  9087. }
  9088. }
  9089. return -1;
  9090. }
  9091. int String::lastIndexOfAnyOf (const tchar* const charactersToLookFor,
  9092. const bool ignoreCase) const throw()
  9093. {
  9094. for (int i = CharacterFunctions::length (text->text); --i >= 0;)
  9095. if (CharacterFunctions::indexOfChar (charactersToLookFor, text->text [i], ignoreCase) >= 0)
  9096. return i;
  9097. return -1;
  9098. }
  9099. bool String::contains (const tchar* const other) const throw()
  9100. {
  9101. return indexOf (other) >= 0;
  9102. }
  9103. bool String::containsChar (const tchar character) const throw()
  9104. {
  9105. return indexOfChar (character) >= 0;
  9106. }
  9107. bool String::containsIgnoreCase (const tchar* const t) const throw()
  9108. {
  9109. return indexOfIgnoreCase (t) >= 0;
  9110. }
  9111. int String::indexOfWholeWord (const tchar* const word) const throw()
  9112. {
  9113. if (word != 0 && *word != 0)
  9114. {
  9115. const int wordLen = CharacterFunctions::length (word);
  9116. const int end = length() - wordLen;
  9117. const tchar* t = text->text;
  9118. for (int i = 0; i <= end; ++i)
  9119. {
  9120. if (CharacterFunctions::compare (t, word, wordLen) == 0
  9121. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9122. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9123. {
  9124. return i;
  9125. }
  9126. ++t;
  9127. }
  9128. }
  9129. return -1;
  9130. }
  9131. int String::indexOfWholeWordIgnoreCase (const tchar* const word) const throw()
  9132. {
  9133. if (word != 0 && *word != 0)
  9134. {
  9135. const int wordLen = CharacterFunctions::length (word);
  9136. const int end = length() - wordLen;
  9137. const tchar* t = text->text;
  9138. for (int i = 0; i <= end; ++i)
  9139. {
  9140. if (CharacterFunctions::compareIgnoreCase (t, word, wordLen) == 0
  9141. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9142. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9143. {
  9144. return i;
  9145. }
  9146. ++t;
  9147. }
  9148. }
  9149. return -1;
  9150. }
  9151. bool String::containsWholeWord (const tchar* const wordToLookFor) const throw()
  9152. {
  9153. return indexOfWholeWord (wordToLookFor) >= 0;
  9154. }
  9155. bool String::containsWholeWordIgnoreCase (const tchar* const wordToLookFor) const throw()
  9156. {
  9157. return indexOfWholeWordIgnoreCase (wordToLookFor) >= 0;
  9158. }
  9159. static int indexOfMatch (const tchar* const wildcard,
  9160. const tchar* const test,
  9161. const bool ignoreCase) throw()
  9162. {
  9163. int start = 0;
  9164. while (test [start] != 0)
  9165. {
  9166. int i = 0;
  9167. for (;;)
  9168. {
  9169. const tchar wc = wildcard [i];
  9170. const tchar c = test [i + start];
  9171. if (wc == c
  9172. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9173. || (wc == T('?') && c != 0))
  9174. {
  9175. if (wc == 0)
  9176. return start;
  9177. ++i;
  9178. }
  9179. else
  9180. {
  9181. if (wc == T('*') && (wildcard [i + 1] == 0
  9182. || indexOfMatch (wildcard + i + 1,
  9183. test + start + i,
  9184. ignoreCase) >= 0))
  9185. {
  9186. return start;
  9187. }
  9188. break;
  9189. }
  9190. }
  9191. ++start;
  9192. }
  9193. return -1;
  9194. }
  9195. bool String::matchesWildcard (const tchar* wildcard, const bool ignoreCase) const throw()
  9196. {
  9197. int i = 0;
  9198. for (;;)
  9199. {
  9200. const tchar wc = wildcard [i];
  9201. const tchar c = text->text [i];
  9202. if (wc == c
  9203. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9204. || (wc == T('?') && c != 0))
  9205. {
  9206. if (wc == 0)
  9207. return true;
  9208. ++i;
  9209. }
  9210. else
  9211. {
  9212. return wc == T('*') && (wildcard [i + 1] == 0
  9213. || indexOfMatch (wildcard + i + 1,
  9214. text->text + i,
  9215. ignoreCase) >= 0);
  9216. }
  9217. }
  9218. }
  9219. void String::printf (const tchar* const pf, ...) throw()
  9220. {
  9221. va_list list;
  9222. va_start (list, pf);
  9223. vprintf (pf, list);
  9224. }
  9225. const String String::formatted (const tchar* const pf, ...) throw()
  9226. {
  9227. va_list list;
  9228. va_start (list, pf);
  9229. String result;
  9230. result.vprintf (pf, list);
  9231. return result;
  9232. }
  9233. void String::vprintf (const tchar* const pf, va_list& args) throw()
  9234. {
  9235. int bufferSize = 256;
  9236. String result (bufferSize, 0);
  9237. do
  9238. {
  9239. #if JUCE_LINUX && JUCE_64BIT
  9240. va_list tempArgs;
  9241. va_copy (tempArgs, args);
  9242. const int num = CharacterFunctions::vprintf (result.text->text, bufferSize - 1, pf, tempArgs);
  9243. va_end (tempArgs);
  9244. #else
  9245. const int num = CharacterFunctions::vprintf (result.text->text, bufferSize - 1, pf, args);
  9246. #endif
  9247. if (num > 0)
  9248. {
  9249. *this = result;
  9250. break;
  9251. }
  9252. else if (num == 0)
  9253. {
  9254. *this = String::empty;
  9255. break;
  9256. }
  9257. bufferSize += 256;
  9258. result.preallocateStorage (bufferSize);
  9259. }
  9260. while (bufferSize < 65536); // this is a sanity check to avoid situations where vprintf repeatedly
  9261. // returns -1 because of an error rather than because it needs more space.
  9262. }
  9263. const String String::repeatedString (const tchar* const stringToRepeat,
  9264. int numberOfTimesToRepeat)
  9265. {
  9266. const int len = CharacterFunctions::length (stringToRepeat);
  9267. String result ((int) (len * numberOfTimesToRepeat + 1), (int) 0);
  9268. tchar* n = result.text->text;
  9269. n[0] = 0;
  9270. while (--numberOfTimesToRepeat >= 0)
  9271. {
  9272. CharacterFunctions::append (n, stringToRepeat);
  9273. n += len;
  9274. }
  9275. return result;
  9276. }
  9277. const String String::paddedLeft (const juce_wchar padCharacter, int minimumLength) const
  9278. {
  9279. if (padCharacter == 0)
  9280. {
  9281. jassertfalse;
  9282. return *this;
  9283. }
  9284. const int len = length();
  9285. if (len >= minimumLength)
  9286. return *this;
  9287. String result ((int) minimumLength + 1, (int) 0);
  9288. tchar* n = result.text->text;
  9289. minimumLength -= len;
  9290. while (--minimumLength >= 0)
  9291. *n++ = padCharacter;
  9292. *n = 0;
  9293. CharacterFunctions::append (n, text->text);
  9294. return result;
  9295. }
  9296. const String String::paddedRight (const juce_wchar padCharacter, int minimumLength) const
  9297. {
  9298. if (padCharacter == 0)
  9299. {
  9300. jassertfalse;
  9301. return *this;
  9302. }
  9303. const int paddingNeeded = minimumLength - length();
  9304. if (paddingNeeded <= 0)
  9305. return *this;
  9306. return *this + String::empty.paddedLeft (padCharacter, paddingNeeded);
  9307. }
  9308. const String String::replaceSection (int index,
  9309. int numCharsToReplace,
  9310. const tchar* const stringToInsert) const throw()
  9311. {
  9312. if (index < 0)
  9313. {
  9314. // a negative index to replace from?
  9315. jassertfalse
  9316. index = 0;
  9317. }
  9318. if (numCharsToReplace < 0)
  9319. {
  9320. // replacing a negative number of characters?
  9321. numCharsToReplace = 0;
  9322. jassertfalse;
  9323. }
  9324. const int len = length();
  9325. if (index + numCharsToReplace > len)
  9326. {
  9327. if (index > len)
  9328. {
  9329. // replacing beyond the end of the string?
  9330. index = len;
  9331. jassertfalse
  9332. }
  9333. numCharsToReplace = len - index;
  9334. }
  9335. const int newStringLen = (stringToInsert != 0) ? CharacterFunctions::length (stringToInsert) : 0;
  9336. const int newTotalLen = len + newStringLen - numCharsToReplace;
  9337. if (newTotalLen <= 0)
  9338. return String::empty;
  9339. String result (newTotalLen, (int) 0);
  9340. memcpy (result.text->text,
  9341. text->text,
  9342. index * sizeof (tchar));
  9343. if (newStringLen > 0)
  9344. memcpy (result.text->text + index,
  9345. stringToInsert,
  9346. newStringLen * sizeof (tchar));
  9347. const int endStringLen = newTotalLen - (index + newStringLen);
  9348. if (endStringLen > 0)
  9349. memcpy (result.text->text + (index + newStringLen),
  9350. text->text + (index + numCharsToReplace),
  9351. endStringLen * sizeof (tchar));
  9352. result.text->text [newTotalLen] = 0;
  9353. return result;
  9354. }
  9355. const String String::replace (const tchar* const stringToReplace,
  9356. const tchar* const stringToInsert,
  9357. const bool ignoreCase) const throw()
  9358. {
  9359. const int stringToReplaceLen = CharacterFunctions::length (stringToReplace);
  9360. const int stringToInsertLen = CharacterFunctions::length (stringToInsert);
  9361. int i = 0;
  9362. String result (*this);
  9363. while ((i = (ignoreCase ? result.indexOfIgnoreCase (i, stringToReplace)
  9364. : result.indexOf (i, stringToReplace))) >= 0)
  9365. {
  9366. result = result.replaceSection (i, stringToReplaceLen, stringToInsert);
  9367. i += stringToInsertLen;
  9368. }
  9369. return result;
  9370. }
  9371. const String String::replaceCharacter (const tchar charToReplace,
  9372. const tchar charToInsert) const throw()
  9373. {
  9374. const int index = indexOfChar (charToReplace);
  9375. if (index < 0)
  9376. return *this;
  9377. String result (*this);
  9378. result.dupeInternalIfMultiplyReferenced();
  9379. tchar* t = result.text->text + index;
  9380. while (*t != 0)
  9381. {
  9382. if (*t == charToReplace)
  9383. *t = charToInsert;
  9384. ++t;
  9385. }
  9386. return result;
  9387. }
  9388. const String String::replaceCharacters (const String& charactersToReplace,
  9389. const tchar* const charactersToInsertInstead) const throw()
  9390. {
  9391. String result (*this);
  9392. result.dupeInternalIfMultiplyReferenced();
  9393. tchar* t = result.text->text;
  9394. const int len2 = CharacterFunctions::length (charactersToInsertInstead);
  9395. // the two strings passed in are supposed to be the same length!
  9396. jassert (len2 == charactersToReplace.length());
  9397. while (*t != 0)
  9398. {
  9399. const int index = charactersToReplace.indexOfChar (*t);
  9400. if (((unsigned int) index) < (unsigned int) len2)
  9401. *t = charactersToInsertInstead [index];
  9402. ++t;
  9403. }
  9404. return result;
  9405. }
  9406. bool String::startsWith (const tchar* const other) const throw()
  9407. {
  9408. return other != 0
  9409. && CharacterFunctions::compare (text->text, other, CharacterFunctions::length (other)) == 0;
  9410. }
  9411. bool String::startsWithIgnoreCase (const tchar* const other) const throw()
  9412. {
  9413. return other != 0
  9414. && CharacterFunctions::compareIgnoreCase (text->text, other, CharacterFunctions::length (other)) == 0;
  9415. }
  9416. bool String::startsWithChar (const tchar character) const throw()
  9417. {
  9418. jassert (character != 0); // strings can't contain a null character!
  9419. return text->text[0] == character;
  9420. }
  9421. bool String::endsWithChar (const tchar character) const throw()
  9422. {
  9423. jassert (character != 0); // strings can't contain a null character!
  9424. return text->text[0] != 0
  9425. && text->text [length() - 1] == character;
  9426. }
  9427. bool String::endsWith (const tchar* const other) const throw()
  9428. {
  9429. if (other == 0)
  9430. return false;
  9431. const int thisLen = length();
  9432. const int otherLen = CharacterFunctions::length (other);
  9433. return thisLen >= otherLen
  9434. && CharacterFunctions::compare (text->text + thisLen - otherLen, other) == 0;
  9435. }
  9436. bool String::endsWithIgnoreCase (const tchar* const other) const throw()
  9437. {
  9438. if (other == 0)
  9439. return false;
  9440. const int thisLen = length();
  9441. const int otherLen = CharacterFunctions::length (other);
  9442. return thisLen >= otherLen
  9443. && CharacterFunctions::compareIgnoreCase (text->text + thisLen - otherLen, other) == 0;
  9444. }
  9445. const String String::toUpperCase() const throw()
  9446. {
  9447. String result (*this);
  9448. result.dupeInternalIfMultiplyReferenced();
  9449. CharacterFunctions::toUpperCase (result.text->text);
  9450. return result;
  9451. }
  9452. const String String::toLowerCase() const throw()
  9453. {
  9454. String result (*this);
  9455. result.dupeInternalIfMultiplyReferenced();
  9456. CharacterFunctions::toLowerCase (result.text->text);
  9457. return result;
  9458. }
  9459. juce_wchar& String::operator[] (const int index) throw()
  9460. {
  9461. jassert (((unsigned int) index) <= (unsigned int) length());
  9462. dupeInternalIfMultiplyReferenced();
  9463. return text->text [index];
  9464. }
  9465. juce_wchar String::getLastCharacter() const throw()
  9466. {
  9467. return (isEmpty()) ? ((juce_wchar) 0)
  9468. : text->text [CharacterFunctions::length (text->text) - 1];
  9469. }
  9470. const String String::substring (int start, int end) const throw()
  9471. {
  9472. if (start < 0)
  9473. start = 0;
  9474. else if (end <= start)
  9475. return empty;
  9476. int len = 0;
  9477. const tchar* const t = text->text;
  9478. while (len <= end && t [len] != 0)
  9479. ++len;
  9480. if (end >= len)
  9481. {
  9482. if (start == 0)
  9483. return *this;
  9484. end = len;
  9485. }
  9486. return String (text->text + start,
  9487. end - start);
  9488. }
  9489. const String String::substring (const int start) const throw()
  9490. {
  9491. if (start <= 0)
  9492. return *this;
  9493. const int len = CharacterFunctions::length (text->text);
  9494. if (start >= len)
  9495. return empty;
  9496. else
  9497. return String (text->text + start,
  9498. len - start);
  9499. }
  9500. const String String::dropLastCharacters (const int numberToDrop) const throw()
  9501. {
  9502. return String (text->text,
  9503. jmax (0, CharacterFunctions::length (text->text) - numberToDrop));
  9504. }
  9505. const String String::getLastCharacters (const int numCharacters) const throw()
  9506. {
  9507. return String (text->text + jmax (0, CharacterFunctions::length (text->text) - jmax (0, numCharacters)));
  9508. }
  9509. const String String::fromFirstOccurrenceOf (const tchar* const sub,
  9510. const bool includeSubString,
  9511. const bool ignoreCase) const throw()
  9512. {
  9513. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9514. : indexOf (sub);
  9515. if (i < 0)
  9516. return empty;
  9517. else
  9518. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9519. }
  9520. const String String::fromLastOccurrenceOf (const tchar* const sub,
  9521. const bool includeSubString,
  9522. const bool ignoreCase) const throw()
  9523. {
  9524. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9525. : lastIndexOf (sub);
  9526. if (i < 0)
  9527. return *this;
  9528. else
  9529. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9530. }
  9531. const String String::upToFirstOccurrenceOf (const tchar* const sub,
  9532. const bool includeSubString,
  9533. const bool ignoreCase) const throw()
  9534. {
  9535. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9536. : indexOf (sub);
  9537. if (i < 0)
  9538. return *this;
  9539. else
  9540. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9541. }
  9542. const String String::upToLastOccurrenceOf (const tchar* const sub,
  9543. const bool includeSubString,
  9544. const bool ignoreCase) const throw()
  9545. {
  9546. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9547. : lastIndexOf (sub);
  9548. if (i < 0)
  9549. return *this;
  9550. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9551. }
  9552. bool String::isQuotedString() const throw()
  9553. {
  9554. const String trimmed (trimStart());
  9555. return trimmed[0] == T('"')
  9556. || trimmed[0] == T('\'');
  9557. }
  9558. const String String::unquoted() const throw()
  9559. {
  9560. String s (*this);
  9561. if (s[0] == T('"') || s[0] == T('\''))
  9562. s = s.substring (1);
  9563. const int lastCharIndex = s.length() - 1;
  9564. if (lastCharIndex >= 0
  9565. && (s [lastCharIndex] == T('"') || s[lastCharIndex] == T('\'')))
  9566. s [lastCharIndex] = 0;
  9567. return s;
  9568. }
  9569. const String String::quoted (const tchar quoteCharacter) const throw()
  9570. {
  9571. if (isEmpty())
  9572. return charToString (quoteCharacter) + quoteCharacter;
  9573. String t (*this);
  9574. if (! t.startsWithChar (quoteCharacter))
  9575. t = charToString (quoteCharacter) + t;
  9576. if (! t.endsWithChar (quoteCharacter))
  9577. t += quoteCharacter;
  9578. return t;
  9579. }
  9580. const String String::trim() const throw()
  9581. {
  9582. if (isEmpty())
  9583. return empty;
  9584. int start = 0;
  9585. while (CharacterFunctions::isWhitespace (text->text [start]))
  9586. ++start;
  9587. const int len = CharacterFunctions::length (text->text);
  9588. int end = len - 1;
  9589. while ((end >= start) && CharacterFunctions::isWhitespace (text->text [end]))
  9590. --end;
  9591. ++end;
  9592. if (end <= start)
  9593. return empty;
  9594. else if (start > 0 || end < len)
  9595. return String (text->text + start, end - start);
  9596. else
  9597. return *this;
  9598. }
  9599. const String String::trimStart() const throw()
  9600. {
  9601. if (isEmpty())
  9602. return empty;
  9603. const tchar* t = text->text;
  9604. while (CharacterFunctions::isWhitespace (*t))
  9605. ++t;
  9606. if (t == text->text)
  9607. return *this;
  9608. else
  9609. return String (t);
  9610. }
  9611. const String String::trimEnd() const throw()
  9612. {
  9613. if (isEmpty())
  9614. return empty;
  9615. const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1);
  9616. while ((endT >= text->text) && CharacterFunctions::isWhitespace (*endT))
  9617. --endT;
  9618. return String (text->text, (int) (++endT - text->text));
  9619. }
  9620. const String String::trimCharactersAtStart (const tchar* charactersToTrim) const throw()
  9621. {
  9622. jassert (charactersToTrim != 0);
  9623. if (isEmpty())
  9624. return empty;
  9625. const tchar* t = text->text;
  9626. while (CharacterFunctions::indexOfCharFast (charactersToTrim, *t) >= 0)
  9627. ++t;
  9628. if (t == text->text)
  9629. return *this;
  9630. else
  9631. return String (t);
  9632. }
  9633. const String String::trimCharactersAtEnd (const tchar* charactersToTrim) const throw()
  9634. {
  9635. jassert (charactersToTrim != 0);
  9636. if (isEmpty())
  9637. return empty;
  9638. const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1);
  9639. while ((endT >= text->text) && CharacterFunctions::indexOfCharFast (charactersToTrim, *endT) >= 0)
  9640. --endT;
  9641. return String (text->text, (int) (++endT - text->text));
  9642. }
  9643. const String String::retainCharacters (const tchar* const charactersToRetain) const throw()
  9644. {
  9645. jassert (charactersToRetain != 0);
  9646. if (isEmpty())
  9647. return empty;
  9648. String result (text->allocatedNumChars, (int) 0);
  9649. tchar* dst = result.text->text;
  9650. const tchar* src = text->text;
  9651. while (*src != 0)
  9652. {
  9653. if (CharacterFunctions::indexOfCharFast (charactersToRetain, *src) >= 0)
  9654. *dst++ = *src;
  9655. ++src;
  9656. }
  9657. *dst = 0;
  9658. return result;
  9659. }
  9660. const String String::removeCharacters (const tchar* const charactersToRemove) const throw()
  9661. {
  9662. jassert (charactersToRemove != 0);
  9663. if (isEmpty())
  9664. return empty;
  9665. String result (text->allocatedNumChars, (int) 0);
  9666. tchar* dst = result.text->text;
  9667. const tchar* src = text->text;
  9668. while (*src != 0)
  9669. {
  9670. if (CharacterFunctions::indexOfCharFast (charactersToRemove, *src) < 0)
  9671. *dst++ = *src;
  9672. ++src;
  9673. }
  9674. *dst = 0;
  9675. return result;
  9676. }
  9677. const String String::initialSectionContainingOnly (const tchar* const permittedCharacters) const throw()
  9678. {
  9679. return substring (0, CharacterFunctions::getIntialSectionContainingOnly (text->text, permittedCharacters));
  9680. }
  9681. const String String::initialSectionNotContaining (const tchar* const charactersToStopAt) const throw()
  9682. {
  9683. jassert (charactersToStopAt != 0);
  9684. const tchar* const t = text->text;
  9685. int i = 0;
  9686. while (t[i] != 0)
  9687. {
  9688. if (CharacterFunctions::indexOfCharFast (charactersToStopAt, t[i]) >= 0)
  9689. return String (text->text, i);
  9690. ++i;
  9691. }
  9692. return empty;
  9693. }
  9694. bool String::containsOnly (const tchar* const chars) const throw()
  9695. {
  9696. jassert (chars != 0);
  9697. const tchar* t = text->text;
  9698. while (*t != 0)
  9699. if (CharacterFunctions::indexOfCharFast (chars, *t++) < 0)
  9700. return false;
  9701. return true;
  9702. }
  9703. bool String::containsAnyOf (const tchar* const chars) const throw()
  9704. {
  9705. jassert (chars != 0);
  9706. const tchar* t = text->text;
  9707. while (*t != 0)
  9708. if (CharacterFunctions::indexOfCharFast (chars, *t++) >= 0)
  9709. return true;
  9710. return false;
  9711. }
  9712. bool String::containsNonWhitespaceChars() const throw()
  9713. {
  9714. const tchar* t = text->text;
  9715. while (*t != 0)
  9716. if (! CharacterFunctions::isWhitespace (*t++))
  9717. return true;
  9718. return false;
  9719. }
  9720. int String::getIntValue() const throw()
  9721. {
  9722. return CharacterFunctions::getIntValue (text->text);
  9723. }
  9724. int String::getTrailingIntValue() const throw()
  9725. {
  9726. int n = 0;
  9727. int mult = 1;
  9728. const tchar* t = text->text + length();
  9729. while (--t >= text->text)
  9730. {
  9731. const tchar c = *t;
  9732. if (! CharacterFunctions::isDigit (c))
  9733. {
  9734. if (c == T('-'))
  9735. n = -n;
  9736. break;
  9737. }
  9738. n += mult * (c - T('0'));
  9739. mult *= 10;
  9740. }
  9741. return n;
  9742. }
  9743. int64 String::getLargeIntValue() const throw()
  9744. {
  9745. return CharacterFunctions::getInt64Value (text->text);
  9746. }
  9747. float String::getFloatValue() const throw()
  9748. {
  9749. return (float) CharacterFunctions::getDoubleValue (text->text);
  9750. }
  9751. double String::getDoubleValue() const throw()
  9752. {
  9753. return CharacterFunctions::getDoubleValue (text->text);
  9754. }
  9755. static const tchar* const hexDigits = T("0123456789abcdef");
  9756. const String String::toHexString (const int number) throw()
  9757. {
  9758. tchar buffer[32];
  9759. tchar* const end = buffer + 32;
  9760. tchar* t = end;
  9761. *--t = 0;
  9762. unsigned int v = (unsigned int) number;
  9763. do
  9764. {
  9765. *--t = hexDigits [v & 15];
  9766. v >>= 4;
  9767. } while (v != 0);
  9768. return String (t, (int) (((char*) end) - (char*) t) - 1);
  9769. }
  9770. const String String::toHexString (const int64 number) throw()
  9771. {
  9772. tchar buffer[32];
  9773. tchar* const end = buffer + 32;
  9774. tchar* t = end;
  9775. *--t = 0;
  9776. uint64 v = (uint64) number;
  9777. do
  9778. {
  9779. *--t = hexDigits [(int) (v & 15)];
  9780. v >>= 4;
  9781. } while (v != 0);
  9782. return String (t, (int) (((char*) end) - (char*) t));
  9783. }
  9784. const String String::toHexString (const short number) throw()
  9785. {
  9786. return toHexString ((int) (unsigned short) number);
  9787. }
  9788. const String String::toHexString (const unsigned char* data,
  9789. const int size,
  9790. const int groupSize) throw()
  9791. {
  9792. if (size <= 0)
  9793. return empty;
  9794. int numChars = (size * 2) + 2;
  9795. if (groupSize > 0)
  9796. numChars += size / groupSize;
  9797. String s (numChars, (int) 0);
  9798. tchar* d = s.text->text;
  9799. for (int i = 0; i < size; ++i)
  9800. {
  9801. *d++ = hexDigits [(*data) >> 4];
  9802. *d++ = hexDigits [(*data) & 0xf];
  9803. ++data;
  9804. if (groupSize > 0 && (i % groupSize) == (groupSize - 1) && i < (size - 1))
  9805. *d++ = T(' ');
  9806. }
  9807. *d = 0;
  9808. return s;
  9809. }
  9810. int String::getHexValue32() const throw()
  9811. {
  9812. int result = 0;
  9813. const tchar* c = text->text;
  9814. for (;;)
  9815. {
  9816. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9817. if (hexValue >= 0)
  9818. result = (result << 4) | hexValue;
  9819. else if (*c == 0)
  9820. break;
  9821. ++c;
  9822. }
  9823. return result;
  9824. }
  9825. int64 String::getHexValue64() const throw()
  9826. {
  9827. int64 result = 0;
  9828. const tchar* c = text->text;
  9829. for (;;)
  9830. {
  9831. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9832. if (hexValue >= 0)
  9833. result = (result << 4) | hexValue;
  9834. else if (*c == 0)
  9835. break;
  9836. ++c;
  9837. }
  9838. return result;
  9839. }
  9840. const String String::createStringFromData (const void* const data_,
  9841. const int size) throw()
  9842. {
  9843. const char* const data = (const char*) data_;
  9844. if (size <= 0 || data == 0)
  9845. {
  9846. return empty;
  9847. }
  9848. else if (size < 2)
  9849. {
  9850. return charToString (data[0]);
  9851. }
  9852. else if ((data[0] == (char)-2 && data[1] == (char)-1)
  9853. || (data[0] == (char)-1 && data[1] == (char)-2))
  9854. {
  9855. // assume it's 16-bit unicode
  9856. const bool bigEndian = (data[0] == (char)-2);
  9857. const int numChars = size / 2 - 1;
  9858. String result;
  9859. result.preallocateStorage (numChars + 2);
  9860. const uint16* const src = (const uint16*) (data + 2);
  9861. tchar* const dst = const_cast <tchar*> ((const tchar*) result);
  9862. if (bigEndian)
  9863. {
  9864. for (int i = 0; i < numChars; ++i)
  9865. dst[i] = (tchar) ByteOrder::swapIfLittleEndian (src[i]);
  9866. }
  9867. else
  9868. {
  9869. for (int i = 0; i < numChars; ++i)
  9870. dst[i] = (tchar) ByteOrder::swapIfBigEndian (src[i]);
  9871. }
  9872. dst [numChars] = 0;
  9873. return result;
  9874. }
  9875. else
  9876. {
  9877. return String::fromUTF8 (data, size);
  9878. }
  9879. }
  9880. const char* String::toUTF8() const
  9881. {
  9882. if (isEmpty())
  9883. {
  9884. return (const char*) emptyCharString;
  9885. }
  9886. else
  9887. {
  9888. String* const mutableThis = const_cast <String*> (this);
  9889. mutableThis->dupeInternalIfMultiplyReferenced();
  9890. const int currentLen = CharacterFunctions::length (text->text) + 1;
  9891. const int utf8BytesNeeded = getNumBytesAsUTF8() + 1;
  9892. mutableThis->text = (InternalRefCountedStringHolder*)
  9893. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  9894. + (currentLen * sizeof (juce_wchar) + utf8BytesNeeded));
  9895. char* const otherCopy = (char*) (text->text + currentLen);
  9896. copyToUTF8 (otherCopy, std::numeric_limits<int>::max());
  9897. return otherCopy;
  9898. }
  9899. }
  9900. int String::copyToUTF8 (char* const buffer, const int maxBufferSizeBytes) const throw()
  9901. {
  9902. jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied!
  9903. int num = 0, index = 0;
  9904. for (;;)
  9905. {
  9906. const uint32 c = (uint32) text->text [index++];
  9907. if (c >= 0x80)
  9908. {
  9909. int numExtraBytes = 1;
  9910. if (c >= 0x800)
  9911. {
  9912. ++numExtraBytes;
  9913. if (c >= 0x10000)
  9914. {
  9915. ++numExtraBytes;
  9916. if (c >= 0x200000)
  9917. {
  9918. ++numExtraBytes;
  9919. if (c >= 0x4000000)
  9920. ++numExtraBytes;
  9921. }
  9922. }
  9923. }
  9924. if (buffer != 0)
  9925. {
  9926. if (num + numExtraBytes >= maxBufferSizeBytes)
  9927. {
  9928. buffer [num++] = 0;
  9929. break;
  9930. }
  9931. else
  9932. {
  9933. buffer [num++] = (uint8) ((0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
  9934. while (--numExtraBytes >= 0)
  9935. buffer [num++] = (uint8) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
  9936. }
  9937. }
  9938. else
  9939. {
  9940. num += numExtraBytes + 1;
  9941. }
  9942. }
  9943. else
  9944. {
  9945. if (buffer != 0)
  9946. {
  9947. if (num + 1 >= maxBufferSizeBytes)
  9948. {
  9949. buffer [num++] = 0;
  9950. break;
  9951. }
  9952. buffer [num] = (uint8) c;
  9953. }
  9954. ++num;
  9955. }
  9956. if (c == 0)
  9957. break;
  9958. }
  9959. return num;
  9960. }
  9961. int String::getNumBytesAsUTF8() const throw()
  9962. {
  9963. int num = 0;
  9964. const juce_wchar* t = text->text;
  9965. for (;;)
  9966. {
  9967. const uint32 c = (uint32) *t;
  9968. if (c >= 0x80)
  9969. {
  9970. ++num;
  9971. if (c >= 0x800)
  9972. {
  9973. ++num;
  9974. if (c >= 0x10000)
  9975. {
  9976. ++num;
  9977. if (c >= 0x200000)
  9978. {
  9979. ++num;
  9980. if (c >= 0x4000000)
  9981. ++num;
  9982. }
  9983. }
  9984. }
  9985. }
  9986. else if (c == 0)
  9987. break;
  9988. ++num;
  9989. ++t;
  9990. }
  9991. return num;
  9992. }
  9993. const String String::fromUTF8 (const char* const buffer, int bufferSizeBytes)
  9994. {
  9995. if (buffer == 0)
  9996. return empty;
  9997. if (bufferSizeBytes < 0)
  9998. bufferSizeBytes = std::numeric_limits<int>::max();
  9999. size_t numBytes;
  10000. for (numBytes = 0; numBytes < (size_t) bufferSizeBytes; ++numBytes)
  10001. if (buffer [numBytes] == 0)
  10002. break;
  10003. String result ((int) numBytes + 1, 0);
  10004. juce_wchar* dest = result.text->text;
  10005. size_t i = 0;
  10006. while (i < numBytes)
  10007. {
  10008. const char c = buffer [i++];
  10009. if (c < 0)
  10010. {
  10011. unsigned int mask = 0x7f;
  10012. int bit = 0x40;
  10013. int numExtraValues = 0;
  10014. while (bit != 0 && (c & bit) != 0)
  10015. {
  10016. bit >>= 1;
  10017. mask >>= 1;
  10018. ++numExtraValues;
  10019. }
  10020. int n = (mask & (unsigned char) c);
  10021. while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes)
  10022. {
  10023. const char nextByte = buffer[i];
  10024. if ((nextByte & 0xc0) != 0x80)
  10025. break;
  10026. n <<= 6;
  10027. n |= (nextByte & 0x3f);
  10028. ++i;
  10029. }
  10030. *dest++ = (juce_wchar) n;
  10031. }
  10032. else
  10033. {
  10034. *dest++ = (juce_wchar) c;
  10035. }
  10036. }
  10037. *dest = 0;
  10038. return result;
  10039. }
  10040. const char* String::toCString() const
  10041. {
  10042. if (isEmpty())
  10043. {
  10044. return (const char*) emptyCharString;
  10045. }
  10046. else
  10047. {
  10048. String* const mutableThis = const_cast <String*> (this);
  10049. mutableThis->dupeInternalIfMultiplyReferenced();
  10050. int len = length() + 1;
  10051. mutableThis->text = (InternalRefCountedStringHolder*)
  10052. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  10053. + (len * sizeof (juce_wchar) + len));
  10054. char* otherCopy = (char*) (text->text + len);
  10055. --len;
  10056. CharacterFunctions::copy (otherCopy, text->text, len);
  10057. otherCopy [len] = 0;
  10058. return otherCopy;
  10059. }
  10060. }
  10061. #ifdef _MSC_VER
  10062. #pragma warning (disable: 4514 4996)
  10063. #pragma warning (push)
  10064. #endif
  10065. int String::getNumBytesAsCString() const throw()
  10066. {
  10067. return (int) wcstombs (0, text->text, 0);
  10068. }
  10069. int String::copyToCString (char* destBuffer, const int maxBufferSizeBytes) const throw()
  10070. {
  10071. const int numBytes = (int) wcstombs (destBuffer, text->text, maxBufferSizeBytes);
  10072. if (destBuffer != 0 && numBytes >= 0)
  10073. destBuffer [numBytes] = 0;
  10074. return numBytes;
  10075. }
  10076. #ifdef _MSC_VER
  10077. #pragma warning (pop)
  10078. #endif
  10079. void String::copyToUnicode (juce_wchar* const destBuffer, const int maxCharsToCopy) const throw()
  10080. {
  10081. const int len = jmin (maxCharsToCopy, length());
  10082. memcpy (destBuffer, text->text, len * sizeof (juce_wchar));
  10083. destBuffer [len] = 0;
  10084. }
  10085. String::Concatenator::Concatenator (String& stringToAppendTo)
  10086. : result (stringToAppendTo),
  10087. nextIndex (stringToAppendTo.length())
  10088. {
  10089. }
  10090. String::Concatenator::~Concatenator()
  10091. {
  10092. }
  10093. void String::Concatenator::append (const String& s)
  10094. {
  10095. const int len = s.length();
  10096. if (len > 0)
  10097. {
  10098. result.preallocateStorage (nextIndex + len);
  10099. s.copyToUnicode (((juce_wchar*) result) + nextIndex, len);
  10100. nextIndex += len;
  10101. }
  10102. }
  10103. END_JUCE_NAMESPACE
  10104. /*** End of inlined file: juce_String.cpp ***/
  10105. /*** Start of inlined file: juce_StringArray.cpp ***/
  10106. BEGIN_JUCE_NAMESPACE
  10107. StringArray::StringArray() throw()
  10108. {
  10109. }
  10110. StringArray::StringArray (const StringArray& other)
  10111. : strings (other.strings)
  10112. {
  10113. }
  10114. StringArray::StringArray (const juce_wchar** const initialStrings,
  10115. const int numberOfStrings)
  10116. {
  10117. for (int i = 0; i < numberOfStrings; ++i)
  10118. add (initialStrings [i]);
  10119. }
  10120. StringArray::StringArray (const char** const initialStrings,
  10121. const int numberOfStrings)
  10122. {
  10123. for (int i = 0; i < numberOfStrings; ++i)
  10124. add (initialStrings [i]);
  10125. }
  10126. StringArray::StringArray (const juce_wchar** const initialStrings)
  10127. {
  10128. int i = 0;
  10129. while (initialStrings[i] != 0)
  10130. add (initialStrings [i++]);
  10131. }
  10132. StringArray::StringArray (const char** const initialStrings)
  10133. {
  10134. int i = 0;
  10135. while (initialStrings[i] != 0)
  10136. add (initialStrings [i++]);
  10137. }
  10138. StringArray& StringArray::operator= (const StringArray& other)
  10139. {
  10140. strings = other.strings;
  10141. return *this;
  10142. }
  10143. StringArray::~StringArray()
  10144. {
  10145. }
  10146. bool StringArray::operator== (const StringArray& other) const
  10147. {
  10148. if (other.size() != size())
  10149. return false;
  10150. for (int i = size(); --i >= 0;)
  10151. if (other.strings.getReference(i) != strings.getReference(i))
  10152. return false;
  10153. return true;
  10154. }
  10155. bool StringArray::operator!= (const StringArray& other) const
  10156. {
  10157. return ! operator== (other);
  10158. }
  10159. void StringArray::clear()
  10160. {
  10161. strings.clear();
  10162. }
  10163. const String& StringArray::operator[] (const int index) const throw()
  10164. {
  10165. if (((unsigned int) index) < (unsigned int) strings.size())
  10166. return strings.getReference (index);
  10167. return String::empty;
  10168. }
  10169. void StringArray::add (const String& newString)
  10170. {
  10171. strings.add (newString);
  10172. }
  10173. void StringArray::insert (const int index, const String& newString)
  10174. {
  10175. strings.insert (index, newString);
  10176. }
  10177. void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
  10178. {
  10179. if (! contains (newString, ignoreCase))
  10180. add (newString);
  10181. }
  10182. void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)
  10183. {
  10184. if (startIndex < 0)
  10185. {
  10186. jassertfalse
  10187. startIndex = 0;
  10188. }
  10189. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.size())
  10190. numElementsToAdd = otherArray.size() - startIndex;
  10191. while (--numElementsToAdd >= 0)
  10192. strings.add (otherArray.strings.getReference (startIndex++));
  10193. }
  10194. void StringArray::set (const int index, const String& newString)
  10195. {
  10196. strings.set (index, newString);
  10197. }
  10198. bool StringArray::contains (const String& stringToLookFor, const bool ignoreCase) const
  10199. {
  10200. if (ignoreCase)
  10201. {
  10202. for (int i = size(); --i >= 0;)
  10203. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10204. return true;
  10205. }
  10206. else
  10207. {
  10208. for (int i = size(); --i >= 0;)
  10209. if (stringToLookFor == strings.getReference(i))
  10210. return true;
  10211. }
  10212. return false;
  10213. }
  10214. int StringArray::indexOf (const String& stringToLookFor, const bool ignoreCase, int i) const
  10215. {
  10216. if (i < 0)
  10217. i = 0;
  10218. const int numElements = size();
  10219. if (ignoreCase)
  10220. {
  10221. while (i < numElements)
  10222. {
  10223. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10224. return i;
  10225. ++i;
  10226. }
  10227. }
  10228. else
  10229. {
  10230. while (i < numElements)
  10231. {
  10232. if (stringToLookFor == strings.getReference (i))
  10233. return i;
  10234. ++i;
  10235. }
  10236. }
  10237. return -1;
  10238. }
  10239. void StringArray::remove (const int index)
  10240. {
  10241. strings.remove (index);
  10242. }
  10243. void StringArray::removeString (const String& stringToRemove,
  10244. const bool ignoreCase)
  10245. {
  10246. if (ignoreCase)
  10247. {
  10248. for (int i = size(); --i >= 0;)
  10249. if (strings.getReference(i).equalsIgnoreCase (stringToRemove))
  10250. strings.remove (i);
  10251. }
  10252. else
  10253. {
  10254. for (int i = size(); --i >= 0;)
  10255. if (stringToRemove == strings.getReference (i))
  10256. strings.remove (i);
  10257. }
  10258. }
  10259. void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings)
  10260. {
  10261. if (removeWhitespaceStrings)
  10262. {
  10263. for (int i = size(); --i >= 0;)
  10264. if (! strings.getReference(i).containsNonWhitespaceChars())
  10265. strings.remove (i);
  10266. }
  10267. else
  10268. {
  10269. for (int i = size(); --i >= 0;)
  10270. if (strings.getReference(i).isEmpty())
  10271. strings.remove (i);
  10272. }
  10273. }
  10274. void StringArray::trim()
  10275. {
  10276. for (int i = size(); --i >= 0;)
  10277. {
  10278. String& s = strings.getReference(i);
  10279. s = s.trim();
  10280. }
  10281. }
  10282. class InternalStringArrayComparator_CaseSensitive
  10283. {
  10284. public:
  10285. static int compareElements (String& first, String& second) { return first.compare (second); }
  10286. };
  10287. class InternalStringArrayComparator_CaseInsensitive
  10288. {
  10289. public:
  10290. static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
  10291. };
  10292. void StringArray::sort (const bool ignoreCase)
  10293. {
  10294. if (ignoreCase)
  10295. {
  10296. InternalStringArrayComparator_CaseInsensitive comp;
  10297. strings.sort (comp);
  10298. }
  10299. else
  10300. {
  10301. InternalStringArrayComparator_CaseSensitive comp;
  10302. strings.sort (comp);
  10303. }
  10304. }
  10305. void StringArray::move (const int currentIndex, int newIndex) throw()
  10306. {
  10307. strings.move (currentIndex, newIndex);
  10308. }
  10309. const String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const
  10310. {
  10311. const int last = (numberToJoin < 0) ? size()
  10312. : jmin (size(), start + numberToJoin);
  10313. if (start < 0)
  10314. start = 0;
  10315. if (start >= last)
  10316. return String::empty;
  10317. if (start == last - 1)
  10318. return strings.getReference (start);
  10319. const int separatorLen = separator.length();
  10320. int charsNeeded = separatorLen * (last - start - 1);
  10321. for (int i = start; i < last; ++i)
  10322. charsNeeded += strings.getReference(i).length();
  10323. String result;
  10324. result.preallocateStorage (charsNeeded);
  10325. juce_wchar* dest = (juce_wchar*) result;
  10326. while (start < last)
  10327. {
  10328. const String& s = strings.getReference (start);
  10329. const int len = s.length();
  10330. if (len > 0)
  10331. {
  10332. s.copyToUnicode (dest, len);
  10333. dest += len;
  10334. }
  10335. if (++start < last && separatorLen > 0)
  10336. {
  10337. separator.copyToUnicode (dest, separatorLen);
  10338. dest += separatorLen;
  10339. }
  10340. }
  10341. *dest = 0;
  10342. return result;
  10343. }
  10344. int StringArray::addTokens (const tchar* const text, const bool preserveQuotedStrings)
  10345. {
  10346. return addTokens (text,
  10347. T(" \n\r\t"),
  10348. preserveQuotedStrings ? T("\"") : 0);
  10349. }
  10350. int StringArray::addTokens (const tchar* const text, const tchar* breakCharacters, const tchar* quoteCharacters)
  10351. {
  10352. int num = 0;
  10353. if (text != 0 && *text != 0)
  10354. {
  10355. if (breakCharacters == 0)
  10356. breakCharacters = T("");
  10357. if (quoteCharacters == 0)
  10358. quoteCharacters = T("");
  10359. bool insideQuotes = false;
  10360. tchar currentQuoteChar = 0;
  10361. int i = 0;
  10362. int tokenStart = 0;
  10363. for (;;)
  10364. {
  10365. const tchar c = text[i];
  10366. bool isBreak = (c == 0);
  10367. if (! (insideQuotes || isBreak))
  10368. {
  10369. const tchar* b = breakCharacters;
  10370. while (*b != 0)
  10371. {
  10372. if (*b++ == c)
  10373. {
  10374. isBreak = true;
  10375. break;
  10376. }
  10377. }
  10378. }
  10379. if (! isBreak)
  10380. {
  10381. bool isQuote = false;
  10382. const tchar* q = quoteCharacters;
  10383. while (*q != 0)
  10384. {
  10385. if (*q++ == c)
  10386. {
  10387. isQuote = true;
  10388. break;
  10389. }
  10390. }
  10391. if (isQuote)
  10392. {
  10393. if (insideQuotes)
  10394. {
  10395. // only break out of quotes-mode if we find a matching quote to the
  10396. // one that we opened with..
  10397. if (currentQuoteChar == c)
  10398. insideQuotes = false;
  10399. }
  10400. else
  10401. {
  10402. insideQuotes = true;
  10403. currentQuoteChar = c;
  10404. }
  10405. }
  10406. }
  10407. else
  10408. {
  10409. add (String (text + tokenStart, i - tokenStart));
  10410. ++num;
  10411. tokenStart = i + 1;
  10412. }
  10413. if (c == 0)
  10414. break;
  10415. ++i;
  10416. }
  10417. }
  10418. return num;
  10419. }
  10420. int StringArray::addLines (const tchar* text)
  10421. {
  10422. int numLines = 0;
  10423. if (text != 0)
  10424. {
  10425. while (*text != 0)
  10426. {
  10427. const tchar* const startOfLine = text;
  10428. while (*text != 0)
  10429. {
  10430. if (*text == T('\r'))
  10431. {
  10432. ++text;
  10433. if (*text == T('\n'))
  10434. ++text;
  10435. break;
  10436. }
  10437. if (*text == T('\n'))
  10438. {
  10439. ++text;
  10440. break;
  10441. }
  10442. ++text;
  10443. }
  10444. const tchar* endOfLine = text;
  10445. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10446. --endOfLine;
  10447. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10448. --endOfLine;
  10449. add (String (startOfLine, jmax (0, (int) (endOfLine - startOfLine))));
  10450. ++numLines;
  10451. }
  10452. }
  10453. return numLines;
  10454. }
  10455. void StringArray::removeDuplicates (const bool ignoreCase)
  10456. {
  10457. for (int i = 0; i < size() - 1; ++i)
  10458. {
  10459. const String s (strings.getReference(i));
  10460. int nextIndex = i + 1;
  10461. for (;;)
  10462. {
  10463. nextIndex = indexOf (s, ignoreCase, nextIndex);
  10464. if (nextIndex < 0)
  10465. break;
  10466. strings.remove (nextIndex);
  10467. }
  10468. }
  10469. }
  10470. void StringArray::appendNumbersToDuplicates (const bool ignoreCase,
  10471. const bool appendNumberToFirstInstance,
  10472. const tchar* const preNumberString,
  10473. const tchar* const postNumberString)
  10474. {
  10475. for (int i = 0; i < size() - 1; ++i)
  10476. {
  10477. String& s = strings.getReference(i);
  10478. int nextIndex = indexOf (s, ignoreCase, i + 1);
  10479. if (nextIndex >= 0)
  10480. {
  10481. const String original (s);
  10482. int number = 0;
  10483. if (appendNumberToFirstInstance)
  10484. s = original + preNumberString + String (++number) + postNumberString;
  10485. else
  10486. ++number;
  10487. while (nextIndex >= 0)
  10488. {
  10489. set (nextIndex, (*this)[nextIndex] + preNumberString + String (++number) + postNumberString);
  10490. nextIndex = indexOf (original, ignoreCase, nextIndex + 1);
  10491. }
  10492. }
  10493. }
  10494. }
  10495. void StringArray::minimiseStorageOverheads()
  10496. {
  10497. strings.minimiseStorageOverheads();
  10498. }
  10499. END_JUCE_NAMESPACE
  10500. /*** End of inlined file: juce_StringArray.cpp ***/
  10501. /*** Start of inlined file: juce_StringPairArray.cpp ***/
  10502. BEGIN_JUCE_NAMESPACE
  10503. StringPairArray::StringPairArray (const bool ignoreCase_) throw()
  10504. : ignoreCase (ignoreCase_)
  10505. {
  10506. }
  10507. StringPairArray::StringPairArray (const StringPairArray& other) throw()
  10508. : keys (other.keys),
  10509. values (other.values),
  10510. ignoreCase (other.ignoreCase)
  10511. {
  10512. }
  10513. StringPairArray::~StringPairArray() throw()
  10514. {
  10515. }
  10516. StringPairArray& StringPairArray::operator= (const StringPairArray& other) throw()
  10517. {
  10518. keys = other.keys;
  10519. values = other.values;
  10520. return *this;
  10521. }
  10522. bool StringPairArray::operator== (const StringPairArray& other) const throw()
  10523. {
  10524. for (int i = keys.size(); --i >= 0;)
  10525. if (other [keys[i]] != values[i])
  10526. return false;
  10527. return true;
  10528. }
  10529. bool StringPairArray::operator!= (const StringPairArray& other) const throw()
  10530. {
  10531. return ! operator== (other);
  10532. }
  10533. const String& StringPairArray::operator[] (const String& key) const throw()
  10534. {
  10535. return values [keys.indexOf (key, ignoreCase)];
  10536. }
  10537. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  10538. {
  10539. const int i = keys.indexOf (key, ignoreCase);
  10540. if (i >= 0)
  10541. return values[i];
  10542. return defaultReturnValue;
  10543. }
  10544. void StringPairArray::set (const String& key,
  10545. const String& value) throw()
  10546. {
  10547. const int i = keys.indexOf (key, ignoreCase);
  10548. if (i >= 0)
  10549. {
  10550. values.set (i, value);
  10551. }
  10552. else
  10553. {
  10554. keys.add (key);
  10555. values.add (value);
  10556. }
  10557. }
  10558. void StringPairArray::addArray (const StringPairArray& other)
  10559. {
  10560. for (int i = 0; i < other.size(); ++i)
  10561. set (other.keys[i], other.values[i]);
  10562. }
  10563. void StringPairArray::clear() throw()
  10564. {
  10565. keys.clear();
  10566. values.clear();
  10567. }
  10568. void StringPairArray::remove (const String& key) throw()
  10569. {
  10570. remove (keys.indexOf (key, ignoreCase));
  10571. }
  10572. void StringPairArray::remove (const int index) throw()
  10573. {
  10574. keys.remove (index);
  10575. values.remove (index);
  10576. }
  10577. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase) throw()
  10578. {
  10579. ignoreCase = shouldIgnoreCase;
  10580. }
  10581. const String StringPairArray::getDescription() const
  10582. {
  10583. String s;
  10584. for (int i = 0; i < keys.size(); ++i)
  10585. {
  10586. s << keys[i] << T(" = ") << values[i];
  10587. if (i < keys.size())
  10588. s << T(", ");
  10589. }
  10590. return s;
  10591. }
  10592. void StringPairArray::minimiseStorageOverheads() throw()
  10593. {
  10594. keys.minimiseStorageOverheads();
  10595. values.minimiseStorageOverheads();
  10596. }
  10597. END_JUCE_NAMESPACE
  10598. /*** End of inlined file: juce_StringPairArray.cpp ***/
  10599. /*** Start of inlined file: juce_XmlDocument.cpp ***/
  10600. BEGIN_JUCE_NAMESPACE
  10601. XmlDocument::XmlDocument (const String& documentText) throw()
  10602. : originalText (documentText),
  10603. ignoreEmptyTextElements (true)
  10604. {
  10605. }
  10606. XmlDocument::XmlDocument (const File& file)
  10607. {
  10608. inputSource = new FileInputSource (file);
  10609. }
  10610. XmlDocument::~XmlDocument() throw()
  10611. {
  10612. }
  10613. void XmlDocument::setInputSource (InputSource* const newSource) throw()
  10614. {
  10615. inputSource = newSource;
  10616. }
  10617. void XmlDocument::setEmptyTextElementsIgnored (const bool shouldBeIgnored) throw()
  10618. {
  10619. ignoreEmptyTextElements = shouldBeIgnored;
  10620. }
  10621. bool XmlDocument::isXmlIdentifierCharSlow (const tchar c) throw()
  10622. {
  10623. return CharacterFunctions::isLetterOrDigit (c)
  10624. || c == T('_')
  10625. || c == T('-')
  10626. || c == T(':')
  10627. || c == T('.');
  10628. }
  10629. inline bool XmlDocument::isXmlIdentifierChar (const tchar c) const throw()
  10630. {
  10631. return (c > 0 && c <= 127) ? identifierLookupTable [(int) c]
  10632. : isXmlIdentifierCharSlow (c);
  10633. }
  10634. XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement)
  10635. {
  10636. String textToParse (originalText);
  10637. if (textToParse.isEmpty() && inputSource != 0)
  10638. {
  10639. ScopedPointer <InputStream> in (inputSource->createInputStream());
  10640. if (in != 0)
  10641. {
  10642. MemoryBlock data;
  10643. in->readIntoMemoryBlock (data, onlyReadOuterDocumentElement ? 8192 : -1);
  10644. if (data.getSize() >= 2
  10645. && ((data[0] == (char)-2 && data[1] == (char)-1)
  10646. || (data[0] == (char)-1 && data[1] == (char)-2)))
  10647. {
  10648. textToParse = String::createStringFromData ((const char*) data.getData(), (int) data.getSize());
  10649. }
  10650. else
  10651. {
  10652. textToParse = String::fromUTF8 ((const char*) data.getData(), (int) data.getSize());
  10653. }
  10654. if (! onlyReadOuterDocumentElement)
  10655. originalText = textToParse;
  10656. }
  10657. }
  10658. input = textToParse;
  10659. lastError = String::empty;
  10660. errorOccurred = false;
  10661. outOfData = false;
  10662. needToLoadDTD = true;
  10663. for (int i = 0; i < 128; ++i)
  10664. identifierLookupTable[i] = isXmlIdentifierCharSlow ((tchar) i);
  10665. if (textToParse.isEmpty())
  10666. {
  10667. lastError = "not enough input";
  10668. }
  10669. else
  10670. {
  10671. skipHeader();
  10672. if (input != 0)
  10673. {
  10674. ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
  10675. if (! errorOccurred)
  10676. return result.release();
  10677. }
  10678. else
  10679. {
  10680. lastError = "incorrect xml header";
  10681. }
  10682. }
  10683. return 0;
  10684. }
  10685. const String& XmlDocument::getLastParseError() const throw()
  10686. {
  10687. return lastError;
  10688. }
  10689. void XmlDocument::setLastError (const String& desc, const bool carryOn) throw()
  10690. {
  10691. lastError = desc;
  10692. errorOccurred = ! carryOn;
  10693. }
  10694. const String XmlDocument::getFileContents (const String& filename) const
  10695. {
  10696. if (inputSource != 0)
  10697. {
  10698. const ScopedPointer <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
  10699. if (in != 0)
  10700. return in->readEntireStreamAsString();
  10701. }
  10702. return String::empty;
  10703. }
  10704. tchar XmlDocument::readNextChar() throw()
  10705. {
  10706. if (*input != 0)
  10707. {
  10708. return *input++;
  10709. }
  10710. else
  10711. {
  10712. outOfData = true;
  10713. return 0;
  10714. }
  10715. }
  10716. int XmlDocument::findNextTokenLength() throw()
  10717. {
  10718. int len = 0;
  10719. tchar c = *input;
  10720. while (isXmlIdentifierChar (c))
  10721. c = input [++len];
  10722. return len;
  10723. }
  10724. void XmlDocument::skipHeader() throw()
  10725. {
  10726. const tchar* const found = CharacterFunctions::find (input, T("<?xml"));
  10727. if (found != 0)
  10728. {
  10729. input = found;
  10730. input = CharacterFunctions::find (input, T("?>"));
  10731. if (input == 0)
  10732. return;
  10733. input += 2;
  10734. }
  10735. skipNextWhiteSpace();
  10736. const tchar* docType = CharacterFunctions::find (input, T("<!DOCTYPE"));
  10737. if (docType == 0)
  10738. return;
  10739. input = docType + 9;
  10740. int n = 1;
  10741. while (n > 0)
  10742. {
  10743. const tchar c = readNextChar();
  10744. if (outOfData)
  10745. return;
  10746. if (c == T('<'))
  10747. ++n;
  10748. else if (c == T('>'))
  10749. --n;
  10750. }
  10751. docType += 9;
  10752. dtdText = String (docType, (int) (input - (docType + 1))).trim();
  10753. }
  10754. void XmlDocument::skipNextWhiteSpace() throw()
  10755. {
  10756. for (;;)
  10757. {
  10758. tchar c = *input;
  10759. while (CharacterFunctions::isWhitespace (c))
  10760. c = *++input;
  10761. if (c == 0)
  10762. {
  10763. outOfData = true;
  10764. break;
  10765. }
  10766. else if (c == T('<'))
  10767. {
  10768. if (input[1] == T('!')
  10769. && input[2] == T('-')
  10770. && input[3] == T('-'))
  10771. {
  10772. const tchar* const closeComment = CharacterFunctions::find (input, T("-->"));
  10773. if (closeComment == 0)
  10774. {
  10775. outOfData = true;
  10776. break;
  10777. }
  10778. input = closeComment + 3;
  10779. continue;
  10780. }
  10781. else if (input[1] == T('?'))
  10782. {
  10783. const tchar* const closeBracket = CharacterFunctions::find (input, T("?>"));
  10784. if (closeBracket == 0)
  10785. {
  10786. outOfData = true;
  10787. break;
  10788. }
  10789. input = closeBracket + 2;
  10790. continue;
  10791. }
  10792. }
  10793. break;
  10794. }
  10795. }
  10796. void XmlDocument::readQuotedString (String& result) throw()
  10797. {
  10798. const tchar quote = readNextChar();
  10799. while (! outOfData)
  10800. {
  10801. const tchar c = readNextChar();
  10802. if (c == quote)
  10803. break;
  10804. if (c == T('&'))
  10805. {
  10806. --input;
  10807. readEntity (result);
  10808. }
  10809. else
  10810. {
  10811. --input;
  10812. const tchar* const start = input;
  10813. for (;;)
  10814. {
  10815. const tchar character = *input;
  10816. if (character == quote)
  10817. {
  10818. result.append (start, (int) (input - start));
  10819. ++input;
  10820. return;
  10821. }
  10822. else if (character == T('&'))
  10823. {
  10824. result.append (start, (int) (input - start));
  10825. break;
  10826. }
  10827. else if (character == 0)
  10828. {
  10829. outOfData = true;
  10830. setLastError ("unmatched quotes", false);
  10831. break;
  10832. }
  10833. ++input;
  10834. }
  10835. }
  10836. }
  10837. }
  10838. XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) throw()
  10839. {
  10840. XmlElement* node = 0;
  10841. skipNextWhiteSpace();
  10842. if (outOfData)
  10843. return 0;
  10844. input = CharacterFunctions::find (input, T("<"));
  10845. if (input != 0)
  10846. {
  10847. ++input;
  10848. int tagLen = findNextTokenLength();
  10849. if (tagLen == 0)
  10850. {
  10851. // no tag name - but allow for a gap after the '<' before giving an error
  10852. skipNextWhiteSpace();
  10853. tagLen = findNextTokenLength();
  10854. if (tagLen == 0)
  10855. {
  10856. setLastError ("tag name missing", false);
  10857. return node;
  10858. }
  10859. }
  10860. node = new XmlElement (String (input, tagLen));
  10861. input += tagLen;
  10862. XmlElement::XmlAttributeNode* lastAttribute = 0;
  10863. // look for attributes
  10864. for (;;)
  10865. {
  10866. skipNextWhiteSpace();
  10867. const tchar c = *input;
  10868. // empty tag..
  10869. if (c == T('/') && input[1] == T('>'))
  10870. {
  10871. input += 2;
  10872. break;
  10873. }
  10874. // parse the guts of the element..
  10875. if (c == T('>'))
  10876. {
  10877. ++input;
  10878. skipNextWhiteSpace();
  10879. if (alsoParseSubElements)
  10880. readChildElements (node);
  10881. break;
  10882. }
  10883. // get an attribute..
  10884. if (isXmlIdentifierChar (c))
  10885. {
  10886. const int attNameLen = findNextTokenLength();
  10887. if (attNameLen > 0)
  10888. {
  10889. const tchar* attNameStart = input;
  10890. input += attNameLen;
  10891. skipNextWhiteSpace();
  10892. if (readNextChar() == T('='))
  10893. {
  10894. skipNextWhiteSpace();
  10895. const tchar nextChar = *input;
  10896. if (nextChar == T('"') || nextChar == T('\''))
  10897. {
  10898. XmlElement::XmlAttributeNode* const newAtt
  10899. = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen),
  10900. String::empty);
  10901. readQuotedString (newAtt->value);
  10902. if (lastAttribute == 0)
  10903. node->attributes = newAtt;
  10904. else
  10905. lastAttribute->next = newAtt;
  10906. lastAttribute = newAtt;
  10907. continue;
  10908. }
  10909. }
  10910. }
  10911. }
  10912. else
  10913. {
  10914. if (! outOfData)
  10915. setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
  10916. }
  10917. break;
  10918. }
  10919. }
  10920. return node;
  10921. }
  10922. void XmlDocument::readChildElements (XmlElement* parent) throw()
  10923. {
  10924. XmlElement* lastChildNode = 0;
  10925. for (;;)
  10926. {
  10927. skipNextWhiteSpace();
  10928. if (outOfData)
  10929. {
  10930. setLastError ("unmatched tags", false);
  10931. break;
  10932. }
  10933. if (*input == T('<'))
  10934. {
  10935. if (input[1] == T('/'))
  10936. {
  10937. // our close tag..
  10938. input = CharacterFunctions::find (input, T(">"));
  10939. ++input;
  10940. break;
  10941. }
  10942. else if (input[1] == T('!')
  10943. && input[2] == T('[')
  10944. && input[3] == T('C')
  10945. && input[4] == T('D')
  10946. && input[5] == T('A')
  10947. && input[6] == T('T')
  10948. && input[7] == T('A')
  10949. && input[8] == T('['))
  10950. {
  10951. input += 9;
  10952. const tchar* const inputStart = input;
  10953. int len = 0;
  10954. for (;;)
  10955. {
  10956. if (*input == 0)
  10957. {
  10958. setLastError ("unterminated CDATA section", false);
  10959. outOfData = true;
  10960. break;
  10961. }
  10962. else if (input[0] == T(']')
  10963. && input[1] == T(']')
  10964. && input[2] == T('>'))
  10965. {
  10966. input += 3;
  10967. break;
  10968. }
  10969. ++input;
  10970. ++len;
  10971. }
  10972. XmlElement* const e = new XmlElement ((int) 0);
  10973. e->setText (String (inputStart, len));
  10974. if (lastChildNode != 0)
  10975. lastChildNode->nextElement = e;
  10976. else
  10977. parent->addChildElement (e);
  10978. lastChildNode = e;
  10979. }
  10980. else
  10981. {
  10982. // this is some other element, so parse and add it..
  10983. XmlElement* const n = readNextElement (true);
  10984. if (n != 0)
  10985. {
  10986. if (lastChildNode == 0)
  10987. parent->addChildElement (n);
  10988. else
  10989. lastChildNode->nextElement = n;
  10990. lastChildNode = n;
  10991. }
  10992. else
  10993. {
  10994. return;
  10995. }
  10996. }
  10997. }
  10998. else
  10999. {
  11000. // read character block..
  11001. XmlElement* const e = new XmlElement ((int)0);
  11002. if (lastChildNode != 0)
  11003. lastChildNode->nextElement = e;
  11004. else
  11005. parent->addChildElement (e);
  11006. lastChildNode = e;
  11007. String textElementContent;
  11008. for (;;)
  11009. {
  11010. const tchar c = *input;
  11011. if (c == T('<'))
  11012. break;
  11013. if (c == 0)
  11014. {
  11015. setLastError ("unmatched tags", false);
  11016. outOfData = true;
  11017. return;
  11018. }
  11019. if (c == T('&'))
  11020. {
  11021. String entity;
  11022. readEntity (entity);
  11023. if (entity.startsWithChar (T('<')) && entity [1] != 0)
  11024. {
  11025. const tchar* const oldInput = input;
  11026. const bool oldOutOfData = outOfData;
  11027. input = (const tchar*) entity;
  11028. outOfData = false;
  11029. for (;;)
  11030. {
  11031. XmlElement* const n = readNextElement (true);
  11032. if (n == 0)
  11033. break;
  11034. if (lastChildNode == 0)
  11035. parent->addChildElement (n);
  11036. else
  11037. lastChildNode->nextElement = n;
  11038. lastChildNode = n;
  11039. }
  11040. input = oldInput;
  11041. outOfData = oldOutOfData;
  11042. }
  11043. else
  11044. {
  11045. textElementContent += entity;
  11046. }
  11047. }
  11048. else
  11049. {
  11050. const tchar* start = input;
  11051. int len = 0;
  11052. for (;;)
  11053. {
  11054. const tchar nextChar = *input;
  11055. if (nextChar == T('<') || nextChar == T('&'))
  11056. {
  11057. break;
  11058. }
  11059. else if (nextChar == 0)
  11060. {
  11061. setLastError ("unmatched tags", false);
  11062. outOfData = true;
  11063. return;
  11064. }
  11065. ++input;
  11066. ++len;
  11067. }
  11068. textElementContent.append (start, len);
  11069. }
  11070. }
  11071. if (ignoreEmptyTextElements ? textElementContent.containsNonWhitespaceChars()
  11072. : textElementContent.isNotEmpty())
  11073. e->setText (textElementContent);
  11074. }
  11075. }
  11076. }
  11077. void XmlDocument::readEntity (String& result) throw()
  11078. {
  11079. // skip over the ampersand
  11080. ++input;
  11081. if (CharacterFunctions::compareIgnoreCase (input, T("amp;"), 4) == 0)
  11082. {
  11083. input += 4;
  11084. result += T("&");
  11085. }
  11086. else if (CharacterFunctions::compareIgnoreCase (input, T("quot;"), 5) == 0)
  11087. {
  11088. input += 5;
  11089. result += T("\"");
  11090. }
  11091. else if (CharacterFunctions::compareIgnoreCase (input, T("apos;"), 5) == 0)
  11092. {
  11093. input += 5;
  11094. result += T("\'");
  11095. }
  11096. else if (CharacterFunctions::compareIgnoreCase (input, T("lt;"), 3) == 0)
  11097. {
  11098. input += 3;
  11099. result += T("<");
  11100. }
  11101. else if (CharacterFunctions::compareIgnoreCase (input, T("gt;"), 3) == 0)
  11102. {
  11103. input += 3;
  11104. result += T(">");
  11105. }
  11106. else if (*input == T('#'))
  11107. {
  11108. int charCode = 0;
  11109. ++input;
  11110. if (*input == T('x') || *input == T('X'))
  11111. {
  11112. ++input;
  11113. int numChars = 0;
  11114. while (input[0] != T(';'))
  11115. {
  11116. const int hexValue = CharacterFunctions::getHexDigitValue (input[0]);
  11117. if (hexValue < 0 || ++numChars > 8)
  11118. {
  11119. setLastError ("illegal escape sequence", true);
  11120. break;
  11121. }
  11122. charCode = (charCode << 4) | hexValue;
  11123. ++input;
  11124. }
  11125. ++input;
  11126. }
  11127. else if (input[0] >= T('0') && input[0] <= T('9'))
  11128. {
  11129. int numChars = 0;
  11130. while (input[0] != T(';'))
  11131. {
  11132. if (++numChars > 12)
  11133. {
  11134. setLastError ("illegal escape sequence", true);
  11135. break;
  11136. }
  11137. charCode = charCode * 10 + (input[0] - T('0'));
  11138. ++input;
  11139. }
  11140. ++input;
  11141. }
  11142. else
  11143. {
  11144. setLastError ("illegal escape sequence", true);
  11145. result += T("&");
  11146. return;
  11147. }
  11148. result << (tchar) charCode;
  11149. }
  11150. else
  11151. {
  11152. const tchar* const entityNameStart = input;
  11153. const tchar* const closingSemiColon = CharacterFunctions::find (input, T(";"));
  11154. if (closingSemiColon == 0)
  11155. {
  11156. outOfData = true;
  11157. result += T("&");
  11158. }
  11159. else
  11160. {
  11161. input = closingSemiColon + 1;
  11162. result += expandExternalEntity (String (entityNameStart,
  11163. (int) (closingSemiColon - entityNameStart)));
  11164. }
  11165. }
  11166. }
  11167. const String XmlDocument::expandEntity (const String& ent)
  11168. {
  11169. if (ent.equalsIgnoreCase (T("amp")))
  11170. {
  11171. return T("&");
  11172. }
  11173. else if (ent.equalsIgnoreCase (T("quot")))
  11174. {
  11175. return T("\"");
  11176. }
  11177. else if (ent.equalsIgnoreCase (T("apos")))
  11178. {
  11179. return T("\'");
  11180. }
  11181. else if (ent.equalsIgnoreCase (T("lt")))
  11182. {
  11183. return T("<");
  11184. }
  11185. else if (ent.equalsIgnoreCase (T("gt")))
  11186. {
  11187. return T(">");
  11188. }
  11189. else if (ent[0] == T('#'))
  11190. {
  11191. if (ent[1] == T('x') || ent[1] == T('X'))
  11192. {
  11193. return String::charToString ((tchar) ent.substring (2).getHexValue32());
  11194. }
  11195. else if (ent[1] >= T('0') && ent[1] <= T('9'))
  11196. {
  11197. return String::charToString ((tchar) ent.substring (1).getIntValue());
  11198. }
  11199. setLastError ("illegal escape sequence", false);
  11200. return T("&");
  11201. }
  11202. else
  11203. {
  11204. return expandExternalEntity (ent);
  11205. }
  11206. }
  11207. const String XmlDocument::expandExternalEntity (const String& entity)
  11208. {
  11209. if (needToLoadDTD)
  11210. {
  11211. if (dtdText.isNotEmpty())
  11212. {
  11213. while (dtdText.endsWithChar (T('>')))
  11214. dtdText = dtdText.dropLastCharacters (1);
  11215. tokenisedDTD.addTokens (dtdText, true);
  11216. if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase (T("system"))
  11217. && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString())
  11218. {
  11219. const String fn (tokenisedDTD [tokenisedDTD.size() - 1]);
  11220. tokenisedDTD.clear();
  11221. tokenisedDTD.addTokens (getFileContents (fn), true);
  11222. }
  11223. else
  11224. {
  11225. tokenisedDTD.clear();
  11226. const int openBracket = dtdText.indexOfChar (T('['));
  11227. if (openBracket > 0)
  11228. {
  11229. const int closeBracket = dtdText.lastIndexOfChar (T(']'));
  11230. if (closeBracket > openBracket)
  11231. tokenisedDTD.addTokens (dtdText.substring (openBracket + 1,
  11232. closeBracket), true);
  11233. }
  11234. }
  11235. for (int i = tokenisedDTD.size(); --i >= 0;)
  11236. {
  11237. if (tokenisedDTD[i].startsWithChar (T('%'))
  11238. && tokenisedDTD[i].endsWithChar (T(';')))
  11239. {
  11240. const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1)));
  11241. StringArray newToks;
  11242. newToks.addTokens (parsed, true);
  11243. tokenisedDTD.remove (i);
  11244. for (int j = newToks.size(); --j >= 0;)
  11245. tokenisedDTD.insert (i, newToks[j]);
  11246. }
  11247. }
  11248. }
  11249. needToLoadDTD = false;
  11250. }
  11251. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11252. {
  11253. if (tokenisedDTD[i] == entity)
  11254. {
  11255. if (tokenisedDTD[i - 1].equalsIgnoreCase (T("<!entity")))
  11256. {
  11257. String ent (tokenisedDTD [i + 1]);
  11258. while (ent.endsWithChar (T('>')))
  11259. ent = ent.dropLastCharacters (1);
  11260. ent = ent.trim().unquoted();
  11261. // check for sub-entities..
  11262. int ampersand = ent.indexOfChar (T('&'));
  11263. while (ampersand >= 0)
  11264. {
  11265. const int semiColon = ent.indexOf (i + 1, T(";"));
  11266. if (semiColon < 0)
  11267. {
  11268. setLastError ("entity without terminating semi-colon", false);
  11269. break;
  11270. }
  11271. const String resolved (expandEntity (ent.substring (i + 1, semiColon)));
  11272. ent = ent.substring (0, ampersand)
  11273. + resolved
  11274. + ent.substring (semiColon + 1);
  11275. ampersand = ent.indexOfChar (semiColon + 1, T('&'));
  11276. }
  11277. return ent;
  11278. }
  11279. }
  11280. }
  11281. setLastError ("unknown entity", true);
  11282. return entity;
  11283. }
  11284. const String XmlDocument::getParameterEntity (const String& entity)
  11285. {
  11286. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11287. {
  11288. if (tokenisedDTD[i] == entity)
  11289. {
  11290. if (tokenisedDTD [i - 1] == T("%")
  11291. && tokenisedDTD [i - 2].equalsIgnoreCase (T("<!entity")))
  11292. {
  11293. String ent (tokenisedDTD [i + 1]);
  11294. while (ent.endsWithChar (T('>')))
  11295. ent = ent.dropLastCharacters (1);
  11296. if (ent.equalsIgnoreCase (T("system")))
  11297. {
  11298. String filename (tokenisedDTD [i + 2]);
  11299. while (filename.endsWithChar (T('>')))
  11300. filename = filename.dropLastCharacters (1);
  11301. return getFileContents (filename);
  11302. }
  11303. else
  11304. {
  11305. return ent.trim().unquoted();
  11306. }
  11307. }
  11308. }
  11309. }
  11310. return entity;
  11311. }
  11312. END_JUCE_NAMESPACE
  11313. /*** End of inlined file: juce_XmlDocument.cpp ***/
  11314. /*** Start of inlined file: juce_XmlElement.cpp ***/
  11315. BEGIN_JUCE_NAMESPACE
  11316. XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
  11317. : name (other.name),
  11318. value (other.value),
  11319. next (0)
  11320. {
  11321. }
  11322. XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_,
  11323. const String& value_) throw()
  11324. : name (name_),
  11325. value (value_),
  11326. next (0)
  11327. {
  11328. }
  11329. XmlElement::XmlElement (const String& tagName_) throw()
  11330. : tagName (tagName_),
  11331. firstChildElement (0),
  11332. nextElement (0),
  11333. attributes (0)
  11334. {
  11335. // the tag name mustn't be empty, or it'll look like a text element!
  11336. jassert (tagName_.containsNonWhitespaceChars())
  11337. // The tag can't contain spaces or other characters that would create invalid XML!
  11338. jassert (! tagName_.containsAnyOf (T(" <>/&")));
  11339. }
  11340. XmlElement::XmlElement (int /*dummy*/) throw()
  11341. : firstChildElement (0),
  11342. nextElement (0),
  11343. attributes (0)
  11344. {
  11345. }
  11346. XmlElement::XmlElement (const XmlElement& other) throw()
  11347. : tagName (other.tagName),
  11348. firstChildElement (0),
  11349. nextElement (0),
  11350. attributes (0)
  11351. {
  11352. copyChildrenAndAttributesFrom (other);
  11353. }
  11354. XmlElement& XmlElement::operator= (const XmlElement& other) throw()
  11355. {
  11356. if (this != &other)
  11357. {
  11358. removeAllAttributes();
  11359. deleteAllChildElements();
  11360. tagName = other.tagName;
  11361. copyChildrenAndAttributesFrom (other);
  11362. }
  11363. return *this;
  11364. }
  11365. void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other) throw()
  11366. {
  11367. XmlElement* child = other.firstChildElement;
  11368. XmlElement* lastChild = 0;
  11369. while (child != 0)
  11370. {
  11371. XmlElement* const copiedChild = new XmlElement (*child);
  11372. if (lastChild != 0)
  11373. lastChild->nextElement = copiedChild;
  11374. else
  11375. firstChildElement = copiedChild;
  11376. lastChild = copiedChild;
  11377. child = child->nextElement;
  11378. }
  11379. const XmlAttributeNode* att = other.attributes;
  11380. XmlAttributeNode* lastAtt = 0;
  11381. while (att != 0)
  11382. {
  11383. XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
  11384. if (lastAtt != 0)
  11385. lastAtt->next = newAtt;
  11386. else
  11387. attributes = newAtt;
  11388. lastAtt = newAtt;
  11389. att = att->next;
  11390. }
  11391. }
  11392. XmlElement::~XmlElement() throw()
  11393. {
  11394. XmlElement* child = firstChildElement;
  11395. while (child != 0)
  11396. {
  11397. XmlElement* const nextChild = child->nextElement;
  11398. delete child;
  11399. child = nextChild;
  11400. }
  11401. XmlAttributeNode* att = attributes;
  11402. while (att != 0)
  11403. {
  11404. XmlAttributeNode* const nextAtt = att->next;
  11405. delete att;
  11406. att = nextAtt;
  11407. }
  11408. }
  11409. namespace XmlOutputFunctions
  11410. {
  11411. static bool isLegalXmlChar (const uint32 c) throw()
  11412. {
  11413. static const unsigned char legalChars[] = { 0, 0, 0, 0, 171, 255, 255, 175, 255, 255, 255, 191, 254, 255, 255, 111 };
  11414. return c < sizeof (legalChars) * 8
  11415. && (legalChars [c >> 3] & (1 << (c & 7))) != 0;
  11416. }
  11417. static void escapeIllegalXmlChars (OutputStream& outputStream, const String& text, const bool changeNewLines)
  11418. {
  11419. const juce_wchar* t = (const juce_wchar*) text;
  11420. for (;;)
  11421. {
  11422. const juce_wchar character = *t++;
  11423. if (character == 0)
  11424. {
  11425. break;
  11426. }
  11427. else if (isLegalXmlChar ((uint32) character))
  11428. {
  11429. outputStream << (char) character;
  11430. }
  11431. else
  11432. {
  11433. switch (character)
  11434. {
  11435. case '&': outputStream << "&amp;"; break;
  11436. case '"': outputStream << "&quot;"; break;
  11437. case '>': outputStream << "&gt;"; break;
  11438. case '<': outputStream << "&lt;"; break;
  11439. case '\n':
  11440. if (changeNewLines)
  11441. outputStream << "&#10;";
  11442. else
  11443. outputStream << (char) character;
  11444. break;
  11445. case '\r':
  11446. if (changeNewLines)
  11447. outputStream << "&#13;";
  11448. else
  11449. outputStream << (char) character;
  11450. break;
  11451. default:
  11452. outputStream << "&#" << ((int) (unsigned int) character) << ';';
  11453. break;
  11454. }
  11455. }
  11456. }
  11457. }
  11458. static void writeSpaces (OutputStream& out, int numSpaces) throw()
  11459. {
  11460. if (numSpaces > 0)
  11461. {
  11462. const char* const blanks = " ";
  11463. const int blankSize = (int) sizeof (blanks) - 1;
  11464. while (numSpaces > blankSize)
  11465. {
  11466. out.write (blanks, blankSize);
  11467. numSpaces -= blankSize;
  11468. }
  11469. out.write (blanks, numSpaces);
  11470. }
  11471. }
  11472. }
  11473. void XmlElement::writeElementAsText (OutputStream& outputStream,
  11474. const int indentationLevel,
  11475. const int lineWrapLength) const throw()
  11476. {
  11477. using namespace XmlOutputFunctions;
  11478. writeSpaces (outputStream, indentationLevel);
  11479. if (! isTextElement())
  11480. {
  11481. outputStream.writeByte ('<');
  11482. outputStream << tagName;
  11483. const int attIndent = indentationLevel + tagName.length() + 1;
  11484. int lineLen = 0;
  11485. const XmlAttributeNode* att = attributes;
  11486. while (att != 0)
  11487. {
  11488. if (lineLen > lineWrapLength && indentationLevel >= 0)
  11489. {
  11490. outputStream.write ("\r\n", 2);
  11491. writeSpaces (outputStream, attIndent);
  11492. lineLen = 0;
  11493. }
  11494. const int64 startPos = outputStream.getPosition();
  11495. outputStream.writeByte (' ');
  11496. outputStream << att->name;
  11497. outputStream.write ("=\"", 2);
  11498. escapeIllegalXmlChars (outputStream, att->value, true);
  11499. outputStream.writeByte ('"');
  11500. lineLen += (int) (outputStream.getPosition() - startPos);
  11501. att = att->next;
  11502. }
  11503. if (firstChildElement != 0)
  11504. {
  11505. XmlElement* child = firstChildElement;
  11506. if (child->nextElement == 0 && child->isTextElement())
  11507. {
  11508. outputStream.writeByte ('>');
  11509. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11510. }
  11511. else
  11512. {
  11513. if (indentationLevel >= 0)
  11514. outputStream.write (">\r\n", 3);
  11515. else
  11516. outputStream.writeByte ('>');
  11517. bool lastWasTextNode = false;
  11518. while (child != 0)
  11519. {
  11520. if (child->isTextElement())
  11521. {
  11522. if ((! lastWasTextNode) && (indentationLevel >= 0))
  11523. writeSpaces (outputStream, indentationLevel + 2);
  11524. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11525. lastWasTextNode = true;
  11526. }
  11527. else
  11528. {
  11529. if (indentationLevel >= 0)
  11530. {
  11531. if (lastWasTextNode)
  11532. outputStream.write ("\r\n", 2);
  11533. child->writeElementAsText (outputStream, indentationLevel + 2, lineWrapLength);
  11534. }
  11535. else
  11536. {
  11537. child->writeElementAsText (outputStream, indentationLevel, lineWrapLength);
  11538. }
  11539. lastWasTextNode = false;
  11540. }
  11541. child = child->nextElement;
  11542. }
  11543. if (indentationLevel >= 0)
  11544. {
  11545. if (lastWasTextNode)
  11546. outputStream.write ("\r\n", 2);
  11547. writeSpaces (outputStream, indentationLevel);
  11548. }
  11549. }
  11550. outputStream.write ("</", 2);
  11551. outputStream << tagName;
  11552. if (indentationLevel >= 0)
  11553. outputStream.write (">\r\n", 3);
  11554. else
  11555. outputStream.writeByte ('>');
  11556. }
  11557. else
  11558. {
  11559. if (indentationLevel >= 0)
  11560. outputStream.write ("/>\r\n", 4);
  11561. else
  11562. outputStream.write ("/>", 2);
  11563. }
  11564. }
  11565. else
  11566. {
  11567. if (indentationLevel >= 0)
  11568. writeSpaces (outputStream, indentationLevel + 2);
  11569. escapeIllegalXmlChars (outputStream, getText(), false);
  11570. }
  11571. }
  11572. const String XmlElement::createDocument (const String& dtdToUse,
  11573. const bool allOnOneLine,
  11574. const bool includeXmlHeader,
  11575. const String& encodingType,
  11576. const int lineWrapLength) const throw()
  11577. {
  11578. MemoryOutputStream mem (2048, 4096);
  11579. writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
  11580. return String (mem.getData(), mem.getDataSize());
  11581. }
  11582. void XmlElement::writeToStream (OutputStream& output,
  11583. const String& dtdToUse,
  11584. const bool allOnOneLine,
  11585. const bool includeXmlHeader,
  11586. const String& encodingType,
  11587. const int lineWrapLength) const throw()
  11588. {
  11589. if (includeXmlHeader)
  11590. {
  11591. output << "<?xml version=\"1.0\" encoding=\"" << encodingType;
  11592. if (allOnOneLine)
  11593. output << "\"?> ";
  11594. else
  11595. output << "\"?>\r\n\r\n";
  11596. }
  11597. if (dtdToUse.isNotEmpty())
  11598. {
  11599. output << dtdToUse;
  11600. if (allOnOneLine)
  11601. output << " ";
  11602. else
  11603. output << "\r\n";
  11604. }
  11605. writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength);
  11606. }
  11607. bool XmlElement::writeToFile (const File& file,
  11608. const String& dtdToUse,
  11609. const String& encodingType,
  11610. const int lineWrapLength) const throw()
  11611. {
  11612. if (file.hasWriteAccess())
  11613. {
  11614. TemporaryFile tempFile (file);
  11615. ScopedPointer <FileOutputStream> out (tempFile.getFile().createOutputStream());
  11616. if (out != 0)
  11617. {
  11618. writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength);
  11619. out = 0;
  11620. return tempFile.overwriteTargetFileWithTemporary();
  11621. }
  11622. }
  11623. return false;
  11624. }
  11625. bool XmlElement::hasTagName (const String& tagNameWanted) const throw()
  11626. {
  11627. #ifdef JUCE_DEBUG
  11628. // if debugging, check that the case is actually the same, because
  11629. // valid xml is case-sensitive, and although this lets it pass, it's
  11630. // better not to..
  11631. if (tagName.equalsIgnoreCase (tagNameWanted))
  11632. {
  11633. jassert (tagName == tagNameWanted);
  11634. return true;
  11635. }
  11636. else
  11637. {
  11638. return false;
  11639. }
  11640. #else
  11641. return tagName.equalsIgnoreCase (tagNameWanted);
  11642. #endif
  11643. }
  11644. XmlElement* XmlElement::getNextElementWithTagName (const String& requiredTagName) const
  11645. {
  11646. XmlElement* e = nextElement;
  11647. while (e != 0 && ! e->hasTagName (requiredTagName))
  11648. e = e->nextElement;
  11649. return e;
  11650. }
  11651. int XmlElement::getNumAttributes() const throw()
  11652. {
  11653. const XmlAttributeNode* att = attributes;
  11654. int count = 0;
  11655. while (att != 0)
  11656. {
  11657. att = att->next;
  11658. ++count;
  11659. }
  11660. return count;
  11661. }
  11662. const String& XmlElement::getAttributeName (const int index) const throw()
  11663. {
  11664. const XmlAttributeNode* att = attributes;
  11665. int count = 0;
  11666. while (att != 0)
  11667. {
  11668. if (count == index)
  11669. return att->name;
  11670. att = att->next;
  11671. ++count;
  11672. }
  11673. return String::empty;
  11674. }
  11675. const String& XmlElement::getAttributeValue (const int index) const throw()
  11676. {
  11677. const XmlAttributeNode* att = attributes;
  11678. int count = 0;
  11679. while (att != 0)
  11680. {
  11681. if (count == index)
  11682. return att->value;
  11683. att = att->next;
  11684. ++count;
  11685. }
  11686. return String::empty;
  11687. }
  11688. bool XmlElement::hasAttribute (const String& attributeName) const throw()
  11689. {
  11690. const XmlAttributeNode* att = attributes;
  11691. while (att != 0)
  11692. {
  11693. if (att->name.equalsIgnoreCase (attributeName))
  11694. return true;
  11695. att = att->next;
  11696. }
  11697. return false;
  11698. }
  11699. const String XmlElement::getStringAttribute (const String& attributeName,
  11700. const String& defaultReturnValue) const throw()
  11701. {
  11702. const XmlAttributeNode* att = attributes;
  11703. while (att != 0)
  11704. {
  11705. if (att->name.equalsIgnoreCase (attributeName))
  11706. return att->value;
  11707. att = att->next;
  11708. }
  11709. return defaultReturnValue;
  11710. }
  11711. int XmlElement::getIntAttribute (const String& attributeName,
  11712. const int defaultReturnValue) const throw()
  11713. {
  11714. const XmlAttributeNode* att = attributes;
  11715. while (att != 0)
  11716. {
  11717. if (att->name.equalsIgnoreCase (attributeName))
  11718. return att->value.getIntValue();
  11719. att = att->next;
  11720. }
  11721. return defaultReturnValue;
  11722. }
  11723. double XmlElement::getDoubleAttribute (const String& attributeName,
  11724. const double defaultReturnValue) const throw()
  11725. {
  11726. const XmlAttributeNode* att = attributes;
  11727. while (att != 0)
  11728. {
  11729. if (att->name.equalsIgnoreCase (attributeName))
  11730. return att->value.getDoubleValue();
  11731. att = att->next;
  11732. }
  11733. return defaultReturnValue;
  11734. }
  11735. bool XmlElement::getBoolAttribute (const String& attributeName,
  11736. const bool defaultReturnValue) const throw()
  11737. {
  11738. const XmlAttributeNode* att = attributes;
  11739. while (att != 0)
  11740. {
  11741. if (att->name.equalsIgnoreCase (attributeName))
  11742. {
  11743. tchar firstChar = att->value[0];
  11744. if (CharacterFunctions::isWhitespace (firstChar))
  11745. firstChar = att->value.trimStart() [0];
  11746. return firstChar == T('1')
  11747. || firstChar == T('t')
  11748. || firstChar == T('y')
  11749. || firstChar == T('T')
  11750. || firstChar == T('Y');
  11751. }
  11752. att = att->next;
  11753. }
  11754. return defaultReturnValue;
  11755. }
  11756. bool XmlElement::compareAttribute (const String& attributeName,
  11757. const String& stringToCompareAgainst,
  11758. const bool ignoreCase) const throw()
  11759. {
  11760. const XmlAttributeNode* att = attributes;
  11761. while (att != 0)
  11762. {
  11763. if (att->name.equalsIgnoreCase (attributeName))
  11764. {
  11765. if (ignoreCase)
  11766. return att->value.equalsIgnoreCase (stringToCompareAgainst);
  11767. else
  11768. return att->value == stringToCompareAgainst;
  11769. }
  11770. att = att->next;
  11771. }
  11772. return false;
  11773. }
  11774. void XmlElement::setAttribute (const String& attributeName,
  11775. const String& value) throw()
  11776. {
  11777. #ifdef JUCE_DEBUG
  11778. // check the identifier being passed in is legal..
  11779. const tchar* t = attributeName;
  11780. while (*t != 0)
  11781. {
  11782. jassert (CharacterFunctions::isLetterOrDigit (*t)
  11783. || *t == T('_')
  11784. || *t == T('-')
  11785. || *t == T(':'));
  11786. ++t;
  11787. }
  11788. #endif
  11789. if (attributes == 0)
  11790. {
  11791. attributes = new XmlAttributeNode (attributeName, value);
  11792. }
  11793. else
  11794. {
  11795. XmlAttributeNode* att = attributes;
  11796. for (;;)
  11797. {
  11798. if (att->name.equalsIgnoreCase (attributeName))
  11799. {
  11800. att->value = value;
  11801. break;
  11802. }
  11803. else if (att->next == 0)
  11804. {
  11805. att->next = new XmlAttributeNode (attributeName, value);
  11806. break;
  11807. }
  11808. att = att->next;
  11809. }
  11810. }
  11811. }
  11812. void XmlElement::setAttribute (const String& attributeName,
  11813. const int number) throw()
  11814. {
  11815. setAttribute (attributeName, String (number));
  11816. }
  11817. void XmlElement::setAttribute (const String& attributeName,
  11818. const double number) throw()
  11819. {
  11820. setAttribute (attributeName, String (number));
  11821. }
  11822. void XmlElement::removeAttribute (const String& attributeName) throw()
  11823. {
  11824. XmlAttributeNode* att = attributes;
  11825. XmlAttributeNode* lastAtt = 0;
  11826. while (att != 0)
  11827. {
  11828. if (att->name.equalsIgnoreCase (attributeName))
  11829. {
  11830. if (lastAtt == 0)
  11831. attributes = att->next;
  11832. else
  11833. lastAtt->next = att->next;
  11834. delete att;
  11835. break;
  11836. }
  11837. lastAtt = att;
  11838. att = att->next;
  11839. }
  11840. }
  11841. void XmlElement::removeAllAttributes() throw()
  11842. {
  11843. while (attributes != 0)
  11844. {
  11845. XmlAttributeNode* const nextAtt = attributes->next;
  11846. delete attributes;
  11847. attributes = nextAtt;
  11848. }
  11849. }
  11850. int XmlElement::getNumChildElements() const throw()
  11851. {
  11852. int count = 0;
  11853. const XmlElement* child = firstChildElement;
  11854. while (child != 0)
  11855. {
  11856. ++count;
  11857. child = child->nextElement;
  11858. }
  11859. return count;
  11860. }
  11861. XmlElement* XmlElement::getChildElement (const int index) const throw()
  11862. {
  11863. int count = 0;
  11864. XmlElement* child = firstChildElement;
  11865. while (child != 0 && count < index)
  11866. {
  11867. child = child->nextElement;
  11868. ++count;
  11869. }
  11870. return child;
  11871. }
  11872. XmlElement* XmlElement::getChildByName (const String& childName) const throw()
  11873. {
  11874. XmlElement* child = firstChildElement;
  11875. while (child != 0)
  11876. {
  11877. if (child->hasTagName (childName))
  11878. break;
  11879. child = child->nextElement;
  11880. }
  11881. return child;
  11882. }
  11883. void XmlElement::addChildElement (XmlElement* const newNode) throw()
  11884. {
  11885. if (newNode != 0)
  11886. {
  11887. if (firstChildElement == 0)
  11888. {
  11889. firstChildElement = newNode;
  11890. }
  11891. else
  11892. {
  11893. XmlElement* child = firstChildElement;
  11894. while (child->nextElement != 0)
  11895. child = child->nextElement;
  11896. child->nextElement = newNode;
  11897. // if this is non-zero, then something's probably
  11898. // gone wrong..
  11899. jassert (newNode->nextElement == 0);
  11900. }
  11901. }
  11902. }
  11903. void XmlElement::insertChildElement (XmlElement* const newNode,
  11904. int indexToInsertAt) throw()
  11905. {
  11906. if (newNode != 0)
  11907. {
  11908. removeChildElement (newNode, false);
  11909. if (indexToInsertAt == 0)
  11910. {
  11911. newNode->nextElement = firstChildElement;
  11912. firstChildElement = newNode;
  11913. }
  11914. else
  11915. {
  11916. if (firstChildElement == 0)
  11917. {
  11918. firstChildElement = newNode;
  11919. }
  11920. else
  11921. {
  11922. if (indexToInsertAt < 0)
  11923. indexToInsertAt = std::numeric_limits<int>::max();
  11924. XmlElement* child = firstChildElement;
  11925. while (child->nextElement != 0 && --indexToInsertAt > 0)
  11926. child = child->nextElement;
  11927. newNode->nextElement = child->nextElement;
  11928. child->nextElement = newNode;
  11929. }
  11930. }
  11931. }
  11932. }
  11933. XmlElement* XmlElement::createNewChildElement (const String& tagName)
  11934. {
  11935. XmlElement* const newElement = new XmlElement (tagName);
  11936. addChildElement (newElement);
  11937. return newElement;
  11938. }
  11939. bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
  11940. XmlElement* const newNode) throw()
  11941. {
  11942. if (newNode != 0)
  11943. {
  11944. XmlElement* child = firstChildElement;
  11945. XmlElement* previousNode = 0;
  11946. while (child != 0)
  11947. {
  11948. if (child == currentChildElement)
  11949. {
  11950. if (child != newNode)
  11951. {
  11952. if (previousNode == 0)
  11953. firstChildElement = newNode;
  11954. else
  11955. previousNode->nextElement = newNode;
  11956. newNode->nextElement = child->nextElement;
  11957. delete child;
  11958. }
  11959. return true;
  11960. }
  11961. previousNode = child;
  11962. child = child->nextElement;
  11963. }
  11964. }
  11965. return false;
  11966. }
  11967. void XmlElement::removeChildElement (XmlElement* const childToRemove,
  11968. const bool shouldDeleteTheChild) throw()
  11969. {
  11970. if (childToRemove != 0)
  11971. {
  11972. if (firstChildElement == childToRemove)
  11973. {
  11974. firstChildElement = childToRemove->nextElement;
  11975. childToRemove->nextElement = 0;
  11976. }
  11977. else
  11978. {
  11979. XmlElement* child = firstChildElement;
  11980. XmlElement* last = 0;
  11981. while (child != 0)
  11982. {
  11983. if (child == childToRemove)
  11984. {
  11985. if (last == 0)
  11986. firstChildElement = child->nextElement;
  11987. else
  11988. last->nextElement = child->nextElement;
  11989. childToRemove->nextElement = 0;
  11990. break;
  11991. }
  11992. last = child;
  11993. child = child->nextElement;
  11994. }
  11995. }
  11996. if (shouldDeleteTheChild)
  11997. delete childToRemove;
  11998. }
  11999. }
  12000. bool XmlElement::isEquivalentTo (const XmlElement* const other,
  12001. const bool ignoreOrderOfAttributes) const throw()
  12002. {
  12003. if (this != other)
  12004. {
  12005. if (other == 0 || tagName != other->tagName)
  12006. {
  12007. return false;
  12008. }
  12009. if (ignoreOrderOfAttributes)
  12010. {
  12011. int totalAtts = 0;
  12012. const XmlAttributeNode* att = attributes;
  12013. while (att != 0)
  12014. {
  12015. if (! other->compareAttribute (att->name, att->value))
  12016. return false;
  12017. att = att->next;
  12018. ++totalAtts;
  12019. }
  12020. if (totalAtts != other->getNumAttributes())
  12021. return false;
  12022. }
  12023. else
  12024. {
  12025. const XmlAttributeNode* thisAtt = attributes;
  12026. const XmlAttributeNode* otherAtt = other->attributes;
  12027. for (;;)
  12028. {
  12029. if (thisAtt == 0 || otherAtt == 0)
  12030. {
  12031. if (thisAtt == otherAtt) // both 0, so it's a match
  12032. break;
  12033. return false;
  12034. }
  12035. if (thisAtt->name != otherAtt->name
  12036. || thisAtt->value != otherAtt->value)
  12037. {
  12038. return false;
  12039. }
  12040. thisAtt = thisAtt->next;
  12041. otherAtt = otherAtt->next;
  12042. }
  12043. }
  12044. const XmlElement* thisChild = firstChildElement;
  12045. const XmlElement* otherChild = other->firstChildElement;
  12046. for (;;)
  12047. {
  12048. if (thisChild == 0 || otherChild == 0)
  12049. {
  12050. if (thisChild == otherChild) // both 0, so it's a match
  12051. break;
  12052. return false;
  12053. }
  12054. if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
  12055. return false;
  12056. thisChild = thisChild->nextElement;
  12057. otherChild = otherChild->nextElement;
  12058. }
  12059. }
  12060. return true;
  12061. }
  12062. void XmlElement::deleteAllChildElements() throw()
  12063. {
  12064. while (firstChildElement != 0)
  12065. {
  12066. XmlElement* const nextChild = firstChildElement->nextElement;
  12067. delete firstChildElement;
  12068. firstChildElement = nextChild;
  12069. }
  12070. }
  12071. void XmlElement::deleteAllChildElementsWithTagName (const String& name) throw()
  12072. {
  12073. XmlElement* child = firstChildElement;
  12074. while (child != 0)
  12075. {
  12076. if (child->hasTagName (name))
  12077. {
  12078. XmlElement* const nextChild = child->nextElement;
  12079. removeChildElement (child, true);
  12080. child = nextChild;
  12081. }
  12082. else
  12083. {
  12084. child = child->nextElement;
  12085. }
  12086. }
  12087. }
  12088. bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
  12089. {
  12090. const XmlElement* child = firstChildElement;
  12091. while (child != 0)
  12092. {
  12093. if (child == possibleChild)
  12094. return true;
  12095. child = child->nextElement;
  12096. }
  12097. return false;
  12098. }
  12099. XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
  12100. {
  12101. if (this == elementToLookFor || elementToLookFor == 0)
  12102. return 0;
  12103. XmlElement* child = firstChildElement;
  12104. while (child != 0)
  12105. {
  12106. if (elementToLookFor == child)
  12107. return this;
  12108. XmlElement* const found = child->findParentElementOf (elementToLookFor);
  12109. if (found != 0)
  12110. return found;
  12111. child = child->nextElement;
  12112. }
  12113. return 0;
  12114. }
  12115. void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
  12116. {
  12117. XmlElement* e = firstChildElement;
  12118. while (e != 0)
  12119. {
  12120. *elems++ = e;
  12121. e = e->nextElement;
  12122. }
  12123. }
  12124. void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
  12125. {
  12126. XmlElement* e = firstChildElement = elems[0];
  12127. for (int i = 1; i < num; ++i)
  12128. {
  12129. e->nextElement = elems[i];
  12130. e = e->nextElement;
  12131. }
  12132. e->nextElement = 0;
  12133. }
  12134. bool XmlElement::isTextElement() const throw()
  12135. {
  12136. return tagName.isEmpty();
  12137. }
  12138. static const tchar* const juce_xmltextContentAttributeName = T("text");
  12139. const String XmlElement::getText() const throw()
  12140. {
  12141. jassert (isTextElement()); // you're trying to get the text from an element that
  12142. // isn't actually a text element.. If this contains text sub-nodes, you
  12143. // probably want to use getAllSubText instead.
  12144. return getStringAttribute (juce_xmltextContentAttributeName);
  12145. }
  12146. void XmlElement::setText (const String& newText) throw()
  12147. {
  12148. if (isTextElement())
  12149. {
  12150. setAttribute (juce_xmltextContentAttributeName, newText);
  12151. }
  12152. else
  12153. {
  12154. jassertfalse // you can only change the text in a text element, not a normal one.
  12155. }
  12156. }
  12157. const String XmlElement::getAllSubText() const throw()
  12158. {
  12159. String result;
  12160. String::Concatenator concatenator (result);
  12161. const XmlElement* child = firstChildElement;
  12162. while (child != 0)
  12163. {
  12164. if (child->isTextElement())
  12165. concatenator.append (child->getText());
  12166. child = child->nextElement;
  12167. }
  12168. return result;
  12169. }
  12170. const String XmlElement::getChildElementAllSubText (const String& childTagName,
  12171. const String& defaultReturnValue) const throw()
  12172. {
  12173. const XmlElement* const child = getChildByName (childTagName);
  12174. if (child != 0)
  12175. return child->getAllSubText();
  12176. return defaultReturnValue;
  12177. }
  12178. XmlElement* XmlElement::createTextElement (const String& text) throw()
  12179. {
  12180. XmlElement* const e = new XmlElement ((int) 0);
  12181. e->setAttribute (juce_xmltextContentAttributeName, text);
  12182. return e;
  12183. }
  12184. void XmlElement::addTextElement (const String& text) throw()
  12185. {
  12186. addChildElement (createTextElement (text));
  12187. }
  12188. void XmlElement::deleteAllTextElements() throw()
  12189. {
  12190. XmlElement* child = firstChildElement;
  12191. while (child != 0)
  12192. {
  12193. XmlElement* const next = child->nextElement;
  12194. if (child->isTextElement())
  12195. removeChildElement (child, true);
  12196. child = next;
  12197. }
  12198. }
  12199. END_JUCE_NAMESPACE
  12200. /*** End of inlined file: juce_XmlElement.cpp ***/
  12201. /*** Start of inlined file: juce_InterProcessLock.cpp ***/
  12202. BEGIN_JUCE_NAMESPACE
  12203. // (implemented in the platform-specific code files)
  12204. END_JUCE_NAMESPACE
  12205. /*** End of inlined file: juce_InterProcessLock.cpp ***/
  12206. /*** Start of inlined file: juce_ReadWriteLock.cpp ***/
  12207. BEGIN_JUCE_NAMESPACE
  12208. ReadWriteLock::ReadWriteLock() throw()
  12209. : numWaitingWriters (0),
  12210. numWriters (0),
  12211. writerThreadId (0)
  12212. {
  12213. }
  12214. ReadWriteLock::~ReadWriteLock() throw()
  12215. {
  12216. jassert (readerThreads.size() == 0);
  12217. jassert (numWriters == 0);
  12218. }
  12219. void ReadWriteLock::enterRead() const throw()
  12220. {
  12221. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12222. const ScopedLock sl (accessLock);
  12223. for (;;)
  12224. {
  12225. jassert (readerThreads.size() % 2 == 0);
  12226. int i;
  12227. for (i = 0; i < readerThreads.size(); i += 2)
  12228. if (readerThreads.getUnchecked(i) == threadId)
  12229. break;
  12230. if (i < readerThreads.size()
  12231. || numWriters + numWaitingWriters == 0
  12232. || (threadId == writerThreadId && numWriters > 0))
  12233. {
  12234. if (i < readerThreads.size())
  12235. {
  12236. readerThreads.set (i + 1, (Thread::ThreadID) (1 + (pointer_sized_int) readerThreads.getUnchecked (i + 1)));
  12237. }
  12238. else
  12239. {
  12240. readerThreads.add (threadId);
  12241. readerThreads.add ((Thread::ThreadID) 1);
  12242. }
  12243. return;
  12244. }
  12245. const ScopedUnlock ul (accessLock);
  12246. waitEvent.wait (100);
  12247. }
  12248. }
  12249. void ReadWriteLock::exitRead() const throw()
  12250. {
  12251. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12252. const ScopedLock sl (accessLock);
  12253. for (int i = 0; i < readerThreads.size(); i += 2)
  12254. {
  12255. if (readerThreads.getUnchecked(i) == threadId)
  12256. {
  12257. const pointer_sized_int newCount = ((pointer_sized_int) readerThreads.getUnchecked (i + 1)) - 1;
  12258. if (newCount == 0)
  12259. {
  12260. readerThreads.removeRange (i, 2);
  12261. waitEvent.signal();
  12262. }
  12263. else
  12264. {
  12265. readerThreads.set (i + 1, (Thread::ThreadID) newCount);
  12266. }
  12267. return;
  12268. }
  12269. }
  12270. jassertfalse // unlocking a lock that wasn't locked..
  12271. }
  12272. void ReadWriteLock::enterWrite() const throw()
  12273. {
  12274. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12275. const ScopedLock sl (accessLock);
  12276. for (;;)
  12277. {
  12278. if (readerThreads.size() + numWriters == 0
  12279. || threadId == writerThreadId
  12280. || (readerThreads.size() == 2
  12281. && readerThreads.getUnchecked(0) == threadId))
  12282. {
  12283. writerThreadId = threadId;
  12284. ++numWriters;
  12285. break;
  12286. }
  12287. ++numWaitingWriters;
  12288. accessLock.exit();
  12289. waitEvent.wait (100);
  12290. accessLock.enter();
  12291. --numWaitingWriters;
  12292. }
  12293. }
  12294. bool ReadWriteLock::tryEnterWrite() const throw()
  12295. {
  12296. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12297. const ScopedLock sl (accessLock);
  12298. if (readerThreads.size() + numWriters == 0
  12299. || threadId == writerThreadId
  12300. || (readerThreads.size() == 2
  12301. && readerThreads.getUnchecked(0) == threadId))
  12302. {
  12303. writerThreadId = threadId;
  12304. ++numWriters;
  12305. return true;
  12306. }
  12307. return false;
  12308. }
  12309. void ReadWriteLock::exitWrite() const throw()
  12310. {
  12311. const ScopedLock sl (accessLock);
  12312. // check this thread actually had the lock..
  12313. jassert (numWriters > 0 && writerThreadId == Thread::getCurrentThreadId());
  12314. if (--numWriters == 0)
  12315. {
  12316. writerThreadId = 0;
  12317. waitEvent.signal();
  12318. }
  12319. }
  12320. END_JUCE_NAMESPACE
  12321. /*** End of inlined file: juce_ReadWriteLock.cpp ***/
  12322. /*** Start of inlined file: juce_Thread.cpp ***/
  12323. BEGIN_JUCE_NAMESPACE
  12324. // these functions are implemented in the platform-specific code.
  12325. void* juce_createThread (void* userData);
  12326. void juce_killThread (void* handle);
  12327. bool juce_setThreadPriority (void* handle, int priority);
  12328. void juce_setCurrentThreadName (const String& name);
  12329. #if JUCE_WIN32
  12330. void juce_CloseThreadHandle (void* handle);
  12331. #endif
  12332. void Thread::threadEntryPoint (Thread* const thread)
  12333. {
  12334. {
  12335. const ScopedLock sl (runningThreadsLock);
  12336. runningThreads.add (thread);
  12337. }
  12338. JUCE_TRY
  12339. {
  12340. thread->threadId_ = Thread::getCurrentThreadId();
  12341. if (thread->threadName_.isNotEmpty())
  12342. juce_setCurrentThreadName (thread->threadName_);
  12343. if (thread->startSuspensionEvent_.wait (10000))
  12344. {
  12345. if (thread->affinityMask_ != 0)
  12346. setCurrentThreadAffinityMask (thread->affinityMask_);
  12347. thread->run();
  12348. }
  12349. }
  12350. JUCE_CATCH_ALL_ASSERT
  12351. {
  12352. const ScopedLock sl (runningThreadsLock);
  12353. jassert (runningThreads.contains (thread));
  12354. runningThreads.removeValue (thread);
  12355. }
  12356. #if JUCE_WIN32
  12357. juce_CloseThreadHandle (thread->threadHandle_);
  12358. #endif
  12359. thread->threadHandle_ = 0;
  12360. thread->threadId_ = 0;
  12361. }
  12362. // used to wrap the incoming call from the platform-specific code
  12363. void JUCE_API juce_threadEntryPoint (void* userData)
  12364. {
  12365. Thread::threadEntryPoint ((Thread*) userData);
  12366. }
  12367. Thread::Thread (const String& threadName)
  12368. : threadName_ (threadName),
  12369. threadHandle_ (0),
  12370. threadPriority_ (5),
  12371. threadId_ (0),
  12372. affinityMask_ (0),
  12373. threadShouldExit_ (false)
  12374. {
  12375. }
  12376. Thread::~Thread()
  12377. {
  12378. stopThread (100);
  12379. }
  12380. void Thread::startThread()
  12381. {
  12382. const ScopedLock sl (startStopLock);
  12383. threadShouldExit_ = false;
  12384. if (threadHandle_ == 0)
  12385. {
  12386. threadHandle_ = juce_createThread ((void*) this);
  12387. juce_setThreadPriority (threadHandle_, threadPriority_);
  12388. startSuspensionEvent_.signal();
  12389. }
  12390. }
  12391. void Thread::startThread (const int priority)
  12392. {
  12393. const ScopedLock sl (startStopLock);
  12394. if (threadHandle_ == 0)
  12395. {
  12396. threadPriority_ = priority;
  12397. startThread();
  12398. }
  12399. else
  12400. {
  12401. setPriority (priority);
  12402. }
  12403. }
  12404. bool Thread::isThreadRunning() const
  12405. {
  12406. return threadHandle_ != 0;
  12407. }
  12408. void Thread::signalThreadShouldExit()
  12409. {
  12410. threadShouldExit_ = true;
  12411. }
  12412. bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
  12413. {
  12414. // Doh! So how exactly do you expect this thread to wait for itself to stop??
  12415. jassert (getThreadId() != getCurrentThreadId());
  12416. const int sleepMsPerIteration = 5;
  12417. int count = timeOutMilliseconds / sleepMsPerIteration;
  12418. while (isThreadRunning())
  12419. {
  12420. if (timeOutMilliseconds > 0 && --count < 0)
  12421. return false;
  12422. sleep (sleepMsPerIteration);
  12423. }
  12424. return true;
  12425. }
  12426. void Thread::stopThread (const int timeOutMilliseconds)
  12427. {
  12428. // agh! You can't stop the thread that's calling this method! How on earth
  12429. // would that work??
  12430. jassert (getCurrentThreadId() != getThreadId());
  12431. const ScopedLock sl (startStopLock);
  12432. if (isThreadRunning())
  12433. {
  12434. signalThreadShouldExit();
  12435. notify();
  12436. if (timeOutMilliseconds != 0)
  12437. waitForThreadToExit (timeOutMilliseconds);
  12438. if (isThreadRunning())
  12439. {
  12440. // very bad karma if this point is reached, as
  12441. // there are bound to be locks and events left in
  12442. // silly states when a thread is killed by force..
  12443. jassertfalse
  12444. Logger::writeToLog ("!! killing thread by force !!");
  12445. juce_killThread (threadHandle_);
  12446. threadHandle_ = 0;
  12447. threadId_ = 0;
  12448. const ScopedLock sl2 (runningThreadsLock);
  12449. runningThreads.removeValue (this);
  12450. }
  12451. }
  12452. }
  12453. bool Thread::setPriority (const int priority)
  12454. {
  12455. const ScopedLock sl (startStopLock);
  12456. const bool worked = juce_setThreadPriority (threadHandle_, priority);
  12457. if (worked)
  12458. threadPriority_ = priority;
  12459. return worked;
  12460. }
  12461. bool Thread::setCurrentThreadPriority (const int priority)
  12462. {
  12463. return juce_setThreadPriority (0, priority);
  12464. }
  12465. void Thread::setAffinityMask (const uint32 affinityMask)
  12466. {
  12467. affinityMask_ = affinityMask;
  12468. }
  12469. bool Thread::wait (const int timeOutMilliseconds) const
  12470. {
  12471. return defaultEvent_.wait (timeOutMilliseconds);
  12472. }
  12473. void Thread::notify() const
  12474. {
  12475. defaultEvent_.signal();
  12476. }
  12477. int Thread::getNumRunningThreads()
  12478. {
  12479. return runningThreads.size();
  12480. }
  12481. Thread* Thread::getCurrentThread()
  12482. {
  12483. const ThreadID thisId = getCurrentThreadId();
  12484. const ScopedLock sl (runningThreadsLock);
  12485. for (int i = runningThreads.size(); --i >= 0;)
  12486. {
  12487. Thread* const t = runningThreads.getUnchecked(i);
  12488. if (t->threadId_ == thisId)
  12489. return t;
  12490. }
  12491. return 0;
  12492. }
  12493. void Thread::stopAllThreads (const int timeOutMilliseconds)
  12494. {
  12495. {
  12496. const ScopedLock sl (runningThreadsLock);
  12497. for (int i = runningThreads.size(); --i >= 0;)
  12498. runningThreads.getUnchecked(i)->signalThreadShouldExit();
  12499. }
  12500. for (;;)
  12501. {
  12502. Thread* firstThread;
  12503. {
  12504. const ScopedLock sl (runningThreadsLock);
  12505. firstThread = runningThreads.getFirst();
  12506. }
  12507. if (firstThread == 0)
  12508. break;
  12509. firstThread->stopThread (timeOutMilliseconds);
  12510. }
  12511. }
  12512. Array<Thread*> Thread::runningThreads;
  12513. CriticalSection Thread::runningThreadsLock;
  12514. END_JUCE_NAMESPACE
  12515. /*** End of inlined file: juce_Thread.cpp ***/
  12516. /*** Start of inlined file: juce_ThreadPool.cpp ***/
  12517. BEGIN_JUCE_NAMESPACE
  12518. ThreadPoolJob::ThreadPoolJob (const String& name)
  12519. : jobName (name),
  12520. pool (0),
  12521. shouldStop (false),
  12522. isActive (false),
  12523. shouldBeDeleted (false)
  12524. {
  12525. }
  12526. ThreadPoolJob::~ThreadPoolJob()
  12527. {
  12528. // you mustn't delete a job while it's still in a pool! Use ThreadPool::removeJob()
  12529. // to remove it first!
  12530. jassert (pool == 0 || ! pool->contains (this));
  12531. }
  12532. const String ThreadPoolJob::getJobName() const
  12533. {
  12534. return jobName;
  12535. }
  12536. void ThreadPoolJob::setJobName (const String& newName)
  12537. {
  12538. jobName = newName;
  12539. }
  12540. void ThreadPoolJob::signalJobShouldExit()
  12541. {
  12542. shouldStop = true;
  12543. }
  12544. class ThreadPool::ThreadPoolThread : public Thread
  12545. {
  12546. public:
  12547. ThreadPoolThread (ThreadPool& pool_)
  12548. : Thread (T("Pool")),
  12549. pool (pool_),
  12550. busy (false)
  12551. {
  12552. }
  12553. ~ThreadPoolThread()
  12554. {
  12555. }
  12556. void run()
  12557. {
  12558. while (! threadShouldExit())
  12559. {
  12560. if (! pool.runNextJob())
  12561. wait (500);
  12562. }
  12563. }
  12564. private:
  12565. ThreadPool& pool;
  12566. bool volatile busy;
  12567. ThreadPoolThread (const ThreadPoolThread&);
  12568. ThreadPoolThread& operator= (const ThreadPoolThread&);
  12569. };
  12570. ThreadPool::ThreadPool (const int numThreads,
  12571. const bool startThreadsOnlyWhenNeeded,
  12572. const int stopThreadsWhenNotUsedTimeoutMs)
  12573. : threadStopTimeout (stopThreadsWhenNotUsedTimeoutMs),
  12574. priority (5)
  12575. {
  12576. jassert (numThreads > 0); // not much point having one of these with no threads in it.
  12577. for (int i = jmax (1, numThreads); --i >= 0;)
  12578. threads.add (new ThreadPoolThread (*this));
  12579. if (! startThreadsOnlyWhenNeeded)
  12580. for (int i = threads.size(); --i >= 0;)
  12581. threads.getUnchecked(i)->startThread (priority);
  12582. }
  12583. ThreadPool::~ThreadPool()
  12584. {
  12585. removeAllJobs (true, 4000);
  12586. int i;
  12587. for (i = threads.size(); --i >= 0;)
  12588. threads.getUnchecked(i)->signalThreadShouldExit();
  12589. for (i = threads.size(); --i >= 0;)
  12590. threads.getUnchecked(i)->stopThread (500);
  12591. }
  12592. void ThreadPool::addJob (ThreadPoolJob* const job)
  12593. {
  12594. jassert (job != 0);
  12595. jassert (job->pool == 0);
  12596. if (job->pool == 0)
  12597. {
  12598. job->pool = this;
  12599. job->shouldStop = false;
  12600. job->isActive = false;
  12601. {
  12602. const ScopedLock sl (lock);
  12603. jobs.add (job);
  12604. int numRunning = 0;
  12605. for (int i = threads.size(); --i >= 0;)
  12606. if (threads.getUnchecked(i)->isThreadRunning() && ! threads.getUnchecked(i)->threadShouldExit())
  12607. ++numRunning;
  12608. if (numRunning < threads.size())
  12609. {
  12610. bool startedOne = false;
  12611. int n = 1000;
  12612. while (--n >= 0 && ! startedOne)
  12613. {
  12614. for (int i = threads.size(); --i >= 0;)
  12615. {
  12616. if (! threads.getUnchecked(i)->isThreadRunning())
  12617. {
  12618. threads.getUnchecked(i)->startThread (priority);
  12619. startedOne = true;
  12620. break;
  12621. }
  12622. }
  12623. if (! startedOne)
  12624. Thread::sleep (2);
  12625. }
  12626. }
  12627. }
  12628. for (int i = threads.size(); --i >= 0;)
  12629. threads.getUnchecked(i)->notify();
  12630. }
  12631. }
  12632. int ThreadPool::getNumJobs() const
  12633. {
  12634. return jobs.size();
  12635. }
  12636. ThreadPoolJob* ThreadPool::getJob (const int index) const
  12637. {
  12638. const ScopedLock sl (lock);
  12639. return (ThreadPoolJob*) jobs [index];
  12640. }
  12641. bool ThreadPool::contains (const ThreadPoolJob* const job) const
  12642. {
  12643. const ScopedLock sl (lock);
  12644. return jobs.contains (const_cast <ThreadPoolJob*> (job));
  12645. }
  12646. bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
  12647. {
  12648. const ScopedLock sl (lock);
  12649. return jobs.contains (const_cast <ThreadPoolJob*> (job)) && job->isActive;
  12650. }
  12651. bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job,
  12652. const int timeOutMs) const
  12653. {
  12654. if (job != 0)
  12655. {
  12656. const uint32 start = Time::getMillisecondCounter();
  12657. while (contains (job))
  12658. {
  12659. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12660. return false;
  12661. jobFinishedSignal.wait (2);
  12662. }
  12663. }
  12664. return true;
  12665. }
  12666. bool ThreadPool::removeJob (ThreadPoolJob* const job,
  12667. const bool interruptIfRunning,
  12668. const int timeOutMs)
  12669. {
  12670. bool dontWait = true;
  12671. if (job != 0)
  12672. {
  12673. const ScopedLock sl (lock);
  12674. if (jobs.contains (job))
  12675. {
  12676. if (job->isActive)
  12677. {
  12678. if (interruptIfRunning)
  12679. job->signalJobShouldExit();
  12680. dontWait = false;
  12681. }
  12682. else
  12683. {
  12684. jobs.removeValue (job);
  12685. }
  12686. }
  12687. }
  12688. return dontWait || waitForJobToFinish (job, timeOutMs);
  12689. }
  12690. bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
  12691. const int timeOutMs,
  12692. const bool deleteInactiveJobs,
  12693. ThreadPool::JobSelector* selectedJobsToRemove)
  12694. {
  12695. Array <ThreadPoolJob*> jobsToWaitFor;
  12696. {
  12697. const ScopedLock sl (lock);
  12698. for (int i = jobs.size(); --i >= 0;)
  12699. {
  12700. ThreadPoolJob* const job = jobs.getUnchecked(i);
  12701. if (selectedJobsToRemove == 0 || selectedJobsToRemove->isJobSuitable (job))
  12702. {
  12703. if (job->isActive)
  12704. {
  12705. jobsToWaitFor.add (job);
  12706. if (interruptRunningJobs)
  12707. job->signalJobShouldExit();
  12708. }
  12709. else
  12710. {
  12711. jobs.remove (i);
  12712. if (deleteInactiveJobs)
  12713. delete job;
  12714. }
  12715. }
  12716. }
  12717. }
  12718. const uint32 start = Time::getMillisecondCounter();
  12719. for (;;)
  12720. {
  12721. for (int i = jobsToWaitFor.size(); --i >= 0;)
  12722. if (! isJobRunning (jobsToWaitFor.getUnchecked (i)))
  12723. jobsToWaitFor.remove (i);
  12724. if (jobsToWaitFor.size() == 0)
  12725. break;
  12726. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12727. return false;
  12728. jobFinishedSignal.wait (20);
  12729. }
  12730. return true;
  12731. }
  12732. const StringArray ThreadPool::getNamesOfAllJobs (const bool onlyReturnActiveJobs) const
  12733. {
  12734. StringArray s;
  12735. const ScopedLock sl (lock);
  12736. for (int i = 0; i < jobs.size(); ++i)
  12737. {
  12738. const ThreadPoolJob* const job = jobs.getUnchecked(i);
  12739. if (job->isActive || ! onlyReturnActiveJobs)
  12740. s.add (job->getJobName());
  12741. }
  12742. return s;
  12743. }
  12744. bool ThreadPool::setThreadPriorities (const int newPriority)
  12745. {
  12746. bool ok = true;
  12747. if (priority != newPriority)
  12748. {
  12749. priority = newPriority;
  12750. for (int i = threads.size(); --i >= 0;)
  12751. if (! threads.getUnchecked(i)->setPriority (newPriority))
  12752. ok = false;
  12753. }
  12754. return ok;
  12755. }
  12756. bool ThreadPool::runNextJob()
  12757. {
  12758. ThreadPoolJob* job = 0;
  12759. {
  12760. const ScopedLock sl (lock);
  12761. for (int i = 0; i < jobs.size(); ++i)
  12762. {
  12763. job = jobs[i];
  12764. if (job != 0 && ! (job->isActive || job->shouldStop))
  12765. break;
  12766. job = 0;
  12767. }
  12768. if (job != 0)
  12769. job->isActive = true;
  12770. }
  12771. if (job != 0)
  12772. {
  12773. JUCE_TRY
  12774. {
  12775. ThreadPoolJob::JobStatus result = job->runJob();
  12776. lastJobEndTime = Time::getApproximateMillisecondCounter();
  12777. const ScopedLock sl (lock);
  12778. if (jobs.contains (job))
  12779. {
  12780. job->isActive = false;
  12781. if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
  12782. {
  12783. job->pool = 0;
  12784. job->shouldStop = true;
  12785. jobs.removeValue (job);
  12786. if (result == ThreadPoolJob::jobHasFinishedAndShouldBeDeleted)
  12787. delete job;
  12788. jobFinishedSignal.signal();
  12789. }
  12790. else
  12791. {
  12792. // move the job to the end of the queue if it wants another go
  12793. jobs.move (jobs.indexOf (job), -1);
  12794. }
  12795. }
  12796. }
  12797. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  12798. catch (...)
  12799. {
  12800. const ScopedLock sl (lock);
  12801. jobs.removeValue (job);
  12802. }
  12803. #endif
  12804. }
  12805. else
  12806. {
  12807. if (threadStopTimeout > 0
  12808. && Time::getApproximateMillisecondCounter() > lastJobEndTime + threadStopTimeout)
  12809. {
  12810. const ScopedLock sl (lock);
  12811. if (jobs.size() == 0)
  12812. for (int i = threads.size(); --i >= 0;)
  12813. threads.getUnchecked(i)->signalThreadShouldExit();
  12814. }
  12815. else
  12816. {
  12817. return false;
  12818. }
  12819. }
  12820. return true;
  12821. }
  12822. END_JUCE_NAMESPACE
  12823. /*** End of inlined file: juce_ThreadPool.cpp ***/
  12824. /*** Start of inlined file: juce_TimeSliceThread.cpp ***/
  12825. BEGIN_JUCE_NAMESPACE
  12826. TimeSliceThread::TimeSliceThread (const String& threadName)
  12827. : Thread (threadName),
  12828. index (0),
  12829. clientBeingCalled (0),
  12830. clientsChanged (false)
  12831. {
  12832. }
  12833. TimeSliceThread::~TimeSliceThread()
  12834. {
  12835. stopThread (2000);
  12836. }
  12837. void TimeSliceThread::addTimeSliceClient (TimeSliceClient* const client)
  12838. {
  12839. const ScopedLock sl (listLock);
  12840. clients.addIfNotAlreadyThere (client);
  12841. clientsChanged = true;
  12842. notify();
  12843. }
  12844. void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
  12845. {
  12846. const ScopedLock sl1 (listLock);
  12847. clientsChanged = true;
  12848. // if there's a chance we're in the middle of calling this client, we need to
  12849. // also lock the outer lock..
  12850. if (clientBeingCalled == client)
  12851. {
  12852. const ScopedUnlock ul (listLock); // unlock first to get the order right..
  12853. const ScopedLock sl2 (callbackLock);
  12854. const ScopedLock sl3 (listLock);
  12855. clients.removeValue (client);
  12856. }
  12857. else
  12858. {
  12859. clients.removeValue (client);
  12860. }
  12861. }
  12862. int TimeSliceThread::getNumClients() const
  12863. {
  12864. return clients.size();
  12865. }
  12866. TimeSliceClient* TimeSliceThread::getClient (const int i) const
  12867. {
  12868. const ScopedLock sl (listLock);
  12869. return clients [i];
  12870. }
  12871. void TimeSliceThread::run()
  12872. {
  12873. int numCallsSinceBusy = 0;
  12874. while (! threadShouldExit())
  12875. {
  12876. int timeToWait = 500;
  12877. {
  12878. const ScopedLock sl (callbackLock);
  12879. {
  12880. const ScopedLock sl2 (listLock);
  12881. if (clients.size() > 0)
  12882. {
  12883. index = (index + 1) % clients.size();
  12884. clientBeingCalled = clients [index];
  12885. }
  12886. else
  12887. {
  12888. index = 0;
  12889. clientBeingCalled = 0;
  12890. }
  12891. if (clientsChanged)
  12892. {
  12893. clientsChanged = false;
  12894. numCallsSinceBusy = 0;
  12895. }
  12896. }
  12897. if (clientBeingCalled != 0)
  12898. {
  12899. if (clientBeingCalled->useTimeSlice())
  12900. numCallsSinceBusy = 0;
  12901. else
  12902. ++numCallsSinceBusy;
  12903. if (numCallsSinceBusy >= clients.size())
  12904. timeToWait = 500;
  12905. else if (index == 0)
  12906. timeToWait = 1; // throw in an occasional pause, to stop everything locking up
  12907. else
  12908. timeToWait = 0;
  12909. }
  12910. }
  12911. if (timeToWait > 0)
  12912. wait (timeToWait);
  12913. }
  12914. }
  12915. END_JUCE_NAMESPACE
  12916. /*** End of inlined file: juce_TimeSliceThread.cpp ***/
  12917. #endif
  12918. #if JUCE_BUILD_MISC
  12919. /*** Start of inlined file: juce_ValueTree.cpp ***/
  12920. BEGIN_JUCE_NAMESPACE
  12921. class ValueTreeSetPropertyAction : public UndoableAction
  12922. {
  12923. public:
  12924. ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& name_,
  12925. const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_)
  12926. : target (target_), name (name_), newValue (newValue_),
  12927. isAddingNewProperty (isAddingNewProperty_),
  12928. isDeletingProperty (isDeletingProperty_)
  12929. {
  12930. if (! isAddingNewProperty)
  12931. oldValue = target_->getProperty (name_);
  12932. }
  12933. ~ValueTreeSetPropertyAction() {}
  12934. bool perform()
  12935. {
  12936. jassert (! (isAddingNewProperty && target->hasProperty (name)));
  12937. if (isDeletingProperty)
  12938. target->removeProperty (name, 0);
  12939. else
  12940. target->setProperty (name, newValue, 0);
  12941. return true;
  12942. }
  12943. bool undo()
  12944. {
  12945. if (isAddingNewProperty)
  12946. target->removeProperty (name, 0);
  12947. else
  12948. target->setProperty (name, oldValue, 0);
  12949. return true;
  12950. }
  12951. int getSizeInUnits()
  12952. {
  12953. return (int) sizeof (*this); //xxx should be more accurate
  12954. }
  12955. private:
  12956. const ValueTree::SharedObjectPtr target;
  12957. const var::identifier name;
  12958. const var newValue;
  12959. var oldValue;
  12960. const bool isAddingNewProperty, isDeletingProperty;
  12961. ValueTreeSetPropertyAction (const ValueTreeSetPropertyAction&);
  12962. ValueTreeSetPropertyAction& operator= (const ValueTreeSetPropertyAction&);
  12963. };
  12964. class ValueTreeChildChangeAction : public UndoableAction
  12965. {
  12966. public:
  12967. ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_,
  12968. const ValueTree::SharedObjectPtr& newChild_)
  12969. : target (target_),
  12970. child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]),
  12971. childIndex (childIndex_),
  12972. isDeleting (newChild_ == 0)
  12973. {
  12974. jassert (child != 0);
  12975. }
  12976. ~ValueTreeChildChangeAction() {}
  12977. bool perform()
  12978. {
  12979. if (isDeleting)
  12980. target->removeChild (childIndex, 0);
  12981. else
  12982. target->addChild (child, childIndex, 0);
  12983. return true;
  12984. }
  12985. bool undo()
  12986. {
  12987. if (isDeleting)
  12988. target->addChild (child, childIndex, 0);
  12989. else
  12990. target->removeChild (childIndex, 0);
  12991. return true;
  12992. }
  12993. int getSizeInUnits()
  12994. {
  12995. return (int) sizeof (*this); //xxx should be more accurate
  12996. }
  12997. private:
  12998. const ValueTree::SharedObjectPtr target, child;
  12999. const int childIndex;
  13000. const bool isDeleting;
  13001. ValueTreeChildChangeAction (const ValueTreeChildChangeAction&);
  13002. ValueTreeChildChangeAction& operator= (const ValueTreeChildChangeAction&);
  13003. };
  13004. ValueTree::SharedObject::SharedObject (const String& type_)
  13005. : type (type_), parent (0)
  13006. {
  13007. }
  13008. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  13009. : type (other.type), properties (other.properties), parent (0)
  13010. {
  13011. for (int i = 0; i < other.children.size(); ++i)
  13012. children.add (new SharedObject (*other.children.getUnchecked(i)));
  13013. }
  13014. ValueTree::SharedObject::~SharedObject()
  13015. {
  13016. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  13017. for (int i = children.size(); --i >= 0;)
  13018. {
  13019. const SharedObjectPtr c (children.getUnchecked(i));
  13020. c->parent = 0;
  13021. children.remove (i);
  13022. c->sendParentChangeMessage();
  13023. }
  13024. }
  13025. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  13026. {
  13027. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  13028. {
  13029. ValueTree* const v = valueTreesWithListeners[i];
  13030. if (v != 0)
  13031. v->listeners.call (&ValueTree::Listener::valueTreePropertyChanged, tree, property);
  13032. }
  13033. }
  13034. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  13035. {
  13036. ValueTree tree (this);
  13037. ValueTree::SharedObject* t = this;
  13038. while (t != 0)
  13039. {
  13040. t->sendPropertyChangeMessage (tree, property);
  13041. t = t->parent;
  13042. }
  13043. }
  13044. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  13045. {
  13046. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  13047. {
  13048. ValueTree* const v = valueTreesWithListeners[i];
  13049. if (v != 0)
  13050. v->listeners.call (&ValueTree::Listener::valueTreeChildrenChanged, tree);
  13051. }
  13052. }
  13053. void ValueTree::SharedObject::sendChildChangeMessage()
  13054. {
  13055. ValueTree tree (this);
  13056. ValueTree::SharedObject* t = this;
  13057. while (t != 0)
  13058. {
  13059. t->sendChildChangeMessage (tree);
  13060. t = t->parent;
  13061. }
  13062. }
  13063. void ValueTree::SharedObject::sendParentChangeMessage()
  13064. {
  13065. ValueTree tree (this);
  13066. int i;
  13067. for (i = children.size(); --i >= 0;)
  13068. {
  13069. SharedObject* const t = children[i];
  13070. if (t != 0)
  13071. t->sendParentChangeMessage();
  13072. }
  13073. for (i = valueTreesWithListeners.size(); --i >= 0;)
  13074. {
  13075. ValueTree* const v = valueTreesWithListeners[i];
  13076. if (v != 0)
  13077. v->listeners.call (&ValueTree::Listener::valueTreeParentChanged, tree);
  13078. }
  13079. }
  13080. const var& ValueTree::SharedObject::getProperty (const var::identifier& name) const
  13081. {
  13082. return properties [name];
  13083. }
  13084. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13085. {
  13086. if (undoManager == 0)
  13087. {
  13088. if (properties.set (name, newValue))
  13089. sendPropertyChangeMessage (name);
  13090. }
  13091. else
  13092. {
  13093. var* const existingValue = properties.getItem (name);
  13094. if (existingValue != 0)
  13095. {
  13096. if (*existingValue != newValue)
  13097. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, false, false));
  13098. }
  13099. else
  13100. {
  13101. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, true, false));
  13102. }
  13103. }
  13104. }
  13105. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  13106. {
  13107. return properties.contains (name);
  13108. }
  13109. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13110. {
  13111. if (undoManager == 0)
  13112. {
  13113. if (properties.remove (name))
  13114. sendPropertyChangeMessage (name);
  13115. }
  13116. else
  13117. {
  13118. if (properties.contains (name))
  13119. undoManager->perform (new ValueTreeSetPropertyAction (this, name, var::null, false, true));
  13120. }
  13121. }
  13122. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  13123. {
  13124. if (undoManager == 0)
  13125. {
  13126. while (properties.size() > 0)
  13127. {
  13128. const var::identifier name (properties.getName (properties.size() - 1));
  13129. properties.remove (name);
  13130. sendPropertyChangeMessage (name);
  13131. }
  13132. }
  13133. else
  13134. {
  13135. for (int i = properties.size(); --i >= 0;)
  13136. undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getName(i), var::null, false, true));
  13137. }
  13138. }
  13139. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  13140. {
  13141. for (int i = 0; i < children.size(); ++i)
  13142. if (children.getUnchecked(i)->type == typeToMatch)
  13143. return (SharedObject*) children.getUnchecked(i);
  13144. return (SharedObject*) 0;
  13145. }
  13146. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13147. {
  13148. for (int i = 0; i < children.size(); ++i)
  13149. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  13150. return (SharedObject*) children.getUnchecked(i);
  13151. return (SharedObject*) 0;
  13152. }
  13153. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  13154. {
  13155. const SharedObject* p = parent;
  13156. while (p != 0)
  13157. {
  13158. if (p == possibleParent)
  13159. return true;
  13160. p = p->parent;
  13161. }
  13162. return false;
  13163. }
  13164. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  13165. {
  13166. if (child != 0 && child->parent != this)
  13167. {
  13168. if (child != this && ! isAChildOf (child))
  13169. {
  13170. // You should always make sure that a child is removed from its previous parent before
  13171. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  13172. // undomanager should be used when removing it from its current parent..
  13173. jassert (child->parent == 0);
  13174. if (child->parent != 0)
  13175. {
  13176. jassert (child->parent->children.indexOf (child) >= 0);
  13177. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  13178. }
  13179. if (undoManager == 0)
  13180. {
  13181. children.insert (index, child);
  13182. child->parent = this;
  13183. sendChildChangeMessage();
  13184. child->sendParentChangeMessage();
  13185. }
  13186. else
  13187. {
  13188. undoManager->perform (new ValueTreeChildChangeAction (this, index, child));
  13189. }
  13190. }
  13191. else
  13192. {
  13193. // You're attempting to create a recursive loop! A node
  13194. // can't be a child of one of its own children!
  13195. jassertfalse
  13196. }
  13197. }
  13198. }
  13199. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  13200. {
  13201. const SharedObjectPtr child (children [childIndex]);
  13202. if (child != 0)
  13203. {
  13204. if (undoManager == 0)
  13205. {
  13206. children.remove (childIndex);
  13207. child->parent = 0;
  13208. sendChildChangeMessage();
  13209. child->sendParentChangeMessage();
  13210. }
  13211. else
  13212. {
  13213. undoManager->perform (new ValueTreeChildChangeAction (this, childIndex, 0));
  13214. }
  13215. }
  13216. }
  13217. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  13218. {
  13219. while (children.size() > 0)
  13220. removeChild (children.size() - 1, undoManager);
  13221. }
  13222. ValueTree::ValueTree (const String& type_)
  13223. : object (new ValueTree::SharedObject (type_))
  13224. {
  13225. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  13226. }
  13227. ValueTree::ValueTree (SharedObject* const object_)
  13228. : object (object_)
  13229. {
  13230. }
  13231. ValueTree::ValueTree (const ValueTree& other)
  13232. : object (other.object)
  13233. {
  13234. }
  13235. ValueTree& ValueTree::operator= (const ValueTree& other)
  13236. {
  13237. if (listeners.size() > 0)
  13238. {
  13239. if (object != 0)
  13240. object->valueTreesWithListeners.removeValue (this);
  13241. if (other.object != 0)
  13242. other.object->valueTreesWithListeners.add (this);
  13243. }
  13244. object = other.object;
  13245. return *this;
  13246. }
  13247. ValueTree::~ValueTree()
  13248. {
  13249. if (listeners.size() > 0 && object != 0)
  13250. object->valueTreesWithListeners.removeValue (this);
  13251. }
  13252. bool ValueTree::operator== (const ValueTree& other) const
  13253. {
  13254. return object == other.object;
  13255. }
  13256. bool ValueTree::operator!= (const ValueTree& other) const
  13257. {
  13258. return object != other.object;
  13259. }
  13260. ValueTree ValueTree::createCopy() const
  13261. {
  13262. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  13263. }
  13264. bool ValueTree::hasType (const String& typeName) const
  13265. {
  13266. return object != 0 && object->type == typeName;
  13267. }
  13268. const String ValueTree::getType() const
  13269. {
  13270. return object != 0 ? object->type : String::empty;
  13271. }
  13272. ValueTree ValueTree::getParent() const
  13273. {
  13274. return object != 0 ? ValueTree (object->parent) : ValueTree ((SharedObject*) 0);
  13275. }
  13276. const var& ValueTree::operator[] (const var::identifier& name) const
  13277. {
  13278. return object == 0 ? var::null : object->getProperty (name);
  13279. }
  13280. const var& ValueTree::getProperty (const var::identifier& name) const
  13281. {
  13282. return object == 0 ? var::null : object->getProperty (name);
  13283. }
  13284. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13285. {
  13286. jassert (name.name.isNotEmpty());
  13287. if (object != 0 && name.name.isNotEmpty())
  13288. object->setProperty (name, newValue, undoManager);
  13289. }
  13290. bool ValueTree::hasProperty (const var::identifier& name) const
  13291. {
  13292. return object != 0 && object->hasProperty (name);
  13293. }
  13294. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13295. {
  13296. if (object != 0)
  13297. object->removeProperty (name, undoManager);
  13298. }
  13299. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  13300. {
  13301. if (object != 0)
  13302. object->removeAllProperties (undoManager);
  13303. }
  13304. int ValueTree::getNumProperties() const
  13305. {
  13306. return object == 0 ? 0 : object->properties.size();
  13307. }
  13308. const var::identifier ValueTree::getPropertyName (int index) const
  13309. {
  13310. return (object == 0) ? var::identifier()
  13311. : object->properties.getName (index);
  13312. }
  13313. class ValueTreePropertyValueSource : public Value::ValueSource,
  13314. public ValueTree::Listener
  13315. {
  13316. public:
  13317. ValueTreePropertyValueSource (const ValueTree& tree_,
  13318. const var::identifier& property_,
  13319. UndoManager* const undoManager_)
  13320. : tree (tree_),
  13321. property (property_),
  13322. undoManager (undoManager_)
  13323. {
  13324. tree.addListener (this);
  13325. }
  13326. ~ValueTreePropertyValueSource()
  13327. {
  13328. tree.removeListener (this);
  13329. }
  13330. const var getValue() const
  13331. {
  13332. return tree [property];
  13333. }
  13334. void setValue (const var& newValue)
  13335. {
  13336. tree.setProperty (property, newValue, undoManager);
  13337. }
  13338. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  13339. {
  13340. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  13341. sendChangeMessage (false);
  13342. }
  13343. void valueTreeChildrenChanged (ValueTree&) {}
  13344. void valueTreeParentChanged (ValueTree&) {}
  13345. private:
  13346. ValueTree tree;
  13347. const var::identifier property;
  13348. UndoManager* const undoManager;
  13349. ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  13350. };
  13351. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  13352. {
  13353. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  13354. }
  13355. int ValueTree::getNumChildren() const
  13356. {
  13357. return object == 0 ? 0 : object->children.size();
  13358. }
  13359. ValueTree ValueTree::getChild (int index) const
  13360. {
  13361. return object != 0 ? (SharedObject*) object->children [index] : ValueTree ((SharedObject*) 0);
  13362. }
  13363. ValueTree ValueTree::getChildWithName (const String& type) const
  13364. {
  13365. return object != 0 ? object->getChildWithName (type) : ValueTree ((SharedObject*) 0);
  13366. }
  13367. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13368. {
  13369. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree ((SharedObject*) 0);
  13370. }
  13371. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  13372. {
  13373. return object != 0 && object->isAChildOf (possibleParent.object);
  13374. }
  13375. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  13376. {
  13377. if (object != 0)
  13378. object->addChild (child.object, index, undoManager);
  13379. }
  13380. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  13381. {
  13382. if (object != 0)
  13383. object->removeChild (childIndex, undoManager);
  13384. }
  13385. void ValueTree::removeChild (ValueTree& child, UndoManager* const undoManager)
  13386. {
  13387. if (object != 0)
  13388. object->removeChild (object->children.indexOf (child.object), undoManager);
  13389. }
  13390. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  13391. {
  13392. if (object != 0)
  13393. object->removeAllChildren (undoManager);
  13394. }
  13395. void ValueTree::addListener (Listener* listener)
  13396. {
  13397. if (listener != 0)
  13398. {
  13399. if (listeners.size() == 0 && object != 0)
  13400. object->valueTreesWithListeners.add (this);
  13401. listeners.add (listener);
  13402. }
  13403. }
  13404. void ValueTree::removeListener (Listener* listener)
  13405. {
  13406. listeners.remove (listener);
  13407. if (listeners.size() == 0 && object != 0)
  13408. object->valueTreesWithListeners.removeValue (this);
  13409. }
  13410. XmlElement* ValueTree::SharedObject::createXml() const
  13411. {
  13412. XmlElement* xml = new XmlElement (type);
  13413. int i;
  13414. for (i = 0; i < properties.size(); ++i)
  13415. {
  13416. var::identifier name (properties.getName(i));
  13417. const var& v = properties [name];
  13418. jassert (! v.isObject()); // DynamicObjects can't be stored as XML!
  13419. xml->setAttribute (name.name, v.toString());
  13420. }
  13421. for (i = 0; i < children.size(); ++i)
  13422. xml->addChildElement (children.getUnchecked(i)->createXml());
  13423. return xml;
  13424. }
  13425. XmlElement* ValueTree::createXml() const
  13426. {
  13427. return object != 0 ? object->createXml() : 0;
  13428. }
  13429. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13430. {
  13431. ValueTree v (xml.getTagName());
  13432. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13433. for (int i = 0; i < numAtts; ++i)
  13434. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13435. forEachXmlChildElement (xml, e)
  13436. {
  13437. v.addChild (fromXml (*e), -1, 0);
  13438. }
  13439. return v;
  13440. }
  13441. void ValueTree::writeToStream (OutputStream& output)
  13442. {
  13443. output.writeString (getType());
  13444. const int numProps = getNumProperties();
  13445. output.writeCompressedInt (numProps);
  13446. int i;
  13447. for (i = 0; i < numProps; ++i)
  13448. {
  13449. const var::identifier name (getPropertyName(i));
  13450. output.writeString (name.name);
  13451. getProperty(name).writeToStream (output);
  13452. }
  13453. const int numChildren = getNumChildren();
  13454. output.writeCompressedInt (numChildren);
  13455. for (i = 0; i < numChildren; ++i)
  13456. getChild (i).writeToStream (output);
  13457. }
  13458. ValueTree ValueTree::readFromStream (InputStream& input)
  13459. {
  13460. String type (input.readString());
  13461. if (type.isEmpty())
  13462. return ValueTree ((SharedObject*) 0);
  13463. ValueTree v (type);
  13464. const int numProps = input.readCompressedInt();
  13465. if (numProps < 0)
  13466. {
  13467. jassertfalse // trying to read corrupted data!
  13468. return v;
  13469. }
  13470. int i;
  13471. for (i = 0; i < numProps; ++i)
  13472. {
  13473. const String name (input.readString());
  13474. jassert (name.isNotEmpty());
  13475. const var value (var::readFromStream (input));
  13476. v.setProperty (name, value, 0);
  13477. }
  13478. const int numChildren = input.readCompressedInt();
  13479. for (i = 0; i < numChildren; ++i)
  13480. v.addChild (readFromStream (input), -1, 0);
  13481. return v;
  13482. }
  13483. END_JUCE_NAMESPACE
  13484. /*** End of inlined file: juce_ValueTree.cpp ***/
  13485. /*** Start of inlined file: juce_Value.cpp ***/
  13486. BEGIN_JUCE_NAMESPACE
  13487. Value::ValueSource::ValueSource()
  13488. {
  13489. }
  13490. Value::ValueSource::~ValueSource()
  13491. {
  13492. }
  13493. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13494. {
  13495. if (synchronous)
  13496. {
  13497. for (int i = valuesWithListeners.size(); --i >= 0;)
  13498. {
  13499. Value* const v = valuesWithListeners[i];
  13500. if (v != 0)
  13501. v->callListeners();
  13502. }
  13503. }
  13504. else
  13505. {
  13506. triggerAsyncUpdate();
  13507. }
  13508. }
  13509. void Value::ValueSource::handleAsyncUpdate()
  13510. {
  13511. sendChangeMessage (true);
  13512. }
  13513. class SimpleValueSource : public Value::ValueSource
  13514. {
  13515. public:
  13516. SimpleValueSource()
  13517. {
  13518. }
  13519. SimpleValueSource (const var& initialValue)
  13520. : value (initialValue)
  13521. {
  13522. }
  13523. ~SimpleValueSource()
  13524. {
  13525. }
  13526. const var getValue() const
  13527. {
  13528. return value;
  13529. }
  13530. void setValue (const var& newValue)
  13531. {
  13532. if (newValue != value)
  13533. {
  13534. value = newValue;
  13535. sendChangeMessage (false);
  13536. }
  13537. }
  13538. private:
  13539. var value;
  13540. SimpleValueSource (const SimpleValueSource&);
  13541. SimpleValueSource& operator= (const SimpleValueSource&);
  13542. };
  13543. Value::Value()
  13544. : value (new SimpleValueSource())
  13545. {
  13546. }
  13547. Value::Value (ValueSource* const value_)
  13548. : value (value_)
  13549. {
  13550. jassert (value_ != 0);
  13551. }
  13552. Value::Value (const var& initialValue)
  13553. : value (new SimpleValueSource (initialValue))
  13554. {
  13555. }
  13556. Value::Value (const Value& other)
  13557. : value (other.value)
  13558. {
  13559. }
  13560. Value& Value::operator= (const Value& other)
  13561. {
  13562. value = other.value;
  13563. return *this;
  13564. }
  13565. Value::~Value()
  13566. {
  13567. if (listeners.size() > 0)
  13568. value->valuesWithListeners.removeValue (this);
  13569. }
  13570. const var Value::getValue() const
  13571. {
  13572. return value->getValue();
  13573. }
  13574. void Value::setValue (const var& newValue)
  13575. {
  13576. value->setValue (newValue);
  13577. }
  13578. const String Value::toString() const
  13579. {
  13580. return value->getValue().toString();
  13581. }
  13582. Value& Value::operator= (const var& newValue)
  13583. {
  13584. value->setValue (newValue);
  13585. return *this;
  13586. }
  13587. void Value::referTo (const Value& valueToReferTo)
  13588. {
  13589. if (valueToReferTo.value != value)
  13590. {
  13591. if (listeners.size() > 0)
  13592. {
  13593. value->valuesWithListeners.removeValue (this);
  13594. valueToReferTo.value->valuesWithListeners.add (this);
  13595. }
  13596. value = valueToReferTo.value;
  13597. callListeners();
  13598. }
  13599. }
  13600. bool Value::refersToSameSourceAs (const Value& other) const
  13601. {
  13602. return value == other.value;
  13603. }
  13604. bool Value::operator== (const Value& other) const
  13605. {
  13606. return value == other.value || value->getValue() == other.getValue();
  13607. }
  13608. bool Value::operator!= (const Value& other) const
  13609. {
  13610. return value != other.value && value->getValue() != other.getValue();
  13611. }
  13612. void Value::addListener (Listener* const listener)
  13613. {
  13614. if (listener != 0)
  13615. {
  13616. if (listeners.size() == 0)
  13617. value->valuesWithListeners.add (this);
  13618. listeners.add (listener);
  13619. }
  13620. }
  13621. void Value::removeListener (Listener* const listener)
  13622. {
  13623. listeners.remove (listener);
  13624. if (listeners.size() == 0)
  13625. value->valuesWithListeners.removeValue (this);
  13626. }
  13627. void Value::callListeners()
  13628. {
  13629. Value v (*this); // (create a copy in case this gets deleted by a callback)
  13630. listeners.call (&Listener::valueChanged, v);
  13631. }
  13632. END_JUCE_NAMESPACE
  13633. /*** End of inlined file: juce_Value.cpp ***/
  13634. /*** Start of inlined file: juce_Application.cpp ***/
  13635. #if JUCE_MSVC
  13636. #pragma warning (push)
  13637. #pragma warning (disable: 4245 4514 4100)
  13638. #include <crtdbg.h>
  13639. #pragma warning (pop)
  13640. #endif
  13641. BEGIN_JUCE_NAMESPACE
  13642. void juce_setCurrentThreadName (const String& name);
  13643. static JUCEApplication* appInstance = 0;
  13644. JUCEApplication::JUCEApplication()
  13645. : appReturnValue (0),
  13646. stillInitialising (true)
  13647. {
  13648. }
  13649. JUCEApplication::~JUCEApplication()
  13650. {
  13651. if (appLock != 0)
  13652. {
  13653. appLock->exit();
  13654. appLock = 0;
  13655. }
  13656. }
  13657. JUCEApplication* JUCEApplication::getInstance() throw()
  13658. {
  13659. return appInstance;
  13660. }
  13661. bool JUCEApplication::isInitialising() const throw()
  13662. {
  13663. return stillInitialising;
  13664. }
  13665. const String JUCEApplication::getApplicationVersion()
  13666. {
  13667. return String::empty;
  13668. }
  13669. bool JUCEApplication::moreThanOneInstanceAllowed()
  13670. {
  13671. return true;
  13672. }
  13673. void JUCEApplication::anotherInstanceStarted (const String&)
  13674. {
  13675. }
  13676. void JUCEApplication::systemRequestedQuit()
  13677. {
  13678. quit();
  13679. }
  13680. void JUCEApplication::quit()
  13681. {
  13682. MessageManager::getInstance()->stopDispatchLoop();
  13683. }
  13684. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13685. {
  13686. appReturnValue = newReturnValue;
  13687. }
  13688. void JUCEApplication::unhandledException (const std::exception*,
  13689. const String&,
  13690. const int)
  13691. {
  13692. jassertfalse
  13693. }
  13694. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13695. const char* const sourceFile,
  13696. const int lineNumber)
  13697. {
  13698. if (appInstance != 0)
  13699. appInstance->unhandledException (e, sourceFile, lineNumber);
  13700. }
  13701. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13702. {
  13703. return 0;
  13704. }
  13705. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13706. {
  13707. commands.add (StandardApplicationCommandIDs::quit);
  13708. }
  13709. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13710. {
  13711. if (commandID == StandardApplicationCommandIDs::quit)
  13712. {
  13713. result.setInfo (TRANS("Quit"),
  13714. TRANS("Quits the application"),
  13715. "Application",
  13716. 0);
  13717. result.defaultKeypresses.add (KeyPress (T('q'), ModifierKeys::commandModifier, 0));
  13718. }
  13719. }
  13720. bool JUCEApplication::perform (const InvocationInfo& info)
  13721. {
  13722. if (info.commandID == StandardApplicationCommandIDs::quit)
  13723. {
  13724. systemRequestedQuit();
  13725. return true;
  13726. }
  13727. return false;
  13728. }
  13729. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13730. {
  13731. if (! app->initialiseApp (commandLine))
  13732. return 0;
  13733. // now loop until a quit message is received..
  13734. JUCE_TRY
  13735. {
  13736. MessageManager::getInstance()->runDispatchLoop();
  13737. }
  13738. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13739. catch (const std::exception& e)
  13740. {
  13741. app->unhandledException (&e, __FILE__, __LINE__);
  13742. }
  13743. catch (...)
  13744. {
  13745. app->unhandledException (0, __FILE__, __LINE__);
  13746. }
  13747. #endif
  13748. return shutdownAppAndClearUp();
  13749. }
  13750. bool JUCEApplication::initialiseApp (String& commandLine)
  13751. {
  13752. jassert (appInstance == 0);
  13753. appInstance = this;
  13754. commandLineParameters = commandLine.trim();
  13755. commandLine = String::empty;
  13756. initialiseJuce_GUI();
  13757. #if ! JUCE_IPHONE
  13758. jassert (appLock == 0); // initialiseApp must only be called once!
  13759. if (! moreThanOneInstanceAllowed())
  13760. {
  13761. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13762. if (! appLock->enter(0))
  13763. {
  13764. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13765. delete appInstance;
  13766. appInstance = 0;
  13767. DBG ("Another instance is running - quitting...");
  13768. return false;
  13769. }
  13770. }
  13771. #endif
  13772. // let the app do its setting-up..
  13773. initialise (commandLineParameters);
  13774. // register for broadcast new app messages
  13775. MessageManager::getInstance()->registerBroadcastListener (this);
  13776. stillInitialising = false;
  13777. return true;
  13778. }
  13779. int JUCEApplication::shutdownAppAndClearUp()
  13780. {
  13781. jassert (appInstance != 0);
  13782. ScopedPointer<JUCEApplication> app (appInstance);
  13783. int returnValue = 0;
  13784. MessageManager::getInstance()->deregisterBroadcastListener ((JUCEApplication*) app);
  13785. static bool reentrancyCheck = false;
  13786. if (! reentrancyCheck)
  13787. {
  13788. reentrancyCheck = true;
  13789. JUCE_TRY
  13790. {
  13791. // give the app a chance to clean up..
  13792. app->shutdown();
  13793. }
  13794. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13795. catch (const std::exception& e)
  13796. {
  13797. app->unhandledException (&e, __FILE__, __LINE__);
  13798. }
  13799. catch (...)
  13800. {
  13801. app->unhandledException (0, __FILE__, __LINE__);
  13802. }
  13803. #endif
  13804. JUCE_TRY
  13805. {
  13806. shutdownJuce_GUI();
  13807. returnValue = app->getApplicationReturnValue();
  13808. appInstance = 0;
  13809. app = 0;
  13810. }
  13811. JUCE_CATCH_ALL_ASSERT
  13812. reentrancyCheck = false;
  13813. }
  13814. return returnValue;
  13815. }
  13816. #if JUCE_IPHONE
  13817. extern int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app);
  13818. #endif
  13819. #if ! JUCE_WINDOWS
  13820. extern const char* juce_Argv0;
  13821. #endif
  13822. int JUCEApplication::main (int argc, const char* argv[], JUCEApplication* const newApp)
  13823. {
  13824. #if ! JUCE_WINDOWS
  13825. juce_Argv0 = argv[0];
  13826. #endif
  13827. #if JUCE_IPHONE
  13828. const ScopedAutoReleasePool pool;
  13829. return juce_IPhoneMain (argc, argv, newApp);
  13830. #else
  13831. #if JUCE_MAC
  13832. const ScopedAutoReleasePool pool;
  13833. #endif
  13834. String cmd;
  13835. for (int i = 1; i < argc; ++i)
  13836. cmd << argv[i] << ' ';
  13837. return JUCEApplication::main (cmd, newApp);
  13838. #endif
  13839. }
  13840. void JUCEApplication::actionListenerCallback (const String& message)
  13841. {
  13842. if (message.startsWith (getApplicationName() + "/"))
  13843. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13844. }
  13845. static bool juceInitialisedGUI = false;
  13846. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13847. {
  13848. if (! juceInitialisedGUI)
  13849. {
  13850. #if JUCE_MAC || JUCE_IPHONE
  13851. const ScopedAutoReleasePool pool;
  13852. #endif
  13853. juceInitialisedGUI = true;
  13854. initialiseJuce_NonGUI();
  13855. MessageManager::getInstance();
  13856. LookAndFeel::setDefaultLookAndFeel (0);
  13857. juce_setCurrentThreadName ("Juce Message Thread");
  13858. #if JUCE_WINDOWS && JUCE_DEBUG
  13859. // This section is just for catching people who mess up their project settings and
  13860. // turn RTTI off..
  13861. try
  13862. {
  13863. TextButton tb (String::empty);
  13864. Component* c = &tb;
  13865. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13866. c = dynamic_cast <Button*> (c);
  13867. }
  13868. catch (...)
  13869. {
  13870. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13871. // got as far as this catch statement, then why haven't you got exception catching
  13872. // turned on in the debugger???
  13873. jassertfalse
  13874. }
  13875. #endif
  13876. }
  13877. }
  13878. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13879. {
  13880. if (juceInitialisedGUI)
  13881. {
  13882. #if JUCE_MAC
  13883. const ScopedAutoReleasePool pool;
  13884. #endif
  13885. {
  13886. DeletedAtShutdown::deleteAll();
  13887. LookAndFeel::clearDefaultLookAndFeel();
  13888. }
  13889. delete MessageManager::getInstance();
  13890. shutdownJuce_NonGUI();
  13891. juceInitialisedGUI = false;
  13892. }
  13893. }
  13894. END_JUCE_NAMESPACE
  13895. /*** End of inlined file: juce_Application.cpp ***/
  13896. /*** Start of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13897. BEGIN_JUCE_NAMESPACE
  13898. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13899. : commandID (commandID_),
  13900. flags (0)
  13901. {
  13902. }
  13903. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13904. const String& description_,
  13905. const String& categoryName_,
  13906. const int flags_) throw()
  13907. {
  13908. shortName = shortName_;
  13909. description = description_;
  13910. categoryName = categoryName_;
  13911. flags = flags_;
  13912. }
  13913. void ApplicationCommandInfo::setActive (const bool b) throw()
  13914. {
  13915. if (b)
  13916. flags &= ~isDisabled;
  13917. else
  13918. flags |= isDisabled;
  13919. }
  13920. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13921. {
  13922. if (b)
  13923. flags |= isTicked;
  13924. else
  13925. flags &= ~isTicked;
  13926. }
  13927. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  13928. {
  13929. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  13930. }
  13931. END_JUCE_NAMESPACE
  13932. /*** End of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13933. /*** Start of inlined file: juce_ApplicationCommandManager.cpp ***/
  13934. BEGIN_JUCE_NAMESPACE
  13935. ApplicationCommandManager::ApplicationCommandManager()
  13936. : firstTarget (0)
  13937. {
  13938. keyMappings = new KeyPressMappingSet (this);
  13939. Desktop::getInstance().addFocusChangeListener (this);
  13940. }
  13941. ApplicationCommandManager::~ApplicationCommandManager()
  13942. {
  13943. Desktop::getInstance().removeFocusChangeListener (this);
  13944. keyMappings = 0;
  13945. }
  13946. void ApplicationCommandManager::clearCommands()
  13947. {
  13948. commands.clear();
  13949. keyMappings->clearAllKeyPresses();
  13950. triggerAsyncUpdate();
  13951. }
  13952. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  13953. {
  13954. // zero isn't a valid command ID!
  13955. jassert (newCommand.commandID != 0);
  13956. // the name isn't optional!
  13957. jassert (newCommand.shortName.isNotEmpty());
  13958. if (getCommandForID (newCommand.commandID) == 0)
  13959. {
  13960. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  13961. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  13962. commands.add (newInfo);
  13963. keyMappings->resetToDefaultMapping (newCommand.commandID);
  13964. triggerAsyncUpdate();
  13965. }
  13966. else
  13967. {
  13968. // trying to re-register the same command with different parameters?
  13969. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  13970. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  13971. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  13972. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  13973. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  13974. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  13975. }
  13976. }
  13977. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  13978. {
  13979. if (target != 0)
  13980. {
  13981. Array <CommandID> commandIDs;
  13982. target->getAllCommands (commandIDs);
  13983. for (int i = 0; i < commandIDs.size(); ++i)
  13984. {
  13985. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  13986. target->getCommandInfo (info.commandID, info);
  13987. registerCommand (info);
  13988. }
  13989. }
  13990. }
  13991. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  13992. {
  13993. for (int i = commands.size(); --i >= 0;)
  13994. {
  13995. if (commands.getUnchecked (i)->commandID == commandID)
  13996. {
  13997. commands.remove (i);
  13998. triggerAsyncUpdate();
  13999. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  14000. for (int j = keys.size(); --j >= 0;)
  14001. keyMappings->removeKeyPress (keys.getReference (j));
  14002. }
  14003. }
  14004. }
  14005. void ApplicationCommandManager::commandStatusChanged()
  14006. {
  14007. triggerAsyncUpdate();
  14008. }
  14009. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  14010. {
  14011. for (int i = commands.size(); --i >= 0;)
  14012. if (commands.getUnchecked(i)->commandID == commandID)
  14013. return commands.getUnchecked(i);
  14014. return 0;
  14015. }
  14016. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  14017. {
  14018. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  14019. return (ci != 0) ? ci->shortName : String::empty;
  14020. }
  14021. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  14022. {
  14023. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  14024. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  14025. : String::empty;
  14026. }
  14027. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  14028. {
  14029. StringArray s;
  14030. for (int i = 0; i < commands.size(); ++i)
  14031. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  14032. return s;
  14033. }
  14034. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  14035. {
  14036. Array <CommandID> results;
  14037. for (int i = 0; i < commands.size(); ++i)
  14038. if (commands.getUnchecked(i)->categoryName == categoryName)
  14039. results.add (commands.getUnchecked(i)->commandID);
  14040. return results;
  14041. }
  14042. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14043. {
  14044. ApplicationCommandTarget::InvocationInfo info (commandID);
  14045. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14046. return invoke (info, asynchronously);
  14047. }
  14048. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  14049. {
  14050. // This call isn't thread-safe for use from a non-UI thread without locking the message
  14051. // manager first..
  14052. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  14053. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  14054. if (target == 0)
  14055. return false;
  14056. ApplicationCommandInfo commandInfo (0);
  14057. target->getCommandInfo (info_.commandID, commandInfo);
  14058. ApplicationCommandTarget::InvocationInfo info (info_);
  14059. info.commandFlags = commandInfo.flags;
  14060. sendListenerInvokeCallback (info);
  14061. const bool ok = target->invoke (info, asynchronously);
  14062. commandStatusChanged();
  14063. return ok;
  14064. }
  14065. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  14066. {
  14067. return firstTarget != 0 ? firstTarget
  14068. : findDefaultComponentTarget();
  14069. }
  14070. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  14071. {
  14072. firstTarget = newTarget;
  14073. }
  14074. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  14075. ApplicationCommandInfo& upToDateInfo)
  14076. {
  14077. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  14078. if (target == 0)
  14079. target = JUCEApplication::getInstance();
  14080. if (target != 0)
  14081. target = target->getTargetForCommand (commandID);
  14082. if (target != 0)
  14083. target->getCommandInfo (commandID, upToDateInfo);
  14084. return target;
  14085. }
  14086. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  14087. {
  14088. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  14089. if (target == 0 && c != 0)
  14090. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14091. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14092. return target;
  14093. }
  14094. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  14095. {
  14096. Component* c = Component::getCurrentlyFocusedComponent();
  14097. if (c == 0)
  14098. {
  14099. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  14100. if (activeWindow != 0)
  14101. {
  14102. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  14103. if (c == 0)
  14104. c = activeWindow;
  14105. }
  14106. }
  14107. if (c == 0 && Process::isForegroundProcess())
  14108. {
  14109. // getting a bit desperate now - try all desktop comps..
  14110. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  14111. {
  14112. ApplicationCommandTarget* const target
  14113. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  14114. ->getPeer()->getLastFocusedSubcomponent());
  14115. if (target != 0)
  14116. return target;
  14117. }
  14118. }
  14119. if (c != 0)
  14120. {
  14121. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  14122. // if we're focused on a ResizableWindow, chances are that it's the content
  14123. // component that really should get the event. And if not, the event will
  14124. // still be passed up to the top level window anyway, so let's send it to the
  14125. // content comp.
  14126. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  14127. c = resizableWindow->getContentComponent();
  14128. ApplicationCommandTarget* const target = findTargetForComponent (c);
  14129. if (target != 0)
  14130. return target;
  14131. }
  14132. return JUCEApplication::getInstance();
  14133. }
  14134. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  14135. {
  14136. listeners.add (listener);
  14137. }
  14138. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  14139. {
  14140. listeners.remove (listener);
  14141. }
  14142. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info)
  14143. {
  14144. listeners.call (&ApplicationCommandManagerListener::applicationCommandInvoked, info);
  14145. }
  14146. void ApplicationCommandManager::handleAsyncUpdate()
  14147. {
  14148. listeners.call (&ApplicationCommandManagerListener::applicationCommandListChanged);
  14149. }
  14150. void ApplicationCommandManager::globalFocusChanged (Component*)
  14151. {
  14152. commandStatusChanged();
  14153. }
  14154. END_JUCE_NAMESPACE
  14155. /*** End of inlined file: juce_ApplicationCommandManager.cpp ***/
  14156. /*** Start of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14157. BEGIN_JUCE_NAMESPACE
  14158. ApplicationCommandTarget::ApplicationCommandTarget()
  14159. {
  14160. }
  14161. ApplicationCommandTarget::~ApplicationCommandTarget()
  14162. {
  14163. messageInvoker = 0;
  14164. }
  14165. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  14166. {
  14167. if (isCommandActive (info.commandID))
  14168. {
  14169. if (async)
  14170. {
  14171. if (messageInvoker == 0)
  14172. messageInvoker = new CommandTargetMessageInvoker (this);
  14173. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  14174. return true;
  14175. }
  14176. else
  14177. {
  14178. const bool success = perform (info);
  14179. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  14180. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  14181. // returns the command's info.
  14182. return success;
  14183. }
  14184. }
  14185. return false;
  14186. }
  14187. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  14188. {
  14189. Component* c = dynamic_cast <Component*> (this);
  14190. if (c != 0)
  14191. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14192. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14193. return 0;
  14194. }
  14195. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  14196. {
  14197. ApplicationCommandTarget* target = this;
  14198. int depth = 0;
  14199. while (target != 0)
  14200. {
  14201. Array <CommandID> commandIDs;
  14202. target->getAllCommands (commandIDs);
  14203. if (commandIDs.contains (commandID))
  14204. return target;
  14205. target = target->getNextCommandTarget();
  14206. ++depth;
  14207. jassert (depth < 100); // could be a recursive command chain??
  14208. jassert (target != this); // definitely a recursive command chain!
  14209. if (depth > 100 || target == this)
  14210. break;
  14211. }
  14212. if (target == 0)
  14213. {
  14214. target = JUCEApplication::getInstance();
  14215. if (target != 0)
  14216. {
  14217. Array <CommandID> commandIDs;
  14218. target->getAllCommands (commandIDs);
  14219. if (commandIDs.contains (commandID))
  14220. return target;
  14221. }
  14222. }
  14223. return 0;
  14224. }
  14225. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  14226. {
  14227. ApplicationCommandInfo info (commandID);
  14228. info.flags = ApplicationCommandInfo::isDisabled;
  14229. getCommandInfo (commandID, info);
  14230. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  14231. }
  14232. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  14233. {
  14234. ApplicationCommandTarget* target = this;
  14235. int depth = 0;
  14236. while (target != 0)
  14237. {
  14238. if (target->tryToInvoke (info, async))
  14239. return true;
  14240. target = target->getNextCommandTarget();
  14241. ++depth;
  14242. jassert (depth < 100); // could be a recursive command chain??
  14243. jassert (target != this); // definitely a recursive command chain!
  14244. if (depth > 100 || target == this)
  14245. break;
  14246. }
  14247. if (target == 0)
  14248. {
  14249. target = JUCEApplication::getInstance();
  14250. if (target != 0)
  14251. return target->tryToInvoke (info, async);
  14252. }
  14253. return false;
  14254. }
  14255. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14256. {
  14257. ApplicationCommandTarget::InvocationInfo info (commandID);
  14258. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14259. return invoke (info, asynchronously);
  14260. }
  14261. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  14262. : commandID (commandID_),
  14263. commandFlags (0),
  14264. invocationMethod (direct),
  14265. originatingComponent (0),
  14266. isKeyDown (false),
  14267. millisecsSinceKeyPressed (0)
  14268. {
  14269. }
  14270. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  14271. : owner (owner_)
  14272. {
  14273. }
  14274. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  14275. {
  14276. }
  14277. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  14278. {
  14279. const ScopedPointer <InvocationInfo> info ((InvocationInfo*) message.pointerParameter);
  14280. owner->tryToInvoke (*info, false);
  14281. }
  14282. END_JUCE_NAMESPACE
  14283. /*** End of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14284. /*** Start of inlined file: juce_ApplicationProperties.cpp ***/
  14285. BEGIN_JUCE_NAMESPACE
  14286. juce_ImplementSingleton (ApplicationProperties)
  14287. ApplicationProperties::ApplicationProperties() throw()
  14288. : msBeforeSaving (3000),
  14289. options (PropertiesFile::storeAsBinary),
  14290. commonSettingsAreReadOnly (0)
  14291. {
  14292. }
  14293. ApplicationProperties::~ApplicationProperties()
  14294. {
  14295. closeFiles();
  14296. clearSingletonInstance();
  14297. }
  14298. void ApplicationProperties::setStorageParameters (const String& applicationName,
  14299. const String& fileNameSuffix,
  14300. const String& folderName_,
  14301. const int millisecondsBeforeSaving,
  14302. const int propertiesFileOptions) throw()
  14303. {
  14304. appName = applicationName;
  14305. fileSuffix = fileNameSuffix;
  14306. folderName = folderName_;
  14307. msBeforeSaving = millisecondsBeforeSaving;
  14308. options = propertiesFileOptions;
  14309. }
  14310. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  14311. const bool testCommonSettings,
  14312. const bool showWarningDialogOnFailure)
  14313. {
  14314. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  14315. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  14316. if (! (userOk && commonOk))
  14317. {
  14318. if (showWarningDialogOnFailure)
  14319. {
  14320. String filenames;
  14321. if (userProps != 0 && ! userOk)
  14322. filenames << '\n' << userProps->getFile().getFullPathName();
  14323. if (commonProps != 0 && ! commonOk)
  14324. filenames << '\n' << commonProps->getFile().getFullPathName();
  14325. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14326. appName + TRANS(" - Unable to save settings"),
  14327. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  14328. + appName + TRANS(" needs to be able to write to the following files:\n")
  14329. + filenames
  14330. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  14331. }
  14332. return false;
  14333. }
  14334. return true;
  14335. }
  14336. void ApplicationProperties::openFiles() throw()
  14337. {
  14338. // You need to call setStorageParameters() before trying to get hold of the
  14339. // properties!
  14340. jassert (appName.isNotEmpty());
  14341. if (appName.isNotEmpty())
  14342. {
  14343. if (userProps == 0)
  14344. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14345. false, msBeforeSaving, options);
  14346. if (commonProps == 0)
  14347. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14348. true, msBeforeSaving, options);
  14349. userProps->setFallbackPropertySet (commonProps);
  14350. }
  14351. }
  14352. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  14353. {
  14354. if (userProps == 0)
  14355. openFiles();
  14356. return userProps;
  14357. }
  14358. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  14359. {
  14360. if (commonProps == 0)
  14361. openFiles();
  14362. if (returnUserPropsIfReadOnly)
  14363. {
  14364. if (commonSettingsAreReadOnly == 0)
  14365. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  14366. if (commonSettingsAreReadOnly > 0)
  14367. return userProps;
  14368. }
  14369. return commonProps;
  14370. }
  14371. bool ApplicationProperties::saveIfNeeded()
  14372. {
  14373. return (userProps == 0 || userProps->saveIfNeeded())
  14374. && (commonProps == 0 || commonProps->saveIfNeeded());
  14375. }
  14376. void ApplicationProperties::closeFiles()
  14377. {
  14378. userProps = 0;
  14379. commonProps = 0;
  14380. }
  14381. END_JUCE_NAMESPACE
  14382. /*** End of inlined file: juce_ApplicationProperties.cpp ***/
  14383. /*** Start of inlined file: juce_DeletedAtShutdown.cpp ***/
  14384. BEGIN_JUCE_NAMESPACE
  14385. static VoidArray objectsToDelete;
  14386. static CriticalSection lock;
  14387. DeletedAtShutdown::DeletedAtShutdown()
  14388. {
  14389. const ScopedLock sl (lock);
  14390. objectsToDelete.add (this);
  14391. }
  14392. DeletedAtShutdown::~DeletedAtShutdown()
  14393. {
  14394. const ScopedLock sl (lock);
  14395. objectsToDelete.removeValue (this);
  14396. }
  14397. void DeletedAtShutdown::deleteAll()
  14398. {
  14399. // make a local copy of the array, so it can't get into a loop if something
  14400. // creates another DeletedAtShutdown object during its destructor.
  14401. VoidArray localCopy;
  14402. {
  14403. const ScopedLock sl (lock);
  14404. localCopy = objectsToDelete;
  14405. }
  14406. for (int i = localCopy.size(); --i >= 0;)
  14407. {
  14408. JUCE_TRY
  14409. {
  14410. DeletedAtShutdown* deletee = (DeletedAtShutdown*) localCopy.getUnchecked(i);
  14411. // double-check that it's not already been deleted during another object's destructor.
  14412. {
  14413. const ScopedLock sl (lock);
  14414. if (! objectsToDelete.contains (deletee))
  14415. deletee = 0;
  14416. }
  14417. delete deletee;
  14418. }
  14419. JUCE_CATCH_EXCEPTION
  14420. }
  14421. // if no objects got re-created during shutdown, this should have been emptied by their
  14422. // destructors
  14423. jassert (objectsToDelete.size() == 0);
  14424. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14425. }
  14426. END_JUCE_NAMESPACE
  14427. /*** End of inlined file: juce_DeletedAtShutdown.cpp ***/
  14428. /*** Start of inlined file: juce_PropertiesFile.cpp ***/
  14429. BEGIN_JUCE_NAMESPACE
  14430. static const int propFileMagicNumber = ((int) ByteOrder::littleEndianInt ("PROP"));
  14431. static const int propFileMagicNumberCompressed = ((int) ByteOrder::littleEndianInt ("CPRP"));
  14432. static const tchar* const propertyFileXmlTag = T("PROPERTIES");
  14433. static const tchar* const propertyTagName = T("VALUE");
  14434. PropertiesFile::PropertiesFile (const File& f,
  14435. const int millisecondsBeforeSaving,
  14436. const int options_)
  14437. : PropertySet (ignoreCaseOfKeyNames),
  14438. file (f),
  14439. timerInterval (millisecondsBeforeSaving),
  14440. options (options_),
  14441. needsWriting (false)
  14442. {
  14443. // You need to correctly specify just one storage format for the file
  14444. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14445. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14446. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14447. ScopedPointer <InputStream> fileStream (f.createInputStream());
  14448. if (fileStream != 0)
  14449. {
  14450. int magicNumber = fileStream->readInt();
  14451. if (magicNumber == propFileMagicNumberCompressed)
  14452. {
  14453. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true),
  14454. true);
  14455. magicNumber = propFileMagicNumber;
  14456. }
  14457. if (magicNumber == propFileMagicNumber)
  14458. {
  14459. BufferedInputStream in (fileStream.release(), 2048, true);
  14460. int numValues = in.readInt();
  14461. while (--numValues >= 0 && ! in.isExhausted())
  14462. {
  14463. const String key (in.readString());
  14464. const String value (in.readString());
  14465. jassert (key.isNotEmpty());
  14466. if (key.isNotEmpty())
  14467. getAllProperties().set (key, value);
  14468. }
  14469. }
  14470. else
  14471. {
  14472. // Not a binary props file - let's see if it's XML..
  14473. fileStream = 0;
  14474. XmlDocument parser (f);
  14475. ScopedPointer <XmlElement> doc (parser.getDocumentElement (true));
  14476. if (doc != 0 && doc->hasTagName (propertyFileXmlTag))
  14477. {
  14478. doc = parser.getDocumentElement();
  14479. if (doc != 0)
  14480. {
  14481. forEachXmlChildElementWithTagName (*doc, e, propertyTagName)
  14482. {
  14483. const String name (e->getStringAttribute (T("name")));
  14484. if (name.isNotEmpty())
  14485. {
  14486. getAllProperties().set (name,
  14487. e->getFirstChildElement() != 0
  14488. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14489. : e->getStringAttribute (T("val")));
  14490. }
  14491. }
  14492. }
  14493. else
  14494. {
  14495. // must be a pretty broken XML file we're trying to parse here!
  14496. jassertfalse
  14497. }
  14498. }
  14499. }
  14500. }
  14501. }
  14502. PropertiesFile::~PropertiesFile()
  14503. {
  14504. saveIfNeeded();
  14505. }
  14506. bool PropertiesFile::saveIfNeeded()
  14507. {
  14508. const ScopedLock sl (getLock());
  14509. return (! needsWriting) || save();
  14510. }
  14511. bool PropertiesFile::needsToBeSaved() const
  14512. {
  14513. const ScopedLock sl (getLock());
  14514. return needsWriting;
  14515. }
  14516. bool PropertiesFile::save()
  14517. {
  14518. const ScopedLock sl (getLock());
  14519. stopTimer();
  14520. if (file == File::nonexistent
  14521. || file.isDirectory()
  14522. || ! file.getParentDirectory().createDirectory())
  14523. return false;
  14524. if ((options & storeAsXML) != 0)
  14525. {
  14526. XmlElement doc (propertyFileXmlTag);
  14527. for (int i = 0; i < getAllProperties().size(); ++i)
  14528. {
  14529. XmlElement* const e = doc.createNewChildElement (propertyTagName);
  14530. e->setAttribute (T("name"), getAllProperties().getAllKeys() [i]);
  14531. // if the value seems to contain xml, store it as such..
  14532. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14533. XmlElement* const childElement = xmlContent.getDocumentElement();
  14534. if (childElement != 0)
  14535. e->addChildElement (childElement);
  14536. else
  14537. e->setAttribute (T("val"), getAllProperties().getAllValues() [i]);
  14538. }
  14539. return doc.writeToFile (file, String::empty);
  14540. }
  14541. else
  14542. {
  14543. TemporaryFile tempFile (file);
  14544. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14545. if (out != 0)
  14546. {
  14547. if ((options & storeAsCompressedBinary) != 0)
  14548. {
  14549. out->writeInt (propFileMagicNumberCompressed);
  14550. out->flush();
  14551. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14552. }
  14553. else
  14554. {
  14555. // have you set up the storage option flags correctly?
  14556. jassert ((options & storeAsBinary) != 0);
  14557. out->writeInt (propFileMagicNumber);
  14558. }
  14559. const int numProperties = getAllProperties().size();
  14560. out->writeInt (numProperties);
  14561. for (int i = 0; i < numProperties; ++i)
  14562. {
  14563. out->writeString (getAllProperties().getAllKeys() [i]);
  14564. out->writeString (getAllProperties().getAllValues() [i]);
  14565. }
  14566. out = 0;
  14567. if (tempFile.overwriteTargetFileWithTemporary())
  14568. {
  14569. needsWriting = false;
  14570. return true;
  14571. }
  14572. }
  14573. }
  14574. return false;
  14575. }
  14576. void PropertiesFile::timerCallback()
  14577. {
  14578. saveIfNeeded();
  14579. }
  14580. void PropertiesFile::propertyChanged()
  14581. {
  14582. sendChangeMessage (this);
  14583. needsWriting = true;
  14584. if (timerInterval > 0)
  14585. startTimer (timerInterval);
  14586. else if (timerInterval == 0)
  14587. saveIfNeeded();
  14588. }
  14589. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14590. const String& fileNameSuffix,
  14591. const String& folderName,
  14592. const bool commonToAllUsers)
  14593. {
  14594. // mustn't have illegal characters in this name..
  14595. jassert (applicationName == File::createLegalFileName (applicationName));
  14596. #if JUCE_MAC || JUCE_IPHONE
  14597. File dir (commonToAllUsers ? "/Library/Preferences"
  14598. : "~/Library/Preferences");
  14599. if (folderName.isNotEmpty())
  14600. dir = dir.getChildFile (folderName);
  14601. #endif
  14602. #ifdef JUCE_LINUX
  14603. const File dir ((commonToAllUsers ? T("/var/") : T("~/"))
  14604. + (folderName.isNotEmpty() ? folderName
  14605. : (T(".") + applicationName)));
  14606. #endif
  14607. #if JUCE_WIN32
  14608. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14609. : File::userApplicationDataDirectory));
  14610. if (dir == File::nonexistent)
  14611. return File::nonexistent;
  14612. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14613. : applicationName);
  14614. #endif
  14615. return dir.getChildFile (applicationName)
  14616. .withFileExtension (fileNameSuffix);
  14617. }
  14618. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14619. const String& fileNameSuffix,
  14620. const String& folderName,
  14621. const bool commonToAllUsers,
  14622. const int millisecondsBeforeSaving,
  14623. const int propertiesFileOptions)
  14624. {
  14625. const File file (getDefaultAppSettingsFile (applicationName,
  14626. fileNameSuffix,
  14627. folderName,
  14628. commonToAllUsers));
  14629. jassert (file != File::nonexistent);
  14630. if (file == File::nonexistent)
  14631. return 0;
  14632. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions);
  14633. }
  14634. END_JUCE_NAMESPACE
  14635. /*** End of inlined file: juce_PropertiesFile.cpp ***/
  14636. /*** Start of inlined file: juce_FileBasedDocument.cpp ***/
  14637. BEGIN_JUCE_NAMESPACE
  14638. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14639. const String& fileWildcard_,
  14640. const String& openFileDialogTitle_,
  14641. const String& saveFileDialogTitle_)
  14642. : changedSinceSave (false),
  14643. fileExtension (fileExtension_),
  14644. fileWildcard (fileWildcard_),
  14645. openFileDialogTitle (openFileDialogTitle_),
  14646. saveFileDialogTitle (saveFileDialogTitle_)
  14647. {
  14648. }
  14649. FileBasedDocument::~FileBasedDocument()
  14650. {
  14651. }
  14652. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14653. {
  14654. changedSinceSave = hasChanged;
  14655. }
  14656. void FileBasedDocument::changed()
  14657. {
  14658. changedSinceSave = true;
  14659. sendChangeMessage (this);
  14660. }
  14661. void FileBasedDocument::setFile (const File& newFile)
  14662. {
  14663. if (documentFile != newFile)
  14664. {
  14665. documentFile = newFile;
  14666. changedSinceSave = true;
  14667. }
  14668. }
  14669. bool FileBasedDocument::loadFrom (const File& newFile,
  14670. const bool showMessageOnFailure)
  14671. {
  14672. MouseCursor::showWaitCursor();
  14673. const File oldFile (documentFile);
  14674. documentFile = newFile;
  14675. String error;
  14676. if (newFile.existsAsFile())
  14677. {
  14678. error = loadDocument (newFile);
  14679. if (error.isEmpty())
  14680. {
  14681. setChangedFlag (false);
  14682. MouseCursor::hideWaitCursor();
  14683. setLastDocumentOpened (newFile);
  14684. return true;
  14685. }
  14686. }
  14687. else
  14688. {
  14689. error = "The file doesn't exist";
  14690. }
  14691. documentFile = oldFile;
  14692. MouseCursor::hideWaitCursor();
  14693. if (showMessageOnFailure)
  14694. {
  14695. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14696. TRANS("Failed to open file..."),
  14697. TRANS("There was an error while trying to load the file:\n\n")
  14698. + newFile.getFullPathName()
  14699. + T("\n\n")
  14700. + error);
  14701. }
  14702. return false;
  14703. }
  14704. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14705. {
  14706. FileChooser fc (openFileDialogTitle,
  14707. getLastDocumentOpened(),
  14708. fileWildcard);
  14709. if (fc.browseForFileToOpen())
  14710. return loadFrom (fc.getResult(), showMessageOnFailure);
  14711. return false;
  14712. }
  14713. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14714. const bool showMessageOnFailure)
  14715. {
  14716. return saveAs (documentFile,
  14717. false,
  14718. askUserForFileIfNotSpecified,
  14719. showMessageOnFailure);
  14720. }
  14721. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14722. const bool warnAboutOverwritingExistingFiles,
  14723. const bool askUserForFileIfNotSpecified,
  14724. const bool showMessageOnFailure)
  14725. {
  14726. if (newFile == File::nonexistent)
  14727. {
  14728. if (askUserForFileIfNotSpecified)
  14729. {
  14730. return saveAsInteractive (true);
  14731. }
  14732. else
  14733. {
  14734. // can't save to an unspecified file
  14735. jassertfalse
  14736. return failedToWriteToFile;
  14737. }
  14738. }
  14739. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14740. {
  14741. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14742. TRANS("File already exists"),
  14743. TRANS("There's already a file called:\n\n")
  14744. + newFile.getFullPathName()
  14745. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14746. TRANS("overwrite"),
  14747. TRANS("cancel")))
  14748. {
  14749. return userCancelledSave;
  14750. }
  14751. }
  14752. MouseCursor::showWaitCursor();
  14753. const File oldFile (documentFile);
  14754. documentFile = newFile;
  14755. String error (saveDocument (newFile));
  14756. if (error.isEmpty())
  14757. {
  14758. setChangedFlag (false);
  14759. MouseCursor::hideWaitCursor();
  14760. return savedOk;
  14761. }
  14762. documentFile = oldFile;
  14763. MouseCursor::hideWaitCursor();
  14764. if (showMessageOnFailure)
  14765. {
  14766. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14767. TRANS("Error writing to file..."),
  14768. TRANS("An error occurred while trying to save \"")
  14769. + getDocumentTitle()
  14770. + TRANS("\" to the file:\n\n")
  14771. + newFile.getFullPathName()
  14772. + T("\n\n")
  14773. + error);
  14774. }
  14775. return failedToWriteToFile;
  14776. }
  14777. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14778. {
  14779. if (! hasChangedSinceSaved())
  14780. return savedOk;
  14781. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14782. TRANS("Closing document..."),
  14783. TRANS("Do you want to save the changes to \"")
  14784. + getDocumentTitle() + T("\"?"),
  14785. TRANS("save"),
  14786. TRANS("discard changes"),
  14787. TRANS("cancel"));
  14788. if (r == 1)
  14789. {
  14790. // save changes
  14791. return save (true, true);
  14792. }
  14793. else if (r == 2)
  14794. {
  14795. // discard changes
  14796. return savedOk;
  14797. }
  14798. return userCancelledSave;
  14799. }
  14800. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14801. {
  14802. File f;
  14803. if (documentFile.existsAsFile())
  14804. f = documentFile;
  14805. else
  14806. f = getLastDocumentOpened();
  14807. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14808. if (legalFilename.isEmpty())
  14809. legalFilename = "unnamed";
  14810. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14811. f = f.getSiblingFile (legalFilename);
  14812. else
  14813. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14814. f = f.withFileExtension (fileExtension)
  14815. .getNonexistentSibling (true);
  14816. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14817. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14818. {
  14819. setLastDocumentOpened (fc.getResult());
  14820. File chosen (fc.getResult());
  14821. if (chosen.getFileExtension().isEmpty())
  14822. {
  14823. chosen = chosen.withFileExtension (fileExtension);
  14824. if (chosen.exists())
  14825. {
  14826. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14827. TRANS("File already exists"),
  14828. TRANS("There's already a file called:\n\n")
  14829. + chosen.getFullPathName()
  14830. + T("\n\nAre you sure you want to overwrite it?"),
  14831. TRANS("overwrite"),
  14832. TRANS("cancel")))
  14833. {
  14834. return userCancelledSave;
  14835. }
  14836. }
  14837. }
  14838. return saveAs (chosen, false, false, true);
  14839. }
  14840. return userCancelledSave;
  14841. }
  14842. END_JUCE_NAMESPACE
  14843. /*** End of inlined file: juce_FileBasedDocument.cpp ***/
  14844. /*** Start of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14845. BEGIN_JUCE_NAMESPACE
  14846. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14847. : maxNumberOfItems (10)
  14848. {
  14849. }
  14850. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14851. {
  14852. }
  14853. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14854. {
  14855. maxNumberOfItems = jmax (1, newMaxNumber);
  14856. while (getNumFiles() > maxNumberOfItems)
  14857. files.remove (getNumFiles() - 1);
  14858. }
  14859. int RecentlyOpenedFilesList::getNumFiles() const
  14860. {
  14861. return files.size();
  14862. }
  14863. const File RecentlyOpenedFilesList::getFile (const int index) const
  14864. {
  14865. return File (files [index]);
  14866. }
  14867. void RecentlyOpenedFilesList::clear()
  14868. {
  14869. files.clear();
  14870. }
  14871. void RecentlyOpenedFilesList::addFile (const File& file)
  14872. {
  14873. const String path (file.getFullPathName());
  14874. files.removeString (path, true);
  14875. files.insert (0, path);
  14876. setMaxNumberOfItems (maxNumberOfItems);
  14877. }
  14878. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14879. {
  14880. for (int i = getNumFiles(); --i >= 0;)
  14881. if (! getFile(i).exists())
  14882. files.remove (i);
  14883. }
  14884. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14885. const int baseItemId,
  14886. const bool showFullPaths,
  14887. const bool dontAddNonExistentFiles,
  14888. const File** filesToAvoid)
  14889. {
  14890. int num = 0;
  14891. for (int i = 0; i < getNumFiles(); ++i)
  14892. {
  14893. const File f (getFile(i));
  14894. if ((! dontAddNonExistentFiles) || f.exists())
  14895. {
  14896. bool needsAvoiding = false;
  14897. if (filesToAvoid != 0)
  14898. {
  14899. const File** avoid = filesToAvoid;
  14900. while (*avoid != 0)
  14901. {
  14902. if (f == **avoid)
  14903. {
  14904. needsAvoiding = true;
  14905. break;
  14906. }
  14907. ++avoid;
  14908. }
  14909. }
  14910. if (! needsAvoiding)
  14911. {
  14912. menuToAddTo.addItem (baseItemId + i,
  14913. showFullPaths ? f.getFullPathName()
  14914. : f.getFileName());
  14915. ++num;
  14916. }
  14917. }
  14918. }
  14919. return num;
  14920. }
  14921. const String RecentlyOpenedFilesList::toString() const
  14922. {
  14923. return files.joinIntoString (T("\n"));
  14924. }
  14925. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  14926. {
  14927. clear();
  14928. files.addLines (stringifiedVersion);
  14929. setMaxNumberOfItems (maxNumberOfItems);
  14930. }
  14931. END_JUCE_NAMESPACE
  14932. /*** End of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14933. /*** Start of inlined file: juce_UndoManager.cpp ***/
  14934. BEGIN_JUCE_NAMESPACE
  14935. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  14936. const int minimumTransactions)
  14937. : totalUnitsStored (0),
  14938. nextIndex (0),
  14939. newTransaction (true),
  14940. reentrancyCheck (false)
  14941. {
  14942. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  14943. minimumTransactions);
  14944. }
  14945. UndoManager::~UndoManager()
  14946. {
  14947. clearUndoHistory();
  14948. }
  14949. void UndoManager::clearUndoHistory()
  14950. {
  14951. transactions.clear();
  14952. transactionNames.clear();
  14953. totalUnitsStored = 0;
  14954. nextIndex = 0;
  14955. sendChangeMessage (this);
  14956. }
  14957. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  14958. {
  14959. return totalUnitsStored;
  14960. }
  14961. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  14962. const int minimumTransactions)
  14963. {
  14964. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  14965. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  14966. }
  14967. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  14968. {
  14969. if (command != 0)
  14970. {
  14971. if (actionName.isNotEmpty())
  14972. currentTransactionName = actionName;
  14973. if (reentrancyCheck)
  14974. {
  14975. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  14976. // undo() methods, or else these actions won't actually get done.
  14977. return false;
  14978. }
  14979. else
  14980. {
  14981. bool success = false;
  14982. JUCE_TRY
  14983. {
  14984. success = command->perform();
  14985. }
  14986. JUCE_CATCH_EXCEPTION
  14987. jassert (success);
  14988. if (success)
  14989. {
  14990. if (nextIndex > 0 && ! newTransaction)
  14991. {
  14992. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  14993. jassert (commandSet != 0);
  14994. if (commandSet == 0)
  14995. return false;
  14996. commandSet->add (command);
  14997. }
  14998. else
  14999. {
  15000. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  15001. commandSet->add (command);
  15002. transactions.insert (nextIndex, commandSet);
  15003. transactionNames.insert (nextIndex, currentTransactionName);
  15004. ++nextIndex;
  15005. }
  15006. totalUnitsStored += command->getSizeInUnits();
  15007. newTransaction = false;
  15008. }
  15009. while (nextIndex < transactions.size())
  15010. {
  15011. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  15012. for (int i = lastSet->size(); --i >= 0;)
  15013. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  15014. transactions.removeLast();
  15015. transactionNames.remove (transactionNames.size() - 1);
  15016. }
  15017. while (nextIndex > 0
  15018. && totalUnitsStored > maxNumUnitsToKeep
  15019. && transactions.size() > minimumTransactionsToKeep)
  15020. {
  15021. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  15022. for (int i = firstSet->size(); --i >= 0;)
  15023. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  15024. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  15025. transactions.remove (0);
  15026. transactionNames.remove (0);
  15027. --nextIndex;
  15028. }
  15029. sendChangeMessage (this);
  15030. return success;
  15031. }
  15032. }
  15033. return false;
  15034. }
  15035. void UndoManager::beginNewTransaction (const String& actionName)
  15036. {
  15037. newTransaction = true;
  15038. currentTransactionName = actionName;
  15039. }
  15040. void UndoManager::setCurrentTransactionName (const String& newName)
  15041. {
  15042. currentTransactionName = newName;
  15043. }
  15044. bool UndoManager::canUndo() const
  15045. {
  15046. return nextIndex > 0;
  15047. }
  15048. bool UndoManager::canRedo() const
  15049. {
  15050. return nextIndex < transactions.size();
  15051. }
  15052. const String UndoManager::getUndoDescription() const
  15053. {
  15054. return transactionNames [nextIndex - 1];
  15055. }
  15056. const String UndoManager::getRedoDescription() const
  15057. {
  15058. return transactionNames [nextIndex];
  15059. }
  15060. bool UndoManager::undo()
  15061. {
  15062. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15063. if (commandSet == 0)
  15064. return false;
  15065. reentrancyCheck = true;
  15066. bool failed = false;
  15067. for (int i = commandSet->size(); --i >= 0;)
  15068. {
  15069. if (! commandSet->getUnchecked(i)->undo())
  15070. {
  15071. jassertfalse
  15072. failed = true;
  15073. break;
  15074. }
  15075. }
  15076. reentrancyCheck = false;
  15077. if (failed)
  15078. {
  15079. clearUndoHistory();
  15080. }
  15081. else
  15082. {
  15083. --nextIndex;
  15084. }
  15085. beginNewTransaction();
  15086. sendChangeMessage (this);
  15087. return true;
  15088. }
  15089. bool UndoManager::redo()
  15090. {
  15091. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  15092. if (commandSet == 0)
  15093. return false;
  15094. reentrancyCheck = true;
  15095. bool failed = false;
  15096. for (int i = 0; i < commandSet->size(); ++i)
  15097. {
  15098. if (! commandSet->getUnchecked(i)->perform())
  15099. {
  15100. jassertfalse
  15101. failed = true;
  15102. break;
  15103. }
  15104. }
  15105. reentrancyCheck = false;
  15106. if (failed)
  15107. {
  15108. clearUndoHistory();
  15109. }
  15110. else
  15111. {
  15112. ++nextIndex;
  15113. }
  15114. beginNewTransaction();
  15115. sendChangeMessage (this);
  15116. return true;
  15117. }
  15118. bool UndoManager::undoCurrentTransactionOnly()
  15119. {
  15120. return newTransaction ? false
  15121. : undo();
  15122. }
  15123. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  15124. {
  15125. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15126. if (commandSet != 0 && ! newTransaction)
  15127. {
  15128. for (int i = 0; i < commandSet->size(); ++i)
  15129. actionsFound.add (commandSet->getUnchecked(i));
  15130. }
  15131. }
  15132. int UndoManager::getNumActionsInCurrentTransaction() const
  15133. {
  15134. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15135. if (commandSet != 0 && ! newTransaction)
  15136. return commandSet->size();
  15137. return 0;
  15138. }
  15139. END_JUCE_NAMESPACE
  15140. /*** End of inlined file: juce_UndoManager.cpp ***/
  15141. /*** Start of inlined file: juce_AiffAudioFormat.cpp ***/
  15142. BEGIN_JUCE_NAMESPACE
  15143. static const char* const aiffFormatName = "AIFF file";
  15144. static const tchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  15145. class AiffAudioFormatReader : public AudioFormatReader
  15146. {
  15147. public:
  15148. int bytesPerFrame;
  15149. int64 dataChunkStart;
  15150. bool littleEndian;
  15151. AiffAudioFormatReader (InputStream* in)
  15152. : AudioFormatReader (in, TRANS (aiffFormatName))
  15153. {
  15154. if (input->readInt() == chunkName ("FORM"))
  15155. {
  15156. const int len = input->readIntBigEndian();
  15157. const int64 end = input->getPosition() + len;
  15158. const int nextType = input->readInt();
  15159. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  15160. {
  15161. bool hasGotVer = false;
  15162. bool hasGotData = false;
  15163. bool hasGotType = false;
  15164. while (input->getPosition() < end)
  15165. {
  15166. const int type = input->readInt();
  15167. const uint32 length = (uint32) input->readIntBigEndian();
  15168. const int64 chunkEnd = input->getPosition() + length;
  15169. if (type == chunkName ("FVER"))
  15170. {
  15171. hasGotVer = true;
  15172. const int ver = input->readIntBigEndian();
  15173. if (ver != 0 && ver != (int)0xa2805140)
  15174. break;
  15175. }
  15176. else if (type == chunkName ("COMM"))
  15177. {
  15178. hasGotType = true;
  15179. numChannels = (unsigned int)input->readShortBigEndian();
  15180. lengthInSamples = input->readIntBigEndian();
  15181. bitsPerSample = input->readShortBigEndian();
  15182. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  15183. unsigned char sampleRateBytes[10];
  15184. input->read (sampleRateBytes, 10);
  15185. const int byte0 = sampleRateBytes[0];
  15186. if ((byte0 & 0x80) != 0
  15187. || byte0 <= 0x3F || byte0 > 0x40
  15188. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  15189. break;
  15190. unsigned int sampRate = ByteOrder::bigEndianInt ((char*) sampleRateBytes + 2);
  15191. sampRate >>= (16414 - ByteOrder::bigEndianShort ((char*) sampleRateBytes));
  15192. sampleRate = (int) sampRate;
  15193. if (length <= 18)
  15194. {
  15195. // some types don't have a chunk large enough to include a compression
  15196. // type, so assume it's just big-endian pcm
  15197. littleEndian = false;
  15198. }
  15199. else
  15200. {
  15201. const int compType = input->readInt();
  15202. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  15203. {
  15204. littleEndian = false;
  15205. }
  15206. else if (compType == chunkName ("sowt"))
  15207. {
  15208. littleEndian = true;
  15209. }
  15210. else
  15211. {
  15212. sampleRate = 0;
  15213. break;
  15214. }
  15215. }
  15216. }
  15217. else if (type == chunkName ("SSND"))
  15218. {
  15219. hasGotData = true;
  15220. const int offset = input->readIntBigEndian();
  15221. dataChunkStart = input->getPosition() + 4 + offset;
  15222. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  15223. }
  15224. else if ((hasGotVer && hasGotData && hasGotType)
  15225. || chunkEnd < input->getPosition()
  15226. || input->isExhausted())
  15227. {
  15228. break;
  15229. }
  15230. input->setPosition (chunkEnd);
  15231. }
  15232. }
  15233. }
  15234. }
  15235. ~AiffAudioFormatReader()
  15236. {
  15237. }
  15238. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15239. int64 startSampleInFile, int numSamples)
  15240. {
  15241. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  15242. if (samplesAvailable < numSamples)
  15243. {
  15244. for (int i = numDestChannels; --i >= 0;)
  15245. if (destSamples[i] != 0)
  15246. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  15247. numSamples = (int) samplesAvailable;
  15248. }
  15249. if (numSamples <= 0)
  15250. return true;
  15251. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  15252. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  15253. char tempBuffer [tempBufSize];
  15254. while (numSamples > 0)
  15255. {
  15256. int* left = destSamples[0];
  15257. if (left != 0)
  15258. left += startOffsetInDestBuffer;
  15259. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  15260. if (right != 0)
  15261. right += startOffsetInDestBuffer;
  15262. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  15263. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  15264. if (bytesRead < numThisTime * bytesPerFrame)
  15265. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  15266. if (bitsPerSample == 16)
  15267. {
  15268. if (littleEndian)
  15269. {
  15270. const short* src = (const short*) tempBuffer;
  15271. if (numChannels > 1)
  15272. {
  15273. if (left == 0)
  15274. {
  15275. for (int i = numThisTime; --i >= 0;)
  15276. {
  15277. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15278. ++src;
  15279. }
  15280. }
  15281. else if (right == 0)
  15282. {
  15283. for (int i = numThisTime; --i >= 0;)
  15284. {
  15285. ++src;
  15286. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15287. }
  15288. }
  15289. else
  15290. {
  15291. for (int i = numThisTime; --i >= 0;)
  15292. {
  15293. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15294. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15295. }
  15296. }
  15297. }
  15298. else
  15299. {
  15300. for (int i = numThisTime; --i >= 0;)
  15301. {
  15302. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15303. }
  15304. }
  15305. }
  15306. else
  15307. {
  15308. const char* src = (const char*) tempBuffer;
  15309. if (numChannels > 1)
  15310. {
  15311. if (left == 0)
  15312. {
  15313. for (int i = numThisTime; --i >= 0;)
  15314. {
  15315. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15316. src += 4;
  15317. }
  15318. }
  15319. else if (right == 0)
  15320. {
  15321. for (int i = numThisTime; --i >= 0;)
  15322. {
  15323. src += 2;
  15324. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15325. src += 2;
  15326. }
  15327. }
  15328. else
  15329. {
  15330. for (int i = numThisTime; --i >= 0;)
  15331. {
  15332. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15333. src += 2;
  15334. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15335. src += 2;
  15336. }
  15337. }
  15338. }
  15339. else
  15340. {
  15341. for (int i = numThisTime; --i >= 0;)
  15342. {
  15343. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15344. src += 2;
  15345. }
  15346. }
  15347. }
  15348. }
  15349. else if (bitsPerSample == 24)
  15350. {
  15351. const char* src = (const char*)tempBuffer;
  15352. if (littleEndian)
  15353. {
  15354. if (numChannels > 1)
  15355. {
  15356. if (left == 0)
  15357. {
  15358. for (int i = numThisTime; --i >= 0;)
  15359. {
  15360. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15361. src += 6;
  15362. }
  15363. }
  15364. else if (right == 0)
  15365. {
  15366. for (int i = numThisTime; --i >= 0;)
  15367. {
  15368. src += 3;
  15369. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15370. src += 3;
  15371. }
  15372. }
  15373. else
  15374. {
  15375. for (int i = numThisTime; --i >= 0;)
  15376. {
  15377. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15378. src += 3;
  15379. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15380. src += 3;
  15381. }
  15382. }
  15383. }
  15384. else
  15385. {
  15386. for (int i = numThisTime; --i >= 0;)
  15387. {
  15388. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15389. src += 3;
  15390. }
  15391. }
  15392. }
  15393. else
  15394. {
  15395. if (numChannels > 1)
  15396. {
  15397. if (left == 0)
  15398. {
  15399. for (int i = numThisTime; --i >= 0;)
  15400. {
  15401. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15402. src += 6;
  15403. }
  15404. }
  15405. else if (right == 0)
  15406. {
  15407. for (int i = numThisTime; --i >= 0;)
  15408. {
  15409. src += 3;
  15410. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15411. src += 3;
  15412. }
  15413. }
  15414. else
  15415. {
  15416. for (int i = numThisTime; --i >= 0;)
  15417. {
  15418. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15419. src += 3;
  15420. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15421. src += 3;
  15422. }
  15423. }
  15424. }
  15425. else
  15426. {
  15427. for (int i = numThisTime; --i >= 0;)
  15428. {
  15429. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15430. src += 3;
  15431. }
  15432. }
  15433. }
  15434. }
  15435. else if (bitsPerSample == 32)
  15436. {
  15437. const unsigned int* src = (const unsigned int*) tempBuffer;
  15438. unsigned int* l = (unsigned int*) left;
  15439. unsigned int* r = (unsigned int*) right;
  15440. if (littleEndian)
  15441. {
  15442. if (numChannels > 1)
  15443. {
  15444. if (l == 0)
  15445. {
  15446. for (int i = numThisTime; --i >= 0;)
  15447. {
  15448. ++src;
  15449. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15450. }
  15451. }
  15452. else if (r == 0)
  15453. {
  15454. for (int i = numThisTime; --i >= 0;)
  15455. {
  15456. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15457. ++src;
  15458. }
  15459. }
  15460. else
  15461. {
  15462. for (int i = numThisTime; --i >= 0;)
  15463. {
  15464. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15465. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15466. }
  15467. }
  15468. }
  15469. else
  15470. {
  15471. for (int i = numThisTime; --i >= 0;)
  15472. {
  15473. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15474. }
  15475. }
  15476. }
  15477. else
  15478. {
  15479. if (numChannels > 1)
  15480. {
  15481. if (l == 0)
  15482. {
  15483. for (int i = numThisTime; --i >= 0;)
  15484. {
  15485. ++src;
  15486. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15487. }
  15488. }
  15489. else if (r == 0)
  15490. {
  15491. for (int i = numThisTime; --i >= 0;)
  15492. {
  15493. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15494. ++src;
  15495. }
  15496. }
  15497. else
  15498. {
  15499. for (int i = numThisTime; --i >= 0;)
  15500. {
  15501. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15502. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15503. }
  15504. }
  15505. }
  15506. else
  15507. {
  15508. for (int i = numThisTime; --i >= 0;)
  15509. {
  15510. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15511. }
  15512. }
  15513. }
  15514. left = (int*) l;
  15515. right = (int*) r;
  15516. }
  15517. else if (bitsPerSample == 8)
  15518. {
  15519. const char* src = (const char*) tempBuffer;
  15520. if (numChannels > 1)
  15521. {
  15522. if (left == 0)
  15523. {
  15524. for (int i = numThisTime; --i >= 0;)
  15525. {
  15526. *right++ = ((int) *src++) << 24;
  15527. ++src;
  15528. }
  15529. }
  15530. else if (right == 0)
  15531. {
  15532. for (int i = numThisTime; --i >= 0;)
  15533. {
  15534. ++src;
  15535. *left++ = ((int) *src++) << 24;
  15536. }
  15537. }
  15538. else
  15539. {
  15540. for (int i = numThisTime; --i >= 0;)
  15541. {
  15542. *left++ = ((int) *src++) << 24;
  15543. *right++ = ((int) *src++) << 24;
  15544. }
  15545. }
  15546. }
  15547. else
  15548. {
  15549. for (int i = numThisTime; --i >= 0;)
  15550. {
  15551. *left++ = ((int) *src++) << 24;
  15552. }
  15553. }
  15554. }
  15555. startOffsetInDestBuffer += numThisTime;
  15556. numSamples -= numThisTime;
  15557. }
  15558. if (numSamples > 0)
  15559. {
  15560. for (int i = numDestChannels; --i >= 0;)
  15561. if (destSamples[i] != 0)
  15562. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15563. sizeof (int) * numSamples);
  15564. }
  15565. return true;
  15566. }
  15567. juce_UseDebuggingNewOperator
  15568. private:
  15569. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15570. AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15571. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15572. };
  15573. class AiffAudioFormatWriter : public AudioFormatWriter
  15574. {
  15575. MemoryBlock tempBlock;
  15576. uint32 lengthInSamples, bytesWritten;
  15577. int64 headerPosition;
  15578. bool writeFailed;
  15579. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15580. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15581. AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15582. void writeHeader()
  15583. {
  15584. const bool couldSeekOk = output->setPosition (headerPosition);
  15585. (void) couldSeekOk;
  15586. // if this fails, you've given it an output stream that can't seek! It needs
  15587. // to be able to seek back to write the header
  15588. jassert (couldSeekOk);
  15589. const int headerLen = 54;
  15590. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15591. audioBytes += (audioBytes & 1);
  15592. output->writeInt (chunkName ("FORM"));
  15593. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15594. output->writeInt (chunkName ("AIFF"));
  15595. output->writeInt (chunkName ("COMM"));
  15596. output->writeIntBigEndian (18);
  15597. output->writeShortBigEndian ((short) numChannels);
  15598. output->writeIntBigEndian (lengthInSamples);
  15599. output->writeShortBigEndian ((short) bitsPerSample);
  15600. uint8 sampleRateBytes[10];
  15601. zeromem (sampleRateBytes, 10);
  15602. if (sampleRate <= 1)
  15603. {
  15604. sampleRateBytes[0] = 0x3f;
  15605. sampleRateBytes[1] = 0xff;
  15606. sampleRateBytes[2] = 0x80;
  15607. }
  15608. else
  15609. {
  15610. int mask = 0x40000000;
  15611. sampleRateBytes[0] = 0x40;
  15612. if (sampleRate >= mask)
  15613. {
  15614. jassertfalse
  15615. sampleRateBytes[1] = 0x1d;
  15616. }
  15617. else
  15618. {
  15619. int n = (int) sampleRate;
  15620. int i;
  15621. for (i = 0; i <= 32 ; ++i)
  15622. {
  15623. if ((n & mask) != 0)
  15624. break;
  15625. mask >>= 1;
  15626. }
  15627. n = n << (i + 1);
  15628. sampleRateBytes[1] = (uint8) (29 - i);
  15629. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15630. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15631. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15632. sampleRateBytes[5] = (uint8) (n & 0xff);
  15633. }
  15634. }
  15635. output->write (sampleRateBytes, 10);
  15636. output->writeInt (chunkName ("SSND"));
  15637. output->writeIntBigEndian (audioBytes + 8);
  15638. output->writeInt (0);
  15639. output->writeInt (0);
  15640. jassert (output->getPosition() == headerLen);
  15641. }
  15642. public:
  15643. AiffAudioFormatWriter (OutputStream* out,
  15644. const double sampleRate_,
  15645. const unsigned int chans,
  15646. const int bits)
  15647. : AudioFormatWriter (out,
  15648. TRANS (aiffFormatName),
  15649. sampleRate_,
  15650. chans,
  15651. bits),
  15652. lengthInSamples (0),
  15653. bytesWritten (0),
  15654. writeFailed (false)
  15655. {
  15656. headerPosition = out->getPosition();
  15657. writeHeader();
  15658. }
  15659. ~AiffAudioFormatWriter()
  15660. {
  15661. if ((bytesWritten & 1) != 0)
  15662. output->writeByte (0);
  15663. writeHeader();
  15664. }
  15665. bool write (const int** data, int numSamples)
  15666. {
  15667. if (writeFailed)
  15668. return false;
  15669. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15670. tempBlock.ensureSize (bytes, false);
  15671. char* buffer = (char*) tempBlock.getData();
  15672. const int* left = data[0];
  15673. const int* right = data[1];
  15674. if (right == 0)
  15675. right = left;
  15676. if (bitsPerSample == 16)
  15677. {
  15678. short* b = (short*) buffer;
  15679. if (numChannels > 1)
  15680. {
  15681. for (int i = numSamples; --i >= 0;)
  15682. {
  15683. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15684. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15685. }
  15686. }
  15687. else
  15688. {
  15689. for (int i = numSamples; --i >= 0;)
  15690. {
  15691. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15692. }
  15693. }
  15694. }
  15695. else if (bitsPerSample == 24)
  15696. {
  15697. char* b = (char*) buffer;
  15698. if (numChannels > 1)
  15699. {
  15700. for (int i = numSamples; --i >= 0;)
  15701. {
  15702. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15703. b += 3;
  15704. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15705. b += 3;
  15706. }
  15707. }
  15708. else
  15709. {
  15710. for (int i = numSamples; --i >= 0;)
  15711. {
  15712. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15713. b += 3;
  15714. }
  15715. }
  15716. }
  15717. else if (bitsPerSample == 32)
  15718. {
  15719. uint32* b = (uint32*) buffer;
  15720. if (numChannels > 1)
  15721. {
  15722. for (int i = numSamples; --i >= 0;)
  15723. {
  15724. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15725. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15726. }
  15727. }
  15728. else
  15729. {
  15730. for (int i = numSamples; --i >= 0;)
  15731. {
  15732. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15733. }
  15734. }
  15735. }
  15736. else if (bitsPerSample == 8)
  15737. {
  15738. char* b = (char*) buffer;
  15739. if (numChannels > 1)
  15740. {
  15741. for (int i = numSamples; --i >= 0;)
  15742. {
  15743. *b++ = (char) (*left++ >> 24);
  15744. *b++ = (char) (*right++ >> 24);
  15745. }
  15746. }
  15747. else
  15748. {
  15749. for (int i = numSamples; --i >= 0;)
  15750. {
  15751. *b++ = (char) (*left++ >> 24);
  15752. }
  15753. }
  15754. }
  15755. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15756. || ! output->write (buffer, bytes))
  15757. {
  15758. // failed to write to disk, so let's try writing the header.
  15759. // If it's just run out of disk space, then if it does manage
  15760. // to write the header, we'll still have a useable file..
  15761. writeHeader();
  15762. writeFailed = true;
  15763. return false;
  15764. }
  15765. else
  15766. {
  15767. bytesWritten += bytes;
  15768. lengthInSamples += numSamples;
  15769. return true;
  15770. }
  15771. }
  15772. juce_UseDebuggingNewOperator
  15773. };
  15774. AiffAudioFormat::AiffAudioFormat()
  15775. : AudioFormat (TRANS (aiffFormatName), (const tchar**) aiffExtensions)
  15776. {
  15777. }
  15778. AiffAudioFormat::~AiffAudioFormat()
  15779. {
  15780. }
  15781. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15782. {
  15783. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15784. return Array <int> (rates);
  15785. }
  15786. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15787. {
  15788. const int depths[] = { 8, 16, 24, 0 };
  15789. return Array <int> (depths);
  15790. }
  15791. bool AiffAudioFormat::canDoStereo()
  15792. {
  15793. return true;
  15794. }
  15795. bool AiffAudioFormat::canDoMono()
  15796. {
  15797. return true;
  15798. }
  15799. #if JUCE_MAC
  15800. bool AiffAudioFormat::canHandleFile (const File& f)
  15801. {
  15802. if (AudioFormat::canHandleFile (f))
  15803. return true;
  15804. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15805. return type == 'AIFF' || type == 'AIFC'
  15806. || type == 'aiff' || type == 'aifc';
  15807. }
  15808. #endif
  15809. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15810. const bool deleteStreamIfOpeningFails)
  15811. {
  15812. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15813. if (w->sampleRate != 0)
  15814. return w.release();
  15815. if (! deleteStreamIfOpeningFails)
  15816. w->input = 0;
  15817. return 0;
  15818. }
  15819. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15820. double sampleRate,
  15821. unsigned int chans,
  15822. int bitsPerSample,
  15823. const StringPairArray& /*metadataValues*/,
  15824. int /*qualityOptionIndex*/)
  15825. {
  15826. if (getPossibleBitDepths().contains (bitsPerSample))
  15827. {
  15828. return new AiffAudioFormatWriter (out,
  15829. sampleRate,
  15830. chans,
  15831. bitsPerSample);
  15832. }
  15833. return 0;
  15834. }
  15835. END_JUCE_NAMESPACE
  15836. /*** End of inlined file: juce_AiffAudioFormat.cpp ***/
  15837. /*** Start of inlined file: juce_AudioCDReader.cpp ***/
  15838. BEGIN_JUCE_NAMESPACE
  15839. #if JUCE_MAC && JUCE_USE_CDREADER
  15840. // Mac version doesn't need any native code because it's all done with files..
  15841. // Windows + Linux versions are in the platform-dependent code sections.
  15842. static void findCDs (Array<File>& cds)
  15843. {
  15844. File volumes ("/Volumes");
  15845. volumes.findChildFiles (cds, File::findDirectories, false);
  15846. for (int i = cds.size(); --i >= 0;)
  15847. if (! cds.getReference(i).getChildFile (".TOC.plist").exists())
  15848. cds.remove (i);
  15849. }
  15850. const StringArray AudioCDReader::getAvailableCDNames()
  15851. {
  15852. Array<File> cds;
  15853. findCDs (cds);
  15854. StringArray names;
  15855. for (int i = 0; i < cds.size(); ++i)
  15856. names.add (cds.getReference(i).getFileName());
  15857. return names;
  15858. }
  15859. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15860. {
  15861. Array<File> cds;
  15862. findCDs (cds);
  15863. if (cds[index] != File::nonexistent)
  15864. return new AudioCDReader (cds[index]);
  15865. else
  15866. return 0;
  15867. }
  15868. AudioCDReader::AudioCDReader (const File& volume)
  15869. : AudioFormatReader (0, "CD Audio"),
  15870. volumeDir (volume),
  15871. currentReaderTrack (-1),
  15872. reader (0)
  15873. {
  15874. sampleRate = 44100.0;
  15875. bitsPerSample = 16;
  15876. numChannels = 2;
  15877. usesFloatingPointData = false;
  15878. refreshTrackLengths();
  15879. }
  15880. AudioCDReader::~AudioCDReader()
  15881. {
  15882. }
  15883. static int getTrackNumber (const File& file)
  15884. {
  15885. return file.getFileName()
  15886. .initialSectionContainingOnly (T("0123456789"))
  15887. .getIntValue();
  15888. }
  15889. int AudioCDReader::compareElements (const File& first, const File& second)
  15890. {
  15891. const int firstTrack = getTrackNumber (first);
  15892. const int secondTrack = getTrackNumber (second);
  15893. jassert (firstTrack > 0 && secondTrack > 0);
  15894. return firstTrack - secondTrack;
  15895. }
  15896. void AudioCDReader::refreshTrackLengths()
  15897. {
  15898. tracks.clear();
  15899. trackStartSamples.clear();
  15900. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, T("*.aiff"));
  15901. tracks.sort (*this);
  15902. AiffAudioFormat format;
  15903. int sample = 0;
  15904. for (int i = 0; i < tracks.size(); ++i)
  15905. {
  15906. trackStartSamples.add (sample);
  15907. FileInputStream* const in = tracks.getReference(i).createInputStream();
  15908. if (in != 0)
  15909. {
  15910. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15911. if (r != 0)
  15912. sample += (int) r->lengthInSamples;
  15913. }
  15914. }
  15915. trackStartSamples.add (sample);
  15916. lengthInSamples = sample;
  15917. }
  15918. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15919. int64 startSampleInFile, int numSamples)
  15920. {
  15921. while (numSamples > 0)
  15922. {
  15923. int track = -1;
  15924. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  15925. {
  15926. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  15927. {
  15928. track = i;
  15929. break;
  15930. }
  15931. }
  15932. if (track < 0)
  15933. return false;
  15934. if (track != currentReaderTrack)
  15935. {
  15936. reader = 0;
  15937. FileInputStream* const in = tracks [track].createInputStream();
  15938. if (in != 0)
  15939. {
  15940. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  15941. AiffAudioFormat format;
  15942. reader = format.createReaderFor (bin, true);
  15943. if (reader == 0)
  15944. currentReaderTrack = -1;
  15945. else
  15946. currentReaderTrack = track;
  15947. }
  15948. }
  15949. if (reader == 0)
  15950. return false;
  15951. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  15952. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  15953. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  15954. numSamples -= numAvailable;
  15955. startSampleInFile += numAvailable;
  15956. }
  15957. return true;
  15958. }
  15959. bool AudioCDReader::isCDStillPresent() const
  15960. {
  15961. return volumeDir.exists();
  15962. }
  15963. int AudioCDReader::getNumTracks() const
  15964. {
  15965. return tracks.size();
  15966. }
  15967. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  15968. {
  15969. return trackStartSamples [trackNum];
  15970. }
  15971. bool AudioCDReader::isTrackAudio (int trackNum) const
  15972. {
  15973. return tracks [trackNum] != File::nonexistent;
  15974. }
  15975. void AudioCDReader::enableIndexScanning (bool b)
  15976. {
  15977. // any way to do this on a Mac??
  15978. }
  15979. int AudioCDReader::getLastIndex() const
  15980. {
  15981. return 0;
  15982. }
  15983. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  15984. {
  15985. return Array <int>();
  15986. }
  15987. int AudioCDReader::getCDDBId()
  15988. {
  15989. return 0; //xxx
  15990. }
  15991. #endif
  15992. END_JUCE_NAMESPACE
  15993. /*** End of inlined file: juce_AudioCDReader.cpp ***/
  15994. /*** Start of inlined file: juce_AudioFormat.cpp ***/
  15995. BEGIN_JUCE_NAMESPACE
  15996. AudioFormatReader::AudioFormatReader (InputStream* const in,
  15997. const String& formatName_)
  15998. : sampleRate (0),
  15999. bitsPerSample (0),
  16000. lengthInSamples (0),
  16001. numChannels (0),
  16002. usesFloatingPointData (false),
  16003. input (in),
  16004. formatName (formatName_)
  16005. {
  16006. }
  16007. AudioFormatReader::~AudioFormatReader()
  16008. {
  16009. delete input;
  16010. }
  16011. bool AudioFormatReader::read (int** destSamples,
  16012. int numDestChannels,
  16013. int64 startSampleInSource,
  16014. int numSamplesToRead,
  16015. const bool fillLeftoverChannelsWithCopies)
  16016. {
  16017. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  16018. int startOffsetInDestBuffer = 0;
  16019. if (startSampleInSource < 0)
  16020. {
  16021. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  16022. for (int i = numDestChannels; --i >= 0;)
  16023. if (destSamples[i] != 0)
  16024. zeromem (destSamples[i], sizeof (int) * silence);
  16025. startOffsetInDestBuffer += silence;
  16026. numSamplesToRead -= silence;
  16027. startSampleInSource = 0;
  16028. }
  16029. if (numSamplesToRead <= 0)
  16030. return true;
  16031. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  16032. startSampleInSource, numSamplesToRead))
  16033. return false;
  16034. if (numDestChannels > (int) numChannels)
  16035. {
  16036. if (fillLeftoverChannelsWithCopies)
  16037. {
  16038. int* lastFullChannel = destSamples[0];
  16039. for (int i = numDestChannels; --i > 0;)
  16040. {
  16041. if (destSamples[i] != 0)
  16042. {
  16043. lastFullChannel = destSamples[i];
  16044. break;
  16045. }
  16046. }
  16047. if (lastFullChannel != 0)
  16048. for (int i = numChannels; i < numDestChannels; ++i)
  16049. if (destSamples[i] != 0)
  16050. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  16051. }
  16052. else
  16053. {
  16054. for (int i = numChannels; i < numDestChannels; ++i)
  16055. if (destSamples[i] != 0)
  16056. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  16057. }
  16058. }
  16059. return true;
  16060. }
  16061. static void findAudioBufferMaxMin (const float* const buffer, const int num, float& maxVal, float& minVal) throw()
  16062. {
  16063. float mn = buffer[0];
  16064. float mx = mn;
  16065. for (int i = 1; i < num; ++i)
  16066. {
  16067. const float s = buffer[i];
  16068. if (s > mx) mx = s;
  16069. if (s < mn) mn = s;
  16070. }
  16071. maxVal = mx;
  16072. minVal = mn;
  16073. }
  16074. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  16075. int64 numSamples,
  16076. float& lowestLeft, float& highestLeft,
  16077. float& lowestRight, float& highestRight)
  16078. {
  16079. if (numSamples <= 0)
  16080. {
  16081. lowestLeft = 0;
  16082. lowestRight = 0;
  16083. highestLeft = 0;
  16084. highestRight = 0;
  16085. return;
  16086. }
  16087. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  16088. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16089. int* tempBuffer[3];
  16090. tempBuffer[0] = (int*) tempSpace.getData();
  16091. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16092. tempBuffer[2] = 0;
  16093. if (usesFloatingPointData)
  16094. {
  16095. float lmin = 1.0e6f;
  16096. float lmax = -lmin;
  16097. float rmin = lmin;
  16098. float rmax = lmax;
  16099. while (numSamples > 0)
  16100. {
  16101. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16102. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16103. numSamples -= numToDo;
  16104. startSampleInFile += numToDo;
  16105. float bufmin, bufmax;
  16106. findAudioBufferMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  16107. lmin = jmin (lmin, bufmin);
  16108. lmax = jmax (lmax, bufmax);
  16109. if (numChannels > 1)
  16110. {
  16111. findAudioBufferMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  16112. rmin = jmin (rmin, bufmin);
  16113. rmax = jmax (rmax, bufmax);
  16114. }
  16115. }
  16116. if (numChannels <= 1)
  16117. {
  16118. rmax = lmax;
  16119. rmin = lmin;
  16120. }
  16121. lowestLeft = lmin;
  16122. highestLeft = lmax;
  16123. lowestRight = rmin;
  16124. highestRight = rmax;
  16125. }
  16126. else
  16127. {
  16128. int lmax = std::numeric_limits<int>::min();
  16129. int lmin = std::numeric_limits<int>::max();
  16130. int rmax = std::numeric_limits<int>::min();
  16131. int rmin = std::numeric_limits<int>::max();
  16132. while (numSamples > 0)
  16133. {
  16134. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16135. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16136. numSamples -= numToDo;
  16137. startSampleInFile += numToDo;
  16138. for (int j = numChannels; --j >= 0;)
  16139. {
  16140. int bufMax = std::numeric_limits<int>::min();
  16141. int bufMin = std::numeric_limits<int>::max();
  16142. const int* const b = tempBuffer[j];
  16143. for (int i = 0; i < numToDo; ++i)
  16144. {
  16145. const int samp = b[i];
  16146. if (samp < bufMin)
  16147. bufMin = samp;
  16148. if (samp > bufMax)
  16149. bufMax = samp;
  16150. }
  16151. if (j == 0)
  16152. {
  16153. lmax = jmax (lmax, bufMax);
  16154. lmin = jmin (lmin, bufMin);
  16155. }
  16156. else
  16157. {
  16158. rmax = jmax (rmax, bufMax);
  16159. rmin = jmin (rmin, bufMin);
  16160. }
  16161. }
  16162. }
  16163. if (numChannels <= 1)
  16164. {
  16165. rmax = lmax;
  16166. rmin = lmin;
  16167. }
  16168. lowestLeft = lmin / (float) std::numeric_limits<int>::max();
  16169. highestLeft = lmax / (float) std::numeric_limits<int>::max();
  16170. lowestRight = rmin / (float) std::numeric_limits<int>::max();
  16171. highestRight = rmax / (float) std::numeric_limits<int>::max();
  16172. }
  16173. }
  16174. int64 AudioFormatReader::searchForLevel (int64 startSample,
  16175. int64 numSamplesToSearch,
  16176. const double magnitudeRangeMinimum,
  16177. const double magnitudeRangeMaximum,
  16178. const int minimumConsecutiveSamples)
  16179. {
  16180. if (numSamplesToSearch == 0)
  16181. return -1;
  16182. const int bufferSize = 4096;
  16183. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16184. int* tempBuffer[3];
  16185. tempBuffer[0] = (int*) tempSpace.getData();
  16186. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16187. tempBuffer[2] = 0;
  16188. int consecutive = 0;
  16189. int64 firstMatchPos = -1;
  16190. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  16191. const double doubleMin = jlimit (0.0, (double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
  16192. const double doubleMax = jlimit (doubleMin, (double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
  16193. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  16194. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  16195. while (numSamplesToSearch != 0)
  16196. {
  16197. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  16198. int64 bufferStart = startSample;
  16199. if (numSamplesToSearch < 0)
  16200. bufferStart -= numThisTime;
  16201. if (bufferStart >= (int) lengthInSamples)
  16202. break;
  16203. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  16204. int num = numThisTime;
  16205. while (--num >= 0)
  16206. {
  16207. if (numSamplesToSearch < 0)
  16208. --startSample;
  16209. bool matches = false;
  16210. const int index = (int) (startSample - bufferStart);
  16211. if (usesFloatingPointData)
  16212. {
  16213. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  16214. if (sample1 >= magnitudeRangeMinimum
  16215. && sample1 <= magnitudeRangeMaximum)
  16216. {
  16217. matches = true;
  16218. }
  16219. else if (numChannels > 1)
  16220. {
  16221. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  16222. matches = (sample2 >= magnitudeRangeMinimum
  16223. && sample2 <= magnitudeRangeMaximum);
  16224. }
  16225. }
  16226. else
  16227. {
  16228. const int sample1 = abs (tempBuffer[0] [index]);
  16229. if (sample1 >= intMagnitudeRangeMinimum
  16230. && sample1 <= intMagnitudeRangeMaximum)
  16231. {
  16232. matches = true;
  16233. }
  16234. else if (numChannels > 1)
  16235. {
  16236. const int sample2 = abs (tempBuffer[1][index]);
  16237. matches = (sample2 >= intMagnitudeRangeMinimum
  16238. && sample2 <= intMagnitudeRangeMaximum);
  16239. }
  16240. }
  16241. if (matches)
  16242. {
  16243. if (firstMatchPos < 0)
  16244. firstMatchPos = startSample;
  16245. if (++consecutive >= minimumConsecutiveSamples)
  16246. {
  16247. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  16248. return -1;
  16249. return firstMatchPos;
  16250. }
  16251. }
  16252. else
  16253. {
  16254. consecutive = 0;
  16255. firstMatchPos = -1;
  16256. }
  16257. if (numSamplesToSearch > 0)
  16258. ++startSample;
  16259. }
  16260. if (numSamplesToSearch > 0)
  16261. numSamplesToSearch -= numThisTime;
  16262. else
  16263. numSamplesToSearch += numThisTime;
  16264. }
  16265. return -1;
  16266. }
  16267. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  16268. const String& formatName_,
  16269. const double rate,
  16270. const unsigned int numChannels_,
  16271. const unsigned int bitsPerSample_)
  16272. : sampleRate (rate),
  16273. numChannels (numChannels_),
  16274. bitsPerSample (bitsPerSample_),
  16275. usesFloatingPointData (false),
  16276. output (out),
  16277. formatName (formatName_)
  16278. {
  16279. }
  16280. AudioFormatWriter::~AudioFormatWriter()
  16281. {
  16282. delete output;
  16283. }
  16284. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  16285. int64 startSample,
  16286. int64 numSamplesToRead)
  16287. {
  16288. const int bufferSize = 16384;
  16289. const int maxChans = 128;
  16290. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  16291. int* buffers [maxChans];
  16292. for (int i = maxChans; --i >= 0;)
  16293. buffers[i] = 0;
  16294. if (numSamplesToRead < 0)
  16295. numSamplesToRead = reader.lengthInSamples;
  16296. while (numSamplesToRead > 0)
  16297. {
  16298. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  16299. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  16300. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16301. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  16302. return false;
  16303. if (reader.usesFloatingPointData != isFloatingPoint())
  16304. {
  16305. int** bufferChan = buffers;
  16306. while (*bufferChan != 0)
  16307. {
  16308. int* b = *bufferChan++;
  16309. if (isFloatingPoint())
  16310. {
  16311. // int -> float
  16312. const double factor = 1.0 / std::numeric_limits<int>::max();
  16313. for (int i = 0; i < numToDo; ++i)
  16314. ((float*) b)[i] = (float) (factor * b[i]);
  16315. }
  16316. else
  16317. {
  16318. // float -> int
  16319. for (int i = 0; i < numToDo; ++i)
  16320. {
  16321. const double samp = *(const float*) b;
  16322. if (samp <= -1.0)
  16323. *b++ = std::numeric_limits<int>::min();
  16324. else if (samp >= 1.0)
  16325. *b++ = std::numeric_limits<int>::max();
  16326. else
  16327. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16328. }
  16329. }
  16330. }
  16331. }
  16332. if (! write ((const int**) buffers, numToDo))
  16333. return false;
  16334. numSamplesToRead -= numToDo;
  16335. startSample += numToDo;
  16336. }
  16337. return true;
  16338. }
  16339. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  16340. int numSamplesToRead,
  16341. const int samplesPerBlock)
  16342. {
  16343. const int maxChans = 128;
  16344. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  16345. int* buffers [maxChans];
  16346. while (numSamplesToRead > 0)
  16347. {
  16348. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  16349. AudioSourceChannelInfo info;
  16350. info.buffer = &tempBuffer;
  16351. info.startSample = 0;
  16352. info.numSamples = numToDo;
  16353. info.clearActiveBufferRegion();
  16354. source.getNextAudioBlock (info);
  16355. int i;
  16356. for (i = maxChans; --i >= 0;)
  16357. buffers[i] = 0;
  16358. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16359. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16360. if (! isFloatingPoint())
  16361. {
  16362. int** bufferChan = buffers;
  16363. while (*bufferChan != 0)
  16364. {
  16365. int* b = *bufferChan++;
  16366. // float -> int
  16367. for (int j = numToDo; --j >= 0;)
  16368. {
  16369. const double samp = *(const float*) b;
  16370. if (samp <= -1.0)
  16371. *b++ = std::numeric_limits<int>::min();
  16372. else if (samp >= 1.0)
  16373. *b++ = std::numeric_limits<int>::max();
  16374. else
  16375. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16376. }
  16377. }
  16378. }
  16379. if (! write ((const int**) buffers, numToDo))
  16380. return false;
  16381. numSamplesToRead -= numToDo;
  16382. }
  16383. return true;
  16384. }
  16385. AudioFormat::AudioFormat (const String& name,
  16386. const tchar** const extensions)
  16387. : formatName (name),
  16388. fileExtensions (extensions)
  16389. {
  16390. }
  16391. AudioFormat::~AudioFormat()
  16392. {
  16393. }
  16394. const String& AudioFormat::getFormatName() const
  16395. {
  16396. return formatName;
  16397. }
  16398. const StringArray& AudioFormat::getFileExtensions() const
  16399. {
  16400. return fileExtensions;
  16401. }
  16402. bool AudioFormat::canHandleFile (const File& f)
  16403. {
  16404. for (int i = 0; i < fileExtensions.size(); ++i)
  16405. if (f.hasFileExtension (fileExtensions[i]))
  16406. return true;
  16407. return false;
  16408. }
  16409. bool AudioFormat::isCompressed()
  16410. {
  16411. return false;
  16412. }
  16413. const StringArray AudioFormat::getQualityOptions()
  16414. {
  16415. return StringArray();
  16416. }
  16417. END_JUCE_NAMESPACE
  16418. /*** End of inlined file: juce_AudioFormat.cpp ***/
  16419. /*** Start of inlined file: juce_AudioFormatManager.cpp ***/
  16420. BEGIN_JUCE_NAMESPACE
  16421. AudioFormatManager::AudioFormatManager()
  16422. : defaultFormatIndex (0)
  16423. {
  16424. }
  16425. AudioFormatManager::~AudioFormatManager()
  16426. {
  16427. clearFormats();
  16428. clearSingletonInstance();
  16429. }
  16430. juce_ImplementSingleton (AudioFormatManager);
  16431. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16432. const bool makeThisTheDefaultFormat)
  16433. {
  16434. jassert (newFormat != 0);
  16435. if (newFormat != 0)
  16436. {
  16437. #ifdef JUCE_DEBUG
  16438. for (int i = getNumKnownFormats(); --i >= 0;)
  16439. {
  16440. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16441. {
  16442. jassertfalse // trying to add the same format twice!
  16443. }
  16444. }
  16445. #endif
  16446. if (makeThisTheDefaultFormat)
  16447. defaultFormatIndex = knownFormats.size();
  16448. knownFormats.add (newFormat);
  16449. }
  16450. }
  16451. void AudioFormatManager::registerBasicFormats()
  16452. {
  16453. #if JUCE_MAC
  16454. registerFormat (new AiffAudioFormat(), true);
  16455. registerFormat (new WavAudioFormat(), false);
  16456. #else
  16457. registerFormat (new WavAudioFormat(), true);
  16458. registerFormat (new AiffAudioFormat(), false);
  16459. #endif
  16460. #if JUCE_USE_FLAC
  16461. registerFormat (new FlacAudioFormat(), false);
  16462. #endif
  16463. #if JUCE_USE_OGGVORBIS
  16464. registerFormat (new OggVorbisAudioFormat(), false);
  16465. #endif
  16466. }
  16467. void AudioFormatManager::clearFormats()
  16468. {
  16469. for (int i = getNumKnownFormats(); --i >= 0;)
  16470. delete getKnownFormat(i);
  16471. knownFormats.clear();
  16472. defaultFormatIndex = 0;
  16473. }
  16474. int AudioFormatManager::getNumKnownFormats() const
  16475. {
  16476. return knownFormats.size();
  16477. }
  16478. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16479. {
  16480. return (AudioFormat*) knownFormats [index];
  16481. }
  16482. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16483. {
  16484. return getKnownFormat (defaultFormatIndex);
  16485. }
  16486. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16487. {
  16488. String e (fileExtension);
  16489. if (! e.startsWithChar (T('.')))
  16490. e = T(".") + e;
  16491. for (int i = 0; i < getNumKnownFormats(); ++i)
  16492. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16493. return getKnownFormat(i);
  16494. return 0;
  16495. }
  16496. const String AudioFormatManager::getWildcardForAllFormats() const
  16497. {
  16498. StringArray allExtensions;
  16499. int i;
  16500. for (i = 0; i < getNumKnownFormats(); ++i)
  16501. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16502. allExtensions.trim();
  16503. allExtensions.removeEmptyStrings();
  16504. String s;
  16505. for (i = 0; i < allExtensions.size(); ++i)
  16506. {
  16507. s << T('*');
  16508. if (! allExtensions[i].startsWithChar (T('.')))
  16509. s << T('.');
  16510. s << allExtensions[i];
  16511. if (i < allExtensions.size() - 1)
  16512. s << T(';');
  16513. }
  16514. return s;
  16515. }
  16516. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16517. {
  16518. // you need to actually register some formats before the manager can
  16519. // use them to open a file!
  16520. jassert (knownFormats.size() > 0);
  16521. for (int i = 0; i < getNumKnownFormats(); ++i)
  16522. {
  16523. AudioFormat* const af = getKnownFormat(i);
  16524. if (af->canHandleFile (file))
  16525. {
  16526. InputStream* const in = file.createInputStream();
  16527. if (in != 0)
  16528. {
  16529. AudioFormatReader* const r = af->createReaderFor (in, true);
  16530. if (r != 0)
  16531. return r;
  16532. }
  16533. }
  16534. }
  16535. return 0;
  16536. }
  16537. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16538. {
  16539. // you need to actually register some formats before the manager can
  16540. // use them to open a file!
  16541. jassert (knownFormats.size() > 0);
  16542. ScopedPointer <InputStream> in (audioFileStream);
  16543. if (in != 0)
  16544. {
  16545. const int64 originalStreamPos = in->getPosition();
  16546. for (int i = 0; i < getNumKnownFormats(); ++i)
  16547. {
  16548. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16549. if (r != 0)
  16550. {
  16551. in.release();
  16552. return r;
  16553. }
  16554. in->setPosition (originalStreamPos);
  16555. // the stream that is passed-in must be capable of being repositioned so
  16556. // that all the formats can have a go at opening it.
  16557. jassert (in->getPosition() == originalStreamPos);
  16558. }
  16559. }
  16560. return 0;
  16561. }
  16562. END_JUCE_NAMESPACE
  16563. /*** End of inlined file: juce_AudioFormatManager.cpp ***/
  16564. /*** Start of inlined file: juce_AudioSubsectionReader.cpp ***/
  16565. BEGIN_JUCE_NAMESPACE
  16566. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16567. const int64 startSample_,
  16568. const int64 length_,
  16569. const bool deleteSourceWhenDeleted_)
  16570. : AudioFormatReader (0, source_->getFormatName()),
  16571. source (source_),
  16572. startSample (startSample_),
  16573. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16574. {
  16575. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16576. sampleRate = source->sampleRate;
  16577. bitsPerSample = source->bitsPerSample;
  16578. lengthInSamples = length;
  16579. numChannels = source->numChannels;
  16580. usesFloatingPointData = source->usesFloatingPointData;
  16581. }
  16582. AudioSubsectionReader::~AudioSubsectionReader()
  16583. {
  16584. if (deleteSourceWhenDeleted)
  16585. delete source;
  16586. }
  16587. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16588. int64 startSampleInFile, int numSamples)
  16589. {
  16590. if (startSampleInFile + numSamples > length)
  16591. {
  16592. for (int i = numDestChannels; --i >= 0;)
  16593. if (destSamples[i] != 0)
  16594. zeromem (destSamples[i], sizeof (int) * numSamples);
  16595. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16596. if (numSamples <= 0)
  16597. return true;
  16598. }
  16599. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16600. startSampleInFile + startSample, numSamples);
  16601. }
  16602. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16603. int64 numSamples,
  16604. float& lowestLeft,
  16605. float& highestLeft,
  16606. float& lowestRight,
  16607. float& highestRight)
  16608. {
  16609. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16610. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16611. source->readMaxLevels (startSampleInFile + startSample,
  16612. numSamples,
  16613. lowestLeft,
  16614. highestLeft,
  16615. lowestRight,
  16616. highestRight);
  16617. }
  16618. END_JUCE_NAMESPACE
  16619. /*** End of inlined file: juce_AudioSubsectionReader.cpp ***/
  16620. /*** Start of inlined file: juce_AudioThumbnail.cpp ***/
  16621. BEGIN_JUCE_NAMESPACE
  16622. const int timeBeforeDeletingReader = 2000;
  16623. struct AudioThumbnailDataFormat
  16624. {
  16625. char thumbnailMagic[4];
  16626. int samplesPerThumbSample;
  16627. int64 totalSamples; // source samples
  16628. int64 numFinishedSamples; // source samples
  16629. int numThumbnailSamples;
  16630. int numChannels;
  16631. int sampleRate;
  16632. char future[16];
  16633. char data[1];
  16634. void swapEndiannessIfNeeded() throw()
  16635. {
  16636. #if JUCE_BIG_ENDIAN
  16637. flip (samplesPerThumbSample);
  16638. flip (totalSamples);
  16639. flip (numFinishedSamples);
  16640. flip (numThumbnailSamples);
  16641. flip (numChannels);
  16642. flip (sampleRate);
  16643. #endif
  16644. }
  16645. private:
  16646. #if JUCE_BIG_ENDIAN
  16647. static void flip (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16648. static void flip (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16649. #endif
  16650. };
  16651. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16652. AudioFormatManager& formatManagerToUse_,
  16653. AudioThumbnailCache& cacheToUse)
  16654. : formatManagerToUse (formatManagerToUse_),
  16655. cache (cacheToUse),
  16656. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16657. {
  16658. clear();
  16659. }
  16660. AudioThumbnail::~AudioThumbnail()
  16661. {
  16662. cache.removeThumbnail (this);
  16663. const ScopedLock sl (readerLock);
  16664. reader = 0;
  16665. }
  16666. void AudioThumbnail::setSource (InputSource* const newSource)
  16667. {
  16668. cache.removeThumbnail (this);
  16669. timerCallback(); // stops the timer and deletes the reader
  16670. source = newSource;
  16671. clear();
  16672. if (newSource != 0
  16673. && ! (cache.loadThumb (*this, newSource->hashCode())
  16674. && isFullyLoaded()))
  16675. {
  16676. {
  16677. const ScopedLock sl (readerLock);
  16678. reader = createReader();
  16679. }
  16680. if (reader != 0)
  16681. {
  16682. initialiseFromAudioFile (*reader);
  16683. cache.addThumbnail (this);
  16684. }
  16685. }
  16686. sendChangeMessage (this);
  16687. }
  16688. bool AudioThumbnail::useTimeSlice()
  16689. {
  16690. const ScopedLock sl (readerLock);
  16691. if (isFullyLoaded())
  16692. {
  16693. if (reader != 0)
  16694. startTimer (timeBeforeDeletingReader);
  16695. cache.removeThumbnail (this);
  16696. return false;
  16697. }
  16698. if (reader == 0)
  16699. reader = createReader();
  16700. if (reader != 0)
  16701. {
  16702. readNextBlockFromAudioFile (*reader);
  16703. stopTimer();
  16704. sendChangeMessage (this);
  16705. const bool justFinished = isFullyLoaded();
  16706. if (justFinished)
  16707. cache.storeThumb (*this, source->hashCode());
  16708. return ! justFinished;
  16709. }
  16710. return false;
  16711. }
  16712. AudioFormatReader* AudioThumbnail::createReader() const
  16713. {
  16714. if (source != 0)
  16715. {
  16716. InputStream* const audioFileStream = source->createInputStream();
  16717. if (audioFileStream != 0)
  16718. return formatManagerToUse.createReaderFor (audioFileStream);
  16719. }
  16720. return 0;
  16721. }
  16722. void AudioThumbnail::timerCallback()
  16723. {
  16724. stopTimer();
  16725. const ScopedLock sl (readerLock);
  16726. reader = 0;
  16727. }
  16728. void AudioThumbnail::clear()
  16729. {
  16730. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16731. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16732. d->thumbnailMagic[0] = 'j';
  16733. d->thumbnailMagic[1] = 'a';
  16734. d->thumbnailMagic[2] = 't';
  16735. d->thumbnailMagic[3] = 'm';
  16736. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16737. d->totalSamples = 0;
  16738. d->numFinishedSamples = 0;
  16739. d->numThumbnailSamples = 0;
  16740. d->numChannels = 0;
  16741. d->sampleRate = 0;
  16742. numSamplesCached = 0;
  16743. cacheNeedsRefilling = true;
  16744. }
  16745. void AudioThumbnail::loadFrom (InputStream& input)
  16746. {
  16747. const ScopedLock sl (readerLock);
  16748. data.setSize (0);
  16749. input.readIntoMemoryBlock (data);
  16750. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16751. d->swapEndiannessIfNeeded();
  16752. if (! (d->thumbnailMagic[0] == 'j'
  16753. && d->thumbnailMagic[1] == 'a'
  16754. && d->thumbnailMagic[2] == 't'
  16755. && d->thumbnailMagic[3] == 'm'))
  16756. {
  16757. clear();
  16758. }
  16759. numSamplesCached = 0;
  16760. cacheNeedsRefilling = true;
  16761. }
  16762. void AudioThumbnail::saveTo (OutputStream& output) const
  16763. {
  16764. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16765. d->swapEndiannessIfNeeded();
  16766. output.write (data.getData(), (int) data.getSize());
  16767. d->swapEndiannessIfNeeded();
  16768. }
  16769. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16770. {
  16771. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16772. d->totalSamples = fileReader.lengthInSamples;
  16773. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16774. d->numFinishedSamples = 0;
  16775. d->sampleRate = roundToInt (fileReader.sampleRate);
  16776. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16777. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16778. d = (AudioThumbnailDataFormat*) data.getData();
  16779. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16780. return d->totalSamples > 0;
  16781. }
  16782. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16783. {
  16784. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16785. if (d->numFinishedSamples < d->totalSamples)
  16786. {
  16787. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16788. generateSection (fileReader,
  16789. d->numFinishedSamples,
  16790. numToDo);
  16791. d->numFinishedSamples += numToDo;
  16792. }
  16793. cacheNeedsRefilling = true;
  16794. return (d->numFinishedSamples < d->totalSamples);
  16795. }
  16796. int AudioThumbnail::getNumChannels() const throw()
  16797. {
  16798. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16799. jassert (d != 0);
  16800. return d->numChannels;
  16801. }
  16802. double AudioThumbnail::getTotalLength() const throw()
  16803. {
  16804. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16805. jassert (d != 0);
  16806. if (d->sampleRate > 0)
  16807. return d->totalSamples / (double)d->sampleRate;
  16808. else
  16809. return 0.0;
  16810. }
  16811. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16812. int64 startSample,
  16813. int numSamples)
  16814. {
  16815. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16816. jassert (d != 0);
  16817. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16818. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16819. char* l = getChannelData (0);
  16820. char* r = getChannelData (1);
  16821. for (int i = firstDataPos; i < lastDataPos; ++i)
  16822. {
  16823. const int sourceStart = i * d->samplesPerThumbSample;
  16824. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16825. float lowestLeft, highestLeft, lowestRight, highestRight;
  16826. fileReader.readMaxLevels (sourceStart,
  16827. sourceEnd - sourceStart,
  16828. lowestLeft,
  16829. highestLeft,
  16830. lowestRight,
  16831. highestRight);
  16832. int n = i * 2;
  16833. if (r != 0)
  16834. {
  16835. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16836. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16837. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16838. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16839. }
  16840. else
  16841. {
  16842. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16843. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16844. }
  16845. }
  16846. }
  16847. char* AudioThumbnail::getChannelData (int channel) const
  16848. {
  16849. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16850. jassert (d != 0);
  16851. if (channel >= 0 && channel < d->numChannels)
  16852. return d->data + (channel * 2 * d->numThumbnailSamples);
  16853. return 0;
  16854. }
  16855. bool AudioThumbnail::isFullyLoaded() const throw()
  16856. {
  16857. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16858. jassert (d != 0);
  16859. return d->numFinishedSamples >= d->totalSamples;
  16860. }
  16861. void AudioThumbnail::refillCache (const int numSamples,
  16862. double startTime,
  16863. const double timePerPixel)
  16864. {
  16865. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16866. jassert (d != 0);
  16867. if (numSamples <= 0
  16868. || timePerPixel <= 0.0
  16869. || d->sampleRate <= 0)
  16870. {
  16871. numSamplesCached = 0;
  16872. cacheNeedsRefilling = true;
  16873. return;
  16874. }
  16875. if (numSamples == numSamplesCached
  16876. && numChannelsCached == d->numChannels
  16877. && startTime == cachedStart
  16878. && timePerPixel == cachedTimePerPixel
  16879. && ! cacheNeedsRefilling)
  16880. {
  16881. return;
  16882. }
  16883. numSamplesCached = numSamples;
  16884. numChannelsCached = d->numChannels;
  16885. cachedStart = startTime;
  16886. cachedTimePerPixel = timePerPixel;
  16887. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16888. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16889. const ScopedLock sl (readerLock);
  16890. cacheNeedsRefilling = false;
  16891. if (needExtraDetail && reader == 0)
  16892. reader = createReader();
  16893. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16894. {
  16895. startTimer (timeBeforeDeletingReader);
  16896. char* cacheData = (char*) cachedLevels.getData();
  16897. int sample = roundToInt (startTime * d->sampleRate);
  16898. for (int i = numSamples; --i >= 0;)
  16899. {
  16900. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16901. if (sample >= 0)
  16902. {
  16903. if (sample >= reader->lengthInSamples)
  16904. break;
  16905. float lmin, lmax, rmin, rmax;
  16906. reader->readMaxLevels (sample,
  16907. jmax (1, nextSample - sample),
  16908. lmin, lmax, rmin, rmax);
  16909. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16910. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16911. if (numChannelsCached > 1)
  16912. {
  16913. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  16914. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  16915. }
  16916. cacheData += 2 * numChannelsCached;
  16917. }
  16918. startTime += timePerPixel;
  16919. sample = nextSample;
  16920. }
  16921. }
  16922. else
  16923. {
  16924. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  16925. {
  16926. char* const channelData = getChannelData (channelNum);
  16927. char* cacheData = ((char*) cachedLevels.getData()) + channelNum * 2;
  16928. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  16929. startTime = cachedStart;
  16930. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  16931. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  16932. for (int i = numSamples; --i >= 0;)
  16933. {
  16934. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  16935. if (sample >= 0 && channelData != 0)
  16936. {
  16937. char mx = -128;
  16938. char mn = 127;
  16939. while (sample <= nextSample)
  16940. {
  16941. if (sample >= numFinished)
  16942. break;
  16943. const int n = sample << 1;
  16944. const char sampMin = channelData [n];
  16945. const char sampMax = channelData [n + 1];
  16946. if (sampMin < mn)
  16947. mn = sampMin;
  16948. if (sampMax > mx)
  16949. mx = sampMax;
  16950. ++sample;
  16951. }
  16952. if (mn <= mx)
  16953. {
  16954. cacheData[0] = mn;
  16955. cacheData[1] = mx;
  16956. }
  16957. else
  16958. {
  16959. cacheData[0] = 1;
  16960. cacheData[1] = 0;
  16961. }
  16962. }
  16963. else
  16964. {
  16965. cacheData[0] = 1;
  16966. cacheData[1] = 0;
  16967. }
  16968. cacheData += numChannelsCached * 2;
  16969. startTime += timePerPixel;
  16970. sample = nextSample;
  16971. }
  16972. }
  16973. }
  16974. }
  16975. void AudioThumbnail::drawChannel (Graphics& g,
  16976. int x, int y, int w, int h,
  16977. double startTime,
  16978. double endTime,
  16979. int channelNum,
  16980. const float verticalZoomFactor)
  16981. {
  16982. refillCache (w, startTime, (endTime - startTime) / w);
  16983. if (numSamplesCached >= w
  16984. && channelNum >= 0
  16985. && channelNum < numChannelsCached)
  16986. {
  16987. const float topY = (float) y;
  16988. const float bottomY = topY + h;
  16989. const float midY = topY + h * 0.5f;
  16990. const float vscale = verticalZoomFactor * h / 256.0f;
  16991. const Rectangle<int> clip (g.getClipBounds());
  16992. const int skipLeft = jlimit (0, w, clip.getX() - x);
  16993. w -= skipLeft;
  16994. x += skipLeft;
  16995. const char* cacheData = ((const char*) cachedLevels.getData())
  16996. + (channelNum << 1)
  16997. + skipLeft * (numChannelsCached << 1);
  16998. while (--w >= 0)
  16999. {
  17000. const char mn = cacheData[0];
  17001. const char mx = cacheData[1];
  17002. cacheData += numChannelsCached << 1;
  17003. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  17004. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  17005. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  17006. ++x;
  17007. if (x >= clip.getRight())
  17008. break;
  17009. }
  17010. }
  17011. }
  17012. END_JUCE_NAMESPACE
  17013. /*** End of inlined file: juce_AudioThumbnail.cpp ***/
  17014. /*** Start of inlined file: juce_AudioThumbnailCache.cpp ***/
  17015. BEGIN_JUCE_NAMESPACE
  17016. struct ThumbnailCacheEntry
  17017. {
  17018. int64 hash;
  17019. uint32 lastUsed;
  17020. MemoryBlock data;
  17021. juce_UseDebuggingNewOperator
  17022. };
  17023. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  17024. : TimeSliceThread (T("thumb cache")),
  17025. maxNumThumbsToStore (maxNumThumbsToStore_)
  17026. {
  17027. startThread (2);
  17028. }
  17029. AudioThumbnailCache::~AudioThumbnailCache()
  17030. {
  17031. }
  17032. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  17033. {
  17034. for (int i = thumbs.size(); --i >= 0;)
  17035. {
  17036. if (thumbs[i]->hash == hashCode)
  17037. {
  17038. MemoryInputStream in ((const char*) thumbs[i]->data.getData(),
  17039. thumbs[i]->data.getSize(),
  17040. false);
  17041. thumb.loadFrom (in);
  17042. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  17043. return true;
  17044. }
  17045. }
  17046. return false;
  17047. }
  17048. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  17049. const int64 hashCode)
  17050. {
  17051. MemoryOutputStream out;
  17052. thumb.saveTo (out);
  17053. ThumbnailCacheEntry* te = 0;
  17054. for (int i = thumbs.size(); --i >= 0;)
  17055. {
  17056. if (thumbs[i]->hash == hashCode)
  17057. {
  17058. te = thumbs[i];
  17059. break;
  17060. }
  17061. }
  17062. if (te == 0)
  17063. {
  17064. te = new ThumbnailCacheEntry();
  17065. te->hash = hashCode;
  17066. if (thumbs.size() < maxNumThumbsToStore)
  17067. {
  17068. thumbs.add (te);
  17069. }
  17070. else
  17071. {
  17072. int oldest = 0;
  17073. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  17074. int i;
  17075. for (i = thumbs.size(); --i >= 0;)
  17076. if (thumbs[i]->lastUsed < oldestTime)
  17077. oldest = i;
  17078. thumbs.set (i, te);
  17079. }
  17080. }
  17081. te->lastUsed = Time::getMillisecondCounter();
  17082. te->data.setSize (0);
  17083. te->data.append (out.getData(), out.getDataSize());
  17084. }
  17085. void AudioThumbnailCache::clear()
  17086. {
  17087. thumbs.clear();
  17088. }
  17089. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  17090. {
  17091. addTimeSliceClient (thumb);
  17092. }
  17093. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  17094. {
  17095. removeTimeSliceClient (thumb);
  17096. }
  17097. END_JUCE_NAMESPACE
  17098. /*** End of inlined file: juce_AudioThumbnailCache.cpp ***/
  17099. /*** Start of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17100. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  17101. #if ! JUCE_WINDOWS
  17102. #include <QuickTime/Movies.h>
  17103. #include <QuickTime/QTML.h>
  17104. #include <QuickTime/QuickTimeComponents.h>
  17105. #include <QuickTime/MediaHandlers.h>
  17106. #include <QuickTime/ImageCodec.h>
  17107. #else
  17108. #if JUCE_MSVC
  17109. #pragma warning (push)
  17110. #pragma warning (disable : 4100)
  17111. #endif
  17112. #include <Movies.h>
  17113. #include <QTML.h>
  17114. #include <QuickTimeComponents.h>
  17115. #include <MediaHandlers.h>
  17116. #include <ImageCodec.h>
  17117. #if JUCE_MSVC
  17118. #pragma warning (pop)
  17119. #endif
  17120. #endif
  17121. BEGIN_JUCE_NAMESPACE
  17122. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  17123. static const char* const quickTimeFormatName = "QuickTime file";
  17124. static const tchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  17125. class QTAudioReader : public AudioFormatReader
  17126. {
  17127. public:
  17128. QTAudioReader (InputStream* const input_, const int trackNum_)
  17129. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  17130. ok (false),
  17131. movie (0),
  17132. trackNum (trackNum_),
  17133. lastSampleRead (0),
  17134. lastThreadId (0),
  17135. extractor (0),
  17136. dataHandle (0)
  17137. {
  17138. bufferList.calloc (256, 1);
  17139. #ifdef WIN32
  17140. if (InitializeQTML (0) != noErr)
  17141. return;
  17142. #endif
  17143. if (EnterMovies() != noErr)
  17144. return;
  17145. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  17146. if (! opened)
  17147. return;
  17148. {
  17149. const int numTracks = GetMovieTrackCount (movie);
  17150. int trackCount = 0;
  17151. for (int i = 1; i <= numTracks; ++i)
  17152. {
  17153. track = GetMovieIndTrack (movie, i);
  17154. media = GetTrackMedia (track);
  17155. OSType mediaType;
  17156. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  17157. if (mediaType == SoundMediaType
  17158. && trackCount++ == trackNum_)
  17159. {
  17160. ok = true;
  17161. break;
  17162. }
  17163. }
  17164. }
  17165. if (! ok)
  17166. return;
  17167. ok = false;
  17168. lengthInSamples = GetMediaDecodeDuration (media);
  17169. usesFloatingPointData = false;
  17170. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  17171. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  17172. / GetMediaTimeScale (media);
  17173. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  17174. unsigned long output_layout_size;
  17175. err = MovieAudioExtractionGetPropertyInfo (extractor,
  17176. kQTPropertyClass_MovieAudioExtraction_Audio,
  17177. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17178. 0, &output_layout_size, 0);
  17179. if (err != noErr)
  17180. return;
  17181. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  17182. qt_audio_channel_layout.calloc (output_layout_size, 1);
  17183. err = MovieAudioExtractionGetProperty (extractor,
  17184. kQTPropertyClass_MovieAudioExtraction_Audio,
  17185. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17186. output_layout_size, qt_audio_channel_layout, 0);
  17187. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  17188. err = MovieAudioExtractionSetProperty (extractor,
  17189. kQTPropertyClass_MovieAudioExtraction_Audio,
  17190. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17191. output_layout_size,
  17192. qt_audio_channel_layout);
  17193. err = MovieAudioExtractionGetProperty (extractor,
  17194. kQTPropertyClass_MovieAudioExtraction_Audio,
  17195. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17196. sizeof (inputStreamDesc),
  17197. &inputStreamDesc, 0);
  17198. if (err != noErr)
  17199. return;
  17200. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  17201. | kAudioFormatFlagIsPacked
  17202. | kAudioFormatFlagsNativeEndian;
  17203. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  17204. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  17205. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  17206. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  17207. err = MovieAudioExtractionSetProperty (extractor,
  17208. kQTPropertyClass_MovieAudioExtraction_Audio,
  17209. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17210. sizeof (inputStreamDesc),
  17211. &inputStreamDesc);
  17212. if (err != noErr)
  17213. return;
  17214. Boolean allChannelsDiscrete = false;
  17215. err = MovieAudioExtractionSetProperty (extractor,
  17216. kQTPropertyClass_MovieAudioExtraction_Movie,
  17217. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  17218. sizeof (allChannelsDiscrete),
  17219. &allChannelsDiscrete);
  17220. if (err != noErr)
  17221. return;
  17222. bufferList->mNumberBuffers = 1;
  17223. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  17224. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  17225. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  17226. sampleRate = inputStreamDesc.mSampleRate;
  17227. bitsPerSample = 16;
  17228. numChannels = inputStreamDesc.mChannelsPerFrame;
  17229. detachThread();
  17230. ok = true;
  17231. }
  17232. ~QTAudioReader()
  17233. {
  17234. if (dataHandle != 0)
  17235. DisposeHandle (dataHandle);
  17236. if (extractor != 0)
  17237. {
  17238. MovieAudioExtractionEnd (extractor);
  17239. extractor = 0;
  17240. }
  17241. checkThreadIsAttached();
  17242. DisposeMovie (movie);
  17243. juce_free (bufferList->mBuffers[0].mData);
  17244. #if JUCE_MAC
  17245. ExitMoviesOnThread ();
  17246. #endif
  17247. }
  17248. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17249. int64 startSampleInFile, int numSamples)
  17250. {
  17251. checkThreadIsAttached();
  17252. while (numSamples > 0)
  17253. {
  17254. if (! loadFrame ((int) startSampleInFile))
  17255. return false;
  17256. const int numToDo = jmin (numSamples, samplesPerFrame);
  17257. for (int j = numDestChannels; --j >= 0;)
  17258. {
  17259. if (destSamples[j] != 0)
  17260. {
  17261. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  17262. for (int i = 0; i < numToDo; ++i)
  17263. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  17264. }
  17265. }
  17266. startOffsetInDestBuffer += numToDo;
  17267. startSampleInFile += numToDo;
  17268. numSamples -= numToDo;
  17269. }
  17270. detachThread();
  17271. return true;
  17272. }
  17273. bool loadFrame (const int sampleNum)
  17274. {
  17275. if (lastSampleRead != sampleNum)
  17276. {
  17277. TimeRecord time;
  17278. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  17279. time.base = 0;
  17280. time.value.hi = 0;
  17281. time.value.lo = (UInt32) sampleNum;
  17282. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  17283. kQTPropertyClass_MovieAudioExtraction_Movie,
  17284. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  17285. sizeof (time), &time);
  17286. if (err != noErr)
  17287. return false;
  17288. }
  17289. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  17290. UInt32 outFlags = 0;
  17291. UInt32 actualNumSamples = samplesPerFrame;
  17292. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  17293. bufferList, &outFlags);
  17294. lastSampleRead = sampleNum + samplesPerFrame;
  17295. return err == noErr;
  17296. }
  17297. juce_UseDebuggingNewOperator
  17298. bool ok;
  17299. private:
  17300. Movie movie;
  17301. Media media;
  17302. Track track;
  17303. const int trackNum;
  17304. double trackUnitsPerFrame;
  17305. int samplesPerFrame;
  17306. int lastSampleRead;
  17307. Thread::ThreadID lastThreadId;
  17308. MovieAudioExtractionRef extractor;
  17309. AudioStreamBasicDescription inputStreamDesc;
  17310. HeapBlock <AudioBufferList> bufferList;
  17311. Handle dataHandle;
  17312. void checkThreadIsAttached()
  17313. {
  17314. #if JUCE_MAC
  17315. if (Thread::getCurrentThreadId() != lastThreadId)
  17316. EnterMoviesOnThread (0);
  17317. AttachMovieToCurrentThread (movie);
  17318. #endif
  17319. }
  17320. void detachThread()
  17321. {
  17322. #if JUCE_MAC
  17323. DetachMovieFromCurrentThread (movie);
  17324. #endif
  17325. }
  17326. };
  17327. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17328. : AudioFormat (TRANS (quickTimeFormatName), (const tchar**) quickTimeExtensions)
  17329. {
  17330. }
  17331. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17332. {
  17333. }
  17334. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17335. {
  17336. return Array<int>();
  17337. }
  17338. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17339. {
  17340. return Array<int>();
  17341. }
  17342. bool QuickTimeAudioFormat::canDoStereo()
  17343. {
  17344. return true;
  17345. }
  17346. bool QuickTimeAudioFormat::canDoMono()
  17347. {
  17348. return true;
  17349. }
  17350. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17351. const bool deleteStreamIfOpeningFails)
  17352. {
  17353. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17354. if (r->ok)
  17355. return r.release();
  17356. if (! deleteStreamIfOpeningFails)
  17357. r->input = 0;
  17358. return 0;
  17359. }
  17360. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17361. double /*sampleRateToUse*/,
  17362. unsigned int /*numberOfChannels*/,
  17363. int /*bitsPerSample*/,
  17364. const StringPairArray& /*metadataValues*/,
  17365. int /*qualityOptionIndex*/)
  17366. {
  17367. jassertfalse // not yet implemented!
  17368. return 0;
  17369. }
  17370. END_JUCE_NAMESPACE
  17371. #endif
  17372. /*** End of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17373. /*** Start of inlined file: juce_WavAudioFormat.cpp ***/
  17374. BEGIN_JUCE_NAMESPACE
  17375. static const char* const wavFormatName = "WAV file";
  17376. static const tchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17377. const tchar* const WavAudioFormat::bwavDescription = T("bwav description");
  17378. const tchar* const WavAudioFormat::bwavOriginator = T("bwav originator");
  17379. const tchar* const WavAudioFormat::bwavOriginatorRef = T("bwav originator ref");
  17380. const tchar* const WavAudioFormat::bwavOriginationDate = T("bwav origination date");
  17381. const tchar* const WavAudioFormat::bwavOriginationTime = T("bwav origination time");
  17382. const tchar* const WavAudioFormat::bwavTimeReference = T("bwav time reference");
  17383. const tchar* const WavAudioFormat::bwavCodingHistory = T("bwav coding history");
  17384. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17385. const String& originator,
  17386. const String& originatorRef,
  17387. const Time& date,
  17388. const int64 timeReferenceSamples,
  17389. const String& codingHistory)
  17390. {
  17391. StringPairArray m;
  17392. m.set (bwavDescription, description);
  17393. m.set (bwavOriginator, originator);
  17394. m.set (bwavOriginatorRef, originatorRef);
  17395. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17396. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17397. m.set (bwavTimeReference, String (timeReferenceSamples));
  17398. m.set (bwavCodingHistory, codingHistory);
  17399. return m;
  17400. }
  17401. #if JUCE_MSVC
  17402. #pragma pack (push, 1)
  17403. #define PACKED
  17404. #elif JUCE_GCC
  17405. #define PACKED __attribute__((packed))
  17406. #else
  17407. #define PACKED
  17408. #endif
  17409. struct BWAVChunk
  17410. {
  17411. char description [256];
  17412. char originator [32];
  17413. char originatorRef [32];
  17414. char originationDate [10];
  17415. char originationTime [8];
  17416. uint32 timeRefLow;
  17417. uint32 timeRefHigh;
  17418. uint16 version;
  17419. uint8 umid[64];
  17420. uint8 reserved[190];
  17421. char codingHistory[1];
  17422. void copyTo (StringPairArray& values) const
  17423. {
  17424. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17425. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17426. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17427. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17428. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17429. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17430. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17431. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17432. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17433. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17434. }
  17435. static MemoryBlock createFrom (const StringPairArray& values)
  17436. {
  17437. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8();
  17438. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17439. data.fillWith (0);
  17440. BWAVChunk* b = (BWAVChunk*) data.getData();
  17441. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17442. // as they get called in the right order..
  17443. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17444. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17445. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17446. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17447. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17448. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17449. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17450. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17451. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory, 0x7fffffff);
  17452. if (b->description[0] != 0
  17453. || b->originator[0] != 0
  17454. || b->originationDate[0] != 0
  17455. || b->originationTime[0] != 0
  17456. || b->codingHistory[0] != 0
  17457. || time != 0)
  17458. {
  17459. return data;
  17460. }
  17461. return MemoryBlock();
  17462. }
  17463. } PACKED;
  17464. struct SMPLChunk
  17465. {
  17466. struct SampleLoop
  17467. {
  17468. uint32 identifier;
  17469. uint32 type;
  17470. uint32 start;
  17471. uint32 end;
  17472. uint32 fraction;
  17473. uint32 playCount;
  17474. } PACKED;
  17475. uint32 manufacturer;
  17476. uint32 product;
  17477. uint32 samplePeriod;
  17478. uint32 midiUnityNote;
  17479. uint32 midiPitchFraction;
  17480. uint32 smpteFormat;
  17481. uint32 smpteOffset;
  17482. uint32 numSampleLoops;
  17483. uint32 samplerData;
  17484. SampleLoop loops[1];
  17485. void copyTo (StringPairArray& values, const int totalSize) const
  17486. {
  17487. values.set ("Manufacturer", String (ByteOrder::swapIfBigEndian (manufacturer)));
  17488. values.set ("Product", String (ByteOrder::swapIfBigEndian (product)));
  17489. values.set ("SamplePeriod", String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17490. values.set ("MidiUnityNote", String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17491. values.set ("MidiPitchFraction", String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17492. values.set ("SmpteFormat", String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17493. values.set ("SmpteOffset", String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17494. values.set ("NumSampleLoops", String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17495. values.set ("SamplerData", String (ByteOrder::swapIfBigEndian (samplerData)));
  17496. for (uint32 i = 0; i < numSampleLoops; ++i)
  17497. {
  17498. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17499. break;
  17500. const String prefix ("Loop" + String(i));
  17501. values.set (prefix + "Identifier", String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17502. values.set (prefix + "Type", String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17503. values.set (prefix + "Start", String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17504. values.set (prefix + "End", String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17505. values.set (prefix + "Fraction", String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17506. values.set (prefix + "PlayCount", String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17507. }
  17508. }
  17509. static MemoryBlock createFrom (const StringPairArray& values)
  17510. {
  17511. const int numLoops = jmin (64, values.getValue ("NumSampleLoops", "0").getIntValue());
  17512. if (numLoops <= 0)
  17513. return MemoryBlock();
  17514. const size_t sizeNeeded = sizeof (SMPLChunk) + (numLoops - 1) * sizeof (SampleLoop);
  17515. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17516. data.fillWith (0);
  17517. SMPLChunk* s = (SMPLChunk*) data.getData();
  17518. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17519. // as they get called in the right order..
  17520. s->manufacturer = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Manufacturer", "0").getIntValue());
  17521. s->product = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Product", "0").getIntValue());
  17522. s->samplePeriod = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplePeriod", "0").getIntValue());
  17523. s->midiUnityNote = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiUnityNote", "60").getIntValue());
  17524. s->midiPitchFraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiPitchFraction", "0").getIntValue());
  17525. s->smpteFormat = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteFormat", "0").getIntValue());
  17526. s->smpteOffset = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteOffset", "0").getIntValue());
  17527. s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops);
  17528. s->samplerData = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplerData", "0").getIntValue());
  17529. for (int i = 0; i < numLoops; ++i)
  17530. {
  17531. const String prefix ("Loop" + String(i));
  17532. s->loops[i].identifier = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Identifier", "0").getIntValue());
  17533. s->loops[i].type = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Type", "0").getIntValue());
  17534. s->loops[i].start = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Start", "0").getIntValue());
  17535. s->loops[i].end = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "End", "0").getIntValue());
  17536. s->loops[i].fraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Fraction", "0").getIntValue());
  17537. s->loops[i].playCount = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "PlayCount", "0").getIntValue());
  17538. }
  17539. return data;
  17540. }
  17541. } PACKED;
  17542. struct ExtensibleWavSubFormat
  17543. {
  17544. uint32 data1;
  17545. uint16 data2;
  17546. uint16 data3;
  17547. uint8 data4[8];
  17548. } PACKED;
  17549. #if JUCE_MSVC
  17550. #pragma pack (pop)
  17551. #endif
  17552. #undef PACKED
  17553. class WavAudioFormatReader : public AudioFormatReader
  17554. {
  17555. int bytesPerFrame;
  17556. int64 dataChunkStart, dataLength;
  17557. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17558. WavAudioFormatReader (const WavAudioFormatReader&);
  17559. WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17560. public:
  17561. int64 bwavChunkStart, bwavSize;
  17562. WavAudioFormatReader (InputStream* const in)
  17563. : AudioFormatReader (in, TRANS (wavFormatName)),
  17564. dataLength (0),
  17565. bwavChunkStart (0),
  17566. bwavSize (0)
  17567. {
  17568. if (input->readInt() == chunkName ("RIFF"))
  17569. {
  17570. const uint32 len = (uint32) input->readInt();
  17571. const int64 end = input->getPosition() + len;
  17572. bool hasGotType = false;
  17573. bool hasGotData = false;
  17574. if (input->readInt() == chunkName ("WAVE"))
  17575. {
  17576. while (input->getPosition() < end
  17577. && ! input->isExhausted())
  17578. {
  17579. const int chunkType = input->readInt();
  17580. uint32 length = (uint32) input->readInt();
  17581. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17582. if (chunkType == chunkName ("fmt "))
  17583. {
  17584. // read the format chunk
  17585. const unsigned short format = input->readShort();
  17586. const short numChans = input->readShort();
  17587. sampleRate = input->readInt();
  17588. const int bytesPerSec = input->readInt();
  17589. numChannels = numChans;
  17590. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17591. bitsPerSample = 8 * bytesPerFrame / numChans;
  17592. if (format == 3)
  17593. {
  17594. usesFloatingPointData = true;
  17595. }
  17596. else if (format == 0xfffe /*WAVE_FORMAT_EXTENSIBLE*/)
  17597. {
  17598. if (length < 40) // too short
  17599. {
  17600. bytesPerFrame = 0;
  17601. }
  17602. else
  17603. {
  17604. input->skipNextBytes (12); // skip over blockAlign, bitsPerSample and speakerPosition mask
  17605. ExtensibleWavSubFormat subFormat;
  17606. subFormat.data1 = input->readInt();
  17607. subFormat.data2 = input->readShort();
  17608. subFormat.data3 = input->readShort();
  17609. input->read (subFormat.data4, sizeof (subFormat.data4));
  17610. const ExtensibleWavSubFormat pcmFormat
  17611. = { 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
  17612. if (memcmp (&subFormat, &pcmFormat, sizeof (subFormat)) != 0)
  17613. {
  17614. const ExtensibleWavSubFormat ambisonicFormat
  17615. = { 0x00000001, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 } };
  17616. if (memcmp (&subFormat, &ambisonicFormat, sizeof (subFormat)) != 0)
  17617. bytesPerFrame = 0;
  17618. }
  17619. }
  17620. }
  17621. else if (format != 1)
  17622. {
  17623. bytesPerFrame = 0;
  17624. }
  17625. hasGotType = true;
  17626. }
  17627. else if (chunkType == chunkName ("data"))
  17628. {
  17629. // get the data chunk's position
  17630. dataLength = length;
  17631. dataChunkStart = input->getPosition();
  17632. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17633. hasGotData = true;
  17634. }
  17635. else if (chunkType == chunkName ("bext"))
  17636. {
  17637. bwavChunkStart = input->getPosition();
  17638. bwavSize = length;
  17639. // Broadcast-wav extension chunk..
  17640. HeapBlock <BWAVChunk> bwav;
  17641. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17642. input->read (bwav, length);
  17643. bwav->copyTo (metadataValues);
  17644. }
  17645. else if (chunkType == chunkName ("smpl"))
  17646. {
  17647. HeapBlock <SMPLChunk> smpl;
  17648. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17649. input->read (smpl, length);
  17650. smpl->copyTo (metadataValues, length);
  17651. }
  17652. else if (chunkEnd <= input->getPosition())
  17653. {
  17654. break;
  17655. }
  17656. input->setPosition (chunkEnd);
  17657. }
  17658. }
  17659. }
  17660. }
  17661. ~WavAudioFormatReader()
  17662. {
  17663. }
  17664. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17665. int64 startSampleInFile, int numSamples)
  17666. {
  17667. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17668. if (samplesAvailable < numSamples)
  17669. {
  17670. for (int i = numDestChannels; --i >= 0;)
  17671. if (destSamples[i] != 0)
  17672. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17673. numSamples = (int) samplesAvailable;
  17674. }
  17675. if (numSamples <= 0)
  17676. return true;
  17677. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17678. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17679. char tempBuffer [tempBufSize];
  17680. while (numSamples > 0)
  17681. {
  17682. int* left = destSamples[0];
  17683. if (left != 0)
  17684. left += startOffsetInDestBuffer;
  17685. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17686. if (right != 0)
  17687. right += startOffsetInDestBuffer;
  17688. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17689. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17690. if (bytesRead < numThisTime * bytesPerFrame)
  17691. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17692. if (bitsPerSample == 16)
  17693. {
  17694. const short* src = (const short*) tempBuffer;
  17695. if (numChannels > 1)
  17696. {
  17697. if (left == 0)
  17698. {
  17699. for (int i = numThisTime; --i >= 0;)
  17700. {
  17701. ++src;
  17702. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17703. }
  17704. }
  17705. else if (right == 0)
  17706. {
  17707. for (int i = numThisTime; --i >= 0;)
  17708. {
  17709. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17710. ++src;
  17711. }
  17712. }
  17713. else
  17714. {
  17715. for (int i = numThisTime; --i >= 0;)
  17716. {
  17717. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17718. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17719. }
  17720. }
  17721. }
  17722. else
  17723. {
  17724. for (int i = numThisTime; --i >= 0;)
  17725. {
  17726. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17727. }
  17728. }
  17729. }
  17730. else if (bitsPerSample == 24)
  17731. {
  17732. const char* src = (const char*) tempBuffer;
  17733. if (numChannels > 1)
  17734. {
  17735. if (left == 0)
  17736. {
  17737. for (int i = numThisTime; --i >= 0;)
  17738. {
  17739. src += 3;
  17740. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17741. src += 3;
  17742. }
  17743. }
  17744. else if (right == 0)
  17745. {
  17746. for (int i = numThisTime; --i >= 0;)
  17747. {
  17748. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17749. src += 6;
  17750. }
  17751. }
  17752. else
  17753. {
  17754. for (int i = 0; i < numThisTime; ++i)
  17755. {
  17756. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17757. src += 3;
  17758. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17759. src += 3;
  17760. }
  17761. }
  17762. }
  17763. else
  17764. {
  17765. for (int i = 0; i < numThisTime; ++i)
  17766. {
  17767. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17768. src += 3;
  17769. }
  17770. }
  17771. }
  17772. else if (bitsPerSample == 32)
  17773. {
  17774. const unsigned int* src = (const unsigned int*) tempBuffer;
  17775. unsigned int* l = (unsigned int*) left;
  17776. unsigned int* r = (unsigned int*) right;
  17777. if (numChannels > 1)
  17778. {
  17779. if (l == 0)
  17780. {
  17781. for (int i = numThisTime; --i >= 0;)
  17782. {
  17783. ++src;
  17784. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17785. }
  17786. }
  17787. else if (r == 0)
  17788. {
  17789. for (int i = numThisTime; --i >= 0;)
  17790. {
  17791. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17792. ++src;
  17793. }
  17794. }
  17795. else
  17796. {
  17797. for (int i = numThisTime; --i >= 0;)
  17798. {
  17799. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17800. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17801. }
  17802. }
  17803. }
  17804. else
  17805. {
  17806. for (int i = numThisTime; --i >= 0;)
  17807. {
  17808. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17809. }
  17810. }
  17811. left = (int*)l;
  17812. right = (int*)r;
  17813. }
  17814. else if (bitsPerSample == 8)
  17815. {
  17816. const unsigned char* src = (const unsigned char*) tempBuffer;
  17817. if (numChannels > 1)
  17818. {
  17819. if (left == 0)
  17820. {
  17821. for (int i = numThisTime; --i >= 0;)
  17822. {
  17823. ++src;
  17824. *right++ = ((int) *src++ - 128) << 24;
  17825. }
  17826. }
  17827. else if (right == 0)
  17828. {
  17829. for (int i = numThisTime; --i >= 0;)
  17830. {
  17831. *left++ = ((int) *src++ - 128) << 24;
  17832. ++src;
  17833. }
  17834. }
  17835. else
  17836. {
  17837. for (int i = numThisTime; --i >= 0;)
  17838. {
  17839. *left++ = ((int) *src++ - 128) << 24;
  17840. *right++ = ((int) *src++ - 128) << 24;
  17841. }
  17842. }
  17843. }
  17844. else
  17845. {
  17846. for (int i = numThisTime; --i >= 0;)
  17847. {
  17848. *left++ = ((int)*src++ - 128) << 24;
  17849. }
  17850. }
  17851. }
  17852. startOffsetInDestBuffer += numThisTime;
  17853. numSamples -= numThisTime;
  17854. }
  17855. if (numSamples > 0)
  17856. {
  17857. for (int i = numDestChannels; --i >= 0;)
  17858. if (destSamples[i] != 0)
  17859. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17860. sizeof (int) * numSamples);
  17861. }
  17862. return true;
  17863. }
  17864. juce_UseDebuggingNewOperator
  17865. };
  17866. class WavAudioFormatWriter : public AudioFormatWriter
  17867. {
  17868. MemoryBlock tempBlock, bwavChunk, smplChunk;
  17869. uint32 lengthInSamples, bytesWritten;
  17870. int64 headerPosition;
  17871. bool writeFailed;
  17872. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17873. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17874. WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17875. void writeHeader()
  17876. {
  17877. const bool seekedOk = output->setPosition (headerPosition);
  17878. (void) seekedOk;
  17879. // if this fails, you've given it an output stream that can't seek! It needs
  17880. // to be able to seek back to write the header
  17881. jassert (seekedOk);
  17882. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17883. output->writeInt (chunkName ("RIFF"));
  17884. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17885. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17886. output->writeInt (chunkName ("WAVE"));
  17887. output->writeInt (chunkName ("fmt "));
  17888. output->writeInt (16);
  17889. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17890. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17891. output->writeShort ((short) numChannels);
  17892. output->writeInt ((int) sampleRate);
  17893. output->writeInt (bytesPerFrame * (int) sampleRate);
  17894. output->writeShort ((short) bytesPerFrame);
  17895. output->writeShort ((short) bitsPerSample);
  17896. if (bwavChunk.getSize() > 0)
  17897. {
  17898. output->writeInt (chunkName ("bext"));
  17899. output->writeInt ((int) bwavChunk.getSize());
  17900. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17901. }
  17902. if (smplChunk.getSize() > 0)
  17903. {
  17904. output->writeInt (chunkName ("smpl"));
  17905. output->writeInt ((int) smplChunk.getSize());
  17906. output->write (smplChunk.getData(), (int) smplChunk.getSize());
  17907. }
  17908. output->writeInt (chunkName ("data"));
  17909. output->writeInt (lengthInSamples * bytesPerFrame);
  17910. usesFloatingPointData = (bitsPerSample == 32);
  17911. }
  17912. public:
  17913. WavAudioFormatWriter (OutputStream* const out,
  17914. const double sampleRate_,
  17915. const unsigned int numChannels_,
  17916. const int bits,
  17917. const StringPairArray& metadataValues)
  17918. : AudioFormatWriter (out,
  17919. TRANS (wavFormatName),
  17920. sampleRate_,
  17921. numChannels_,
  17922. bits),
  17923. lengthInSamples (0),
  17924. bytesWritten (0),
  17925. writeFailed (false)
  17926. {
  17927. if (metadataValues.size() > 0)
  17928. {
  17929. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17930. smplChunk = SMPLChunk::createFrom (metadataValues);
  17931. }
  17932. headerPosition = out->getPosition();
  17933. writeHeader();
  17934. }
  17935. ~WavAudioFormatWriter()
  17936. {
  17937. writeHeader();
  17938. }
  17939. bool write (const int** data, int numSamples)
  17940. {
  17941. if (writeFailed)
  17942. return false;
  17943. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17944. tempBlock.ensureSize (bytes, false);
  17945. char* buffer = (char*) tempBlock.getData();
  17946. const int* left = data[0];
  17947. const int* right = data[1];
  17948. if (right == 0)
  17949. right = left;
  17950. if (bitsPerSample == 16)
  17951. {
  17952. short* b = (short*) buffer;
  17953. if (numChannels > 1)
  17954. {
  17955. for (int i = numSamples; --i >= 0;)
  17956. {
  17957. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17958. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  17959. }
  17960. }
  17961. else
  17962. {
  17963. for (int i = numSamples; --i >= 0;)
  17964. {
  17965. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17966. }
  17967. }
  17968. }
  17969. else if (bitsPerSample == 24)
  17970. {
  17971. char* b = (char*) buffer;
  17972. if (numChannels > 1)
  17973. {
  17974. for (int i = numSamples; --i >= 0;)
  17975. {
  17976. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17977. b += 3;
  17978. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  17979. b += 3;
  17980. }
  17981. }
  17982. else
  17983. {
  17984. for (int i = numSamples; --i >= 0;)
  17985. {
  17986. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17987. b += 3;
  17988. }
  17989. }
  17990. }
  17991. else if (bitsPerSample == 32)
  17992. {
  17993. unsigned int* b = (unsigned int*) buffer;
  17994. if (numChannels > 1)
  17995. {
  17996. for (int i = numSamples; --i >= 0;)
  17997. {
  17998. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17999. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  18000. }
  18001. }
  18002. else
  18003. {
  18004. for (int i = numSamples; --i >= 0;)
  18005. {
  18006. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  18007. }
  18008. }
  18009. }
  18010. else if (bitsPerSample == 8)
  18011. {
  18012. unsigned char* b = (unsigned char*) buffer;
  18013. if (numChannels > 1)
  18014. {
  18015. for (int i = numSamples; --i >= 0;)
  18016. {
  18017. *b++ = (unsigned char) (128 + (*left++ >> 24));
  18018. *b++ = (unsigned char) (128 + (*right++ >> 24));
  18019. }
  18020. }
  18021. else
  18022. {
  18023. for (int i = numSamples; --i >= 0;)
  18024. {
  18025. *b++ = (unsigned char) (128 + (*left++ >> 24));
  18026. }
  18027. }
  18028. }
  18029. if (bytesWritten + bytes >= (uint32) 0xfff00000
  18030. || ! output->write (buffer, bytes))
  18031. {
  18032. // failed to write to disk, so let's try writing the header.
  18033. // If it's just run out of disk space, then if it does manage
  18034. // to write the header, we'll still have a useable file..
  18035. writeHeader();
  18036. writeFailed = true;
  18037. return false;
  18038. }
  18039. else
  18040. {
  18041. bytesWritten += bytes;
  18042. lengthInSamples += numSamples;
  18043. return true;
  18044. }
  18045. }
  18046. juce_UseDebuggingNewOperator
  18047. };
  18048. WavAudioFormat::WavAudioFormat()
  18049. : AudioFormat (TRANS (wavFormatName), (const tchar**) wavExtensions)
  18050. {
  18051. }
  18052. WavAudioFormat::~WavAudioFormat()
  18053. {
  18054. }
  18055. const Array <int> WavAudioFormat::getPossibleSampleRates()
  18056. {
  18057. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  18058. return Array <int> (rates);
  18059. }
  18060. const Array <int> WavAudioFormat::getPossibleBitDepths()
  18061. {
  18062. const int depths[] = { 8, 16, 24, 32, 0 };
  18063. return Array <int> (depths);
  18064. }
  18065. bool WavAudioFormat::canDoStereo()
  18066. {
  18067. return true;
  18068. }
  18069. bool WavAudioFormat::canDoMono()
  18070. {
  18071. return true;
  18072. }
  18073. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  18074. const bool deleteStreamIfOpeningFails)
  18075. {
  18076. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  18077. if (r->sampleRate != 0)
  18078. return r.release();
  18079. if (! deleteStreamIfOpeningFails)
  18080. r->input = 0;
  18081. return 0;
  18082. }
  18083. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  18084. double sampleRate,
  18085. unsigned int numChannels,
  18086. int bitsPerSample,
  18087. const StringPairArray& metadataValues,
  18088. int /*qualityOptionIndex*/)
  18089. {
  18090. if (getPossibleBitDepths().contains (bitsPerSample))
  18091. {
  18092. return new WavAudioFormatWriter (out,
  18093. sampleRate,
  18094. numChannels,
  18095. bitsPerSample,
  18096. metadataValues);
  18097. }
  18098. return 0;
  18099. }
  18100. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  18101. {
  18102. TemporaryFile tempFile (file);
  18103. WavAudioFormat wav;
  18104. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  18105. if (reader != 0)
  18106. {
  18107. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  18108. if (outStream != 0)
  18109. {
  18110. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  18111. reader->numChannels, reader->bitsPerSample,
  18112. metadata, 0));
  18113. if (writer != 0)
  18114. {
  18115. outStream.release();
  18116. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  18117. writer = 0;
  18118. reader = 0;
  18119. return ok && tempFile.overwriteTargetFileWithTemporary();
  18120. }
  18121. }
  18122. }
  18123. return false;
  18124. }
  18125. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  18126. {
  18127. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  18128. if (reader != 0)
  18129. {
  18130. const int64 bwavPos = reader->bwavChunkStart;
  18131. const int64 bwavSize = reader->bwavSize;
  18132. reader = 0;
  18133. if (bwavSize > 0)
  18134. {
  18135. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  18136. if (chunk.getSize() <= (size_t) bwavSize)
  18137. {
  18138. // the new one will fit in the space available, so write it directly..
  18139. const int64 oldSize = wavFile.getSize();
  18140. {
  18141. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  18142. out->setPosition (bwavPos);
  18143. out->write (chunk.getData(), (int) chunk.getSize());
  18144. out->setPosition (oldSize);
  18145. }
  18146. jassert (wavFile.getSize() == oldSize);
  18147. return true;
  18148. }
  18149. }
  18150. }
  18151. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  18152. }
  18153. END_JUCE_NAMESPACE
  18154. /*** End of inlined file: juce_WavAudioFormat.cpp ***/
  18155. /*** Start of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18156. BEGIN_JUCE_NAMESPACE
  18157. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  18158. const bool deleteReaderWhenThisIsDeleted)
  18159. : reader (reader_),
  18160. deleteReader (deleteReaderWhenThisIsDeleted),
  18161. nextPlayPos (0),
  18162. looping (false)
  18163. {
  18164. jassert (reader != 0);
  18165. }
  18166. AudioFormatReaderSource::~AudioFormatReaderSource()
  18167. {
  18168. releaseResources();
  18169. if (deleteReader)
  18170. delete reader;
  18171. }
  18172. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  18173. {
  18174. nextPlayPos = newPosition;
  18175. }
  18176. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  18177. {
  18178. looping = shouldLoop;
  18179. }
  18180. int AudioFormatReaderSource::getNextReadPosition() const
  18181. {
  18182. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  18183. : nextPlayPos;
  18184. }
  18185. int AudioFormatReaderSource::getTotalLength() const
  18186. {
  18187. return (int) reader->lengthInSamples;
  18188. }
  18189. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  18190. double /*sampleRate*/)
  18191. {
  18192. }
  18193. void AudioFormatReaderSource::releaseResources()
  18194. {
  18195. }
  18196. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18197. {
  18198. if (info.numSamples > 0)
  18199. {
  18200. const int start = nextPlayPos;
  18201. if (looping)
  18202. {
  18203. const int newStart = start % (int) reader->lengthInSamples;
  18204. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  18205. if (newEnd > newStart)
  18206. {
  18207. info.buffer->readFromAudioReader (reader,
  18208. info.startSample,
  18209. newEnd - newStart,
  18210. newStart,
  18211. true, true);
  18212. }
  18213. else
  18214. {
  18215. const int endSamps = (int) reader->lengthInSamples - newStart;
  18216. info.buffer->readFromAudioReader (reader,
  18217. info.startSample,
  18218. endSamps,
  18219. newStart,
  18220. true, true);
  18221. info.buffer->readFromAudioReader (reader,
  18222. info.startSample + endSamps,
  18223. newEnd,
  18224. 0,
  18225. true, true);
  18226. }
  18227. nextPlayPos = newEnd;
  18228. }
  18229. else
  18230. {
  18231. info.buffer->readFromAudioReader (reader,
  18232. info.startSample,
  18233. info.numSamples,
  18234. start,
  18235. true, true);
  18236. nextPlayPos += info.numSamples;
  18237. }
  18238. }
  18239. }
  18240. END_JUCE_NAMESPACE
  18241. /*** End of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18242. /*** Start of inlined file: juce_AudioSourcePlayer.cpp ***/
  18243. BEGIN_JUCE_NAMESPACE
  18244. AudioSourcePlayer::AudioSourcePlayer()
  18245. : source (0),
  18246. sampleRate (0),
  18247. bufferSize (0),
  18248. tempBuffer (2, 8),
  18249. lastGain (1.0f),
  18250. gain (1.0f)
  18251. {
  18252. }
  18253. AudioSourcePlayer::~AudioSourcePlayer()
  18254. {
  18255. setSource (0);
  18256. }
  18257. void AudioSourcePlayer::setSource (AudioSource* newSource)
  18258. {
  18259. if (source != newSource)
  18260. {
  18261. AudioSource* const oldSource = source;
  18262. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  18263. newSource->prepareToPlay (bufferSize, sampleRate);
  18264. {
  18265. const ScopedLock sl (readLock);
  18266. source = newSource;
  18267. }
  18268. if (oldSource != 0)
  18269. oldSource->releaseResources();
  18270. }
  18271. }
  18272. void AudioSourcePlayer::setGain (const float newGain) throw()
  18273. {
  18274. gain = newGain;
  18275. }
  18276. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  18277. int totalNumInputChannels,
  18278. float** outputChannelData,
  18279. int totalNumOutputChannels,
  18280. int numSamples)
  18281. {
  18282. // these should have been prepared by audioDeviceAboutToStart()...
  18283. jassert (sampleRate > 0 && bufferSize > 0);
  18284. const ScopedLock sl (readLock);
  18285. if (source != 0)
  18286. {
  18287. AudioSourceChannelInfo info;
  18288. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18289. // messy stuff needed to compact the channels down into an array
  18290. // of non-zero pointers..
  18291. for (i = 0; i < totalNumInputChannels; ++i)
  18292. {
  18293. if (inputChannelData[i] != 0)
  18294. {
  18295. inputChans [numInputs++] = inputChannelData[i];
  18296. if (numInputs >= numElementsInArray (inputChans))
  18297. break;
  18298. }
  18299. }
  18300. for (i = 0; i < totalNumOutputChannels; ++i)
  18301. {
  18302. if (outputChannelData[i] != 0)
  18303. {
  18304. outputChans [numOutputs++] = outputChannelData[i];
  18305. if (numOutputs >= numElementsInArray (outputChans))
  18306. break;
  18307. }
  18308. }
  18309. if (numInputs > numOutputs)
  18310. {
  18311. // if there aren't enough output channels for the number of
  18312. // inputs, we need to create some temporary extra ones (can't
  18313. // use the input data in case it gets written to)
  18314. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18315. false, false, true);
  18316. for (i = 0; i < numOutputs; ++i)
  18317. {
  18318. channels[numActiveChans] = outputChans[i];
  18319. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18320. ++numActiveChans;
  18321. }
  18322. for (i = numOutputs; i < numInputs; ++i)
  18323. {
  18324. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18325. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18326. ++numActiveChans;
  18327. }
  18328. }
  18329. else
  18330. {
  18331. for (i = 0; i < numInputs; ++i)
  18332. {
  18333. channels[numActiveChans] = outputChans[i];
  18334. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18335. ++numActiveChans;
  18336. }
  18337. for (i = numInputs; i < numOutputs; ++i)
  18338. {
  18339. channels[numActiveChans] = outputChans[i];
  18340. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18341. ++numActiveChans;
  18342. }
  18343. }
  18344. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18345. info.buffer = &buffer;
  18346. info.startSample = 0;
  18347. info.numSamples = numSamples;
  18348. source->getNextAudioBlock (info);
  18349. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18350. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18351. lastGain = gain;
  18352. }
  18353. else
  18354. {
  18355. for (int i = 0; i < totalNumOutputChannels; ++i)
  18356. if (outputChannelData[i] != 0)
  18357. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18358. }
  18359. }
  18360. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18361. {
  18362. sampleRate = device->getCurrentSampleRate();
  18363. bufferSize = device->getCurrentBufferSizeSamples();
  18364. zeromem (channels, sizeof (channels));
  18365. if (source != 0)
  18366. source->prepareToPlay (bufferSize, sampleRate);
  18367. }
  18368. void AudioSourcePlayer::audioDeviceStopped()
  18369. {
  18370. if (source != 0)
  18371. source->releaseResources();
  18372. sampleRate = 0.0;
  18373. bufferSize = 0;
  18374. tempBuffer.setSize (2, 8);
  18375. }
  18376. END_JUCE_NAMESPACE
  18377. /*** End of inlined file: juce_AudioSourcePlayer.cpp ***/
  18378. /*** Start of inlined file: juce_AudioTransportSource.cpp ***/
  18379. BEGIN_JUCE_NAMESPACE
  18380. AudioTransportSource::AudioTransportSource()
  18381. : source (0),
  18382. resamplerSource (0),
  18383. bufferingSource (0),
  18384. positionableSource (0),
  18385. masterSource (0),
  18386. gain (1.0f),
  18387. lastGain (1.0f),
  18388. playing (false),
  18389. stopped (true),
  18390. sampleRate (44100.0),
  18391. sourceSampleRate (0.0),
  18392. blockSize (128),
  18393. readAheadBufferSize (0),
  18394. isPrepared (false),
  18395. inputStreamEOF (false)
  18396. {
  18397. }
  18398. AudioTransportSource::~AudioTransportSource()
  18399. {
  18400. setSource (0);
  18401. releaseResources();
  18402. }
  18403. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18404. int readAheadBufferSize_,
  18405. double sourceSampleRateToCorrectFor)
  18406. {
  18407. if (source == newSource)
  18408. {
  18409. if (source == 0)
  18410. return;
  18411. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18412. }
  18413. readAheadBufferSize = readAheadBufferSize_;
  18414. sourceSampleRate = sourceSampleRateToCorrectFor;
  18415. ResamplingAudioSource* newResamplerSource = 0;
  18416. BufferingAudioSource* newBufferingSource = 0;
  18417. PositionableAudioSource* newPositionableSource = 0;
  18418. AudioSource* newMasterSource = 0;
  18419. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18420. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18421. AudioSource* oldMasterSource = masterSource;
  18422. if (newSource != 0)
  18423. {
  18424. newPositionableSource = newSource;
  18425. if (readAheadBufferSize_ > 0)
  18426. newPositionableSource = newBufferingSource
  18427. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18428. newPositionableSource->setNextReadPosition (0);
  18429. if (sourceSampleRateToCorrectFor != 0)
  18430. newMasterSource = newResamplerSource
  18431. = new ResamplingAudioSource (newPositionableSource, false);
  18432. else
  18433. newMasterSource = newPositionableSource;
  18434. if (isPrepared)
  18435. {
  18436. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18437. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18438. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18439. }
  18440. }
  18441. {
  18442. const ScopedLock sl (callbackLock);
  18443. source = newSource;
  18444. resamplerSource = newResamplerSource;
  18445. bufferingSource = newBufferingSource;
  18446. masterSource = newMasterSource;
  18447. positionableSource = newPositionableSource;
  18448. playing = false;
  18449. }
  18450. if (oldMasterSource != 0)
  18451. oldMasterSource->releaseResources();
  18452. }
  18453. void AudioTransportSource::start()
  18454. {
  18455. if ((! playing) && masterSource != 0)
  18456. {
  18457. {
  18458. const ScopedLock sl (callbackLock);
  18459. playing = true;
  18460. stopped = false;
  18461. inputStreamEOF = false;
  18462. }
  18463. sendChangeMessage (this);
  18464. }
  18465. }
  18466. void AudioTransportSource::stop()
  18467. {
  18468. if (playing)
  18469. {
  18470. {
  18471. const ScopedLock sl (callbackLock);
  18472. playing = false;
  18473. }
  18474. int n = 500;
  18475. while (--n >= 0 && ! stopped)
  18476. Thread::sleep (2);
  18477. sendChangeMessage (this);
  18478. }
  18479. }
  18480. void AudioTransportSource::setPosition (double newPosition)
  18481. {
  18482. if (sampleRate > 0.0)
  18483. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18484. }
  18485. double AudioTransportSource::getCurrentPosition() const
  18486. {
  18487. if (sampleRate > 0.0)
  18488. return getNextReadPosition() / sampleRate;
  18489. else
  18490. return 0.0;
  18491. }
  18492. void AudioTransportSource::setNextReadPosition (int newPosition)
  18493. {
  18494. if (positionableSource != 0)
  18495. {
  18496. if (sampleRate > 0 && sourceSampleRate > 0)
  18497. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18498. positionableSource->setNextReadPosition (newPosition);
  18499. }
  18500. }
  18501. int AudioTransportSource::getNextReadPosition() const
  18502. {
  18503. if (positionableSource != 0)
  18504. {
  18505. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18506. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18507. }
  18508. return 0;
  18509. }
  18510. int AudioTransportSource::getTotalLength() const
  18511. {
  18512. const ScopedLock sl (callbackLock);
  18513. if (positionableSource != 0)
  18514. {
  18515. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18516. return roundToInt (positionableSource->getTotalLength() * ratio);
  18517. }
  18518. return 0;
  18519. }
  18520. bool AudioTransportSource::isLooping() const
  18521. {
  18522. const ScopedLock sl (callbackLock);
  18523. return positionableSource != 0
  18524. && positionableSource->isLooping();
  18525. }
  18526. void AudioTransportSource::setGain (const float newGain) throw()
  18527. {
  18528. gain = newGain;
  18529. }
  18530. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18531. double sampleRate_)
  18532. {
  18533. const ScopedLock sl (callbackLock);
  18534. sampleRate = sampleRate_;
  18535. blockSize = samplesPerBlockExpected;
  18536. if (masterSource != 0)
  18537. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18538. if (resamplerSource != 0 && sourceSampleRate != 0)
  18539. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18540. isPrepared = true;
  18541. }
  18542. void AudioTransportSource::releaseResources()
  18543. {
  18544. const ScopedLock sl (callbackLock);
  18545. if (masterSource != 0)
  18546. masterSource->releaseResources();
  18547. isPrepared = false;
  18548. }
  18549. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18550. {
  18551. const ScopedLock sl (callbackLock);
  18552. inputStreamEOF = false;
  18553. if (masterSource != 0 && ! stopped)
  18554. {
  18555. masterSource->getNextAudioBlock (info);
  18556. if (! playing)
  18557. {
  18558. // just stopped playing, so fade out the last block..
  18559. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18560. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18561. if (info.numSamples > 256)
  18562. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18563. }
  18564. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18565. && ! positionableSource->isLooping())
  18566. {
  18567. playing = false;
  18568. inputStreamEOF = true;
  18569. sendChangeMessage (this);
  18570. }
  18571. stopped = ! playing;
  18572. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18573. {
  18574. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18575. lastGain, gain);
  18576. }
  18577. }
  18578. else
  18579. {
  18580. info.clearActiveBufferRegion();
  18581. stopped = true;
  18582. }
  18583. lastGain = gain;
  18584. }
  18585. END_JUCE_NAMESPACE
  18586. /*** End of inlined file: juce_AudioTransportSource.cpp ***/
  18587. /*** Start of inlined file: juce_BufferingAudioSource.cpp ***/
  18588. BEGIN_JUCE_NAMESPACE
  18589. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18590. public Thread,
  18591. private Timer
  18592. {
  18593. public:
  18594. SharedBufferingAudioSourceThread()
  18595. : Thread ("Audio Buffer")
  18596. {
  18597. }
  18598. ~SharedBufferingAudioSourceThread()
  18599. {
  18600. stopThread (10000);
  18601. clearSingletonInstance();
  18602. }
  18603. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18604. void addSource (BufferingAudioSource* source)
  18605. {
  18606. const ScopedLock sl (lock);
  18607. if (! sources.contains ((void*) source))
  18608. {
  18609. sources.add ((void*) source);
  18610. startThread();
  18611. stopTimer();
  18612. }
  18613. notify();
  18614. }
  18615. void removeSource (BufferingAudioSource* source)
  18616. {
  18617. const ScopedLock sl (lock);
  18618. sources.removeValue ((void*) source);
  18619. if (sources.size() == 0)
  18620. startTimer (5000);
  18621. }
  18622. private:
  18623. VoidArray sources;
  18624. CriticalSection lock;
  18625. void run()
  18626. {
  18627. while (! threadShouldExit())
  18628. {
  18629. bool busy = false;
  18630. for (int i = sources.size(); --i >= 0;)
  18631. {
  18632. if (threadShouldExit())
  18633. return;
  18634. const ScopedLock sl (lock);
  18635. BufferingAudioSource* const b = (BufferingAudioSource*) sources[i];
  18636. if (b != 0 && b->readNextBufferChunk())
  18637. busy = true;
  18638. }
  18639. if (! busy)
  18640. wait (500);
  18641. }
  18642. }
  18643. void timerCallback()
  18644. {
  18645. stopTimer();
  18646. if (sources.size() == 0)
  18647. deleteInstance();
  18648. }
  18649. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18650. SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18651. };
  18652. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18653. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18654. const bool deleteSourceWhenDeleted_,
  18655. int numberOfSamplesToBuffer_)
  18656. : source (source_),
  18657. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18658. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18659. buffer (2, 0),
  18660. bufferValidStart (0),
  18661. bufferValidEnd (0),
  18662. nextPlayPos (0),
  18663. wasSourceLooping (false)
  18664. {
  18665. jassert (source_ != 0);
  18666. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18667. // not using a larger buffer..
  18668. }
  18669. BufferingAudioSource::~BufferingAudioSource()
  18670. {
  18671. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18672. if (thread != 0)
  18673. thread->removeSource (this);
  18674. if (deleteSourceWhenDeleted)
  18675. delete source;
  18676. }
  18677. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18678. {
  18679. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18680. sampleRate = sampleRate_;
  18681. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18682. buffer.clear();
  18683. bufferValidStart = 0;
  18684. bufferValidEnd = 0;
  18685. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18686. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18687. buffer.getNumSamples() / 2))
  18688. {
  18689. SharedBufferingAudioSourceThread::getInstance()->notify();
  18690. Thread::sleep (5);
  18691. }
  18692. }
  18693. void BufferingAudioSource::releaseResources()
  18694. {
  18695. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18696. if (thread != 0)
  18697. thread->removeSource (this);
  18698. buffer.setSize (2, 0);
  18699. source->releaseResources();
  18700. }
  18701. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18702. {
  18703. const ScopedLock sl (bufferStartPosLock);
  18704. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18705. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18706. if (validStart == validEnd)
  18707. {
  18708. // total cache miss
  18709. info.clearActiveBufferRegion();
  18710. }
  18711. else
  18712. {
  18713. if (validStart > 0)
  18714. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18715. if (validEnd < info.numSamples)
  18716. info.buffer->clear (info.startSample + validEnd,
  18717. info.numSamples - validEnd); // partial cache miss at end
  18718. if (validStart < validEnd)
  18719. {
  18720. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18721. {
  18722. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18723. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18724. if (startBufferIndex < endBufferIndex)
  18725. {
  18726. info.buffer->copyFrom (chan, info.startSample + validStart,
  18727. buffer,
  18728. chan, startBufferIndex,
  18729. validEnd - validStart);
  18730. }
  18731. else
  18732. {
  18733. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18734. info.buffer->copyFrom (chan, info.startSample + validStart,
  18735. buffer,
  18736. chan, startBufferIndex,
  18737. initialSize);
  18738. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18739. buffer,
  18740. chan, 0,
  18741. (validEnd - validStart) - initialSize);
  18742. }
  18743. }
  18744. }
  18745. nextPlayPos += info.numSamples;
  18746. if (source->isLooping() && nextPlayPos > 0)
  18747. nextPlayPos %= source->getTotalLength();
  18748. }
  18749. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18750. if (thread != 0)
  18751. thread->notify();
  18752. }
  18753. int BufferingAudioSource::getNextReadPosition() const
  18754. {
  18755. return (source->isLooping() && nextPlayPos > 0)
  18756. ? nextPlayPos % source->getTotalLength()
  18757. : nextPlayPos;
  18758. }
  18759. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18760. {
  18761. const ScopedLock sl (bufferStartPosLock);
  18762. nextPlayPos = newPosition;
  18763. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18764. if (thread != 0)
  18765. thread->notify();
  18766. }
  18767. bool BufferingAudioSource::readNextBufferChunk()
  18768. {
  18769. int newBVS, newBVE, sectionToReadStart, sectionToReadEnd;
  18770. {
  18771. const ScopedLock sl (bufferStartPosLock);
  18772. if (wasSourceLooping != isLooping())
  18773. {
  18774. wasSourceLooping = isLooping();
  18775. bufferValidStart = 0;
  18776. bufferValidEnd = 0;
  18777. }
  18778. newBVS = jmax (0, nextPlayPos);
  18779. newBVE = newBVS + buffer.getNumSamples() - 4;
  18780. sectionToReadStart = 0;
  18781. sectionToReadEnd = 0;
  18782. const int maxChunkSize = 2048;
  18783. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18784. {
  18785. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18786. sectionToReadStart = newBVS;
  18787. sectionToReadEnd = newBVE;
  18788. bufferValidStart = 0;
  18789. bufferValidEnd = 0;
  18790. }
  18791. else if (abs (newBVS - bufferValidStart) > 512
  18792. || abs (newBVE - bufferValidEnd) > 512)
  18793. {
  18794. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18795. sectionToReadStart = bufferValidEnd;
  18796. sectionToReadEnd = newBVE;
  18797. bufferValidStart = newBVS;
  18798. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18799. }
  18800. }
  18801. if (sectionToReadStart != sectionToReadEnd)
  18802. {
  18803. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18804. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18805. if (bufferIndexStart < bufferIndexEnd)
  18806. {
  18807. readBufferSection (sectionToReadStart,
  18808. sectionToReadEnd - sectionToReadStart,
  18809. bufferIndexStart);
  18810. }
  18811. else
  18812. {
  18813. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18814. readBufferSection (sectionToReadStart,
  18815. initialSize,
  18816. bufferIndexStart);
  18817. readBufferSection (sectionToReadStart + initialSize,
  18818. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18819. 0);
  18820. }
  18821. const ScopedLock sl2 (bufferStartPosLock);
  18822. bufferValidStart = newBVS;
  18823. bufferValidEnd = newBVE;
  18824. return true;
  18825. }
  18826. else
  18827. {
  18828. return false;
  18829. }
  18830. }
  18831. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18832. {
  18833. if (source->getNextReadPosition() != start)
  18834. source->setNextReadPosition (start);
  18835. AudioSourceChannelInfo info;
  18836. info.buffer = &buffer;
  18837. info.startSample = bufferOffset;
  18838. info.numSamples = length;
  18839. source->getNextAudioBlock (info);
  18840. }
  18841. END_JUCE_NAMESPACE
  18842. /*** End of inlined file: juce_BufferingAudioSource.cpp ***/
  18843. /*** Start of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18844. BEGIN_JUCE_NAMESPACE
  18845. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18846. const bool deleteSourceWhenDeleted_)
  18847. : requiredNumberOfChannels (2),
  18848. source (source_),
  18849. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18850. buffer (2, 16)
  18851. {
  18852. remappedInfo.buffer = &buffer;
  18853. remappedInfo.startSample = 0;
  18854. }
  18855. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18856. {
  18857. if (deleteSourceWhenDeleted)
  18858. delete source;
  18859. }
  18860. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18861. {
  18862. const ScopedLock sl (lock);
  18863. requiredNumberOfChannels = requiredNumberOfChannels_;
  18864. }
  18865. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18866. {
  18867. const ScopedLock sl (lock);
  18868. remappedInputs.clear();
  18869. remappedOutputs.clear();
  18870. }
  18871. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18872. {
  18873. const ScopedLock sl (lock);
  18874. while (remappedInputs.size() < destIndex)
  18875. remappedInputs.add (-1);
  18876. remappedInputs.set (destIndex, sourceIndex);
  18877. }
  18878. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18879. {
  18880. const ScopedLock sl (lock);
  18881. while (remappedOutputs.size() < sourceIndex)
  18882. remappedOutputs.add (-1);
  18883. remappedOutputs.set (sourceIndex, destIndex);
  18884. }
  18885. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18886. {
  18887. const ScopedLock sl (lock);
  18888. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18889. return remappedInputs.getUnchecked (inputChannelIndex);
  18890. return -1;
  18891. }
  18892. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18893. {
  18894. const ScopedLock sl (lock);
  18895. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18896. return remappedOutputs .getUnchecked (outputChannelIndex);
  18897. return -1;
  18898. }
  18899. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18900. {
  18901. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18902. }
  18903. void ChannelRemappingAudioSource::releaseResources()
  18904. {
  18905. source->releaseResources();
  18906. }
  18907. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18908. {
  18909. const ScopedLock sl (lock);
  18910. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18911. const int numChans = bufferToFill.buffer->getNumChannels();
  18912. int i;
  18913. for (i = 0; i < buffer.getNumChannels(); ++i)
  18914. {
  18915. const int remappedChan = getRemappedInputChannel (i);
  18916. if (remappedChan >= 0 && remappedChan < numChans)
  18917. {
  18918. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18919. remappedChan,
  18920. bufferToFill.startSample,
  18921. bufferToFill.numSamples);
  18922. }
  18923. else
  18924. {
  18925. buffer.clear (i, 0, bufferToFill.numSamples);
  18926. }
  18927. }
  18928. remappedInfo.numSamples = bufferToFill.numSamples;
  18929. source->getNextAudioBlock (remappedInfo);
  18930. bufferToFill.clearActiveBufferRegion();
  18931. for (i = 0; i < requiredNumberOfChannels; ++i)
  18932. {
  18933. const int remappedChan = getRemappedOutputChannel (i);
  18934. if (remappedChan >= 0 && remappedChan < numChans)
  18935. {
  18936. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18937. buffer, i, 0, bufferToFill.numSamples);
  18938. }
  18939. }
  18940. }
  18941. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18942. {
  18943. XmlElement* e = new XmlElement (T("MAPPINGS"));
  18944. String ins, outs;
  18945. int i;
  18946. const ScopedLock sl (lock);
  18947. for (i = 0; i < remappedInputs.size(); ++i)
  18948. ins << remappedInputs.getUnchecked(i) << T(' ');
  18949. for (i = 0; i < remappedOutputs.size(); ++i)
  18950. outs << remappedOutputs.getUnchecked(i) << T(' ');
  18951. e->setAttribute (T("inputs"), ins.trimEnd());
  18952. e->setAttribute (T("outputs"), outs.trimEnd());
  18953. return e;
  18954. }
  18955. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  18956. {
  18957. if (e.hasTagName (T("MAPPINGS")))
  18958. {
  18959. const ScopedLock sl (lock);
  18960. clearAllMappings();
  18961. StringArray ins, outs;
  18962. ins.addTokens (e.getStringAttribute (T("inputs")), false);
  18963. outs.addTokens (e.getStringAttribute (T("outputs")), false);
  18964. int i;
  18965. for (i = 0; i < ins.size(); ++i)
  18966. remappedInputs.add (ins[i].getIntValue());
  18967. for (i = 0; i < outs.size(); ++i)
  18968. remappedOutputs.add (outs[i].getIntValue());
  18969. }
  18970. }
  18971. END_JUCE_NAMESPACE
  18972. /*** End of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18973. /*** Start of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18974. BEGIN_JUCE_NAMESPACE
  18975. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  18976. const bool deleteInputWhenDeleted_)
  18977. : input (inputSource),
  18978. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  18979. {
  18980. jassert (inputSource != 0);
  18981. for (int i = 2; --i >= 0;)
  18982. iirFilters.add (new IIRFilter());
  18983. }
  18984. IIRFilterAudioSource::~IIRFilterAudioSource()
  18985. {
  18986. if (deleteInputWhenDeleted)
  18987. delete input;
  18988. }
  18989. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  18990. {
  18991. for (int i = iirFilters.size(); --i >= 0;)
  18992. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  18993. }
  18994. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18995. {
  18996. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18997. for (int i = iirFilters.size(); --i >= 0;)
  18998. iirFilters.getUnchecked(i)->reset();
  18999. }
  19000. void IIRFilterAudioSource::releaseResources()
  19001. {
  19002. input->releaseResources();
  19003. }
  19004. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  19005. {
  19006. input->getNextAudioBlock (bufferToFill);
  19007. const int numChannels = bufferToFill.buffer->getNumChannels();
  19008. while (numChannels > iirFilters.size())
  19009. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  19010. for (int i = 0; i < numChannels; ++i)
  19011. iirFilters.getUnchecked(i)
  19012. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  19013. bufferToFill.numSamples);
  19014. }
  19015. END_JUCE_NAMESPACE
  19016. /*** End of inlined file: juce_IIRFilterAudioSource.cpp ***/
  19017. /*** Start of inlined file: juce_MixerAudioSource.cpp ***/
  19018. BEGIN_JUCE_NAMESPACE
  19019. MixerAudioSource::MixerAudioSource()
  19020. : tempBuffer (2, 0),
  19021. currentSampleRate (0.0),
  19022. bufferSizeExpected (0)
  19023. {
  19024. }
  19025. MixerAudioSource::~MixerAudioSource()
  19026. {
  19027. removeAllInputs();
  19028. }
  19029. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  19030. {
  19031. if (input != 0 && ! inputs.contains (input))
  19032. {
  19033. double localRate;
  19034. int localBufferSize;
  19035. {
  19036. const ScopedLock sl (lock);
  19037. localRate = currentSampleRate;
  19038. localBufferSize = bufferSizeExpected;
  19039. }
  19040. if (localRate != 0.0)
  19041. input->prepareToPlay (localBufferSize, localRate);
  19042. const ScopedLock sl (lock);
  19043. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  19044. inputs.add (input);
  19045. }
  19046. }
  19047. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  19048. {
  19049. if (input != 0)
  19050. {
  19051. int index;
  19052. {
  19053. const ScopedLock sl (lock);
  19054. index = inputs.indexOf ((void*) input);
  19055. if (index >= 0)
  19056. {
  19057. inputsToDelete.shiftBits (index, 1);
  19058. inputs.remove (index);
  19059. }
  19060. }
  19061. if (index >= 0)
  19062. {
  19063. input->releaseResources();
  19064. if (deleteInput)
  19065. delete input;
  19066. }
  19067. }
  19068. }
  19069. void MixerAudioSource::removeAllInputs()
  19070. {
  19071. VoidArray inputsCopy;
  19072. BitArray inputsToDeleteCopy;
  19073. {
  19074. const ScopedLock sl (lock);
  19075. inputsCopy = inputs;
  19076. inputsToDeleteCopy = inputsToDelete;
  19077. }
  19078. for (int i = inputsCopy.size(); --i >= 0;)
  19079. if (inputsToDeleteCopy[i])
  19080. delete (AudioSource*) inputsCopy[i];
  19081. }
  19082. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  19083. {
  19084. tempBuffer.setSize (2, samplesPerBlockExpected);
  19085. const ScopedLock sl (lock);
  19086. currentSampleRate = sampleRate;
  19087. bufferSizeExpected = samplesPerBlockExpected;
  19088. for (int i = inputs.size(); --i >= 0;)
  19089. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  19090. sampleRate);
  19091. }
  19092. void MixerAudioSource::releaseResources()
  19093. {
  19094. const ScopedLock sl (lock);
  19095. for (int i = inputs.size(); --i >= 0;)
  19096. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  19097. tempBuffer.setSize (2, 0);
  19098. currentSampleRate = 0;
  19099. bufferSizeExpected = 0;
  19100. }
  19101. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19102. {
  19103. const ScopedLock sl (lock);
  19104. if (inputs.size() > 0)
  19105. {
  19106. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  19107. if (inputs.size() > 1)
  19108. {
  19109. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  19110. info.buffer->getNumSamples());
  19111. AudioSourceChannelInfo info2;
  19112. info2.buffer = &tempBuffer;
  19113. info2.numSamples = info.numSamples;
  19114. info2.startSample = 0;
  19115. for (int i = 1; i < inputs.size(); ++i)
  19116. {
  19117. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  19118. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  19119. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  19120. }
  19121. }
  19122. }
  19123. else
  19124. {
  19125. info.clearActiveBufferRegion();
  19126. }
  19127. }
  19128. END_JUCE_NAMESPACE
  19129. /*** End of inlined file: juce_MixerAudioSource.cpp ***/
  19130. /*** Start of inlined file: juce_ResamplingAudioSource.cpp ***/
  19131. BEGIN_JUCE_NAMESPACE
  19132. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  19133. const bool deleteInputWhenDeleted_)
  19134. : input (inputSource),
  19135. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  19136. ratio (1.0),
  19137. lastRatio (1.0),
  19138. buffer (2, 0),
  19139. sampsInBuffer (0)
  19140. {
  19141. jassert (input != 0);
  19142. }
  19143. ResamplingAudioSource::~ResamplingAudioSource()
  19144. {
  19145. if (deleteInputWhenDeleted)
  19146. delete input;
  19147. }
  19148. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  19149. {
  19150. jassert (samplesInPerOutputSample > 0);
  19151. const ScopedLock sl (ratioLock);
  19152. ratio = jmax (0.0, samplesInPerOutputSample);
  19153. }
  19154. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  19155. double sampleRate)
  19156. {
  19157. const ScopedLock sl (ratioLock);
  19158. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  19159. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  19160. buffer.clear();
  19161. sampsInBuffer = 0;
  19162. bufferPos = 0;
  19163. subSampleOffset = 0.0;
  19164. createLowPass (ratio);
  19165. resetFilters();
  19166. }
  19167. void ResamplingAudioSource::releaseResources()
  19168. {
  19169. input->releaseResources();
  19170. buffer.setSize (2, 0);
  19171. }
  19172. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19173. {
  19174. const ScopedLock sl (ratioLock);
  19175. if (lastRatio != ratio)
  19176. {
  19177. createLowPass (ratio);
  19178. lastRatio = ratio;
  19179. }
  19180. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  19181. int bufferSize = buffer.getNumSamples();
  19182. if (bufferSize < sampsNeeded + 8)
  19183. {
  19184. bufferPos %= bufferSize;
  19185. bufferSize = sampsNeeded + 32;
  19186. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  19187. }
  19188. bufferPos %= bufferSize;
  19189. int endOfBufferPos = bufferPos + sampsInBuffer;
  19190. while (sampsNeeded > sampsInBuffer)
  19191. {
  19192. endOfBufferPos %= bufferSize;
  19193. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  19194. bufferSize - endOfBufferPos);
  19195. AudioSourceChannelInfo readInfo;
  19196. readInfo.buffer = &buffer;
  19197. readInfo.numSamples = numToDo;
  19198. readInfo.startSample = endOfBufferPos;
  19199. input->getNextAudioBlock (readInfo);
  19200. if (ratio > 1.0001)
  19201. {
  19202. // for down-sampling, pre-apply the filter..
  19203. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19204. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  19205. }
  19206. sampsInBuffer += numToDo;
  19207. endOfBufferPos += numToDo;
  19208. }
  19209. float* dl = info.buffer->getSampleData (0, info.startSample);
  19210. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  19211. const float* const bl = buffer.getSampleData (0, 0);
  19212. const float* const br = buffer.getSampleData (1, 0);
  19213. int nextPos = (bufferPos + 1) % bufferSize;
  19214. for (int m = info.numSamples; --m >= 0;)
  19215. {
  19216. const float alpha = (float) subSampleOffset;
  19217. const float invAlpha = 1.0f - alpha;
  19218. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  19219. if (dr != 0)
  19220. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  19221. subSampleOffset += ratio;
  19222. jassert (sampsInBuffer > 0);
  19223. while (subSampleOffset >= 1.0)
  19224. {
  19225. if (++bufferPos >= bufferSize)
  19226. bufferPos = 0;
  19227. --sampsInBuffer;
  19228. nextPos = (bufferPos + 1) % bufferSize;
  19229. subSampleOffset -= 1.0;
  19230. }
  19231. }
  19232. if (ratio < 0.9999)
  19233. {
  19234. // for up-sampling, apply the filter after transposing..
  19235. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19236. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  19237. }
  19238. else if (ratio <= 1.0001)
  19239. {
  19240. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  19241. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19242. {
  19243. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  19244. FilterState& fs = filterStates[i];
  19245. if (info.numSamples > 1)
  19246. {
  19247. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  19248. }
  19249. else
  19250. {
  19251. fs.y2 = fs.y1;
  19252. fs.x2 = fs.x1;
  19253. }
  19254. fs.y1 = fs.x1 = *endOfBuffer;
  19255. }
  19256. }
  19257. jassert (sampsInBuffer >= 0);
  19258. }
  19259. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  19260. {
  19261. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  19262. : 0.5 * frequencyRatio;
  19263. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  19264. const double nSquared = n * n;
  19265. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  19266. setFilterCoefficients (c1,
  19267. c1 * 2.0f,
  19268. c1,
  19269. 1.0,
  19270. c1 * 2.0 * (1.0 - nSquared),
  19271. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  19272. }
  19273. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  19274. {
  19275. const double a = 1.0 / c4;
  19276. c1 *= a;
  19277. c2 *= a;
  19278. c3 *= a;
  19279. c5 *= a;
  19280. c6 *= a;
  19281. coefficients[0] = c1;
  19282. coefficients[1] = c2;
  19283. coefficients[2] = c3;
  19284. coefficients[3] = c4;
  19285. coefficients[4] = c5;
  19286. coefficients[5] = c6;
  19287. }
  19288. void ResamplingAudioSource::resetFilters()
  19289. {
  19290. zeromem (filterStates, sizeof (filterStates));
  19291. }
  19292. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19293. {
  19294. while (--num >= 0)
  19295. {
  19296. const double in = *samples;
  19297. double out = coefficients[0] * in
  19298. + coefficients[1] * fs.x1
  19299. + coefficients[2] * fs.x2
  19300. - coefficients[4] * fs.y1
  19301. - coefficients[5] * fs.y2;
  19302. #if JUCE_INTEL
  19303. if (! (out < -1.0e-8 || out > 1.0e-8))
  19304. out = 0;
  19305. #endif
  19306. fs.x2 = fs.x1;
  19307. fs.x1 = in;
  19308. fs.y2 = fs.y1;
  19309. fs.y1 = out;
  19310. *samples++ = (float) out;
  19311. }
  19312. }
  19313. END_JUCE_NAMESPACE
  19314. /*** End of inlined file: juce_ResamplingAudioSource.cpp ***/
  19315. /*** Start of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19316. BEGIN_JUCE_NAMESPACE
  19317. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19318. : frequency (1000.0),
  19319. sampleRate (44100.0),
  19320. currentPhase (0.0),
  19321. phasePerSample (0.0),
  19322. amplitude (0.5f)
  19323. {
  19324. }
  19325. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19326. {
  19327. }
  19328. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19329. {
  19330. amplitude = newAmplitude;
  19331. }
  19332. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19333. {
  19334. frequency = newFrequencyHz;
  19335. phasePerSample = 0.0;
  19336. }
  19337. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19338. double sampleRate_)
  19339. {
  19340. currentPhase = 0.0;
  19341. phasePerSample = 0.0;
  19342. sampleRate = sampleRate_;
  19343. }
  19344. void ToneGeneratorAudioSource::releaseResources()
  19345. {
  19346. }
  19347. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19348. {
  19349. if (phasePerSample == 0.0)
  19350. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19351. for (int i = 0; i < info.numSamples; ++i)
  19352. {
  19353. const float sample = amplitude * (float) sin (currentPhase);
  19354. currentPhase += phasePerSample;
  19355. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19356. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19357. }
  19358. }
  19359. END_JUCE_NAMESPACE
  19360. /*** End of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19361. /*** Start of inlined file: juce_AudioDeviceManager.cpp ***/
  19362. BEGIN_JUCE_NAMESPACE
  19363. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19364. : sampleRate (0),
  19365. bufferSize (0),
  19366. useDefaultInputChannels (true),
  19367. useDefaultOutputChannels (true)
  19368. {
  19369. }
  19370. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19371. {
  19372. return outputDeviceName == other.outputDeviceName
  19373. && inputDeviceName == other.inputDeviceName
  19374. && sampleRate == other.sampleRate
  19375. && bufferSize == other.bufferSize
  19376. && inputChannels == other.inputChannels
  19377. && useDefaultInputChannels == other.useDefaultInputChannels
  19378. && outputChannels == other.outputChannels
  19379. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19380. }
  19381. AudioDeviceManager::AudioDeviceManager()
  19382. : currentAudioDevice (0),
  19383. numInputChansNeeded (0),
  19384. numOutputChansNeeded (2),
  19385. listNeedsScanning (true),
  19386. useInputNames (false),
  19387. inputLevelMeasurementEnabledCount (0),
  19388. inputLevel (0),
  19389. tempBuffer (2, 2),
  19390. defaultMidiOutput (0),
  19391. cpuUsageMs (0),
  19392. timeToCpuScale (0)
  19393. {
  19394. callbackHandler.owner = this;
  19395. }
  19396. AudioDeviceManager::~AudioDeviceManager()
  19397. {
  19398. currentAudioDevice = 0;
  19399. defaultMidiOutput = 0;
  19400. }
  19401. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19402. {
  19403. if (availableDeviceTypes.size() == 0)
  19404. {
  19405. createAudioDeviceTypes (availableDeviceTypes);
  19406. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19407. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19408. if (availableDeviceTypes.size() > 0)
  19409. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19410. }
  19411. }
  19412. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19413. {
  19414. scanDevicesIfNeeded();
  19415. return availableDeviceTypes;
  19416. }
  19417. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19418. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19419. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19420. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19421. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19422. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19423. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19424. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19425. {
  19426. #if JUCE_WINDOWS
  19427. #if JUCE_WASAPI
  19428. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19429. list.add (juce_createAudioIODeviceType_WASAPI());
  19430. #endif
  19431. #if JUCE_DIRECTSOUND
  19432. list.add (juce_createAudioIODeviceType_DirectSound());
  19433. #endif
  19434. #if JUCE_ASIO
  19435. list.add (juce_createAudioIODeviceType_ASIO());
  19436. #endif
  19437. #endif
  19438. #if JUCE_MAC
  19439. list.add (juce_createAudioIODeviceType_CoreAudio());
  19440. #endif
  19441. #if JUCE_IPHONE
  19442. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19443. #endif
  19444. #if JUCE_LINUX && JUCE_ALSA
  19445. list.add (juce_createAudioIODeviceType_ALSA());
  19446. #endif
  19447. #if JUCE_LINUX && JUCE_JACK
  19448. list.add (juce_createAudioIODeviceType_JACK());
  19449. #endif
  19450. }
  19451. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19452. const int numOutputChannelsNeeded,
  19453. const XmlElement* const e,
  19454. const bool selectDefaultDeviceOnFailure,
  19455. const String& preferredDefaultDeviceName,
  19456. const AudioDeviceSetup* preferredSetupOptions)
  19457. {
  19458. scanDevicesIfNeeded();
  19459. numInputChansNeeded = numInputChannelsNeeded;
  19460. numOutputChansNeeded = numOutputChannelsNeeded;
  19461. if (e != 0 && e->hasTagName (T("DEVICESETUP")))
  19462. {
  19463. lastExplicitSettings = new XmlElement (*e);
  19464. String error;
  19465. AudioDeviceSetup setup;
  19466. if (preferredSetupOptions != 0)
  19467. setup = *preferredSetupOptions;
  19468. if (e->getStringAttribute (T("audioDeviceName")).isNotEmpty())
  19469. {
  19470. setup.inputDeviceName = setup.outputDeviceName
  19471. = e->getStringAttribute (T("audioDeviceName"));
  19472. }
  19473. else
  19474. {
  19475. setup.inputDeviceName = e->getStringAttribute (T("audioInputDeviceName"));
  19476. setup.outputDeviceName = e->getStringAttribute (T("audioOutputDeviceName"));
  19477. }
  19478. currentDeviceType = e->getStringAttribute (T("deviceType"));
  19479. if (currentDeviceType.isEmpty())
  19480. {
  19481. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19482. if (type != 0)
  19483. currentDeviceType = type->getTypeName();
  19484. else if (availableDeviceTypes.size() > 0)
  19485. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19486. }
  19487. setup.bufferSize = e->getIntAttribute (T("audioDeviceBufferSize"));
  19488. setup.sampleRate = e->getDoubleAttribute (T("audioDeviceRate"));
  19489. setup.inputChannels.parseString (e->getStringAttribute (T("audioDeviceInChans"), T("11")), 2);
  19490. setup.outputChannels.parseString (e->getStringAttribute (T("audioDeviceOutChans"), T("11")), 2);
  19491. setup.useDefaultInputChannels = ! e->hasAttribute (T("audioDeviceInChans"));
  19492. setup.useDefaultOutputChannels = ! e->hasAttribute (T("audioDeviceOutChans"));
  19493. error = setAudioDeviceSetup (setup, true);
  19494. midiInsFromXml.clear();
  19495. forEachXmlChildElementWithTagName (*e, c, T("MIDIINPUT"))
  19496. midiInsFromXml.add (c->getStringAttribute (T("name")));
  19497. const StringArray allMidiIns (MidiInput::getDevices());
  19498. for (int i = allMidiIns.size(); --i >= 0;)
  19499. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19500. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19501. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19502. false, preferredDefaultDeviceName);
  19503. setDefaultMidiOutput (e->getStringAttribute (T("defaultMidiOutput")));
  19504. return error;
  19505. }
  19506. else
  19507. {
  19508. AudioDeviceSetup setup;
  19509. if (preferredSetupOptions != 0)
  19510. {
  19511. setup = *preferredSetupOptions;
  19512. }
  19513. else if (preferredDefaultDeviceName.isNotEmpty())
  19514. {
  19515. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19516. {
  19517. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19518. StringArray outs (type->getDeviceNames (false));
  19519. int i;
  19520. for (i = 0; i < outs.size(); ++i)
  19521. {
  19522. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19523. {
  19524. setup.outputDeviceName = outs[i];
  19525. break;
  19526. }
  19527. }
  19528. StringArray ins (type->getDeviceNames (true));
  19529. for (i = 0; i < ins.size(); ++i)
  19530. {
  19531. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19532. {
  19533. setup.inputDeviceName = ins[i];
  19534. break;
  19535. }
  19536. }
  19537. }
  19538. }
  19539. insertDefaultDeviceNames (setup);
  19540. return setAudioDeviceSetup (setup, false);
  19541. }
  19542. }
  19543. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19544. {
  19545. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19546. if (type != 0)
  19547. {
  19548. if (setup.outputDeviceName.isEmpty())
  19549. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19550. if (setup.inputDeviceName.isEmpty())
  19551. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19552. }
  19553. }
  19554. XmlElement* AudioDeviceManager::createStateXml() const
  19555. {
  19556. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19557. }
  19558. void AudioDeviceManager::scanDevicesIfNeeded()
  19559. {
  19560. if (listNeedsScanning)
  19561. {
  19562. listNeedsScanning = false;
  19563. createDeviceTypesIfNeeded();
  19564. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19565. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19566. }
  19567. }
  19568. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19569. {
  19570. scanDevicesIfNeeded();
  19571. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19572. {
  19573. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19574. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19575. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19576. {
  19577. return type;
  19578. }
  19579. }
  19580. return 0;
  19581. }
  19582. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19583. {
  19584. setup = currentSetup;
  19585. }
  19586. void AudioDeviceManager::deleteCurrentDevice()
  19587. {
  19588. currentAudioDevice = 0;
  19589. currentSetup.inputDeviceName = String::empty;
  19590. currentSetup.outputDeviceName = String::empty;
  19591. }
  19592. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19593. const bool treatAsChosenDevice)
  19594. {
  19595. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19596. {
  19597. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19598. && currentDeviceType != type)
  19599. {
  19600. currentDeviceType = type;
  19601. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19602. insertDefaultDeviceNames (s);
  19603. setAudioDeviceSetup (s, treatAsChosenDevice);
  19604. sendChangeMessage (this);
  19605. break;
  19606. }
  19607. }
  19608. }
  19609. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19610. {
  19611. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19612. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19613. return availableDeviceTypes[i];
  19614. return availableDeviceTypes[0];
  19615. }
  19616. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19617. const bool treatAsChosenDevice)
  19618. {
  19619. jassert (&newSetup != &currentSetup); // this will have no effect
  19620. if (newSetup == currentSetup && currentAudioDevice != 0)
  19621. return String::empty;
  19622. if (! (newSetup == currentSetup))
  19623. sendChangeMessage (this);
  19624. stopDevice();
  19625. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19626. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19627. String error;
  19628. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19629. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19630. {
  19631. deleteCurrentDevice();
  19632. if (treatAsChosenDevice)
  19633. updateXml();
  19634. return String::empty;
  19635. }
  19636. if (currentSetup.inputDeviceName != newInputDeviceName
  19637. || currentSetup.outputDeviceName != newOutputDeviceName
  19638. || currentAudioDevice == 0)
  19639. {
  19640. deleteCurrentDevice();
  19641. scanDevicesIfNeeded();
  19642. if (newOutputDeviceName.isNotEmpty()
  19643. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19644. {
  19645. return "No such device: " + newOutputDeviceName;
  19646. }
  19647. if (newInputDeviceName.isNotEmpty()
  19648. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19649. {
  19650. return "No such device: " + newInputDeviceName;
  19651. }
  19652. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19653. if (currentAudioDevice == 0)
  19654. 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!";
  19655. else
  19656. error = currentAudioDevice->getLastError();
  19657. if (error.isNotEmpty())
  19658. {
  19659. deleteCurrentDevice();
  19660. return error;
  19661. }
  19662. if (newSetup.useDefaultInputChannels)
  19663. {
  19664. inputChannels.clear();
  19665. inputChannels.setRange (0, numInputChansNeeded, true);
  19666. }
  19667. if (newSetup.useDefaultOutputChannels)
  19668. {
  19669. outputChannels.clear();
  19670. outputChannels.setRange (0, numOutputChansNeeded, true);
  19671. }
  19672. if (newInputDeviceName.isEmpty())
  19673. inputChannels.clear();
  19674. if (newOutputDeviceName.isEmpty())
  19675. outputChannels.clear();
  19676. }
  19677. if (! newSetup.useDefaultInputChannels)
  19678. inputChannels = newSetup.inputChannels;
  19679. if (! newSetup.useDefaultOutputChannels)
  19680. outputChannels = newSetup.outputChannels;
  19681. currentSetup = newSetup;
  19682. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19683. error = currentAudioDevice->open (inputChannels,
  19684. outputChannels,
  19685. currentSetup.sampleRate,
  19686. currentSetup.bufferSize);
  19687. if (error.isEmpty())
  19688. {
  19689. currentDeviceType = currentAudioDevice->getTypeName();
  19690. currentAudioDevice->start (&callbackHandler);
  19691. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19692. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19693. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19694. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19695. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19696. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19697. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19698. if (treatAsChosenDevice)
  19699. updateXml();
  19700. }
  19701. else
  19702. {
  19703. deleteCurrentDevice();
  19704. }
  19705. return error;
  19706. }
  19707. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19708. {
  19709. jassert (currentAudioDevice != 0);
  19710. if (rate > 0)
  19711. {
  19712. bool ok = false;
  19713. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19714. {
  19715. const double sr = currentAudioDevice->getSampleRate (i);
  19716. if (sr == rate)
  19717. ok = true;
  19718. }
  19719. if (! ok)
  19720. rate = 0;
  19721. }
  19722. if (rate == 0)
  19723. {
  19724. double lowestAbove44 = 0.0;
  19725. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19726. {
  19727. const double sr = currentAudioDevice->getSampleRate (i);
  19728. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19729. lowestAbove44 = sr;
  19730. }
  19731. if (lowestAbove44 == 0.0)
  19732. rate = currentAudioDevice->getSampleRate (0);
  19733. else
  19734. rate = lowestAbove44;
  19735. }
  19736. return rate;
  19737. }
  19738. void AudioDeviceManager::stopDevice()
  19739. {
  19740. if (currentAudioDevice != 0)
  19741. currentAudioDevice->stop();
  19742. testSound = 0;
  19743. }
  19744. void AudioDeviceManager::closeAudioDevice()
  19745. {
  19746. stopDevice();
  19747. currentAudioDevice = 0;
  19748. }
  19749. void AudioDeviceManager::restartLastAudioDevice()
  19750. {
  19751. if (currentAudioDevice == 0)
  19752. {
  19753. if (currentSetup.inputDeviceName.isEmpty()
  19754. && currentSetup.outputDeviceName.isEmpty())
  19755. {
  19756. // This method will only reload the last device that was running
  19757. // before closeAudioDevice() was called - you need to actually open
  19758. // one first, with setAudioDevice().
  19759. jassertfalse
  19760. return;
  19761. }
  19762. AudioDeviceSetup s (currentSetup);
  19763. setAudioDeviceSetup (s, false);
  19764. }
  19765. }
  19766. void AudioDeviceManager::updateXml()
  19767. {
  19768. lastExplicitSettings = new XmlElement ("DEVICESETUP");
  19769. lastExplicitSettings->setAttribute ("deviceType", currentDeviceType);
  19770. lastExplicitSettings->setAttribute ("audioOutputDeviceName", currentSetup.outputDeviceName);
  19771. lastExplicitSettings->setAttribute ("audioInputDeviceName", currentSetup.inputDeviceName);
  19772. if (currentAudioDevice != 0)
  19773. {
  19774. lastExplicitSettings->setAttribute ("audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
  19775. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19776. lastExplicitSettings->setAttribute ("audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
  19777. if (! currentSetup.useDefaultInputChannels)
  19778. lastExplicitSettings->setAttribute ("audioDeviceInChans", currentSetup.inputChannels.toString (2));
  19779. if (! currentSetup.useDefaultOutputChannels)
  19780. lastExplicitSettings->setAttribute ("audioDeviceOutChans", currentSetup.outputChannels.toString (2));
  19781. }
  19782. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19783. {
  19784. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19785. m->setAttribute ("name", enabledMidiInputs[i]->getName());
  19786. }
  19787. if (midiInsFromXml.size() > 0)
  19788. {
  19789. // Add any midi devices that have been enabled before, but which aren't currently
  19790. // open because the device has been disconnected.
  19791. const StringArray availableMidiDevices (MidiInput::getDevices());
  19792. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19793. {
  19794. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19795. {
  19796. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19797. m->setAttribute ("name", midiInsFromXml[i]);
  19798. }
  19799. }
  19800. }
  19801. if (defaultMidiOutputName.isNotEmpty())
  19802. lastExplicitSettings->setAttribute ("defaultMidiOutput", defaultMidiOutputName);
  19803. }
  19804. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19805. {
  19806. {
  19807. const ScopedLock sl (audioCallbackLock);
  19808. if (callbacks.contains (newCallback))
  19809. return;
  19810. }
  19811. if (currentAudioDevice != 0 && newCallback != 0)
  19812. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19813. const ScopedLock sl (audioCallbackLock);
  19814. callbacks.add (newCallback);
  19815. }
  19816. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19817. {
  19818. if (callback != 0)
  19819. {
  19820. bool needsDeinitialising = currentAudioDevice != 0;
  19821. {
  19822. const ScopedLock sl (audioCallbackLock);
  19823. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19824. callbacks.removeValue (callback);
  19825. }
  19826. if (needsDeinitialising)
  19827. callback->audioDeviceStopped();
  19828. }
  19829. }
  19830. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19831. int numInputChannels,
  19832. float** outputChannelData,
  19833. int numOutputChannels,
  19834. int numSamples)
  19835. {
  19836. const ScopedLock sl (audioCallbackLock);
  19837. if (inputLevelMeasurementEnabledCount > 0)
  19838. {
  19839. for (int j = 0; j < numSamples; ++j)
  19840. {
  19841. float s = 0;
  19842. for (int i = 0; i < numInputChannels; ++i)
  19843. s += fabsf (inputChannelData[i][j]);
  19844. s /= numInputChannels;
  19845. const double decayFactor = 0.99992;
  19846. if (s > inputLevel)
  19847. inputLevel = s;
  19848. else if (inputLevel > 0.001f)
  19849. inputLevel *= decayFactor;
  19850. else
  19851. inputLevel = 0;
  19852. }
  19853. }
  19854. if (callbacks.size() > 0)
  19855. {
  19856. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19857. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19858. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19859. outputChannelData, numOutputChannels, numSamples);
  19860. float** const tempChans = tempBuffer.getArrayOfChannels();
  19861. for (int i = callbacks.size(); --i > 0;)
  19862. {
  19863. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19864. tempChans, numOutputChannels, numSamples);
  19865. for (int chan = 0; chan < numOutputChannels; ++chan)
  19866. {
  19867. const float* const src = tempChans [chan];
  19868. float* const dst = outputChannelData [chan];
  19869. if (src != 0 && dst != 0)
  19870. for (int j = 0; j < numSamples; ++j)
  19871. dst[j] += src[j];
  19872. }
  19873. }
  19874. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19875. const double filterAmount = 0.2;
  19876. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19877. }
  19878. else
  19879. {
  19880. for (int i = 0; i < numOutputChannels; ++i)
  19881. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19882. }
  19883. if (testSound != 0)
  19884. {
  19885. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19886. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19887. for (int i = 0; i < numOutputChannels; ++i)
  19888. for (int j = 0; j < numSamps; ++j)
  19889. outputChannelData [i][j] += src[j];
  19890. testSoundPosition += numSamps;
  19891. if (testSoundPosition >= testSound->getNumSamples())
  19892. testSound = 0;
  19893. }
  19894. }
  19895. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19896. {
  19897. cpuUsageMs = 0;
  19898. const double sampleRate = device->getCurrentSampleRate();
  19899. const int blockSize = device->getCurrentBufferSizeSamples();
  19900. if (sampleRate > 0.0 && blockSize > 0)
  19901. {
  19902. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19903. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19904. }
  19905. {
  19906. const ScopedLock sl (audioCallbackLock);
  19907. for (int i = callbacks.size(); --i >= 0;)
  19908. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19909. }
  19910. sendChangeMessage (this);
  19911. }
  19912. void AudioDeviceManager::audioDeviceStoppedInt()
  19913. {
  19914. cpuUsageMs = 0;
  19915. timeToCpuScale = 0;
  19916. sendChangeMessage (this);
  19917. const ScopedLock sl (audioCallbackLock);
  19918. for (int i = callbacks.size(); --i >= 0;)
  19919. callbacks.getUnchecked(i)->audioDeviceStopped();
  19920. }
  19921. double AudioDeviceManager::getCpuUsage() const
  19922. {
  19923. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19924. }
  19925. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19926. const bool enabled)
  19927. {
  19928. if (enabled != isMidiInputEnabled (name))
  19929. {
  19930. if (enabled)
  19931. {
  19932. const int index = MidiInput::getDevices().indexOf (name);
  19933. if (index >= 0)
  19934. {
  19935. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19936. if (min != 0)
  19937. {
  19938. enabledMidiInputs.add (min);
  19939. min->start();
  19940. }
  19941. }
  19942. }
  19943. else
  19944. {
  19945. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19946. if (enabledMidiInputs[i]->getName() == name)
  19947. enabledMidiInputs.remove (i);
  19948. }
  19949. updateXml();
  19950. sendChangeMessage (this);
  19951. }
  19952. }
  19953. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19954. {
  19955. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19956. if (enabledMidiInputs[i]->getName() == name)
  19957. return true;
  19958. return false;
  19959. }
  19960. void AudioDeviceManager::addMidiInputCallback (const String& name,
  19961. MidiInputCallback* callback)
  19962. {
  19963. removeMidiInputCallback (name, callback);
  19964. if (name.isEmpty())
  19965. {
  19966. midiCallbacks.add (callback);
  19967. midiCallbackDevices.add (0);
  19968. }
  19969. else
  19970. {
  19971. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19972. {
  19973. if (enabledMidiInputs[i]->getName() == name)
  19974. {
  19975. const ScopedLock sl (midiCallbackLock);
  19976. midiCallbacks.add (callback);
  19977. midiCallbackDevices.add (enabledMidiInputs[i]);
  19978. break;
  19979. }
  19980. }
  19981. }
  19982. }
  19983. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  19984. MidiInputCallback* /*callback*/)
  19985. {
  19986. const ScopedLock sl (midiCallbackLock);
  19987. for (int i = midiCallbacks.size(); --i >= 0;)
  19988. {
  19989. String devName;
  19990. if (midiCallbackDevices.getUnchecked(i) != 0)
  19991. devName = midiCallbackDevices.getUnchecked(i)->getName();
  19992. if (devName == name)
  19993. {
  19994. midiCallbacks.remove (i);
  19995. midiCallbackDevices.remove (i);
  19996. }
  19997. }
  19998. }
  19999. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  20000. const MidiMessage& message)
  20001. {
  20002. if (! message.isActiveSense())
  20003. {
  20004. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  20005. const ScopedLock sl (midiCallbackLock);
  20006. for (int i = midiCallbackDevices.size(); --i >= 0;)
  20007. {
  20008. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  20009. if (md == source || (md == 0 && isDefaultSource))
  20010. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  20011. }
  20012. }
  20013. }
  20014. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  20015. {
  20016. if (defaultMidiOutputName != deviceName)
  20017. {
  20018. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  20019. {
  20020. const ScopedLock sl (audioCallbackLock);
  20021. oldCallbacks = callbacks;
  20022. callbacks.clear();
  20023. }
  20024. if (currentAudioDevice != 0)
  20025. for (int i = oldCallbacks.size(); --i >= 0;)
  20026. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  20027. defaultMidiOutput = 0;
  20028. defaultMidiOutputName = deviceName;
  20029. if (deviceName.isNotEmpty())
  20030. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  20031. if (currentAudioDevice != 0)
  20032. for (int i = oldCallbacks.size(); --i >= 0;)
  20033. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  20034. {
  20035. const ScopedLock sl (audioCallbackLock);
  20036. callbacks = oldCallbacks;
  20037. }
  20038. updateXml();
  20039. sendChangeMessage (this);
  20040. }
  20041. }
  20042. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  20043. int numInputChannels,
  20044. float** outputChannelData,
  20045. int numOutputChannels,
  20046. int numSamples)
  20047. {
  20048. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  20049. }
  20050. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  20051. {
  20052. owner->audioDeviceAboutToStartInt (device);
  20053. }
  20054. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  20055. {
  20056. owner->audioDeviceStoppedInt();
  20057. }
  20058. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  20059. {
  20060. owner->handleIncomingMidiMessageInt (source, message);
  20061. }
  20062. void AudioDeviceManager::playTestSound()
  20063. {
  20064. { // cunningly nested to swap, unlock and delete in that order.
  20065. ScopedPointer <AudioSampleBuffer> oldSound;
  20066. {
  20067. const ScopedLock sl (audioCallbackLock);
  20068. oldSound = testSound;
  20069. }
  20070. }
  20071. testSoundPosition = 0;
  20072. if (currentAudioDevice != 0)
  20073. {
  20074. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  20075. const int soundLength = (int) sampleRate;
  20076. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  20077. float* samples = newSound->getSampleData (0);
  20078. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  20079. const float amplitude = 0.5f;
  20080. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  20081. for (int i = 0; i < soundLength; ++i)
  20082. samples[i] = amplitude * (float) sin (i * phasePerSample);
  20083. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  20084. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  20085. const ScopedLock sl (audioCallbackLock);
  20086. testSound = newSound;
  20087. }
  20088. }
  20089. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  20090. {
  20091. const ScopedLock sl (audioCallbackLock);
  20092. if (enableMeasurement)
  20093. ++inputLevelMeasurementEnabledCount;
  20094. else
  20095. --inputLevelMeasurementEnabledCount;
  20096. inputLevel = 0;
  20097. }
  20098. double AudioDeviceManager::getCurrentInputLevel() const
  20099. {
  20100. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  20101. return inputLevel;
  20102. }
  20103. END_JUCE_NAMESPACE
  20104. /*** End of inlined file: juce_AudioDeviceManager.cpp ***/
  20105. /*** Start of inlined file: juce_AudioIODevice.cpp ***/
  20106. BEGIN_JUCE_NAMESPACE
  20107. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  20108. : name (deviceName),
  20109. typeName (typeName_)
  20110. {
  20111. }
  20112. AudioIODevice::~AudioIODevice()
  20113. {
  20114. }
  20115. bool AudioIODevice::hasControlPanel() const
  20116. {
  20117. return false;
  20118. }
  20119. bool AudioIODevice::showControlPanel()
  20120. {
  20121. jassertfalse // this should only be called for devices which return true from
  20122. // their hasControlPanel() method.
  20123. return false;
  20124. }
  20125. END_JUCE_NAMESPACE
  20126. /*** End of inlined file: juce_AudioIODevice.cpp ***/
  20127. /*** Start of inlined file: juce_AudioIODeviceType.cpp ***/
  20128. BEGIN_JUCE_NAMESPACE
  20129. AudioIODeviceType::AudioIODeviceType (const tchar* const name)
  20130. : typeName (name)
  20131. {
  20132. }
  20133. AudioIODeviceType::~AudioIODeviceType()
  20134. {
  20135. }
  20136. END_JUCE_NAMESPACE
  20137. /*** End of inlined file: juce_AudioIODeviceType.cpp ***/
  20138. /*** Start of inlined file: juce_MidiOutput.cpp ***/
  20139. BEGIN_JUCE_NAMESPACE
  20140. MidiOutput::MidiOutput() throw()
  20141. : Thread ("midi out"),
  20142. internal (0),
  20143. firstMessage (0)
  20144. {
  20145. }
  20146. MidiOutput::PendingMessage::PendingMessage (const uint8* const data,
  20147. const int len,
  20148. const double sampleNumber) throw()
  20149. : message (data, len, sampleNumber)
  20150. {
  20151. }
  20152. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  20153. const double millisecondCounterToStartAt,
  20154. double samplesPerSecondForBuffer) throw()
  20155. {
  20156. // You've got to call startBackgroundThread() for this to actually work..
  20157. jassert (isThreadRunning());
  20158. // this needs to be a value in the future - RTFM for this method!
  20159. jassert (millisecondCounterToStartAt > 0);
  20160. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  20161. MidiBuffer::Iterator i (buffer);
  20162. const uint8* data;
  20163. int len, time;
  20164. while (i.getNextEvent (data, len, time))
  20165. {
  20166. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  20167. PendingMessage* const m
  20168. = new PendingMessage (data, len, eventTime);
  20169. const ScopedLock sl (lock);
  20170. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  20171. {
  20172. m->next = firstMessage;
  20173. firstMessage = m;
  20174. }
  20175. else
  20176. {
  20177. PendingMessage* mm = firstMessage;
  20178. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  20179. mm = mm->next;
  20180. m->next = mm->next;
  20181. mm->next = m;
  20182. }
  20183. }
  20184. notify();
  20185. }
  20186. void MidiOutput::clearAllPendingMessages() throw()
  20187. {
  20188. const ScopedLock sl (lock);
  20189. while (firstMessage != 0)
  20190. {
  20191. PendingMessage* const m = firstMessage;
  20192. firstMessage = firstMessage->next;
  20193. delete m;
  20194. }
  20195. }
  20196. void MidiOutput::startBackgroundThread() throw()
  20197. {
  20198. startThread (9);
  20199. }
  20200. void MidiOutput::stopBackgroundThread() throw()
  20201. {
  20202. stopThread (5000);
  20203. }
  20204. void MidiOutput::run()
  20205. {
  20206. while (! threadShouldExit())
  20207. {
  20208. uint32 now = Time::getMillisecondCounter();
  20209. uint32 eventTime = 0;
  20210. uint32 timeToWait = 500;
  20211. PendingMessage* message;
  20212. {
  20213. const ScopedLock sl (lock);
  20214. message = firstMessage;
  20215. if (message != 0)
  20216. {
  20217. eventTime = roundToInt (message->message.getTimeStamp());
  20218. if (eventTime > now + 20)
  20219. {
  20220. timeToWait = eventTime - (now + 20);
  20221. message = 0;
  20222. }
  20223. else
  20224. {
  20225. firstMessage = message->next;
  20226. }
  20227. }
  20228. }
  20229. if (message != 0)
  20230. {
  20231. if (eventTime > now)
  20232. {
  20233. Time::waitForMillisecondCounter (eventTime);
  20234. if (threadShouldExit())
  20235. break;
  20236. }
  20237. if (eventTime > now - 200)
  20238. sendMessageNow (message->message);
  20239. delete message;
  20240. }
  20241. else
  20242. {
  20243. jassert (timeToWait < 1000 * 30);
  20244. wait (timeToWait);
  20245. }
  20246. }
  20247. clearAllPendingMessages();
  20248. }
  20249. END_JUCE_NAMESPACE
  20250. /*** End of inlined file: juce_MidiOutput.cpp ***/
  20251. /*** Start of inlined file: juce_AudioDataConverters.cpp ***/
  20252. BEGIN_JUCE_NAMESPACE
  20253. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20254. {
  20255. const double maxVal = (double) 0x7fff;
  20256. char* intData = (char*) dest;
  20257. if (dest != (void*) source || destBytesPerSample <= 4)
  20258. {
  20259. for (int i = 0; i < numSamples; ++i)
  20260. {
  20261. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20262. intData += destBytesPerSample;
  20263. }
  20264. }
  20265. else
  20266. {
  20267. intData += destBytesPerSample * numSamples;
  20268. for (int i = numSamples; --i >= 0;)
  20269. {
  20270. intData -= destBytesPerSample;
  20271. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20272. }
  20273. }
  20274. }
  20275. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20276. {
  20277. const double maxVal = (double) 0x7fff;
  20278. char* intData = (char*) dest;
  20279. if (dest != (void*) source || destBytesPerSample <= 4)
  20280. {
  20281. for (int i = 0; i < numSamples; ++i)
  20282. {
  20283. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20284. intData += destBytesPerSample;
  20285. }
  20286. }
  20287. else
  20288. {
  20289. intData += destBytesPerSample * numSamples;
  20290. for (int i = numSamples; --i >= 0;)
  20291. {
  20292. intData -= destBytesPerSample;
  20293. *(uint16*)intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20294. }
  20295. }
  20296. }
  20297. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20298. {
  20299. const double maxVal = (double) 0x7fffff;
  20300. char* intData = (char*) dest;
  20301. if (dest != (void*) source || destBytesPerSample <= 4)
  20302. {
  20303. for (int i = 0; i < numSamples; ++i)
  20304. {
  20305. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20306. intData += destBytesPerSample;
  20307. }
  20308. }
  20309. else
  20310. {
  20311. intData += destBytesPerSample * numSamples;
  20312. for (int i = numSamples; --i >= 0;)
  20313. {
  20314. intData -= destBytesPerSample;
  20315. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20316. }
  20317. }
  20318. }
  20319. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20320. {
  20321. const double maxVal = (double) 0x7fffff;
  20322. char* intData = (char*) dest;
  20323. if (dest != (void*) source || destBytesPerSample <= 4)
  20324. {
  20325. for (int i = 0; i < numSamples; ++i)
  20326. {
  20327. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20328. intData += destBytesPerSample;
  20329. }
  20330. }
  20331. else
  20332. {
  20333. intData += destBytesPerSample * numSamples;
  20334. for (int i = numSamples; --i >= 0;)
  20335. {
  20336. intData -= destBytesPerSample;
  20337. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20338. }
  20339. }
  20340. }
  20341. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20342. {
  20343. const double maxVal = (double) 0x7fffffff;
  20344. char* intData = (char*) dest;
  20345. if (dest != (void*) source || destBytesPerSample <= 4)
  20346. {
  20347. for (int i = 0; i < numSamples; ++i)
  20348. {
  20349. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20350. intData += destBytesPerSample;
  20351. }
  20352. }
  20353. else
  20354. {
  20355. intData += destBytesPerSample * numSamples;
  20356. for (int i = numSamples; --i >= 0;)
  20357. {
  20358. intData -= destBytesPerSample;
  20359. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20360. }
  20361. }
  20362. }
  20363. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20364. {
  20365. const double maxVal = (double) 0x7fffffff;
  20366. char* intData = (char*) dest;
  20367. if (dest != (void*) source || destBytesPerSample <= 4)
  20368. {
  20369. for (int i = 0; i < numSamples; ++i)
  20370. {
  20371. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20372. intData += destBytesPerSample;
  20373. }
  20374. }
  20375. else
  20376. {
  20377. intData += destBytesPerSample * numSamples;
  20378. for (int i = numSamples; --i >= 0;)
  20379. {
  20380. intData -= destBytesPerSample;
  20381. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20382. }
  20383. }
  20384. }
  20385. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20386. {
  20387. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20388. char* d = (char*) dest;
  20389. for (int i = 0; i < numSamples; ++i)
  20390. {
  20391. *(float*) d = source[i];
  20392. #if JUCE_BIG_ENDIAN
  20393. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20394. #endif
  20395. d += destBytesPerSample;
  20396. }
  20397. }
  20398. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20399. {
  20400. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20401. char* d = (char*) dest;
  20402. for (int i = 0; i < numSamples; ++i)
  20403. {
  20404. *(float*) d = source[i];
  20405. #if JUCE_LITTLE_ENDIAN
  20406. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20407. #endif
  20408. d += destBytesPerSample;
  20409. }
  20410. }
  20411. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20412. {
  20413. const float scale = 1.0f / 0x7fff;
  20414. const char* intData = (const char*) source;
  20415. if (source != (void*) dest || srcBytesPerSample >= 4)
  20416. {
  20417. for (int i = 0; i < numSamples; ++i)
  20418. {
  20419. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20420. intData += srcBytesPerSample;
  20421. }
  20422. }
  20423. else
  20424. {
  20425. intData += srcBytesPerSample * numSamples;
  20426. for (int i = numSamples; --i >= 0;)
  20427. {
  20428. intData -= srcBytesPerSample;
  20429. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20430. }
  20431. }
  20432. }
  20433. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20434. {
  20435. const float scale = 1.0f / 0x7fff;
  20436. const char* intData = (const char*) source;
  20437. if (source != (void*) dest || srcBytesPerSample >= 4)
  20438. {
  20439. for (int i = 0; i < numSamples; ++i)
  20440. {
  20441. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20442. intData += srcBytesPerSample;
  20443. }
  20444. }
  20445. else
  20446. {
  20447. intData += srcBytesPerSample * numSamples;
  20448. for (int i = numSamples; --i >= 0;)
  20449. {
  20450. intData -= srcBytesPerSample;
  20451. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20452. }
  20453. }
  20454. }
  20455. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20456. {
  20457. const float scale = 1.0f / 0x7fffff;
  20458. const char* intData = (const char*) source;
  20459. if (source != (void*) dest || srcBytesPerSample >= 4)
  20460. {
  20461. for (int i = 0; i < numSamples; ++i)
  20462. {
  20463. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20464. intData += srcBytesPerSample;
  20465. }
  20466. }
  20467. else
  20468. {
  20469. intData += srcBytesPerSample * numSamples;
  20470. for (int i = numSamples; --i >= 0;)
  20471. {
  20472. intData -= srcBytesPerSample;
  20473. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20474. }
  20475. }
  20476. }
  20477. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20478. {
  20479. const float scale = 1.0f / 0x7fffff;
  20480. const char* intData = (const char*) source;
  20481. if (source != (void*) dest || srcBytesPerSample >= 4)
  20482. {
  20483. for (int i = 0; i < numSamples; ++i)
  20484. {
  20485. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20486. intData += srcBytesPerSample;
  20487. }
  20488. }
  20489. else
  20490. {
  20491. intData += srcBytesPerSample * numSamples;
  20492. for (int i = numSamples; --i >= 0;)
  20493. {
  20494. intData -= srcBytesPerSample;
  20495. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20496. }
  20497. }
  20498. }
  20499. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20500. {
  20501. const float scale = 1.0f / 0x7fffffff;
  20502. const char* intData = (const char*) source;
  20503. if (source != (void*) dest || srcBytesPerSample >= 4)
  20504. {
  20505. for (int i = 0; i < numSamples; ++i)
  20506. {
  20507. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20508. intData += srcBytesPerSample;
  20509. }
  20510. }
  20511. else
  20512. {
  20513. intData += srcBytesPerSample * numSamples;
  20514. for (int i = numSamples; --i >= 0;)
  20515. {
  20516. intData -= srcBytesPerSample;
  20517. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20518. }
  20519. }
  20520. }
  20521. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20522. {
  20523. const float scale = 1.0f / 0x7fffffff;
  20524. const char* intData = (const char*) source;
  20525. if (source != (void*) dest || srcBytesPerSample >= 4)
  20526. {
  20527. for (int i = 0; i < numSamples; ++i)
  20528. {
  20529. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20530. intData += srcBytesPerSample;
  20531. }
  20532. }
  20533. else
  20534. {
  20535. intData += srcBytesPerSample * numSamples;
  20536. for (int i = numSamples; --i >= 0;)
  20537. {
  20538. intData -= srcBytesPerSample;
  20539. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20540. }
  20541. }
  20542. }
  20543. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20544. {
  20545. const char* s = (const char*) source;
  20546. for (int i = 0; i < numSamples; ++i)
  20547. {
  20548. dest[i] = *(float*)s;
  20549. #if JUCE_BIG_ENDIAN
  20550. uint32* const d = (uint32*) (dest + i);
  20551. *d = ByteOrder::swap (*d);
  20552. #endif
  20553. s += srcBytesPerSample;
  20554. }
  20555. }
  20556. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20557. {
  20558. const char* s = (const char*) source;
  20559. for (int i = 0; i < numSamples; ++i)
  20560. {
  20561. dest[i] = *(float*)s;
  20562. #if JUCE_LITTLE_ENDIAN
  20563. uint32* const d = (uint32*) (dest + i);
  20564. *d = ByteOrder::swap (*d);
  20565. #endif
  20566. s += srcBytesPerSample;
  20567. }
  20568. }
  20569. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20570. const float* const source,
  20571. void* const dest,
  20572. const int numSamples)
  20573. {
  20574. switch (destFormat)
  20575. {
  20576. case int16LE:
  20577. convertFloatToInt16LE (source, dest, numSamples);
  20578. break;
  20579. case int16BE:
  20580. convertFloatToInt16BE (source, dest, numSamples);
  20581. break;
  20582. case int24LE:
  20583. convertFloatToInt24LE (source, dest, numSamples);
  20584. break;
  20585. case int24BE:
  20586. convertFloatToInt24BE (source, dest, numSamples);
  20587. break;
  20588. case int32LE:
  20589. convertFloatToInt32LE (source, dest, numSamples);
  20590. break;
  20591. case int32BE:
  20592. convertFloatToInt32BE (source, dest, numSamples);
  20593. break;
  20594. case float32LE:
  20595. convertFloatToFloat32LE (source, dest, numSamples);
  20596. break;
  20597. case float32BE:
  20598. convertFloatToFloat32BE (source, dest, numSamples);
  20599. break;
  20600. default:
  20601. jassertfalse
  20602. break;
  20603. }
  20604. }
  20605. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20606. const void* const source,
  20607. float* const dest,
  20608. const int numSamples)
  20609. {
  20610. switch (sourceFormat)
  20611. {
  20612. case int16LE:
  20613. convertInt16LEToFloat (source, dest, numSamples);
  20614. break;
  20615. case int16BE:
  20616. convertInt16BEToFloat (source, dest, numSamples);
  20617. break;
  20618. case int24LE:
  20619. convertInt24LEToFloat (source, dest, numSamples);
  20620. break;
  20621. case int24BE:
  20622. convertInt24BEToFloat (source, dest, numSamples);
  20623. break;
  20624. case int32LE:
  20625. convertInt32LEToFloat (source, dest, numSamples);
  20626. break;
  20627. case int32BE:
  20628. convertInt32BEToFloat (source, dest, numSamples);
  20629. break;
  20630. case float32LE:
  20631. convertFloat32LEToFloat (source, dest, numSamples);
  20632. break;
  20633. case float32BE:
  20634. convertFloat32BEToFloat (source, dest, numSamples);
  20635. break;
  20636. default:
  20637. jassertfalse
  20638. break;
  20639. }
  20640. }
  20641. void AudioDataConverters::interleaveSamples (const float** const source,
  20642. float* const dest,
  20643. const int numSamples,
  20644. const int numChannels)
  20645. {
  20646. for (int chan = 0; chan < numChannels; ++chan)
  20647. {
  20648. int i = chan;
  20649. const float* src = source [chan];
  20650. for (int j = 0; j < numSamples; ++j)
  20651. {
  20652. dest [i] = src [j];
  20653. i += numChannels;
  20654. }
  20655. }
  20656. }
  20657. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20658. float** const dest,
  20659. const int numSamples,
  20660. const int numChannels)
  20661. {
  20662. for (int chan = 0; chan < numChannels; ++chan)
  20663. {
  20664. int i = chan;
  20665. float* dst = dest [chan];
  20666. for (int j = 0; j < numSamples; ++j)
  20667. {
  20668. dst [j] = source [i];
  20669. i += numChannels;
  20670. }
  20671. }
  20672. }
  20673. END_JUCE_NAMESPACE
  20674. /*** End of inlined file: juce_AudioDataConverters.cpp ***/
  20675. /*** Start of inlined file: juce_AudioSampleBuffer.cpp ***/
  20676. BEGIN_JUCE_NAMESPACE
  20677. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20678. const int numSamples) throw()
  20679. : numChannels (numChannels_),
  20680. size (numSamples)
  20681. {
  20682. jassert (numSamples >= 0);
  20683. jassert (numChannels_ > 0);
  20684. allocateData();
  20685. }
  20686. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20687. : numChannels (other.numChannels),
  20688. size (other.size)
  20689. {
  20690. allocateData();
  20691. const size_t numBytes = size * sizeof (float);
  20692. for (int i = 0; i < numChannels; ++i)
  20693. memcpy (channels[i], other.channels[i], numBytes);
  20694. }
  20695. void AudioSampleBuffer::allocateData()
  20696. {
  20697. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20698. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20699. allocatedData.malloc (allocatedBytes);
  20700. channels = reinterpret_cast <float**> (allocatedData.getData());
  20701. float* chan = (float*) (allocatedData + channelListSize);
  20702. for (int i = 0; i < numChannels; ++i)
  20703. {
  20704. channels[i] = chan;
  20705. chan += size;
  20706. }
  20707. channels [numChannels] = 0;
  20708. }
  20709. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20710. const int numChannels_,
  20711. const int numSamples) throw()
  20712. : numChannels (numChannels_),
  20713. size (numSamples),
  20714. allocatedBytes (0)
  20715. {
  20716. jassert (numChannels_ > 0);
  20717. allocateChannels (dataToReferTo);
  20718. }
  20719. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20720. const int newNumChannels,
  20721. const int newNumSamples) throw()
  20722. {
  20723. jassert (newNumChannels > 0);
  20724. allocatedBytes = 0;
  20725. allocatedData.free();
  20726. numChannels = newNumChannels;
  20727. size = newNumSamples;
  20728. allocateChannels (dataToReferTo);
  20729. }
  20730. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20731. {
  20732. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20733. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20734. {
  20735. channels = static_cast <float**> (preallocatedChannelSpace);
  20736. }
  20737. else
  20738. {
  20739. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20740. channels = reinterpret_cast <float**> (allocatedData.getData());
  20741. }
  20742. for (int i = 0; i < numChannels; ++i)
  20743. {
  20744. // you have to pass in the same number of valid pointers as numChannels
  20745. jassert (dataToReferTo[i] != 0);
  20746. channels[i] = dataToReferTo[i];
  20747. }
  20748. channels [numChannels] = 0;
  20749. }
  20750. AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20751. {
  20752. if (this != &other)
  20753. {
  20754. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20755. const size_t numBytes = size * sizeof (float);
  20756. for (int i = 0; i < numChannels; ++i)
  20757. memcpy (channels[i], other.channels[i], numBytes);
  20758. }
  20759. return *this;
  20760. }
  20761. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20762. {
  20763. }
  20764. void AudioSampleBuffer::setSize (const int newNumChannels,
  20765. const int newNumSamples,
  20766. const bool keepExistingContent,
  20767. const bool clearExtraSpace,
  20768. const bool avoidReallocating) throw()
  20769. {
  20770. jassert (newNumChannels > 0);
  20771. if (newNumSamples != size || newNumChannels != numChannels)
  20772. {
  20773. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20774. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20775. if (keepExistingContent)
  20776. {
  20777. HeapBlock <char> newData;
  20778. newData.allocate (newTotalBytes, clearExtraSpace);
  20779. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20780. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20781. float** const newChannels = reinterpret_cast <float**> (newData.getData());
  20782. float* newChan = reinterpret_cast <float*> (newData + channelListSize);
  20783. for (int i = 0; i < numChansToCopy; ++i)
  20784. {
  20785. memcpy (newChan, channels[i], numBytesToCopy);
  20786. newChannels[i] = newChan;
  20787. newChan += newNumSamples;
  20788. }
  20789. allocatedData.swapWith (newData);
  20790. allocatedBytes = (int) newTotalBytes;
  20791. channels = newChannels;
  20792. }
  20793. else
  20794. {
  20795. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20796. {
  20797. if (clearExtraSpace)
  20798. zeromem (allocatedData, newTotalBytes);
  20799. }
  20800. else
  20801. {
  20802. allocatedBytes = newTotalBytes;
  20803. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20804. channels = reinterpret_cast <float**> (allocatedData.getData());
  20805. }
  20806. float* chan = reinterpret_cast <float*> (allocatedData + channelListSize);
  20807. for (int i = 0; i < newNumChannels; ++i)
  20808. {
  20809. channels[i] = chan;
  20810. chan += newNumSamples;
  20811. }
  20812. }
  20813. channels [newNumChannels] = 0;
  20814. size = newNumSamples;
  20815. numChannels = newNumChannels;
  20816. }
  20817. }
  20818. void AudioSampleBuffer::clear() throw()
  20819. {
  20820. for (int i = 0; i < numChannels; ++i)
  20821. zeromem (channels[i], size * sizeof (float));
  20822. }
  20823. void AudioSampleBuffer::clear (const int startSample,
  20824. const int numSamples) throw()
  20825. {
  20826. jassert (startSample >= 0 && startSample + numSamples <= size);
  20827. for (int i = 0; i < numChannels; ++i)
  20828. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20829. }
  20830. void AudioSampleBuffer::clear (const int channel,
  20831. const int startSample,
  20832. const int numSamples) throw()
  20833. {
  20834. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20835. jassert (startSample >= 0 && startSample + numSamples <= size);
  20836. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20837. }
  20838. void AudioSampleBuffer::applyGain (const int channel,
  20839. const int startSample,
  20840. int numSamples,
  20841. const float gain) throw()
  20842. {
  20843. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20844. jassert (startSample >= 0 && startSample + numSamples <= size);
  20845. if (gain != 1.0f)
  20846. {
  20847. float* d = channels [channel] + startSample;
  20848. if (gain == 0.0f)
  20849. {
  20850. zeromem (d, sizeof (float) * numSamples);
  20851. }
  20852. else
  20853. {
  20854. while (--numSamples >= 0)
  20855. *d++ *= gain;
  20856. }
  20857. }
  20858. }
  20859. void AudioSampleBuffer::applyGainRamp (const int channel,
  20860. const int startSample,
  20861. int numSamples,
  20862. float startGain,
  20863. float endGain) throw()
  20864. {
  20865. if (startGain == endGain)
  20866. {
  20867. applyGain (channel, startSample, numSamples, startGain);
  20868. }
  20869. else
  20870. {
  20871. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20872. jassert (startSample >= 0 && startSample + numSamples <= size);
  20873. const float increment = (endGain - startGain) / numSamples;
  20874. float* d = channels [channel] + startSample;
  20875. while (--numSamples >= 0)
  20876. {
  20877. *d++ *= startGain;
  20878. startGain += increment;
  20879. }
  20880. }
  20881. }
  20882. void AudioSampleBuffer::applyGain (const int startSample,
  20883. const int numSamples,
  20884. const float gain) throw()
  20885. {
  20886. for (int i = 0; i < numChannels; ++i)
  20887. applyGain (i, startSample, numSamples, gain);
  20888. }
  20889. void AudioSampleBuffer::addFrom (const int destChannel,
  20890. const int destStartSample,
  20891. const AudioSampleBuffer& source,
  20892. const int sourceChannel,
  20893. const int sourceStartSample,
  20894. int numSamples,
  20895. const float gain) throw()
  20896. {
  20897. jassert (&source != this || sourceChannel != destChannel);
  20898. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20899. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20900. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20901. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20902. if (gain != 0.0f && numSamples > 0)
  20903. {
  20904. float* d = channels [destChannel] + destStartSample;
  20905. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20906. if (gain != 1.0f)
  20907. {
  20908. while (--numSamples >= 0)
  20909. *d++ += gain * *s++;
  20910. }
  20911. else
  20912. {
  20913. while (--numSamples >= 0)
  20914. *d++ += *s++;
  20915. }
  20916. }
  20917. }
  20918. void AudioSampleBuffer::addFrom (const int destChannel,
  20919. const int destStartSample,
  20920. const float* source,
  20921. int numSamples,
  20922. const float gain) throw()
  20923. {
  20924. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20925. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20926. jassert (source != 0);
  20927. if (gain != 0.0f && numSamples > 0)
  20928. {
  20929. float* d = channels [destChannel] + destStartSample;
  20930. if (gain != 1.0f)
  20931. {
  20932. while (--numSamples >= 0)
  20933. *d++ += gain * *source++;
  20934. }
  20935. else
  20936. {
  20937. while (--numSamples >= 0)
  20938. *d++ += *source++;
  20939. }
  20940. }
  20941. }
  20942. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20943. const int destStartSample,
  20944. const float* source,
  20945. int numSamples,
  20946. float startGain,
  20947. const float endGain) throw()
  20948. {
  20949. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20950. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20951. jassert (source != 0);
  20952. if (startGain == endGain)
  20953. {
  20954. addFrom (destChannel,
  20955. destStartSample,
  20956. source,
  20957. numSamples,
  20958. startGain);
  20959. }
  20960. else
  20961. {
  20962. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20963. {
  20964. const float increment = (endGain - startGain) / numSamples;
  20965. float* d = channels [destChannel] + destStartSample;
  20966. while (--numSamples >= 0)
  20967. {
  20968. *d++ += startGain * *source++;
  20969. startGain += increment;
  20970. }
  20971. }
  20972. }
  20973. }
  20974. void AudioSampleBuffer::copyFrom (const int destChannel,
  20975. const int destStartSample,
  20976. const AudioSampleBuffer& source,
  20977. const int sourceChannel,
  20978. const int sourceStartSample,
  20979. int numSamples) throw()
  20980. {
  20981. jassert (&source != this || sourceChannel != destChannel);
  20982. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20983. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20984. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20985. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20986. if (numSamples > 0)
  20987. {
  20988. memcpy (channels [destChannel] + destStartSample,
  20989. source.channels [sourceChannel] + sourceStartSample,
  20990. sizeof (float) * numSamples);
  20991. }
  20992. }
  20993. void AudioSampleBuffer::copyFrom (const int destChannel,
  20994. const int destStartSample,
  20995. const float* source,
  20996. int numSamples) throw()
  20997. {
  20998. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20999. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21000. jassert (source != 0);
  21001. if (numSamples > 0)
  21002. {
  21003. memcpy (channels [destChannel] + destStartSample,
  21004. source,
  21005. sizeof (float) * numSamples);
  21006. }
  21007. }
  21008. void AudioSampleBuffer::copyFrom (const int destChannel,
  21009. const int destStartSample,
  21010. const float* source,
  21011. int numSamples,
  21012. const float gain) throw()
  21013. {
  21014. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21015. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21016. jassert (source != 0);
  21017. if (numSamples > 0)
  21018. {
  21019. float* d = channels [destChannel] + destStartSample;
  21020. if (gain != 1.0f)
  21021. {
  21022. if (gain == 0)
  21023. {
  21024. zeromem (d, sizeof (float) * numSamples);
  21025. }
  21026. else
  21027. {
  21028. while (--numSamples >= 0)
  21029. *d++ = gain * *source++;
  21030. }
  21031. }
  21032. else
  21033. {
  21034. memcpy (d, source, sizeof (float) * numSamples);
  21035. }
  21036. }
  21037. }
  21038. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  21039. const int destStartSample,
  21040. const float* source,
  21041. int numSamples,
  21042. float startGain,
  21043. float endGain) throw()
  21044. {
  21045. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21046. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21047. jassert (source != 0);
  21048. if (startGain == endGain)
  21049. {
  21050. copyFrom (destChannel,
  21051. destStartSample,
  21052. source,
  21053. numSamples,
  21054. startGain);
  21055. }
  21056. else
  21057. {
  21058. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  21059. {
  21060. const float increment = (endGain - startGain) / numSamples;
  21061. float* d = channels [destChannel] + destStartSample;
  21062. while (--numSamples >= 0)
  21063. {
  21064. *d++ = startGain * *source++;
  21065. startGain += increment;
  21066. }
  21067. }
  21068. }
  21069. }
  21070. void AudioSampleBuffer::findMinMax (const int channel,
  21071. const int startSample,
  21072. int numSamples,
  21073. float& minVal,
  21074. float& maxVal) const throw()
  21075. {
  21076. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21077. jassert (startSample >= 0 && startSample + numSamples <= size);
  21078. if (numSamples <= 0)
  21079. {
  21080. minVal = 0.0f;
  21081. maxVal = 0.0f;
  21082. }
  21083. else
  21084. {
  21085. const float* d = channels [channel] + startSample;
  21086. float mn = *d++;
  21087. float mx = mn;
  21088. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  21089. {
  21090. const float samp = *d++;
  21091. if (samp > mx)
  21092. mx = samp;
  21093. if (samp < mn)
  21094. mn = samp;
  21095. }
  21096. maxVal = mx;
  21097. minVal = mn;
  21098. }
  21099. }
  21100. float AudioSampleBuffer::getMagnitude (const int channel,
  21101. const int startSample,
  21102. const int numSamples) const throw()
  21103. {
  21104. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21105. jassert (startSample >= 0 && startSample + numSamples <= size);
  21106. float mn, mx;
  21107. findMinMax (channel, startSample, numSamples, mn, mx);
  21108. return jmax (mn, -mn, mx, -mx);
  21109. }
  21110. float AudioSampleBuffer::getMagnitude (const int startSample,
  21111. const int numSamples) const throw()
  21112. {
  21113. float mag = 0.0f;
  21114. for (int i = 0; i < numChannels; ++i)
  21115. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  21116. return mag;
  21117. }
  21118. float AudioSampleBuffer::getRMSLevel (const int channel,
  21119. const int startSample,
  21120. const int numSamples) const throw()
  21121. {
  21122. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21123. jassert (startSample >= 0 && startSample + numSamples <= size);
  21124. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  21125. return 0.0f;
  21126. const float* const data = channels [channel] + startSample;
  21127. double sum = 0.0;
  21128. for (int i = 0; i < numSamples; ++i)
  21129. {
  21130. const float sample = data [i];
  21131. sum += sample * sample;
  21132. }
  21133. return (float) sqrt (sum / numSamples);
  21134. }
  21135. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  21136. const int startSample,
  21137. const int numSamples,
  21138. const int readerStartSample,
  21139. const bool useLeftChan,
  21140. const bool useRightChan) throw()
  21141. {
  21142. jassert (reader != 0);
  21143. jassert (startSample >= 0 && startSample + numSamples <= size);
  21144. if (numSamples > 0)
  21145. {
  21146. int* chans[3];
  21147. if (useLeftChan == useRightChan)
  21148. {
  21149. chans[0] = (int*) getSampleData (0, startSample);
  21150. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  21151. }
  21152. else if (useLeftChan || (reader->numChannels == 1))
  21153. {
  21154. chans[0] = (int*) getSampleData (0, startSample);
  21155. chans[1] = 0;
  21156. }
  21157. else if (useRightChan)
  21158. {
  21159. chans[0] = 0;
  21160. chans[1] = (int*) getSampleData (0, startSample);
  21161. }
  21162. chans[2] = 0;
  21163. reader->read (chans, 2, readerStartSample, numSamples, true);
  21164. if (! reader->usesFloatingPointData)
  21165. {
  21166. for (int j = 0; j < 2; ++j)
  21167. {
  21168. float* const d = (float*) (chans[j]);
  21169. if (d != 0)
  21170. {
  21171. const float multiplier = 1.0f / 0x7fffffff;
  21172. for (int i = 0; i < numSamples; ++i)
  21173. d[i] = *(int*)(d + i) * multiplier;
  21174. }
  21175. }
  21176. }
  21177. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  21178. {
  21179. // if this is a stereo buffer and the source was mono, dupe the first channel..
  21180. memcpy (getSampleData (1, startSample),
  21181. getSampleData (0, startSample),
  21182. sizeof (float) * numSamples);
  21183. }
  21184. }
  21185. }
  21186. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  21187. const int startSample,
  21188. const int numSamples) const throw()
  21189. {
  21190. jassert (startSample >= 0 && startSample + numSamples <= size);
  21191. if (numSamples > 0)
  21192. {
  21193. int* chans [3];
  21194. if (writer->isFloatingPoint())
  21195. {
  21196. chans[0] = (int*) getSampleData (0, startSample);
  21197. if (numChannels > 1)
  21198. chans[1] = (int*) getSampleData (1, startSample);
  21199. else
  21200. chans[1] = 0;
  21201. chans[2] = 0;
  21202. writer->write ((const int**) chans, numSamples);
  21203. }
  21204. else
  21205. {
  21206. HeapBlock <int> tempBuffer (numSamples * 2);
  21207. chans[0] = tempBuffer;
  21208. if (numChannels > 1)
  21209. chans[1] = chans[0] + numSamples;
  21210. else
  21211. chans[1] = 0;
  21212. chans[2] = 0;
  21213. for (int j = 0; j < 2; ++j)
  21214. {
  21215. int* const dest = chans[j];
  21216. if (dest != 0)
  21217. {
  21218. const float* const src = channels [j] + startSample;
  21219. for (int i = 0; i < numSamples; ++i)
  21220. {
  21221. const double samp = src[i];
  21222. if (samp <= -1.0)
  21223. dest[i] = std::numeric_limits<int>::min();
  21224. else if (samp >= 1.0)
  21225. dest[i] = std::numeric_limits<int>::max();
  21226. else
  21227. dest[i] = roundToInt (std::numeric_limits<int>::max() * samp);
  21228. }
  21229. }
  21230. }
  21231. writer->write ((const int**) chans, numSamples);
  21232. }
  21233. }
  21234. }
  21235. END_JUCE_NAMESPACE
  21236. /*** End of inlined file: juce_AudioSampleBuffer.cpp ***/
  21237. /*** Start of inlined file: juce_IIRFilter.cpp ***/
  21238. BEGIN_JUCE_NAMESPACE
  21239. IIRFilter::IIRFilter() throw()
  21240. : active (false)
  21241. {
  21242. reset();
  21243. }
  21244. IIRFilter::IIRFilter (const IIRFilter& other) throw()
  21245. : active (other.active)
  21246. {
  21247. const ScopedLock sl (other.processLock);
  21248. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21249. reset();
  21250. }
  21251. IIRFilter::~IIRFilter() throw()
  21252. {
  21253. }
  21254. void IIRFilter::reset() throw()
  21255. {
  21256. const ScopedLock sl (processLock);
  21257. x1 = 0;
  21258. x2 = 0;
  21259. y1 = 0;
  21260. y2 = 0;
  21261. }
  21262. float IIRFilter::processSingleSampleRaw (const float in) throw()
  21263. {
  21264. float out = coefficients[0] * in
  21265. + coefficients[1] * x1
  21266. + coefficients[2] * x2
  21267. - coefficients[4] * y1
  21268. - coefficients[5] * y2;
  21269. #if JUCE_INTEL
  21270. if (! (out < -1.0e-8 || out > 1.0e-8))
  21271. out = 0;
  21272. #endif
  21273. x2 = x1;
  21274. x1 = in;
  21275. y2 = y1;
  21276. y1 = out;
  21277. return out;
  21278. }
  21279. void IIRFilter::processSamples (float* const samples,
  21280. const int numSamples) throw()
  21281. {
  21282. const ScopedLock sl (processLock);
  21283. if (active)
  21284. {
  21285. for (int i = 0; i < numSamples; ++i)
  21286. {
  21287. const float in = samples[i];
  21288. float out = coefficients[0] * in
  21289. + coefficients[1] * x1
  21290. + coefficients[2] * x2
  21291. - coefficients[4] * y1
  21292. - coefficients[5] * y2;
  21293. #if JUCE_INTEL
  21294. if (! (out < -1.0e-8 || out > 1.0e-8))
  21295. out = 0;
  21296. #endif
  21297. x2 = x1;
  21298. x1 = in;
  21299. y2 = y1;
  21300. y1 = out;
  21301. samples[i] = out;
  21302. }
  21303. }
  21304. }
  21305. void IIRFilter::makeLowPass (const double sampleRate,
  21306. const double frequency) throw()
  21307. {
  21308. jassert (sampleRate > 0);
  21309. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21310. const double nSquared = n * n;
  21311. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21312. setCoefficients (c1,
  21313. c1 * 2.0f,
  21314. c1,
  21315. 1.0,
  21316. c1 * 2.0 * (1.0 - nSquared),
  21317. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21318. }
  21319. void IIRFilter::makeHighPass (const double sampleRate,
  21320. const double frequency) throw()
  21321. {
  21322. const double n = tan (double_Pi * frequency / sampleRate);
  21323. const double nSquared = n * n;
  21324. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21325. setCoefficients (c1,
  21326. c1 * -2.0f,
  21327. c1,
  21328. 1.0,
  21329. c1 * 2.0 * (nSquared - 1.0),
  21330. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21331. }
  21332. void IIRFilter::makeLowShelf (const double sampleRate,
  21333. const double cutOffFrequency,
  21334. const double Q,
  21335. const float gainFactor) throw()
  21336. {
  21337. jassert (sampleRate > 0);
  21338. jassert (Q > 0);
  21339. const double A = jmax (0.0f, gainFactor);
  21340. const double aminus1 = A - 1.0;
  21341. const double aplus1 = A + 1.0;
  21342. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21343. const double coso = cos (omega);
  21344. const double beta = sin (omega) * sqrt (A) / Q;
  21345. const double aminus1TimesCoso = aminus1 * coso;
  21346. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21347. A * 2.0 * (aminus1 - aplus1 * coso),
  21348. A * (aplus1 - aminus1TimesCoso - beta),
  21349. aplus1 + aminus1TimesCoso + beta,
  21350. -2.0 * (aminus1 + aplus1 * coso),
  21351. aplus1 + aminus1TimesCoso - beta);
  21352. }
  21353. void IIRFilter::makeHighShelf (const double sampleRate,
  21354. const double cutOffFrequency,
  21355. const double Q,
  21356. const float gainFactor) throw()
  21357. {
  21358. jassert (sampleRate > 0);
  21359. jassert (Q > 0);
  21360. const double A = jmax (0.0f, gainFactor);
  21361. const double aminus1 = A - 1.0;
  21362. const double aplus1 = A + 1.0;
  21363. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21364. const double coso = cos (omega);
  21365. const double beta = sin (omega) * sqrt (A) / Q;
  21366. const double aminus1TimesCoso = aminus1 * coso;
  21367. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21368. A * -2.0 * (aminus1 + aplus1 * coso),
  21369. A * (aplus1 + aminus1TimesCoso - beta),
  21370. aplus1 - aminus1TimesCoso + beta,
  21371. 2.0 * (aminus1 - aplus1 * coso),
  21372. aplus1 - aminus1TimesCoso - beta);
  21373. }
  21374. void IIRFilter::makeBandPass (const double sampleRate,
  21375. const double centreFrequency,
  21376. const double Q,
  21377. const float gainFactor) throw()
  21378. {
  21379. jassert (sampleRate > 0);
  21380. jassert (Q > 0);
  21381. const double A = jmax (0.0f, gainFactor);
  21382. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21383. const double alpha = 0.5 * sin (omega) / Q;
  21384. const double c2 = -2.0 * cos (omega);
  21385. const double alphaTimesA = alpha * A;
  21386. const double alphaOverA = alpha / A;
  21387. setCoefficients (1.0 + alphaTimesA,
  21388. c2,
  21389. 1.0 - alphaTimesA,
  21390. 1.0 + alphaOverA,
  21391. c2,
  21392. 1.0 - alphaOverA);
  21393. }
  21394. void IIRFilter::makeInactive() throw()
  21395. {
  21396. const ScopedLock sl (processLock);
  21397. active = false;
  21398. }
  21399. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21400. {
  21401. const ScopedLock sl (processLock);
  21402. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21403. active = other.active;
  21404. }
  21405. void IIRFilter::setCoefficients (double c1,
  21406. double c2,
  21407. double c3,
  21408. double c4,
  21409. double c5,
  21410. double c6) throw()
  21411. {
  21412. const double a = 1.0 / c4;
  21413. c1 *= a;
  21414. c2 *= a;
  21415. c3 *= a;
  21416. c5 *= a;
  21417. c6 *= a;
  21418. const ScopedLock sl (processLock);
  21419. coefficients[0] = (float) c1;
  21420. coefficients[1] = (float) c2;
  21421. coefficients[2] = (float) c3;
  21422. coefficients[3] = (float) c4;
  21423. coefficients[4] = (float) c5;
  21424. coefficients[5] = (float) c6;
  21425. active = true;
  21426. }
  21427. END_JUCE_NAMESPACE
  21428. /*** End of inlined file: juce_IIRFilter.cpp ***/
  21429. /*** Start of inlined file: juce_MidiBuffer.cpp ***/
  21430. BEGIN_JUCE_NAMESPACE
  21431. MidiBuffer::MidiBuffer() throw()
  21432. : bytesUsed (0)
  21433. {
  21434. }
  21435. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21436. : bytesUsed (0)
  21437. {
  21438. addEvent (message, 0);
  21439. }
  21440. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21441. : data (other.data),
  21442. bytesUsed (other.bytesUsed)
  21443. {
  21444. }
  21445. MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21446. {
  21447. bytesUsed = other.bytesUsed;
  21448. data = other.data;
  21449. return *this;
  21450. }
  21451. void MidiBuffer::swap (MidiBuffer& other)
  21452. {
  21453. data.swapWith (other.data);
  21454. swapVariables <int> (bytesUsed, other.bytesUsed);
  21455. }
  21456. MidiBuffer::~MidiBuffer() throw()
  21457. {
  21458. }
  21459. void MidiBuffer::clear() throw()
  21460. {
  21461. bytesUsed = 0;
  21462. }
  21463. void MidiBuffer::clear (const int startSample,
  21464. const int numSamples) throw()
  21465. {
  21466. uint8* const start = findEventAfter (getData(), startSample - 1);
  21467. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21468. if (end > start)
  21469. {
  21470. const size_t bytesToMove = (size_t) (bytesUsed - (end - getData()));
  21471. if (bytesToMove > 0)
  21472. memmove (start, end, bytesToMove);
  21473. bytesUsed -= (int) (end - start);
  21474. }
  21475. }
  21476. void MidiBuffer::addEvent (const MidiMessage& m,
  21477. const int sampleNumber) throw()
  21478. {
  21479. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21480. }
  21481. static int findActualEventLength (const uint8* const data,
  21482. const int maxBytes) throw()
  21483. {
  21484. unsigned int byte = (unsigned int) *data;
  21485. int size = 0;
  21486. if (byte == 0xf0 || byte == 0xf7)
  21487. {
  21488. const uint8* d = data + 1;
  21489. while (d < data + maxBytes)
  21490. if (*d++ == 0xf7)
  21491. break;
  21492. size = (int) (d - data);
  21493. }
  21494. else if (byte == 0xff)
  21495. {
  21496. int n;
  21497. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21498. size = jmin (maxBytes, n + 2 + bytesLeft);
  21499. }
  21500. else if (byte >= 0x80)
  21501. {
  21502. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21503. }
  21504. return size;
  21505. }
  21506. void MidiBuffer::addEvent (const uint8* const newData,
  21507. const int maxBytes,
  21508. const int sampleNumber) throw()
  21509. {
  21510. const int numBytes = findActualEventLength (newData, maxBytes);
  21511. if (numBytes > 0)
  21512. {
  21513. int spaceNeeded = bytesUsed + numBytes + 6;
  21514. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21515. uint8* d = findEventAfter (getData(), sampleNumber);
  21516. const size_t bytesToMove = (size_t) (bytesUsed - (d - getData()));
  21517. if (bytesToMove > 0)
  21518. memmove (d + numBytes + 6,
  21519. d,
  21520. bytesToMove);
  21521. *(int*) d = sampleNumber;
  21522. d += 4;
  21523. *(uint16*) d = (uint16) numBytes;
  21524. d += 2;
  21525. memcpy (d, newData, numBytes);
  21526. bytesUsed += numBytes + 6;
  21527. }
  21528. }
  21529. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21530. const int startSample,
  21531. const int numSamples,
  21532. const int sampleDeltaToAdd) throw()
  21533. {
  21534. Iterator i (otherBuffer);
  21535. i.setNextSamplePosition (startSample);
  21536. const uint8* eventData;
  21537. int eventSize, position;
  21538. while (i.getNextEvent (eventData, eventSize, position)
  21539. && (position < startSample + numSamples || numSamples < 0))
  21540. {
  21541. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21542. }
  21543. }
  21544. bool MidiBuffer::isEmpty() const throw()
  21545. {
  21546. return bytesUsed == 0;
  21547. }
  21548. int MidiBuffer::getNumEvents() const throw()
  21549. {
  21550. int n = 0;
  21551. const uint8* d = getData();
  21552. const uint8* const end = d + bytesUsed;
  21553. while (d < end)
  21554. {
  21555. d += 4;
  21556. d += 2 + *(const uint16*) d;
  21557. ++n;
  21558. }
  21559. return n;
  21560. }
  21561. int MidiBuffer::getFirstEventTime() const throw()
  21562. {
  21563. return (bytesUsed > 0) ? *reinterpret_cast <const int*> (data.getData()) : 0;
  21564. }
  21565. int MidiBuffer::getLastEventTime() const throw()
  21566. {
  21567. if (bytesUsed == 0)
  21568. return 0;
  21569. const uint8* d = getData();
  21570. const uint8* const endData = d + bytesUsed;
  21571. for (;;)
  21572. {
  21573. const uint8* nextOne = d + 6 + * (const uint16*) (d + 4);
  21574. if (nextOne >= endData)
  21575. return *(const int*) d;
  21576. d = nextOne;
  21577. }
  21578. }
  21579. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21580. {
  21581. const uint8* const endData = getData() + bytesUsed;
  21582. while (d < endData && *(int*) d <= samplePosition)
  21583. {
  21584. d += 4;
  21585. d += 2 + *(uint16*) d;
  21586. }
  21587. return d;
  21588. }
  21589. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21590. : buffer (buffer_),
  21591. data (buffer_.getData())
  21592. {
  21593. }
  21594. MidiBuffer::Iterator::~Iterator() throw()
  21595. {
  21596. }
  21597. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21598. {
  21599. data = buffer.getData();
  21600. const uint8* dataEnd = data + buffer.bytesUsed;
  21601. while (data < dataEnd && *reinterpret_cast<const int*> (data) < samplePosition)
  21602. {
  21603. data += 4;
  21604. data += 2 + *(uint16*) data;
  21605. }
  21606. }
  21607. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData,
  21608. int& numBytes,
  21609. int& samplePosition) throw()
  21610. {
  21611. if (data >= buffer.getData() + buffer.bytesUsed)
  21612. return false;
  21613. samplePosition = *(int*) data;
  21614. data += 4;
  21615. numBytes = *(uint16*) data;
  21616. data += 2;
  21617. midiData = data;
  21618. data += numBytes;
  21619. return true;
  21620. }
  21621. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result,
  21622. int& samplePosition) throw()
  21623. {
  21624. if (data >= buffer.getData() + buffer.bytesUsed)
  21625. return false;
  21626. samplePosition = *reinterpret_cast <const int*> (data);
  21627. data += 4;
  21628. const int numBytes = *reinterpret_cast <const uint16*> (data);
  21629. data += 2;
  21630. result = MidiMessage (data, numBytes, samplePosition);
  21631. data += numBytes;
  21632. return true;
  21633. }
  21634. END_JUCE_NAMESPACE
  21635. /*** End of inlined file: juce_MidiBuffer.cpp ***/
  21636. /*** Start of inlined file: juce_MidiFile.cpp ***/
  21637. BEGIN_JUCE_NAMESPACE
  21638. namespace MidiFileHelpers
  21639. {
  21640. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21641. {
  21642. unsigned int buffer = v & 0x7F;
  21643. while ((v >>= 7) != 0)
  21644. {
  21645. buffer <<= 8;
  21646. buffer |= ((v & 0x7F) | 0x80);
  21647. }
  21648. for (;;)
  21649. {
  21650. out.writeByte ((char) buffer);
  21651. if (buffer & 0x80)
  21652. buffer >>= 8;
  21653. else
  21654. break;
  21655. }
  21656. }
  21657. static bool parseMidiHeader (const char* &data, short& timeFormat, short& fileType, short& numberOfTracks) throw()
  21658. {
  21659. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21660. data += 4;
  21661. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21662. {
  21663. bool ok = false;
  21664. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21665. {
  21666. for (int i = 0; i < 8; ++i)
  21667. {
  21668. ch = ByteOrder::bigEndianInt (data);
  21669. data += 4;
  21670. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21671. {
  21672. ok = true;
  21673. break;
  21674. }
  21675. }
  21676. }
  21677. if (! ok)
  21678. return false;
  21679. }
  21680. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21681. data += 4;
  21682. fileType = (short) ByteOrder::bigEndianShort (data);
  21683. data += 2;
  21684. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21685. data += 2;
  21686. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21687. data += 2;
  21688. bytesRemaining -= 6;
  21689. data += bytesRemaining;
  21690. return true;
  21691. }
  21692. static double convertTicksToSeconds (const double time,
  21693. const MidiMessageSequence& tempoEvents,
  21694. const int timeFormat)
  21695. {
  21696. if (timeFormat > 0)
  21697. {
  21698. int numer = 4, denom = 4;
  21699. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21700. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21701. double secsPerTick = 0.5 * tickLen;
  21702. const int numEvents = tempoEvents.getNumEvents();
  21703. for (int i = 0; i < numEvents; ++i)
  21704. {
  21705. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21706. if (time <= m.getTimeStamp())
  21707. break;
  21708. if (timeFormat > 0)
  21709. {
  21710. correctedTempoTime = correctedTempoTime
  21711. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21712. }
  21713. else
  21714. {
  21715. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21716. }
  21717. tempoTime = m.getTimeStamp();
  21718. if (m.isTempoMetaEvent())
  21719. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21720. else if (m.isTimeSignatureMetaEvent())
  21721. m.getTimeSignatureInfo (numer, denom);
  21722. while (i + 1 < numEvents)
  21723. {
  21724. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21725. if (m2.getTimeStamp() == tempoTime)
  21726. {
  21727. ++i;
  21728. if (m2.isTempoMetaEvent())
  21729. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21730. else if (m2.isTimeSignatureMetaEvent())
  21731. m2.getTimeSignatureInfo (numer, denom);
  21732. }
  21733. else
  21734. {
  21735. break;
  21736. }
  21737. }
  21738. }
  21739. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21740. }
  21741. else
  21742. {
  21743. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21744. }
  21745. }
  21746. }
  21747. MidiFile::MidiFile() throw()
  21748. : timeFormat ((short) (unsigned short) 0xe728)
  21749. {
  21750. }
  21751. MidiFile::~MidiFile() throw()
  21752. {
  21753. clear();
  21754. }
  21755. void MidiFile::clear() throw()
  21756. {
  21757. tracks.clear();
  21758. }
  21759. int MidiFile::getNumTracks() const throw()
  21760. {
  21761. return tracks.size();
  21762. }
  21763. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21764. {
  21765. return tracks [index];
  21766. }
  21767. void MidiFile::addTrack (const MidiMessageSequence& trackSequence) throw()
  21768. {
  21769. tracks.add (new MidiMessageSequence (trackSequence));
  21770. }
  21771. short MidiFile::getTimeFormat() const throw()
  21772. {
  21773. return timeFormat;
  21774. }
  21775. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21776. {
  21777. timeFormat = (short)ticks;
  21778. }
  21779. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21780. const int subframeResolution) throw()
  21781. {
  21782. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21783. }
  21784. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21785. {
  21786. for (int i = tracks.size(); --i >= 0;)
  21787. {
  21788. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21789. for (int j = 0; j < numEvents; ++j)
  21790. {
  21791. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21792. if (m.isTempoMetaEvent())
  21793. tempoChangeEvents.addEvent (m);
  21794. }
  21795. }
  21796. }
  21797. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21798. {
  21799. for (int i = tracks.size(); --i >= 0;)
  21800. {
  21801. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21802. for (int j = 0; j < numEvents; ++j)
  21803. {
  21804. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21805. if (m.isTimeSignatureMetaEvent())
  21806. timeSigEvents.addEvent (m);
  21807. }
  21808. }
  21809. }
  21810. double MidiFile::getLastTimestamp() const
  21811. {
  21812. double t = 0.0;
  21813. for (int i = tracks.size(); --i >= 0;)
  21814. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21815. return t;
  21816. }
  21817. bool MidiFile::readFrom (InputStream& sourceStream)
  21818. {
  21819. clear();
  21820. MemoryBlock data;
  21821. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21822. // (put a sanity-check on the file size, as midi files are generally small)
  21823. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21824. {
  21825. size_t size = data.getSize();
  21826. const char* d = (char*) data.getData();
  21827. short fileType, expectedTracks;
  21828. if (size > 16 && MidiFileHelpers::parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21829. {
  21830. size -= (int) (d - (char*) data.getData());
  21831. int track = 0;
  21832. while (size > 0 && track < expectedTracks)
  21833. {
  21834. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21835. d += 4;
  21836. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21837. d += 4;
  21838. if (chunkSize <= 0)
  21839. break;
  21840. if (size < 0)
  21841. return false;
  21842. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21843. {
  21844. readNextTrack (d, chunkSize);
  21845. }
  21846. size -= chunkSize + 8;
  21847. d += chunkSize;
  21848. ++track;
  21849. }
  21850. return true;
  21851. }
  21852. }
  21853. return false;
  21854. }
  21855. // a comparator that puts all the note-offs before note-ons that have the same time
  21856. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21857. const MidiMessageSequence::MidiEventHolder* const second) throw()
  21858. {
  21859. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21860. if (diff == 0)
  21861. {
  21862. if (first->message.isNoteOff() && second->message.isNoteOn())
  21863. return -1;
  21864. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21865. return 1;
  21866. else
  21867. return 0;
  21868. }
  21869. else
  21870. {
  21871. return (diff > 0) ? 1 : -1;
  21872. }
  21873. }
  21874. void MidiFile::readNextTrack (const char* data, int size)
  21875. {
  21876. double time = 0;
  21877. char lastStatusByte = 0;
  21878. MidiMessageSequence result;
  21879. while (size > 0)
  21880. {
  21881. int bytesUsed;
  21882. const int delay = MidiMessage::readVariableLengthVal ((const uint8*) data, bytesUsed);
  21883. data += bytesUsed;
  21884. size -= bytesUsed;
  21885. time += delay;
  21886. int messSize = 0;
  21887. const MidiMessage mm ((const uint8*) data, size, messSize, lastStatusByte, time);
  21888. if (messSize <= 0)
  21889. break;
  21890. size -= messSize;
  21891. data += messSize;
  21892. result.addEvent (mm);
  21893. const char firstByte = *(mm.getRawData());
  21894. if ((firstByte & 0xf0) != 0xf0)
  21895. lastStatusByte = firstByte;
  21896. }
  21897. // use a sort that puts all the note-offs before note-ons that have the same time
  21898. result.list.sort (*this, true);
  21899. result.updateMatchedPairs();
  21900. addTrack (result);
  21901. }
  21902. void MidiFile::convertTimestampTicksToSeconds()
  21903. {
  21904. MidiMessageSequence tempoEvents;
  21905. findAllTempoEvents (tempoEvents);
  21906. findAllTimeSigEvents (tempoEvents);
  21907. for (int i = 0; i < tracks.size(); ++i)
  21908. {
  21909. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21910. for (int j = ms.getNumEvents(); --j >= 0;)
  21911. {
  21912. MidiMessage& m = ms.getEventPointer(j)->message;
  21913. m.setTimeStamp (MidiFileHelpers::convertTicksToSeconds (m.getTimeStamp(),
  21914. tempoEvents,
  21915. timeFormat));
  21916. }
  21917. }
  21918. }
  21919. bool MidiFile::writeTo (OutputStream& out)
  21920. {
  21921. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21922. out.writeIntBigEndian (6);
  21923. out.writeShortBigEndian (1); // type
  21924. out.writeShortBigEndian ((short) tracks.size());
  21925. out.writeShortBigEndian (timeFormat);
  21926. for (int i = 0; i < tracks.size(); ++i)
  21927. writeTrack (out, i);
  21928. out.flush();
  21929. return true;
  21930. }
  21931. void MidiFile::writeTrack (OutputStream& mainOut,
  21932. const int trackNum)
  21933. {
  21934. MemoryOutputStream out;
  21935. const MidiMessageSequence& ms = *tracks[trackNum];
  21936. int lastTick = 0;
  21937. char lastStatusByte = 0;
  21938. for (int i = 0; i < ms.getNumEvents(); ++i)
  21939. {
  21940. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21941. const int tick = roundToInt (mm.getTimeStamp());
  21942. const int delta = jmax (0, tick - lastTick);
  21943. MidiFileHelpers::writeVariableLengthInt (out, delta);
  21944. lastTick = tick;
  21945. const char statusByte = *(mm.getRawData());
  21946. if ((statusByte == lastStatusByte)
  21947. && ((statusByte & 0xf0) != 0xf0)
  21948. && i > 0
  21949. && mm.getRawDataSize() > 1)
  21950. {
  21951. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21952. }
  21953. else
  21954. {
  21955. out.write (mm.getRawData(), mm.getRawDataSize());
  21956. }
  21957. lastStatusByte = statusByte;
  21958. }
  21959. out.writeByte (0);
  21960. const MidiMessage m (MidiMessage::endOfTrack());
  21961. out.write (m.getRawData(),
  21962. m.getRawDataSize());
  21963. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  21964. mainOut.writeIntBigEndian ((int) out.getDataSize());
  21965. mainOut.write (out.getData(), (int) out.getDataSize());
  21966. }
  21967. END_JUCE_NAMESPACE
  21968. /*** End of inlined file: juce_MidiFile.cpp ***/
  21969. /*** Start of inlined file: juce_MidiKeyboardState.cpp ***/
  21970. BEGIN_JUCE_NAMESPACE
  21971. MidiKeyboardState::MidiKeyboardState()
  21972. {
  21973. zeromem (noteStates, sizeof (noteStates));
  21974. }
  21975. MidiKeyboardState::~MidiKeyboardState()
  21976. {
  21977. }
  21978. void MidiKeyboardState::reset()
  21979. {
  21980. const ScopedLock sl (lock);
  21981. zeromem (noteStates, sizeof (noteStates));
  21982. eventsToAdd.clear();
  21983. }
  21984. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  21985. {
  21986. jassert (midiChannel >= 0 && midiChannel <= 16);
  21987. return ((unsigned int) n) < 128
  21988. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  21989. }
  21990. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  21991. {
  21992. return ((unsigned int) n) < 128
  21993. && (noteStates[n] & midiChannelMask) != 0;
  21994. }
  21995. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  21996. {
  21997. jassert (midiChannel >= 0 && midiChannel <= 16);
  21998. jassert (((unsigned int) midiNoteNumber) < 128);
  21999. const ScopedLock sl (lock);
  22000. if (((unsigned int) midiNoteNumber) < 128)
  22001. {
  22002. const int timeNow = (int) Time::getMillisecondCounter();
  22003. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  22004. eventsToAdd.clear (0, timeNow - 500);
  22005. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  22006. }
  22007. }
  22008. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  22009. {
  22010. if (((unsigned int) midiNoteNumber) < 128)
  22011. {
  22012. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  22013. for (int i = listeners.size(); --i >= 0;)
  22014. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  22015. ->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  22016. }
  22017. }
  22018. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  22019. {
  22020. const ScopedLock sl (lock);
  22021. if (isNoteOn (midiChannel, midiNoteNumber))
  22022. {
  22023. const int timeNow = (int) Time::getMillisecondCounter();
  22024. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  22025. eventsToAdd.clear (0, timeNow - 500);
  22026. noteOffInternal (midiChannel, midiNoteNumber);
  22027. }
  22028. }
  22029. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  22030. {
  22031. if (isNoteOn (midiChannel, midiNoteNumber))
  22032. {
  22033. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  22034. for (int i = listeners.size(); --i >= 0;)
  22035. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  22036. ->handleNoteOff (this, midiChannel, midiNoteNumber);
  22037. }
  22038. }
  22039. void MidiKeyboardState::allNotesOff (const int midiChannel)
  22040. {
  22041. const ScopedLock sl (lock);
  22042. if (midiChannel <= 0)
  22043. {
  22044. for (int i = 1; i <= 16; ++i)
  22045. allNotesOff (i);
  22046. }
  22047. else
  22048. {
  22049. for (int i = 0; i < 128; ++i)
  22050. noteOff (midiChannel, i);
  22051. }
  22052. }
  22053. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  22054. {
  22055. if (message.isNoteOn())
  22056. {
  22057. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  22058. }
  22059. else if (message.isNoteOff())
  22060. {
  22061. noteOffInternal (message.getChannel(), message.getNoteNumber());
  22062. }
  22063. else if (message.isAllNotesOff())
  22064. {
  22065. for (int i = 0; i < 128; ++i)
  22066. noteOffInternal (message.getChannel(), i);
  22067. }
  22068. }
  22069. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  22070. const int startSample,
  22071. const int numSamples,
  22072. const bool injectIndirectEvents)
  22073. {
  22074. MidiBuffer::Iterator i (buffer);
  22075. MidiMessage message (0xf4, 0.0);
  22076. int time;
  22077. const ScopedLock sl (lock);
  22078. while (i.getNextEvent (message, time))
  22079. processNextMidiEvent (message);
  22080. if (injectIndirectEvents)
  22081. {
  22082. MidiBuffer::Iterator i2 (eventsToAdd);
  22083. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  22084. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  22085. while (i2.getNextEvent (message, time))
  22086. {
  22087. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  22088. buffer.addEvent (message, startSample + pos);
  22089. }
  22090. }
  22091. eventsToAdd.clear();
  22092. }
  22093. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  22094. {
  22095. const ScopedLock sl (lock);
  22096. listeners.addIfNotAlreadyThere (listener);
  22097. }
  22098. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  22099. {
  22100. const ScopedLock sl (lock);
  22101. listeners.removeValue (listener);
  22102. }
  22103. END_JUCE_NAMESPACE
  22104. /*** End of inlined file: juce_MidiKeyboardState.cpp ***/
  22105. /*** Start of inlined file: juce_MidiMessage.cpp ***/
  22106. BEGIN_JUCE_NAMESPACE
  22107. int MidiMessage::readVariableLengthVal (const uint8* data,
  22108. int& numBytesUsed) throw()
  22109. {
  22110. numBytesUsed = 0;
  22111. int v = 0;
  22112. int i;
  22113. do
  22114. {
  22115. i = (int) *data++;
  22116. if (++numBytesUsed > 6)
  22117. break;
  22118. v = (v << 7) + (i & 0x7f);
  22119. } while (i & 0x80);
  22120. return v;
  22121. }
  22122. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  22123. {
  22124. // this method only works for valid starting bytes of a short midi message
  22125. jassert (firstByte >= 0x80
  22126. && firstByte != 0xf0
  22127. && firstByte != 0xf7);
  22128. static const char messageLengths[] =
  22129. {
  22130. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22131. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22132. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22133. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22134. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22135. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22136. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22137. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  22138. };
  22139. return messageLengths [firstByte & 0x7f];
  22140. }
  22141. MidiMessage::MidiMessage (const uint8* const d,
  22142. const int dataSize,
  22143. const double t) throw()
  22144. : timeStamp (t),
  22145. message (0),
  22146. size (dataSize)
  22147. {
  22148. jassert (dataSize > 0);
  22149. if (dataSize <= 4)
  22150. data = (uint8*) &message;
  22151. else
  22152. data = (uint8*) juce_malloc (dataSize);
  22153. memcpy (data, d, dataSize);
  22154. // check that the length matches the data..
  22155. jassert (size > 3 || *d >= 0xf0 || getMessageLengthFromFirstByte (*d) == size);
  22156. }
  22157. MidiMessage::MidiMessage (const int byte1,
  22158. const double t) throw()
  22159. : timeStamp (t),
  22160. data ((uint8*) &message),
  22161. size (1)
  22162. {
  22163. data[0] = (uint8) byte1;
  22164. // check that the length matches the data..
  22165. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  22166. }
  22167. MidiMessage::MidiMessage (const int byte1,
  22168. const int byte2,
  22169. const double t) throw()
  22170. : timeStamp (t),
  22171. data ((uint8*) &message),
  22172. size (2)
  22173. {
  22174. data[0] = (uint8) byte1;
  22175. data[1] = (uint8) byte2;
  22176. // check that the length matches the data..
  22177. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  22178. }
  22179. MidiMessage::MidiMessage (const int byte1,
  22180. const int byte2,
  22181. const int byte3,
  22182. const double t) throw()
  22183. : timeStamp (t),
  22184. data ((uint8*) &message),
  22185. size (3)
  22186. {
  22187. data[0] = (uint8) byte1;
  22188. data[1] = (uint8) byte2;
  22189. data[2] = (uint8) byte3;
  22190. // check that the length matches the data..
  22191. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  22192. }
  22193. MidiMessage::MidiMessage (const MidiMessage& other) throw()
  22194. : timeStamp (other.timeStamp),
  22195. message (other.message),
  22196. size (other.size)
  22197. {
  22198. if (other.data != (uint8*) &other.message)
  22199. {
  22200. data = (uint8*) juce_malloc (size);
  22201. memcpy (data, other.data, size);
  22202. }
  22203. else
  22204. {
  22205. data = (uint8*) &message;
  22206. }
  22207. }
  22208. MidiMessage::MidiMessage (const MidiMessage& other,
  22209. const double newTimeStamp) throw()
  22210. : timeStamp (newTimeStamp),
  22211. message (other.message),
  22212. size (other.size)
  22213. {
  22214. if (other.data != (uint8*) &other.message)
  22215. {
  22216. data = (uint8*) juce_malloc (size);
  22217. memcpy (data, other.data, size);
  22218. }
  22219. else
  22220. {
  22221. data = (uint8*) &message;
  22222. }
  22223. }
  22224. MidiMessage::MidiMessage (const uint8* src,
  22225. int sz,
  22226. int& numBytesUsed,
  22227. const uint8 lastStatusByte,
  22228. double t) throw()
  22229. : timeStamp (t),
  22230. data ((uint8*) &message),
  22231. message (0)
  22232. {
  22233. unsigned int byte = (unsigned int) *src;
  22234. if (byte < 0x80)
  22235. {
  22236. byte = (unsigned int) (uint8) lastStatusByte;
  22237. numBytesUsed = -1;
  22238. }
  22239. else
  22240. {
  22241. numBytesUsed = 0;
  22242. --sz;
  22243. ++src;
  22244. }
  22245. if (byte >= 0x80)
  22246. {
  22247. if (byte == 0xf0)
  22248. {
  22249. const uint8* d = (const uint8*) src;
  22250. while (d < src + sz)
  22251. {
  22252. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  22253. {
  22254. if (*d == 0xf7) // include an 0xf7 if we hit one
  22255. ++d;
  22256. break;
  22257. }
  22258. ++d;
  22259. }
  22260. size = 1 + (int) (d - src);
  22261. data = (uint8*) juce_malloc (size);
  22262. *data = (uint8) byte;
  22263. memcpy (data + 1, src, size - 1);
  22264. }
  22265. else if (byte == 0xff)
  22266. {
  22267. int n;
  22268. const int bytesLeft = readVariableLengthVal (src + 1, n);
  22269. size = jmin (sz + 1, n + 2 + bytesLeft);
  22270. data = (uint8*) juce_malloc (size);
  22271. *data = (uint8) byte;
  22272. memcpy (data + 1, src, size - 1);
  22273. }
  22274. else
  22275. {
  22276. size = getMessageLengthFromFirstByte ((uint8) byte);
  22277. *data = (uint8) byte;
  22278. if (size > 1)
  22279. {
  22280. data[1] = src[0];
  22281. if (size > 2)
  22282. data[2] = src[1];
  22283. }
  22284. }
  22285. numBytesUsed += size;
  22286. }
  22287. else
  22288. {
  22289. message = 0;
  22290. size = 0;
  22291. }
  22292. }
  22293. MidiMessage& MidiMessage::operator= (const MidiMessage& other) throw()
  22294. {
  22295. if (this != &other)
  22296. {
  22297. timeStamp = other.timeStamp;
  22298. size = other.size;
  22299. message = other.message;
  22300. if (data != (uint8*) &message)
  22301. juce_free (data);
  22302. if (other.data != (uint8*) &other.message)
  22303. {
  22304. data = (uint8*) juce_malloc (size);
  22305. memcpy (data, other.data, size);
  22306. }
  22307. else
  22308. {
  22309. data = (uint8*) &message;
  22310. }
  22311. }
  22312. return *this;
  22313. }
  22314. MidiMessage::~MidiMessage() throw()
  22315. {
  22316. if (data != (uint8*) &message)
  22317. juce_free (data);
  22318. }
  22319. int MidiMessage::getChannel() const throw()
  22320. {
  22321. if ((data[0] & 0xf0) != 0xf0)
  22322. return (data[0] & 0xf) + 1;
  22323. else
  22324. return 0;
  22325. }
  22326. bool MidiMessage::isForChannel (const int channel) const throw()
  22327. {
  22328. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22329. return ((data[0] & 0xf) == channel - 1)
  22330. && ((data[0] & 0xf0) != 0xf0);
  22331. }
  22332. void MidiMessage::setChannel (const int channel) throw()
  22333. {
  22334. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22335. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22336. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22337. | (uint8)(channel - 1));
  22338. }
  22339. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22340. {
  22341. return ((data[0] & 0xf0) == 0x90)
  22342. && (returnTrueForVelocity0 || data[2] != 0);
  22343. }
  22344. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22345. {
  22346. return ((data[0] & 0xf0) == 0x80)
  22347. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22348. }
  22349. bool MidiMessage::isNoteOnOrOff() const throw()
  22350. {
  22351. const int d = data[0] & 0xf0;
  22352. return (d == 0x90) || (d == 0x80);
  22353. }
  22354. int MidiMessage::getNoteNumber() const throw()
  22355. {
  22356. return data[1];
  22357. }
  22358. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22359. {
  22360. if (isNoteOnOrOff())
  22361. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22362. }
  22363. uint8 MidiMessage::getVelocity() const throw()
  22364. {
  22365. if (isNoteOnOrOff())
  22366. return data[2];
  22367. else
  22368. return 0;
  22369. }
  22370. float MidiMessage::getFloatVelocity() const throw()
  22371. {
  22372. return getVelocity() * (1.0f / 127.0f);
  22373. }
  22374. void MidiMessage::setVelocity (const float newVelocity) throw()
  22375. {
  22376. if (isNoteOnOrOff())
  22377. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22378. }
  22379. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22380. {
  22381. if (isNoteOnOrOff())
  22382. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22383. }
  22384. bool MidiMessage::isAftertouch() const throw()
  22385. {
  22386. return (data[0] & 0xf0) == 0xa0;
  22387. }
  22388. int MidiMessage::getAfterTouchValue() const throw()
  22389. {
  22390. return data[2];
  22391. }
  22392. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22393. const int noteNum,
  22394. const int aftertouchValue) throw()
  22395. {
  22396. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22397. jassert (((unsigned int) noteNum) <= 127);
  22398. jassert (((unsigned int) aftertouchValue) <= 127);
  22399. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22400. noteNum & 0x7f,
  22401. aftertouchValue & 0x7f);
  22402. }
  22403. bool MidiMessage::isChannelPressure() const throw()
  22404. {
  22405. return (data[0] & 0xf0) == 0xd0;
  22406. }
  22407. int MidiMessage::getChannelPressureValue() const throw()
  22408. {
  22409. jassert (isChannelPressure());
  22410. return data[1];
  22411. }
  22412. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22413. const int pressure) throw()
  22414. {
  22415. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22416. jassert (((unsigned int) pressure) <= 127);
  22417. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22418. pressure & 0x7f);
  22419. }
  22420. bool MidiMessage::isProgramChange() const throw()
  22421. {
  22422. return (data[0] & 0xf0) == 0xc0;
  22423. }
  22424. int MidiMessage::getProgramChangeNumber() const throw()
  22425. {
  22426. return data[1];
  22427. }
  22428. const MidiMessage MidiMessage::programChange (const int channel,
  22429. const int programNumber) throw()
  22430. {
  22431. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22432. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22433. programNumber & 0x7f);
  22434. }
  22435. bool MidiMessage::isPitchWheel() const throw()
  22436. {
  22437. return (data[0] & 0xf0) == 0xe0;
  22438. }
  22439. int MidiMessage::getPitchWheelValue() const throw()
  22440. {
  22441. return data[1] | (data[2] << 7);
  22442. }
  22443. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22444. const int position) throw()
  22445. {
  22446. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22447. jassert (((unsigned int) position) <= 0x3fff);
  22448. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22449. position & 127,
  22450. (position >> 7) & 127);
  22451. }
  22452. bool MidiMessage::isController() const throw()
  22453. {
  22454. return (data[0] & 0xf0) == 0xb0;
  22455. }
  22456. int MidiMessage::getControllerNumber() const throw()
  22457. {
  22458. jassert (isController());
  22459. return data[1];
  22460. }
  22461. int MidiMessage::getControllerValue() const throw()
  22462. {
  22463. jassert (isController());
  22464. return data[2];
  22465. }
  22466. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22467. const int controllerType,
  22468. const int value) throw()
  22469. {
  22470. // the channel must be between 1 and 16 inclusive
  22471. jassert (channel > 0 && channel <= 16);
  22472. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22473. controllerType & 127,
  22474. value & 127);
  22475. }
  22476. const MidiMessage MidiMessage::noteOn (const int channel,
  22477. const int noteNumber,
  22478. const float velocity) throw()
  22479. {
  22480. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22481. }
  22482. const MidiMessage MidiMessage::noteOn (const int channel,
  22483. const int noteNumber,
  22484. const uint8 velocity) throw()
  22485. {
  22486. jassert (channel > 0 && channel <= 16);
  22487. jassert (((unsigned int) noteNumber) <= 127);
  22488. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22489. noteNumber & 127,
  22490. jlimit (0, 127, roundToInt (velocity)));
  22491. }
  22492. const MidiMessage MidiMessage::noteOff (const int channel,
  22493. const int noteNumber) throw()
  22494. {
  22495. jassert (channel > 0 && channel <= 16);
  22496. jassert (((unsigned int) noteNumber) <= 127);
  22497. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22498. }
  22499. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22500. {
  22501. jassert (channel > 0 && channel <= 16);
  22502. return controllerEvent (channel, 123, 0);
  22503. }
  22504. bool MidiMessage::isAllNotesOff() const throw()
  22505. {
  22506. return (data[0] & 0xf0) == 0xb0
  22507. && data[1] == 123;
  22508. }
  22509. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22510. {
  22511. return controllerEvent (channel, 120, 0);
  22512. }
  22513. bool MidiMessage::isAllSoundOff() const throw()
  22514. {
  22515. return (data[0] & 0xf0) == 0xb0
  22516. && data[1] == 120;
  22517. }
  22518. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22519. {
  22520. return controllerEvent (channel, 121, 0);
  22521. }
  22522. const MidiMessage MidiMessage::masterVolume (const float volume) throw()
  22523. {
  22524. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22525. uint8 buf[8];
  22526. buf[0] = 0xf0;
  22527. buf[1] = 0x7f;
  22528. buf[2] = 0x7f;
  22529. buf[3] = 0x04;
  22530. buf[4] = 0x01;
  22531. buf[5] = (uint8) (vol & 0x7f);
  22532. buf[6] = (uint8) (vol >> 7);
  22533. buf[7] = 0xf7;
  22534. return MidiMessage (buf, 8);
  22535. }
  22536. bool MidiMessage::isSysEx() const throw()
  22537. {
  22538. return *data == 0xf0;
  22539. }
  22540. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData,
  22541. const int dataSize) throw()
  22542. {
  22543. MemoryBlock mm (dataSize + 2);
  22544. uint8* const m = (uint8*) mm.getData();
  22545. m[0] = 0xf0;
  22546. memcpy (m + 1, sysexData, dataSize);
  22547. m[dataSize + 1] = 0xf7;
  22548. return MidiMessage (m, dataSize + 2);
  22549. }
  22550. const uint8* MidiMessage::getSysExData() const throw()
  22551. {
  22552. return (isSysEx()) ? getRawData() + 1
  22553. : 0;
  22554. }
  22555. int MidiMessage::getSysExDataSize() const throw()
  22556. {
  22557. return (isSysEx()) ? size - 2
  22558. : 0;
  22559. }
  22560. bool MidiMessage::isMetaEvent() const throw()
  22561. {
  22562. return *data == 0xff;
  22563. }
  22564. bool MidiMessage::isActiveSense() const throw()
  22565. {
  22566. return *data == 0xfe;
  22567. }
  22568. int MidiMessage::getMetaEventType() const throw()
  22569. {
  22570. if (*data != 0xff)
  22571. return -1;
  22572. else
  22573. return data[1];
  22574. }
  22575. int MidiMessage::getMetaEventLength() const throw()
  22576. {
  22577. if (*data == 0xff)
  22578. {
  22579. int n;
  22580. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22581. }
  22582. return 0;
  22583. }
  22584. const uint8* MidiMessage::getMetaEventData() const throw()
  22585. {
  22586. int n;
  22587. const uint8* d = data + 2;
  22588. readVariableLengthVal (d, n);
  22589. return d + n;
  22590. }
  22591. bool MidiMessage::isTrackMetaEvent() const throw()
  22592. {
  22593. return getMetaEventType() == 0;
  22594. }
  22595. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22596. {
  22597. return getMetaEventType() == 47;
  22598. }
  22599. bool MidiMessage::isTextMetaEvent() const throw()
  22600. {
  22601. const int t = getMetaEventType();
  22602. return t > 0 && t < 16;
  22603. }
  22604. const String MidiMessage::getTextFromTextMetaEvent() const throw()
  22605. {
  22606. return String ((const char*) getMetaEventData(),
  22607. getMetaEventLength());
  22608. }
  22609. bool MidiMessage::isTrackNameEvent() const throw()
  22610. {
  22611. return (data[1] == 3)
  22612. && (*data == 0xff);
  22613. }
  22614. bool MidiMessage::isTempoMetaEvent() const throw()
  22615. {
  22616. return (data[1] == 81)
  22617. && (*data == 0xff);
  22618. }
  22619. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22620. {
  22621. return (data[1] == 0x20)
  22622. && (*data == 0xff)
  22623. && (data[2] == 1);
  22624. }
  22625. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22626. {
  22627. return data[3] + 1;
  22628. }
  22629. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22630. {
  22631. if (! isTempoMetaEvent())
  22632. return 0.0;
  22633. const uint8* const d = getMetaEventData();
  22634. return (((unsigned int) d[0] << 16)
  22635. | ((unsigned int) d[1] << 8)
  22636. | d[2])
  22637. / 1000000.0;
  22638. }
  22639. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22640. {
  22641. if (timeFormat > 0)
  22642. {
  22643. if (! isTempoMetaEvent())
  22644. return 0.5 / timeFormat;
  22645. return getTempoSecondsPerQuarterNote() / timeFormat;
  22646. }
  22647. else
  22648. {
  22649. const int frameCode = (-timeFormat) >> 8;
  22650. double framesPerSecond;
  22651. switch (frameCode)
  22652. {
  22653. case 24: framesPerSecond = 24.0; break;
  22654. case 25: framesPerSecond = 25.0; break;
  22655. case 29: framesPerSecond = 29.97; break;
  22656. case 30: framesPerSecond = 30.0; break;
  22657. default: framesPerSecond = 30.0; break;
  22658. }
  22659. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22660. }
  22661. }
  22662. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22663. {
  22664. uint8 d[8];
  22665. d[0] = 0xff;
  22666. d[1] = 81;
  22667. d[2] = 3;
  22668. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22669. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22670. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22671. return MidiMessage (d, 6, 0.0);
  22672. }
  22673. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22674. {
  22675. return (data[1] == 0x58)
  22676. && (*data == (uint8) 0xff);
  22677. }
  22678. void MidiMessage::getTimeSignatureInfo (int& numerator,
  22679. int& denominator) const throw()
  22680. {
  22681. if (isTimeSignatureMetaEvent())
  22682. {
  22683. const uint8* const d = getMetaEventData();
  22684. numerator = d[0];
  22685. denominator = 1 << d[1];
  22686. }
  22687. else
  22688. {
  22689. numerator = 4;
  22690. denominator = 4;
  22691. }
  22692. }
  22693. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator,
  22694. const int denominator) throw()
  22695. {
  22696. uint8 d[8];
  22697. d[0] = 0xff;
  22698. d[1] = 0x58;
  22699. d[2] = 0x04;
  22700. d[3] = (uint8) numerator;
  22701. int n = 1;
  22702. int powerOfTwo = 0;
  22703. while (n < denominator)
  22704. {
  22705. n <<= 1;
  22706. ++powerOfTwo;
  22707. }
  22708. d[4] = (uint8) powerOfTwo;
  22709. d[5] = 0x01;
  22710. d[6] = 96;
  22711. return MidiMessage (d, 7, 0.0);
  22712. }
  22713. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22714. {
  22715. uint8 d[8];
  22716. d[0] = 0xff;
  22717. d[1] = 0x20;
  22718. d[2] = 0x01;
  22719. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22720. return MidiMessage (d, 4, 0.0);
  22721. }
  22722. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22723. {
  22724. return getMetaEventType() == 89;
  22725. }
  22726. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22727. {
  22728. return (int) *getMetaEventData();
  22729. }
  22730. const MidiMessage MidiMessage::endOfTrack() throw()
  22731. {
  22732. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22733. }
  22734. bool MidiMessage::isSongPositionPointer() const throw()
  22735. {
  22736. return *data == 0xf2;
  22737. }
  22738. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22739. {
  22740. return data[1] | (data[2] << 7);
  22741. }
  22742. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22743. {
  22744. return MidiMessage (0xf2,
  22745. positionInMidiBeats & 127,
  22746. (positionInMidiBeats >> 7) & 127);
  22747. }
  22748. bool MidiMessage::isMidiStart() const throw()
  22749. {
  22750. return *data == 0xfa;
  22751. }
  22752. const MidiMessage MidiMessage::midiStart() throw()
  22753. {
  22754. return MidiMessage (0xfa);
  22755. }
  22756. bool MidiMessage::isMidiContinue() const throw()
  22757. {
  22758. return *data == 0xfb;
  22759. }
  22760. const MidiMessage MidiMessage::midiContinue() throw()
  22761. {
  22762. return MidiMessage (0xfb);
  22763. }
  22764. bool MidiMessage::isMidiStop() const throw()
  22765. {
  22766. return *data == 0xfc;
  22767. }
  22768. const MidiMessage MidiMessage::midiStop() throw()
  22769. {
  22770. return MidiMessage (0xfc);
  22771. }
  22772. bool MidiMessage::isMidiClock() const throw()
  22773. {
  22774. return *data == 0xf8;
  22775. }
  22776. const MidiMessage MidiMessage::midiClock() throw()
  22777. {
  22778. return MidiMessage (0xf8);
  22779. }
  22780. bool MidiMessage::isQuarterFrame() const throw()
  22781. {
  22782. return *data == 0xf1;
  22783. }
  22784. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22785. {
  22786. return ((int) data[1]) >> 4;
  22787. }
  22788. int MidiMessage::getQuarterFrameValue() const throw()
  22789. {
  22790. return ((int) data[1]) & 0x0f;
  22791. }
  22792. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22793. const int value) throw()
  22794. {
  22795. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22796. }
  22797. bool MidiMessage::isFullFrame() const throw()
  22798. {
  22799. return data[0] == 0xf0
  22800. && data[1] == 0x7f
  22801. && size >= 10
  22802. && data[3] == 0x01
  22803. && data[4] == 0x01;
  22804. }
  22805. void MidiMessage::getFullFrameParameters (int& hours,
  22806. int& minutes,
  22807. int& seconds,
  22808. int& frames,
  22809. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22810. {
  22811. jassert (isFullFrame());
  22812. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22813. hours = data[5] & 0x1f;
  22814. minutes = data[6];
  22815. seconds = data[7];
  22816. frames = data[8];
  22817. }
  22818. const MidiMessage MidiMessage::fullFrame (const int hours,
  22819. const int minutes,
  22820. const int seconds,
  22821. const int frames,
  22822. MidiMessage::SmpteTimecodeType timecodeType)
  22823. {
  22824. uint8 d[10];
  22825. d[0] = 0xf0;
  22826. d[1] = 0x7f;
  22827. d[2] = 0x7f;
  22828. d[3] = 0x01;
  22829. d[4] = 0x01;
  22830. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22831. d[6] = (uint8) minutes;
  22832. d[7] = (uint8) seconds;
  22833. d[8] = (uint8) frames;
  22834. d[9] = 0xf7;
  22835. return MidiMessage (d, 10, 0.0);
  22836. }
  22837. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22838. {
  22839. return data[0] == 0xf0
  22840. && data[1] == 0x7f
  22841. && data[3] == 0x06
  22842. && size > 5;
  22843. }
  22844. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22845. {
  22846. jassert (isMidiMachineControlMessage());
  22847. return (MidiMachineControlCommand) data[4];
  22848. }
  22849. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22850. {
  22851. uint8 d[6];
  22852. d[0] = 0xf0;
  22853. d[1] = 0x7f;
  22854. d[2] = 0x00;
  22855. d[3] = 0x06;
  22856. d[4] = (uint8) command;
  22857. d[5] = 0xf7;
  22858. return MidiMessage (d, 6, 0.0);
  22859. }
  22860. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22861. int& minutes,
  22862. int& seconds,
  22863. int& frames) const throw()
  22864. {
  22865. if (size >= 12
  22866. && data[0] == 0xf0
  22867. && data[1] == 0x7f
  22868. && data[3] == 0x06
  22869. && data[4] == 0x44
  22870. && data[5] == 0x06
  22871. && data[6] == 0x01)
  22872. {
  22873. hours = data[7] % 24; // (that some machines send out hours > 24)
  22874. minutes = data[8];
  22875. seconds = data[9];
  22876. frames = data[10];
  22877. return true;
  22878. }
  22879. return false;
  22880. }
  22881. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22882. int minutes,
  22883. int seconds,
  22884. int frames)
  22885. {
  22886. uint8 d[12];
  22887. d[0] = 0xf0;
  22888. d[1] = 0x7f;
  22889. d[2] = 0x00;
  22890. d[3] = 0x06;
  22891. d[4] = 0x44;
  22892. d[5] = 0x06;
  22893. d[6] = 0x01;
  22894. d[7] = (uint8) hours;
  22895. d[8] = (uint8) minutes;
  22896. d[9] = (uint8) seconds;
  22897. d[10] = (uint8) frames;
  22898. d[11] = 0xf7;
  22899. return MidiMessage (d, 12, 0.0);
  22900. }
  22901. const String MidiMessage::getMidiNoteName (int note,
  22902. bool useSharps,
  22903. bool includeOctaveNumber,
  22904. int octaveNumForMiddleC) throw()
  22905. {
  22906. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22907. "F", "F#", "G", "G#", "A",
  22908. "A#", "B" };
  22909. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22910. "F", "Gb", "G", "Ab", "A",
  22911. "Bb", "B" };
  22912. if (((unsigned int) note) < 128)
  22913. {
  22914. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22915. : flatNoteNames [note % 12]);
  22916. if (includeOctaveNumber)
  22917. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22918. else
  22919. return s;
  22920. }
  22921. return String::empty;
  22922. }
  22923. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22924. {
  22925. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22926. return 440.0 * pow (2.0, noteNumber / 12.0);
  22927. }
  22928. const String MidiMessage::getGMInstrumentName (int n) throw()
  22929. {
  22930. const char *names[] =
  22931. {
  22932. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22933. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22934. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22935. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22936. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22937. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22938. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22939. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22940. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22941. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22942. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22943. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22944. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22945. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22946. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22947. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22948. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22949. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22950. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22951. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22952. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22953. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22954. "Applause", "Gunshot"
  22955. };
  22956. return (((unsigned int) n) < 128) ? names[n]
  22957. : (const char*)0;
  22958. }
  22959. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  22960. {
  22961. const char* names[] =
  22962. {
  22963. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  22964. "Bass", "Strings", "Ensemble", "Brass",
  22965. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  22966. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  22967. };
  22968. return (((unsigned int) n) <= 15) ? names[n]
  22969. : (const char*)0;
  22970. }
  22971. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  22972. {
  22973. const char* names[] =
  22974. {
  22975. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  22976. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  22977. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  22978. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  22979. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  22980. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  22981. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  22982. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  22983. "Mute Triangle", "Open Triangle"
  22984. };
  22985. return (n >= 35 && n <= 81) ? names [n - 35]
  22986. : (const char*)0;
  22987. }
  22988. const String MidiMessage::getControllerName (int n) throw()
  22989. {
  22990. const char* names[] =
  22991. {
  22992. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  22993. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  22994. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  22995. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  22996. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  22997. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  22998. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  22999. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  23000. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  23001. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  23002. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  23003. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  23004. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  23005. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  23006. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  23007. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  23008. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  23009. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  23010. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  23011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  23012. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  23013. "Poly Operation"
  23014. };
  23015. return (((unsigned int) n) < 128) ? names[n]
  23016. : (const char*)0;
  23017. }
  23018. END_JUCE_NAMESPACE
  23019. /*** End of inlined file: juce_MidiMessage.cpp ***/
  23020. /*** Start of inlined file: juce_MidiMessageCollector.cpp ***/
  23021. BEGIN_JUCE_NAMESPACE
  23022. MidiMessageCollector::MidiMessageCollector()
  23023. : lastCallbackTime (0),
  23024. sampleRate (44100.0001)
  23025. {
  23026. }
  23027. MidiMessageCollector::~MidiMessageCollector()
  23028. {
  23029. }
  23030. void MidiMessageCollector::reset (const double sampleRate_)
  23031. {
  23032. jassert (sampleRate_ > 0);
  23033. const ScopedLock sl (midiCallbackLock);
  23034. sampleRate = sampleRate_;
  23035. incomingMessages.clear();
  23036. lastCallbackTime = Time::getMillisecondCounterHiRes();
  23037. }
  23038. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  23039. {
  23040. // you need to call reset() to set the correct sample rate before using this object
  23041. jassert (sampleRate != 44100.0001);
  23042. // the messages that come in here need to be time-stamped correctly - see MidiInput
  23043. // for details of what the number should be.
  23044. jassert (message.getTimeStamp() != 0);
  23045. const ScopedLock sl (midiCallbackLock);
  23046. const int sampleNumber
  23047. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  23048. incomingMessages.addEvent (message, sampleNumber);
  23049. // if the messages don't get used for over a second, we'd better
  23050. // get rid of any old ones to avoid the queue getting too big
  23051. if (sampleNumber > sampleRate)
  23052. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  23053. }
  23054. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  23055. const int numSamples)
  23056. {
  23057. // you need to call reset() to set the correct sample rate before using this object
  23058. jassert (sampleRate != 44100.0001);
  23059. const double timeNow = Time::getMillisecondCounterHiRes();
  23060. const double msElapsed = timeNow - lastCallbackTime;
  23061. const ScopedLock sl (midiCallbackLock);
  23062. lastCallbackTime = timeNow;
  23063. if (! incomingMessages.isEmpty())
  23064. {
  23065. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  23066. int startSample = 0;
  23067. int scale = 1 << 16;
  23068. const uint8* midiData;
  23069. int numBytes, samplePosition;
  23070. MidiBuffer::Iterator iter (incomingMessages);
  23071. if (numSourceSamples > numSamples)
  23072. {
  23073. // if our list of events is longer than the buffer we're being
  23074. // asked for, scale them down to squeeze them all in..
  23075. const int maxBlockLengthToUse = numSamples << 5;
  23076. if (numSourceSamples > maxBlockLengthToUse)
  23077. {
  23078. startSample = numSourceSamples - maxBlockLengthToUse;
  23079. numSourceSamples = maxBlockLengthToUse;
  23080. iter.setNextSamplePosition (startSample);
  23081. }
  23082. scale = (numSamples << 10) / numSourceSamples;
  23083. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23084. {
  23085. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  23086. destBuffer.addEvent (midiData, numBytes,
  23087. jlimit (0, numSamples - 1, samplePosition));
  23088. }
  23089. }
  23090. else
  23091. {
  23092. // if our event list is shorter than the number we need, put them
  23093. // towards the end of the buffer
  23094. startSample = numSamples - numSourceSamples;
  23095. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23096. {
  23097. destBuffer.addEvent (midiData, numBytes,
  23098. jlimit (0, numSamples - 1, samplePosition + startSample));
  23099. }
  23100. }
  23101. incomingMessages.clear();
  23102. }
  23103. }
  23104. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  23105. {
  23106. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  23107. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23108. addMessageToQueue (m);
  23109. }
  23110. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  23111. {
  23112. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  23113. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23114. addMessageToQueue (m);
  23115. }
  23116. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  23117. {
  23118. addMessageToQueue (message);
  23119. }
  23120. END_JUCE_NAMESPACE
  23121. /*** End of inlined file: juce_MidiMessageCollector.cpp ***/
  23122. /*** Start of inlined file: juce_MidiMessageSequence.cpp ***/
  23123. BEGIN_JUCE_NAMESPACE
  23124. MidiMessageSequence::MidiMessageSequence()
  23125. {
  23126. }
  23127. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  23128. {
  23129. list.ensureStorageAllocated (other.list.size());
  23130. for (int i = 0; i < other.list.size(); ++i)
  23131. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  23132. }
  23133. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  23134. {
  23135. MidiMessageSequence otherCopy (other);
  23136. swapWith (otherCopy);
  23137. return *this;
  23138. }
  23139. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  23140. {
  23141. list.swapWithArray (other.list);
  23142. }
  23143. MidiMessageSequence::~MidiMessageSequence()
  23144. {
  23145. }
  23146. void MidiMessageSequence::clear()
  23147. {
  23148. list.clear();
  23149. }
  23150. int MidiMessageSequence::getNumEvents() const
  23151. {
  23152. return list.size();
  23153. }
  23154. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  23155. {
  23156. return list [index];
  23157. }
  23158. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  23159. {
  23160. const MidiEventHolder* const meh = list [index];
  23161. if (meh != 0 && meh->noteOffObject != 0)
  23162. return meh->noteOffObject->message.getTimeStamp();
  23163. else
  23164. return 0.0;
  23165. }
  23166. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  23167. {
  23168. const MidiEventHolder* const meh = list [index];
  23169. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  23170. }
  23171. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  23172. {
  23173. return list.indexOf (event);
  23174. }
  23175. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  23176. {
  23177. const int numEvents = list.size();
  23178. int i;
  23179. for (i = 0; i < numEvents; ++i)
  23180. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  23181. break;
  23182. return i;
  23183. }
  23184. double MidiMessageSequence::getStartTime() const
  23185. {
  23186. if (list.size() > 0)
  23187. return list.getUnchecked(0)->message.getTimeStamp();
  23188. else
  23189. return 0;
  23190. }
  23191. double MidiMessageSequence::getEndTime() const
  23192. {
  23193. if (list.size() > 0)
  23194. return list.getLast()->message.getTimeStamp();
  23195. else
  23196. return 0;
  23197. }
  23198. double MidiMessageSequence::getEventTime (const int index) const
  23199. {
  23200. if (((unsigned int) index) < (unsigned int) list.size())
  23201. return list.getUnchecked (index)->message.getTimeStamp();
  23202. return 0.0;
  23203. }
  23204. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  23205. double timeAdjustment)
  23206. {
  23207. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  23208. timeAdjustment += newMessage.getTimeStamp();
  23209. newOne->message.setTimeStamp (timeAdjustment);
  23210. int i;
  23211. for (i = list.size(); --i >= 0;)
  23212. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  23213. break;
  23214. list.insert (i + 1, newOne);
  23215. }
  23216. void MidiMessageSequence::deleteEvent (const int index,
  23217. const bool deleteMatchingNoteUp)
  23218. {
  23219. if (((unsigned int) index) < (unsigned int) list.size())
  23220. {
  23221. if (deleteMatchingNoteUp)
  23222. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  23223. list.remove (index);
  23224. }
  23225. }
  23226. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  23227. double timeAdjustment,
  23228. double firstAllowableTime,
  23229. double endOfAllowableDestTimes)
  23230. {
  23231. firstAllowableTime -= timeAdjustment;
  23232. endOfAllowableDestTimes -= timeAdjustment;
  23233. for (int i = 0; i < other.list.size(); ++i)
  23234. {
  23235. const MidiMessage& m = other.list.getUnchecked(i)->message;
  23236. const double t = m.getTimeStamp();
  23237. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  23238. {
  23239. MidiEventHolder* const newOne = new MidiEventHolder (m);
  23240. newOne->message.setTimeStamp (timeAdjustment + t);
  23241. list.add (newOne);
  23242. }
  23243. }
  23244. sort();
  23245. }
  23246. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  23247. const MidiMessageSequence::MidiEventHolder* const second) throw()
  23248. {
  23249. const double diff = first->message.getTimeStamp()
  23250. - second->message.getTimeStamp();
  23251. return (diff > 0) - (diff < 0);
  23252. }
  23253. void MidiMessageSequence::sort()
  23254. {
  23255. list.sort (*this, true);
  23256. }
  23257. void MidiMessageSequence::updateMatchedPairs()
  23258. {
  23259. for (int i = 0; i < list.size(); ++i)
  23260. {
  23261. const MidiMessage& m1 = list.getUnchecked(i)->message;
  23262. if (m1.isNoteOn())
  23263. {
  23264. list.getUnchecked(i)->noteOffObject = 0;
  23265. const int note = m1.getNoteNumber();
  23266. const int chan = m1.getChannel();
  23267. const int len = list.size();
  23268. for (int j = i + 1; j < len; ++j)
  23269. {
  23270. const MidiMessage& m = list.getUnchecked(j)->message;
  23271. if (m.getNoteNumber() == note && m.getChannel() == chan)
  23272. {
  23273. if (m.isNoteOff())
  23274. {
  23275. list.getUnchecked(i)->noteOffObject = list[j];
  23276. break;
  23277. }
  23278. else if (m.isNoteOn())
  23279. {
  23280. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  23281. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  23282. list.getUnchecked(i)->noteOffObject = list[j];
  23283. break;
  23284. }
  23285. }
  23286. }
  23287. }
  23288. }
  23289. }
  23290. void MidiMessageSequence::addTimeToMessages (const double delta)
  23291. {
  23292. for (int i = list.size(); --i >= 0;)
  23293. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  23294. + delta);
  23295. }
  23296. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  23297. MidiMessageSequence& destSequence,
  23298. const bool alsoIncludeMetaEvents) const
  23299. {
  23300. for (int i = 0; i < list.size(); ++i)
  23301. {
  23302. const MidiMessage& mm = list.getUnchecked(i)->message;
  23303. if (mm.isForChannel (channelNumberToExtract)
  23304. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23305. {
  23306. destSequence.addEvent (mm);
  23307. }
  23308. }
  23309. }
  23310. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23311. {
  23312. for (int i = 0; i < list.size(); ++i)
  23313. {
  23314. const MidiMessage& mm = list.getUnchecked(i)->message;
  23315. if (mm.isSysEx())
  23316. destSequence.addEvent (mm);
  23317. }
  23318. }
  23319. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23320. {
  23321. for (int i = list.size(); --i >= 0;)
  23322. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23323. list.remove(i);
  23324. }
  23325. void MidiMessageSequence::deleteSysExMessages()
  23326. {
  23327. for (int i = list.size(); --i >= 0;)
  23328. if (list.getUnchecked(i)->message.isSysEx())
  23329. list.remove(i);
  23330. }
  23331. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23332. const double time,
  23333. OwnedArray<MidiMessage>& dest)
  23334. {
  23335. bool doneProg = false;
  23336. bool donePitchWheel = false;
  23337. Array <int> doneControllers;
  23338. doneControllers.ensureStorageAllocated (32);
  23339. for (int i = list.size(); --i >= 0;)
  23340. {
  23341. const MidiMessage& mm = list.getUnchecked(i)->message;
  23342. if (mm.isForChannel (channelNumber)
  23343. && mm.getTimeStamp() <= time)
  23344. {
  23345. if (mm.isProgramChange())
  23346. {
  23347. if (! doneProg)
  23348. {
  23349. dest.add (new MidiMessage (mm, 0.0));
  23350. doneProg = true;
  23351. }
  23352. }
  23353. else if (mm.isController())
  23354. {
  23355. if (! doneControllers.contains (mm.getControllerNumber()))
  23356. {
  23357. dest.add (new MidiMessage (mm, 0.0));
  23358. doneControllers.add (mm.getControllerNumber());
  23359. }
  23360. }
  23361. else if (mm.isPitchWheel())
  23362. {
  23363. if (! donePitchWheel)
  23364. {
  23365. dest.add (new MidiMessage (mm, 0.0));
  23366. donePitchWheel = true;
  23367. }
  23368. }
  23369. }
  23370. }
  23371. }
  23372. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23373. : message (message_),
  23374. noteOffObject (0)
  23375. {
  23376. }
  23377. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23378. {
  23379. }
  23380. END_JUCE_NAMESPACE
  23381. /*** End of inlined file: juce_MidiMessageSequence.cpp ***/
  23382. /*** Start of inlined file: juce_AudioPluginFormat.cpp ***/
  23383. BEGIN_JUCE_NAMESPACE
  23384. AudioPluginFormat::AudioPluginFormat() throw()
  23385. {
  23386. }
  23387. AudioPluginFormat::~AudioPluginFormat()
  23388. {
  23389. }
  23390. END_JUCE_NAMESPACE
  23391. /*** End of inlined file: juce_AudioPluginFormat.cpp ***/
  23392. /*** Start of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23393. BEGIN_JUCE_NAMESPACE
  23394. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23395. {
  23396. }
  23397. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23398. {
  23399. clearSingletonInstance();
  23400. }
  23401. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23402. void AudioPluginFormatManager::addDefaultFormats()
  23403. {
  23404. #ifdef JUCE_DEBUG
  23405. // you should only call this method once!
  23406. for (int i = formats.size(); --i >= 0;)
  23407. {
  23408. #if JUCE_PLUGINHOST_VST
  23409. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23410. #endif
  23411. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23412. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23413. #endif
  23414. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23415. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23416. #endif
  23417. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23418. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23419. #endif
  23420. }
  23421. #endif
  23422. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23423. formats.add (new AudioUnitPluginFormat());
  23424. #endif
  23425. #if JUCE_PLUGINHOST_VST
  23426. formats.add (new VSTPluginFormat());
  23427. #endif
  23428. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23429. formats.add (new DirectXPluginFormat());
  23430. #endif
  23431. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23432. formats.add (new LADSPAPluginFormat());
  23433. #endif
  23434. }
  23435. int AudioPluginFormatManager::getNumFormats() throw()
  23436. {
  23437. return formats.size();
  23438. }
  23439. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23440. {
  23441. return formats [index];
  23442. }
  23443. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23444. {
  23445. formats.add (format);
  23446. }
  23447. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23448. String& errorMessage) const
  23449. {
  23450. AudioPluginInstance* result = 0;
  23451. for (int i = 0; i < formats.size(); ++i)
  23452. {
  23453. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23454. if (result != 0)
  23455. break;
  23456. }
  23457. if (result == 0)
  23458. {
  23459. if (! doesPluginStillExist (description))
  23460. errorMessage = TRANS ("This plug-in file no longer exists");
  23461. else
  23462. errorMessage = TRANS ("This plug-in failed to load correctly");
  23463. }
  23464. return result;
  23465. }
  23466. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23467. {
  23468. for (int i = 0; i < formats.size(); ++i)
  23469. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23470. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23471. return false;
  23472. }
  23473. END_JUCE_NAMESPACE
  23474. /*** End of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23475. /*** Start of inlined file: juce_AudioPluginInstance.cpp ***/
  23476. #define JUCE_PLUGIN_HOST 1
  23477. BEGIN_JUCE_NAMESPACE
  23478. AudioPluginInstance::AudioPluginInstance()
  23479. {
  23480. }
  23481. AudioPluginInstance::~AudioPluginInstance()
  23482. {
  23483. }
  23484. END_JUCE_NAMESPACE
  23485. /*** End of inlined file: juce_AudioPluginInstance.cpp ***/
  23486. /*** Start of inlined file: juce_KnownPluginList.cpp ***/
  23487. BEGIN_JUCE_NAMESPACE
  23488. KnownPluginList::KnownPluginList()
  23489. {
  23490. }
  23491. KnownPluginList::~KnownPluginList()
  23492. {
  23493. }
  23494. void KnownPluginList::clear()
  23495. {
  23496. if (types.size() > 0)
  23497. {
  23498. types.clear();
  23499. sendChangeMessage (this);
  23500. }
  23501. }
  23502. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23503. {
  23504. for (int i = 0; i < types.size(); ++i)
  23505. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23506. return types.getUnchecked(i);
  23507. return 0;
  23508. }
  23509. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23510. {
  23511. for (int i = 0; i < types.size(); ++i)
  23512. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23513. return types.getUnchecked(i);
  23514. return 0;
  23515. }
  23516. bool KnownPluginList::addType (const PluginDescription& type)
  23517. {
  23518. for (int i = types.size(); --i >= 0;)
  23519. {
  23520. if (types.getUnchecked(i)->isDuplicateOf (type))
  23521. {
  23522. // strange - found a duplicate plugin with different info..
  23523. jassert (types.getUnchecked(i)->name == type.name);
  23524. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23525. *types.getUnchecked(i) = type;
  23526. return false;
  23527. }
  23528. }
  23529. types.add (new PluginDescription (type));
  23530. sendChangeMessage (this);
  23531. return true;
  23532. }
  23533. void KnownPluginList::removeType (const int index) throw()
  23534. {
  23535. types.remove (index);
  23536. sendChangeMessage (this);
  23537. }
  23538. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23539. {
  23540. if (fileOrIdentifier.startsWithChar (T('/'))
  23541. || fileOrIdentifier[1] == T(':'))
  23542. {
  23543. return File (fileOrIdentifier).getLastModificationTime();
  23544. }
  23545. return Time (0);
  23546. }
  23547. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23548. {
  23549. return t1 != t2 || t1 == Time (0);
  23550. }
  23551. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23552. {
  23553. if (getTypeForFile (fileOrIdentifier) == 0)
  23554. return false;
  23555. for (int i = types.size(); --i >= 0;)
  23556. {
  23557. const PluginDescription* const d = types.getUnchecked(i);
  23558. if (d->fileOrIdentifier == fileOrIdentifier
  23559. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23560. {
  23561. return false;
  23562. }
  23563. }
  23564. return true;
  23565. }
  23566. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23567. const bool dontRescanIfAlreadyInList,
  23568. OwnedArray <PluginDescription>& typesFound,
  23569. AudioPluginFormat& format)
  23570. {
  23571. bool addedOne = false;
  23572. if (dontRescanIfAlreadyInList
  23573. && getTypeForFile (fileOrIdentifier) != 0)
  23574. {
  23575. bool needsRescanning = false;
  23576. for (int i = types.size(); --i >= 0;)
  23577. {
  23578. const PluginDescription* const d = types.getUnchecked(i);
  23579. if (d->fileOrIdentifier == fileOrIdentifier)
  23580. {
  23581. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23582. needsRescanning = true;
  23583. else
  23584. typesFound.add (new PluginDescription (*d));
  23585. }
  23586. }
  23587. if (! needsRescanning)
  23588. return false;
  23589. }
  23590. OwnedArray <PluginDescription> found;
  23591. format.findAllTypesForFile (found, fileOrIdentifier);
  23592. for (int i = 0; i < found.size(); ++i)
  23593. {
  23594. PluginDescription* const desc = found.getUnchecked(i);
  23595. jassert (desc != 0);
  23596. if (addType (*desc))
  23597. addedOne = true;
  23598. typesFound.add (new PluginDescription (*desc));
  23599. }
  23600. return addedOne;
  23601. }
  23602. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23603. OwnedArray <PluginDescription>& typesFound)
  23604. {
  23605. for (int i = 0; i < files.size(); ++i)
  23606. {
  23607. bool loaded = false;
  23608. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23609. {
  23610. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23611. if (scanAndAddFile (files[i], true, typesFound, *format))
  23612. loaded = true;
  23613. }
  23614. if (! loaded)
  23615. {
  23616. const File f (files[i]);
  23617. if (f.isDirectory())
  23618. {
  23619. StringArray s;
  23620. {
  23621. Array<File> subFiles;
  23622. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23623. for (int j = 0; j < subFiles.size(); ++j)
  23624. s.add (subFiles.getReference(j).getFullPathName());
  23625. }
  23626. scanAndAddDragAndDroppedFiles (s, typesFound);
  23627. }
  23628. }
  23629. }
  23630. }
  23631. class PluginSorter
  23632. {
  23633. public:
  23634. KnownPluginList::SortMethod method;
  23635. PluginSorter() throw() {}
  23636. int compareElements (const PluginDescription* const first,
  23637. const PluginDescription* const second) const throw()
  23638. {
  23639. int diff = 0;
  23640. if (method == KnownPluginList::sortByCategory)
  23641. diff = first->category.compareLexicographically (second->category);
  23642. else if (method == KnownPluginList::sortByManufacturer)
  23643. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23644. else if (method == KnownPluginList::sortByFileSystemLocation)
  23645. diff = first->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23646. .upToLastOccurrenceOf (T("/"), false, false)
  23647. .compare (second->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23648. .upToLastOccurrenceOf (T("/"), false, false));
  23649. if (diff == 0)
  23650. diff = first->name.compareLexicographically (second->name);
  23651. return diff;
  23652. }
  23653. };
  23654. void KnownPluginList::sort (const SortMethod method)
  23655. {
  23656. if (method != defaultOrder)
  23657. {
  23658. PluginSorter sorter;
  23659. sorter.method = method;
  23660. types.sort (sorter, true);
  23661. sendChangeMessage (this);
  23662. }
  23663. }
  23664. XmlElement* KnownPluginList::createXml() const
  23665. {
  23666. XmlElement* const e = new XmlElement (T("KNOWNPLUGINS"));
  23667. for (int i = 0; i < types.size(); ++i)
  23668. e->addChildElement (types.getUnchecked(i)->createXml());
  23669. return e;
  23670. }
  23671. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23672. {
  23673. clear();
  23674. if (xml.hasTagName (T("KNOWNPLUGINS")))
  23675. {
  23676. forEachXmlChildElement (xml, e)
  23677. {
  23678. PluginDescription info;
  23679. if (info.loadFromXml (*e))
  23680. addType (info);
  23681. }
  23682. }
  23683. }
  23684. const int menuIdBase = 0x324503f4;
  23685. // This is used to turn a bunch of paths into a nested menu structure.
  23686. struct PluginFilesystemTree
  23687. {
  23688. private:
  23689. String folder;
  23690. OwnedArray <PluginFilesystemTree> subFolders;
  23691. Array <PluginDescription*> plugins;
  23692. void addPlugin (PluginDescription* const pd, const String& path)
  23693. {
  23694. if (path.isEmpty())
  23695. {
  23696. plugins.add (pd);
  23697. }
  23698. else
  23699. {
  23700. const String firstSubFolder (path.upToFirstOccurrenceOf (T("/"), false, false));
  23701. const String remainingPath (path.fromFirstOccurrenceOf (T("/"), false, false));
  23702. for (int i = subFolders.size(); --i >= 0;)
  23703. {
  23704. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23705. {
  23706. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23707. return;
  23708. }
  23709. }
  23710. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23711. newFolder->folder = firstSubFolder;
  23712. subFolders.add (newFolder);
  23713. newFolder->addPlugin (pd, remainingPath);
  23714. }
  23715. }
  23716. // removes any deeply nested folders that don't contain any actual plugins
  23717. void optimise()
  23718. {
  23719. for (int i = subFolders.size(); --i >= 0;)
  23720. {
  23721. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23722. sub->optimise();
  23723. if (sub->plugins.size() == 0)
  23724. {
  23725. for (int j = 0; j < sub->subFolders.size(); ++j)
  23726. subFolders.add (sub->subFolders.getUnchecked(j));
  23727. sub->subFolders.clear (false);
  23728. subFolders.remove (i);
  23729. }
  23730. }
  23731. }
  23732. public:
  23733. void buildTree (const Array <PluginDescription*>& allPlugins)
  23734. {
  23735. for (int i = 0; i < allPlugins.size(); ++i)
  23736. {
  23737. String path (allPlugins.getUnchecked(i)
  23738. ->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23739. .upToLastOccurrenceOf (T("/"), false, false));
  23740. if (path.substring (1, 2) == T(":"))
  23741. path = path.substring (2);
  23742. addPlugin (allPlugins.getUnchecked(i), path);
  23743. }
  23744. optimise();
  23745. }
  23746. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23747. {
  23748. int i;
  23749. for (i = 0; i < subFolders.size(); ++i)
  23750. {
  23751. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23752. PopupMenu subMenu;
  23753. sub->addToMenu (subMenu, allPlugins);
  23754. #if JUCE_MAC
  23755. // avoid the special AU formatting nonsense on Mac..
  23756. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (T(":"), false, false), subMenu);
  23757. #else
  23758. m.addSubMenu (sub->folder, subMenu);
  23759. #endif
  23760. }
  23761. for (i = 0; i < plugins.size(); ++i)
  23762. {
  23763. PluginDescription* const plugin = plugins.getUnchecked(i);
  23764. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23765. plugin->name, true, false);
  23766. }
  23767. }
  23768. };
  23769. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23770. {
  23771. Array <PluginDescription*> sorted;
  23772. {
  23773. PluginSorter sorter;
  23774. sorter.method = sortMethod;
  23775. for (int i = 0; i < types.size(); ++i)
  23776. sorted.addSorted (sorter, types.getUnchecked(i));
  23777. }
  23778. if (sortMethod == sortByCategory
  23779. || sortMethod == sortByManufacturer)
  23780. {
  23781. String lastSubMenuName;
  23782. PopupMenu sub;
  23783. for (int i = 0; i < sorted.size(); ++i)
  23784. {
  23785. const PluginDescription* const pd = sorted.getUnchecked(i);
  23786. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23787. : pd->manufacturerName);
  23788. if (! thisSubMenuName.containsNonWhitespaceChars())
  23789. thisSubMenuName = T("Other");
  23790. if (thisSubMenuName != lastSubMenuName)
  23791. {
  23792. if (sub.getNumItems() > 0)
  23793. {
  23794. menu.addSubMenu (lastSubMenuName, sub);
  23795. sub.clear();
  23796. }
  23797. lastSubMenuName = thisSubMenuName;
  23798. }
  23799. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23800. }
  23801. if (sub.getNumItems() > 0)
  23802. menu.addSubMenu (lastSubMenuName, sub);
  23803. }
  23804. else if (sortMethod == sortByFileSystemLocation)
  23805. {
  23806. PluginFilesystemTree root;
  23807. root.buildTree (sorted);
  23808. root.addToMenu (menu, types);
  23809. }
  23810. else
  23811. {
  23812. for (int i = 0; i < sorted.size(); ++i)
  23813. {
  23814. const PluginDescription* const pd = sorted.getUnchecked(i);
  23815. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23816. }
  23817. }
  23818. }
  23819. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23820. {
  23821. const int i = menuResultCode - menuIdBase;
  23822. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23823. }
  23824. END_JUCE_NAMESPACE
  23825. /*** End of inlined file: juce_KnownPluginList.cpp ***/
  23826. /*** Start of inlined file: juce_PluginDescription.cpp ***/
  23827. BEGIN_JUCE_NAMESPACE
  23828. PluginDescription::PluginDescription() throw()
  23829. : uid (0),
  23830. isInstrument (false),
  23831. numInputChannels (0),
  23832. numOutputChannels (0)
  23833. {
  23834. }
  23835. PluginDescription::~PluginDescription() throw()
  23836. {
  23837. }
  23838. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23839. : name (other.name),
  23840. pluginFormatName (other.pluginFormatName),
  23841. category (other.category),
  23842. manufacturerName (other.manufacturerName),
  23843. version (other.version),
  23844. fileOrIdentifier (other.fileOrIdentifier),
  23845. lastFileModTime (other.lastFileModTime),
  23846. uid (other.uid),
  23847. isInstrument (other.isInstrument),
  23848. numInputChannels (other.numInputChannels),
  23849. numOutputChannels (other.numOutputChannels)
  23850. {
  23851. }
  23852. PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23853. {
  23854. name = other.name;
  23855. pluginFormatName = other.pluginFormatName;
  23856. category = other.category;
  23857. manufacturerName = other.manufacturerName;
  23858. version = other.version;
  23859. fileOrIdentifier = other.fileOrIdentifier;
  23860. uid = other.uid;
  23861. isInstrument = other.isInstrument;
  23862. lastFileModTime = other.lastFileModTime;
  23863. numInputChannels = other.numInputChannels;
  23864. numOutputChannels = other.numOutputChannels;
  23865. return *this;
  23866. }
  23867. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23868. {
  23869. return fileOrIdentifier == other.fileOrIdentifier
  23870. && uid == other.uid;
  23871. }
  23872. const String PluginDescription::createIdentifierString() const throw()
  23873. {
  23874. return pluginFormatName
  23875. + T("-") + name
  23876. + T("-") + String::toHexString (fileOrIdentifier.hashCode())
  23877. + T("-") + String::toHexString (uid);
  23878. }
  23879. XmlElement* PluginDescription::createXml() const
  23880. {
  23881. XmlElement* const e = new XmlElement (T("PLUGIN"));
  23882. e->setAttribute (T("name"), name);
  23883. e->setAttribute (T("format"), pluginFormatName);
  23884. e->setAttribute (T("category"), category);
  23885. e->setAttribute (T("manufacturer"), manufacturerName);
  23886. e->setAttribute (T("version"), version);
  23887. e->setAttribute (T("file"), fileOrIdentifier);
  23888. e->setAttribute (T("uid"), String::toHexString (uid));
  23889. e->setAttribute (T("isInstrument"), isInstrument);
  23890. e->setAttribute (T("fileTime"), String::toHexString (lastFileModTime.toMilliseconds()));
  23891. e->setAttribute (T("numInputs"), numInputChannels);
  23892. e->setAttribute (T("numOutputs"), numOutputChannels);
  23893. return e;
  23894. }
  23895. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23896. {
  23897. if (xml.hasTagName (T("PLUGIN")))
  23898. {
  23899. name = xml.getStringAttribute (T("name"));
  23900. pluginFormatName = xml.getStringAttribute (T("format"));
  23901. category = xml.getStringAttribute (T("category"));
  23902. manufacturerName = xml.getStringAttribute (T("manufacturer"));
  23903. version = xml.getStringAttribute (T("version"));
  23904. fileOrIdentifier = xml.getStringAttribute (T("file"));
  23905. uid = xml.getStringAttribute (T("uid")).getHexValue32();
  23906. isInstrument = xml.getBoolAttribute (T("isInstrument"), false);
  23907. lastFileModTime = Time (xml.getStringAttribute (T("fileTime")).getHexValue64());
  23908. numInputChannels = xml.getIntAttribute (T("numInputs"));
  23909. numOutputChannels = xml.getIntAttribute (T("numOutputs"));
  23910. return true;
  23911. }
  23912. return false;
  23913. }
  23914. END_JUCE_NAMESPACE
  23915. /*** End of inlined file: juce_PluginDescription.cpp ***/
  23916. /*** Start of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23917. BEGIN_JUCE_NAMESPACE
  23918. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23919. AudioPluginFormat& formatToLookFor,
  23920. FileSearchPath directoriesToSearch,
  23921. const bool recursive,
  23922. const File& deadMansPedalFile_)
  23923. : list (listToAddTo),
  23924. format (formatToLookFor),
  23925. deadMansPedalFile (deadMansPedalFile_),
  23926. nextIndex (0),
  23927. progress (0)
  23928. {
  23929. directoriesToSearch.removeRedundantPaths();
  23930. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23931. // If any plugins have crashed recently when being loaded, move them to the
  23932. // end of the list to give the others a chance to load correctly..
  23933. const StringArray crashedPlugins (getDeadMansPedalFile());
  23934. for (int i = 0; i < crashedPlugins.size(); ++i)
  23935. {
  23936. const String f = crashedPlugins[i];
  23937. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23938. if (f == filesOrIdentifiersToScan[j])
  23939. filesOrIdentifiersToScan.move (j, -1);
  23940. }
  23941. }
  23942. PluginDirectoryScanner::~PluginDirectoryScanner()
  23943. {
  23944. }
  23945. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23946. {
  23947. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23948. }
  23949. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23950. {
  23951. String file (filesOrIdentifiersToScan [nextIndex]);
  23952. if (file.isNotEmpty())
  23953. {
  23954. if (! list.isListingUpToDate (file))
  23955. {
  23956. OwnedArray <PluginDescription> typesFound;
  23957. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  23958. StringArray crashedPlugins (getDeadMansPedalFile());
  23959. crashedPlugins.removeString (file);
  23960. crashedPlugins.add (file);
  23961. setDeadMansPedalFile (crashedPlugins);
  23962. list.scanAndAddFile (file,
  23963. dontRescanIfAlreadyInList,
  23964. typesFound,
  23965. format);
  23966. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  23967. crashedPlugins.removeString (file);
  23968. setDeadMansPedalFile (crashedPlugins);
  23969. if (typesFound.size() == 0)
  23970. failedFiles.add (file);
  23971. }
  23972. ++nextIndex;
  23973. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  23974. }
  23975. return nextIndex < filesOrIdentifiersToScan.size();
  23976. }
  23977. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  23978. {
  23979. StringArray lines;
  23980. if (deadMansPedalFile != File::nonexistent)
  23981. {
  23982. lines.addLines (deadMansPedalFile.loadFileAsString());
  23983. lines.removeEmptyStrings();
  23984. }
  23985. return lines;
  23986. }
  23987. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  23988. {
  23989. if (deadMansPedalFile != File::nonexistent)
  23990. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  23991. }
  23992. END_JUCE_NAMESPACE
  23993. /*** End of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23994. /*** Start of inlined file: juce_PluginListComponent.cpp ***/
  23995. BEGIN_JUCE_NAMESPACE
  23996. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  23997. const File& deadMansPedalFile_,
  23998. PropertiesFile* const propertiesToUse_)
  23999. : list (listToEdit),
  24000. deadMansPedalFile (deadMansPedalFile_),
  24001. propertiesToUse (propertiesToUse_)
  24002. {
  24003. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  24004. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  24005. optionsButton->addButtonListener (this);
  24006. optionsButton->setTriggeredOnMouseDown (true);
  24007. setSize (400, 600);
  24008. list.addChangeListener (this);
  24009. }
  24010. PluginListComponent::~PluginListComponent()
  24011. {
  24012. list.removeChangeListener (this);
  24013. deleteAllChildren();
  24014. }
  24015. void PluginListComponent::resized()
  24016. {
  24017. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  24018. optionsButton->changeWidthToFitText (24);
  24019. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  24020. }
  24021. void PluginListComponent::changeListenerCallback (void*)
  24022. {
  24023. listBox->updateContent();
  24024. listBox->repaint();
  24025. }
  24026. int PluginListComponent::getNumRows()
  24027. {
  24028. return list.getNumTypes();
  24029. }
  24030. void PluginListComponent::paintListBoxItem (int row,
  24031. Graphics& g,
  24032. int width, int height,
  24033. bool rowIsSelected)
  24034. {
  24035. if (rowIsSelected)
  24036. g.fillAll (findColour (TextEditor::highlightColourId));
  24037. const PluginDescription* const pd = list.getType (row);
  24038. if (pd != 0)
  24039. {
  24040. GlyphArrangement ga;
  24041. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  24042. g.setColour (Colours::black);
  24043. ga.draw (g);
  24044. float x, y, r, b;
  24045. ga.getBoundingBox (0, -1, x, y, r, b, false);
  24046. String desc;
  24047. desc << pd->pluginFormatName
  24048. << (pd->isInstrument ? " instrument" : " effect")
  24049. << " - "
  24050. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  24051. << " / "
  24052. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  24053. if (pd->manufacturerName.isNotEmpty())
  24054. desc << " - " << pd->manufacturerName;
  24055. if (pd->version.isNotEmpty())
  24056. desc << " - " << pd->version;
  24057. if (pd->category.isNotEmpty())
  24058. desc << " - category: '" << pd->category << '\'';
  24059. g.setColour (Colours::grey);
  24060. ga.clear();
  24061. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, r + 10.0f, height * 0.8f, width - r - 12.0f, true);
  24062. ga.draw (g);
  24063. }
  24064. }
  24065. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  24066. {
  24067. list.removeType (lastRowSelected);
  24068. }
  24069. void PluginListComponent::buttonClicked (Button* b)
  24070. {
  24071. if (optionsButton == b)
  24072. {
  24073. PopupMenu menu;
  24074. menu.addItem (1, TRANS("Clear list"));
  24075. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  24076. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  24077. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  24078. menu.addSeparator();
  24079. menu.addItem (2, TRANS("Sort alphabetically"));
  24080. menu.addItem (3, TRANS("Sort by category"));
  24081. menu.addItem (4, TRANS("Sort by manufacturer"));
  24082. menu.addSeparator();
  24083. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  24084. {
  24085. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  24086. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  24087. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  24088. }
  24089. const int r = menu.showAt (optionsButton);
  24090. if (r == 1)
  24091. {
  24092. list.clear();
  24093. }
  24094. else if (r == 2)
  24095. {
  24096. list.sort (KnownPluginList::sortAlphabetically);
  24097. }
  24098. else if (r == 3)
  24099. {
  24100. list.sort (KnownPluginList::sortByCategory);
  24101. }
  24102. else if (r == 4)
  24103. {
  24104. list.sort (KnownPluginList::sortByManufacturer);
  24105. }
  24106. else if (r == 5)
  24107. {
  24108. const SparseSet <int> selected (listBox->getSelectedRows());
  24109. for (int i = list.getNumTypes(); --i >= 0;)
  24110. if (selected.contains (i))
  24111. list.removeType (i);
  24112. }
  24113. else if (r == 6)
  24114. {
  24115. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  24116. if (desc != 0)
  24117. {
  24118. if (File (desc->fileOrIdentifier).existsAsFile())
  24119. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  24120. }
  24121. }
  24122. else if (r == 7)
  24123. {
  24124. for (int i = list.getNumTypes(); --i >= 0;)
  24125. {
  24126. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  24127. {
  24128. list.removeType (i);
  24129. }
  24130. }
  24131. }
  24132. else if (r != 0)
  24133. {
  24134. typeToScan = r - 10;
  24135. startTimer (1);
  24136. }
  24137. }
  24138. }
  24139. void PluginListComponent::timerCallback()
  24140. {
  24141. stopTimer();
  24142. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  24143. }
  24144. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  24145. {
  24146. return true;
  24147. }
  24148. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  24149. {
  24150. OwnedArray <PluginDescription> typesFound;
  24151. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  24152. }
  24153. void PluginListComponent::scanFor (AudioPluginFormat* format)
  24154. {
  24155. if (format == 0)
  24156. return;
  24157. FileSearchPath path (format->getDefaultLocationsToSearch());
  24158. if (propertiesToUse != 0)
  24159. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24160. {
  24161. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  24162. FileSearchPathListComponent pathList;
  24163. pathList.setSize (500, 300);
  24164. pathList.setPath (path);
  24165. aw.addCustomComponent (&pathList);
  24166. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  24167. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24168. if (aw.runModalLoop() == 0)
  24169. return;
  24170. path = pathList.getPath();
  24171. }
  24172. if (propertiesToUse != 0)
  24173. {
  24174. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24175. propertiesToUse->saveIfNeeded();
  24176. }
  24177. double progress = 0.0;
  24178. AlertWindow aw (TRANS("Scanning for plugins..."),
  24179. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  24180. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24181. aw.addProgressBarComponent (progress);
  24182. aw.enterModalState();
  24183. MessageManager::getInstance()->runDispatchLoopUntil (300);
  24184. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  24185. for (;;)
  24186. {
  24187. aw.setMessage (TRANS("Testing:\n\n")
  24188. + scanner.getNextPluginFileThatWillBeScanned());
  24189. MessageManager::getInstance()->runDispatchLoopUntil (20);
  24190. if (! scanner.scanNextFile (true))
  24191. break;
  24192. if (! aw.isCurrentlyModal())
  24193. break;
  24194. progress = scanner.getProgress();
  24195. }
  24196. if (scanner.getFailedFiles().size() > 0)
  24197. {
  24198. StringArray shortNames;
  24199. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  24200. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  24201. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  24202. TRANS("Scan complete"),
  24203. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  24204. + shortNames.joinIntoString (", "));
  24205. }
  24206. }
  24207. END_JUCE_NAMESPACE
  24208. /*** End of inlined file: juce_PluginListComponent.cpp ***/
  24209. /*** Start of inlined file: juce_AudioUnitPluginFormat.mm ***/
  24210. #if JUCE_PLUGINHOST_AU && (! (defined (LINUX) || defined (_WIN32)))
  24211. #include <AudioUnit/AudioUnit.h>
  24212. #include <AudioUnit/AUCocoaUIView.h>
  24213. #include <CoreAudioKit/AUGenericView.h>
  24214. #if JUCE_SUPPORT_CARBON
  24215. #include <AudioToolbox/AudioUnitUtilities.h>
  24216. #include <AudioUnit/AudioUnitCarbonView.h>
  24217. #endif
  24218. BEGIN_JUCE_NAMESPACE
  24219. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  24220. #endif
  24221. #if JUCE_MAC
  24222. // Change this to disable logging of various activities
  24223. #ifndef AU_LOGGING
  24224. #define AU_LOGGING 1
  24225. #endif
  24226. #if AU_LOGGING
  24227. #define log(a) Logger::writeToLog(a);
  24228. #else
  24229. #define log(a)
  24230. #endif
  24231. static int insideCallback = 0;
  24232. static const String osTypeToString (OSType type) throw()
  24233. {
  24234. char s[4];
  24235. s[0] = (char) (((uint32) type) >> 24);
  24236. s[1] = (char) (((uint32) type) >> 16);
  24237. s[2] = (char) (((uint32) type) >> 8);
  24238. s[3] = (char) ((uint32) type);
  24239. return String (s, 4);
  24240. }
  24241. static OSType stringToOSType (const String& s1) throw()
  24242. {
  24243. const String s (s1 + " ");
  24244. return (((OSType) (unsigned char) s[0]) << 24)
  24245. | (((OSType) (unsigned char) s[1]) << 16)
  24246. | (((OSType) (unsigned char) s[2]) << 8)
  24247. | ((OSType) (unsigned char) s[3]);
  24248. }
  24249. static const tchar* auIdentifierPrefix = T("AudioUnit:");
  24250. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  24251. {
  24252. jassert (osTypeToString ('abcd') == T("abcd")); // agh, must have got the endianness wrong..
  24253. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  24254. String s (auIdentifierPrefix);
  24255. if (desc.componentType == kAudioUnitType_MusicDevice)
  24256. s << "Synths/";
  24257. else if (desc.componentType == kAudioUnitType_MusicEffect
  24258. || desc.componentType == kAudioUnitType_Effect)
  24259. s << "Effects/";
  24260. else if (desc.componentType == kAudioUnitType_Generator)
  24261. s << "Generators/";
  24262. else if (desc.componentType == kAudioUnitType_Panner)
  24263. s << "Panners/";
  24264. s << osTypeToString (desc.componentType)
  24265. << T(",")
  24266. << osTypeToString (desc.componentSubType)
  24267. << T(",")
  24268. << osTypeToString (desc.componentManufacturer);
  24269. return s;
  24270. }
  24271. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  24272. {
  24273. Handle componentNameHandle = NewHandle (sizeof (void*));
  24274. Handle componentInfoHandle = NewHandle (sizeof (void*));
  24275. if (componentNameHandle != 0 && componentInfoHandle != 0)
  24276. {
  24277. ComponentDescription desc;
  24278. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  24279. {
  24280. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  24281. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  24282. if (nameString != 0 && nameString[0] != 0)
  24283. {
  24284. const String all ((const char*) nameString + 1, nameString[0]);
  24285. DBG ("name: "+ all);
  24286. manufacturer = all.upToFirstOccurrenceOf (T(":"), false, false).trim();
  24287. name = all.fromFirstOccurrenceOf (T(":"), false, false).trim();
  24288. }
  24289. if (infoString != 0 && infoString[0] != 0)
  24290. {
  24291. const String all ((const char*) infoString + 1, infoString[0]);
  24292. DBG ("info: " + all);
  24293. }
  24294. if (name.isEmpty())
  24295. name = "<Unknown>";
  24296. }
  24297. DisposeHandle (componentNameHandle);
  24298. DisposeHandle (componentInfoHandle);
  24299. }
  24300. }
  24301. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  24302. String& name, String& version, String& manufacturer)
  24303. {
  24304. zerostruct (desc);
  24305. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24306. {
  24307. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (T(':')),
  24308. fileOrIdentifier.lastIndexOfChar (T('/'))) + 1));
  24309. StringArray tokens;
  24310. tokens.addTokens (s, T(","), 0);
  24311. tokens.trim();
  24312. tokens.removeEmptyStrings();
  24313. if (tokens.size() == 3)
  24314. {
  24315. desc.componentType = stringToOSType (tokens[0]);
  24316. desc.componentSubType = stringToOSType (tokens[1]);
  24317. desc.componentManufacturer = stringToOSType (tokens[2]);
  24318. ComponentRecord* comp = FindNextComponent (0, &desc);
  24319. if (comp != 0)
  24320. {
  24321. getAUDetails (comp, name, manufacturer);
  24322. return true;
  24323. }
  24324. }
  24325. }
  24326. return false;
  24327. }
  24328. class AudioUnitPluginWindowCarbon;
  24329. class AudioUnitPluginWindowCocoa;
  24330. class AudioUnitPluginInstance : public AudioPluginInstance
  24331. {
  24332. public:
  24333. ~AudioUnitPluginInstance();
  24334. // AudioPluginInstance methods:
  24335. void fillInPluginDescription (PluginDescription& desc) const
  24336. {
  24337. desc.name = pluginName;
  24338. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24339. desc.uid = ((int) componentDesc.componentType)
  24340. ^ ((int) componentDesc.componentSubType)
  24341. ^ ((int) componentDesc.componentManufacturer);
  24342. desc.lastFileModTime = 0;
  24343. desc.pluginFormatName = "AudioUnit";
  24344. desc.category = getCategory();
  24345. desc.manufacturerName = manufacturer;
  24346. desc.version = version;
  24347. desc.numInputChannels = getNumInputChannels();
  24348. desc.numOutputChannels = getNumOutputChannels();
  24349. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24350. }
  24351. const String getName() const { return pluginName; }
  24352. bool acceptsMidi() const { return wantsMidiMessages; }
  24353. bool producesMidi() const { return false; }
  24354. // AudioProcessor methods:
  24355. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24356. void releaseResources();
  24357. void processBlock (AudioSampleBuffer& buffer,
  24358. MidiBuffer& midiMessages);
  24359. AudioProcessorEditor* createEditor();
  24360. const String getInputChannelName (const int index) const;
  24361. bool isInputChannelStereoPair (int index) const;
  24362. const String getOutputChannelName (const int index) const;
  24363. bool isOutputChannelStereoPair (int index) const;
  24364. int getNumParameters();
  24365. float getParameter (int index);
  24366. void setParameter (int index, float newValue);
  24367. const String getParameterName (int index);
  24368. const String getParameterText (int index);
  24369. bool isParameterAutomatable (int index) const;
  24370. int getNumPrograms();
  24371. int getCurrentProgram();
  24372. void setCurrentProgram (int index);
  24373. const String getProgramName (int index);
  24374. void changeProgramName (int index, const String& newName);
  24375. void getStateInformation (MemoryBlock& destData);
  24376. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24377. void setStateInformation (const void* data, int sizeInBytes);
  24378. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24379. juce_UseDebuggingNewOperator
  24380. private:
  24381. friend class AudioUnitPluginWindowCarbon;
  24382. friend class AudioUnitPluginWindowCocoa;
  24383. friend class AudioUnitPluginFormat;
  24384. ComponentDescription componentDesc;
  24385. String pluginName, manufacturer, version;
  24386. String fileOrIdentifier;
  24387. CriticalSection lock;
  24388. bool initialised, wantsMidiMessages, wasPlaying;
  24389. HeapBlock <AudioBufferList> outputBufferList;
  24390. AudioTimeStamp timeStamp;
  24391. AudioSampleBuffer* currentBuffer;
  24392. AudioUnit audioUnit;
  24393. Array <int> parameterIds;
  24394. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24395. void initialise();
  24396. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24397. const AudioTimeStamp* inTimeStamp,
  24398. UInt32 inBusNumber,
  24399. UInt32 inNumberFrames,
  24400. AudioBufferList* ioData) const;
  24401. static OSStatus renderGetInputCallback (void* inRefCon,
  24402. AudioUnitRenderActionFlags* ioActionFlags,
  24403. const AudioTimeStamp* inTimeStamp,
  24404. UInt32 inBusNumber,
  24405. UInt32 inNumberFrames,
  24406. AudioBufferList* ioData)
  24407. {
  24408. return ((AudioUnitPluginInstance*) inRefCon)
  24409. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24410. }
  24411. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24412. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24413. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24414. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24415. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24416. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24417. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24418. {
  24419. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24420. }
  24421. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24422. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24423. Float64* outCurrentMeasureDownBeat)
  24424. {
  24425. return ((AudioUnitPluginInstance*) inHostUserData)
  24426. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24427. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24428. }
  24429. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24430. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24431. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24432. {
  24433. return ((AudioUnitPluginInstance*) inHostUserData)
  24434. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24435. outCurrentSampleInTimeLine, outIsCycling,
  24436. outCycleStartBeat, outCycleEndBeat);
  24437. }
  24438. void getNumChannels (int& numIns, int& numOuts)
  24439. {
  24440. numIns = 0;
  24441. numOuts = 0;
  24442. AUChannelInfo supportedChannels [128];
  24443. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24444. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24445. 0, supportedChannels, &supportedChannelsSize) == noErr
  24446. && supportedChannelsSize > 0)
  24447. {
  24448. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24449. {
  24450. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24451. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24452. }
  24453. }
  24454. else
  24455. {
  24456. // (this really means the plugin will take any number of ins/outs as long
  24457. // as they are the same)
  24458. numIns = numOuts = 2;
  24459. }
  24460. }
  24461. const String getCategory() const;
  24462. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24463. };
  24464. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24465. : fileOrIdentifier (fileOrIdentifier),
  24466. initialised (false),
  24467. wantsMidiMessages (false),
  24468. audioUnit (0),
  24469. currentBuffer (0)
  24470. {
  24471. try
  24472. {
  24473. ++insideCallback;
  24474. log (T("Opening AU: ") + fileOrIdentifier);
  24475. if (getComponentDescFromFile (fileOrIdentifier))
  24476. {
  24477. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24478. if (comp != 0)
  24479. {
  24480. audioUnit = (AudioUnit) OpenComponent (comp);
  24481. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24482. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24483. }
  24484. }
  24485. --insideCallback;
  24486. }
  24487. catch (...)
  24488. {
  24489. --insideCallback;
  24490. }
  24491. }
  24492. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24493. {
  24494. {
  24495. const ScopedLock sl (lock);
  24496. jassert (insideCallback == 0);
  24497. if (audioUnit != 0)
  24498. {
  24499. AudioUnitUninitialize (audioUnit);
  24500. CloseComponent (audioUnit);
  24501. audioUnit = 0;
  24502. }
  24503. }
  24504. }
  24505. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24506. {
  24507. zerostruct (componentDesc);
  24508. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24509. return true;
  24510. const File file (fileOrIdentifier);
  24511. if (! file.hasFileExtension (T(".component")))
  24512. return false;
  24513. const char* const utf8 = fileOrIdentifier.toUTF8();
  24514. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24515. strlen (utf8), file.isDirectory());
  24516. if (url != 0)
  24517. {
  24518. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24519. CFRelease (url);
  24520. if (bundleRef != 0)
  24521. {
  24522. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24523. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24524. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24525. if (pluginName.isEmpty())
  24526. pluginName = file.getFileNameWithoutExtension();
  24527. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24528. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24529. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24530. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24531. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24532. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24533. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24534. UseResFile (resFileId);
  24535. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24536. {
  24537. Handle h = Get1IndResource ('thng', i);
  24538. if (h != 0)
  24539. {
  24540. HLock (h);
  24541. const uint32* const types = (const uint32*) *h;
  24542. if (types[0] == kAudioUnitType_MusicDevice
  24543. || types[0] == kAudioUnitType_MusicEffect
  24544. || types[0] == kAudioUnitType_Effect
  24545. || types[0] == kAudioUnitType_Generator
  24546. || types[0] == kAudioUnitType_Panner)
  24547. {
  24548. componentDesc.componentType = types[0];
  24549. componentDesc.componentSubType = types[1];
  24550. componentDesc.componentManufacturer = types[2];
  24551. break;
  24552. }
  24553. HUnlock (h);
  24554. ReleaseResource (h);
  24555. }
  24556. }
  24557. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24558. CFRelease (bundleRef);
  24559. }
  24560. }
  24561. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24562. }
  24563. void AudioUnitPluginInstance::initialise()
  24564. {
  24565. if (initialised || audioUnit == 0)
  24566. return;
  24567. log (T("Initialising AU: ") + pluginName);
  24568. parameterIds.clear();
  24569. {
  24570. UInt32 paramListSize = 0;
  24571. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24572. 0, 0, &paramListSize);
  24573. if (paramListSize > 0)
  24574. {
  24575. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24576. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24577. 0, &parameterIds.getReference(0), &paramListSize);
  24578. }
  24579. }
  24580. {
  24581. AURenderCallbackStruct info;
  24582. zerostruct (info);
  24583. info.inputProcRefCon = this;
  24584. info.inputProc = renderGetInputCallback;
  24585. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24586. 0, &info, sizeof (info));
  24587. }
  24588. {
  24589. HostCallbackInfo info;
  24590. zerostruct (info);
  24591. info.hostUserData = this;
  24592. info.beatAndTempoProc = getBeatAndTempoCallback;
  24593. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24594. info.transportStateProc = getTransportStateCallback;
  24595. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24596. 0, &info, sizeof (info));
  24597. }
  24598. int numIns, numOuts;
  24599. getNumChannels (numIns, numOuts);
  24600. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24601. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24602. setLatencySamples (0);
  24603. }
  24604. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24605. int samplesPerBlockExpected)
  24606. {
  24607. initialise();
  24608. if (initialised)
  24609. {
  24610. int numIns, numOuts;
  24611. getNumChannels (numIns, numOuts);
  24612. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24613. Float64 latencySecs = 0.0;
  24614. UInt32 latencySize = sizeof (latencySecs);
  24615. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24616. 0, &latencySecs, &latencySize);
  24617. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24618. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24619. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24620. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24621. AudioStreamBasicDescription stream;
  24622. zerostruct (stream);
  24623. stream.mSampleRate = sampleRate_;
  24624. stream.mFormatID = kAudioFormatLinearPCM;
  24625. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24626. stream.mFramesPerPacket = 1;
  24627. stream.mBytesPerPacket = 4;
  24628. stream.mBytesPerFrame = 4;
  24629. stream.mBitsPerChannel = 32;
  24630. stream.mChannelsPerFrame = numIns;
  24631. OSStatus err = AudioUnitSetProperty (audioUnit,
  24632. kAudioUnitProperty_StreamFormat,
  24633. kAudioUnitScope_Input,
  24634. 0, &stream, sizeof (stream));
  24635. stream.mChannelsPerFrame = numOuts;
  24636. err = AudioUnitSetProperty (audioUnit,
  24637. kAudioUnitProperty_StreamFormat,
  24638. kAudioUnitScope_Output,
  24639. 0, &stream, sizeof (stream));
  24640. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24641. outputBufferList->mNumberBuffers = numOuts;
  24642. for (int i = numOuts; --i >= 0;)
  24643. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24644. zerostruct (timeStamp);
  24645. timeStamp.mSampleTime = 0;
  24646. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24647. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24648. currentBuffer = 0;
  24649. wasPlaying = false;
  24650. }
  24651. }
  24652. void AudioUnitPluginInstance::releaseResources()
  24653. {
  24654. if (initialised)
  24655. {
  24656. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24657. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24658. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24659. outputBufferList.free();
  24660. currentBuffer = 0;
  24661. }
  24662. }
  24663. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24664. const AudioTimeStamp* inTimeStamp,
  24665. UInt32 inBusNumber,
  24666. UInt32 inNumberFrames,
  24667. AudioBufferList* ioData) const
  24668. {
  24669. if (inBusNumber == 0
  24670. && currentBuffer != 0)
  24671. {
  24672. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24673. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24674. {
  24675. if (i < currentBuffer->getNumChannels())
  24676. {
  24677. memcpy (ioData->mBuffers[i].mData,
  24678. currentBuffer->getSampleData (i, 0),
  24679. sizeof (float) * inNumberFrames);
  24680. }
  24681. else
  24682. {
  24683. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24684. }
  24685. }
  24686. }
  24687. return noErr;
  24688. }
  24689. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24690. MidiBuffer& midiMessages)
  24691. {
  24692. const int numSamples = buffer.getNumSamples();
  24693. if (initialised)
  24694. {
  24695. AudioUnitRenderActionFlags flags = 0;
  24696. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24697. for (int i = getNumOutputChannels(); --i >= 0;)
  24698. {
  24699. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24700. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24701. }
  24702. currentBuffer = &buffer;
  24703. if (wantsMidiMessages)
  24704. {
  24705. const uint8* midiEventData;
  24706. int midiEventSize, midiEventPosition;
  24707. MidiBuffer::Iterator i (midiMessages);
  24708. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24709. {
  24710. if (midiEventSize <= 3)
  24711. MusicDeviceMIDIEvent (audioUnit,
  24712. midiEventData[0], midiEventData[1], midiEventData[2],
  24713. midiEventPosition);
  24714. else
  24715. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24716. }
  24717. midiMessages.clear();
  24718. }
  24719. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24720. 0, numSamples, outputBufferList);
  24721. timeStamp.mSampleTime += numSamples;
  24722. }
  24723. else
  24724. {
  24725. // Not initialised, so just bypass..
  24726. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24727. buffer.clear (i, 0, buffer.getNumSamples());
  24728. }
  24729. }
  24730. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24731. {
  24732. AudioPlayHead* const ph = getPlayHead();
  24733. AudioPlayHead::CurrentPositionInfo result;
  24734. if (ph != 0 && ph->getCurrentPosition (result))
  24735. {
  24736. if (outCurrentBeat != 0)
  24737. *outCurrentBeat = result.ppqPosition;
  24738. if (outCurrentTempo != 0)
  24739. *outCurrentTempo = result.bpm;
  24740. }
  24741. else
  24742. {
  24743. if (outCurrentBeat != 0)
  24744. *outCurrentBeat = 0;
  24745. if (outCurrentTempo != 0)
  24746. *outCurrentTempo = 120.0;
  24747. }
  24748. return noErr;
  24749. }
  24750. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24751. Float32* outTimeSig_Numerator,
  24752. UInt32* outTimeSig_Denominator,
  24753. Float64* outCurrentMeasureDownBeat) const
  24754. {
  24755. AudioPlayHead* const ph = getPlayHead();
  24756. AudioPlayHead::CurrentPositionInfo result;
  24757. if (ph != 0 && ph->getCurrentPosition (result))
  24758. {
  24759. if (outTimeSig_Numerator != 0)
  24760. *outTimeSig_Numerator = result.timeSigNumerator;
  24761. if (outTimeSig_Denominator != 0)
  24762. *outTimeSig_Denominator = result.timeSigDenominator;
  24763. if (outDeltaSampleOffsetToNextBeat != 0)
  24764. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24765. if (outCurrentMeasureDownBeat != 0)
  24766. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24767. }
  24768. else
  24769. {
  24770. if (outDeltaSampleOffsetToNextBeat != 0)
  24771. *outDeltaSampleOffsetToNextBeat = 0;
  24772. if (outTimeSig_Numerator != 0)
  24773. *outTimeSig_Numerator = 4;
  24774. if (outTimeSig_Denominator != 0)
  24775. *outTimeSig_Denominator = 4;
  24776. if (outCurrentMeasureDownBeat != 0)
  24777. *outCurrentMeasureDownBeat = 0;
  24778. }
  24779. return noErr;
  24780. }
  24781. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24782. Boolean* outTransportStateChanged,
  24783. Float64* outCurrentSampleInTimeLine,
  24784. Boolean* outIsCycling,
  24785. Float64* outCycleStartBeat,
  24786. Float64* outCycleEndBeat)
  24787. {
  24788. AudioPlayHead* const ph = getPlayHead();
  24789. AudioPlayHead::CurrentPositionInfo result;
  24790. if (ph != 0 && ph->getCurrentPosition (result))
  24791. {
  24792. if (outIsPlaying != 0)
  24793. *outIsPlaying = result.isPlaying;
  24794. if (outTransportStateChanged != 0)
  24795. {
  24796. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24797. wasPlaying = result.isPlaying;
  24798. }
  24799. if (outCurrentSampleInTimeLine != 0)
  24800. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24801. if (outIsCycling != 0)
  24802. *outIsCycling = false;
  24803. if (outCycleStartBeat != 0)
  24804. *outCycleStartBeat = 0;
  24805. if (outCycleEndBeat != 0)
  24806. *outCycleEndBeat = 0;
  24807. }
  24808. else
  24809. {
  24810. if (outIsPlaying != 0)
  24811. *outIsPlaying = false;
  24812. if (outTransportStateChanged != 0)
  24813. *outTransportStateChanged = false;
  24814. if (outCurrentSampleInTimeLine != 0)
  24815. *outCurrentSampleInTimeLine = 0;
  24816. if (outIsCycling != 0)
  24817. *outIsCycling = false;
  24818. if (outCycleStartBeat != 0)
  24819. *outCycleStartBeat = 0;
  24820. if (outCycleEndBeat != 0)
  24821. *outCycleEndBeat = 0;
  24822. }
  24823. return noErr;
  24824. }
  24825. static VoidArray activeWindows;
  24826. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24827. {
  24828. public:
  24829. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24830. : AudioProcessorEditor (&plugin_),
  24831. plugin (plugin_),
  24832. wrapper (0)
  24833. {
  24834. addAndMakeVisible (wrapper = new NSViewComponent());
  24835. activeWindows.add (this);
  24836. setOpaque (true);
  24837. setVisible (true);
  24838. setSize (100, 100);
  24839. createView (createGenericViewIfNeeded);
  24840. }
  24841. ~AudioUnitPluginWindowCocoa()
  24842. {
  24843. const bool wasValid = isValid();
  24844. wrapper->setView (0);
  24845. activeWindows.removeValue (this);
  24846. if (wasValid)
  24847. plugin.editorBeingDeleted (this);
  24848. delete wrapper;
  24849. }
  24850. bool isValid() const { return wrapper->getView() != 0; }
  24851. void paint (Graphics& g)
  24852. {
  24853. g.fillAll (Colours::white);
  24854. }
  24855. void resized()
  24856. {
  24857. wrapper->setSize (getWidth(), getHeight());
  24858. }
  24859. private:
  24860. AudioUnitPluginInstance& plugin;
  24861. NSViewComponent* wrapper;
  24862. bool createView (const bool createGenericViewIfNeeded)
  24863. {
  24864. NSView* pluginView = 0;
  24865. UInt32 dataSize = 0;
  24866. Boolean isWritable = false;
  24867. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24868. 0, &dataSize, &isWritable) == noErr
  24869. && dataSize != 0
  24870. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24871. 0, &dataSize, &isWritable) == noErr)
  24872. {
  24873. HeapBlock <AudioUnitCocoaViewInfo> info;
  24874. info.calloc (dataSize, 1);
  24875. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24876. 0, info, &dataSize) == noErr)
  24877. {
  24878. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24879. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24880. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24881. Class viewClass = [viewBundle classNamed: viewClassName];
  24882. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24883. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24884. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24885. {
  24886. id factory = [[[viewClass alloc] init] autorelease];
  24887. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24888. withSize: NSMakeSize (getWidth(), getHeight())];
  24889. }
  24890. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24891. {
  24892. CFRelease (info->mCocoaAUViewClass[i]);
  24893. CFRelease (info->mCocoaAUViewBundleLocation);
  24894. }
  24895. }
  24896. }
  24897. if (createGenericViewIfNeeded && (pluginView == 0))
  24898. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24899. wrapper->setView (pluginView);
  24900. if (pluginView != 0)
  24901. setSize ([pluginView frame].size.width,
  24902. [pluginView frame].size.height);
  24903. return pluginView != 0;
  24904. }
  24905. };
  24906. #if JUCE_SUPPORT_CARBON
  24907. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24908. {
  24909. public:
  24910. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24911. : AudioProcessorEditor (&plugin_),
  24912. plugin (plugin_),
  24913. viewComponent (0)
  24914. {
  24915. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24916. activeWindows.add (this);
  24917. setOpaque (true);
  24918. setVisible (true);
  24919. setSize (400, 300);
  24920. ComponentDescription viewList [16];
  24921. UInt32 viewListSize = sizeof (viewList);
  24922. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24923. 0, &viewList, &viewListSize);
  24924. componentRecord = FindNextComponent (0, &viewList[0]);
  24925. }
  24926. ~AudioUnitPluginWindowCarbon()
  24927. {
  24928. deleteAndZero (innerWrapper);
  24929. activeWindows.removeValue (this);
  24930. if (isValid())
  24931. plugin.editorBeingDeleted (this);
  24932. }
  24933. bool isValid() const throw() { return componentRecord != 0; }
  24934. void paint (Graphics& g)
  24935. {
  24936. g.fillAll (Colours::black);
  24937. }
  24938. void resized()
  24939. {
  24940. innerWrapper->setSize (getWidth(), getHeight());
  24941. }
  24942. bool keyStateChanged (const bool)
  24943. {
  24944. return false;
  24945. }
  24946. bool keyPressed (const KeyPress&)
  24947. {
  24948. return false;
  24949. }
  24950. void broughtToFront()
  24951. {
  24952. activeWindows.removeValue (this);
  24953. activeWindows.add (this);
  24954. }
  24955. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  24956. AudioUnitCarbonView getViewComponent()
  24957. {
  24958. if (viewComponent == 0 && componentRecord != 0)
  24959. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  24960. return viewComponent;
  24961. }
  24962. void closeViewComponent()
  24963. {
  24964. if (viewComponent != 0)
  24965. {
  24966. CloseComponent (viewComponent);
  24967. viewComponent = 0;
  24968. }
  24969. }
  24970. juce_UseDebuggingNewOperator
  24971. private:
  24972. AudioUnitPluginInstance& plugin;
  24973. ComponentRecord* componentRecord;
  24974. AudioUnitCarbonView viewComponent;
  24975. class InnerWrapperComponent : public CarbonViewWrapperComponent
  24976. {
  24977. public:
  24978. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  24979. : owner (owner_)
  24980. {
  24981. }
  24982. ~InnerWrapperComponent()
  24983. {
  24984. deleteWindow();
  24985. }
  24986. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  24987. {
  24988. log (T("Opening AU GUI: ") + owner->plugin.getName());
  24989. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  24990. if (viewComponent == 0)
  24991. return 0;
  24992. Float32Point pos = { 0, 0 };
  24993. Float32Point size = { 250, 200 };
  24994. HIViewRef pluginView = 0;
  24995. AudioUnitCarbonViewCreate (viewComponent,
  24996. owner->getAudioUnit(),
  24997. windowRef,
  24998. rootView,
  24999. &pos,
  25000. &size,
  25001. (ControlRef*) &pluginView);
  25002. return pluginView;
  25003. }
  25004. void removeView (HIViewRef)
  25005. {
  25006. log (T("Closing AU GUI: ") + owner->plugin.getName());
  25007. owner->closeViewComponent();
  25008. }
  25009. private:
  25010. AudioUnitPluginWindowCarbon* const owner;
  25011. };
  25012. friend class InnerWrapperComponent;
  25013. InnerWrapperComponent* innerWrapper;
  25014. };
  25015. #endif
  25016. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  25017. {
  25018. ScopedPointer <AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  25019. if (! ((AudioUnitPluginWindowCocoa*) w)->isValid())
  25020. w = 0;
  25021. #if JUCE_SUPPORT_CARBON
  25022. if (w == 0)
  25023. {
  25024. w = new AudioUnitPluginWindowCarbon (*this);
  25025. if (! ((AudioUnitPluginWindowCarbon*) w)->isValid())
  25026. w = 0;
  25027. }
  25028. #endif
  25029. if (w == 0)
  25030. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  25031. return w.release();
  25032. }
  25033. const String AudioUnitPluginInstance::getCategory() const
  25034. {
  25035. const char* result = 0;
  25036. switch (componentDesc.componentType)
  25037. {
  25038. case kAudioUnitType_Effect:
  25039. case kAudioUnitType_MusicEffect:
  25040. result = "Effect";
  25041. break;
  25042. case kAudioUnitType_MusicDevice:
  25043. result = "Synth";
  25044. break;
  25045. case kAudioUnitType_Generator:
  25046. result = "Generator";
  25047. break;
  25048. case kAudioUnitType_Panner:
  25049. result = "Panner";
  25050. break;
  25051. default:
  25052. break;
  25053. }
  25054. return result;
  25055. }
  25056. int AudioUnitPluginInstance::getNumParameters()
  25057. {
  25058. return parameterIds.size();
  25059. }
  25060. float AudioUnitPluginInstance::getParameter (int index)
  25061. {
  25062. const ScopedLock sl (lock);
  25063. Float32 value = 0.0f;
  25064. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  25065. {
  25066. AudioUnitGetParameter (audioUnit,
  25067. (UInt32) parameterIds.getUnchecked (index),
  25068. kAudioUnitScope_Global, 0,
  25069. &value);
  25070. }
  25071. return value;
  25072. }
  25073. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  25074. {
  25075. const ScopedLock sl (lock);
  25076. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  25077. {
  25078. AudioUnitSetParameter (audioUnit,
  25079. (UInt32) parameterIds.getUnchecked (index),
  25080. kAudioUnitScope_Global, 0,
  25081. newValue, 0);
  25082. }
  25083. }
  25084. const String AudioUnitPluginInstance::getParameterName (int index)
  25085. {
  25086. AudioUnitParameterInfo info;
  25087. zerostruct (info);
  25088. UInt32 sz = sizeof (info);
  25089. String name;
  25090. if (AudioUnitGetProperty (audioUnit,
  25091. kAudioUnitProperty_ParameterInfo,
  25092. kAudioUnitScope_Global,
  25093. parameterIds [index], &info, &sz) == noErr)
  25094. {
  25095. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  25096. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  25097. else
  25098. name = String (info.name, sizeof (info.name));
  25099. }
  25100. return name;
  25101. }
  25102. const String AudioUnitPluginInstance::getParameterText (int index)
  25103. {
  25104. return String (getParameter (index));
  25105. }
  25106. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  25107. {
  25108. AudioUnitParameterInfo info;
  25109. UInt32 sz = sizeof (info);
  25110. if (AudioUnitGetProperty (audioUnit,
  25111. kAudioUnitProperty_ParameterInfo,
  25112. kAudioUnitScope_Global,
  25113. parameterIds [index], &info, &sz) == noErr)
  25114. {
  25115. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  25116. }
  25117. return true;
  25118. }
  25119. int AudioUnitPluginInstance::getNumPrograms()
  25120. {
  25121. CFArrayRef presets;
  25122. UInt32 sz = sizeof (CFArrayRef);
  25123. int num = 0;
  25124. if (AudioUnitGetProperty (audioUnit,
  25125. kAudioUnitProperty_FactoryPresets,
  25126. kAudioUnitScope_Global,
  25127. 0, &presets, &sz) == noErr)
  25128. {
  25129. num = (int) CFArrayGetCount (presets);
  25130. CFRelease (presets);
  25131. }
  25132. return num;
  25133. }
  25134. int AudioUnitPluginInstance::getCurrentProgram()
  25135. {
  25136. AUPreset current;
  25137. current.presetNumber = 0;
  25138. UInt32 sz = sizeof (AUPreset);
  25139. AudioUnitGetProperty (audioUnit,
  25140. kAudioUnitProperty_FactoryPresets,
  25141. kAudioUnitScope_Global,
  25142. 0, &current, &sz);
  25143. return current.presetNumber;
  25144. }
  25145. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  25146. {
  25147. AUPreset current;
  25148. current.presetNumber = newIndex;
  25149. current.presetName = 0;
  25150. AudioUnitSetProperty (audioUnit,
  25151. kAudioUnitProperty_FactoryPresets,
  25152. kAudioUnitScope_Global,
  25153. 0, &current, sizeof (AUPreset));
  25154. }
  25155. const String AudioUnitPluginInstance::getProgramName (int index)
  25156. {
  25157. String s;
  25158. CFArrayRef presets;
  25159. UInt32 sz = sizeof (CFArrayRef);
  25160. if (AudioUnitGetProperty (audioUnit,
  25161. kAudioUnitProperty_FactoryPresets,
  25162. kAudioUnitScope_Global,
  25163. 0, &presets, &sz) == noErr)
  25164. {
  25165. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  25166. {
  25167. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  25168. if (p != 0 && p->presetNumber == index)
  25169. {
  25170. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  25171. break;
  25172. }
  25173. }
  25174. CFRelease (presets);
  25175. }
  25176. return s;
  25177. }
  25178. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  25179. {
  25180. jassertfalse // xxx not implemented!
  25181. }
  25182. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  25183. {
  25184. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  25185. return T("Input ") + String (index + 1);
  25186. return String::empty;
  25187. }
  25188. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  25189. {
  25190. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  25191. return false;
  25192. return true;
  25193. }
  25194. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  25195. {
  25196. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  25197. return T("Output ") + String (index + 1);
  25198. return String::empty;
  25199. }
  25200. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  25201. {
  25202. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  25203. return false;
  25204. return true;
  25205. }
  25206. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  25207. {
  25208. getCurrentProgramStateInformation (destData);
  25209. }
  25210. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  25211. {
  25212. CFPropertyListRef propertyList = 0;
  25213. UInt32 sz = sizeof (CFPropertyListRef);
  25214. if (AudioUnitGetProperty (audioUnit,
  25215. kAudioUnitProperty_ClassInfo,
  25216. kAudioUnitScope_Global,
  25217. 0, &propertyList, &sz) == noErr)
  25218. {
  25219. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  25220. CFWriteStreamOpen (stream);
  25221. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  25222. CFWriteStreamClose (stream);
  25223. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  25224. destData.setSize (bytesWritten);
  25225. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  25226. CFRelease (data);
  25227. CFRelease (stream);
  25228. CFRelease (propertyList);
  25229. }
  25230. }
  25231. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  25232. {
  25233. setCurrentProgramStateInformation (data, sizeInBytes);
  25234. }
  25235. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  25236. {
  25237. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  25238. (const UInt8*) data,
  25239. sizeInBytes,
  25240. kCFAllocatorNull);
  25241. CFReadStreamOpen (stream);
  25242. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  25243. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  25244. stream,
  25245. 0,
  25246. kCFPropertyListImmutable,
  25247. &format,
  25248. 0);
  25249. CFRelease (stream);
  25250. if (propertyList != 0)
  25251. AudioUnitSetProperty (audioUnit,
  25252. kAudioUnitProperty_ClassInfo,
  25253. kAudioUnitScope_Global,
  25254. 0, &propertyList, sizeof (propertyList));
  25255. }
  25256. AudioUnitPluginFormat::AudioUnitPluginFormat()
  25257. {
  25258. }
  25259. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  25260. {
  25261. }
  25262. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  25263. const String& fileOrIdentifier)
  25264. {
  25265. if (! fileMightContainThisPluginType (fileOrIdentifier))
  25266. return;
  25267. PluginDescription desc;
  25268. desc.fileOrIdentifier = fileOrIdentifier;
  25269. desc.uid = 0;
  25270. try
  25271. {
  25272. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  25273. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  25274. if (auInstance != 0)
  25275. {
  25276. auInstance->fillInPluginDescription (desc);
  25277. results.add (new PluginDescription (desc));
  25278. }
  25279. }
  25280. catch (...)
  25281. {
  25282. // crashed while loading...
  25283. }
  25284. }
  25285. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  25286. {
  25287. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  25288. {
  25289. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  25290. if (result->audioUnit != 0)
  25291. {
  25292. result->initialise();
  25293. return result.release();
  25294. }
  25295. }
  25296. return 0;
  25297. }
  25298. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  25299. const bool /*recursive*/)
  25300. {
  25301. StringArray result;
  25302. ComponentRecord* comp = 0;
  25303. ComponentDescription desc;
  25304. zerostruct (desc);
  25305. for (;;)
  25306. {
  25307. zerostruct (desc);
  25308. comp = FindNextComponent (comp, &desc);
  25309. if (comp == 0)
  25310. break;
  25311. GetComponentInfo (comp, &desc, 0, 0, 0);
  25312. if (desc.componentType == kAudioUnitType_MusicDevice
  25313. || desc.componentType == kAudioUnitType_MusicEffect
  25314. || desc.componentType == kAudioUnitType_Effect
  25315. || desc.componentType == kAudioUnitType_Generator
  25316. || desc.componentType == kAudioUnitType_Panner)
  25317. {
  25318. const String s (createAUPluginIdentifier (desc));
  25319. DBG (s);
  25320. result.add (s);
  25321. }
  25322. }
  25323. return result;
  25324. }
  25325. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25326. {
  25327. ComponentDescription desc;
  25328. String name, version, manufacturer;
  25329. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25330. return FindNextComponent (0, &desc) != 0;
  25331. const File f (fileOrIdentifier);
  25332. return f.hasFileExtension (T(".component"))
  25333. && f.isDirectory();
  25334. }
  25335. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25336. {
  25337. ComponentDescription desc;
  25338. String name, version, manufacturer;
  25339. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25340. if (name.isEmpty())
  25341. name = fileOrIdentifier;
  25342. return name;
  25343. }
  25344. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25345. {
  25346. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25347. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25348. else
  25349. return File (desc.fileOrIdentifier).exists();
  25350. }
  25351. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25352. {
  25353. return FileSearchPath ("/(Default AudioUnit locations)");
  25354. }
  25355. #endif
  25356. END_JUCE_NAMESPACE
  25357. #undef log
  25358. #endif
  25359. /*** End of inlined file: juce_AudioUnitPluginFormat.mm ***/
  25360. /*** Start of inlined file: juce_VSTPluginFormat.mm ***/
  25361. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25362. #define JUCE_MAC_VST_INCLUDED 1
  25363. /*** Start of inlined file: juce_VSTPluginFormat.cpp ***/
  25364. #if JUCE_PLUGINHOST_VST
  25365. #if (defined (_WIN32) || defined (_WIN64))
  25366. #undef _WIN32_WINNT
  25367. #define _WIN32_WINNT 0x500
  25368. #undef STRICT
  25369. #define STRICT
  25370. #include <windows.h>
  25371. #include <float.h>
  25372. #pragma warning (disable : 4312 4355)
  25373. #elif defined (LINUX) || defined (__linux__)
  25374. #include <float.h>
  25375. #include <sys/time.h>
  25376. #include <X11/Xlib.h>
  25377. #include <X11/Xutil.h>
  25378. #include <X11/Xatom.h>
  25379. #undef Font
  25380. #undef KeyPress
  25381. #undef Drawable
  25382. #undef Time
  25383. #else
  25384. #ifndef JUCE_MAC_VST_INCLUDED
  25385. // On the mac, this file needs to be compiled indirectly, by using
  25386. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25387. #error
  25388. #endif
  25389. #include <Cocoa/Cocoa.h>
  25390. #include <Carbon/Carbon.h>
  25391. #endif
  25392. #if ! (JUCE_MAC && JUCE_64BIT)
  25393. BEGIN_JUCE_NAMESPACE
  25394. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25395. #endif
  25396. #undef PRAGMA_ALIGN_SUPPORTED
  25397. #define VST_FORCE_DEPRECATED 0
  25398. #ifdef _MSC_VER
  25399. #pragma warning (push)
  25400. #pragma warning (disable: 4996)
  25401. #endif
  25402. #include "pluginterfaces/vst2.x/aeffectx.h"
  25403. #ifdef _MSC_VER
  25404. #pragma warning (pop)
  25405. #endif
  25406. #if JUCE_LINUX
  25407. #define Font JUCE_NAMESPACE::Font
  25408. #define KeyPress JUCE_NAMESPACE::KeyPress
  25409. #define Drawable JUCE_NAMESPACE::Drawable
  25410. #define Time JUCE_NAMESPACE::Time
  25411. #endif
  25412. /*** Start of inlined file: juce_VSTMidiEventList.h ***/
  25413. #ifdef __aeffect__
  25414. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25415. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25416. class VSTMidiEventList
  25417. {
  25418. public:
  25419. VSTMidiEventList()
  25420. : numEventsUsed (0), numEventsAllocated (0)
  25421. {
  25422. }
  25423. ~VSTMidiEventList()
  25424. {
  25425. freeEvents();
  25426. }
  25427. void clear()
  25428. {
  25429. numEventsUsed = 0;
  25430. if (events != 0)
  25431. events->numEvents = 0;
  25432. }
  25433. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25434. {
  25435. ensureSize (numEventsUsed + 1);
  25436. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25437. events->numEvents = ++numEventsUsed;
  25438. if (numBytes <= 4)
  25439. {
  25440. if (e->type == kVstSysExType)
  25441. {
  25442. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25443. e->type = kVstMidiType;
  25444. e->byteSize = sizeof (VstMidiEvent);
  25445. e->noteLength = 0;
  25446. e->noteOffset = 0;
  25447. e->detune = 0;
  25448. e->noteOffVelocity = 0;
  25449. }
  25450. e->deltaFrames = frameOffset;
  25451. memcpy (e->midiData, midiData, numBytes);
  25452. }
  25453. else
  25454. {
  25455. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25456. if (se->type == kVstSysExType)
  25457. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25458. else
  25459. se->sysexDump = (char*) juce_malloc (numBytes);
  25460. memcpy (se->sysexDump, midiData, numBytes);
  25461. se->type = kVstSysExType;
  25462. se->byteSize = sizeof (VstMidiSysexEvent);
  25463. se->deltaFrames = frameOffset;
  25464. se->flags = 0;
  25465. se->dumpBytes = numBytes;
  25466. se->resvd1 = 0;
  25467. se->resvd2 = 0;
  25468. }
  25469. }
  25470. // Handy method to pull the events out of an event buffer supplied by the host
  25471. // or plugin.
  25472. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25473. {
  25474. for (int i = 0; i < events->numEvents; ++i)
  25475. {
  25476. const VstEvent* const e = events->events[i];
  25477. if (e != 0)
  25478. {
  25479. if (e->type == kVstMidiType)
  25480. {
  25481. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25482. 4, e->deltaFrames);
  25483. }
  25484. else if (e->type == kVstSysExType)
  25485. {
  25486. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25487. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25488. e->deltaFrames);
  25489. }
  25490. }
  25491. }
  25492. }
  25493. void ensureSize (int numEventsNeeded)
  25494. {
  25495. if (numEventsNeeded > numEventsAllocated)
  25496. {
  25497. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25498. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25499. if (events == 0)
  25500. events.calloc (size, 1);
  25501. else
  25502. events.realloc (size, 1);
  25503. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25504. {
  25505. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25506. (int) sizeof (VstMidiSysexEvent)));
  25507. e->type = kVstMidiType;
  25508. e->byteSize = sizeof (VstMidiEvent);
  25509. events->events[i] = (VstEvent*) e;
  25510. }
  25511. numEventsAllocated = numEventsNeeded;
  25512. }
  25513. }
  25514. void freeEvents()
  25515. {
  25516. if (events != 0)
  25517. {
  25518. for (int i = numEventsAllocated; --i >= 0;)
  25519. {
  25520. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25521. if (e->type == kVstSysExType)
  25522. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25523. juce_free (e);
  25524. }
  25525. events.free();
  25526. numEventsUsed = 0;
  25527. numEventsAllocated = 0;
  25528. }
  25529. }
  25530. HeapBlock <VstEvents> events;
  25531. private:
  25532. int numEventsUsed, numEventsAllocated;
  25533. };
  25534. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25535. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25536. /*** End of inlined file: juce_VSTMidiEventList.h ***/
  25537. #if ! JUCE_WIN32
  25538. #define _fpreset()
  25539. #define _clearfp()
  25540. #endif
  25541. extern void juce_callAnyTimersSynchronously();
  25542. const int fxbVersionNum = 1;
  25543. struct fxProgram
  25544. {
  25545. long chunkMagic; // 'CcnK'
  25546. long byteSize; // of this chunk, excl. magic + byteSize
  25547. long fxMagic; // 'FxCk'
  25548. long version;
  25549. long fxID; // fx unique id
  25550. long fxVersion;
  25551. long numParams;
  25552. char prgName[28];
  25553. float params[1]; // variable no. of parameters
  25554. };
  25555. struct fxSet
  25556. {
  25557. long chunkMagic; // 'CcnK'
  25558. long byteSize; // of this chunk, excl. magic + byteSize
  25559. long fxMagic; // 'FxBk'
  25560. long version;
  25561. long fxID; // fx unique id
  25562. long fxVersion;
  25563. long numPrograms;
  25564. char future[128];
  25565. fxProgram programs[1]; // variable no. of programs
  25566. };
  25567. struct fxChunkSet
  25568. {
  25569. long chunkMagic; // 'CcnK'
  25570. long byteSize; // of this chunk, excl. magic + byteSize
  25571. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25572. long version;
  25573. long fxID; // fx unique id
  25574. long fxVersion;
  25575. long numPrograms;
  25576. char future[128];
  25577. long chunkSize;
  25578. char chunk[8]; // variable
  25579. };
  25580. struct fxProgramSet
  25581. {
  25582. long chunkMagic; // 'CcnK'
  25583. long byteSize; // of this chunk, excl. magic + byteSize
  25584. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25585. long version;
  25586. long fxID; // fx unique id
  25587. long fxVersion;
  25588. long numPrograms;
  25589. char name[28];
  25590. long chunkSize;
  25591. char chunk[8]; // variable
  25592. };
  25593. static long vst_swap (const long x) throw()
  25594. {
  25595. #ifdef JUCE_LITTLE_ENDIAN
  25596. return (long) ByteOrder::swap ((uint32) x);
  25597. #else
  25598. return x;
  25599. #endif
  25600. }
  25601. static float vst_swapFloat (const float x) throw()
  25602. {
  25603. #ifdef JUCE_LITTLE_ENDIAN
  25604. union { uint32 asInt; float asFloat; } n;
  25605. n.asFloat = x;
  25606. n.asInt = ByteOrder::swap (n.asInt);
  25607. return n.asFloat;
  25608. #else
  25609. return x;
  25610. #endif
  25611. }
  25612. typedef AEffect* (*MainCall) (audioMasterCallback);
  25613. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25614. static int shellUIDToCreate = 0;
  25615. static int insideVSTCallback = 0;
  25616. class VSTPluginWindow;
  25617. // Change this to disable logging of various VST activities
  25618. #ifndef VST_LOGGING
  25619. #define VST_LOGGING 1
  25620. #endif
  25621. #if VST_LOGGING
  25622. #define log(a) Logger::writeToLog(a);
  25623. #else
  25624. #define log(a)
  25625. #endif
  25626. #if JUCE_MAC && JUCE_PPC
  25627. static void* NewCFMFromMachO (void* const machofp) throw()
  25628. {
  25629. void* result = juce_malloc (8);
  25630. ((void**) result)[0] = machofp;
  25631. ((void**) result)[1] = result;
  25632. return result;
  25633. }
  25634. #endif
  25635. #if JUCE_LINUX
  25636. extern Display* display;
  25637. extern XContext improbableNumber;
  25638. typedef void (*EventProcPtr) (XEvent* ev);
  25639. static bool xErrorTriggered;
  25640. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25641. {
  25642. xErrorTriggered = true;
  25643. return 0;
  25644. }
  25645. static int getPropertyFromXWindow (Window handle, Atom atom)
  25646. {
  25647. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25648. xErrorTriggered = false;
  25649. int userSize;
  25650. unsigned long bytes, userCount;
  25651. unsigned char* data;
  25652. Atom userType;
  25653. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25654. &userType, &userSize, &userCount, &bytes, &data);
  25655. XSetErrorHandler (oldErrorHandler);
  25656. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25657. : 0;
  25658. }
  25659. static Window getChildWindow (Window windowToCheck)
  25660. {
  25661. Window rootWindow, parentWindow;
  25662. Window* childWindows;
  25663. unsigned int numChildren;
  25664. XQueryTree (display,
  25665. windowToCheck,
  25666. &rootWindow,
  25667. &parentWindow,
  25668. &childWindows,
  25669. &numChildren);
  25670. if (numChildren > 0)
  25671. return childWindows [0];
  25672. return 0;
  25673. }
  25674. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25675. {
  25676. if (e.mods.isLeftButtonDown())
  25677. {
  25678. ev.xbutton.button = Button1;
  25679. ev.xbutton.state |= Button1Mask;
  25680. }
  25681. else if (e.mods.isRightButtonDown())
  25682. {
  25683. ev.xbutton.button = Button3;
  25684. ev.xbutton.state |= Button3Mask;
  25685. }
  25686. else if (e.mods.isMiddleButtonDown())
  25687. {
  25688. ev.xbutton.button = Button2;
  25689. ev.xbutton.state |= Button2Mask;
  25690. }
  25691. }
  25692. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25693. {
  25694. if (e.mods.isLeftButtonDown())
  25695. ev.xmotion.state |= Button1Mask;
  25696. else if (e.mods.isRightButtonDown())
  25697. ev.xmotion.state |= Button3Mask;
  25698. else if (e.mods.isMiddleButtonDown())
  25699. ev.xmotion.state |= Button2Mask;
  25700. }
  25701. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25702. {
  25703. if (e.mods.isLeftButtonDown())
  25704. ev.xcrossing.state |= Button1Mask;
  25705. else if (e.mods.isRightButtonDown())
  25706. ev.xcrossing.state |= Button3Mask;
  25707. else if (e.mods.isMiddleButtonDown())
  25708. ev.xcrossing.state |= Button2Mask;
  25709. }
  25710. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25711. {
  25712. if (increment < 0)
  25713. {
  25714. ev.xbutton.button = Button5;
  25715. ev.xbutton.state |= Button5Mask;
  25716. }
  25717. else if (increment > 0)
  25718. {
  25719. ev.xbutton.button = Button4;
  25720. ev.xbutton.state |= Button4Mask;
  25721. }
  25722. }
  25723. #endif
  25724. static VoidArray activeModules;
  25725. class ModuleHandle : public ReferenceCountedObject
  25726. {
  25727. public:
  25728. File file;
  25729. MainCall moduleMain;
  25730. String pluginName;
  25731. static ModuleHandle* findOrCreateModule (const File& file)
  25732. {
  25733. for (int i = activeModules.size(); --i >= 0;)
  25734. {
  25735. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25736. if (module->file == file)
  25737. return module;
  25738. }
  25739. _fpreset(); // (doesn't do any harm)
  25740. ++insideVSTCallback;
  25741. shellUIDToCreate = 0;
  25742. log ("Attempting to load VST: " + file.getFullPathName());
  25743. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25744. if (! m->open())
  25745. m = 0;
  25746. --insideVSTCallback;
  25747. _fpreset(); // (doesn't do any harm)
  25748. return m.release();
  25749. }
  25750. ModuleHandle (const File& file_)
  25751. : file (file_),
  25752. moduleMain (0),
  25753. #if JUCE_WIN32 || JUCE_LINUX
  25754. hModule (0)
  25755. #elif JUCE_MAC
  25756. fragId (0),
  25757. resHandle (0),
  25758. bundleRef (0),
  25759. resFileId (0)
  25760. #endif
  25761. {
  25762. activeModules.add (this);
  25763. #if JUCE_WIN32 || JUCE_LINUX
  25764. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25765. #elif JUCE_MAC
  25766. FSRef ref;
  25767. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25768. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25769. #endif
  25770. }
  25771. ~ModuleHandle()
  25772. {
  25773. activeModules.removeValue (this);
  25774. close();
  25775. }
  25776. juce_UseDebuggingNewOperator
  25777. #if JUCE_WIN32 || JUCE_LINUX
  25778. void* hModule;
  25779. String fullParentDirectoryPathName;
  25780. bool open()
  25781. {
  25782. #if JUCE_WIN32
  25783. static bool timePeriodSet = false;
  25784. if (! timePeriodSet)
  25785. {
  25786. timePeriodSet = true;
  25787. timeBeginPeriod (2);
  25788. }
  25789. #endif
  25790. pluginName = file.getFileNameWithoutExtension();
  25791. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25792. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25793. if (moduleMain == 0)
  25794. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25795. return moduleMain != 0;
  25796. }
  25797. void close()
  25798. {
  25799. _fpreset(); // (doesn't do any harm)
  25800. PlatformUtilities::freeDynamicLibrary (hModule);
  25801. }
  25802. void closeEffect (AEffect* eff)
  25803. {
  25804. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25805. }
  25806. #else
  25807. CFragConnectionID fragId;
  25808. Handle resHandle;
  25809. CFBundleRef bundleRef;
  25810. FSSpec parentDirFSSpec;
  25811. short resFileId;
  25812. bool open()
  25813. {
  25814. bool ok = false;
  25815. const String filename (file.getFullPathName());
  25816. if (file.hasFileExtension (T(".vst")))
  25817. {
  25818. const char* const utf8 = filename.toUTF8();
  25819. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25820. strlen (utf8), file.isDirectory());
  25821. if (url != 0)
  25822. {
  25823. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25824. CFRelease (url);
  25825. if (bundleRef != 0)
  25826. {
  25827. if (CFBundleLoadExecutable (bundleRef))
  25828. {
  25829. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25830. if (moduleMain == 0)
  25831. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25832. if (moduleMain != 0)
  25833. {
  25834. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25835. if (name != 0)
  25836. {
  25837. if (CFGetTypeID (name) == CFStringGetTypeID())
  25838. {
  25839. char buffer[1024];
  25840. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25841. pluginName = buffer;
  25842. }
  25843. }
  25844. if (pluginName.isEmpty())
  25845. pluginName = file.getFileNameWithoutExtension();
  25846. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25847. ok = true;
  25848. }
  25849. }
  25850. if (! ok)
  25851. {
  25852. CFBundleUnloadExecutable (bundleRef);
  25853. CFRelease (bundleRef);
  25854. bundleRef = 0;
  25855. }
  25856. }
  25857. }
  25858. }
  25859. #if JUCE_PPC
  25860. else
  25861. {
  25862. FSRef fn;
  25863. if (FSPathMakeRef ((UInt8*) filename.toUTF8(), &fn, 0) == noErr)
  25864. {
  25865. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25866. if (resFileId != -1)
  25867. {
  25868. const int numEffs = Count1Resources ('aEff');
  25869. for (int i = 0; i < numEffs; ++i)
  25870. {
  25871. resHandle = Get1IndResource ('aEff', i + 1);
  25872. if (resHandle != 0)
  25873. {
  25874. OSType type;
  25875. Str255 name;
  25876. SInt16 id;
  25877. GetResInfo (resHandle, &id, &type, name);
  25878. pluginName = String ((const char*) name + 1, name[0]);
  25879. DetachResource (resHandle);
  25880. HLock (resHandle);
  25881. Ptr ptr;
  25882. Str255 errorText;
  25883. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25884. name, kPrivateCFragCopy,
  25885. &fragId, &ptr, errorText);
  25886. if (err == noErr)
  25887. {
  25888. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25889. ok = true;
  25890. }
  25891. else
  25892. {
  25893. HUnlock (resHandle);
  25894. }
  25895. break;
  25896. }
  25897. }
  25898. if (! ok)
  25899. CloseResFile (resFileId);
  25900. }
  25901. }
  25902. }
  25903. #endif
  25904. return ok;
  25905. }
  25906. void close()
  25907. {
  25908. #if JUCE_PPC
  25909. if (fragId != 0)
  25910. {
  25911. if (moduleMain != 0)
  25912. disposeMachOFromCFM ((void*) moduleMain);
  25913. CloseConnection (&fragId);
  25914. HUnlock (resHandle);
  25915. if (resFileId != 0)
  25916. CloseResFile (resFileId);
  25917. }
  25918. else
  25919. #endif
  25920. if (bundleRef != 0)
  25921. {
  25922. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25923. if (CFGetRetainCount (bundleRef) == 1)
  25924. CFBundleUnloadExecutable (bundleRef);
  25925. if (CFGetRetainCount (bundleRef) > 0)
  25926. CFRelease (bundleRef);
  25927. }
  25928. }
  25929. void closeEffect (AEffect* eff)
  25930. {
  25931. #if JUCE_PPC
  25932. if (fragId != 0)
  25933. {
  25934. VoidArray thingsToDelete;
  25935. thingsToDelete.add ((void*) eff->dispatcher);
  25936. thingsToDelete.add ((void*) eff->process);
  25937. thingsToDelete.add ((void*) eff->setParameter);
  25938. thingsToDelete.add ((void*) eff->getParameter);
  25939. thingsToDelete.add ((void*) eff->processReplacing);
  25940. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25941. for (int i = thingsToDelete.size(); --i >= 0;)
  25942. disposeMachOFromCFM (thingsToDelete[i]);
  25943. }
  25944. else
  25945. #endif
  25946. {
  25947. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25948. }
  25949. }
  25950. #if JUCE_PPC
  25951. static void* newMachOFromCFM (void* cfmfp)
  25952. {
  25953. if (cfmfp == 0)
  25954. return 0;
  25955. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  25956. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  25957. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  25958. mfp[2] = 0x800c0000;
  25959. mfp[3] = 0x804c0004;
  25960. mfp[4] = 0x7c0903a6;
  25961. mfp[5] = 0x4e800420;
  25962. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  25963. return mfp;
  25964. }
  25965. static void disposeMachOFromCFM (void* ptr)
  25966. {
  25967. juce_free (ptr);
  25968. }
  25969. void coerceAEffectFunctionCalls (AEffect* eff)
  25970. {
  25971. if (fragId != 0)
  25972. {
  25973. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  25974. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  25975. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  25976. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  25977. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  25978. }
  25979. }
  25980. #endif
  25981. #endif
  25982. };
  25983. class VSTPluginInstance : public AudioPluginInstance,
  25984. private Timer,
  25985. private AsyncUpdater
  25986. {
  25987. public:
  25988. ~VSTPluginInstance();
  25989. // AudioPluginInstance methods:
  25990. void fillInPluginDescription (PluginDescription& desc) const
  25991. {
  25992. desc.name = name;
  25993. desc.fileOrIdentifier = module->file.getFullPathName();
  25994. desc.uid = getUID();
  25995. desc.lastFileModTime = module->file.getLastModificationTime();
  25996. desc.pluginFormatName = "VST";
  25997. desc.category = getCategory();
  25998. {
  25999. char buffer [kVstMaxVendorStrLen + 8];
  26000. zerostruct (buffer);
  26001. dispatch (effGetVendorString, 0, 0, buffer, 0);
  26002. desc.manufacturerName = buffer;
  26003. }
  26004. desc.version = getVersion();
  26005. desc.numInputChannels = getNumInputChannels();
  26006. desc.numOutputChannels = getNumOutputChannels();
  26007. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  26008. }
  26009. const String getName() const { return name; }
  26010. int getUID() const throw();
  26011. bool acceptsMidi() const { return wantsMidiMessages; }
  26012. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  26013. // AudioProcessor methods:
  26014. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  26015. void releaseResources();
  26016. void processBlock (AudioSampleBuffer& buffer,
  26017. MidiBuffer& midiMessages);
  26018. AudioProcessorEditor* createEditor();
  26019. const String getInputChannelName (const int index) const;
  26020. bool isInputChannelStereoPair (int index) const;
  26021. const String getOutputChannelName (const int index) const;
  26022. bool isOutputChannelStereoPair (int index) const;
  26023. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  26024. float getParameter (int index);
  26025. void setParameter (int index, float newValue);
  26026. const String getParameterName (int index);
  26027. const String getParameterText (int index);
  26028. bool isParameterAutomatable (int index) const;
  26029. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  26030. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  26031. void setCurrentProgram (int index);
  26032. const String getProgramName (int index);
  26033. void changeProgramName (int index, const String& newName);
  26034. void getStateInformation (MemoryBlock& destData);
  26035. void getCurrentProgramStateInformation (MemoryBlock& destData);
  26036. void setStateInformation (const void* data, int sizeInBytes);
  26037. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  26038. void timerCallback();
  26039. void handleAsyncUpdate();
  26040. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  26041. juce_UseDebuggingNewOperator
  26042. private:
  26043. friend class VSTPluginWindow;
  26044. friend class VSTPluginFormat;
  26045. AEffect* effect;
  26046. String name;
  26047. CriticalSection lock;
  26048. bool wantsMidiMessages, initialised, isPowerOn;
  26049. mutable StringArray programNames;
  26050. AudioSampleBuffer tempBuffer;
  26051. CriticalSection midiInLock;
  26052. MidiBuffer incomingMidi;
  26053. VSTMidiEventList midiEventsToSend;
  26054. VstTimeInfo vstHostTime;
  26055. HeapBlock <float*> channels;
  26056. ReferenceCountedObjectPtr <ModuleHandle> module;
  26057. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  26058. bool restoreProgramSettings (const fxProgram* const prog);
  26059. const String getCurrentProgramName();
  26060. void setParamsInProgramBlock (fxProgram* const prog) throw();
  26061. void updateStoredProgramNames();
  26062. void initialise();
  26063. void handleMidiFromPlugin (const VstEvents* const events);
  26064. void createTempParameterStore (MemoryBlock& dest);
  26065. void restoreFromTempParameterStore (const MemoryBlock& mb);
  26066. const String getParameterLabel (int index) const;
  26067. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  26068. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  26069. void setChunkData (const char* data, int size, bool isPreset);
  26070. bool loadFromFXBFile (const void* data, int numBytes);
  26071. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  26072. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  26073. const String getVersion() const throw();
  26074. const String getCategory() const throw();
  26075. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  26076. void setPower (const bool on);
  26077. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  26078. };
  26079. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  26080. : effect (0),
  26081. wantsMidiMessages (false),
  26082. initialised (false),
  26083. isPowerOn (false),
  26084. tempBuffer (1, 1),
  26085. module (module_)
  26086. {
  26087. try
  26088. {
  26089. _fpreset();
  26090. ++insideVSTCallback;
  26091. name = module->pluginName;
  26092. log (T("Creating VST instance: ") + name);
  26093. #if JUCE_MAC
  26094. if (module->resFileId != 0)
  26095. UseResFile (module->resFileId);
  26096. #if JUCE_PPC
  26097. if (module->fragId != 0)
  26098. {
  26099. static void* audioMasterCoerced = 0;
  26100. if (audioMasterCoerced == 0)
  26101. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  26102. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  26103. }
  26104. else
  26105. #endif
  26106. #endif
  26107. {
  26108. effect = module->moduleMain (&audioMaster);
  26109. }
  26110. --insideVSTCallback;
  26111. if (effect != 0 && effect->magic == kEffectMagic)
  26112. {
  26113. #if JUCE_PPC
  26114. module->coerceAEffectFunctionCalls (effect);
  26115. #endif
  26116. jassert (effect->resvd2 == 0);
  26117. jassert (effect->object != 0);
  26118. _fpreset(); // some dodgy plugs fuck around with this
  26119. }
  26120. else
  26121. {
  26122. effect = 0;
  26123. }
  26124. }
  26125. catch (...)
  26126. {
  26127. --insideVSTCallback;
  26128. }
  26129. }
  26130. VSTPluginInstance::~VSTPluginInstance()
  26131. {
  26132. {
  26133. const ScopedLock sl (lock);
  26134. jassert (insideVSTCallback == 0);
  26135. if (effect != 0 && effect->magic == kEffectMagic)
  26136. {
  26137. try
  26138. {
  26139. #if JUCE_MAC
  26140. if (module->resFileId != 0)
  26141. UseResFile (module->resFileId);
  26142. #endif
  26143. // Must delete any editors before deleting the plugin instance!
  26144. jassert (getActiveEditor() == 0);
  26145. _fpreset(); // some dodgy plugs fuck around with this
  26146. module->closeEffect (effect);
  26147. }
  26148. catch (...)
  26149. {}
  26150. }
  26151. module = 0;
  26152. effect = 0;
  26153. }
  26154. }
  26155. void VSTPluginInstance::initialise()
  26156. {
  26157. if (initialised || effect == 0)
  26158. return;
  26159. log (T("Initialising VST: ") + module->pluginName);
  26160. initialised = true;
  26161. dispatch (effIdentify, 0, 0, 0, 0);
  26162. // this code would ask the plugin for its name, but so few plugins
  26163. // actually bother implementing this correctly, that it's better to
  26164. // just ignore it and use the file name instead.
  26165. if (getSampleRate() > 0)
  26166. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  26167. if (getBlockSize() > 0)
  26168. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  26169. dispatch (effOpen, 0, 0, 0, 0);
  26170. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26171. getSampleRate(), getBlockSize());
  26172. if (getNumPrograms() > 1)
  26173. setCurrentProgram (0);
  26174. else
  26175. dispatch (effSetProgram, 0, 0, 0, 0);
  26176. int i;
  26177. for (i = effect->numInputs; --i >= 0;)
  26178. dispatch (effConnectInput, i, 1, 0, 0);
  26179. for (i = effect->numOutputs; --i >= 0;)
  26180. dispatch (effConnectOutput, i, 1, 0, 0);
  26181. updateStoredProgramNames();
  26182. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  26183. setLatencySamples (effect->initialDelay);
  26184. }
  26185. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  26186. int samplesPerBlockExpected)
  26187. {
  26188. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26189. sampleRate_, samplesPerBlockExpected);
  26190. setLatencySamples (effect->initialDelay);
  26191. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  26192. vstHostTime.tempo = 120.0;
  26193. vstHostTime.timeSigNumerator = 4;
  26194. vstHostTime.timeSigDenominator = 4;
  26195. vstHostTime.sampleRate = sampleRate_;
  26196. vstHostTime.samplePos = 0;
  26197. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  26198. initialise();
  26199. if (initialised)
  26200. {
  26201. wantsMidiMessages = wantsMidiMessages
  26202. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  26203. if (wantsMidiMessages)
  26204. midiEventsToSend.ensureSize (256);
  26205. else
  26206. midiEventsToSend.freeEvents();
  26207. incomingMidi.clear();
  26208. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  26209. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  26210. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  26211. if (! isPowerOn)
  26212. setPower (true);
  26213. // dodgy hack to force some plugins to initialise the sample rate..
  26214. if ((! hasEditor()) && getNumParameters() > 0)
  26215. {
  26216. const float old = getParameter (0);
  26217. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  26218. setParameter (0, old);
  26219. }
  26220. dispatch (effStartProcess, 0, 0, 0, 0);
  26221. }
  26222. }
  26223. void VSTPluginInstance::releaseResources()
  26224. {
  26225. if (initialised)
  26226. {
  26227. dispatch (effStopProcess, 0, 0, 0, 0);
  26228. setPower (false);
  26229. }
  26230. tempBuffer.setSize (1, 1);
  26231. incomingMidi.clear();
  26232. midiEventsToSend.freeEvents();
  26233. channels.free();
  26234. }
  26235. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  26236. MidiBuffer& midiMessages)
  26237. {
  26238. const int numSamples = buffer.getNumSamples();
  26239. if (initialised)
  26240. {
  26241. AudioPlayHead* playHead = getPlayHead();
  26242. if (playHead != 0)
  26243. {
  26244. AudioPlayHead::CurrentPositionInfo position;
  26245. playHead->getCurrentPosition (position);
  26246. vstHostTime.tempo = position.bpm;
  26247. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  26248. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  26249. vstHostTime.ppqPos = position.ppqPosition;
  26250. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  26251. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  26252. if (position.isPlaying)
  26253. vstHostTime.flags |= kVstTransportPlaying;
  26254. else
  26255. vstHostTime.flags &= ~kVstTransportPlaying;
  26256. }
  26257. #if JUCE_WIN32
  26258. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  26259. #elif JUCE_LINUX
  26260. timeval micro;
  26261. gettimeofday (&micro, 0);
  26262. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  26263. #elif JUCE_MAC
  26264. UnsignedWide micro;
  26265. Microseconds (&micro);
  26266. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  26267. #endif
  26268. if (wantsMidiMessages)
  26269. {
  26270. midiEventsToSend.clear();
  26271. midiEventsToSend.ensureSize (1);
  26272. MidiBuffer::Iterator iter (midiMessages);
  26273. const uint8* midiData;
  26274. int numBytesOfMidiData, samplePosition;
  26275. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  26276. {
  26277. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  26278. jlimit (0, numSamples - 1, samplePosition));
  26279. }
  26280. try
  26281. {
  26282. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  26283. }
  26284. catch (...)
  26285. {}
  26286. }
  26287. int i;
  26288. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  26289. for (i = 0; i < maxChans; ++i)
  26290. channels[i] = buffer.getSampleData (i);
  26291. channels [maxChans] = 0;
  26292. _clearfp();
  26293. if ((effect->flags & effFlagsCanReplacing) != 0)
  26294. {
  26295. try
  26296. {
  26297. effect->processReplacing (effect, channels, channels, numSamples);
  26298. }
  26299. catch (...)
  26300. {}
  26301. }
  26302. else
  26303. {
  26304. tempBuffer.setSize (effect->numOutputs, numSamples);
  26305. tempBuffer.clear();
  26306. float* outs [64];
  26307. for (i = effect->numOutputs; --i >= 0;)
  26308. outs[i] = tempBuffer.getSampleData (i);
  26309. outs [effect->numOutputs] = 0;
  26310. try
  26311. {
  26312. effect->process (effect, channels, outs, numSamples);
  26313. }
  26314. catch (...)
  26315. {}
  26316. for (i = effect->numOutputs; --i >= 0;)
  26317. buffer.copyFrom (i, 0, outs[i], numSamples);
  26318. }
  26319. }
  26320. else
  26321. {
  26322. // Not initialised, so just bypass..
  26323. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26324. buffer.clear (i, 0, buffer.getNumSamples());
  26325. }
  26326. {
  26327. // copy any incoming midi..
  26328. const ScopedLock sl (midiInLock);
  26329. midiMessages = incomingMidi;
  26330. incomingMidi.clear();
  26331. }
  26332. }
  26333. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26334. {
  26335. if (events != 0)
  26336. {
  26337. const ScopedLock sl (midiInLock);
  26338. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26339. }
  26340. }
  26341. static Array <VSTPluginWindow*> activeVSTWindows;
  26342. class VSTPluginWindow : public AudioProcessorEditor,
  26343. #if ! JUCE_MAC
  26344. public ComponentMovementWatcher,
  26345. #endif
  26346. public Timer
  26347. {
  26348. public:
  26349. VSTPluginWindow (VSTPluginInstance& plugin_)
  26350. : AudioProcessorEditor (&plugin_),
  26351. #if ! JUCE_MAC
  26352. ComponentMovementWatcher (this),
  26353. #endif
  26354. plugin (plugin_),
  26355. isOpen (false),
  26356. wasShowing (false),
  26357. pluginRefusesToResize (false),
  26358. pluginWantsKeys (false),
  26359. alreadyInside (false),
  26360. recursiveResize (false)
  26361. {
  26362. #if JUCE_WIN32
  26363. sizeCheckCount = 0;
  26364. pluginHWND = 0;
  26365. #elif JUCE_LINUX
  26366. pluginWindow = None;
  26367. pluginProc = None;
  26368. #else
  26369. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26370. #endif
  26371. activeVSTWindows.add (this);
  26372. setSize (1, 1);
  26373. setOpaque (true);
  26374. setVisible (true);
  26375. }
  26376. ~VSTPluginWindow()
  26377. {
  26378. #if JUCE_MAC
  26379. innerWrapper = 0;
  26380. #else
  26381. closePluginWindow();
  26382. #endif
  26383. activeVSTWindows.removeValue (this);
  26384. plugin.editorBeingDeleted (this);
  26385. }
  26386. #if ! JUCE_MAC
  26387. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26388. {
  26389. if (recursiveResize)
  26390. return;
  26391. Component* const topComp = getTopLevelComponent();
  26392. if (topComp->getPeer() != 0)
  26393. {
  26394. const Point<int> pos (relativePositionToOtherComponent (topComp, Point<int>()));
  26395. recursiveResize = true;
  26396. #if JUCE_WIN32
  26397. if (pluginHWND != 0)
  26398. MoveWindow (pluginHWND, pos.getX(), pos.getY(), getWidth(), getHeight(), TRUE);
  26399. #elif JUCE_LINUX
  26400. if (pluginWindow != 0)
  26401. {
  26402. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26403. XMoveWindow (display, pluginWindow, pos.getX(), pos.getY());
  26404. XMapRaised (display, pluginWindow);
  26405. }
  26406. #endif
  26407. recursiveResize = false;
  26408. }
  26409. }
  26410. void componentVisibilityChanged (Component&)
  26411. {
  26412. const bool isShowingNow = isShowing();
  26413. if (wasShowing != isShowingNow)
  26414. {
  26415. wasShowing = isShowingNow;
  26416. if (isShowingNow)
  26417. openPluginWindow();
  26418. else
  26419. closePluginWindow();
  26420. }
  26421. componentMovedOrResized (true, true);
  26422. }
  26423. void componentPeerChanged()
  26424. {
  26425. closePluginWindow();
  26426. openPluginWindow();
  26427. }
  26428. #endif
  26429. bool keyStateChanged (const bool)
  26430. {
  26431. return pluginWantsKeys;
  26432. }
  26433. bool keyPressed (const KeyPress&)
  26434. {
  26435. return pluginWantsKeys;
  26436. }
  26437. #if JUCE_MAC
  26438. void paint (Graphics& g)
  26439. {
  26440. g.fillAll (Colours::black);
  26441. }
  26442. #else
  26443. void paint (Graphics& g)
  26444. {
  26445. if (isOpen)
  26446. {
  26447. ComponentPeer* const peer = getPeer();
  26448. if (peer != 0)
  26449. {
  26450. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26451. peer->addMaskedRegion (pos.getX(), pos.getY(), getWidth(), getHeight());
  26452. #if JUCE_LINUX
  26453. if (pluginWindow != 0)
  26454. {
  26455. const Rectangle<int> clip (g.getClipBounds());
  26456. XEvent ev;
  26457. zerostruct (ev);
  26458. ev.xexpose.type = Expose;
  26459. ev.xexpose.display = display;
  26460. ev.xexpose.window = pluginWindow;
  26461. ev.xexpose.x = clip.getX();
  26462. ev.xexpose.y = clip.getY();
  26463. ev.xexpose.width = clip.getWidth();
  26464. ev.xexpose.height = clip.getHeight();
  26465. sendEventToChild (&ev);
  26466. }
  26467. #endif
  26468. }
  26469. }
  26470. else
  26471. {
  26472. g.fillAll (Colours::black);
  26473. }
  26474. }
  26475. #endif
  26476. void timerCallback()
  26477. {
  26478. #if JUCE_WIN32
  26479. if (--sizeCheckCount <= 0)
  26480. {
  26481. sizeCheckCount = 10;
  26482. checkPluginWindowSize();
  26483. }
  26484. #endif
  26485. try
  26486. {
  26487. static bool reentrant = false;
  26488. if (! reentrant)
  26489. {
  26490. reentrant = true;
  26491. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26492. reentrant = false;
  26493. }
  26494. }
  26495. catch (...)
  26496. {}
  26497. }
  26498. void mouseDown (const MouseEvent& e)
  26499. {
  26500. #if JUCE_LINUX
  26501. if (pluginWindow == 0)
  26502. return;
  26503. toFront (true);
  26504. XEvent ev;
  26505. zerostruct (ev);
  26506. ev.xbutton.display = display;
  26507. ev.xbutton.type = ButtonPress;
  26508. ev.xbutton.window = pluginWindow;
  26509. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26510. ev.xbutton.time = CurrentTime;
  26511. ev.xbutton.x = e.x;
  26512. ev.xbutton.y = e.y;
  26513. ev.xbutton.x_root = e.getScreenX();
  26514. ev.xbutton.y_root = e.getScreenY();
  26515. translateJuceToXButtonModifiers (e, ev);
  26516. sendEventToChild (&ev);
  26517. #elif JUCE_WIN32
  26518. (void) e;
  26519. toFront (true);
  26520. #endif
  26521. }
  26522. void broughtToFront()
  26523. {
  26524. activeVSTWindows.removeValue (this);
  26525. activeVSTWindows.add (this);
  26526. #if JUCE_MAC
  26527. dispatch (effEditTop, 0, 0, 0, 0);
  26528. #endif
  26529. }
  26530. juce_UseDebuggingNewOperator
  26531. private:
  26532. VSTPluginInstance& plugin;
  26533. bool isOpen, wasShowing, recursiveResize;
  26534. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26535. #if JUCE_WIN32
  26536. HWND pluginHWND;
  26537. void* originalWndProc;
  26538. int sizeCheckCount;
  26539. #elif JUCE_LINUX
  26540. Window pluginWindow;
  26541. EventProcPtr pluginProc;
  26542. #endif
  26543. #if JUCE_MAC
  26544. void openPluginWindow (WindowRef parentWindow)
  26545. {
  26546. if (isOpen || parentWindow == 0)
  26547. return;
  26548. isOpen = true;
  26549. ERect* rect = 0;
  26550. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26551. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26552. // do this before and after like in the steinberg example
  26553. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26554. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26555. // Install keyboard hooks
  26556. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26557. // double-check it's not too tiny
  26558. int w = 250, h = 150;
  26559. if (rect != 0)
  26560. {
  26561. w = rect->right - rect->left;
  26562. h = rect->bottom - rect->top;
  26563. if (w == 0 || h == 0)
  26564. {
  26565. w = 250;
  26566. h = 150;
  26567. }
  26568. }
  26569. w = jmax (w, 32);
  26570. h = jmax (h, 32);
  26571. setSize (w, h);
  26572. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26573. repaint();
  26574. }
  26575. #else
  26576. void openPluginWindow()
  26577. {
  26578. if (isOpen || getWindowHandle() == 0)
  26579. return;
  26580. log (T("Opening VST UI: ") + plugin.name);
  26581. isOpen = true;
  26582. ERect* rect = 0;
  26583. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26584. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26585. // do this before and after like in the steinberg example
  26586. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26587. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26588. // Install keyboard hooks
  26589. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26590. #if JUCE_WIN32
  26591. originalWndProc = 0;
  26592. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26593. if (pluginHWND == 0)
  26594. {
  26595. isOpen = false;
  26596. setSize (300, 150);
  26597. return;
  26598. }
  26599. #pragma warning (push)
  26600. #pragma warning (disable: 4244)
  26601. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26602. if (! pluginWantsKeys)
  26603. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) vstHookWndProc);
  26604. #pragma warning (pop)
  26605. int w, h;
  26606. RECT r;
  26607. GetWindowRect (pluginHWND, &r);
  26608. w = r.right - r.left;
  26609. h = r.bottom - r.top;
  26610. if (rect != 0)
  26611. {
  26612. const int rw = rect->right - rect->left;
  26613. const int rh = rect->bottom - rect->top;
  26614. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26615. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26616. {
  26617. // very dodgy logic to decide which size is right.
  26618. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26619. {
  26620. SetWindowPos (pluginHWND, 0,
  26621. 0, 0, rw, rh,
  26622. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26623. GetWindowRect (pluginHWND, &r);
  26624. w = r.right - r.left;
  26625. h = r.bottom - r.top;
  26626. pluginRefusesToResize = (w != rw) || (h != rh);
  26627. w = rw;
  26628. h = rh;
  26629. }
  26630. }
  26631. }
  26632. #elif JUCE_LINUX
  26633. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26634. if (pluginWindow != 0)
  26635. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26636. XInternAtom (display, "_XEventProc", False));
  26637. int w = 250, h = 150;
  26638. if (rect != 0)
  26639. {
  26640. w = rect->right - rect->left;
  26641. h = rect->bottom - rect->top;
  26642. if (w == 0 || h == 0)
  26643. {
  26644. w = 250;
  26645. h = 150;
  26646. }
  26647. }
  26648. if (pluginWindow != 0)
  26649. XMapRaised (display, pluginWindow);
  26650. #endif
  26651. // double-check it's not too tiny
  26652. w = jmax (w, 32);
  26653. h = jmax (h, 32);
  26654. setSize (w, h);
  26655. #if JUCE_WIN32
  26656. checkPluginWindowSize();
  26657. #endif
  26658. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26659. repaint();
  26660. }
  26661. #endif
  26662. #if ! JUCE_MAC
  26663. void closePluginWindow()
  26664. {
  26665. if (isOpen)
  26666. {
  26667. log (T("Closing VST UI: ") + plugin.getName());
  26668. isOpen = false;
  26669. dispatch (effEditClose, 0, 0, 0, 0);
  26670. #if JUCE_WIN32
  26671. #pragma warning (push)
  26672. #pragma warning (disable: 4244)
  26673. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26674. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) originalWndProc);
  26675. #pragma warning (pop)
  26676. stopTimer();
  26677. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26678. DestroyWindow (pluginHWND);
  26679. pluginHWND = 0;
  26680. #elif JUCE_LINUX
  26681. stopTimer();
  26682. pluginWindow = 0;
  26683. pluginProc = 0;
  26684. #endif
  26685. }
  26686. }
  26687. #endif
  26688. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26689. {
  26690. return plugin.dispatch (opcode, index, value, ptr, opt);
  26691. }
  26692. #if JUCE_WIN32
  26693. void checkPluginWindowSize() throw()
  26694. {
  26695. RECT r;
  26696. GetWindowRect (pluginHWND, &r);
  26697. const int w = r.right - r.left;
  26698. const int h = r.bottom - r.top;
  26699. if (isShowing() && w > 0 && h > 0
  26700. && (w != getWidth() || h != getHeight())
  26701. && ! pluginRefusesToResize)
  26702. {
  26703. setSize (w, h);
  26704. sizeCheckCount = 0;
  26705. }
  26706. }
  26707. // hooks to get keyboard events from VST windows..
  26708. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26709. {
  26710. for (int i = activeVSTWindows.size(); --i >= 0;)
  26711. {
  26712. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26713. if (w->pluginHWND == hW)
  26714. {
  26715. if (message == WM_CHAR
  26716. || message == WM_KEYDOWN
  26717. || message == WM_SYSKEYDOWN
  26718. || message == WM_KEYUP
  26719. || message == WM_SYSKEYUP
  26720. || message == WM_APPCOMMAND)
  26721. {
  26722. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26723. message, wParam, lParam);
  26724. }
  26725. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26726. (HWND) w->pluginHWND,
  26727. message,
  26728. wParam,
  26729. lParam);
  26730. }
  26731. }
  26732. return DefWindowProc (hW, message, wParam, lParam);
  26733. }
  26734. #endif
  26735. #if JUCE_LINUX
  26736. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26737. void sendEventToChild (XEvent* event)
  26738. {
  26739. if (pluginProc != 0)
  26740. {
  26741. // if the plugin publishes an event procedure, pass the event directly..
  26742. pluginProc (event);
  26743. }
  26744. else if (pluginWindow != 0)
  26745. {
  26746. // if the plugin has a window, then send the event to the window so that
  26747. // its message thread will pick it up..
  26748. XSendEvent (display, pluginWindow, False, 0L, event);
  26749. XFlush (display);
  26750. }
  26751. }
  26752. void mouseEnter (const MouseEvent& e)
  26753. {
  26754. if (pluginWindow != 0)
  26755. {
  26756. XEvent ev;
  26757. zerostruct (ev);
  26758. ev.xcrossing.display = display;
  26759. ev.xcrossing.type = EnterNotify;
  26760. ev.xcrossing.window = pluginWindow;
  26761. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26762. ev.xcrossing.time = CurrentTime;
  26763. ev.xcrossing.x = e.x;
  26764. ev.xcrossing.y = e.y;
  26765. ev.xcrossing.x_root = e.getScreenX();
  26766. ev.xcrossing.y_root = e.getScreenY();
  26767. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26768. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26769. translateJuceToXCrossingModifiers (e, ev);
  26770. sendEventToChild (&ev);
  26771. }
  26772. }
  26773. void mouseExit (const MouseEvent& e)
  26774. {
  26775. if (pluginWindow != 0)
  26776. {
  26777. XEvent ev;
  26778. zerostruct (ev);
  26779. ev.xcrossing.display = display;
  26780. ev.xcrossing.type = LeaveNotify;
  26781. ev.xcrossing.window = pluginWindow;
  26782. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26783. ev.xcrossing.time = CurrentTime;
  26784. ev.xcrossing.x = e.x;
  26785. ev.xcrossing.y = e.y;
  26786. ev.xcrossing.x_root = e.getScreenX();
  26787. ev.xcrossing.y_root = e.getScreenY();
  26788. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26789. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26790. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26791. translateJuceToXCrossingModifiers (e, ev);
  26792. sendEventToChild (&ev);
  26793. }
  26794. }
  26795. void mouseMove (const MouseEvent& e)
  26796. {
  26797. if (pluginWindow != 0)
  26798. {
  26799. XEvent ev;
  26800. zerostruct (ev);
  26801. ev.xmotion.display = display;
  26802. ev.xmotion.type = MotionNotify;
  26803. ev.xmotion.window = pluginWindow;
  26804. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26805. ev.xmotion.time = CurrentTime;
  26806. ev.xmotion.is_hint = NotifyNormal;
  26807. ev.xmotion.x = e.x;
  26808. ev.xmotion.y = e.y;
  26809. ev.xmotion.x_root = e.getScreenX();
  26810. ev.xmotion.y_root = e.getScreenY();
  26811. sendEventToChild (&ev);
  26812. }
  26813. }
  26814. void mouseDrag (const MouseEvent& e)
  26815. {
  26816. if (pluginWindow != 0)
  26817. {
  26818. XEvent ev;
  26819. zerostruct (ev);
  26820. ev.xmotion.display = display;
  26821. ev.xmotion.type = MotionNotify;
  26822. ev.xmotion.window = pluginWindow;
  26823. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26824. ev.xmotion.time = CurrentTime;
  26825. ev.xmotion.x = e.x ;
  26826. ev.xmotion.y = e.y;
  26827. ev.xmotion.x_root = e.getScreenX();
  26828. ev.xmotion.y_root = e.getScreenY();
  26829. ev.xmotion.is_hint = NotifyNormal;
  26830. translateJuceToXMotionModifiers (e, ev);
  26831. sendEventToChild (&ev);
  26832. }
  26833. }
  26834. void mouseUp (const MouseEvent& e)
  26835. {
  26836. if (pluginWindow != 0)
  26837. {
  26838. XEvent ev;
  26839. zerostruct (ev);
  26840. ev.xbutton.display = display;
  26841. ev.xbutton.type = ButtonRelease;
  26842. ev.xbutton.window = pluginWindow;
  26843. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26844. ev.xbutton.time = CurrentTime;
  26845. ev.xbutton.x = e.x;
  26846. ev.xbutton.y = e.y;
  26847. ev.xbutton.x_root = e.getScreenX();
  26848. ev.xbutton.y_root = e.getScreenY();
  26849. translateJuceToXButtonModifiers (e, ev);
  26850. sendEventToChild (&ev);
  26851. }
  26852. }
  26853. void mouseWheelMove (const MouseEvent& e,
  26854. float incrementX,
  26855. float incrementY)
  26856. {
  26857. if (pluginWindow != 0)
  26858. {
  26859. XEvent ev;
  26860. zerostruct (ev);
  26861. ev.xbutton.display = display;
  26862. ev.xbutton.type = ButtonPress;
  26863. ev.xbutton.window = pluginWindow;
  26864. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26865. ev.xbutton.time = CurrentTime;
  26866. ev.xbutton.x = e.x;
  26867. ev.xbutton.y = e.y;
  26868. ev.xbutton.x_root = e.getScreenX();
  26869. ev.xbutton.y_root = e.getScreenY();
  26870. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26871. sendEventToChild (&ev);
  26872. // TODO - put a usleep here ?
  26873. ev.xbutton.type = ButtonRelease;
  26874. sendEventToChild (&ev);
  26875. }
  26876. }
  26877. #endif
  26878. #if JUCE_MAC
  26879. #if ! JUCE_SUPPORT_CARBON
  26880. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26881. #endif
  26882. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26883. {
  26884. public:
  26885. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26886. : owner (owner_),
  26887. alreadyInside (false)
  26888. {
  26889. }
  26890. ~InnerWrapperComponent()
  26891. {
  26892. deleteWindow();
  26893. }
  26894. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26895. {
  26896. owner->openPluginWindow (windowRef);
  26897. return 0;
  26898. }
  26899. void removeView (HIViewRef)
  26900. {
  26901. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26902. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26903. }
  26904. bool getEmbeddedViewSize (int& w, int& h)
  26905. {
  26906. ERect* rect = 0;
  26907. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26908. w = rect->right - rect->left;
  26909. h = rect->bottom - rect->top;
  26910. return true;
  26911. }
  26912. void mouseDown (int x, int y)
  26913. {
  26914. if (! alreadyInside)
  26915. {
  26916. alreadyInside = true;
  26917. getTopLevelComponent()->toFront (true);
  26918. owner->dispatch (effEditMouse, x, y, 0, 0);
  26919. alreadyInside = false;
  26920. }
  26921. else
  26922. {
  26923. PostEvent (::mouseDown, 0);
  26924. }
  26925. }
  26926. void paint()
  26927. {
  26928. ComponentPeer* const peer = getPeer();
  26929. if (peer != 0)
  26930. {
  26931. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26932. ERect r;
  26933. r.left = pos.getX();
  26934. r.right = r.left + getWidth();
  26935. r.top = pos.getY();
  26936. r.bottom = r.top + getHeight();
  26937. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26938. }
  26939. }
  26940. private:
  26941. VSTPluginWindow* const owner;
  26942. bool alreadyInside;
  26943. };
  26944. friend class InnerWrapperComponent;
  26945. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26946. void resized()
  26947. {
  26948. innerWrapper->setSize (getWidth(), getHeight());
  26949. }
  26950. #endif
  26951. };
  26952. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26953. {
  26954. if (hasEditor())
  26955. return new VSTPluginWindow (*this);
  26956. return 0;
  26957. }
  26958. void VSTPluginInstance::handleAsyncUpdate()
  26959. {
  26960. // indicates that something about the plugin has changed..
  26961. updateHostDisplay();
  26962. }
  26963. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  26964. {
  26965. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  26966. {
  26967. changeProgramName (getCurrentProgram(), prog->prgName);
  26968. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26969. setParameter (i, vst_swapFloat (prog->params[i]));
  26970. return true;
  26971. }
  26972. return false;
  26973. }
  26974. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  26975. const int dataSize)
  26976. {
  26977. if (dataSize < 28)
  26978. return false;
  26979. const fxSet* const set = (const fxSet*) data;
  26980. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  26981. || vst_swap (set->version) > fxbVersionNum)
  26982. return false;
  26983. if (vst_swap (set->fxMagic) == 'FxBk')
  26984. {
  26985. // bank of programs
  26986. if (vst_swap (set->numPrograms) >= 0)
  26987. {
  26988. const int oldProg = getCurrentProgram();
  26989. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  26990. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26991. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  26992. {
  26993. if (i != oldProg)
  26994. {
  26995. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  26996. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26997. return false;
  26998. if (vst_swap (set->numPrograms) > 0)
  26999. setCurrentProgram (i);
  27000. if (! restoreProgramSettings (prog))
  27001. return false;
  27002. }
  27003. }
  27004. if (vst_swap (set->numPrograms) > 0)
  27005. setCurrentProgram (oldProg);
  27006. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  27007. if (((const char*) prog) - ((const char*) set) >= dataSize)
  27008. return false;
  27009. if (! restoreProgramSettings (prog))
  27010. return false;
  27011. }
  27012. }
  27013. else if (vst_swap (set->fxMagic) == 'FxCk')
  27014. {
  27015. // single program
  27016. const fxProgram* const prog = (const fxProgram*) data;
  27017. if (vst_swap (prog->chunkMagic) != 'CcnK')
  27018. return false;
  27019. changeProgramName (getCurrentProgram(), prog->prgName);
  27020. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  27021. setParameter (i, vst_swapFloat (prog->params[i]));
  27022. }
  27023. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  27024. {
  27025. // non-preset chunk
  27026. const fxChunkSet* const cset = (const fxChunkSet*) data;
  27027. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  27028. return false;
  27029. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  27030. }
  27031. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  27032. {
  27033. // preset chunk
  27034. const fxProgramSet* const cset = (const fxProgramSet*) data;
  27035. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  27036. return false;
  27037. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  27038. changeProgramName (getCurrentProgram(), cset->name);
  27039. }
  27040. else
  27041. {
  27042. return false;
  27043. }
  27044. return true;
  27045. }
  27046. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  27047. {
  27048. const int numParams = getNumParameters();
  27049. prog->chunkMagic = vst_swap ('CcnK');
  27050. prog->byteSize = 0;
  27051. prog->fxMagic = vst_swap ('FxCk');
  27052. prog->version = vst_swap (fxbVersionNum);
  27053. prog->fxID = vst_swap (getUID());
  27054. prog->fxVersion = vst_swap (getVersionNumber());
  27055. prog->numParams = vst_swap (numParams);
  27056. getCurrentProgramName().copyToCString (prog->prgName, sizeof (prog->prgName) - 1);
  27057. for (int i = 0; i < numParams; ++i)
  27058. prog->params[i] = vst_swapFloat (getParameter (i));
  27059. }
  27060. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  27061. {
  27062. const int numPrograms = getNumPrograms();
  27063. const int numParams = getNumParameters();
  27064. if (usesChunks())
  27065. {
  27066. if (isFXB)
  27067. {
  27068. MemoryBlock chunk;
  27069. getChunkData (chunk, false, maxSizeMB);
  27070. const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  27071. dest.setSize (totalLen, true);
  27072. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  27073. set->chunkMagic = vst_swap ('CcnK');
  27074. set->byteSize = 0;
  27075. set->fxMagic = vst_swap ('FBCh');
  27076. set->version = vst_swap (fxbVersionNum);
  27077. set->fxID = vst_swap (getUID());
  27078. set->fxVersion = vst_swap (getVersionNumber());
  27079. set->numPrograms = vst_swap (numPrograms);
  27080. set->chunkSize = vst_swap ((long) chunk.getSize());
  27081. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27082. }
  27083. else
  27084. {
  27085. MemoryBlock chunk;
  27086. getChunkData (chunk, true, maxSizeMB);
  27087. const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  27088. dest.setSize (totalLen, true);
  27089. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  27090. set->chunkMagic = vst_swap ('CcnK');
  27091. set->byteSize = 0;
  27092. set->fxMagic = vst_swap ('FPCh');
  27093. set->version = vst_swap (fxbVersionNum);
  27094. set->fxID = vst_swap (getUID());
  27095. set->fxVersion = vst_swap (getVersionNumber());
  27096. set->numPrograms = vst_swap (numPrograms);
  27097. set->chunkSize = vst_swap ((long) chunk.getSize());
  27098. getCurrentProgramName().copyToCString (set->name, sizeof (set->name) - 1);
  27099. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27100. }
  27101. }
  27102. else
  27103. {
  27104. if (isFXB)
  27105. {
  27106. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27107. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  27108. dest.setSize (len, true);
  27109. fxSet* const set = (fxSet*) dest.getData();
  27110. set->chunkMagic = vst_swap ('CcnK');
  27111. set->byteSize = 0;
  27112. set->fxMagic = vst_swap ('FxBk');
  27113. set->version = vst_swap (fxbVersionNum);
  27114. set->fxID = vst_swap (getUID());
  27115. set->fxVersion = vst_swap (getVersionNumber());
  27116. set->numPrograms = vst_swap (numPrograms);
  27117. const int oldProgram = getCurrentProgram();
  27118. MemoryBlock oldSettings;
  27119. createTempParameterStore (oldSettings);
  27120. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  27121. for (int i = 0; i < numPrograms; ++i)
  27122. {
  27123. if (i != oldProgram)
  27124. {
  27125. setCurrentProgram (i);
  27126. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  27127. }
  27128. }
  27129. setCurrentProgram (oldProgram);
  27130. restoreFromTempParameterStore (oldSettings);
  27131. }
  27132. else
  27133. {
  27134. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27135. dest.setSize (totalLen, true);
  27136. setParamsInProgramBlock ((fxProgram*) dest.getData());
  27137. }
  27138. }
  27139. return true;
  27140. }
  27141. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  27142. {
  27143. if (usesChunks())
  27144. {
  27145. void* data = 0;
  27146. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  27147. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  27148. {
  27149. mb.setSize (bytes);
  27150. mb.copyFrom (data, 0, bytes);
  27151. }
  27152. }
  27153. }
  27154. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  27155. {
  27156. if (size > 0 && usesChunks())
  27157. {
  27158. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  27159. if (! isPreset)
  27160. updateStoredProgramNames();
  27161. }
  27162. }
  27163. void VSTPluginInstance::timerCallback()
  27164. {
  27165. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  27166. stopTimer();
  27167. }
  27168. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  27169. {
  27170. const ScopedLock sl (lock);
  27171. ++insideVSTCallback;
  27172. int result = 0;
  27173. try
  27174. {
  27175. if (effect != 0)
  27176. {
  27177. #if JUCE_MAC
  27178. if (module->resFileId != 0)
  27179. UseResFile (module->resFileId);
  27180. CGrafPtr oldPort;
  27181. if (getActiveEditor() != 0)
  27182. {
  27183. const Point<int> pos (getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), Point<int>()));
  27184. GetPort (&oldPort);
  27185. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  27186. SetOrigin (-pos.getX(), -pos.getY());
  27187. }
  27188. #endif
  27189. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  27190. #if JUCE_MAC
  27191. if (getActiveEditor() != 0)
  27192. SetPort (oldPort);
  27193. module->resFileId = CurResFile();
  27194. #endif
  27195. --insideVSTCallback;
  27196. return result;
  27197. }
  27198. }
  27199. catch (...)
  27200. {
  27201. }
  27202. --insideVSTCallback;
  27203. return result;
  27204. }
  27205. // handles non plugin-specific callbacks..
  27206. static const int defaultVSTSampleRateValue = 16384;
  27207. static const int defaultVSTBlockSizeValue = 512;
  27208. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27209. {
  27210. (void) index;
  27211. (void) value;
  27212. (void) opt;
  27213. switch (opcode)
  27214. {
  27215. case audioMasterCanDo:
  27216. {
  27217. static const char* canDos[] = { "supplyIdle",
  27218. "sendVstEvents",
  27219. "sendVstMidiEvent",
  27220. "sendVstTimeInfo",
  27221. "receiveVstEvents",
  27222. "receiveVstMidiEvent",
  27223. "supportShell",
  27224. "shellCategory" };
  27225. for (int i = 0; i < numElementsInArray (canDos); ++i)
  27226. if (strcmp (canDos[i], (const char*) ptr) == 0)
  27227. return 1;
  27228. return 0;
  27229. }
  27230. case audioMasterVersion:
  27231. return 0x2400;
  27232. case audioMasterCurrentId:
  27233. return shellUIDToCreate;
  27234. case audioMasterGetNumAutomatableParameters:
  27235. return 0;
  27236. case audioMasterGetAutomationState:
  27237. return 1;
  27238. case audioMasterGetVendorVersion:
  27239. return 0x0101;
  27240. case audioMasterGetVendorString:
  27241. case audioMasterGetProductString:
  27242. {
  27243. String hostName ("Juce VST Host");
  27244. if (JUCEApplication::getInstance() != 0)
  27245. hostName = JUCEApplication::getInstance()->getApplicationName();
  27246. hostName.copyToCString ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  27247. }
  27248. break;
  27249. case audioMasterGetSampleRate:
  27250. return (VstIntPtr) defaultVSTSampleRateValue;
  27251. case audioMasterGetBlockSize:
  27252. return (VstIntPtr) defaultVSTBlockSizeValue;
  27253. case audioMasterSetOutputSampleRate:
  27254. return 0;
  27255. default:
  27256. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  27257. break;
  27258. }
  27259. return 0;
  27260. }
  27261. // handles callbacks for a specific plugin
  27262. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27263. {
  27264. switch (opcode)
  27265. {
  27266. case audioMasterAutomate:
  27267. sendParamChangeMessageToListeners (index, opt);
  27268. break;
  27269. case audioMasterProcessEvents:
  27270. handleMidiFromPlugin ((const VstEvents*) ptr);
  27271. break;
  27272. case audioMasterGetTime:
  27273. #ifdef _MSC_VER
  27274. #pragma warning (push)
  27275. #pragma warning (disable: 4311)
  27276. #endif
  27277. return (VstIntPtr) &vstHostTime;
  27278. #ifdef _MSC_VER
  27279. #pragma warning (pop)
  27280. #endif
  27281. break;
  27282. case audioMasterIdle:
  27283. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  27284. {
  27285. ++insideVSTCallback;
  27286. #if JUCE_MAC
  27287. if (getActiveEditor() != 0)
  27288. dispatch (effEditIdle, 0, 0, 0, 0);
  27289. #endif
  27290. juce_callAnyTimersSynchronously();
  27291. handleUpdateNowIfNeeded();
  27292. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  27293. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  27294. --insideVSTCallback;
  27295. }
  27296. break;
  27297. case audioMasterUpdateDisplay:
  27298. triggerAsyncUpdate();
  27299. break;
  27300. case audioMasterTempoAt:
  27301. // returns (10000 * bpm)
  27302. break;
  27303. case audioMasterNeedIdle:
  27304. startTimer (50);
  27305. break;
  27306. case audioMasterSizeWindow:
  27307. if (getActiveEditor() != 0)
  27308. getActiveEditor()->setSize (index, value);
  27309. return 1;
  27310. case audioMasterGetSampleRate:
  27311. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27312. case audioMasterGetBlockSize:
  27313. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27314. case audioMasterWantMidi:
  27315. wantsMidiMessages = true;
  27316. break;
  27317. case audioMasterGetDirectory:
  27318. #if JUCE_MAC
  27319. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27320. #else
  27321. return (VstIntPtr) (pointer_sized_uint) module->fullParentDirectoryPathName.toUTF8();
  27322. #endif
  27323. case audioMasterGetAutomationState:
  27324. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27325. break;
  27326. // none of these are handled (yet)..
  27327. case audioMasterBeginEdit:
  27328. case audioMasterEndEdit:
  27329. case audioMasterSetTime:
  27330. case audioMasterPinConnected:
  27331. case audioMasterGetParameterQuantization:
  27332. case audioMasterIOChanged:
  27333. case audioMasterGetInputLatency:
  27334. case audioMasterGetOutputLatency:
  27335. case audioMasterGetPreviousPlug:
  27336. case audioMasterGetNextPlug:
  27337. case audioMasterWillReplaceOrAccumulate:
  27338. case audioMasterGetCurrentProcessLevel:
  27339. case audioMasterOfflineStart:
  27340. case audioMasterOfflineRead:
  27341. case audioMasterOfflineWrite:
  27342. case audioMasterOfflineGetCurrentPass:
  27343. case audioMasterOfflineGetCurrentMetaPass:
  27344. case audioMasterVendorSpecific:
  27345. case audioMasterSetIcon:
  27346. case audioMasterGetLanguage:
  27347. case audioMasterOpenWindow:
  27348. case audioMasterCloseWindow:
  27349. break;
  27350. default:
  27351. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27352. }
  27353. return 0;
  27354. }
  27355. // entry point for all callbacks from the plugin
  27356. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27357. {
  27358. try
  27359. {
  27360. if (effect != 0 && effect->resvd2 != 0)
  27361. {
  27362. return ((VSTPluginInstance*)(effect->resvd2))
  27363. ->handleCallback (opcode, index, value, ptr, opt);
  27364. }
  27365. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27366. }
  27367. catch (...)
  27368. {
  27369. return 0;
  27370. }
  27371. }
  27372. const String VSTPluginInstance::getVersion() const throw()
  27373. {
  27374. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27375. String s;
  27376. if (v == 0 || v == -1)
  27377. v = getVersionNumber();
  27378. if (v != 0)
  27379. {
  27380. int versionBits[4];
  27381. int n = 0;
  27382. while (v != 0)
  27383. {
  27384. versionBits [n++] = (v & 0xff);
  27385. v >>= 8;
  27386. }
  27387. s << 'V';
  27388. while (n > 0)
  27389. {
  27390. s << versionBits [--n];
  27391. if (n > 0)
  27392. s << '.';
  27393. }
  27394. }
  27395. return s;
  27396. }
  27397. int VSTPluginInstance::getUID() const throw()
  27398. {
  27399. int uid = effect != 0 ? effect->uniqueID : 0;
  27400. if (uid == 0)
  27401. uid = module->file.hashCode();
  27402. return uid;
  27403. }
  27404. const String VSTPluginInstance::getCategory() const throw()
  27405. {
  27406. const char* result = 0;
  27407. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27408. {
  27409. case kPlugCategEffect:
  27410. result = "Effect";
  27411. break;
  27412. case kPlugCategSynth:
  27413. result = "Synth";
  27414. break;
  27415. case kPlugCategAnalysis:
  27416. result = "Anaylsis";
  27417. break;
  27418. case kPlugCategMastering:
  27419. result = "Mastering";
  27420. break;
  27421. case kPlugCategSpacializer:
  27422. result = "Spacial";
  27423. break;
  27424. case kPlugCategRoomFx:
  27425. result = "Reverb";
  27426. break;
  27427. case kPlugSurroundFx:
  27428. result = "Surround";
  27429. break;
  27430. case kPlugCategRestoration:
  27431. result = "Restoration";
  27432. break;
  27433. case kPlugCategGenerator:
  27434. result = "Tone generation";
  27435. break;
  27436. default:
  27437. break;
  27438. }
  27439. return result;
  27440. }
  27441. float VSTPluginInstance::getParameter (int index)
  27442. {
  27443. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27444. {
  27445. try
  27446. {
  27447. const ScopedLock sl (lock);
  27448. return effect->getParameter (effect, index);
  27449. }
  27450. catch (...)
  27451. {
  27452. }
  27453. }
  27454. return 0.0f;
  27455. }
  27456. void VSTPluginInstance::setParameter (int index, float newValue)
  27457. {
  27458. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27459. {
  27460. try
  27461. {
  27462. const ScopedLock sl (lock);
  27463. if (effect->getParameter (effect, index) != newValue)
  27464. effect->setParameter (effect, index, newValue);
  27465. }
  27466. catch (...)
  27467. {
  27468. }
  27469. }
  27470. }
  27471. const String VSTPluginInstance::getParameterName (int index)
  27472. {
  27473. if (effect != 0)
  27474. {
  27475. jassert (index >= 0 && index < effect->numParams);
  27476. char nm [256];
  27477. zerostruct (nm);
  27478. dispatch (effGetParamName, index, 0, nm, 0);
  27479. return String (nm).trim();
  27480. }
  27481. return String::empty;
  27482. }
  27483. const String VSTPluginInstance::getParameterLabel (int index) const
  27484. {
  27485. if (effect != 0)
  27486. {
  27487. jassert (index >= 0 && index < effect->numParams);
  27488. char nm [256];
  27489. zerostruct (nm);
  27490. dispatch (effGetParamLabel, index, 0, nm, 0);
  27491. return String (nm).trim();
  27492. }
  27493. return String::empty;
  27494. }
  27495. const String VSTPluginInstance::getParameterText (int index)
  27496. {
  27497. if (effect != 0)
  27498. {
  27499. jassert (index >= 0 && index < effect->numParams);
  27500. char nm [256];
  27501. zerostruct (nm);
  27502. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27503. return String (nm).trim();
  27504. }
  27505. return String::empty;
  27506. }
  27507. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27508. {
  27509. if (effect != 0)
  27510. {
  27511. jassert (index >= 0 && index < effect->numParams);
  27512. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27513. }
  27514. return false;
  27515. }
  27516. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27517. {
  27518. dest.setSize (64 + 4 * getNumParameters());
  27519. dest.fillWith (0);
  27520. getCurrentProgramName().copyToCString ((char*) dest.getData(), 63);
  27521. float* const p = (float*) (((char*) dest.getData()) + 64);
  27522. for (int i = 0; i < getNumParameters(); ++i)
  27523. p[i] = getParameter(i);
  27524. }
  27525. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27526. {
  27527. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27528. float* p = (float*) (((char*) m.getData()) + 64);
  27529. for (int i = 0; i < getNumParameters(); ++i)
  27530. setParameter (i, p[i]);
  27531. }
  27532. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27533. {
  27534. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27535. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27536. }
  27537. const String VSTPluginInstance::getProgramName (int index)
  27538. {
  27539. if (index == getCurrentProgram())
  27540. {
  27541. return getCurrentProgramName();
  27542. }
  27543. else if (effect != 0)
  27544. {
  27545. char nm [256];
  27546. zerostruct (nm);
  27547. if (dispatch (effGetProgramNameIndexed,
  27548. jlimit (0, getNumPrograms(), index),
  27549. -1, nm, 0) != 0)
  27550. {
  27551. return String (nm).trim();
  27552. }
  27553. }
  27554. return programNames [index];
  27555. }
  27556. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27557. {
  27558. if (index == getCurrentProgram())
  27559. {
  27560. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27561. dispatch (effSetProgramName, 0, 0, (void*) newName.substring (0, 24).toCString(), 0.0f);
  27562. }
  27563. else
  27564. {
  27565. jassertfalse // xxx not implemented!
  27566. }
  27567. }
  27568. void VSTPluginInstance::updateStoredProgramNames()
  27569. {
  27570. if (effect != 0 && getNumPrograms() > 0)
  27571. {
  27572. char nm [256];
  27573. zerostruct (nm);
  27574. // only do this if the plugin can't use indexed names..
  27575. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27576. {
  27577. const int oldProgram = getCurrentProgram();
  27578. MemoryBlock oldSettings;
  27579. createTempParameterStore (oldSettings);
  27580. for (int i = 0; i < getNumPrograms(); ++i)
  27581. {
  27582. setCurrentProgram (i);
  27583. getCurrentProgramName(); // (this updates the list)
  27584. }
  27585. setCurrentProgram (oldProgram);
  27586. restoreFromTempParameterStore (oldSettings);
  27587. }
  27588. }
  27589. }
  27590. const String VSTPluginInstance::getCurrentProgramName()
  27591. {
  27592. if (effect != 0)
  27593. {
  27594. char nm [256];
  27595. zerostruct (nm);
  27596. dispatch (effGetProgramName, 0, 0, nm, 0);
  27597. const int index = getCurrentProgram();
  27598. if (programNames[index].isEmpty())
  27599. {
  27600. while (programNames.size() < index)
  27601. programNames.add (String::empty);
  27602. programNames.set (index, String (nm).trim());
  27603. }
  27604. return String (nm).trim();
  27605. }
  27606. return String::empty;
  27607. }
  27608. const String VSTPluginInstance::getInputChannelName (const int index) const
  27609. {
  27610. if (index >= 0 && index < getNumInputChannels())
  27611. {
  27612. VstPinProperties pinProps;
  27613. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27614. return String (pinProps.label, sizeof (pinProps.label));
  27615. }
  27616. return String::empty;
  27617. }
  27618. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27619. {
  27620. if (index < 0 || index >= getNumInputChannels())
  27621. return false;
  27622. VstPinProperties pinProps;
  27623. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27624. return (pinProps.flags & kVstPinIsStereo) != 0;
  27625. return true;
  27626. }
  27627. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27628. {
  27629. if (index >= 0 && index < getNumOutputChannels())
  27630. {
  27631. VstPinProperties pinProps;
  27632. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27633. return String (pinProps.label, sizeof (pinProps.label));
  27634. }
  27635. return String::empty;
  27636. }
  27637. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27638. {
  27639. if (index < 0 || index >= getNumOutputChannels())
  27640. return false;
  27641. VstPinProperties pinProps;
  27642. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27643. return (pinProps.flags & kVstPinIsStereo) != 0;
  27644. return true;
  27645. }
  27646. void VSTPluginInstance::setPower (const bool on)
  27647. {
  27648. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27649. isPowerOn = on;
  27650. }
  27651. const int defaultMaxSizeMB = 64;
  27652. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27653. {
  27654. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27655. }
  27656. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27657. {
  27658. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27659. }
  27660. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27661. {
  27662. loadFromFXBFile (data, sizeInBytes);
  27663. }
  27664. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27665. {
  27666. loadFromFXBFile (data, sizeInBytes);
  27667. }
  27668. VSTPluginFormat::VSTPluginFormat()
  27669. {
  27670. }
  27671. VSTPluginFormat::~VSTPluginFormat()
  27672. {
  27673. }
  27674. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27675. const String& fileOrIdentifier)
  27676. {
  27677. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27678. return;
  27679. PluginDescription desc;
  27680. desc.fileOrIdentifier = fileOrIdentifier;
  27681. desc.uid = 0;
  27682. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27683. if (instance == 0)
  27684. return;
  27685. try
  27686. {
  27687. #if JUCE_MAC
  27688. if (instance->module->resFileId != 0)
  27689. UseResFile (instance->module->resFileId);
  27690. #endif
  27691. instance->fillInPluginDescription (desc);
  27692. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27693. if (category != kPlugCategShell)
  27694. {
  27695. // Normal plugin...
  27696. results.add (new PluginDescription (desc));
  27697. ++insideVSTCallback;
  27698. instance->dispatch (effOpen, 0, 0, 0, 0);
  27699. --insideVSTCallback;
  27700. }
  27701. else
  27702. {
  27703. // It's a shell plugin, so iterate all the subtypes...
  27704. char shellEffectName [64];
  27705. for (;;)
  27706. {
  27707. zerostruct (shellEffectName);
  27708. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27709. if (uid == 0)
  27710. {
  27711. break;
  27712. }
  27713. else
  27714. {
  27715. desc.uid = uid;
  27716. desc.name = shellEffectName;
  27717. bool alreadyThere = false;
  27718. for (int i = results.size(); --i >= 0;)
  27719. {
  27720. PluginDescription* const d = results.getUnchecked(i);
  27721. if (d->isDuplicateOf (desc))
  27722. {
  27723. alreadyThere = true;
  27724. break;
  27725. }
  27726. }
  27727. if (! alreadyThere)
  27728. results.add (new PluginDescription (desc));
  27729. }
  27730. }
  27731. }
  27732. }
  27733. catch (...)
  27734. {
  27735. // crashed while loading...
  27736. }
  27737. }
  27738. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27739. {
  27740. ScopedPointer <VSTPluginInstance> result;
  27741. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27742. {
  27743. File file (desc.fileOrIdentifier);
  27744. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27745. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27746. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27747. if (module != 0)
  27748. {
  27749. shellUIDToCreate = desc.uid;
  27750. result = new VSTPluginInstance (module);
  27751. if (result->effect != 0)
  27752. {
  27753. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27754. result->initialise();
  27755. }
  27756. else
  27757. {
  27758. result = 0;
  27759. }
  27760. }
  27761. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27762. }
  27763. return result.release();
  27764. }
  27765. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27766. {
  27767. const File f (fileOrIdentifier);
  27768. #if JUCE_MAC
  27769. if (f.isDirectory() && f.hasFileExtension (T(".vst")))
  27770. return true;
  27771. #if JUCE_PPC
  27772. FSRef fileRef;
  27773. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27774. {
  27775. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27776. if (resFileId != -1)
  27777. {
  27778. const int numEffects = Count1Resources ('aEff');
  27779. CloseResFile (resFileId);
  27780. if (numEffects > 0)
  27781. return true;
  27782. }
  27783. }
  27784. #endif
  27785. return false;
  27786. #elif JUCE_WIN32
  27787. return f.existsAsFile()
  27788. && f.hasFileExtension (T(".dll"));
  27789. #elif JUCE_LINUX
  27790. return f.existsAsFile()
  27791. && f.hasFileExtension (T(".so"));
  27792. #endif
  27793. }
  27794. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27795. {
  27796. return fileOrIdentifier;
  27797. }
  27798. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27799. {
  27800. return File (desc.fileOrIdentifier).exists();
  27801. }
  27802. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27803. {
  27804. StringArray results;
  27805. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27806. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27807. return results;
  27808. }
  27809. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27810. {
  27811. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27812. // .component or .vst directories.
  27813. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27814. while (iter.next())
  27815. {
  27816. const File f (iter.getFile());
  27817. bool isPlugin = false;
  27818. if (fileMightContainThisPluginType (f.getFullPathName()))
  27819. {
  27820. isPlugin = true;
  27821. results.add (f.getFullPathName());
  27822. }
  27823. if (recursive && (! isPlugin) && f.isDirectory())
  27824. recursiveFileSearch (results, f, true);
  27825. }
  27826. }
  27827. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27828. {
  27829. #if JUCE_MAC
  27830. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27831. #elif JUCE_WIN32
  27832. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27833. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27834. #elif JUCE_LINUX
  27835. return FileSearchPath ("/usr/lib/vst");
  27836. #endif
  27837. }
  27838. END_JUCE_NAMESPACE
  27839. #endif
  27840. #undef log
  27841. #endif
  27842. /*** End of inlined file: juce_VSTPluginFormat.cpp ***/
  27843. /*** End of inlined file: juce_VSTPluginFormat.mm ***/
  27844. /*** Start of inlined file: juce_AudioProcessor.cpp ***/
  27845. BEGIN_JUCE_NAMESPACE
  27846. AudioProcessor::AudioProcessor()
  27847. : playHead (0),
  27848. activeEditor (0),
  27849. sampleRate (0),
  27850. blockSize (0),
  27851. numInputChannels (0),
  27852. numOutputChannels (0),
  27853. latencySamples (0),
  27854. suspended (false),
  27855. nonRealtime (false)
  27856. {
  27857. }
  27858. AudioProcessor::~AudioProcessor()
  27859. {
  27860. // ooh, nasty - the editor should have been deleted before the filter
  27861. // that it refers to is deleted..
  27862. jassert (activeEditor == 0);
  27863. #ifdef JUCE_DEBUG
  27864. // This will fail if you've called beginParameterChangeGesture() for one
  27865. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27866. jassert (changingParams.countNumberOfSetBits() == 0);
  27867. #endif
  27868. }
  27869. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27870. {
  27871. playHead = newPlayHead;
  27872. }
  27873. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27874. {
  27875. const ScopedLock sl (listenerLock);
  27876. listeners.addIfNotAlreadyThere (newListener);
  27877. }
  27878. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27879. {
  27880. const ScopedLock sl (listenerLock);
  27881. listeners.removeValue (listenerToRemove);
  27882. }
  27883. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27884. const int numOuts,
  27885. const double sampleRate_,
  27886. const int blockSize_) throw()
  27887. {
  27888. numInputChannels = numIns;
  27889. numOutputChannels = numOuts;
  27890. sampleRate = sampleRate_;
  27891. blockSize = blockSize_;
  27892. }
  27893. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27894. {
  27895. nonRealtime = nonRealtime_;
  27896. }
  27897. void AudioProcessor::setLatencySamples (const int newLatency)
  27898. {
  27899. if (latencySamples != newLatency)
  27900. {
  27901. latencySamples = newLatency;
  27902. updateHostDisplay();
  27903. }
  27904. }
  27905. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27906. const float newValue)
  27907. {
  27908. setParameter (parameterIndex, newValue);
  27909. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27910. }
  27911. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27912. {
  27913. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27914. for (int i = listeners.size(); --i >= 0;)
  27915. {
  27916. AudioProcessorListener* l;
  27917. {
  27918. const ScopedLock sl (listenerLock);
  27919. l = (AudioProcessorListener*) listeners [i];
  27920. }
  27921. if (l != 0)
  27922. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27923. }
  27924. }
  27925. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27926. {
  27927. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27928. #ifdef JUCE_DEBUG
  27929. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27930. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27931. jassert (! changingParams [parameterIndex]);
  27932. changingParams.setBit (parameterIndex);
  27933. #endif
  27934. for (int i = listeners.size(); --i >= 0;)
  27935. {
  27936. AudioProcessorListener* l;
  27937. {
  27938. const ScopedLock sl (listenerLock);
  27939. l = (AudioProcessorListener*) listeners [i];
  27940. }
  27941. if (l != 0)
  27942. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27943. }
  27944. }
  27945. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27946. {
  27947. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27948. #ifdef JUCE_DEBUG
  27949. // This means you've called endParameterChangeGesture without having previously called
  27950. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27951. // calls matched correctly.
  27952. jassert (changingParams [parameterIndex]);
  27953. changingParams.clearBit (parameterIndex);
  27954. #endif
  27955. for (int i = listeners.size(); --i >= 0;)
  27956. {
  27957. AudioProcessorListener* l;
  27958. {
  27959. const ScopedLock sl (listenerLock);
  27960. l = (AudioProcessorListener*) listeners [i];
  27961. }
  27962. if (l != 0)
  27963. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  27964. }
  27965. }
  27966. void AudioProcessor::updateHostDisplay()
  27967. {
  27968. for (int i = listeners.size(); --i >= 0;)
  27969. {
  27970. AudioProcessorListener* l;
  27971. {
  27972. const ScopedLock sl (listenerLock);
  27973. l = (AudioProcessorListener*) listeners [i];
  27974. }
  27975. if (l != 0)
  27976. l->audioProcessorChanged (this);
  27977. }
  27978. }
  27979. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  27980. {
  27981. return true;
  27982. }
  27983. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  27984. {
  27985. return false;
  27986. }
  27987. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  27988. {
  27989. const ScopedLock sl (callbackLock);
  27990. suspended = shouldBeSuspended;
  27991. }
  27992. void AudioProcessor::reset()
  27993. {
  27994. }
  27995. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  27996. {
  27997. const ScopedLock sl (callbackLock);
  27998. jassert (activeEditor == editor);
  27999. if (activeEditor == editor)
  28000. activeEditor = 0;
  28001. }
  28002. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  28003. {
  28004. if (activeEditor != 0)
  28005. return activeEditor;
  28006. AudioProcessorEditor* const ed = createEditor();
  28007. if (ed != 0)
  28008. {
  28009. // you must give your editor comp a size before returning it..
  28010. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  28011. const ScopedLock sl (callbackLock);
  28012. activeEditor = ed;
  28013. }
  28014. return ed;
  28015. }
  28016. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  28017. {
  28018. getStateInformation (destData);
  28019. }
  28020. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  28021. {
  28022. setStateInformation (data, sizeInBytes);
  28023. }
  28024. // magic number to identify memory blocks that we've stored as XML
  28025. const uint32 magicXmlNumber = 0x21324356;
  28026. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  28027. JUCE_NAMESPACE::MemoryBlock& destData)
  28028. {
  28029. const String xmlString (xml.createDocument (String::empty, true, false));
  28030. const int stringLength = xmlString.getNumBytesAsUTF8();
  28031. destData.setSize (stringLength + 10);
  28032. char* const d = (char*) destData.getData();
  28033. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  28034. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  28035. xmlString.copyToUTF8 (d + 8, stringLength + 1);
  28036. }
  28037. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  28038. const int sizeInBytes)
  28039. {
  28040. if (sizeInBytes > 8
  28041. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  28042. {
  28043. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  28044. if (stringLength > 0)
  28045. {
  28046. XmlDocument doc (String::fromUTF8 (((const char*) data) + 8,
  28047. jmin ((sizeInBytes - 8), stringLength)));
  28048. return doc.getDocumentElement();
  28049. }
  28050. }
  28051. return 0;
  28052. }
  28053. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  28054. {
  28055. }
  28056. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  28057. {
  28058. }
  28059. END_JUCE_NAMESPACE
  28060. /*** End of inlined file: juce_AudioProcessor.cpp ***/
  28061. /*** Start of inlined file: juce_AudioProcessorEditor.cpp ***/
  28062. BEGIN_JUCE_NAMESPACE
  28063. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  28064. : owner (owner_)
  28065. {
  28066. // the filter must be valid..
  28067. jassert (owner != 0);
  28068. }
  28069. AudioProcessorEditor::~AudioProcessorEditor()
  28070. {
  28071. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  28072. // filter for some reason..
  28073. jassert (owner->getActiveEditor() != this);
  28074. }
  28075. END_JUCE_NAMESPACE
  28076. /*** End of inlined file: juce_AudioProcessorEditor.cpp ***/
  28077. /*** Start of inlined file: juce_AudioProcessorGraph.cpp ***/
  28078. BEGIN_JUCE_NAMESPACE
  28079. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  28080. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  28081. : id (id_),
  28082. processor (processor_),
  28083. isPrepared (false)
  28084. {
  28085. jassert (processor_ != 0);
  28086. }
  28087. AudioProcessorGraph::Node::~Node()
  28088. {
  28089. delete processor;
  28090. }
  28091. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  28092. AudioProcessorGraph* const graph)
  28093. {
  28094. if (! isPrepared)
  28095. {
  28096. isPrepared = true;
  28097. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28098. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  28099. if (ioProc != 0)
  28100. ioProc->setParentGraph (graph);
  28101. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  28102. processor->getNumOutputChannels(),
  28103. sampleRate, blockSize);
  28104. processor->prepareToPlay (sampleRate, blockSize);
  28105. }
  28106. }
  28107. void AudioProcessorGraph::Node::unprepare()
  28108. {
  28109. if (isPrepared)
  28110. {
  28111. isPrepared = false;
  28112. processor->releaseResources();
  28113. }
  28114. }
  28115. AudioProcessorGraph::AudioProcessorGraph()
  28116. : lastNodeId (0),
  28117. renderingBuffers (1, 1),
  28118. currentAudioOutputBuffer (1, 1)
  28119. {
  28120. }
  28121. AudioProcessorGraph::~AudioProcessorGraph()
  28122. {
  28123. clearRenderingSequence();
  28124. clear();
  28125. }
  28126. const String AudioProcessorGraph::getName() const
  28127. {
  28128. return "Audio Graph";
  28129. }
  28130. void AudioProcessorGraph::clear()
  28131. {
  28132. nodes.clear();
  28133. connections.clear();
  28134. triggerAsyncUpdate();
  28135. }
  28136. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  28137. {
  28138. for (int i = nodes.size(); --i >= 0;)
  28139. if (nodes.getUnchecked(i)->id == nodeId)
  28140. return nodes.getUnchecked(i);
  28141. return 0;
  28142. }
  28143. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  28144. uint32 nodeId)
  28145. {
  28146. if (newProcessor == 0)
  28147. {
  28148. jassertfalse
  28149. return 0;
  28150. }
  28151. if (nodeId == 0)
  28152. {
  28153. nodeId = ++lastNodeId;
  28154. }
  28155. else
  28156. {
  28157. // you can't add a node with an id that already exists in the graph..
  28158. jassert (getNodeForId (nodeId) == 0);
  28159. removeNode (nodeId);
  28160. }
  28161. lastNodeId = nodeId;
  28162. Node* const n = new Node (nodeId, newProcessor);
  28163. nodes.add (n);
  28164. triggerAsyncUpdate();
  28165. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28166. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  28167. if (ioProc != 0)
  28168. ioProc->setParentGraph (this);
  28169. return n;
  28170. }
  28171. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  28172. {
  28173. disconnectNode (nodeId);
  28174. for (int i = nodes.size(); --i >= 0;)
  28175. {
  28176. if (nodes.getUnchecked(i)->id == nodeId)
  28177. {
  28178. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28179. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  28180. if (ioProc != 0)
  28181. ioProc->setParentGraph (0);
  28182. nodes.remove (i);
  28183. triggerAsyncUpdate();
  28184. return true;
  28185. }
  28186. }
  28187. return false;
  28188. }
  28189. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  28190. const int sourceChannelIndex,
  28191. const uint32 destNodeId,
  28192. const int destChannelIndex) const
  28193. {
  28194. for (int i = connections.size(); --i >= 0;)
  28195. {
  28196. const Connection* const c = connections.getUnchecked(i);
  28197. if (c->sourceNodeId == sourceNodeId
  28198. && c->destNodeId == destNodeId
  28199. && c->sourceChannelIndex == sourceChannelIndex
  28200. && c->destChannelIndex == destChannelIndex)
  28201. {
  28202. return c;
  28203. }
  28204. }
  28205. return 0;
  28206. }
  28207. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  28208. const uint32 possibleDestNodeId) const
  28209. {
  28210. for (int i = connections.size(); --i >= 0;)
  28211. {
  28212. const Connection* const c = connections.getUnchecked(i);
  28213. if (c->sourceNodeId == possibleSourceNodeId
  28214. && c->destNodeId == possibleDestNodeId)
  28215. {
  28216. return true;
  28217. }
  28218. }
  28219. return false;
  28220. }
  28221. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  28222. const int sourceChannelIndex,
  28223. const uint32 destNodeId,
  28224. const int destChannelIndex) const
  28225. {
  28226. if (sourceChannelIndex < 0
  28227. || destChannelIndex < 0
  28228. || sourceNodeId == destNodeId
  28229. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  28230. return false;
  28231. const Node* const source = getNodeForId (sourceNodeId);
  28232. if (source == 0
  28233. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  28234. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  28235. return false;
  28236. const Node* const dest = getNodeForId (destNodeId);
  28237. if (dest == 0
  28238. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  28239. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  28240. return false;
  28241. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  28242. destNodeId, destChannelIndex) == 0;
  28243. }
  28244. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  28245. const int sourceChannelIndex,
  28246. const uint32 destNodeId,
  28247. const int destChannelIndex)
  28248. {
  28249. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  28250. return false;
  28251. Connection* const c = new Connection();
  28252. c->sourceNodeId = sourceNodeId;
  28253. c->sourceChannelIndex = sourceChannelIndex;
  28254. c->destNodeId = destNodeId;
  28255. c->destChannelIndex = destChannelIndex;
  28256. connections.add (c);
  28257. triggerAsyncUpdate();
  28258. return true;
  28259. }
  28260. void AudioProcessorGraph::removeConnection (const int index)
  28261. {
  28262. connections.remove (index);
  28263. triggerAsyncUpdate();
  28264. }
  28265. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  28266. const uint32 destNodeId, const int destChannelIndex)
  28267. {
  28268. bool doneAnything = false;
  28269. for (int i = connections.size(); --i >= 0;)
  28270. {
  28271. const Connection* const c = connections.getUnchecked(i);
  28272. if (c->sourceNodeId == sourceNodeId
  28273. && c->destNodeId == destNodeId
  28274. && c->sourceChannelIndex == sourceChannelIndex
  28275. && c->destChannelIndex == destChannelIndex)
  28276. {
  28277. removeConnection (i);
  28278. doneAnything = true;
  28279. triggerAsyncUpdate();
  28280. }
  28281. }
  28282. return doneAnything;
  28283. }
  28284. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28285. {
  28286. bool doneAnything = false;
  28287. for (int i = connections.size(); --i >= 0;)
  28288. {
  28289. const Connection* const c = connections.getUnchecked(i);
  28290. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28291. {
  28292. removeConnection (i);
  28293. doneAnything = true;
  28294. triggerAsyncUpdate();
  28295. }
  28296. }
  28297. return doneAnything;
  28298. }
  28299. bool AudioProcessorGraph::removeIllegalConnections()
  28300. {
  28301. bool doneAnything = false;
  28302. for (int i = connections.size(); --i >= 0;)
  28303. {
  28304. const Connection* const c = connections.getUnchecked(i);
  28305. const Node* const source = getNodeForId (c->sourceNodeId);
  28306. const Node* const dest = getNodeForId (c->destNodeId);
  28307. if (source == 0 || dest == 0
  28308. || (c->sourceChannelIndex != midiChannelIndex
  28309. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28310. || (c->sourceChannelIndex == midiChannelIndex
  28311. && ! source->processor->producesMidi())
  28312. || (c->destChannelIndex != midiChannelIndex
  28313. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28314. || (c->destChannelIndex == midiChannelIndex
  28315. && ! dest->processor->acceptsMidi()))
  28316. {
  28317. removeConnection (i);
  28318. doneAnything = true;
  28319. triggerAsyncUpdate();
  28320. }
  28321. }
  28322. return doneAnything;
  28323. }
  28324. namespace GraphRenderingOps
  28325. {
  28326. class AudioGraphRenderingOp
  28327. {
  28328. public:
  28329. AudioGraphRenderingOp() {}
  28330. virtual ~AudioGraphRenderingOp() {}
  28331. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28332. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28333. const int numSamples) = 0;
  28334. juce_UseDebuggingNewOperator
  28335. };
  28336. class ClearChannelOp : public AudioGraphRenderingOp
  28337. {
  28338. public:
  28339. ClearChannelOp (const int channelNum_)
  28340. : channelNum (channelNum_)
  28341. {}
  28342. ~ClearChannelOp() {}
  28343. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28344. {
  28345. sharedBufferChans.clear (channelNum, 0, numSamples);
  28346. }
  28347. private:
  28348. const int channelNum;
  28349. ClearChannelOp (const ClearChannelOp&);
  28350. ClearChannelOp& operator= (const ClearChannelOp&);
  28351. };
  28352. class CopyChannelOp : public AudioGraphRenderingOp
  28353. {
  28354. public:
  28355. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28356. : srcChannelNum (srcChannelNum_),
  28357. dstChannelNum (dstChannelNum_)
  28358. {}
  28359. ~CopyChannelOp() {}
  28360. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28361. {
  28362. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28363. }
  28364. private:
  28365. const int srcChannelNum, dstChannelNum;
  28366. CopyChannelOp (const CopyChannelOp&);
  28367. CopyChannelOp& operator= (const CopyChannelOp&);
  28368. };
  28369. class AddChannelOp : public AudioGraphRenderingOp
  28370. {
  28371. public:
  28372. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28373. : srcChannelNum (srcChannelNum_),
  28374. dstChannelNum (dstChannelNum_)
  28375. {}
  28376. ~AddChannelOp() {}
  28377. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28378. {
  28379. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28380. }
  28381. private:
  28382. const int srcChannelNum, dstChannelNum;
  28383. AddChannelOp (const AddChannelOp&);
  28384. AddChannelOp& operator= (const AddChannelOp&);
  28385. };
  28386. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28387. {
  28388. public:
  28389. ClearMidiBufferOp (const int bufferNum_)
  28390. : bufferNum (bufferNum_)
  28391. {}
  28392. ~ClearMidiBufferOp() {}
  28393. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28394. {
  28395. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28396. }
  28397. private:
  28398. const int bufferNum;
  28399. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28400. ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28401. };
  28402. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28403. {
  28404. public:
  28405. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28406. : srcBufferNum (srcBufferNum_),
  28407. dstBufferNum (dstBufferNum_)
  28408. {}
  28409. ~CopyMidiBufferOp() {}
  28410. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28411. {
  28412. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28413. }
  28414. private:
  28415. const int srcBufferNum, dstBufferNum;
  28416. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28417. CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28418. };
  28419. class AddMidiBufferOp : public AudioGraphRenderingOp
  28420. {
  28421. public:
  28422. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28423. : srcBufferNum (srcBufferNum_),
  28424. dstBufferNum (dstBufferNum_)
  28425. {}
  28426. ~AddMidiBufferOp() {}
  28427. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28428. {
  28429. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28430. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28431. }
  28432. private:
  28433. const int srcBufferNum, dstBufferNum;
  28434. AddMidiBufferOp (const AddMidiBufferOp&);
  28435. AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28436. };
  28437. class ProcessBufferOp : public AudioGraphRenderingOp
  28438. {
  28439. public:
  28440. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28441. const Array <int>& audioChannelsToUse_,
  28442. const int totalChans_,
  28443. const int midiBufferToUse_)
  28444. : node (node_),
  28445. processor (node_->processor),
  28446. audioChannelsToUse (audioChannelsToUse_),
  28447. totalChans (jmax (1, totalChans_)),
  28448. midiBufferToUse (midiBufferToUse_)
  28449. {
  28450. channels.calloc (totalChans);
  28451. while (audioChannelsToUse.size() < totalChans)
  28452. audioChannelsToUse.add (0);
  28453. }
  28454. ~ProcessBufferOp()
  28455. {
  28456. }
  28457. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28458. {
  28459. for (int i = totalChans; --i >= 0;)
  28460. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28461. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28462. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28463. }
  28464. const AudioProcessorGraph::Node::Ptr node;
  28465. AudioProcessor* const processor;
  28466. private:
  28467. Array <int> audioChannelsToUse;
  28468. HeapBlock <float*> channels;
  28469. int totalChans;
  28470. int midiBufferToUse;
  28471. ProcessBufferOp (const ProcessBufferOp&);
  28472. ProcessBufferOp& operator= (const ProcessBufferOp&);
  28473. };
  28474. class RenderingOpSequenceCalculator
  28475. {
  28476. public:
  28477. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28478. const VoidArray& orderedNodes_,
  28479. VoidArray& renderingOps)
  28480. : graph (graph_),
  28481. orderedNodes (orderedNodes_)
  28482. {
  28483. nodeIds.add (-2); // first buffer is read-only zeros
  28484. channels.add (0);
  28485. midiNodeIds.add (-2);
  28486. for (int i = 0; i < orderedNodes.size(); ++i)
  28487. {
  28488. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28489. renderingOps, i);
  28490. markAnyUnusedBuffersAsFree (i);
  28491. }
  28492. }
  28493. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28494. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28495. juce_UseDebuggingNewOperator
  28496. private:
  28497. AudioProcessorGraph& graph;
  28498. const VoidArray& orderedNodes;
  28499. Array <int> nodeIds, channels, midiNodeIds;
  28500. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28501. VoidArray& renderingOps,
  28502. const int ourRenderingIndex)
  28503. {
  28504. const int numIns = node->processor->getNumInputChannels();
  28505. const int numOuts = node->processor->getNumOutputChannels();
  28506. const int totalChans = jmax (numIns, numOuts);
  28507. Array <int> audioChannelsToUse;
  28508. int midiBufferToUse = -1;
  28509. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28510. {
  28511. // get a list of all the inputs to this node
  28512. Array <int> sourceNodes, sourceOutputChans;
  28513. for (int i = graph.getNumConnections(); --i >= 0;)
  28514. {
  28515. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28516. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28517. {
  28518. sourceNodes.add (c->sourceNodeId);
  28519. sourceOutputChans.add (c->sourceChannelIndex);
  28520. }
  28521. }
  28522. int bufIndex = -1;
  28523. if (sourceNodes.size() == 0)
  28524. {
  28525. // unconnected input channel
  28526. if (inputChan >= numOuts)
  28527. {
  28528. bufIndex = getReadOnlyEmptyBuffer();
  28529. jassert (bufIndex >= 0);
  28530. }
  28531. else
  28532. {
  28533. bufIndex = getFreeBuffer (false);
  28534. renderingOps.add (new ClearChannelOp (bufIndex));
  28535. }
  28536. }
  28537. else if (sourceNodes.size() == 1)
  28538. {
  28539. // channel with a straightforward single input..
  28540. const int srcNode = sourceNodes.getUnchecked(0);
  28541. const int srcChan = sourceOutputChans.getUnchecked(0);
  28542. bufIndex = getBufferContaining (srcNode, srcChan);
  28543. if (bufIndex < 0)
  28544. {
  28545. // if not found, this is probably a feedback loop
  28546. bufIndex = getReadOnlyEmptyBuffer();
  28547. jassert (bufIndex >= 0);
  28548. }
  28549. if (inputChan < numOuts
  28550. && isBufferNeededLater (ourRenderingIndex,
  28551. inputChan,
  28552. srcNode, srcChan))
  28553. {
  28554. // can't mess up this channel because it's needed later by another node, so we
  28555. // need to use a copy of it..
  28556. const int newFreeBuffer = getFreeBuffer (false);
  28557. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28558. bufIndex = newFreeBuffer;
  28559. }
  28560. }
  28561. else
  28562. {
  28563. // channel with a mix of several inputs..
  28564. // try to find a re-usable channel from our inputs..
  28565. int reusableInputIndex = -1;
  28566. for (int i = 0; i < sourceNodes.size(); ++i)
  28567. {
  28568. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28569. sourceOutputChans.getUnchecked(i));
  28570. if (sourceBufIndex >= 0
  28571. && ! isBufferNeededLater (ourRenderingIndex,
  28572. inputChan,
  28573. sourceNodes.getUnchecked(i),
  28574. sourceOutputChans.getUnchecked(i)))
  28575. {
  28576. // we've found one of our input chans that can be re-used..
  28577. reusableInputIndex = i;
  28578. bufIndex = sourceBufIndex;
  28579. break;
  28580. }
  28581. }
  28582. if (reusableInputIndex < 0)
  28583. {
  28584. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28585. bufIndex = getFreeBuffer (false);
  28586. jassert (bufIndex != 0);
  28587. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28588. sourceOutputChans.getUnchecked (0));
  28589. if (srcIndex < 0)
  28590. {
  28591. // if not found, this is probably a feedback loop
  28592. renderingOps.add (new ClearChannelOp (bufIndex));
  28593. }
  28594. else
  28595. {
  28596. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28597. }
  28598. reusableInputIndex = 0;
  28599. }
  28600. for (int j = 0; j < sourceNodes.size(); ++j)
  28601. {
  28602. if (j != reusableInputIndex)
  28603. {
  28604. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28605. sourceOutputChans.getUnchecked(j));
  28606. if (srcIndex >= 0)
  28607. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28608. }
  28609. }
  28610. }
  28611. jassert (bufIndex >= 0);
  28612. audioChannelsToUse.add (bufIndex);
  28613. if (inputChan < numOuts)
  28614. markBufferAsContaining (bufIndex, node->id, inputChan);
  28615. }
  28616. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28617. {
  28618. const int bufIndex = getFreeBuffer (false);
  28619. jassert (bufIndex != 0);
  28620. audioChannelsToUse.add (bufIndex);
  28621. markBufferAsContaining (bufIndex, node->id, outputChan);
  28622. }
  28623. // Now the same thing for midi..
  28624. Array <int> midiSourceNodes;
  28625. for (int i = graph.getNumConnections(); --i >= 0;)
  28626. {
  28627. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28628. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28629. midiSourceNodes.add (c->sourceNodeId);
  28630. }
  28631. if (midiSourceNodes.size() == 0)
  28632. {
  28633. // No midi inputs..
  28634. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28635. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28636. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28637. }
  28638. else if (midiSourceNodes.size() == 1)
  28639. {
  28640. // One midi input..
  28641. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28642. AudioProcessorGraph::midiChannelIndex);
  28643. if (midiBufferToUse >= 0)
  28644. {
  28645. if (isBufferNeededLater (ourRenderingIndex,
  28646. AudioProcessorGraph::midiChannelIndex,
  28647. midiSourceNodes.getUnchecked(0),
  28648. AudioProcessorGraph::midiChannelIndex))
  28649. {
  28650. // can't mess up this channel because it's needed later by another node, so we
  28651. // need to use a copy of it..
  28652. const int newFreeBuffer = getFreeBuffer (true);
  28653. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28654. midiBufferToUse = newFreeBuffer;
  28655. }
  28656. }
  28657. else
  28658. {
  28659. // probably a feedback loop, so just use an empty one..
  28660. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28661. }
  28662. }
  28663. else
  28664. {
  28665. // More than one midi input being mixed..
  28666. int reusableInputIndex = -1;
  28667. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28668. {
  28669. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28670. AudioProcessorGraph::midiChannelIndex);
  28671. if (sourceBufIndex >= 0
  28672. && ! isBufferNeededLater (ourRenderingIndex,
  28673. AudioProcessorGraph::midiChannelIndex,
  28674. midiSourceNodes.getUnchecked(i),
  28675. AudioProcessorGraph::midiChannelIndex))
  28676. {
  28677. // we've found one of our input buffers that can be re-used..
  28678. reusableInputIndex = i;
  28679. midiBufferToUse = sourceBufIndex;
  28680. break;
  28681. }
  28682. }
  28683. if (reusableInputIndex < 0)
  28684. {
  28685. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28686. midiBufferToUse = getFreeBuffer (true);
  28687. jassert (midiBufferToUse >= 0);
  28688. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28689. AudioProcessorGraph::midiChannelIndex);
  28690. if (srcIndex >= 0)
  28691. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28692. else
  28693. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28694. reusableInputIndex = 0;
  28695. }
  28696. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28697. {
  28698. if (j != reusableInputIndex)
  28699. {
  28700. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28701. AudioProcessorGraph::midiChannelIndex);
  28702. if (srcIndex >= 0)
  28703. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28704. }
  28705. }
  28706. }
  28707. if (node->processor->producesMidi())
  28708. markBufferAsContaining (midiBufferToUse, node->id,
  28709. AudioProcessorGraph::midiChannelIndex);
  28710. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28711. totalChans, midiBufferToUse));
  28712. }
  28713. int getFreeBuffer (const bool forMidi)
  28714. {
  28715. if (forMidi)
  28716. {
  28717. for (int i = 1; i < midiNodeIds.size(); ++i)
  28718. if (midiNodeIds.getUnchecked(i) < 0)
  28719. return i;
  28720. midiNodeIds.add (-1);
  28721. return midiNodeIds.size() - 1;
  28722. }
  28723. else
  28724. {
  28725. for (int i = 1; i < nodeIds.size(); ++i)
  28726. if (nodeIds.getUnchecked(i) < 0)
  28727. return i;
  28728. nodeIds.add (-1);
  28729. channels.add (0);
  28730. return nodeIds.size() - 1;
  28731. }
  28732. }
  28733. int getReadOnlyEmptyBuffer() const
  28734. {
  28735. return 0;
  28736. }
  28737. int getBufferContaining (const int nodeId, const int outputChannel) const
  28738. {
  28739. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28740. {
  28741. for (int i = midiNodeIds.size(); --i >= 0;)
  28742. if (midiNodeIds.getUnchecked(i) == nodeId)
  28743. return i;
  28744. }
  28745. else
  28746. {
  28747. for (int i = nodeIds.size(); --i >= 0;)
  28748. if (nodeIds.getUnchecked(i) == nodeId
  28749. && channels.getUnchecked(i) == outputChannel)
  28750. return i;
  28751. }
  28752. return -1;
  28753. }
  28754. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28755. {
  28756. int i;
  28757. for (i = 0; i < nodeIds.size(); ++i)
  28758. {
  28759. if (nodeIds.getUnchecked(i) >= 0
  28760. && ! isBufferNeededLater (stepIndex, -1,
  28761. nodeIds.getUnchecked(i),
  28762. channels.getUnchecked(i)))
  28763. {
  28764. nodeIds.set (i, -1);
  28765. }
  28766. }
  28767. for (i = 0; i < midiNodeIds.size(); ++i)
  28768. {
  28769. if (midiNodeIds.getUnchecked(i) >= 0
  28770. && ! isBufferNeededLater (stepIndex, -1,
  28771. midiNodeIds.getUnchecked(i),
  28772. AudioProcessorGraph::midiChannelIndex))
  28773. {
  28774. midiNodeIds.set (i, -1);
  28775. }
  28776. }
  28777. }
  28778. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28779. int inputChannelOfIndexToIgnore,
  28780. const int nodeId,
  28781. const int outputChanIndex) const
  28782. {
  28783. while (stepIndexToSearchFrom < orderedNodes.size())
  28784. {
  28785. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28786. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28787. {
  28788. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28789. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28790. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28791. return true;
  28792. }
  28793. else
  28794. {
  28795. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28796. if (i != inputChannelOfIndexToIgnore
  28797. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28798. node->id, i) != 0)
  28799. return true;
  28800. }
  28801. inputChannelOfIndexToIgnore = -1;
  28802. ++stepIndexToSearchFrom;
  28803. }
  28804. return false;
  28805. }
  28806. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28807. {
  28808. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28809. {
  28810. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28811. midiNodeIds.set (bufferNum, nodeId);
  28812. }
  28813. else
  28814. {
  28815. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28816. nodeIds.set (bufferNum, nodeId);
  28817. channels.set (bufferNum, outputIndex);
  28818. }
  28819. }
  28820. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28821. RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28822. };
  28823. }
  28824. void AudioProcessorGraph::clearRenderingSequence()
  28825. {
  28826. const ScopedLock sl (renderLock);
  28827. for (int i = renderingOps.size(); --i >= 0;)
  28828. {
  28829. GraphRenderingOps::AudioGraphRenderingOp* const r
  28830. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28831. renderingOps.remove (i);
  28832. delete r;
  28833. }
  28834. }
  28835. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28836. const uint32 possibleDestinationId,
  28837. const int recursionCheck) const
  28838. {
  28839. if (recursionCheck > 0)
  28840. {
  28841. for (int i = connections.size(); --i >= 0;)
  28842. {
  28843. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28844. if (c->destNodeId == possibleDestinationId
  28845. && (c->sourceNodeId == possibleInputId
  28846. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28847. return true;
  28848. }
  28849. }
  28850. return false;
  28851. }
  28852. void AudioProcessorGraph::buildRenderingSequence()
  28853. {
  28854. VoidArray newRenderingOps;
  28855. int numRenderingBuffersNeeded = 2;
  28856. int numMidiBuffersNeeded = 1;
  28857. {
  28858. MessageManagerLock mml;
  28859. VoidArray orderedNodes;
  28860. int i;
  28861. for (i = 0; i < nodes.size(); ++i)
  28862. {
  28863. Node* const node = nodes.getUnchecked(i);
  28864. node->prepare (getSampleRate(), getBlockSize(), this);
  28865. int j = 0;
  28866. for (; j < orderedNodes.size(); ++j)
  28867. if (isAnInputTo (node->id,
  28868. ((Node*) orderedNodes.getUnchecked (j))->id,
  28869. nodes.size() + 1))
  28870. break;
  28871. orderedNodes.insert (j, node);
  28872. }
  28873. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28874. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28875. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28876. }
  28877. VoidArray oldRenderingOps (renderingOps);
  28878. {
  28879. // swap over to the new rendering sequence..
  28880. const ScopedLock sl (renderLock);
  28881. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28882. renderingBuffers.clear();
  28883. for (int i = midiBuffers.size(); --i >= 0;)
  28884. midiBuffers.getUnchecked(i)->clear();
  28885. while (midiBuffers.size() < numMidiBuffersNeeded)
  28886. midiBuffers.add (new MidiBuffer());
  28887. renderingOps = newRenderingOps;
  28888. }
  28889. for (int i = oldRenderingOps.size(); --i >= 0;)
  28890. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28891. }
  28892. void AudioProcessorGraph::handleAsyncUpdate()
  28893. {
  28894. buildRenderingSequence();
  28895. }
  28896. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28897. {
  28898. currentAudioInputBuffer = 0;
  28899. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28900. currentMidiInputBuffer = 0;
  28901. currentMidiOutputBuffer.clear();
  28902. clearRenderingSequence();
  28903. buildRenderingSequence();
  28904. }
  28905. void AudioProcessorGraph::releaseResources()
  28906. {
  28907. for (int i = 0; i < nodes.size(); ++i)
  28908. nodes.getUnchecked(i)->unprepare();
  28909. renderingBuffers.setSize (1, 1);
  28910. midiBuffers.clear();
  28911. currentAudioInputBuffer = 0;
  28912. currentAudioOutputBuffer.setSize (1, 1);
  28913. currentMidiInputBuffer = 0;
  28914. currentMidiOutputBuffer.clear();
  28915. }
  28916. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28917. {
  28918. const int numSamples = buffer.getNumSamples();
  28919. const ScopedLock sl (renderLock);
  28920. currentAudioInputBuffer = &buffer;
  28921. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28922. currentAudioOutputBuffer.clear();
  28923. currentMidiInputBuffer = &midiMessages;
  28924. currentMidiOutputBuffer.clear();
  28925. int i;
  28926. for (i = 0; i < renderingOps.size(); ++i)
  28927. {
  28928. GraphRenderingOps::AudioGraphRenderingOp* const op
  28929. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28930. op->perform (renderingBuffers, midiBuffers, numSamples);
  28931. }
  28932. for (i = 0; i < buffer.getNumChannels(); ++i)
  28933. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28934. midiMessages.clear();
  28935. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28936. }
  28937. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28938. {
  28939. return "Input " + String (channelIndex + 1);
  28940. }
  28941. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28942. {
  28943. return "Output " + String (channelIndex + 1);
  28944. }
  28945. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28946. {
  28947. return true;
  28948. }
  28949. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28950. {
  28951. return true;
  28952. }
  28953. bool AudioProcessorGraph::acceptsMidi() const
  28954. {
  28955. return true;
  28956. }
  28957. bool AudioProcessorGraph::producesMidi() const
  28958. {
  28959. return true;
  28960. }
  28961. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  28962. {
  28963. }
  28964. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  28965. {
  28966. }
  28967. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  28968. : type (type_),
  28969. graph (0)
  28970. {
  28971. }
  28972. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  28973. {
  28974. }
  28975. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  28976. {
  28977. switch (type)
  28978. {
  28979. case audioOutputNode:
  28980. return "Audio Output";
  28981. case audioInputNode:
  28982. return "Audio Input";
  28983. case midiOutputNode:
  28984. return "Midi Output";
  28985. case midiInputNode:
  28986. return "Midi Input";
  28987. default:
  28988. break;
  28989. }
  28990. return String::empty;
  28991. }
  28992. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  28993. {
  28994. d.name = getName();
  28995. d.uid = d.name.hashCode();
  28996. d.category = "I/O devices";
  28997. d.pluginFormatName = "Internal";
  28998. d.manufacturerName = "Raw Material Software";
  28999. d.version = "1.0";
  29000. d.isInstrument = false;
  29001. d.numInputChannels = getNumInputChannels();
  29002. if (type == audioOutputNode && graph != 0)
  29003. d.numInputChannels = graph->getNumInputChannels();
  29004. d.numOutputChannels = getNumOutputChannels();
  29005. if (type == audioInputNode && graph != 0)
  29006. d.numOutputChannels = graph->getNumOutputChannels();
  29007. }
  29008. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  29009. {
  29010. jassert (graph != 0);
  29011. }
  29012. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  29013. {
  29014. }
  29015. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  29016. MidiBuffer& midiMessages)
  29017. {
  29018. jassert (graph != 0);
  29019. switch (type)
  29020. {
  29021. case audioOutputNode:
  29022. {
  29023. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  29024. buffer.getNumChannels()); --i >= 0;)
  29025. {
  29026. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  29027. }
  29028. break;
  29029. }
  29030. case audioInputNode:
  29031. {
  29032. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  29033. buffer.getNumChannels()); --i >= 0;)
  29034. {
  29035. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  29036. }
  29037. break;
  29038. }
  29039. case midiOutputNode:
  29040. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  29041. break;
  29042. case midiInputNode:
  29043. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  29044. break;
  29045. default:
  29046. break;
  29047. }
  29048. }
  29049. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  29050. {
  29051. return type == midiOutputNode;
  29052. }
  29053. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  29054. {
  29055. return type == midiInputNode;
  29056. }
  29057. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  29058. {
  29059. switch (type)
  29060. {
  29061. case audioOutputNode:
  29062. return "Output " + String (channelIndex + 1);
  29063. case midiOutputNode:
  29064. return "Midi Output";
  29065. default:
  29066. break;
  29067. }
  29068. return String::empty;
  29069. }
  29070. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  29071. {
  29072. switch (type)
  29073. {
  29074. case audioInputNode:
  29075. return "Input " + String (channelIndex + 1);
  29076. case midiInputNode:
  29077. return "Midi Input";
  29078. default:
  29079. break;
  29080. }
  29081. return String::empty;
  29082. }
  29083. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  29084. {
  29085. return type == audioInputNode || type == audioOutputNode;
  29086. }
  29087. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  29088. {
  29089. return isInputChannelStereoPair (index);
  29090. }
  29091. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  29092. {
  29093. return type == audioInputNode || type == midiInputNode;
  29094. }
  29095. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  29096. {
  29097. return type == audioOutputNode || type == midiOutputNode;
  29098. }
  29099. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  29100. {
  29101. return 0;
  29102. }
  29103. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  29104. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  29105. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  29106. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  29107. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  29108. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  29109. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  29110. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  29111. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  29112. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  29113. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  29114. {
  29115. }
  29116. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  29117. {
  29118. }
  29119. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  29120. {
  29121. graph = newGraph;
  29122. if (graph != 0)
  29123. {
  29124. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  29125. type == audioInputNode ? graph->getNumInputChannels() : 0,
  29126. getSampleRate(),
  29127. getBlockSize());
  29128. updateHostDisplay();
  29129. }
  29130. }
  29131. END_JUCE_NAMESPACE
  29132. /*** End of inlined file: juce_AudioProcessorGraph.cpp ***/
  29133. /*** Start of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29134. BEGIN_JUCE_NAMESPACE
  29135. AudioProcessorPlayer::AudioProcessorPlayer()
  29136. : processor (0),
  29137. sampleRate (0),
  29138. blockSize (0),
  29139. isPrepared (false),
  29140. numInputChans (0),
  29141. numOutputChans (0),
  29142. tempBuffer (1, 1)
  29143. {
  29144. }
  29145. AudioProcessorPlayer::~AudioProcessorPlayer()
  29146. {
  29147. setProcessor (0);
  29148. }
  29149. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  29150. {
  29151. if (processor != processorToPlay)
  29152. {
  29153. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  29154. {
  29155. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  29156. sampleRate, blockSize);
  29157. processorToPlay->prepareToPlay (sampleRate, blockSize);
  29158. }
  29159. AudioProcessor* oldOne;
  29160. {
  29161. const ScopedLock sl (lock);
  29162. oldOne = isPrepared ? processor : 0;
  29163. processor = processorToPlay;
  29164. isPrepared = true;
  29165. }
  29166. if (oldOne != 0)
  29167. oldOne->releaseResources();
  29168. }
  29169. }
  29170. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  29171. int numInputChannels,
  29172. float** outputChannelData,
  29173. int numOutputChannels,
  29174. int numSamples)
  29175. {
  29176. // these should have been prepared by audioDeviceAboutToStart()...
  29177. jassert (sampleRate > 0 && blockSize > 0);
  29178. incomingMidi.clear();
  29179. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  29180. int i, totalNumChans = 0;
  29181. if (numInputChannels > numOutputChannels)
  29182. {
  29183. // if there aren't enough output channels for the number of
  29184. // inputs, we need to create some temporary extra ones (can't
  29185. // use the input data in case it gets written to)
  29186. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  29187. false, false, true);
  29188. for (i = 0; i < numOutputChannels; ++i)
  29189. {
  29190. channels[totalNumChans] = outputChannelData[i];
  29191. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29192. ++totalNumChans;
  29193. }
  29194. for (i = numOutputChannels; i < numInputChannels; ++i)
  29195. {
  29196. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  29197. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29198. ++totalNumChans;
  29199. }
  29200. }
  29201. else
  29202. {
  29203. for (i = 0; i < numInputChannels; ++i)
  29204. {
  29205. channels[totalNumChans] = outputChannelData[i];
  29206. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29207. ++totalNumChans;
  29208. }
  29209. for (i = numInputChannels; i < numOutputChannels; ++i)
  29210. {
  29211. channels[totalNumChans] = outputChannelData[i];
  29212. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  29213. ++totalNumChans;
  29214. }
  29215. }
  29216. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  29217. const ScopedLock sl (lock);
  29218. if (processor != 0)
  29219. processor->processBlock (buffer, incomingMidi);
  29220. }
  29221. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  29222. {
  29223. const ScopedLock sl (lock);
  29224. sampleRate = device->getCurrentSampleRate();
  29225. blockSize = device->getCurrentBufferSizeSamples();
  29226. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  29227. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  29228. messageCollector.reset (sampleRate);
  29229. zeromem (channels, sizeof (channels));
  29230. if (processor != 0)
  29231. {
  29232. if (isPrepared)
  29233. processor->releaseResources();
  29234. AudioProcessor* const oldProcessor = processor;
  29235. setProcessor (0);
  29236. setProcessor (oldProcessor);
  29237. }
  29238. }
  29239. void AudioProcessorPlayer::audioDeviceStopped()
  29240. {
  29241. const ScopedLock sl (lock);
  29242. if (processor != 0 && isPrepared)
  29243. processor->releaseResources();
  29244. sampleRate = 0.0;
  29245. blockSize = 0;
  29246. isPrepared = false;
  29247. tempBuffer.setSize (1, 1);
  29248. }
  29249. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  29250. {
  29251. messageCollector.addMessageToQueue (message);
  29252. }
  29253. END_JUCE_NAMESPACE
  29254. /*** End of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29255. /*** Start of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29256. BEGIN_JUCE_NAMESPACE
  29257. class ProcessorParameterPropertyComp : public PropertyComponent,
  29258. public AudioProcessorListener,
  29259. public AsyncUpdater
  29260. {
  29261. public:
  29262. ProcessorParameterPropertyComp (const String& name,
  29263. AudioProcessor* const owner_,
  29264. const int index_)
  29265. : PropertyComponent (name),
  29266. owner (owner_),
  29267. index (index_)
  29268. {
  29269. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  29270. owner_->addListener (this);
  29271. }
  29272. ~ProcessorParameterPropertyComp()
  29273. {
  29274. owner->removeListener (this);
  29275. deleteAllChildren();
  29276. }
  29277. void refresh()
  29278. {
  29279. slider->setValue (owner->getParameter (index), false);
  29280. }
  29281. void audioProcessorChanged (AudioProcessor*) {}
  29282. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  29283. {
  29284. if (parameterIndex == index)
  29285. triggerAsyncUpdate();
  29286. }
  29287. void handleAsyncUpdate()
  29288. {
  29289. refresh();
  29290. }
  29291. juce_UseDebuggingNewOperator
  29292. private:
  29293. AudioProcessor* const owner;
  29294. const int index;
  29295. Slider* slider;
  29296. class ParamSlider : public Slider
  29297. {
  29298. public:
  29299. ParamSlider (AudioProcessor* const owner_, const int index_)
  29300. : Slider (String::empty),
  29301. owner (owner_),
  29302. index (index_)
  29303. {
  29304. setRange (0.0, 1.0, 0.0);
  29305. setSliderStyle (Slider::LinearBar);
  29306. setTextBoxIsEditable (false);
  29307. setScrollWheelEnabled (false);
  29308. }
  29309. ~ParamSlider()
  29310. {
  29311. }
  29312. void valueChanged()
  29313. {
  29314. const float newVal = (float) getValue();
  29315. if (owner->getParameter (index) != newVal)
  29316. owner->setParameter (index, newVal);
  29317. }
  29318. const String getTextFromValue (double /*value*/)
  29319. {
  29320. return owner->getParameterText (index);
  29321. }
  29322. juce_UseDebuggingNewOperator
  29323. private:
  29324. AudioProcessor* const owner;
  29325. const int index;
  29326. ParamSlider (const ParamSlider&);
  29327. ParamSlider& operator= (const ParamSlider&);
  29328. };
  29329. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29330. ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29331. };
  29332. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29333. : AudioProcessorEditor (owner_)
  29334. {
  29335. setOpaque (true);
  29336. addAndMakeVisible (panel = new PropertyPanel());
  29337. Array <PropertyComponent*> params;
  29338. const int numParams = owner_->getNumParameters();
  29339. int totalHeight = 0;
  29340. for (int i = 0; i < numParams; ++i)
  29341. {
  29342. String name (owner_->getParameterName (i));
  29343. if (name.trim().isEmpty())
  29344. name = "Unnamed";
  29345. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29346. params.add (pc);
  29347. totalHeight += pc->getPreferredHeight();
  29348. }
  29349. panel->addProperties (params);
  29350. setSize (400, jlimit (25, 400, totalHeight));
  29351. }
  29352. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29353. {
  29354. deleteAllChildren();
  29355. }
  29356. void GenericAudioProcessorEditor::paint (Graphics& g)
  29357. {
  29358. g.fillAll (Colours::white);
  29359. }
  29360. void GenericAudioProcessorEditor::resized()
  29361. {
  29362. panel->setSize (getWidth(), getHeight());
  29363. }
  29364. END_JUCE_NAMESPACE
  29365. /*** End of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29366. /*** Start of inlined file: juce_Sampler.cpp ***/
  29367. BEGIN_JUCE_NAMESPACE
  29368. SamplerSound::SamplerSound (const String& name_,
  29369. AudioFormatReader& source,
  29370. const BitArray& midiNotes_,
  29371. const int midiNoteForNormalPitch,
  29372. const double attackTimeSecs,
  29373. const double releaseTimeSecs,
  29374. const double maxSampleLengthSeconds)
  29375. : name (name_),
  29376. midiNotes (midiNotes_),
  29377. midiRootNote (midiNoteForNormalPitch)
  29378. {
  29379. sourceSampleRate = source.sampleRate;
  29380. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29381. {
  29382. length = 0;
  29383. attackSamples = 0;
  29384. releaseSamples = 0;
  29385. }
  29386. else
  29387. {
  29388. length = jmin ((int) source.lengthInSamples,
  29389. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29390. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29391. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29392. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29393. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29394. }
  29395. }
  29396. SamplerSound::~SamplerSound()
  29397. {
  29398. }
  29399. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29400. {
  29401. return midiNotes [midiNoteNumber];
  29402. }
  29403. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29404. {
  29405. return true;
  29406. }
  29407. SamplerVoice::SamplerVoice()
  29408. : pitchRatio (0.0),
  29409. sourceSamplePosition (0.0),
  29410. lgain (0.0f),
  29411. rgain (0.0f),
  29412. isInAttack (false),
  29413. isInRelease (false)
  29414. {
  29415. }
  29416. SamplerVoice::~SamplerVoice()
  29417. {
  29418. }
  29419. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29420. {
  29421. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29422. }
  29423. void SamplerVoice::startNote (const int midiNoteNumber,
  29424. const float velocity,
  29425. SynthesiserSound* s,
  29426. const int /*currentPitchWheelPosition*/)
  29427. {
  29428. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29429. jassert (sound != 0); // this object can only play SamplerSounds!
  29430. if (sound != 0)
  29431. {
  29432. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29433. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29434. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29435. sourceSamplePosition = 0.0;
  29436. lgain = velocity;
  29437. rgain = velocity;
  29438. isInAttack = (sound->attackSamples > 0);
  29439. isInRelease = false;
  29440. if (isInAttack)
  29441. {
  29442. attackReleaseLevel = 0.0f;
  29443. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29444. }
  29445. else
  29446. {
  29447. attackReleaseLevel = 1.0f;
  29448. attackDelta = 0.0f;
  29449. }
  29450. if (sound->releaseSamples > 0)
  29451. {
  29452. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29453. }
  29454. else
  29455. {
  29456. releaseDelta = 0.0f;
  29457. }
  29458. }
  29459. }
  29460. void SamplerVoice::stopNote (const bool allowTailOff)
  29461. {
  29462. if (allowTailOff)
  29463. {
  29464. isInAttack = false;
  29465. isInRelease = true;
  29466. }
  29467. else
  29468. {
  29469. clearCurrentNote();
  29470. }
  29471. }
  29472. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29473. {
  29474. }
  29475. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29476. const int /*newValue*/)
  29477. {
  29478. }
  29479. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29480. {
  29481. const SamplerSound* const playingSound = (SamplerSound*) (SynthesiserSound*) getCurrentlyPlayingSound();
  29482. if (playingSound != 0)
  29483. {
  29484. const float* const inL = playingSound->data->getSampleData (0, 0);
  29485. const float* const inR = playingSound->data->getNumChannels() > 1
  29486. ? playingSound->data->getSampleData (1, 0) : 0;
  29487. float* outL = outputBuffer.getSampleData (0, startSample);
  29488. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29489. while (--numSamples >= 0)
  29490. {
  29491. const int pos = (int) sourceSamplePosition;
  29492. const float alpha = (float) (sourceSamplePosition - pos);
  29493. const float invAlpha = 1.0f - alpha;
  29494. // just using a very simple linear interpolation here..
  29495. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29496. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29497. : l;
  29498. l *= lgain;
  29499. r *= rgain;
  29500. if (isInAttack)
  29501. {
  29502. l *= attackReleaseLevel;
  29503. r *= attackReleaseLevel;
  29504. attackReleaseLevel += attackDelta;
  29505. if (attackReleaseLevel >= 1.0f)
  29506. {
  29507. attackReleaseLevel = 1.0f;
  29508. isInAttack = false;
  29509. }
  29510. }
  29511. else if (isInRelease)
  29512. {
  29513. l *= attackReleaseLevel;
  29514. r *= attackReleaseLevel;
  29515. attackReleaseLevel += releaseDelta;
  29516. if (attackReleaseLevel <= 0.0f)
  29517. {
  29518. stopNote (false);
  29519. break;
  29520. }
  29521. }
  29522. if (outR != 0)
  29523. {
  29524. *outL++ += l;
  29525. *outR++ += r;
  29526. }
  29527. else
  29528. {
  29529. *outL++ += (l + r) * 0.5f;
  29530. }
  29531. sourceSamplePosition += pitchRatio;
  29532. if (sourceSamplePosition > playingSound->length)
  29533. {
  29534. stopNote (false);
  29535. break;
  29536. }
  29537. }
  29538. }
  29539. }
  29540. END_JUCE_NAMESPACE
  29541. /*** End of inlined file: juce_Sampler.cpp ***/
  29542. /*** Start of inlined file: juce_Synthesiser.cpp ***/
  29543. BEGIN_JUCE_NAMESPACE
  29544. SynthesiserSound::SynthesiserSound()
  29545. {
  29546. }
  29547. SynthesiserSound::~SynthesiserSound()
  29548. {
  29549. }
  29550. SynthesiserVoice::SynthesiserVoice()
  29551. : currentSampleRate (44100.0),
  29552. currentlyPlayingNote (-1),
  29553. noteOnTime (0),
  29554. currentlyPlayingSound (0)
  29555. {
  29556. }
  29557. SynthesiserVoice::~SynthesiserVoice()
  29558. {
  29559. }
  29560. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29561. {
  29562. return currentlyPlayingSound != 0
  29563. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29564. }
  29565. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29566. {
  29567. currentSampleRate = newRate;
  29568. }
  29569. void SynthesiserVoice::clearCurrentNote()
  29570. {
  29571. currentlyPlayingNote = -1;
  29572. currentlyPlayingSound = 0;
  29573. }
  29574. Synthesiser::Synthesiser()
  29575. : sampleRate (0),
  29576. lastNoteOnCounter (0),
  29577. shouldStealNotes (true)
  29578. {
  29579. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29580. lastPitchWheelValues[i] = 0x2000;
  29581. }
  29582. Synthesiser::~Synthesiser()
  29583. {
  29584. }
  29585. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29586. {
  29587. const ScopedLock sl (lock);
  29588. return voices [index];
  29589. }
  29590. void Synthesiser::clearVoices()
  29591. {
  29592. const ScopedLock sl (lock);
  29593. voices.clear();
  29594. }
  29595. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29596. {
  29597. const ScopedLock sl (lock);
  29598. voices.add (newVoice);
  29599. }
  29600. void Synthesiser::removeVoice (const int index)
  29601. {
  29602. const ScopedLock sl (lock);
  29603. voices.remove (index);
  29604. }
  29605. void Synthesiser::clearSounds()
  29606. {
  29607. const ScopedLock sl (lock);
  29608. sounds.clear();
  29609. }
  29610. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29611. {
  29612. const ScopedLock sl (lock);
  29613. sounds.add (newSound);
  29614. }
  29615. void Synthesiser::removeSound (const int index)
  29616. {
  29617. const ScopedLock sl (lock);
  29618. sounds.remove (index);
  29619. }
  29620. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29621. {
  29622. shouldStealNotes = shouldStealNotes_;
  29623. }
  29624. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29625. {
  29626. if (sampleRate != newRate)
  29627. {
  29628. const ScopedLock sl (lock);
  29629. allNotesOff (0, false);
  29630. sampleRate = newRate;
  29631. for (int i = voices.size(); --i >= 0;)
  29632. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29633. }
  29634. }
  29635. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29636. const MidiBuffer& midiData,
  29637. int startSample,
  29638. int numSamples)
  29639. {
  29640. // must set the sample rate before using this!
  29641. jassert (sampleRate != 0);
  29642. const ScopedLock sl (lock);
  29643. MidiBuffer::Iterator midiIterator (midiData);
  29644. midiIterator.setNextSamplePosition (startSample);
  29645. MidiMessage m (0xf4, 0.0);
  29646. while (numSamples > 0)
  29647. {
  29648. int midiEventPos;
  29649. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29650. && midiEventPos < startSample + numSamples;
  29651. const int numThisTime = useEvent ? midiEventPos - startSample
  29652. : numSamples;
  29653. if (numThisTime > 0)
  29654. {
  29655. for (int i = voices.size(); --i >= 0;)
  29656. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29657. }
  29658. if (useEvent)
  29659. {
  29660. if (m.isNoteOn())
  29661. {
  29662. const int channel = m.getChannel();
  29663. noteOn (channel,
  29664. m.getNoteNumber(),
  29665. m.getFloatVelocity());
  29666. }
  29667. else if (m.isNoteOff())
  29668. {
  29669. noteOff (m.getChannel(),
  29670. m.getNoteNumber(),
  29671. true);
  29672. }
  29673. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29674. {
  29675. allNotesOff (m.getChannel(), true);
  29676. }
  29677. else if (m.isPitchWheel())
  29678. {
  29679. const int channel = m.getChannel();
  29680. const int wheelPos = m.getPitchWheelValue();
  29681. lastPitchWheelValues [channel - 1] = wheelPos;
  29682. handlePitchWheel (channel, wheelPos);
  29683. }
  29684. else if (m.isController())
  29685. {
  29686. handleController (m.getChannel(),
  29687. m.getControllerNumber(),
  29688. m.getControllerValue());
  29689. }
  29690. }
  29691. startSample += numThisTime;
  29692. numSamples -= numThisTime;
  29693. }
  29694. }
  29695. void Synthesiser::noteOn (const int midiChannel,
  29696. const int midiNoteNumber,
  29697. const float velocity)
  29698. {
  29699. const ScopedLock sl (lock);
  29700. for (int i = sounds.size(); --i >= 0;)
  29701. {
  29702. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29703. if (sound->appliesToNote (midiNoteNumber)
  29704. && sound->appliesToChannel (midiChannel))
  29705. {
  29706. startVoice (findFreeVoice (sound, shouldStealNotes),
  29707. sound, midiChannel, midiNoteNumber, velocity);
  29708. }
  29709. }
  29710. }
  29711. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29712. SynthesiserSound* const sound,
  29713. const int midiChannel,
  29714. const int midiNoteNumber,
  29715. const float velocity)
  29716. {
  29717. if (voice != 0 && sound != 0)
  29718. {
  29719. if (voice->currentlyPlayingSound != 0)
  29720. voice->stopNote (false);
  29721. voice->startNote (midiNoteNumber,
  29722. velocity,
  29723. sound,
  29724. lastPitchWheelValues [midiChannel - 1]);
  29725. voice->currentlyPlayingNote = midiNoteNumber;
  29726. voice->noteOnTime = ++lastNoteOnCounter;
  29727. voice->currentlyPlayingSound = sound;
  29728. }
  29729. }
  29730. void Synthesiser::noteOff (const int midiChannel,
  29731. const int midiNoteNumber,
  29732. const bool allowTailOff)
  29733. {
  29734. const ScopedLock sl (lock);
  29735. for (int i = voices.size(); --i >= 0;)
  29736. {
  29737. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29738. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29739. {
  29740. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29741. if (sound != 0
  29742. && sound->appliesToNote (midiNoteNumber)
  29743. && sound->appliesToChannel (midiChannel))
  29744. {
  29745. voice->stopNote (allowTailOff);
  29746. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29747. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29748. }
  29749. }
  29750. }
  29751. }
  29752. void Synthesiser::allNotesOff (const int midiChannel,
  29753. const bool allowTailOff)
  29754. {
  29755. const ScopedLock sl (lock);
  29756. for (int i = voices.size(); --i >= 0;)
  29757. {
  29758. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29759. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29760. voice->stopNote (allowTailOff);
  29761. }
  29762. }
  29763. void Synthesiser::handlePitchWheel (const int midiChannel,
  29764. const int wheelValue)
  29765. {
  29766. const ScopedLock sl (lock);
  29767. for (int i = voices.size(); --i >= 0;)
  29768. {
  29769. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29770. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29771. {
  29772. voice->pitchWheelMoved (wheelValue);
  29773. }
  29774. }
  29775. }
  29776. void Synthesiser::handleController (const int midiChannel,
  29777. const int controllerNumber,
  29778. const int controllerValue)
  29779. {
  29780. const ScopedLock sl (lock);
  29781. for (int i = voices.size(); --i >= 0;)
  29782. {
  29783. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29784. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29785. voice->controllerMoved (controllerNumber, controllerValue);
  29786. }
  29787. }
  29788. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29789. const bool stealIfNoneAvailable) const
  29790. {
  29791. const ScopedLock sl (lock);
  29792. for (int i = voices.size(); --i >= 0;)
  29793. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29794. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29795. return voices.getUnchecked (i);
  29796. if (stealIfNoneAvailable)
  29797. {
  29798. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29799. SynthesiserVoice* oldest = 0;
  29800. for (int i = voices.size(); --i >= 0;)
  29801. {
  29802. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29803. if (voice->canPlaySound (soundToPlay)
  29804. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29805. oldest = voice;
  29806. }
  29807. jassert (oldest != 0);
  29808. return oldest;
  29809. }
  29810. return 0;
  29811. }
  29812. END_JUCE_NAMESPACE
  29813. /*** End of inlined file: juce_Synthesiser.cpp ***/
  29814. /*** Start of inlined file: juce_ActionBroadcaster.cpp ***/
  29815. BEGIN_JUCE_NAMESPACE
  29816. ActionBroadcaster::ActionBroadcaster() throw()
  29817. {
  29818. // are you trying to create this object before or after juce has been intialised??
  29819. jassert (MessageManager::instance != 0);
  29820. }
  29821. ActionBroadcaster::~ActionBroadcaster()
  29822. {
  29823. // all event-based objects must be deleted BEFORE juce is shut down!
  29824. jassert (MessageManager::instance != 0);
  29825. }
  29826. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29827. {
  29828. actionListenerList.addActionListener (listener);
  29829. }
  29830. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29831. {
  29832. jassert (actionListenerList.isValidMessageListener());
  29833. if (actionListenerList.isValidMessageListener())
  29834. actionListenerList.removeActionListener (listener);
  29835. }
  29836. void ActionBroadcaster::removeAllActionListeners()
  29837. {
  29838. actionListenerList.removeAllActionListeners();
  29839. }
  29840. void ActionBroadcaster::sendActionMessage (const String& message) const
  29841. {
  29842. actionListenerList.sendActionMessage (message);
  29843. }
  29844. END_JUCE_NAMESPACE
  29845. /*** End of inlined file: juce_ActionBroadcaster.cpp ***/
  29846. /*** Start of inlined file: juce_ActionListenerList.cpp ***/
  29847. BEGIN_JUCE_NAMESPACE
  29848. // special message of our own with a string in it
  29849. class ActionMessage : public Message
  29850. {
  29851. public:
  29852. const String message;
  29853. ActionMessage (const String& messageText,
  29854. void* const listener_) throw()
  29855. : message (messageText)
  29856. {
  29857. pointerParameter = listener_;
  29858. }
  29859. ~ActionMessage() throw()
  29860. {
  29861. }
  29862. private:
  29863. ActionMessage (const ActionMessage&);
  29864. ActionMessage& operator= (const ActionMessage&);
  29865. };
  29866. ActionListenerList::ActionListenerList() throw()
  29867. {
  29868. }
  29869. ActionListenerList::~ActionListenerList() throw()
  29870. {
  29871. }
  29872. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29873. {
  29874. const ScopedLock sl (actionListenerLock_);
  29875. jassert (listener != 0);
  29876. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29877. if (listener != 0)
  29878. actionListeners_.add (listener);
  29879. }
  29880. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29881. {
  29882. const ScopedLock sl (actionListenerLock_);
  29883. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29884. actionListeners_.removeValue (listener);
  29885. }
  29886. void ActionListenerList::removeAllActionListeners() throw()
  29887. {
  29888. const ScopedLock sl (actionListenerLock_);
  29889. actionListeners_.clear();
  29890. }
  29891. void ActionListenerList::sendActionMessage (const String& message) const
  29892. {
  29893. const ScopedLock sl (actionListenerLock_);
  29894. for (int i = actionListeners_.size(); --i >= 0;)
  29895. {
  29896. postMessage (new ActionMessage (message,
  29897. (ActionListener*) actionListeners_.getUnchecked(i)));
  29898. }
  29899. }
  29900. void ActionListenerList::handleMessage (const Message& message)
  29901. {
  29902. const ActionMessage& am = (const ActionMessage&) message;
  29903. if (actionListeners_.contains (am.pointerParameter))
  29904. ((ActionListener*) am.pointerParameter)->actionListenerCallback (am.message);
  29905. }
  29906. END_JUCE_NAMESPACE
  29907. /*** End of inlined file: juce_ActionListenerList.cpp ***/
  29908. /*** Start of inlined file: juce_AsyncUpdater.cpp ***/
  29909. BEGIN_JUCE_NAMESPACE
  29910. AsyncUpdater::AsyncUpdater() throw()
  29911. : asyncMessagePending (false)
  29912. {
  29913. internalAsyncHandler.owner = this;
  29914. }
  29915. AsyncUpdater::~AsyncUpdater()
  29916. {
  29917. }
  29918. void AsyncUpdater::triggerAsyncUpdate() throw()
  29919. {
  29920. if (! asyncMessagePending)
  29921. {
  29922. asyncMessagePending = true;
  29923. internalAsyncHandler.postMessage (new Message());
  29924. }
  29925. }
  29926. void AsyncUpdater::cancelPendingUpdate() throw()
  29927. {
  29928. asyncMessagePending = false;
  29929. }
  29930. void AsyncUpdater::handleUpdateNowIfNeeded()
  29931. {
  29932. if (asyncMessagePending)
  29933. {
  29934. asyncMessagePending = false;
  29935. handleAsyncUpdate();
  29936. }
  29937. }
  29938. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29939. {
  29940. owner->handleUpdateNowIfNeeded();
  29941. }
  29942. END_JUCE_NAMESPACE
  29943. /*** End of inlined file: juce_AsyncUpdater.cpp ***/
  29944. /*** Start of inlined file: juce_ChangeBroadcaster.cpp ***/
  29945. BEGIN_JUCE_NAMESPACE
  29946. ChangeBroadcaster::ChangeBroadcaster() throw()
  29947. {
  29948. // are you trying to create this object before or after juce has been intialised??
  29949. jassert (MessageManager::instance != 0);
  29950. }
  29951. ChangeBroadcaster::~ChangeBroadcaster()
  29952. {
  29953. // all event-based objects must be deleted BEFORE juce is shut down!
  29954. jassert (MessageManager::instance != 0);
  29955. }
  29956. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29957. {
  29958. changeListenerList.addChangeListener (listener);
  29959. }
  29960. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  29961. {
  29962. jassert (changeListenerList.isValidMessageListener());
  29963. if (changeListenerList.isValidMessageListener())
  29964. changeListenerList.removeChangeListener (listener);
  29965. }
  29966. void ChangeBroadcaster::removeAllChangeListeners() throw()
  29967. {
  29968. changeListenerList.removeAllChangeListeners();
  29969. }
  29970. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  29971. {
  29972. changeListenerList.sendChangeMessage (objectThatHasChanged);
  29973. }
  29974. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  29975. {
  29976. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  29977. }
  29978. void ChangeBroadcaster::dispatchPendingMessages()
  29979. {
  29980. changeListenerList.dispatchPendingMessages();
  29981. }
  29982. END_JUCE_NAMESPACE
  29983. /*** End of inlined file: juce_ChangeBroadcaster.cpp ***/
  29984. /*** Start of inlined file: juce_ChangeListenerList.cpp ***/
  29985. BEGIN_JUCE_NAMESPACE
  29986. ChangeListenerList::ChangeListenerList() throw()
  29987. : lastChangedObject (0),
  29988. messagePending (false)
  29989. {
  29990. }
  29991. ChangeListenerList::~ChangeListenerList() throw()
  29992. {
  29993. }
  29994. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  29995. {
  29996. const ScopedLock sl (lock);
  29997. jassert (listener != 0);
  29998. if (listener != 0)
  29999. listeners.add (listener);
  30000. }
  30001. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  30002. {
  30003. const ScopedLock sl (lock);
  30004. listeners.removeValue (listener);
  30005. }
  30006. void ChangeListenerList::removeAllChangeListeners() throw()
  30007. {
  30008. const ScopedLock sl (lock);
  30009. listeners.clear();
  30010. }
  30011. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  30012. {
  30013. const ScopedLock sl (lock);
  30014. if ((! messagePending) && (listeners.size() > 0))
  30015. {
  30016. lastChangedObject = objectThatHasChanged;
  30017. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  30018. messagePending = true;
  30019. }
  30020. }
  30021. void ChangeListenerList::handleMessage (const Message& message)
  30022. {
  30023. sendSynchronousChangeMessage (message.pointerParameter);
  30024. }
  30025. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  30026. {
  30027. const ScopedLock sl (lock);
  30028. messagePending = false;
  30029. for (int i = listeners.size(); --i >= 0;)
  30030. {
  30031. ChangeListener* const l = (ChangeListener*) listeners.getUnchecked (i);
  30032. {
  30033. const ScopedUnlock tempUnlocker (lock);
  30034. l->changeListenerCallback (objectThatHasChanged);
  30035. }
  30036. i = jmin (i, listeners.size());
  30037. }
  30038. }
  30039. void ChangeListenerList::dispatchPendingMessages()
  30040. {
  30041. if (messagePending)
  30042. sendSynchronousChangeMessage (lastChangedObject);
  30043. }
  30044. END_JUCE_NAMESPACE
  30045. /*** End of inlined file: juce_ChangeListenerList.cpp ***/
  30046. /*** Start of inlined file: juce_InterprocessConnection.cpp ***/
  30047. BEGIN_JUCE_NAMESPACE
  30048. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  30049. const uint32 magicMessageHeaderNumber)
  30050. : Thread ("Juce IPC connection"),
  30051. callbackConnectionState (false),
  30052. useMessageThread (callbacksOnMessageThread),
  30053. magicMessageHeader (magicMessageHeaderNumber),
  30054. pipeReceiveMessageTimeout (-1)
  30055. {
  30056. }
  30057. InterprocessConnection::~InterprocessConnection()
  30058. {
  30059. callbackConnectionState = false;
  30060. disconnect();
  30061. }
  30062. bool InterprocessConnection::connectToSocket (const String& hostName,
  30063. const int portNumber,
  30064. const int timeOutMillisecs)
  30065. {
  30066. disconnect();
  30067. const ScopedLock sl (pipeAndSocketLock);
  30068. socket = new StreamingSocket();
  30069. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  30070. {
  30071. connectionMadeInt();
  30072. startThread();
  30073. return true;
  30074. }
  30075. else
  30076. {
  30077. socket = 0;
  30078. return false;
  30079. }
  30080. }
  30081. bool InterprocessConnection::connectToPipe (const String& pipeName,
  30082. const int pipeReceiveMessageTimeoutMs)
  30083. {
  30084. disconnect();
  30085. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30086. if (newPipe->openExisting (pipeName))
  30087. {
  30088. const ScopedLock sl (pipeAndSocketLock);
  30089. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30090. initialiseWithPipe (newPipe.release());
  30091. return true;
  30092. }
  30093. return false;
  30094. }
  30095. bool InterprocessConnection::createPipe (const String& pipeName,
  30096. const int pipeReceiveMessageTimeoutMs)
  30097. {
  30098. disconnect();
  30099. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30100. if (newPipe->createNewPipe (pipeName))
  30101. {
  30102. const ScopedLock sl (pipeAndSocketLock);
  30103. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30104. initialiseWithPipe (newPipe.release());
  30105. return true;
  30106. }
  30107. return false;
  30108. }
  30109. void InterprocessConnection::disconnect()
  30110. {
  30111. if (socket != 0)
  30112. socket->close();
  30113. if (pipe != 0)
  30114. {
  30115. pipe->cancelPendingReads();
  30116. pipe->close();
  30117. }
  30118. stopThread (4000);
  30119. {
  30120. const ScopedLock sl (pipeAndSocketLock);
  30121. socket = 0;
  30122. pipe = 0;
  30123. }
  30124. connectionLostInt();
  30125. }
  30126. bool InterprocessConnection::isConnected() const
  30127. {
  30128. const ScopedLock sl (pipeAndSocketLock);
  30129. return ((socket != 0 && socket->isConnected())
  30130. || (pipe != 0 && pipe->isOpen()))
  30131. && isThreadRunning();
  30132. }
  30133. const String InterprocessConnection::getConnectedHostName() const
  30134. {
  30135. if (pipe != 0)
  30136. {
  30137. return "localhost";
  30138. }
  30139. else if (socket != 0)
  30140. {
  30141. if (! socket->isLocal())
  30142. return socket->getHostName();
  30143. return "localhost";
  30144. }
  30145. return String::empty;
  30146. }
  30147. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  30148. {
  30149. uint32 messageHeader[2];
  30150. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  30151. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  30152. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  30153. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  30154. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  30155. size_t bytesWritten = 0;
  30156. const ScopedLock sl (pipeAndSocketLock);
  30157. if (socket != 0)
  30158. {
  30159. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  30160. }
  30161. else if (pipe != 0)
  30162. {
  30163. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  30164. }
  30165. if (bytesWritten < 0)
  30166. {
  30167. // error..
  30168. return false;
  30169. }
  30170. return (bytesWritten == messageData.getSize());
  30171. }
  30172. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  30173. {
  30174. jassert (socket == 0);
  30175. socket = socket_;
  30176. connectionMadeInt();
  30177. startThread();
  30178. }
  30179. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  30180. {
  30181. jassert (pipe == 0);
  30182. pipe = pipe_;
  30183. connectionMadeInt();
  30184. startThread();
  30185. }
  30186. const int messageMagicNumber = 0xb734128b;
  30187. void InterprocessConnection::handleMessage (const Message& message)
  30188. {
  30189. if (message.intParameter1 == messageMagicNumber)
  30190. {
  30191. switch (message.intParameter2)
  30192. {
  30193. case 0:
  30194. {
  30195. ScopedPointer <MemoryBlock> data ((MemoryBlock*) message.pointerParameter);
  30196. messageReceived (*data);
  30197. break;
  30198. }
  30199. case 1:
  30200. connectionMade();
  30201. break;
  30202. case 2:
  30203. connectionLost();
  30204. break;
  30205. }
  30206. }
  30207. }
  30208. void InterprocessConnection::connectionMadeInt()
  30209. {
  30210. if (! callbackConnectionState)
  30211. {
  30212. callbackConnectionState = true;
  30213. if (useMessageThread)
  30214. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  30215. else
  30216. connectionMade();
  30217. }
  30218. }
  30219. void InterprocessConnection::connectionLostInt()
  30220. {
  30221. if (callbackConnectionState)
  30222. {
  30223. callbackConnectionState = false;
  30224. if (useMessageThread)
  30225. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  30226. else
  30227. connectionLost();
  30228. }
  30229. }
  30230. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  30231. {
  30232. jassert (callbackConnectionState);
  30233. if (useMessageThread)
  30234. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  30235. else
  30236. messageReceived (data);
  30237. }
  30238. bool InterprocessConnection::readNextMessageInt()
  30239. {
  30240. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  30241. uint32 messageHeader[2];
  30242. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  30243. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  30244. if (bytes == sizeof (messageHeader)
  30245. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  30246. {
  30247. const int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  30248. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  30249. {
  30250. MemoryBlock messageData (bytesInMessage, true);
  30251. int bytesRead = 0;
  30252. while (bytesRead < bytesInMessage)
  30253. {
  30254. if (threadShouldExit())
  30255. return false;
  30256. const int numThisTime = jmin (bytesInMessage, 65536);
  30257. const int bytesIn = (socket != 0) ? socket->read (((char*) messageData.getData()) + bytesRead, numThisTime, true)
  30258. : pipe->read (((char*) messageData.getData()) + bytesRead, numThisTime,
  30259. pipeReceiveMessageTimeout);
  30260. if (bytesIn <= 0)
  30261. break;
  30262. bytesRead += bytesIn;
  30263. }
  30264. if (bytesRead >= 0)
  30265. deliverDataInt (messageData);
  30266. }
  30267. }
  30268. else if (bytes < 0)
  30269. {
  30270. {
  30271. const ScopedLock sl (pipeAndSocketLock);
  30272. socket = 0;
  30273. }
  30274. connectionLostInt();
  30275. return false;
  30276. }
  30277. return true;
  30278. }
  30279. void InterprocessConnection::run()
  30280. {
  30281. while (! threadShouldExit())
  30282. {
  30283. if (socket != 0)
  30284. {
  30285. const int ready = socket->waitUntilReady (true, 0);
  30286. if (ready < 0)
  30287. {
  30288. {
  30289. const ScopedLock sl (pipeAndSocketLock);
  30290. socket = 0;
  30291. }
  30292. connectionLostInt();
  30293. break;
  30294. }
  30295. else if (ready > 0)
  30296. {
  30297. if (! readNextMessageInt())
  30298. break;
  30299. }
  30300. else
  30301. {
  30302. Thread::sleep (2);
  30303. }
  30304. }
  30305. else if (pipe != 0)
  30306. {
  30307. if (! pipe->isOpen())
  30308. {
  30309. {
  30310. const ScopedLock sl (pipeAndSocketLock);
  30311. pipe = 0;
  30312. }
  30313. connectionLostInt();
  30314. break;
  30315. }
  30316. else
  30317. {
  30318. if (! readNextMessageInt())
  30319. break;
  30320. }
  30321. }
  30322. else
  30323. {
  30324. break;
  30325. }
  30326. }
  30327. }
  30328. END_JUCE_NAMESPACE
  30329. /*** End of inlined file: juce_InterprocessConnection.cpp ***/
  30330. /*** Start of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30331. BEGIN_JUCE_NAMESPACE
  30332. InterprocessConnectionServer::InterprocessConnectionServer()
  30333. : Thread ("Juce IPC server")
  30334. {
  30335. }
  30336. InterprocessConnectionServer::~InterprocessConnectionServer()
  30337. {
  30338. stop();
  30339. }
  30340. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30341. {
  30342. stop();
  30343. socket = new StreamingSocket();
  30344. if (socket->createListener (portNumber))
  30345. {
  30346. startThread();
  30347. return true;
  30348. }
  30349. socket = 0;
  30350. return false;
  30351. }
  30352. void InterprocessConnectionServer::stop()
  30353. {
  30354. signalThreadShouldExit();
  30355. if (socket != 0)
  30356. socket->close();
  30357. stopThread (4000);
  30358. socket = 0;
  30359. }
  30360. void InterprocessConnectionServer::run()
  30361. {
  30362. while ((! threadShouldExit()) && socket != 0)
  30363. {
  30364. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30365. if (clientSocket != 0)
  30366. {
  30367. InterprocessConnection* newConnection = createConnectionObject();
  30368. if (newConnection != 0)
  30369. newConnection->initialiseWithSocket (clientSocket.release());
  30370. }
  30371. }
  30372. }
  30373. END_JUCE_NAMESPACE
  30374. /*** End of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30375. /*** Start of inlined file: juce_Message.cpp ***/
  30376. BEGIN_JUCE_NAMESPACE
  30377. Message::Message() throw()
  30378. {
  30379. }
  30380. Message::~Message() throw()
  30381. {
  30382. }
  30383. Message::Message (const int intParameter1_,
  30384. const int intParameter2_,
  30385. const int intParameter3_,
  30386. void* const pointerParameter_) throw()
  30387. : intParameter1 (intParameter1_),
  30388. intParameter2 (intParameter2_),
  30389. intParameter3 (intParameter3_),
  30390. pointerParameter (pointerParameter_)
  30391. {
  30392. }
  30393. END_JUCE_NAMESPACE
  30394. /*** End of inlined file: juce_Message.cpp ***/
  30395. /*** Start of inlined file: juce_MessageListener.cpp ***/
  30396. BEGIN_JUCE_NAMESPACE
  30397. MessageListener::MessageListener() throw()
  30398. {
  30399. // are you trying to create a messagelistener before or after juce has been intialised??
  30400. jassert (MessageManager::instance != 0);
  30401. if (MessageManager::instance != 0)
  30402. MessageManager::instance->messageListeners.add (this);
  30403. }
  30404. MessageListener::~MessageListener()
  30405. {
  30406. if (MessageManager::instance != 0)
  30407. MessageManager::instance->messageListeners.removeValue (this);
  30408. }
  30409. void MessageListener::postMessage (Message* const message) const throw()
  30410. {
  30411. message->messageRecipient = const_cast <MessageListener*> (this);
  30412. if (MessageManager::instance == 0)
  30413. MessageManager::getInstance();
  30414. MessageManager::instance->postMessageToQueue (message);
  30415. }
  30416. bool MessageListener::isValidMessageListener() const throw()
  30417. {
  30418. return (MessageManager::instance != 0)
  30419. && MessageManager::instance->messageListeners.contains (this);
  30420. }
  30421. END_JUCE_NAMESPACE
  30422. /*** End of inlined file: juce_MessageListener.cpp ***/
  30423. /*** Start of inlined file: juce_MessageManager.cpp ***/
  30424. BEGIN_JUCE_NAMESPACE
  30425. // platform-specific functions..
  30426. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30427. bool juce_postMessageToSystemQueue (void* message);
  30428. MessageManager* MessageManager::instance = 0;
  30429. static const int quitMessageId = 0xfffff321;
  30430. MessageManager::MessageManager() throw()
  30431. : quitMessagePosted (false),
  30432. quitMessageReceived (false),
  30433. threadWithLock (0)
  30434. {
  30435. messageThreadId = Thread::getCurrentThreadId();
  30436. }
  30437. MessageManager::~MessageManager() throw()
  30438. {
  30439. broadcastListeners = 0;
  30440. doPlatformSpecificShutdown();
  30441. jassert (instance == this);
  30442. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30443. }
  30444. MessageManager* MessageManager::getInstance() throw()
  30445. {
  30446. if (instance == 0)
  30447. {
  30448. instance = new MessageManager();
  30449. doPlatformSpecificInitialisation();
  30450. }
  30451. return instance;
  30452. }
  30453. void MessageManager::postMessageToQueue (Message* const message)
  30454. {
  30455. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30456. delete message;
  30457. }
  30458. CallbackMessage::CallbackMessage() throw() {}
  30459. CallbackMessage::~CallbackMessage() throw() {}
  30460. void CallbackMessage::post()
  30461. {
  30462. if (MessageManager::instance != 0)
  30463. MessageManager::instance->postCallbackMessage (this);
  30464. }
  30465. void MessageManager::postCallbackMessage (Message* const message)
  30466. {
  30467. message->messageRecipient = 0;
  30468. postMessageToQueue (message);
  30469. }
  30470. // not for public use..
  30471. void MessageManager::deliverMessage (void* message)
  30472. {
  30473. const ScopedPointer <Message> m ((Message*) message);
  30474. MessageListener* const recipient = m->messageRecipient;
  30475. JUCE_TRY
  30476. {
  30477. if (messageListeners.contains (recipient))
  30478. {
  30479. recipient->handleMessage (*m);
  30480. }
  30481. else if (recipient == 0)
  30482. {
  30483. if (m->intParameter1 == quitMessageId)
  30484. {
  30485. quitMessageReceived = true;
  30486. }
  30487. else
  30488. {
  30489. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> ((Message*) m);
  30490. if (cm != 0)
  30491. cm->messageCallback();
  30492. }
  30493. }
  30494. }
  30495. JUCE_CATCH_EXCEPTION
  30496. }
  30497. #if ! (JUCE_MAC || JUCE_IPHONE)
  30498. void MessageManager::runDispatchLoop()
  30499. {
  30500. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30501. runDispatchLoopUntil (-1);
  30502. }
  30503. void MessageManager::stopDispatchLoop()
  30504. {
  30505. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30506. m->messageRecipient = 0;
  30507. postMessageToQueue (m);
  30508. quitMessagePosted = true;
  30509. }
  30510. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30511. {
  30512. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30513. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30514. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30515. && ! quitMessageReceived)
  30516. {
  30517. JUCE_TRY
  30518. {
  30519. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30520. {
  30521. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30522. if (msToWait > 0)
  30523. Thread::sleep (jmin (5, msToWait));
  30524. }
  30525. }
  30526. JUCE_CATCH_EXCEPTION
  30527. }
  30528. return ! quitMessageReceived;
  30529. }
  30530. #endif
  30531. void MessageManager::deliverBroadcastMessage (const String& value)
  30532. {
  30533. if (broadcastListeners != 0)
  30534. broadcastListeners->sendActionMessage (value);
  30535. }
  30536. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30537. {
  30538. if (broadcastListeners == 0)
  30539. broadcastListeners = new ActionListenerList();
  30540. broadcastListeners->addActionListener (listener);
  30541. }
  30542. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30543. {
  30544. if (broadcastListeners != 0)
  30545. broadcastListeners->removeActionListener (listener);
  30546. }
  30547. bool MessageManager::isThisTheMessageThread() const throw()
  30548. {
  30549. return Thread::getCurrentThreadId() == messageThreadId;
  30550. }
  30551. void MessageManager::setCurrentThreadAsMessageThread()
  30552. {
  30553. if (messageThreadId != Thread::getCurrentThreadId())
  30554. {
  30555. messageThreadId = Thread::getCurrentThreadId();
  30556. // This is needed on windows to make sure the message window is created by this thread
  30557. doPlatformSpecificShutdown();
  30558. doPlatformSpecificInitialisation();
  30559. }
  30560. }
  30561. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30562. {
  30563. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30564. return thisThread == messageThreadId || thisThread == threadWithLock;
  30565. }
  30566. class MessageManagerLock::SharedEvents : public ReferenceCountedObject
  30567. {
  30568. public:
  30569. SharedEvents() {}
  30570. ~SharedEvents() {}
  30571. WaitableEvent lockedEvent, releaseEvent;
  30572. private:
  30573. SharedEvents (const SharedEvents&);
  30574. SharedEvents& operator= (const SharedEvents&);
  30575. };
  30576. class MessageManagerLock::BlockingMessage : public CallbackMessage
  30577. {
  30578. public:
  30579. BlockingMessage (MessageManagerLock::SharedEvents* const events_) : events (events_) {}
  30580. ~BlockingMessage() throw() {}
  30581. void messageCallback()
  30582. {
  30583. events->lockedEvent.signal();
  30584. events->releaseEvent.wait();
  30585. }
  30586. juce_UseDebuggingNewOperator
  30587. private:
  30588. ReferenceCountedObjectPtr <MessageManagerLock::SharedEvents> events;
  30589. BlockingMessage (const BlockingMessage&);
  30590. BlockingMessage& operator= (const BlockingMessage&);
  30591. };
  30592. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30593. : sharedEvents (0),
  30594. locked (false)
  30595. {
  30596. init (threadToCheck, 0);
  30597. }
  30598. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30599. : sharedEvents (0),
  30600. locked (false)
  30601. {
  30602. init (0, jobToCheckForExitSignal);
  30603. }
  30604. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30605. {
  30606. if (MessageManager::instance != 0)
  30607. {
  30608. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30609. {
  30610. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30611. }
  30612. else
  30613. {
  30614. if (threadToCheck == 0 && job == 0)
  30615. {
  30616. MessageManager::instance->lockingLock.enter();
  30617. }
  30618. else
  30619. {
  30620. while (! MessageManager::instance->lockingLock.tryEnter())
  30621. {
  30622. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30623. || (job != 0 && job->shouldExit()))
  30624. return;
  30625. Thread::sleep (1);
  30626. }
  30627. }
  30628. sharedEvents = new SharedEvents();
  30629. sharedEvents->incReferenceCount();
  30630. (new BlockingMessage (sharedEvents))->post();
  30631. while (! sharedEvents->lockedEvent.wait (50))
  30632. {
  30633. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30634. || (job != 0 && job->shouldExit()))
  30635. {
  30636. sharedEvents->releaseEvent.signal();
  30637. sharedEvents->decReferenceCount();
  30638. sharedEvents = 0;
  30639. MessageManager::instance->lockingLock.exit();
  30640. return;
  30641. }
  30642. }
  30643. jassert (MessageManager::instance->threadWithLock == 0);
  30644. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30645. locked = true;
  30646. }
  30647. }
  30648. }
  30649. MessageManagerLock::~MessageManagerLock() throw()
  30650. {
  30651. if (sharedEvents != 0)
  30652. {
  30653. jassert (MessageManager::instance == 0 || MessageManager::instance->currentThreadHasLockedMessageManager());
  30654. sharedEvents->releaseEvent.signal();
  30655. sharedEvents->decReferenceCount();
  30656. if (MessageManager::instance != 0)
  30657. {
  30658. MessageManager::instance->threadWithLock = 0;
  30659. MessageManager::instance->lockingLock.exit();
  30660. }
  30661. }
  30662. }
  30663. END_JUCE_NAMESPACE
  30664. /*** End of inlined file: juce_MessageManager.cpp ***/
  30665. /*** Start of inlined file: juce_MultiTimer.cpp ***/
  30666. BEGIN_JUCE_NAMESPACE
  30667. class MultiTimer::MultiTimerCallback : public Timer
  30668. {
  30669. public:
  30670. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30671. : timerId (timerId_),
  30672. owner (owner_)
  30673. {
  30674. }
  30675. ~MultiTimerCallback()
  30676. {
  30677. }
  30678. void timerCallback()
  30679. {
  30680. owner.timerCallback (timerId);
  30681. }
  30682. const int timerId;
  30683. private:
  30684. MultiTimer& owner;
  30685. };
  30686. MultiTimer::MultiTimer() throw()
  30687. {
  30688. }
  30689. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30690. {
  30691. }
  30692. MultiTimer::~MultiTimer()
  30693. {
  30694. const ScopedLock sl (timerListLock);
  30695. timers.clear();
  30696. }
  30697. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30698. {
  30699. const ScopedLock sl (timerListLock);
  30700. for (int i = timers.size(); --i >= 0;)
  30701. {
  30702. MultiTimerCallback* const t = timers.getUnchecked(i);
  30703. if (t->timerId == timerId)
  30704. {
  30705. t->startTimer (intervalInMilliseconds);
  30706. return;
  30707. }
  30708. }
  30709. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30710. timers.add (newTimer);
  30711. newTimer->startTimer (intervalInMilliseconds);
  30712. }
  30713. void MultiTimer::stopTimer (const int timerId) throw()
  30714. {
  30715. const ScopedLock sl (timerListLock);
  30716. for (int i = timers.size(); --i >= 0;)
  30717. {
  30718. MultiTimerCallback* const t = timers.getUnchecked(i);
  30719. if (t->timerId == timerId)
  30720. t->stopTimer();
  30721. }
  30722. }
  30723. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30724. {
  30725. const ScopedLock sl (timerListLock);
  30726. for (int i = timers.size(); --i >= 0;)
  30727. {
  30728. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30729. if (t->timerId == timerId)
  30730. return t->isTimerRunning();
  30731. }
  30732. return false;
  30733. }
  30734. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30735. {
  30736. const ScopedLock sl (timerListLock);
  30737. for (int i = timers.size(); --i >= 0;)
  30738. {
  30739. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30740. if (t->timerId == timerId)
  30741. return t->getTimerInterval();
  30742. }
  30743. return 0;
  30744. }
  30745. END_JUCE_NAMESPACE
  30746. /*** End of inlined file: juce_MultiTimer.cpp ***/
  30747. /*** Start of inlined file: juce_Timer.cpp ***/
  30748. BEGIN_JUCE_NAMESPACE
  30749. class InternalTimerThread : private Thread,
  30750. private MessageListener,
  30751. private DeletedAtShutdown,
  30752. private AsyncUpdater
  30753. {
  30754. public:
  30755. InternalTimerThread()
  30756. : Thread ("Juce Timer"),
  30757. firstTimer (0),
  30758. callbackNeeded (false)
  30759. {
  30760. triggerAsyncUpdate();
  30761. }
  30762. ~InternalTimerThread() throw()
  30763. {
  30764. stopThread (4000);
  30765. jassert (instance == this || instance == 0);
  30766. if (instance == this)
  30767. instance = 0;
  30768. }
  30769. void run()
  30770. {
  30771. uint32 lastTime = Time::getMillisecondCounter();
  30772. while (! threadShouldExit())
  30773. {
  30774. const uint32 now = Time::getMillisecondCounter();
  30775. if (now <= lastTime)
  30776. {
  30777. wait (2);
  30778. continue;
  30779. }
  30780. const int elapsed = now - lastTime;
  30781. lastTime = now;
  30782. int timeUntilFirstTimer = 1000;
  30783. {
  30784. const ScopedLock sl (lock);
  30785. decrementAllCounters (elapsed);
  30786. if (firstTimer != 0)
  30787. timeUntilFirstTimer = firstTimer->countdownMs;
  30788. }
  30789. if (timeUntilFirstTimer <= 0)
  30790. {
  30791. if (callbackNeeded.set (true))
  30792. {
  30793. postMessage (new Message());
  30794. const uint32 messageDeliveryTimeout = now + 2000;
  30795. while (callbackNeeded.get())
  30796. {
  30797. wait (4);
  30798. if (threadShouldExit())
  30799. return;
  30800. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30801. break;
  30802. }
  30803. }
  30804. }
  30805. else
  30806. {
  30807. // don't wait for too long because running this loop also helps keep the
  30808. // Time::getApproximateMillisecondTimer value stay up-to-date
  30809. wait (jlimit (1, 50, timeUntilFirstTimer));
  30810. }
  30811. }
  30812. }
  30813. void callTimers()
  30814. {
  30815. const ScopedLock sl (lock);
  30816. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30817. {
  30818. Timer* const t = firstTimer;
  30819. t->countdownMs = t->periodMs;
  30820. removeTimer (t);
  30821. addTimer (t);
  30822. const ScopedUnlock ul (lock);
  30823. JUCE_TRY
  30824. {
  30825. t->timerCallback();
  30826. }
  30827. JUCE_CATCH_EXCEPTION
  30828. }
  30829. callbackNeeded.set (false);
  30830. }
  30831. void handleMessage (const Message&)
  30832. {
  30833. callTimers();
  30834. }
  30835. void callTimersSynchronously()
  30836. {
  30837. if (! isThreadRunning())
  30838. {
  30839. // (This is relied on by some plugins in cases where the MM has
  30840. // had to restart and the async callback never started)
  30841. cancelPendingUpdate();
  30842. triggerAsyncUpdate();
  30843. }
  30844. callTimers();
  30845. }
  30846. static void callAnyTimersSynchronously()
  30847. {
  30848. if (InternalTimerThread::instance != 0)
  30849. InternalTimerThread::instance->callTimersSynchronously();
  30850. }
  30851. static inline void add (Timer* const tim) throw()
  30852. {
  30853. if (instance == 0)
  30854. instance = new InternalTimerThread();
  30855. const ScopedLock sl (instance->lock);
  30856. instance->addTimer (tim);
  30857. }
  30858. static inline void remove (Timer* const tim) throw()
  30859. {
  30860. if (instance != 0)
  30861. {
  30862. const ScopedLock sl (instance->lock);
  30863. instance->removeTimer (tim);
  30864. }
  30865. }
  30866. static inline void resetCounter (Timer* const tim,
  30867. const int newCounter) throw()
  30868. {
  30869. if (instance != 0)
  30870. {
  30871. tim->countdownMs = newCounter;
  30872. tim->periodMs = newCounter;
  30873. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30874. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30875. {
  30876. const ScopedLock sl (instance->lock);
  30877. instance->removeTimer (tim);
  30878. instance->addTimer (tim);
  30879. }
  30880. }
  30881. }
  30882. private:
  30883. friend class Timer;
  30884. static InternalTimerThread* instance;
  30885. static CriticalSection lock;
  30886. Timer* volatile firstTimer;
  30887. class AtomicBool
  30888. {
  30889. public:
  30890. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30891. ~AtomicBool() throw() {}
  30892. bool get() const throw() { return value != 0; }
  30893. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30894. private:
  30895. int32 value;
  30896. AtomicBool (const AtomicBool&);
  30897. AtomicBool& operator= (const AtomicBool&);
  30898. };
  30899. AtomicBool callbackNeeded;
  30900. void addTimer (Timer* const t) throw()
  30901. {
  30902. #ifdef JUCE_DEBUG
  30903. Timer* tt = firstTimer;
  30904. while (tt != 0)
  30905. {
  30906. // trying to add a timer that's already here - shouldn't get to this point,
  30907. // so if you get this assertion, let me know!
  30908. jassert (tt != t);
  30909. tt = tt->next;
  30910. }
  30911. jassert (t->previous == 0 && t->next == 0);
  30912. #endif
  30913. Timer* i = firstTimer;
  30914. if (i == 0 || i->countdownMs > t->countdownMs)
  30915. {
  30916. t->next = firstTimer;
  30917. firstTimer = t;
  30918. }
  30919. else
  30920. {
  30921. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30922. i = i->next;
  30923. jassert (i != 0);
  30924. t->next = i->next;
  30925. t->previous = i;
  30926. i->next = t;
  30927. }
  30928. if (t->next != 0)
  30929. t->next->previous = t;
  30930. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30931. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30932. notify();
  30933. }
  30934. void removeTimer (Timer* const t) throw()
  30935. {
  30936. #ifdef JUCE_DEBUG
  30937. Timer* tt = firstTimer;
  30938. bool found = false;
  30939. while (tt != 0)
  30940. {
  30941. if (tt == t)
  30942. {
  30943. found = true;
  30944. break;
  30945. }
  30946. tt = tt->next;
  30947. }
  30948. // trying to remove a timer that's not here - shouldn't get to this point,
  30949. // so if you get this assertion, let me know!
  30950. jassert (found);
  30951. #endif
  30952. if (t->previous != 0)
  30953. {
  30954. jassert (firstTimer != t);
  30955. t->previous->next = t->next;
  30956. }
  30957. else
  30958. {
  30959. jassert (firstTimer == t);
  30960. firstTimer = t->next;
  30961. }
  30962. if (t->next != 0)
  30963. t->next->previous = t->previous;
  30964. t->next = 0;
  30965. t->previous = 0;
  30966. }
  30967. void decrementAllCounters (const int numMillisecs) const
  30968. {
  30969. Timer* t = firstTimer;
  30970. while (t != 0)
  30971. {
  30972. t->countdownMs -= numMillisecs;
  30973. t = t->next;
  30974. }
  30975. }
  30976. void handleAsyncUpdate()
  30977. {
  30978. startThread (7);
  30979. }
  30980. InternalTimerThread (const InternalTimerThread&);
  30981. InternalTimerThread& operator= (const InternalTimerThread&);
  30982. };
  30983. InternalTimerThread* InternalTimerThread::instance = 0;
  30984. CriticalSection InternalTimerThread::lock;
  30985. void juce_callAnyTimersSynchronously()
  30986. {
  30987. InternalTimerThread::callAnyTimersSynchronously();
  30988. }
  30989. #ifdef JUCE_DEBUG
  30990. static SortedSet <Timer*> activeTimers;
  30991. #endif
  30992. Timer::Timer() throw()
  30993. : countdownMs (0),
  30994. periodMs (0),
  30995. previous (0),
  30996. next (0)
  30997. {
  30998. #ifdef JUCE_DEBUG
  30999. activeTimers.add (this);
  31000. #endif
  31001. }
  31002. Timer::Timer (const Timer&) throw()
  31003. : countdownMs (0),
  31004. periodMs (0),
  31005. previous (0),
  31006. next (0)
  31007. {
  31008. #ifdef JUCE_DEBUG
  31009. activeTimers.add (this);
  31010. #endif
  31011. }
  31012. Timer::~Timer()
  31013. {
  31014. stopTimer();
  31015. #ifdef JUCE_DEBUG
  31016. activeTimers.removeValue (this);
  31017. #endif
  31018. }
  31019. void Timer::startTimer (const int interval) throw()
  31020. {
  31021. const ScopedLock sl (InternalTimerThread::lock);
  31022. #ifdef JUCE_DEBUG
  31023. // this isn't a valid object! Your timer might be a dangling pointer or something..
  31024. jassert (activeTimers.contains (this));
  31025. #endif
  31026. if (periodMs == 0)
  31027. {
  31028. countdownMs = interval;
  31029. periodMs = jmax (1, interval);
  31030. InternalTimerThread::add (this);
  31031. }
  31032. else
  31033. {
  31034. InternalTimerThread::resetCounter (this, interval);
  31035. }
  31036. }
  31037. void Timer::stopTimer() throw()
  31038. {
  31039. const ScopedLock sl (InternalTimerThread::lock);
  31040. #ifdef JUCE_DEBUG
  31041. // this isn't a valid object! Your timer might be a dangling pointer or something..
  31042. jassert (activeTimers.contains (this));
  31043. #endif
  31044. if (periodMs > 0)
  31045. {
  31046. InternalTimerThread::remove (this);
  31047. periodMs = 0;
  31048. }
  31049. }
  31050. END_JUCE_NAMESPACE
  31051. /*** End of inlined file: juce_Timer.cpp ***/
  31052. #endif
  31053. #if JUCE_BUILD_GUI
  31054. /*** Start of inlined file: juce_Component.cpp ***/
  31055. BEGIN_JUCE_NAMESPACE
  31056. Component* Component::currentlyFocusedComponent = 0;
  31057. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  31058. static Array <int> modalReturnValues;
  31059. enum ComponentMessageNumbers
  31060. {
  31061. customCommandMessage = 0x7fff0001,
  31062. exitModalStateMessage = 0x7fff0002
  31063. };
  31064. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  31065. static uint32 nextComponentUID = 0;
  31066. Component::Component()
  31067. : parentComponent_ (0),
  31068. componentUID (++nextComponentUID),
  31069. numDeepMouseListeners (0),
  31070. lookAndFeel_ (0),
  31071. effect_ (0),
  31072. bufferedImage_ (0),
  31073. mouseListeners_ (0),
  31074. keyListeners_ (0),
  31075. componentFlags_ (0)
  31076. {
  31077. }
  31078. Component::Component (const String& name)
  31079. : componentName_ (name),
  31080. parentComponent_ (0),
  31081. componentUID (++nextComponentUID),
  31082. numDeepMouseListeners (0),
  31083. lookAndFeel_ (0),
  31084. effect_ (0),
  31085. bufferedImage_ (0),
  31086. mouseListeners_ (0),
  31087. keyListeners_ (0),
  31088. componentFlags_ (0)
  31089. {
  31090. }
  31091. Component::~Component()
  31092. {
  31093. componentListeners.call (&ComponentListener::componentBeingDeleted, *this);
  31094. if (parentComponent_ != 0)
  31095. {
  31096. parentComponent_->removeChildComponent (this);
  31097. }
  31098. else if ((currentlyFocusedComponent == this)
  31099. || isParentOf (currentlyFocusedComponent))
  31100. {
  31101. giveAwayFocus();
  31102. }
  31103. if (flags.hasHeavyweightPeerFlag)
  31104. removeFromDesktop();
  31105. modalComponentStack.removeValue (this);
  31106. for (int i = childComponentList_.size(); --i >= 0;)
  31107. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  31108. delete bufferedImage_;
  31109. delete mouseListeners_;
  31110. delete keyListeners_;
  31111. }
  31112. void Component::setName (const String& name)
  31113. {
  31114. // if component methods are being called from threads other than the message
  31115. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31116. checkMessageManagerIsLocked
  31117. if (componentName_ != name)
  31118. {
  31119. componentName_ = name;
  31120. if (flags.hasHeavyweightPeerFlag)
  31121. {
  31122. ComponentPeer* const peer = getPeer();
  31123. jassert (peer != 0);
  31124. if (peer != 0)
  31125. peer->setTitle (name);
  31126. }
  31127. BailOutChecker checker (this);
  31128. componentListeners.callChecked (checker, &ComponentListener::componentNameChanged, *this);
  31129. }
  31130. }
  31131. void Component::setVisible (bool shouldBeVisible)
  31132. {
  31133. if (flags.visibleFlag != shouldBeVisible)
  31134. {
  31135. // if component methods are being called from threads other than the message
  31136. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31137. checkMessageManagerIsLocked
  31138. SafePointer<Component> safePointer (this);
  31139. flags.visibleFlag = shouldBeVisible;
  31140. internalRepaint (0, 0, getWidth(), getHeight());
  31141. sendFakeMouseMove();
  31142. if (! shouldBeVisible)
  31143. {
  31144. if (currentlyFocusedComponent == this
  31145. || isParentOf (currentlyFocusedComponent))
  31146. {
  31147. if (parentComponent_ != 0)
  31148. parentComponent_->grabKeyboardFocus();
  31149. else
  31150. giveAwayFocus();
  31151. }
  31152. }
  31153. sendVisibilityChangeMessage();
  31154. if (safePointer != 0 && flags.hasHeavyweightPeerFlag)
  31155. {
  31156. ComponentPeer* const peer = getPeer();
  31157. jassert (peer != 0);
  31158. if (peer != 0)
  31159. {
  31160. peer->setVisible (shouldBeVisible);
  31161. internalHierarchyChanged();
  31162. }
  31163. }
  31164. }
  31165. }
  31166. void Component::visibilityChanged()
  31167. {
  31168. }
  31169. void Component::sendVisibilityChangeMessage()
  31170. {
  31171. BailOutChecker checker (this);
  31172. visibilityChanged();
  31173. if (! checker.shouldBailOut())
  31174. componentListeners.callChecked (checker, &ComponentListener::componentVisibilityChanged, *this);
  31175. }
  31176. bool Component::isShowing() const
  31177. {
  31178. if (flags.visibleFlag)
  31179. {
  31180. if (parentComponent_ != 0)
  31181. {
  31182. return parentComponent_->isShowing();
  31183. }
  31184. else
  31185. {
  31186. const ComponentPeer* const peer = getPeer();
  31187. return peer != 0 && ! peer->isMinimised();
  31188. }
  31189. }
  31190. return false;
  31191. }
  31192. class FadeOutProxyComponent : public Component,
  31193. public Timer
  31194. {
  31195. public:
  31196. FadeOutProxyComponent (Component* comp,
  31197. const int fadeLengthMs,
  31198. const int deltaXToMove,
  31199. const int deltaYToMove,
  31200. const float scaleFactorAtEnd)
  31201. : lastTime (0),
  31202. alpha (1.0f),
  31203. scale (1.0f)
  31204. {
  31205. image = comp->createComponentSnapshot (Rectangle<int> (0, 0, comp->getWidth(), comp->getHeight()));
  31206. setBounds (comp->getBounds());
  31207. comp->getParentComponent()->addAndMakeVisible (this);
  31208. toBehind (comp);
  31209. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  31210. centreX = comp->getX() + comp->getWidth() * 0.5f;
  31211. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  31212. centreY = comp->getY() + comp->getHeight() * 0.5f;
  31213. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  31214. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  31215. setInterceptsMouseClicks (false, false);
  31216. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  31217. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  31218. }
  31219. ~FadeOutProxyComponent()
  31220. {
  31221. delete image;
  31222. }
  31223. void paint (Graphics& g)
  31224. {
  31225. g.setOpacity (alpha);
  31226. g.drawImage (image,
  31227. 0, 0, getWidth(), getHeight(),
  31228. 0, 0, image->getWidth(), image->getHeight());
  31229. }
  31230. void timerCallback()
  31231. {
  31232. const uint32 now = Time::getMillisecondCounter();
  31233. if (lastTime == 0)
  31234. lastTime = now;
  31235. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  31236. lastTime = now;
  31237. alpha += alphaChangePerMs * msPassed;
  31238. if (alpha > 0)
  31239. {
  31240. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  31241. {
  31242. centreX += xChangePerMs * msPassed;
  31243. centreY += yChangePerMs * msPassed;
  31244. scale += scaleChangePerMs * msPassed;
  31245. const int w = roundToInt (image->getWidth() * scale);
  31246. const int h = roundToInt (image->getHeight() * scale);
  31247. setBounds (roundToInt (centreX) - w / 2,
  31248. roundToInt (centreY) - h / 2,
  31249. w, h);
  31250. }
  31251. repaint();
  31252. }
  31253. else
  31254. {
  31255. delete this;
  31256. }
  31257. }
  31258. juce_UseDebuggingNewOperator
  31259. private:
  31260. Image* image;
  31261. uint32 lastTime;
  31262. float alpha, alphaChangePerMs;
  31263. float centreX, xChangePerMs;
  31264. float centreY, yChangePerMs;
  31265. float scale, scaleChangePerMs;
  31266. FadeOutProxyComponent (const FadeOutProxyComponent&);
  31267. FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  31268. };
  31269. void Component::fadeOutComponent (const int millisecondsToFade,
  31270. const int deltaXToMove,
  31271. const int deltaYToMove,
  31272. const float scaleFactorAtEnd)
  31273. {
  31274. //xxx won't work for comps without parents
  31275. if (isShowing() && millisecondsToFade > 0)
  31276. new FadeOutProxyComponent (this, millisecondsToFade,
  31277. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  31278. setVisible (false);
  31279. }
  31280. bool Component::isValidComponent() const
  31281. {
  31282. return (this != 0) && isValidMessageListener();
  31283. }
  31284. void* Component::getWindowHandle() const
  31285. {
  31286. const ComponentPeer* const peer = getPeer();
  31287. if (peer != 0)
  31288. return peer->getNativeHandle();
  31289. return 0;
  31290. }
  31291. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31292. {
  31293. // if component methods are being called from threads other than the message
  31294. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31295. checkMessageManagerIsLocked
  31296. if (isOpaque())
  31297. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31298. else
  31299. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31300. int currentStyleFlags = 0;
  31301. // don't use getPeer(), so that we only get the peer that's specifically
  31302. // for this comp, and not for one of its parents.
  31303. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31304. if (peer != 0)
  31305. currentStyleFlags = peer->getStyleFlags();
  31306. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31307. {
  31308. SafePointer<Component> safePointer (this);
  31309. #if JUCE_LINUX
  31310. // it's wise to give the component a non-zero size before
  31311. // putting it on the desktop, as X windows get confused by this, and
  31312. // a (1, 1) minimum size is enforced here.
  31313. setSize (jmax (1, getWidth()),
  31314. jmax (1, getHeight()));
  31315. #endif
  31316. const Point<int> topLeft (relativePositionToGlobal (Point<int> (0, 0)));
  31317. bool wasFullscreen = false;
  31318. bool wasMinimised = false;
  31319. ComponentBoundsConstrainer* currentConstainer = 0;
  31320. Rectangle<int> oldNonFullScreenBounds;
  31321. if (peer != 0)
  31322. {
  31323. wasFullscreen = peer->isFullScreen();
  31324. wasMinimised = peer->isMinimised();
  31325. currentConstainer = peer->getConstrainer();
  31326. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31327. removeFromDesktop();
  31328. setTopLeftPosition (topLeft.getX(), topLeft.getY());
  31329. }
  31330. if (parentComponent_ != 0)
  31331. parentComponent_->removeChildComponent (this);
  31332. if (safePointer != 0)
  31333. {
  31334. flags.hasHeavyweightPeerFlag = true;
  31335. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31336. Desktop::getInstance().addDesktopComponent (this);
  31337. bounds_.setPosition (topLeft);
  31338. peer->setBounds (topLeft.getX(), topLeft.getY(), getWidth(), getHeight(), false);
  31339. peer->setVisible (isVisible());
  31340. if (wasFullscreen)
  31341. {
  31342. peer->setFullScreen (true);
  31343. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31344. }
  31345. if (wasMinimised)
  31346. peer->setMinimised (true);
  31347. if (isAlwaysOnTop())
  31348. peer->setAlwaysOnTop (true);
  31349. peer->setConstrainer (currentConstainer);
  31350. repaint();
  31351. }
  31352. internalHierarchyChanged();
  31353. }
  31354. }
  31355. void Component::removeFromDesktop()
  31356. {
  31357. // if component methods are being called from threads other than the message
  31358. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31359. checkMessageManagerIsLocked
  31360. if (flags.hasHeavyweightPeerFlag)
  31361. {
  31362. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31363. flags.hasHeavyweightPeerFlag = false;
  31364. jassert (peer != 0);
  31365. delete peer;
  31366. Desktop::getInstance().removeDesktopComponent (this);
  31367. }
  31368. }
  31369. bool Component::isOnDesktop() const throw()
  31370. {
  31371. return flags.hasHeavyweightPeerFlag;
  31372. }
  31373. void Component::userTriedToCloseWindow()
  31374. {
  31375. /* This means that the user's trying to get rid of your window with the 'close window' system
  31376. menu option (on windows) or possibly the task manager - you should really handle this
  31377. and delete or hide your component in an appropriate way.
  31378. If you want to ignore the event and don't want to trigger this assertion, just override
  31379. this method and do nothing.
  31380. */
  31381. jassertfalse
  31382. }
  31383. void Component::minimisationStateChanged (bool)
  31384. {
  31385. }
  31386. void Component::setOpaque (const bool shouldBeOpaque)
  31387. {
  31388. if (shouldBeOpaque != flags.opaqueFlag)
  31389. {
  31390. flags.opaqueFlag = shouldBeOpaque;
  31391. if (flags.hasHeavyweightPeerFlag)
  31392. {
  31393. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31394. if (peer != 0)
  31395. {
  31396. // to make it recreate the heavyweight window
  31397. addToDesktop (peer->getStyleFlags());
  31398. }
  31399. }
  31400. repaint();
  31401. }
  31402. }
  31403. bool Component::isOpaque() const throw()
  31404. {
  31405. return flags.opaqueFlag;
  31406. }
  31407. void Component::setBufferedToImage (const bool shouldBeBuffered)
  31408. {
  31409. if (shouldBeBuffered != flags.bufferToImageFlag)
  31410. {
  31411. deleteAndZero (bufferedImage_);
  31412. flags.bufferToImageFlag = shouldBeBuffered;
  31413. }
  31414. }
  31415. void Component::toFront (const bool setAsForeground)
  31416. {
  31417. // if component methods are being called from threads other than the message
  31418. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31419. checkMessageManagerIsLocked
  31420. if (flags.hasHeavyweightPeerFlag)
  31421. {
  31422. ComponentPeer* const peer = getPeer();
  31423. if (peer != 0)
  31424. {
  31425. peer->toFront (setAsForeground);
  31426. if (setAsForeground && ! hasKeyboardFocus (true))
  31427. grabKeyboardFocus();
  31428. }
  31429. }
  31430. else if (parentComponent_ != 0)
  31431. {
  31432. if (parentComponent_->childComponentList_.getLast() != this)
  31433. {
  31434. const int index = parentComponent_->childComponentList_.indexOf (this);
  31435. if (index >= 0)
  31436. {
  31437. int insertIndex = -1;
  31438. if (! flags.alwaysOnTopFlag)
  31439. {
  31440. insertIndex = parentComponent_->childComponentList_.size() - 1;
  31441. while (insertIndex > 0
  31442. && parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31443. {
  31444. --insertIndex;
  31445. }
  31446. }
  31447. if (index != insertIndex)
  31448. {
  31449. parentComponent_->childComponentList_.move (index, insertIndex);
  31450. sendFakeMouseMove();
  31451. repaintParent();
  31452. }
  31453. }
  31454. }
  31455. if (setAsForeground)
  31456. {
  31457. internalBroughtToFront();
  31458. grabKeyboardFocus();
  31459. }
  31460. }
  31461. }
  31462. void Component::toBehind (Component* const other)
  31463. {
  31464. if (other != 0)
  31465. {
  31466. // the two components must belong to the same parent..
  31467. jassert (parentComponent_ == other->parentComponent_);
  31468. if (parentComponent_ != 0)
  31469. {
  31470. const int index = parentComponent_->childComponentList_.indexOf (this);
  31471. int otherIndex = parentComponent_->childComponentList_.indexOf (other);
  31472. if (index >= 0
  31473. && otherIndex >= 0
  31474. && index != otherIndex - 1
  31475. && other != this)
  31476. {
  31477. if (index < otherIndex)
  31478. --otherIndex;
  31479. parentComponent_->childComponentList_.move (index, otherIndex);
  31480. sendFakeMouseMove();
  31481. repaintParent();
  31482. }
  31483. }
  31484. else if (isOnDesktop())
  31485. {
  31486. jassert (other->isOnDesktop());
  31487. if (other->isOnDesktop())
  31488. {
  31489. ComponentPeer* const us = getPeer();
  31490. ComponentPeer* const them = other->getPeer();
  31491. jassert (us != 0 && them != 0);
  31492. if (us != 0 && them != 0)
  31493. us->toBehind (them);
  31494. }
  31495. }
  31496. }
  31497. }
  31498. void Component::toBack()
  31499. {
  31500. if (isOnDesktop())
  31501. {
  31502. jassertfalse //xxx need to add this to native window
  31503. }
  31504. else if (parentComponent_ != 0
  31505. && parentComponent_->childComponentList_.getFirst() != this)
  31506. {
  31507. const int index = parentComponent_->childComponentList_.indexOf (this);
  31508. if (index > 0)
  31509. {
  31510. int insertIndex = 0;
  31511. if (flags.alwaysOnTopFlag)
  31512. {
  31513. while (insertIndex < parentComponent_->childComponentList_.size()
  31514. && ! parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31515. {
  31516. ++insertIndex;
  31517. }
  31518. }
  31519. if (index != insertIndex)
  31520. {
  31521. parentComponent_->childComponentList_.move (index, insertIndex);
  31522. sendFakeMouseMove();
  31523. repaintParent();
  31524. }
  31525. }
  31526. }
  31527. }
  31528. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31529. {
  31530. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31531. {
  31532. flags.alwaysOnTopFlag = shouldStayOnTop;
  31533. if (isOnDesktop())
  31534. {
  31535. ComponentPeer* const peer = getPeer();
  31536. jassert (peer != 0);
  31537. if (peer != 0)
  31538. {
  31539. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31540. {
  31541. // some kinds of peer can't change their always-on-top status, so
  31542. // for these, we'll need to create a new window
  31543. const int oldFlags = peer->getStyleFlags();
  31544. removeFromDesktop();
  31545. addToDesktop (oldFlags);
  31546. }
  31547. }
  31548. }
  31549. if (shouldStayOnTop)
  31550. toFront (false);
  31551. internalHierarchyChanged();
  31552. }
  31553. }
  31554. bool Component::isAlwaysOnTop() const throw()
  31555. {
  31556. return flags.alwaysOnTopFlag;
  31557. }
  31558. int Component::proportionOfWidth (const float proportion) const throw()
  31559. {
  31560. return roundToInt (proportion * bounds_.getWidth());
  31561. }
  31562. int Component::proportionOfHeight (const float proportion) const throw()
  31563. {
  31564. return roundToInt (proportion * bounds_.getHeight());
  31565. }
  31566. int Component::getParentWidth() const throw()
  31567. {
  31568. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31569. : getParentMonitorArea().getWidth();
  31570. }
  31571. int Component::getParentHeight() const throw()
  31572. {
  31573. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31574. : getParentMonitorArea().getHeight();
  31575. }
  31576. int Component::getScreenX() const
  31577. {
  31578. return getScreenPosition().getX();
  31579. }
  31580. int Component::getScreenY() const
  31581. {
  31582. return getScreenPosition().getY();
  31583. }
  31584. const Point<int> Component::getScreenPosition() const
  31585. {
  31586. return (parentComponent_ != 0) ? parentComponent_->getScreenPosition() + getPosition()
  31587. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenPosition()
  31588. : getPosition());
  31589. }
  31590. const Rectangle<int> Component::getScreenBounds() const
  31591. {
  31592. return bounds_.withPosition (getScreenPosition());
  31593. }
  31594. const Point<int> Component::relativePositionToGlobal (const Point<int>& relativePosition) const
  31595. {
  31596. const Component* c = this;
  31597. Point<int> p (relativePosition);
  31598. do
  31599. {
  31600. if (c->flags.hasHeavyweightPeerFlag)
  31601. return c->getPeer()->relativePositionToGlobal (p);
  31602. p += c->getPosition();
  31603. c = c->parentComponent_;
  31604. }
  31605. while (c != 0);
  31606. return p;
  31607. }
  31608. const Point<int> Component::globalPositionToRelative (const Point<int>& screenPosition) const
  31609. {
  31610. if (flags.hasHeavyweightPeerFlag)
  31611. {
  31612. return getPeer()->globalPositionToRelative (screenPosition);
  31613. }
  31614. else
  31615. {
  31616. if (parentComponent_ != 0)
  31617. return parentComponent_->globalPositionToRelative (screenPosition) - getPosition();
  31618. return screenPosition - getPosition();
  31619. }
  31620. }
  31621. const Point<int> Component::relativePositionToOtherComponent (const Component* const targetComponent, const Point<int>& positionRelativeToThis) const
  31622. {
  31623. Point<int> p (positionRelativeToThis);
  31624. if (targetComponent != 0)
  31625. {
  31626. const Component* c = this;
  31627. do
  31628. {
  31629. if (c == targetComponent)
  31630. return p;
  31631. if (c->flags.hasHeavyweightPeerFlag)
  31632. {
  31633. p = c->getPeer()->relativePositionToGlobal (p);
  31634. break;
  31635. }
  31636. p += c->getPosition();
  31637. c = c->parentComponent_;
  31638. }
  31639. while (c != 0);
  31640. p = targetComponent->globalPositionToRelative (p);
  31641. }
  31642. return p;
  31643. }
  31644. void Component::setBounds (int x, int y, int w, int h)
  31645. {
  31646. // if component methods are being called from threads other than the message
  31647. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31648. checkMessageManagerIsLocked
  31649. if (w < 0) w = 0;
  31650. if (h < 0) h = 0;
  31651. const bool wasResized = (getWidth() != w || getHeight() != h);
  31652. const bool wasMoved = (getX() != x || getY() != y);
  31653. #ifdef JUCE_DEBUG
  31654. // It's a very bad idea to try to resize a window during its paint() method!
  31655. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31656. #endif
  31657. if (wasMoved || wasResized)
  31658. {
  31659. if (flags.visibleFlag)
  31660. {
  31661. // send a fake mouse move to trigger enter/exit messages if needed..
  31662. sendFakeMouseMove();
  31663. if (! flags.hasHeavyweightPeerFlag)
  31664. repaintParent();
  31665. }
  31666. bounds_.setBounds (x, y, w, h);
  31667. if (wasResized)
  31668. repaint();
  31669. else if (! flags.hasHeavyweightPeerFlag)
  31670. repaintParent();
  31671. if (flags.hasHeavyweightPeerFlag)
  31672. {
  31673. ComponentPeer* const peer = getPeer();
  31674. if (peer != 0)
  31675. {
  31676. if (wasMoved && wasResized)
  31677. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31678. else if (wasMoved)
  31679. peer->setPosition (getX(), getY());
  31680. else if (wasResized)
  31681. peer->setSize (getWidth(), getHeight());
  31682. }
  31683. }
  31684. sendMovedResizedMessages (wasMoved, wasResized);
  31685. }
  31686. }
  31687. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31688. {
  31689. JUCE_TRY
  31690. {
  31691. if (wasMoved)
  31692. moved();
  31693. if (wasResized)
  31694. {
  31695. resized();
  31696. for (int i = childComponentList_.size(); --i >= 0;)
  31697. {
  31698. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31699. i = jmin (i, childComponentList_.size());
  31700. }
  31701. }
  31702. BailOutChecker checker (this);
  31703. if (parentComponent_ != 0)
  31704. parentComponent_->childBoundsChanged (this);
  31705. if (! checker.shouldBailOut())
  31706. componentListeners.callChecked (checker, &ComponentListener::componentMovedOrResized,
  31707. *this, wasMoved, wasResized);
  31708. }
  31709. JUCE_CATCH_EXCEPTION
  31710. }
  31711. void Component::setSize (const int w, const int h)
  31712. {
  31713. setBounds (getX(), getY(), w, h);
  31714. }
  31715. void Component::setTopLeftPosition (const int x, const int y)
  31716. {
  31717. setBounds (x, y, getWidth(), getHeight());
  31718. }
  31719. void Component::setTopRightPosition (const int x, const int y)
  31720. {
  31721. setTopLeftPosition (x - getWidth(), y);
  31722. }
  31723. void Component::setBounds (const Rectangle<int>& r)
  31724. {
  31725. setBounds (r.getX(),
  31726. r.getY(),
  31727. r.getWidth(),
  31728. r.getHeight());
  31729. }
  31730. void Component::setBoundsRelative (const float x, const float y,
  31731. const float w, const float h)
  31732. {
  31733. const int pw = getParentWidth();
  31734. const int ph = getParentHeight();
  31735. setBounds (roundToInt (x * pw),
  31736. roundToInt (y * ph),
  31737. roundToInt (w * pw),
  31738. roundToInt (h * ph));
  31739. }
  31740. void Component::setCentrePosition (const int x, const int y)
  31741. {
  31742. setTopLeftPosition (x - getWidth() / 2,
  31743. y - getHeight() / 2);
  31744. }
  31745. void Component::setCentreRelative (const float x, const float y)
  31746. {
  31747. setCentrePosition (roundToInt (getParentWidth() * x),
  31748. roundToInt (getParentHeight() * y));
  31749. }
  31750. void Component::centreWithSize (const int width, const int height)
  31751. {
  31752. setBounds ((getParentWidth() - width) / 2,
  31753. (getParentHeight() - height) / 2,
  31754. width,
  31755. height);
  31756. }
  31757. void Component::setBoundsInset (const BorderSize& borders)
  31758. {
  31759. setBounds (borders.getLeft(),
  31760. borders.getTop(),
  31761. getParentWidth() - (borders.getLeftAndRight()),
  31762. getParentHeight() - (borders.getTopAndBottom()));
  31763. }
  31764. void Component::setBoundsToFit (int x, int y, int width, int height,
  31765. const Justification& justification,
  31766. const bool onlyReduceInSize)
  31767. {
  31768. // it's no good calling this method unless both the component and
  31769. // target rectangle have a finite size.
  31770. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31771. if (getWidth() > 0 && getHeight() > 0
  31772. && width > 0 && height > 0)
  31773. {
  31774. int newW, newH;
  31775. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31776. {
  31777. newW = getWidth();
  31778. newH = getHeight();
  31779. }
  31780. else
  31781. {
  31782. const double imageRatio = getHeight() / (double) getWidth();
  31783. const double targetRatio = height / (double) width;
  31784. if (imageRatio <= targetRatio)
  31785. {
  31786. newW = width;
  31787. newH = jmin (height, roundToInt (newW * imageRatio));
  31788. }
  31789. else
  31790. {
  31791. newH = height;
  31792. newW = jmin (width, roundToInt (newH / imageRatio));
  31793. }
  31794. }
  31795. if (newW > 0 && newH > 0)
  31796. {
  31797. int newX, newY;
  31798. justification.applyToRectangle (newX, newY, newW, newH,
  31799. x, y, width, height);
  31800. setBounds (newX, newY, newW, newH);
  31801. }
  31802. }
  31803. }
  31804. bool Component::hitTest (int x, int y)
  31805. {
  31806. if (! flags.ignoresMouseClicksFlag)
  31807. return true;
  31808. if (flags.allowChildMouseClicksFlag)
  31809. {
  31810. for (int i = getNumChildComponents(); --i >= 0;)
  31811. {
  31812. Component* const c = getChildComponent (i);
  31813. if (c->isVisible()
  31814. && c->bounds_.contains (x, y)
  31815. && c->hitTest (x - c->getX(),
  31816. y - c->getY()))
  31817. {
  31818. return true;
  31819. }
  31820. }
  31821. }
  31822. return false;
  31823. }
  31824. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31825. const bool allowClicksOnChildComponents) throw()
  31826. {
  31827. flags.ignoresMouseClicksFlag = ! allowClicks;
  31828. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31829. }
  31830. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31831. bool& allowsClicksOnChildComponents) const throw()
  31832. {
  31833. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31834. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31835. }
  31836. bool Component::contains (const int x, const int y)
  31837. {
  31838. if (((unsigned int) x) < (unsigned int) getWidth()
  31839. && ((unsigned int) y) < (unsigned int) getHeight()
  31840. && hitTest (x, y))
  31841. {
  31842. if (parentComponent_ != 0)
  31843. {
  31844. return parentComponent_->contains (x + getX(),
  31845. y + getY());
  31846. }
  31847. else if (flags.hasHeavyweightPeerFlag)
  31848. {
  31849. const ComponentPeer* const peer = getPeer();
  31850. if (peer != 0)
  31851. return peer->contains (Point<int> (x, y), true);
  31852. }
  31853. }
  31854. return false;
  31855. }
  31856. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31857. {
  31858. if (! contains (x, y))
  31859. return false;
  31860. Component* p = this;
  31861. while (p->parentComponent_ != 0)
  31862. {
  31863. x += p->getX();
  31864. y += p->getY();
  31865. p = p->parentComponent_;
  31866. }
  31867. const Component* const c = p->getComponentAt (x, y);
  31868. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31869. }
  31870. Component* Component::getComponentAt (const Point<int>& position)
  31871. {
  31872. return getComponentAt (position.getX(), position.getY());
  31873. }
  31874. Component* Component::getComponentAt (const int x, const int y)
  31875. {
  31876. if (flags.visibleFlag
  31877. && ((unsigned int) x) < (unsigned int) getWidth()
  31878. && ((unsigned int) y) < (unsigned int) getHeight()
  31879. && hitTest (x, y))
  31880. {
  31881. for (int i = childComponentList_.size(); --i >= 0;)
  31882. {
  31883. Component* const child = childComponentList_.getUnchecked(i);
  31884. Component* const c = child->getComponentAt (x - child->getX(),
  31885. y - child->getY());
  31886. if (c != 0)
  31887. return c;
  31888. }
  31889. return this;
  31890. }
  31891. return 0;
  31892. }
  31893. void Component::addChildComponent (Component* const child, int zOrder)
  31894. {
  31895. // if component methods are being called from threads other than the message
  31896. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31897. checkMessageManagerIsLocked
  31898. if (child != 0 && child->parentComponent_ != this)
  31899. {
  31900. if (child->parentComponent_ != 0)
  31901. child->parentComponent_->removeChildComponent (child);
  31902. else
  31903. child->removeFromDesktop();
  31904. child->parentComponent_ = this;
  31905. if (child->isVisible())
  31906. child->repaintParent();
  31907. if (! child->isAlwaysOnTop())
  31908. {
  31909. if (zOrder < 0 || zOrder > childComponentList_.size())
  31910. zOrder = childComponentList_.size();
  31911. while (zOrder > 0)
  31912. {
  31913. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31914. break;
  31915. --zOrder;
  31916. }
  31917. }
  31918. childComponentList_.insert (zOrder, child);
  31919. child->internalHierarchyChanged();
  31920. internalChildrenChanged();
  31921. }
  31922. }
  31923. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31924. {
  31925. if (child != 0)
  31926. {
  31927. child->setVisible (true);
  31928. addChildComponent (child, zOrder);
  31929. }
  31930. }
  31931. void Component::removeChildComponent (Component* const child)
  31932. {
  31933. removeChildComponent (childComponentList_.indexOf (child));
  31934. }
  31935. Component* Component::removeChildComponent (const int index)
  31936. {
  31937. // if component methods are being called from threads other than the message
  31938. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31939. checkMessageManagerIsLocked
  31940. Component* const child = childComponentList_ [index];
  31941. if (child != 0)
  31942. {
  31943. sendFakeMouseMove();
  31944. child->repaintParent();
  31945. childComponentList_.remove (index);
  31946. child->parentComponent_ = 0;
  31947. JUCE_TRY
  31948. {
  31949. if ((currentlyFocusedComponent == child)
  31950. || child->isParentOf (currentlyFocusedComponent))
  31951. {
  31952. // get rid first to force the grabKeyboardFocus to change to us.
  31953. giveAwayFocus();
  31954. grabKeyboardFocus();
  31955. }
  31956. }
  31957. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31958. catch (const std::exception& e)
  31959. {
  31960. currentlyFocusedComponent = 0;
  31961. Desktop::getInstance().triggerFocusCallback();
  31962. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31963. }
  31964. catch (...)
  31965. {
  31966. currentlyFocusedComponent = 0;
  31967. Desktop::getInstance().triggerFocusCallback();
  31968. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31969. }
  31970. #endif
  31971. child->internalHierarchyChanged();
  31972. internalChildrenChanged();
  31973. }
  31974. return child;
  31975. }
  31976. void Component::removeAllChildren()
  31977. {
  31978. for (int i = childComponentList_.size(); --i >= 0;)
  31979. removeChildComponent (i);
  31980. }
  31981. void Component::deleteAllChildren()
  31982. {
  31983. for (int i = childComponentList_.size(); --i >= 0;)
  31984. delete (removeChildComponent (i));
  31985. }
  31986. int Component::getNumChildComponents() const throw()
  31987. {
  31988. return childComponentList_.size();
  31989. }
  31990. Component* Component::getChildComponent (const int index) const throw()
  31991. {
  31992. return childComponentList_ [index];
  31993. }
  31994. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  31995. {
  31996. return childComponentList_.indexOf (const_cast <Component*> (child));
  31997. }
  31998. Component* Component::getTopLevelComponent() const throw()
  31999. {
  32000. const Component* comp = this;
  32001. while (comp->parentComponent_ != 0)
  32002. comp = comp->parentComponent_;
  32003. return const_cast <Component*> (comp);
  32004. }
  32005. bool Component::isParentOf (const Component* possibleChild) const throw()
  32006. {
  32007. if (! possibleChild->isValidComponent())
  32008. {
  32009. jassert (possibleChild == 0);
  32010. return false;
  32011. }
  32012. while (possibleChild != 0)
  32013. {
  32014. possibleChild = possibleChild->parentComponent_;
  32015. if (possibleChild == this)
  32016. return true;
  32017. }
  32018. return false;
  32019. }
  32020. void Component::parentHierarchyChanged()
  32021. {
  32022. }
  32023. void Component::childrenChanged()
  32024. {
  32025. }
  32026. void Component::internalChildrenChanged()
  32027. {
  32028. if (componentListeners.isEmpty())
  32029. {
  32030. childrenChanged();
  32031. }
  32032. else
  32033. {
  32034. BailOutChecker checker (this);
  32035. childrenChanged();
  32036. if (! checker.shouldBailOut())
  32037. componentListeners.callChecked (checker, &ComponentListener::componentChildrenChanged, *this);
  32038. }
  32039. }
  32040. void Component::internalHierarchyChanged()
  32041. {
  32042. BailOutChecker checker (this);
  32043. parentHierarchyChanged();
  32044. if (checker.shouldBailOut())
  32045. return;
  32046. componentListeners.callChecked (checker, &ComponentListener::componentParentHierarchyChanged, *this);
  32047. if (checker.shouldBailOut())
  32048. return;
  32049. for (int i = childComponentList_.size(); --i >= 0;)
  32050. {
  32051. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  32052. if (checker.shouldBailOut())
  32053. {
  32054. // you really shouldn't delete the parent component during a callback telling you
  32055. // that it's changed..
  32056. jassertfalse;
  32057. return;
  32058. }
  32059. i = jmin (i, childComponentList_.size());
  32060. }
  32061. }
  32062. void* Component::runModalLoopCallback (void* userData)
  32063. {
  32064. return (void*) (pointer_sized_int) ((Component*) userData)->runModalLoop();
  32065. }
  32066. int Component::runModalLoop()
  32067. {
  32068. if (! MessageManager::getInstance()->isThisTheMessageThread())
  32069. {
  32070. // use a callback so this can be called from non-gui threads
  32071. return (int) (pointer_sized_int)
  32072. MessageManager::getInstance()
  32073. ->callFunctionOnMessageThread (&runModalLoopCallback, (void*) this);
  32074. }
  32075. SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  32076. if (! isCurrentlyModal())
  32077. enterModalState();
  32078. JUCE_TRY
  32079. {
  32080. while (flags.currentlyModalFlag && flags.visibleFlag)
  32081. {
  32082. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  32083. break;
  32084. // check whether this component was deleted during the last message
  32085. if (! isValidMessageListener())
  32086. break;
  32087. }
  32088. }
  32089. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  32090. catch (const std::exception& e)
  32091. {
  32092. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  32093. return 0;
  32094. }
  32095. catch (...)
  32096. {
  32097. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  32098. return 0;
  32099. }
  32100. #endif
  32101. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32102. int returnValue = 0;
  32103. if (modalIndex >= 0)
  32104. {
  32105. modalComponentReturnValueKeys.remove (modalIndex);
  32106. returnValue = modalReturnValues.remove (modalIndex);
  32107. }
  32108. modalComponentStack.removeValue (this);
  32109. if (prevFocused != 0)
  32110. prevFocused->grabKeyboardFocus();
  32111. return returnValue;
  32112. }
  32113. void Component::enterModalState (const bool takeKeyboardFocus_)
  32114. {
  32115. // if component methods are being called from threads other than the message
  32116. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32117. checkMessageManagerIsLocked
  32118. // Check for an attempt to make a component modal when it already is!
  32119. // This can cause nasty problems..
  32120. jassert (! flags.currentlyModalFlag);
  32121. if (! isCurrentlyModal())
  32122. {
  32123. modalComponentStack.add (this);
  32124. modalComponentReturnValueKeys.add (this);
  32125. modalReturnValues.add (0);
  32126. flags.currentlyModalFlag = true;
  32127. setVisible (true);
  32128. if (takeKeyboardFocus_)
  32129. grabKeyboardFocus();
  32130. }
  32131. }
  32132. void Component::exitModalState (const int returnValue)
  32133. {
  32134. if (isCurrentlyModal())
  32135. {
  32136. if (MessageManager::getInstance()->isThisTheMessageThread())
  32137. {
  32138. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32139. if (modalIndex >= 0)
  32140. {
  32141. modalReturnValues.set (modalIndex, returnValue);
  32142. }
  32143. else
  32144. {
  32145. modalComponentReturnValueKeys.add (this);
  32146. modalReturnValues.add (returnValue);
  32147. }
  32148. modalComponentStack.removeValue (this);
  32149. flags.currentlyModalFlag = false;
  32150. bringModalComponentToFront();
  32151. }
  32152. else
  32153. {
  32154. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  32155. }
  32156. }
  32157. }
  32158. bool Component::isCurrentlyModal() const throw()
  32159. {
  32160. return flags.currentlyModalFlag
  32161. && getCurrentlyModalComponent() == this;
  32162. }
  32163. bool Component::isCurrentlyBlockedByAnotherModalComponent() const
  32164. {
  32165. Component* const mc = getCurrentlyModalComponent();
  32166. return mc != 0
  32167. && mc != this
  32168. && (! mc->isParentOf (this))
  32169. && ! mc->canModalEventBeSentToComponent (this);
  32170. }
  32171. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  32172. {
  32173. return modalComponentStack.size();
  32174. }
  32175. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  32176. {
  32177. Component* const c = static_cast <Component*> (modalComponentStack [modalComponentStack.size() - index - 1]);
  32178. return c->isValidComponent() ? c : 0;
  32179. }
  32180. void Component::bringModalComponentToFront()
  32181. {
  32182. ComponentPeer* lastOne = 0;
  32183. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  32184. {
  32185. Component* const c = getCurrentlyModalComponent (i);
  32186. if (c == 0)
  32187. break;
  32188. ComponentPeer* peer = c->getPeer();
  32189. if (peer != 0 && peer != lastOne)
  32190. {
  32191. if (lastOne == 0)
  32192. {
  32193. peer->toFront (true);
  32194. peer->grabFocus();
  32195. }
  32196. else
  32197. peer->toBehind (lastOne);
  32198. lastOne = peer;
  32199. }
  32200. }
  32201. }
  32202. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  32203. {
  32204. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  32205. }
  32206. bool Component::isBroughtToFrontOnMouseClick() const throw()
  32207. {
  32208. return flags.bringToFrontOnClickFlag;
  32209. }
  32210. void Component::setMouseCursor (const MouseCursor& cursor)
  32211. {
  32212. cursor_ = cursor;
  32213. if (flags.visibleFlag)
  32214. sendFakeMouseMove();
  32215. }
  32216. const MouseCursor Component::getMouseCursor()
  32217. {
  32218. return cursor_;
  32219. }
  32220. void Component::updateMouseCursor() const
  32221. {
  32222. sendFakeMouseMove();
  32223. }
  32224. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  32225. {
  32226. flags.repaintOnMouseActivityFlag = shouldRepaint;
  32227. }
  32228. void Component::repaintParent()
  32229. {
  32230. if (flags.visibleFlag)
  32231. internalRepaint (0, 0, getWidth(), getHeight());
  32232. }
  32233. void Component::repaint()
  32234. {
  32235. repaint (0, 0, getWidth(), getHeight());
  32236. }
  32237. void Component::repaint (const int x, const int y,
  32238. const int w, const int h)
  32239. {
  32240. deleteAndZero (bufferedImage_);
  32241. if (flags.visibleFlag)
  32242. internalRepaint (x, y, w, h);
  32243. }
  32244. void Component::internalRepaint (int x, int y, int w, int h)
  32245. {
  32246. // if component methods are being called from threads other than the message
  32247. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32248. checkMessageManagerIsLocked
  32249. if (x < 0)
  32250. {
  32251. w += x;
  32252. x = 0;
  32253. }
  32254. if (x + w > getWidth())
  32255. w = getWidth() - x;
  32256. if (w > 0)
  32257. {
  32258. if (y < 0)
  32259. {
  32260. h += y;
  32261. y = 0;
  32262. }
  32263. if (y + h > getHeight())
  32264. h = getHeight() - y;
  32265. if (h > 0)
  32266. {
  32267. if (parentComponent_ != 0)
  32268. {
  32269. x += getX();
  32270. y += getY();
  32271. if (parentComponent_->flags.visibleFlag)
  32272. parentComponent_->internalRepaint (x, y, w, h);
  32273. }
  32274. else if (flags.hasHeavyweightPeerFlag)
  32275. {
  32276. ComponentPeer* const peer = getPeer();
  32277. if (peer != 0)
  32278. peer->repaint (x, y, w, h);
  32279. }
  32280. }
  32281. }
  32282. }
  32283. void Component::renderComponent (Graphics& g)
  32284. {
  32285. const Rectangle<int> clipBounds (g.getClipBounds());
  32286. g.saveState();
  32287. clipObscuredRegions (g, clipBounds, 0, 0);
  32288. if (! g.isClipEmpty())
  32289. {
  32290. if (flags.bufferToImageFlag)
  32291. {
  32292. if (bufferedImage_ == 0)
  32293. {
  32294. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32295. getWidth(), getHeight(), ! flags.opaqueFlag);
  32296. Graphics imG (*bufferedImage_);
  32297. paint (imG);
  32298. }
  32299. g.setColour (Colours::black);
  32300. g.drawImageAt (bufferedImage_, 0, 0);
  32301. }
  32302. else
  32303. {
  32304. paint (g);
  32305. }
  32306. }
  32307. g.restoreState();
  32308. for (int i = 0; i < childComponentList_.size(); ++i)
  32309. {
  32310. Component* const child = childComponentList_.getUnchecked (i);
  32311. if (child->isVisible() && clipBounds.intersects (child->getBounds()))
  32312. {
  32313. g.saveState();
  32314. if (g.reduceClipRegion (child->getX(), child->getY(),
  32315. child->getWidth(), child->getHeight()))
  32316. {
  32317. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32318. {
  32319. const Component* const sibling = childComponentList_.getUnchecked (j);
  32320. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32321. g.excludeClipRegion (sibling->getBounds());
  32322. }
  32323. if (! g.isClipEmpty())
  32324. {
  32325. g.setOrigin (child->getX(), child->getY());
  32326. child->paintEntireComponent (g);
  32327. }
  32328. }
  32329. g.restoreState();
  32330. }
  32331. }
  32332. g.saveState();
  32333. paintOverChildren (g);
  32334. g.restoreState();
  32335. }
  32336. void Component::paintEntireComponent (Graphics& g)
  32337. {
  32338. jassert (! g.isClipEmpty());
  32339. #ifdef JUCE_DEBUG
  32340. flags.isInsidePaintCall = true;
  32341. #endif
  32342. if (effect_ != 0)
  32343. {
  32344. ScopedPointer<Image> effectImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32345. getWidth(), getHeight(),
  32346. ! flags.opaqueFlag));
  32347. {
  32348. Graphics g2 (*effectImage);
  32349. renderComponent (g2);
  32350. }
  32351. effect_->applyEffect (*effectImage, g);
  32352. }
  32353. else
  32354. {
  32355. renderComponent (g);
  32356. }
  32357. #ifdef JUCE_DEBUG
  32358. flags.isInsidePaintCall = false;
  32359. #endif
  32360. }
  32361. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32362. const bool clipImageToComponentBounds)
  32363. {
  32364. Rectangle<int> r (areaToGrab);
  32365. if (clipImageToComponentBounds)
  32366. r = r.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  32367. ScopedPointer<Image> componentImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32368. jmax (1, r.getWidth()),
  32369. jmax (1, r.getHeight()),
  32370. true));
  32371. Graphics imageContext (*componentImage);
  32372. imageContext.setOrigin (-r.getX(), -r.getY());
  32373. paintEntireComponent (imageContext);
  32374. return componentImage.release();
  32375. }
  32376. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32377. {
  32378. if (effect_ != effect)
  32379. {
  32380. effect_ = effect;
  32381. repaint();
  32382. }
  32383. }
  32384. LookAndFeel& Component::getLookAndFeel() const throw()
  32385. {
  32386. const Component* c = this;
  32387. do
  32388. {
  32389. if (c->lookAndFeel_ != 0)
  32390. return *(c->lookAndFeel_);
  32391. c = c->parentComponent_;
  32392. }
  32393. while (c != 0);
  32394. return LookAndFeel::getDefaultLookAndFeel();
  32395. }
  32396. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32397. {
  32398. if (lookAndFeel_ != newLookAndFeel)
  32399. {
  32400. lookAndFeel_ = newLookAndFeel;
  32401. sendLookAndFeelChange();
  32402. }
  32403. }
  32404. void Component::lookAndFeelChanged()
  32405. {
  32406. }
  32407. void Component::sendLookAndFeelChange()
  32408. {
  32409. repaint();
  32410. lookAndFeelChanged();
  32411. // (it's not a great idea to do anything that would delete this component
  32412. // during the lookAndFeelChanged() callback)
  32413. jassert (isValidComponent());
  32414. SafePointer<Component> safePointer (this);
  32415. for (int i = childComponentList_.size(); --i >= 0;)
  32416. {
  32417. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32418. if (safePointer == 0)
  32419. return;
  32420. i = jmin (i, childComponentList_.size());
  32421. }
  32422. }
  32423. static const var::identifier getColourPropertyId (const int colourId)
  32424. {
  32425. String s;
  32426. s.preallocateStorage (18);
  32427. s << T("jcclr_") << String::toHexString (colourId);
  32428. return s;
  32429. }
  32430. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const
  32431. {
  32432. var* v = properties.getItem (getColourPropertyId (colourId));
  32433. if (v != 0)
  32434. return Colour ((int) *v);
  32435. if (inheritFromParent && parentComponent_ != 0)
  32436. return parentComponent_->findColour (colourId, true);
  32437. return getLookAndFeel().findColour (colourId);
  32438. }
  32439. bool Component::isColourSpecified (const int colourId) const
  32440. {
  32441. return properties.contains (getColourPropertyId (colourId));
  32442. }
  32443. void Component::removeColour (const int colourId)
  32444. {
  32445. if (properties.remove (getColourPropertyId (colourId)))
  32446. colourChanged();
  32447. }
  32448. void Component::setColour (const int colourId, const Colour& colour)
  32449. {
  32450. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32451. colourChanged();
  32452. }
  32453. void Component::copyAllExplicitColoursTo (Component& target) const
  32454. {
  32455. bool changed = false;
  32456. for (int i = properties.size(); --i >= 0;)
  32457. {
  32458. const var::identifier name (properties.getName(i));
  32459. if (name.name.startsWith (T("jcclr_")))
  32460. if (target.properties.set (name, properties [name]))
  32461. changed = true;
  32462. }
  32463. if (changed)
  32464. target.colourChanged();
  32465. }
  32466. void Component::colourChanged()
  32467. {
  32468. }
  32469. const Rectangle<int> Component::getUnclippedArea() const
  32470. {
  32471. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32472. Component* p = parentComponent_;
  32473. int px = getX();
  32474. int py = getY();
  32475. while (p != 0)
  32476. {
  32477. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32478. return Rectangle<int>();
  32479. px += p->getX();
  32480. py += p->getY();
  32481. p = p->parentComponent_;
  32482. }
  32483. return Rectangle<int> (x, y, w, h);
  32484. }
  32485. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32486. const int deltaX, const int deltaY) const
  32487. {
  32488. for (int i = childComponentList_.size(); --i >= 0;)
  32489. {
  32490. const Component* const c = childComponentList_.getUnchecked(i);
  32491. if (c->isVisible())
  32492. {
  32493. const Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32494. if (! newClip.isEmpty())
  32495. {
  32496. if (c->isOpaque())
  32497. {
  32498. g.excludeClipRegion (newClip.translated (deltaX, deltaY));
  32499. }
  32500. else
  32501. {
  32502. c->clipObscuredRegions (g, newClip.translated (-c->getX(), -c->getY()),
  32503. c->getX() + deltaX,
  32504. c->getY() + deltaY);
  32505. }
  32506. }
  32507. }
  32508. }
  32509. }
  32510. void Component::getVisibleArea (RectangleList& result,
  32511. const bool includeSiblings) const
  32512. {
  32513. result.clear();
  32514. const Rectangle<int> unclipped (getUnclippedArea());
  32515. if (! unclipped.isEmpty())
  32516. {
  32517. result.add (unclipped);
  32518. if (includeSiblings)
  32519. {
  32520. const Component* const c = getTopLevelComponent();
  32521. c->subtractObscuredRegions (result, c->relativePositionToOtherComponent (this, Point<int>()),
  32522. Rectangle<int> (0, 0, c->getWidth(), c->getHeight()),
  32523. this);
  32524. }
  32525. subtractObscuredRegions (result, Point<int>(), unclipped, 0);
  32526. result.consolidate();
  32527. }
  32528. }
  32529. void Component::subtractObscuredRegions (RectangleList& result,
  32530. const Point<int>& delta,
  32531. const Rectangle<int>& clipRect,
  32532. const Component* const compToAvoid) const
  32533. {
  32534. for (int i = childComponentList_.size(); --i >= 0;)
  32535. {
  32536. const Component* const c = childComponentList_.getUnchecked(i);
  32537. if (c != compToAvoid && c->isVisible())
  32538. {
  32539. if (c->isOpaque())
  32540. {
  32541. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32542. childBounds.translate (delta.getX(), delta.getY());
  32543. result.subtract (childBounds);
  32544. }
  32545. else
  32546. {
  32547. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32548. newClip.translate (-c->getX(), -c->getY());
  32549. c->subtractObscuredRegions (result, c->getPosition() + delta,
  32550. newClip, compToAvoid);
  32551. }
  32552. }
  32553. }
  32554. }
  32555. void Component::mouseEnter (const MouseEvent&)
  32556. {
  32557. // base class does nothing
  32558. }
  32559. void Component::mouseExit (const MouseEvent&)
  32560. {
  32561. // base class does nothing
  32562. }
  32563. void Component::mouseDown (const MouseEvent&)
  32564. {
  32565. // base class does nothing
  32566. }
  32567. void Component::mouseUp (const MouseEvent&)
  32568. {
  32569. // base class does nothing
  32570. }
  32571. void Component::mouseDrag (const MouseEvent&)
  32572. {
  32573. // base class does nothing
  32574. }
  32575. void Component::mouseMove (const MouseEvent&)
  32576. {
  32577. // base class does nothing
  32578. }
  32579. void Component::mouseDoubleClick (const MouseEvent&)
  32580. {
  32581. // base class does nothing
  32582. }
  32583. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32584. {
  32585. // the base class just passes this event up to its parent..
  32586. if (parentComponent_ != 0)
  32587. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32588. wheelIncrementX, wheelIncrementY);
  32589. }
  32590. void Component::resized()
  32591. {
  32592. // base class does nothing
  32593. }
  32594. void Component::moved()
  32595. {
  32596. // base class does nothing
  32597. }
  32598. void Component::childBoundsChanged (Component*)
  32599. {
  32600. // base class does nothing
  32601. }
  32602. void Component::parentSizeChanged()
  32603. {
  32604. // base class does nothing
  32605. }
  32606. void Component::addComponentListener (ComponentListener* const newListener)
  32607. {
  32608. componentListeners.add (newListener);
  32609. }
  32610. void Component::removeComponentListener (ComponentListener* const listenerToRemove)
  32611. {
  32612. jassert (isValidComponent());
  32613. componentListeners.remove (listenerToRemove);
  32614. }
  32615. void Component::inputAttemptWhenModal()
  32616. {
  32617. bringModalComponentToFront();
  32618. getLookAndFeel().playAlertSound();
  32619. }
  32620. bool Component::canModalEventBeSentToComponent (const Component*)
  32621. {
  32622. return false;
  32623. }
  32624. void Component::internalModalInputAttempt()
  32625. {
  32626. Component* const current = getCurrentlyModalComponent();
  32627. if (current != 0)
  32628. current->inputAttemptWhenModal();
  32629. }
  32630. void Component::paint (Graphics&)
  32631. {
  32632. // all painting is done in the subclasses
  32633. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32634. }
  32635. void Component::paintOverChildren (Graphics&)
  32636. {
  32637. // all painting is done in the subclasses
  32638. }
  32639. void Component::handleMessage (const Message& message)
  32640. {
  32641. if (message.intParameter1 == exitModalStateMessage)
  32642. {
  32643. exitModalState (message.intParameter2);
  32644. }
  32645. else if (message.intParameter1 == customCommandMessage)
  32646. {
  32647. handleCommandMessage (message.intParameter2);
  32648. }
  32649. }
  32650. void Component::postCommandMessage (const int commandId)
  32651. {
  32652. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32653. }
  32654. void Component::handleCommandMessage (int)
  32655. {
  32656. // used by subclasses
  32657. }
  32658. void Component::addMouseListener (MouseListener* const newListener,
  32659. const bool wantsEventsForAllNestedChildComponents)
  32660. {
  32661. // if component methods are being called from threads other than the message
  32662. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32663. checkMessageManagerIsLocked
  32664. if (mouseListeners_ == 0)
  32665. mouseListeners_ = new VoidArray();
  32666. if (! mouseListeners_->contains (newListener))
  32667. {
  32668. if (wantsEventsForAllNestedChildComponents)
  32669. {
  32670. mouseListeners_->insert (0, newListener);
  32671. ++numDeepMouseListeners;
  32672. }
  32673. else
  32674. {
  32675. mouseListeners_->add (newListener);
  32676. }
  32677. }
  32678. }
  32679. void Component::removeMouseListener (MouseListener* const listenerToRemove)
  32680. {
  32681. // if component methods are being called from threads other than the message
  32682. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32683. checkMessageManagerIsLocked
  32684. if (mouseListeners_ != 0)
  32685. {
  32686. const int index = mouseListeners_->indexOf (listenerToRemove);
  32687. if (index >= 0)
  32688. {
  32689. if (index < numDeepMouseListeners)
  32690. --numDeepMouseListeners;
  32691. mouseListeners_->remove (index);
  32692. }
  32693. }
  32694. }
  32695. void Component::internalMouseEnter (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32696. {
  32697. if (isCurrentlyBlockedByAnotherModalComponent())
  32698. {
  32699. // if something else is modal, always just show a normal mouse cursor
  32700. source.showMouseCursor (MouseCursor::NormalCursor);
  32701. return;
  32702. }
  32703. if (! flags.mouseInsideFlag)
  32704. {
  32705. flags.mouseInsideFlag = true;
  32706. flags.mouseOverFlag = true;
  32707. flags.draggingFlag = false;
  32708. BailOutChecker checker (this);
  32709. if (flags.repaintOnMouseActivityFlag)
  32710. repaint();
  32711. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32712. this, time, relativePos,
  32713. time, 0, false);
  32714. mouseEnter (me);
  32715. if (checker.shouldBailOut())
  32716. return;
  32717. Desktop::getInstance().resetTimer();
  32718. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseEnter, me);
  32719. if (checker.shouldBailOut())
  32720. return;
  32721. if (mouseListeners_ != 0)
  32722. {
  32723. for (int i = mouseListeners_->size(); --i >= 0;)
  32724. {
  32725. ((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me);
  32726. if (checker.shouldBailOut())
  32727. return;
  32728. i = jmin (i, mouseListeners_->size());
  32729. }
  32730. }
  32731. Component* p = parentComponent_;
  32732. while (p != 0)
  32733. {
  32734. if (p->numDeepMouseListeners > 0)
  32735. {
  32736. BailOutChecker checker (this, p);
  32737. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32738. {
  32739. ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me);
  32740. if (checker.shouldBailOut())
  32741. return;
  32742. i = jmin (i, p->numDeepMouseListeners);
  32743. }
  32744. }
  32745. p = p->parentComponent_;
  32746. }
  32747. }
  32748. }
  32749. void Component::internalMouseExit (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32750. {
  32751. BailOutChecker checker (this);
  32752. if (flags.draggingFlag)
  32753. {
  32754. internalMouseUp (source, relativePos, time, source.getCurrentModifiers().getRawFlags());
  32755. if (checker.shouldBailOut())
  32756. return;
  32757. }
  32758. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32759. {
  32760. flags.mouseInsideFlag = false;
  32761. flags.mouseOverFlag = false;
  32762. flags.draggingFlag = false;
  32763. if (flags.repaintOnMouseActivityFlag)
  32764. repaint();
  32765. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32766. this, time, relativePos,
  32767. time, 0, false);
  32768. mouseExit (me);
  32769. if (checker.shouldBailOut())
  32770. return;
  32771. Desktop::getInstance().resetTimer();
  32772. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseExit, me);
  32773. if (checker.shouldBailOut())
  32774. return;
  32775. if (mouseListeners_ != 0)
  32776. {
  32777. for (int i = mouseListeners_->size(); --i >= 0;)
  32778. {
  32779. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32780. if (checker.shouldBailOut())
  32781. return;
  32782. i = jmin (i, mouseListeners_->size());
  32783. }
  32784. }
  32785. Component* p = parentComponent_;
  32786. while (p != 0)
  32787. {
  32788. if (p->numDeepMouseListeners > 0)
  32789. {
  32790. BailOutChecker checker (this, p);
  32791. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32792. {
  32793. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me);
  32794. if (checker.shouldBailOut())
  32795. return;
  32796. i = jmin (i, p->numDeepMouseListeners);
  32797. }
  32798. }
  32799. p = p->parentComponent_;
  32800. }
  32801. }
  32802. }
  32803. class InternalDragRepeater : public Timer
  32804. {
  32805. public:
  32806. InternalDragRepeater()
  32807. {}
  32808. ~InternalDragRepeater()
  32809. {
  32810. clearSingletonInstance();
  32811. }
  32812. juce_DeclareSingleton_SingleThreaded_Minimal (InternalDragRepeater)
  32813. void timerCallback()
  32814. {
  32815. Desktop& desktop = Desktop::getInstance();
  32816. int numMiceDown = 0;
  32817. for (int i = desktop.getNumMouseSources(); --i >= 0;)
  32818. {
  32819. MouseInputSource* const source = desktop.getMouseSource(i);
  32820. if (source->isDragging())
  32821. {
  32822. source->triggerFakeMove();
  32823. ++numMiceDown;
  32824. }
  32825. }
  32826. if (numMiceDown == 0)
  32827. deleteInstance();
  32828. }
  32829. juce_UseDebuggingNewOperator
  32830. private:
  32831. InternalDragRepeater (const InternalDragRepeater&);
  32832. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32833. };
  32834. juce_ImplementSingleton_SingleThreaded (InternalDragRepeater)
  32835. void Component::beginDragAutoRepeat (const int interval)
  32836. {
  32837. if (interval > 0)
  32838. {
  32839. if (InternalDragRepeater::getInstance()->getTimerInterval() != interval)
  32840. InternalDragRepeater::getInstance()->startTimer (interval);
  32841. }
  32842. else
  32843. {
  32844. InternalDragRepeater::deleteInstance();
  32845. }
  32846. }
  32847. void Component::internalMouseDown (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32848. {
  32849. Desktop& desktop = Desktop::getInstance();
  32850. BailOutChecker checker (this);
  32851. if (isCurrentlyBlockedByAnotherModalComponent())
  32852. {
  32853. internalModalInputAttempt();
  32854. if (checker.shouldBailOut())
  32855. return;
  32856. // If processing the input attempt has exited the modal loop, we'll allow the event
  32857. // to be delivered..
  32858. if (isCurrentlyBlockedByAnotherModalComponent())
  32859. {
  32860. // allow blocked mouse-events to go to global listeners..
  32861. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32862. this, time, relativePos, time,
  32863. source.getNumberOfMultipleClicks(), false);
  32864. desktop.resetTimer();
  32865. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32866. return;
  32867. }
  32868. }
  32869. {
  32870. Component* c = this;
  32871. while (c != 0)
  32872. {
  32873. if (c->isBroughtToFrontOnMouseClick())
  32874. {
  32875. c->toFront (true);
  32876. if (checker.shouldBailOut())
  32877. return;
  32878. }
  32879. c = c->parentComponent_;
  32880. }
  32881. }
  32882. if (! flags.dontFocusOnMouseClickFlag)
  32883. {
  32884. grabFocusInternal (focusChangedByMouseClick);
  32885. if (checker.shouldBailOut())
  32886. return;
  32887. }
  32888. flags.draggingFlag = true;
  32889. flags.mouseOverFlag = true;
  32890. if (flags.repaintOnMouseActivityFlag)
  32891. repaint();
  32892. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32893. this, time, relativePos, time,
  32894. source.getNumberOfMultipleClicks(), false);
  32895. mouseDown (me);
  32896. if (checker.shouldBailOut())
  32897. return;
  32898. desktop.resetTimer();
  32899. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32900. if (checker.shouldBailOut())
  32901. return;
  32902. if (mouseListeners_ != 0)
  32903. {
  32904. for (int i = mouseListeners_->size(); --i >= 0;)
  32905. {
  32906. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  32907. if (checker.shouldBailOut())
  32908. return;
  32909. i = jmin (i, mouseListeners_->size());
  32910. }
  32911. }
  32912. Component* p = parentComponent_;
  32913. while (p != 0)
  32914. {
  32915. if (p->numDeepMouseListeners > 0)
  32916. {
  32917. BailOutChecker checker (this, p);
  32918. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32919. {
  32920. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
  32921. if (checker.shouldBailOut())
  32922. return;
  32923. i = jmin (i, p->numDeepMouseListeners);
  32924. }
  32925. }
  32926. p = p->parentComponent_;
  32927. }
  32928. }
  32929. void Component::internalMouseUp (MouseInputSource& source, const Point<int>& relativePos, const Time& time, const ModifierKeys& oldModifiers)
  32930. {
  32931. if (flags.draggingFlag)
  32932. {
  32933. Desktop& desktop = Desktop::getInstance();
  32934. flags.draggingFlag = false;
  32935. BailOutChecker checker (this);
  32936. if (flags.repaintOnMouseActivityFlag)
  32937. repaint();
  32938. const MouseEvent me (source, relativePos,
  32939. oldModifiers, this, time,
  32940. globalPositionToRelative (source.getLastMouseDownPosition()),
  32941. source.getLastMouseDownTime(),
  32942. source.getNumberOfMultipleClicks(),
  32943. source.hasMouseMovedSignificantlySincePressed());
  32944. mouseUp (me);
  32945. if (checker.shouldBailOut())
  32946. return;
  32947. desktop.resetTimer();
  32948. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseUp, me);
  32949. if (checker.shouldBailOut())
  32950. return;
  32951. if (mouseListeners_ != 0)
  32952. {
  32953. for (int i = mouseListeners_->size(); --i >= 0;)
  32954. {
  32955. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  32956. if (checker.shouldBailOut())
  32957. return;
  32958. i = jmin (i, mouseListeners_->size());
  32959. }
  32960. }
  32961. {
  32962. Component* p = parentComponent_;
  32963. while (p != 0)
  32964. {
  32965. if (p->numDeepMouseListeners > 0)
  32966. {
  32967. BailOutChecker checker (this, p);
  32968. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32969. {
  32970. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me);
  32971. if (checker.shouldBailOut())
  32972. return;
  32973. i = jmin (i, p->numDeepMouseListeners);
  32974. }
  32975. }
  32976. p = p->parentComponent_;
  32977. }
  32978. }
  32979. // check for double-click
  32980. if (me.getNumberOfClicks() >= 2)
  32981. {
  32982. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  32983. mouseDoubleClick (me);
  32984. if (checker.shouldBailOut())
  32985. return;
  32986. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDoubleClick, me);
  32987. if (checker.shouldBailOut())
  32988. return;
  32989. for (int i = numListeners; --i >= 0;)
  32990. {
  32991. if (checker.shouldBailOut())
  32992. return;
  32993. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  32994. if (ml != 0)
  32995. ml->mouseDoubleClick (me);
  32996. }
  32997. if (checker.shouldBailOut())
  32998. return;
  32999. Component* p = parentComponent_;
  33000. while (p != 0)
  33001. {
  33002. if (p->numDeepMouseListeners > 0)
  33003. {
  33004. BailOutChecker checker (this, p);
  33005. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33006. {
  33007. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me);
  33008. if (checker.shouldBailOut())
  33009. return;
  33010. i = jmin (i, p->numDeepMouseListeners);
  33011. }
  33012. }
  33013. p = p->parentComponent_;
  33014. }
  33015. }
  33016. }
  33017. }
  33018. void Component::internalMouseDrag (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  33019. {
  33020. if (flags.draggingFlag)
  33021. {
  33022. Desktop& desktop = Desktop::getInstance();
  33023. flags.mouseOverFlag = reallyContains (relativePos.getX(), relativePos.getY(), false);
  33024. BailOutChecker checker (this);
  33025. const MouseEvent me (source, relativePos,
  33026. source.getCurrentModifiers(), this, time,
  33027. globalPositionToRelative (source.getLastMouseDownPosition()),
  33028. source.getLastMouseDownTime(),
  33029. source.getNumberOfMultipleClicks(),
  33030. source.hasMouseMovedSignificantlySincePressed());
  33031. mouseDrag (me);
  33032. if (checker.shouldBailOut())
  33033. return;
  33034. desktop.resetTimer();
  33035. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  33036. if (checker.shouldBailOut())
  33037. return;
  33038. if (mouseListeners_ != 0)
  33039. {
  33040. for (int i = mouseListeners_->size(); --i >= 0;)
  33041. {
  33042. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  33043. if (checker.shouldBailOut())
  33044. return;
  33045. i = jmin (i, mouseListeners_->size());
  33046. }
  33047. }
  33048. Component* p = parentComponent_;
  33049. while (p != 0)
  33050. {
  33051. if (p->numDeepMouseListeners > 0)
  33052. {
  33053. BailOutChecker checker (this, p);
  33054. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33055. {
  33056. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me);
  33057. if (checker.shouldBailOut())
  33058. return;
  33059. i = jmin (i, p->numDeepMouseListeners);
  33060. }
  33061. }
  33062. p = p->parentComponent_;
  33063. }
  33064. }
  33065. }
  33066. void Component::internalMouseMove (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  33067. {
  33068. Desktop& desktop = Desktop::getInstance();
  33069. BailOutChecker checker (this);
  33070. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  33071. this, time, relativePos,
  33072. time, 0, false);
  33073. if (isCurrentlyBlockedByAnotherModalComponent())
  33074. {
  33075. // allow blocked mouse-events to go to global listeners..
  33076. desktop.sendMouseMove();
  33077. }
  33078. else
  33079. {
  33080. flags.mouseOverFlag = true;
  33081. mouseMove (me);
  33082. if (checker.shouldBailOut())
  33083. return;
  33084. desktop.resetTimer();
  33085. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  33086. if (checker.shouldBailOut())
  33087. return;
  33088. if (mouseListeners_ != 0)
  33089. {
  33090. for (int i = mouseListeners_->size(); --i >= 0;)
  33091. {
  33092. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  33093. if (checker.shouldBailOut())
  33094. return;
  33095. i = jmin (i, mouseListeners_->size());
  33096. }
  33097. }
  33098. Component* p = parentComponent_;
  33099. while (p != 0)
  33100. {
  33101. if (p->numDeepMouseListeners > 0)
  33102. {
  33103. BailOutChecker checker (this, p);
  33104. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33105. {
  33106. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseMove (me);
  33107. if (checker.shouldBailOut())
  33108. return;
  33109. i = jmin (i, p->numDeepMouseListeners);
  33110. }
  33111. }
  33112. p = p->parentComponent_;
  33113. }
  33114. }
  33115. }
  33116. void Component::internalMouseWheel (MouseInputSource& source, const Point<int>& relativePos,
  33117. const Time& time, const float amountX, const float amountY)
  33118. {
  33119. Desktop& desktop = Desktop::getInstance();
  33120. BailOutChecker checker (this);
  33121. const float wheelIncrementX = amountX * (1.0f / 256.0f);
  33122. const float wheelIncrementY = amountY * (1.0f / 256.0f);
  33123. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  33124. this, time, relativePos, time, 0, false);
  33125. if (isCurrentlyBlockedByAnotherModalComponent())
  33126. {
  33127. // allow blocked mouse-events to go to global listeners..
  33128. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  33129. }
  33130. else
  33131. {
  33132. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33133. if (checker.shouldBailOut())
  33134. return;
  33135. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  33136. if (checker.shouldBailOut())
  33137. return;
  33138. if (mouseListeners_ != 0)
  33139. {
  33140. for (int i = mouseListeners_->size(); --i >= 0;)
  33141. {
  33142. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33143. if (checker.shouldBailOut())
  33144. return;
  33145. i = jmin (i, mouseListeners_->size());
  33146. }
  33147. }
  33148. Component* p = parentComponent_;
  33149. while (p != 0)
  33150. {
  33151. if (p->numDeepMouseListeners > 0)
  33152. {
  33153. BailOutChecker checker (this, p);
  33154. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33155. {
  33156. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33157. if (checker.shouldBailOut())
  33158. return;
  33159. i = jmin (i, p->numDeepMouseListeners);
  33160. }
  33161. }
  33162. p = p->parentComponent_;
  33163. }
  33164. }
  33165. }
  33166. void Component::sendFakeMouseMove() const
  33167. {
  33168. Desktop::getInstance().getMainMouseSource().triggerFakeMove();
  33169. }
  33170. void Component::broughtToFront()
  33171. {
  33172. }
  33173. void Component::internalBroughtToFront()
  33174. {
  33175. if (! isValidComponent())
  33176. return;
  33177. if (flags.hasHeavyweightPeerFlag)
  33178. Desktop::getInstance().componentBroughtToFront (this);
  33179. BailOutChecker checker (this);
  33180. broughtToFront();
  33181. if (checker.shouldBailOut())
  33182. return;
  33183. componentListeners.callChecked (checker, &ComponentListener::componentBroughtToFront, *this);
  33184. if (checker.shouldBailOut())
  33185. return;
  33186. // When brought to the front and there's a modal component blocking this one,
  33187. // we need to bring the modal one to the front instead..
  33188. Component* const cm = getCurrentlyModalComponent();
  33189. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  33190. bringModalComponentToFront();
  33191. }
  33192. void Component::focusGained (FocusChangeType)
  33193. {
  33194. // base class does nothing
  33195. }
  33196. void Component::internalFocusGain (const FocusChangeType cause)
  33197. {
  33198. SafePointer<Component> safePointer (this);
  33199. focusGained (cause);
  33200. if (safePointer != 0)
  33201. internalChildFocusChange (cause);
  33202. }
  33203. void Component::focusLost (FocusChangeType)
  33204. {
  33205. // base class does nothing
  33206. }
  33207. void Component::internalFocusLoss (const FocusChangeType cause)
  33208. {
  33209. SafePointer<Component> safePointer (this);
  33210. focusLost (focusChangedDirectly);
  33211. if (safePointer != 0)
  33212. internalChildFocusChange (cause);
  33213. }
  33214. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  33215. {
  33216. // base class does nothing
  33217. }
  33218. void Component::internalChildFocusChange (FocusChangeType cause)
  33219. {
  33220. const bool childIsNowFocused = hasKeyboardFocus (true);
  33221. if (flags.childCompFocusedFlag != childIsNowFocused)
  33222. {
  33223. flags.childCompFocusedFlag = childIsNowFocused;
  33224. SafePointer<Component> safePointer (this);
  33225. focusOfChildComponentChanged (cause);
  33226. if (safePointer == 0)
  33227. return;
  33228. }
  33229. if (parentComponent_ != 0)
  33230. parentComponent_->internalChildFocusChange (cause);
  33231. }
  33232. bool Component::isEnabled() const throw()
  33233. {
  33234. return (! flags.isDisabledFlag)
  33235. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  33236. }
  33237. void Component::setEnabled (const bool shouldBeEnabled)
  33238. {
  33239. if (flags.isDisabledFlag == shouldBeEnabled)
  33240. {
  33241. flags.isDisabledFlag = ! shouldBeEnabled;
  33242. // if any parent components are disabled, setting our flag won't make a difference,
  33243. // so no need to send a change message
  33244. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  33245. sendEnablementChangeMessage();
  33246. }
  33247. }
  33248. void Component::sendEnablementChangeMessage()
  33249. {
  33250. SafePointer<Component> safePointer (this);
  33251. enablementChanged();
  33252. if (safePointer == 0)
  33253. return;
  33254. for (int i = getNumChildComponents(); --i >= 0;)
  33255. {
  33256. Component* const c = getChildComponent (i);
  33257. if (c != 0)
  33258. {
  33259. c->sendEnablementChangeMessage();
  33260. if (safePointer == 0)
  33261. return;
  33262. }
  33263. }
  33264. }
  33265. void Component::enablementChanged()
  33266. {
  33267. }
  33268. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33269. {
  33270. flags.wantsFocusFlag = wantsFocus;
  33271. }
  33272. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33273. {
  33274. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33275. }
  33276. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33277. {
  33278. return ! flags.dontFocusOnMouseClickFlag;
  33279. }
  33280. bool Component::getWantsKeyboardFocus() const throw()
  33281. {
  33282. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33283. }
  33284. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33285. {
  33286. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33287. }
  33288. bool Component::isFocusContainer() const throw()
  33289. {
  33290. return flags.isFocusContainerFlag;
  33291. }
  33292. int Component::getExplicitFocusOrder() const
  33293. {
  33294. return properties ["_jexfo"];
  33295. }
  33296. void Component::setExplicitFocusOrder (const int newFocusOrderIndex)
  33297. {
  33298. properties.set ("_jexfo", newFocusOrderIndex);
  33299. }
  33300. KeyboardFocusTraverser* Component::createFocusTraverser()
  33301. {
  33302. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33303. return new KeyboardFocusTraverser();
  33304. return parentComponent_->createFocusTraverser();
  33305. }
  33306. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33307. {
  33308. // give the focus to this component
  33309. if (currentlyFocusedComponent != this)
  33310. {
  33311. JUCE_TRY
  33312. {
  33313. // get the focus onto our desktop window
  33314. ComponentPeer* const peer = getPeer();
  33315. if (peer != 0)
  33316. {
  33317. SafePointer<Component> safePointer (this);
  33318. peer->grabFocus();
  33319. if (peer->isFocused() && currentlyFocusedComponent != this)
  33320. {
  33321. Component* const componentLosingFocus = currentlyFocusedComponent;
  33322. currentlyFocusedComponent = this;
  33323. Desktop::getInstance().triggerFocusCallback();
  33324. // call this after setting currentlyFocusedComponent so that the one that's
  33325. // losing it has a chance to see where focus is going
  33326. if (componentLosingFocus->isValidComponent())
  33327. componentLosingFocus->internalFocusLoss (cause);
  33328. if (currentlyFocusedComponent == this)
  33329. {
  33330. focusGained (cause);
  33331. if (safePointer != 0)
  33332. internalChildFocusChange (cause);
  33333. }
  33334. }
  33335. }
  33336. }
  33337. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33338. catch (const std::exception& e)
  33339. {
  33340. currentlyFocusedComponent = 0;
  33341. Desktop::getInstance().triggerFocusCallback();
  33342. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33343. }
  33344. catch (...)
  33345. {
  33346. currentlyFocusedComponent = 0;
  33347. Desktop::getInstance().triggerFocusCallback();
  33348. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33349. }
  33350. #endif
  33351. }
  33352. }
  33353. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33354. {
  33355. if (isShowing())
  33356. {
  33357. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33358. {
  33359. takeKeyboardFocus (cause);
  33360. }
  33361. else
  33362. {
  33363. if (isParentOf (currentlyFocusedComponent)
  33364. && currentlyFocusedComponent->isShowing())
  33365. {
  33366. // do nothing if the focused component is actually a child of ours..
  33367. }
  33368. else
  33369. {
  33370. // find the default child component..
  33371. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33372. if (traverser != 0)
  33373. {
  33374. Component* const defaultComp = traverser->getDefaultComponent (this);
  33375. traverser = 0;
  33376. if (defaultComp != 0)
  33377. {
  33378. defaultComp->grabFocusInternal (cause, false);
  33379. return;
  33380. }
  33381. }
  33382. if (canTryParent && parentComponent_ != 0)
  33383. {
  33384. // if no children want it and we're allowed to try our parent comp,
  33385. // then pass up to parent, which will try our siblings.
  33386. parentComponent_->grabFocusInternal (cause, true);
  33387. }
  33388. }
  33389. }
  33390. }
  33391. }
  33392. void Component::grabKeyboardFocus()
  33393. {
  33394. // if component methods are being called from threads other than the message
  33395. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33396. checkMessageManagerIsLocked
  33397. grabFocusInternal (focusChangedDirectly);
  33398. }
  33399. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33400. {
  33401. // if component methods are being called from threads other than the message
  33402. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33403. checkMessageManagerIsLocked
  33404. if (parentComponent_ != 0)
  33405. {
  33406. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33407. if (traverser != 0)
  33408. {
  33409. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33410. : traverser->getPreviousComponent (this);
  33411. traverser = 0;
  33412. if (nextComp != 0)
  33413. {
  33414. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33415. {
  33416. SafePointer<Component> safePointer (this);
  33417. internalModalInputAttempt();
  33418. if (safePointer == 0 || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33419. return;
  33420. }
  33421. nextComp->grabFocusInternal (focusChangedByTabKey);
  33422. return;
  33423. }
  33424. }
  33425. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33426. }
  33427. }
  33428. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const
  33429. {
  33430. return (currentlyFocusedComponent == this)
  33431. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33432. }
  33433. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33434. {
  33435. return currentlyFocusedComponent;
  33436. }
  33437. void Component::giveAwayFocus()
  33438. {
  33439. // use a copy so we can clear the value before the call
  33440. Component* const componentLosingFocus = currentlyFocusedComponent;
  33441. currentlyFocusedComponent = 0;
  33442. Desktop::getInstance().triggerFocusCallback();
  33443. if (componentLosingFocus->isValidComponent())
  33444. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33445. }
  33446. bool Component::isMouseOver() const throw()
  33447. {
  33448. return flags.mouseOverFlag;
  33449. }
  33450. bool Component::isMouseButtonDown() const throw()
  33451. {
  33452. return flags.draggingFlag;
  33453. }
  33454. bool Component::isMouseOverOrDragging() const throw()
  33455. {
  33456. return flags.mouseOverFlag || flags.draggingFlag;
  33457. }
  33458. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33459. {
  33460. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33461. }
  33462. const Point<int> Component::getMouseXYRelative() const
  33463. {
  33464. return globalPositionToRelative (Desktop::getMousePosition());
  33465. }
  33466. const Rectangle<int> Component::getParentMonitorArea() const
  33467. {
  33468. return Desktop::getInstance()
  33469. .getMonitorAreaContaining (relativePositionToGlobal (Point<int> (getWidth() / 2,
  33470. getHeight() / 2)));
  33471. }
  33472. void Component::addKeyListener (KeyListener* const newListener)
  33473. {
  33474. if (keyListeners_ == 0)
  33475. keyListeners_ = new VoidArray();
  33476. keyListeners_->addIfNotAlreadyThere (newListener);
  33477. }
  33478. void Component::removeKeyListener (KeyListener* const listenerToRemove)
  33479. {
  33480. if (keyListeners_ != 0)
  33481. keyListeners_->removeValue (listenerToRemove);
  33482. }
  33483. bool Component::keyPressed (const KeyPress&)
  33484. {
  33485. return false;
  33486. }
  33487. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33488. {
  33489. return false;
  33490. }
  33491. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33492. {
  33493. if (parentComponent_ != 0)
  33494. parentComponent_->modifierKeysChanged (modifiers);
  33495. }
  33496. void Component::internalModifierKeysChanged()
  33497. {
  33498. sendFakeMouseMove();
  33499. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33500. }
  33501. ComponentPeer* Component::getPeer() const
  33502. {
  33503. if (flags.hasHeavyweightPeerFlag)
  33504. return ComponentPeer::getPeerFor (this);
  33505. else if (parentComponent_ != 0)
  33506. return parentComponent_->getPeer();
  33507. else
  33508. return 0;
  33509. }
  33510. Component::BailOutChecker::BailOutChecker (Component* const component1, Component* const component2_)
  33511. : safePointer1 (component1), safePointer2 (component2_), component2 (component2_)
  33512. {
  33513. jassert (component1 != 0);
  33514. }
  33515. bool Component::BailOutChecker::shouldBailOut() const throw()
  33516. {
  33517. return safePointer1 == 0 || safePointer2 != component2;
  33518. }
  33519. END_JUCE_NAMESPACE
  33520. /*** End of inlined file: juce_Component.cpp ***/
  33521. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33522. BEGIN_JUCE_NAMESPACE
  33523. void ComponentListener::componentMovedOrResized (Component&, bool, bool) {}
  33524. void ComponentListener::componentBroughtToFront (Component&) {}
  33525. void ComponentListener::componentVisibilityChanged (Component&) {}
  33526. void ComponentListener::componentChildrenChanged (Component&) {}
  33527. void ComponentListener::componentParentHierarchyChanged (Component&) {}
  33528. void ComponentListener::componentNameChanged (Component&) {}
  33529. void ComponentListener::componentBeingDeleted (Component&) {}
  33530. END_JUCE_NAMESPACE
  33531. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33532. /*** Start of inlined file: juce_Desktop.cpp ***/
  33533. BEGIN_JUCE_NAMESPACE
  33534. Desktop::Desktop()
  33535. : mouseClickCounter (0),
  33536. kioskModeComponent (0)
  33537. {
  33538. createMouseInputSources();
  33539. refreshMonitorSizes();
  33540. }
  33541. Desktop::~Desktop()
  33542. {
  33543. jassert (instance == this);
  33544. instance = 0;
  33545. // doh! If you don't delete all your windows before exiting, you're going to
  33546. // be leaking memory!
  33547. jassert (desktopComponents.size() == 0);
  33548. }
  33549. Desktop& JUCE_CALLTYPE Desktop::getInstance()
  33550. {
  33551. if (instance == 0)
  33552. instance = new Desktop();
  33553. return *instance;
  33554. }
  33555. Desktop* Desktop::instance = 0;
  33556. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33557. const bool clipToWorkArea);
  33558. void Desktop::refreshMonitorSizes()
  33559. {
  33560. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33561. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33562. monitorCoordsClipped.clear();
  33563. monitorCoordsUnclipped.clear();
  33564. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33565. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33566. jassert (monitorCoordsClipped.size() > 0
  33567. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33568. if (oldClipped != monitorCoordsClipped
  33569. || oldUnclipped != monitorCoordsUnclipped)
  33570. {
  33571. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33572. {
  33573. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33574. if (p != 0)
  33575. p->handleScreenSizeChange();
  33576. }
  33577. }
  33578. }
  33579. int Desktop::getNumDisplayMonitors() const throw()
  33580. {
  33581. return monitorCoordsClipped.size();
  33582. }
  33583. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33584. {
  33585. return clippedToWorkArea ? monitorCoordsClipped [index]
  33586. : monitorCoordsUnclipped [index];
  33587. }
  33588. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33589. {
  33590. RectangleList rl;
  33591. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33592. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33593. return rl;
  33594. }
  33595. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33596. {
  33597. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33598. }
  33599. const Rectangle<int> Desktop::getMonitorAreaContaining (const Point<int>& position, const bool clippedToWorkArea) const
  33600. {
  33601. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33602. double bestDistance = 1.0e10;
  33603. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33604. {
  33605. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33606. if (rect.contains (position))
  33607. return rect;
  33608. const double distance = rect.getCentre().getDistanceFrom (position);
  33609. if (distance < bestDistance)
  33610. {
  33611. bestDistance = distance;
  33612. best = rect;
  33613. }
  33614. }
  33615. return best;
  33616. }
  33617. int Desktop::getNumComponents() const throw()
  33618. {
  33619. return desktopComponents.size();
  33620. }
  33621. Component* Desktop::getComponent (const int index) const throw()
  33622. {
  33623. return desktopComponents [index];
  33624. }
  33625. Component* Desktop::findComponentAt (const Point<int>& screenPosition) const
  33626. {
  33627. for (int i = desktopComponents.size(); --i >= 0;)
  33628. {
  33629. Component* const c = desktopComponents.getUnchecked(i);
  33630. const Point<int> relative (c->globalPositionToRelative (screenPosition));
  33631. if (c->contains (relative.getX(), relative.getY()))
  33632. return c->getComponentAt (relative.getX(), relative.getY());
  33633. }
  33634. return 0;
  33635. }
  33636. void Desktop::addDesktopComponent (Component* const c)
  33637. {
  33638. jassert (c != 0);
  33639. jassert (! desktopComponents.contains (c));
  33640. desktopComponents.addIfNotAlreadyThere (c);
  33641. }
  33642. void Desktop::removeDesktopComponent (Component* const c)
  33643. {
  33644. desktopComponents.removeValue (c);
  33645. }
  33646. void Desktop::componentBroughtToFront (Component* const c)
  33647. {
  33648. const int index = desktopComponents.indexOf (c);
  33649. jassert (index >= 0);
  33650. if (index >= 0)
  33651. {
  33652. int newIndex = -1;
  33653. if (! c->isAlwaysOnTop())
  33654. {
  33655. newIndex = desktopComponents.size();
  33656. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33657. --newIndex;
  33658. --newIndex;
  33659. }
  33660. desktopComponents.move (index, newIndex);
  33661. }
  33662. }
  33663. const Point<int> Desktop::getLastMouseDownPosition() throw()
  33664. {
  33665. return getInstance().getMainMouseSource().getLastMouseDownPosition();
  33666. }
  33667. int Desktop::getMouseButtonClickCounter() throw()
  33668. {
  33669. return getInstance().mouseClickCounter;
  33670. }
  33671. void Desktop::incrementMouseClickCounter() throw()
  33672. {
  33673. ++mouseClickCounter;
  33674. }
  33675. int Desktop::getNumDraggingMouseSources() const throw()
  33676. {
  33677. int num = 0;
  33678. for (int i = mouseSources.size(); --i >= 0;)
  33679. if (mouseSources.getUnchecked(i)->isDragging())
  33680. ++num;
  33681. return num;
  33682. }
  33683. MouseInputSource* Desktop::getDraggingMouseSource (int index) const throw()
  33684. {
  33685. int num = 0;
  33686. for (int i = mouseSources.size(); --i >= 0;)
  33687. {
  33688. MouseInputSource* const mi = mouseSources.getUnchecked(i);
  33689. if (mi->isDragging())
  33690. {
  33691. if (index == num)
  33692. return mi;
  33693. ++num;
  33694. }
  33695. }
  33696. return 0;
  33697. }
  33698. void Desktop::addFocusChangeListener (FocusChangeListener* const listener)
  33699. {
  33700. focusListeners.add (listener);
  33701. }
  33702. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener)
  33703. {
  33704. focusListeners.remove (listener);
  33705. }
  33706. void Desktop::triggerFocusCallback()
  33707. {
  33708. triggerAsyncUpdate();
  33709. }
  33710. void Desktop::handleAsyncUpdate()
  33711. {
  33712. Component* currentFocus = Component::getCurrentlyFocusedComponent();
  33713. focusListeners.call (&FocusChangeListener::globalFocusChanged, currentFocus);
  33714. }
  33715. void Desktop::addGlobalMouseListener (MouseListener* const listener)
  33716. {
  33717. mouseListeners.add (listener);
  33718. resetTimer();
  33719. }
  33720. void Desktop::removeGlobalMouseListener (MouseListener* const listener)
  33721. {
  33722. mouseListeners.remove (listener);
  33723. resetTimer();
  33724. }
  33725. void Desktop::timerCallback()
  33726. {
  33727. if (lastFakeMouseMove != getMousePosition())
  33728. sendMouseMove();
  33729. }
  33730. void Desktop::sendMouseMove()
  33731. {
  33732. if (! mouseListeners.isEmpty())
  33733. {
  33734. startTimer (20);
  33735. lastFakeMouseMove = getMousePosition();
  33736. Component* const target = findComponentAt (lastFakeMouseMove);
  33737. if (target != 0)
  33738. {
  33739. Component::BailOutChecker checker (target);
  33740. const Point<int> pos (target->globalPositionToRelative (lastFakeMouseMove));
  33741. const Time now (Time::getCurrentTime());
  33742. const MouseEvent me (getMainMouseSource(), pos, ModifierKeys::getCurrentModifiers(),
  33743. target, now, pos, now, 0, false);
  33744. if (me.mods.isAnyMouseButtonDown())
  33745. mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  33746. else
  33747. mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  33748. }
  33749. }
  33750. }
  33751. void Desktop::resetTimer()
  33752. {
  33753. if (mouseListeners.size() == 0)
  33754. stopTimer();
  33755. else
  33756. startTimer (100);
  33757. lastFakeMouseMove = getMousePosition();
  33758. }
  33759. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  33760. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  33761. {
  33762. if (kioskModeComponent != componentToUse)
  33763. {
  33764. // agh! Don't delete a component without first stopping it being the kiosk comp
  33765. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  33766. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  33767. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  33768. if (kioskModeComponent->isValidComponent())
  33769. {
  33770. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  33771. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  33772. }
  33773. kioskModeComponent = componentToUse;
  33774. if (kioskModeComponent != 0)
  33775. {
  33776. jassert (kioskModeComponent->isValidComponent());
  33777. // Only components that are already on the desktop can be put into kiosk mode!
  33778. jassert (kioskModeComponent->isOnDesktop());
  33779. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  33780. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  33781. }
  33782. }
  33783. }
  33784. END_JUCE_NAMESPACE
  33785. /*** End of inlined file: juce_Desktop.cpp ***/
  33786. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  33787. BEGIN_JUCE_NAMESPACE
  33788. ArrowButton::ArrowButton (const String& name,
  33789. float arrowDirectionInRadians,
  33790. const Colour& arrowColour)
  33791. : Button (name),
  33792. colour (arrowColour)
  33793. {
  33794. path.lineTo (0.0f, 1.0f);
  33795. path.lineTo (1.0f, 0.5f);
  33796. path.closeSubPath();
  33797. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  33798. 0.5f, 0.5f));
  33799. setComponentEffect (&shadow);
  33800. buttonStateChanged();
  33801. }
  33802. ArrowButton::~ArrowButton()
  33803. {
  33804. }
  33805. void ArrowButton::paintButton (Graphics& g,
  33806. bool /*isMouseOverButton*/,
  33807. bool /*isButtonDown*/)
  33808. {
  33809. g.setColour (colour);
  33810. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  33811. (float) offset,
  33812. (float) (getWidth() - 3),
  33813. (float) (getHeight() - 3),
  33814. false));
  33815. }
  33816. void ArrowButton::buttonStateChanged()
  33817. {
  33818. offset = (isDown()) ? 1 : 0;
  33819. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  33820. 0.3f, -1, 0);
  33821. }
  33822. END_JUCE_NAMESPACE
  33823. /*** End of inlined file: juce_ArrowButton.cpp ***/
  33824. /*** Start of inlined file: juce_Button.cpp ***/
  33825. BEGIN_JUCE_NAMESPACE
  33826. class Button::RepeatTimer : public Timer
  33827. {
  33828. public:
  33829. RepeatTimer (Button& owner_) : owner (owner_) {}
  33830. void timerCallback() { owner.repeatTimerCallback(); }
  33831. juce_UseDebuggingNewOperator
  33832. private:
  33833. Button& owner;
  33834. RepeatTimer (const RepeatTimer&);
  33835. RepeatTimer& operator= (const RepeatTimer&);
  33836. };
  33837. Button::Button (const String& name)
  33838. : Component (name),
  33839. text (name),
  33840. buttonPressTime (0),
  33841. lastTimeCallbackTime (0),
  33842. commandManagerToUse (0),
  33843. autoRepeatDelay (-1),
  33844. autoRepeatSpeed (0),
  33845. autoRepeatMinimumDelay (-1),
  33846. radioGroupId (0),
  33847. commandID (0),
  33848. connectedEdgeFlags (0),
  33849. buttonState (buttonNormal),
  33850. lastToggleState (false),
  33851. clickTogglesState (false),
  33852. needsToRelease (false),
  33853. needsRepainting (false),
  33854. isKeyDown (false),
  33855. triggerOnMouseDown (false),
  33856. generateTooltip (false)
  33857. {
  33858. setWantsKeyboardFocus (true);
  33859. isOn.addListener (this);
  33860. }
  33861. Button::~Button()
  33862. {
  33863. isOn.removeListener (this);
  33864. if (commandManagerToUse != 0)
  33865. commandManagerToUse->removeListener (this);
  33866. repeatTimer = 0;
  33867. clearShortcuts();
  33868. }
  33869. void Button::setButtonText (const String& newText)
  33870. {
  33871. if (text != newText)
  33872. {
  33873. text = newText;
  33874. repaint();
  33875. }
  33876. }
  33877. void Button::setTooltip (const String& newTooltip)
  33878. {
  33879. SettableTooltipClient::setTooltip (newTooltip);
  33880. generateTooltip = false;
  33881. }
  33882. const String Button::getTooltip()
  33883. {
  33884. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  33885. {
  33886. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  33887. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  33888. for (int i = 0; i < keyPresses.size(); ++i)
  33889. {
  33890. const String key (keyPresses.getReference(i).getTextDescription());
  33891. tt << " [";
  33892. if (key.length() == 1)
  33893. tt << TRANS("shortcut") << ": '" << key << "']";
  33894. else
  33895. tt << key << ']';
  33896. }
  33897. return tt;
  33898. }
  33899. return SettableTooltipClient::getTooltip();
  33900. }
  33901. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  33902. {
  33903. if (connectedEdgeFlags != connectedEdgeFlags_)
  33904. {
  33905. connectedEdgeFlags = connectedEdgeFlags_;
  33906. repaint();
  33907. }
  33908. }
  33909. void Button::setToggleState (const bool shouldBeOn,
  33910. const bool sendChangeNotification)
  33911. {
  33912. if (shouldBeOn != lastToggleState)
  33913. {
  33914. isOn = shouldBeOn;
  33915. lastToggleState = shouldBeOn;
  33916. repaint();
  33917. if (sendChangeNotification)
  33918. {
  33919. Component::SafePointer<Component> deletionWatcher (this);
  33920. sendClickMessage (ModifierKeys());
  33921. if (deletionWatcher == 0)
  33922. return;
  33923. }
  33924. if (lastToggleState)
  33925. turnOffOtherButtonsInGroup (sendChangeNotification);
  33926. }
  33927. }
  33928. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  33929. {
  33930. clickTogglesState = shouldToggle;
  33931. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33932. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33933. // it is that this button represents, and the button will update its state to reflect this
  33934. // in the applicationCommandListChanged() method.
  33935. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33936. }
  33937. bool Button::getClickingTogglesState() const throw()
  33938. {
  33939. return clickTogglesState;
  33940. }
  33941. void Button::valueChanged (Value& value)
  33942. {
  33943. if (value.refersToSameSourceAs (isOn))
  33944. setToggleState (isOn.getValue(), true);
  33945. }
  33946. void Button::setRadioGroupId (const int newGroupId)
  33947. {
  33948. if (radioGroupId != newGroupId)
  33949. {
  33950. radioGroupId = newGroupId;
  33951. if (lastToggleState)
  33952. turnOffOtherButtonsInGroup (true);
  33953. }
  33954. }
  33955. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  33956. {
  33957. Component* const p = getParentComponent();
  33958. if (p != 0 && radioGroupId != 0)
  33959. {
  33960. Component::SafePointer<Component> deletionWatcher (this);
  33961. for (int i = p->getNumChildComponents(); --i >= 0;)
  33962. {
  33963. Component* const c = p->getChildComponent (i);
  33964. if (c != this)
  33965. {
  33966. Button* const b = dynamic_cast <Button*> (c);
  33967. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  33968. {
  33969. b->setToggleState (false, sendChangeNotification);
  33970. if (deletionWatcher == 0)
  33971. return;
  33972. }
  33973. }
  33974. }
  33975. }
  33976. }
  33977. void Button::enablementChanged()
  33978. {
  33979. updateState (0);
  33980. repaint();
  33981. }
  33982. Button::ButtonState Button::updateState (const MouseEvent* const e)
  33983. {
  33984. ButtonState state = buttonNormal;
  33985. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  33986. {
  33987. Point<int> mousePos;
  33988. if (e == 0)
  33989. mousePos = getMouseXYRelative();
  33990. else
  33991. mousePos = e->getEventRelativeTo (this).getPosition();
  33992. const bool over = reallyContains (mousePos.getX(), mousePos.getY(), true);
  33993. const bool down = isMouseButtonDown();
  33994. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  33995. state = buttonDown;
  33996. else if (over)
  33997. state = buttonOver;
  33998. }
  33999. setState (state);
  34000. return state;
  34001. }
  34002. void Button::setState (const ButtonState newState)
  34003. {
  34004. if (buttonState != newState)
  34005. {
  34006. buttonState = newState;
  34007. repaint();
  34008. if (buttonState == buttonDown)
  34009. {
  34010. buttonPressTime = Time::getApproximateMillisecondCounter();
  34011. lastTimeCallbackTime = buttonPressTime;
  34012. }
  34013. sendStateMessage();
  34014. }
  34015. }
  34016. bool Button::isDown() const throw()
  34017. {
  34018. return buttonState == buttonDown;
  34019. }
  34020. bool Button::isOver() const throw()
  34021. {
  34022. return buttonState != buttonNormal;
  34023. }
  34024. void Button::buttonStateChanged()
  34025. {
  34026. }
  34027. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  34028. {
  34029. const uint32 now = Time::getApproximateMillisecondCounter();
  34030. return now > buttonPressTime ? now - buttonPressTime : 0;
  34031. }
  34032. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  34033. {
  34034. triggerOnMouseDown = isTriggeredOnMouseDown;
  34035. }
  34036. void Button::clicked()
  34037. {
  34038. }
  34039. void Button::clicked (const ModifierKeys& /*modifiers*/)
  34040. {
  34041. clicked();
  34042. }
  34043. static const int clickMessageId = 0x2f3f4f99;
  34044. void Button::triggerClick()
  34045. {
  34046. postCommandMessage (clickMessageId);
  34047. }
  34048. void Button::internalClickCallback (const ModifierKeys& modifiers)
  34049. {
  34050. if (clickTogglesState)
  34051. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  34052. sendClickMessage (modifiers);
  34053. }
  34054. void Button::flashButtonState()
  34055. {
  34056. if (isEnabled())
  34057. {
  34058. needsToRelease = true;
  34059. setState (buttonDown);
  34060. getRepeatTimer().startTimer (100);
  34061. }
  34062. }
  34063. void Button::handleCommandMessage (int commandId)
  34064. {
  34065. if (commandId == clickMessageId)
  34066. {
  34067. if (isEnabled())
  34068. {
  34069. flashButtonState();
  34070. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34071. }
  34072. }
  34073. else
  34074. {
  34075. Component::handleCommandMessage (commandId);
  34076. }
  34077. }
  34078. void Button::addButtonListener (ButtonListener* const newListener)
  34079. {
  34080. buttonListeners.add (newListener);
  34081. }
  34082. void Button::removeButtonListener (ButtonListener* const listener)
  34083. {
  34084. buttonListeners.remove (listener);
  34085. }
  34086. void Button::sendClickMessage (const ModifierKeys& modifiers)
  34087. {
  34088. Component::BailOutChecker checker (this);
  34089. if (commandManagerToUse != 0 && commandID != 0)
  34090. {
  34091. ApplicationCommandTarget::InvocationInfo info (commandID);
  34092. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  34093. info.originatingComponent = this;
  34094. commandManagerToUse->invoke (info, true);
  34095. }
  34096. clicked (modifiers);
  34097. if (! checker.shouldBailOut())
  34098. buttonListeners.callChecked (checker, &ButtonListener::buttonClicked, this);
  34099. }
  34100. void Button::sendStateMessage()
  34101. {
  34102. Component::BailOutChecker checker (this);
  34103. buttonStateChanged();
  34104. if (! checker.shouldBailOut())
  34105. buttonListeners.callChecked (checker, &ButtonListener::buttonStateChanged, this);
  34106. }
  34107. void Button::paint (Graphics& g)
  34108. {
  34109. if (needsToRelease && isEnabled())
  34110. {
  34111. needsToRelease = false;
  34112. needsRepainting = true;
  34113. }
  34114. paintButton (g, isOver(), isDown());
  34115. }
  34116. void Button::mouseEnter (const MouseEvent& e)
  34117. {
  34118. updateState (&e);
  34119. }
  34120. void Button::mouseExit (const MouseEvent& e)
  34121. {
  34122. updateState (&e);
  34123. }
  34124. void Button::mouseDown (const MouseEvent& e)
  34125. {
  34126. updateState (&e);
  34127. if (isDown())
  34128. {
  34129. if (autoRepeatDelay >= 0)
  34130. getRepeatTimer().startTimer (autoRepeatDelay);
  34131. if (triggerOnMouseDown)
  34132. internalClickCallback (e.mods);
  34133. }
  34134. }
  34135. void Button::mouseUp (const MouseEvent& e)
  34136. {
  34137. const bool wasDown = isDown();
  34138. updateState (&e);
  34139. if (wasDown && isOver() && ! triggerOnMouseDown)
  34140. internalClickCallback (e.mods);
  34141. }
  34142. void Button::mouseDrag (const MouseEvent& e)
  34143. {
  34144. const ButtonState oldState = buttonState;
  34145. updateState (&e);
  34146. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  34147. getRepeatTimer().startTimer (autoRepeatSpeed);
  34148. }
  34149. void Button::focusGained (FocusChangeType)
  34150. {
  34151. updateState (0);
  34152. repaint();
  34153. }
  34154. void Button::focusLost (FocusChangeType)
  34155. {
  34156. updateState (0);
  34157. repaint();
  34158. }
  34159. void Button::setVisible (bool shouldBeVisible)
  34160. {
  34161. if (shouldBeVisible != isVisible())
  34162. {
  34163. Component::setVisible (shouldBeVisible);
  34164. if (! shouldBeVisible)
  34165. needsToRelease = false;
  34166. updateState (0);
  34167. }
  34168. else
  34169. {
  34170. Component::setVisible (shouldBeVisible);
  34171. }
  34172. }
  34173. void Button::parentHierarchyChanged()
  34174. {
  34175. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  34176. if (newKeySource != keySource)
  34177. {
  34178. if (keySource != 0)
  34179. keySource->removeKeyListener (this);
  34180. keySource = newKeySource;
  34181. if (keySource != 0)
  34182. keySource->addKeyListener (this);
  34183. }
  34184. }
  34185. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  34186. const int commandID_,
  34187. const bool generateTooltip_)
  34188. {
  34189. commandID = commandID_;
  34190. generateTooltip = generateTooltip_;
  34191. if (commandManagerToUse != commandManagerToUse_)
  34192. {
  34193. if (commandManagerToUse != 0)
  34194. commandManagerToUse->removeListener (this);
  34195. commandManagerToUse = commandManagerToUse_;
  34196. if (commandManagerToUse != 0)
  34197. commandManagerToUse->addListener (this);
  34198. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34199. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34200. // it is that this button represents, and the button will update its state to reflect this
  34201. // in the applicationCommandListChanged() method.
  34202. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34203. }
  34204. if (commandManagerToUse != 0)
  34205. applicationCommandListChanged();
  34206. else
  34207. setEnabled (true);
  34208. }
  34209. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  34210. {
  34211. if (info.commandID == commandID
  34212. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  34213. {
  34214. flashButtonState();
  34215. }
  34216. }
  34217. void Button::applicationCommandListChanged()
  34218. {
  34219. if (commandManagerToUse != 0)
  34220. {
  34221. ApplicationCommandInfo info (0);
  34222. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  34223. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  34224. if (target != 0)
  34225. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  34226. }
  34227. }
  34228. void Button::addShortcut (const KeyPress& key)
  34229. {
  34230. if (key.isValid())
  34231. {
  34232. jassert (! isRegisteredForShortcut (key)); // already registered!
  34233. shortcuts.add (key);
  34234. parentHierarchyChanged();
  34235. }
  34236. }
  34237. void Button::clearShortcuts()
  34238. {
  34239. shortcuts.clear();
  34240. parentHierarchyChanged();
  34241. }
  34242. bool Button::isShortcutPressed() const
  34243. {
  34244. if (! isCurrentlyBlockedByAnotherModalComponent())
  34245. {
  34246. for (int i = shortcuts.size(); --i >= 0;)
  34247. if (shortcuts.getReference(i).isCurrentlyDown())
  34248. return true;
  34249. }
  34250. return false;
  34251. }
  34252. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  34253. {
  34254. for (int i = shortcuts.size(); --i >= 0;)
  34255. if (key == shortcuts.getReference(i))
  34256. return true;
  34257. return false;
  34258. }
  34259. bool Button::keyStateChanged (const bool, Component*)
  34260. {
  34261. if (! isEnabled())
  34262. return false;
  34263. const bool wasDown = isKeyDown;
  34264. isKeyDown = isShortcutPressed();
  34265. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  34266. getRepeatTimer().startTimer (autoRepeatDelay);
  34267. updateState (0);
  34268. if (isEnabled() && wasDown && ! isKeyDown)
  34269. {
  34270. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34271. // (return immediately - this button may now have been deleted)
  34272. return true;
  34273. }
  34274. return wasDown || isKeyDown;
  34275. }
  34276. bool Button::keyPressed (const KeyPress&, Component*)
  34277. {
  34278. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34279. return isShortcutPressed();
  34280. }
  34281. bool Button::keyPressed (const KeyPress& key)
  34282. {
  34283. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34284. {
  34285. triggerClick();
  34286. return true;
  34287. }
  34288. return false;
  34289. }
  34290. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34291. const int repeatMillisecs,
  34292. const int minimumDelayInMillisecs) throw()
  34293. {
  34294. autoRepeatDelay = initialDelayMillisecs;
  34295. autoRepeatSpeed = repeatMillisecs;
  34296. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34297. }
  34298. void Button::repeatTimerCallback()
  34299. {
  34300. if (needsRepainting)
  34301. {
  34302. getRepeatTimer().stopTimer();
  34303. updateState (0);
  34304. needsRepainting = false;
  34305. }
  34306. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34307. {
  34308. int repeatSpeed = autoRepeatSpeed;
  34309. if (autoRepeatMinimumDelay >= 0)
  34310. {
  34311. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34312. timeHeldDown *= timeHeldDown;
  34313. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34314. }
  34315. repeatSpeed = jmax (1, repeatSpeed);
  34316. getRepeatTimer().startTimer (repeatSpeed);
  34317. const uint32 now = Time::getApproximateMillisecondCounter();
  34318. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34319. lastTimeCallbackTime = now;
  34320. Component::SafePointer<Component> deletionWatcher (this);
  34321. for (int i = numTimesToCallback; --i >= 0;)
  34322. {
  34323. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34324. if (deletionWatcher == 0 || ! isDown())
  34325. return;
  34326. }
  34327. }
  34328. else if (! needsToRelease)
  34329. {
  34330. getRepeatTimer().stopTimer();
  34331. }
  34332. }
  34333. Button::RepeatTimer& Button::getRepeatTimer()
  34334. {
  34335. if (repeatTimer == 0)
  34336. repeatTimer = new RepeatTimer (*this);
  34337. return *repeatTimer;
  34338. }
  34339. END_JUCE_NAMESPACE
  34340. /*** End of inlined file: juce_Button.cpp ***/
  34341. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  34342. BEGIN_JUCE_NAMESPACE
  34343. DrawableButton::DrawableButton (const String& name,
  34344. const DrawableButton::ButtonStyle buttonStyle)
  34345. : Button (name),
  34346. style (buttonStyle),
  34347. edgeIndent (3)
  34348. {
  34349. if (buttonStyle == ImageOnButtonBackground)
  34350. {
  34351. backgroundOff = Colour (0xffbbbbff);
  34352. backgroundOn = Colour (0xff3333ff);
  34353. }
  34354. else
  34355. {
  34356. backgroundOff = Colours::transparentBlack;
  34357. backgroundOn = Colour (0xaabbbbff);
  34358. }
  34359. }
  34360. DrawableButton::~DrawableButton()
  34361. {
  34362. deleteImages();
  34363. }
  34364. void DrawableButton::deleteImages()
  34365. {
  34366. }
  34367. void DrawableButton::setImages (const Drawable* normal,
  34368. const Drawable* over,
  34369. const Drawable* down,
  34370. const Drawable* disabled,
  34371. const Drawable* normalOn,
  34372. const Drawable* overOn,
  34373. const Drawable* downOn,
  34374. const Drawable* disabledOn)
  34375. {
  34376. deleteImages();
  34377. jassert (normal != 0); // you really need to give it at least a normal image..
  34378. if (normal != 0)
  34379. normalImage = normal->createCopy();
  34380. if (over != 0)
  34381. overImage = over->createCopy();
  34382. if (down != 0)
  34383. downImage = down->createCopy();
  34384. if (disabled != 0)
  34385. disabledImage = disabled->createCopy();
  34386. if (normalOn != 0)
  34387. normalImageOn = normalOn->createCopy();
  34388. if (overOn != 0)
  34389. overImageOn = overOn->createCopy();
  34390. if (downOn != 0)
  34391. downImageOn = downOn->createCopy();
  34392. if (disabledOn != 0)
  34393. disabledImageOn = disabledOn->createCopy();
  34394. repaint();
  34395. }
  34396. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34397. {
  34398. if (style != newStyle)
  34399. {
  34400. style = newStyle;
  34401. repaint();
  34402. }
  34403. }
  34404. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34405. const Colour& toggledOnColour)
  34406. {
  34407. if (backgroundOff != toggledOffColour
  34408. || backgroundOn != toggledOnColour)
  34409. {
  34410. backgroundOff = toggledOffColour;
  34411. backgroundOn = toggledOnColour;
  34412. repaint();
  34413. }
  34414. }
  34415. const Colour& DrawableButton::getBackgroundColour() const throw()
  34416. {
  34417. return getToggleState() ? backgroundOn
  34418. : backgroundOff;
  34419. }
  34420. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34421. {
  34422. edgeIndent = numPixelsIndent;
  34423. repaint();
  34424. }
  34425. void DrawableButton::paintButton (Graphics& g,
  34426. bool isMouseOverButton,
  34427. bool isButtonDown)
  34428. {
  34429. Rectangle<int> imageSpace;
  34430. if (style == ImageOnButtonBackground)
  34431. {
  34432. const int insetX = getWidth() / 4;
  34433. const int insetY = getHeight() / 4;
  34434. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34435. getLookAndFeel().drawButtonBackground (g, *this,
  34436. getBackgroundColour(),
  34437. isMouseOverButton,
  34438. isButtonDown);
  34439. }
  34440. else
  34441. {
  34442. g.fillAll (getBackgroundColour());
  34443. const int textH = (style == ImageAboveTextLabel)
  34444. ? jmin (16, proportionOfHeight (0.25f))
  34445. : 0;
  34446. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34447. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34448. imageSpace.setBounds (indentX, indentY,
  34449. getWidth() - indentX * 2,
  34450. getHeight() - indentY * 2 - textH);
  34451. if (textH > 0)
  34452. {
  34453. g.setFont ((float) textH);
  34454. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34455. g.drawFittedText (getButtonText(),
  34456. 2, getHeight() - textH - 1,
  34457. getWidth() - 4, textH,
  34458. Justification::centred, 1);
  34459. }
  34460. }
  34461. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34462. g.setOpacity (1.0f);
  34463. const Drawable* imageToDraw = 0;
  34464. if (isEnabled())
  34465. {
  34466. imageToDraw = getCurrentImage();
  34467. }
  34468. else
  34469. {
  34470. imageToDraw = getToggleState() ? disabledImageOn
  34471. : disabledImage;
  34472. if (imageToDraw == 0)
  34473. {
  34474. g.setOpacity (0.4f);
  34475. imageToDraw = getNormalImage();
  34476. }
  34477. }
  34478. if (imageToDraw != 0)
  34479. {
  34480. if (style == ImageRaw)
  34481. {
  34482. imageToDraw->draw (g, 1.0f);
  34483. }
  34484. else
  34485. {
  34486. imageToDraw->drawWithin (g,
  34487. imageSpace.getX(),
  34488. imageSpace.getY(),
  34489. imageSpace.getWidth(),
  34490. imageSpace.getHeight(),
  34491. RectanglePlacement::centred,
  34492. 1.0f);
  34493. }
  34494. }
  34495. }
  34496. const Drawable* DrawableButton::getCurrentImage() const throw()
  34497. {
  34498. if (isDown())
  34499. return getDownImage();
  34500. if (isOver())
  34501. return getOverImage();
  34502. return getNormalImage();
  34503. }
  34504. const Drawable* DrawableButton::getNormalImage() const throw()
  34505. {
  34506. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34507. : normalImage;
  34508. }
  34509. const Drawable* DrawableButton::getOverImage() const throw()
  34510. {
  34511. const Drawable* d = normalImage;
  34512. if (getToggleState())
  34513. {
  34514. if (overImageOn != 0)
  34515. d = overImageOn;
  34516. else if (normalImageOn != 0)
  34517. d = normalImageOn;
  34518. else if (overImage != 0)
  34519. d = overImage;
  34520. }
  34521. else
  34522. {
  34523. if (overImage != 0)
  34524. d = overImage;
  34525. }
  34526. return d;
  34527. }
  34528. const Drawable* DrawableButton::getDownImage() const throw()
  34529. {
  34530. const Drawable* d = normalImage;
  34531. if (getToggleState())
  34532. {
  34533. if (downImageOn != 0)
  34534. d = downImageOn;
  34535. else if (overImageOn != 0)
  34536. d = overImageOn;
  34537. else if (normalImageOn != 0)
  34538. d = normalImageOn;
  34539. else if (downImage != 0)
  34540. d = downImage;
  34541. else
  34542. d = getOverImage();
  34543. }
  34544. else
  34545. {
  34546. if (downImage != 0)
  34547. d = downImage;
  34548. else
  34549. d = getOverImage();
  34550. }
  34551. return d;
  34552. }
  34553. END_JUCE_NAMESPACE
  34554. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34555. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34556. BEGIN_JUCE_NAMESPACE
  34557. HyperlinkButton::HyperlinkButton (const String& linkText,
  34558. const URL& linkURL)
  34559. : Button (linkText),
  34560. url (linkURL),
  34561. font (14.0f, Font::underlined),
  34562. resizeFont (true),
  34563. justification (Justification::centred)
  34564. {
  34565. setMouseCursor (MouseCursor::PointingHandCursor);
  34566. setTooltip (linkURL.toString (false));
  34567. }
  34568. HyperlinkButton::~HyperlinkButton()
  34569. {
  34570. }
  34571. void HyperlinkButton::setFont (const Font& newFont,
  34572. const bool resizeToMatchComponentHeight,
  34573. const Justification& justificationType)
  34574. {
  34575. font = newFont;
  34576. resizeFont = resizeToMatchComponentHeight;
  34577. justification = justificationType;
  34578. repaint();
  34579. }
  34580. void HyperlinkButton::setURL (const URL& newURL) throw()
  34581. {
  34582. url = newURL;
  34583. setTooltip (newURL.toString (false));
  34584. }
  34585. const Font HyperlinkButton::getFontToUse() const
  34586. {
  34587. Font f (font);
  34588. if (resizeFont)
  34589. f.setHeight (getHeight() * 0.7f);
  34590. return f;
  34591. }
  34592. void HyperlinkButton::changeWidthToFitText()
  34593. {
  34594. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34595. }
  34596. void HyperlinkButton::colourChanged()
  34597. {
  34598. repaint();
  34599. }
  34600. void HyperlinkButton::clicked()
  34601. {
  34602. if (url.isWellFormed())
  34603. url.launchInDefaultBrowser();
  34604. }
  34605. void HyperlinkButton::paintButton (Graphics& g,
  34606. bool isMouseOverButton,
  34607. bool isButtonDown)
  34608. {
  34609. const Colour textColour (findColour (textColourId));
  34610. if (isEnabled())
  34611. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34612. : textColour);
  34613. else
  34614. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34615. g.setFont (getFontToUse());
  34616. g.drawText (getButtonText(),
  34617. 2, 0, getWidth() - 2, getHeight(),
  34618. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34619. true);
  34620. }
  34621. END_JUCE_NAMESPACE
  34622. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34623. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34624. BEGIN_JUCE_NAMESPACE
  34625. ImageButton::ImageButton (const String& text_)
  34626. : Button (text_),
  34627. scaleImageToFit (true),
  34628. preserveProportions (true),
  34629. alphaThreshold (0),
  34630. imageX (0),
  34631. imageY (0),
  34632. imageW (0),
  34633. imageH (0),
  34634. normalImage (0),
  34635. overImage (0),
  34636. downImage (0)
  34637. {
  34638. }
  34639. ImageButton::~ImageButton()
  34640. {
  34641. deleteImages();
  34642. }
  34643. void ImageButton::deleteImages()
  34644. {
  34645. ImageCache::releaseOrDelete (normalImage);
  34646. ImageCache::releaseOrDelete (overImage);
  34647. ImageCache::releaseOrDelete (downImage);
  34648. }
  34649. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  34650. const bool rescaleImagesWhenButtonSizeChanges,
  34651. const bool preserveImageProportions,
  34652. Image* const normalImage_,
  34653. const float imageOpacityWhenNormal,
  34654. const Colour& overlayColourWhenNormal,
  34655. Image* const overImage_,
  34656. const float imageOpacityWhenOver,
  34657. const Colour& overlayColourWhenOver,
  34658. Image* const downImage_,
  34659. const float imageOpacityWhenDown,
  34660. const Colour& overlayColourWhenDown,
  34661. const float hitTestAlphaThreshold)
  34662. {
  34663. deleteImages();
  34664. normalImage = normalImage_;
  34665. overImage = overImage_;
  34666. downImage = downImage_;
  34667. if (resizeButtonNowToFitThisImage && normalImage != 0)
  34668. {
  34669. imageW = normalImage->getWidth();
  34670. imageH = normalImage->getHeight();
  34671. setSize (imageW, imageH);
  34672. }
  34673. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  34674. preserveProportions = preserveImageProportions;
  34675. normalOpacity = imageOpacityWhenNormal;
  34676. normalOverlay = overlayColourWhenNormal;
  34677. overOpacity = imageOpacityWhenOver;
  34678. overOverlay = overlayColourWhenOver;
  34679. downOpacity = imageOpacityWhenDown;
  34680. downOverlay = overlayColourWhenDown;
  34681. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  34682. repaint();
  34683. }
  34684. Image* ImageButton::getCurrentImage() const
  34685. {
  34686. if (isDown() || getToggleState())
  34687. return getDownImage();
  34688. if (isOver())
  34689. return getOverImage();
  34690. return getNormalImage();
  34691. }
  34692. Image* ImageButton::getNormalImage() const throw()
  34693. {
  34694. return normalImage;
  34695. }
  34696. Image* ImageButton::getOverImage() const throw()
  34697. {
  34698. return (overImage != 0) ? overImage
  34699. : normalImage;
  34700. }
  34701. Image* ImageButton::getDownImage() const throw()
  34702. {
  34703. return (downImage != 0) ? downImage
  34704. : getOverImage();
  34705. }
  34706. void ImageButton::paintButton (Graphics& g,
  34707. bool isMouseOverButton,
  34708. bool isButtonDown)
  34709. {
  34710. if (! isEnabled())
  34711. {
  34712. isMouseOverButton = false;
  34713. isButtonDown = false;
  34714. }
  34715. Image* const im = getCurrentImage();
  34716. if (im != 0)
  34717. {
  34718. const int iw = im->getWidth();
  34719. const int ih = im->getHeight();
  34720. imageW = getWidth();
  34721. imageH = getHeight();
  34722. imageX = (imageW - iw) >> 1;
  34723. imageY = (imageH - ih) >> 1;
  34724. if (scaleImageToFit)
  34725. {
  34726. if (preserveProportions)
  34727. {
  34728. int newW, newH;
  34729. const float imRatio = ih / (float)iw;
  34730. const float destRatio = imageH / (float)imageW;
  34731. if (imRatio > destRatio)
  34732. {
  34733. newW = roundToInt (imageH / imRatio);
  34734. newH = imageH;
  34735. }
  34736. else
  34737. {
  34738. newW = imageW;
  34739. newH = roundToInt (imageW * imRatio);
  34740. }
  34741. imageX = (imageW - newW) / 2;
  34742. imageY = (imageH - newH) / 2;
  34743. imageW = newW;
  34744. imageH = newH;
  34745. }
  34746. else
  34747. {
  34748. imageX = 0;
  34749. imageY = 0;
  34750. }
  34751. }
  34752. if (! scaleImageToFit)
  34753. {
  34754. imageW = iw;
  34755. imageH = ih;
  34756. }
  34757. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  34758. isButtonDown ? downOverlay
  34759. : (isMouseOverButton ? overOverlay
  34760. : normalOverlay),
  34761. isButtonDown ? downOpacity
  34762. : (isMouseOverButton ? overOpacity
  34763. : normalOpacity),
  34764. *this);
  34765. }
  34766. }
  34767. bool ImageButton::hitTest (int x, int y)
  34768. {
  34769. if (alphaThreshold == 0)
  34770. return true;
  34771. Image* const im = getCurrentImage();
  34772. return im == 0
  34773. || (imageW > 0 && imageH > 0
  34774. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  34775. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  34776. }
  34777. END_JUCE_NAMESPACE
  34778. /*** End of inlined file: juce_ImageButton.cpp ***/
  34779. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  34780. BEGIN_JUCE_NAMESPACE
  34781. ShapeButton::ShapeButton (const String& text_,
  34782. const Colour& normalColour_,
  34783. const Colour& overColour_,
  34784. const Colour& downColour_)
  34785. : Button (text_),
  34786. normalColour (normalColour_),
  34787. overColour (overColour_),
  34788. downColour (downColour_),
  34789. maintainShapeProportions (false),
  34790. outlineWidth (0.0f)
  34791. {
  34792. }
  34793. ShapeButton::~ShapeButton()
  34794. {
  34795. }
  34796. void ShapeButton::setColours (const Colour& newNormalColour,
  34797. const Colour& newOverColour,
  34798. const Colour& newDownColour)
  34799. {
  34800. normalColour = newNormalColour;
  34801. overColour = newOverColour;
  34802. downColour = newDownColour;
  34803. }
  34804. void ShapeButton::setOutline (const Colour& newOutlineColour,
  34805. const float newOutlineWidth)
  34806. {
  34807. outlineColour = newOutlineColour;
  34808. outlineWidth = newOutlineWidth;
  34809. }
  34810. void ShapeButton::setShape (const Path& newShape,
  34811. const bool resizeNowToFitThisShape,
  34812. const bool maintainShapeProportions_,
  34813. const bool hasShadow)
  34814. {
  34815. shape = newShape;
  34816. maintainShapeProportions = maintainShapeProportions_;
  34817. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  34818. setComponentEffect ((hasShadow) ? &shadow : 0);
  34819. if (resizeNowToFitThisShape)
  34820. {
  34821. Rectangle<float> bounds (shape.getBounds());
  34822. if (hasShadow)
  34823. bounds.expand (4.0f, 4.0f);
  34824. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  34825. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  34826. 1 + (int) (bounds.getHeight() + outlineWidth));
  34827. }
  34828. }
  34829. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  34830. {
  34831. if (! isEnabled())
  34832. {
  34833. isMouseOverButton = false;
  34834. isButtonDown = false;
  34835. }
  34836. g.setColour ((isButtonDown) ? downColour
  34837. : (isMouseOverButton) ? overColour
  34838. : normalColour);
  34839. int w = getWidth();
  34840. int h = getHeight();
  34841. if (getComponentEffect() != 0)
  34842. {
  34843. w -= 4;
  34844. h -= 4;
  34845. }
  34846. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  34847. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  34848. w - offset - outlineWidth,
  34849. h - offset - outlineWidth,
  34850. maintainShapeProportions));
  34851. g.fillPath (shape, trans);
  34852. if (outlineWidth > 0.0f)
  34853. {
  34854. g.setColour (outlineColour);
  34855. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  34856. }
  34857. }
  34858. END_JUCE_NAMESPACE
  34859. /*** End of inlined file: juce_ShapeButton.cpp ***/
  34860. /*** Start of inlined file: juce_TextButton.cpp ***/
  34861. BEGIN_JUCE_NAMESPACE
  34862. TextButton::TextButton (const String& name,
  34863. const String& toolTip)
  34864. : Button (name)
  34865. {
  34866. setTooltip (toolTip);
  34867. }
  34868. TextButton::~TextButton()
  34869. {
  34870. }
  34871. void TextButton::paintButton (Graphics& g,
  34872. bool isMouseOverButton,
  34873. bool isButtonDown)
  34874. {
  34875. getLookAndFeel().drawButtonBackground (g, *this,
  34876. findColour (getToggleState() ? buttonOnColourId
  34877. : buttonColourId),
  34878. isMouseOverButton,
  34879. isButtonDown);
  34880. getLookAndFeel().drawButtonText (g, *this,
  34881. isMouseOverButton,
  34882. isButtonDown);
  34883. }
  34884. void TextButton::colourChanged()
  34885. {
  34886. repaint();
  34887. }
  34888. const Font TextButton::getFont()
  34889. {
  34890. return Font (jmin (15.0f, getHeight() * 0.6f));
  34891. }
  34892. void TextButton::changeWidthToFitText (const int newHeight)
  34893. {
  34894. if (newHeight >= 0)
  34895. setSize (jmax (1, getWidth()), newHeight);
  34896. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  34897. getHeight());
  34898. }
  34899. END_JUCE_NAMESPACE
  34900. /*** End of inlined file: juce_TextButton.cpp ***/
  34901. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  34902. BEGIN_JUCE_NAMESPACE
  34903. ToggleButton::ToggleButton (const String& buttonText)
  34904. : Button (buttonText)
  34905. {
  34906. setClickingTogglesState (true);
  34907. }
  34908. ToggleButton::~ToggleButton()
  34909. {
  34910. }
  34911. void ToggleButton::paintButton (Graphics& g,
  34912. bool isMouseOverButton,
  34913. bool isButtonDown)
  34914. {
  34915. getLookAndFeel().drawToggleButton (g, *this,
  34916. isMouseOverButton,
  34917. isButtonDown);
  34918. }
  34919. void ToggleButton::changeWidthToFitText()
  34920. {
  34921. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  34922. }
  34923. void ToggleButton::colourChanged()
  34924. {
  34925. repaint();
  34926. }
  34927. END_JUCE_NAMESPACE
  34928. /*** End of inlined file: juce_ToggleButton.cpp ***/
  34929. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  34930. BEGIN_JUCE_NAMESPACE
  34931. ToolbarButton::ToolbarButton (const int itemId_,
  34932. const String& buttonText,
  34933. Drawable* const normalImage_,
  34934. Drawable* const toggledOnImage_)
  34935. : ToolbarItemComponent (itemId_, buttonText, true),
  34936. normalImage (normalImage_),
  34937. toggledOnImage (toggledOnImage_)
  34938. {
  34939. }
  34940. ToolbarButton::~ToolbarButton()
  34941. {
  34942. }
  34943. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  34944. bool /*isToolbarVertical*/,
  34945. int& preferredSize,
  34946. int& minSize, int& maxSize)
  34947. {
  34948. preferredSize = minSize = maxSize = toolbarDepth;
  34949. return true;
  34950. }
  34951. void ToolbarButton::paintButtonArea (Graphics& g,
  34952. int width, int height,
  34953. bool /*isMouseOver*/,
  34954. bool /*isMouseDown*/)
  34955. {
  34956. Drawable* d = normalImage;
  34957. if (getToggleState() && toggledOnImage != 0)
  34958. d = toggledOnImage;
  34959. if (! isEnabled())
  34960. {
  34961. Image im (Image::ARGB, width, height, true);
  34962. Graphics g2 (im);
  34963. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34964. im.desaturate();
  34965. g.drawImageAt (&im, 0, 0);
  34966. }
  34967. else
  34968. {
  34969. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34970. }
  34971. }
  34972. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  34973. {
  34974. }
  34975. END_JUCE_NAMESPACE
  34976. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  34977. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  34978. BEGIN_JUCE_NAMESPACE
  34979. class CodeDocumentLine
  34980. {
  34981. public:
  34982. CodeDocumentLine (const tchar* const line_,
  34983. const int lineLength_,
  34984. const int numNewLineChars,
  34985. const int lineStartInFile_)
  34986. : line (line_, lineLength_),
  34987. lineStartInFile (lineStartInFile_),
  34988. lineLength (lineLength_),
  34989. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  34990. {
  34991. }
  34992. ~CodeDocumentLine()
  34993. {
  34994. }
  34995. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  34996. {
  34997. const tchar* const t = (const tchar*) text;
  34998. int pos = 0;
  34999. while (t [pos] != 0)
  35000. {
  35001. const int startOfLine = pos;
  35002. int numNewLineChars = 0;
  35003. while (t[pos] != 0)
  35004. {
  35005. if (t[pos] == T('\r'))
  35006. {
  35007. ++numNewLineChars;
  35008. ++pos;
  35009. if (t[pos] == T('\n'))
  35010. {
  35011. ++numNewLineChars;
  35012. ++pos;
  35013. }
  35014. break;
  35015. }
  35016. if (t[pos] == T('\n'))
  35017. {
  35018. ++numNewLineChars;
  35019. ++pos;
  35020. break;
  35021. }
  35022. ++pos;
  35023. }
  35024. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  35025. numNewLineChars, startOfLine));
  35026. }
  35027. jassert (pos == text.length());
  35028. }
  35029. bool endsWithLineBreak() const throw()
  35030. {
  35031. return lineLengthWithoutNewLines != lineLength;
  35032. }
  35033. void updateLength() throw()
  35034. {
  35035. lineLengthWithoutNewLines = lineLength = line.length();
  35036. while (lineLengthWithoutNewLines > 0
  35037. && (line [lineLengthWithoutNewLines - 1] == '\n'
  35038. || line [lineLengthWithoutNewLines - 1] == '\r'))
  35039. {
  35040. --lineLengthWithoutNewLines;
  35041. }
  35042. }
  35043. String line;
  35044. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  35045. };
  35046. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  35047. : document (document_),
  35048. currentLine (document_->lines[0]),
  35049. line (0),
  35050. position (0)
  35051. {
  35052. }
  35053. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  35054. : document (other.document),
  35055. currentLine (other.currentLine),
  35056. line (other.line),
  35057. position (other.position)
  35058. {
  35059. }
  35060. CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  35061. {
  35062. document = other.document;
  35063. currentLine = other.currentLine;
  35064. line = other.line;
  35065. position = other.position;
  35066. return *this;
  35067. }
  35068. CodeDocument::Iterator::~Iterator() throw()
  35069. {
  35070. }
  35071. juce_wchar CodeDocument::Iterator::nextChar()
  35072. {
  35073. if (currentLine == 0)
  35074. return 0;
  35075. jassert (currentLine == document->lines.getUnchecked (line));
  35076. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  35077. skip();
  35078. return result;
  35079. }
  35080. void CodeDocument::Iterator::skip()
  35081. {
  35082. if (currentLine != 0)
  35083. {
  35084. jassert (currentLine == document->lines.getUnchecked (line));
  35085. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  35086. {
  35087. ++line;
  35088. currentLine = document->lines [line];
  35089. }
  35090. }
  35091. }
  35092. void CodeDocument::Iterator::skipToEndOfLine()
  35093. {
  35094. if (currentLine != 0)
  35095. {
  35096. jassert (currentLine == document->lines.getUnchecked (line));
  35097. ++line;
  35098. currentLine = document->lines [line];
  35099. if (currentLine != 0)
  35100. position = currentLine->lineStartInFile;
  35101. else
  35102. position = document->getNumCharacters();
  35103. }
  35104. }
  35105. juce_wchar CodeDocument::Iterator::peekNextChar() const
  35106. {
  35107. if (currentLine == 0)
  35108. return 0;
  35109. jassert (currentLine == document->lines.getUnchecked (line));
  35110. return currentLine->line [position - currentLine->lineStartInFile];
  35111. }
  35112. void CodeDocument::Iterator::skipWhitespace()
  35113. {
  35114. while (CharacterFunctions::isWhitespace (peekNextChar()))
  35115. skip();
  35116. }
  35117. bool CodeDocument::Iterator::isEOF() const throw()
  35118. {
  35119. return currentLine == 0;
  35120. }
  35121. CodeDocument::Position::Position() throw()
  35122. : owner (0), characterPos (0), line (0),
  35123. indexInLine (0), positionMaintained (false)
  35124. {
  35125. }
  35126. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35127. const int line_, const int indexInLine_) throw()
  35128. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35129. characterPos (0), line (line_),
  35130. indexInLine (indexInLine_), positionMaintained (false)
  35131. {
  35132. setLineAndIndex (line_, indexInLine_);
  35133. }
  35134. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35135. const int characterPos_) throw()
  35136. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35137. positionMaintained (false)
  35138. {
  35139. setPosition (characterPos_);
  35140. }
  35141. CodeDocument::Position::Position (const Position& other) throw()
  35142. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  35143. indexInLine (other.indexInLine), positionMaintained (false)
  35144. {
  35145. jassert (*this == other);
  35146. }
  35147. CodeDocument::Position::~Position() throw()
  35148. {
  35149. setPositionMaintained (false);
  35150. }
  35151. CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  35152. {
  35153. if (this != &other)
  35154. {
  35155. const bool wasPositionMaintained = positionMaintained;
  35156. if (owner != other.owner)
  35157. setPositionMaintained (false);
  35158. owner = other.owner;
  35159. line = other.line;
  35160. indexInLine = other.indexInLine;
  35161. characterPos = other.characterPos;
  35162. setPositionMaintained (wasPositionMaintained);
  35163. jassert (*this == other);
  35164. }
  35165. return *this;
  35166. }
  35167. bool CodeDocument::Position::operator== (const Position& other) const throw()
  35168. {
  35169. jassert ((characterPos == other.characterPos)
  35170. == (line == other.line && indexInLine == other.indexInLine));
  35171. return characterPos == other.characterPos
  35172. && line == other.line
  35173. && indexInLine == other.indexInLine
  35174. && owner == other.owner;
  35175. }
  35176. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  35177. {
  35178. return ! operator== (other);
  35179. }
  35180. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  35181. {
  35182. jassert (owner != 0);
  35183. if (owner->lines.size() == 0)
  35184. {
  35185. line = 0;
  35186. indexInLine = 0;
  35187. characterPos = 0;
  35188. }
  35189. else
  35190. {
  35191. if (newLine >= owner->lines.size())
  35192. {
  35193. line = owner->lines.size() - 1;
  35194. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35195. jassert (l != 0);
  35196. indexInLine = l->lineLengthWithoutNewLines;
  35197. characterPos = l->lineStartInFile + indexInLine;
  35198. }
  35199. else
  35200. {
  35201. line = jmax (0, newLine);
  35202. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35203. jassert (l != 0);
  35204. if (l->lineLengthWithoutNewLines > 0)
  35205. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  35206. else
  35207. indexInLine = 0;
  35208. characterPos = l->lineStartInFile + indexInLine;
  35209. }
  35210. }
  35211. }
  35212. void CodeDocument::Position::setPosition (const int newPosition) throw()
  35213. {
  35214. jassert (owner != 0);
  35215. line = 0;
  35216. indexInLine = 0;
  35217. characterPos = 0;
  35218. if (newPosition > 0)
  35219. {
  35220. int lineStart = 0;
  35221. int lineEnd = owner->lines.size();
  35222. for (;;)
  35223. {
  35224. if (lineEnd - lineStart < 4)
  35225. {
  35226. for (int i = lineStart; i < lineEnd; ++i)
  35227. {
  35228. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  35229. int index = newPosition - l->lineStartInFile;
  35230. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  35231. {
  35232. line = i;
  35233. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  35234. characterPos = l->lineStartInFile + indexInLine;
  35235. }
  35236. }
  35237. break;
  35238. }
  35239. else
  35240. {
  35241. const int midIndex = (lineStart + lineEnd + 1) / 2;
  35242. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  35243. if (newPosition >= mid->lineStartInFile)
  35244. lineStart = midIndex;
  35245. else
  35246. lineEnd = midIndex;
  35247. }
  35248. }
  35249. }
  35250. }
  35251. void CodeDocument::Position::moveBy (int characterDelta) throw()
  35252. {
  35253. jassert (owner != 0);
  35254. if (characterDelta == 1)
  35255. {
  35256. setPosition (getPosition());
  35257. // If moving right, make sure we don't get stuck between the \r and \n characters..
  35258. if (line < owner->lines.size())
  35259. {
  35260. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35261. if (indexInLine + characterDelta < l->lineLength
  35262. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  35263. ++characterDelta;
  35264. }
  35265. }
  35266. setPosition (characterPos + characterDelta);
  35267. }
  35268. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35269. {
  35270. CodeDocument::Position p (*this);
  35271. p.moveBy (characterDelta);
  35272. return p;
  35273. }
  35274. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35275. {
  35276. CodeDocument::Position p (*this);
  35277. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35278. return p;
  35279. }
  35280. const tchar CodeDocument::Position::getCharacter() const throw()
  35281. {
  35282. const CodeDocumentLine* const l = owner->lines [line];
  35283. return l == 0 ? 0 : l->line [getIndexInLine()];
  35284. }
  35285. const String CodeDocument::Position::getLineText() const throw()
  35286. {
  35287. const CodeDocumentLine* const l = owner->lines [line];
  35288. return l == 0 ? String::empty : l->line;
  35289. }
  35290. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35291. {
  35292. if (isMaintained != positionMaintained)
  35293. {
  35294. positionMaintained = isMaintained;
  35295. if (owner != 0)
  35296. {
  35297. if (isMaintained)
  35298. {
  35299. jassert (! owner->positionsToMaintain.contains (this));
  35300. owner->positionsToMaintain.add (this);
  35301. }
  35302. else
  35303. {
  35304. jassert (owner->positionsToMaintain.contains (this));
  35305. owner->positionsToMaintain.removeValue (this);
  35306. }
  35307. }
  35308. }
  35309. }
  35310. CodeDocument::CodeDocument()
  35311. : undoManager (std::numeric_limits<int>::max(), 10000),
  35312. currentActionIndex (0),
  35313. indexOfSavedState (-1),
  35314. maximumLineLength (-1),
  35315. newLineChars ("\r\n")
  35316. {
  35317. }
  35318. CodeDocument::~CodeDocument()
  35319. {
  35320. }
  35321. const String CodeDocument::getAllContent() const throw()
  35322. {
  35323. return getTextBetween (Position (this, 0),
  35324. Position (this, lines.size(), 0));
  35325. }
  35326. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35327. {
  35328. if (end.getPosition() <= start.getPosition())
  35329. return String::empty;
  35330. const int startLine = start.getLineNumber();
  35331. const int endLine = end.getLineNumber();
  35332. if (startLine == endLine)
  35333. {
  35334. CodeDocumentLine* const line = lines [startLine];
  35335. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35336. }
  35337. String result;
  35338. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35339. String::Concatenator concatenator (result);
  35340. const int maxLine = jmin (lines.size() - 1, endLine);
  35341. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35342. {
  35343. const CodeDocumentLine* line = lines.getUnchecked(i);
  35344. int len = line->lineLength;
  35345. if (i == startLine)
  35346. {
  35347. const int index = start.getIndexInLine();
  35348. concatenator.append (line->line.substring (index, len));
  35349. }
  35350. else if (i == endLine)
  35351. {
  35352. len = end.getIndexInLine();
  35353. concatenator.append (line->line.substring (0, len));
  35354. }
  35355. else
  35356. {
  35357. concatenator.append (line->line);
  35358. }
  35359. }
  35360. return result;
  35361. }
  35362. int CodeDocument::getNumCharacters() const throw()
  35363. {
  35364. const CodeDocumentLine* const lastLine = lines.getLast();
  35365. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35366. }
  35367. const String CodeDocument::getLine (const int lineIndex) const throw()
  35368. {
  35369. const CodeDocumentLine* const line = lines [lineIndex];
  35370. return (line == 0) ? String::empty : line->line;
  35371. }
  35372. int CodeDocument::getMaximumLineLength() throw()
  35373. {
  35374. if (maximumLineLength < 0)
  35375. {
  35376. maximumLineLength = 0;
  35377. for (int i = lines.size(); --i >= 0;)
  35378. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35379. }
  35380. return maximumLineLength;
  35381. }
  35382. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35383. {
  35384. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35385. }
  35386. void CodeDocument::insertText (const Position& position, const String& text)
  35387. {
  35388. insert (text, position.getPosition(), true);
  35389. }
  35390. void CodeDocument::replaceAllContent (const String& newContent)
  35391. {
  35392. remove (0, getNumCharacters(), true);
  35393. insert (newContent, 0, true);
  35394. }
  35395. bool CodeDocument::loadFromStream (InputStream& stream)
  35396. {
  35397. replaceAllContent (stream.readEntireStreamAsString());
  35398. setSavePoint();
  35399. clearUndoHistory();
  35400. return true;
  35401. }
  35402. bool CodeDocument::writeToStream (OutputStream& stream)
  35403. {
  35404. for (int i = 0; i < lines.size(); ++i)
  35405. {
  35406. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35407. const char* utf8 = temp.toUTF8();
  35408. if (! stream.write (utf8, (int) strlen (utf8)))
  35409. return false;
  35410. }
  35411. return true;
  35412. }
  35413. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35414. {
  35415. jassert (newLine == T("\r\n") || newLine == T("\n") || newLine == T("\r"));
  35416. newLineChars = newLine;
  35417. }
  35418. void CodeDocument::newTransaction()
  35419. {
  35420. undoManager.beginNewTransaction (String::empty);
  35421. }
  35422. void CodeDocument::undo()
  35423. {
  35424. newTransaction();
  35425. undoManager.undo();
  35426. }
  35427. void CodeDocument::redo()
  35428. {
  35429. undoManager.redo();
  35430. }
  35431. void CodeDocument::clearUndoHistory()
  35432. {
  35433. undoManager.clearUndoHistory();
  35434. }
  35435. void CodeDocument::setSavePoint() throw()
  35436. {
  35437. indexOfSavedState = currentActionIndex;
  35438. }
  35439. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35440. {
  35441. return currentActionIndex != indexOfSavedState;
  35442. }
  35443. static int getCodeCharacterCategory (const tchar character) throw()
  35444. {
  35445. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35446. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35447. }
  35448. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35449. {
  35450. Position p (position);
  35451. const int maxDistance = 256;
  35452. int i = 0;
  35453. while (i < maxDistance
  35454. && CharacterFunctions::isWhitespace (p.getCharacter())
  35455. && (i == 0 || (p.getCharacter() != T('\n')
  35456. && p.getCharacter() != T('\r'))))
  35457. {
  35458. ++i;
  35459. p.moveBy (1);
  35460. }
  35461. if (i == 0)
  35462. {
  35463. const int type = getCodeCharacterCategory (p.getCharacter());
  35464. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35465. {
  35466. ++i;
  35467. p.moveBy (1);
  35468. }
  35469. while (i < maxDistance
  35470. && CharacterFunctions::isWhitespace (p.getCharacter())
  35471. && (i == 0 || (p.getCharacter() != T('\n')
  35472. && p.getCharacter() != T('\r'))))
  35473. {
  35474. ++i;
  35475. p.moveBy (1);
  35476. }
  35477. }
  35478. return p;
  35479. }
  35480. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35481. {
  35482. Position p (position);
  35483. const int maxDistance = 256;
  35484. int i = 0;
  35485. bool stoppedAtLineStart = false;
  35486. while (i < maxDistance)
  35487. {
  35488. const tchar c = p.movedBy (-1).getCharacter();
  35489. if (c == T('\r') || c == T('\n'))
  35490. {
  35491. stoppedAtLineStart = true;
  35492. if (i > 0)
  35493. break;
  35494. }
  35495. if (! CharacterFunctions::isWhitespace (c))
  35496. break;
  35497. p.moveBy (-1);
  35498. ++i;
  35499. }
  35500. if (i < maxDistance && ! stoppedAtLineStart)
  35501. {
  35502. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35503. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35504. {
  35505. p.moveBy (-1);
  35506. ++i;
  35507. }
  35508. }
  35509. return p;
  35510. }
  35511. void CodeDocument::checkLastLineStatus()
  35512. {
  35513. while (lines.size() > 0
  35514. && lines.getLast()->lineLength == 0
  35515. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35516. {
  35517. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35518. lines.removeLast();
  35519. }
  35520. const CodeDocumentLine* const lastLine = lines.getLast();
  35521. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35522. {
  35523. // check that there's an empty line at the end if the preceding one ends in a newline..
  35524. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35525. }
  35526. }
  35527. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35528. {
  35529. listeners.addIfNotAlreadyThere (listener);
  35530. }
  35531. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35532. {
  35533. listeners.removeValue (listener);
  35534. }
  35535. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35536. {
  35537. const Position startPos (this, startLine, 0);
  35538. const Position endPos (this, endLine, 0);
  35539. for (int i = listeners.size(); --i >= 0;)
  35540. {
  35541. Listener* const l = (Listener*) listeners[i];
  35542. if (l != 0)
  35543. l->codeDocumentChanged (startPos, endPos);
  35544. }
  35545. }
  35546. class CodeDocumentInsertAction : public UndoableAction
  35547. {
  35548. CodeDocument& owner;
  35549. const String text;
  35550. int insertPos;
  35551. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35552. CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35553. public:
  35554. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35555. : owner (owner_),
  35556. text (text_),
  35557. insertPos (insertPos_)
  35558. {
  35559. }
  35560. ~CodeDocumentInsertAction() {}
  35561. bool perform()
  35562. {
  35563. owner.currentActionIndex++;
  35564. owner.insert (text, insertPos, false);
  35565. return true;
  35566. }
  35567. bool undo()
  35568. {
  35569. owner.currentActionIndex--;
  35570. owner.remove (insertPos, insertPos + text.length(), false);
  35571. return true;
  35572. }
  35573. int getSizeInUnits() { return text.length() + 32; }
  35574. };
  35575. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35576. {
  35577. if (text.isEmpty())
  35578. return;
  35579. if (undoable)
  35580. {
  35581. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35582. }
  35583. else
  35584. {
  35585. Position pos (this, insertPos);
  35586. const int firstAffectedLine = pos.getLineNumber();
  35587. int lastAffectedLine = firstAffectedLine + 1;
  35588. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35589. String textInsideOriginalLine (text);
  35590. if (firstLine != 0)
  35591. {
  35592. const int index = pos.getIndexInLine();
  35593. textInsideOriginalLine = firstLine->line.substring (0, index)
  35594. + textInsideOriginalLine
  35595. + firstLine->line.substring (index);
  35596. }
  35597. maximumLineLength = -1;
  35598. Array <CodeDocumentLine*> newLines;
  35599. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35600. jassert (newLines.size() > 0);
  35601. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35602. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35603. lines.set (firstAffectedLine, newFirstLine);
  35604. if (newLines.size() > 1)
  35605. {
  35606. for (int i = 1; i < newLines.size(); ++i)
  35607. {
  35608. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35609. lines.insert (firstAffectedLine + i, l);
  35610. }
  35611. lastAffectedLine = lines.size();
  35612. }
  35613. int i, lineStart = newFirstLine->lineStartInFile;
  35614. for (i = firstAffectedLine; i < lines.size(); ++i)
  35615. {
  35616. CodeDocumentLine* const l = lines.getUnchecked (i);
  35617. l->lineStartInFile = lineStart;
  35618. lineStart += l->lineLength;
  35619. }
  35620. checkLastLineStatus();
  35621. const int newTextLength = text.length();
  35622. for (i = 0; i < positionsToMaintain.size(); ++i)
  35623. {
  35624. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35625. if (p->getPosition() >= insertPos)
  35626. p->setPosition (p->getPosition() + newTextLength);
  35627. }
  35628. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35629. }
  35630. }
  35631. class CodeDocumentDeleteAction : public UndoableAction
  35632. {
  35633. CodeDocument& owner;
  35634. int startPos, endPos;
  35635. String removedText;
  35636. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35637. CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35638. public:
  35639. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35640. : owner (owner_),
  35641. startPos (startPos_),
  35642. endPos (endPos_)
  35643. {
  35644. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  35645. CodeDocument::Position (&owner, endPos));
  35646. }
  35647. ~CodeDocumentDeleteAction() {}
  35648. bool perform()
  35649. {
  35650. owner.currentActionIndex++;
  35651. owner.remove (startPos, endPos, false);
  35652. return true;
  35653. }
  35654. bool undo()
  35655. {
  35656. owner.currentActionIndex--;
  35657. owner.insert (removedText, startPos, false);
  35658. return true;
  35659. }
  35660. int getSizeInUnits() { return removedText.length() + 32; }
  35661. };
  35662. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  35663. {
  35664. if (endPos <= startPos)
  35665. return;
  35666. if (undoable)
  35667. {
  35668. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  35669. }
  35670. else
  35671. {
  35672. Position startPosition (this, startPos);
  35673. Position endPosition (this, endPos);
  35674. maximumLineLength = -1;
  35675. const int firstAffectedLine = startPosition.getLineNumber();
  35676. const int endLine = endPosition.getLineNumber();
  35677. int lastAffectedLine = firstAffectedLine + 1;
  35678. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  35679. if (firstAffectedLine == endLine)
  35680. {
  35681. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35682. + firstLine->line.substring (endPosition.getIndexInLine());
  35683. firstLine->updateLength();
  35684. }
  35685. else
  35686. {
  35687. lastAffectedLine = lines.size();
  35688. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  35689. jassert (lastLine != 0);
  35690. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35691. + lastLine->line.substring (endPosition.getIndexInLine());
  35692. firstLine->updateLength();
  35693. int numLinesToRemove = endLine - firstAffectedLine;
  35694. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  35695. }
  35696. int i;
  35697. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  35698. {
  35699. CodeDocumentLine* const l = lines.getUnchecked (i);
  35700. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  35701. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  35702. }
  35703. checkLastLineStatus();
  35704. const int totalChars = getNumCharacters();
  35705. for (i = 0; i < positionsToMaintain.size(); ++i)
  35706. {
  35707. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  35708. if (p->getPosition() > startPosition.getPosition())
  35709. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  35710. if (p->getPosition() > totalChars)
  35711. p->setPosition (totalChars);
  35712. }
  35713. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35714. }
  35715. }
  35716. END_JUCE_NAMESPACE
  35717. /*** End of inlined file: juce_CodeDocument.cpp ***/
  35718. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  35719. BEGIN_JUCE_NAMESPACE
  35720. class CaretComponent : public Component,
  35721. public Timer
  35722. {
  35723. public:
  35724. CaretComponent()
  35725. {
  35726. setAlwaysOnTop (true);
  35727. setInterceptsMouseClicks (false, false);
  35728. }
  35729. ~CaretComponent()
  35730. {
  35731. }
  35732. void paint (Graphics& g)
  35733. {
  35734. if (getParentComponent()->hasKeyboardFocus (true))
  35735. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  35736. }
  35737. void timerCallback()
  35738. {
  35739. setVisible (! isVisible());
  35740. }
  35741. void updatePosition (CodeEditorComponent& owner)
  35742. {
  35743. startTimer (400);
  35744. setVisible (true);
  35745. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  35746. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  35747. }
  35748. };
  35749. class CodeEditorComponent::CodeEditorLine
  35750. {
  35751. public:
  35752. CodeEditorLine() throw()
  35753. {
  35754. }
  35755. ~CodeEditorLine() throw()
  35756. {
  35757. }
  35758. bool update (CodeDocument& document, int lineNum,
  35759. CodeDocument::Iterator& source,
  35760. CodeTokeniser* analyser, const int spacesPerTab,
  35761. const CodeDocument::Position& selectionStart,
  35762. const CodeDocument::Position& selectionEnd)
  35763. {
  35764. Array <SyntaxToken> newTokens;
  35765. newTokens.ensureStorageAllocated (8);
  35766. if (analyser == 0)
  35767. {
  35768. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  35769. }
  35770. else if (lineNum < document.getNumLines())
  35771. {
  35772. const CodeDocument::Position pos (&document, lineNum, 0);
  35773. createTokens (pos.getPosition(), pos.getLineText(),
  35774. source, analyser, newTokens);
  35775. }
  35776. replaceTabsWithSpaces (newTokens, spacesPerTab);
  35777. int newHighlightStart = 0;
  35778. int newHighlightEnd = 0;
  35779. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  35780. {
  35781. const String line (document.getLine (lineNum));
  35782. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  35783. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  35784. line, spacesPerTab);
  35785. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  35786. line, spacesPerTab);
  35787. }
  35788. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  35789. {
  35790. highlightColumnStart = newHighlightStart;
  35791. highlightColumnEnd = newHighlightEnd;
  35792. }
  35793. else
  35794. {
  35795. if (tokens.size() == newTokens.size())
  35796. {
  35797. bool allTheSame = true;
  35798. for (int i = newTokens.size(); --i >= 0;)
  35799. {
  35800. if (tokens.getReference(i) != newTokens.getReference(i))
  35801. {
  35802. allTheSame = false;
  35803. break;
  35804. }
  35805. }
  35806. if (allTheSame)
  35807. return false;
  35808. }
  35809. }
  35810. tokens.swapWithArray (newTokens);
  35811. return true;
  35812. }
  35813. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  35814. float x, const int y, const int baselineOffset, const int lineHeight,
  35815. const Colour& highlightColour) const throw()
  35816. {
  35817. if (highlightColumnStart < highlightColumnEnd)
  35818. {
  35819. g.setColour (highlightColour);
  35820. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  35821. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  35822. }
  35823. int lastType = std::numeric_limits<int>::min();
  35824. for (int i = 0; i < tokens.size(); ++i)
  35825. {
  35826. SyntaxToken& token = tokens.getReference(i);
  35827. if (lastType != token.tokenType)
  35828. {
  35829. lastType = token.tokenType;
  35830. g.setColour (owner.getColourForTokenType (lastType));
  35831. }
  35832. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  35833. if (i < tokens.size() - 1)
  35834. {
  35835. if (token.width < 0)
  35836. token.width = font.getStringWidthFloat (token.text);
  35837. x += token.width;
  35838. }
  35839. }
  35840. }
  35841. private:
  35842. struct SyntaxToken
  35843. {
  35844. String text;
  35845. int tokenType;
  35846. float width;
  35847. SyntaxToken (const String& text_, const int type) throw()
  35848. : text (text_), tokenType (type), width (-1.0f)
  35849. {
  35850. }
  35851. bool operator!= (const SyntaxToken& other) const throw()
  35852. {
  35853. return text != other.text || tokenType != other.tokenType;
  35854. }
  35855. };
  35856. Array <SyntaxToken> tokens;
  35857. int highlightColumnStart, highlightColumnEnd;
  35858. static void createTokens (int startPosition, const String& lineText,
  35859. CodeDocument::Iterator& source,
  35860. CodeTokeniser* analyser,
  35861. Array <SyntaxToken>& newTokens)
  35862. {
  35863. CodeDocument::Iterator lastIterator (source);
  35864. const int lineLength = lineText.length();
  35865. for (;;)
  35866. {
  35867. int tokenType = analyser->readNextToken (source);
  35868. int tokenStart = lastIterator.getPosition();
  35869. int tokenEnd = source.getPosition();
  35870. if (tokenEnd <= tokenStart)
  35871. break;
  35872. tokenEnd -= startPosition;
  35873. if (tokenEnd > 0)
  35874. {
  35875. tokenStart -= startPosition;
  35876. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  35877. tokenType));
  35878. if (tokenEnd >= lineLength)
  35879. break;
  35880. }
  35881. lastIterator = source;
  35882. }
  35883. source = lastIterator;
  35884. }
  35885. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  35886. {
  35887. int x = 0;
  35888. for (int i = 0; i < tokens.size(); ++i)
  35889. {
  35890. SyntaxToken& t = tokens.getReference(i);
  35891. for (;;)
  35892. {
  35893. int tabPos = t.text.indexOfChar (T('\t'));
  35894. if (tabPos < 0)
  35895. break;
  35896. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  35897. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (T(" "), spacesNeeded));
  35898. }
  35899. x += t.text.length();
  35900. }
  35901. }
  35902. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  35903. {
  35904. jassert (index <= line.length());
  35905. int col = 0;
  35906. for (int i = 0; i < index; ++i)
  35907. {
  35908. if (line[i] != T('\t'))
  35909. ++col;
  35910. else
  35911. col += spacesPerTab - (col % spacesPerTab);
  35912. }
  35913. return col;
  35914. }
  35915. };
  35916. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  35917. CodeTokeniser* const codeTokeniser_)
  35918. : document (document_),
  35919. firstLineOnScreen (0),
  35920. gutter (5),
  35921. spacesPerTab (4),
  35922. lineHeight (0),
  35923. linesOnScreen (0),
  35924. columnsOnScreen (0),
  35925. scrollbarThickness (16),
  35926. columnToTryToMaintain (-1),
  35927. useSpacesForTabs (false),
  35928. xOffset (0),
  35929. codeTokeniser (codeTokeniser_)
  35930. {
  35931. caretPos = CodeDocument::Position (&document_, 0, 0);
  35932. caretPos.setPositionMaintained (true);
  35933. selectionStart = CodeDocument::Position (&document_, 0, 0);
  35934. selectionStart.setPositionMaintained (true);
  35935. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  35936. selectionEnd.setPositionMaintained (true);
  35937. setOpaque (true);
  35938. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  35939. setWantsKeyboardFocus (true);
  35940. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  35941. verticalScrollBar->setSingleStepSize (1.0);
  35942. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  35943. horizontalScrollBar->setSingleStepSize (1.0);
  35944. addAndMakeVisible (caret = new CaretComponent());
  35945. Font f (12.0f);
  35946. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  35947. setFont (f);
  35948. resetToDefaultColours();
  35949. verticalScrollBar->addListener (this);
  35950. horizontalScrollBar->addListener (this);
  35951. document.addListener (this);
  35952. }
  35953. CodeEditorComponent::~CodeEditorComponent()
  35954. {
  35955. document.removeListener (this);
  35956. deleteAllChildren();
  35957. }
  35958. void CodeEditorComponent::loadContent (const String& newContent)
  35959. {
  35960. clearCachedIterators (0);
  35961. document.replaceAllContent (newContent);
  35962. document.clearUndoHistory();
  35963. document.setSavePoint();
  35964. caretPos.setPosition (0);
  35965. selectionStart.setPosition (0);
  35966. selectionEnd.setPosition (0);
  35967. scrollToLine (0);
  35968. }
  35969. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  35970. const CodeDocument::Position& affectedTextEnd)
  35971. {
  35972. clearCachedIterators (affectedTextStart.getLineNumber());
  35973. triggerAsyncUpdate();
  35974. ((CaretComponent*) caret)->updatePosition (*this);
  35975. columnToTryToMaintain = -1;
  35976. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  35977. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  35978. deselectAll();
  35979. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  35980. || caretPos.getPosition() < affectedTextStart.getPosition())
  35981. moveCaretTo (affectedTextStart, false);
  35982. updateScrollBars();
  35983. }
  35984. void CodeEditorComponent::resized()
  35985. {
  35986. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  35987. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  35988. lines.clear();
  35989. rebuildLineTokens();
  35990. ((CaretComponent*) caret)->updatePosition (*this);
  35991. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  35992. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  35993. updateScrollBars();
  35994. }
  35995. void CodeEditorComponent::paint (Graphics& g)
  35996. {
  35997. handleUpdateNowIfNeeded();
  35998. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  35999. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  36000. g.setFont (font);
  36001. const int baselineOffset = (int) font.getAscent();
  36002. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  36003. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  36004. const Rectangle<int> clip (g.getClipBounds());
  36005. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  36006. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  36007. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  36008. {
  36009. lines.getUnchecked(j)->draw (*this, g, font,
  36010. (float) (gutter - xOffset * charWidth),
  36011. lineHeight * j, baselineOffset, lineHeight,
  36012. highlightColour);
  36013. }
  36014. }
  36015. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  36016. {
  36017. if (scrollbarThickness != thickness)
  36018. {
  36019. scrollbarThickness = thickness;
  36020. resized();
  36021. }
  36022. }
  36023. void CodeEditorComponent::handleAsyncUpdate()
  36024. {
  36025. rebuildLineTokens();
  36026. }
  36027. void CodeEditorComponent::rebuildLineTokens()
  36028. {
  36029. cancelPendingUpdate();
  36030. const int numNeeded = linesOnScreen + 1;
  36031. int minLineToRepaint = numNeeded;
  36032. int maxLineToRepaint = 0;
  36033. if (numNeeded != lines.size())
  36034. {
  36035. lines.clear();
  36036. for (int i = numNeeded; --i >= 0;)
  36037. lines.add (new CodeEditorLine());
  36038. minLineToRepaint = 0;
  36039. maxLineToRepaint = numNeeded;
  36040. }
  36041. jassert (numNeeded == lines.size());
  36042. CodeDocument::Iterator source (&document);
  36043. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  36044. for (int i = 0; i < numNeeded; ++i)
  36045. {
  36046. CodeEditorLine* const line = lines.getUnchecked(i);
  36047. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  36048. selectionStart, selectionEnd))
  36049. {
  36050. minLineToRepaint = jmin (minLineToRepaint, i);
  36051. maxLineToRepaint = jmax (maxLineToRepaint, i);
  36052. }
  36053. }
  36054. if (minLineToRepaint <= maxLineToRepaint)
  36055. {
  36056. repaint (gutter, lineHeight * minLineToRepaint - 1,
  36057. verticalScrollBar->getX() - gutter,
  36058. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  36059. }
  36060. }
  36061. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  36062. {
  36063. caretPos = newPos;
  36064. columnToTryToMaintain = -1;
  36065. if (highlighting)
  36066. {
  36067. if (dragType == notDragging)
  36068. {
  36069. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  36070. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  36071. dragType = draggingSelectionStart;
  36072. else
  36073. dragType = draggingSelectionEnd;
  36074. }
  36075. if (dragType == draggingSelectionStart)
  36076. {
  36077. selectionStart = caretPos;
  36078. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36079. {
  36080. const CodeDocument::Position temp (selectionStart);
  36081. selectionStart = selectionEnd;
  36082. selectionEnd = temp;
  36083. dragType = draggingSelectionEnd;
  36084. }
  36085. }
  36086. else
  36087. {
  36088. selectionEnd = caretPos;
  36089. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36090. {
  36091. const CodeDocument::Position temp (selectionStart);
  36092. selectionStart = selectionEnd;
  36093. selectionEnd = temp;
  36094. dragType = draggingSelectionStart;
  36095. }
  36096. }
  36097. triggerAsyncUpdate();
  36098. }
  36099. else
  36100. {
  36101. deselectAll();
  36102. }
  36103. ((CaretComponent*) caret)->updatePosition (*this);
  36104. scrollToKeepCaretOnScreen();
  36105. updateScrollBars();
  36106. }
  36107. void CodeEditorComponent::deselectAll()
  36108. {
  36109. if (selectionStart != selectionEnd)
  36110. triggerAsyncUpdate();
  36111. selectionStart = caretPos;
  36112. selectionEnd = caretPos;
  36113. }
  36114. void CodeEditorComponent::updateScrollBars()
  36115. {
  36116. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  36117. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  36118. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  36119. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  36120. }
  36121. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  36122. {
  36123. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  36124. newFirstLineOnScreen);
  36125. if (newFirstLineOnScreen != firstLineOnScreen)
  36126. {
  36127. firstLineOnScreen = newFirstLineOnScreen;
  36128. ((CaretComponent*) caret)->updatePosition (*this);
  36129. updateCachedIterators (firstLineOnScreen);
  36130. triggerAsyncUpdate();
  36131. }
  36132. }
  36133. void CodeEditorComponent::scrollToColumnInternal (double column)
  36134. {
  36135. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  36136. if (xOffset != newOffset)
  36137. {
  36138. xOffset = newOffset;
  36139. ((CaretComponent*) caret)->updatePosition (*this);
  36140. repaint();
  36141. }
  36142. }
  36143. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  36144. {
  36145. scrollToLineInternal (newFirstLineOnScreen);
  36146. updateScrollBars();
  36147. }
  36148. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  36149. {
  36150. scrollToColumnInternal (newFirstColumnOnScreen);
  36151. updateScrollBars();
  36152. }
  36153. void CodeEditorComponent::scrollBy (int deltaLines)
  36154. {
  36155. scrollToLine (firstLineOnScreen + deltaLines);
  36156. }
  36157. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  36158. {
  36159. if (caretPos.getLineNumber() < firstLineOnScreen)
  36160. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  36161. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36162. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  36163. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36164. if (column >= xOffset + columnsOnScreen - 1)
  36165. scrollToColumn (column + 1 - columnsOnScreen);
  36166. else if (column < xOffset)
  36167. scrollToColumn (column);
  36168. }
  36169. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  36170. {
  36171. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  36172. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  36173. roundToInt (charWidth),
  36174. lineHeight);
  36175. }
  36176. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  36177. {
  36178. const int line = y / lineHeight + firstLineOnScreen;
  36179. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  36180. const int index = columnToIndex (line, column);
  36181. return CodeDocument::Position (&document, line, index);
  36182. }
  36183. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  36184. {
  36185. document.deleteSection (selectionStart, selectionEnd);
  36186. if (newText.isNotEmpty())
  36187. document.insertText (caretPos, newText);
  36188. scrollToKeepCaretOnScreen();
  36189. }
  36190. void CodeEditorComponent::insertTabAtCaret()
  36191. {
  36192. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  36193. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  36194. {
  36195. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  36196. }
  36197. if (useSpacesForTabs)
  36198. {
  36199. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36200. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  36201. insertTextAtCaret (String::repeatedString (T(" "), spacesNeeded));
  36202. }
  36203. else
  36204. {
  36205. insertTextAtCaret (T("\t"));
  36206. }
  36207. }
  36208. void CodeEditorComponent::cut()
  36209. {
  36210. insertTextAtCaret (String::empty);
  36211. }
  36212. void CodeEditorComponent::copy()
  36213. {
  36214. newTransaction();
  36215. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  36216. if (selection.isNotEmpty())
  36217. SystemClipboard::copyTextToClipboard (selection);
  36218. }
  36219. void CodeEditorComponent::copyThenCut()
  36220. {
  36221. copy();
  36222. cut();
  36223. newTransaction();
  36224. }
  36225. void CodeEditorComponent::paste()
  36226. {
  36227. newTransaction();
  36228. const String clip (SystemClipboard::getTextFromClipboard());
  36229. if (clip.isNotEmpty())
  36230. insertTextAtCaret (clip);
  36231. newTransaction();
  36232. }
  36233. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  36234. {
  36235. newTransaction();
  36236. if (moveInWholeWordSteps)
  36237. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  36238. else
  36239. moveCaretTo (caretPos.movedBy (-1), selecting);
  36240. }
  36241. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  36242. {
  36243. newTransaction();
  36244. if (moveInWholeWordSteps)
  36245. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  36246. else
  36247. moveCaretTo (caretPos.movedBy (1), selecting);
  36248. }
  36249. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  36250. {
  36251. CodeDocument::Position pos (caretPos);
  36252. const int newLineNum = pos.getLineNumber() + delta;
  36253. if (columnToTryToMaintain < 0)
  36254. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  36255. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  36256. const int colToMaintain = columnToTryToMaintain;
  36257. moveCaretTo (pos, selecting);
  36258. columnToTryToMaintain = colToMaintain;
  36259. }
  36260. void CodeEditorComponent::cursorDown (const bool selecting)
  36261. {
  36262. newTransaction();
  36263. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  36264. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36265. else
  36266. moveLineDelta (1, selecting);
  36267. }
  36268. void CodeEditorComponent::cursorUp (const bool selecting)
  36269. {
  36270. newTransaction();
  36271. if (caretPos.getLineNumber() == 0)
  36272. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36273. else
  36274. moveLineDelta (-1, selecting);
  36275. }
  36276. void CodeEditorComponent::pageDown (const bool selecting)
  36277. {
  36278. newTransaction();
  36279. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36280. moveLineDelta (linesOnScreen, selecting);
  36281. }
  36282. void CodeEditorComponent::pageUp (const bool selecting)
  36283. {
  36284. newTransaction();
  36285. scrollBy (-linesOnScreen);
  36286. moveLineDelta (-linesOnScreen, selecting);
  36287. }
  36288. void CodeEditorComponent::scrollUp()
  36289. {
  36290. newTransaction();
  36291. scrollBy (1);
  36292. if (caretPos.getLineNumber() < firstLineOnScreen)
  36293. moveLineDelta (1, false);
  36294. }
  36295. void CodeEditorComponent::scrollDown()
  36296. {
  36297. newTransaction();
  36298. scrollBy (-1);
  36299. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36300. moveLineDelta (-1, false);
  36301. }
  36302. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36303. {
  36304. newTransaction();
  36305. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36306. }
  36307. static int findFirstNonWhitespaceChar (const String& line) throw()
  36308. {
  36309. const int len = line.length();
  36310. for (int i = 0; i < len; ++i)
  36311. if (! CharacterFunctions::isWhitespace (line [i]))
  36312. return i;
  36313. return 0;
  36314. }
  36315. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36316. {
  36317. newTransaction();
  36318. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36319. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36320. index = 0;
  36321. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36322. }
  36323. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36324. {
  36325. newTransaction();
  36326. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36327. }
  36328. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36329. {
  36330. newTransaction();
  36331. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  36332. }
  36333. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36334. {
  36335. if (moveInWholeWordSteps)
  36336. {
  36337. cut(); // in case something is already highlighted
  36338. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36339. }
  36340. else
  36341. {
  36342. if (selectionStart == selectionEnd)
  36343. selectionStart.moveBy (-1);
  36344. }
  36345. cut();
  36346. }
  36347. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36348. {
  36349. if (moveInWholeWordSteps)
  36350. {
  36351. cut(); // in case something is already highlighted
  36352. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36353. }
  36354. else
  36355. {
  36356. if (selectionStart == selectionEnd)
  36357. selectionEnd.moveBy (1);
  36358. else
  36359. newTransaction();
  36360. }
  36361. cut();
  36362. }
  36363. void CodeEditorComponent::selectAll()
  36364. {
  36365. newTransaction();
  36366. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36367. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36368. }
  36369. void CodeEditorComponent::undo()
  36370. {
  36371. document.undo();
  36372. scrollToKeepCaretOnScreen();
  36373. }
  36374. void CodeEditorComponent::redo()
  36375. {
  36376. document.redo();
  36377. scrollToKeepCaretOnScreen();
  36378. }
  36379. void CodeEditorComponent::newTransaction()
  36380. {
  36381. document.newTransaction();
  36382. startTimer (600);
  36383. }
  36384. void CodeEditorComponent::timerCallback()
  36385. {
  36386. newTransaction();
  36387. }
  36388. const Range<int> CodeEditorComponent::getHighlightedRegion() const
  36389. {
  36390. return Range<int> (selectionStart.getPosition(), selectionEnd.getPosition());
  36391. }
  36392. void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
  36393. {
  36394. moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
  36395. moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
  36396. }
  36397. const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
  36398. {
  36399. return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
  36400. CodeDocument::Position (&document, range.getEnd()));
  36401. }
  36402. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36403. {
  36404. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36405. const bool shiftDown = key.getModifiers().isShiftDown();
  36406. if (key.isKeyCode (KeyPress::leftKey))
  36407. {
  36408. cursorLeft (moveInWholeWordSteps, shiftDown);
  36409. }
  36410. else if (key.isKeyCode (KeyPress::rightKey))
  36411. {
  36412. cursorRight (moveInWholeWordSteps, shiftDown);
  36413. }
  36414. else if (key.isKeyCode (KeyPress::upKey))
  36415. {
  36416. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36417. scrollDown();
  36418. #if JUCE_MAC
  36419. else if (key.getModifiers().isCommandDown())
  36420. goToStartOfDocument (shiftDown);
  36421. #endif
  36422. else
  36423. cursorUp (shiftDown);
  36424. }
  36425. else if (key.isKeyCode (KeyPress::downKey))
  36426. {
  36427. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36428. scrollUp();
  36429. #if JUCE_MAC
  36430. else if (key.getModifiers().isCommandDown())
  36431. goToEndOfDocument (shiftDown);
  36432. #endif
  36433. else
  36434. cursorDown (shiftDown);
  36435. }
  36436. else if (key.isKeyCode (KeyPress::pageDownKey))
  36437. {
  36438. pageDown (shiftDown);
  36439. }
  36440. else if (key.isKeyCode (KeyPress::pageUpKey))
  36441. {
  36442. pageUp (shiftDown);
  36443. }
  36444. else if (key.isKeyCode (KeyPress::homeKey))
  36445. {
  36446. if (moveInWholeWordSteps)
  36447. goToStartOfDocument (shiftDown);
  36448. else
  36449. goToStartOfLine (shiftDown);
  36450. }
  36451. else if (key.isKeyCode (KeyPress::endKey))
  36452. {
  36453. if (moveInWholeWordSteps)
  36454. goToEndOfDocument (shiftDown);
  36455. else
  36456. goToEndOfLine (shiftDown);
  36457. }
  36458. else if (key.isKeyCode (KeyPress::backspaceKey))
  36459. {
  36460. backspace (moveInWholeWordSteps);
  36461. }
  36462. else if (key.isKeyCode (KeyPress::deleteKey))
  36463. {
  36464. deleteForward (moveInWholeWordSteps);
  36465. }
  36466. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  36467. {
  36468. copy();
  36469. }
  36470. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  36471. {
  36472. copyThenCut();
  36473. }
  36474. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0))
  36475. {
  36476. paste();
  36477. }
  36478. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  36479. {
  36480. undo();
  36481. }
  36482. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0)
  36483. || key == KeyPress (T('z'), ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36484. {
  36485. redo();
  36486. }
  36487. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  36488. {
  36489. selectAll();
  36490. }
  36491. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36492. {
  36493. insertTabAtCaret();
  36494. }
  36495. else if (key == KeyPress::returnKey)
  36496. {
  36497. newTransaction();
  36498. insertTextAtCaret (document.getNewLineCharacters());
  36499. }
  36500. else if (key.isKeyCode (KeyPress::escapeKey))
  36501. {
  36502. newTransaction();
  36503. }
  36504. else if (key.getTextCharacter() >= ' ')
  36505. {
  36506. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36507. }
  36508. else
  36509. {
  36510. return false;
  36511. }
  36512. return true;
  36513. }
  36514. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36515. {
  36516. newTransaction();
  36517. dragType = notDragging;
  36518. if (! e.mods.isPopupMenu())
  36519. {
  36520. beginDragAutoRepeat (100);
  36521. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36522. }
  36523. else
  36524. {
  36525. }
  36526. }
  36527. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36528. {
  36529. if (! e.mods.isPopupMenu())
  36530. moveCaretTo (getPositionAt (e.x, e.y), true);
  36531. }
  36532. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36533. {
  36534. newTransaction();
  36535. beginDragAutoRepeat (0);
  36536. dragType = notDragging;
  36537. }
  36538. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36539. {
  36540. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36541. CodeDocument::Position tokenEnd (tokenStart);
  36542. if (e.getNumberOfClicks() > 2)
  36543. {
  36544. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36545. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36546. }
  36547. else
  36548. {
  36549. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36550. tokenEnd.moveBy (1);
  36551. tokenStart = tokenEnd;
  36552. while (tokenStart.getIndexInLine() > 0
  36553. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36554. tokenStart.moveBy (-1);
  36555. }
  36556. moveCaretTo (tokenEnd, false);
  36557. moveCaretTo (tokenStart, true);
  36558. }
  36559. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36560. {
  36561. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36562. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36563. }
  36564. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  36565. {
  36566. if (scrollBarThatHasMoved == verticalScrollBar)
  36567. scrollToLineInternal ((int) newRangeStart);
  36568. else
  36569. scrollToColumnInternal (newRangeStart);
  36570. }
  36571. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36572. {
  36573. useSpacesForTabs = insertSpaces;
  36574. if (spacesPerTab != numSpaces)
  36575. {
  36576. spacesPerTab = numSpaces;
  36577. triggerAsyncUpdate();
  36578. }
  36579. }
  36580. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36581. {
  36582. const String line (document.getLine (lineNum));
  36583. jassert (index <= line.length());
  36584. int col = 0;
  36585. for (int i = 0; i < index; ++i)
  36586. {
  36587. if (line[i] != T('\t'))
  36588. ++col;
  36589. else
  36590. col += getTabSize() - (col % getTabSize());
  36591. }
  36592. return col;
  36593. }
  36594. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36595. {
  36596. const String line (document.getLine (lineNum));
  36597. const int lineLength = line.length();
  36598. int i, col = 0;
  36599. for (i = 0; i < lineLength; ++i)
  36600. {
  36601. if (line[i] != T('\t'))
  36602. ++col;
  36603. else
  36604. col += getTabSize() - (col % getTabSize());
  36605. if (col > column)
  36606. break;
  36607. }
  36608. return i;
  36609. }
  36610. void CodeEditorComponent::setFont (const Font& newFont)
  36611. {
  36612. font = newFont;
  36613. charWidth = font.getStringWidthFloat (T("0"));
  36614. lineHeight = roundToInt (font.getHeight());
  36615. resized();
  36616. }
  36617. void CodeEditorComponent::resetToDefaultColours()
  36618. {
  36619. coloursForTokenCategories.clear();
  36620. if (codeTokeniser != 0)
  36621. {
  36622. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36623. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36624. }
  36625. }
  36626. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36627. {
  36628. jassert (tokenType < 256);
  36629. while (coloursForTokenCategories.size() < tokenType)
  36630. coloursForTokenCategories.add (Colours::black);
  36631. coloursForTokenCategories.set (tokenType, colour);
  36632. repaint();
  36633. }
  36634. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36635. {
  36636. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36637. return findColour (CodeEditorComponent::defaultTextColourId);
  36638. return coloursForTokenCategories.getReference (tokenType);
  36639. }
  36640. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  36641. {
  36642. int i;
  36643. for (i = cachedIterators.size(); --i >= 0;)
  36644. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  36645. break;
  36646. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  36647. }
  36648. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  36649. {
  36650. const int maxNumCachedPositions = 5000;
  36651. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  36652. if (cachedIterators.size() == 0)
  36653. cachedIterators.add (new CodeDocument::Iterator (&document));
  36654. if (codeTokeniser == 0)
  36655. return;
  36656. for (;;)
  36657. {
  36658. CodeDocument::Iterator* last = cachedIterators.getLast();
  36659. if (last->getLine() >= maxLineNum)
  36660. break;
  36661. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  36662. cachedIterators.add (t);
  36663. const int targetLine = last->getLine() + linesBetweenCachedSources;
  36664. for (;;)
  36665. {
  36666. codeTokeniser->readNextToken (*t);
  36667. if (t->getLine() >= targetLine)
  36668. break;
  36669. if (t->isEOF())
  36670. return;
  36671. }
  36672. }
  36673. }
  36674. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  36675. {
  36676. if (codeTokeniser == 0)
  36677. return;
  36678. for (int i = cachedIterators.size(); --i >= 0;)
  36679. {
  36680. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  36681. if (t->getPosition() <= position)
  36682. {
  36683. source = *t;
  36684. break;
  36685. }
  36686. }
  36687. while (source.getPosition() < position)
  36688. {
  36689. const CodeDocument::Iterator original (source);
  36690. codeTokeniser->readNextToken (source);
  36691. if (source.getPosition() > position || source.isEOF())
  36692. {
  36693. source = original;
  36694. break;
  36695. }
  36696. }
  36697. }
  36698. END_JUCE_NAMESPACE
  36699. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  36700. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36701. BEGIN_JUCE_NAMESPACE
  36702. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  36703. {
  36704. }
  36705. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  36706. {
  36707. }
  36708. namespace CppTokeniser
  36709. {
  36710. static bool isIdentifierStart (const tchar c) throw()
  36711. {
  36712. return CharacterFunctions::isLetter (c)
  36713. || c == T('_') || c == T('@');
  36714. }
  36715. static bool isIdentifierBody (const tchar c) throw()
  36716. {
  36717. return CharacterFunctions::isLetter (c)
  36718. || CharacterFunctions::isDigit (c)
  36719. || c == T('_') || c == T('@');
  36720. }
  36721. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  36722. {
  36723. static const tchar* keywords2Char[] =
  36724. { T("if"), T("do"), T("or"), 0 };
  36725. static const tchar* keywords3Char[] =
  36726. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  36727. static const tchar* keywords4Char[] =
  36728. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  36729. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  36730. static const tchar* keywords5Char[] =
  36731. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  36732. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  36733. static const tchar* keywords6Char[] =
  36734. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  36735. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  36736. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  36737. static const tchar* keywordsOther[] =
  36738. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  36739. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  36740. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  36741. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  36742. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  36743. int tokenLength = 0;
  36744. tchar possibleIdentifier [19];
  36745. while (isIdentifierBody (source.peekNextChar()))
  36746. {
  36747. const tchar c = source.nextChar();
  36748. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  36749. possibleIdentifier [tokenLength] = c;
  36750. ++tokenLength;
  36751. }
  36752. if (tokenLength > 1 && tokenLength <= 16)
  36753. {
  36754. possibleIdentifier [tokenLength] = 0;
  36755. const tchar** k;
  36756. switch (tokenLength)
  36757. {
  36758. case 2: k = keywords2Char; break;
  36759. case 3: k = keywords3Char; break;
  36760. case 4: k = keywords4Char; break;
  36761. case 5: k = keywords5Char; break;
  36762. case 6: k = keywords6Char; break;
  36763. default: k = keywordsOther; break;
  36764. }
  36765. int i = 0;
  36766. while (k[i] != 0)
  36767. {
  36768. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  36769. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  36770. ++i;
  36771. }
  36772. }
  36773. return CPlusPlusCodeTokeniser::tokenType_identifier;
  36774. }
  36775. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  36776. {
  36777. const juce_wchar c = source.peekNextChar();
  36778. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  36779. source.skip();
  36780. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  36781. return false;
  36782. return true;
  36783. }
  36784. static bool isHexDigit (const juce_wchar c) throw()
  36785. {
  36786. return (c >= '0' && c <= '9')
  36787. || (c >= 'a' && c <= 'f')
  36788. || (c >= 'A' && c <= 'F');
  36789. }
  36790. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  36791. {
  36792. if (source.nextChar() != '0')
  36793. return false;
  36794. juce_wchar c = source.nextChar();
  36795. if (c != 'x' && c != 'X')
  36796. return false;
  36797. int numDigits = 0;
  36798. while (isHexDigit (source.peekNextChar()))
  36799. {
  36800. ++numDigits;
  36801. source.skip();
  36802. }
  36803. if (numDigits == 0)
  36804. return false;
  36805. return skipNumberSuffix (source);
  36806. }
  36807. static bool isOctalDigit (const juce_wchar c) throw()
  36808. {
  36809. return c >= '0' && c <= '7';
  36810. }
  36811. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  36812. {
  36813. if (source.nextChar() != '0')
  36814. return false;
  36815. if (! isOctalDigit (source.nextChar()))
  36816. return false;
  36817. while (isOctalDigit (source.peekNextChar()))
  36818. source.skip();
  36819. return skipNumberSuffix (source);
  36820. }
  36821. static bool isDecimalDigit (const juce_wchar c) throw()
  36822. {
  36823. return c >= '0' && c <= '9';
  36824. }
  36825. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  36826. {
  36827. int numChars = 0;
  36828. while (isDecimalDigit (source.peekNextChar()))
  36829. {
  36830. ++numChars;
  36831. source.skip();
  36832. }
  36833. if (numChars == 0)
  36834. return false;
  36835. return skipNumberSuffix (source);
  36836. }
  36837. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  36838. {
  36839. int numDigits = 0;
  36840. while (isDecimalDigit (source.peekNextChar()))
  36841. {
  36842. source.skip();
  36843. ++numDigits;
  36844. }
  36845. const bool hasPoint = (source.peekNextChar() == '.');
  36846. if (hasPoint)
  36847. {
  36848. source.skip();
  36849. while (isDecimalDigit (source.peekNextChar()))
  36850. {
  36851. source.skip();
  36852. ++numDigits;
  36853. }
  36854. }
  36855. if (numDigits == 0)
  36856. return false;
  36857. juce_wchar c = source.peekNextChar();
  36858. const bool hasExponent = (c == 'e' || c == 'E');
  36859. if (hasExponent)
  36860. {
  36861. source.skip();
  36862. c = source.peekNextChar();
  36863. if (c == '+' || c == '-')
  36864. source.skip();
  36865. int numExpDigits = 0;
  36866. while (isDecimalDigit (source.peekNextChar()))
  36867. {
  36868. source.skip();
  36869. ++numExpDigits;
  36870. }
  36871. if (numExpDigits == 0)
  36872. return false;
  36873. }
  36874. c = source.peekNextChar();
  36875. if (c == 'f' || c == 'F')
  36876. source.skip();
  36877. else if (! (hasExponent || hasPoint))
  36878. return false;
  36879. return true;
  36880. }
  36881. static int parseNumber (CodeDocument::Iterator& source)
  36882. {
  36883. const CodeDocument::Iterator original (source);
  36884. if (parseFloatLiteral (source))
  36885. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  36886. source = original;
  36887. if (parseHexLiteral (source))
  36888. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36889. source = original;
  36890. if (parseOctalLiteral (source))
  36891. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36892. source = original;
  36893. if (parseDecimalLiteral (source))
  36894. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36895. source = original;
  36896. source.skip();
  36897. return CPlusPlusCodeTokeniser::tokenType_error;
  36898. }
  36899. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  36900. {
  36901. const juce_wchar quote = source.nextChar();
  36902. for (;;)
  36903. {
  36904. const juce_wchar c = source.nextChar();
  36905. if (c == quote || c == 0)
  36906. break;
  36907. if (c == '\\')
  36908. source.skip();
  36909. }
  36910. }
  36911. static void skipComment (CodeDocument::Iterator& source) throw()
  36912. {
  36913. bool lastWasStar = false;
  36914. for (;;)
  36915. {
  36916. const juce_wchar c = source.nextChar();
  36917. if (c == 0 || (c == T('/') && lastWasStar))
  36918. break;
  36919. lastWasStar = (c == '*');
  36920. }
  36921. }
  36922. }
  36923. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  36924. {
  36925. int result = tokenType_error;
  36926. source.skipWhitespace();
  36927. tchar firstChar = source.peekNextChar();
  36928. switch (firstChar)
  36929. {
  36930. case 0:
  36931. source.skip();
  36932. break;
  36933. case T('0'):
  36934. case T('1'):
  36935. case T('2'):
  36936. case T('3'):
  36937. case T('4'):
  36938. case T('5'):
  36939. case T('6'):
  36940. case T('7'):
  36941. case T('8'):
  36942. case T('9'):
  36943. result = CppTokeniser::parseNumber (source);
  36944. break;
  36945. case T('.'):
  36946. result = CppTokeniser::parseNumber (source);
  36947. if (result == tokenType_error)
  36948. result = tokenType_punctuation;
  36949. break;
  36950. case T(','):
  36951. case T(';'):
  36952. case T(':'):
  36953. source.skip();
  36954. result = tokenType_punctuation;
  36955. break;
  36956. case T('('):
  36957. case T(')'):
  36958. case T('{'):
  36959. case T('}'):
  36960. case T('['):
  36961. case T(']'):
  36962. source.skip();
  36963. result = tokenType_bracket;
  36964. break;
  36965. case T('"'):
  36966. case T('\''):
  36967. CppTokeniser::skipQuotedString (source);
  36968. result = tokenType_stringLiteral;
  36969. break;
  36970. case T('+'):
  36971. result = tokenType_operator;
  36972. source.skip();
  36973. if (source.peekNextChar() == T('+'))
  36974. source.skip();
  36975. else if (source.peekNextChar() == T('='))
  36976. source.skip();
  36977. break;
  36978. case T('-'):
  36979. source.skip();
  36980. result = CppTokeniser::parseNumber (source);
  36981. if (result == tokenType_error)
  36982. {
  36983. result = tokenType_operator;
  36984. if (source.peekNextChar() == T('-'))
  36985. source.skip();
  36986. else if (source.peekNextChar() == T('='))
  36987. source.skip();
  36988. }
  36989. break;
  36990. case T('*'):
  36991. case T('%'):
  36992. case T('='):
  36993. case T('!'):
  36994. result = tokenType_operator;
  36995. source.skip();
  36996. if (source.peekNextChar() == T('='))
  36997. source.skip();
  36998. break;
  36999. case T('/'):
  37000. result = tokenType_operator;
  37001. source.skip();
  37002. if (source.peekNextChar() == T('='))
  37003. {
  37004. source.skip();
  37005. }
  37006. else if (source.peekNextChar() == T('/'))
  37007. {
  37008. result = tokenType_comment;
  37009. source.skipToEndOfLine();
  37010. }
  37011. else if (source.peekNextChar() == T('*'))
  37012. {
  37013. source.skip();
  37014. result = tokenType_comment;
  37015. CppTokeniser::skipComment (source);
  37016. }
  37017. break;
  37018. case T('?'):
  37019. case T('~'):
  37020. source.skip();
  37021. result = tokenType_operator;
  37022. break;
  37023. case T('<'):
  37024. source.skip();
  37025. result = tokenType_operator;
  37026. if (source.peekNextChar() == T('='))
  37027. {
  37028. source.skip();
  37029. }
  37030. else if (source.peekNextChar() == T('<'))
  37031. {
  37032. source.skip();
  37033. if (source.peekNextChar() == T('='))
  37034. source.skip();
  37035. }
  37036. break;
  37037. case T('>'):
  37038. source.skip();
  37039. result = tokenType_operator;
  37040. if (source.peekNextChar() == T('='))
  37041. {
  37042. source.skip();
  37043. }
  37044. else if (source.peekNextChar() == T('<'))
  37045. {
  37046. source.skip();
  37047. if (source.peekNextChar() == T('='))
  37048. source.skip();
  37049. }
  37050. break;
  37051. case T('|'):
  37052. source.skip();
  37053. result = tokenType_operator;
  37054. if (source.peekNextChar() == T('='))
  37055. {
  37056. source.skip();
  37057. }
  37058. else if (source.peekNextChar() == T('|'))
  37059. {
  37060. source.skip();
  37061. if (source.peekNextChar() == T('='))
  37062. source.skip();
  37063. }
  37064. break;
  37065. case T('&'):
  37066. source.skip();
  37067. result = tokenType_operator;
  37068. if (source.peekNextChar() == T('='))
  37069. {
  37070. source.skip();
  37071. }
  37072. else if (source.peekNextChar() == T('&'))
  37073. {
  37074. source.skip();
  37075. if (source.peekNextChar() == T('='))
  37076. source.skip();
  37077. }
  37078. break;
  37079. case T('^'):
  37080. source.skip();
  37081. result = tokenType_operator;
  37082. if (source.peekNextChar() == T('='))
  37083. {
  37084. source.skip();
  37085. }
  37086. else if (source.peekNextChar() == T('^'))
  37087. {
  37088. source.skip();
  37089. if (source.peekNextChar() == T('='))
  37090. source.skip();
  37091. }
  37092. break;
  37093. case T('#'):
  37094. result = tokenType_preprocessor;
  37095. source.skipToEndOfLine();
  37096. break;
  37097. default:
  37098. if (CppTokeniser::isIdentifierStart (firstChar))
  37099. result = CppTokeniser::parseIdentifier (source);
  37100. else
  37101. source.skip();
  37102. break;
  37103. }
  37104. //jassert (result != tokenType_unknown);
  37105. return result;
  37106. }
  37107. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  37108. {
  37109. StringArray s;
  37110. s.add ("Error");
  37111. s.add ("Comment");
  37112. s.add ("C++ keyword");
  37113. s.add ("Identifier");
  37114. s.add ("Integer literal");
  37115. s.add ("Float literal");
  37116. s.add ("String literal");
  37117. s.add ("Operator");
  37118. s.add ("Bracket");
  37119. s.add ("Punctuation");
  37120. s.add ("Preprocessor line");
  37121. return s;
  37122. }
  37123. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  37124. {
  37125. const uint32 colours[] =
  37126. {
  37127. 0xffcc0000, // error
  37128. 0xff00aa00, // comment
  37129. 0xff0000cc, // keyword
  37130. 0xff000000, // identifier
  37131. 0xff880000, // int literal
  37132. 0xff885500, // float literal
  37133. 0xff990099, // string literal
  37134. 0xff225500, // operator
  37135. 0xff000055, // bracket
  37136. 0xff004400, // punctuation
  37137. 0xff660000 // preprocessor
  37138. };
  37139. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  37140. return Colour (colours [tokenType]);
  37141. return Colours::black;
  37142. }
  37143. END_JUCE_NAMESPACE
  37144. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  37145. /*** Start of inlined file: juce_ComboBox.cpp ***/
  37146. BEGIN_JUCE_NAMESPACE
  37147. ComboBox::ComboBox (const String& name)
  37148. : Component (name),
  37149. lastCurrentId (0),
  37150. isButtonDown (false),
  37151. separatorPending (false),
  37152. menuActive (false),
  37153. label (0)
  37154. {
  37155. noChoicesMessage = TRANS("(no choices)");
  37156. setRepaintsOnMouseActivity (true);
  37157. lookAndFeelChanged();
  37158. currentId.addListener (this);
  37159. }
  37160. ComboBox::~ComboBox()
  37161. {
  37162. currentId.removeListener (this);
  37163. if (menuActive)
  37164. PopupMenu::dismissAllActiveMenus();
  37165. label = 0;
  37166. deleteAllChildren();
  37167. }
  37168. void ComboBox::setEditableText (const bool isEditable)
  37169. {
  37170. label->setEditable (isEditable, isEditable, false);
  37171. setWantsKeyboardFocus (! isEditable);
  37172. resized();
  37173. }
  37174. bool ComboBox::isTextEditable() const throw()
  37175. {
  37176. return label->isEditable();
  37177. }
  37178. void ComboBox::setJustificationType (const Justification& justification) throw()
  37179. {
  37180. label->setJustificationType (justification);
  37181. }
  37182. const Justification ComboBox::getJustificationType() const throw()
  37183. {
  37184. return label->getJustificationType();
  37185. }
  37186. void ComboBox::setTooltip (const String& newTooltip)
  37187. {
  37188. SettableTooltipClient::setTooltip (newTooltip);
  37189. label->setTooltip (newTooltip);
  37190. }
  37191. void ComboBox::addItem (const String& newItemText,
  37192. const int newItemId) throw()
  37193. {
  37194. // you can't add empty strings to the list..
  37195. jassert (newItemText.isNotEmpty());
  37196. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  37197. jassert (newItemId != 0);
  37198. // you shouldn't use duplicate item IDs!
  37199. jassert (getItemForId (newItemId) == 0);
  37200. if (newItemText.isNotEmpty() && newItemId != 0)
  37201. {
  37202. if (separatorPending)
  37203. {
  37204. separatorPending = false;
  37205. ItemInfo* const item = new ItemInfo();
  37206. item->itemId = 0;
  37207. item->isEnabled = false;
  37208. item->isHeading = false;
  37209. items.add (item);
  37210. }
  37211. ItemInfo* const item = new ItemInfo();
  37212. item->name = newItemText;
  37213. item->itemId = newItemId;
  37214. item->isEnabled = true;
  37215. item->isHeading = false;
  37216. items.add (item);
  37217. }
  37218. }
  37219. void ComboBox::addSeparator() throw()
  37220. {
  37221. separatorPending = (items.size() > 0);
  37222. }
  37223. void ComboBox::addSectionHeading (const String& headingName) throw()
  37224. {
  37225. // you can't add empty strings to the list..
  37226. jassert (headingName.isNotEmpty());
  37227. if (headingName.isNotEmpty())
  37228. {
  37229. if (separatorPending)
  37230. {
  37231. separatorPending = false;
  37232. ItemInfo* const item = new ItemInfo();
  37233. item->itemId = 0;
  37234. item->isEnabled = false;
  37235. item->isHeading = false;
  37236. items.add (item);
  37237. }
  37238. ItemInfo* const item = new ItemInfo();
  37239. item->name = headingName;
  37240. item->itemId = 0;
  37241. item->isEnabled = true;
  37242. item->isHeading = true;
  37243. items.add (item);
  37244. }
  37245. }
  37246. void ComboBox::setItemEnabled (const int itemId,
  37247. const bool shouldBeEnabled) throw()
  37248. {
  37249. ItemInfo* const item = getItemForId (itemId);
  37250. if (item != 0)
  37251. item->isEnabled = shouldBeEnabled;
  37252. }
  37253. void ComboBox::changeItemText (const int itemId,
  37254. const String& newText) throw()
  37255. {
  37256. ItemInfo* const item = getItemForId (itemId);
  37257. jassert (item != 0);
  37258. if (item != 0)
  37259. item->name = newText;
  37260. }
  37261. void ComboBox::clear (const bool dontSendChangeMessage)
  37262. {
  37263. items.clear();
  37264. separatorPending = false;
  37265. if (! label->isEditable())
  37266. setSelectedItemIndex (-1, dontSendChangeMessage);
  37267. }
  37268. bool ComboBox::ItemInfo::isSeparator() const throw()
  37269. {
  37270. return name.isEmpty();
  37271. }
  37272. bool ComboBox::ItemInfo::isRealItem() const throw()
  37273. {
  37274. return ! (isHeading || name.isEmpty());
  37275. }
  37276. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37277. {
  37278. if (itemId != 0)
  37279. {
  37280. for (int i = items.size(); --i >= 0;)
  37281. if (items.getUnchecked(i)->itemId == itemId)
  37282. return items.getUnchecked(i);
  37283. }
  37284. return 0;
  37285. }
  37286. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37287. {
  37288. int n = 0;
  37289. for (int i = 0; i < items.size(); ++i)
  37290. {
  37291. ItemInfo* const item = items.getUnchecked(i);
  37292. if (item->isRealItem())
  37293. if (n++ == index)
  37294. return item;
  37295. }
  37296. return 0;
  37297. }
  37298. int ComboBox::getNumItems() const throw()
  37299. {
  37300. int n = 0;
  37301. for (int i = items.size(); --i >= 0;)
  37302. if (items.getUnchecked(i)->isRealItem())
  37303. ++n;
  37304. return n;
  37305. }
  37306. const String ComboBox::getItemText (const int index) const throw()
  37307. {
  37308. const ItemInfo* const item = getItemForIndex (index);
  37309. if (item != 0)
  37310. return item->name;
  37311. return String::empty;
  37312. }
  37313. int ComboBox::getItemId (const int index) const throw()
  37314. {
  37315. const ItemInfo* const item = getItemForIndex (index);
  37316. return (item != 0) ? item->itemId : 0;
  37317. }
  37318. int ComboBox::indexOfItemId (const int itemId) const throw()
  37319. {
  37320. int n = 0;
  37321. for (int i = 0; i < items.size(); ++i)
  37322. {
  37323. const ItemInfo* const item = items.getUnchecked(i);
  37324. if (item->isRealItem())
  37325. {
  37326. if (item->itemId == itemId)
  37327. return n;
  37328. ++n;
  37329. }
  37330. }
  37331. return -1;
  37332. }
  37333. int ComboBox::getSelectedItemIndex() const throw()
  37334. {
  37335. int index = indexOfItemId (currentId.getValue());
  37336. if (getText() != getItemText (index))
  37337. index = -1;
  37338. return index;
  37339. }
  37340. void ComboBox::setSelectedItemIndex (const int index,
  37341. const bool dontSendChangeMessage) throw()
  37342. {
  37343. setSelectedId (getItemId (index), dontSendChangeMessage);
  37344. }
  37345. int ComboBox::getSelectedId() const throw()
  37346. {
  37347. const ItemInfo* const item = getItemForId (currentId.getValue());
  37348. return (item != 0 && getText() == item->name)
  37349. ? item->itemId
  37350. : 0;
  37351. }
  37352. void ComboBox::setSelectedId (const int newItemId,
  37353. const bool dontSendChangeMessage) throw()
  37354. {
  37355. const ItemInfo* const item = getItemForId (newItemId);
  37356. const String newItemText (item != 0 ? item->name : String::empty);
  37357. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37358. {
  37359. if (! dontSendChangeMessage)
  37360. triggerAsyncUpdate();
  37361. label->setText (newItemText, false);
  37362. lastCurrentId = newItemId;
  37363. currentId = newItemId;
  37364. repaint(); // for the benefit of the 'none selected' text
  37365. }
  37366. }
  37367. void ComboBox::valueChanged (Value&)
  37368. {
  37369. if (lastCurrentId != (int) currentId.getValue())
  37370. setSelectedId (currentId.getValue(), false);
  37371. }
  37372. const String ComboBox::getText() const throw()
  37373. {
  37374. return label->getText();
  37375. }
  37376. void ComboBox::setText (const String& newText,
  37377. const bool dontSendChangeMessage) throw()
  37378. {
  37379. for (int i = items.size(); --i >= 0;)
  37380. {
  37381. const ItemInfo* const item = items.getUnchecked(i);
  37382. if (item->isRealItem()
  37383. && item->name == newText)
  37384. {
  37385. setSelectedId (item->itemId, dontSendChangeMessage);
  37386. return;
  37387. }
  37388. }
  37389. lastCurrentId = 0;
  37390. currentId = 0;
  37391. if (label->getText() != newText)
  37392. {
  37393. label->setText (newText, false);
  37394. if (! dontSendChangeMessage)
  37395. triggerAsyncUpdate();
  37396. }
  37397. repaint();
  37398. }
  37399. void ComboBox::showEditor()
  37400. {
  37401. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37402. label->showEditor();
  37403. }
  37404. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37405. {
  37406. textWhenNothingSelected = newMessage;
  37407. repaint();
  37408. }
  37409. const String ComboBox::getTextWhenNothingSelected() const throw()
  37410. {
  37411. return textWhenNothingSelected;
  37412. }
  37413. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37414. {
  37415. noChoicesMessage = newMessage;
  37416. }
  37417. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37418. {
  37419. return noChoicesMessage;
  37420. }
  37421. void ComboBox::paint (Graphics& g)
  37422. {
  37423. getLookAndFeel().drawComboBox (g,
  37424. getWidth(),
  37425. getHeight(),
  37426. isButtonDown,
  37427. label->getRight(),
  37428. 0,
  37429. getWidth() - label->getRight(),
  37430. getHeight(),
  37431. *this);
  37432. if (textWhenNothingSelected.isNotEmpty()
  37433. && label->getText().isEmpty()
  37434. && ! label->isBeingEdited())
  37435. {
  37436. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37437. g.setFont (label->getFont());
  37438. g.drawFittedText (textWhenNothingSelected,
  37439. label->getX() + 2, label->getY() + 1,
  37440. label->getWidth() - 4, label->getHeight() - 2,
  37441. label->getJustificationType(),
  37442. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37443. }
  37444. }
  37445. void ComboBox::resized()
  37446. {
  37447. if (getHeight() > 0 && getWidth() > 0)
  37448. getLookAndFeel().positionComboBoxText (*this, *label);
  37449. }
  37450. void ComboBox::enablementChanged()
  37451. {
  37452. repaint();
  37453. }
  37454. void ComboBox::lookAndFeelChanged()
  37455. {
  37456. repaint();
  37457. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37458. if (label != 0)
  37459. {
  37460. newLabel->setEditable (label->isEditable());
  37461. newLabel->setJustificationType (label->getJustificationType());
  37462. newLabel->setTooltip (label->getTooltip());
  37463. newLabel->setText (label->getText(), false);
  37464. }
  37465. label = newLabel;
  37466. addAndMakeVisible (newLabel);
  37467. newLabel->addListener (this);
  37468. newLabel->addMouseListener (this, false);
  37469. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37470. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37471. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37472. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37473. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37474. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37475. resized();
  37476. }
  37477. void ComboBox::colourChanged()
  37478. {
  37479. lookAndFeelChanged();
  37480. }
  37481. bool ComboBox::keyPressed (const KeyPress& key)
  37482. {
  37483. bool used = false;
  37484. if (key.isKeyCode (KeyPress::upKey)
  37485. || key.isKeyCode (KeyPress::leftKey))
  37486. {
  37487. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37488. used = true;
  37489. }
  37490. else if (key.isKeyCode (KeyPress::downKey)
  37491. || key.isKeyCode (KeyPress::rightKey))
  37492. {
  37493. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37494. used = true;
  37495. }
  37496. else if (key.isKeyCode (KeyPress::returnKey))
  37497. {
  37498. showPopup();
  37499. used = true;
  37500. }
  37501. return used;
  37502. }
  37503. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37504. {
  37505. // only forward key events that aren't used by this component
  37506. return isKeyDown
  37507. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37508. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37509. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37510. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37511. }
  37512. void ComboBox::focusGained (FocusChangeType)
  37513. {
  37514. repaint();
  37515. }
  37516. void ComboBox::focusLost (FocusChangeType)
  37517. {
  37518. repaint();
  37519. }
  37520. void ComboBox::labelTextChanged (Label*)
  37521. {
  37522. triggerAsyncUpdate();
  37523. }
  37524. void ComboBox::showPopup()
  37525. {
  37526. if (! menuActive)
  37527. {
  37528. const int selectedId = getSelectedId();
  37529. Component::SafePointer<Component> deletionWatcher (this);
  37530. PopupMenu menu;
  37531. menu.setLookAndFeel (&getLookAndFeel());
  37532. for (int i = 0; i < items.size(); ++i)
  37533. {
  37534. const ItemInfo* const item = items.getUnchecked(i);
  37535. if (item->isSeparator())
  37536. menu.addSeparator();
  37537. else if (item->isHeading)
  37538. menu.addSectionHeader (item->name);
  37539. else
  37540. menu.addItem (item->itemId, item->name,
  37541. item->isEnabled, item->itemId == selectedId);
  37542. }
  37543. if (items.size() == 0)
  37544. menu.addItem (1, noChoicesMessage, false);
  37545. const int itemHeight = jlimit (12, 24, getHeight());
  37546. menuActive = true;
  37547. const int resultId = menu.showAt (this, selectedId,
  37548. getWidth(), 1, itemHeight);
  37549. if (deletionWatcher == 0)
  37550. return;
  37551. menuActive = false;
  37552. if (resultId != 0)
  37553. setSelectedId (resultId);
  37554. }
  37555. }
  37556. void ComboBox::mouseDown (const MouseEvent& e)
  37557. {
  37558. beginDragAutoRepeat (300);
  37559. isButtonDown = isEnabled();
  37560. if (isButtonDown
  37561. && (e.eventComponent == this || ! label->isEditable()))
  37562. {
  37563. showPopup();
  37564. }
  37565. }
  37566. void ComboBox::mouseDrag (const MouseEvent& e)
  37567. {
  37568. beginDragAutoRepeat (50);
  37569. if (isButtonDown && ! e.mouseWasClicked())
  37570. showPopup();
  37571. }
  37572. void ComboBox::mouseUp (const MouseEvent& e2)
  37573. {
  37574. if (isButtonDown)
  37575. {
  37576. isButtonDown = false;
  37577. repaint();
  37578. const MouseEvent e (e2.getEventRelativeTo (this));
  37579. if (reallyContains (e.x, e.y, true)
  37580. && (e2.eventComponent == this || ! label->isEditable()))
  37581. {
  37582. showPopup();
  37583. }
  37584. }
  37585. }
  37586. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37587. {
  37588. listeners.add (listener);
  37589. }
  37590. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37591. {
  37592. listeners.remove (listener);
  37593. }
  37594. void ComboBox::handleAsyncUpdate()
  37595. {
  37596. Component::BailOutChecker checker (this);
  37597. listeners.callChecked (checker, &ComboBoxListener::comboBoxChanged, this);
  37598. }
  37599. END_JUCE_NAMESPACE
  37600. /*** End of inlined file: juce_ComboBox.cpp ***/
  37601. /*** Start of inlined file: juce_Label.cpp ***/
  37602. BEGIN_JUCE_NAMESPACE
  37603. Label::Label (const String& componentName,
  37604. const String& labelText)
  37605. : Component (componentName),
  37606. textValue (labelText),
  37607. lastTextValue (labelText),
  37608. font (15.0f),
  37609. justification (Justification::centredLeft),
  37610. ownerComponent (0),
  37611. horizontalBorderSize (5),
  37612. verticalBorderSize (1),
  37613. minimumHorizontalScale (0.7f),
  37614. editSingleClick (false),
  37615. editDoubleClick (false),
  37616. lossOfFocusDiscardsChanges (false)
  37617. {
  37618. setColour (TextEditor::textColourId, Colours::black);
  37619. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37620. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37621. textValue.addListener (this);
  37622. }
  37623. Label::~Label()
  37624. {
  37625. textValue.removeListener (this);
  37626. if (ownerComponent != 0)
  37627. ownerComponent->removeComponentListener (this);
  37628. editor = 0;
  37629. }
  37630. void Label::setText (const String& newText,
  37631. const bool broadcastChangeMessage)
  37632. {
  37633. hideEditor (true);
  37634. if (lastTextValue != newText)
  37635. {
  37636. lastTextValue = newText;
  37637. textValue = newText;
  37638. repaint();
  37639. textWasChanged();
  37640. if (ownerComponent != 0)
  37641. componentMovedOrResized (*ownerComponent, true, true);
  37642. if (broadcastChangeMessage)
  37643. callChangeListeners();
  37644. }
  37645. }
  37646. const String Label::getText (const bool returnActiveEditorContents) const throw()
  37647. {
  37648. return (returnActiveEditorContents && isBeingEdited())
  37649. ? editor->getText()
  37650. : textValue.toString();
  37651. }
  37652. void Label::valueChanged (Value&)
  37653. {
  37654. if (lastTextValue != textValue.toString())
  37655. setText (textValue.toString(), true);
  37656. }
  37657. void Label::setFont (const Font& newFont) throw()
  37658. {
  37659. font = newFont;
  37660. repaint();
  37661. }
  37662. const Font& Label::getFont() const throw()
  37663. {
  37664. return font;
  37665. }
  37666. void Label::setEditable (const bool editOnSingleClick,
  37667. const bool editOnDoubleClick,
  37668. const bool lossOfFocusDiscardsChanges_) throw()
  37669. {
  37670. editSingleClick = editOnSingleClick;
  37671. editDoubleClick = editOnDoubleClick;
  37672. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  37673. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  37674. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  37675. }
  37676. void Label::setJustificationType (const Justification& justification_) throw()
  37677. {
  37678. justification = justification_;
  37679. repaint();
  37680. }
  37681. void Label::setBorderSize (int h, int v)
  37682. {
  37683. horizontalBorderSize = h;
  37684. verticalBorderSize = v;
  37685. repaint();
  37686. }
  37687. Component* Label::getAttachedComponent() const
  37688. {
  37689. return static_cast<Component*> (ownerComponent);
  37690. }
  37691. void Label::attachToComponent (Component* owner,
  37692. const bool onLeft)
  37693. {
  37694. if (ownerComponent != 0)
  37695. ownerComponent->removeComponentListener (this);
  37696. ownerComponent = owner;
  37697. leftOfOwnerComp = onLeft;
  37698. if (ownerComponent != 0)
  37699. {
  37700. setVisible (owner->isVisible());
  37701. ownerComponent->addComponentListener (this);
  37702. componentParentHierarchyChanged (*ownerComponent);
  37703. componentMovedOrResized (*ownerComponent, true, true);
  37704. }
  37705. }
  37706. void Label::componentMovedOrResized (Component& component,
  37707. bool /*wasMoved*/,
  37708. bool /*wasResized*/)
  37709. {
  37710. if (leftOfOwnerComp)
  37711. {
  37712. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  37713. component.getHeight());
  37714. setTopRightPosition (component.getX(), component.getY());
  37715. }
  37716. else
  37717. {
  37718. setSize (component.getWidth(),
  37719. 8 + roundToInt (getFont().getHeight()));
  37720. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  37721. }
  37722. }
  37723. void Label::componentParentHierarchyChanged (Component& component)
  37724. {
  37725. if (component.getParentComponent() != 0)
  37726. component.getParentComponent()->addChildComponent (this);
  37727. }
  37728. void Label::componentVisibilityChanged (Component& component)
  37729. {
  37730. setVisible (component.isVisible());
  37731. }
  37732. void Label::textWasEdited()
  37733. {
  37734. }
  37735. void Label::textWasChanged()
  37736. {
  37737. }
  37738. void Label::showEditor()
  37739. {
  37740. if (editor == 0)
  37741. {
  37742. addAndMakeVisible (editor = createEditorComponent());
  37743. editor->setText (getText(), false);
  37744. editor->addListener (this);
  37745. editor->grabKeyboardFocus();
  37746. editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
  37747. editor->addListener (this);
  37748. resized();
  37749. repaint();
  37750. editorShown (editor);
  37751. enterModalState();
  37752. editor->grabKeyboardFocus();
  37753. }
  37754. }
  37755. void Label::editorShown (TextEditor* /*editorComponent*/)
  37756. {
  37757. }
  37758. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  37759. {
  37760. }
  37761. bool Label::updateFromTextEditorContents()
  37762. {
  37763. jassert (editor != 0);
  37764. const String newText (editor->getText());
  37765. if (textValue.toString() != newText)
  37766. {
  37767. lastTextValue = newText;
  37768. textValue = newText;
  37769. repaint();
  37770. textWasChanged();
  37771. if (ownerComponent != 0)
  37772. componentMovedOrResized (*ownerComponent, true, true);
  37773. return true;
  37774. }
  37775. return false;
  37776. }
  37777. void Label::hideEditor (const bool discardCurrentEditorContents)
  37778. {
  37779. if (editor != 0)
  37780. {
  37781. Component::SafePointer<Component> deletionChecker (this);
  37782. editorAboutToBeHidden (editor);
  37783. const bool changed = (! discardCurrentEditorContents)
  37784. && updateFromTextEditorContents();
  37785. editor = 0;
  37786. repaint();
  37787. if (changed)
  37788. textWasEdited();
  37789. if (deletionChecker != 0)
  37790. exitModalState (0);
  37791. if (changed && deletionChecker != 0)
  37792. callChangeListeners();
  37793. }
  37794. }
  37795. void Label::inputAttemptWhenModal()
  37796. {
  37797. if (editor != 0)
  37798. {
  37799. if (lossOfFocusDiscardsChanges)
  37800. textEditorEscapeKeyPressed (*editor);
  37801. else
  37802. textEditorReturnKeyPressed (*editor);
  37803. }
  37804. }
  37805. bool Label::isBeingEdited() const throw()
  37806. {
  37807. return editor != 0;
  37808. }
  37809. TextEditor* Label::createEditorComponent()
  37810. {
  37811. TextEditor* const ed = new TextEditor (getName());
  37812. ed->setFont (font);
  37813. // copy these colours from our own settings..
  37814. const int cols[] = { TextEditor::backgroundColourId,
  37815. TextEditor::textColourId,
  37816. TextEditor::highlightColourId,
  37817. TextEditor::highlightedTextColourId,
  37818. TextEditor::caretColourId,
  37819. TextEditor::outlineColourId,
  37820. TextEditor::focusedOutlineColourId,
  37821. TextEditor::shadowColourId };
  37822. for (int i = 0; i < numElementsInArray (cols); ++i)
  37823. ed->setColour (cols[i], findColour (cols[i]));
  37824. return ed;
  37825. }
  37826. void Label::paint (Graphics& g)
  37827. {
  37828. getLookAndFeel().drawLabel (g, *this);
  37829. }
  37830. void Label::mouseUp (const MouseEvent& e)
  37831. {
  37832. if (editSingleClick
  37833. && e.mouseWasClicked()
  37834. && contains (e.x, e.y)
  37835. && ! e.mods.isPopupMenu())
  37836. {
  37837. showEditor();
  37838. }
  37839. }
  37840. void Label::mouseDoubleClick (const MouseEvent& e)
  37841. {
  37842. if (editDoubleClick && ! e.mods.isPopupMenu())
  37843. showEditor();
  37844. }
  37845. void Label::resized()
  37846. {
  37847. if (editor != 0)
  37848. editor->setBoundsInset (BorderSize (0));
  37849. }
  37850. void Label::focusGained (FocusChangeType cause)
  37851. {
  37852. if (editSingleClick && cause == focusChangedByTabKey)
  37853. showEditor();
  37854. }
  37855. void Label::enablementChanged()
  37856. {
  37857. repaint();
  37858. }
  37859. void Label::colourChanged()
  37860. {
  37861. repaint();
  37862. }
  37863. void Label::setMinimumHorizontalScale (const float newScale)
  37864. {
  37865. if (minimumHorizontalScale != newScale)
  37866. {
  37867. minimumHorizontalScale = newScale;
  37868. repaint();
  37869. }
  37870. }
  37871. // We'll use a custom focus traverser here to make sure focus goes from the
  37872. // text editor to another component rather than back to the label itself.
  37873. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  37874. {
  37875. public:
  37876. LabelKeyboardFocusTraverser() {}
  37877. Component* getNextComponent (Component* current)
  37878. {
  37879. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  37880. ? current->getParentComponent() : current);
  37881. }
  37882. Component* getPreviousComponent (Component* current)
  37883. {
  37884. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  37885. ? current->getParentComponent() : current);
  37886. }
  37887. };
  37888. KeyboardFocusTraverser* Label::createFocusTraverser()
  37889. {
  37890. return new LabelKeyboardFocusTraverser();
  37891. }
  37892. void Label::addListener (LabelListener* const listener) throw()
  37893. {
  37894. listeners.add (listener);
  37895. }
  37896. void Label::removeListener (LabelListener* const listener) throw()
  37897. {
  37898. listeners.remove (listener);
  37899. }
  37900. void Label::callChangeListeners()
  37901. {
  37902. Component::BailOutChecker checker (this);
  37903. listeners.callChecked (checker, &LabelListener::labelTextChanged, this);
  37904. }
  37905. void Label::textEditorTextChanged (TextEditor& ed)
  37906. {
  37907. if (editor != 0)
  37908. {
  37909. jassert (&ed == editor);
  37910. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  37911. {
  37912. if (lossOfFocusDiscardsChanges)
  37913. textEditorEscapeKeyPressed (ed);
  37914. else
  37915. textEditorReturnKeyPressed (ed);
  37916. }
  37917. }
  37918. }
  37919. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  37920. {
  37921. if (editor != 0)
  37922. {
  37923. jassert (&ed == editor);
  37924. (void) ed;
  37925. const bool changed = updateFromTextEditorContents();
  37926. hideEditor (true);
  37927. if (changed)
  37928. {
  37929. Component::SafePointer<Component> deletionChecker (this);
  37930. textWasEdited();
  37931. if (deletionChecker != 0)
  37932. callChangeListeners();
  37933. }
  37934. }
  37935. }
  37936. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  37937. {
  37938. if (editor != 0)
  37939. {
  37940. jassert (&ed == editor);
  37941. (void) ed;
  37942. editor->setText (textValue.toString(), false);
  37943. hideEditor (true);
  37944. }
  37945. }
  37946. void Label::textEditorFocusLost (TextEditor& ed)
  37947. {
  37948. textEditorTextChanged (ed);
  37949. }
  37950. END_JUCE_NAMESPACE
  37951. /*** End of inlined file: juce_Label.cpp ***/
  37952. /*** Start of inlined file: juce_ListBox.cpp ***/
  37953. BEGIN_JUCE_NAMESPACE
  37954. class ListBoxRowComponent : public Component,
  37955. public TooltipClient
  37956. {
  37957. public:
  37958. ListBoxRowComponent (ListBox& owner_)
  37959. : owner (owner_),
  37960. row (-1),
  37961. selected (false),
  37962. isDragging (false)
  37963. {
  37964. }
  37965. ~ListBoxRowComponent()
  37966. {
  37967. deleteAllChildren();
  37968. }
  37969. void paint (Graphics& g)
  37970. {
  37971. if (owner.getModel() != 0)
  37972. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  37973. }
  37974. void update (const int row_, const bool selected_)
  37975. {
  37976. if (row != row_ || selected != selected_)
  37977. {
  37978. repaint();
  37979. row = row_;
  37980. selected = selected_;
  37981. }
  37982. if (owner.getModel() != 0)
  37983. {
  37984. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  37985. if (customComp != 0)
  37986. {
  37987. addAndMakeVisible (customComp);
  37988. customComp->setBounds (0, 0, getWidth(), getHeight());
  37989. for (int i = getNumChildComponents(); --i >= 0;)
  37990. if (getChildComponent (i) != customComp)
  37991. delete getChildComponent (i);
  37992. }
  37993. else
  37994. {
  37995. deleteAllChildren();
  37996. }
  37997. }
  37998. }
  37999. void mouseDown (const MouseEvent& e)
  38000. {
  38001. isDragging = false;
  38002. selectRowOnMouseUp = false;
  38003. if (isEnabled())
  38004. {
  38005. if (! selected)
  38006. {
  38007. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38008. if (owner.getModel() != 0)
  38009. owner.getModel()->listBoxItemClicked (row, e);
  38010. }
  38011. else
  38012. {
  38013. selectRowOnMouseUp = true;
  38014. }
  38015. }
  38016. }
  38017. void mouseUp (const MouseEvent& e)
  38018. {
  38019. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  38020. {
  38021. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38022. if (owner.getModel() != 0)
  38023. owner.getModel()->listBoxItemClicked (row, e);
  38024. }
  38025. }
  38026. void mouseDoubleClick (const MouseEvent& e)
  38027. {
  38028. if (owner.getModel() != 0 && isEnabled())
  38029. owner.getModel()->listBoxItemDoubleClicked (row, e);
  38030. }
  38031. void mouseDrag (const MouseEvent& e)
  38032. {
  38033. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  38034. {
  38035. const SparseSet <int> selectedRows (owner.getSelectedRows());
  38036. if (selectedRows.size() > 0)
  38037. {
  38038. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  38039. if (dragDescription.isNotEmpty())
  38040. {
  38041. isDragging = true;
  38042. owner.startDragAndDrop (e, dragDescription);
  38043. }
  38044. }
  38045. }
  38046. }
  38047. void resized()
  38048. {
  38049. if (getNumChildComponents() > 0)
  38050. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  38051. }
  38052. const String getTooltip()
  38053. {
  38054. if (owner.getModel() != 0)
  38055. return owner.getModel()->getTooltipForRow (row);
  38056. return String::empty;
  38057. }
  38058. juce_UseDebuggingNewOperator
  38059. bool neededFlag;
  38060. private:
  38061. ListBox& owner;
  38062. int row;
  38063. bool selected, isDragging, selectRowOnMouseUp;
  38064. ListBoxRowComponent (const ListBoxRowComponent&);
  38065. ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  38066. };
  38067. class ListViewport : public Viewport
  38068. {
  38069. public:
  38070. int firstIndex, firstWholeIndex, lastWholeIndex;
  38071. bool hasUpdated;
  38072. ListViewport (ListBox& owner_)
  38073. : owner (owner_)
  38074. {
  38075. setWantsKeyboardFocus (false);
  38076. setViewedComponent (new Component());
  38077. getViewedComponent()->addMouseListener (this, false);
  38078. getViewedComponent()->setWantsKeyboardFocus (false);
  38079. }
  38080. ~ListViewport()
  38081. {
  38082. getViewedComponent()->removeMouseListener (this);
  38083. getViewedComponent()->deleteAllChildren();
  38084. }
  38085. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  38086. {
  38087. return (ListBoxRowComponent*) getViewedComponent()
  38088. ->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents()));
  38089. }
  38090. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  38091. {
  38092. const int index = getIndexOfChildComponent (rowComponent);
  38093. const int num = getViewedComponent()->getNumChildComponents();
  38094. for (int i = num; --i >= 0;)
  38095. if (((firstIndex + i) % jmax (1, num)) == index)
  38096. return firstIndex + i;
  38097. return -1;
  38098. }
  38099. Component* getComponentForRowIfOnscreen (const int row) const throw()
  38100. {
  38101. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  38102. ? getComponentForRow (row) : 0;
  38103. }
  38104. void visibleAreaChanged (int, int, int, int)
  38105. {
  38106. updateVisibleArea (true);
  38107. if (owner.getModel() != 0)
  38108. owner.getModel()->listWasScrolled();
  38109. }
  38110. void updateVisibleArea (const bool makeSureItUpdatesContent)
  38111. {
  38112. hasUpdated = false;
  38113. const int newX = getViewedComponent()->getX();
  38114. int newY = getViewedComponent()->getY();
  38115. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  38116. const int newH = owner.totalItems * owner.getRowHeight();
  38117. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  38118. newY = getMaximumVisibleHeight() - newH;
  38119. getViewedComponent()->setBounds (newX, newY, newW, newH);
  38120. if (makeSureItUpdatesContent && ! hasUpdated)
  38121. updateContents();
  38122. }
  38123. void updateContents()
  38124. {
  38125. hasUpdated = true;
  38126. const int rowHeight = owner.getRowHeight();
  38127. if (rowHeight > 0)
  38128. {
  38129. const int y = getViewPositionY();
  38130. const int w = getViewedComponent()->getWidth();
  38131. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  38132. while (numNeeded > getViewedComponent()->getNumChildComponents())
  38133. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  38134. jassert (numNeeded >= 0);
  38135. while (numNeeded < getViewedComponent()->getNumChildComponents())
  38136. {
  38137. Component* const rowToRemove
  38138. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  38139. delete rowToRemove;
  38140. }
  38141. firstIndex = y / rowHeight;
  38142. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  38143. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  38144. for (int i = 0; i < numNeeded; ++i)
  38145. {
  38146. const int row = i + firstIndex;
  38147. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  38148. if (rowComp != 0)
  38149. {
  38150. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  38151. rowComp->update (row, owner.isRowSelected (row));
  38152. }
  38153. }
  38154. }
  38155. if (owner.headerComponent != 0)
  38156. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  38157. owner.outlineThickness,
  38158. jmax (owner.getWidth() - owner.outlineThickness * 2,
  38159. getViewedComponent()->getWidth()),
  38160. owner.headerComponent->getHeight());
  38161. }
  38162. void paint (Graphics& g)
  38163. {
  38164. if (isOpaque())
  38165. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  38166. }
  38167. bool keyPressed (const KeyPress& key)
  38168. {
  38169. if (key.isKeyCode (KeyPress::upKey)
  38170. || key.isKeyCode (KeyPress::downKey)
  38171. || key.isKeyCode (KeyPress::pageUpKey)
  38172. || key.isKeyCode (KeyPress::pageDownKey)
  38173. || key.isKeyCode (KeyPress::homeKey)
  38174. || key.isKeyCode (KeyPress::endKey))
  38175. {
  38176. // we want to avoid these keypresses going to the viewport, and instead allow
  38177. // them to pass up to our listbox..
  38178. return false;
  38179. }
  38180. return Viewport::keyPressed (key);
  38181. }
  38182. juce_UseDebuggingNewOperator
  38183. private:
  38184. ListBox& owner;
  38185. ListViewport (const ListViewport&);
  38186. ListViewport& operator= (const ListViewport&);
  38187. };
  38188. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  38189. : Component (name),
  38190. model (model_),
  38191. headerComponent (0),
  38192. totalItems (0),
  38193. rowHeight (22),
  38194. minimumRowWidth (0),
  38195. outlineThickness (0),
  38196. lastRowSelected (-1),
  38197. mouseMoveSelects (false),
  38198. multipleSelection (false),
  38199. hasDoneInitialUpdate (false)
  38200. {
  38201. addAndMakeVisible (viewport = new ListViewport (*this));
  38202. setWantsKeyboardFocus (true);
  38203. colourChanged();
  38204. }
  38205. ListBox::~ListBox()
  38206. {
  38207. deleteAllChildren();
  38208. }
  38209. void ListBox::setModel (ListBoxModel* const newModel)
  38210. {
  38211. if (model != newModel)
  38212. {
  38213. model = newModel;
  38214. updateContent();
  38215. }
  38216. }
  38217. void ListBox::setMultipleSelectionEnabled (bool b)
  38218. {
  38219. multipleSelection = b;
  38220. }
  38221. void ListBox::setMouseMoveSelectsRows (bool b)
  38222. {
  38223. mouseMoveSelects = b;
  38224. if (b)
  38225. addMouseListener (this, true);
  38226. }
  38227. void ListBox::paint (Graphics& g)
  38228. {
  38229. if (! hasDoneInitialUpdate)
  38230. updateContent();
  38231. g.fillAll (findColour (backgroundColourId));
  38232. }
  38233. void ListBox::paintOverChildren (Graphics& g)
  38234. {
  38235. if (outlineThickness > 0)
  38236. {
  38237. g.setColour (findColour (outlineColourId));
  38238. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  38239. }
  38240. }
  38241. void ListBox::resized()
  38242. {
  38243. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  38244. outlineThickness,
  38245. outlineThickness,
  38246. outlineThickness));
  38247. viewport->setSingleStepSizes (20, getRowHeight());
  38248. viewport->updateVisibleArea (false);
  38249. }
  38250. void ListBox::visibilityChanged()
  38251. {
  38252. viewport->updateVisibleArea (true);
  38253. }
  38254. Viewport* ListBox::getViewport() const throw()
  38255. {
  38256. return viewport;
  38257. }
  38258. void ListBox::updateContent()
  38259. {
  38260. hasDoneInitialUpdate = true;
  38261. totalItems = (model != 0) ? model->getNumRows() : 0;
  38262. bool selectionChanged = false;
  38263. if (selected [selected.size() - 1] >= totalItems)
  38264. {
  38265. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38266. lastRowSelected = getSelectedRow (0);
  38267. selectionChanged = true;
  38268. }
  38269. viewport->updateVisibleArea (isVisible());
  38270. viewport->resized();
  38271. if (selectionChanged && model != 0)
  38272. model->selectedRowsChanged (lastRowSelected);
  38273. }
  38274. void ListBox::selectRow (const int row,
  38275. bool dontScroll,
  38276. bool deselectOthersFirst)
  38277. {
  38278. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38279. }
  38280. void ListBox::selectRowInternal (const int row,
  38281. bool dontScroll,
  38282. bool deselectOthersFirst,
  38283. bool isMouseClick)
  38284. {
  38285. if (! multipleSelection)
  38286. deselectOthersFirst = true;
  38287. if ((! isRowSelected (row))
  38288. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38289. {
  38290. if (((unsigned int) row) < (unsigned int) totalItems)
  38291. {
  38292. if (deselectOthersFirst)
  38293. selected.clear();
  38294. selected.addRange (row, 1);
  38295. if (getHeight() == 0 || getWidth() == 0)
  38296. dontScroll = true;
  38297. viewport->hasUpdated = false;
  38298. if (row < viewport->firstWholeIndex && ! dontScroll)
  38299. {
  38300. viewport->setViewPosition (viewport->getViewPositionX(),
  38301. row * getRowHeight());
  38302. }
  38303. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38304. {
  38305. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38306. if (row >= lastRowSelected + rowsOnScreen
  38307. && rowsOnScreen < totalItems - 1
  38308. && ! isMouseClick)
  38309. {
  38310. viewport->setViewPosition (viewport->getViewPositionX(),
  38311. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38312. * getRowHeight());
  38313. }
  38314. else
  38315. {
  38316. viewport->setViewPosition (viewport->getViewPositionX(),
  38317. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38318. }
  38319. }
  38320. if (! viewport->hasUpdated)
  38321. viewport->updateContents();
  38322. lastRowSelected = row;
  38323. model->selectedRowsChanged (row);
  38324. }
  38325. else
  38326. {
  38327. if (deselectOthersFirst)
  38328. deselectAllRows();
  38329. }
  38330. }
  38331. }
  38332. void ListBox::deselectRow (const int row)
  38333. {
  38334. if (selected.contains (row))
  38335. {
  38336. selected.removeRange (row, 1);
  38337. if (row == lastRowSelected)
  38338. lastRowSelected = getSelectedRow (0);
  38339. viewport->updateContents();
  38340. model->selectedRowsChanged (lastRowSelected);
  38341. }
  38342. }
  38343. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38344. const bool sendNotificationEventToModel)
  38345. {
  38346. selected = setOfRowsToBeSelected;
  38347. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38348. if (! isRowSelected (lastRowSelected))
  38349. lastRowSelected = getSelectedRow (0);
  38350. viewport->updateContents();
  38351. if ((model != 0) && sendNotificationEventToModel)
  38352. model->selectedRowsChanged (lastRowSelected);
  38353. }
  38354. const SparseSet<int> ListBox::getSelectedRows() const
  38355. {
  38356. return selected;
  38357. }
  38358. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38359. {
  38360. if (multipleSelection && (firstRow != lastRow))
  38361. {
  38362. const int numRows = totalItems - 1;
  38363. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38364. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38365. selected.addRange (jmin (firstRow, lastRow),
  38366. abs (firstRow - lastRow) + 1);
  38367. selected.removeRange (lastRow, 1);
  38368. }
  38369. selectRowInternal (lastRow, false, false, true);
  38370. }
  38371. void ListBox::flipRowSelection (const int row)
  38372. {
  38373. if (isRowSelected (row))
  38374. deselectRow (row);
  38375. else
  38376. selectRowInternal (row, false, false, true);
  38377. }
  38378. void ListBox::deselectAllRows()
  38379. {
  38380. if (! selected.isEmpty())
  38381. {
  38382. selected.clear();
  38383. lastRowSelected = -1;
  38384. viewport->updateContents();
  38385. if (model != 0)
  38386. model->selectedRowsChanged (lastRowSelected);
  38387. }
  38388. }
  38389. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38390. const ModifierKeys& mods)
  38391. {
  38392. if (multipleSelection && mods.isCommandDown())
  38393. {
  38394. flipRowSelection (row);
  38395. }
  38396. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38397. {
  38398. selectRangeOfRows (lastRowSelected, row);
  38399. }
  38400. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38401. {
  38402. selectRowInternal (row, false, true, true);
  38403. }
  38404. }
  38405. int ListBox::getNumSelectedRows() const
  38406. {
  38407. return selected.size();
  38408. }
  38409. int ListBox::getSelectedRow (const int index) const
  38410. {
  38411. return (((unsigned int) index) < (unsigned int) selected.size())
  38412. ? selected [index] : -1;
  38413. }
  38414. bool ListBox::isRowSelected (const int row) const
  38415. {
  38416. return selected.contains (row);
  38417. }
  38418. int ListBox::getLastRowSelected() const
  38419. {
  38420. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38421. }
  38422. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38423. {
  38424. if (((unsigned int) x) < (unsigned int) getWidth())
  38425. {
  38426. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38427. if (((unsigned int) row) < (unsigned int) totalItems)
  38428. return row;
  38429. }
  38430. return -1;
  38431. }
  38432. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38433. {
  38434. if (((unsigned int) x) < (unsigned int) getWidth())
  38435. {
  38436. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38437. return jlimit (0, totalItems, row);
  38438. }
  38439. return -1;
  38440. }
  38441. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38442. {
  38443. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38444. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38445. }
  38446. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38447. {
  38448. return viewport->getRowNumberOfComponent (rowComponent);
  38449. }
  38450. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38451. const bool relativeToComponentTopLeft) const throw()
  38452. {
  38453. const int rowHeight = getRowHeight();
  38454. int y = viewport->getY() + rowHeight * rowNumber;
  38455. if (relativeToComponentTopLeft)
  38456. y -= viewport->getViewPositionY();
  38457. return Rectangle<int> (viewport->getX(), y,
  38458. viewport->getViewedComponent()->getWidth(), rowHeight);
  38459. }
  38460. void ListBox::setVerticalPosition (const double proportion)
  38461. {
  38462. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38463. viewport->setViewPosition (viewport->getViewPositionX(),
  38464. jmax (0, roundToInt (proportion * offscreen)));
  38465. }
  38466. double ListBox::getVerticalPosition() const
  38467. {
  38468. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38469. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38470. : 0;
  38471. }
  38472. int ListBox::getVisibleRowWidth() const throw()
  38473. {
  38474. return viewport->getViewWidth();
  38475. }
  38476. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38477. {
  38478. if (row < viewport->firstWholeIndex)
  38479. {
  38480. viewport->setViewPosition (viewport->getViewPositionX(),
  38481. row * getRowHeight());
  38482. }
  38483. else if (row >= viewport->lastWholeIndex)
  38484. {
  38485. viewport->setViewPosition (viewport->getViewPositionX(),
  38486. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38487. }
  38488. }
  38489. bool ListBox::keyPressed (const KeyPress& key)
  38490. {
  38491. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38492. const bool multiple = multipleSelection
  38493. && (lastRowSelected >= 0)
  38494. && (key.getModifiers().isShiftDown()
  38495. || key.getModifiers().isCtrlDown()
  38496. || key.getModifiers().isCommandDown());
  38497. if (key.isKeyCode (KeyPress::upKey))
  38498. {
  38499. if (multiple)
  38500. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38501. else
  38502. selectRow (jmax (0, lastRowSelected - 1));
  38503. }
  38504. else if (key.isKeyCode (KeyPress::returnKey)
  38505. && isRowSelected (lastRowSelected))
  38506. {
  38507. if (model != 0)
  38508. model->returnKeyPressed (lastRowSelected);
  38509. }
  38510. else if (key.isKeyCode (KeyPress::pageUpKey))
  38511. {
  38512. if (multiple)
  38513. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38514. else
  38515. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38516. }
  38517. else if (key.isKeyCode (KeyPress::pageDownKey))
  38518. {
  38519. if (multiple)
  38520. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38521. else
  38522. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38523. }
  38524. else if (key.isKeyCode (KeyPress::homeKey))
  38525. {
  38526. if (multiple && key.getModifiers().isShiftDown())
  38527. selectRangeOfRows (lastRowSelected, 0);
  38528. else
  38529. selectRow (0);
  38530. }
  38531. else if (key.isKeyCode (KeyPress::endKey))
  38532. {
  38533. if (multiple && key.getModifiers().isShiftDown())
  38534. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38535. else
  38536. selectRow (totalItems - 1);
  38537. }
  38538. else if (key.isKeyCode (KeyPress::downKey))
  38539. {
  38540. if (multiple)
  38541. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38542. else
  38543. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38544. }
  38545. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38546. && isRowSelected (lastRowSelected))
  38547. {
  38548. if (model != 0)
  38549. model->deleteKeyPressed (lastRowSelected);
  38550. }
  38551. else if (multiple && key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  38552. {
  38553. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38554. }
  38555. else
  38556. {
  38557. return false;
  38558. }
  38559. return true;
  38560. }
  38561. bool ListBox::keyStateChanged (const bool isKeyDown)
  38562. {
  38563. return isKeyDown
  38564. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38565. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38566. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38567. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38568. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38569. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38570. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38571. }
  38572. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38573. {
  38574. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38575. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38576. }
  38577. void ListBox::mouseMove (const MouseEvent& e)
  38578. {
  38579. if (mouseMoveSelects)
  38580. {
  38581. const MouseEvent e2 (e.getEventRelativeTo (this));
  38582. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38583. }
  38584. }
  38585. void ListBox::mouseExit (const MouseEvent& e)
  38586. {
  38587. mouseMove (e);
  38588. }
  38589. void ListBox::mouseUp (const MouseEvent& e)
  38590. {
  38591. if (e.mouseWasClicked() && model != 0)
  38592. model->backgroundClicked();
  38593. }
  38594. void ListBox::setRowHeight (const int newHeight)
  38595. {
  38596. rowHeight = jmax (1, newHeight);
  38597. viewport->setSingleStepSizes (20, rowHeight);
  38598. updateContent();
  38599. }
  38600. int ListBox::getNumRowsOnScreen() const throw()
  38601. {
  38602. return viewport->getMaximumVisibleHeight() / rowHeight;
  38603. }
  38604. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38605. {
  38606. minimumRowWidth = newMinimumWidth;
  38607. updateContent();
  38608. }
  38609. int ListBox::getVisibleContentWidth() const throw()
  38610. {
  38611. return viewport->getMaximumVisibleWidth();
  38612. }
  38613. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38614. {
  38615. return viewport->getVerticalScrollBar();
  38616. }
  38617. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38618. {
  38619. return viewport->getHorizontalScrollBar();
  38620. }
  38621. void ListBox::colourChanged()
  38622. {
  38623. setOpaque (findColour (backgroundColourId).isOpaque());
  38624. viewport->setOpaque (isOpaque());
  38625. repaint();
  38626. }
  38627. void ListBox::setOutlineThickness (const int outlineThickness_)
  38628. {
  38629. outlineThickness = outlineThickness_;
  38630. resized();
  38631. }
  38632. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38633. {
  38634. if (headerComponent != newHeaderComponent)
  38635. {
  38636. delete headerComponent;
  38637. headerComponent = newHeaderComponent;
  38638. addAndMakeVisible (newHeaderComponent);
  38639. ListBox::resized();
  38640. }
  38641. }
  38642. void ListBox::repaintRow (const int rowNumber) throw()
  38643. {
  38644. const Rectangle<int> r (getRowPosition (rowNumber, true));
  38645. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  38646. }
  38647. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  38648. {
  38649. Rectangle<int> imageArea;
  38650. const int firstRow = getRowContainingPosition (0, 0);
  38651. int i;
  38652. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38653. {
  38654. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38655. if (rowComp != 0 && isRowSelected (firstRow + i))
  38656. {
  38657. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38658. const Rectangle<int> rowRect (pos.getX(), pos.getY(), rowComp->getWidth(), rowComp->getHeight());
  38659. if (imageArea.isEmpty())
  38660. imageArea = rowRect;
  38661. else
  38662. imageArea = imageArea.getUnion (rowRect);
  38663. }
  38664. }
  38665. imageArea = imageArea.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  38666. imageX = imageArea.getX();
  38667. imageY = imageArea.getY();
  38668. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  38669. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38670. {
  38671. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38672. if (rowComp != 0 && isRowSelected (firstRow + i))
  38673. {
  38674. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38675. Graphics g (*snapshot);
  38676. g.setOrigin (pos.getX() - imageX, pos.getY() - imageY);
  38677. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  38678. rowComp->paintEntireComponent (g);
  38679. }
  38680. }
  38681. return snapshot;
  38682. }
  38683. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  38684. {
  38685. DragAndDropContainer* const dragContainer
  38686. = DragAndDropContainer::findParentDragContainerFor (this);
  38687. if (dragContainer != 0)
  38688. {
  38689. int x, y;
  38690. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  38691. dragImage->multiplyAllAlphas (0.6f);
  38692. MouseEvent e2 (e.getEventRelativeTo (this));
  38693. const Point<int> p (x - e2.x, y - e2.y);
  38694. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  38695. }
  38696. else
  38697. {
  38698. // to be able to do a drag-and-drop operation, the listbox needs to
  38699. // be inside a component which is also a DragAndDropContainer.
  38700. jassertfalse
  38701. }
  38702. }
  38703. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  38704. {
  38705. (void) existingComponentToUpdate;
  38706. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  38707. return 0;
  38708. }
  38709. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  38710. {
  38711. }
  38712. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  38713. {
  38714. }
  38715. void ListBoxModel::backgroundClicked()
  38716. {
  38717. }
  38718. void ListBoxModel::selectedRowsChanged (int)
  38719. {
  38720. }
  38721. void ListBoxModel::deleteKeyPressed (int)
  38722. {
  38723. }
  38724. void ListBoxModel::returnKeyPressed (int)
  38725. {
  38726. }
  38727. void ListBoxModel::listWasScrolled()
  38728. {
  38729. }
  38730. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  38731. {
  38732. return String::empty;
  38733. }
  38734. const String ListBoxModel::getTooltipForRow (int)
  38735. {
  38736. return String::empty;
  38737. }
  38738. END_JUCE_NAMESPACE
  38739. /*** End of inlined file: juce_ListBox.cpp ***/
  38740. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  38741. BEGIN_JUCE_NAMESPACE
  38742. ProgressBar::ProgressBar (double& progress_)
  38743. : progress (progress_),
  38744. displayPercentage (true),
  38745. lastCallbackTime (0)
  38746. {
  38747. currentValue = jlimit (0.0, 1.0, progress);
  38748. }
  38749. ProgressBar::~ProgressBar()
  38750. {
  38751. }
  38752. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  38753. {
  38754. displayPercentage = shouldDisplayPercentage;
  38755. repaint();
  38756. }
  38757. void ProgressBar::setTextToDisplay (const String& text)
  38758. {
  38759. displayPercentage = false;
  38760. displayedMessage = text;
  38761. }
  38762. void ProgressBar::lookAndFeelChanged()
  38763. {
  38764. setOpaque (findColour (backgroundColourId).isOpaque());
  38765. }
  38766. void ProgressBar::colourChanged()
  38767. {
  38768. lookAndFeelChanged();
  38769. }
  38770. void ProgressBar::paint (Graphics& g)
  38771. {
  38772. String text;
  38773. if (displayPercentage)
  38774. {
  38775. if (currentValue >= 0 && currentValue <= 1.0)
  38776. text << roundToInt (currentValue * 100.0) << T("%");
  38777. }
  38778. else
  38779. {
  38780. text = displayedMessage;
  38781. }
  38782. getLookAndFeel().drawProgressBar (g, *this,
  38783. getWidth(), getHeight(),
  38784. currentValue, text);
  38785. }
  38786. void ProgressBar::visibilityChanged()
  38787. {
  38788. if (isVisible())
  38789. startTimer (30);
  38790. else
  38791. stopTimer();
  38792. }
  38793. void ProgressBar::timerCallback()
  38794. {
  38795. double newProgress = progress;
  38796. const uint32 now = Time::getMillisecondCounter();
  38797. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  38798. lastCallbackTime = now;
  38799. if (currentValue != newProgress
  38800. || newProgress < 0 || newProgress >= 1.0
  38801. || currentMessage != displayedMessage)
  38802. {
  38803. if (currentValue < newProgress
  38804. && newProgress >= 0 && newProgress < 1.0
  38805. && currentValue >= 0 && currentValue < 1.0)
  38806. {
  38807. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  38808. newProgress);
  38809. }
  38810. currentValue = newProgress;
  38811. currentMessage = displayedMessage;
  38812. repaint();
  38813. }
  38814. }
  38815. END_JUCE_NAMESPACE
  38816. /*** End of inlined file: juce_ProgressBar.cpp ***/
  38817. /*** Start of inlined file: juce_Slider.cpp ***/
  38818. BEGIN_JUCE_NAMESPACE
  38819. class SliderPopupDisplayComponent : public BubbleComponent
  38820. {
  38821. public:
  38822. SliderPopupDisplayComponent (Slider* const owner_)
  38823. : owner (owner_),
  38824. font (15.0f, Font::bold)
  38825. {
  38826. setAlwaysOnTop (true);
  38827. }
  38828. ~SliderPopupDisplayComponent()
  38829. {
  38830. }
  38831. void paintContent (Graphics& g, int w, int h)
  38832. {
  38833. g.setFont (font);
  38834. g.setColour (Colours::black);
  38835. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  38836. }
  38837. void getContentSize (int& w, int& h)
  38838. {
  38839. w = font.getStringWidth (text) + 18;
  38840. h = (int) (font.getHeight() * 1.6f);
  38841. }
  38842. void updatePosition (const String& newText)
  38843. {
  38844. if (text != newText)
  38845. {
  38846. text = newText;
  38847. repaint();
  38848. }
  38849. BubbleComponent::setPosition (owner);
  38850. }
  38851. juce_UseDebuggingNewOperator
  38852. private:
  38853. Slider* owner;
  38854. Font font;
  38855. String text;
  38856. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  38857. SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  38858. };
  38859. Slider::Slider (const String& name)
  38860. : Component (name),
  38861. lastCurrentValue (0),
  38862. lastValueMin (0),
  38863. lastValueMax (0),
  38864. minimum (0),
  38865. maximum (10),
  38866. interval (0),
  38867. skewFactor (1.0),
  38868. velocityModeSensitivity (1.0),
  38869. velocityModeOffset (0.0),
  38870. velocityModeThreshold (1),
  38871. rotaryStart (float_Pi * 1.2f),
  38872. rotaryEnd (float_Pi * 2.8f),
  38873. numDecimalPlaces (7),
  38874. sliderRegionStart (0),
  38875. sliderRegionSize (1),
  38876. sliderBeingDragged (-1),
  38877. pixelsForFullDragExtent (250),
  38878. style (LinearHorizontal),
  38879. textBoxPos (TextBoxLeft),
  38880. textBoxWidth (80),
  38881. textBoxHeight (20),
  38882. incDecButtonMode (incDecButtonsNotDraggable),
  38883. editableText (true),
  38884. doubleClickToValue (false),
  38885. isVelocityBased (false),
  38886. userKeyOverridesVelocity (true),
  38887. rotaryStop (true),
  38888. incDecButtonsSideBySide (false),
  38889. sendChangeOnlyOnRelease (false),
  38890. popupDisplayEnabled (false),
  38891. menuEnabled (false),
  38892. menuShown (false),
  38893. scrollWheelEnabled (true),
  38894. snapsToMousePos (true),
  38895. valueBox (0),
  38896. incButton (0),
  38897. decButton (0),
  38898. popupDisplay (0),
  38899. parentForPopupDisplay (0)
  38900. {
  38901. setWantsKeyboardFocus (false);
  38902. setRepaintsOnMouseActivity (true);
  38903. lookAndFeelChanged();
  38904. updateText();
  38905. currentValue.addListener (this);
  38906. valueMin.addListener (this);
  38907. valueMax.addListener (this);
  38908. }
  38909. Slider::~Slider()
  38910. {
  38911. currentValue.removeListener (this);
  38912. valueMin.removeListener (this);
  38913. valueMax.removeListener (this);
  38914. popupDisplay = 0;
  38915. deleteAllChildren();
  38916. }
  38917. void Slider::handleAsyncUpdate()
  38918. {
  38919. cancelPendingUpdate();
  38920. Component::BailOutChecker checker (this);
  38921. listeners.callChecked (checker, &SliderListener::sliderValueChanged, this);
  38922. }
  38923. void Slider::sendDragStart()
  38924. {
  38925. startedDragging();
  38926. Component::BailOutChecker checker (this);
  38927. listeners.callChecked (checker, &SliderListener::sliderDragStarted, this);
  38928. }
  38929. void Slider::sendDragEnd()
  38930. {
  38931. stoppedDragging();
  38932. sliderBeingDragged = -1;
  38933. Component::BailOutChecker checker (this);
  38934. listeners.callChecked (checker, &SliderListener::sliderDragEnded, this);
  38935. }
  38936. void Slider::addListener (SliderListener* const listener)
  38937. {
  38938. listeners.add (listener);
  38939. }
  38940. void Slider::removeListener (SliderListener* const listener)
  38941. {
  38942. listeners.remove (listener);
  38943. }
  38944. void Slider::setSliderStyle (const SliderStyle newStyle)
  38945. {
  38946. if (style != newStyle)
  38947. {
  38948. style = newStyle;
  38949. repaint();
  38950. lookAndFeelChanged();
  38951. }
  38952. }
  38953. void Slider::setRotaryParameters (const float startAngleRadians,
  38954. const float endAngleRadians,
  38955. const bool stopAtEnd)
  38956. {
  38957. // make sure the values are sensible..
  38958. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  38959. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  38960. jassert (rotaryStart < rotaryEnd);
  38961. rotaryStart = startAngleRadians;
  38962. rotaryEnd = endAngleRadians;
  38963. rotaryStop = stopAtEnd;
  38964. }
  38965. void Slider::setVelocityBasedMode (const bool velBased)
  38966. {
  38967. isVelocityBased = velBased;
  38968. }
  38969. void Slider::setVelocityModeParameters (const double sensitivity,
  38970. const int threshold,
  38971. const double offset,
  38972. const bool userCanPressKeyToSwapMode)
  38973. {
  38974. jassert (threshold >= 0);
  38975. jassert (sensitivity > 0);
  38976. jassert (offset >= 0);
  38977. velocityModeSensitivity = sensitivity;
  38978. velocityModeOffset = offset;
  38979. velocityModeThreshold = threshold;
  38980. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  38981. }
  38982. void Slider::setSkewFactor (const double factor)
  38983. {
  38984. skewFactor = factor;
  38985. }
  38986. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  38987. {
  38988. if (maximum > minimum)
  38989. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  38990. / (maximum - minimum));
  38991. }
  38992. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  38993. {
  38994. jassert (distanceForFullScaleDrag > 0);
  38995. pixelsForFullDragExtent = distanceForFullScaleDrag;
  38996. }
  38997. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  38998. {
  38999. if (incDecButtonMode != mode)
  39000. {
  39001. incDecButtonMode = mode;
  39002. lookAndFeelChanged();
  39003. }
  39004. }
  39005. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  39006. const bool isReadOnly,
  39007. const int textEntryBoxWidth,
  39008. const int textEntryBoxHeight)
  39009. {
  39010. textBoxPos = newPosition;
  39011. editableText = ! isReadOnly;
  39012. textBoxWidth = textEntryBoxWidth;
  39013. textBoxHeight = textEntryBoxHeight;
  39014. repaint();
  39015. lookAndFeelChanged();
  39016. }
  39017. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  39018. {
  39019. editableText = shouldBeEditable;
  39020. if (valueBox != 0)
  39021. valueBox->setEditable (shouldBeEditable && isEnabled());
  39022. }
  39023. void Slider::showTextBox()
  39024. {
  39025. jassert (editableText); // this should probably be avoided in read-only sliders.
  39026. if (valueBox != 0)
  39027. valueBox->showEditor();
  39028. }
  39029. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  39030. {
  39031. if (valueBox != 0)
  39032. {
  39033. valueBox->hideEditor (discardCurrentEditorContents);
  39034. if (discardCurrentEditorContents)
  39035. updateText();
  39036. }
  39037. }
  39038. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  39039. {
  39040. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  39041. }
  39042. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  39043. {
  39044. snapsToMousePos = shouldSnapToMouse;
  39045. }
  39046. void Slider::setPopupDisplayEnabled (const bool enabled,
  39047. Component* const parentComponentToUse)
  39048. {
  39049. popupDisplayEnabled = enabled;
  39050. parentForPopupDisplay = parentComponentToUse;
  39051. }
  39052. void Slider::colourChanged()
  39053. {
  39054. lookAndFeelChanged();
  39055. }
  39056. void Slider::lookAndFeelChanged()
  39057. {
  39058. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  39059. : getTextFromValue (currentValue.getValue()));
  39060. deleteAllChildren();
  39061. valueBox = 0;
  39062. LookAndFeel& lf = getLookAndFeel();
  39063. if (textBoxPos != NoTextBox)
  39064. {
  39065. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  39066. valueBox->setWantsKeyboardFocus (false);
  39067. valueBox->setText (previousTextBoxContent, false);
  39068. valueBox->setEditable (editableText && isEnabled());
  39069. valueBox->addListener (this);
  39070. if (style == LinearBar)
  39071. valueBox->addMouseListener (this, false);
  39072. valueBox->setTooltip (getTooltip());
  39073. }
  39074. if (style == IncDecButtons)
  39075. {
  39076. addAndMakeVisible (incButton = lf.createSliderButton (true));
  39077. incButton->addButtonListener (this);
  39078. addAndMakeVisible (decButton = lf.createSliderButton (false));
  39079. decButton->addButtonListener (this);
  39080. if (incDecButtonMode != incDecButtonsNotDraggable)
  39081. {
  39082. incButton->addMouseListener (this, false);
  39083. decButton->addMouseListener (this, false);
  39084. }
  39085. else
  39086. {
  39087. incButton->setRepeatSpeed (300, 100, 20);
  39088. incButton->addMouseListener (decButton, false);
  39089. decButton->setRepeatSpeed (300, 100, 20);
  39090. decButton->addMouseListener (incButton, false);
  39091. }
  39092. incButton->setTooltip (getTooltip());
  39093. decButton->setTooltip (getTooltip());
  39094. }
  39095. setComponentEffect (lf.getSliderEffect());
  39096. resized();
  39097. repaint();
  39098. }
  39099. void Slider::setRange (const double newMin,
  39100. const double newMax,
  39101. const double newInt)
  39102. {
  39103. if (minimum != newMin
  39104. || maximum != newMax
  39105. || interval != newInt)
  39106. {
  39107. minimum = newMin;
  39108. maximum = newMax;
  39109. interval = newInt;
  39110. // figure out the number of DPs needed to display all values at this
  39111. // interval setting.
  39112. numDecimalPlaces = 7;
  39113. if (newInt != 0)
  39114. {
  39115. int v = abs ((int) (newInt * 10000000));
  39116. while ((v % 10) == 0)
  39117. {
  39118. --numDecimalPlaces;
  39119. v /= 10;
  39120. }
  39121. }
  39122. // keep the current values inside the new range..
  39123. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39124. {
  39125. setValue (getValue(), false, false);
  39126. }
  39127. else
  39128. {
  39129. setMinValue (getMinValue(), false, false);
  39130. setMaxValue (getMaxValue(), false, false);
  39131. }
  39132. updateText();
  39133. }
  39134. }
  39135. void Slider::triggerChangeMessage (const bool synchronous)
  39136. {
  39137. if (synchronous)
  39138. handleAsyncUpdate();
  39139. else
  39140. triggerAsyncUpdate();
  39141. valueChanged();
  39142. }
  39143. void Slider::valueChanged (Value& value)
  39144. {
  39145. if (value.refersToSameSourceAs (currentValue))
  39146. {
  39147. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39148. setValue (currentValue.getValue(), false, false);
  39149. }
  39150. else if (value.refersToSameSourceAs (valueMin))
  39151. setMinValue (valueMin.getValue(), false, false, true);
  39152. else if (value.refersToSameSourceAs (valueMax))
  39153. setMaxValue (valueMax.getValue(), false, false, true);
  39154. }
  39155. double Slider::getValue() const
  39156. {
  39157. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  39158. // methods to get the two values.
  39159. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39160. return currentValue.getValue();
  39161. }
  39162. void Slider::setValue (double newValue,
  39163. const bool sendUpdateMessage,
  39164. const bool sendMessageSynchronously)
  39165. {
  39166. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  39167. // methods to set the two values.
  39168. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39169. newValue = constrainedValue (newValue);
  39170. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39171. {
  39172. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  39173. newValue = jlimit ((double) valueMin.getValue(),
  39174. (double) valueMax.getValue(),
  39175. newValue);
  39176. }
  39177. if (newValue != lastCurrentValue)
  39178. {
  39179. if (valueBox != 0)
  39180. valueBox->hideEditor (true);
  39181. lastCurrentValue = newValue;
  39182. currentValue = newValue;
  39183. updateText();
  39184. repaint();
  39185. if (popupDisplay != 0)
  39186. {
  39187. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39188. ->updatePosition (getTextFromValue (newValue));
  39189. popupDisplay->repaint();
  39190. }
  39191. if (sendUpdateMessage)
  39192. triggerChangeMessage (sendMessageSynchronously);
  39193. }
  39194. }
  39195. double Slider::getMinValue() const
  39196. {
  39197. // The minimum value only applies to sliders that are in two- or three-value mode.
  39198. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39199. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39200. return valueMin.getValue();
  39201. }
  39202. double Slider::getMaxValue() const
  39203. {
  39204. // The maximum value only applies to sliders that are in two- or three-value mode.
  39205. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39206. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39207. return valueMax.getValue();
  39208. }
  39209. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39210. {
  39211. // The minimum value only applies to sliders that are in two- or three-value mode.
  39212. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39213. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39214. newValue = constrainedValue (newValue);
  39215. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39216. {
  39217. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  39218. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39219. newValue = jmin ((double) valueMax.getValue(), newValue);
  39220. }
  39221. else
  39222. {
  39223. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  39224. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39225. newValue = jmin (lastCurrentValue, newValue);
  39226. }
  39227. if (lastValueMin != newValue)
  39228. {
  39229. lastValueMin = newValue;
  39230. valueMin = newValue;
  39231. repaint();
  39232. if (popupDisplay != 0)
  39233. {
  39234. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39235. ->updatePosition (getTextFromValue (newValue));
  39236. popupDisplay->repaint();
  39237. }
  39238. if (sendUpdateMessage)
  39239. triggerChangeMessage (sendMessageSynchronously);
  39240. }
  39241. }
  39242. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39243. {
  39244. // The maximum value only applies to sliders that are in two- or three-value mode.
  39245. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39246. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39247. newValue = constrainedValue (newValue);
  39248. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39249. {
  39250. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  39251. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39252. newValue = jmax ((double) valueMin.getValue(), newValue);
  39253. }
  39254. else
  39255. {
  39256. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  39257. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39258. newValue = jmax (lastCurrentValue, newValue);
  39259. }
  39260. if (lastValueMax != newValue)
  39261. {
  39262. lastValueMax = newValue;
  39263. valueMax = newValue;
  39264. repaint();
  39265. if (popupDisplay != 0)
  39266. {
  39267. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39268. ->updatePosition (getTextFromValue (valueMax.getValue()));
  39269. popupDisplay->repaint();
  39270. }
  39271. if (sendUpdateMessage)
  39272. triggerChangeMessage (sendMessageSynchronously);
  39273. }
  39274. }
  39275. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39276. const double valueToSetOnDoubleClick)
  39277. {
  39278. doubleClickToValue = isDoubleClickEnabled;
  39279. doubleClickReturnValue = valueToSetOnDoubleClick;
  39280. }
  39281. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39282. {
  39283. isEnabled_ = doubleClickToValue;
  39284. return doubleClickReturnValue;
  39285. }
  39286. void Slider::updateText()
  39287. {
  39288. if (valueBox != 0)
  39289. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39290. }
  39291. void Slider::setTextValueSuffix (const String& suffix)
  39292. {
  39293. if (textSuffix != suffix)
  39294. {
  39295. textSuffix = suffix;
  39296. updateText();
  39297. }
  39298. }
  39299. const String Slider::getTextFromValue (double v)
  39300. {
  39301. if (numDecimalPlaces > 0)
  39302. return String (v, numDecimalPlaces) + textSuffix;
  39303. else
  39304. return String (roundToInt (v)) + textSuffix;
  39305. }
  39306. double Slider::getValueFromText (const String& text)
  39307. {
  39308. String t (text.trimStart());
  39309. if (t.endsWith (textSuffix))
  39310. t = t.substring (0, t.length() - textSuffix.length());
  39311. while (t.startsWithChar (T('+')))
  39312. t = t.substring (1).trimStart();
  39313. return t.initialSectionContainingOnly (T("0123456789.,-"))
  39314. .getDoubleValue();
  39315. }
  39316. double Slider::proportionOfLengthToValue (double proportion)
  39317. {
  39318. if (skewFactor != 1.0 && proportion > 0.0)
  39319. proportion = exp (log (proportion) / skewFactor);
  39320. return minimum + (maximum - minimum) * proportion;
  39321. }
  39322. double Slider::valueToProportionOfLength (double value)
  39323. {
  39324. const double n = (value - minimum) / (maximum - minimum);
  39325. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39326. }
  39327. double Slider::snapValue (double attemptedValue, const bool)
  39328. {
  39329. return attemptedValue;
  39330. }
  39331. void Slider::startedDragging()
  39332. {
  39333. }
  39334. void Slider::stoppedDragging()
  39335. {
  39336. }
  39337. void Slider::valueChanged()
  39338. {
  39339. }
  39340. void Slider::enablementChanged()
  39341. {
  39342. repaint();
  39343. }
  39344. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39345. {
  39346. menuEnabled = menuEnabled_;
  39347. }
  39348. void Slider::setScrollWheelEnabled (const bool enabled)
  39349. {
  39350. scrollWheelEnabled = enabled;
  39351. }
  39352. void Slider::labelTextChanged (Label* label)
  39353. {
  39354. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39355. if (newValue != (double) currentValue.getValue())
  39356. {
  39357. sendDragStart();
  39358. setValue (newValue, true, true);
  39359. sendDragEnd();
  39360. }
  39361. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39362. }
  39363. void Slider::buttonClicked (Button* button)
  39364. {
  39365. if (style == IncDecButtons)
  39366. {
  39367. sendDragStart();
  39368. if (button == incButton)
  39369. setValue (snapValue (getValue() + interval, false), true, true);
  39370. else if (button == decButton)
  39371. setValue (snapValue (getValue() - interval, false), true, true);
  39372. sendDragEnd();
  39373. }
  39374. }
  39375. double Slider::constrainedValue (double value) const
  39376. {
  39377. if (interval > 0)
  39378. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39379. if (value <= minimum || maximum <= minimum)
  39380. value = minimum;
  39381. else if (value >= maximum)
  39382. value = maximum;
  39383. return value;
  39384. }
  39385. float Slider::getLinearSliderPos (const double value)
  39386. {
  39387. double sliderPosProportional;
  39388. if (maximum > minimum)
  39389. {
  39390. if (value < minimum)
  39391. {
  39392. sliderPosProportional = 0.0;
  39393. }
  39394. else if (value > maximum)
  39395. {
  39396. sliderPosProportional = 1.0;
  39397. }
  39398. else
  39399. {
  39400. sliderPosProportional = valueToProportionOfLength (value);
  39401. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39402. }
  39403. }
  39404. else
  39405. {
  39406. sliderPosProportional = 0.5;
  39407. }
  39408. if (isVertical() || style == IncDecButtons)
  39409. sliderPosProportional = 1.0 - sliderPosProportional;
  39410. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39411. }
  39412. bool Slider::isHorizontal() const
  39413. {
  39414. return style == LinearHorizontal
  39415. || style == LinearBar
  39416. || style == TwoValueHorizontal
  39417. || style == ThreeValueHorizontal;
  39418. }
  39419. bool Slider::isVertical() const
  39420. {
  39421. return style == LinearVertical
  39422. || style == TwoValueVertical
  39423. || style == ThreeValueVertical;
  39424. }
  39425. bool Slider::incDecDragDirectionIsHorizontal() const
  39426. {
  39427. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39428. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39429. }
  39430. float Slider::getPositionOfValue (const double value)
  39431. {
  39432. if (isHorizontal() || isVertical())
  39433. {
  39434. return getLinearSliderPos (value);
  39435. }
  39436. else
  39437. {
  39438. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39439. return 0.0f;
  39440. }
  39441. }
  39442. void Slider::paint (Graphics& g)
  39443. {
  39444. if (style != IncDecButtons)
  39445. {
  39446. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39447. {
  39448. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39449. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39450. getLookAndFeel().drawRotarySlider (g,
  39451. sliderRect.getX(),
  39452. sliderRect.getY(),
  39453. sliderRect.getWidth(),
  39454. sliderRect.getHeight(),
  39455. sliderPos,
  39456. rotaryStart, rotaryEnd,
  39457. *this);
  39458. }
  39459. else
  39460. {
  39461. getLookAndFeel().drawLinearSlider (g,
  39462. sliderRect.getX(),
  39463. sliderRect.getY(),
  39464. sliderRect.getWidth(),
  39465. sliderRect.getHeight(),
  39466. getLinearSliderPos (lastCurrentValue),
  39467. getLinearSliderPos (lastValueMin),
  39468. getLinearSliderPos (lastValueMax),
  39469. style,
  39470. *this);
  39471. }
  39472. if (style == LinearBar && valueBox == 0)
  39473. {
  39474. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39475. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39476. }
  39477. }
  39478. }
  39479. void Slider::resized()
  39480. {
  39481. int minXSpace = 0;
  39482. int minYSpace = 0;
  39483. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39484. minXSpace = 30;
  39485. else
  39486. minYSpace = 15;
  39487. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39488. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39489. if (style == LinearBar)
  39490. {
  39491. if (valueBox != 0)
  39492. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39493. }
  39494. else
  39495. {
  39496. if (textBoxPos == NoTextBox)
  39497. {
  39498. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39499. }
  39500. else if (textBoxPos == TextBoxLeft)
  39501. {
  39502. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39503. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39504. }
  39505. else if (textBoxPos == TextBoxRight)
  39506. {
  39507. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39508. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39509. }
  39510. else if (textBoxPos == TextBoxAbove)
  39511. {
  39512. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39513. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39514. }
  39515. else if (textBoxPos == TextBoxBelow)
  39516. {
  39517. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39518. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39519. }
  39520. }
  39521. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39522. if (style == LinearBar)
  39523. {
  39524. const int barIndent = 1;
  39525. sliderRegionStart = barIndent;
  39526. sliderRegionSize = getWidth() - barIndent * 2;
  39527. sliderRect.setBounds (sliderRegionStart, barIndent,
  39528. sliderRegionSize, getHeight() - barIndent * 2);
  39529. }
  39530. else if (isHorizontal())
  39531. {
  39532. sliderRegionStart = sliderRect.getX() + indent;
  39533. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39534. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39535. sliderRegionSize, sliderRect.getHeight());
  39536. }
  39537. else if (isVertical())
  39538. {
  39539. sliderRegionStart = sliderRect.getY() + indent;
  39540. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39541. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39542. sliderRect.getWidth(), sliderRegionSize);
  39543. }
  39544. else
  39545. {
  39546. sliderRegionStart = 0;
  39547. sliderRegionSize = 100;
  39548. }
  39549. if (style == IncDecButtons)
  39550. {
  39551. Rectangle<int> buttonRect (sliderRect);
  39552. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39553. buttonRect.expand (-2, 0);
  39554. else
  39555. buttonRect.expand (0, -2);
  39556. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39557. if (incDecButtonsSideBySide)
  39558. {
  39559. decButton->setBounds (buttonRect.getX(),
  39560. buttonRect.getY(),
  39561. buttonRect.getWidth() / 2,
  39562. buttonRect.getHeight());
  39563. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39564. incButton->setBounds (buttonRect.getCentreX(),
  39565. buttonRect.getY(),
  39566. buttonRect.getWidth() / 2,
  39567. buttonRect.getHeight());
  39568. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39569. }
  39570. else
  39571. {
  39572. incButton->setBounds (buttonRect.getX(),
  39573. buttonRect.getY(),
  39574. buttonRect.getWidth(),
  39575. buttonRect.getHeight() / 2);
  39576. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39577. decButton->setBounds (buttonRect.getX(),
  39578. buttonRect.getCentreY(),
  39579. buttonRect.getWidth(),
  39580. buttonRect.getHeight() / 2);
  39581. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39582. }
  39583. }
  39584. }
  39585. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39586. {
  39587. repaint();
  39588. }
  39589. void Slider::mouseDown (const MouseEvent& e)
  39590. {
  39591. mouseWasHidden = false;
  39592. incDecDragged = false;
  39593. mouseXWhenLastDragged = e.x;
  39594. mouseYWhenLastDragged = e.y;
  39595. mouseDragStartX = e.getMouseDownX();
  39596. mouseDragStartY = e.getMouseDownY();
  39597. if (isEnabled())
  39598. {
  39599. if (e.mods.isPopupMenu() && menuEnabled)
  39600. {
  39601. menuShown = true;
  39602. PopupMenu m;
  39603. m.setLookAndFeel (&getLookAndFeel());
  39604. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39605. m.addSeparator();
  39606. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39607. {
  39608. PopupMenu rotaryMenu;
  39609. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39610. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39611. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39612. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39613. }
  39614. const int r = m.show();
  39615. if (r == 1)
  39616. {
  39617. setVelocityBasedMode (! isVelocityBased);
  39618. }
  39619. else if (r == 2)
  39620. {
  39621. setSliderStyle (Rotary);
  39622. }
  39623. else if (r == 3)
  39624. {
  39625. setSliderStyle (RotaryHorizontalDrag);
  39626. }
  39627. else if (r == 4)
  39628. {
  39629. setSliderStyle (RotaryVerticalDrag);
  39630. }
  39631. }
  39632. else if (maximum > minimum)
  39633. {
  39634. menuShown = false;
  39635. if (valueBox != 0)
  39636. valueBox->hideEditor (true);
  39637. sliderBeingDragged = 0;
  39638. if (style == TwoValueHorizontal
  39639. || style == TwoValueVertical
  39640. || style == ThreeValueHorizontal
  39641. || style == ThreeValueVertical)
  39642. {
  39643. const float mousePos = (float) (isVertical() ? e.y : e.x);
  39644. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  39645. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  39646. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  39647. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39648. {
  39649. if (maxPosDistance <= minPosDistance)
  39650. sliderBeingDragged = 2;
  39651. else
  39652. sliderBeingDragged = 1;
  39653. }
  39654. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39655. {
  39656. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  39657. sliderBeingDragged = 1;
  39658. else if (normalPosDistance >= maxPosDistance)
  39659. sliderBeingDragged = 2;
  39660. }
  39661. }
  39662. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39663. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  39664. * valueToProportionOfLength (currentValue.getValue());
  39665. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  39666. : ((sliderBeingDragged == 1) ? valueMin
  39667. : currentValue)).getValue();
  39668. valueOnMouseDown = valueWhenLastDragged;
  39669. if (popupDisplayEnabled)
  39670. {
  39671. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  39672. popupDisplay = popup;
  39673. if (parentForPopupDisplay != 0)
  39674. {
  39675. parentForPopupDisplay->addChildComponent (popup);
  39676. }
  39677. else
  39678. {
  39679. popup->addToDesktop (0);
  39680. }
  39681. popup->setVisible (true);
  39682. }
  39683. sendDragStart();
  39684. mouseDrag (e);
  39685. }
  39686. }
  39687. }
  39688. void Slider::mouseUp (const MouseEvent&)
  39689. {
  39690. if (isEnabled()
  39691. && (! menuShown)
  39692. && (maximum > minimum)
  39693. && (style != IncDecButtons || incDecDragged))
  39694. {
  39695. restoreMouseIfHidden();
  39696. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  39697. triggerChangeMessage (false);
  39698. sendDragEnd();
  39699. popupDisplay = 0;
  39700. if (style == IncDecButtons)
  39701. {
  39702. incButton->setState (Button::buttonNormal);
  39703. decButton->setState (Button::buttonNormal);
  39704. }
  39705. }
  39706. }
  39707. void Slider::restoreMouseIfHidden()
  39708. {
  39709. if (mouseWasHidden)
  39710. {
  39711. mouseWasHidden = false;
  39712. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  39713. Desktop::getInstance().getMouseSource(i)->enableUnboundedMouseMovement (false);
  39714. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  39715. : ((sliderBeingDragged == 1) ? getMinValue()
  39716. : (double) currentValue.getValue());
  39717. Point<int> mousePos;
  39718. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39719. {
  39720. mousePos = Desktop::getLastMouseDownPosition();
  39721. if (style == RotaryHorizontalDrag)
  39722. {
  39723. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  39724. mousePos += Point<int> (roundToInt (pixelsForFullDragExtent * posDiff), 0);
  39725. }
  39726. else
  39727. {
  39728. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  39729. mousePos += Point<int> (0, roundToInt (pixelsForFullDragExtent * posDiff));
  39730. }
  39731. }
  39732. else
  39733. {
  39734. const int pixelPos = (int) getLinearSliderPos (pos);
  39735. mousePos = relativePositionToGlobal (Point<int> (isHorizontal() ? pixelPos : (getWidth() / 2),
  39736. isVertical() ? pixelPos : (getHeight() / 2)));
  39737. }
  39738. Desktop::setMousePosition (mousePos);
  39739. }
  39740. }
  39741. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  39742. {
  39743. if (isEnabled()
  39744. && style != IncDecButtons
  39745. && style != Rotary
  39746. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  39747. {
  39748. restoreMouseIfHidden();
  39749. }
  39750. }
  39751. static double smallestAngleBetween (double a1, double a2)
  39752. {
  39753. return jmin (fabs (a1 - a2),
  39754. fabs (a1 + double_Pi * 2.0 - a2),
  39755. fabs (a2 + double_Pi * 2.0 - a1));
  39756. }
  39757. void Slider::mouseDrag (const MouseEvent& e)
  39758. {
  39759. if (isEnabled()
  39760. && (! menuShown)
  39761. && (maximum > minimum))
  39762. {
  39763. if (style == Rotary)
  39764. {
  39765. int dx = e.x - sliderRect.getCentreX();
  39766. int dy = e.y - sliderRect.getCentreY();
  39767. if (dx * dx + dy * dy > 25)
  39768. {
  39769. double angle = atan2 ((double) dx, (double) -dy);
  39770. while (angle < 0.0)
  39771. angle += double_Pi * 2.0;
  39772. if (rotaryStop && ! e.mouseWasClicked())
  39773. {
  39774. if (fabs (angle - lastAngle) > double_Pi)
  39775. {
  39776. if (angle >= lastAngle)
  39777. angle -= double_Pi * 2.0;
  39778. else
  39779. angle += double_Pi * 2.0;
  39780. }
  39781. if (angle >= lastAngle)
  39782. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  39783. else
  39784. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  39785. }
  39786. else
  39787. {
  39788. while (angle < rotaryStart)
  39789. angle += double_Pi * 2.0;
  39790. if (angle > rotaryEnd)
  39791. {
  39792. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  39793. angle = rotaryStart;
  39794. else
  39795. angle = rotaryEnd;
  39796. }
  39797. }
  39798. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  39799. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  39800. lastAngle = angle;
  39801. }
  39802. }
  39803. else
  39804. {
  39805. if (style == LinearBar && e.mouseWasClicked()
  39806. && valueBox != 0 && valueBox->isEditable())
  39807. return;
  39808. if (style == IncDecButtons && ! incDecDragged)
  39809. {
  39810. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  39811. return;
  39812. incDecDragged = true;
  39813. mouseDragStartX = e.x;
  39814. mouseDragStartY = e.y;
  39815. }
  39816. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  39817. : false))
  39818. || ((maximum - minimum) / sliderRegionSize < interval))
  39819. {
  39820. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  39821. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  39822. if (style == RotaryHorizontalDrag
  39823. || style == RotaryVerticalDrag
  39824. || style == IncDecButtons
  39825. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  39826. && ! snapsToMousePos))
  39827. {
  39828. const int mouseDiff = (style == RotaryHorizontalDrag
  39829. || style == LinearHorizontal
  39830. || style == LinearBar
  39831. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39832. ? e.x - mouseDragStartX
  39833. : mouseDragStartY - e.y;
  39834. double newPos = valueToProportionOfLength (valueOnMouseDown)
  39835. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  39836. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  39837. if (style == IncDecButtons)
  39838. {
  39839. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  39840. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  39841. }
  39842. }
  39843. else
  39844. {
  39845. if (isVertical())
  39846. scaledMousePos = 1.0 - scaledMousePos;
  39847. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  39848. }
  39849. }
  39850. else
  39851. {
  39852. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  39853. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39854. ? e.x - mouseXWhenLastDragged
  39855. : e.y - mouseYWhenLastDragged;
  39856. const double maxSpeed = jmax (200, sliderRegionSize);
  39857. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  39858. if (speed != 0)
  39859. {
  39860. speed = 0.2 * velocityModeSensitivity
  39861. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  39862. + jmax (0.0, (double) (speed - velocityModeThreshold))
  39863. / maxSpeed))));
  39864. if (mouseDiff < 0)
  39865. speed = -speed;
  39866. if (isVertical() || style == RotaryVerticalDrag
  39867. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  39868. speed = -speed;
  39869. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  39870. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  39871. e.source.enableUnboundedMouseMovement (true, false);
  39872. mouseWasHidden = true;
  39873. }
  39874. }
  39875. }
  39876. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  39877. if (sliderBeingDragged == 0)
  39878. {
  39879. setValue (snapValue (valueWhenLastDragged, true),
  39880. ! sendChangeOnlyOnRelease, true);
  39881. }
  39882. else if (sliderBeingDragged == 1)
  39883. {
  39884. setMinValue (snapValue (valueWhenLastDragged, true),
  39885. ! sendChangeOnlyOnRelease, false, true);
  39886. if (e.mods.isShiftDown())
  39887. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  39888. else
  39889. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39890. }
  39891. else
  39892. {
  39893. jassert (sliderBeingDragged == 2);
  39894. setMaxValue (snapValue (valueWhenLastDragged, true),
  39895. ! sendChangeOnlyOnRelease, false, true);
  39896. if (e.mods.isShiftDown())
  39897. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  39898. else
  39899. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39900. }
  39901. mouseXWhenLastDragged = e.x;
  39902. mouseYWhenLastDragged = e.y;
  39903. }
  39904. }
  39905. void Slider::mouseDoubleClick (const MouseEvent&)
  39906. {
  39907. if (doubleClickToValue
  39908. && isEnabled()
  39909. && style != IncDecButtons
  39910. && minimum <= doubleClickReturnValue
  39911. && maximum >= doubleClickReturnValue)
  39912. {
  39913. sendDragStart();
  39914. setValue (doubleClickReturnValue, true, true);
  39915. sendDragEnd();
  39916. }
  39917. }
  39918. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  39919. {
  39920. if (scrollWheelEnabled && isEnabled()
  39921. && style != TwoValueHorizontal
  39922. && style != TwoValueVertical)
  39923. {
  39924. if (maximum > minimum && ! e.mods.isAnyMouseButtonDown())
  39925. {
  39926. if (valueBox != 0)
  39927. valueBox->hideEditor (false);
  39928. const double value = (double) currentValue.getValue();
  39929. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  39930. const double currentPos = valueToProportionOfLength (value);
  39931. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  39932. double delta = (newValue != value)
  39933. ? jmax (fabs (newValue - value), interval) : 0;
  39934. if (value > newValue)
  39935. delta = -delta;
  39936. sendDragStart();
  39937. setValue (snapValue (value + delta, false), true, true);
  39938. sendDragEnd();
  39939. }
  39940. }
  39941. else
  39942. {
  39943. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  39944. }
  39945. }
  39946. void SliderListener::sliderDragStarted (Slider*)
  39947. {
  39948. }
  39949. void SliderListener::sliderDragEnded (Slider*)
  39950. {
  39951. }
  39952. END_JUCE_NAMESPACE
  39953. /*** End of inlined file: juce_Slider.cpp ***/
  39954. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  39955. BEGIN_JUCE_NAMESPACE
  39956. class DragOverlayComp : public Component
  39957. {
  39958. public:
  39959. DragOverlayComp (Image* const image_)
  39960. : image (image_)
  39961. {
  39962. image->multiplyAllAlphas (0.8f);
  39963. setAlwaysOnTop (true);
  39964. }
  39965. ~DragOverlayComp()
  39966. {
  39967. }
  39968. void paint (Graphics& g)
  39969. {
  39970. g.drawImageAt (image, 0, 0);
  39971. }
  39972. private:
  39973. ScopedPointer <Image> image;
  39974. DragOverlayComp (const DragOverlayComp&);
  39975. DragOverlayComp& operator= (const DragOverlayComp&);
  39976. };
  39977. TableHeaderComponent::TableHeaderComponent()
  39978. : columnsChanged (false),
  39979. columnsResized (false),
  39980. sortChanged (false),
  39981. menuActive (true),
  39982. stretchToFit (false),
  39983. columnIdBeingResized (0),
  39984. columnIdBeingDragged (0),
  39985. columnIdUnderMouse (0),
  39986. lastDeliberateWidth (0)
  39987. {
  39988. }
  39989. TableHeaderComponent::~TableHeaderComponent()
  39990. {
  39991. dragOverlayComp = 0;
  39992. }
  39993. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  39994. {
  39995. menuActive = hasMenu;
  39996. }
  39997. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  39998. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  39999. {
  40000. if (onlyCountVisibleColumns)
  40001. {
  40002. int num = 0;
  40003. for (int i = columns.size(); --i >= 0;)
  40004. if (columns.getUnchecked(i)->isVisible())
  40005. ++num;
  40006. return num;
  40007. }
  40008. else
  40009. {
  40010. return columns.size();
  40011. }
  40012. }
  40013. const String TableHeaderComponent::getColumnName (const int columnId) const
  40014. {
  40015. const ColumnInfo* const ci = getInfoForId (columnId);
  40016. return ci != 0 ? ci->name : String::empty;
  40017. }
  40018. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  40019. {
  40020. ColumnInfo* const ci = getInfoForId (columnId);
  40021. if (ci != 0 && ci->name != newName)
  40022. {
  40023. ci->name = newName;
  40024. sendColumnsChanged();
  40025. }
  40026. }
  40027. void TableHeaderComponent::addColumn (const String& columnName,
  40028. const int columnId,
  40029. const int width,
  40030. const int minimumWidth,
  40031. const int maximumWidth,
  40032. const int propertyFlags,
  40033. const int insertIndex)
  40034. {
  40035. // can't have a duplicate or null ID!
  40036. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  40037. jassert (width > 0);
  40038. ColumnInfo* const ci = new ColumnInfo();
  40039. ci->name = columnName;
  40040. ci->id = columnId;
  40041. ci->width = width;
  40042. ci->lastDeliberateWidth = width;
  40043. ci->minimumWidth = minimumWidth;
  40044. ci->maximumWidth = maximumWidth;
  40045. if (ci->maximumWidth < 0)
  40046. ci->maximumWidth = std::numeric_limits<int>::max();
  40047. jassert (ci->maximumWidth >= ci->minimumWidth);
  40048. ci->propertyFlags = propertyFlags;
  40049. columns.insert (insertIndex, ci);
  40050. sendColumnsChanged();
  40051. }
  40052. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  40053. {
  40054. const int index = getIndexOfColumnId (columnIdToRemove, false);
  40055. if (index >= 0)
  40056. {
  40057. columns.remove (index);
  40058. sortChanged = true;
  40059. sendColumnsChanged();
  40060. }
  40061. }
  40062. void TableHeaderComponent::removeAllColumns()
  40063. {
  40064. if (columns.size() > 0)
  40065. {
  40066. columns.clear();
  40067. sendColumnsChanged();
  40068. }
  40069. }
  40070. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  40071. {
  40072. const int currentIndex = getIndexOfColumnId (columnId, false);
  40073. newIndex = visibleIndexToTotalIndex (newIndex);
  40074. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  40075. {
  40076. columns.move (currentIndex, newIndex);
  40077. sendColumnsChanged();
  40078. }
  40079. }
  40080. int TableHeaderComponent::getColumnWidth (const int columnId) const
  40081. {
  40082. const ColumnInfo* const ci = getInfoForId (columnId);
  40083. return ci != 0 ? ci->width : 0;
  40084. }
  40085. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  40086. {
  40087. ColumnInfo* const ci = getInfoForId (columnId);
  40088. if (ci != 0 && ci->width != newWidth)
  40089. {
  40090. const int numColumns = getNumColumns (true);
  40091. ci->lastDeliberateWidth = ci->width
  40092. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  40093. if (stretchToFit)
  40094. {
  40095. const int index = getIndexOfColumnId (columnId, true) + 1;
  40096. if (((unsigned int) index) < (unsigned int) numColumns)
  40097. {
  40098. const int x = getColumnPosition (index).getX();
  40099. if (lastDeliberateWidth == 0)
  40100. lastDeliberateWidth = getTotalWidth();
  40101. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  40102. }
  40103. }
  40104. repaint();
  40105. columnsResized = true;
  40106. triggerAsyncUpdate();
  40107. }
  40108. }
  40109. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  40110. {
  40111. int n = 0;
  40112. for (int i = 0; i < columns.size(); ++i)
  40113. {
  40114. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  40115. {
  40116. if (columns.getUnchecked(i)->id == columnId)
  40117. return n;
  40118. ++n;
  40119. }
  40120. }
  40121. return -1;
  40122. }
  40123. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  40124. {
  40125. if (onlyCountVisibleColumns)
  40126. index = visibleIndexToTotalIndex (index);
  40127. const ColumnInfo* const ci = columns [index];
  40128. return (ci != 0) ? ci->id : 0;
  40129. }
  40130. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  40131. {
  40132. int x = 0, width = 0, n = 0;
  40133. for (int i = 0; i < columns.size(); ++i)
  40134. {
  40135. x += width;
  40136. if (columns.getUnchecked(i)->isVisible())
  40137. {
  40138. width = columns.getUnchecked(i)->width;
  40139. if (n++ == index)
  40140. break;
  40141. }
  40142. else
  40143. {
  40144. width = 0;
  40145. }
  40146. }
  40147. return Rectangle<int> (x, 0, width, getHeight());
  40148. }
  40149. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  40150. {
  40151. if (xToFind >= 0)
  40152. {
  40153. int x = 0;
  40154. for (int i = 0; i < columns.size(); ++i)
  40155. {
  40156. const ColumnInfo* const ci = columns.getUnchecked(i);
  40157. if (ci->isVisible())
  40158. {
  40159. x += ci->width;
  40160. if (xToFind < x)
  40161. return ci->id;
  40162. }
  40163. }
  40164. }
  40165. return 0;
  40166. }
  40167. int TableHeaderComponent::getTotalWidth() const
  40168. {
  40169. int w = 0;
  40170. for (int i = columns.size(); --i >= 0;)
  40171. if (columns.getUnchecked(i)->isVisible())
  40172. w += columns.getUnchecked(i)->width;
  40173. return w;
  40174. }
  40175. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  40176. {
  40177. stretchToFit = shouldStretchToFit;
  40178. lastDeliberateWidth = getTotalWidth();
  40179. resized();
  40180. }
  40181. bool TableHeaderComponent::isStretchToFitActive() const
  40182. {
  40183. return stretchToFit;
  40184. }
  40185. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  40186. {
  40187. if (stretchToFit && getWidth() > 0
  40188. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  40189. {
  40190. lastDeliberateWidth = targetTotalWidth;
  40191. resizeColumnsToFit (0, targetTotalWidth);
  40192. }
  40193. }
  40194. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  40195. {
  40196. targetTotalWidth = jmax (targetTotalWidth, 0);
  40197. StretchableObjectResizer sor;
  40198. int i;
  40199. for (i = firstColumnIndex; i < columns.size(); ++i)
  40200. {
  40201. ColumnInfo* const ci = columns.getUnchecked(i);
  40202. if (ci->isVisible())
  40203. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  40204. }
  40205. sor.resizeToFit (targetTotalWidth);
  40206. int visIndex = 0;
  40207. for (i = firstColumnIndex; i < columns.size(); ++i)
  40208. {
  40209. ColumnInfo* const ci = columns.getUnchecked(i);
  40210. if (ci->isVisible())
  40211. {
  40212. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  40213. (int) floor (sor.getItemSize (visIndex++)));
  40214. if (newWidth != ci->width)
  40215. {
  40216. ci->width = newWidth;
  40217. repaint();
  40218. columnsResized = true;
  40219. triggerAsyncUpdate();
  40220. }
  40221. }
  40222. }
  40223. }
  40224. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  40225. {
  40226. ColumnInfo* const ci = getInfoForId (columnId);
  40227. if (ci != 0 && shouldBeVisible != ci->isVisible())
  40228. {
  40229. if (shouldBeVisible)
  40230. ci->propertyFlags |= visible;
  40231. else
  40232. ci->propertyFlags &= ~visible;
  40233. sendColumnsChanged();
  40234. resized();
  40235. }
  40236. }
  40237. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  40238. {
  40239. const ColumnInfo* const ci = getInfoForId (columnId);
  40240. return ci != 0 && ci->isVisible();
  40241. }
  40242. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  40243. {
  40244. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  40245. {
  40246. for (int i = columns.size(); --i >= 0;)
  40247. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  40248. ColumnInfo* const ci = getInfoForId (columnId);
  40249. if (ci != 0)
  40250. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  40251. reSortTable();
  40252. }
  40253. }
  40254. int TableHeaderComponent::getSortColumnId() const
  40255. {
  40256. for (int i = columns.size(); --i >= 0;)
  40257. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40258. return columns.getUnchecked(i)->id;
  40259. return 0;
  40260. }
  40261. bool TableHeaderComponent::isSortedForwards() const
  40262. {
  40263. for (int i = columns.size(); --i >= 0;)
  40264. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40265. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40266. return true;
  40267. }
  40268. void TableHeaderComponent::reSortTable()
  40269. {
  40270. sortChanged = true;
  40271. repaint();
  40272. triggerAsyncUpdate();
  40273. }
  40274. const String TableHeaderComponent::toString() const
  40275. {
  40276. String s;
  40277. XmlElement doc ("TABLELAYOUT");
  40278. doc.setAttribute ("sortedCol", getSortColumnId());
  40279. doc.setAttribute ("sortForwards", isSortedForwards());
  40280. for (int i = 0; i < columns.size(); ++i)
  40281. {
  40282. const ColumnInfo* const ci = columns.getUnchecked (i);
  40283. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  40284. e->setAttribute ("id", ci->id);
  40285. e->setAttribute ("visible", ci->isVisible());
  40286. e->setAttribute ("width", ci->width);
  40287. }
  40288. return doc.createDocument (String::empty, true, false);
  40289. }
  40290. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40291. {
  40292. XmlDocument doc (storedVersion);
  40293. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40294. int index = 0;
  40295. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  40296. {
  40297. forEachXmlChildElement (*storedXml, col)
  40298. {
  40299. const int tabId = col->getIntAttribute ("id");
  40300. ColumnInfo* const ci = getInfoForId (tabId);
  40301. if (ci != 0)
  40302. {
  40303. columns.move (columns.indexOf (ci), index);
  40304. ci->width = col->getIntAttribute ("width");
  40305. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  40306. }
  40307. ++index;
  40308. }
  40309. columnsResized = true;
  40310. sendColumnsChanged();
  40311. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  40312. storedXml->getBoolAttribute ("sortForwards", true));
  40313. }
  40314. }
  40315. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40316. {
  40317. listeners.addIfNotAlreadyThere (newListener);
  40318. }
  40319. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40320. {
  40321. listeners.removeValue (listenerToRemove);
  40322. }
  40323. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40324. {
  40325. const ColumnInfo* const ci = getInfoForId (columnId);
  40326. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40327. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40328. }
  40329. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40330. {
  40331. for (int i = 0; i < columns.size(); ++i)
  40332. {
  40333. const ColumnInfo* const ci = columns.getUnchecked(i);
  40334. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40335. menu.addItem (ci->id, ci->name,
  40336. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40337. isColumnVisible (ci->id));
  40338. }
  40339. }
  40340. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40341. {
  40342. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40343. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40344. }
  40345. void TableHeaderComponent::paint (Graphics& g)
  40346. {
  40347. LookAndFeel& lf = getLookAndFeel();
  40348. lf.drawTableHeaderBackground (g, *this);
  40349. const Rectangle<int> clip (g.getClipBounds());
  40350. int x = 0;
  40351. for (int i = 0; i < columns.size(); ++i)
  40352. {
  40353. const ColumnInfo* const ci = columns.getUnchecked(i);
  40354. if (ci->isVisible())
  40355. {
  40356. if (x + ci->width > clip.getX()
  40357. && (ci->id != columnIdBeingDragged
  40358. || dragOverlayComp == 0
  40359. || ! dragOverlayComp->isVisible()))
  40360. {
  40361. g.saveState();
  40362. g.setOrigin (x, 0);
  40363. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40364. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40365. ci->id == columnIdUnderMouse,
  40366. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40367. ci->propertyFlags);
  40368. g.restoreState();
  40369. }
  40370. x += ci->width;
  40371. if (x >= clip.getRight())
  40372. break;
  40373. }
  40374. }
  40375. }
  40376. void TableHeaderComponent::resized()
  40377. {
  40378. }
  40379. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40380. {
  40381. updateColumnUnderMouse (e.x, e.y);
  40382. }
  40383. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40384. {
  40385. updateColumnUnderMouse (e.x, e.y);
  40386. }
  40387. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40388. {
  40389. updateColumnUnderMouse (e.x, e.y);
  40390. }
  40391. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40392. {
  40393. repaint();
  40394. columnIdBeingResized = 0;
  40395. columnIdBeingDragged = 0;
  40396. if (columnIdUnderMouse != 0)
  40397. {
  40398. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40399. if (e.mods.isPopupMenu())
  40400. columnClicked (columnIdUnderMouse, e.mods);
  40401. }
  40402. if (menuActive && e.mods.isPopupMenu())
  40403. showColumnChooserMenu (columnIdUnderMouse);
  40404. }
  40405. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40406. {
  40407. if (columnIdBeingResized == 0
  40408. && columnIdBeingDragged == 0
  40409. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40410. {
  40411. dragOverlayComp = 0;
  40412. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40413. if (columnIdBeingResized != 0)
  40414. {
  40415. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40416. initialColumnWidth = ci->width;
  40417. }
  40418. else
  40419. {
  40420. beginDrag (e);
  40421. }
  40422. }
  40423. if (columnIdBeingResized != 0)
  40424. {
  40425. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40426. if (ci != 0)
  40427. {
  40428. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40429. initialColumnWidth + e.getDistanceFromDragStartX());
  40430. if (stretchToFit)
  40431. {
  40432. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40433. int minWidthOnRight = 0;
  40434. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40435. if (columns.getUnchecked (i)->isVisible())
  40436. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40437. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40438. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40439. }
  40440. setColumnWidth (columnIdBeingResized, w);
  40441. }
  40442. }
  40443. else if (columnIdBeingDragged != 0)
  40444. {
  40445. if (e.y >= -50 && e.y < getHeight() + 50)
  40446. {
  40447. if (dragOverlayComp != 0)
  40448. {
  40449. dragOverlayComp->setVisible (true);
  40450. dragOverlayComp->setBounds (jlimit (0,
  40451. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40452. e.x - draggingColumnOffset),
  40453. 0,
  40454. dragOverlayComp->getWidth(),
  40455. getHeight());
  40456. for (int i = columns.size(); --i >= 0;)
  40457. {
  40458. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40459. int newIndex = currentIndex;
  40460. if (newIndex > 0)
  40461. {
  40462. // if the previous column isn't draggable, we can't move our column
  40463. // past it, because that'd change the undraggable column's position..
  40464. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40465. if ((previous->propertyFlags & draggable) != 0)
  40466. {
  40467. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40468. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40469. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40470. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40471. {
  40472. --newIndex;
  40473. }
  40474. }
  40475. }
  40476. if (newIndex < columns.size() - 1)
  40477. {
  40478. // if the next column isn't draggable, we can't move our column
  40479. // past it, because that'd change the undraggable column's position..
  40480. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40481. if ((nextCol->propertyFlags & draggable) != 0)
  40482. {
  40483. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40484. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40485. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40486. > abs (dragOverlayComp->getRight() - rightOfNext))
  40487. {
  40488. ++newIndex;
  40489. }
  40490. }
  40491. }
  40492. if (newIndex != currentIndex)
  40493. moveColumn (columnIdBeingDragged, newIndex);
  40494. else
  40495. break;
  40496. }
  40497. }
  40498. }
  40499. else
  40500. {
  40501. endDrag (draggingColumnOriginalIndex);
  40502. }
  40503. }
  40504. }
  40505. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40506. {
  40507. if (columnIdBeingDragged == 0)
  40508. {
  40509. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40510. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40511. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40512. {
  40513. columnIdBeingDragged = 0;
  40514. }
  40515. else
  40516. {
  40517. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40518. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40519. const int temp = columnIdBeingDragged;
  40520. columnIdBeingDragged = 0;
  40521. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40522. columnIdBeingDragged = temp;
  40523. dragOverlayComp->setBounds (columnRect);
  40524. for (int i = listeners.size(); --i >= 0;)
  40525. {
  40526. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40527. i = jmin (i, listeners.size() - 1);
  40528. }
  40529. }
  40530. }
  40531. }
  40532. void TableHeaderComponent::endDrag (const int finalIndex)
  40533. {
  40534. if (columnIdBeingDragged != 0)
  40535. {
  40536. moveColumn (columnIdBeingDragged, finalIndex);
  40537. columnIdBeingDragged = 0;
  40538. repaint();
  40539. for (int i = listeners.size(); --i >= 0;)
  40540. {
  40541. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40542. i = jmin (i, listeners.size() - 1);
  40543. }
  40544. }
  40545. }
  40546. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40547. {
  40548. mouseDrag (e);
  40549. for (int i = columns.size(); --i >= 0;)
  40550. if (columns.getUnchecked (i)->isVisible())
  40551. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40552. columnIdBeingResized = 0;
  40553. repaint();
  40554. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40555. updateColumnUnderMouse (e.x, e.y);
  40556. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40557. columnClicked (columnIdUnderMouse, e.mods);
  40558. dragOverlayComp = 0;
  40559. }
  40560. const MouseCursor TableHeaderComponent::getMouseCursor()
  40561. {
  40562. if (columnIdBeingResized != 0 || (getResizeDraggerAt (getMouseXYRelative().getX()) != 0 && ! isMouseButtonDown()))
  40563. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40564. return Component::getMouseCursor();
  40565. }
  40566. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40567. {
  40568. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40569. }
  40570. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40571. {
  40572. for (int i = columns.size(); --i >= 0;)
  40573. if (columns.getUnchecked(i)->id == id)
  40574. return columns.getUnchecked(i);
  40575. return 0;
  40576. }
  40577. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40578. {
  40579. int n = 0;
  40580. for (int i = 0; i < columns.size(); ++i)
  40581. {
  40582. if (columns.getUnchecked(i)->isVisible())
  40583. {
  40584. if (n == visibleIndex)
  40585. return i;
  40586. ++n;
  40587. }
  40588. }
  40589. return -1;
  40590. }
  40591. void TableHeaderComponent::sendColumnsChanged()
  40592. {
  40593. if (stretchToFit && lastDeliberateWidth > 0)
  40594. resizeAllColumnsToFit (lastDeliberateWidth);
  40595. repaint();
  40596. columnsChanged = true;
  40597. triggerAsyncUpdate();
  40598. }
  40599. void TableHeaderComponent::handleAsyncUpdate()
  40600. {
  40601. const bool changed = columnsChanged || sortChanged;
  40602. const bool sized = columnsResized || changed;
  40603. const bool sorted = sortChanged;
  40604. columnsChanged = false;
  40605. columnsResized = false;
  40606. sortChanged = false;
  40607. if (sorted)
  40608. {
  40609. for (int i = listeners.size(); --i >= 0;)
  40610. {
  40611. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40612. i = jmin (i, listeners.size() - 1);
  40613. }
  40614. }
  40615. if (changed)
  40616. {
  40617. for (int i = listeners.size(); --i >= 0;)
  40618. {
  40619. listeners.getUnchecked(i)->tableColumnsChanged (this);
  40620. i = jmin (i, listeners.size() - 1);
  40621. }
  40622. }
  40623. if (sized)
  40624. {
  40625. for (int i = listeners.size(); --i >= 0;)
  40626. {
  40627. listeners.getUnchecked(i)->tableColumnsResized (this);
  40628. i = jmin (i, listeners.size() - 1);
  40629. }
  40630. }
  40631. }
  40632. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  40633. {
  40634. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  40635. {
  40636. const int draggableDistance = 3;
  40637. int x = 0;
  40638. for (int i = 0; i < columns.size(); ++i)
  40639. {
  40640. const ColumnInfo* const ci = columns.getUnchecked(i);
  40641. if (ci->isVisible())
  40642. {
  40643. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  40644. && (ci->propertyFlags & resizable) != 0)
  40645. return ci->id;
  40646. x += ci->width;
  40647. }
  40648. }
  40649. }
  40650. return 0;
  40651. }
  40652. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  40653. {
  40654. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  40655. ? getColumnIdAtX (x) : 0;
  40656. if (newCol != columnIdUnderMouse)
  40657. {
  40658. columnIdUnderMouse = newCol;
  40659. repaint();
  40660. }
  40661. }
  40662. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  40663. {
  40664. PopupMenu m;
  40665. addMenuItems (m, columnIdClicked);
  40666. if (m.getNumItems() > 0)
  40667. {
  40668. m.setLookAndFeel (&getLookAndFeel());
  40669. const int result = m.show();
  40670. if (result != 0)
  40671. reactToMenuItem (result, columnIdClicked);
  40672. }
  40673. }
  40674. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  40675. {
  40676. }
  40677. END_JUCE_NAMESPACE
  40678. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  40679. /*** Start of inlined file: juce_TableListBox.cpp ***/
  40680. BEGIN_JUCE_NAMESPACE
  40681. static const char* const tableColumnPropertyTag = "_tableColumnID";
  40682. class TableListRowComp : public Component,
  40683. public TooltipClient
  40684. {
  40685. public:
  40686. TableListRowComp (TableListBox& owner_)
  40687. : owner (owner_),
  40688. row (-1),
  40689. isSelected (false)
  40690. {
  40691. }
  40692. ~TableListRowComp()
  40693. {
  40694. deleteAllChildren();
  40695. }
  40696. void paint (Graphics& g)
  40697. {
  40698. TableListBoxModel* const model = owner.getModel();
  40699. if (model != 0)
  40700. {
  40701. const TableHeaderComponent* const header = owner.getHeader();
  40702. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  40703. const int numColumns = header->getNumColumns (true);
  40704. for (int i = 0; i < numColumns; ++i)
  40705. {
  40706. if (! columnsWithComponents [i])
  40707. {
  40708. const int columnId = header->getColumnIdOfIndex (i, true);
  40709. Rectangle<int> columnRect (header->getColumnPosition (i));
  40710. columnRect.setSize (columnRect.getWidth(), getHeight());
  40711. g.saveState();
  40712. g.reduceClipRegion (columnRect);
  40713. g.setOrigin (columnRect.getX(), 0);
  40714. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  40715. g.restoreState();
  40716. }
  40717. }
  40718. }
  40719. }
  40720. void update (const int newRow, const bool isNowSelected)
  40721. {
  40722. if (newRow != row || isNowSelected != isSelected)
  40723. {
  40724. row = newRow;
  40725. isSelected = isNowSelected;
  40726. repaint();
  40727. }
  40728. if (row < owner.getNumRows())
  40729. {
  40730. jassert (row >= 0);
  40731. const var::identifier tagPropertyName ("_tableLastUseNum");
  40732. const int newTag = Random::getSystemRandom().nextInt();
  40733. const TableHeaderComponent* const header = owner.getHeader();
  40734. const int numColumns = header->getNumColumns (true);
  40735. int i;
  40736. columnsWithComponents.clear();
  40737. if (owner.getModel() != 0)
  40738. {
  40739. for (i = 0; i < numColumns; ++i)
  40740. {
  40741. const int columnId = header->getColumnIdOfIndex (i, true);
  40742. Component* const newComp
  40743. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  40744. findChildComponentForColumn (columnId));
  40745. if (newComp != 0)
  40746. {
  40747. addAndMakeVisible (newComp);
  40748. newComp->getProperties().set (tagPropertyName, newTag);
  40749. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  40750. const Rectangle<int> columnRect (header->getColumnPosition (i));
  40751. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40752. columnsWithComponents.setBit (i);
  40753. }
  40754. }
  40755. }
  40756. for (i = getNumChildComponents(); --i >= 0;)
  40757. {
  40758. Component* const c = getChildComponent (i);
  40759. if ((int) c->getProperties() [tagPropertyName] != newTag)
  40760. delete c;
  40761. }
  40762. }
  40763. else
  40764. {
  40765. columnsWithComponents.clear();
  40766. deleteAllChildren();
  40767. }
  40768. }
  40769. void resized()
  40770. {
  40771. for (int i = getNumChildComponents(); --i >= 0;)
  40772. {
  40773. Component* const c = getChildComponent (i);
  40774. const int columnId = c->getProperties() [tableColumnPropertyTag];
  40775. if (columnId != 0)
  40776. {
  40777. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  40778. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40779. }
  40780. }
  40781. }
  40782. void mouseDown (const MouseEvent& e)
  40783. {
  40784. isDragging = false;
  40785. selectRowOnMouseUp = false;
  40786. if (isEnabled())
  40787. {
  40788. if (! isSelected)
  40789. {
  40790. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40791. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40792. if (columnId != 0 && owner.getModel() != 0)
  40793. owner.getModel()->cellClicked (row, columnId, e);
  40794. }
  40795. else
  40796. {
  40797. selectRowOnMouseUp = true;
  40798. }
  40799. }
  40800. }
  40801. void mouseDrag (const MouseEvent& e)
  40802. {
  40803. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  40804. {
  40805. const SparseSet <int> selectedRows (owner.getSelectedRows());
  40806. if (selectedRows.size() > 0)
  40807. {
  40808. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  40809. if (dragDescription.isNotEmpty())
  40810. {
  40811. isDragging = true;
  40812. owner.startDragAndDrop (e, dragDescription);
  40813. }
  40814. }
  40815. }
  40816. }
  40817. void mouseUp (const MouseEvent& e)
  40818. {
  40819. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  40820. {
  40821. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40822. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40823. if (columnId != 0 && owner.getModel() != 0)
  40824. owner.getModel()->cellClicked (row, columnId, e);
  40825. }
  40826. }
  40827. void mouseDoubleClick (const MouseEvent& e)
  40828. {
  40829. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40830. if (columnId != 0 && owner.getModel() != 0)
  40831. owner.getModel()->cellDoubleClicked (row, columnId, e);
  40832. }
  40833. const String getTooltip()
  40834. {
  40835. const int columnId = owner.getHeader()->getColumnIdAtX (getMouseXYRelative().getX());
  40836. if (columnId != 0 && owner.getModel() != 0)
  40837. return owner.getModel()->getCellTooltip (row, columnId);
  40838. return String::empty;
  40839. }
  40840. juce_UseDebuggingNewOperator
  40841. private:
  40842. TableListBox& owner;
  40843. int row;
  40844. bool isSelected, isDragging, selectRowOnMouseUp;
  40845. BitArray columnsWithComponents;
  40846. Component* findChildComponentForColumn (const int columnId) const
  40847. {
  40848. for (int i = getNumChildComponents(); --i >= 0;)
  40849. {
  40850. Component* const c = getChildComponent (i);
  40851. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  40852. return c;
  40853. }
  40854. return 0;
  40855. }
  40856. TableListRowComp (const TableListRowComp&);
  40857. TableListRowComp& operator= (const TableListRowComp&);
  40858. };
  40859. class TableListBoxHeader : public TableHeaderComponent
  40860. {
  40861. public:
  40862. TableListBoxHeader (TableListBox& owner_)
  40863. : owner (owner_)
  40864. {
  40865. }
  40866. ~TableListBoxHeader()
  40867. {
  40868. }
  40869. void addMenuItems (PopupMenu& menu, const int columnIdClicked)
  40870. {
  40871. if (owner.isAutoSizeMenuOptionShown())
  40872. {
  40873. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  40874. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  40875. menu.addSeparator();
  40876. }
  40877. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  40878. }
  40879. void reactToMenuItem (const int menuReturnId, const int columnIdClicked)
  40880. {
  40881. if (menuReturnId == 0xf836743)
  40882. {
  40883. owner.autoSizeColumn (columnIdClicked);
  40884. }
  40885. else if (menuReturnId == 0xf836744)
  40886. {
  40887. owner.autoSizeAllColumns();
  40888. }
  40889. else
  40890. {
  40891. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  40892. }
  40893. }
  40894. juce_UseDebuggingNewOperator
  40895. private:
  40896. TableListBox& owner;
  40897. TableListBoxHeader (const TableListBoxHeader&);
  40898. TableListBoxHeader& operator= (const TableListBoxHeader&);
  40899. };
  40900. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  40901. : ListBox (name, 0),
  40902. model (model_),
  40903. autoSizeOptionsShown (true)
  40904. {
  40905. ListBox::model = this;
  40906. header = new TableListBoxHeader (*this);
  40907. header->setSize (100, 28);
  40908. header->addListener (this);
  40909. setHeaderComponent (header);
  40910. }
  40911. TableListBox::~TableListBox()
  40912. {
  40913. deleteAllChildren();
  40914. }
  40915. void TableListBox::setModel (TableListBoxModel* const newModel)
  40916. {
  40917. if (model != newModel)
  40918. {
  40919. model = newModel;
  40920. updateContent();
  40921. }
  40922. }
  40923. int TableListBox::getHeaderHeight() const
  40924. {
  40925. return header->getHeight();
  40926. }
  40927. void TableListBox::setHeaderHeight (const int newHeight)
  40928. {
  40929. header->setSize (header->getWidth(), newHeight);
  40930. resized();
  40931. }
  40932. void TableListBox::autoSizeColumn (const int columnId)
  40933. {
  40934. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  40935. if (width > 0)
  40936. header->setColumnWidth (columnId, width);
  40937. }
  40938. void TableListBox::autoSizeAllColumns()
  40939. {
  40940. for (int i = 0; i < header->getNumColumns (true); ++i)
  40941. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  40942. }
  40943. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  40944. {
  40945. autoSizeOptionsShown = shouldBeShown;
  40946. }
  40947. bool TableListBox::isAutoSizeMenuOptionShown() const
  40948. {
  40949. return autoSizeOptionsShown;
  40950. }
  40951. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  40952. const int rowNumber,
  40953. const bool relativeToComponentTopLeft) const
  40954. {
  40955. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40956. if (relativeToComponentTopLeft)
  40957. headerCell.translate (header->getX(), 0);
  40958. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  40959. return Rectangle<int> (headerCell.getX(), row.getY(),
  40960. headerCell.getWidth(), row.getHeight());
  40961. }
  40962. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  40963. {
  40964. ScrollBar* const scrollbar = getHorizontalScrollBar();
  40965. if (scrollbar != 0)
  40966. {
  40967. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40968. double x = scrollbar->getCurrentRangeStart();
  40969. const double w = scrollbar->getCurrentRangeSize();
  40970. if (pos.getX() < x)
  40971. x = pos.getX();
  40972. else if (pos.getRight() > x + w)
  40973. x += jmax (0.0, pos.getRight() - (x + w));
  40974. scrollbar->setCurrentRangeStart (x);
  40975. }
  40976. }
  40977. int TableListBox::getNumRows()
  40978. {
  40979. return model != 0 ? model->getNumRows() : 0;
  40980. }
  40981. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  40982. {
  40983. }
  40984. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  40985. {
  40986. if (existingComponentToUpdate == 0)
  40987. existingComponentToUpdate = new TableListRowComp (*this);
  40988. ((TableListRowComp*) existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  40989. return existingComponentToUpdate;
  40990. }
  40991. void TableListBox::selectedRowsChanged (int row)
  40992. {
  40993. if (model != 0)
  40994. model->selectedRowsChanged (row);
  40995. }
  40996. void TableListBox::deleteKeyPressed (int row)
  40997. {
  40998. if (model != 0)
  40999. model->deleteKeyPressed (row);
  41000. }
  41001. void TableListBox::returnKeyPressed (int row)
  41002. {
  41003. if (model != 0)
  41004. model->returnKeyPressed (row);
  41005. }
  41006. void TableListBox::backgroundClicked()
  41007. {
  41008. if (model != 0)
  41009. model->backgroundClicked();
  41010. }
  41011. void TableListBox::listWasScrolled()
  41012. {
  41013. if (model != 0)
  41014. model->listWasScrolled();
  41015. }
  41016. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  41017. {
  41018. setMinimumContentWidth (header->getTotalWidth());
  41019. repaint();
  41020. updateColumnComponents();
  41021. }
  41022. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  41023. {
  41024. setMinimumContentWidth (header->getTotalWidth());
  41025. repaint();
  41026. updateColumnComponents();
  41027. }
  41028. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  41029. {
  41030. if (model != 0)
  41031. model->sortOrderChanged (header->getSortColumnId(),
  41032. header->isSortedForwards());
  41033. }
  41034. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  41035. {
  41036. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  41037. repaint();
  41038. }
  41039. void TableListBox::resized()
  41040. {
  41041. ListBox::resized();
  41042. header->resizeAllColumnsToFit (getVisibleContentWidth());
  41043. setMinimumContentWidth (header->getTotalWidth());
  41044. }
  41045. void TableListBox::updateColumnComponents() const
  41046. {
  41047. const int firstRow = getRowContainingPosition (0, 0);
  41048. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  41049. {
  41050. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  41051. if (rowComp != 0)
  41052. rowComp->resized();
  41053. }
  41054. }
  41055. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  41056. {
  41057. }
  41058. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  41059. {
  41060. }
  41061. void TableListBoxModel::backgroundClicked()
  41062. {
  41063. }
  41064. void TableListBoxModel::sortOrderChanged (int, const bool)
  41065. {
  41066. }
  41067. int TableListBoxModel::getColumnAutoSizeWidth (int)
  41068. {
  41069. return 0;
  41070. }
  41071. void TableListBoxModel::selectedRowsChanged (int)
  41072. {
  41073. }
  41074. void TableListBoxModel::deleteKeyPressed (int)
  41075. {
  41076. }
  41077. void TableListBoxModel::returnKeyPressed (int)
  41078. {
  41079. }
  41080. void TableListBoxModel::listWasScrolled()
  41081. {
  41082. }
  41083. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  41084. {
  41085. return String::empty;
  41086. }
  41087. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  41088. {
  41089. return String::empty;
  41090. }
  41091. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  41092. {
  41093. (void) existingComponentToUpdate;
  41094. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  41095. return 0;
  41096. }
  41097. END_JUCE_NAMESPACE
  41098. /*** End of inlined file: juce_TableListBox.cpp ***/
  41099. /*** Start of inlined file: juce_TextEditor.cpp ***/
  41100. BEGIN_JUCE_NAMESPACE
  41101. // a word or space that can't be broken down any further
  41102. struct TextAtom
  41103. {
  41104. String atomText;
  41105. float width;
  41106. uint16 numChars;
  41107. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  41108. bool isNewLine() const { return atomText[0] == T('\r') || atomText[0] == T('\n'); }
  41109. const String getText (const tchar passwordCharacter) const
  41110. {
  41111. if (passwordCharacter == 0)
  41112. return atomText;
  41113. else
  41114. return String::repeatedString (String::charToString (passwordCharacter),
  41115. atomText.length());
  41116. }
  41117. const String getTrimmedText (const tchar passwordCharacter) const
  41118. {
  41119. if (passwordCharacter == 0)
  41120. return atomText.substring (0, numChars);
  41121. else if (isNewLine())
  41122. return String::empty;
  41123. else
  41124. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  41125. }
  41126. };
  41127. // a run of text with a single font and colour
  41128. class UniformTextSection
  41129. {
  41130. public:
  41131. UniformTextSection (const String& text,
  41132. const Font& font_,
  41133. const Colour& colour_,
  41134. const tchar passwordCharacter)
  41135. : font (font_),
  41136. colour (colour_)
  41137. {
  41138. initialiseAtoms (text, passwordCharacter);
  41139. }
  41140. UniformTextSection (const UniformTextSection& other)
  41141. : font (other.font),
  41142. colour (other.colour)
  41143. {
  41144. atoms.ensureStorageAllocated (other.atoms.size());
  41145. for (int i = 0; i < other.atoms.size(); ++i)
  41146. atoms.add (new TextAtom (*(const TextAtom*) other.atoms.getUnchecked(i)));
  41147. }
  41148. ~UniformTextSection()
  41149. {
  41150. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  41151. }
  41152. void clear()
  41153. {
  41154. for (int i = atoms.size(); --i >= 0;)
  41155. delete getAtom(i);
  41156. atoms.clear();
  41157. }
  41158. int getNumAtoms() const
  41159. {
  41160. return atoms.size();
  41161. }
  41162. TextAtom* getAtom (const int index) const
  41163. {
  41164. return (TextAtom*) atoms.getUnchecked (index);
  41165. }
  41166. void append (const UniformTextSection& other, const tchar passwordCharacter)
  41167. {
  41168. if (other.atoms.size() > 0)
  41169. {
  41170. TextAtom* const lastAtom = (TextAtom*) atoms.getLast();
  41171. int i = 0;
  41172. if (lastAtom != 0)
  41173. {
  41174. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  41175. {
  41176. TextAtom* const first = other.getAtom(0);
  41177. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  41178. {
  41179. lastAtom->atomText += first->atomText;
  41180. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  41181. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  41182. delete first;
  41183. ++i;
  41184. }
  41185. }
  41186. }
  41187. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  41188. while (i < other.atoms.size())
  41189. {
  41190. atoms.add (other.getAtom(i));
  41191. ++i;
  41192. }
  41193. }
  41194. }
  41195. UniformTextSection* split (const int indexToBreakAt,
  41196. const tchar passwordCharacter)
  41197. {
  41198. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  41199. font, colour,
  41200. passwordCharacter);
  41201. int index = 0;
  41202. for (int i = 0; i < atoms.size(); ++i)
  41203. {
  41204. TextAtom* const atom = getAtom(i);
  41205. const int nextIndex = index + atom->numChars;
  41206. if (index == indexToBreakAt)
  41207. {
  41208. int j;
  41209. for (j = i; j < atoms.size(); ++j)
  41210. section2->atoms.add (getAtom (j));
  41211. for (j = atoms.size(); --j >= i;)
  41212. atoms.remove (j);
  41213. break;
  41214. }
  41215. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  41216. {
  41217. TextAtom* const secondAtom = new TextAtom();
  41218. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  41219. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  41220. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  41221. section2->atoms.add (secondAtom);
  41222. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  41223. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41224. atom->numChars = (uint16) (indexToBreakAt - index);
  41225. int j;
  41226. for (j = i + 1; j < atoms.size(); ++j)
  41227. section2->atoms.add (getAtom (j));
  41228. for (j = atoms.size(); --j > i;)
  41229. atoms.remove (j);
  41230. break;
  41231. }
  41232. index = nextIndex;
  41233. }
  41234. return section2;
  41235. }
  41236. void appendAllText (String::Concatenator& concatenator) const
  41237. {
  41238. for (int i = 0; i < atoms.size(); ++i)
  41239. concatenator.append (getAtom(i)->atomText);
  41240. }
  41241. void appendSubstring (String::Concatenator& concatenator,
  41242. const Range<int>& range) const
  41243. {
  41244. int index = 0;
  41245. for (int i = 0; i < atoms.size(); ++i)
  41246. {
  41247. const TextAtom* const atom = getAtom (i);
  41248. const int nextIndex = index + atom->numChars;
  41249. if (range.getStart() < nextIndex)
  41250. {
  41251. if (range.getEnd() <= index)
  41252. break;
  41253. const Range<int> r ((range - index).getIntersectionWith (Range<int> (0, (int) atom->numChars)));
  41254. if (! r.isEmpty())
  41255. concatenator.append (atom->atomText.substring (r.getStart(), r.getEnd()));
  41256. }
  41257. index = nextIndex;
  41258. }
  41259. }
  41260. int getTotalLength() const
  41261. {
  41262. int total = 0;
  41263. for (int i = atoms.size(); --i >= 0;)
  41264. total += getAtom(i)->numChars;
  41265. return total;
  41266. }
  41267. void setFont (const Font& newFont,
  41268. const tchar passwordCharacter)
  41269. {
  41270. if (font != newFont)
  41271. {
  41272. font = newFont;
  41273. for (int i = atoms.size(); --i >= 0;)
  41274. {
  41275. TextAtom* const atom = (TextAtom*) atoms.getUnchecked(i);
  41276. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41277. }
  41278. }
  41279. }
  41280. juce_UseDebuggingNewOperator
  41281. Font font;
  41282. Colour colour;
  41283. private:
  41284. VoidArray atoms;
  41285. void initialiseAtoms (const String& textToParse,
  41286. const tchar passwordCharacter)
  41287. {
  41288. int i = 0;
  41289. const int len = textToParse.length();
  41290. const tchar* const text = (const tchar*) textToParse;
  41291. while (i < len)
  41292. {
  41293. int start = i;
  41294. // create a whitespace atom unless it starts with non-ws
  41295. if (CharacterFunctions::isWhitespace (text[i])
  41296. && text[i] != T('\r')
  41297. && text[i] != T('\n'))
  41298. {
  41299. while (i < len
  41300. && CharacterFunctions::isWhitespace (text[i])
  41301. && text[i] != T('\r')
  41302. && text[i] != T('\n'))
  41303. {
  41304. ++i;
  41305. }
  41306. }
  41307. else
  41308. {
  41309. if (text[i] == T('\r'))
  41310. {
  41311. ++i;
  41312. if ((i < len) && (text[i] == T('\n')))
  41313. {
  41314. ++start;
  41315. ++i;
  41316. }
  41317. }
  41318. else if (text[i] == T('\n'))
  41319. {
  41320. ++i;
  41321. }
  41322. else
  41323. {
  41324. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41325. ++i;
  41326. }
  41327. }
  41328. TextAtom* const atom = new TextAtom();
  41329. atom->atomText = String (text + start, i - start);
  41330. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41331. atom->numChars = (uint16) (i - start);
  41332. atoms.add (atom);
  41333. }
  41334. }
  41335. UniformTextSection& operator= (const UniformTextSection& other);
  41336. };
  41337. class TextEditorIterator
  41338. {
  41339. public:
  41340. TextEditorIterator (const VoidArray& sections_,
  41341. const float wordWrapWidth_,
  41342. const tchar passwordCharacter_)
  41343. : indexInText (0),
  41344. lineY (0),
  41345. lineHeight (0),
  41346. maxDescent (0),
  41347. atomX (0),
  41348. atomRight (0),
  41349. atom (0),
  41350. currentSection (0),
  41351. sections (sections_),
  41352. sectionIndex (0),
  41353. atomIndex (0),
  41354. wordWrapWidth (wordWrapWidth_),
  41355. passwordCharacter (passwordCharacter_)
  41356. {
  41357. jassert (wordWrapWidth_ > 0);
  41358. if (sections.size() > 0)
  41359. {
  41360. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41361. if (currentSection != 0)
  41362. beginNewLine();
  41363. }
  41364. }
  41365. TextEditorIterator (const TextEditorIterator& other)
  41366. : indexInText (other.indexInText),
  41367. lineY (other.lineY),
  41368. lineHeight (other.lineHeight),
  41369. maxDescent (other.maxDescent),
  41370. atomX (other.atomX),
  41371. atomRight (other.atomRight),
  41372. atom (other.atom),
  41373. currentSection (other.currentSection),
  41374. sections (other.sections),
  41375. sectionIndex (other.sectionIndex),
  41376. atomIndex (other.atomIndex),
  41377. wordWrapWidth (other.wordWrapWidth),
  41378. passwordCharacter (other.passwordCharacter),
  41379. tempAtom (other.tempAtom)
  41380. {
  41381. }
  41382. ~TextEditorIterator()
  41383. {
  41384. }
  41385. bool next()
  41386. {
  41387. if (atom == &tempAtom)
  41388. {
  41389. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41390. if (numRemaining > 0)
  41391. {
  41392. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41393. atomX = 0;
  41394. if (tempAtom.numChars > 0)
  41395. lineY += lineHeight;
  41396. indexInText += tempAtom.numChars;
  41397. GlyphArrangement g;
  41398. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41399. int split;
  41400. for (split = 0; split < g.getNumGlyphs(); ++split)
  41401. if (shouldWrap (g.getGlyph (split).getRight()))
  41402. break;
  41403. if (split > 0 && split <= numRemaining)
  41404. {
  41405. tempAtom.numChars = (uint16) split;
  41406. tempAtom.width = g.getGlyph (split - 1).getRight();
  41407. atomRight = atomX + tempAtom.width;
  41408. return true;
  41409. }
  41410. }
  41411. }
  41412. bool forceNewLine = false;
  41413. if (sectionIndex >= sections.size())
  41414. {
  41415. moveToEndOfLastAtom();
  41416. return false;
  41417. }
  41418. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41419. {
  41420. if (atomIndex >= currentSection->getNumAtoms())
  41421. {
  41422. if (++sectionIndex >= sections.size())
  41423. {
  41424. moveToEndOfLastAtom();
  41425. return false;
  41426. }
  41427. atomIndex = 0;
  41428. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41429. }
  41430. else
  41431. {
  41432. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41433. if (! lastAtom->isWhitespace())
  41434. {
  41435. // handle the case where the last atom in a section is actually part of the same
  41436. // word as the first atom of the next section...
  41437. float right = atomRight + lastAtom->width;
  41438. float lineHeight2 = lineHeight;
  41439. float maxDescent2 = maxDescent;
  41440. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41441. {
  41442. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked (section);
  41443. if (s->getNumAtoms() == 0)
  41444. break;
  41445. const TextAtom* const nextAtom = s->getAtom (0);
  41446. if (nextAtom->isWhitespace())
  41447. break;
  41448. right += nextAtom->width;
  41449. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41450. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41451. if (shouldWrap (right))
  41452. {
  41453. lineHeight = lineHeight2;
  41454. maxDescent = maxDescent2;
  41455. forceNewLine = true;
  41456. break;
  41457. }
  41458. if (s->getNumAtoms() > 1)
  41459. break;
  41460. }
  41461. }
  41462. }
  41463. }
  41464. if (atom != 0)
  41465. {
  41466. atomX = atomRight;
  41467. indexInText += atom->numChars;
  41468. if (atom->isNewLine())
  41469. beginNewLine();
  41470. }
  41471. atom = currentSection->getAtom (atomIndex);
  41472. atomRight = atomX + atom->width;
  41473. ++atomIndex;
  41474. if (shouldWrap (atomRight) || forceNewLine)
  41475. {
  41476. if (atom->isWhitespace())
  41477. {
  41478. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41479. atomRight = jmin (atomRight, wordWrapWidth);
  41480. }
  41481. else
  41482. {
  41483. atomRight = atom->width;
  41484. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41485. {
  41486. tempAtom = *atom;
  41487. tempAtom.width = 0;
  41488. tempAtom.numChars = 0;
  41489. atom = &tempAtom;
  41490. if (atomX > 0)
  41491. beginNewLine();
  41492. return next();
  41493. }
  41494. beginNewLine();
  41495. return true;
  41496. }
  41497. }
  41498. return true;
  41499. }
  41500. void beginNewLine()
  41501. {
  41502. atomX = 0;
  41503. lineY += lineHeight;
  41504. int tempSectionIndex = sectionIndex;
  41505. int tempAtomIndex = atomIndex;
  41506. const UniformTextSection* section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41507. lineHeight = section->font.getHeight();
  41508. maxDescent = section->font.getDescent();
  41509. float x = (atom != 0) ? atom->width : 0;
  41510. while (! shouldWrap (x))
  41511. {
  41512. if (tempSectionIndex >= sections.size())
  41513. break;
  41514. bool checkSize = false;
  41515. if (tempAtomIndex >= section->getNumAtoms())
  41516. {
  41517. if (++tempSectionIndex >= sections.size())
  41518. break;
  41519. tempAtomIndex = 0;
  41520. section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41521. checkSize = true;
  41522. }
  41523. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41524. if (nextAtom == 0)
  41525. break;
  41526. x += nextAtom->width;
  41527. if (shouldWrap (x) || nextAtom->isNewLine())
  41528. break;
  41529. if (checkSize)
  41530. {
  41531. lineHeight = jmax (lineHeight, section->font.getHeight());
  41532. maxDescent = jmax (maxDescent, section->font.getDescent());
  41533. }
  41534. ++tempAtomIndex;
  41535. }
  41536. }
  41537. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41538. {
  41539. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41540. {
  41541. if (lastSection != currentSection)
  41542. {
  41543. lastSection = currentSection;
  41544. g.setColour (currentSection->colour);
  41545. g.setFont (currentSection->font);
  41546. }
  41547. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41548. GlyphArrangement ga;
  41549. ga.addLineOfText (currentSection->font,
  41550. atom->getTrimmedText (passwordCharacter),
  41551. atomX,
  41552. (float) roundToInt (lineY + lineHeight - maxDescent));
  41553. ga.draw (g);
  41554. }
  41555. }
  41556. void drawSelection (Graphics& g,
  41557. const Range<int>& selection) const
  41558. {
  41559. const int startX = roundToInt (indexToX (selection.getStart()));
  41560. const int endX = roundToInt (indexToX (selection.getEnd()));
  41561. const int y = roundToInt (lineY);
  41562. const int nextY = roundToInt (lineY + lineHeight);
  41563. g.fillRect (startX, y, endX - startX, nextY - y);
  41564. }
  41565. void drawSelectedText (Graphics& g,
  41566. const Range<int>& selection,
  41567. const Colour& selectedTextColour) const
  41568. {
  41569. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41570. {
  41571. GlyphArrangement ga;
  41572. ga.addLineOfText (currentSection->font,
  41573. atom->getTrimmedText (passwordCharacter),
  41574. atomX,
  41575. (float) roundToInt (lineY + lineHeight - maxDescent));
  41576. if (selection.getEnd() < indexInText + atom->numChars)
  41577. {
  41578. GlyphArrangement ga2 (ga);
  41579. ga2.removeRangeOfGlyphs (0, selection.getEnd() - indexInText);
  41580. ga.removeRangeOfGlyphs (selection.getEnd() - indexInText, -1);
  41581. g.setColour (currentSection->colour);
  41582. ga2.draw (g);
  41583. }
  41584. if (selection.getStart() > indexInText)
  41585. {
  41586. GlyphArrangement ga2 (ga);
  41587. ga2.removeRangeOfGlyphs (selection.getStart() - indexInText, -1);
  41588. ga.removeRangeOfGlyphs (0, selection.getStart() - indexInText);
  41589. g.setColour (currentSection->colour);
  41590. ga2.draw (g);
  41591. }
  41592. g.setColour (selectedTextColour);
  41593. ga.draw (g);
  41594. }
  41595. }
  41596. float indexToX (const int indexToFind) const
  41597. {
  41598. if (indexToFind <= indexInText)
  41599. return atomX;
  41600. if (indexToFind >= indexInText + atom->numChars)
  41601. return atomRight;
  41602. GlyphArrangement g;
  41603. g.addLineOfText (currentSection->font,
  41604. atom->getText (passwordCharacter),
  41605. atomX, 0.0f);
  41606. if (indexToFind - indexInText >= g.getNumGlyphs())
  41607. return atomRight;
  41608. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41609. }
  41610. int xToIndex (const float xToFind) const
  41611. {
  41612. if (xToFind <= atomX || atom->isNewLine())
  41613. return indexInText;
  41614. if (xToFind >= atomRight)
  41615. return indexInText + atom->numChars;
  41616. GlyphArrangement g;
  41617. g.addLineOfText (currentSection->font,
  41618. atom->getText (passwordCharacter),
  41619. atomX, 0.0f);
  41620. int j;
  41621. for (j = 0; j < g.getNumGlyphs(); ++j)
  41622. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  41623. break;
  41624. return indexInText + j;
  41625. }
  41626. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  41627. {
  41628. while (next())
  41629. {
  41630. if (indexInText + atom->numChars > index)
  41631. {
  41632. cx = indexToX (index);
  41633. cy = lineY;
  41634. lineHeight_ = lineHeight;
  41635. return true;
  41636. }
  41637. }
  41638. cx = atomX;
  41639. cy = lineY;
  41640. lineHeight_ = lineHeight;
  41641. return false;
  41642. }
  41643. juce_UseDebuggingNewOperator
  41644. int indexInText;
  41645. float lineY, lineHeight, maxDescent;
  41646. float atomX, atomRight;
  41647. const TextAtom* atom;
  41648. const UniformTextSection* currentSection;
  41649. private:
  41650. const VoidArray& sections;
  41651. int sectionIndex, atomIndex;
  41652. const float wordWrapWidth;
  41653. const tchar passwordCharacter;
  41654. TextAtom tempAtom;
  41655. TextEditorIterator& operator= (const TextEditorIterator&);
  41656. void moveToEndOfLastAtom()
  41657. {
  41658. if (atom != 0)
  41659. {
  41660. atomX = atomRight;
  41661. if (atom->isNewLine())
  41662. {
  41663. atomX = 0.0f;
  41664. lineY += lineHeight;
  41665. }
  41666. }
  41667. }
  41668. bool shouldWrap (const float x) const
  41669. {
  41670. return (x - 0.0001f) >= wordWrapWidth;
  41671. }
  41672. };
  41673. class TextEditorInsertAction : public UndoableAction
  41674. {
  41675. TextEditor& owner;
  41676. const String text;
  41677. const int insertIndex, oldCaretPos, newCaretPos;
  41678. const Font font;
  41679. const Colour colour;
  41680. TextEditorInsertAction (const TextEditorInsertAction&);
  41681. TextEditorInsertAction& operator= (const TextEditorInsertAction&);
  41682. public:
  41683. TextEditorInsertAction (TextEditor& owner_,
  41684. const String& text_,
  41685. const int insertIndex_,
  41686. const Font& font_,
  41687. const Colour& colour_,
  41688. const int oldCaretPos_,
  41689. const int newCaretPos_)
  41690. : owner (owner_),
  41691. text (text_),
  41692. insertIndex (insertIndex_),
  41693. oldCaretPos (oldCaretPos_),
  41694. newCaretPos (newCaretPos_),
  41695. font (font_),
  41696. colour (colour_)
  41697. {
  41698. }
  41699. ~TextEditorInsertAction()
  41700. {
  41701. }
  41702. bool perform()
  41703. {
  41704. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  41705. return true;
  41706. }
  41707. bool undo()
  41708. {
  41709. owner.remove (Range<int> (insertIndex, insertIndex + text.length()), 0, oldCaretPos);
  41710. return true;
  41711. }
  41712. int getSizeInUnits()
  41713. {
  41714. return text.length() + 16;
  41715. }
  41716. };
  41717. class TextEditorRemoveAction : public UndoableAction
  41718. {
  41719. TextEditor& owner;
  41720. const Range<int> range;
  41721. const int oldCaretPos, newCaretPos;
  41722. VoidArray removedSections;
  41723. TextEditorRemoveAction (const TextEditorRemoveAction&);
  41724. TextEditorRemoveAction& operator= (const TextEditorRemoveAction&);
  41725. public:
  41726. TextEditorRemoveAction (TextEditor& owner_,
  41727. const Range<int> range_,
  41728. const int oldCaretPos_,
  41729. const int newCaretPos_,
  41730. const VoidArray& removedSections_)
  41731. : owner (owner_),
  41732. range (range_),
  41733. oldCaretPos (oldCaretPos_),
  41734. newCaretPos (newCaretPos_),
  41735. removedSections (removedSections_)
  41736. {
  41737. }
  41738. ~TextEditorRemoveAction()
  41739. {
  41740. for (int i = removedSections.size(); --i >= 0;)
  41741. {
  41742. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  41743. section->clear();
  41744. delete section;
  41745. }
  41746. }
  41747. bool perform()
  41748. {
  41749. owner.remove (range, 0, newCaretPos);
  41750. return true;
  41751. }
  41752. bool undo()
  41753. {
  41754. owner.reinsert (range.getStart(), removedSections);
  41755. owner.moveCursorTo (oldCaretPos, false);
  41756. return true;
  41757. }
  41758. int getSizeInUnits()
  41759. {
  41760. int n = 0;
  41761. for (int i = removedSections.size(); --i >= 0;)
  41762. {
  41763. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  41764. n += section->getTotalLength();
  41765. }
  41766. return n + 16;
  41767. }
  41768. };
  41769. class TextHolderComponent : public Component,
  41770. public Timer,
  41771. public Value::Listener
  41772. {
  41773. TextEditor& owner;
  41774. TextHolderComponent (const TextHolderComponent&);
  41775. TextHolderComponent& operator= (const TextHolderComponent&);
  41776. public:
  41777. TextHolderComponent (TextEditor& owner_)
  41778. : owner (owner_)
  41779. {
  41780. setWantsKeyboardFocus (false);
  41781. setInterceptsMouseClicks (false, true);
  41782. owner.getTextValue().addListener (this);
  41783. }
  41784. ~TextHolderComponent()
  41785. {
  41786. owner.getTextValue().removeListener (this);
  41787. }
  41788. void paint (Graphics& g)
  41789. {
  41790. owner.drawContent (g);
  41791. }
  41792. void timerCallback()
  41793. {
  41794. owner.timerCallbackInt();
  41795. }
  41796. const MouseCursor getMouseCursor()
  41797. {
  41798. return owner.getMouseCursor();
  41799. }
  41800. void valueChanged (Value&)
  41801. {
  41802. owner.textWasChangedByValue();
  41803. }
  41804. };
  41805. class TextEditorViewport : public Viewport
  41806. {
  41807. TextEditor* const owner;
  41808. float lastWordWrapWidth;
  41809. TextEditorViewport (const TextEditorViewport&);
  41810. TextEditorViewport& operator= (const TextEditorViewport&);
  41811. public:
  41812. TextEditorViewport (TextEditor* const owner_)
  41813. : owner (owner_),
  41814. lastWordWrapWidth (0)
  41815. {
  41816. }
  41817. ~TextEditorViewport()
  41818. {
  41819. }
  41820. void visibleAreaChanged (int, int, int, int)
  41821. {
  41822. const float wordWrapWidth = owner->getWordWrapWidth();
  41823. if (wordWrapWidth != lastWordWrapWidth)
  41824. {
  41825. lastWordWrapWidth = wordWrapWidth;
  41826. owner->updateTextHolderSize();
  41827. }
  41828. }
  41829. };
  41830. namespace TextEditorDefs
  41831. {
  41832. const int flashSpeedIntervalMs = 380;
  41833. const int textChangeMessageId = 0x10003001;
  41834. const int returnKeyMessageId = 0x10003002;
  41835. const int escapeKeyMessageId = 0x10003003;
  41836. const int focusLossMessageId = 0x10003004;
  41837. const int maxActionsPerTransaction = 100;
  41838. }
  41839. TextEditor::TextEditor (const String& name,
  41840. const tchar passwordCharacter_)
  41841. : Component (name),
  41842. borderSize (1, 1, 1, 3),
  41843. readOnly (false),
  41844. multiline (false),
  41845. wordWrap (false),
  41846. returnKeyStartsNewLine (false),
  41847. caretVisible (true),
  41848. popupMenuEnabled (true),
  41849. selectAllTextWhenFocused (false),
  41850. scrollbarVisible (true),
  41851. wasFocused (false),
  41852. caretFlashState (true),
  41853. keepCursorOnScreen (true),
  41854. tabKeyUsed (false),
  41855. menuActive (false),
  41856. valueTextNeedsUpdating (false),
  41857. cursorX (0),
  41858. cursorY (0),
  41859. cursorHeight (0),
  41860. maxTextLength (0),
  41861. leftIndent (4),
  41862. topIndent (4),
  41863. lastTransactionTime (0),
  41864. currentFont (14.0f),
  41865. totalNumChars (0),
  41866. caretPosition (0),
  41867. passwordCharacter (passwordCharacter_),
  41868. dragType (notDragging)
  41869. {
  41870. setOpaque (true);
  41871. addAndMakeVisible (viewport = new TextEditorViewport (this));
  41872. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  41873. viewport->setWantsKeyboardFocus (false);
  41874. viewport->setScrollBarsShown (false, false);
  41875. setMouseCursor (MouseCursor::IBeamCursor);
  41876. setWantsKeyboardFocus (true);
  41877. }
  41878. TextEditor::~TextEditor()
  41879. {
  41880. textValue.referTo (Value());
  41881. clearInternal (0);
  41882. viewport = 0;
  41883. textHolder = 0;
  41884. }
  41885. void TextEditor::newTransaction()
  41886. {
  41887. lastTransactionTime = Time::getApproximateMillisecondCounter();
  41888. undoManager.beginNewTransaction();
  41889. }
  41890. void TextEditor::doUndoRedo (const bool isRedo)
  41891. {
  41892. if (! isReadOnly())
  41893. {
  41894. if (isRedo ? undoManager.redo()
  41895. : undoManager.undo())
  41896. {
  41897. scrollToMakeSureCursorIsVisible();
  41898. repaint();
  41899. textChanged();
  41900. }
  41901. }
  41902. }
  41903. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  41904. const bool shouldWordWrap)
  41905. {
  41906. multiline = shouldBeMultiLine;
  41907. wordWrap = shouldWordWrap && shouldBeMultiLine;
  41908. setScrollbarsShown (scrollbarVisible);
  41909. viewport->setViewPosition (0, 0);
  41910. resized();
  41911. scrollToMakeSureCursorIsVisible();
  41912. }
  41913. bool TextEditor::isMultiLine() const
  41914. {
  41915. return multiline;
  41916. }
  41917. void TextEditor::setScrollbarsShown (bool enabled)
  41918. {
  41919. scrollbarVisible = enabled;
  41920. enabled = enabled && isMultiLine();
  41921. viewport->setScrollBarsShown (enabled, enabled);
  41922. }
  41923. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  41924. {
  41925. readOnly = shouldBeReadOnly;
  41926. enablementChanged();
  41927. }
  41928. bool TextEditor::isReadOnly() const
  41929. {
  41930. return readOnly || ! isEnabled();
  41931. }
  41932. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  41933. {
  41934. returnKeyStartsNewLine = shouldStartNewLine;
  41935. }
  41936. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  41937. {
  41938. tabKeyUsed = shouldTabKeyBeUsed;
  41939. }
  41940. void TextEditor::setPopupMenuEnabled (const bool b)
  41941. {
  41942. popupMenuEnabled = b;
  41943. }
  41944. void TextEditor::setSelectAllWhenFocused (const bool b)
  41945. {
  41946. selectAllTextWhenFocused = b;
  41947. }
  41948. const Font TextEditor::getFont() const
  41949. {
  41950. return currentFont;
  41951. }
  41952. void TextEditor::setFont (const Font& newFont)
  41953. {
  41954. currentFont = newFont;
  41955. scrollToMakeSureCursorIsVisible();
  41956. }
  41957. void TextEditor::applyFontToAllText (const Font& newFont)
  41958. {
  41959. currentFont = newFont;
  41960. const Colour overallColour (findColour (textColourId));
  41961. for (int i = sections.size(); --i >= 0;)
  41962. {
  41963. UniformTextSection* const uts = (UniformTextSection*) sections.getUnchecked(i);
  41964. uts->setFont (newFont, passwordCharacter);
  41965. uts->colour = overallColour;
  41966. }
  41967. coalesceSimilarSections();
  41968. updateTextHolderSize();
  41969. scrollToMakeSureCursorIsVisible();
  41970. repaint();
  41971. }
  41972. void TextEditor::colourChanged()
  41973. {
  41974. setOpaque (findColour (backgroundColourId).isOpaque());
  41975. repaint();
  41976. }
  41977. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  41978. {
  41979. caretVisible = shouldCaretBeVisible;
  41980. if (shouldCaretBeVisible)
  41981. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41982. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  41983. : MouseCursor::NormalCursor);
  41984. }
  41985. void TextEditor::setInputRestrictions (const int maxLen,
  41986. const String& chars)
  41987. {
  41988. maxTextLength = jmax (0, maxLen);
  41989. allowedCharacters = chars;
  41990. }
  41991. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  41992. {
  41993. textToShowWhenEmpty = text;
  41994. colourForTextWhenEmpty = colourToUse;
  41995. }
  41996. void TextEditor::setPasswordCharacter (const tchar newPasswordCharacter)
  41997. {
  41998. if (passwordCharacter != newPasswordCharacter)
  41999. {
  42000. passwordCharacter = newPasswordCharacter;
  42001. resized();
  42002. repaint();
  42003. }
  42004. }
  42005. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  42006. {
  42007. viewport->setScrollBarThickness (newThicknessPixels);
  42008. }
  42009. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  42010. {
  42011. viewport->setScrollBarButtonVisibility (buttonsVisible);
  42012. }
  42013. void TextEditor::clear()
  42014. {
  42015. clearInternal (0);
  42016. updateTextHolderSize();
  42017. undoManager.clearUndoHistory();
  42018. }
  42019. void TextEditor::setText (const String& newText,
  42020. const bool sendTextChangeMessage)
  42021. {
  42022. const int newLength = newText.length();
  42023. if (newLength != getTotalNumChars() || getText() != newText)
  42024. {
  42025. const int oldCursorPos = caretPosition;
  42026. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  42027. clearInternal (0);
  42028. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  42029. // if you're adding text with line-feeds to a single-line text editor, it
  42030. // ain't gonna look right!
  42031. jassert (multiline || ! newText.containsAnyOf (T("\r\n")));
  42032. if (cursorWasAtEnd && ! isMultiLine())
  42033. moveCursorTo (getTotalNumChars(), false);
  42034. else
  42035. moveCursorTo (oldCursorPos, false);
  42036. if (sendTextChangeMessage)
  42037. textChanged();
  42038. repaint();
  42039. }
  42040. updateTextHolderSize();
  42041. scrollToMakeSureCursorIsVisible();
  42042. undoManager.clearUndoHistory();
  42043. }
  42044. Value& TextEditor::getTextValue()
  42045. {
  42046. if (valueTextNeedsUpdating)
  42047. {
  42048. valueTextNeedsUpdating = false;
  42049. textValue = getText();
  42050. }
  42051. return textValue;
  42052. }
  42053. void TextEditor::textWasChangedByValue()
  42054. {
  42055. if (textValue.getValueSource().getReferenceCount() > 1)
  42056. setText (textValue.getValue());
  42057. }
  42058. void TextEditor::textChanged()
  42059. {
  42060. updateTextHolderSize();
  42061. postCommandMessage (TextEditorDefs::textChangeMessageId);
  42062. if (textValue.getValueSource().getReferenceCount() > 1)
  42063. {
  42064. valueTextNeedsUpdating = false;
  42065. textValue = getText();
  42066. }
  42067. }
  42068. void TextEditor::returnPressed()
  42069. {
  42070. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  42071. }
  42072. void TextEditor::escapePressed()
  42073. {
  42074. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  42075. }
  42076. void TextEditor::addListener (TextEditorListener* const newListener)
  42077. {
  42078. listeners.add (newListener);
  42079. }
  42080. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  42081. {
  42082. listeners.remove (listenerToRemove);
  42083. }
  42084. void TextEditor::timerCallbackInt()
  42085. {
  42086. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  42087. if (caretFlashState != newState)
  42088. {
  42089. caretFlashState = newState;
  42090. if (caretFlashState)
  42091. wasFocused = true;
  42092. if (caretVisible
  42093. && hasKeyboardFocus (false)
  42094. && ! isReadOnly())
  42095. {
  42096. repaintCaret();
  42097. }
  42098. }
  42099. const unsigned int now = Time::getApproximateMillisecondCounter();
  42100. if (now > lastTransactionTime + 200)
  42101. newTransaction();
  42102. }
  42103. void TextEditor::repaintCaret()
  42104. {
  42105. if (! findColour (caretColourId).isTransparent())
  42106. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  42107. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  42108. 4,
  42109. roundToInt (cursorHeight) + 2);
  42110. }
  42111. void TextEditor::repaintText (const Range<int>& range)
  42112. {
  42113. if (! range.isEmpty())
  42114. {
  42115. float x = 0, y = 0, lh = currentFont.getHeight();
  42116. const float wordWrapWidth = getWordWrapWidth();
  42117. if (wordWrapWidth > 0)
  42118. {
  42119. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42120. i.getCharPosition (range.getStart(), x, y, lh);
  42121. const int y1 = (int) y;
  42122. int y2;
  42123. if (range.getEnd() >= getTotalNumChars())
  42124. {
  42125. y2 = textHolder->getHeight();
  42126. }
  42127. else
  42128. {
  42129. i.getCharPosition (range.getEnd(), x, y, lh);
  42130. y2 = (int) (y + lh * 2.0f);
  42131. }
  42132. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  42133. }
  42134. }
  42135. }
  42136. void TextEditor::moveCaret (int newCaretPos)
  42137. {
  42138. if (newCaretPos < 0)
  42139. newCaretPos = 0;
  42140. else if (newCaretPos > getTotalNumChars())
  42141. newCaretPos = getTotalNumChars();
  42142. if (newCaretPos != getCaretPosition())
  42143. {
  42144. repaintCaret();
  42145. caretFlashState = true;
  42146. caretPosition = newCaretPos;
  42147. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42148. scrollToMakeSureCursorIsVisible();
  42149. repaintCaret();
  42150. }
  42151. }
  42152. void TextEditor::setCaretPosition (const int newIndex)
  42153. {
  42154. moveCursorTo (newIndex, false);
  42155. }
  42156. int TextEditor::getCaretPosition() const
  42157. {
  42158. return caretPosition;
  42159. }
  42160. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  42161. const int desiredCaretY)
  42162. {
  42163. updateCaretPosition();
  42164. int vx = roundToInt (cursorX) - desiredCaretX;
  42165. int vy = roundToInt (cursorY) - desiredCaretY;
  42166. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  42167. {
  42168. vx += desiredCaretX - proportionOfWidth (0.2f);
  42169. }
  42170. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42171. {
  42172. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42173. }
  42174. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  42175. if (! isMultiLine())
  42176. {
  42177. vy = viewport->getViewPositionY();
  42178. }
  42179. else
  42180. {
  42181. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  42182. const int curH = roundToInt (cursorHeight);
  42183. if (desiredCaretY < 0)
  42184. {
  42185. vy = jmax (0, desiredCaretY + vy);
  42186. }
  42187. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42188. {
  42189. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42190. }
  42191. }
  42192. viewport->setViewPosition (vx, vy);
  42193. }
  42194. const Rectangle<int> TextEditor::getCaretRectangle()
  42195. {
  42196. updateCaretPosition();
  42197. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  42198. roundToInt (cursorY) - viewport->getY(),
  42199. 1, roundToInt (cursorHeight));
  42200. }
  42201. float TextEditor::getWordWrapWidth() const
  42202. {
  42203. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  42204. : 1.0e10f;
  42205. }
  42206. void TextEditor::updateTextHolderSize()
  42207. {
  42208. const float wordWrapWidth = getWordWrapWidth();
  42209. if (wordWrapWidth > 0)
  42210. {
  42211. float maxWidth = 0.0f;
  42212. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42213. while (i.next())
  42214. maxWidth = jmax (maxWidth, i.atomRight);
  42215. const int w = leftIndent + roundToInt (maxWidth);
  42216. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  42217. currentFont.getHeight()));
  42218. textHolder->setSize (w + 1, h + 1);
  42219. }
  42220. }
  42221. int TextEditor::getTextWidth() const
  42222. {
  42223. return textHolder->getWidth();
  42224. }
  42225. int TextEditor::getTextHeight() const
  42226. {
  42227. return textHolder->getHeight();
  42228. }
  42229. void TextEditor::setIndents (const int newLeftIndent,
  42230. const int newTopIndent)
  42231. {
  42232. leftIndent = newLeftIndent;
  42233. topIndent = newTopIndent;
  42234. }
  42235. void TextEditor::setBorder (const BorderSize& border)
  42236. {
  42237. borderSize = border;
  42238. resized();
  42239. }
  42240. const BorderSize TextEditor::getBorder() const
  42241. {
  42242. return borderSize;
  42243. }
  42244. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  42245. {
  42246. keepCursorOnScreen = shouldScrollToShowCursor;
  42247. }
  42248. void TextEditor::updateCaretPosition()
  42249. {
  42250. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  42251. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  42252. }
  42253. void TextEditor::scrollToMakeSureCursorIsVisible()
  42254. {
  42255. updateCaretPosition();
  42256. if (keepCursorOnScreen)
  42257. {
  42258. int x = viewport->getViewPositionX();
  42259. int y = viewport->getViewPositionY();
  42260. const int relativeCursorX = roundToInt (cursorX) - x;
  42261. const int relativeCursorY = roundToInt (cursorY) - y;
  42262. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42263. {
  42264. x += relativeCursorX - proportionOfWidth (0.2f);
  42265. }
  42266. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42267. {
  42268. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42269. }
  42270. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42271. if (! isMultiLine())
  42272. {
  42273. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42274. }
  42275. else
  42276. {
  42277. const int curH = roundToInt (cursorHeight);
  42278. if (relativeCursorY < 0)
  42279. {
  42280. y = jmax (0, relativeCursorY + y);
  42281. }
  42282. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42283. {
  42284. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42285. }
  42286. }
  42287. viewport->setViewPosition (x, y);
  42288. }
  42289. }
  42290. void TextEditor::moveCursorTo (const int newPosition,
  42291. const bool isSelecting)
  42292. {
  42293. if (isSelecting)
  42294. {
  42295. moveCaret (newPosition);
  42296. const Range<int> oldSelection (selection);
  42297. if (dragType == notDragging)
  42298. {
  42299. if (abs (getCaretPosition() - selection.getStart()) < abs (getCaretPosition() - selection.getEnd()))
  42300. dragType = draggingSelectionStart;
  42301. else
  42302. dragType = draggingSelectionEnd;
  42303. }
  42304. if (dragType == draggingSelectionStart)
  42305. {
  42306. if (getCaretPosition() >= selection.getEnd())
  42307. dragType = draggingSelectionEnd;
  42308. selection = Range<int>::between (getCaretPosition(), selection.getEnd());
  42309. }
  42310. else
  42311. {
  42312. if (getCaretPosition() < selection.getStart())
  42313. dragType = draggingSelectionStart;
  42314. selection = Range<int>::between (getCaretPosition(), selection.getStart());
  42315. }
  42316. repaintText (selection.getUnionWith (oldSelection));
  42317. }
  42318. else
  42319. {
  42320. dragType = notDragging;
  42321. repaintText (selection);
  42322. moveCaret (newPosition);
  42323. selection = Range<int>::emptyRange (getCaretPosition());
  42324. }
  42325. }
  42326. int TextEditor::getTextIndexAt (const int x,
  42327. const int y)
  42328. {
  42329. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42330. (float) (y + viewport->getViewPositionY() - topIndent));
  42331. }
  42332. void TextEditor::insertTextAtCaret (const String& newText_)
  42333. {
  42334. String newText (newText_);
  42335. if (allowedCharacters.isNotEmpty())
  42336. newText = newText.retainCharacters (allowedCharacters);
  42337. if (! isMultiLine())
  42338. newText = newText.replaceCharacters (T("\r\n"), T(" "));
  42339. else
  42340. newText = newText.replace (T("\r\n"), T("\n"));
  42341. const int newCaretPos = selection.getStart() + newText.length();
  42342. const int insertIndex = selection.getStart();
  42343. remove (selection, getUndoManager(),
  42344. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42345. if (maxTextLength > 0)
  42346. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42347. if (newText.isNotEmpty())
  42348. insert (newText,
  42349. insertIndex,
  42350. currentFont,
  42351. findColour (textColourId),
  42352. getUndoManager(),
  42353. newCaretPos);
  42354. textChanged();
  42355. }
  42356. void TextEditor::setHighlightedRegion (const Range<int>& newSelection)
  42357. {
  42358. moveCursorTo (newSelection.getStart(), false);
  42359. moveCursorTo (newSelection.getEnd(), true);
  42360. }
  42361. void TextEditor::copy()
  42362. {
  42363. if (passwordCharacter == 0)
  42364. {
  42365. const String selection (getHighlightedText());
  42366. if (selection.isNotEmpty())
  42367. SystemClipboard::copyTextToClipboard (selection);
  42368. }
  42369. }
  42370. void TextEditor::paste()
  42371. {
  42372. if (! isReadOnly())
  42373. {
  42374. const String clip (SystemClipboard::getTextFromClipboard());
  42375. if (clip.isNotEmpty())
  42376. insertTextAtCaret (clip);
  42377. }
  42378. }
  42379. void TextEditor::cut()
  42380. {
  42381. if (! isReadOnly())
  42382. {
  42383. moveCaret (selection.getEnd());
  42384. insertTextAtCaret (String::empty);
  42385. }
  42386. }
  42387. void TextEditor::drawContent (Graphics& g)
  42388. {
  42389. const float wordWrapWidth = getWordWrapWidth();
  42390. if (wordWrapWidth > 0)
  42391. {
  42392. g.setOrigin (leftIndent, topIndent);
  42393. const Rectangle<int> clip (g.getClipBounds());
  42394. Colour selectedTextColour;
  42395. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42396. while (i.lineY + 200.0 < clip.getY() && i.next())
  42397. {}
  42398. if (! selection.isEmpty())
  42399. {
  42400. g.setColour (findColour (highlightColourId)
  42401. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42402. selectedTextColour = findColour (highlightedTextColourId);
  42403. TextEditorIterator i2 (i);
  42404. while (i2.next() && i2.lineY < clip.getBottom())
  42405. {
  42406. if (i2.lineY + i2.lineHeight >= clip.getY()
  42407. && selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
  42408. {
  42409. i2.drawSelection (g, selection);
  42410. }
  42411. }
  42412. }
  42413. const UniformTextSection* lastSection = 0;
  42414. while (i.next() && i.lineY < clip.getBottom())
  42415. {
  42416. if (i.lineY + i.lineHeight >= clip.getY())
  42417. {
  42418. if (selection.intersects (Range<int> (i.indexInText, i.indexInText + i.atom->numChars)))
  42419. {
  42420. i.drawSelectedText (g, selection, selectedTextColour);
  42421. lastSection = 0;
  42422. }
  42423. else
  42424. {
  42425. i.draw (g, lastSection);
  42426. }
  42427. }
  42428. }
  42429. }
  42430. }
  42431. void TextEditor::paint (Graphics& g)
  42432. {
  42433. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42434. }
  42435. void TextEditor::paintOverChildren (Graphics& g)
  42436. {
  42437. if (caretFlashState
  42438. && hasKeyboardFocus (false)
  42439. && caretVisible
  42440. && ! isReadOnly())
  42441. {
  42442. g.setColour (findColour (caretColourId));
  42443. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42444. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42445. 2.0f, cursorHeight);
  42446. }
  42447. if (textToShowWhenEmpty.isNotEmpty()
  42448. && (! hasKeyboardFocus (false))
  42449. && getTotalNumChars() == 0)
  42450. {
  42451. g.setColour (colourForTextWhenEmpty);
  42452. g.setFont (getFont());
  42453. if (isMultiLine())
  42454. {
  42455. g.drawText (textToShowWhenEmpty,
  42456. 0, 0, getWidth(), getHeight(),
  42457. Justification::centred, true);
  42458. }
  42459. else
  42460. {
  42461. g.drawText (textToShowWhenEmpty,
  42462. leftIndent, topIndent,
  42463. viewport->getWidth() - leftIndent,
  42464. viewport->getHeight() - topIndent,
  42465. Justification::centredLeft, true);
  42466. }
  42467. }
  42468. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42469. }
  42470. void TextEditor::mouseDown (const MouseEvent& e)
  42471. {
  42472. beginDragAutoRepeat (100);
  42473. newTransaction();
  42474. if (wasFocused || ! selectAllTextWhenFocused)
  42475. {
  42476. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42477. {
  42478. moveCursorTo (getTextIndexAt (e.x, e.y),
  42479. e.mods.isShiftDown());
  42480. }
  42481. else
  42482. {
  42483. PopupMenu m;
  42484. m.setLookAndFeel (&getLookAndFeel());
  42485. addPopupMenuItems (m, &e);
  42486. menuActive = true;
  42487. const int result = m.show();
  42488. menuActive = false;
  42489. if (result != 0)
  42490. performPopupMenuAction (result);
  42491. }
  42492. }
  42493. }
  42494. void TextEditor::mouseDrag (const MouseEvent& e)
  42495. {
  42496. if (wasFocused || ! selectAllTextWhenFocused)
  42497. {
  42498. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42499. {
  42500. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42501. }
  42502. }
  42503. }
  42504. void TextEditor::mouseUp (const MouseEvent& e)
  42505. {
  42506. newTransaction();
  42507. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42508. if (wasFocused || ! selectAllTextWhenFocused)
  42509. {
  42510. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42511. {
  42512. moveCaret (getTextIndexAt (e.x, e.y));
  42513. }
  42514. }
  42515. wasFocused = true;
  42516. }
  42517. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42518. {
  42519. int tokenEnd = getTextIndexAt (e.x, e.y);
  42520. int tokenStart = tokenEnd;
  42521. if (e.getNumberOfClicks() > 3)
  42522. {
  42523. tokenStart = 0;
  42524. tokenEnd = getTotalNumChars();
  42525. }
  42526. else
  42527. {
  42528. const String t (getText());
  42529. const int totalLength = getTotalNumChars();
  42530. while (tokenEnd < totalLength)
  42531. {
  42532. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42533. ++tokenEnd;
  42534. else
  42535. break;
  42536. }
  42537. tokenStart = tokenEnd;
  42538. while (tokenStart > 0)
  42539. {
  42540. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42541. --tokenStart;
  42542. else
  42543. break;
  42544. }
  42545. if (e.getNumberOfClicks() > 2)
  42546. {
  42547. while (tokenEnd < totalLength)
  42548. {
  42549. if (t [tokenEnd] != T('\r') && t [tokenEnd] != T('\n'))
  42550. ++tokenEnd;
  42551. else
  42552. break;
  42553. }
  42554. while (tokenStart > 0)
  42555. {
  42556. if (t [tokenStart - 1] != T('\r') && t [tokenStart - 1] != T('\n'))
  42557. --tokenStart;
  42558. else
  42559. break;
  42560. }
  42561. }
  42562. }
  42563. moveCursorTo (tokenEnd, false);
  42564. moveCursorTo (tokenStart, true);
  42565. }
  42566. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42567. {
  42568. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42569. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42570. }
  42571. bool TextEditor::keyPressed (const KeyPress& key)
  42572. {
  42573. if (isReadOnly() && key != KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  42574. return false;
  42575. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42576. if (key.isKeyCode (KeyPress::leftKey)
  42577. || key.isKeyCode (KeyPress::upKey))
  42578. {
  42579. newTransaction();
  42580. int newPos;
  42581. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42582. newPos = indexAtPosition (cursorX, cursorY - 1);
  42583. else if (moveInWholeWordSteps)
  42584. newPos = findWordBreakBefore (getCaretPosition());
  42585. else
  42586. newPos = getCaretPosition() - 1;
  42587. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42588. }
  42589. else if (key.isKeyCode (KeyPress::rightKey)
  42590. || key.isKeyCode (KeyPress::downKey))
  42591. {
  42592. newTransaction();
  42593. int newPos;
  42594. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42595. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42596. else if (moveInWholeWordSteps)
  42597. newPos = findWordBreakAfter (getCaretPosition());
  42598. else
  42599. newPos = getCaretPosition() + 1;
  42600. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42601. }
  42602. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42603. {
  42604. newTransaction();
  42605. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42606. key.getModifiers().isShiftDown());
  42607. }
  42608. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42609. {
  42610. newTransaction();
  42611. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  42612. key.getModifiers().isShiftDown());
  42613. }
  42614. else if (key.isKeyCode (KeyPress::homeKey))
  42615. {
  42616. newTransaction();
  42617. if (isMultiLine() && ! moveInWholeWordSteps)
  42618. moveCursorTo (indexAtPosition (0.0f, cursorY),
  42619. key.getModifiers().isShiftDown());
  42620. else
  42621. moveCursorTo (0, key.getModifiers().isShiftDown());
  42622. }
  42623. else if (key.isKeyCode (KeyPress::endKey))
  42624. {
  42625. newTransaction();
  42626. if (isMultiLine() && ! moveInWholeWordSteps)
  42627. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  42628. key.getModifiers().isShiftDown());
  42629. else
  42630. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  42631. }
  42632. else if (key.isKeyCode (KeyPress::backspaceKey))
  42633. {
  42634. if (moveInWholeWordSteps)
  42635. {
  42636. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  42637. }
  42638. else
  42639. {
  42640. if (selection.isEmpty() && selection.getStart() > 0)
  42641. selection.setStart (selection.getEnd() - 1);
  42642. }
  42643. cut();
  42644. }
  42645. else if (key.isKeyCode (KeyPress::deleteKey))
  42646. {
  42647. if (key.getModifiers().isShiftDown())
  42648. copy();
  42649. if (selection.isEmpty() && selection.getStart() < getTotalNumChars())
  42650. selection.setEnd (selection.getStart() + 1);
  42651. cut();
  42652. }
  42653. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0)
  42654. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  42655. {
  42656. newTransaction();
  42657. copy();
  42658. }
  42659. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  42660. {
  42661. newTransaction();
  42662. copy();
  42663. cut();
  42664. }
  42665. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0)
  42666. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  42667. {
  42668. newTransaction();
  42669. paste();
  42670. }
  42671. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  42672. {
  42673. newTransaction();
  42674. doUndoRedo (false);
  42675. }
  42676. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0))
  42677. {
  42678. newTransaction();
  42679. doUndoRedo (true);
  42680. }
  42681. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  42682. {
  42683. newTransaction();
  42684. moveCursorTo (getTotalNumChars(), false);
  42685. moveCursorTo (0, true);
  42686. }
  42687. else if (key == KeyPress::returnKey)
  42688. {
  42689. newTransaction();
  42690. if (returnKeyStartsNewLine)
  42691. insertTextAtCaret (T("\n"));
  42692. else
  42693. returnPressed();
  42694. }
  42695. else if (key.isKeyCode (KeyPress::escapeKey))
  42696. {
  42697. newTransaction();
  42698. moveCursorTo (getCaretPosition(), false);
  42699. escapePressed();
  42700. }
  42701. else if (key.getTextCharacter() >= ' '
  42702. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  42703. {
  42704. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  42705. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42706. }
  42707. else
  42708. {
  42709. return false;
  42710. }
  42711. return true;
  42712. }
  42713. bool TextEditor::keyStateChanged (const bool isKeyDown)
  42714. {
  42715. if (! isKeyDown)
  42716. return false;
  42717. #if JUCE_WIN32
  42718. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  42719. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  42720. #endif
  42721. // (overridden to avoid forwarding key events to the parent)
  42722. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  42723. }
  42724. const int baseMenuItemID = 0x7fff0000;
  42725. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  42726. {
  42727. const bool writable = ! isReadOnly();
  42728. if (passwordCharacter == 0)
  42729. {
  42730. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  42731. m.addItem (baseMenuItemID + 2, TRANS("copy"), ! selection.isEmpty());
  42732. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  42733. }
  42734. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  42735. m.addSeparator();
  42736. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  42737. m.addSeparator();
  42738. if (getUndoManager() != 0)
  42739. {
  42740. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  42741. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  42742. }
  42743. }
  42744. void TextEditor::performPopupMenuAction (const int menuItemID)
  42745. {
  42746. switch (menuItemID)
  42747. {
  42748. case baseMenuItemID + 1:
  42749. copy();
  42750. cut();
  42751. break;
  42752. case baseMenuItemID + 2:
  42753. copy();
  42754. break;
  42755. case baseMenuItemID + 3:
  42756. paste();
  42757. break;
  42758. case baseMenuItemID + 4:
  42759. cut();
  42760. break;
  42761. case baseMenuItemID + 5:
  42762. moveCursorTo (getTotalNumChars(), false);
  42763. moveCursorTo (0, true);
  42764. break;
  42765. case baseMenuItemID + 6:
  42766. doUndoRedo (false);
  42767. break;
  42768. case baseMenuItemID + 7:
  42769. doUndoRedo (true);
  42770. break;
  42771. default:
  42772. break;
  42773. }
  42774. }
  42775. void TextEditor::focusGained (FocusChangeType)
  42776. {
  42777. newTransaction();
  42778. caretFlashState = true;
  42779. if (selectAllTextWhenFocused)
  42780. {
  42781. moveCursorTo (0, false);
  42782. moveCursorTo (getTotalNumChars(), true);
  42783. }
  42784. repaint();
  42785. if (caretVisible)
  42786. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42787. ComponentPeer* const peer = getPeer();
  42788. if (peer != 0 && ! isReadOnly())
  42789. peer->textInputRequired (getScreenPosition() - peer->getScreenPosition());
  42790. }
  42791. void TextEditor::focusLost (FocusChangeType)
  42792. {
  42793. newTransaction();
  42794. wasFocused = false;
  42795. textHolder->stopTimer();
  42796. caretFlashState = false;
  42797. postCommandMessage (TextEditorDefs::focusLossMessageId);
  42798. repaint();
  42799. }
  42800. void TextEditor::resized()
  42801. {
  42802. viewport->setBoundsInset (borderSize);
  42803. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  42804. updateTextHolderSize();
  42805. if (! isMultiLine())
  42806. {
  42807. scrollToMakeSureCursorIsVisible();
  42808. }
  42809. else
  42810. {
  42811. updateCaretPosition();
  42812. }
  42813. }
  42814. void TextEditor::handleCommandMessage (const int commandId)
  42815. {
  42816. Component::BailOutChecker checker (this);
  42817. switch (commandId)
  42818. {
  42819. case TextEditorDefs::textChangeMessageId:
  42820. listeners.callChecked (checker, &TextEditorListener::textEditorTextChanged, (TextEditor&) *this);
  42821. break;
  42822. case TextEditorDefs::returnKeyMessageId:
  42823. listeners.callChecked (checker, &TextEditorListener::textEditorReturnKeyPressed, (TextEditor&) *this);
  42824. break;
  42825. case TextEditorDefs::escapeKeyMessageId:
  42826. listeners.callChecked (checker, &TextEditorListener::textEditorEscapeKeyPressed, (TextEditor&) *this);
  42827. break;
  42828. case TextEditorDefs::focusLossMessageId:
  42829. listeners.callChecked (checker, &TextEditorListener::textEditorFocusLost, (TextEditor&) *this);
  42830. break;
  42831. default:
  42832. jassertfalse
  42833. break;
  42834. }
  42835. }
  42836. void TextEditor::enablementChanged()
  42837. {
  42838. setMouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  42839. : MouseCursor::IBeamCursor);
  42840. repaint();
  42841. }
  42842. UndoManager* TextEditor::getUndoManager() throw()
  42843. {
  42844. return isReadOnly() ? &undoManager : 0;
  42845. }
  42846. void TextEditor::clearInternal (UndoManager* const um)
  42847. {
  42848. remove (Range<int> (0, getTotalNumChars()), um, caretPosition);
  42849. }
  42850. void TextEditor::insert (const String& text,
  42851. const int insertIndex,
  42852. const Font& font,
  42853. const Colour& colour,
  42854. UndoManager* const um,
  42855. const int caretPositionToMoveTo)
  42856. {
  42857. if (text.isNotEmpty())
  42858. {
  42859. if (um != 0)
  42860. {
  42861. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42862. newTransaction();
  42863. um->perform (new TextEditorInsertAction (*this,
  42864. text,
  42865. insertIndex,
  42866. font,
  42867. colour,
  42868. caretPosition,
  42869. caretPositionToMoveTo));
  42870. }
  42871. else
  42872. {
  42873. repaintText (Range<int> (insertIndex, getTotalNumChars())); // must do this before and after changing the data, in case
  42874. // a line gets moved due to word wrap
  42875. int index = 0;
  42876. int nextIndex = 0;
  42877. for (int i = 0; i < sections.size(); ++i)
  42878. {
  42879. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42880. if (insertIndex == index)
  42881. {
  42882. sections.insert (i, new UniformTextSection (text,
  42883. font, colour,
  42884. passwordCharacter));
  42885. break;
  42886. }
  42887. else if (insertIndex > index && insertIndex < nextIndex)
  42888. {
  42889. splitSection (i, insertIndex - index);
  42890. sections.insert (i + 1, new UniformTextSection (text,
  42891. font, colour,
  42892. passwordCharacter));
  42893. break;
  42894. }
  42895. index = nextIndex;
  42896. }
  42897. if (nextIndex == insertIndex)
  42898. sections.add (new UniformTextSection (text,
  42899. font, colour,
  42900. passwordCharacter));
  42901. coalesceSimilarSections();
  42902. totalNumChars = -1;
  42903. valueTextNeedsUpdating = true;
  42904. moveCursorTo (caretPositionToMoveTo, false);
  42905. repaintText (Range<int> (insertIndex, getTotalNumChars()));
  42906. }
  42907. }
  42908. }
  42909. void TextEditor::reinsert (const int insertIndex,
  42910. const VoidArray& sectionsToInsert)
  42911. {
  42912. int index = 0;
  42913. int nextIndex = 0;
  42914. for (int i = 0; i < sections.size(); ++i)
  42915. {
  42916. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42917. if (insertIndex == index)
  42918. {
  42919. for (int j = sectionsToInsert.size(); --j >= 0;)
  42920. sections.insert (i, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42921. break;
  42922. }
  42923. else if (insertIndex > index && insertIndex < nextIndex)
  42924. {
  42925. splitSection (i, insertIndex - index);
  42926. for (int j = sectionsToInsert.size(); --j >= 0;)
  42927. sections.insert (i + 1, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42928. break;
  42929. }
  42930. index = nextIndex;
  42931. }
  42932. if (nextIndex == insertIndex)
  42933. {
  42934. for (int j = 0; j < sectionsToInsert.size(); ++j)
  42935. sections.add (new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42936. }
  42937. coalesceSimilarSections();
  42938. totalNumChars = -1;
  42939. valueTextNeedsUpdating = true;
  42940. }
  42941. void TextEditor::remove (const Range<int>& range,
  42942. UndoManager* const um,
  42943. const int caretPositionToMoveTo)
  42944. {
  42945. if (! range.isEmpty())
  42946. {
  42947. int index = 0;
  42948. for (int i = 0; i < sections.size(); ++i)
  42949. {
  42950. const int nextIndex = index + ((UniformTextSection*) sections[i])->getTotalLength();
  42951. if (range.getStart() > index && range.getStart() < nextIndex)
  42952. {
  42953. splitSection (i, range.getStart() - index);
  42954. --i;
  42955. }
  42956. else if (range.getEnd() > index && range.getEnd() < nextIndex)
  42957. {
  42958. splitSection (i, range.getEnd() - index);
  42959. --i;
  42960. }
  42961. else
  42962. {
  42963. index = nextIndex;
  42964. if (index > range.getEnd())
  42965. break;
  42966. }
  42967. }
  42968. index = 0;
  42969. if (um != 0)
  42970. {
  42971. VoidArray removedSections;
  42972. for (int i = 0; i < sections.size(); ++i)
  42973. {
  42974. if (range.getEnd() <= range.getStart())
  42975. break;
  42976. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  42977. const int nextIndex = index + section->getTotalLength();
  42978. if (range.getStart() <= index && range.getEnd() >= nextIndex)
  42979. removedSections.add (new UniformTextSection (*section));
  42980. index = nextIndex;
  42981. }
  42982. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42983. newTransaction();
  42984. um->perform (new TextEditorRemoveAction (*this,
  42985. range,
  42986. caretPosition,
  42987. caretPositionToMoveTo,
  42988. removedSections));
  42989. }
  42990. else
  42991. {
  42992. Range<int> remainingRange (range);
  42993. for (int i = 0; i < sections.size(); ++i)
  42994. {
  42995. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  42996. const int nextIndex = index + section->getTotalLength();
  42997. if (remainingRange.getStart() <= index && remainingRange.getEnd() >= nextIndex)
  42998. {
  42999. sections.remove(i);
  43000. section->clear();
  43001. delete section;
  43002. remainingRange.setEnd (remainingRange.getEnd() - (nextIndex - index));
  43003. if (remainingRange.isEmpty())
  43004. break;
  43005. --i;
  43006. }
  43007. else
  43008. {
  43009. index = nextIndex;
  43010. }
  43011. }
  43012. coalesceSimilarSections();
  43013. totalNumChars = -1;
  43014. valueTextNeedsUpdating = true;
  43015. moveCursorTo (caretPositionToMoveTo, false);
  43016. repaintText (Range<int> (range.getStart(), getTotalNumChars()));
  43017. }
  43018. }
  43019. }
  43020. const String TextEditor::getText() const
  43021. {
  43022. String t;
  43023. t.preallocateStorage (getTotalNumChars());
  43024. String::Concatenator concatenator (t);
  43025. for (int i = 0; i < sections.size(); ++i)
  43026. ((const UniformTextSection*) sections.getUnchecked(i))->appendAllText (concatenator);
  43027. return t;
  43028. }
  43029. const String TextEditor::getTextInRange (const Range<int>& range) const
  43030. {
  43031. String t;
  43032. if (! range.isEmpty())
  43033. {
  43034. t.preallocateStorage (jmin (getTotalNumChars(), range.getLength()));
  43035. String::Concatenator concatenator (t);
  43036. int index = 0;
  43037. for (int i = 0; i < sections.size(); ++i)
  43038. {
  43039. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked(i);
  43040. const int nextIndex = index + s->getTotalLength();
  43041. if (range.getStart() < nextIndex)
  43042. {
  43043. if (range.getEnd() <= index)
  43044. break;
  43045. s->appendSubstring (concatenator, range - index);
  43046. }
  43047. index = nextIndex;
  43048. }
  43049. }
  43050. return t;
  43051. }
  43052. const String TextEditor::getHighlightedText() const
  43053. {
  43054. return getTextInRange (selection);
  43055. }
  43056. int TextEditor::getTotalNumChars() const
  43057. {
  43058. if (totalNumChars < 0)
  43059. {
  43060. totalNumChars = 0;
  43061. for (int i = sections.size(); --i >= 0;)
  43062. totalNumChars += ((const UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43063. }
  43064. return totalNumChars;
  43065. }
  43066. bool TextEditor::isEmpty() const
  43067. {
  43068. return getTotalNumChars() == 0;
  43069. }
  43070. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  43071. {
  43072. const float wordWrapWidth = getWordWrapWidth();
  43073. if (wordWrapWidth > 0 && sections.size() > 0)
  43074. {
  43075. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43076. i.getCharPosition (index, cx, cy, lineHeight);
  43077. }
  43078. else
  43079. {
  43080. cx = cy = 0;
  43081. lineHeight = currentFont.getHeight();
  43082. }
  43083. }
  43084. int TextEditor::indexAtPosition (const float x, const float y)
  43085. {
  43086. const float wordWrapWidth = getWordWrapWidth();
  43087. if (wordWrapWidth > 0)
  43088. {
  43089. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43090. while (i.next())
  43091. {
  43092. if (i.lineY + i.lineHeight > y)
  43093. {
  43094. if (i.lineY > y)
  43095. return jmax (0, i.indexInText - 1);
  43096. if (i.atomX >= x)
  43097. return i.indexInText;
  43098. if (x < i.atomRight)
  43099. return i.xToIndex (x);
  43100. }
  43101. }
  43102. }
  43103. return getTotalNumChars();
  43104. }
  43105. static int getCharacterCategory (const tchar character)
  43106. {
  43107. return CharacterFunctions::isLetterOrDigit (character)
  43108. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  43109. }
  43110. int TextEditor::findWordBreakAfter (const int position) const
  43111. {
  43112. const String t (getTextInRange (Range<int> (position, position + 512)));
  43113. const int totalLength = t.length();
  43114. int i = 0;
  43115. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43116. ++i;
  43117. const int type = getCharacterCategory (t[i]);
  43118. while (i < totalLength && type == getCharacterCategory (t[i]))
  43119. ++i;
  43120. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43121. ++i;
  43122. return position + i;
  43123. }
  43124. int TextEditor::findWordBreakBefore (const int position) const
  43125. {
  43126. if (position <= 0)
  43127. return 0;
  43128. const int startOfBuffer = jmax (0, position - 512);
  43129. const String t (getTextInRange (Range<int> (startOfBuffer, position)));
  43130. int i = position - startOfBuffer;
  43131. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  43132. --i;
  43133. if (i > 0)
  43134. {
  43135. const int type = getCharacterCategory (t [i - 1]);
  43136. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  43137. --i;
  43138. }
  43139. jassert (startOfBuffer + i >= 0);
  43140. return startOfBuffer + i;
  43141. }
  43142. void TextEditor::splitSection (const int sectionIndex,
  43143. const int charToSplitAt)
  43144. {
  43145. jassert (sections[sectionIndex] != 0);
  43146. sections.insert (sectionIndex + 1,
  43147. ((UniformTextSection*) sections.getUnchecked (sectionIndex))
  43148. ->split (charToSplitAt, passwordCharacter));
  43149. }
  43150. void TextEditor::coalesceSimilarSections()
  43151. {
  43152. for (int i = 0; i < sections.size() - 1; ++i)
  43153. {
  43154. UniformTextSection* const s1 = (UniformTextSection*) sections.getUnchecked (i);
  43155. UniformTextSection* const s2 = (UniformTextSection*) sections.getUnchecked (i + 1);
  43156. if (s1->font == s2->font
  43157. && s1->colour == s2->colour)
  43158. {
  43159. s1->append (*s2, passwordCharacter);
  43160. sections.remove (i + 1);
  43161. delete s2;
  43162. --i;
  43163. }
  43164. }
  43165. }
  43166. END_JUCE_NAMESPACE
  43167. /*** End of inlined file: juce_TextEditor.cpp ***/
  43168. /*** Start of inlined file: juce_Toolbar.cpp ***/
  43169. BEGIN_JUCE_NAMESPACE
  43170. const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_");
  43171. class ToolbarSpacerComp : public ToolbarItemComponent
  43172. {
  43173. public:
  43174. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  43175. : ToolbarItemComponent (itemId_, String::empty, false),
  43176. fixedSize (fixedSize_),
  43177. drawBar (drawBar_)
  43178. {
  43179. }
  43180. ~ToolbarSpacerComp()
  43181. {
  43182. }
  43183. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  43184. int& preferredSize, int& minSize, int& maxSize)
  43185. {
  43186. if (fixedSize <= 0)
  43187. {
  43188. preferredSize = toolbarThickness * 2;
  43189. minSize = 4;
  43190. maxSize = 32768;
  43191. }
  43192. else
  43193. {
  43194. maxSize = roundToInt (toolbarThickness * fixedSize);
  43195. minSize = drawBar ? maxSize : jmin (4, maxSize);
  43196. preferredSize = maxSize;
  43197. if (getEditingMode() == editableOnPalette)
  43198. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  43199. }
  43200. return true;
  43201. }
  43202. void paintButtonArea (Graphics&, int, int, bool, bool)
  43203. {
  43204. }
  43205. void contentAreaChanged (const Rectangle<int>&)
  43206. {
  43207. }
  43208. int getResizeOrder() const throw()
  43209. {
  43210. return fixedSize <= 0 ? 0 : 1;
  43211. }
  43212. void paint (Graphics& g)
  43213. {
  43214. const int w = getWidth();
  43215. const int h = getHeight();
  43216. if (drawBar)
  43217. {
  43218. g.setColour (findColour (Toolbar::separatorColourId, true));
  43219. const float thickness = 0.2f;
  43220. if (isToolbarVertical())
  43221. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  43222. else
  43223. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  43224. }
  43225. if (getEditingMode() != normalMode && ! drawBar)
  43226. {
  43227. g.setColour (findColour (Toolbar::separatorColourId, true));
  43228. const int indentX = jmin (2, (w - 3) / 2);
  43229. const int indentY = jmin (2, (h - 3) / 2);
  43230. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  43231. if (fixedSize <= 0)
  43232. {
  43233. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  43234. if (isToolbarVertical())
  43235. {
  43236. x1 = w * 0.5f;
  43237. y1 = h * 0.4f;
  43238. x2 = x1;
  43239. y2 = indentX * 2.0f;
  43240. x3 = x1;
  43241. y3 = h * 0.6f;
  43242. x4 = x1;
  43243. y4 = h - y2;
  43244. hw = w * 0.15f;
  43245. hl = w * 0.2f;
  43246. }
  43247. else
  43248. {
  43249. x1 = w * 0.4f;
  43250. y1 = h * 0.5f;
  43251. x2 = indentX * 2.0f;
  43252. y2 = y1;
  43253. x3 = w * 0.6f;
  43254. y3 = y1;
  43255. x4 = w - x2;
  43256. y4 = y1;
  43257. hw = h * 0.15f;
  43258. hl = h * 0.2f;
  43259. }
  43260. Path p;
  43261. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  43262. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  43263. g.fillPath (p);
  43264. }
  43265. }
  43266. }
  43267. juce_UseDebuggingNewOperator
  43268. private:
  43269. const float fixedSize;
  43270. const bool drawBar;
  43271. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43272. ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43273. };
  43274. class MissingItemsComponent : public PopupMenuCustomComponent
  43275. {
  43276. public:
  43277. MissingItemsComponent (Toolbar& owner_, const int height_)
  43278. : PopupMenuCustomComponent (true),
  43279. owner (owner_),
  43280. height (height_)
  43281. {
  43282. for (int i = owner_.items.size(); --i >= 0;)
  43283. {
  43284. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43285. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43286. {
  43287. oldIndexes.insert (0, i);
  43288. addAndMakeVisible (tc, 0);
  43289. }
  43290. }
  43291. layout (400);
  43292. }
  43293. ~MissingItemsComponent()
  43294. {
  43295. // deleting the toolbar while its menu it open??
  43296. jassert (owner.isValidComponent());
  43297. for (int i = 0; i < getNumChildComponents(); ++i)
  43298. {
  43299. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43300. if (tc != 0)
  43301. {
  43302. tc->setVisible (false);
  43303. const int index = oldIndexes.remove (i);
  43304. owner.addChildComponent (tc, index);
  43305. --i;
  43306. }
  43307. }
  43308. owner.resized();
  43309. }
  43310. void layout (const int preferredWidth)
  43311. {
  43312. const int indent = 8;
  43313. int x = indent;
  43314. int y = indent;
  43315. int maxX = 0;
  43316. for (int i = 0; i < getNumChildComponents(); ++i)
  43317. {
  43318. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43319. if (tc != 0)
  43320. {
  43321. int preferredSize = 1, minSize = 1, maxSize = 1;
  43322. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43323. {
  43324. if (x + preferredSize > preferredWidth && x > indent)
  43325. {
  43326. x = indent;
  43327. y += height;
  43328. }
  43329. tc->setBounds (x, y, preferredSize, height);
  43330. x += preferredSize;
  43331. maxX = jmax (maxX, x);
  43332. }
  43333. }
  43334. }
  43335. setSize (maxX + 8, y + height + 8);
  43336. }
  43337. void getIdealSize (int& idealWidth, int& idealHeight)
  43338. {
  43339. idealWidth = getWidth();
  43340. idealHeight = getHeight();
  43341. }
  43342. juce_UseDebuggingNewOperator
  43343. private:
  43344. Toolbar& owner;
  43345. const int height;
  43346. Array <int> oldIndexes;
  43347. MissingItemsComponent (const MissingItemsComponent&);
  43348. MissingItemsComponent& operator= (const MissingItemsComponent&);
  43349. };
  43350. Toolbar::Toolbar()
  43351. : vertical (false),
  43352. isEditingActive (false),
  43353. toolbarStyle (Toolbar::iconsOnly)
  43354. {
  43355. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43356. missingItemsButton->setAlwaysOnTop (true);
  43357. missingItemsButton->addButtonListener (this);
  43358. }
  43359. Toolbar::~Toolbar()
  43360. {
  43361. animator.cancelAllAnimations (true);
  43362. deleteAllChildren();
  43363. }
  43364. void Toolbar::setVertical (const bool shouldBeVertical)
  43365. {
  43366. if (vertical != shouldBeVertical)
  43367. {
  43368. vertical = shouldBeVertical;
  43369. resized();
  43370. }
  43371. }
  43372. void Toolbar::clear()
  43373. {
  43374. for (int i = items.size(); --i >= 0;)
  43375. {
  43376. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43377. items.remove (i);
  43378. delete tc;
  43379. }
  43380. resized();
  43381. }
  43382. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43383. {
  43384. if (itemId == ToolbarItemFactory::separatorBarId)
  43385. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43386. else if (itemId == ToolbarItemFactory::spacerId)
  43387. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43388. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43389. return new ToolbarSpacerComp (itemId, 0, false);
  43390. return factory.createItem (itemId);
  43391. }
  43392. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43393. const int itemId,
  43394. const int insertIndex)
  43395. {
  43396. // An ID can't be zero - this might indicate a mistake somewhere?
  43397. jassert (itemId != 0);
  43398. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43399. if (tc != 0)
  43400. {
  43401. #ifdef JUCE_DEBUG
  43402. Array <int> allowedIds;
  43403. factory.getAllToolbarItemIds (allowedIds);
  43404. // If your factory can create an item for a given ID, it must also return
  43405. // that ID from its getAllToolbarItemIds() method!
  43406. jassert (allowedIds.contains (itemId));
  43407. #endif
  43408. items.insert (insertIndex, tc);
  43409. addAndMakeVisible (tc, insertIndex);
  43410. }
  43411. }
  43412. void Toolbar::addItem (ToolbarItemFactory& factory,
  43413. const int itemId,
  43414. const int insertIndex)
  43415. {
  43416. addItemInternal (factory, itemId, insertIndex);
  43417. resized();
  43418. }
  43419. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43420. {
  43421. Array <int> ids;
  43422. factoryToUse.getDefaultItemSet (ids);
  43423. clear();
  43424. for (int i = 0; i < ids.size(); ++i)
  43425. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43426. resized();
  43427. }
  43428. void Toolbar::removeToolbarItem (const int itemIndex)
  43429. {
  43430. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43431. if (tc != 0)
  43432. {
  43433. items.removeValue (tc);
  43434. delete tc;
  43435. resized();
  43436. }
  43437. }
  43438. int Toolbar::getNumItems() const throw()
  43439. {
  43440. return items.size();
  43441. }
  43442. int Toolbar::getItemId (const int itemIndex) const throw()
  43443. {
  43444. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43445. return tc != 0 ? tc->getItemId() : 0;
  43446. }
  43447. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43448. {
  43449. return items [itemIndex];
  43450. }
  43451. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43452. {
  43453. for (;;)
  43454. {
  43455. index += delta;
  43456. ToolbarItemComponent* const tc = getItemComponent (index);
  43457. if (tc == 0)
  43458. break;
  43459. if (tc->isActive)
  43460. return tc;
  43461. }
  43462. return 0;
  43463. }
  43464. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43465. {
  43466. if (toolbarStyle != newStyle)
  43467. {
  43468. toolbarStyle = newStyle;
  43469. updateAllItemPositions (false);
  43470. }
  43471. }
  43472. const String Toolbar::toString() const
  43473. {
  43474. String s (T("TB:"));
  43475. for (int i = 0; i < getNumItems(); ++i)
  43476. s << getItemId(i) << T(' ');
  43477. return s.trimEnd();
  43478. }
  43479. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43480. const String& savedVersion)
  43481. {
  43482. if (! savedVersion.startsWith (T("TB:")))
  43483. return false;
  43484. StringArray tokens;
  43485. tokens.addTokens (savedVersion.substring (3), false);
  43486. clear();
  43487. for (int i = 0; i < tokens.size(); ++i)
  43488. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43489. resized();
  43490. return true;
  43491. }
  43492. void Toolbar::paint (Graphics& g)
  43493. {
  43494. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43495. }
  43496. int Toolbar::getThickness() const throw()
  43497. {
  43498. return vertical ? getWidth() : getHeight();
  43499. }
  43500. int Toolbar::getLength() const throw()
  43501. {
  43502. return vertical ? getHeight() : getWidth();
  43503. }
  43504. void Toolbar::setEditingActive (const bool active)
  43505. {
  43506. if (isEditingActive != active)
  43507. {
  43508. isEditingActive = active;
  43509. updateAllItemPositions (false);
  43510. }
  43511. }
  43512. void Toolbar::resized()
  43513. {
  43514. updateAllItemPositions (false);
  43515. }
  43516. void Toolbar::updateAllItemPositions (const bool animate)
  43517. {
  43518. if (getWidth() > 0 && getHeight() > 0)
  43519. {
  43520. StretchableObjectResizer resizer;
  43521. int i;
  43522. for (i = 0; i < items.size(); ++i)
  43523. {
  43524. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43525. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43526. : ToolbarItemComponent::normalMode);
  43527. tc->setStyle (toolbarStyle);
  43528. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43529. int preferredSize = 1, minSize = 1, maxSize = 1;
  43530. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43531. preferredSize, minSize, maxSize))
  43532. {
  43533. tc->isActive = true;
  43534. resizer.addItem (preferredSize, minSize, maxSize,
  43535. spacer != 0 ? spacer->getResizeOrder() : 2);
  43536. }
  43537. else
  43538. {
  43539. tc->isActive = false;
  43540. tc->setVisible (false);
  43541. }
  43542. }
  43543. resizer.resizeToFit (getLength());
  43544. int totalLength = 0;
  43545. for (i = 0; i < resizer.getNumItems(); ++i)
  43546. totalLength += (int) resizer.getItemSize (i);
  43547. const bool itemsOffTheEnd = totalLength > getLength();
  43548. const int extrasButtonSize = getThickness() / 2;
  43549. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43550. missingItemsButton->setVisible (itemsOffTheEnd);
  43551. missingItemsButton->setEnabled (! isEditingActive);
  43552. if (vertical)
  43553. missingItemsButton->setCentrePosition (getWidth() / 2,
  43554. getHeight() - 4 - extrasButtonSize / 2);
  43555. else
  43556. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43557. getHeight() / 2);
  43558. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43559. : missingItemsButton->getX()) - 4
  43560. : getLength();
  43561. int pos = 0, activeIndex = 0;
  43562. for (i = 0; i < items.size(); ++i)
  43563. {
  43564. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43565. if (tc->isActive)
  43566. {
  43567. const int size = (int) resizer.getItemSize (activeIndex++);
  43568. Rectangle<int> newBounds;
  43569. if (vertical)
  43570. newBounds.setBounds (0, pos, getWidth(), size);
  43571. else
  43572. newBounds.setBounds (pos, 0, size, getHeight());
  43573. if (animate)
  43574. {
  43575. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43576. }
  43577. else
  43578. {
  43579. animator.cancelAnimation (tc, false);
  43580. tc->setBounds (newBounds);
  43581. }
  43582. pos += size;
  43583. tc->setVisible (pos <= maxLength
  43584. && ((! tc->isBeingDragged)
  43585. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43586. }
  43587. }
  43588. }
  43589. }
  43590. void Toolbar::buttonClicked (Button*)
  43591. {
  43592. jassert (missingItemsButton->isShowing());
  43593. if (missingItemsButton->isShowing())
  43594. {
  43595. PopupMenu m;
  43596. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43597. m.showAt (missingItemsButton);
  43598. }
  43599. }
  43600. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43601. Component* /*sourceComponent*/)
  43602. {
  43603. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43604. }
  43605. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43606. {
  43607. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43608. if (tc != 0)
  43609. {
  43610. if (getNumItems() == 0)
  43611. {
  43612. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43613. {
  43614. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43615. if (palette != 0)
  43616. palette->replaceComponent (tc);
  43617. }
  43618. else
  43619. {
  43620. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43621. }
  43622. items.add (tc);
  43623. addChildComponent (tc);
  43624. updateAllItemPositions (false);
  43625. }
  43626. else
  43627. {
  43628. for (int i = getNumItems(); --i >= 0;)
  43629. {
  43630. int currentIndex = getIndexOfChildComponent (tc);
  43631. if (currentIndex < 0)
  43632. {
  43633. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43634. {
  43635. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43636. if (palette != 0)
  43637. palette->replaceComponent (tc);
  43638. }
  43639. else
  43640. {
  43641. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43642. }
  43643. items.add (tc);
  43644. addChildComponent (tc);
  43645. currentIndex = getIndexOfChildComponent (tc);
  43646. updateAllItemPositions (true);
  43647. }
  43648. int newIndex = currentIndex;
  43649. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  43650. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  43651. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  43652. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  43653. if (prev != 0)
  43654. {
  43655. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  43656. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  43657. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  43658. {
  43659. newIndex = getIndexOfChildComponent (prev);
  43660. }
  43661. }
  43662. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  43663. if (next != 0)
  43664. {
  43665. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  43666. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  43667. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  43668. {
  43669. newIndex = getIndexOfChildComponent (next) + 1;
  43670. }
  43671. }
  43672. if (newIndex != currentIndex)
  43673. {
  43674. items.removeValue (tc);
  43675. removeChildComponent (tc);
  43676. addChildComponent (tc, newIndex);
  43677. items.insert (newIndex, tc);
  43678. updateAllItemPositions (true);
  43679. }
  43680. else
  43681. {
  43682. break;
  43683. }
  43684. }
  43685. }
  43686. }
  43687. }
  43688. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  43689. {
  43690. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43691. if (tc != 0)
  43692. {
  43693. if (isParentOf (tc))
  43694. {
  43695. items.removeValue (tc);
  43696. removeChildComponent (tc);
  43697. updateAllItemPositions (true);
  43698. }
  43699. }
  43700. }
  43701. void Toolbar::itemDropped (const String&, Component*, int, int)
  43702. {
  43703. }
  43704. void Toolbar::mouseDown (const MouseEvent& e)
  43705. {
  43706. if (e.mods.isPopupMenu())
  43707. {
  43708. }
  43709. }
  43710. class ToolbarCustomisationDialog : public DialogWindow
  43711. {
  43712. public:
  43713. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  43714. Toolbar* const toolbar_,
  43715. const int optionFlags)
  43716. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  43717. toolbar (toolbar_)
  43718. {
  43719. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  43720. setResizable (true, true);
  43721. setResizeLimits (400, 300, 1500, 1000);
  43722. positionNearBar();
  43723. }
  43724. ~ToolbarCustomisationDialog()
  43725. {
  43726. setContentComponent (0, true);
  43727. }
  43728. void closeButtonPressed()
  43729. {
  43730. setVisible (false);
  43731. }
  43732. bool canModalEventBeSentToComponent (const Component* comp)
  43733. {
  43734. return toolbar->isParentOf (comp);
  43735. }
  43736. void positionNearBar()
  43737. {
  43738. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  43739. const int tbx = toolbar->getScreenX();
  43740. const int tby = toolbar->getScreenY();
  43741. const int gap = 8;
  43742. int x, y;
  43743. if (toolbar->isVertical())
  43744. {
  43745. y = tby;
  43746. if (tbx > screenSize.getCentreX())
  43747. x = tbx - getWidth() - gap;
  43748. else
  43749. x = tbx + toolbar->getWidth() + gap;
  43750. }
  43751. else
  43752. {
  43753. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  43754. if (tby > screenSize.getCentreY())
  43755. y = tby - getHeight() - gap;
  43756. else
  43757. y = tby + toolbar->getHeight() + gap;
  43758. }
  43759. setTopLeftPosition (x, y);
  43760. }
  43761. private:
  43762. Toolbar* const toolbar;
  43763. class CustomiserPanel : public Component,
  43764. private ComboBoxListener,
  43765. private ButtonListener
  43766. {
  43767. public:
  43768. CustomiserPanel (ToolbarItemFactory& factory_,
  43769. Toolbar* const toolbar_,
  43770. const int optionFlags)
  43771. : factory (factory_),
  43772. toolbar (toolbar_),
  43773. styleBox (0),
  43774. defaultButton (0)
  43775. {
  43776. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  43777. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  43778. | Toolbar::allowIconsWithTextChoice
  43779. | Toolbar::allowTextOnlyChoice)) != 0)
  43780. {
  43781. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  43782. styleBox->setEditableText (false);
  43783. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  43784. styleBox->addItem (TRANS("Show icons only"), 1);
  43785. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  43786. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  43787. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  43788. styleBox->addItem (TRANS("Show descriptions only"), 3);
  43789. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  43790. styleBox->setSelectedId (1);
  43791. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  43792. styleBox->setSelectedId (2);
  43793. else if (toolbar_->getStyle() == Toolbar::textOnly)
  43794. styleBox->setSelectedId (3);
  43795. styleBox->addListener (this);
  43796. }
  43797. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  43798. {
  43799. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  43800. defaultButton->addButtonListener (this);
  43801. }
  43802. addAndMakeVisible (instructions = new Label (String::empty,
  43803. 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.")));
  43804. instructions->setFont (Font (13.0f));
  43805. setSize (500, 300);
  43806. }
  43807. ~CustomiserPanel()
  43808. {
  43809. deleteAllChildren();
  43810. }
  43811. void comboBoxChanged (ComboBox*)
  43812. {
  43813. if (styleBox->getSelectedId() == 1)
  43814. toolbar->setStyle (Toolbar::iconsOnly);
  43815. else if (styleBox->getSelectedId() == 2)
  43816. toolbar->setStyle (Toolbar::iconsWithText);
  43817. else if (styleBox->getSelectedId() == 3)
  43818. toolbar->setStyle (Toolbar::textOnly);
  43819. palette->resized(); // to make it update the styles
  43820. }
  43821. void buttonClicked (Button*)
  43822. {
  43823. toolbar->addDefaultItems (factory);
  43824. }
  43825. void paint (Graphics& g)
  43826. {
  43827. Colour background;
  43828. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  43829. if (dw != 0)
  43830. background = dw->getBackgroundColour();
  43831. g.setColour (background.contrasting().withAlpha (0.3f));
  43832. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  43833. }
  43834. void resized()
  43835. {
  43836. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  43837. if (styleBox != 0)
  43838. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  43839. if (defaultButton != 0)
  43840. {
  43841. defaultButton->changeWidthToFitText (22);
  43842. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  43843. }
  43844. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  43845. }
  43846. private:
  43847. ToolbarItemFactory& factory;
  43848. Toolbar* const toolbar;
  43849. Label* instructions;
  43850. ToolbarItemPalette* palette;
  43851. ComboBox* styleBox;
  43852. TextButton* defaultButton;
  43853. };
  43854. };
  43855. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  43856. {
  43857. setEditingActive (true);
  43858. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  43859. dw.runModalLoop();
  43860. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  43861. setEditingActive (false);
  43862. }
  43863. END_JUCE_NAMESPACE
  43864. /*** End of inlined file: juce_Toolbar.cpp ***/
  43865. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  43866. BEGIN_JUCE_NAMESPACE
  43867. ToolbarItemFactory::ToolbarItemFactory()
  43868. {
  43869. }
  43870. ToolbarItemFactory::~ToolbarItemFactory()
  43871. {
  43872. }
  43873. class ItemDragAndDropOverlayComponent : public Component
  43874. {
  43875. public:
  43876. ItemDragAndDropOverlayComponent()
  43877. : isDragging (false)
  43878. {
  43879. setAlwaysOnTop (true);
  43880. setRepaintsOnMouseActivity (true);
  43881. setMouseCursor (MouseCursor::DraggingHandCursor);
  43882. }
  43883. ~ItemDragAndDropOverlayComponent()
  43884. {
  43885. }
  43886. void paint (Graphics& g)
  43887. {
  43888. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43889. if (isMouseOverOrDragging()
  43890. && tc != 0
  43891. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43892. {
  43893. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  43894. g.drawRect (0, 0, getWidth(), getHeight(),
  43895. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  43896. }
  43897. }
  43898. void mouseDown (const MouseEvent& e)
  43899. {
  43900. isDragging = false;
  43901. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43902. if (tc != 0)
  43903. {
  43904. tc->dragOffsetX = e.x;
  43905. tc->dragOffsetY = e.y;
  43906. }
  43907. }
  43908. void mouseDrag (const MouseEvent& e)
  43909. {
  43910. if (! (isDragging || e.mouseWasClicked()))
  43911. {
  43912. isDragging = true;
  43913. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  43914. if (dnd != 0)
  43915. {
  43916. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  43917. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43918. if (tc != 0)
  43919. {
  43920. tc->isBeingDragged = true;
  43921. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43922. tc->setVisible (false);
  43923. }
  43924. }
  43925. }
  43926. }
  43927. void mouseUp (const MouseEvent&)
  43928. {
  43929. isDragging = false;
  43930. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43931. if (tc != 0)
  43932. {
  43933. tc->isBeingDragged = false;
  43934. Toolbar* const tb = tc->getToolbar();
  43935. if (tb != 0)
  43936. tb->updateAllItemPositions (true);
  43937. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43938. delete tc;
  43939. }
  43940. }
  43941. void parentSizeChanged()
  43942. {
  43943. setBounds (0, 0, getParentWidth(), getParentHeight());
  43944. }
  43945. juce_UseDebuggingNewOperator
  43946. private:
  43947. bool isDragging;
  43948. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  43949. ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  43950. };
  43951. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  43952. const String& labelText,
  43953. const bool isBeingUsedAsAButton_)
  43954. : Button (labelText),
  43955. itemId (itemId_),
  43956. mode (normalMode),
  43957. toolbarStyle (Toolbar::iconsOnly),
  43958. dragOffsetX (0),
  43959. dragOffsetY (0),
  43960. isActive (true),
  43961. isBeingDragged (false),
  43962. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  43963. {
  43964. // Your item ID can't be 0!
  43965. jassert (itemId_ != 0);
  43966. }
  43967. ToolbarItemComponent::~ToolbarItemComponent()
  43968. {
  43969. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43970. overlayComp = 0;
  43971. }
  43972. Toolbar* ToolbarItemComponent::getToolbar() const
  43973. {
  43974. return dynamic_cast <Toolbar*> (getParentComponent());
  43975. }
  43976. bool ToolbarItemComponent::isToolbarVertical() const
  43977. {
  43978. const Toolbar* const t = getToolbar();
  43979. return t != 0 && t->isVertical();
  43980. }
  43981. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  43982. {
  43983. if (toolbarStyle != newStyle)
  43984. {
  43985. toolbarStyle = newStyle;
  43986. repaint();
  43987. resized();
  43988. }
  43989. }
  43990. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  43991. {
  43992. if (isBeingUsedAsAButton)
  43993. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  43994. isMouseOver, isMouseDown, *this);
  43995. if (toolbarStyle != Toolbar::iconsOnly)
  43996. {
  43997. const int indent = contentArea.getX();
  43998. int y = indent;
  43999. int h = getHeight() - indent * 2;
  44000. if (toolbarStyle == Toolbar::iconsWithText)
  44001. {
  44002. y = contentArea.getBottom() + indent / 2;
  44003. h -= contentArea.getHeight();
  44004. }
  44005. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  44006. getButtonText(), *this);
  44007. }
  44008. if (! contentArea.isEmpty())
  44009. {
  44010. g.saveState();
  44011. g.setOrigin (contentArea.getX(), contentArea.getY());
  44012. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  44013. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  44014. g.restoreState();
  44015. }
  44016. }
  44017. void ToolbarItemComponent::resized()
  44018. {
  44019. if (toolbarStyle != Toolbar::textOnly)
  44020. {
  44021. const int indent = jmin (proportionOfWidth (0.08f),
  44022. proportionOfHeight (0.08f));
  44023. contentArea = Rectangle<int> (indent, indent,
  44024. getWidth() - indent * 2,
  44025. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  44026. : (getHeight() - indent * 2));
  44027. }
  44028. else
  44029. {
  44030. contentArea = Rectangle<int>();
  44031. }
  44032. contentAreaChanged (contentArea);
  44033. }
  44034. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  44035. {
  44036. if (mode != newMode)
  44037. {
  44038. mode = newMode;
  44039. repaint();
  44040. if (mode == normalMode)
  44041. {
  44042. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44043. overlayComp = 0;
  44044. }
  44045. else if (overlayComp == 0)
  44046. {
  44047. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  44048. overlayComp->parentSizeChanged();
  44049. }
  44050. resized();
  44051. }
  44052. }
  44053. END_JUCE_NAMESPACE
  44054. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  44055. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  44056. BEGIN_JUCE_NAMESPACE
  44057. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  44058. Toolbar* const toolbar_)
  44059. : factory (factory_),
  44060. toolbar (toolbar_)
  44061. {
  44062. Component* const itemHolder = new Component();
  44063. Array <int> allIds;
  44064. factory_.getAllToolbarItemIds (allIds);
  44065. for (int i = 0; i < allIds.size(); ++i)
  44066. {
  44067. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  44068. jassert (tc != 0);
  44069. if (tc != 0)
  44070. {
  44071. itemHolder->addAndMakeVisible (tc);
  44072. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  44073. }
  44074. }
  44075. viewport = new Viewport();
  44076. viewport->setViewedComponent (itemHolder);
  44077. addAndMakeVisible (viewport);
  44078. }
  44079. ToolbarItemPalette::~ToolbarItemPalette()
  44080. {
  44081. viewport->getViewedComponent()->deleteAllChildren();
  44082. deleteAllChildren();
  44083. }
  44084. void ToolbarItemPalette::resized()
  44085. {
  44086. viewport->setBoundsInset (BorderSize (1));
  44087. Component* const itemHolder = viewport->getViewedComponent();
  44088. const int indent = 8;
  44089. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  44090. const int height = toolbar->getThickness();
  44091. int x = indent;
  44092. int y = indent;
  44093. int maxX = 0;
  44094. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  44095. {
  44096. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  44097. if (tc != 0)
  44098. {
  44099. tc->setStyle (toolbar->getStyle());
  44100. int preferredSize = 1, minSize = 1, maxSize = 1;
  44101. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  44102. {
  44103. if (x + preferredSize > preferredWidth && x > indent)
  44104. {
  44105. x = indent;
  44106. y += height;
  44107. }
  44108. tc->setBounds (x, y, preferredSize, height);
  44109. x += preferredSize + 8;
  44110. maxX = jmax (maxX, x);
  44111. }
  44112. }
  44113. }
  44114. itemHolder->setSize (maxX, y + height + 8);
  44115. }
  44116. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  44117. {
  44118. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  44119. jassert (tc != 0);
  44120. if (tc != 0)
  44121. {
  44122. tc->setBounds (comp->getBounds());
  44123. tc->setStyle (toolbar->getStyle());
  44124. tc->setEditingMode (comp->getEditingMode());
  44125. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  44126. }
  44127. }
  44128. END_JUCE_NAMESPACE
  44129. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  44130. /*** Start of inlined file: juce_TreeView.cpp ***/
  44131. BEGIN_JUCE_NAMESPACE
  44132. class TreeViewContentComponent : public Component,
  44133. public TooltipClient
  44134. {
  44135. public:
  44136. TreeViewContentComponent (TreeView* const owner_)
  44137. : owner (owner_),
  44138. buttonUnderMouse (0),
  44139. isDragging (false)
  44140. {
  44141. }
  44142. ~TreeViewContentComponent()
  44143. {
  44144. deleteAllChildren();
  44145. }
  44146. void mouseDown (const MouseEvent& e)
  44147. {
  44148. updateButtonUnderMouse (e);
  44149. isDragging = false;
  44150. needSelectionOnMouseUp = false;
  44151. Rectangle<int> pos;
  44152. TreeViewItem* const item = findItemAt (e.y, pos);
  44153. if (item == 0)
  44154. return;
  44155. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  44156. // as selection clicks)
  44157. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  44158. {
  44159. if (e.x >= pos.getX() - owner->getIndentSize())
  44160. item->setOpen (! item->isOpen());
  44161. // (clicks to the left of an open/close button are ignored)
  44162. }
  44163. else
  44164. {
  44165. // mouse-down inside the body of the item..
  44166. if (! owner->isMultiSelectEnabled())
  44167. item->setSelected (true, true);
  44168. else if (item->isSelected())
  44169. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  44170. else
  44171. selectBasedOnModifiers (item, e.mods);
  44172. if (e.x >= pos.getX())
  44173. item->itemClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  44174. }
  44175. }
  44176. void mouseUp (const MouseEvent& e)
  44177. {
  44178. updateButtonUnderMouse (e);
  44179. if (needSelectionOnMouseUp && e.mouseWasClicked())
  44180. {
  44181. Rectangle<int> pos;
  44182. TreeViewItem* const item = findItemAt (e.y, pos);
  44183. if (item != 0)
  44184. selectBasedOnModifiers (item, e.mods);
  44185. }
  44186. }
  44187. void mouseDoubleClick (const MouseEvent& e)
  44188. {
  44189. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  44190. {
  44191. Rectangle<int> pos;
  44192. TreeViewItem* const item = findItemAt (e.y, pos);
  44193. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  44194. item->itemDoubleClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  44195. }
  44196. }
  44197. void mouseDrag (const MouseEvent& e)
  44198. {
  44199. if (isEnabled()
  44200. && ! (isDragging || e.mouseWasClicked()
  44201. || e.getDistanceFromDragStart() < 5
  44202. || e.mods.isPopupMenu()))
  44203. {
  44204. isDragging = true;
  44205. Rectangle<int> pos;
  44206. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  44207. if (item != 0 && e.getMouseDownX() >= pos.getX())
  44208. {
  44209. const String dragDescription (item->getDragSourceDescription());
  44210. if (dragDescription.isNotEmpty())
  44211. {
  44212. DragAndDropContainer* const dragContainer
  44213. = DragAndDropContainer::findParentDragContainerFor (this);
  44214. if (dragContainer != 0)
  44215. {
  44216. pos.setSize (pos.getWidth(), item->itemHeight);
  44217. Image* dragImage = Component::createComponentSnapshot (pos, true);
  44218. dragImage->multiplyAllAlphas (0.6f);
  44219. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  44220. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  44221. }
  44222. else
  44223. {
  44224. // to be able to do a drag-and-drop operation, the treeview needs to
  44225. // be inside a component which is also a DragAndDropContainer.
  44226. jassertfalse
  44227. }
  44228. }
  44229. }
  44230. }
  44231. }
  44232. void mouseMove (const MouseEvent& e)
  44233. {
  44234. updateButtonUnderMouse (e);
  44235. }
  44236. void mouseExit (const MouseEvent& e)
  44237. {
  44238. updateButtonUnderMouse (e);
  44239. }
  44240. void paint (Graphics& g);
  44241. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  44242. static bool isMouseDraggingInChildCompOf (Component* const comp)
  44243. {
  44244. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  44245. {
  44246. MouseInputSource* source = Desktop::getInstance().getMouseSource(i);
  44247. if (source->isDragging())
  44248. {
  44249. Component* const underMouse = source->getComponentUnderMouse();
  44250. if (underMouse != 0 && (comp == underMouse || comp->isParentOf (underMouse)))
  44251. return true;
  44252. }
  44253. }
  44254. return false;
  44255. }
  44256. void updateComponents()
  44257. {
  44258. const int visibleTop = -getY();
  44259. const int visibleBottom = visibleTop + getParentHeight();
  44260. BitArray itemsToKeep;
  44261. TreeViewItem* item = owner->rootItem;
  44262. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  44263. while (item != 0 && y < visibleBottom)
  44264. {
  44265. y += item->itemHeight;
  44266. if (y >= visibleTop)
  44267. {
  44268. const int index = rowComponentIds.indexOf (item->uid);
  44269. if (index < 0)
  44270. {
  44271. Component* const comp = item->createItemComponent();
  44272. if (comp != 0)
  44273. {
  44274. addAndMakeVisible (comp);
  44275. itemsToKeep.setBit (rowComponentItems.size());
  44276. rowComponentItems.add (item);
  44277. rowComponentIds.add (item->uid);
  44278. rowComponents.add (comp);
  44279. }
  44280. }
  44281. else
  44282. {
  44283. itemsToKeep.setBit (index);
  44284. }
  44285. }
  44286. item = item->getNextVisibleItem (true);
  44287. }
  44288. for (int i = rowComponentItems.size(); --i >= 0;)
  44289. {
  44290. Component* const comp = (Component*) rowComponents.getUnchecked(i);
  44291. bool keep = false;
  44292. if (isParentOf (comp))
  44293. {
  44294. if (itemsToKeep[i])
  44295. {
  44296. const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i);
  44297. Rectangle<int> pos (item->getItemPosition (false));
  44298. pos.setSize (pos.getWidth(), item->itemHeight);
  44299. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44300. {
  44301. keep = true;
  44302. comp->setBounds (pos);
  44303. }
  44304. }
  44305. if ((! keep) && isMouseDraggingInChildCompOf (comp))
  44306. {
  44307. keep = true;
  44308. comp->setSize (0, 0);
  44309. }
  44310. }
  44311. if (! keep)
  44312. {
  44313. delete comp;
  44314. rowComponents.remove (i);
  44315. rowComponentIds.remove (i);
  44316. rowComponentItems.remove (i);
  44317. }
  44318. }
  44319. }
  44320. void updateButtonUnderMouse (const MouseEvent& e)
  44321. {
  44322. TreeViewItem* newItem = 0;
  44323. if (owner->openCloseButtonsVisible)
  44324. {
  44325. Rectangle<int> pos;
  44326. TreeViewItem* item = findItemAt (e.y, pos);
  44327. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44328. {
  44329. newItem = item;
  44330. if (! newItem->mightContainSubItems())
  44331. newItem = 0;
  44332. }
  44333. }
  44334. if (buttonUnderMouse != newItem)
  44335. {
  44336. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44337. {
  44338. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44339. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44340. }
  44341. buttonUnderMouse = newItem;
  44342. if (buttonUnderMouse != 0)
  44343. {
  44344. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44345. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44346. }
  44347. }
  44348. }
  44349. bool isMouseOverButton (TreeViewItem* item) const throw()
  44350. {
  44351. return item == buttonUnderMouse;
  44352. }
  44353. void resized()
  44354. {
  44355. owner->itemsChanged();
  44356. }
  44357. const String getTooltip()
  44358. {
  44359. Rectangle<int> pos;
  44360. TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos);
  44361. if (item != 0)
  44362. return item->getTooltip();
  44363. return owner->getTooltip();
  44364. }
  44365. juce_UseDebuggingNewOperator
  44366. private:
  44367. TreeView* const owner;
  44368. VoidArray rowComponentItems;
  44369. Array <int> rowComponentIds;
  44370. VoidArray rowComponents;
  44371. TreeViewItem* buttonUnderMouse;
  44372. bool isDragging, needSelectionOnMouseUp;
  44373. TreeViewContentComponent (const TreeViewContentComponent&);
  44374. TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44375. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44376. {
  44377. TreeViewItem* firstSelected = 0;
  44378. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44379. {
  44380. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44381. jassert (lastSelected != 0);
  44382. int rowStart = firstSelected->getRowNumberInTree();
  44383. int rowEnd = lastSelected->getRowNumberInTree();
  44384. if (rowStart > rowEnd)
  44385. swapVariables (rowStart, rowEnd);
  44386. int ourRow = item->getRowNumberInTree();
  44387. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44388. if (ourRow > otherEnd)
  44389. swapVariables (ourRow, otherEnd);
  44390. for (int i = ourRow; i <= otherEnd; ++i)
  44391. owner->getItemOnRow (i)->setSelected (true, false);
  44392. }
  44393. else
  44394. {
  44395. const bool cmd = modifiers.isCommandDown();
  44396. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44397. }
  44398. }
  44399. bool containsItem (TreeViewItem* const item) const
  44400. {
  44401. for (int i = rowComponentItems.size(); --i >= 0;)
  44402. if ((TreeViewItem*) rowComponentItems.getUnchecked (i) == item)
  44403. return true;
  44404. return false;
  44405. }
  44406. };
  44407. class TreeViewport : public Viewport
  44408. {
  44409. public:
  44410. TreeViewport() throw() {}
  44411. ~TreeViewport() throw() {}
  44412. void updateComponents()
  44413. {
  44414. if (getViewedComponent() != 0)
  44415. ((TreeViewContentComponent*) getViewedComponent())->updateComponents();
  44416. repaint();
  44417. }
  44418. void visibleAreaChanged (int, int, int, int)
  44419. {
  44420. updateComponents();
  44421. }
  44422. juce_UseDebuggingNewOperator
  44423. private:
  44424. TreeViewport (const TreeViewport&);
  44425. TreeViewport& operator= (const TreeViewport&);
  44426. };
  44427. TreeView::TreeView (const String& componentName)
  44428. : Component (componentName),
  44429. rootItem (0),
  44430. dragInsertPointHighlight (0),
  44431. dragTargetGroupHighlight (0),
  44432. indentSize (24),
  44433. defaultOpenness (false),
  44434. needsRecalculating (true),
  44435. rootItemVisible (true),
  44436. multiSelectEnabled (false),
  44437. openCloseButtonsVisible (true)
  44438. {
  44439. addAndMakeVisible (viewport = new TreeViewport());
  44440. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44441. viewport->setWantsKeyboardFocus (false);
  44442. setWantsKeyboardFocus (true);
  44443. }
  44444. TreeView::~TreeView()
  44445. {
  44446. if (rootItem != 0)
  44447. rootItem->setOwnerView (0);
  44448. deleteAllChildren();
  44449. }
  44450. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44451. {
  44452. if (rootItem != newRootItem)
  44453. {
  44454. if (newRootItem != 0)
  44455. {
  44456. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44457. if (newRootItem->ownerView != 0)
  44458. newRootItem->ownerView->setRootItem (0);
  44459. }
  44460. if (rootItem != 0)
  44461. rootItem->setOwnerView (0);
  44462. rootItem = newRootItem;
  44463. if (newRootItem != 0)
  44464. newRootItem->setOwnerView (this);
  44465. needsRecalculating = true;
  44466. handleAsyncUpdate();
  44467. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44468. {
  44469. rootItem->setOpen (false); // force a re-open
  44470. rootItem->setOpen (true);
  44471. }
  44472. }
  44473. }
  44474. void TreeView::deleteRootItem()
  44475. {
  44476. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44477. setRootItem (0);
  44478. }
  44479. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44480. {
  44481. rootItemVisible = shouldBeVisible;
  44482. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44483. {
  44484. rootItem->setOpen (false); // force a re-open
  44485. rootItem->setOpen (true);
  44486. }
  44487. itemsChanged();
  44488. }
  44489. void TreeView::colourChanged()
  44490. {
  44491. setOpaque (findColour (backgroundColourId).isOpaque());
  44492. repaint();
  44493. }
  44494. void TreeView::setIndentSize (const int newIndentSize)
  44495. {
  44496. if (indentSize != newIndentSize)
  44497. {
  44498. indentSize = newIndentSize;
  44499. resized();
  44500. }
  44501. }
  44502. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44503. {
  44504. if (defaultOpenness != isOpenByDefault)
  44505. {
  44506. defaultOpenness = isOpenByDefault;
  44507. itemsChanged();
  44508. }
  44509. }
  44510. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44511. {
  44512. multiSelectEnabled = canMultiSelect;
  44513. }
  44514. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44515. {
  44516. if (openCloseButtonsVisible != shouldBeVisible)
  44517. {
  44518. openCloseButtonsVisible = shouldBeVisible;
  44519. itemsChanged();
  44520. }
  44521. }
  44522. void TreeView::clearSelectedItems()
  44523. {
  44524. if (rootItem != 0)
  44525. rootItem->deselectAllRecursively();
  44526. }
  44527. int TreeView::getNumSelectedItems() const throw()
  44528. {
  44529. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44530. }
  44531. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44532. {
  44533. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44534. }
  44535. int TreeView::getNumRowsInTree() const
  44536. {
  44537. if (rootItem != 0)
  44538. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44539. return 0;
  44540. }
  44541. TreeViewItem* TreeView::getItemOnRow (int index) const
  44542. {
  44543. if (! rootItemVisible)
  44544. ++index;
  44545. if (rootItem != 0 && index >= 0)
  44546. return rootItem->getItemOnRow (index);
  44547. return 0;
  44548. }
  44549. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44550. {
  44551. TreeViewContentComponent* const tc = (TreeViewContentComponent*) viewport->getViewedComponent();
  44552. Rectangle<int> pos;
  44553. return tc->findItemAt (relativePositionToOtherComponent (tc, Point<int> (0, y)).getY(), pos);
  44554. }
  44555. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44556. {
  44557. if (rootItem == 0)
  44558. return 0;
  44559. return rootItem->findItemFromIdentifierString (identifierString);
  44560. }
  44561. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44562. {
  44563. XmlElement* e = 0;
  44564. if (rootItem != 0)
  44565. {
  44566. e = rootItem->getOpennessState();
  44567. if (e != 0 && alsoIncludeScrollPosition)
  44568. e->setAttribute (T("scrollPos"), viewport->getViewPositionY());
  44569. }
  44570. return e;
  44571. }
  44572. void TreeView::restoreOpennessState (const XmlElement& newState)
  44573. {
  44574. if (rootItem != 0)
  44575. {
  44576. rootItem->restoreOpennessState (newState);
  44577. if (newState.hasAttribute (T("scrollPos")))
  44578. viewport->setViewPosition (viewport->getViewPositionX(),
  44579. newState.getIntAttribute (T("scrollPos")));
  44580. }
  44581. }
  44582. void TreeView::paint (Graphics& g)
  44583. {
  44584. g.fillAll (findColour (backgroundColourId));
  44585. }
  44586. void TreeView::resized()
  44587. {
  44588. viewport->setBounds (0, 0, getWidth(), getHeight());
  44589. itemsChanged();
  44590. handleAsyncUpdate();
  44591. }
  44592. void TreeView::enablementChanged()
  44593. {
  44594. repaint();
  44595. }
  44596. void TreeView::moveSelectedRow (int delta)
  44597. {
  44598. if (delta == 0)
  44599. return;
  44600. int rowSelected = 0;
  44601. TreeViewItem* const firstSelected = getSelectedItem (0);
  44602. if (firstSelected != 0)
  44603. rowSelected = firstSelected->getRowNumberInTree();
  44604. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44605. for (;;)
  44606. {
  44607. TreeViewItem* item = getItemOnRow (rowSelected);
  44608. if (item != 0)
  44609. {
  44610. if (! item->canBeSelected())
  44611. {
  44612. // if the row we want to highlight doesn't allow it, try skipping
  44613. // to the next item..
  44614. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  44615. rowSelected + (delta < 0 ? -1 : 1));
  44616. if (rowSelected != nextRowToTry)
  44617. {
  44618. rowSelected = nextRowToTry;
  44619. continue;
  44620. }
  44621. else
  44622. {
  44623. break;
  44624. }
  44625. }
  44626. item->setSelected (true, true);
  44627. scrollToKeepItemVisible (item);
  44628. }
  44629. break;
  44630. }
  44631. }
  44632. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  44633. {
  44634. if (item != 0 && item->ownerView == this)
  44635. {
  44636. handleAsyncUpdate();
  44637. item = item->getDeepestOpenParentItem();
  44638. int y = item->y;
  44639. int viewTop = viewport->getViewPositionY();
  44640. if (y < viewTop)
  44641. {
  44642. viewport->setViewPosition (viewport->getViewPositionX(), y);
  44643. }
  44644. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  44645. {
  44646. viewport->setViewPosition (viewport->getViewPositionX(),
  44647. (y + item->itemHeight) - viewport->getViewHeight());
  44648. }
  44649. }
  44650. }
  44651. bool TreeView::keyPressed (const KeyPress& key)
  44652. {
  44653. if (key.isKeyCode (KeyPress::upKey))
  44654. {
  44655. moveSelectedRow (-1);
  44656. }
  44657. else if (key.isKeyCode (KeyPress::downKey))
  44658. {
  44659. moveSelectedRow (1);
  44660. }
  44661. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  44662. {
  44663. if (rootItem != 0)
  44664. {
  44665. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  44666. if (key.isKeyCode (KeyPress::pageUpKey))
  44667. rowsOnScreen = -rowsOnScreen;
  44668. moveSelectedRow (rowsOnScreen);
  44669. }
  44670. }
  44671. else if (key.isKeyCode (KeyPress::homeKey))
  44672. {
  44673. moveSelectedRow (-0x3fffffff);
  44674. }
  44675. else if (key.isKeyCode (KeyPress::endKey))
  44676. {
  44677. moveSelectedRow (0x3fffffff);
  44678. }
  44679. else if (key.isKeyCode (KeyPress::returnKey))
  44680. {
  44681. TreeViewItem* const firstSelected = getSelectedItem (0);
  44682. if (firstSelected != 0)
  44683. firstSelected->setOpen (! firstSelected->isOpen());
  44684. }
  44685. else if (key.isKeyCode (KeyPress::leftKey))
  44686. {
  44687. TreeViewItem* const firstSelected = getSelectedItem (0);
  44688. if (firstSelected != 0)
  44689. {
  44690. if (firstSelected->isOpen())
  44691. {
  44692. firstSelected->setOpen (false);
  44693. }
  44694. else
  44695. {
  44696. TreeViewItem* parent = firstSelected->parentItem;
  44697. if ((! rootItemVisible) && parent == rootItem)
  44698. parent = 0;
  44699. if (parent != 0)
  44700. {
  44701. parent->setSelected (true, true);
  44702. scrollToKeepItemVisible (parent);
  44703. }
  44704. }
  44705. }
  44706. }
  44707. else if (key.isKeyCode (KeyPress::rightKey))
  44708. {
  44709. TreeViewItem* const firstSelected = getSelectedItem (0);
  44710. if (firstSelected != 0)
  44711. {
  44712. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  44713. moveSelectedRow (1);
  44714. else
  44715. firstSelected->setOpen (true);
  44716. }
  44717. }
  44718. else
  44719. {
  44720. return false;
  44721. }
  44722. return true;
  44723. }
  44724. void TreeView::itemsChanged() throw()
  44725. {
  44726. needsRecalculating = true;
  44727. repaint();
  44728. triggerAsyncUpdate();
  44729. }
  44730. void TreeView::handleAsyncUpdate()
  44731. {
  44732. if (needsRecalculating)
  44733. {
  44734. needsRecalculating = false;
  44735. const ScopedLock sl (nodeAlterationLock);
  44736. if (rootItem != 0)
  44737. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  44738. ((TreeViewport*) viewport)->updateComponents();
  44739. if (rootItem != 0)
  44740. {
  44741. viewport->getViewedComponent()
  44742. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  44743. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  44744. }
  44745. else
  44746. {
  44747. viewport->getViewedComponent()->setSize (0, 0);
  44748. }
  44749. }
  44750. }
  44751. class TreeViewDragInsertPointHighlight : public Component
  44752. {
  44753. public:
  44754. TreeViewDragInsertPointHighlight()
  44755. : lastItem (0)
  44756. {
  44757. setSize (100, 12);
  44758. setAlwaysOnTop (true);
  44759. setInterceptsMouseClicks (false, false);
  44760. }
  44761. ~TreeViewDragInsertPointHighlight() {}
  44762. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  44763. {
  44764. lastItem = item;
  44765. lastIndex = insertIndex;
  44766. const int offset = getHeight() / 2;
  44767. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  44768. }
  44769. void paint (Graphics& g)
  44770. {
  44771. Path p;
  44772. const float h = (float) getHeight();
  44773. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  44774. p.startNewSubPath (h - 2.0f, h / 2.0f);
  44775. p.lineTo ((float) getWidth(), h / 2.0f);
  44776. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44777. g.strokePath (p, PathStrokeType (2.0f));
  44778. }
  44779. TreeViewItem* lastItem;
  44780. int lastIndex;
  44781. };
  44782. class TreeViewDragTargetGroupHighlight : public Component
  44783. {
  44784. public:
  44785. TreeViewDragTargetGroupHighlight()
  44786. {
  44787. setAlwaysOnTop (true);
  44788. setInterceptsMouseClicks (false, false);
  44789. }
  44790. ~TreeViewDragTargetGroupHighlight() {}
  44791. void setTargetPosition (TreeViewItem* const item) throw()
  44792. {
  44793. Rectangle<int> r (item->getItemPosition (true));
  44794. r.setHeight (item->getItemHeight());
  44795. setBounds (r);
  44796. }
  44797. void paint (Graphics& g)
  44798. {
  44799. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44800. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  44801. }
  44802. };
  44803. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  44804. {
  44805. beginDragAutoRepeat (1000 / 30);
  44806. if (dragInsertPointHighlight == 0)
  44807. {
  44808. addAndMakeVisible (dragInsertPointHighlight = new TreeViewDragInsertPointHighlight());
  44809. addAndMakeVisible (dragTargetGroupHighlight = new TreeViewDragTargetGroupHighlight());
  44810. }
  44811. ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)
  44812. ->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  44813. ((TreeViewDragTargetGroupHighlight*) dragTargetGroupHighlight)
  44814. ->setTargetPosition (item);
  44815. }
  44816. void TreeView::hideDragHighlight() throw()
  44817. {
  44818. deleteAndZero (dragInsertPointHighlight);
  44819. deleteAndZero (dragTargetGroupHighlight);
  44820. }
  44821. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  44822. const StringArray& files, const String& sourceDescription,
  44823. Component* sourceComponent) const throw()
  44824. {
  44825. insertIndex = 0;
  44826. TreeViewItem* item = getItemAt (y);
  44827. if (item == 0)
  44828. return 0;
  44829. Rectangle<int> itemPos (item->getItemPosition (true));
  44830. insertIndex = item->getIndexInParent();
  44831. const int oldY = y;
  44832. y = itemPos.getY();
  44833. if (item->getNumSubItems() == 0 || ! item->isOpen())
  44834. {
  44835. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44836. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44837. {
  44838. // Check if we're trying to drag into an empty group item..
  44839. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  44840. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  44841. {
  44842. insertIndex = 0;
  44843. x = itemPos.getX() + getIndentSize();
  44844. y = itemPos.getBottom();
  44845. return item;
  44846. }
  44847. }
  44848. }
  44849. if (oldY > itemPos.getCentreY())
  44850. {
  44851. y += item->getItemHeight();
  44852. while (item->isLastOfSiblings() && item->parentItem != 0
  44853. && item->parentItem->parentItem != 0)
  44854. {
  44855. if (x > itemPos.getX())
  44856. break;
  44857. item = item->parentItem;
  44858. itemPos = item->getItemPosition (true);
  44859. insertIndex = item->getIndexInParent();
  44860. }
  44861. ++insertIndex;
  44862. }
  44863. x = itemPos.getX();
  44864. return item->parentItem;
  44865. }
  44866. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44867. {
  44868. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  44869. int insertIndex;
  44870. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44871. if (item != 0)
  44872. {
  44873. if (scrolled || dragInsertPointHighlight == 0
  44874. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastItem != item
  44875. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastIndex != insertIndex)
  44876. {
  44877. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44878. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44879. showDragHighlight (item, insertIndex, x, y);
  44880. else
  44881. hideDragHighlight();
  44882. }
  44883. }
  44884. else
  44885. {
  44886. hideDragHighlight();
  44887. }
  44888. }
  44889. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44890. {
  44891. hideDragHighlight();
  44892. int insertIndex;
  44893. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44894. if (item != 0)
  44895. {
  44896. if (files.size() > 0)
  44897. {
  44898. if (item->isInterestedInFileDrag (files))
  44899. item->filesDropped (files, insertIndex);
  44900. }
  44901. else
  44902. {
  44903. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44904. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  44905. }
  44906. }
  44907. }
  44908. bool TreeView::isInterestedInFileDrag (const StringArray&)
  44909. {
  44910. return true;
  44911. }
  44912. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  44913. {
  44914. fileDragMove (files, x, y);
  44915. }
  44916. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  44917. {
  44918. handleDrag (files, String::empty, 0, x, y);
  44919. }
  44920. void TreeView::fileDragExit (const StringArray&)
  44921. {
  44922. hideDragHighlight();
  44923. }
  44924. void TreeView::filesDropped (const StringArray& files, int x, int y)
  44925. {
  44926. handleDrop (files, String::empty, 0, x, y);
  44927. }
  44928. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44929. {
  44930. return true;
  44931. }
  44932. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44933. {
  44934. itemDragMove (sourceDescription, sourceComponent, x, y);
  44935. }
  44936. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44937. {
  44938. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  44939. }
  44940. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44941. {
  44942. hideDragHighlight();
  44943. }
  44944. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44945. {
  44946. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  44947. }
  44948. void TreeViewContentComponent::paint (Graphics& g)
  44949. {
  44950. if (owner->rootItem != 0)
  44951. {
  44952. owner->handleAsyncUpdate();
  44953. if (! owner->rootItemVisible)
  44954. g.setOrigin (0, -owner->rootItem->itemHeight);
  44955. owner->rootItem->paintRecursively (g, getWidth());
  44956. }
  44957. }
  44958. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  44959. {
  44960. if (owner->rootItem != 0)
  44961. {
  44962. owner->handleAsyncUpdate();
  44963. if (! owner->rootItemVisible)
  44964. y += owner->rootItem->itemHeight;
  44965. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  44966. if (ti != 0)
  44967. itemPosition = ti->getItemPosition (false);
  44968. return ti;
  44969. }
  44970. return 0;
  44971. }
  44972. enum TreeViewOpenness
  44973. {
  44974. opennessDefault = 0,
  44975. opennessClosed = 1,
  44976. opennessOpen = 2
  44977. };
  44978. TreeViewItem::TreeViewItem()
  44979. : ownerView (0),
  44980. parentItem (0),
  44981. y (0),
  44982. itemHeight (0),
  44983. totalHeight (0),
  44984. selected (false),
  44985. redrawNeeded (true),
  44986. drawLinesInside (true),
  44987. drawsInLeftMargin (false),
  44988. openness (opennessDefault)
  44989. {
  44990. static int nextUID = 0;
  44991. uid = nextUID++;
  44992. }
  44993. TreeViewItem::~TreeViewItem()
  44994. {
  44995. }
  44996. const String TreeViewItem::getUniqueName() const
  44997. {
  44998. return String::empty;
  44999. }
  45000. void TreeViewItem::itemOpennessChanged (bool)
  45001. {
  45002. }
  45003. int TreeViewItem::getNumSubItems() const throw()
  45004. {
  45005. return subItems.size();
  45006. }
  45007. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  45008. {
  45009. return subItems [index];
  45010. }
  45011. void TreeViewItem::clearSubItems()
  45012. {
  45013. if (subItems.size() > 0)
  45014. {
  45015. if (ownerView != 0)
  45016. {
  45017. const ScopedLock sl (ownerView->nodeAlterationLock);
  45018. subItems.clear();
  45019. treeHasChanged();
  45020. }
  45021. else
  45022. {
  45023. subItems.clear();
  45024. }
  45025. }
  45026. }
  45027. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  45028. {
  45029. if (newItem != 0)
  45030. {
  45031. newItem->parentItem = this;
  45032. newItem->setOwnerView (ownerView);
  45033. newItem->y = 0;
  45034. newItem->itemHeight = newItem->getItemHeight();
  45035. newItem->totalHeight = 0;
  45036. newItem->itemWidth = newItem->getItemWidth();
  45037. newItem->totalWidth = 0;
  45038. if (ownerView != 0)
  45039. {
  45040. const ScopedLock sl (ownerView->nodeAlterationLock);
  45041. subItems.insert (insertPosition, newItem);
  45042. treeHasChanged();
  45043. if (newItem->isOpen())
  45044. newItem->itemOpennessChanged (true);
  45045. }
  45046. else
  45047. {
  45048. subItems.insert (insertPosition, newItem);
  45049. if (newItem->isOpen())
  45050. newItem->itemOpennessChanged (true);
  45051. }
  45052. }
  45053. }
  45054. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  45055. {
  45056. if (ownerView != 0)
  45057. {
  45058. const ScopedLock sl (ownerView->nodeAlterationLock);
  45059. if (((unsigned int) index) < (unsigned int) subItems.size())
  45060. {
  45061. subItems.remove (index, deleteItem);
  45062. treeHasChanged();
  45063. }
  45064. }
  45065. else
  45066. {
  45067. subItems.remove (index, deleteItem);
  45068. }
  45069. }
  45070. bool TreeViewItem::isOpen() const throw()
  45071. {
  45072. if (openness == opennessDefault)
  45073. return ownerView != 0 && ownerView->defaultOpenness;
  45074. else
  45075. return openness == opennessOpen;
  45076. }
  45077. void TreeViewItem::setOpen (const bool shouldBeOpen)
  45078. {
  45079. if (isOpen() != shouldBeOpen)
  45080. {
  45081. openness = shouldBeOpen ? opennessOpen
  45082. : opennessClosed;
  45083. treeHasChanged();
  45084. itemOpennessChanged (isOpen());
  45085. }
  45086. }
  45087. bool TreeViewItem::isSelected() const throw()
  45088. {
  45089. return selected;
  45090. }
  45091. void TreeViewItem::deselectAllRecursively()
  45092. {
  45093. setSelected (false, false);
  45094. for (int i = 0; i < subItems.size(); ++i)
  45095. subItems.getUnchecked(i)->deselectAllRecursively();
  45096. }
  45097. void TreeViewItem::setSelected (const bool shouldBeSelected,
  45098. const bool deselectOtherItemsFirst)
  45099. {
  45100. if (shouldBeSelected && ! canBeSelected())
  45101. return;
  45102. if (deselectOtherItemsFirst)
  45103. getTopLevelItem()->deselectAllRecursively();
  45104. if (shouldBeSelected != selected)
  45105. {
  45106. selected = shouldBeSelected;
  45107. if (ownerView != 0)
  45108. ownerView->repaint();
  45109. itemSelectionChanged (shouldBeSelected);
  45110. }
  45111. }
  45112. void TreeViewItem::paintItem (Graphics&, int, int)
  45113. {
  45114. }
  45115. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  45116. {
  45117. ownerView->getLookAndFeel()
  45118. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  45119. }
  45120. void TreeViewItem::itemClicked (const MouseEvent&)
  45121. {
  45122. }
  45123. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  45124. {
  45125. if (mightContainSubItems())
  45126. setOpen (! isOpen());
  45127. }
  45128. void TreeViewItem::itemSelectionChanged (bool)
  45129. {
  45130. }
  45131. const String TreeViewItem::getTooltip()
  45132. {
  45133. return String::empty;
  45134. }
  45135. const String TreeViewItem::getDragSourceDescription()
  45136. {
  45137. return String::empty;
  45138. }
  45139. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  45140. {
  45141. return false;
  45142. }
  45143. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  45144. {
  45145. }
  45146. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45147. {
  45148. return false;
  45149. }
  45150. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  45151. {
  45152. }
  45153. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  45154. {
  45155. const int indentX = getIndentX();
  45156. int width = itemWidth;
  45157. if (ownerView != 0 && width < 0)
  45158. width = ownerView->viewport->getViewWidth() - indentX;
  45159. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  45160. if (relativeToTreeViewTopLeft)
  45161. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  45162. r.getY() - ownerView->viewport->getViewPositionY());
  45163. return r;
  45164. }
  45165. void TreeViewItem::treeHasChanged() const throw()
  45166. {
  45167. if (ownerView != 0)
  45168. ownerView->itemsChanged();
  45169. }
  45170. void TreeViewItem::repaintItem() const
  45171. {
  45172. if (ownerView != 0 && areAllParentsOpen())
  45173. {
  45174. const Rectangle<int> r (getItemPosition (true));
  45175. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  45176. }
  45177. }
  45178. bool TreeViewItem::areAllParentsOpen() const throw()
  45179. {
  45180. return parentItem == 0
  45181. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  45182. }
  45183. void TreeViewItem::updatePositions (int newY)
  45184. {
  45185. y = newY;
  45186. itemHeight = getItemHeight();
  45187. totalHeight = itemHeight;
  45188. itemWidth = getItemWidth();
  45189. totalWidth = jmax (itemWidth, 0) + getIndentX();
  45190. if (isOpen())
  45191. {
  45192. newY += totalHeight;
  45193. for (int i = 0; i < subItems.size(); ++i)
  45194. {
  45195. TreeViewItem* const ti = subItems.getUnchecked(i);
  45196. ti->updatePositions (newY);
  45197. newY += ti->totalHeight;
  45198. totalHeight += ti->totalHeight;
  45199. totalWidth = jmax (totalWidth, ti->totalWidth);
  45200. }
  45201. }
  45202. }
  45203. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  45204. {
  45205. TreeViewItem* result = this;
  45206. TreeViewItem* item = this;
  45207. while (item->parentItem != 0)
  45208. {
  45209. item = item->parentItem;
  45210. if (! item->isOpen())
  45211. result = item;
  45212. }
  45213. return result;
  45214. }
  45215. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  45216. {
  45217. ownerView = newOwner;
  45218. for (int i = subItems.size(); --i >= 0;)
  45219. subItems.getUnchecked(i)->setOwnerView (newOwner);
  45220. }
  45221. int TreeViewItem::getIndentX() const throw()
  45222. {
  45223. const int indentWidth = ownerView->getIndentSize();
  45224. int x = ownerView->rootItemVisible ? indentWidth : 0;
  45225. if (! ownerView->openCloseButtonsVisible)
  45226. x -= indentWidth;
  45227. TreeViewItem* p = parentItem;
  45228. while (p != 0)
  45229. {
  45230. x += indentWidth;
  45231. p = p->parentItem;
  45232. }
  45233. return x;
  45234. }
  45235. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  45236. {
  45237. drawsInLeftMargin = canDrawInLeftMargin;
  45238. }
  45239. void TreeViewItem::paintRecursively (Graphics& g, int width)
  45240. {
  45241. jassert (ownerView != 0);
  45242. if (ownerView == 0)
  45243. return;
  45244. const int indent = getIndentX();
  45245. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  45246. g.setColour (ownerView->findColour (TreeView::linesColourId));
  45247. const float halfH = itemHeight * 0.5f;
  45248. int depth = 0;
  45249. TreeViewItem* p = parentItem;
  45250. while (p != 0)
  45251. {
  45252. ++depth;
  45253. p = p->parentItem;
  45254. }
  45255. if (! ownerView->rootItemVisible)
  45256. --depth;
  45257. const int indentWidth = ownerView->getIndentSize();
  45258. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  45259. {
  45260. float x = (depth + 0.5f) * indentWidth;
  45261. if (depth >= 0)
  45262. {
  45263. if (parentItem != 0 && parentItem->drawLinesInside)
  45264. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45265. if ((parentItem != 0 && parentItem->drawLinesInside)
  45266. || (parentItem == 0 && drawLinesInside))
  45267. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45268. }
  45269. p = parentItem;
  45270. int d = depth;
  45271. while (p != 0 && --d >= 0)
  45272. {
  45273. x -= (float) indentWidth;
  45274. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45275. && ! p->isLastOfSiblings())
  45276. {
  45277. g.drawLine (x, 0, x, (float) itemHeight);
  45278. }
  45279. p = p->parentItem;
  45280. }
  45281. if (mightContainSubItems())
  45282. {
  45283. g.saveState();
  45284. g.setOrigin (depth * indentWidth, 0);
  45285. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45286. paintOpenCloseButton (g, indentWidth, itemHeight,
  45287. ((TreeViewContentComponent*) ownerView->viewport->getViewedComponent())
  45288. ->isMouseOverButton (this));
  45289. g.restoreState();
  45290. }
  45291. }
  45292. {
  45293. g.saveState();
  45294. g.setOrigin (indent, 0);
  45295. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45296. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45297. paintItem (g, itemW, itemHeight);
  45298. g.restoreState();
  45299. }
  45300. if (isOpen())
  45301. {
  45302. const Rectangle<int> clip (g.getClipBounds());
  45303. for (int i = 0; i < subItems.size(); ++i)
  45304. {
  45305. TreeViewItem* const ti = subItems.getUnchecked(i);
  45306. const int relY = ti->y - y;
  45307. if (relY >= clip.getBottom())
  45308. break;
  45309. if (relY + ti->totalHeight >= clip.getY())
  45310. {
  45311. g.saveState();
  45312. g.setOrigin (0, relY);
  45313. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45314. ti->paintRecursively (g, width);
  45315. g.restoreState();
  45316. }
  45317. }
  45318. }
  45319. }
  45320. bool TreeViewItem::isLastOfSiblings() const throw()
  45321. {
  45322. return parentItem == 0
  45323. || parentItem->subItems.getLast() == this;
  45324. }
  45325. int TreeViewItem::getIndexInParent() const throw()
  45326. {
  45327. if (parentItem == 0)
  45328. return 0;
  45329. return parentItem->subItems.indexOf (this);
  45330. }
  45331. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45332. {
  45333. return (parentItem == 0) ? this
  45334. : parentItem->getTopLevelItem();
  45335. }
  45336. int TreeViewItem::getNumRows() const throw()
  45337. {
  45338. int num = 1;
  45339. if (isOpen())
  45340. {
  45341. for (int i = subItems.size(); --i >= 0;)
  45342. num += subItems.getUnchecked(i)->getNumRows();
  45343. }
  45344. return num;
  45345. }
  45346. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45347. {
  45348. if (index == 0)
  45349. return this;
  45350. if (index > 0 && isOpen())
  45351. {
  45352. --index;
  45353. for (int i = 0; i < subItems.size(); ++i)
  45354. {
  45355. TreeViewItem* const item = subItems.getUnchecked(i);
  45356. if (index == 0)
  45357. return item;
  45358. const int numRows = item->getNumRows();
  45359. if (numRows > index)
  45360. return item->getItemOnRow (index);
  45361. index -= numRows;
  45362. }
  45363. }
  45364. return 0;
  45365. }
  45366. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45367. {
  45368. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45369. {
  45370. const int h = itemHeight;
  45371. if (targetY < h)
  45372. return this;
  45373. if (isOpen())
  45374. {
  45375. targetY -= h;
  45376. for (int i = 0; i < subItems.size(); ++i)
  45377. {
  45378. TreeViewItem* const ti = subItems.getUnchecked(i);
  45379. if (targetY < ti->totalHeight)
  45380. return ti->findItemRecursively (targetY);
  45381. targetY -= ti->totalHeight;
  45382. }
  45383. }
  45384. }
  45385. return 0;
  45386. }
  45387. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45388. {
  45389. int total = 0;
  45390. if (isSelected())
  45391. ++total;
  45392. for (int i = subItems.size(); --i >= 0;)
  45393. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45394. return total;
  45395. }
  45396. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45397. {
  45398. if (isSelected())
  45399. {
  45400. if (index == 0)
  45401. return this;
  45402. --index;
  45403. }
  45404. if (index >= 0)
  45405. {
  45406. for (int i = 0; i < subItems.size(); ++i)
  45407. {
  45408. TreeViewItem* const item = subItems.getUnchecked(i);
  45409. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45410. if (found != 0)
  45411. return found;
  45412. index -= item->countSelectedItemsRecursively();
  45413. }
  45414. }
  45415. return 0;
  45416. }
  45417. int TreeViewItem::getRowNumberInTree() const throw()
  45418. {
  45419. if (parentItem != 0 && ownerView != 0)
  45420. {
  45421. int n = 1 + parentItem->getRowNumberInTree();
  45422. int ourIndex = parentItem->subItems.indexOf (this);
  45423. jassert (ourIndex >= 0);
  45424. while (--ourIndex >= 0)
  45425. n += parentItem->subItems [ourIndex]->getNumRows();
  45426. if (parentItem->parentItem == 0
  45427. && ! ownerView->rootItemVisible)
  45428. --n;
  45429. return n;
  45430. }
  45431. else
  45432. {
  45433. return 0;
  45434. }
  45435. }
  45436. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45437. {
  45438. drawLinesInside = drawLines;
  45439. }
  45440. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45441. {
  45442. if (recurse && isOpen() && subItems.size() > 0)
  45443. return subItems [0];
  45444. if (parentItem != 0)
  45445. {
  45446. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45447. if (nextIndex >= parentItem->subItems.size())
  45448. return parentItem->getNextVisibleItem (false);
  45449. return parentItem->subItems [nextIndex];
  45450. }
  45451. return 0;
  45452. }
  45453. const String TreeViewItem::getItemIdentifierString() const
  45454. {
  45455. String s;
  45456. if (parentItem != 0)
  45457. s = parentItem->getItemIdentifierString();
  45458. return s + T("/") + getUniqueName().replaceCharacter (T('/'), T('\\'));
  45459. }
  45460. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45461. {
  45462. const String uid (getUniqueName());
  45463. if (uid == identifierString)
  45464. return this;
  45465. if (identifierString.startsWith (uid + T("/")))
  45466. {
  45467. const String remainingPath (identifierString.substring (uid.length() + 1));
  45468. bool wasOpen = isOpen();
  45469. setOpen (true);
  45470. for (int i = subItems.size(); --i >= 0;)
  45471. {
  45472. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45473. if (item != 0)
  45474. return item;
  45475. }
  45476. setOpen (wasOpen);
  45477. }
  45478. return 0;
  45479. }
  45480. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45481. {
  45482. if (e.hasTagName (T("CLOSED")))
  45483. {
  45484. setOpen (false);
  45485. }
  45486. else if (e.hasTagName (T("OPEN")))
  45487. {
  45488. setOpen (true);
  45489. forEachXmlChildElement (e, n)
  45490. {
  45491. const String id (n->getStringAttribute (T("id")));
  45492. for (int i = 0; i < subItems.size(); ++i)
  45493. {
  45494. TreeViewItem* const ti = subItems.getUnchecked(i);
  45495. if (ti->getUniqueName() == id)
  45496. {
  45497. ti->restoreOpennessState (*n);
  45498. break;
  45499. }
  45500. }
  45501. }
  45502. }
  45503. }
  45504. XmlElement* TreeViewItem::getOpennessState() const throw()
  45505. {
  45506. const String name (getUniqueName());
  45507. if (name.isNotEmpty())
  45508. {
  45509. XmlElement* e;
  45510. if (isOpen())
  45511. {
  45512. e = new XmlElement (T("OPEN"));
  45513. for (int i = 0; i < subItems.size(); ++i)
  45514. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45515. }
  45516. else
  45517. {
  45518. e = new XmlElement (T("CLOSED"));
  45519. }
  45520. e->setAttribute (T("id"), name);
  45521. return e;
  45522. }
  45523. else
  45524. {
  45525. // trying to save the openness for an element that has no name - this won't
  45526. // work because it needs the names to identify what to open.
  45527. jassertfalse
  45528. }
  45529. return 0;
  45530. }
  45531. END_JUCE_NAMESPACE
  45532. /*** End of inlined file: juce_TreeView.cpp ***/
  45533. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45534. BEGIN_JUCE_NAMESPACE
  45535. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45536. : fileList (listToShow)
  45537. {
  45538. }
  45539. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45540. {
  45541. }
  45542. FileBrowserListener::~FileBrowserListener()
  45543. {
  45544. }
  45545. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener) throw()
  45546. {
  45547. listeners.add (listener);
  45548. }
  45549. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener) throw()
  45550. {
  45551. listeners.remove (listener);
  45552. }
  45553. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45554. {
  45555. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45556. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45557. }
  45558. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45559. {
  45560. if (fileList.getDirectory().exists())
  45561. {
  45562. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45563. listeners.callChecked (checker, &FileBrowserListener::fileClicked, file, e);
  45564. }
  45565. }
  45566. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45567. {
  45568. if (fileList.getDirectory().exists())
  45569. {
  45570. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45571. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, file);
  45572. }
  45573. }
  45574. END_JUCE_NAMESPACE
  45575. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45576. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45577. BEGIN_JUCE_NAMESPACE
  45578. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45579. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45580. Time* creationTime, bool* isReadOnly);
  45581. bool juce_findFileNext (void* handle, String& resultFile,
  45582. bool* isDirectory, bool* isHidden, int64* fileSize,
  45583. Time* modTime, Time* creationTime, bool* isReadOnly);
  45584. void juce_findFileClose (void* handle);
  45585. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45586. TimeSliceThread& thread_)
  45587. : fileFilter (fileFilter_),
  45588. thread (thread_),
  45589. includeDirectories (false),
  45590. includeFiles (false),
  45591. ignoreHiddenFiles (true),
  45592. fileFindHandle (0),
  45593. shouldStop (true)
  45594. {
  45595. }
  45596. DirectoryContentsList::~DirectoryContentsList()
  45597. {
  45598. clear();
  45599. }
  45600. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  45601. {
  45602. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  45603. }
  45604. const File& DirectoryContentsList::getDirectory() const
  45605. {
  45606. return root;
  45607. }
  45608. void DirectoryContentsList::setDirectory (const File& directory,
  45609. const bool includeDirectories_,
  45610. const bool includeFiles_)
  45611. {
  45612. if (directory != root
  45613. || includeDirectories != includeDirectories_
  45614. || includeFiles != includeFiles_)
  45615. {
  45616. clear();
  45617. root = directory;
  45618. includeDirectories = includeDirectories_;
  45619. includeFiles = includeFiles_;
  45620. refresh();
  45621. }
  45622. }
  45623. void DirectoryContentsList::clear()
  45624. {
  45625. shouldStop = true;
  45626. thread.removeTimeSliceClient (this);
  45627. if (fileFindHandle != 0)
  45628. {
  45629. juce_findFileClose (fileFindHandle);
  45630. fileFindHandle = 0;
  45631. }
  45632. if (files.size() > 0)
  45633. {
  45634. files.clear();
  45635. changed();
  45636. }
  45637. }
  45638. void DirectoryContentsList::refresh()
  45639. {
  45640. clear();
  45641. if (root.isDirectory())
  45642. {
  45643. String fileFound;
  45644. bool fileFoundIsDir, isHidden, isReadOnly;
  45645. int64 fileSize;
  45646. Time modTime, creationTime;
  45647. String path (root.getFullPathName());
  45648. if (! path.endsWithChar (File::separator))
  45649. path += File::separator;
  45650. jassert (fileFindHandle == 0);
  45651. fileFindHandle = juce_findFileStart (path, T("*"), fileFound,
  45652. &fileFoundIsDir,
  45653. &isHidden,
  45654. &fileSize,
  45655. &modTime,
  45656. &creationTime,
  45657. &isReadOnly);
  45658. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  45659. {
  45660. if (addFile (fileFound, fileFoundIsDir, isHidden,
  45661. fileSize, modTime, creationTime, isReadOnly))
  45662. {
  45663. changed();
  45664. }
  45665. }
  45666. shouldStop = false;
  45667. thread.addTimeSliceClient (this);
  45668. }
  45669. }
  45670. int DirectoryContentsList::getNumFiles() const
  45671. {
  45672. return files.size();
  45673. }
  45674. bool DirectoryContentsList::getFileInfo (const int index,
  45675. FileInfo& result) const
  45676. {
  45677. const ScopedLock sl (fileListLock);
  45678. const FileInfo* const info = files [index];
  45679. if (info != 0)
  45680. {
  45681. result = *info;
  45682. return true;
  45683. }
  45684. return false;
  45685. }
  45686. const File DirectoryContentsList::getFile (const int index) const
  45687. {
  45688. const ScopedLock sl (fileListLock);
  45689. const FileInfo* const info = files [index];
  45690. if (info != 0)
  45691. return root.getChildFile (info->filename);
  45692. return File::nonexistent;
  45693. }
  45694. bool DirectoryContentsList::isStillLoading() const
  45695. {
  45696. return fileFindHandle != 0;
  45697. }
  45698. void DirectoryContentsList::changed()
  45699. {
  45700. sendChangeMessage (this);
  45701. }
  45702. bool DirectoryContentsList::useTimeSlice()
  45703. {
  45704. const uint32 startTime = Time::getApproximateMillisecondCounter();
  45705. bool hasChanged = false;
  45706. for (int i = 100; --i >= 0;)
  45707. {
  45708. if (! checkNextFile (hasChanged))
  45709. {
  45710. if (hasChanged)
  45711. changed();
  45712. return false;
  45713. }
  45714. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  45715. break;
  45716. }
  45717. if (hasChanged)
  45718. changed();
  45719. return true;
  45720. }
  45721. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  45722. {
  45723. if (fileFindHandle != 0)
  45724. {
  45725. String fileFound;
  45726. bool fileFoundIsDir, isHidden, isReadOnly;
  45727. int64 fileSize;
  45728. Time modTime, creationTime;
  45729. if (juce_findFileNext (fileFindHandle, fileFound,
  45730. &fileFoundIsDir, &isHidden,
  45731. &fileSize,
  45732. &modTime,
  45733. &creationTime,
  45734. &isReadOnly))
  45735. {
  45736. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  45737. modTime, creationTime, isReadOnly))
  45738. {
  45739. hasChanged = true;
  45740. }
  45741. return true;
  45742. }
  45743. else
  45744. {
  45745. juce_findFileClose (fileFindHandle);
  45746. fileFindHandle = 0;
  45747. }
  45748. }
  45749. return false;
  45750. }
  45751. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  45752. const DirectoryContentsList::FileInfo* const second)
  45753. {
  45754. #if JUCE_WINDOWS
  45755. if (first->isDirectory != second->isDirectory)
  45756. return first->isDirectory ? -1 : 1;
  45757. #endif
  45758. return first->filename.compareIgnoreCase (second->filename);
  45759. }
  45760. bool DirectoryContentsList::addFile (const String& filename,
  45761. const bool isDir,
  45762. const bool isHidden,
  45763. const int64 fileSize,
  45764. const Time& modTime,
  45765. const Time& creationTime,
  45766. const bool isReadOnly)
  45767. {
  45768. if (filename == T("..")
  45769. || filename == T(".")
  45770. || (ignoreHiddenFiles && isHidden))
  45771. return false;
  45772. const File file (root.getChildFile (filename));
  45773. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  45774. && (fileFilter == 0
  45775. || ((! isDir) && fileFilter->isFileSuitable (file))
  45776. || (isDir && fileFilter->isDirectorySuitable (file))))
  45777. {
  45778. ScopedPointer <FileInfo> info (new FileInfo());
  45779. info->filename = filename;
  45780. info->fileSize = fileSize;
  45781. info->modificationTime = modTime;
  45782. info->creationTime = creationTime;
  45783. info->isDirectory = isDir;
  45784. info->isReadOnly = isReadOnly;
  45785. const ScopedLock sl (fileListLock);
  45786. for (int i = files.size(); --i >= 0;)
  45787. if (files.getUnchecked(i)->filename == info->filename)
  45788. return false;
  45789. files.addSorted (*this, info.release());
  45790. return true;
  45791. }
  45792. return false;
  45793. }
  45794. END_JUCE_NAMESPACE
  45795. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  45796. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  45797. BEGIN_JUCE_NAMESPACE
  45798. FileBrowserComponent::FileBrowserComponent (int flags_,
  45799. const File& initialFileOrDirectory,
  45800. const FileFilter* fileFilter_,
  45801. FilePreviewComponent* previewComp_)
  45802. : FileFilter (String::empty),
  45803. fileFilter (fileFilter_),
  45804. flags (flags_),
  45805. previewComp (previewComp_),
  45806. thread ("Juce FileBrowser")
  45807. {
  45808. // You need to specify one or other of the open/save flags..
  45809. jassert ((flags & (saveMode | openMode)) != 0);
  45810. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  45811. // You need to specify at least one of these flags..
  45812. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  45813. String filename;
  45814. if (initialFileOrDirectory == File::nonexistent)
  45815. {
  45816. currentRoot = File::getCurrentWorkingDirectory();
  45817. }
  45818. else if (initialFileOrDirectory.isDirectory())
  45819. {
  45820. currentRoot = initialFileOrDirectory;
  45821. }
  45822. else
  45823. {
  45824. chosenFiles.add (initialFileOrDirectory);
  45825. currentRoot = initialFileOrDirectory.getParentDirectory();
  45826. filename = initialFileOrDirectory.getFileName();
  45827. }
  45828. fileList = new DirectoryContentsList (this, thread);
  45829. if ((flags & useTreeView) != 0)
  45830. {
  45831. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  45832. if ((flags & canSelectMultipleItems) != 0)
  45833. tree->setMultiSelectEnabled (true);
  45834. addAndMakeVisible (tree);
  45835. fileListComponent = tree;
  45836. }
  45837. else
  45838. {
  45839. FileListComponent* const list = new FileListComponent (*fileList);
  45840. list->setOutlineThickness (1);
  45841. if ((flags & canSelectMultipleItems) != 0)
  45842. list->setMultipleSelectionEnabled (true);
  45843. addAndMakeVisible (list);
  45844. fileListComponent = list;
  45845. }
  45846. fileListComponent->addListener (this);
  45847. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  45848. currentPathBox->setEditableText (true);
  45849. StringArray rootNames, rootPaths;
  45850. const BitArray separators (getRoots (rootNames, rootPaths));
  45851. for (int i = 0; i < rootNames.size(); ++i)
  45852. {
  45853. if (separators [i])
  45854. currentPathBox->addSeparator();
  45855. currentPathBox->addItem (rootNames[i], i + 1);
  45856. }
  45857. currentPathBox->addSeparator();
  45858. currentPathBox->addListener (this);
  45859. addAndMakeVisible (filenameBox = new TextEditor());
  45860. filenameBox->setMultiLine (false);
  45861. filenameBox->setSelectAllWhenFocused (true);
  45862. filenameBox->setText (filename, false);
  45863. filenameBox->addListener (this);
  45864. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  45865. Label* label = new Label ("f", TRANS("file:"));
  45866. addAndMakeVisible (label);
  45867. label->attachToComponent (filenameBox, true);
  45868. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  45869. goUpButton->addButtonListener (this);
  45870. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  45871. if (previewComp != 0)
  45872. addAndMakeVisible (previewComp);
  45873. setRoot (currentRoot);
  45874. thread.startThread (4);
  45875. }
  45876. FileBrowserComponent::~FileBrowserComponent()
  45877. {
  45878. if (previewComp != 0)
  45879. removeChildComponent (previewComp);
  45880. deleteAllChildren();
  45881. fileList = 0;
  45882. thread.stopThread (10000);
  45883. }
  45884. void FileBrowserComponent::addListener (FileBrowserListener* const newListener) throw()
  45885. {
  45886. listeners.add (newListener);
  45887. }
  45888. void FileBrowserComponent::removeListener (FileBrowserListener* const listener) throw()
  45889. {
  45890. listeners.remove (listener);
  45891. }
  45892. bool FileBrowserComponent::isSaveMode() const throw()
  45893. {
  45894. return (flags & saveMode) != 0;
  45895. }
  45896. int FileBrowserComponent::getNumSelectedFiles() const throw()
  45897. {
  45898. if (chosenFiles.size() == 0 && currentFileIsValid())
  45899. return 1;
  45900. return chosenFiles.size();
  45901. }
  45902. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  45903. {
  45904. if (! filenameBox->isReadOnly())
  45905. return currentRoot.getChildFile (filenameBox->getText());
  45906. else
  45907. return chosenFiles[index];
  45908. }
  45909. bool FileBrowserComponent::currentFileIsValid() const
  45910. {
  45911. if (isSaveMode())
  45912. return ! getSelectedFile (0).isDirectory();
  45913. else
  45914. return getSelectedFile (0).exists();
  45915. }
  45916. const File FileBrowserComponent::getHighlightedFile() const throw()
  45917. {
  45918. return fileListComponent->getSelectedFile (0);
  45919. }
  45920. bool FileBrowserComponent::isFileSuitable (const File& file) const
  45921. {
  45922. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  45923. : false;
  45924. }
  45925. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  45926. {
  45927. return true;
  45928. }
  45929. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  45930. {
  45931. if (f.isDirectory())
  45932. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  45933. return (flags & canSelectFiles) != 0 && f.exists()
  45934. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  45935. }
  45936. const File FileBrowserComponent::getRoot() const
  45937. {
  45938. return currentRoot;
  45939. }
  45940. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  45941. {
  45942. if (currentRoot != newRootDirectory)
  45943. {
  45944. fileListComponent->scrollToTop();
  45945. String path (newRootDirectory.getFullPathName());
  45946. if (path.isEmpty())
  45947. path += File::separator;
  45948. StringArray rootNames, rootPaths;
  45949. getRoots (rootNames, rootPaths);
  45950. if (! rootPaths.contains (path, true))
  45951. {
  45952. bool alreadyListed = false;
  45953. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  45954. {
  45955. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  45956. {
  45957. alreadyListed = true;
  45958. break;
  45959. }
  45960. }
  45961. if (! alreadyListed)
  45962. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  45963. }
  45964. }
  45965. currentRoot = newRootDirectory;
  45966. fileList->setDirectory (currentRoot, true, true);
  45967. String currentRootName (currentRoot.getFullPathName());
  45968. if (currentRootName.isEmpty())
  45969. currentRootName += File::separator;
  45970. currentPathBox->setText (currentRootName, true);
  45971. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  45972. && currentRoot.getParentDirectory() != currentRoot);
  45973. }
  45974. void FileBrowserComponent::goUp()
  45975. {
  45976. setRoot (getRoot().getParentDirectory());
  45977. }
  45978. void FileBrowserComponent::refresh()
  45979. {
  45980. fileList->refresh();
  45981. }
  45982. const String FileBrowserComponent::getActionVerb() const
  45983. {
  45984. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  45985. }
  45986. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  45987. {
  45988. return previewComp;
  45989. }
  45990. void FileBrowserComponent::resized()
  45991. {
  45992. getLookAndFeel()
  45993. .layoutFileBrowserComponent (*this, fileListComponent,
  45994. previewComp, currentPathBox,
  45995. filenameBox, goUpButton);
  45996. }
  45997. void FileBrowserComponent::sendListenerChangeMessage()
  45998. {
  45999. Component::BailOutChecker checker (this);
  46000. if (previewComp != 0)
  46001. previewComp->selectedFileChanged (getSelectedFile (0));
  46002. // You shouldn't delete the browser when the file gets changed!
  46003. jassert (! checker.shouldBailOut());
  46004. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  46005. }
  46006. void FileBrowserComponent::selectionChanged()
  46007. {
  46008. StringArray newFilenames;
  46009. bool resetChosenFiles = true;
  46010. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  46011. {
  46012. const File f (fileListComponent->getSelectedFile (i));
  46013. if (isFileOrDirSuitable (f))
  46014. {
  46015. if (resetChosenFiles)
  46016. {
  46017. chosenFiles.clear();
  46018. resetChosenFiles = false;
  46019. }
  46020. chosenFiles.add (f);
  46021. newFilenames.add (f.getRelativePathFrom (getRoot()));
  46022. }
  46023. }
  46024. if (newFilenames.size() > 0)
  46025. filenameBox->setText (newFilenames.joinIntoString (T(", ")), false);
  46026. sendListenerChangeMessage();
  46027. }
  46028. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  46029. {
  46030. Component::BailOutChecker checker (this);
  46031. listeners.callChecked (checker, &FileBrowserListener::fileClicked, f, e);
  46032. }
  46033. void FileBrowserComponent::fileDoubleClicked (const File& f)
  46034. {
  46035. if (f.isDirectory())
  46036. {
  46037. setRoot (f);
  46038. }
  46039. else
  46040. {
  46041. Component::BailOutChecker checker (this);
  46042. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, f);
  46043. }
  46044. }
  46045. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  46046. {
  46047. #if JUCE_LINUX || JUCE_WINDOWS
  46048. if (key.getModifiers().isCommandDown()
  46049. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  46050. {
  46051. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  46052. fileList->refresh();
  46053. return true;
  46054. }
  46055. #endif
  46056. return false;
  46057. }
  46058. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  46059. {
  46060. sendListenerChangeMessage();
  46061. }
  46062. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  46063. {
  46064. if (filenameBox->getText().containsChar (File::separator))
  46065. {
  46066. const File f (currentRoot.getChildFile (filenameBox->getText()));
  46067. if (f.isDirectory())
  46068. {
  46069. setRoot (f);
  46070. chosenFiles.clear();
  46071. filenameBox->setText (String::empty);
  46072. }
  46073. else
  46074. {
  46075. setRoot (f.getParentDirectory());
  46076. chosenFiles.clear();
  46077. chosenFiles.add (f);
  46078. filenameBox->setText (f.getFileName());
  46079. }
  46080. }
  46081. else
  46082. {
  46083. fileDoubleClicked (getSelectedFile (0));
  46084. }
  46085. }
  46086. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  46087. {
  46088. }
  46089. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  46090. {
  46091. if (! isSaveMode())
  46092. selectionChanged();
  46093. }
  46094. void FileBrowserComponent::buttonClicked (Button*)
  46095. {
  46096. goUp();
  46097. }
  46098. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  46099. {
  46100. const String newText (currentPathBox->getText().trim().unquoted());
  46101. if (newText.isNotEmpty())
  46102. {
  46103. const int index = currentPathBox->getSelectedId() - 1;
  46104. StringArray rootNames, rootPaths;
  46105. getRoots (rootNames, rootPaths);
  46106. if (rootPaths [index].isNotEmpty())
  46107. {
  46108. setRoot (File (rootPaths [index]));
  46109. }
  46110. else
  46111. {
  46112. File f (newText);
  46113. for (;;)
  46114. {
  46115. if (f.isDirectory())
  46116. {
  46117. setRoot (f);
  46118. break;
  46119. }
  46120. if (f.getParentDirectory() == f)
  46121. break;
  46122. f = f.getParentDirectory();
  46123. }
  46124. }
  46125. }
  46126. }
  46127. const BitArray FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  46128. {
  46129. BitArray separators;
  46130. #if JUCE_WINDOWS
  46131. Array<File> roots;
  46132. File::findFileSystemRoots (roots);
  46133. rootPaths.clear();
  46134. for (int i = 0; i < roots.size(); ++i)
  46135. {
  46136. const File& drive = roots.getReference(i);
  46137. String name (drive.getFullPathName());
  46138. rootPaths.add (name);
  46139. if (drive.isOnHardDisk())
  46140. {
  46141. String volume (drive.getVolumeLabel());
  46142. if (volume.isEmpty())
  46143. volume = TRANS("Hard Drive");
  46144. name << " [" << drive.getVolumeLabel() << ']';
  46145. }
  46146. else if (drive.isOnCDRomDrive())
  46147. {
  46148. name << TRANS(" [CD/DVD drive]");
  46149. }
  46150. rootNames.add (name);
  46151. }
  46152. separators.setBit (rootPaths.size());
  46153. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46154. rootNames.add ("Documents");
  46155. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46156. rootNames.add ("Desktop");
  46157. #endif
  46158. #if JUCE_MAC
  46159. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46160. rootNames.add ("Home folder");
  46161. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46162. rootNames.add ("Documents");
  46163. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46164. rootNames.add ("Desktop");
  46165. separators.setBit (rootPaths.size());
  46166. Array <File> volumes;
  46167. File vol ("/Volumes");
  46168. vol.findChildFiles (volumes, File::findDirectories, false);
  46169. for (int i = 0; i < volumes.size(); ++i)
  46170. {
  46171. const File& volume = volumes.getReference(i);
  46172. if (volume.isDirectory() && ! volume.getFileName().startsWithChar (T('.')))
  46173. {
  46174. rootPaths.add (volume.getFullPathName());
  46175. rootNames.add (volume.getFileName());
  46176. }
  46177. }
  46178. #endif
  46179. #if JUCE_LINUX
  46180. rootPaths.add ("/");
  46181. rootNames.add ("/");
  46182. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46183. rootNames.add ("Home folder");
  46184. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46185. rootNames.add ("Desktop");
  46186. #endif
  46187. return separators;
  46188. }
  46189. END_JUCE_NAMESPACE
  46190. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  46191. /*** Start of inlined file: juce_FileChooser.cpp ***/
  46192. BEGIN_JUCE_NAMESPACE
  46193. FileChooser::FileChooser (const String& chooserBoxTitle,
  46194. const File& currentFileOrDirectory,
  46195. const String& fileFilters,
  46196. const bool useNativeDialogBox_)
  46197. : title (chooserBoxTitle),
  46198. filters (fileFilters),
  46199. startingFile (currentFileOrDirectory),
  46200. useNativeDialogBox (useNativeDialogBox_)
  46201. {
  46202. #if JUCE_LINUX
  46203. useNativeDialogBox = false;
  46204. #endif
  46205. if (! fileFilters.containsNonWhitespaceChars())
  46206. filters = T("*");
  46207. }
  46208. FileChooser::~FileChooser()
  46209. {
  46210. }
  46211. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  46212. {
  46213. return showDialog (false, true, false, false, false, previewComponent);
  46214. }
  46215. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  46216. {
  46217. return showDialog (false, true, false, false, true, previewComponent);
  46218. }
  46219. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  46220. {
  46221. return showDialog (true, true, false, false, true, previewComponent);
  46222. }
  46223. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  46224. {
  46225. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  46226. }
  46227. bool FileChooser::browseForDirectory()
  46228. {
  46229. return showDialog (true, false, false, false, false, 0);
  46230. }
  46231. const File FileChooser::getResult() const
  46232. {
  46233. // if you've used a multiple-file select, you should use the getResults() method
  46234. // to retrieve all the files that were chosen.
  46235. jassert (results.size() <= 1);
  46236. return results.getFirst();
  46237. }
  46238. const Array<File>& FileChooser::getResults() const
  46239. {
  46240. return results;
  46241. }
  46242. bool FileChooser::showDialog (const bool selectsDirectories,
  46243. const bool selectsFiles,
  46244. const bool isSave,
  46245. const bool warnAboutOverwritingExistingFiles,
  46246. const bool selectMultipleFiles,
  46247. FilePreviewComponent* const previewComponent)
  46248. {
  46249. Component::SafePointer<Component> previouslyFocused (Component::getCurrentlyFocusedComponent());
  46250. results.clear();
  46251. // the preview component needs to be the right size before you pass it in here..
  46252. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  46253. && previewComponent->getHeight() > 10));
  46254. #if JUCE_WINDOWS
  46255. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  46256. #elif JUCE_MAC
  46257. if (useNativeDialogBox && (previewComponent == 0))
  46258. #else
  46259. if (false)
  46260. #endif
  46261. {
  46262. showPlatformDialog (results, title, startingFile, filters,
  46263. selectsDirectories, selectsFiles, isSave,
  46264. warnAboutOverwritingExistingFiles,
  46265. selectMultipleFiles,
  46266. previewComponent);
  46267. }
  46268. else
  46269. {
  46270. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46271. selectsDirectories ? "*" : String::empty,
  46272. String::empty);
  46273. int flags = isSave ? FileBrowserComponent::saveMode
  46274. : FileBrowserComponent::openMode;
  46275. if (selectsFiles)
  46276. flags |= FileBrowserComponent::canSelectFiles;
  46277. if (selectsDirectories)
  46278. flags |= FileBrowserComponent::canSelectDirectories;
  46279. if (selectMultipleFiles)
  46280. flags |= FileBrowserComponent::canSelectMultipleItems;
  46281. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46282. FileChooserDialogBox box (title, String::empty,
  46283. browserComponent,
  46284. warnAboutOverwritingExistingFiles,
  46285. browserComponent.findColour (AlertWindow::backgroundColourId));
  46286. if (box.show())
  46287. {
  46288. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46289. results.add (browserComponent.getSelectedFile (i));
  46290. }
  46291. }
  46292. if (previouslyFocused != 0)
  46293. previouslyFocused->grabKeyboardFocus();
  46294. return results.size() > 0;
  46295. }
  46296. FilePreviewComponent::FilePreviewComponent()
  46297. {
  46298. }
  46299. FilePreviewComponent::~FilePreviewComponent()
  46300. {
  46301. }
  46302. END_JUCE_NAMESPACE
  46303. /*** End of inlined file: juce_FileChooser.cpp ***/
  46304. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  46305. BEGIN_JUCE_NAMESPACE
  46306. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46307. const String& instructions,
  46308. FileBrowserComponent& chooserComponent,
  46309. const bool warnAboutOverwritingExistingFiles_,
  46310. const Colour& backgroundColour)
  46311. : ResizableWindow (name, backgroundColour, true),
  46312. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46313. {
  46314. content = new ContentComponent();
  46315. content->setName (name);
  46316. content->instructions = instructions;
  46317. content->chooserComponent = &chooserComponent;
  46318. content->addAndMakeVisible (&chooserComponent);
  46319. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46320. content->addAndMakeVisible (content->okButton);
  46321. content->okButton->addButtonListener (this);
  46322. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46323. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46324. content->cancelButton = new TextButton (TRANS("Cancel"));
  46325. content->addAndMakeVisible (content->cancelButton);
  46326. content->cancelButton->addButtonListener (this);
  46327. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46328. setContentComponent (content);
  46329. setResizable (true, true);
  46330. setResizeLimits (300, 300, 1200, 1000);
  46331. content->chooserComponent->addListener (this);
  46332. }
  46333. FileChooserDialogBox::~FileChooserDialogBox()
  46334. {
  46335. content->chooserComponent->removeListener (this);
  46336. }
  46337. bool FileChooserDialogBox::show (int w, int h)
  46338. {
  46339. if (w <= 0)
  46340. {
  46341. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46342. if (previewComp != 0)
  46343. w = 400 + previewComp->getWidth();
  46344. else
  46345. w = 600;
  46346. }
  46347. if (h <= 0)
  46348. h = 500;
  46349. centreWithSize (w, h);
  46350. const bool ok = (runModalLoop() != 0);
  46351. setVisible (false);
  46352. return ok;
  46353. }
  46354. void FileChooserDialogBox::buttonClicked (Button* button)
  46355. {
  46356. if (button == content->okButton)
  46357. {
  46358. if (warnAboutOverwritingExistingFiles
  46359. && content->chooserComponent->isSaveMode()
  46360. && content->chooserComponent->getSelectedFile(0).exists())
  46361. {
  46362. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46363. TRANS("File already exists"),
  46364. TRANS("There's already a file called:\n\n")
  46365. + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46366. + T("\n\nAre you sure you want to overwrite it?"),
  46367. TRANS("overwrite"),
  46368. TRANS("cancel")))
  46369. {
  46370. return;
  46371. }
  46372. }
  46373. exitModalState (1);
  46374. }
  46375. else if (button == content->cancelButton)
  46376. closeButtonPressed();
  46377. }
  46378. void FileChooserDialogBox::closeButtonPressed()
  46379. {
  46380. setVisible (false);
  46381. }
  46382. void FileChooserDialogBox::selectionChanged()
  46383. {
  46384. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46385. }
  46386. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46387. {
  46388. }
  46389. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46390. {
  46391. selectionChanged();
  46392. content->okButton->triggerClick();
  46393. }
  46394. FileChooserDialogBox::ContentComponent::ContentComponent()
  46395. {
  46396. setInterceptsMouseClicks (false, true);
  46397. }
  46398. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46399. {
  46400. delete okButton;
  46401. delete cancelButton;
  46402. }
  46403. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46404. {
  46405. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46406. text.draw (g);
  46407. }
  46408. void FileChooserDialogBox::ContentComponent::resized()
  46409. {
  46410. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46411. float left, top, right, bottom;
  46412. text.getBoundingBox (0, text.getNumGlyphs(), left, top, right, bottom, false);
  46413. const int y = roundToInt (bottom) + 10;
  46414. const int buttonHeight = 26;
  46415. const int buttonY = getHeight() - buttonHeight - 8;
  46416. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46417. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46418. proportionOfWidth (0.2f), buttonHeight);
  46419. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46420. proportionOfWidth (0.2f), buttonHeight);
  46421. }
  46422. END_JUCE_NAMESPACE
  46423. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46424. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46425. BEGIN_JUCE_NAMESPACE
  46426. FileFilter::FileFilter (const String& filterDescription)
  46427. : description (filterDescription)
  46428. {
  46429. }
  46430. FileFilter::~FileFilter()
  46431. {
  46432. }
  46433. const String& FileFilter::getDescription() const throw()
  46434. {
  46435. return description;
  46436. }
  46437. END_JUCE_NAMESPACE
  46438. /*** End of inlined file: juce_FileFilter.cpp ***/
  46439. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46440. BEGIN_JUCE_NAMESPACE
  46441. Image* juce_createIconForFile (const File& file);
  46442. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46443. : ListBox (String::empty, 0),
  46444. DirectoryContentsDisplayComponent (listToShow)
  46445. {
  46446. setModel (this);
  46447. fileList.addChangeListener (this);
  46448. }
  46449. FileListComponent::~FileListComponent()
  46450. {
  46451. fileList.removeChangeListener (this);
  46452. deleteAllChildren();
  46453. }
  46454. int FileListComponent::getNumSelectedFiles() const
  46455. {
  46456. return getNumSelectedRows();
  46457. }
  46458. const File FileListComponent::getSelectedFile (int index) const
  46459. {
  46460. return fileList.getFile (getSelectedRow (index));
  46461. }
  46462. void FileListComponent::scrollToTop()
  46463. {
  46464. getVerticalScrollBar()->setCurrentRangeStart (0);
  46465. }
  46466. void FileListComponent::changeListenerCallback (void*)
  46467. {
  46468. updateContent();
  46469. if (lastDirectory != fileList.getDirectory())
  46470. {
  46471. lastDirectory = fileList.getDirectory();
  46472. deselectAllRows();
  46473. }
  46474. }
  46475. class FileListItemComponent : public Component,
  46476. public TimeSliceClient,
  46477. public AsyncUpdater
  46478. {
  46479. public:
  46480. FileListItemComponent (FileListComponent& owner_,
  46481. TimeSliceThread& thread_) throw()
  46482. : owner (owner_),
  46483. thread (thread_),
  46484. icon (0)
  46485. {
  46486. }
  46487. ~FileListItemComponent() throw()
  46488. {
  46489. thread.removeTimeSliceClient (this);
  46490. clearIcon();
  46491. }
  46492. void paint (Graphics& g)
  46493. {
  46494. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46495. file.getFileName(),
  46496. icon,
  46497. fileSize, modTime,
  46498. isDirectory, highlighted,
  46499. index);
  46500. }
  46501. void mouseDown (const MouseEvent& e)
  46502. {
  46503. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46504. owner.sendMouseClickMessage (file, e);
  46505. }
  46506. void mouseDoubleClick (const MouseEvent&)
  46507. {
  46508. owner.sendDoubleClickMessage (file);
  46509. }
  46510. void update (const File& root,
  46511. const DirectoryContentsList::FileInfo* const fileInfo,
  46512. const int index_,
  46513. const bool highlighted_) throw()
  46514. {
  46515. thread.removeTimeSliceClient (this);
  46516. if (highlighted_ != highlighted
  46517. || index_ != index)
  46518. {
  46519. index = index_;
  46520. highlighted = highlighted_;
  46521. repaint();
  46522. }
  46523. File newFile;
  46524. String newFileSize;
  46525. String newModTime;
  46526. if (fileInfo != 0)
  46527. {
  46528. newFile = root.getChildFile (fileInfo->filename);
  46529. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46530. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46531. }
  46532. if (newFile != file
  46533. || fileSize != newFileSize
  46534. || modTime != newModTime)
  46535. {
  46536. file = newFile;
  46537. fileSize = newFileSize;
  46538. modTime = newModTime;
  46539. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46540. repaint();
  46541. clearIcon();
  46542. }
  46543. if (file != File::nonexistent
  46544. && icon == 0 && ! isDirectory)
  46545. {
  46546. updateIcon (true);
  46547. if (icon == 0)
  46548. thread.addTimeSliceClient (this);
  46549. }
  46550. }
  46551. bool useTimeSlice()
  46552. {
  46553. updateIcon (false);
  46554. return false;
  46555. }
  46556. void handleAsyncUpdate()
  46557. {
  46558. repaint();
  46559. }
  46560. juce_UseDebuggingNewOperator
  46561. private:
  46562. FileListComponent& owner;
  46563. TimeSliceThread& thread;
  46564. bool highlighted;
  46565. int index;
  46566. File file;
  46567. String fileSize;
  46568. String modTime;
  46569. Image* icon;
  46570. bool isDirectory;
  46571. void clearIcon() throw()
  46572. {
  46573. ImageCache::release (icon);
  46574. icon = 0;
  46575. }
  46576. void updateIcon (const bool onlyUpdateIfCached) throw()
  46577. {
  46578. if (icon == 0)
  46579. {
  46580. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  46581. Image* im = ImageCache::getFromHashCode (hashCode);
  46582. if (im == 0 && ! onlyUpdateIfCached)
  46583. {
  46584. im = juce_createIconForFile (file);
  46585. if (im != 0)
  46586. ImageCache::addImageToCache (im, hashCode);
  46587. }
  46588. if (im != 0)
  46589. {
  46590. icon = im;
  46591. triggerAsyncUpdate();
  46592. }
  46593. }
  46594. }
  46595. };
  46596. int FileListComponent::getNumRows()
  46597. {
  46598. return fileList.getNumFiles();
  46599. }
  46600. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  46601. {
  46602. }
  46603. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  46604. {
  46605. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  46606. if (comp == 0)
  46607. {
  46608. delete existingComponentToUpdate;
  46609. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  46610. }
  46611. DirectoryContentsList::FileInfo fileInfo;
  46612. if (fileList.getFileInfo (row, fileInfo))
  46613. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  46614. else
  46615. comp->update (fileList.getDirectory(), 0, row, isSelected);
  46616. return comp;
  46617. }
  46618. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  46619. {
  46620. sendSelectionChangeMessage();
  46621. }
  46622. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  46623. {
  46624. }
  46625. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  46626. {
  46627. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  46628. }
  46629. END_JUCE_NAMESPACE
  46630. /*** End of inlined file: juce_FileListComponent.cpp ***/
  46631. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  46632. BEGIN_JUCE_NAMESPACE
  46633. FilenameComponent::FilenameComponent (const String& name,
  46634. const File& currentFile,
  46635. const bool canEditFilename,
  46636. const bool isDirectory,
  46637. const bool isForSaving,
  46638. const String& fileBrowserWildcard,
  46639. const String& enforcedSuffix_,
  46640. const String& textWhenNothingSelected)
  46641. : Component (name),
  46642. maxRecentFiles (30),
  46643. isDir (isDirectory),
  46644. isSaving (isForSaving),
  46645. isFileDragOver (false),
  46646. wildcard (fileBrowserWildcard),
  46647. enforcedSuffix (enforcedSuffix_)
  46648. {
  46649. addAndMakeVisible (filenameBox = new ComboBox (T("fn")));
  46650. filenameBox->setEditableText (canEditFilename);
  46651. filenameBox->addListener (this);
  46652. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  46653. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  46654. browseButton = 0;
  46655. setBrowseButtonText (T("..."));
  46656. setCurrentFile (currentFile, true);
  46657. }
  46658. FilenameComponent::~FilenameComponent()
  46659. {
  46660. deleteAllChildren();
  46661. }
  46662. void FilenameComponent::paintOverChildren (Graphics& g)
  46663. {
  46664. if (isFileDragOver)
  46665. {
  46666. g.setColour (Colours::red.withAlpha (0.2f));
  46667. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  46668. }
  46669. }
  46670. void FilenameComponent::resized()
  46671. {
  46672. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  46673. }
  46674. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  46675. {
  46676. browseButtonText = newBrowseButtonText;
  46677. lookAndFeelChanged();
  46678. }
  46679. void FilenameComponent::lookAndFeelChanged()
  46680. {
  46681. deleteAndZero (browseButton);
  46682. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  46683. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  46684. resized();
  46685. browseButton->addButtonListener (this);
  46686. }
  46687. void FilenameComponent::setTooltip (const String& newTooltip)
  46688. {
  46689. SettableTooltipClient::setTooltip (newTooltip);
  46690. filenameBox->setTooltip (newTooltip);
  46691. }
  46692. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  46693. {
  46694. defaultBrowseFile = newDefaultDirectory;
  46695. }
  46696. void FilenameComponent::buttonClicked (Button*)
  46697. {
  46698. FileChooser fc (TRANS("Choose a new file"),
  46699. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  46700. : getCurrentFile(),
  46701. wildcard);
  46702. if (isDir ? fc.browseForDirectory()
  46703. : (isSaving ? fc.browseForFileToSave (false)
  46704. : fc.browseForFileToOpen()))
  46705. {
  46706. setCurrentFile (fc.getResult(), true);
  46707. }
  46708. }
  46709. void FilenameComponent::comboBoxChanged (ComboBox*)
  46710. {
  46711. setCurrentFile (getCurrentFile(), true);
  46712. }
  46713. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  46714. {
  46715. return true;
  46716. }
  46717. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  46718. {
  46719. isFileDragOver = false;
  46720. repaint();
  46721. const File f (filenames[0]);
  46722. if (f.exists() && (f.isDirectory() == isDir))
  46723. setCurrentFile (f, true);
  46724. }
  46725. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  46726. {
  46727. isFileDragOver = true;
  46728. repaint();
  46729. }
  46730. void FilenameComponent::fileDragExit (const StringArray&)
  46731. {
  46732. isFileDragOver = false;
  46733. repaint();
  46734. }
  46735. const File FilenameComponent::getCurrentFile() const
  46736. {
  46737. File f (filenameBox->getText());
  46738. if (enforcedSuffix.isNotEmpty())
  46739. f = f.withFileExtension (enforcedSuffix);
  46740. return f;
  46741. }
  46742. void FilenameComponent::setCurrentFile (File newFile,
  46743. const bool addToRecentlyUsedList,
  46744. const bool sendChangeNotification)
  46745. {
  46746. if (enforcedSuffix.isNotEmpty())
  46747. newFile = newFile.withFileExtension (enforcedSuffix);
  46748. if (newFile.getFullPathName() != lastFilename)
  46749. {
  46750. lastFilename = newFile.getFullPathName();
  46751. if (addToRecentlyUsedList)
  46752. addRecentlyUsedFile (newFile);
  46753. filenameBox->setText (lastFilename, true);
  46754. if (sendChangeNotification)
  46755. triggerAsyncUpdate();
  46756. }
  46757. }
  46758. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  46759. {
  46760. filenameBox->setEditableText (shouldBeEditable);
  46761. }
  46762. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  46763. {
  46764. StringArray names;
  46765. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  46766. names.add (filenameBox->getItemText (i));
  46767. return names;
  46768. }
  46769. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  46770. {
  46771. if (filenames != getRecentlyUsedFilenames())
  46772. {
  46773. filenameBox->clear();
  46774. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  46775. filenameBox->addItem (filenames[i], i + 1);
  46776. }
  46777. }
  46778. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  46779. {
  46780. maxRecentFiles = jmax (1, newMaximum);
  46781. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  46782. }
  46783. void FilenameComponent::addRecentlyUsedFile (const File& file)
  46784. {
  46785. StringArray files (getRecentlyUsedFilenames());
  46786. if (file.getFullPathName().isNotEmpty())
  46787. {
  46788. files.removeString (file.getFullPathName(), true);
  46789. files.insert (0, file.getFullPathName());
  46790. setRecentlyUsedFilenames (files);
  46791. }
  46792. }
  46793. void FilenameComponent::addListener (FilenameComponentListener* const listener) throw()
  46794. {
  46795. listeners.add (listener);
  46796. }
  46797. void FilenameComponent::removeListener (FilenameComponentListener* const listener) throw()
  46798. {
  46799. listeners.remove (listener);
  46800. }
  46801. void FilenameComponent::handleAsyncUpdate()
  46802. {
  46803. Component::BailOutChecker checker (this);
  46804. listeners.callChecked (checker, &FilenameComponentListener::filenameComponentChanged, this);
  46805. }
  46806. END_JUCE_NAMESPACE
  46807. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  46808. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46809. BEGIN_JUCE_NAMESPACE
  46810. FileSearchPathListComponent::FileSearchPathListComponent()
  46811. {
  46812. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  46813. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  46814. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  46815. listBox->setOutlineThickness (1);
  46816. addAndMakeVisible (addButton = new TextButton ("+"));
  46817. addButton->addButtonListener (this);
  46818. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46819. addAndMakeVisible (removeButton = new TextButton ("-"));
  46820. removeButton->addButtonListener (this);
  46821. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46822. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  46823. changeButton->addButtonListener (this);
  46824. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46825. upButton->addButtonListener (this);
  46826. {
  46827. Path arrowPath;
  46828. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  46829. DrawablePath arrowImage;
  46830. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46831. arrowImage.setPath (arrowPath);
  46832. ((DrawableButton*) upButton)->setImages (&arrowImage);
  46833. }
  46834. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46835. downButton->addButtonListener (this);
  46836. {
  46837. Path arrowPath;
  46838. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  46839. DrawablePath arrowImage;
  46840. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46841. arrowImage.setPath (arrowPath);
  46842. ((DrawableButton*) downButton)->setImages (&arrowImage);
  46843. }
  46844. updateButtons();
  46845. }
  46846. FileSearchPathListComponent::~FileSearchPathListComponent()
  46847. {
  46848. deleteAllChildren();
  46849. }
  46850. void FileSearchPathListComponent::updateButtons() throw()
  46851. {
  46852. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  46853. removeButton->setEnabled (anythingSelected);
  46854. changeButton->setEnabled (anythingSelected);
  46855. upButton->setEnabled (anythingSelected);
  46856. downButton->setEnabled (anythingSelected);
  46857. }
  46858. void FileSearchPathListComponent::changed() throw()
  46859. {
  46860. listBox->updateContent();
  46861. listBox->repaint();
  46862. updateButtons();
  46863. }
  46864. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  46865. {
  46866. if (newPath.toString() != path.toString())
  46867. {
  46868. path = newPath;
  46869. changed();
  46870. }
  46871. }
  46872. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  46873. {
  46874. defaultBrowseTarget = newDefaultDirectory;
  46875. }
  46876. int FileSearchPathListComponent::getNumRows()
  46877. {
  46878. return path.getNumPaths();
  46879. }
  46880. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  46881. {
  46882. if (rowIsSelected)
  46883. g.fillAll (findColour (TextEditor::highlightColourId));
  46884. g.setColour (findColour (ListBox::textColourId));
  46885. Font f (height * 0.7f);
  46886. f.setHorizontalScale (0.9f);
  46887. g.setFont (f);
  46888. g.drawText (path [rowNumber].getFullPathName(),
  46889. 4, 0, width - 6, height,
  46890. Justification::centredLeft, true);
  46891. }
  46892. void FileSearchPathListComponent::deleteKeyPressed (int row)
  46893. {
  46894. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  46895. {
  46896. path.remove (row);
  46897. changed();
  46898. }
  46899. }
  46900. void FileSearchPathListComponent::returnKeyPressed (int row)
  46901. {
  46902. FileChooser chooser (TRANS("Change folder..."), path [row], T("*"));
  46903. if (chooser.browseForDirectory())
  46904. {
  46905. path.remove (row);
  46906. path.add (chooser.getResult(), row);
  46907. changed();
  46908. }
  46909. }
  46910. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  46911. {
  46912. returnKeyPressed (row);
  46913. }
  46914. void FileSearchPathListComponent::selectedRowsChanged (int)
  46915. {
  46916. updateButtons();
  46917. }
  46918. void FileSearchPathListComponent::paint (Graphics& g)
  46919. {
  46920. g.fillAll (findColour (backgroundColourId));
  46921. }
  46922. void FileSearchPathListComponent::resized()
  46923. {
  46924. const int buttonH = 22;
  46925. const int buttonY = getHeight() - buttonH - 4;
  46926. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  46927. addButton->setBounds (2, buttonY, buttonH, buttonH);
  46928. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  46929. ((TextButton*) changeButton)->changeWidthToFitText (buttonH);
  46930. downButton->setSize (buttonH * 2, buttonH);
  46931. upButton->setSize (buttonH * 2, buttonH);
  46932. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  46933. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  46934. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  46935. }
  46936. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  46937. {
  46938. return true;
  46939. }
  46940. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  46941. {
  46942. for (int i = filenames.size(); --i >= 0;)
  46943. {
  46944. const File f (filenames[i]);
  46945. if (f.isDirectory())
  46946. {
  46947. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  46948. path.add (f, row);
  46949. changed();
  46950. }
  46951. }
  46952. }
  46953. void FileSearchPathListComponent::buttonClicked (Button* button)
  46954. {
  46955. const int currentRow = listBox->getSelectedRow();
  46956. if (button == removeButton)
  46957. {
  46958. deleteKeyPressed (currentRow);
  46959. }
  46960. else if (button == addButton)
  46961. {
  46962. File start (defaultBrowseTarget);
  46963. if (start == File::nonexistent)
  46964. start = path [0];
  46965. if (start == File::nonexistent)
  46966. start = File::getCurrentWorkingDirectory();
  46967. FileChooser chooser (TRANS("Add a folder..."), start, T("*"));
  46968. if (chooser.browseForDirectory())
  46969. {
  46970. path.add (chooser.getResult(), currentRow);
  46971. }
  46972. }
  46973. else if (button == changeButton)
  46974. {
  46975. returnKeyPressed (currentRow);
  46976. }
  46977. else if (button == upButton)
  46978. {
  46979. if (currentRow > 0 && currentRow < path.getNumPaths())
  46980. {
  46981. const File f (path[currentRow]);
  46982. path.remove (currentRow);
  46983. path.add (f, currentRow - 1);
  46984. listBox->selectRow (currentRow - 1);
  46985. }
  46986. }
  46987. else if (button == downButton)
  46988. {
  46989. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  46990. {
  46991. const File f (path[currentRow]);
  46992. path.remove (currentRow);
  46993. path.add (f, currentRow + 1);
  46994. listBox->selectRow (currentRow + 1);
  46995. }
  46996. }
  46997. changed();
  46998. }
  46999. END_JUCE_NAMESPACE
  47000. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  47001. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  47002. BEGIN_JUCE_NAMESPACE
  47003. Image* juce_createIconForFile (const File& file);
  47004. class FileListTreeItem : public TreeViewItem,
  47005. public TimeSliceClient,
  47006. public AsyncUpdater,
  47007. public ChangeListener
  47008. {
  47009. public:
  47010. FileListTreeItem (FileTreeComponent& owner_,
  47011. DirectoryContentsList* const parentContentsList_,
  47012. const int indexInContentsList_,
  47013. const File& file_,
  47014. TimeSliceThread& thread_) throw()
  47015. : file (file_),
  47016. owner (owner_),
  47017. parentContentsList (parentContentsList_),
  47018. indexInContentsList (indexInContentsList_),
  47019. subContentsList (0),
  47020. canDeleteSubContentsList (false),
  47021. thread (thread_),
  47022. icon (0)
  47023. {
  47024. DirectoryContentsList::FileInfo fileInfo;
  47025. if (parentContentsList_ != 0
  47026. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  47027. {
  47028. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  47029. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  47030. isDirectory = fileInfo.isDirectory;
  47031. }
  47032. else
  47033. {
  47034. isDirectory = true;
  47035. }
  47036. }
  47037. ~FileListTreeItem() throw()
  47038. {
  47039. thread.removeTimeSliceClient (this);
  47040. clearSubItems();
  47041. ImageCache::release (icon);
  47042. if (canDeleteSubContentsList)
  47043. delete subContentsList;
  47044. }
  47045. bool mightContainSubItems() { return isDirectory; }
  47046. const String getUniqueName() const { return file.getFullPathName(); }
  47047. int getItemHeight() const { return 22; }
  47048. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  47049. void itemOpennessChanged (bool isNowOpen)
  47050. {
  47051. if (isNowOpen)
  47052. {
  47053. clearSubItems();
  47054. isDirectory = file.isDirectory();
  47055. if (isDirectory)
  47056. {
  47057. if (subContentsList == 0)
  47058. {
  47059. jassert (parentContentsList != 0);
  47060. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  47061. l->setDirectory (file, true, true);
  47062. setSubContentsList (l);
  47063. canDeleteSubContentsList = true;
  47064. }
  47065. changeListenerCallback (0);
  47066. }
  47067. }
  47068. }
  47069. void setSubContentsList (DirectoryContentsList* newList) throw()
  47070. {
  47071. jassert (subContentsList == 0);
  47072. subContentsList = newList;
  47073. newList->addChangeListener (this);
  47074. }
  47075. void changeListenerCallback (void*)
  47076. {
  47077. clearSubItems();
  47078. if (isOpen() && subContentsList != 0)
  47079. {
  47080. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  47081. {
  47082. FileListTreeItem* const item
  47083. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  47084. addSubItem (item);
  47085. }
  47086. }
  47087. }
  47088. void paintItem (Graphics& g, int width, int height)
  47089. {
  47090. if (file != File::nonexistent)
  47091. {
  47092. updateIcon (true);
  47093. if (icon == 0)
  47094. thread.addTimeSliceClient (this);
  47095. }
  47096. owner.getLookAndFeel()
  47097. .drawFileBrowserRow (g, width, height,
  47098. file.getFileName(),
  47099. icon,
  47100. fileSize, modTime,
  47101. isDirectory, isSelected(),
  47102. indexInContentsList);
  47103. }
  47104. void itemClicked (const MouseEvent& e)
  47105. {
  47106. owner.sendMouseClickMessage (file, e);
  47107. }
  47108. void itemDoubleClicked (const MouseEvent& e)
  47109. {
  47110. TreeViewItem::itemDoubleClicked (e);
  47111. owner.sendDoubleClickMessage (file);
  47112. }
  47113. void itemSelectionChanged (bool)
  47114. {
  47115. owner.sendSelectionChangeMessage();
  47116. }
  47117. bool useTimeSlice()
  47118. {
  47119. updateIcon (false);
  47120. thread.removeTimeSliceClient (this);
  47121. return false;
  47122. }
  47123. void handleAsyncUpdate()
  47124. {
  47125. owner.repaint();
  47126. }
  47127. const File file;
  47128. juce_UseDebuggingNewOperator
  47129. private:
  47130. FileTreeComponent& owner;
  47131. DirectoryContentsList* parentContentsList;
  47132. int indexInContentsList;
  47133. DirectoryContentsList* subContentsList;
  47134. bool isDirectory, canDeleteSubContentsList;
  47135. TimeSliceThread& thread;
  47136. Image* icon;
  47137. String fileSize;
  47138. String modTime;
  47139. void updateIcon (const bool onlyUpdateIfCached) throw()
  47140. {
  47141. if (icon == 0)
  47142. {
  47143. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  47144. Image* im = ImageCache::getFromHashCode (hashCode);
  47145. if (im == 0 && ! onlyUpdateIfCached)
  47146. {
  47147. im = juce_createIconForFile (file);
  47148. if (im != 0)
  47149. ImageCache::addImageToCache (im, hashCode);
  47150. }
  47151. if (im != 0)
  47152. {
  47153. icon = im;
  47154. triggerAsyncUpdate();
  47155. }
  47156. }
  47157. }
  47158. };
  47159. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  47160. : DirectoryContentsDisplayComponent (listToShow)
  47161. {
  47162. FileListTreeItem* const root
  47163. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  47164. listToShow.getTimeSliceThread());
  47165. root->setSubContentsList (&listToShow);
  47166. setRootItemVisible (false);
  47167. setRootItem (root);
  47168. }
  47169. FileTreeComponent::~FileTreeComponent()
  47170. {
  47171. deleteRootItem();
  47172. }
  47173. const File FileTreeComponent::getSelectedFile (const int index) const
  47174. {
  47175. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  47176. if (item != 0)
  47177. return item->file;
  47178. return File::nonexistent;
  47179. }
  47180. void FileTreeComponent::scrollToTop()
  47181. {
  47182. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  47183. }
  47184. void FileTreeComponent::setDragAndDropDescription (const String& description) throw()
  47185. {
  47186. dragAndDropDescription = description;
  47187. }
  47188. END_JUCE_NAMESPACE
  47189. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  47190. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  47191. BEGIN_JUCE_NAMESPACE
  47192. ImagePreviewComponent::ImagePreviewComponent()
  47193. {
  47194. }
  47195. ImagePreviewComponent::~ImagePreviewComponent()
  47196. {
  47197. }
  47198. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  47199. {
  47200. const int availableW = proportionOfWidth (0.97f);
  47201. const int availableH = getHeight() - 13 * 4;
  47202. const double scale = jmin (1.0,
  47203. availableW / (double) w,
  47204. availableH / (double) h);
  47205. w = roundToInt (scale * w);
  47206. h = roundToInt (scale * h);
  47207. }
  47208. void ImagePreviewComponent::selectedFileChanged (const File& file)
  47209. {
  47210. if (fileToLoad != file)
  47211. {
  47212. fileToLoad = file;
  47213. startTimer (100);
  47214. }
  47215. }
  47216. void ImagePreviewComponent::timerCallback()
  47217. {
  47218. stopTimer();
  47219. currentThumbnail = 0;
  47220. currentDetails = String::empty;
  47221. repaint();
  47222. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  47223. if (in != 0)
  47224. {
  47225. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  47226. if (format != 0)
  47227. {
  47228. currentThumbnail = format->decodeImage (*in);
  47229. if (currentThumbnail != 0)
  47230. {
  47231. int w = currentThumbnail->getWidth();
  47232. int h = currentThumbnail->getHeight();
  47233. currentDetails
  47234. << fileToLoad.getFileName() << "\n"
  47235. << format->getFormatName() << "\n"
  47236. << w << " x " << h << " pixels\n"
  47237. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  47238. getThumbSize (w, h);
  47239. currentThumbnail = currentThumbnail->createCopy (w, h);
  47240. }
  47241. }
  47242. }
  47243. }
  47244. void ImagePreviewComponent::paint (Graphics& g)
  47245. {
  47246. if (currentThumbnail != 0)
  47247. {
  47248. g.setFont (13.0f);
  47249. int w = currentThumbnail->getWidth();
  47250. int h = currentThumbnail->getHeight();
  47251. getThumbSize (w, h);
  47252. const int numLines = 4;
  47253. const int totalH = 13 * numLines + h + 4;
  47254. const int y = (getHeight() - totalH) / 2;
  47255. g.drawImageWithin (currentThumbnail,
  47256. (getWidth() - w) / 2, y, w, h,
  47257. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  47258. false);
  47259. g.drawFittedText (currentDetails,
  47260. 0, y + h + 4, getWidth(), 100,
  47261. Justification::centredTop, numLines);
  47262. }
  47263. }
  47264. END_JUCE_NAMESPACE
  47265. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  47266. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  47267. BEGIN_JUCE_NAMESPACE
  47268. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47269. const String& directoryWildcardPatterns,
  47270. const String& description_)
  47271. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47272. : (description_ + T(" (") + fileWildcardPatterns + T(")")))
  47273. {
  47274. parse (fileWildcardPatterns, fileWildcards);
  47275. parse (directoryWildcardPatterns, directoryWildcards);
  47276. }
  47277. WildcardFileFilter::~WildcardFileFilter()
  47278. {
  47279. }
  47280. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47281. {
  47282. return match (file, fileWildcards);
  47283. }
  47284. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47285. {
  47286. return match (file, directoryWildcards);
  47287. }
  47288. void WildcardFileFilter::parse (const String& pattern, StringArray& result) throw()
  47289. {
  47290. result.addTokens (pattern.toLowerCase(), T(";,"), T("\"'"));
  47291. result.trim();
  47292. result.removeEmptyStrings();
  47293. // special case for *.*, because people use it to mean "any file", but it
  47294. // would actually ignore files with no extension.
  47295. for (int i = result.size(); --i >= 0;)
  47296. if (result[i] == T("*.*"))
  47297. result.set (i, T("*"));
  47298. }
  47299. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards) throw()
  47300. {
  47301. const String filename (file.getFileName());
  47302. for (int i = wildcards.size(); --i >= 0;)
  47303. if (filename.matchesWildcard (wildcards[i], true))
  47304. return true;
  47305. return false;
  47306. }
  47307. END_JUCE_NAMESPACE
  47308. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  47309. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47310. BEGIN_JUCE_NAMESPACE
  47311. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47312. {
  47313. }
  47314. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47315. {
  47316. }
  47317. namespace KeyboardFocusHelpers
  47318. {
  47319. // This will sort a set of components, so that they are ordered in terms of
  47320. // left-to-right and then top-to-bottom.
  47321. class ScreenPositionComparator
  47322. {
  47323. public:
  47324. ScreenPositionComparator() {}
  47325. static int compareElements (const Component* const first, const Component* const second) throw()
  47326. {
  47327. int explicitOrder1 = first->getExplicitFocusOrder();
  47328. if (explicitOrder1 <= 0)
  47329. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  47330. int explicitOrder2 = second->getExplicitFocusOrder();
  47331. if (explicitOrder2 <= 0)
  47332. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  47333. if (explicitOrder1 != explicitOrder2)
  47334. return explicitOrder1 - explicitOrder2;
  47335. const int diff = first->getY() - second->getY();
  47336. return (diff == 0) ? first->getX() - second->getX()
  47337. : diff;
  47338. }
  47339. };
  47340. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47341. {
  47342. if (parent->getNumChildComponents() > 0)
  47343. {
  47344. Array <Component*> localComps;
  47345. ScreenPositionComparator comparator;
  47346. int i;
  47347. for (i = parent->getNumChildComponents(); --i >= 0;)
  47348. {
  47349. Component* const c = parent->getChildComponent (i);
  47350. if (c->isVisible() && c->isEnabled())
  47351. localComps.addSorted (comparator, c);
  47352. }
  47353. for (i = 0; i < localComps.size(); ++i)
  47354. {
  47355. Component* const c = localComps.getUnchecked (i);
  47356. if (c->getWantsKeyboardFocus())
  47357. comps.add (c);
  47358. if (! c->isFocusContainer())
  47359. findAllFocusableComponents (c, comps);
  47360. }
  47361. }
  47362. }
  47363. }
  47364. static Component* getIncrementedComponent (Component* const current, const int delta) throw()
  47365. {
  47366. Component* focusContainer = current->getParentComponent();
  47367. if (focusContainer != 0)
  47368. {
  47369. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47370. focusContainer = focusContainer->getParentComponent();
  47371. if (focusContainer != 0)
  47372. {
  47373. Array <Component*> comps;
  47374. KeyboardFocusHelpers::findAllFocusableComponents (focusContainer, comps);
  47375. if (comps.size() > 0)
  47376. {
  47377. const int index = comps.indexOf (current);
  47378. return comps [(index + comps.size() + delta) % comps.size()];
  47379. }
  47380. }
  47381. }
  47382. return 0;
  47383. }
  47384. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47385. {
  47386. return getIncrementedComponent (current, 1);
  47387. }
  47388. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47389. {
  47390. return getIncrementedComponent (current, -1);
  47391. }
  47392. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47393. {
  47394. Array <Component*> comps;
  47395. if (parentComponent != 0)
  47396. KeyboardFocusHelpers::findAllFocusableComponents (parentComponent, comps);
  47397. return comps.getFirst();
  47398. }
  47399. END_JUCE_NAMESPACE
  47400. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47401. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47402. BEGIN_JUCE_NAMESPACE
  47403. bool KeyListener::keyStateChanged (const bool, Component*)
  47404. {
  47405. return false;
  47406. }
  47407. END_JUCE_NAMESPACE
  47408. /*** End of inlined file: juce_KeyListener.cpp ***/
  47409. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47410. BEGIN_JUCE_NAMESPACE
  47411. // N.B. these two includes are put here deliberately to avoid problems with
  47412. // old GCCs failing on long include paths
  47413. const int maxKeys = 3;
  47414. class KeyMappingChangeButton : public Button
  47415. {
  47416. public:
  47417. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47418. const CommandID commandID_,
  47419. const String& keyName,
  47420. const int keyNum_)
  47421. : Button (keyName),
  47422. owner (owner_),
  47423. commandID (commandID_),
  47424. keyNum (keyNum_)
  47425. {
  47426. setWantsKeyboardFocus (false);
  47427. setTriggeredOnMouseDown (keyNum >= 0);
  47428. if (keyNum_ < 0)
  47429. setTooltip (TRANS("adds a new key-mapping"));
  47430. else
  47431. setTooltip (TRANS("click to change this key-mapping"));
  47432. }
  47433. ~KeyMappingChangeButton()
  47434. {
  47435. }
  47436. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47437. {
  47438. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47439. keyNum >= 0 ? getName() : String::empty);
  47440. }
  47441. void clicked()
  47442. {
  47443. if (keyNum >= 0)
  47444. {
  47445. // existing key clicked..
  47446. PopupMenu m;
  47447. m.addItem (1, TRANS("change this key-mapping"));
  47448. m.addSeparator();
  47449. m.addItem (2, TRANS("remove this key-mapping"));
  47450. const int res = m.show();
  47451. if (res == 1)
  47452. {
  47453. owner->assignNewKey (commandID, keyNum);
  47454. }
  47455. else if (res == 2)
  47456. {
  47457. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47458. }
  47459. }
  47460. else
  47461. {
  47462. // + button pressed..
  47463. owner->assignNewKey (commandID, -1);
  47464. }
  47465. }
  47466. void fitToContent (const int h) throw()
  47467. {
  47468. if (keyNum < 0)
  47469. {
  47470. setSize (h, h);
  47471. }
  47472. else
  47473. {
  47474. Font f (h * 0.6f);
  47475. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47476. }
  47477. }
  47478. juce_UseDebuggingNewOperator
  47479. private:
  47480. KeyMappingEditorComponent* const owner;
  47481. const CommandID commandID;
  47482. const int keyNum;
  47483. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47484. KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47485. };
  47486. class KeyMappingItemComponent : public Component
  47487. {
  47488. public:
  47489. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47490. const CommandID commandID_)
  47491. : owner (owner_),
  47492. commandID (commandID_)
  47493. {
  47494. setInterceptsMouseClicks (false, true);
  47495. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47496. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47497. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47498. {
  47499. KeyMappingChangeButton* const kb
  47500. = new KeyMappingChangeButton (owner_, commandID,
  47501. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47502. kb->setEnabled (! isReadOnly);
  47503. addAndMakeVisible (kb);
  47504. }
  47505. KeyMappingChangeButton* const kb
  47506. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47507. addChildComponent (kb);
  47508. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47509. }
  47510. ~KeyMappingItemComponent()
  47511. {
  47512. deleteAllChildren();
  47513. }
  47514. void paint (Graphics& g)
  47515. {
  47516. g.setFont (getHeight() * 0.7f);
  47517. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47518. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47519. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47520. Justification::centredLeft, true);
  47521. }
  47522. void resized()
  47523. {
  47524. int x = getWidth() - 4;
  47525. for (int i = getNumChildComponents(); --i >= 0;)
  47526. {
  47527. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47528. kb->fitToContent (getHeight() - 2);
  47529. kb->setTopRightPosition (x, 1);
  47530. x -= kb->getWidth() + 5;
  47531. }
  47532. }
  47533. juce_UseDebuggingNewOperator
  47534. private:
  47535. KeyMappingEditorComponent* const owner;
  47536. const CommandID commandID;
  47537. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47538. KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47539. };
  47540. class KeyMappingTreeViewItem : public TreeViewItem
  47541. {
  47542. public:
  47543. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47544. const CommandID commandID_)
  47545. : owner (owner_),
  47546. commandID (commandID_)
  47547. {
  47548. }
  47549. ~KeyMappingTreeViewItem()
  47550. {
  47551. }
  47552. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47553. bool mightContainSubItems() { return false; }
  47554. int getItemHeight() const { return 20; }
  47555. Component* createItemComponent()
  47556. {
  47557. return new KeyMappingItemComponent (owner, commandID);
  47558. }
  47559. juce_UseDebuggingNewOperator
  47560. private:
  47561. KeyMappingEditorComponent* const owner;
  47562. const CommandID commandID;
  47563. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47564. KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47565. };
  47566. class KeyCategoryTreeViewItem : public TreeViewItem
  47567. {
  47568. public:
  47569. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  47570. const String& name)
  47571. : owner (owner_),
  47572. categoryName (name)
  47573. {
  47574. }
  47575. ~KeyCategoryTreeViewItem()
  47576. {
  47577. }
  47578. const String getUniqueName() const { return categoryName + "_cat"; }
  47579. bool mightContainSubItems() { return true; }
  47580. int getItemHeight() const { return 28; }
  47581. void paintItem (Graphics& g, int width, int height)
  47582. {
  47583. g.setFont (height * 0.6f, Font::bold);
  47584. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  47585. g.drawText (categoryName,
  47586. 2, 0, width - 2, height,
  47587. Justification::centredLeft, true);
  47588. }
  47589. void itemOpennessChanged (bool isNowOpen)
  47590. {
  47591. if (isNowOpen)
  47592. {
  47593. if (getNumSubItems() == 0)
  47594. {
  47595. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  47596. for (int i = 0; i < commands.size(); ++i)
  47597. {
  47598. if (owner->shouldCommandBeIncluded (commands[i]))
  47599. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  47600. }
  47601. }
  47602. }
  47603. else
  47604. {
  47605. clearSubItems();
  47606. }
  47607. }
  47608. juce_UseDebuggingNewOperator
  47609. private:
  47610. KeyMappingEditorComponent* owner;
  47611. String categoryName;
  47612. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  47613. KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  47614. };
  47615. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  47616. const bool showResetToDefaultButton)
  47617. : mappings (mappingManager)
  47618. {
  47619. jassert (mappingManager != 0); // can't be null!
  47620. mappingManager->addChangeListener (this);
  47621. setLinesDrawnForSubItems (false);
  47622. resetButton = 0;
  47623. if (showResetToDefaultButton)
  47624. {
  47625. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  47626. resetButton->addButtonListener (this);
  47627. }
  47628. addAndMakeVisible (tree = new TreeView());
  47629. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  47630. tree->setRootItemVisible (false);
  47631. tree->setDefaultOpenness (true);
  47632. tree->setRootItem (this);
  47633. }
  47634. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  47635. {
  47636. mappings->removeChangeListener (this);
  47637. deleteAllChildren();
  47638. }
  47639. bool KeyMappingEditorComponent::mightContainSubItems()
  47640. {
  47641. return true;
  47642. }
  47643. const String KeyMappingEditorComponent::getUniqueName() const
  47644. {
  47645. return T("keys");
  47646. }
  47647. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  47648. const Colour& textColour)
  47649. {
  47650. setColour (backgroundColourId, mainBackground);
  47651. setColour (textColourId, textColour);
  47652. tree->setColour (TreeView::backgroundColourId, mainBackground);
  47653. }
  47654. void KeyMappingEditorComponent::parentHierarchyChanged()
  47655. {
  47656. changeListenerCallback (0);
  47657. }
  47658. void KeyMappingEditorComponent::resized()
  47659. {
  47660. int h = getHeight();
  47661. if (resetButton != 0)
  47662. {
  47663. const int buttonHeight = 20;
  47664. h -= buttonHeight + 8;
  47665. int x = getWidth() - 8;
  47666. const int y = h + 6;
  47667. resetButton->changeWidthToFitText (buttonHeight);
  47668. resetButton->setTopRightPosition (x, y);
  47669. }
  47670. tree->setBounds (0, 0, getWidth(), h);
  47671. }
  47672. void KeyMappingEditorComponent::buttonClicked (Button* button)
  47673. {
  47674. if (button == resetButton)
  47675. {
  47676. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  47677. TRANS("Reset to defaults"),
  47678. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  47679. TRANS("Reset")))
  47680. {
  47681. mappings->resetToDefaultMappings();
  47682. }
  47683. }
  47684. }
  47685. void KeyMappingEditorComponent::changeListenerCallback (void*)
  47686. {
  47687. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  47688. clearSubItems();
  47689. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  47690. for (int i = 0; i < categories.size(); ++i)
  47691. {
  47692. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  47693. int count = 0;
  47694. for (int j = 0; j < commands.size(); ++j)
  47695. if (shouldCommandBeIncluded (commands[j]))
  47696. ++count;
  47697. if (count > 0)
  47698. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  47699. }
  47700. if (openness != 0)
  47701. tree->restoreOpennessState (*openness);
  47702. }
  47703. class KeyEntryWindow : public AlertWindow
  47704. {
  47705. public:
  47706. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  47707. : AlertWindow (TRANS("New key-mapping"),
  47708. TRANS("Please press a key combination now..."),
  47709. AlertWindow::NoIcon),
  47710. owner (owner_)
  47711. {
  47712. addButton (TRANS("ok"), 1);
  47713. addButton (TRANS("cancel"), 0);
  47714. // (avoid return + escape keys getting processed by the buttons..)
  47715. for (int i = getNumChildComponents(); --i >= 0;)
  47716. getChildComponent (i)->setWantsKeyboardFocus (false);
  47717. setWantsKeyboardFocus (true);
  47718. grabKeyboardFocus();
  47719. }
  47720. ~KeyEntryWindow()
  47721. {
  47722. }
  47723. bool keyPressed (const KeyPress& key)
  47724. {
  47725. lastPress = key;
  47726. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  47727. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  47728. if (previousCommand != 0)
  47729. {
  47730. message << "\n\n"
  47731. << TRANS("(Currently assigned to \"")
  47732. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  47733. << "\")";
  47734. }
  47735. setMessage (message);
  47736. return true;
  47737. }
  47738. bool keyStateChanged (const bool)
  47739. {
  47740. return true;
  47741. }
  47742. KeyPress lastPress;
  47743. juce_UseDebuggingNewOperator
  47744. private:
  47745. KeyMappingEditorComponent* owner;
  47746. KeyEntryWindow (const KeyEntryWindow&);
  47747. KeyEntryWindow& operator= (const KeyEntryWindow&);
  47748. };
  47749. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  47750. {
  47751. KeyEntryWindow entryWindow (this);
  47752. if (entryWindow.runModalLoop() != 0)
  47753. {
  47754. entryWindow.setVisible (false);
  47755. if (entryWindow.lastPress.isValid())
  47756. {
  47757. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  47758. if (previousCommand != 0)
  47759. {
  47760. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  47761. TRANS("Change key-mapping"),
  47762. TRANS("This key is already assigned to the command \"")
  47763. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  47764. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  47765. TRANS("re-assign"),
  47766. TRANS("cancel")))
  47767. {
  47768. return;
  47769. }
  47770. }
  47771. mappings->removeKeyPress (entryWindow.lastPress);
  47772. if (index >= 0)
  47773. mappings->removeKeyPress (commandID, index);
  47774. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  47775. }
  47776. }
  47777. }
  47778. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  47779. {
  47780. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47781. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  47782. }
  47783. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  47784. {
  47785. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47786. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  47787. }
  47788. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  47789. {
  47790. return key.getTextDescription();
  47791. }
  47792. END_JUCE_NAMESPACE
  47793. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47794. /*** Start of inlined file: juce_KeyPress.cpp ***/
  47795. BEGIN_JUCE_NAMESPACE
  47796. KeyPress::KeyPress() throw()
  47797. : keyCode (0),
  47798. mods (0),
  47799. textCharacter (0)
  47800. {
  47801. }
  47802. KeyPress::KeyPress (const int keyCode_,
  47803. const ModifierKeys& mods_,
  47804. const juce_wchar textCharacter_) throw()
  47805. : keyCode (keyCode_),
  47806. mods (mods_),
  47807. textCharacter (textCharacter_)
  47808. {
  47809. }
  47810. KeyPress::KeyPress (const int keyCode_) throw()
  47811. : keyCode (keyCode_),
  47812. textCharacter (0)
  47813. {
  47814. }
  47815. KeyPress::KeyPress (const KeyPress& other) throw()
  47816. : keyCode (other.keyCode),
  47817. mods (other.mods),
  47818. textCharacter (other.textCharacter)
  47819. {
  47820. }
  47821. KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  47822. {
  47823. keyCode = other.keyCode;
  47824. mods = other.mods;
  47825. textCharacter = other.textCharacter;
  47826. return *this;
  47827. }
  47828. bool KeyPress::operator== (const KeyPress& other) const throw()
  47829. {
  47830. return mods.getRawFlags() == other.mods.getRawFlags()
  47831. && (textCharacter == other.textCharacter
  47832. || textCharacter == 0
  47833. || other.textCharacter == 0)
  47834. && (keyCode == other.keyCode
  47835. || (keyCode < 256
  47836. && other.keyCode < 256
  47837. && CharacterFunctions::toLowerCase ((tchar) keyCode)
  47838. == CharacterFunctions::toLowerCase ((tchar) other.keyCode)));
  47839. }
  47840. bool KeyPress::operator!= (const KeyPress& other) const throw()
  47841. {
  47842. return ! operator== (other);
  47843. }
  47844. bool KeyPress::isCurrentlyDown() const throw()
  47845. {
  47846. return isKeyCurrentlyDown (keyCode)
  47847. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  47848. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  47849. }
  47850. struct KeyNameAndCode
  47851. {
  47852. const char* name;
  47853. int code;
  47854. };
  47855. static const KeyNameAndCode keyNameTranslations[] =
  47856. {
  47857. { "spacebar", KeyPress::spaceKey },
  47858. { "return", KeyPress::returnKey },
  47859. { "escape", KeyPress::escapeKey },
  47860. { "backspace", KeyPress::backspaceKey },
  47861. { "cursor left", KeyPress::leftKey },
  47862. { "cursor right", KeyPress::rightKey },
  47863. { "cursor up", KeyPress::upKey },
  47864. { "cursor down", KeyPress::downKey },
  47865. { "page up", KeyPress::pageUpKey },
  47866. { "page down", KeyPress::pageDownKey },
  47867. { "home", KeyPress::homeKey },
  47868. { "end", KeyPress::endKey },
  47869. { "delete", KeyPress::deleteKey },
  47870. { "insert", KeyPress::insertKey },
  47871. { "tab", KeyPress::tabKey },
  47872. { "play", KeyPress::playKey },
  47873. { "stop", KeyPress::stopKey },
  47874. { "fast forward", KeyPress::fastForwardKey },
  47875. { "rewind", KeyPress::rewindKey }
  47876. };
  47877. static const tchar* const numberPadPrefix = T("numpad ");
  47878. const KeyPress KeyPress::createFromDescription (const String& desc) throw()
  47879. {
  47880. int modifiers = 0;
  47881. if (desc.containsWholeWordIgnoreCase (T("ctrl"))
  47882. || desc.containsWholeWordIgnoreCase (T("control"))
  47883. || desc.containsWholeWordIgnoreCase (T("ctl")))
  47884. modifiers |= ModifierKeys::ctrlModifier;
  47885. if (desc.containsWholeWordIgnoreCase (T("shift"))
  47886. || desc.containsWholeWordIgnoreCase (T("shft")))
  47887. modifiers |= ModifierKeys::shiftModifier;
  47888. if (desc.containsWholeWordIgnoreCase (T("alt"))
  47889. || desc.containsWholeWordIgnoreCase (T("option")))
  47890. modifiers |= ModifierKeys::altModifier;
  47891. if (desc.containsWholeWordIgnoreCase (T("command"))
  47892. || desc.containsWholeWordIgnoreCase (T("cmd")))
  47893. modifiers |= ModifierKeys::commandModifier;
  47894. int key = 0;
  47895. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  47896. {
  47897. if (desc.containsWholeWordIgnoreCase (String (keyNameTranslations[i].name)))
  47898. {
  47899. key = keyNameTranslations[i].code;
  47900. break;
  47901. }
  47902. }
  47903. if (key == 0)
  47904. {
  47905. // see if it's a numpad key..
  47906. if (desc.containsIgnoreCase (numberPadPrefix))
  47907. {
  47908. const tchar lastChar = desc.trimEnd().getLastCharacter();
  47909. if (lastChar >= T('0') && lastChar <= T('9'))
  47910. key = numberPad0 + lastChar - T('0');
  47911. else if (lastChar == T('+'))
  47912. key = numberPadAdd;
  47913. else if (lastChar == T('-'))
  47914. key = numberPadSubtract;
  47915. else if (lastChar == T('*'))
  47916. key = numberPadMultiply;
  47917. else if (lastChar == T('/'))
  47918. key = numberPadDivide;
  47919. else if (lastChar == T('.'))
  47920. key = numberPadDecimalPoint;
  47921. else if (lastChar == T('='))
  47922. key = numberPadEquals;
  47923. else if (desc.endsWith (T("separator")))
  47924. key = numberPadSeparator;
  47925. else if (desc.endsWith (T("delete")))
  47926. key = numberPadDelete;
  47927. }
  47928. if (key == 0)
  47929. {
  47930. // see if it's a function key..
  47931. for (int i = 1; i <= 12; ++i)
  47932. if (desc.containsWholeWordIgnoreCase (T("f") + String (i)))
  47933. key = F1Key + i - 1;
  47934. if (key == 0)
  47935. {
  47936. // give up and use the hex code..
  47937. const int hexCode = desc.fromFirstOccurrenceOf (T("#"), false, false)
  47938. .toLowerCase()
  47939. .retainCharacters (T("0123456789abcdef"))
  47940. .getHexValue32();
  47941. if (hexCode > 0)
  47942. key = hexCode;
  47943. else
  47944. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  47945. }
  47946. }
  47947. }
  47948. return KeyPress (key, ModifierKeys (modifiers), 0);
  47949. }
  47950. const String KeyPress::getTextDescription() const throw()
  47951. {
  47952. String desc;
  47953. if (keyCode > 0)
  47954. {
  47955. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  47956. // want to store it as being a slash, not shift+whatever.
  47957. if (textCharacter == T('/'))
  47958. return "/";
  47959. if (mods.isCtrlDown())
  47960. desc << "ctrl + ";
  47961. if (mods.isShiftDown())
  47962. desc << "shift + ";
  47963. #if JUCE_MAC
  47964. // only do this on the mac, because on Windows ctrl and command are the same,
  47965. // and this would get confusing
  47966. if (mods.isCommandDown())
  47967. desc << "command + ";
  47968. if (mods.isAltDown())
  47969. desc << "option + ";
  47970. #else
  47971. if (mods.isAltDown())
  47972. desc << "alt + ";
  47973. #endif
  47974. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  47975. if (keyCode == keyNameTranslations[i].code)
  47976. return desc + keyNameTranslations[i].name;
  47977. if (keyCode >= F1Key && keyCode <= F16Key)
  47978. desc << 'F' << (1 + keyCode - F1Key);
  47979. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  47980. desc << numberPadPrefix << (keyCode - numberPad0);
  47981. else if (keyCode >= 33 && keyCode < 176)
  47982. desc += CharacterFunctions::toUpperCase ((tchar) keyCode);
  47983. else if (keyCode == numberPadAdd)
  47984. desc << numberPadPrefix << '+';
  47985. else if (keyCode == numberPadSubtract)
  47986. desc << numberPadPrefix << '-';
  47987. else if (keyCode == numberPadMultiply)
  47988. desc << numberPadPrefix << '*';
  47989. else if (keyCode == numberPadDivide)
  47990. desc << numberPadPrefix << '/';
  47991. else if (keyCode == numberPadSeparator)
  47992. desc << numberPadPrefix << "separator";
  47993. else if (keyCode == numberPadDecimalPoint)
  47994. desc << numberPadPrefix << '.';
  47995. else if (keyCode == numberPadDelete)
  47996. desc << numberPadPrefix << "delete";
  47997. else
  47998. desc << '#' << String::toHexString (keyCode);
  47999. }
  48000. return desc;
  48001. }
  48002. END_JUCE_NAMESPACE
  48003. /*** End of inlined file: juce_KeyPress.cpp ***/
  48004. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  48005. BEGIN_JUCE_NAMESPACE
  48006. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_) throw()
  48007. : commandManager (commandManager_)
  48008. {
  48009. // A manager is needed to get the descriptions of commands, and will be called when
  48010. // a command is invoked. So you can't leave this null..
  48011. jassert (commandManager_ != 0);
  48012. Desktop::getInstance().addFocusChangeListener (this);
  48013. }
  48014. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other) throw()
  48015. : commandManager (other.commandManager)
  48016. {
  48017. Desktop::getInstance().addFocusChangeListener (this);
  48018. }
  48019. KeyPressMappingSet::~KeyPressMappingSet()
  48020. {
  48021. Desktop::getInstance().removeFocusChangeListener (this);
  48022. }
  48023. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const throw()
  48024. {
  48025. for (int i = 0; i < mappings.size(); ++i)
  48026. if (mappings.getUnchecked(i)->commandID == commandID)
  48027. return mappings.getUnchecked (i)->keypresses;
  48028. return Array <KeyPress> ();
  48029. }
  48030. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  48031. const KeyPress& newKeyPress,
  48032. int insertIndex) throw()
  48033. {
  48034. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  48035. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  48036. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  48037. && ! newKeyPress.getModifiers().isShiftDown()));
  48038. if (findCommandForKeyPress (newKeyPress) != commandID)
  48039. {
  48040. removeKeyPress (newKeyPress);
  48041. if (newKeyPress.isValid())
  48042. {
  48043. for (int i = mappings.size(); --i >= 0;)
  48044. {
  48045. if (mappings.getUnchecked(i)->commandID == commandID)
  48046. {
  48047. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  48048. sendChangeMessage (this);
  48049. return;
  48050. }
  48051. }
  48052. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48053. if (ci != 0)
  48054. {
  48055. CommandMapping* const cm = new CommandMapping();
  48056. cm->commandID = commandID;
  48057. cm->keypresses.add (newKeyPress);
  48058. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  48059. mappings.add (cm);
  48060. sendChangeMessage (this);
  48061. }
  48062. }
  48063. }
  48064. }
  48065. void KeyPressMappingSet::resetToDefaultMappings() throw()
  48066. {
  48067. mappings.clear();
  48068. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  48069. {
  48070. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  48071. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48072. {
  48073. addKeyPress (ci->commandID,
  48074. ci->defaultKeypresses.getReference (j));
  48075. }
  48076. }
  48077. sendChangeMessage (this);
  48078. }
  48079. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID) throw()
  48080. {
  48081. clearAllKeyPresses (commandID);
  48082. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48083. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48084. {
  48085. addKeyPress (ci->commandID,
  48086. ci->defaultKeypresses.getReference (j));
  48087. }
  48088. }
  48089. void KeyPressMappingSet::clearAllKeyPresses() throw()
  48090. {
  48091. if (mappings.size() > 0)
  48092. {
  48093. sendChangeMessage (this);
  48094. mappings.clear();
  48095. }
  48096. }
  48097. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID) throw()
  48098. {
  48099. for (int i = mappings.size(); --i >= 0;)
  48100. {
  48101. if (mappings.getUnchecked(i)->commandID == commandID)
  48102. {
  48103. mappings.remove (i);
  48104. sendChangeMessage (this);
  48105. }
  48106. }
  48107. }
  48108. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress) throw()
  48109. {
  48110. if (keypress.isValid())
  48111. {
  48112. for (int i = mappings.size(); --i >= 0;)
  48113. {
  48114. CommandMapping* const cm = mappings.getUnchecked(i);
  48115. for (int j = cm->keypresses.size(); --j >= 0;)
  48116. {
  48117. if (keypress == cm->keypresses [j])
  48118. {
  48119. cm->keypresses.remove (j);
  48120. sendChangeMessage (this);
  48121. }
  48122. }
  48123. }
  48124. }
  48125. }
  48126. void KeyPressMappingSet::removeKeyPress (const CommandID commandID,
  48127. const int keyPressIndex) throw()
  48128. {
  48129. for (int i = mappings.size(); --i >= 0;)
  48130. {
  48131. if (mappings.getUnchecked(i)->commandID == commandID)
  48132. {
  48133. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  48134. sendChangeMessage (this);
  48135. break;
  48136. }
  48137. }
  48138. }
  48139. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  48140. {
  48141. for (int i = 0; i < mappings.size(); ++i)
  48142. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  48143. return mappings.getUnchecked(i)->commandID;
  48144. return 0;
  48145. }
  48146. bool KeyPressMappingSet::containsMapping (const CommandID commandID,
  48147. const KeyPress& keyPress) const throw()
  48148. {
  48149. for (int i = mappings.size(); --i >= 0;)
  48150. if (mappings.getUnchecked(i)->commandID == commandID)
  48151. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  48152. return false;
  48153. }
  48154. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  48155. const KeyPress& key,
  48156. const bool isKeyDown,
  48157. const int millisecsSinceKeyPressed,
  48158. Component* const originatingComponent) const
  48159. {
  48160. ApplicationCommandTarget::InvocationInfo info (commandID);
  48161. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  48162. info.isKeyDown = isKeyDown;
  48163. info.keyPress = key;
  48164. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  48165. info.originatingComponent = originatingComponent;
  48166. commandManager->invoke (info, false);
  48167. }
  48168. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  48169. {
  48170. if (xmlVersion.hasTagName (T("KEYMAPPINGS")))
  48171. {
  48172. if (xmlVersion.getBoolAttribute (T("basedOnDefaults"), true))
  48173. {
  48174. // if the XML was created as a set of differences from the default mappings,
  48175. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  48176. resetToDefaultMappings();
  48177. }
  48178. else
  48179. {
  48180. // if the XML was created calling createXml (false), then we need to clear all
  48181. // the keys and treat the xml as describing the entire set of mappings.
  48182. clearAllKeyPresses();
  48183. }
  48184. forEachXmlChildElement (xmlVersion, map)
  48185. {
  48186. const CommandID commandId = map->getStringAttribute (T("commandId")).getHexValue32();
  48187. if (commandId != 0)
  48188. {
  48189. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute (T("key"))));
  48190. if (map->hasTagName (T("MAPPING")))
  48191. {
  48192. addKeyPress (commandId, key);
  48193. }
  48194. else if (map->hasTagName (T("UNMAPPING")))
  48195. {
  48196. if (containsMapping (commandId, key))
  48197. removeKeyPress (key);
  48198. }
  48199. }
  48200. }
  48201. return true;
  48202. }
  48203. return false;
  48204. }
  48205. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  48206. {
  48207. ScopedPointer <KeyPressMappingSet> defaultSet;
  48208. if (saveDifferencesFromDefaultSet)
  48209. {
  48210. defaultSet = new KeyPressMappingSet (commandManager);
  48211. defaultSet->resetToDefaultMappings();
  48212. }
  48213. XmlElement* const doc = new XmlElement (T("KEYMAPPINGS"));
  48214. doc->setAttribute (T("basedOnDefaults"), saveDifferencesFromDefaultSet);
  48215. int i;
  48216. for (i = 0; i < mappings.size(); ++i)
  48217. {
  48218. const CommandMapping* const cm = mappings.getUnchecked(i);
  48219. for (int j = 0; j < cm->keypresses.size(); ++j)
  48220. {
  48221. if (defaultSet == 0
  48222. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48223. {
  48224. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  48225. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48226. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48227. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48228. }
  48229. }
  48230. }
  48231. if (defaultSet != 0)
  48232. {
  48233. for (i = 0; i < defaultSet->mappings.size(); ++i)
  48234. {
  48235. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  48236. for (int j = 0; j < cm->keypresses.size(); ++j)
  48237. {
  48238. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48239. {
  48240. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  48241. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48242. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48243. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48244. }
  48245. }
  48246. }
  48247. }
  48248. return doc;
  48249. }
  48250. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  48251. Component* originatingComponent)
  48252. {
  48253. bool used = false;
  48254. const CommandID commandID = findCommandForKeyPress (key);
  48255. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48256. if (ci != 0
  48257. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  48258. {
  48259. ApplicationCommandInfo info (0);
  48260. if (commandManager->getTargetForCommand (commandID, info) != 0
  48261. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48262. {
  48263. invokeCommand (commandID, key, true, 0, originatingComponent);
  48264. used = true;
  48265. }
  48266. else
  48267. {
  48268. if (originatingComponent != 0)
  48269. originatingComponent->getLookAndFeel().playAlertSound();
  48270. }
  48271. }
  48272. return used;
  48273. }
  48274. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48275. {
  48276. bool used = false;
  48277. const uint32 now = Time::getMillisecondCounter();
  48278. for (int i = mappings.size(); --i >= 0;)
  48279. {
  48280. CommandMapping* const cm = mappings.getUnchecked(i);
  48281. if (cm->wantsKeyUpDownCallbacks)
  48282. {
  48283. for (int j = cm->keypresses.size(); --j >= 0;)
  48284. {
  48285. const KeyPress key (cm->keypresses.getReference (j));
  48286. const bool isDown = key.isCurrentlyDown();
  48287. int keyPressEntryIndex = 0;
  48288. bool wasDown = false;
  48289. for (int k = keysDown.size(); --k >= 0;)
  48290. {
  48291. if (key == keysDown.getUnchecked(k)->key)
  48292. {
  48293. keyPressEntryIndex = k;
  48294. wasDown = true;
  48295. used = true;
  48296. break;
  48297. }
  48298. }
  48299. if (isDown != wasDown)
  48300. {
  48301. int millisecs = 0;
  48302. if (isDown)
  48303. {
  48304. KeyPressTime* const k = new KeyPressTime();
  48305. k->key = key;
  48306. k->timeWhenPressed = now;
  48307. keysDown.add (k);
  48308. }
  48309. else
  48310. {
  48311. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48312. if (now > pressTime)
  48313. millisecs = now - pressTime;
  48314. keysDown.remove (keyPressEntryIndex);
  48315. }
  48316. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48317. used = true;
  48318. }
  48319. }
  48320. }
  48321. }
  48322. return used;
  48323. }
  48324. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48325. {
  48326. if (focusedComponent != 0)
  48327. focusedComponent->keyStateChanged (false);
  48328. }
  48329. END_JUCE_NAMESPACE
  48330. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  48331. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  48332. BEGIN_JUCE_NAMESPACE
  48333. ModifierKeys::ModifierKeys (const int flags_) throw()
  48334. : flags (flags_)
  48335. {
  48336. }
  48337. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48338. : flags (other.flags)
  48339. {
  48340. }
  48341. ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48342. {
  48343. flags = other.flags;
  48344. return *this;
  48345. }
  48346. ModifierKeys ModifierKeys::currentModifiers;
  48347. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48348. {
  48349. return currentModifiers;
  48350. }
  48351. int ModifierKeys::getNumMouseButtonsDown() const throw()
  48352. {
  48353. int num = 0;
  48354. if (isLeftButtonDown()) ++num;
  48355. if (isRightButtonDown()) ++num;
  48356. if (isMiddleButtonDown()) ++num;
  48357. return num;
  48358. }
  48359. END_JUCE_NAMESPACE
  48360. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  48361. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  48362. BEGIN_JUCE_NAMESPACE
  48363. struct AnimationTask
  48364. {
  48365. AnimationTask (Component* const comp)
  48366. : component (comp)
  48367. {
  48368. }
  48369. Component::SafePointer<Component> component;
  48370. Rectangle<int> destination;
  48371. int msElapsed, msTotal;
  48372. double startSpeed, midSpeed, endSpeed, lastProgress;
  48373. double left, top, right, bottom;
  48374. bool useTimeslice (const int elapsed)
  48375. {
  48376. if (component == 0)
  48377. return false;
  48378. msElapsed += elapsed;
  48379. double newProgress = msElapsed / (double) msTotal;
  48380. if (newProgress >= 0 && newProgress < 1.0)
  48381. {
  48382. newProgress = timeToDistance (newProgress);
  48383. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48384. jassert (newProgress >= lastProgress);
  48385. lastProgress = newProgress;
  48386. left += (destination.getX() - left) * delta;
  48387. top += (destination.getY() - top) * delta;
  48388. right += (destination.getRight() - right) * delta;
  48389. bottom += (destination.getBottom() - bottom) * delta;
  48390. if (delta < 1.0)
  48391. {
  48392. const Rectangle<int> newBounds (roundToInt (left),
  48393. roundToInt (top),
  48394. roundToInt (right - left),
  48395. roundToInt (bottom - top));
  48396. if (newBounds != destination)
  48397. {
  48398. component->setBounds (newBounds);
  48399. return true;
  48400. }
  48401. }
  48402. }
  48403. component->setBounds (destination);
  48404. return false;
  48405. }
  48406. void moveToFinalDestination()
  48407. {
  48408. if (component != 0)
  48409. component->setBounds (destination);
  48410. }
  48411. private:
  48412. inline double timeToDistance (const double time) const
  48413. {
  48414. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48415. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48416. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48417. }
  48418. };
  48419. ComponentAnimator::ComponentAnimator()
  48420. : lastTime (0)
  48421. {
  48422. }
  48423. ComponentAnimator::~ComponentAnimator()
  48424. {
  48425. cancelAllAnimations (false);
  48426. jassert (tasks.size() == 0);
  48427. }
  48428. void* ComponentAnimator::findTaskFor (Component* const component) const
  48429. {
  48430. for (int i = tasks.size(); --i >= 0;)
  48431. if (component == ((AnimationTask*) tasks.getUnchecked(i))->component)
  48432. return tasks.getUnchecked(i);
  48433. return 0;
  48434. }
  48435. void ComponentAnimator::animateComponent (Component* const component,
  48436. const Rectangle<int>& finalPosition,
  48437. const int millisecondsToSpendMoving,
  48438. const double startSpeed,
  48439. const double endSpeed)
  48440. {
  48441. if (component != 0)
  48442. {
  48443. AnimationTask* at = (AnimationTask*) findTaskFor (component);
  48444. if (at == 0)
  48445. {
  48446. at = new AnimationTask (component);
  48447. tasks.add (at);
  48448. sendChangeMessage (this);
  48449. }
  48450. at->msElapsed = 0;
  48451. at->lastProgress = 0;
  48452. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48453. at->destination = finalPosition;
  48454. // the speeds must be 0 or greater!
  48455. jassert (startSpeed >= 0 && endSpeed >= 0)
  48456. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48457. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48458. at->midSpeed = invTotalDistance;
  48459. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48460. at->left = component->getX();
  48461. at->top = component->getY();
  48462. at->right = component->getRight();
  48463. at->bottom = component->getBottom();
  48464. if (! isTimerRunning())
  48465. {
  48466. lastTime = Time::getMillisecondCounter();
  48467. startTimer (1000 / 50);
  48468. }
  48469. }
  48470. }
  48471. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48472. {
  48473. for (int i = tasks.size(); --i >= 0;)
  48474. {
  48475. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48476. if (moveComponentsToTheirFinalPositions)
  48477. at->moveToFinalDestination();
  48478. delete at;
  48479. tasks.remove (i);
  48480. sendChangeMessage (this);
  48481. }
  48482. }
  48483. void ComponentAnimator::cancelAnimation (Component* const component,
  48484. const bool moveComponentToItsFinalPosition)
  48485. {
  48486. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48487. if (at != 0)
  48488. {
  48489. if (moveComponentToItsFinalPosition)
  48490. at->moveToFinalDestination();
  48491. tasks.removeValue (at);
  48492. delete at;
  48493. sendChangeMessage (this);
  48494. }
  48495. }
  48496. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48497. {
  48498. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48499. if (at != 0)
  48500. return at->destination;
  48501. else if (component != 0)
  48502. return component->getBounds();
  48503. return Rectangle<int>();
  48504. }
  48505. bool ComponentAnimator::isAnimating (Component* component) const
  48506. {
  48507. return findTaskFor (component) != 0;
  48508. }
  48509. void ComponentAnimator::timerCallback()
  48510. {
  48511. const uint32 timeNow = Time::getMillisecondCounter();
  48512. if (lastTime == 0 || lastTime == timeNow)
  48513. lastTime = timeNow;
  48514. const int elapsed = timeNow - lastTime;
  48515. for (int i = tasks.size(); --i >= 0;)
  48516. {
  48517. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48518. if (! at->useTimeslice (elapsed))
  48519. {
  48520. tasks.remove (i);
  48521. delete at;
  48522. sendChangeMessage (this);
  48523. }
  48524. }
  48525. lastTime = timeNow;
  48526. if (tasks.size() == 0)
  48527. stopTimer();
  48528. }
  48529. END_JUCE_NAMESPACE
  48530. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48531. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48532. BEGIN_JUCE_NAMESPACE
  48533. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48534. : minW (0),
  48535. maxW (0x3fffffff),
  48536. minH (0),
  48537. maxH (0x3fffffff),
  48538. minOffTop (0),
  48539. minOffLeft (0),
  48540. minOffBottom (0),
  48541. minOffRight (0),
  48542. aspectRatio (0.0)
  48543. {
  48544. }
  48545. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48546. {
  48547. }
  48548. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48549. {
  48550. minW = minimumWidth;
  48551. }
  48552. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48553. {
  48554. maxW = maximumWidth;
  48555. }
  48556. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48557. {
  48558. minH = minimumHeight;
  48559. }
  48560. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48561. {
  48562. maxH = maximumHeight;
  48563. }
  48564. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  48565. {
  48566. jassert (maxW >= minimumWidth);
  48567. jassert (maxH >= minimumHeight);
  48568. jassert (minimumWidth > 0 && minimumHeight > 0);
  48569. minW = minimumWidth;
  48570. minH = minimumHeight;
  48571. if (minW > maxW)
  48572. maxW = minW;
  48573. if (minH > maxH)
  48574. maxH = minH;
  48575. }
  48576. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  48577. {
  48578. jassert (maximumWidth >= minW);
  48579. jassert (maximumHeight >= minH);
  48580. jassert (maximumWidth > 0 && maximumHeight > 0);
  48581. maxW = jmax (minW, maximumWidth);
  48582. maxH = jmax (minH, maximumHeight);
  48583. }
  48584. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  48585. const int minimumHeight,
  48586. const int maximumWidth,
  48587. const int maximumHeight) throw()
  48588. {
  48589. jassert (maximumWidth >= minimumWidth);
  48590. jassert (maximumHeight >= minimumHeight);
  48591. jassert (maximumWidth > 0 && maximumHeight > 0);
  48592. jassert (minimumWidth > 0 && minimumHeight > 0);
  48593. minW = jmax (0, minimumWidth);
  48594. minH = jmax (0, minimumHeight);
  48595. maxW = jmax (minW, maximumWidth);
  48596. maxH = jmax (minH, maximumHeight);
  48597. }
  48598. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  48599. const int minimumWhenOffTheLeft,
  48600. const int minimumWhenOffTheBottom,
  48601. const int minimumWhenOffTheRight) throw()
  48602. {
  48603. minOffTop = minimumWhenOffTheTop;
  48604. minOffLeft = minimumWhenOffTheLeft;
  48605. minOffBottom = minimumWhenOffTheBottom;
  48606. minOffRight = minimumWhenOffTheRight;
  48607. }
  48608. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  48609. {
  48610. aspectRatio = jmax (0.0, widthOverHeight);
  48611. }
  48612. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  48613. {
  48614. return aspectRatio;
  48615. }
  48616. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  48617. const Rectangle<int>& targetBounds,
  48618. const bool isStretchingTop,
  48619. const bool isStretchingLeft,
  48620. const bool isStretchingBottom,
  48621. const bool isStretchingRight)
  48622. {
  48623. jassert (component != 0);
  48624. Rectangle<int> limits, bounds (targetBounds);
  48625. BorderSize border;
  48626. Component* const parent = component->getParentComponent();
  48627. if (parent == 0)
  48628. {
  48629. ComponentPeer* peer = component->getPeer();
  48630. if (peer != 0)
  48631. border = peer->getFrameSize();
  48632. limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentre());
  48633. }
  48634. else
  48635. {
  48636. limits.setSize (parent->getWidth(), parent->getHeight());
  48637. }
  48638. border.addTo (bounds);
  48639. checkBounds (bounds,
  48640. border.addedTo (component->getBounds()), limits,
  48641. isStretchingTop, isStretchingLeft,
  48642. isStretchingBottom, isStretchingRight);
  48643. border.subtractFrom (bounds);
  48644. applyBoundsToComponent (component, bounds);
  48645. }
  48646. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  48647. {
  48648. setBoundsForComponent (component, component->getBounds(),
  48649. false, false, false, false);
  48650. }
  48651. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  48652. const Rectangle<int>& bounds)
  48653. {
  48654. component->setBounds (bounds);
  48655. }
  48656. void ComponentBoundsConstrainer::resizeStart()
  48657. {
  48658. }
  48659. void ComponentBoundsConstrainer::resizeEnd()
  48660. {
  48661. }
  48662. void ComponentBoundsConstrainer::checkBounds (Rectangle<int>& bounds,
  48663. const Rectangle<int>& old,
  48664. const Rectangle<int>& limits,
  48665. const bool isStretchingTop,
  48666. const bool isStretchingLeft,
  48667. const bool isStretchingBottom,
  48668. const bool isStretchingRight)
  48669. {
  48670. int x = bounds.getX();
  48671. int y = bounds.getY();
  48672. int w = bounds.getWidth();
  48673. int h = bounds.getHeight();
  48674. // constrain the size if it's being stretched..
  48675. if (isStretchingLeft)
  48676. {
  48677. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  48678. w = old.getRight() - x;
  48679. }
  48680. if (isStretchingRight)
  48681. {
  48682. w = jlimit (minW, maxW, w);
  48683. }
  48684. if (isStretchingTop)
  48685. {
  48686. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  48687. h = old.getBottom() - y;
  48688. }
  48689. if (isStretchingBottom)
  48690. {
  48691. h = jlimit (minH, maxH, h);
  48692. }
  48693. // constrain the aspect ratio if one has been specified..
  48694. if (aspectRatio > 0.0 && w > 0 && h > 0)
  48695. {
  48696. bool adjustWidth;
  48697. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48698. {
  48699. adjustWidth = true;
  48700. }
  48701. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48702. {
  48703. adjustWidth = false;
  48704. }
  48705. else
  48706. {
  48707. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  48708. const double newRatio = fabs (w / (double) h);
  48709. adjustWidth = (oldRatio > newRatio);
  48710. }
  48711. if (adjustWidth)
  48712. {
  48713. w = roundToInt (h * aspectRatio);
  48714. if (w > maxW || w < minW)
  48715. {
  48716. w = jlimit (minW, maxW, w);
  48717. h = roundToInt (w / aspectRatio);
  48718. }
  48719. }
  48720. else
  48721. {
  48722. h = roundToInt (w / aspectRatio);
  48723. if (h > maxH || h < minH)
  48724. {
  48725. h = jlimit (minH, maxH, h);
  48726. w = roundToInt (h * aspectRatio);
  48727. }
  48728. }
  48729. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48730. {
  48731. x = old.getX() + (old.getWidth() - w) / 2;
  48732. }
  48733. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48734. {
  48735. y = old.getY() + (old.getHeight() - h) / 2;
  48736. }
  48737. else
  48738. {
  48739. if (isStretchingLeft)
  48740. x = old.getRight() - w;
  48741. if (isStretchingTop)
  48742. y = old.getBottom() - h;
  48743. }
  48744. }
  48745. // ...and constrain the position if limits have been set for that.
  48746. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  48747. {
  48748. if (minOffTop > 0)
  48749. {
  48750. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  48751. if (y < limit)
  48752. {
  48753. if (isStretchingTop)
  48754. h -= (limit - y);
  48755. y = limit;
  48756. }
  48757. }
  48758. if (minOffLeft > 0)
  48759. {
  48760. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  48761. if (x < limit)
  48762. {
  48763. if (isStretchingLeft)
  48764. w -= (limit - x);
  48765. x = limit;
  48766. }
  48767. }
  48768. if (minOffBottom > 0)
  48769. {
  48770. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  48771. if (y > limit)
  48772. {
  48773. if (isStretchingBottom)
  48774. h += (limit - y);
  48775. else
  48776. y = limit;
  48777. }
  48778. }
  48779. if (minOffRight > 0)
  48780. {
  48781. const int limit = limits.getRight() - jmin (minOffRight, w);
  48782. if (x > limit)
  48783. {
  48784. if (isStretchingRight)
  48785. w += (limit - x);
  48786. else
  48787. x = limit;
  48788. }
  48789. }
  48790. }
  48791. jassert (w >= 0 && h >= 0);
  48792. bounds = Rectangle<int> (x, y, w, h);
  48793. }
  48794. END_JUCE_NAMESPACE
  48795. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48796. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48797. BEGIN_JUCE_NAMESPACE
  48798. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  48799. : component (component_),
  48800. lastPeer (0),
  48801. reentrant (false)
  48802. {
  48803. jassert (component != 0); // can't use this with a null pointer..
  48804. component->addComponentListener (this);
  48805. registerWithParentComps();
  48806. }
  48807. ComponentMovementWatcher::~ComponentMovementWatcher()
  48808. {
  48809. component->removeComponentListener (this);
  48810. unregister();
  48811. }
  48812. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  48813. {
  48814. // agh! don't delete the target component without deleting this object first!
  48815. jassert (component != 0);
  48816. if (! reentrant)
  48817. {
  48818. reentrant = true;
  48819. ComponentPeer* const peer = component->getPeer();
  48820. if (peer != lastPeer)
  48821. {
  48822. componentPeerChanged();
  48823. if (component == 0)
  48824. return;
  48825. lastPeer = peer;
  48826. }
  48827. unregister();
  48828. registerWithParentComps();
  48829. reentrant = false;
  48830. componentMovedOrResized (*component, true, true);
  48831. }
  48832. }
  48833. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  48834. {
  48835. // agh! don't delete the target component without deleting this object first!
  48836. jassert (component != 0);
  48837. if (wasMoved)
  48838. {
  48839. const Point<int> pos (component->relativePositionToOtherComponent (component->getTopLevelComponent(), Point<int>()));
  48840. wasMoved = lastBounds.getPosition() != pos;
  48841. lastBounds.setPosition (pos);
  48842. }
  48843. wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight());
  48844. lastBounds.setSize (component->getWidth(), component->getHeight());
  48845. if (wasMoved || wasResized)
  48846. componentMovedOrResized (wasMoved, wasResized);
  48847. }
  48848. void ComponentMovementWatcher::registerWithParentComps() throw()
  48849. {
  48850. Component* p = component->getParentComponent();
  48851. while (p != 0)
  48852. {
  48853. p->addComponentListener (this);
  48854. registeredParentComps.add (p);
  48855. p = p->getParentComponent();
  48856. }
  48857. }
  48858. void ComponentMovementWatcher::unregister() throw()
  48859. {
  48860. for (int i = registeredParentComps.size(); --i >= 0;)
  48861. ((Component*) registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  48862. registeredParentComps.clear();
  48863. }
  48864. END_JUCE_NAMESPACE
  48865. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48866. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  48867. BEGIN_JUCE_NAMESPACE
  48868. GroupComponent::GroupComponent (const String& componentName,
  48869. const String& labelText)
  48870. : Component (componentName),
  48871. text (labelText),
  48872. justification (Justification::left)
  48873. {
  48874. setInterceptsMouseClicks (false, true);
  48875. }
  48876. GroupComponent::~GroupComponent()
  48877. {
  48878. }
  48879. void GroupComponent::setText (const String& newText) throw()
  48880. {
  48881. if (text != newText)
  48882. {
  48883. text = newText;
  48884. repaint();
  48885. }
  48886. }
  48887. const String GroupComponent::getText() const throw()
  48888. {
  48889. return text;
  48890. }
  48891. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  48892. {
  48893. if (justification.getFlags() != newJustification.getFlags())
  48894. {
  48895. justification = newJustification;
  48896. repaint();
  48897. }
  48898. }
  48899. void GroupComponent::paint (Graphics& g)
  48900. {
  48901. getLookAndFeel()
  48902. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  48903. text, justification,
  48904. *this);
  48905. }
  48906. void GroupComponent::enablementChanged()
  48907. {
  48908. repaint();
  48909. }
  48910. void GroupComponent::colourChanged()
  48911. {
  48912. repaint();
  48913. }
  48914. END_JUCE_NAMESPACE
  48915. /*** End of inlined file: juce_GroupComponent.cpp ***/
  48916. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  48917. BEGIN_JUCE_NAMESPACE
  48918. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  48919. : DocumentWindow (String::empty, backgroundColour,
  48920. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  48921. {
  48922. }
  48923. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  48924. {
  48925. }
  48926. void MultiDocumentPanelWindow::maximiseButtonPressed()
  48927. {
  48928. MultiDocumentPanel* const owner = getOwner();
  48929. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48930. if (owner != 0)
  48931. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  48932. }
  48933. void MultiDocumentPanelWindow::closeButtonPressed()
  48934. {
  48935. MultiDocumentPanel* const owner = getOwner();
  48936. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48937. if (owner != 0)
  48938. owner->closeDocument (getContentComponent(), true);
  48939. }
  48940. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  48941. {
  48942. DocumentWindow::activeWindowStatusChanged();
  48943. updateOrder();
  48944. }
  48945. void MultiDocumentPanelWindow::broughtToFront()
  48946. {
  48947. DocumentWindow::broughtToFront();
  48948. updateOrder();
  48949. }
  48950. void MultiDocumentPanelWindow::updateOrder()
  48951. {
  48952. MultiDocumentPanel* const owner = getOwner();
  48953. if (owner != 0)
  48954. owner->updateOrder();
  48955. }
  48956. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  48957. {
  48958. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48959. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48960. }
  48961. class MDITabbedComponentInternal : public TabbedComponent
  48962. {
  48963. public:
  48964. MDITabbedComponentInternal()
  48965. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  48966. {
  48967. }
  48968. ~MDITabbedComponentInternal()
  48969. {
  48970. }
  48971. void currentTabChanged (const int, const String&)
  48972. {
  48973. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48974. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48975. if (owner != 0)
  48976. owner->updateOrder();
  48977. }
  48978. };
  48979. MultiDocumentPanel::MultiDocumentPanel()
  48980. : mode (MaximisedWindowsWithTabs),
  48981. tabComponent (0),
  48982. backgroundColour (Colours::lightblue),
  48983. maximumNumDocuments (0),
  48984. numDocsBeforeTabsUsed (0)
  48985. {
  48986. setOpaque (true);
  48987. }
  48988. MultiDocumentPanel::~MultiDocumentPanel()
  48989. {
  48990. closeAllDocuments (false);
  48991. }
  48992. static bool shouldDeleteComp (Component* const c)
  48993. {
  48994. return c->getProperties() ["mdiDocumentDelete_"];
  48995. }
  48996. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  48997. {
  48998. while (components.size() > 0)
  48999. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  49000. return false;
  49001. return true;
  49002. }
  49003. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  49004. {
  49005. return new MultiDocumentPanelWindow (backgroundColour);
  49006. }
  49007. void MultiDocumentPanel::addWindow (Component* component)
  49008. {
  49009. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  49010. dw->setResizable (true, false);
  49011. dw->setContentComponent (component, false, true);
  49012. dw->setName (component->getName());
  49013. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  49014. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  49015. int x = 4;
  49016. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  49017. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  49018. x += 16;
  49019. dw->setTopLeftPosition (x, x);
  49020. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  49021. if (pos.toString().isNotEmpty())
  49022. dw->restoreWindowStateFromString (pos.toString());
  49023. addAndMakeVisible (dw);
  49024. dw->toFront (true);
  49025. }
  49026. bool MultiDocumentPanel::addDocument (Component* const component,
  49027. const Colour& docColour,
  49028. const bool deleteWhenRemoved)
  49029. {
  49030. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  49031. // with a frame-within-a-frame! Just pass in the bare content component.
  49032. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  49033. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  49034. return false;
  49035. components.add (component);
  49036. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  49037. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  49038. component->addComponentListener (this);
  49039. if (mode == FloatingWindows)
  49040. {
  49041. if (isFullscreenWhenOneDocument())
  49042. {
  49043. if (components.size() == 1)
  49044. {
  49045. addAndMakeVisible (component);
  49046. }
  49047. else
  49048. {
  49049. if (components.size() == 2)
  49050. addWindow (components.getFirst());
  49051. addWindow (component);
  49052. }
  49053. }
  49054. else
  49055. {
  49056. addWindow (component);
  49057. }
  49058. }
  49059. else
  49060. {
  49061. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  49062. {
  49063. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  49064. Array <Component*> temp (components);
  49065. for (int i = 0; i < temp.size(); ++i)
  49066. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  49067. resized();
  49068. }
  49069. else
  49070. {
  49071. if (tabComponent != 0)
  49072. tabComponent->addTab (component->getName(), docColour, component, false);
  49073. else
  49074. addAndMakeVisible (component);
  49075. }
  49076. setActiveDocument (component);
  49077. }
  49078. resized();
  49079. activeDocumentChanged();
  49080. return true;
  49081. }
  49082. bool MultiDocumentPanel::closeDocument (Component* component,
  49083. const bool checkItsOkToCloseFirst)
  49084. {
  49085. if (components.contains (component))
  49086. {
  49087. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  49088. return false;
  49089. component->removeComponentListener (this);
  49090. const bool shouldDelete = shouldDeleteComp (component);
  49091. component->getProperties().remove ("mdiDocumentDelete_");
  49092. component->getProperties().remove ("mdiDocumentBkg_");
  49093. if (mode == FloatingWindows)
  49094. {
  49095. for (int i = getNumChildComponents(); --i >= 0;)
  49096. {
  49097. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49098. if (dw != 0 && dw->getContentComponent() == component)
  49099. {
  49100. dw->setContentComponent (0, false);
  49101. delete dw;
  49102. break;
  49103. }
  49104. }
  49105. if (shouldDelete)
  49106. delete component;
  49107. components.removeValue (component);
  49108. if (isFullscreenWhenOneDocument() && components.size() == 1)
  49109. {
  49110. for (int i = getNumChildComponents(); --i >= 0;)
  49111. {
  49112. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49113. if (dw != 0)
  49114. {
  49115. dw->setContentComponent (0, false);
  49116. delete dw;
  49117. }
  49118. }
  49119. addAndMakeVisible (components.getFirst());
  49120. }
  49121. }
  49122. else
  49123. {
  49124. jassert (components.indexOf (component) >= 0);
  49125. if (tabComponent != 0)
  49126. {
  49127. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49128. if (tabComponent->getTabContentComponent (i) == component)
  49129. tabComponent->removeTab (i);
  49130. }
  49131. else
  49132. {
  49133. removeChildComponent (component);
  49134. }
  49135. if (shouldDelete)
  49136. delete component;
  49137. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  49138. deleteAndZero (tabComponent);
  49139. components.removeValue (component);
  49140. if (components.size() > 0 && tabComponent == 0)
  49141. addAndMakeVisible (components.getFirst());
  49142. }
  49143. resized();
  49144. activeDocumentChanged();
  49145. }
  49146. else
  49147. {
  49148. jassertfalse
  49149. }
  49150. return true;
  49151. }
  49152. int MultiDocumentPanel::getNumDocuments() const throw()
  49153. {
  49154. return components.size();
  49155. }
  49156. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  49157. {
  49158. return components [index];
  49159. }
  49160. Component* MultiDocumentPanel::getActiveDocument() const throw()
  49161. {
  49162. if (mode == FloatingWindows)
  49163. {
  49164. for (int i = getNumChildComponents(); --i >= 0;)
  49165. {
  49166. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49167. if (dw != 0 && dw->isActiveWindow())
  49168. return dw->getContentComponent();
  49169. }
  49170. }
  49171. return components.getLast();
  49172. }
  49173. void MultiDocumentPanel::setActiveDocument (Component* component)
  49174. {
  49175. if (mode == FloatingWindows)
  49176. {
  49177. component = getContainerComp (component);
  49178. if (component != 0)
  49179. component->toFront (true);
  49180. }
  49181. else if (tabComponent != 0)
  49182. {
  49183. jassert (components.indexOf (component) >= 0);
  49184. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49185. {
  49186. if (tabComponent->getTabContentComponent (i) == component)
  49187. {
  49188. tabComponent->setCurrentTabIndex (i);
  49189. break;
  49190. }
  49191. }
  49192. }
  49193. else
  49194. {
  49195. component->grabKeyboardFocus();
  49196. }
  49197. }
  49198. void MultiDocumentPanel::activeDocumentChanged()
  49199. {
  49200. }
  49201. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  49202. {
  49203. maximumNumDocuments = newNumber;
  49204. }
  49205. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  49206. {
  49207. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  49208. }
  49209. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  49210. {
  49211. return numDocsBeforeTabsUsed != 0;
  49212. }
  49213. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  49214. {
  49215. if (mode != newLayoutMode)
  49216. {
  49217. mode = newLayoutMode;
  49218. if (mode == FloatingWindows)
  49219. {
  49220. deleteAndZero (tabComponent);
  49221. }
  49222. else
  49223. {
  49224. for (int i = getNumChildComponents(); --i >= 0;)
  49225. {
  49226. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49227. if (dw != 0)
  49228. {
  49229. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  49230. dw->setContentComponent (0, false);
  49231. delete dw;
  49232. }
  49233. }
  49234. }
  49235. resized();
  49236. const Array <Component*> tempComps (components);
  49237. components.clear();
  49238. for (int i = 0; i < tempComps.size(); ++i)
  49239. {
  49240. Component* const c = tempComps.getUnchecked(i);
  49241. addDocument (c,
  49242. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  49243. shouldDeleteComp (c));
  49244. }
  49245. }
  49246. }
  49247. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  49248. {
  49249. if (backgroundColour != newBackgroundColour)
  49250. {
  49251. backgroundColour = newBackgroundColour;
  49252. setOpaque (newBackgroundColour.isOpaque());
  49253. repaint();
  49254. }
  49255. }
  49256. void MultiDocumentPanel::paint (Graphics& g)
  49257. {
  49258. g.fillAll (backgroundColour);
  49259. }
  49260. void MultiDocumentPanel::resized()
  49261. {
  49262. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49263. {
  49264. for (int i = getNumChildComponents(); --i >= 0;)
  49265. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49266. }
  49267. setWantsKeyboardFocus (components.size() == 0);
  49268. }
  49269. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49270. {
  49271. if (mode == FloatingWindows)
  49272. {
  49273. for (int i = 0; i < getNumChildComponents(); ++i)
  49274. {
  49275. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49276. if (dw != 0 && dw->getContentComponent() == c)
  49277. {
  49278. c = dw;
  49279. break;
  49280. }
  49281. }
  49282. }
  49283. return c;
  49284. }
  49285. void MultiDocumentPanel::componentNameChanged (Component&)
  49286. {
  49287. if (mode == FloatingWindows)
  49288. {
  49289. for (int i = 0; i < getNumChildComponents(); ++i)
  49290. {
  49291. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49292. if (dw != 0)
  49293. dw->setName (dw->getContentComponent()->getName());
  49294. }
  49295. }
  49296. else if (tabComponent != 0)
  49297. {
  49298. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49299. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49300. }
  49301. }
  49302. void MultiDocumentPanel::updateOrder()
  49303. {
  49304. const Array <Component*> oldList (components);
  49305. if (mode == FloatingWindows)
  49306. {
  49307. components.clear();
  49308. for (int i = 0; i < getNumChildComponents(); ++i)
  49309. {
  49310. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49311. if (dw != 0)
  49312. components.add (dw->getContentComponent());
  49313. }
  49314. }
  49315. else
  49316. {
  49317. if (tabComponent != 0)
  49318. {
  49319. Component* const current = tabComponent->getCurrentContentComponent();
  49320. if (current != 0)
  49321. {
  49322. components.removeValue (current);
  49323. components.add (current);
  49324. }
  49325. }
  49326. }
  49327. if (components != oldList)
  49328. activeDocumentChanged();
  49329. }
  49330. END_JUCE_NAMESPACE
  49331. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  49332. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  49333. BEGIN_JUCE_NAMESPACE
  49334. enum ResizableBorderComponentZones
  49335. {
  49336. zoneL = 1,
  49337. zoneR = 2,
  49338. zoneT = 4,
  49339. zoneB = 8
  49340. };
  49341. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49342. ComponentBoundsConstrainer* const constrainer_)
  49343. : component (componentToResize),
  49344. constrainer (constrainer_),
  49345. borderSize (5),
  49346. mouseZone (0)
  49347. {
  49348. }
  49349. ResizableBorderComponent::~ResizableBorderComponent()
  49350. {
  49351. }
  49352. void ResizableBorderComponent::paint (Graphics& g)
  49353. {
  49354. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49355. }
  49356. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49357. {
  49358. updateMouseZone (e);
  49359. }
  49360. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49361. {
  49362. updateMouseZone (e);
  49363. }
  49364. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49365. {
  49366. if (component == 0)
  49367. {
  49368. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49369. return;
  49370. }
  49371. updateMouseZone (e);
  49372. originalBounds = component->getBounds();
  49373. if (constrainer != 0)
  49374. constrainer->resizeStart();
  49375. }
  49376. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49377. {
  49378. if (component == 0)
  49379. {
  49380. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49381. return;
  49382. }
  49383. Rectangle<int> bounds (originalBounds);
  49384. if ((mouseZone & zoneL) != 0)
  49385. bounds.setLeft (bounds.getX() + e.getDistanceFromDragStartX());
  49386. if ((mouseZone & zoneT) != 0)
  49387. bounds.setTop (bounds.getY() + e.getDistanceFromDragStartY());
  49388. if ((mouseZone & zoneR) != 0)
  49389. bounds.setWidth (bounds.getWidth() + e.getDistanceFromDragStartX());
  49390. if ((mouseZone & zoneB) != 0)
  49391. bounds.setHeight (bounds.getHeight() + e.getDistanceFromDragStartY());
  49392. if (constrainer != 0)
  49393. constrainer->setBoundsForComponent (component, bounds,
  49394. (mouseZone & zoneT) != 0,
  49395. (mouseZone & zoneL) != 0,
  49396. (mouseZone & zoneB) != 0,
  49397. (mouseZone & zoneR) != 0);
  49398. else
  49399. component->setBounds (bounds);
  49400. }
  49401. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49402. {
  49403. if (constrainer != 0)
  49404. constrainer->resizeEnd();
  49405. }
  49406. bool ResizableBorderComponent::hitTest (int x, int y)
  49407. {
  49408. return x < borderSize.getLeft()
  49409. || x >= getWidth() - borderSize.getRight()
  49410. || y < borderSize.getTop()
  49411. || y >= getHeight() - borderSize.getBottom();
  49412. }
  49413. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize)
  49414. {
  49415. if (borderSize != newBorderSize)
  49416. {
  49417. borderSize = newBorderSize;
  49418. repaint();
  49419. }
  49420. }
  49421. const BorderSize ResizableBorderComponent::getBorderThickness() const
  49422. {
  49423. return borderSize;
  49424. }
  49425. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e)
  49426. {
  49427. int newZone = 0;
  49428. if (ResizableBorderComponent::hitTest (e.x, e.y))
  49429. {
  49430. if (e.x < jmax (borderSize.getLeft(),
  49431. proportionOfWidth (0.1f),
  49432. jmin (10, proportionOfWidth (0.33f))))
  49433. newZone |= zoneL;
  49434. else if (e.x >= jmin (getWidth() - borderSize.getRight(),
  49435. proportionOfWidth (0.9f),
  49436. getWidth() - jmin (10, proportionOfWidth (0.33f))))
  49437. newZone |= zoneR;
  49438. if (e.y < jmax (borderSize.getTop(),
  49439. proportionOfHeight (0.1f),
  49440. jmin (10, proportionOfHeight (0.33f))))
  49441. newZone |= zoneT;
  49442. else if (e.y >= jmin (getHeight() - borderSize.getBottom(),
  49443. proportionOfHeight (0.9f),
  49444. getHeight() - jmin (10, proportionOfHeight (0.33f))))
  49445. newZone |= zoneB;
  49446. }
  49447. if (mouseZone != newZone)
  49448. {
  49449. mouseZone = newZone;
  49450. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49451. switch (newZone)
  49452. {
  49453. case (zoneL | zoneT): mc = MouseCursor::TopLeftCornerResizeCursor; break;
  49454. case zoneT: mc = MouseCursor::TopEdgeResizeCursor; break;
  49455. case (zoneR | zoneT): mc = MouseCursor::TopRightCornerResizeCursor; break;
  49456. case zoneL: mc = MouseCursor::LeftEdgeResizeCursor; break;
  49457. case zoneR: mc = MouseCursor::RightEdgeResizeCursor; break;
  49458. case (zoneL | zoneB): mc = MouseCursor::BottomLeftCornerResizeCursor; break;
  49459. case zoneB: mc = MouseCursor::BottomEdgeResizeCursor; break;
  49460. case (zoneR | zoneB): mc = MouseCursor::BottomRightCornerResizeCursor; break;
  49461. default: break;
  49462. }
  49463. setMouseCursor (mc);
  49464. }
  49465. }
  49466. END_JUCE_NAMESPACE
  49467. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49468. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49469. BEGIN_JUCE_NAMESPACE
  49470. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49471. ComponentBoundsConstrainer* const constrainer_)
  49472. : component (componentToResize),
  49473. constrainer (constrainer_)
  49474. {
  49475. setRepaintsOnMouseActivity (true);
  49476. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49477. }
  49478. ResizableCornerComponent::~ResizableCornerComponent()
  49479. {
  49480. }
  49481. void ResizableCornerComponent::paint (Graphics& g)
  49482. {
  49483. getLookAndFeel()
  49484. .drawCornerResizer (g, getWidth(), getHeight(),
  49485. isMouseOverOrDragging(),
  49486. isMouseButtonDown());
  49487. }
  49488. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49489. {
  49490. if (component == 0)
  49491. {
  49492. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49493. return;
  49494. }
  49495. originalBounds = component->getBounds();
  49496. if (constrainer != 0)
  49497. constrainer->resizeStart();
  49498. }
  49499. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49500. {
  49501. if (component == 0)
  49502. {
  49503. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49504. return;
  49505. }
  49506. Rectangle<int> r (originalBounds.withSize (originalBounds.getWidth() + e.getDistanceFromDragStartX(),
  49507. originalBounds.getHeight() + e.getDistanceFromDragStartY()));
  49508. if (constrainer != 0)
  49509. constrainer->setBoundsForComponent (component, r, false, false, true, true);
  49510. else
  49511. component->setBounds (r);
  49512. }
  49513. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  49514. {
  49515. if (constrainer != 0)
  49516. constrainer->resizeStart();
  49517. }
  49518. bool ResizableCornerComponent::hitTest (int x, int y)
  49519. {
  49520. if (getWidth() <= 0)
  49521. return false;
  49522. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  49523. return y >= yAtX - getHeight() / 4;
  49524. }
  49525. END_JUCE_NAMESPACE
  49526. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  49527. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  49528. BEGIN_JUCE_NAMESPACE
  49529. class ScrollbarButton : public Button
  49530. {
  49531. public:
  49532. int direction;
  49533. ScrollbarButton (const int direction_,
  49534. ScrollBar& owner_) throw()
  49535. : Button (String::empty),
  49536. direction (direction_),
  49537. owner (owner_)
  49538. {
  49539. setWantsKeyboardFocus (false);
  49540. }
  49541. ~ScrollbarButton()
  49542. {
  49543. }
  49544. void paintButton (Graphics& g,
  49545. bool isMouseOver,
  49546. bool isMouseDown)
  49547. {
  49548. getLookAndFeel()
  49549. .drawScrollbarButton (g, owner,
  49550. getWidth(), getHeight(),
  49551. direction,
  49552. owner.isVertical(),
  49553. isMouseOver, isMouseDown);
  49554. }
  49555. void clicked()
  49556. {
  49557. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  49558. }
  49559. juce_UseDebuggingNewOperator
  49560. private:
  49561. ScrollBar& owner;
  49562. ScrollbarButton (const ScrollbarButton&);
  49563. ScrollbarButton& operator= (const ScrollbarButton&);
  49564. };
  49565. ScrollBar::ScrollBar (const bool vertical_,
  49566. const bool buttonsAreVisible)
  49567. : minimum (0.0),
  49568. maximum (1.0),
  49569. rangeStart (0.0),
  49570. rangeSize (0.1),
  49571. singleStepSize (0.1),
  49572. thumbAreaStart (0),
  49573. thumbAreaSize (0),
  49574. thumbStart (0),
  49575. thumbSize (0),
  49576. initialDelayInMillisecs (100),
  49577. repeatDelayInMillisecs (50),
  49578. minimumDelayInMillisecs (10),
  49579. vertical (vertical_),
  49580. isDraggingThumb (false),
  49581. alwaysVisible (false),
  49582. upButton (0),
  49583. downButton (0)
  49584. {
  49585. setButtonVisibility (buttonsAreVisible);
  49586. setRepaintsOnMouseActivity (true);
  49587. setFocusContainer (true);
  49588. }
  49589. ScrollBar::~ScrollBar()
  49590. {
  49591. deleteAllChildren();
  49592. }
  49593. void ScrollBar::setRangeLimits (const double newMinimum,
  49594. const double newMaximum) throw()
  49595. {
  49596. minimum = newMinimum;
  49597. maximum = newMaximum;
  49598. jassert (maximum >= minimum); // these can't be the wrong way round!
  49599. setCurrentRangeStart (rangeStart);
  49600. updateThumbPosition();
  49601. }
  49602. void ScrollBar::setCurrentRange (double newStart,
  49603. double newSize) throw()
  49604. {
  49605. newSize = jlimit (0.0, maximum - minimum, newSize);
  49606. newStart = jlimit (minimum, maximum - newSize, newStart);
  49607. if (rangeStart != newStart
  49608. || rangeSize != newSize)
  49609. {
  49610. rangeStart = newStart;
  49611. rangeSize = newSize;
  49612. updateThumbPosition();
  49613. triggerAsyncUpdate();
  49614. }
  49615. }
  49616. void ScrollBar::setCurrentRangeStart (double newStart) throw()
  49617. {
  49618. setCurrentRange (newStart, rangeSize);
  49619. }
  49620. void ScrollBar::setSingleStepSize (const double newSingleStepSize) throw()
  49621. {
  49622. singleStepSize = newSingleStepSize;
  49623. }
  49624. void ScrollBar::moveScrollbarInSteps (const int howManySteps) throw()
  49625. {
  49626. setCurrentRangeStart (rangeStart + howManySteps * singleStepSize);
  49627. }
  49628. void ScrollBar::moveScrollbarInPages (const int howManyPages) throw()
  49629. {
  49630. setCurrentRangeStart (rangeStart + howManyPages * rangeSize);
  49631. }
  49632. void ScrollBar::scrollToTop() throw()
  49633. {
  49634. setCurrentRangeStart (minimum);
  49635. }
  49636. void ScrollBar::scrollToBottom() throw()
  49637. {
  49638. setCurrentRangeStart (maximum - rangeSize);
  49639. }
  49640. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  49641. const int repeatDelayInMillisecs_,
  49642. const int minimumDelayInMillisecs_) throw()
  49643. {
  49644. initialDelayInMillisecs = initialDelayInMillisecs_;
  49645. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  49646. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  49647. if (upButton != 0)
  49648. {
  49649. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49650. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49651. }
  49652. }
  49653. void ScrollBar::addListener (ScrollBarListener* const listener) throw()
  49654. {
  49655. listeners.add (listener);
  49656. }
  49657. void ScrollBar::removeListener (ScrollBarListener* const listener) throw()
  49658. {
  49659. listeners.remove (listener);
  49660. }
  49661. void ScrollBar::handleAsyncUpdate()
  49662. {
  49663. listeners.call (&ScrollBarListener::scrollBarMoved, this, rangeStart);
  49664. }
  49665. void ScrollBar::updateThumbPosition() throw()
  49666. {
  49667. int newThumbSize = roundToInt ((maximum > minimum) ? (rangeSize * thumbAreaSize) / (maximum - minimum)
  49668. : thumbAreaSize);
  49669. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49670. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  49671. if (newThumbSize > thumbAreaSize)
  49672. newThumbSize = thumbAreaSize;
  49673. int newThumbStart = thumbAreaStart;
  49674. if (maximum - minimum > rangeSize)
  49675. newThumbStart += roundToInt (((rangeStart - minimum) * (thumbAreaSize - newThumbSize))
  49676. / ((maximum - minimum) - rangeSize));
  49677. setVisible (alwaysVisible || (maximum - minimum > rangeSize && rangeSize > 0.0));
  49678. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  49679. {
  49680. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  49681. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  49682. if (vertical)
  49683. repaint (0, repaintStart, getWidth(), repaintSize);
  49684. else
  49685. repaint (repaintStart, 0, repaintSize, getHeight());
  49686. thumbStart = newThumbStart;
  49687. thumbSize = newThumbSize;
  49688. }
  49689. }
  49690. void ScrollBar::setOrientation (const bool shouldBeVertical) throw()
  49691. {
  49692. if (vertical != shouldBeVertical)
  49693. {
  49694. vertical = shouldBeVertical;
  49695. if (upButton != 0)
  49696. {
  49697. ((ScrollbarButton*) upButton)->direction = (vertical) ? 0 : 3;
  49698. ((ScrollbarButton*) downButton)->direction = (vertical) ? 2 : 1;
  49699. }
  49700. updateThumbPosition();
  49701. }
  49702. }
  49703. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  49704. {
  49705. deleteAndZero (upButton);
  49706. deleteAndZero (downButton);
  49707. if (buttonsAreVisible)
  49708. {
  49709. addAndMakeVisible (upButton = new ScrollbarButton ((vertical) ? 0 : 3, *this));
  49710. addAndMakeVisible (downButton = new ScrollbarButton ((vertical) ? 2 : 1, *this));
  49711. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49712. }
  49713. updateThumbPosition();
  49714. }
  49715. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  49716. {
  49717. alwaysVisible = ! shouldHideWhenFullRange;
  49718. updateThumbPosition();
  49719. }
  49720. void ScrollBar::paint (Graphics& g)
  49721. {
  49722. if (thumbAreaSize > 0)
  49723. {
  49724. LookAndFeel& lf = getLookAndFeel();
  49725. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  49726. ? thumbSize : 0;
  49727. if (vertical)
  49728. {
  49729. lf.drawScrollbar (g, *this,
  49730. 0, thumbAreaStart,
  49731. getWidth(), thumbAreaSize,
  49732. vertical,
  49733. thumbStart, thumb,
  49734. isMouseOver(), isMouseButtonDown());
  49735. }
  49736. else
  49737. {
  49738. lf.drawScrollbar (g, *this,
  49739. thumbAreaStart, 0,
  49740. thumbAreaSize, getHeight(),
  49741. vertical,
  49742. thumbStart, thumb,
  49743. isMouseOver(), isMouseButtonDown());
  49744. }
  49745. }
  49746. }
  49747. void ScrollBar::lookAndFeelChanged()
  49748. {
  49749. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  49750. }
  49751. void ScrollBar::resized()
  49752. {
  49753. const int length = ((vertical) ? getHeight() : getWidth());
  49754. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  49755. : 0;
  49756. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49757. {
  49758. thumbAreaStart = length >> 1;
  49759. thumbAreaSize = 0;
  49760. }
  49761. else
  49762. {
  49763. thumbAreaStart = buttonSize;
  49764. thumbAreaSize = length - (buttonSize << 1);
  49765. }
  49766. if (upButton != 0)
  49767. {
  49768. if (vertical)
  49769. {
  49770. upButton->setBounds (0, 0, getWidth(), buttonSize);
  49771. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  49772. }
  49773. else
  49774. {
  49775. upButton->setBounds (0, 0, buttonSize, getHeight());
  49776. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  49777. }
  49778. }
  49779. updateThumbPosition();
  49780. }
  49781. void ScrollBar::mouseDown (const MouseEvent& e)
  49782. {
  49783. isDraggingThumb = false;
  49784. lastMousePos = vertical ? e.y : e.x;
  49785. dragStartMousePos = lastMousePos;
  49786. dragStartRange = rangeStart;
  49787. if (dragStartMousePos < thumbStart)
  49788. {
  49789. moveScrollbarInPages (-1);
  49790. startTimer (400);
  49791. }
  49792. else if (dragStartMousePos >= thumbStart + thumbSize)
  49793. {
  49794. moveScrollbarInPages (1);
  49795. startTimer (400);
  49796. }
  49797. else
  49798. {
  49799. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49800. && (thumbAreaSize > thumbSize);
  49801. }
  49802. }
  49803. void ScrollBar::mouseDrag (const MouseEvent& e)
  49804. {
  49805. if (isDraggingThumb)
  49806. {
  49807. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  49808. setCurrentRangeStart (dragStartRange
  49809. + deltaPixels * ((maximum - minimum) - rangeSize)
  49810. / (thumbAreaSize - thumbSize));
  49811. }
  49812. else
  49813. {
  49814. lastMousePos = (vertical) ? e.y : e.x;
  49815. }
  49816. }
  49817. void ScrollBar::mouseUp (const MouseEvent&)
  49818. {
  49819. isDraggingThumb = false;
  49820. stopTimer();
  49821. repaint();
  49822. }
  49823. void ScrollBar::mouseWheelMove (const MouseEvent&,
  49824. float wheelIncrementX,
  49825. float wheelIncrementY)
  49826. {
  49827. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  49828. if (increment < 0)
  49829. increment = jmin (increment * 10.0f, -1.0f);
  49830. else if (increment > 0)
  49831. increment = jmax (increment * 10.0f, 1.0f);
  49832. setCurrentRangeStart (rangeStart - singleStepSize * increment);
  49833. }
  49834. void ScrollBar::timerCallback()
  49835. {
  49836. if (isMouseButtonDown())
  49837. {
  49838. startTimer (40);
  49839. if (lastMousePos < thumbStart)
  49840. setCurrentRangeStart (rangeStart - rangeSize);
  49841. else if (lastMousePos > thumbStart + thumbSize)
  49842. setCurrentRangeStart (rangeStart + rangeSize);
  49843. }
  49844. else
  49845. {
  49846. stopTimer();
  49847. }
  49848. }
  49849. bool ScrollBar::keyPressed (const KeyPress& key)
  49850. {
  49851. if (! isVisible())
  49852. return false;
  49853. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  49854. moveScrollbarInSteps (-1);
  49855. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  49856. moveScrollbarInSteps (1);
  49857. else if (key.isKeyCode (KeyPress::pageUpKey))
  49858. moveScrollbarInPages (-1);
  49859. else if (key.isKeyCode (KeyPress::pageDownKey))
  49860. moveScrollbarInPages (1);
  49861. else if (key.isKeyCode (KeyPress::homeKey))
  49862. scrollToTop();
  49863. else if (key.isKeyCode (KeyPress::endKey))
  49864. scrollToBottom();
  49865. else
  49866. return false;
  49867. return true;
  49868. }
  49869. END_JUCE_NAMESPACE
  49870. /*** End of inlined file: juce_ScrollBar.cpp ***/
  49871. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  49872. BEGIN_JUCE_NAMESPACE
  49873. StretchableLayoutManager::StretchableLayoutManager()
  49874. : totalSize (0)
  49875. {
  49876. }
  49877. StretchableLayoutManager::~StretchableLayoutManager()
  49878. {
  49879. }
  49880. void StretchableLayoutManager::clearAllItems()
  49881. {
  49882. items.clear();
  49883. totalSize = 0;
  49884. }
  49885. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  49886. const double minimumSize,
  49887. const double maximumSize,
  49888. const double preferredSize)
  49889. {
  49890. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  49891. if (layout == 0)
  49892. {
  49893. layout = new ItemLayoutProperties();
  49894. layout->itemIndex = itemIndex;
  49895. int i;
  49896. for (i = 0; i < items.size(); ++i)
  49897. if (items.getUnchecked (i)->itemIndex > itemIndex)
  49898. break;
  49899. items.insert (i, layout);
  49900. }
  49901. layout->minSize = minimumSize;
  49902. layout->maxSize = maximumSize;
  49903. layout->preferredSize = preferredSize;
  49904. layout->currentSize = 0;
  49905. }
  49906. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  49907. double& minimumSize,
  49908. double& maximumSize,
  49909. double& preferredSize) const
  49910. {
  49911. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49912. if (layout != 0)
  49913. {
  49914. minimumSize = layout->minSize;
  49915. maximumSize = layout->maxSize;
  49916. preferredSize = layout->preferredSize;
  49917. return true;
  49918. }
  49919. return false;
  49920. }
  49921. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  49922. {
  49923. totalSize = newTotalSize;
  49924. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  49925. }
  49926. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  49927. {
  49928. int pos = 0;
  49929. for (int i = 0; i < itemIndex; ++i)
  49930. {
  49931. const ItemLayoutProperties* const layout = getInfoFor (i);
  49932. if (layout != 0)
  49933. pos += layout->currentSize;
  49934. }
  49935. return pos;
  49936. }
  49937. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  49938. {
  49939. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49940. if (layout != 0)
  49941. return layout->currentSize;
  49942. return 0;
  49943. }
  49944. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  49945. {
  49946. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49947. if (layout != 0)
  49948. return -layout->currentSize / (double) totalSize;
  49949. return 0;
  49950. }
  49951. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  49952. int newPosition)
  49953. {
  49954. for (int i = items.size(); --i >= 0;)
  49955. {
  49956. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  49957. if (layout->itemIndex == itemIndex)
  49958. {
  49959. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  49960. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  49961. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  49962. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  49963. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  49964. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  49965. endPos += layout->currentSize;
  49966. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  49967. updatePrefSizesToMatchCurrentPositions();
  49968. break;
  49969. }
  49970. }
  49971. }
  49972. void StretchableLayoutManager::layOutComponents (Component** const components,
  49973. int numComponents,
  49974. int x, int y, int w, int h,
  49975. const bool vertically,
  49976. const bool resizeOtherDimension)
  49977. {
  49978. setTotalSize (vertically ? h : w);
  49979. int pos = vertically ? y : x;
  49980. for (int i = 0; i < numComponents; ++i)
  49981. {
  49982. const ItemLayoutProperties* const layout = getInfoFor (i);
  49983. if (layout != 0)
  49984. {
  49985. Component* const c = components[i];
  49986. if (c != 0)
  49987. {
  49988. if (i == numComponents - 1)
  49989. {
  49990. // if it's the last item, crop it to exactly fit the available space..
  49991. if (resizeOtherDimension)
  49992. {
  49993. if (vertically)
  49994. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  49995. else
  49996. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  49997. }
  49998. else
  49999. {
  50000. if (vertically)
  50001. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  50002. else
  50003. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  50004. }
  50005. }
  50006. else
  50007. {
  50008. if (resizeOtherDimension)
  50009. {
  50010. if (vertically)
  50011. c->setBounds (x, pos, w, layout->currentSize);
  50012. else
  50013. c->setBounds (pos, y, layout->currentSize, h);
  50014. }
  50015. else
  50016. {
  50017. if (vertically)
  50018. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  50019. else
  50020. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  50021. }
  50022. }
  50023. }
  50024. pos += layout->currentSize;
  50025. }
  50026. }
  50027. }
  50028. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  50029. {
  50030. for (int i = items.size(); --i >= 0;)
  50031. if (items.getUnchecked(i)->itemIndex == itemIndex)
  50032. return items.getUnchecked(i);
  50033. return 0;
  50034. }
  50035. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  50036. const int endIndex,
  50037. const int availableSpace,
  50038. int startPos)
  50039. {
  50040. // calculate the total sizes
  50041. int i;
  50042. double totalIdealSize = 0.0;
  50043. int totalMinimums = 0;
  50044. for (i = startIndex; i < endIndex; ++i)
  50045. {
  50046. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50047. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  50048. totalMinimums += layout->currentSize;
  50049. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  50050. }
  50051. if (totalIdealSize <= 0)
  50052. totalIdealSize = 1.0;
  50053. // now calc the best sizes..
  50054. int extraSpace = availableSpace - totalMinimums;
  50055. while (extraSpace > 0)
  50056. {
  50057. int numWantingMoreSpace = 0;
  50058. int numHavingTakenExtraSpace = 0;
  50059. // first figure out how many comps want a slice of the extra space..
  50060. for (i = startIndex; i < endIndex; ++i)
  50061. {
  50062. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50063. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50064. const int bestSize = jlimit (layout->currentSize,
  50065. jmax (layout->currentSize,
  50066. sizeToRealSize (layout->maxSize, totalSize)),
  50067. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50068. if (bestSize > layout->currentSize)
  50069. ++numWantingMoreSpace;
  50070. }
  50071. // ..share out the extra space..
  50072. for (i = startIndex; i < endIndex; ++i)
  50073. {
  50074. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50075. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50076. int bestSize = jlimit (layout->currentSize,
  50077. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  50078. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50079. const int extraWanted = bestSize - layout->currentSize;
  50080. if (extraWanted > 0)
  50081. {
  50082. const int extraAllowed = jmin (extraWanted,
  50083. extraSpace / jmax (1, numWantingMoreSpace));
  50084. if (extraAllowed > 0)
  50085. {
  50086. ++numHavingTakenExtraSpace;
  50087. --numWantingMoreSpace;
  50088. layout->currentSize += extraAllowed;
  50089. extraSpace -= extraAllowed;
  50090. }
  50091. }
  50092. }
  50093. if (numHavingTakenExtraSpace <= 0)
  50094. break;
  50095. }
  50096. // ..and calculate the end position
  50097. for (i = startIndex; i < endIndex; ++i)
  50098. {
  50099. ItemLayoutProperties* const layout = items.getUnchecked(i);
  50100. startPos += layout->currentSize;
  50101. }
  50102. return startPos;
  50103. }
  50104. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  50105. const int endIndex) const
  50106. {
  50107. int totalMinimums = 0;
  50108. for (int i = startIndex; i < endIndex; ++i)
  50109. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  50110. return totalMinimums;
  50111. }
  50112. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  50113. {
  50114. int totalMaximums = 0;
  50115. for (int i = startIndex; i < endIndex; ++i)
  50116. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  50117. return totalMaximums;
  50118. }
  50119. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  50120. {
  50121. for (int i = 0; i < items.size(); ++i)
  50122. {
  50123. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50124. layout->preferredSize
  50125. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  50126. : getItemCurrentAbsoluteSize (i);
  50127. }
  50128. }
  50129. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  50130. {
  50131. if (size < 0)
  50132. size *= -totalSpace;
  50133. return roundToInt (size);
  50134. }
  50135. END_JUCE_NAMESPACE
  50136. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  50137. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50138. BEGIN_JUCE_NAMESPACE
  50139. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  50140. const int itemIndex_,
  50141. const bool isVertical_)
  50142. : layout (layout_),
  50143. itemIndex (itemIndex_),
  50144. isVertical (isVertical_)
  50145. {
  50146. setRepaintsOnMouseActivity (true);
  50147. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  50148. : MouseCursor::UpDownResizeCursor));
  50149. }
  50150. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  50151. {
  50152. }
  50153. void StretchableLayoutResizerBar::paint (Graphics& g)
  50154. {
  50155. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  50156. getWidth(), getHeight(),
  50157. isVertical,
  50158. isMouseOver(),
  50159. isMouseButtonDown());
  50160. }
  50161. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  50162. {
  50163. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  50164. }
  50165. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  50166. {
  50167. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  50168. : e.getDistanceFromDragStartY());
  50169. layout->setItemPosition (itemIndex, desiredPos);
  50170. hasBeenMoved();
  50171. }
  50172. void StretchableLayoutResizerBar::hasBeenMoved()
  50173. {
  50174. if (getParentComponent() != 0)
  50175. getParentComponent()->resized();
  50176. }
  50177. END_JUCE_NAMESPACE
  50178. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50179. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  50180. BEGIN_JUCE_NAMESPACE
  50181. StretchableObjectResizer::StretchableObjectResizer()
  50182. {
  50183. }
  50184. StretchableObjectResizer::~StretchableObjectResizer()
  50185. {
  50186. }
  50187. void StretchableObjectResizer::addItem (const double size,
  50188. const double minSize, const double maxSize,
  50189. const int order)
  50190. {
  50191. // the order must be >= 0 but less than the maximum integer value.
  50192. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  50193. Item* const item = new Item();
  50194. item->size = size;
  50195. item->minSize = minSize;
  50196. item->maxSize = maxSize;
  50197. item->order = order;
  50198. items.add (item);
  50199. }
  50200. double StretchableObjectResizer::getItemSize (const int index) const throw()
  50201. {
  50202. const Item* const it = items [index];
  50203. return it != 0 ? it->size : 0;
  50204. }
  50205. void StretchableObjectResizer::resizeToFit (const double targetSize)
  50206. {
  50207. int order = 0;
  50208. for (;;)
  50209. {
  50210. double currentSize = 0;
  50211. double minSize = 0;
  50212. double maxSize = 0;
  50213. int nextHighestOrder = std::numeric_limits<int>::max();
  50214. for (int i = 0; i < items.size(); ++i)
  50215. {
  50216. const Item* const it = items.getUnchecked(i);
  50217. currentSize += it->size;
  50218. if (it->order <= order)
  50219. {
  50220. minSize += it->minSize;
  50221. maxSize += it->maxSize;
  50222. }
  50223. else
  50224. {
  50225. minSize += it->size;
  50226. maxSize += it->size;
  50227. nextHighestOrder = jmin (nextHighestOrder, it->order);
  50228. }
  50229. }
  50230. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  50231. if (thisIterationTarget >= currentSize)
  50232. {
  50233. const double availableExtraSpace = maxSize - currentSize;
  50234. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  50235. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  50236. for (int i = 0; i < items.size(); ++i)
  50237. {
  50238. Item* const it = items.getUnchecked(i);
  50239. if (it->order <= order)
  50240. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  50241. }
  50242. }
  50243. else
  50244. {
  50245. const double amountOfSlack = currentSize - minSize;
  50246. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50247. const double scale = targetAmountOfSlack / amountOfSlack;
  50248. for (int i = 0; i < items.size(); ++i)
  50249. {
  50250. Item* const it = items.getUnchecked(i);
  50251. if (it->order <= order)
  50252. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50253. }
  50254. }
  50255. if (nextHighestOrder < std::numeric_limits<int>::max())
  50256. order = nextHighestOrder;
  50257. else
  50258. break;
  50259. }
  50260. }
  50261. END_JUCE_NAMESPACE
  50262. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  50263. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  50264. BEGIN_JUCE_NAMESPACE
  50265. TabBarButton::TabBarButton (const String& name,
  50266. TabbedButtonBar* const owner_,
  50267. const int index)
  50268. : Button (name),
  50269. owner (owner_),
  50270. tabIndex (index),
  50271. overlapPixels (0)
  50272. {
  50273. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50274. setComponentEffect (&shadow);
  50275. setWantsKeyboardFocus (false);
  50276. }
  50277. TabBarButton::~TabBarButton()
  50278. {
  50279. }
  50280. void TabBarButton::paintButton (Graphics& g,
  50281. bool isMouseOverButton,
  50282. bool isButtonDown)
  50283. {
  50284. int x, y, w, h;
  50285. getActiveArea (x, y, w, h);
  50286. g.setOrigin (x, y);
  50287. getLookAndFeel()
  50288. .drawTabButton (g, w, h,
  50289. owner->getTabBackgroundColour (tabIndex),
  50290. tabIndex, getButtonText(), *this,
  50291. owner->getOrientation(),
  50292. isMouseOverButton, isButtonDown,
  50293. getToggleState());
  50294. }
  50295. void TabBarButton::clicked (const ModifierKeys& mods)
  50296. {
  50297. if (mods.isPopupMenu())
  50298. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50299. else
  50300. owner->setCurrentTabIndex (tabIndex);
  50301. }
  50302. bool TabBarButton::hitTest (int mx, int my)
  50303. {
  50304. int x, y, w, h;
  50305. getActiveArea (x, y, w, h);
  50306. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50307. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50308. {
  50309. if (((unsigned int) mx) < (unsigned int) getWidth()
  50310. && my >= y + overlapPixels
  50311. && my < y + h - overlapPixels)
  50312. return true;
  50313. }
  50314. else
  50315. {
  50316. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50317. && ((unsigned int) my) < (unsigned int) getHeight())
  50318. return true;
  50319. }
  50320. Path p;
  50321. getLookAndFeel()
  50322. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50323. owner->getOrientation(),
  50324. false, false, getToggleState());
  50325. return p.contains ((float) (mx - x),
  50326. (float) (my - y));
  50327. }
  50328. int TabBarButton::getBestTabLength (const int depth)
  50329. {
  50330. return jlimit (depth * 2,
  50331. depth * 7,
  50332. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50333. }
  50334. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50335. {
  50336. x = 0;
  50337. y = 0;
  50338. int r = getWidth();
  50339. int b = getHeight();
  50340. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50341. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50342. r -= spaceAroundImage;
  50343. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50344. x += spaceAroundImage;
  50345. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50346. y += spaceAroundImage;
  50347. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50348. b -= spaceAroundImage;
  50349. w = r - x;
  50350. h = b - y;
  50351. }
  50352. class TabAreaBehindFrontButtonComponent : public Component
  50353. {
  50354. public:
  50355. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50356. : owner (owner_)
  50357. {
  50358. setInterceptsMouseClicks (false, false);
  50359. }
  50360. ~TabAreaBehindFrontButtonComponent()
  50361. {
  50362. }
  50363. void paint (Graphics& g)
  50364. {
  50365. getLookAndFeel()
  50366. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50367. *owner, owner->getOrientation());
  50368. }
  50369. void enablementChanged()
  50370. {
  50371. repaint();
  50372. }
  50373. private:
  50374. TabbedButtonBar* const owner;
  50375. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50376. TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50377. };
  50378. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50379. : orientation (orientation_),
  50380. currentTabIndex (-1),
  50381. extraTabsButton (0)
  50382. {
  50383. setInterceptsMouseClicks (false, true);
  50384. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50385. setFocusContainer (true);
  50386. }
  50387. TabbedButtonBar::~TabbedButtonBar()
  50388. {
  50389. deleteAllChildren();
  50390. }
  50391. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50392. {
  50393. orientation = newOrientation;
  50394. for (int i = getNumChildComponents(); --i >= 0;)
  50395. getChildComponent (i)->resized();
  50396. resized();
  50397. }
  50398. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50399. {
  50400. return new TabBarButton (name, this, index);
  50401. }
  50402. void TabbedButtonBar::clearTabs()
  50403. {
  50404. tabs.clear();
  50405. tabColours.clear();
  50406. currentTabIndex = -1;
  50407. deleteAndZero (extraTabsButton);
  50408. removeChildComponent (behindFrontTab);
  50409. deleteAllChildren();
  50410. addChildComponent (behindFrontTab);
  50411. setCurrentTabIndex (-1);
  50412. }
  50413. void TabbedButtonBar::addTab (const String& tabName,
  50414. const Colour& tabBackgroundColour,
  50415. int insertIndex)
  50416. {
  50417. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50418. if (tabName.isNotEmpty())
  50419. {
  50420. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50421. insertIndex = tabs.size();
  50422. for (int i = tabs.size(); --i >= insertIndex;)
  50423. {
  50424. TabBarButton* const tb = getTabButton (i);
  50425. if (tb != 0)
  50426. tb->tabIndex++;
  50427. }
  50428. tabs.insert (insertIndex, tabName);
  50429. tabColours.insert (insertIndex, tabBackgroundColour);
  50430. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50431. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50432. addAndMakeVisible (tb, insertIndex);
  50433. resized();
  50434. if (currentTabIndex < 0)
  50435. setCurrentTabIndex (0);
  50436. }
  50437. }
  50438. void TabbedButtonBar::setTabName (const int tabIndex,
  50439. const String& newName)
  50440. {
  50441. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50442. && tabs[tabIndex] != newName)
  50443. {
  50444. tabs.set (tabIndex, newName);
  50445. TabBarButton* const tb = getTabButton (tabIndex);
  50446. if (tb != 0)
  50447. tb->setButtonText (newName);
  50448. resized();
  50449. }
  50450. }
  50451. void TabbedButtonBar::removeTab (const int tabIndex)
  50452. {
  50453. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50454. {
  50455. const int oldTabIndex = currentTabIndex;
  50456. if (currentTabIndex == tabIndex)
  50457. currentTabIndex = -1;
  50458. tabs.remove (tabIndex);
  50459. tabColours.remove (tabIndex);
  50460. delete getTabButton (tabIndex);
  50461. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50462. {
  50463. TabBarButton* const tb = getTabButton (i);
  50464. if (tb != 0)
  50465. tb->tabIndex--;
  50466. }
  50467. resized();
  50468. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50469. }
  50470. }
  50471. void TabbedButtonBar::moveTab (const int currentIndex,
  50472. const int newIndex)
  50473. {
  50474. tabs.move (currentIndex, newIndex);
  50475. tabColours.move (currentIndex, newIndex);
  50476. resized();
  50477. }
  50478. int TabbedButtonBar::getNumTabs() const
  50479. {
  50480. return tabs.size();
  50481. }
  50482. const StringArray TabbedButtonBar::getTabNames() const
  50483. {
  50484. return tabs;
  50485. }
  50486. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50487. {
  50488. if (currentTabIndex != newIndex)
  50489. {
  50490. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50491. newIndex = -1;
  50492. currentTabIndex = newIndex;
  50493. for (int i = 0; i < getNumChildComponents(); ++i)
  50494. {
  50495. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50496. if (tb != 0)
  50497. tb->setToggleState (tb->tabIndex == newIndex, false);
  50498. }
  50499. resized();
  50500. if (sendChangeMessage_)
  50501. sendChangeMessage (this);
  50502. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50503. }
  50504. }
  50505. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50506. {
  50507. for (int i = getNumChildComponents(); --i >= 0;)
  50508. {
  50509. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50510. if (tb != 0 && tb->tabIndex == index)
  50511. return tb;
  50512. }
  50513. return 0;
  50514. }
  50515. void TabbedButtonBar::lookAndFeelChanged()
  50516. {
  50517. deleteAndZero (extraTabsButton);
  50518. resized();
  50519. }
  50520. void TabbedButtonBar::resized()
  50521. {
  50522. const double minimumScale = 0.7;
  50523. int depth = getWidth();
  50524. int length = getHeight();
  50525. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50526. swapVariables (depth, length);
  50527. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  50528. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  50529. int i, totalLength = overlap;
  50530. int numVisibleButtons = tabs.size();
  50531. for (i = 0; i < getNumChildComponents(); ++i)
  50532. {
  50533. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50534. if (tb != 0)
  50535. {
  50536. totalLength += tb->getBestTabLength (depth) - overlap;
  50537. tb->overlapPixels = overlap / 2;
  50538. }
  50539. }
  50540. double scale = 1.0;
  50541. if (totalLength > length)
  50542. scale = jmax (minimumScale, length / (double) totalLength);
  50543. const bool isTooBig = totalLength * scale > length;
  50544. int tabsButtonPos = 0;
  50545. if (isTooBig)
  50546. {
  50547. if (extraTabsButton == 0)
  50548. {
  50549. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  50550. extraTabsButton->addButtonListener (this);
  50551. extraTabsButton->setAlwaysOnTop (true);
  50552. extraTabsButton->setTriggeredOnMouseDown (true);
  50553. }
  50554. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  50555. extraTabsButton->setSize (buttonSize, buttonSize);
  50556. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50557. {
  50558. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  50559. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  50560. }
  50561. else
  50562. {
  50563. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  50564. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  50565. }
  50566. totalLength = 0;
  50567. for (i = 0; i < tabs.size(); ++i)
  50568. {
  50569. TabBarButton* const tb = getTabButton (i);
  50570. if (tb != 0)
  50571. {
  50572. const int newLength = totalLength + tb->getBestTabLength (depth);
  50573. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  50574. {
  50575. totalLength += overlap;
  50576. break;
  50577. }
  50578. numVisibleButtons = i + 1;
  50579. totalLength = newLength - overlap;
  50580. }
  50581. }
  50582. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  50583. }
  50584. else
  50585. {
  50586. deleteAndZero (extraTabsButton);
  50587. }
  50588. int pos = 0;
  50589. TabBarButton* frontTab = 0;
  50590. for (i = 0; i < tabs.size(); ++i)
  50591. {
  50592. TabBarButton* const tb = getTabButton (i);
  50593. if (tb != 0)
  50594. {
  50595. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  50596. if (i < numVisibleButtons)
  50597. {
  50598. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50599. tb->setBounds (pos, 0, bestLength, getHeight());
  50600. else
  50601. tb->setBounds (0, pos, getWidth(), bestLength);
  50602. tb->toBack();
  50603. if (tb->tabIndex == currentTabIndex)
  50604. frontTab = tb;
  50605. tb->setVisible (true);
  50606. }
  50607. else
  50608. {
  50609. tb->setVisible (false);
  50610. }
  50611. pos += bestLength - overlap;
  50612. }
  50613. }
  50614. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  50615. if (frontTab != 0)
  50616. {
  50617. frontTab->toFront (false);
  50618. behindFrontTab->toBehind (frontTab);
  50619. }
  50620. }
  50621. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  50622. {
  50623. return tabColours [tabIndex];
  50624. }
  50625. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50626. {
  50627. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  50628. && tabColours [tabIndex] != newColour)
  50629. {
  50630. tabColours.set (tabIndex, newColour);
  50631. repaint();
  50632. }
  50633. }
  50634. void TabbedButtonBar::buttonClicked (Button* button)
  50635. {
  50636. if (extraTabsButton == button)
  50637. {
  50638. PopupMenu m;
  50639. for (int i = 0; i < tabs.size(); ++i)
  50640. {
  50641. TabBarButton* const tb = getTabButton (i);
  50642. if (tb != 0 && ! tb->isVisible())
  50643. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  50644. }
  50645. const int res = m.showAt (extraTabsButton);
  50646. if (res != 0)
  50647. setCurrentTabIndex (res - 1);
  50648. }
  50649. }
  50650. void TabbedButtonBar::currentTabChanged (const int, const String&)
  50651. {
  50652. }
  50653. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  50654. {
  50655. }
  50656. END_JUCE_NAMESPACE
  50657. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  50658. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  50659. BEGIN_JUCE_NAMESPACE
  50660. class TabCompButtonBar : public TabbedButtonBar
  50661. {
  50662. public:
  50663. TabCompButtonBar (TabbedComponent* const owner_,
  50664. const TabbedButtonBar::Orientation orientation)
  50665. : TabbedButtonBar (orientation),
  50666. owner (owner_)
  50667. {
  50668. }
  50669. ~TabCompButtonBar()
  50670. {
  50671. }
  50672. void currentTabChanged (const int newCurrentTabIndex,
  50673. const String& newTabName)
  50674. {
  50675. owner->changeCallback (newCurrentTabIndex, newTabName);
  50676. }
  50677. void popupMenuClickOnTab (const int tabIndex,
  50678. const String& tabName)
  50679. {
  50680. owner->popupMenuClickOnTab (tabIndex, tabName);
  50681. }
  50682. const Colour getTabBackgroundColour (const int tabIndex)
  50683. {
  50684. return owner->tabs->getTabBackgroundColour (tabIndex);
  50685. }
  50686. TabBarButton* createTabButton (const String& tabName, const int tabIndex)
  50687. {
  50688. return owner->createTabButton (tabName, tabIndex);
  50689. }
  50690. juce_UseDebuggingNewOperator
  50691. private:
  50692. TabbedComponent* const owner;
  50693. TabCompButtonBar (const TabCompButtonBar&);
  50694. TabCompButtonBar& operator= (const TabCompButtonBar&);
  50695. };
  50696. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  50697. : panelComponent (0),
  50698. tabDepth (30),
  50699. outlineThickness (1),
  50700. edgeIndent (0)
  50701. {
  50702. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  50703. }
  50704. TabbedComponent::~TabbedComponent()
  50705. {
  50706. clearTabs();
  50707. delete tabs;
  50708. }
  50709. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  50710. {
  50711. tabs->setOrientation (orientation);
  50712. resized();
  50713. }
  50714. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  50715. {
  50716. return tabs->getOrientation();
  50717. }
  50718. void TabbedComponent::setTabBarDepth (const int newDepth)
  50719. {
  50720. if (tabDepth != newDepth)
  50721. {
  50722. tabDepth = newDepth;
  50723. resized();
  50724. }
  50725. }
  50726. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  50727. {
  50728. return new TabBarButton (tabName, tabs, tabIndex);
  50729. }
  50730. void TabbedComponent::clearTabs()
  50731. {
  50732. if (panelComponent != 0)
  50733. {
  50734. panelComponent->setVisible (false);
  50735. removeChildComponent (panelComponent);
  50736. panelComponent = 0;
  50737. }
  50738. tabs->clearTabs();
  50739. for (int i = contentComponents.size(); --i >= 0;)
  50740. {
  50741. Component* const c = contentComponents.getUnchecked(i);
  50742. // be careful not to delete these components until they've been removed from the tab component
  50743. jassert (c == 0 || c->isValidComponent());
  50744. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50745. delete c;
  50746. }
  50747. contentComponents.clear();
  50748. }
  50749. void TabbedComponent::addTab (const String& tabName,
  50750. const Colour& tabBackgroundColour,
  50751. Component* const contentComponent,
  50752. const bool deleteComponentWhenNotNeeded,
  50753. const int insertIndex)
  50754. {
  50755. contentComponents.insert (insertIndex, contentComponent);
  50756. if (contentComponent != 0)
  50757. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  50758. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  50759. }
  50760. void TabbedComponent::setTabName (const int tabIndex,
  50761. const String& newName)
  50762. {
  50763. tabs->setTabName (tabIndex, newName);
  50764. }
  50765. void TabbedComponent::removeTab (const int tabIndex)
  50766. {
  50767. Component* const c = contentComponents [tabIndex];
  50768. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50769. {
  50770. if (c == panelComponent)
  50771. panelComponent = 0;
  50772. delete c;
  50773. }
  50774. contentComponents.remove (tabIndex);
  50775. tabs->removeTab (tabIndex);
  50776. }
  50777. int TabbedComponent::getNumTabs() const
  50778. {
  50779. return tabs->getNumTabs();
  50780. }
  50781. const StringArray TabbedComponent::getTabNames() const
  50782. {
  50783. return tabs->getTabNames();
  50784. }
  50785. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  50786. {
  50787. return contentComponents [tabIndex];
  50788. }
  50789. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  50790. {
  50791. return tabs->getTabBackgroundColour (tabIndex);
  50792. }
  50793. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50794. {
  50795. tabs->setTabBackgroundColour (tabIndex, newColour);
  50796. if (getCurrentTabIndex() == tabIndex)
  50797. repaint();
  50798. }
  50799. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  50800. {
  50801. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  50802. }
  50803. int TabbedComponent::getCurrentTabIndex() const
  50804. {
  50805. return tabs->getCurrentTabIndex();
  50806. }
  50807. const String& TabbedComponent::getCurrentTabName() const
  50808. {
  50809. return tabs->getCurrentTabName();
  50810. }
  50811. void TabbedComponent::setOutline (int thickness)
  50812. {
  50813. outlineThickness = thickness;
  50814. repaint();
  50815. }
  50816. void TabbedComponent::setIndent (const int indentThickness)
  50817. {
  50818. edgeIndent = indentThickness;
  50819. }
  50820. void TabbedComponent::paint (Graphics& g)
  50821. {
  50822. g.fillAll (findColour (backgroundColourId));
  50823. const TabbedButtonBar::Orientation o = getOrientation();
  50824. int x = 0;
  50825. int y = 0;
  50826. int r = getWidth();
  50827. int b = getHeight();
  50828. if (o == TabbedButtonBar::TabsAtTop)
  50829. y += tabDepth;
  50830. else if (o == TabbedButtonBar::TabsAtBottom)
  50831. b -= tabDepth;
  50832. else if (o == TabbedButtonBar::TabsAtLeft)
  50833. x += tabDepth;
  50834. else if (o == TabbedButtonBar::TabsAtRight)
  50835. r -= tabDepth;
  50836. g.reduceClipRegion (x, y, r - x, b - y);
  50837. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  50838. if (outlineThickness > 0)
  50839. {
  50840. if (o == TabbedButtonBar::TabsAtTop)
  50841. --y;
  50842. else if (o == TabbedButtonBar::TabsAtBottom)
  50843. ++b;
  50844. else if (o == TabbedButtonBar::TabsAtLeft)
  50845. --x;
  50846. else if (o == TabbedButtonBar::TabsAtRight)
  50847. ++r;
  50848. g.setColour (findColour (outlineColourId));
  50849. g.drawRect (x, y, r - x, b - y, outlineThickness);
  50850. }
  50851. }
  50852. void TabbedComponent::resized()
  50853. {
  50854. const TabbedButtonBar::Orientation o = getOrientation();
  50855. const int indent = edgeIndent + outlineThickness;
  50856. BorderSize indents (indent);
  50857. if (o == TabbedButtonBar::TabsAtTop)
  50858. {
  50859. tabs->setBounds (0, 0, getWidth(), tabDepth);
  50860. indents.setTop (tabDepth + edgeIndent);
  50861. }
  50862. else if (o == TabbedButtonBar::TabsAtBottom)
  50863. {
  50864. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  50865. indents.setBottom (tabDepth + edgeIndent);
  50866. }
  50867. else if (o == TabbedButtonBar::TabsAtLeft)
  50868. {
  50869. tabs->setBounds (0, 0, tabDepth, getHeight());
  50870. indents.setLeft (tabDepth + edgeIndent);
  50871. }
  50872. else if (o == TabbedButtonBar::TabsAtRight)
  50873. {
  50874. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  50875. indents.setRight (tabDepth + edgeIndent);
  50876. }
  50877. const Rectangle<int> bounds (indents.subtractedFrom (Rectangle<int> (0, 0, getWidth(), getHeight())));
  50878. for (int i = contentComponents.size(); --i >= 0;)
  50879. if (contentComponents.getUnchecked (i) != 0)
  50880. contentComponents.getUnchecked (i)->setBounds (bounds);
  50881. }
  50882. void TabbedComponent::lookAndFeelChanged()
  50883. {
  50884. for (int i = contentComponents.size(); --i >= 0;)
  50885. if (contentComponents.getUnchecked (i) != 0)
  50886. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  50887. }
  50888. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  50889. const String& newTabName)
  50890. {
  50891. if (panelComponent != 0)
  50892. {
  50893. panelComponent->setVisible (false);
  50894. removeChildComponent (panelComponent);
  50895. panelComponent = 0;
  50896. }
  50897. if (getCurrentTabIndex() >= 0)
  50898. {
  50899. panelComponent = contentComponents [getCurrentTabIndex()];
  50900. if (panelComponent != 0)
  50901. {
  50902. // do these ops as two stages instead of addAndMakeVisible() so that the
  50903. // component has always got a parent when it gets the visibilityChanged() callback
  50904. addChildComponent (panelComponent);
  50905. panelComponent->setVisible (true);
  50906. panelComponent->toFront (true);
  50907. }
  50908. repaint();
  50909. }
  50910. resized();
  50911. currentTabChanged (newCurrentTabIndex, newTabName);
  50912. }
  50913. void TabbedComponent::currentTabChanged (const int, const String&)
  50914. {
  50915. }
  50916. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  50917. {
  50918. }
  50919. END_JUCE_NAMESPACE
  50920. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  50921. /*** Start of inlined file: juce_Viewport.cpp ***/
  50922. BEGIN_JUCE_NAMESPACE
  50923. Viewport::Viewport (const String& componentName)
  50924. : Component (componentName),
  50925. contentComp (0),
  50926. lastVX (0),
  50927. lastVY (0),
  50928. lastVW (0),
  50929. lastVH (0),
  50930. scrollBarThickness (0),
  50931. singleStepX (16),
  50932. singleStepY (16),
  50933. showHScrollbar (true),
  50934. showVScrollbar (true)
  50935. {
  50936. // content holder is used to clip the contents so they don't overlap the scrollbars
  50937. addAndMakeVisible (contentHolder = new Component());
  50938. contentHolder->setInterceptsMouseClicks (false, true);
  50939. verticalScrollBar = new ScrollBar (true);
  50940. horizontalScrollBar = new ScrollBar (false);
  50941. addChildComponent (verticalScrollBar);
  50942. addChildComponent (horizontalScrollBar);
  50943. verticalScrollBar->addListener (this);
  50944. horizontalScrollBar->addListener (this);
  50945. setInterceptsMouseClicks (false, true);
  50946. setWantsKeyboardFocus (true);
  50947. }
  50948. Viewport::~Viewport()
  50949. {
  50950. contentHolder->deleteAllChildren();
  50951. deleteAllChildren();
  50952. }
  50953. void Viewport::visibleAreaChanged (int, int, int, int)
  50954. {
  50955. }
  50956. void Viewport::setViewedComponent (Component* const newViewedComponent)
  50957. {
  50958. if (contentComp != newViewedComponent)
  50959. {
  50960. {
  50961. ScopedPointer<Component> oldCompDeleter (contentComp);
  50962. contentComp = 0;
  50963. }
  50964. contentComp = newViewedComponent;
  50965. if (contentComp != 0)
  50966. {
  50967. contentComp->setTopLeftPosition (0, 0);
  50968. contentHolder->addAndMakeVisible (contentComp);
  50969. contentComp->addComponentListener (this);
  50970. }
  50971. updateVisibleRegion();
  50972. }
  50973. }
  50974. int Viewport::getMaximumVisibleWidth() const throw()
  50975. {
  50976. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50977. }
  50978. int Viewport::getMaximumVisibleHeight() const throw()
  50979. {
  50980. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50981. }
  50982. void Viewport::setViewPosition (const int xPixelsOffset,
  50983. const int yPixelsOffset)
  50984. {
  50985. if (contentComp != 0)
  50986. contentComp->setTopLeftPosition (-xPixelsOffset,
  50987. -yPixelsOffset);
  50988. }
  50989. void Viewport::setViewPositionProportionately (const double x,
  50990. const double y)
  50991. {
  50992. if (contentComp != 0)
  50993. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  50994. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  50995. }
  50996. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  50997. {
  50998. if (contentComp != 0)
  50999. {
  51000. int dx = 0, dy = 0;
  51001. if (mouseX < activeBorderThickness)
  51002. dx = activeBorderThickness - mouseX;
  51003. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  51004. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  51005. if (dx < 0)
  51006. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  51007. else
  51008. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  51009. if (mouseY < activeBorderThickness)
  51010. dy = activeBorderThickness - mouseY;
  51011. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  51012. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  51013. if (dy < 0)
  51014. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  51015. else
  51016. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  51017. if (dx != 0 || dy != 0)
  51018. {
  51019. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  51020. contentComp->getY() + dy);
  51021. return true;
  51022. }
  51023. }
  51024. return false;
  51025. }
  51026. void Viewport::componentMovedOrResized (Component&, bool, bool)
  51027. {
  51028. updateVisibleRegion();
  51029. }
  51030. void Viewport::resized()
  51031. {
  51032. updateVisibleRegion();
  51033. }
  51034. void Viewport::updateVisibleRegion()
  51035. {
  51036. if (contentComp != 0)
  51037. {
  51038. const int newVX = -contentComp->getX();
  51039. const int newVY = -contentComp->getY();
  51040. if (newVX == 0 && newVY == 0
  51041. && contentComp->getWidth() <= getWidth()
  51042. && contentComp->getHeight() <= getHeight())
  51043. {
  51044. horizontalScrollBar->setVisible (false);
  51045. verticalScrollBar->setVisible (false);
  51046. }
  51047. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  51048. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51049. horizontalScrollBar->setSingleStepSize (singleStepX);
  51050. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  51051. horizontalScrollBar->setVisible (false);
  51052. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  51053. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51054. verticalScrollBar->setSingleStepSize (singleStepY);
  51055. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  51056. verticalScrollBar->setVisible (false);
  51057. if (verticalScrollBar->isVisible())
  51058. {
  51059. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51060. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51061. verticalScrollBar
  51062. ->setBounds (getMaximumVisibleWidth(), 0,
  51063. getScrollBarThickness(), getMaximumVisibleHeight());
  51064. }
  51065. if (horizontalScrollBar->isVisible())
  51066. {
  51067. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51068. horizontalScrollBar
  51069. ->setBounds (0, getMaximumVisibleHeight(),
  51070. getMaximumVisibleWidth(), getScrollBarThickness());
  51071. }
  51072. contentHolder->setSize (getMaximumVisibleWidth(),
  51073. getMaximumVisibleHeight());
  51074. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  51075. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  51076. if (newVX != lastVX
  51077. || newVY != lastVY
  51078. || newVW != lastVW
  51079. || newVH != lastVH)
  51080. {
  51081. lastVX = newVX;
  51082. lastVY = newVY;
  51083. lastVW = newVW;
  51084. lastVH = newVH;
  51085. visibleAreaChanged (newVX, newVY, newVW, newVH);
  51086. }
  51087. horizontalScrollBar->handleUpdateNowIfNeeded();
  51088. verticalScrollBar->handleUpdateNowIfNeeded();
  51089. }
  51090. else
  51091. {
  51092. horizontalScrollBar->setVisible (false);
  51093. verticalScrollBar->setVisible (false);
  51094. }
  51095. }
  51096. void Viewport::setSingleStepSizes (const int stepX,
  51097. const int stepY)
  51098. {
  51099. singleStepX = stepX;
  51100. singleStepY = stepY;
  51101. updateVisibleRegion();
  51102. }
  51103. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  51104. const bool showHorizontalScrollbarIfNeeded)
  51105. {
  51106. showVScrollbar = showVerticalScrollbarIfNeeded;
  51107. showHScrollbar = showHorizontalScrollbarIfNeeded;
  51108. updateVisibleRegion();
  51109. }
  51110. void Viewport::setScrollBarThickness (const int thickness)
  51111. {
  51112. scrollBarThickness = thickness;
  51113. updateVisibleRegion();
  51114. }
  51115. int Viewport::getScrollBarThickness() const throw()
  51116. {
  51117. return (scrollBarThickness > 0) ? scrollBarThickness
  51118. : getLookAndFeel().getDefaultScrollbarWidth();
  51119. }
  51120. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  51121. {
  51122. verticalScrollBar->setButtonVisibility (buttonsVisible);
  51123. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  51124. }
  51125. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  51126. {
  51127. if (scrollBarThatHasMoved == horizontalScrollBar)
  51128. {
  51129. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  51130. }
  51131. else if (scrollBarThatHasMoved == verticalScrollBar)
  51132. {
  51133. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  51134. }
  51135. }
  51136. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51137. {
  51138. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  51139. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  51140. }
  51141. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51142. {
  51143. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  51144. {
  51145. const bool hasVertBar = verticalScrollBar->isVisible();
  51146. const bool hasHorzBar = horizontalScrollBar->isVisible();
  51147. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  51148. {
  51149. if (wheelIncrementX == 0 && ! hasVertBar)
  51150. wheelIncrementX = wheelIncrementY;
  51151. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  51152. wheelIncrementX, wheelIncrementY);
  51153. return true;
  51154. }
  51155. else if (hasVertBar && wheelIncrementY != 0)
  51156. {
  51157. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  51158. wheelIncrementX, wheelIncrementY);
  51159. return true;
  51160. }
  51161. }
  51162. return false;
  51163. }
  51164. bool Viewport::keyPressed (const KeyPress& key)
  51165. {
  51166. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  51167. || key.isKeyCode (KeyPress::downKey)
  51168. || key.isKeyCode (KeyPress::pageUpKey)
  51169. || key.isKeyCode (KeyPress::pageDownKey)
  51170. || key.isKeyCode (KeyPress::homeKey)
  51171. || key.isKeyCode (KeyPress::endKey);
  51172. if (verticalScrollBar->isVisible() && isUpDownKey)
  51173. return verticalScrollBar->keyPressed (key);
  51174. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  51175. || key.isKeyCode (KeyPress::rightKey);
  51176. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  51177. return horizontalScrollBar->keyPressed (key);
  51178. return false;
  51179. }
  51180. END_JUCE_NAMESPACE
  51181. /*** End of inlined file: juce_Viewport.cpp ***/
  51182. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  51183. BEGIN_JUCE_NAMESPACE
  51184. static const Colour createBaseColour (const Colour& buttonColour,
  51185. const bool hasKeyboardFocus,
  51186. const bool isMouseOverButton,
  51187. const bool isButtonDown) throw()
  51188. {
  51189. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  51190. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  51191. if (isButtonDown)
  51192. return baseColour.contrasting (0.2f);
  51193. else if (isMouseOverButton)
  51194. return baseColour.contrasting (0.1f);
  51195. return baseColour;
  51196. }
  51197. static String defaultSansName, defaultSerifName, defaultFixedName;
  51198. void clearUpDefaultFontNames() throw()
  51199. {
  51200. defaultSansName = String::empty;
  51201. defaultSerifName = String::empty;
  51202. defaultFixedName = String::empty;
  51203. }
  51204. LookAndFeel::LookAndFeel()
  51205. {
  51206. /* if this fails it means you're trying to create a LookAndFeel object before
  51207. the static Colours have been initialised. That ain't gonna work. It probably
  51208. means that you're using a static LookAndFeel object and that your compiler has
  51209. decided to intialise it before the Colours class.
  51210. */
  51211. jassert (Colours::white == Colour (0xffffffff));
  51212. // set up the standard set of colours..
  51213. const int textButtonColour = 0xffbbbbff;
  51214. const int textHighlightColour = 0x401111ee;
  51215. const int standardOutlineColour = 0xb2808080;
  51216. static const int standardColours[] =
  51217. {
  51218. TextButton::buttonColourId, textButtonColour,
  51219. TextButton::buttonOnColourId, 0xff4444ff,
  51220. TextButton::textColourOnId, 0xff000000,
  51221. TextButton::textColourOffId, 0xff000000,
  51222. ComboBox::buttonColourId, 0xffbbbbff,
  51223. ComboBox::outlineColourId, standardOutlineColour,
  51224. ToggleButton::textColourId, 0xff000000,
  51225. TextEditor::backgroundColourId, 0xffffffff,
  51226. TextEditor::textColourId, 0xff000000,
  51227. TextEditor::highlightColourId, textHighlightColour,
  51228. TextEditor::highlightedTextColourId, 0xff000000,
  51229. TextEditor::caretColourId, 0xff000000,
  51230. TextEditor::outlineColourId, 0x00000000,
  51231. TextEditor::focusedOutlineColourId, textButtonColour,
  51232. TextEditor::shadowColourId, 0x38000000,
  51233. Label::backgroundColourId, 0x00000000,
  51234. Label::textColourId, 0xff000000,
  51235. Label::outlineColourId, 0x00000000,
  51236. ScrollBar::backgroundColourId, 0x00000000,
  51237. ScrollBar::thumbColourId, 0xffffffff,
  51238. ScrollBar::trackColourId, 0xffffffff,
  51239. TreeView::linesColourId, 0x4c000000,
  51240. TreeView::backgroundColourId, 0x00000000,
  51241. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  51242. PopupMenu::backgroundColourId, 0xffffffff,
  51243. PopupMenu::textColourId, 0xff000000,
  51244. PopupMenu::headerTextColourId, 0xff000000,
  51245. PopupMenu::highlightedTextColourId, 0xffffffff,
  51246. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  51247. ComboBox::textColourId, 0xff000000,
  51248. ComboBox::backgroundColourId, 0xffffffff,
  51249. ComboBox::arrowColourId, 0x99000000,
  51250. ListBox::backgroundColourId, 0xffffffff,
  51251. ListBox::outlineColourId, standardOutlineColour,
  51252. ListBox::textColourId, 0xff000000,
  51253. Slider::backgroundColourId, 0x00000000,
  51254. Slider::thumbColourId, textButtonColour,
  51255. Slider::trackColourId, 0x7fffffff,
  51256. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51257. Slider::rotarySliderOutlineColourId, 0x66000000,
  51258. Slider::textBoxTextColourId, 0xff000000,
  51259. Slider::textBoxBackgroundColourId, 0xffffffff,
  51260. Slider::textBoxHighlightColourId, textHighlightColour,
  51261. Slider::textBoxOutlineColourId, standardOutlineColour,
  51262. ResizableWindow::backgroundColourId, 0xff777777,
  51263. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51264. AlertWindow::backgroundColourId, 0xffededed,
  51265. AlertWindow::textColourId, 0xff000000,
  51266. AlertWindow::outlineColourId, 0xff666666,
  51267. ProgressBar::backgroundColourId, 0xffeeeeee,
  51268. ProgressBar::foregroundColourId, 0xffaaaaee,
  51269. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51270. TooltipWindow::textColourId, 0xff000000,
  51271. TooltipWindow::outlineColourId, 0x4c000000,
  51272. TabbedComponent::backgroundColourId, 0x00000000,
  51273. TabbedComponent::outlineColourId, 0xff777777,
  51274. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51275. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51276. Toolbar::backgroundColourId, 0xfff6f8f9,
  51277. Toolbar::separatorColourId, 0x4c000000,
  51278. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51279. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51280. Toolbar::labelTextColourId, 0xff000000,
  51281. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51282. HyperlinkButton::textColourId, 0xcc1111ee,
  51283. GroupComponent::outlineColourId, 0x66000000,
  51284. GroupComponent::textColourId, 0xff000000,
  51285. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51286. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51287. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51288. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51289. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51290. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51291. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51292. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51293. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51294. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51295. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51296. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51297. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51298. CodeEditorComponent::caretColourId, 0xff000000,
  51299. CodeEditorComponent::highlightColourId, textHighlightColour,
  51300. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51301. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51302. ColourSelector::labelTextColourId, 0xff000000,
  51303. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51304. KeyMappingEditorComponent::textColourId, 0xff000000,
  51305. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51306. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51307. };
  51308. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51309. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51310. if (defaultSansName.isEmpty())
  51311. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51312. defaultSans = defaultSansName;
  51313. defaultSerif = defaultSerifName;
  51314. defaultFixed = defaultFixedName;
  51315. }
  51316. LookAndFeel::~LookAndFeel()
  51317. {
  51318. }
  51319. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51320. {
  51321. const int index = colourIds.indexOf (colourId);
  51322. if (index >= 0)
  51323. return colours [index];
  51324. jassertfalse
  51325. return Colours::black;
  51326. }
  51327. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51328. {
  51329. const int index = colourIds.indexOf (colourId);
  51330. if (index >= 0)
  51331. colours.set (index, colour);
  51332. colourIds.add (colourId);
  51333. colours.add (colour);
  51334. }
  51335. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51336. {
  51337. return colourIds.contains (colourId);
  51338. }
  51339. static LookAndFeel* defaultLF = 0;
  51340. static LookAndFeel* currentDefaultLF = 0;
  51341. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51342. {
  51343. // if this happens, your app hasn't initialised itself properly.. if you're
  51344. // trying to hack your own main() function, have a look at
  51345. // JUCEApplication::initialiseForGUI()
  51346. jassert (currentDefaultLF != 0);
  51347. return *currentDefaultLF;
  51348. }
  51349. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51350. {
  51351. if (newDefaultLookAndFeel == 0)
  51352. {
  51353. if (defaultLF == 0)
  51354. defaultLF = new LookAndFeel();
  51355. newDefaultLookAndFeel = defaultLF;
  51356. }
  51357. currentDefaultLF = newDefaultLookAndFeel;
  51358. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51359. {
  51360. Component* const c = Desktop::getInstance().getComponent (i);
  51361. if (c != 0)
  51362. c->sendLookAndFeelChange();
  51363. }
  51364. }
  51365. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51366. {
  51367. if (currentDefaultLF == defaultLF)
  51368. currentDefaultLF = 0;
  51369. deleteAndZero (defaultLF);
  51370. }
  51371. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51372. {
  51373. String faceName (font.getTypefaceName());
  51374. if (faceName == Font::getDefaultSansSerifFontName())
  51375. faceName = defaultSans;
  51376. else if (faceName == Font::getDefaultSerifFontName())
  51377. faceName = defaultSerif;
  51378. else if (faceName == Font::getDefaultMonospacedFontName())
  51379. faceName = defaultFixed;
  51380. Font f (font);
  51381. f.setTypefaceName (faceName);
  51382. return Typeface::createSystemTypefaceFor (f);
  51383. }
  51384. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51385. {
  51386. defaultSans = newName;
  51387. }
  51388. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51389. {
  51390. return component.getMouseCursor();
  51391. }
  51392. void LookAndFeel::drawButtonBackground (Graphics& g,
  51393. Button& button,
  51394. const Colour& backgroundColour,
  51395. bool isMouseOverButton,
  51396. bool isButtonDown)
  51397. {
  51398. const int width = button.getWidth();
  51399. const int height = button.getHeight();
  51400. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51401. const float halfThickness = outlineThickness * 0.5f;
  51402. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51403. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51404. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51405. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51406. const Colour baseColour (createBaseColour (backgroundColour,
  51407. button.hasKeyboardFocus (true),
  51408. isMouseOverButton, isButtonDown)
  51409. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51410. drawGlassLozenge (g,
  51411. indentL,
  51412. indentT,
  51413. width - indentL - indentR,
  51414. height - indentT - indentB,
  51415. baseColour, outlineThickness, -1.0f,
  51416. button.isConnectedOnLeft(),
  51417. button.isConnectedOnRight(),
  51418. button.isConnectedOnTop(),
  51419. button.isConnectedOnBottom());
  51420. }
  51421. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51422. {
  51423. return button.getFont();
  51424. }
  51425. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51426. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51427. {
  51428. Font font (getFontForTextButton (button));
  51429. g.setFont (font);
  51430. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51431. : TextButton::textColourOffId)
  51432. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51433. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51434. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51435. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51436. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51437. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51438. g.drawFittedText (button.getButtonText(),
  51439. leftIndent,
  51440. yIndent,
  51441. button.getWidth() - leftIndent - rightIndent,
  51442. button.getHeight() - yIndent * 2,
  51443. Justification::centred, 2);
  51444. }
  51445. void LookAndFeel::drawTickBox (Graphics& g,
  51446. Component& component,
  51447. float x, float y, float w, float h,
  51448. const bool ticked,
  51449. const bool isEnabled,
  51450. const bool isMouseOverButton,
  51451. const bool isButtonDown)
  51452. {
  51453. const float boxSize = w * 0.7f;
  51454. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51455. createBaseColour (component.findColour (TextButton::buttonColourId)
  51456. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51457. true,
  51458. isMouseOverButton,
  51459. isButtonDown),
  51460. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51461. if (ticked)
  51462. {
  51463. Path tick;
  51464. tick.startNewSubPath (1.5f, 3.0f);
  51465. tick.lineTo (3.0f, 6.0f);
  51466. tick.lineTo (6.0f, 0.0f);
  51467. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51468. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51469. .translated (x, y));
  51470. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51471. }
  51472. }
  51473. void LookAndFeel::drawToggleButton (Graphics& g,
  51474. ToggleButton& button,
  51475. bool isMouseOverButton,
  51476. bool isButtonDown)
  51477. {
  51478. if (button.hasKeyboardFocus (true))
  51479. {
  51480. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51481. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51482. }
  51483. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51484. const float tickWidth = fontSize * 1.1f;
  51485. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51486. tickWidth, tickWidth,
  51487. button.getToggleState(),
  51488. button.isEnabled(),
  51489. isMouseOverButton,
  51490. isButtonDown);
  51491. g.setColour (button.findColour (ToggleButton::textColourId));
  51492. g.setFont (fontSize);
  51493. if (! button.isEnabled())
  51494. g.setOpacity (0.5f);
  51495. const int textX = (int) tickWidth + 5;
  51496. g.drawFittedText (button.getButtonText(),
  51497. textX, 0,
  51498. button.getWidth() - textX - 2, button.getHeight(),
  51499. Justification::centredLeft, 10);
  51500. }
  51501. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51502. {
  51503. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51504. const int tickWidth = jmin (24, button.getHeight());
  51505. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  51506. button.getHeight());
  51507. }
  51508. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  51509. const String& message,
  51510. const String& button1,
  51511. const String& button2,
  51512. const String& button3,
  51513. AlertWindow::AlertIconType iconType,
  51514. int numButtons,
  51515. Component* associatedComponent)
  51516. {
  51517. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  51518. if (numButtons == 1)
  51519. {
  51520. aw->addButton (button1, 0,
  51521. KeyPress (KeyPress::escapeKey, 0, 0),
  51522. KeyPress (KeyPress::returnKey, 0, 0));
  51523. }
  51524. else
  51525. {
  51526. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  51527. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  51528. if (button1ShortCut == button2ShortCut)
  51529. button2ShortCut = KeyPress();
  51530. if (numButtons == 2)
  51531. {
  51532. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  51533. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  51534. }
  51535. else if (numButtons == 3)
  51536. {
  51537. aw->addButton (button1, 1, button1ShortCut);
  51538. aw->addButton (button2, 2, button2ShortCut);
  51539. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  51540. }
  51541. }
  51542. return aw;
  51543. }
  51544. void LookAndFeel::drawAlertBox (Graphics& g,
  51545. AlertWindow& alert,
  51546. const Rectangle<int>& textArea,
  51547. TextLayout& textLayout)
  51548. {
  51549. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  51550. int iconSpaceUsed = 0;
  51551. Justification alignment (Justification::horizontallyCentred);
  51552. const int iconWidth = 80;
  51553. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  51554. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  51555. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  51556. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  51557. iconSize, iconSize);
  51558. if (alert.getAlertType() != AlertWindow::NoIcon)
  51559. {
  51560. Path icon;
  51561. uint32 colour;
  51562. char character;
  51563. if (alert.getAlertType() == AlertWindow::WarningIcon)
  51564. {
  51565. colour = 0x55ff5555;
  51566. character = '!';
  51567. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  51568. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  51569. (float) iconRect.getX(), (float) iconRect.getBottom());
  51570. icon = icon.createPathWithRoundedCorners (5.0f);
  51571. }
  51572. else
  51573. {
  51574. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  51575. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  51576. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  51577. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  51578. }
  51579. GlyphArrangement ga;
  51580. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  51581. String::charToString (character),
  51582. (float) iconRect.getX(), (float) iconRect.getY(),
  51583. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  51584. Justification::centred, false);
  51585. ga.createPath (icon);
  51586. icon.setUsingNonZeroWinding (false);
  51587. g.setColour (Colour (colour));
  51588. g.fillPath (icon);
  51589. iconSpaceUsed = iconWidth;
  51590. alignment = Justification::left;
  51591. }
  51592. g.setColour (alert.findColour (AlertWindow::textColourId));
  51593. textLayout.drawWithin (g,
  51594. textArea.getX() + iconSpaceUsed, textArea.getY(),
  51595. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  51596. alignment.getFlags() | Justification::top);
  51597. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  51598. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  51599. }
  51600. int LookAndFeel::getAlertBoxWindowFlags()
  51601. {
  51602. return ComponentPeer::windowAppearsOnTaskbar
  51603. | ComponentPeer::windowHasDropShadow;
  51604. }
  51605. int LookAndFeel::getAlertWindowButtonHeight()
  51606. {
  51607. return 28;
  51608. }
  51609. const Font LookAndFeel::getAlertWindowFont()
  51610. {
  51611. return Font (12.0f);
  51612. }
  51613. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  51614. int width, int height,
  51615. double progress, const String& textToShow)
  51616. {
  51617. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  51618. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  51619. g.fillAll (background);
  51620. if (progress >= 0.0f && progress < 1.0f)
  51621. {
  51622. drawGlassLozenge (g, 1.0f, 1.0f,
  51623. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  51624. (float) (height - 2),
  51625. foreground,
  51626. 0.5f, 0.0f,
  51627. true, true, true, true);
  51628. }
  51629. else
  51630. {
  51631. // spinning bar..
  51632. g.setColour (foreground);
  51633. const int stripeWidth = height * 2;
  51634. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  51635. Path p;
  51636. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  51637. p.addQuadrilateral (x, 0.0f,
  51638. x + stripeWidth * 0.5f, 0.0f,
  51639. x, (float) height,
  51640. x - stripeWidth * 0.5f, (float) height);
  51641. Image im (Image::ARGB, width, height, true);
  51642. {
  51643. Graphics g2 (im);
  51644. drawGlassLozenge (g2, 1.0f, 1.0f,
  51645. (float) (width - 2),
  51646. (float) (height - 2),
  51647. foreground,
  51648. 0.5f, 0.0f,
  51649. true, true, true, true);
  51650. }
  51651. g.setTiledImageFill (im, 0, 0, 0.85f);
  51652. g.fillPath (p);
  51653. }
  51654. if (textToShow.isNotEmpty())
  51655. {
  51656. g.setColour (Colour::contrasting (background, foreground));
  51657. g.setFont (height * 0.6f);
  51658. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  51659. }
  51660. }
  51661. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  51662. {
  51663. const float radius = jmin (w, h) * 0.4f;
  51664. const float thickness = radius * 0.15f;
  51665. Path p;
  51666. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  51667. radius * 0.6f, thickness,
  51668. thickness * 0.5f);
  51669. const float cx = x + w * 0.5f;
  51670. const float cy = y + h * 0.5f;
  51671. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  51672. for (int i = 0; i < 12; ++i)
  51673. {
  51674. const int n = (i + 12 - animationIndex) % 12;
  51675. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  51676. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  51677. .translated (cx, cy));
  51678. }
  51679. }
  51680. void LookAndFeel::drawScrollbarButton (Graphics& g,
  51681. ScrollBar& scrollbar,
  51682. int width, int height,
  51683. int buttonDirection,
  51684. bool /*isScrollbarVertical*/,
  51685. bool /*isMouseOverButton*/,
  51686. bool isButtonDown)
  51687. {
  51688. Path p;
  51689. if (buttonDirection == 0)
  51690. p.addTriangle (width * 0.5f, height * 0.2f,
  51691. width * 0.1f, height * 0.7f,
  51692. width * 0.9f, height * 0.7f);
  51693. else if (buttonDirection == 1)
  51694. p.addTriangle (width * 0.8f, height * 0.5f,
  51695. width * 0.3f, height * 0.1f,
  51696. width * 0.3f, height * 0.9f);
  51697. else if (buttonDirection == 2)
  51698. p.addTriangle (width * 0.5f, height * 0.8f,
  51699. width * 0.1f, height * 0.3f,
  51700. width * 0.9f, height * 0.3f);
  51701. else if (buttonDirection == 3)
  51702. p.addTriangle (width * 0.2f, height * 0.5f,
  51703. width * 0.7f, height * 0.1f,
  51704. width * 0.7f, height * 0.9f);
  51705. if (isButtonDown)
  51706. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  51707. else
  51708. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51709. g.fillPath (p);
  51710. g.setColour (Colour (0x80000000));
  51711. g.strokePath (p, PathStrokeType (0.5f));
  51712. }
  51713. void LookAndFeel::drawScrollbar (Graphics& g,
  51714. ScrollBar& scrollbar,
  51715. int x, int y,
  51716. int width, int height,
  51717. bool isScrollbarVertical,
  51718. int thumbStartPosition,
  51719. int thumbSize,
  51720. bool /*isMouseOver*/,
  51721. bool /*isMouseDown*/)
  51722. {
  51723. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  51724. Path slotPath, thumbPath;
  51725. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  51726. const float slotIndentx2 = slotIndent * 2.0f;
  51727. const float thumbIndent = slotIndent + 1.0f;
  51728. const float thumbIndentx2 = thumbIndent * 2.0f;
  51729. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  51730. if (isScrollbarVertical)
  51731. {
  51732. slotPath.addRoundedRectangle (x + slotIndent,
  51733. y + slotIndent,
  51734. width - slotIndentx2,
  51735. height - slotIndentx2,
  51736. (width - slotIndentx2) * 0.5f);
  51737. if (thumbSize > 0)
  51738. thumbPath.addRoundedRectangle (x + thumbIndent,
  51739. thumbStartPosition + thumbIndent,
  51740. width - thumbIndentx2,
  51741. thumbSize - thumbIndentx2,
  51742. (width - thumbIndentx2) * 0.5f);
  51743. gx1 = (float) x;
  51744. gx2 = x + width * 0.7f;
  51745. }
  51746. else
  51747. {
  51748. slotPath.addRoundedRectangle (x + slotIndent,
  51749. y + slotIndent,
  51750. width - slotIndentx2,
  51751. height - slotIndentx2,
  51752. (height - slotIndentx2) * 0.5f);
  51753. if (thumbSize > 0)
  51754. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  51755. y + thumbIndent,
  51756. thumbSize - thumbIndentx2,
  51757. height - thumbIndentx2,
  51758. (height - thumbIndentx2) * 0.5f);
  51759. gy1 = (float) y;
  51760. gy2 = y + height * 0.7f;
  51761. }
  51762. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51763. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  51764. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  51765. g.fillPath (slotPath);
  51766. if (isScrollbarVertical)
  51767. {
  51768. gx1 = x + width * 0.6f;
  51769. gx2 = (float) x + width;
  51770. }
  51771. else
  51772. {
  51773. gy1 = y + height * 0.6f;
  51774. gy2 = (float) y + height;
  51775. }
  51776. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  51777. Colour (0x19000000), gx2, gy2, false));
  51778. g.fillPath (slotPath);
  51779. g.setColour (thumbColour);
  51780. g.fillPath (thumbPath);
  51781. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  51782. Colours::transparentBlack, gx2, gy2, false));
  51783. g.saveState();
  51784. if (isScrollbarVertical)
  51785. g.reduceClipRegion (x + width / 2, y, width, height);
  51786. else
  51787. g.reduceClipRegion (x, y + height / 2, width, height);
  51788. g.fillPath (thumbPath);
  51789. g.restoreState();
  51790. g.setColour (Colour (0x4c000000));
  51791. g.strokePath (thumbPath, PathStrokeType (0.4f));
  51792. }
  51793. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  51794. {
  51795. return 0;
  51796. }
  51797. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  51798. {
  51799. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  51800. }
  51801. int LookAndFeel::getDefaultScrollbarWidth()
  51802. {
  51803. return 18;
  51804. }
  51805. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  51806. {
  51807. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  51808. : scrollbar.getHeight());
  51809. }
  51810. const Path LookAndFeel::getTickShape (const float height)
  51811. {
  51812. static const unsigned char tickShapeData[] =
  51813. {
  51814. 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,
  51815. 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,
  51816. 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,
  51817. 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,
  51818. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  51819. };
  51820. Path p;
  51821. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  51822. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51823. return p;
  51824. }
  51825. const Path LookAndFeel::getCrossShape (const float height)
  51826. {
  51827. static const unsigned char crossShapeData[] =
  51828. {
  51829. 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,
  51830. 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,
  51831. 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,
  51832. 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,
  51833. 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,
  51834. 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,
  51835. 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
  51836. };
  51837. Path p;
  51838. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  51839. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51840. return p;
  51841. }
  51842. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  51843. {
  51844. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  51845. x += (w - boxSize) >> 1;
  51846. y += (h - boxSize) >> 1;
  51847. w = boxSize;
  51848. h = boxSize;
  51849. g.setColour (Colour (0xe5ffffff));
  51850. g.fillRect (x, y, w, h);
  51851. g.setColour (Colour (0x80000000));
  51852. g.drawRect (x, y, w, h);
  51853. const float size = boxSize / 2 + 1.0f;
  51854. const float centre = (float) (boxSize / 2);
  51855. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  51856. if (isPlus)
  51857. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  51858. }
  51859. void LookAndFeel::drawBubble (Graphics& g,
  51860. float tipX, float tipY,
  51861. float boxX, float boxY,
  51862. float boxW, float boxH)
  51863. {
  51864. int side = 0;
  51865. if (tipX < boxX)
  51866. side = 1;
  51867. else if (tipX > boxX + boxW)
  51868. side = 3;
  51869. else if (tipY > boxY + boxH)
  51870. side = 2;
  51871. const float indent = 2.0f;
  51872. Path p;
  51873. p.addBubble (boxX + indent,
  51874. boxY + indent,
  51875. boxW - indent * 2.0f,
  51876. boxH - indent * 2.0f,
  51877. 5.0f,
  51878. tipX, tipY,
  51879. side,
  51880. 0.5f,
  51881. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  51882. //xxx need to take comp as param for colour
  51883. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  51884. g.fillPath (p);
  51885. //xxx as above
  51886. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  51887. g.strokePath (p, PathStrokeType (1.33f));
  51888. }
  51889. const Font LookAndFeel::getPopupMenuFont()
  51890. {
  51891. return Font (17.0f);
  51892. }
  51893. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  51894. const bool isSeparator,
  51895. int standardMenuItemHeight,
  51896. int& idealWidth,
  51897. int& idealHeight)
  51898. {
  51899. if (isSeparator)
  51900. {
  51901. idealWidth = 50;
  51902. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  51903. }
  51904. else
  51905. {
  51906. Font font (getPopupMenuFont());
  51907. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  51908. font.setHeight (standardMenuItemHeight / 1.3f);
  51909. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  51910. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  51911. }
  51912. }
  51913. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  51914. {
  51915. const Colour background (findColour (PopupMenu::backgroundColourId));
  51916. g.fillAll (background);
  51917. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  51918. for (int i = 0; i < height; i += 3)
  51919. g.fillRect (0, i, width, 1);
  51920. #if ! JUCE_MAC
  51921. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  51922. g.drawRect (0, 0, width, height);
  51923. #endif
  51924. }
  51925. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  51926. int width, int height,
  51927. bool isScrollUpArrow)
  51928. {
  51929. const Colour background (findColour (PopupMenu::backgroundColourId));
  51930. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  51931. background.withAlpha (0.0f),
  51932. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  51933. false));
  51934. g.fillRect (1, 1, width - 2, height - 2);
  51935. const float hw = width * 0.5f;
  51936. const float arrowW = height * 0.3f;
  51937. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  51938. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  51939. Path p;
  51940. p.addTriangle (hw - arrowW, y1,
  51941. hw + arrowW, y1,
  51942. hw, y2);
  51943. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  51944. g.fillPath (p);
  51945. }
  51946. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  51947. int width, int height,
  51948. const bool isSeparator,
  51949. const bool isActive,
  51950. const bool isHighlighted,
  51951. const bool isTicked,
  51952. const bool hasSubMenu,
  51953. const String& text,
  51954. const String& shortcutKeyText,
  51955. Image* image,
  51956. const Colour* const textColourToUse)
  51957. {
  51958. const float halfH = height * 0.5f;
  51959. if (isSeparator)
  51960. {
  51961. const float separatorIndent = 5.5f;
  51962. g.setColour (Colour (0x33000000));
  51963. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  51964. g.setColour (Colour (0x66ffffff));
  51965. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  51966. }
  51967. else
  51968. {
  51969. Colour textColour (findColour (PopupMenu::textColourId));
  51970. if (textColourToUse != 0)
  51971. textColour = *textColourToUse;
  51972. if (isHighlighted)
  51973. {
  51974. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  51975. g.fillRect (1, 1, width - 2, height - 2);
  51976. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  51977. }
  51978. else
  51979. {
  51980. g.setColour (textColour);
  51981. }
  51982. if (! isActive)
  51983. g.setOpacity (0.3f);
  51984. Font font (getPopupMenuFont());
  51985. if (font.getHeight() > height / 1.3f)
  51986. font.setHeight (height / 1.3f);
  51987. g.setFont (font);
  51988. const int leftBorder = (height * 5) / 4;
  51989. const int rightBorder = 4;
  51990. if (image != 0)
  51991. {
  51992. g.drawImageWithin (image,
  51993. 2, 1, leftBorder - 4, height - 2,
  51994. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  51995. }
  51996. else if (isTicked)
  51997. {
  51998. const Path tick (getTickShape (1.0f));
  51999. const float th = font.getAscent();
  52000. const float ty = halfH - th * 0.5f;
  52001. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  52002. th, true));
  52003. }
  52004. g.drawFittedText (text,
  52005. leftBorder, 0,
  52006. width - (leftBorder + rightBorder), height,
  52007. Justification::centredLeft, 1);
  52008. if (shortcutKeyText.isNotEmpty())
  52009. {
  52010. Font f2 (font);
  52011. f2.setHeight (f2.getHeight() * 0.75f);
  52012. f2.setHorizontalScale (0.95f);
  52013. g.setFont (f2);
  52014. g.drawText (shortcutKeyText,
  52015. leftBorder,
  52016. 0,
  52017. width - (leftBorder + rightBorder + 4),
  52018. height,
  52019. Justification::centredRight,
  52020. true);
  52021. }
  52022. if (hasSubMenu)
  52023. {
  52024. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  52025. const float x = width - height * 0.6f;
  52026. Path p;
  52027. p.addTriangle (x, halfH - arrowH * 0.5f,
  52028. x, halfH + arrowH * 0.5f,
  52029. x + arrowH * 0.6f, halfH);
  52030. g.fillPath (p);
  52031. }
  52032. }
  52033. }
  52034. int LookAndFeel::getMenuWindowFlags()
  52035. {
  52036. return ComponentPeer::windowHasDropShadow;
  52037. }
  52038. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  52039. bool, MenuBarComponent& menuBar)
  52040. {
  52041. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  52042. if (menuBar.isEnabled())
  52043. {
  52044. drawShinyButtonShape (g,
  52045. -4.0f, 0.0f,
  52046. width + 8.0f, (float) height,
  52047. 0.0f,
  52048. baseColour,
  52049. 0.4f,
  52050. true, true, true, true);
  52051. }
  52052. else
  52053. {
  52054. g.fillAll (baseColour);
  52055. }
  52056. }
  52057. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  52058. {
  52059. return Font (menuBar.getHeight() * 0.7f);
  52060. }
  52061. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  52062. {
  52063. return getMenuBarFont (menuBar, itemIndex, itemText)
  52064. .getStringWidth (itemText) + menuBar.getHeight();
  52065. }
  52066. void LookAndFeel::drawMenuBarItem (Graphics& g,
  52067. int width, int height,
  52068. int itemIndex,
  52069. const String& itemText,
  52070. bool isMouseOverItem,
  52071. bool isMenuOpen,
  52072. bool /*isMouseOverBar*/,
  52073. MenuBarComponent& menuBar)
  52074. {
  52075. if (! menuBar.isEnabled())
  52076. {
  52077. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  52078. .withMultipliedAlpha (0.5f));
  52079. }
  52080. else if (isMenuOpen || isMouseOverItem)
  52081. {
  52082. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  52083. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  52084. }
  52085. else
  52086. {
  52087. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  52088. }
  52089. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  52090. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  52091. }
  52092. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  52093. TextEditor& textEditor)
  52094. {
  52095. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  52096. }
  52097. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  52098. {
  52099. if (textEditor.isEnabled())
  52100. {
  52101. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  52102. {
  52103. const int border = 2;
  52104. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  52105. g.drawRect (0, 0, width, height, border);
  52106. g.setOpacity (1.0f);
  52107. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  52108. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  52109. }
  52110. else
  52111. {
  52112. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  52113. g.drawRect (0, 0, width, height);
  52114. g.setOpacity (1.0f);
  52115. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  52116. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  52117. }
  52118. }
  52119. }
  52120. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  52121. const bool isButtonDown,
  52122. int buttonX, int buttonY,
  52123. int buttonW, int buttonH,
  52124. ComboBox& box)
  52125. {
  52126. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  52127. if (box.isEnabled() && box.hasKeyboardFocus (false))
  52128. {
  52129. g.setColour (box.findColour (TextButton::buttonColourId));
  52130. g.drawRect (0, 0, width, height, 2);
  52131. }
  52132. else
  52133. {
  52134. g.setColour (box.findColour (ComboBox::outlineColourId));
  52135. g.drawRect (0, 0, width, height);
  52136. }
  52137. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  52138. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  52139. box.hasKeyboardFocus (true),
  52140. false, isButtonDown)
  52141. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  52142. drawGlassLozenge (g,
  52143. buttonX + outlineThickness, buttonY + outlineThickness,
  52144. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  52145. baseColour, outlineThickness, -1.0f,
  52146. true, true, true, true);
  52147. if (box.isEnabled())
  52148. {
  52149. const float arrowX = 0.3f;
  52150. const float arrowH = 0.2f;
  52151. Path p;
  52152. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  52153. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  52154. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  52155. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  52156. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  52157. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  52158. g.setColour (box.findColour (ComboBox::arrowColourId));
  52159. g.fillPath (p);
  52160. }
  52161. }
  52162. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  52163. {
  52164. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  52165. }
  52166. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  52167. {
  52168. return new Label (String::empty, String::empty);
  52169. }
  52170. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  52171. {
  52172. label.setBounds (1, 1,
  52173. box.getWidth() + 3 - box.getHeight(),
  52174. box.getHeight() - 2);
  52175. label.setFont (getComboBoxFont (box));
  52176. }
  52177. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  52178. {
  52179. g.fillAll (label.findColour (Label::backgroundColourId));
  52180. if (! label.isBeingEdited())
  52181. {
  52182. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  52183. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  52184. g.setFont (label.getFont());
  52185. g.drawFittedText (label.getText(),
  52186. label.getHorizontalBorderSize(),
  52187. label.getVerticalBorderSize(),
  52188. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  52189. label.getHeight() - 2 * label.getVerticalBorderSize(),
  52190. label.getJustificationType(),
  52191. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  52192. label.getMinimumHorizontalScale());
  52193. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  52194. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52195. }
  52196. else if (label.isEnabled())
  52197. {
  52198. g.setColour (label.findColour (Label::outlineColourId));
  52199. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52200. }
  52201. }
  52202. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  52203. int x, int y,
  52204. int width, int height,
  52205. float /*sliderPos*/,
  52206. float /*minSliderPos*/,
  52207. float /*maxSliderPos*/,
  52208. const Slider::SliderStyle /*style*/,
  52209. Slider& slider)
  52210. {
  52211. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52212. const Colour trackColour (slider.findColour (Slider::trackColourId));
  52213. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  52214. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  52215. Path indent;
  52216. if (slider.isHorizontal())
  52217. {
  52218. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  52219. const float ih = sliderRadius;
  52220. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  52221. gradCol2, 0.0f, iy + ih, false));
  52222. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  52223. width + sliderRadius, ih,
  52224. 5.0f);
  52225. g.fillPath (indent);
  52226. }
  52227. else
  52228. {
  52229. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  52230. const float iw = sliderRadius;
  52231. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  52232. gradCol2, ix + iw, 0.0f, false));
  52233. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  52234. iw, height + sliderRadius,
  52235. 5.0f);
  52236. g.fillPath (indent);
  52237. }
  52238. g.setColour (Colour (0x4c000000));
  52239. g.strokePath (indent, PathStrokeType (0.5f));
  52240. }
  52241. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  52242. int x, int y,
  52243. int width, int height,
  52244. float sliderPos,
  52245. float minSliderPos,
  52246. float maxSliderPos,
  52247. const Slider::SliderStyle style,
  52248. Slider& slider)
  52249. {
  52250. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52251. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52252. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52253. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52254. slider.isMouseButtonDown() && slider.isEnabled()));
  52255. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52256. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52257. {
  52258. float kx, ky;
  52259. if (style == Slider::LinearVertical)
  52260. {
  52261. kx = x + width * 0.5f;
  52262. ky = sliderPos;
  52263. }
  52264. else
  52265. {
  52266. kx = sliderPos;
  52267. ky = y + height * 0.5f;
  52268. }
  52269. drawGlassSphere (g,
  52270. kx - sliderRadius,
  52271. ky - sliderRadius,
  52272. sliderRadius * 2.0f,
  52273. knobColour, outlineThickness);
  52274. }
  52275. else
  52276. {
  52277. if (style == Slider::ThreeValueVertical)
  52278. {
  52279. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52280. sliderPos - sliderRadius,
  52281. sliderRadius * 2.0f,
  52282. knobColour, outlineThickness);
  52283. }
  52284. else if (style == Slider::ThreeValueHorizontal)
  52285. {
  52286. drawGlassSphere (g,sliderPos - sliderRadius,
  52287. y + height * 0.5f - sliderRadius,
  52288. sliderRadius * 2.0f,
  52289. knobColour, outlineThickness);
  52290. }
  52291. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52292. {
  52293. const float sr = jmin (sliderRadius, width * 0.4f);
  52294. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52295. minSliderPos - sliderRadius,
  52296. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52297. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52298. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52299. }
  52300. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52301. {
  52302. const float sr = jmin (sliderRadius, height * 0.4f);
  52303. drawGlassPointer (g, minSliderPos - sr,
  52304. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52305. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52306. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52307. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52308. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52309. }
  52310. }
  52311. }
  52312. void LookAndFeel::drawLinearSlider (Graphics& g,
  52313. int x, int y,
  52314. int width, int height,
  52315. float sliderPos,
  52316. float minSliderPos,
  52317. float maxSliderPos,
  52318. const Slider::SliderStyle style,
  52319. Slider& slider)
  52320. {
  52321. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52322. if (style == Slider::LinearBar)
  52323. {
  52324. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52325. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52326. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52327. false,
  52328. isMouseOver,
  52329. isMouseOver || slider.isMouseButtonDown()));
  52330. drawShinyButtonShape (g,
  52331. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52332. baseColour,
  52333. slider.isEnabled() ? 0.9f : 0.3f,
  52334. true, true, true, true);
  52335. }
  52336. else
  52337. {
  52338. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52339. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52340. }
  52341. }
  52342. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52343. {
  52344. return jmin (7,
  52345. slider.getHeight() / 2,
  52346. slider.getWidth() / 2) + 2;
  52347. }
  52348. void LookAndFeel::drawRotarySlider (Graphics& g,
  52349. int x, int y,
  52350. int width, int height,
  52351. float sliderPos,
  52352. const float rotaryStartAngle,
  52353. const float rotaryEndAngle,
  52354. Slider& slider)
  52355. {
  52356. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52357. const float centreX = x + width * 0.5f;
  52358. const float centreY = y + height * 0.5f;
  52359. const float rx = centreX - radius;
  52360. const float ry = centreY - radius;
  52361. const float rw = radius * 2.0f;
  52362. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52363. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52364. if (radius > 12.0f)
  52365. {
  52366. if (slider.isEnabled())
  52367. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52368. else
  52369. g.setColour (Colour (0x80808080));
  52370. const float thickness = 0.7f;
  52371. {
  52372. Path filledArc;
  52373. filledArc.addPieSegment (rx, ry, rw, rw,
  52374. rotaryStartAngle,
  52375. angle,
  52376. thickness);
  52377. g.fillPath (filledArc);
  52378. }
  52379. if (thickness > 0)
  52380. {
  52381. const float innerRadius = radius * 0.2f;
  52382. Path p;
  52383. p.addTriangle (-innerRadius, 0.0f,
  52384. 0.0f, -radius * thickness * 1.1f,
  52385. innerRadius, 0.0f);
  52386. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52387. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52388. }
  52389. if (slider.isEnabled())
  52390. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52391. else
  52392. g.setColour (Colour (0x80808080));
  52393. Path outlineArc;
  52394. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52395. outlineArc.closeSubPath();
  52396. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52397. }
  52398. else
  52399. {
  52400. if (slider.isEnabled())
  52401. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52402. else
  52403. g.setColour (Colour (0x80808080));
  52404. Path p;
  52405. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52406. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52407. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52408. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52409. }
  52410. }
  52411. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52412. {
  52413. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52414. }
  52415. class SliderLabelComp : public Label
  52416. {
  52417. public:
  52418. SliderLabelComp() : Label (String::empty, String::empty) {}
  52419. ~SliderLabelComp() {}
  52420. void mouseWheelMove (const MouseEvent&, float, float) {}
  52421. };
  52422. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52423. {
  52424. Label* const l = new SliderLabelComp();
  52425. l->setJustificationType (Justification::centred);
  52426. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52427. l->setColour (Label::backgroundColourId,
  52428. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52429. : slider.findColour (Slider::textBoxBackgroundColourId));
  52430. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52431. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52432. l->setColour (TextEditor::backgroundColourId,
  52433. slider.findColour (Slider::textBoxBackgroundColourId)
  52434. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52435. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52436. return l;
  52437. }
  52438. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52439. {
  52440. return 0;
  52441. }
  52442. static const TextLayout layoutTooltipText (const String& text) throw()
  52443. {
  52444. const float tooltipFontSize = 12.0f;
  52445. const int maxToolTipWidth = 400;
  52446. const Font f (tooltipFontSize, Font::bold);
  52447. TextLayout tl (text, f);
  52448. tl.layout (maxToolTipWidth, Justification::left, true);
  52449. return tl;
  52450. }
  52451. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52452. {
  52453. const TextLayout tl (layoutTooltipText (tipText));
  52454. width = tl.getWidth() + 14;
  52455. height = tl.getHeight() + 6;
  52456. }
  52457. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52458. {
  52459. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52460. const Colour textCol (findColour (TooltipWindow::textColourId));
  52461. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52462. g.setColour (findColour (TooltipWindow::outlineColourId));
  52463. g.drawRect (0, 0, width, height, 1);
  52464. #endif
  52465. const TextLayout tl (layoutTooltipText (text));
  52466. g.setColour (findColour (TooltipWindow::textColourId));
  52467. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52468. }
  52469. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52470. {
  52471. return new TextButton (text, TRANS("click to browse for a different file"));
  52472. }
  52473. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52474. ComboBox* filenameBox,
  52475. Button* browseButton)
  52476. {
  52477. browseButton->setSize (80, filenameComp.getHeight());
  52478. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52479. if (tb != 0)
  52480. tb->changeWidthToFitText();
  52481. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52482. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52483. }
  52484. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52485. int imageX, int imageY, int imageW, int imageH,
  52486. const Colour& overlayColour,
  52487. float imageOpacity,
  52488. ImageButton& button)
  52489. {
  52490. if (! button.isEnabled())
  52491. imageOpacity *= 0.3f;
  52492. if (! overlayColour.isOpaque())
  52493. {
  52494. g.setOpacity (imageOpacity);
  52495. g.drawImage (image, imageX, imageY, imageW, imageH,
  52496. 0, 0, image->getWidth(), image->getHeight(), false);
  52497. }
  52498. if (! overlayColour.isTransparent())
  52499. {
  52500. g.setColour (overlayColour);
  52501. g.drawImage (image, imageX, imageY, imageW, imageH,
  52502. 0, 0, image->getWidth(), image->getHeight(), true);
  52503. }
  52504. }
  52505. void LookAndFeel::drawCornerResizer (Graphics& g,
  52506. int w, int h,
  52507. bool /*isMouseOver*/,
  52508. bool /*isMouseDragging*/)
  52509. {
  52510. const float lineThickness = jmin (w, h) * 0.075f;
  52511. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  52512. {
  52513. g.setColour (Colours::lightgrey);
  52514. g.drawLine (w * i,
  52515. h + 1.0f,
  52516. w + 1.0f,
  52517. h * i,
  52518. lineThickness);
  52519. g.setColour (Colours::darkgrey);
  52520. g.drawLine (w * i + lineThickness,
  52521. h + 1.0f,
  52522. w + 1.0f,
  52523. h * i + lineThickness,
  52524. lineThickness);
  52525. }
  52526. }
  52527. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  52528. const BorderSize& /*borders*/)
  52529. {
  52530. }
  52531. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  52532. const BorderSize& /*border*/, ResizableWindow& window)
  52533. {
  52534. g.fillAll (window.getBackgroundColour());
  52535. }
  52536. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  52537. const BorderSize& border, ResizableWindow&)
  52538. {
  52539. g.setColour (Colour (0x80000000));
  52540. g.drawRect (0, 0, w, h);
  52541. g.setColour (Colour (0x19000000));
  52542. g.drawRect (border.getLeft() - 1,
  52543. border.getTop() - 1,
  52544. w + 2 - border.getLeftAndRight(),
  52545. h + 2 - border.getTopAndBottom());
  52546. }
  52547. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  52548. Graphics& g, int w, int h,
  52549. int titleSpaceX, int titleSpaceW,
  52550. const Image* icon,
  52551. bool drawTitleTextOnLeft)
  52552. {
  52553. const bool isActive = window.isActiveWindow();
  52554. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  52555. 0.0f, 0.0f,
  52556. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  52557. 0.0f, (float) h, false));
  52558. g.fillAll();
  52559. Font font (h * 0.65f, Font::bold);
  52560. g.setFont (font);
  52561. int textW = font.getStringWidth (window.getName());
  52562. int iconW = 0;
  52563. int iconH = 0;
  52564. if (icon != 0)
  52565. {
  52566. iconH = (int) font.getHeight();
  52567. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  52568. }
  52569. textW = jmin (titleSpaceW, textW + iconW);
  52570. int textX = drawTitleTextOnLeft ? titleSpaceX
  52571. : jmax (titleSpaceX, (w - textW) / 2);
  52572. if (textX + textW > titleSpaceX + titleSpaceW)
  52573. textX = titleSpaceX + titleSpaceW - textW;
  52574. if (icon != 0)
  52575. {
  52576. g.setOpacity (isActive ? 1.0f : 0.6f);
  52577. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  52578. RectanglePlacement::centred, false);
  52579. textX += iconW;
  52580. textW -= iconW;
  52581. }
  52582. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  52583. g.setColour (findColour (DocumentWindow::textColourId));
  52584. else
  52585. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  52586. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  52587. }
  52588. class GlassWindowButton : public Button
  52589. {
  52590. public:
  52591. GlassWindowButton (const String& name, const Colour& col,
  52592. const Path& normalShape_,
  52593. const Path& toggledShape_) throw()
  52594. : Button (name),
  52595. colour (col),
  52596. normalShape (normalShape_),
  52597. toggledShape (toggledShape_)
  52598. {
  52599. }
  52600. ~GlassWindowButton()
  52601. {
  52602. }
  52603. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  52604. {
  52605. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  52606. if (! isEnabled())
  52607. alpha *= 0.5f;
  52608. float x = 0, y = 0, diam;
  52609. if (getWidth() < getHeight())
  52610. {
  52611. diam = (float) getWidth();
  52612. y = (getHeight() - getWidth()) * 0.5f;
  52613. }
  52614. else
  52615. {
  52616. diam = (float) getHeight();
  52617. y = (getWidth() - getHeight()) * 0.5f;
  52618. }
  52619. x += diam * 0.05f;
  52620. y += diam * 0.05f;
  52621. diam *= 0.9f;
  52622. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  52623. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  52624. g.fillEllipse (x, y, diam, diam);
  52625. x += 2.0f;
  52626. y += 2.0f;
  52627. diam -= 4.0f;
  52628. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  52629. Path& p = getToggleState() ? toggledShape : normalShape;
  52630. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  52631. diam * 0.4f, diam * 0.4f, true));
  52632. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  52633. g.fillPath (p, t);
  52634. }
  52635. juce_UseDebuggingNewOperator
  52636. private:
  52637. Colour colour;
  52638. Path normalShape, toggledShape;
  52639. GlassWindowButton (const GlassWindowButton&);
  52640. GlassWindowButton& operator= (const GlassWindowButton&);
  52641. };
  52642. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  52643. {
  52644. Path shape;
  52645. const float crossThickness = 0.25f;
  52646. if (buttonType == DocumentWindow::closeButton)
  52647. {
  52648. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  52649. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  52650. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  52651. }
  52652. else if (buttonType == DocumentWindow::minimiseButton)
  52653. {
  52654. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52655. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  52656. }
  52657. else if (buttonType == DocumentWindow::maximiseButton)
  52658. {
  52659. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  52660. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52661. Path fullscreenShape;
  52662. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  52663. fullscreenShape.lineTo (0.0f, 100.0f);
  52664. fullscreenShape.lineTo (0.0f, 0.0f);
  52665. fullscreenShape.lineTo (100.0f, 0.0f);
  52666. fullscreenShape.lineTo (100.0f, 45.0f);
  52667. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  52668. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  52669. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  52670. }
  52671. jassertfalse
  52672. return 0;
  52673. }
  52674. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  52675. int titleBarX,
  52676. int titleBarY,
  52677. int titleBarW,
  52678. int titleBarH,
  52679. Button* minimiseButton,
  52680. Button* maximiseButton,
  52681. Button* closeButton,
  52682. bool positionTitleBarButtonsOnLeft)
  52683. {
  52684. const int buttonW = titleBarH - titleBarH / 8;
  52685. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  52686. : titleBarX + titleBarW - buttonW - buttonW / 4;
  52687. if (closeButton != 0)
  52688. {
  52689. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52690. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  52691. }
  52692. if (positionTitleBarButtonsOnLeft)
  52693. swapVariables (minimiseButton, maximiseButton);
  52694. if (maximiseButton != 0)
  52695. {
  52696. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52697. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  52698. }
  52699. if (minimiseButton != 0)
  52700. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52701. }
  52702. int LookAndFeel::getDefaultMenuBarHeight()
  52703. {
  52704. return 24;
  52705. }
  52706. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  52707. {
  52708. return new DropShadower (0.4f, 1, 5, 10);
  52709. }
  52710. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  52711. int w, int h,
  52712. bool /*isVerticalBar*/,
  52713. bool isMouseOver,
  52714. bool isMouseDragging)
  52715. {
  52716. float alpha = 0.5f;
  52717. if (isMouseOver || isMouseDragging)
  52718. {
  52719. g.fillAll (Colour (0x190000ff));
  52720. alpha = 1.0f;
  52721. }
  52722. const float cx = w * 0.5f;
  52723. const float cy = h * 0.5f;
  52724. const float cr = jmin (w, h) * 0.4f;
  52725. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  52726. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  52727. true));
  52728. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  52729. }
  52730. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  52731. const String& text,
  52732. const Justification& position,
  52733. GroupComponent& group)
  52734. {
  52735. const float textH = 15.0f;
  52736. const float indent = 3.0f;
  52737. const float textEdgeGap = 4.0f;
  52738. float cs = 5.0f;
  52739. Font f (textH);
  52740. Path p;
  52741. float x = indent;
  52742. float y = f.getAscent() - 3.0f;
  52743. float w = jmax (0.0f, width - x * 2.0f);
  52744. float h = jmax (0.0f, height - y - indent);
  52745. cs = jmin (cs, w * 0.5f, h * 0.5f);
  52746. const float cs2 = 2.0f * cs;
  52747. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  52748. float textX = cs + textEdgeGap;
  52749. if (position.testFlags (Justification::horizontallyCentred))
  52750. textX = cs + (w - cs2 - textW) * 0.5f;
  52751. else if (position.testFlags (Justification::right))
  52752. textX = w - cs - textW - textEdgeGap;
  52753. p.startNewSubPath (x + textX + textW, y);
  52754. p.lineTo (x + w - cs, y);
  52755. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  52756. p.lineTo (x + w, y + h - cs);
  52757. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  52758. p.lineTo (x + cs, y + h);
  52759. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  52760. p.lineTo (x, y + cs);
  52761. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  52762. p.lineTo (x + textX, y);
  52763. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  52764. g.setColour (group.findColour (GroupComponent::outlineColourId)
  52765. .withMultipliedAlpha (alpha));
  52766. g.strokePath (p, PathStrokeType (2.0f));
  52767. g.setColour (group.findColour (GroupComponent::textColourId)
  52768. .withMultipliedAlpha (alpha));
  52769. g.setFont (f);
  52770. g.drawText (text,
  52771. roundToInt (x + textX), 0,
  52772. roundToInt (textW),
  52773. roundToInt (textH),
  52774. Justification::centred, true);
  52775. }
  52776. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  52777. {
  52778. return 1 + tabDepth / 3;
  52779. }
  52780. int LookAndFeel::getTabButtonSpaceAroundImage()
  52781. {
  52782. return 4;
  52783. }
  52784. void LookAndFeel::createTabButtonShape (Path& p,
  52785. int width, int height,
  52786. int /*tabIndex*/,
  52787. const String& /*text*/,
  52788. Button& /*button*/,
  52789. TabbedButtonBar::Orientation orientation,
  52790. const bool /*isMouseOver*/,
  52791. const bool /*isMouseDown*/,
  52792. const bool /*isFrontTab*/)
  52793. {
  52794. const float w = (float) width;
  52795. const float h = (float) height;
  52796. float length = w;
  52797. float depth = h;
  52798. if (orientation == TabbedButtonBar::TabsAtLeft
  52799. || orientation == TabbedButtonBar::TabsAtRight)
  52800. {
  52801. swapVariables (length, depth);
  52802. }
  52803. const float indent = (float) getTabButtonOverlap ((int) depth);
  52804. const float overhang = 4.0f;
  52805. if (orientation == TabbedButtonBar::TabsAtLeft)
  52806. {
  52807. p.startNewSubPath (w, 0.0f);
  52808. p.lineTo (0.0f, indent);
  52809. p.lineTo (0.0f, h - indent);
  52810. p.lineTo (w, h);
  52811. p.lineTo (w + overhang, h + overhang);
  52812. p.lineTo (w + overhang, -overhang);
  52813. }
  52814. else if (orientation == TabbedButtonBar::TabsAtRight)
  52815. {
  52816. p.startNewSubPath (0.0f, 0.0f);
  52817. p.lineTo (w, indent);
  52818. p.lineTo (w, h - indent);
  52819. p.lineTo (0.0f, h);
  52820. p.lineTo (-overhang, h + overhang);
  52821. p.lineTo (-overhang, -overhang);
  52822. }
  52823. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52824. {
  52825. p.startNewSubPath (0.0f, 0.0f);
  52826. p.lineTo (indent, h);
  52827. p.lineTo (w - indent, h);
  52828. p.lineTo (w, 0.0f);
  52829. p.lineTo (w + overhang, -overhang);
  52830. p.lineTo (-overhang, -overhang);
  52831. }
  52832. else
  52833. {
  52834. p.startNewSubPath (0.0f, h);
  52835. p.lineTo (indent, 0.0f);
  52836. p.lineTo (w - indent, 0.0f);
  52837. p.lineTo (w, h);
  52838. p.lineTo (w + overhang, h + overhang);
  52839. p.lineTo (-overhang, h + overhang);
  52840. }
  52841. p.closeSubPath();
  52842. p = p.createPathWithRoundedCorners (3.0f);
  52843. }
  52844. void LookAndFeel::fillTabButtonShape (Graphics& g,
  52845. const Path& path,
  52846. const Colour& preferredColour,
  52847. int /*tabIndex*/,
  52848. const String& /*text*/,
  52849. Button& button,
  52850. TabbedButtonBar::Orientation /*orientation*/,
  52851. const bool /*isMouseOver*/,
  52852. const bool /*isMouseDown*/,
  52853. const bool isFrontTab)
  52854. {
  52855. g.setColour (isFrontTab ? preferredColour
  52856. : preferredColour.withMultipliedAlpha (0.9f));
  52857. g.fillPath (path);
  52858. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  52859. : TabbedButtonBar::tabOutlineColourId, false)
  52860. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  52861. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  52862. }
  52863. void LookAndFeel::drawTabButtonText (Graphics& g,
  52864. int x, int y, int w, int h,
  52865. const Colour& preferredBackgroundColour,
  52866. int /*tabIndex*/,
  52867. const String& text,
  52868. Button& button,
  52869. TabbedButtonBar::Orientation orientation,
  52870. const bool isMouseOver,
  52871. const bool isMouseDown,
  52872. const bool isFrontTab)
  52873. {
  52874. int length = w;
  52875. int depth = h;
  52876. if (orientation == TabbedButtonBar::TabsAtLeft
  52877. || orientation == TabbedButtonBar::TabsAtRight)
  52878. {
  52879. swapVariables (length, depth);
  52880. }
  52881. Font font (depth * 0.6f);
  52882. font.setUnderline (button.hasKeyboardFocus (false));
  52883. GlyphArrangement textLayout;
  52884. textLayout.addFittedText (font, text.trim(),
  52885. 0.0f, 0.0f, (float) length, (float) depth,
  52886. Justification::centred,
  52887. jmax (1, depth / 12));
  52888. AffineTransform transform;
  52889. if (orientation == TabbedButtonBar::TabsAtLeft)
  52890. {
  52891. transform = transform.rotated (float_Pi * -0.5f)
  52892. .translated ((float) x, (float) (y + h));
  52893. }
  52894. else if (orientation == TabbedButtonBar::TabsAtRight)
  52895. {
  52896. transform = transform.rotated (float_Pi * 0.5f)
  52897. .translated ((float) (x + w), (float) y);
  52898. }
  52899. else
  52900. {
  52901. transform = transform.translated ((float) x, (float) y);
  52902. }
  52903. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  52904. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  52905. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  52906. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  52907. else
  52908. g.setColour (preferredBackgroundColour.contrasting());
  52909. if (! (isMouseOver || isMouseDown))
  52910. g.setOpacity (0.8f);
  52911. if (! button.isEnabled())
  52912. g.setOpacity (0.3f);
  52913. textLayout.draw (g, transform);
  52914. }
  52915. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  52916. const String& text,
  52917. int tabDepth,
  52918. Button&)
  52919. {
  52920. Font f (tabDepth * 0.6f);
  52921. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  52922. }
  52923. void LookAndFeel::drawTabButton (Graphics& g,
  52924. int w, int h,
  52925. const Colour& preferredColour,
  52926. int tabIndex,
  52927. const String& text,
  52928. Button& button,
  52929. TabbedButtonBar::Orientation orientation,
  52930. const bool isMouseOver,
  52931. const bool isMouseDown,
  52932. const bool isFrontTab)
  52933. {
  52934. int length = w;
  52935. int depth = h;
  52936. if (orientation == TabbedButtonBar::TabsAtLeft
  52937. || orientation == TabbedButtonBar::TabsAtRight)
  52938. {
  52939. swapVariables (length, depth);
  52940. }
  52941. Path tabShape;
  52942. createTabButtonShape (tabShape, w, h,
  52943. tabIndex, text, button, orientation,
  52944. isMouseOver, isMouseDown, isFrontTab);
  52945. fillTabButtonShape (g, tabShape, preferredColour,
  52946. tabIndex, text, button, orientation,
  52947. isMouseOver, isMouseDown, isFrontTab);
  52948. const int indent = getTabButtonOverlap (depth);
  52949. int x = 0, y = 0;
  52950. if (orientation == TabbedButtonBar::TabsAtLeft
  52951. || orientation == TabbedButtonBar::TabsAtRight)
  52952. {
  52953. y += indent;
  52954. h -= indent * 2;
  52955. }
  52956. else
  52957. {
  52958. x += indent;
  52959. w -= indent * 2;
  52960. }
  52961. drawTabButtonText (g, x, y, w, h, preferredColour,
  52962. tabIndex, text, button, orientation,
  52963. isMouseOver, isMouseDown, isFrontTab);
  52964. }
  52965. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  52966. int w, int h,
  52967. TabbedButtonBar& tabBar,
  52968. TabbedButtonBar::Orientation orientation)
  52969. {
  52970. const float shadowSize = 0.2f;
  52971. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  52972. Rectangle<int> shadowRect;
  52973. if (orientation == TabbedButtonBar::TabsAtLeft)
  52974. {
  52975. x1 = (float) w;
  52976. x2 = w * (1.0f - shadowSize);
  52977. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  52978. }
  52979. else if (orientation == TabbedButtonBar::TabsAtRight)
  52980. {
  52981. x2 = w * shadowSize;
  52982. shadowRect.setBounds (0, 0, (int) x2, h);
  52983. }
  52984. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52985. {
  52986. y2 = h * shadowSize;
  52987. shadowRect.setBounds (0, 0, w, (int) y2);
  52988. }
  52989. else
  52990. {
  52991. y1 = (float) h;
  52992. y2 = h * (1.0f - shadowSize);
  52993. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  52994. }
  52995. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  52996. Colours::transparentBlack, x2, y2, false));
  52997. shadowRect.expand (2, 2);
  52998. g.fillRect (shadowRect);
  52999. g.setColour (Colour (0x80000000));
  53000. if (orientation == TabbedButtonBar::TabsAtLeft)
  53001. {
  53002. g.fillRect (w - 1, 0, 1, h);
  53003. }
  53004. else if (orientation == TabbedButtonBar::TabsAtRight)
  53005. {
  53006. g.fillRect (0, 0, 1, h);
  53007. }
  53008. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53009. {
  53010. g.fillRect (0, 0, w, 1);
  53011. }
  53012. else
  53013. {
  53014. g.fillRect (0, h - 1, w, 1);
  53015. }
  53016. }
  53017. Button* LookAndFeel::createTabBarExtrasButton()
  53018. {
  53019. const float thickness = 7.0f;
  53020. const float indent = 22.0f;
  53021. Path p;
  53022. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  53023. DrawablePath ellipse;
  53024. ellipse.setPath (p);
  53025. ellipse.setFill (Colour (0x99ffffff));
  53026. p.clear();
  53027. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53028. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53029. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53030. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53031. p.setUsingNonZeroWinding (false);
  53032. DrawablePath dp;
  53033. dp.setPath (p);
  53034. dp.setFill (Colour (0x59000000));
  53035. DrawableComposite normalImage;
  53036. normalImage.insertDrawable (ellipse);
  53037. normalImage.insertDrawable (dp);
  53038. dp.setFill (Colour (0xcc000000));
  53039. DrawableComposite overImage;
  53040. overImage.insertDrawable (ellipse);
  53041. overImage.insertDrawable (dp);
  53042. DrawableButton* db = new DrawableButton (T("tabs"), DrawableButton::ImageFitted);
  53043. db->setImages (&normalImage, &overImage, 0);
  53044. return db;
  53045. }
  53046. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  53047. {
  53048. g.fillAll (Colours::white);
  53049. const int w = header.getWidth();
  53050. const int h = header.getHeight();
  53051. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  53052. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  53053. false));
  53054. g.fillRect (0, h / 2, w, h);
  53055. g.setColour (Colour (0x33000000));
  53056. g.fillRect (0, h - 1, w, 1);
  53057. for (int i = header.getNumColumns (true); --i >= 0;)
  53058. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  53059. }
  53060. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  53061. int width, int height,
  53062. bool isMouseOver, bool isMouseDown,
  53063. int columnFlags)
  53064. {
  53065. if (isMouseDown)
  53066. g.fillAll (Colour (0x8899aadd));
  53067. else if (isMouseOver)
  53068. g.fillAll (Colour (0x5599aadd));
  53069. int rightOfText = width - 4;
  53070. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  53071. {
  53072. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  53073. const float bottom = height - top;
  53074. const float w = height * 0.5f;
  53075. const float x = rightOfText - (w * 1.25f);
  53076. rightOfText = (int) x;
  53077. Path sortArrow;
  53078. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  53079. g.setColour (Colour (0x99000000));
  53080. g.fillPath (sortArrow);
  53081. }
  53082. g.setColour (Colours::black);
  53083. g.setFont (height * 0.5f, Font::bold);
  53084. const int textX = 4;
  53085. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  53086. }
  53087. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  53088. {
  53089. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  53090. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  53091. background.darker (0.1f),
  53092. toolbar.isVertical() ? w - 1.0f : 0.0f,
  53093. toolbar.isVertical() ? 0.0f : h - 1.0f,
  53094. false));
  53095. g.fillAll();
  53096. }
  53097. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  53098. {
  53099. return createTabBarExtrasButton();
  53100. }
  53101. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  53102. bool isMouseOver, bool isMouseDown,
  53103. ToolbarItemComponent& component)
  53104. {
  53105. if (isMouseDown)
  53106. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  53107. else if (isMouseOver)
  53108. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  53109. }
  53110. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  53111. const String& text, ToolbarItemComponent& component)
  53112. {
  53113. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  53114. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  53115. const float fontHeight = jmin (14.0f, height * 0.85f);
  53116. g.setFont (fontHeight);
  53117. g.drawFittedText (text,
  53118. x, y, width, height,
  53119. Justification::centred,
  53120. jmax (1, height / (int) fontHeight));
  53121. }
  53122. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  53123. bool isOpen, int width, int height)
  53124. {
  53125. const int buttonSize = (height * 3) / 4;
  53126. const int buttonIndent = (height - buttonSize) / 2;
  53127. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  53128. const int textX = buttonIndent * 2 + buttonSize + 2;
  53129. g.setColour (Colours::black);
  53130. g.setFont (height * 0.7f, Font::bold);
  53131. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  53132. }
  53133. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  53134. PropertyComponent&)
  53135. {
  53136. g.setColour (Colour (0x66ffffff));
  53137. g.fillRect (0, 0, width, height - 1);
  53138. }
  53139. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  53140. PropertyComponent& component)
  53141. {
  53142. g.setColour (Colours::black);
  53143. if (! component.isEnabled())
  53144. g.setOpacity (0.6f);
  53145. g.setFont (jmin (height, 24) * 0.65f);
  53146. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  53147. g.drawFittedText (component.getName(),
  53148. 3, r.getY(), r.getX() - 5, r.getHeight(),
  53149. Justification::centredLeft, 2);
  53150. }
  53151. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  53152. {
  53153. return Rectangle<int> (component.getWidth() / 3, 1,
  53154. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  53155. }
  53156. void LookAndFeel::createFileChooserHeaderText (const String& title,
  53157. const String& instructions,
  53158. GlyphArrangement& text,
  53159. int width)
  53160. {
  53161. text.clear();
  53162. text.addJustifiedText (Font (17.0f, Font::bold), title,
  53163. 8.0f, 22.0f, width - 16.0f,
  53164. Justification::centred);
  53165. text.addJustifiedText (Font (14.0f), instructions,
  53166. 8.0f, 24.0f + 16.0f, width - 16.0f,
  53167. Justification::centred);
  53168. }
  53169. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  53170. const String& filename, Image* icon,
  53171. const String& fileSizeDescription,
  53172. const String& fileTimeDescription,
  53173. const bool isDirectory,
  53174. const bool isItemSelected,
  53175. const int /*itemIndex*/)
  53176. {
  53177. if (isItemSelected)
  53178. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  53179. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  53180. g.setFont (height * 0.7f);
  53181. Image* im = icon;
  53182. Image* toRelease = 0;
  53183. if (im == 0)
  53184. {
  53185. toRelease = im = (isDirectory ? getDefaultFolderImage()
  53186. : getDefaultDocumentFileImage());
  53187. }
  53188. const int x = 32;
  53189. if (im != 0)
  53190. {
  53191. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  53192. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  53193. false);
  53194. ImageCache::release (toRelease);
  53195. }
  53196. if (width > 450 && ! isDirectory)
  53197. {
  53198. const int sizeX = roundToInt (width * 0.7f);
  53199. const int dateX = roundToInt (width * 0.8f);
  53200. g.drawFittedText (filename,
  53201. x, 0, sizeX - x, height,
  53202. Justification::centredLeft, 1);
  53203. g.setFont (height * 0.5f);
  53204. g.setColour (Colours::darkgrey);
  53205. if (! isDirectory)
  53206. {
  53207. g.drawFittedText (fileSizeDescription,
  53208. sizeX, 0, dateX - sizeX - 8, height,
  53209. Justification::centredRight, 1);
  53210. g.drawFittedText (fileTimeDescription,
  53211. dateX, 0, width - 8 - dateX, height,
  53212. Justification::centredRight, 1);
  53213. }
  53214. }
  53215. else
  53216. {
  53217. g.drawFittedText (filename,
  53218. x, 0, width - x, height,
  53219. Justification::centredLeft, 1);
  53220. }
  53221. }
  53222. Button* LookAndFeel::createFileBrowserGoUpButton()
  53223. {
  53224. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  53225. Path arrowPath;
  53226. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  53227. DrawablePath arrowImage;
  53228. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  53229. arrowImage.setPath (arrowPath);
  53230. goUpButton->setImages (&arrowImage);
  53231. return goUpButton;
  53232. }
  53233. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  53234. DirectoryContentsDisplayComponent* fileListComponent,
  53235. FilePreviewComponent* previewComp,
  53236. ComboBox* currentPathBox,
  53237. TextEditor* filenameBox,
  53238. Button* goUpButton)
  53239. {
  53240. const int x = 8;
  53241. int w = browserComp.getWidth() - x - x;
  53242. if (previewComp != 0)
  53243. {
  53244. const int previewWidth = w / 3;
  53245. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  53246. w -= previewWidth + 4;
  53247. }
  53248. int y = 4;
  53249. const int controlsHeight = 22;
  53250. const int bottomSectionHeight = controlsHeight + 8;
  53251. const int upButtonWidth = 50;
  53252. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53253. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53254. y += controlsHeight + 4;
  53255. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53256. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53257. y = listAsComp->getBottom() + 4;
  53258. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53259. }
  53260. Image* LookAndFeel::getDefaultFolderImage()
  53261. {
  53262. 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,
  53263. 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,
  53264. 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,
  53265. 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,
  53266. 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,
  53267. 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,
  53268. 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,
  53269. 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,
  53270. 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,
  53271. 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,
  53272. 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,
  53273. 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,
  53274. 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,
  53275. 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,
  53276. 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,
  53277. 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,
  53278. 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,
  53279. 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,
  53280. 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,
  53281. 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,
  53282. 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,
  53283. 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,
  53284. 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,
  53285. 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,
  53286. 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,
  53287. 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,
  53288. 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,
  53289. 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,
  53290. 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,
  53291. 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,
  53292. 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,
  53293. 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,
  53294. 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,
  53295. 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,
  53296. 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,
  53297. 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,
  53298. 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,
  53299. 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,
  53300. 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,
  53301. 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,
  53302. 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,
  53303. 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,
  53304. 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,
  53305. 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};
  53306. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53307. }
  53308. Image* LookAndFeel::getDefaultDocumentFileImage()
  53309. {
  53310. 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,
  53311. 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,
  53312. 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,
  53313. 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,
  53314. 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,
  53315. 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,
  53316. 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,
  53317. 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,
  53318. 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,
  53319. 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,
  53320. 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,
  53321. 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,
  53322. 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,
  53323. 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,
  53324. 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,
  53325. 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,
  53326. 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,
  53327. 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,
  53328. 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,
  53329. 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,
  53330. 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,
  53331. 174,66,96,130,0,0};
  53332. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53333. }
  53334. void LookAndFeel::playAlertSound()
  53335. {
  53336. PlatformUtilities::beep();
  53337. }
  53338. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53339. {
  53340. g.setColour (Colours::white.withAlpha (0.7f));
  53341. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53342. g.setColour (Colours::black.withAlpha (0.2f));
  53343. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53344. const int totalBlocks = 7;
  53345. const int numBlocks = roundToInt (totalBlocks * level);
  53346. const float w = (width - 6.0f) / (float) totalBlocks;
  53347. for (int i = 0; i < totalBlocks; ++i)
  53348. {
  53349. if (i >= numBlocks)
  53350. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53351. else
  53352. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53353. : Colours::red);
  53354. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53355. }
  53356. }
  53357. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53358. {
  53359. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53360. if (keyDescription.isNotEmpty())
  53361. {
  53362. if (button.isEnabled())
  53363. {
  53364. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53365. g.fillAll (textColour.withAlpha (alpha));
  53366. g.setOpacity (0.3f);
  53367. g.drawBevel (0, 0, width, height, 2);
  53368. }
  53369. g.setColour (textColour);
  53370. g.setFont (height * 0.6f);
  53371. g.drawFittedText (keyDescription,
  53372. 3, 0, width - 6, height,
  53373. Justification::centred, 1);
  53374. }
  53375. else
  53376. {
  53377. const float thickness = 7.0f;
  53378. const float indent = 22.0f;
  53379. Path p;
  53380. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53381. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53382. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53383. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53384. p.setUsingNonZeroWinding (false);
  53385. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53386. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53387. }
  53388. if (button.hasKeyboardFocus (false))
  53389. {
  53390. g.setColour (textColour.withAlpha (0.4f));
  53391. g.drawRect (0, 0, width, height);
  53392. }
  53393. }
  53394. static void createRoundedPath (Path& p,
  53395. const float x, const float y,
  53396. const float w, const float h,
  53397. const float cs,
  53398. const bool curveTopLeft, const bool curveTopRight,
  53399. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53400. {
  53401. const float cs2 = 2.0f * cs;
  53402. if (curveTopLeft)
  53403. {
  53404. p.startNewSubPath (x, y + cs);
  53405. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53406. }
  53407. else
  53408. {
  53409. p.startNewSubPath (x, y);
  53410. }
  53411. if (curveTopRight)
  53412. {
  53413. p.lineTo (x + w - cs, y);
  53414. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53415. }
  53416. else
  53417. {
  53418. p.lineTo (x + w, y);
  53419. }
  53420. if (curveBottomRight)
  53421. {
  53422. p.lineTo (x + w, y + h - cs);
  53423. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53424. }
  53425. else
  53426. {
  53427. p.lineTo (x + w, y + h);
  53428. }
  53429. if (curveBottomLeft)
  53430. {
  53431. p.lineTo (x + cs, y + h);
  53432. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53433. }
  53434. else
  53435. {
  53436. p.lineTo (x, y + h);
  53437. }
  53438. p.closeSubPath();
  53439. }
  53440. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53441. float x, float y, float w, float h,
  53442. float maxCornerSize,
  53443. const Colour& baseColour,
  53444. const float strokeWidth,
  53445. const bool flatOnLeft,
  53446. const bool flatOnRight,
  53447. const bool flatOnTop,
  53448. const bool flatOnBottom) throw()
  53449. {
  53450. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53451. return;
  53452. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53453. Path outline;
  53454. createRoundedPath (outline, x, y, w, h, cs,
  53455. ! (flatOnLeft || flatOnTop),
  53456. ! (flatOnRight || flatOnTop),
  53457. ! (flatOnLeft || flatOnBottom),
  53458. ! (flatOnRight || flatOnBottom));
  53459. ColourGradient cg (baseColour, 0.0f, y,
  53460. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53461. false);
  53462. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53463. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53464. g.setGradientFill (cg);
  53465. g.fillPath (outline);
  53466. g.setColour (Colour (0x80000000));
  53467. g.strokePath (outline, PathStrokeType (strokeWidth));
  53468. }
  53469. void LookAndFeel::drawGlassSphere (Graphics& g,
  53470. const float x, const float y,
  53471. const float diameter,
  53472. const Colour& colour,
  53473. const float outlineThickness) throw()
  53474. {
  53475. if (diameter <= outlineThickness)
  53476. return;
  53477. Path p;
  53478. p.addEllipse (x, y, diameter, diameter);
  53479. {
  53480. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53481. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53482. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53483. g.setGradientFill (cg);
  53484. g.fillPath (p);
  53485. }
  53486. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53487. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53488. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53489. ColourGradient cg (Colours::transparentBlack,
  53490. x + diameter * 0.5f, y + diameter * 0.5f,
  53491. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53492. x, y + diameter * 0.5f, true);
  53493. cg.addColour (0.7, Colours::transparentBlack);
  53494. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53495. g.setGradientFill (cg);
  53496. g.fillPath (p);
  53497. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53498. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53499. }
  53500. void LookAndFeel::drawGlassPointer (Graphics& g,
  53501. const float x, const float y,
  53502. const float diameter,
  53503. const Colour& colour, const float outlineThickness,
  53504. const int direction) throw()
  53505. {
  53506. if (diameter <= outlineThickness)
  53507. return;
  53508. Path p;
  53509. p.startNewSubPath (x + diameter * 0.5f, y);
  53510. p.lineTo (x + diameter, y + diameter * 0.6f);
  53511. p.lineTo (x + diameter, y + diameter);
  53512. p.lineTo (x, y + diameter);
  53513. p.lineTo (x, y + diameter * 0.6f);
  53514. p.closeSubPath();
  53515. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  53516. {
  53517. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53518. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53519. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53520. g.setGradientFill (cg);
  53521. g.fillPath (p);
  53522. }
  53523. ColourGradient cg (Colours::transparentBlack,
  53524. x + diameter * 0.5f, y + diameter * 0.5f,
  53525. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53526. x - diameter * 0.2f, y + diameter * 0.5f, true);
  53527. cg.addColour (0.5, Colours::transparentBlack);
  53528. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  53529. g.setGradientFill (cg);
  53530. g.fillPath (p);
  53531. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53532. g.strokePath (p, PathStrokeType (outlineThickness));
  53533. }
  53534. void LookAndFeel::drawGlassLozenge (Graphics& g,
  53535. const float x, const float y,
  53536. const float width, const float height,
  53537. const Colour& colour,
  53538. const float outlineThickness,
  53539. const float cornerSize,
  53540. const bool flatOnLeft,
  53541. const bool flatOnRight,
  53542. const bool flatOnTop,
  53543. const bool flatOnBottom) throw()
  53544. {
  53545. if (width <= outlineThickness || height <= outlineThickness)
  53546. return;
  53547. const int intX = (int) x;
  53548. const int intY = (int) y;
  53549. const int intW = (int) width;
  53550. const int intH = (int) height;
  53551. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  53552. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  53553. const int intEdge = (int) edgeBlurRadius;
  53554. Path outline;
  53555. createRoundedPath (outline, x, y, width, height, cs,
  53556. ! (flatOnLeft || flatOnTop),
  53557. ! (flatOnRight || flatOnTop),
  53558. ! (flatOnLeft || flatOnBottom),
  53559. ! (flatOnRight || flatOnBottom));
  53560. {
  53561. ColourGradient cg (colour.darker (0.2f), 0, y,
  53562. colour.darker (0.2f), 0, y + height, false);
  53563. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  53564. cg.addColour (0.4, colour);
  53565. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  53566. g.setGradientFill (cg);
  53567. g.fillPath (outline);
  53568. }
  53569. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  53570. colour.darker (0.2f), x, y + height * 0.5f, true);
  53571. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  53572. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  53573. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  53574. {
  53575. g.saveState();
  53576. g.setGradientFill (cg);
  53577. g.reduceClipRegion (intX, intY, intEdge, intH);
  53578. g.fillPath (outline);
  53579. g.restoreState();
  53580. }
  53581. if (! (flatOnRight || flatOnTop || flatOnBottom))
  53582. {
  53583. cg.x1 = x + width - edgeBlurRadius;
  53584. cg.x2 = x + width;
  53585. g.saveState();
  53586. g.setGradientFill (cg);
  53587. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  53588. g.fillPath (outline);
  53589. g.restoreState();
  53590. }
  53591. {
  53592. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  53593. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  53594. Path highlight;
  53595. createRoundedPath (highlight,
  53596. x + leftIndent,
  53597. y + cs * 0.1f,
  53598. width - (leftIndent + rightIndent),
  53599. height * 0.4f, cs * 0.4f,
  53600. ! (flatOnLeft || flatOnTop),
  53601. ! (flatOnRight || flatOnTop),
  53602. ! (flatOnLeft || flatOnBottom),
  53603. ! (flatOnRight || flatOnBottom));
  53604. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  53605. Colours::transparentWhite, 0, y + height * 0.4f, false));
  53606. g.fillPath (highlight);
  53607. }
  53608. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  53609. g.strokePath (outline, PathStrokeType (outlineThickness));
  53610. }
  53611. END_JUCE_NAMESPACE
  53612. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  53613. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53614. BEGIN_JUCE_NAMESPACE
  53615. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  53616. {
  53617. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  53618. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  53619. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  53620. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  53621. setColour (Slider::thumbColourId, Colours::white);
  53622. setColour (Slider::trackColourId, Colour (0x7f000000));
  53623. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  53624. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  53625. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  53626. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  53627. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  53628. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  53629. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  53630. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  53631. }
  53632. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  53633. {
  53634. }
  53635. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  53636. Button& button,
  53637. const Colour& backgroundColour,
  53638. bool isMouseOverButton,
  53639. bool isButtonDown)
  53640. {
  53641. const int width = button.getWidth();
  53642. const int height = button.getHeight();
  53643. const float indent = 2.0f;
  53644. const int cornerSize = jmin (roundToInt (width * 0.4f),
  53645. roundToInt (height * 0.4f));
  53646. Path p;
  53647. p.addRoundedRectangle (indent, indent,
  53648. width - indent * 2.0f,
  53649. height - indent * 2.0f,
  53650. (float) cornerSize);
  53651. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  53652. if (isMouseOverButton)
  53653. {
  53654. if (isButtonDown)
  53655. bc = bc.brighter();
  53656. else if (bc.getBrightness() > 0.5f)
  53657. bc = bc.darker (0.1f);
  53658. else
  53659. bc = bc.brighter (0.1f);
  53660. }
  53661. g.setColour (bc);
  53662. g.fillPath (p);
  53663. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  53664. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  53665. }
  53666. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  53667. Component& /*component*/,
  53668. float x, float y, float w, float h,
  53669. const bool ticked,
  53670. const bool isEnabled,
  53671. const bool /*isMouseOverButton*/,
  53672. const bool isButtonDown)
  53673. {
  53674. Path box;
  53675. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  53676. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  53677. : Colours::lightgrey.withAlpha (0.1f));
  53678. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f).translated (x, y));
  53679. g.fillPath (box, trans);
  53680. g.setColour (Colours::black.withAlpha (0.6f));
  53681. g.strokePath (box, PathStrokeType (0.9f), trans);
  53682. if (ticked)
  53683. {
  53684. Path tick;
  53685. tick.startNewSubPath (1.5f, 3.0f);
  53686. tick.lineTo (3.0f, 6.0f);
  53687. tick.lineTo (6.0f, 0.0f);
  53688. g.setColour (isEnabled ? Colours::black : Colours::grey);
  53689. g.strokePath (tick, PathStrokeType (2.5f), trans);
  53690. }
  53691. }
  53692. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  53693. ToggleButton& button,
  53694. bool isMouseOverButton,
  53695. bool isButtonDown)
  53696. {
  53697. if (button.hasKeyboardFocus (true))
  53698. {
  53699. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  53700. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  53701. }
  53702. const int tickWidth = jmin (20, button.getHeight() - 4);
  53703. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  53704. (float) tickWidth, (float) tickWidth,
  53705. button.getToggleState(),
  53706. button.isEnabled(),
  53707. isMouseOverButton,
  53708. isButtonDown);
  53709. g.setColour (button.findColour (ToggleButton::textColourId));
  53710. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  53711. if (! button.isEnabled())
  53712. g.setOpacity (0.5f);
  53713. const int textX = tickWidth + 5;
  53714. g.drawFittedText (button.getButtonText(),
  53715. textX, 4,
  53716. button.getWidth() - textX - 2, button.getHeight() - 8,
  53717. Justification::centredLeft, 10);
  53718. }
  53719. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  53720. int width, int height,
  53721. double progress, const String& textToShow)
  53722. {
  53723. if (progress < 0 || progress >= 1.0)
  53724. {
  53725. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  53726. }
  53727. else
  53728. {
  53729. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  53730. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  53731. g.fillAll (background);
  53732. g.setColour (foreground);
  53733. g.fillRect (1, 1,
  53734. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  53735. height - 2);
  53736. if (textToShow.isNotEmpty())
  53737. {
  53738. g.setColour (Colour::contrasting (background, foreground));
  53739. g.setFont (height * 0.6f);
  53740. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  53741. }
  53742. }
  53743. }
  53744. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  53745. ScrollBar& bar,
  53746. int width, int height,
  53747. int buttonDirection,
  53748. bool isScrollbarVertical,
  53749. bool isMouseOverButton,
  53750. bool isButtonDown)
  53751. {
  53752. if (isScrollbarVertical)
  53753. width -= 2;
  53754. else
  53755. height -= 2;
  53756. Path p;
  53757. if (buttonDirection == 0)
  53758. p.addTriangle (width * 0.5f, height * 0.2f,
  53759. width * 0.1f, height * 0.7f,
  53760. width * 0.9f, height * 0.7f);
  53761. else if (buttonDirection == 1)
  53762. p.addTriangle (width * 0.8f, height * 0.5f,
  53763. width * 0.3f, height * 0.1f,
  53764. width * 0.3f, height * 0.9f);
  53765. else if (buttonDirection == 2)
  53766. p.addTriangle (width * 0.5f, height * 0.8f,
  53767. width * 0.1f, height * 0.3f,
  53768. width * 0.9f, height * 0.3f);
  53769. else if (buttonDirection == 3)
  53770. p.addTriangle (width * 0.2f, height * 0.5f,
  53771. width * 0.7f, height * 0.1f,
  53772. width * 0.7f, height * 0.9f);
  53773. if (isButtonDown)
  53774. g.setColour (Colours::white);
  53775. else if (isMouseOverButton)
  53776. g.setColour (Colours::white.withAlpha (0.7f));
  53777. else
  53778. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  53779. g.fillPath (p);
  53780. g.setColour (Colours::black.withAlpha (0.5f));
  53781. g.strokePath (p, PathStrokeType (0.5f));
  53782. }
  53783. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  53784. ScrollBar& bar,
  53785. int x, int y,
  53786. int width, int height,
  53787. bool isScrollbarVertical,
  53788. int thumbStartPosition,
  53789. int thumbSize,
  53790. bool isMouseOver,
  53791. bool isMouseDown)
  53792. {
  53793. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  53794. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53795. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  53796. if (thumbSize > 0.0f)
  53797. {
  53798. Rectangle<int> thumb;
  53799. if (isScrollbarVertical)
  53800. {
  53801. width -= 2;
  53802. g.fillRect (x + roundToInt (width * 0.35f), y,
  53803. roundToInt (width * 0.3f), height);
  53804. thumb.setBounds (x + 1, thumbStartPosition,
  53805. width - 2, thumbSize);
  53806. }
  53807. else
  53808. {
  53809. height -= 2;
  53810. g.fillRect (x, y + roundToInt (height * 0.35f),
  53811. width, roundToInt (height * 0.3f));
  53812. thumb.setBounds (thumbStartPosition, y + 1,
  53813. thumbSize, height - 2);
  53814. }
  53815. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53816. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  53817. g.fillRect (thumb);
  53818. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  53819. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  53820. if (thumbSize > 16)
  53821. {
  53822. for (int i = 3; --i >= 0;)
  53823. {
  53824. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  53825. g.setColour (Colours::black.withAlpha (0.15f));
  53826. if (isScrollbarVertical)
  53827. {
  53828. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  53829. g.setColour (Colours::white.withAlpha (0.15f));
  53830. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  53831. }
  53832. else
  53833. {
  53834. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  53835. g.setColour (Colours::white.withAlpha (0.15f));
  53836. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  53837. }
  53838. }
  53839. }
  53840. }
  53841. }
  53842. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  53843. {
  53844. return &scrollbarShadow;
  53845. }
  53846. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  53847. {
  53848. g.fillAll (findColour (PopupMenu::backgroundColourId));
  53849. g.setColour (Colours::black.withAlpha (0.6f));
  53850. g.drawRect (0, 0, width, height);
  53851. }
  53852. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  53853. bool, MenuBarComponent& menuBar)
  53854. {
  53855. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  53856. }
  53857. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  53858. {
  53859. if (textEditor.isEnabled())
  53860. {
  53861. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  53862. g.drawRect (0, 0, width, height);
  53863. }
  53864. }
  53865. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  53866. const bool isButtonDown,
  53867. int buttonX, int buttonY,
  53868. int buttonW, int buttonH,
  53869. ComboBox& box)
  53870. {
  53871. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  53872. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  53873. : ComboBox::backgroundColourId));
  53874. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  53875. g.setColour (box.findColour (ComboBox::outlineColourId));
  53876. g.drawRect (0, 0, width, height);
  53877. const float arrowX = 0.2f;
  53878. const float arrowH = 0.3f;
  53879. if (box.isEnabled())
  53880. {
  53881. Path p;
  53882. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  53883. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  53884. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  53885. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  53886. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  53887. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  53888. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  53889. : ComboBox::buttonColourId));
  53890. g.fillPath (p);
  53891. }
  53892. }
  53893. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  53894. {
  53895. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  53896. f.setHorizontalScale (0.9f);
  53897. return f;
  53898. }
  53899. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  53900. {
  53901. Path p;
  53902. p.addTriangle (x1, y1, x2, y2, x3, y3);
  53903. g.setColour (fill);
  53904. g.fillPath (p);
  53905. g.setColour (outline);
  53906. g.strokePath (p, PathStrokeType (0.3f));
  53907. }
  53908. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  53909. int x, int y,
  53910. int w, int h,
  53911. float sliderPos,
  53912. float minSliderPos,
  53913. float maxSliderPos,
  53914. const Slider::SliderStyle style,
  53915. Slider& slider)
  53916. {
  53917. g.fillAll (slider.findColour (Slider::backgroundColourId));
  53918. if (style == Slider::LinearBar)
  53919. {
  53920. g.setColour (slider.findColour (Slider::thumbColourId));
  53921. g.fillRect (x, y, (int) sliderPos - x, h);
  53922. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  53923. g.drawRect (x, y, (int) sliderPos - x, h);
  53924. }
  53925. else
  53926. {
  53927. g.setColour (slider.findColour (Slider::trackColourId)
  53928. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  53929. if (slider.isHorizontal())
  53930. {
  53931. g.fillRect (x, y + roundToInt (h * 0.6f),
  53932. w, roundToInt (h * 0.2f));
  53933. }
  53934. else
  53935. {
  53936. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  53937. jmin (4, roundToInt (w * 0.2f)), h);
  53938. }
  53939. float alpha = 0.35f;
  53940. if (slider.isEnabled())
  53941. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  53942. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  53943. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  53944. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  53945. {
  53946. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  53947. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  53948. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  53949. fill, outline);
  53950. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  53951. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  53952. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  53953. fill, outline);
  53954. }
  53955. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  53956. {
  53957. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53958. minSliderPos - 7.0f, y + h * 0.9f ,
  53959. minSliderPos, y + h * 0.9f,
  53960. fill, outline);
  53961. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53962. maxSliderPos, y + h * 0.9f,
  53963. maxSliderPos + 7.0f, y + h * 0.9f,
  53964. fill, outline);
  53965. }
  53966. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  53967. {
  53968. drawTriangle (g, sliderPos, y + h * 0.9f,
  53969. sliderPos - 7.0f, y + h * 0.2f,
  53970. sliderPos + 7.0f, y + h * 0.2f,
  53971. fill, outline);
  53972. }
  53973. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  53974. {
  53975. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  53976. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  53977. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  53978. fill, outline);
  53979. }
  53980. }
  53981. }
  53982. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  53983. {
  53984. if (isIncrement)
  53985. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  53986. else
  53987. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  53988. }
  53989. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  53990. {
  53991. return &scrollbarShadow;
  53992. }
  53993. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  53994. {
  53995. return 8;
  53996. }
  53997. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  53998. int w, int h,
  53999. bool isMouseOver,
  54000. bool isMouseDragging)
  54001. {
  54002. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  54003. : Colours::darkgrey);
  54004. const float lineThickness = jmin (w, h) * 0.1f;
  54005. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  54006. {
  54007. g.drawLine (w * i,
  54008. h + 1.0f,
  54009. w + 1.0f,
  54010. h * i,
  54011. lineThickness);
  54012. }
  54013. }
  54014. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  54015. {
  54016. Path shape;
  54017. if (buttonType == DocumentWindow::closeButton)
  54018. {
  54019. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  54020. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  54021. ShapeButton* const b = new ShapeButton ("close",
  54022. Colour (0x7fff3333),
  54023. Colour (0xd7ff3333),
  54024. Colour (0xf7ff3333));
  54025. b->setShape (shape, true, true, true);
  54026. return b;
  54027. }
  54028. else if (buttonType == DocumentWindow::minimiseButton)
  54029. {
  54030. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54031. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  54032. DrawablePath dp;
  54033. dp.setPath (shape);
  54034. dp.setFill (Colours::black.withAlpha (0.3f));
  54035. b->setImages (&dp);
  54036. return b;
  54037. }
  54038. else if (buttonType == DocumentWindow::maximiseButton)
  54039. {
  54040. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  54041. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54042. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  54043. DrawablePath dp;
  54044. dp.setPath (shape);
  54045. dp.setFill (Colours::black.withAlpha (0.3f));
  54046. b->setImages (&dp);
  54047. return b;
  54048. }
  54049. jassertfalse
  54050. return 0;
  54051. }
  54052. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  54053. int titleBarX,
  54054. int titleBarY,
  54055. int titleBarW,
  54056. int titleBarH,
  54057. Button* minimiseButton,
  54058. Button* maximiseButton,
  54059. Button* closeButton,
  54060. bool positionTitleBarButtonsOnLeft)
  54061. {
  54062. titleBarY += titleBarH / 8;
  54063. titleBarH -= titleBarH / 4;
  54064. const int buttonW = titleBarH;
  54065. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  54066. : titleBarX + titleBarW - buttonW - 4;
  54067. if (closeButton != 0)
  54068. {
  54069. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  54070. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  54071. : -(buttonW + buttonW / 5);
  54072. }
  54073. if (positionTitleBarButtonsOnLeft)
  54074. swapVariables (minimiseButton, maximiseButton);
  54075. if (maximiseButton != 0)
  54076. {
  54077. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54078. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  54079. }
  54080. if (minimiseButton != 0)
  54081. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54082. }
  54083. END_JUCE_NAMESPACE
  54084. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  54085. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  54086. BEGIN_JUCE_NAMESPACE
  54087. class DummyMenuComponent : public Component
  54088. {
  54089. DummyMenuComponent (const DummyMenuComponent&);
  54090. DummyMenuComponent& operator= (const DummyMenuComponent&);
  54091. public:
  54092. DummyMenuComponent() {}
  54093. ~DummyMenuComponent() {}
  54094. void inputAttemptWhenModal()
  54095. {
  54096. exitModalState (0);
  54097. }
  54098. };
  54099. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  54100. : model (0),
  54101. itemUnderMouse (-1),
  54102. currentPopupIndex (-1),
  54103. indexToShowAgain (-1),
  54104. lastMouseX (0),
  54105. lastMouseY (0),
  54106. inModalState (false)
  54107. {
  54108. setRepaintsOnMouseActivity (true);
  54109. setWantsKeyboardFocus (false);
  54110. setMouseClickGrabsKeyboardFocus (false);
  54111. setModel (model_);
  54112. }
  54113. MenuBarComponent::~MenuBarComponent()
  54114. {
  54115. setModel (0);
  54116. Desktop::getInstance().removeGlobalMouseListener (this);
  54117. currentPopup = 0;
  54118. }
  54119. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  54120. {
  54121. if (model != newModel)
  54122. {
  54123. if (model != 0)
  54124. model->removeListener (this);
  54125. model = newModel;
  54126. if (model != 0)
  54127. model->addListener (this);
  54128. repaint();
  54129. menuBarItemsChanged (0);
  54130. }
  54131. }
  54132. void MenuBarComponent::paint (Graphics& g)
  54133. {
  54134. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  54135. getLookAndFeel().drawMenuBarBackground (g,
  54136. getWidth(),
  54137. getHeight(),
  54138. isMouseOverBar,
  54139. *this);
  54140. if (model != 0)
  54141. {
  54142. for (int i = 0; i < menuNames.size(); ++i)
  54143. {
  54144. g.saveState();
  54145. g.setOrigin (xPositions [i], 0);
  54146. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  54147. getLookAndFeel().drawMenuBarItem (g,
  54148. xPositions[i + 1] - xPositions[i],
  54149. getHeight(),
  54150. i,
  54151. menuNames[i],
  54152. i == itemUnderMouse,
  54153. i == currentPopupIndex,
  54154. isMouseOverBar,
  54155. *this);
  54156. g.restoreState();
  54157. }
  54158. }
  54159. }
  54160. void MenuBarComponent::resized()
  54161. {
  54162. xPositions.clear();
  54163. int x = 2;
  54164. xPositions.add (x);
  54165. for (int i = 0; i < menuNames.size(); ++i)
  54166. {
  54167. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  54168. xPositions.add (x);
  54169. }
  54170. }
  54171. int MenuBarComponent::getItemAt (const int x, const int y)
  54172. {
  54173. for (int i = 0; i < xPositions.size(); ++i)
  54174. if (x >= xPositions[i] && x < xPositions[i + 1])
  54175. return reallyContains (x, y, true) ? i : -1;
  54176. return -1;
  54177. }
  54178. void MenuBarComponent::repaintMenuItem (int index)
  54179. {
  54180. if (((unsigned int) index) < (unsigned int) xPositions.size())
  54181. {
  54182. const int x1 = xPositions [index];
  54183. const int x2 = xPositions [index + 1];
  54184. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  54185. }
  54186. }
  54187. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  54188. {
  54189. const int newItem = getItemAt (x, y);
  54190. if (itemUnderMouse != newItem)
  54191. {
  54192. repaintMenuItem (itemUnderMouse);
  54193. itemUnderMouse = newItem;
  54194. repaintMenuItem (itemUnderMouse);
  54195. }
  54196. }
  54197. void MenuBarComponent::hideCurrentMenu()
  54198. {
  54199. currentPopup = 0;
  54200. repaint();
  54201. }
  54202. void MenuBarComponent::showMenu (int index)
  54203. {
  54204. if (index != currentPopupIndex)
  54205. {
  54206. if (inModalState)
  54207. {
  54208. hideCurrentMenu();
  54209. indexToShowAgain = index;
  54210. return;
  54211. }
  54212. indexToShowAgain = -1;
  54213. currentPopupIndex = -1;
  54214. itemUnderMouse = index;
  54215. currentPopup = 0;
  54216. menuBarItemsChanged (0);
  54217. Component::SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  54218. Component::SafePointer<Component> deletionChecker (this);
  54219. enterModalState (false);
  54220. inModalState = true;
  54221. int result = 0;
  54222. ApplicationCommandManager* managerOfChosenCommand = 0;
  54223. Desktop::getInstance().addGlobalMouseListener (this);
  54224. for (;;)
  54225. {
  54226. const int x = getScreenX() + xPositions [itemUnderMouse];
  54227. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  54228. currentPopupIndex = itemUnderMouse;
  54229. indexToShowAgain = -1;
  54230. repaint();
  54231. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  54232. {
  54233. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  54234. menuNames [itemUnderMouse]));
  54235. if (m.lookAndFeel == 0)
  54236. m.setLookAndFeel (&getLookAndFeel());
  54237. currentPopup = m.createMenuComponent (x, getScreenY(),
  54238. w, getHeight(),
  54239. 0, w, 0, 0,
  54240. true, this,
  54241. &managerOfChosenCommand,
  54242. this);
  54243. }
  54244. if (currentPopup == 0)
  54245. {
  54246. currentPopup = new DummyMenuComponent();
  54247. addAndMakeVisible (currentPopup);
  54248. }
  54249. currentPopup->enterModalState (false);
  54250. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54251. // be stuck behind other comps that are already modal..
  54252. result = currentPopup->runModalLoop();
  54253. if (deletionChecker == 0)
  54254. return;
  54255. const int lastPopupIndex = currentPopupIndex;
  54256. currentPopup = 0;
  54257. currentPopupIndex = -1;
  54258. if (result != 0)
  54259. {
  54260. topLevelIndexClicked = lastPopupIndex;
  54261. break;
  54262. }
  54263. else if (indexToShowAgain >= 0)
  54264. {
  54265. menuBarItemsChanged (0);
  54266. repaint();
  54267. itemUnderMouse = indexToShowAgain;
  54268. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54269. break;
  54270. }
  54271. else
  54272. {
  54273. break;
  54274. }
  54275. }
  54276. Desktop::getInstance().removeGlobalMouseListener (this);
  54277. inModalState = false;
  54278. exitModalState (0);
  54279. if (prevFocused != 0)
  54280. prevFocused->grabKeyboardFocus();
  54281. const Point<int> mousePos (getMouseXYRelative());
  54282. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54283. repaint();
  54284. if (result != 0)
  54285. {
  54286. if (managerOfChosenCommand != 0)
  54287. {
  54288. ApplicationCommandTarget::InvocationInfo info (result);
  54289. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54290. managerOfChosenCommand->invoke (info, true);
  54291. }
  54292. postCommandMessage (result);
  54293. }
  54294. }
  54295. }
  54296. void MenuBarComponent::handleCommandMessage (int commandId)
  54297. {
  54298. if (model != 0)
  54299. model->menuItemSelected (commandId, topLevelIndexClicked);
  54300. }
  54301. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54302. {
  54303. if (e.eventComponent == this)
  54304. updateItemUnderMouse (e.x, e.y);
  54305. }
  54306. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54307. {
  54308. if (e.eventComponent == this)
  54309. updateItemUnderMouse (e.x, e.y);
  54310. }
  54311. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54312. {
  54313. if (currentPopupIndex < 0)
  54314. {
  54315. const MouseEvent e2 (e.getEventRelativeTo (this));
  54316. updateItemUnderMouse (e2.x, e2.y);
  54317. currentPopupIndex = -2;
  54318. showMenu (itemUnderMouse);
  54319. }
  54320. }
  54321. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54322. {
  54323. const MouseEvent e2 (e.getEventRelativeTo (this));
  54324. const int item = getItemAt (e2.x, e2.y);
  54325. if (item >= 0)
  54326. showMenu (item);
  54327. }
  54328. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54329. {
  54330. const MouseEvent e2 (e.getEventRelativeTo (this));
  54331. updateItemUnderMouse (e2.x, e2.y);
  54332. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> ((Component*) currentPopup) != 0)
  54333. hideCurrentMenu();
  54334. }
  54335. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54336. {
  54337. const MouseEvent e2 (e.getEventRelativeTo (this));
  54338. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54339. {
  54340. if (currentPopupIndex >= 0)
  54341. {
  54342. const int item = getItemAt (e2.x, e2.y);
  54343. if (item >= 0)
  54344. showMenu (item);
  54345. }
  54346. else
  54347. {
  54348. updateItemUnderMouse (e2.x, e2.y);
  54349. }
  54350. lastMouseX = e2.x;
  54351. lastMouseY = e2.y;
  54352. }
  54353. }
  54354. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54355. {
  54356. bool used = false;
  54357. const int numMenus = menuNames.size();
  54358. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54359. if (key.isKeyCode (KeyPress::leftKey))
  54360. {
  54361. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54362. used = true;
  54363. }
  54364. else if (key.isKeyCode (KeyPress::rightKey))
  54365. {
  54366. showMenu ((currentIndex + 1) % numMenus);
  54367. used = true;
  54368. }
  54369. return used;
  54370. }
  54371. void MenuBarComponent::inputAttemptWhenModal()
  54372. {
  54373. hideCurrentMenu();
  54374. }
  54375. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54376. {
  54377. StringArray newNames;
  54378. if (model != 0)
  54379. newNames = model->getMenuBarNames();
  54380. if (newNames != menuNames)
  54381. {
  54382. menuNames = newNames;
  54383. repaint();
  54384. resized();
  54385. }
  54386. }
  54387. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54388. const ApplicationCommandTarget::InvocationInfo& info)
  54389. {
  54390. if (model == 0
  54391. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54392. return;
  54393. for (int i = 0; i < menuNames.size(); ++i)
  54394. {
  54395. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54396. if (menu.containsCommandItem (info.commandID))
  54397. {
  54398. itemUnderMouse = i;
  54399. repaintMenuItem (i);
  54400. startTimer (200);
  54401. break;
  54402. }
  54403. }
  54404. }
  54405. void MenuBarComponent::timerCallback()
  54406. {
  54407. stopTimer();
  54408. const Point<int> mousePos (getMouseXYRelative());
  54409. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54410. }
  54411. END_JUCE_NAMESPACE
  54412. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54413. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54414. BEGIN_JUCE_NAMESPACE
  54415. MenuBarModel::MenuBarModel() throw()
  54416. : manager (0)
  54417. {
  54418. }
  54419. MenuBarModel::~MenuBarModel()
  54420. {
  54421. setApplicationCommandManagerToWatch (0);
  54422. }
  54423. void MenuBarModel::menuItemsChanged()
  54424. {
  54425. triggerAsyncUpdate();
  54426. }
  54427. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54428. {
  54429. if (manager != newManager)
  54430. {
  54431. if (manager != 0)
  54432. manager->removeListener (this);
  54433. manager = newManager;
  54434. if (manager != 0)
  54435. manager->addListener (this);
  54436. }
  54437. }
  54438. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54439. {
  54440. listeners.add (newListener);
  54441. }
  54442. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54443. {
  54444. // Trying to remove a listener that isn't on the list!
  54445. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54446. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54447. jassert (listeners.contains (listenerToRemove));
  54448. listeners.remove (listenerToRemove);
  54449. }
  54450. void MenuBarModel::handleAsyncUpdate()
  54451. {
  54452. listeners.call (&MenuBarModelListener::menuBarItemsChanged, this);
  54453. }
  54454. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54455. {
  54456. listeners.call (&MenuBarModelListener::menuCommandInvoked, this, info);
  54457. }
  54458. void MenuBarModel::applicationCommandListChanged()
  54459. {
  54460. menuItemsChanged();
  54461. }
  54462. END_JUCE_NAMESPACE
  54463. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54464. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54465. BEGIN_JUCE_NAMESPACE
  54466. class PopupMenu::Item
  54467. {
  54468. public:
  54469. Item()
  54470. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54471. usesColour (false), customComp (0), commandManager (0)
  54472. {
  54473. }
  54474. Item (const int itemId_,
  54475. const String& text_,
  54476. const bool active_,
  54477. const bool isTicked_,
  54478. const Image* im,
  54479. const Colour& textColour_,
  54480. const bool usesColour_,
  54481. PopupMenuCustomComponent* const customComp_,
  54482. const PopupMenu* const subMenu_,
  54483. ApplicationCommandManager* const commandManager_)
  54484. : itemId (itemId_), text (text_), textColour (textColour_),
  54485. active (active_), isSeparator (false), isTicked (isTicked_),
  54486. usesColour (usesColour_), customComp (customComp_),
  54487. commandManager (commandManager_)
  54488. {
  54489. if (subMenu_ != 0)
  54490. subMenu = new PopupMenu (*subMenu_);
  54491. if (im != 0)
  54492. image = im->createCopy();
  54493. if (commandManager_ != 0 && itemId_ != 0)
  54494. {
  54495. String shortcutKey;
  54496. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  54497. ->getKeyPressesAssignedToCommand (itemId_));
  54498. for (int i = 0; i < keyPresses.size(); ++i)
  54499. {
  54500. const String key (keyPresses.getReference(i).getTextDescription());
  54501. if (shortcutKey.isNotEmpty())
  54502. shortcutKey << ", ";
  54503. if (key.length() == 1)
  54504. shortcutKey << "shortcut: '" << key << '\'';
  54505. else
  54506. shortcutKey << key;
  54507. }
  54508. shortcutKey = shortcutKey.trim();
  54509. if (shortcutKey.isNotEmpty())
  54510. text << "<end>" << shortcutKey;
  54511. }
  54512. }
  54513. Item (const Item& other)
  54514. : itemId (other.itemId),
  54515. text (other.text),
  54516. textColour (other.textColour),
  54517. active (other.active),
  54518. isSeparator (other.isSeparator),
  54519. isTicked (other.isTicked),
  54520. usesColour (other.usesColour),
  54521. customComp (other.customComp),
  54522. commandManager (other.commandManager)
  54523. {
  54524. if (other.subMenu != 0)
  54525. subMenu = new PopupMenu (*(other.subMenu));
  54526. if (other.image != 0)
  54527. image = other.image->createCopy();
  54528. }
  54529. ~Item()
  54530. {
  54531. customComp = 0;
  54532. }
  54533. bool canBeTriggered() const throw()
  54534. {
  54535. return active && ! (isSeparator || (subMenu != 0));
  54536. }
  54537. bool hasActiveSubMenu() const throw()
  54538. {
  54539. return active && (subMenu != 0);
  54540. }
  54541. const int itemId;
  54542. String text;
  54543. const Colour textColour;
  54544. const bool active, isSeparator, isTicked, usesColour;
  54545. ScopedPointer <Image> image;
  54546. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  54547. ScopedPointer <PopupMenu> subMenu;
  54548. ApplicationCommandManager* const commandManager;
  54549. juce_UseDebuggingNewOperator
  54550. private:
  54551. Item& operator= (const Item&);
  54552. };
  54553. class PopupMenu::ItemComponent : public Component
  54554. {
  54555. public:
  54556. ItemComponent (const PopupMenu::Item& itemInfo_)
  54557. : itemInfo (itemInfo_),
  54558. isHighlighted (false)
  54559. {
  54560. if (itemInfo.customComp != 0)
  54561. addAndMakeVisible (itemInfo.customComp);
  54562. }
  54563. ~ItemComponent()
  54564. {
  54565. if (itemInfo.customComp != 0)
  54566. removeChildComponent (itemInfo.customComp);
  54567. }
  54568. void getIdealSize (int& idealWidth,
  54569. int& idealHeight,
  54570. const int standardItemHeight)
  54571. {
  54572. if (itemInfo.customComp != 0)
  54573. {
  54574. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  54575. }
  54576. else
  54577. {
  54578. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  54579. itemInfo.isSeparator,
  54580. standardItemHeight,
  54581. idealWidth,
  54582. idealHeight);
  54583. }
  54584. }
  54585. void paint (Graphics& g)
  54586. {
  54587. if (itemInfo.customComp == 0)
  54588. {
  54589. String mainText (itemInfo.text);
  54590. String endText;
  54591. const int endIndex = mainText.indexOf (T("<end>"));
  54592. if (endIndex >= 0)
  54593. {
  54594. endText = mainText.substring (endIndex + 5).trim();
  54595. mainText = mainText.substring (0, endIndex);
  54596. }
  54597. getLookAndFeel()
  54598. .drawPopupMenuItem (g, getWidth(), getHeight(),
  54599. itemInfo.isSeparator,
  54600. itemInfo.active,
  54601. isHighlighted,
  54602. itemInfo.isTicked,
  54603. itemInfo.subMenu != 0,
  54604. mainText, endText,
  54605. itemInfo.image,
  54606. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  54607. }
  54608. }
  54609. void resized()
  54610. {
  54611. if (getNumChildComponents() > 0)
  54612. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  54613. }
  54614. void setHighlighted (bool shouldBeHighlighted)
  54615. {
  54616. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  54617. if (isHighlighted != shouldBeHighlighted)
  54618. {
  54619. isHighlighted = shouldBeHighlighted;
  54620. if (itemInfo.customComp != 0)
  54621. {
  54622. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  54623. itemInfo.customComp->repaint();
  54624. }
  54625. repaint();
  54626. }
  54627. }
  54628. PopupMenu::Item itemInfo;
  54629. juce_UseDebuggingNewOperator
  54630. private:
  54631. bool isHighlighted;
  54632. ItemComponent (const ItemComponent&);
  54633. ItemComponent& operator= (const ItemComponent&);
  54634. };
  54635. namespace PopupMenuSettings
  54636. {
  54637. static const int scrollZone = 24;
  54638. static const int borderSize = 2;
  54639. static const int timerInterval = 50;
  54640. static const int dismissCommandId = 0x6287345f;
  54641. }
  54642. class PopupMenu::Window : public Component,
  54643. private Timer
  54644. {
  54645. public:
  54646. Window()
  54647. : Component (T("menu")),
  54648. owner (0),
  54649. currentChild (0),
  54650. activeSubMenu (0),
  54651. menuBarComponent (0),
  54652. managerOfChosenCommand (0),
  54653. minimumWidth (0),
  54654. maximumNumColumns (7),
  54655. standardItemHeight (0),
  54656. isOver (false),
  54657. hasBeenOver (false),
  54658. isDown (false),
  54659. needsToScroll (false),
  54660. hideOnExit (false),
  54661. disableMouseMoves (false),
  54662. hasAnyJuceCompHadFocus (false),
  54663. numColumns (0),
  54664. contentHeight (0),
  54665. childYOffset (0),
  54666. timeEnteredCurrentChildComp (0),
  54667. scrollAcceleration (1.0)
  54668. {
  54669. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  54670. setWantsKeyboardFocus (true);
  54671. setMouseClickGrabsKeyboardFocus (false);
  54672. setOpaque (true);
  54673. setAlwaysOnTop (true);
  54674. Desktop::getInstance().addGlobalMouseListener (this);
  54675. getActiveWindows().add (this);
  54676. }
  54677. ~Window()
  54678. {
  54679. getActiveWindows().removeValue (this);
  54680. Desktop::getInstance().removeGlobalMouseListener (this);
  54681. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54682. activeSubMenu = 0;
  54683. deleteAllChildren();
  54684. }
  54685. static Window* create (const PopupMenu& menu,
  54686. const bool dismissOnMouseUp,
  54687. Window* const owner_,
  54688. const int minX, const int maxX,
  54689. const int minY, const int maxY,
  54690. const int minimumWidth,
  54691. const int maximumNumColumns,
  54692. const int standardItemHeight,
  54693. const bool alignToRectangle,
  54694. const int itemIdThatMustBeVisible,
  54695. Component* const menuBarComponent,
  54696. ApplicationCommandManager** managerOfChosenCommand,
  54697. Component* const componentAttachedTo)
  54698. {
  54699. if (menu.items.size() > 0)
  54700. {
  54701. int totalItems = 0;
  54702. ScopedPointer <Window> mw (new Window());
  54703. mw->setLookAndFeel (menu.lookAndFeel);
  54704. mw->setWantsKeyboardFocus (false);
  54705. mw->minimumWidth = minimumWidth;
  54706. mw->maximumNumColumns = maximumNumColumns;
  54707. mw->standardItemHeight = standardItemHeight;
  54708. mw->dismissOnMouseUp = dismissOnMouseUp;
  54709. for (int i = 0; i < menu.items.size(); ++i)
  54710. {
  54711. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  54712. mw->addItem (*item);
  54713. ++totalItems;
  54714. }
  54715. if (totalItems > 0)
  54716. {
  54717. mw->owner = owner_;
  54718. mw->menuBarComponent = menuBarComponent;
  54719. mw->managerOfChosenCommand = managerOfChosenCommand;
  54720. mw->componentAttachedTo = componentAttachedTo;
  54721. mw->componentAttachedToOriginal = componentAttachedTo;
  54722. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  54723. mw->setTopLeftPosition (mw->windowPos.getX(),
  54724. mw->windowPos.getY());
  54725. mw->updateYPositions();
  54726. if (itemIdThatMustBeVisible != 0)
  54727. {
  54728. const int y = minY - mw->windowPos.getY();
  54729. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  54730. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  54731. }
  54732. mw->resizeToBestWindowPos();
  54733. mw->addToDesktop (ComponentPeer::windowIsTemporary
  54734. | mw->getLookAndFeel().getMenuWindowFlags());
  54735. return mw.release();
  54736. }
  54737. }
  54738. return 0;
  54739. }
  54740. void paint (Graphics& g)
  54741. {
  54742. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  54743. }
  54744. void paintOverChildren (Graphics& g)
  54745. {
  54746. if (isScrolling())
  54747. {
  54748. LookAndFeel& lf = getLookAndFeel();
  54749. if (isScrollZoneActive (false))
  54750. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  54751. if (isScrollZoneActive (true))
  54752. {
  54753. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  54754. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  54755. }
  54756. }
  54757. }
  54758. bool isScrollZoneActive (bool bottomOne) const
  54759. {
  54760. return isScrolling()
  54761. && (bottomOne
  54762. ? childYOffset < contentHeight - windowPos.getHeight()
  54763. : childYOffset > 0);
  54764. }
  54765. void addItem (const PopupMenu::Item& item)
  54766. {
  54767. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  54768. addAndMakeVisible (mic);
  54769. int itemW = 80;
  54770. int itemH = 16;
  54771. mic->getIdealSize (itemW, itemH, standardItemHeight);
  54772. mic->setSize (itemW, jlimit (2, 600, itemH));
  54773. mic->addMouseListener (this, false);
  54774. }
  54775. // hide this and all sub-comps
  54776. void hide (const PopupMenu::Item* const item)
  54777. {
  54778. if (isVisible())
  54779. {
  54780. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54781. activeSubMenu = 0;
  54782. currentChild = 0;
  54783. exitModalState (item != 0 ? item->itemId : 0);
  54784. setVisible (false);
  54785. if (item != 0
  54786. && item->commandManager != 0
  54787. && item->itemId != 0)
  54788. {
  54789. *managerOfChosenCommand = item->commandManager;
  54790. }
  54791. }
  54792. }
  54793. void dismissMenu (const PopupMenu::Item* const item)
  54794. {
  54795. if (owner != 0)
  54796. {
  54797. owner->dismissMenu (item);
  54798. }
  54799. else
  54800. {
  54801. if (item != 0)
  54802. {
  54803. // need a copy of this on the stack as the one passed in will get deleted during this call
  54804. const PopupMenu::Item mi (*item);
  54805. hide (&mi);
  54806. }
  54807. else
  54808. {
  54809. hide (0);
  54810. }
  54811. }
  54812. }
  54813. void mouseMove (const MouseEvent&)
  54814. {
  54815. timerCallback();
  54816. }
  54817. void mouseDown (const MouseEvent&)
  54818. {
  54819. timerCallback();
  54820. }
  54821. void mouseDrag (const MouseEvent&)
  54822. {
  54823. timerCallback();
  54824. }
  54825. void mouseUp (const MouseEvent&)
  54826. {
  54827. timerCallback();
  54828. }
  54829. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  54830. {
  54831. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  54832. lastMouse = Point<int> (-1, -1);
  54833. }
  54834. bool keyPressed (const KeyPress& key)
  54835. {
  54836. if (key.isKeyCode (KeyPress::downKey))
  54837. {
  54838. selectNextItem (1);
  54839. }
  54840. else if (key.isKeyCode (KeyPress::upKey))
  54841. {
  54842. selectNextItem (-1);
  54843. }
  54844. else if (key.isKeyCode (KeyPress::leftKey))
  54845. {
  54846. if (owner != 0)
  54847. {
  54848. Component::SafePointer<Window> parentWindow (owner);
  54849. PopupMenu::ItemComponent* currentChildOfParent = parentWindow->currentChild;
  54850. hide (0);
  54851. if (parentWindow != 0)
  54852. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  54853. disableTimerUntilMouseMoves();
  54854. }
  54855. else if (menuBarComponent != 0)
  54856. {
  54857. menuBarComponent->keyPressed (key);
  54858. }
  54859. }
  54860. else if (key.isKeyCode (KeyPress::rightKey))
  54861. {
  54862. disableTimerUntilMouseMoves();
  54863. if (showSubMenuFor (currentChild))
  54864. {
  54865. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54866. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  54867. activeSubMenu->selectNextItem (1);
  54868. }
  54869. else if (menuBarComponent != 0)
  54870. {
  54871. menuBarComponent->keyPressed (key);
  54872. }
  54873. }
  54874. else if (key.isKeyCode (KeyPress::returnKey))
  54875. {
  54876. triggerCurrentlyHighlightedItem();
  54877. }
  54878. else if (key.isKeyCode (KeyPress::escapeKey))
  54879. {
  54880. dismissMenu (0);
  54881. }
  54882. else
  54883. {
  54884. return false;
  54885. }
  54886. return true;
  54887. }
  54888. void inputAttemptWhenModal()
  54889. {
  54890. timerCallback();
  54891. if (! isOverAnyMenu())
  54892. {
  54893. if (componentAttachedTo != 0)
  54894. {
  54895. // we want to dismiss the menu, but if we do it synchronously, then
  54896. // the mouse-click will be allowed to pass through. That's good, except
  54897. // when the user clicks on the button that orginally popped the menu up,
  54898. // as they'll expect the menu to go away, and in fact it'll just
  54899. // come back. So only dismiss synchronously if they're not on the original
  54900. // comp that we're attached to.
  54901. const Point<int> mousePos (componentAttachedTo->getMouseXYRelative());
  54902. if (componentAttachedTo->reallyContains (mousePos.getX(), mousePos.getY(), true))
  54903. {
  54904. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  54905. return;
  54906. }
  54907. }
  54908. dismissMenu (0);
  54909. }
  54910. }
  54911. void handleCommandMessage (int commandId)
  54912. {
  54913. Component::handleCommandMessage (commandId);
  54914. if (commandId == PopupMenuSettings::dismissCommandId)
  54915. dismissMenu (0);
  54916. }
  54917. void timerCallback()
  54918. {
  54919. if (! isVisible())
  54920. return;
  54921. if (componentAttachedTo != componentAttachedToOriginal)
  54922. {
  54923. dismissMenu (0);
  54924. return;
  54925. }
  54926. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  54927. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  54928. return;
  54929. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  54930. // move rather than a real timer callback
  54931. const Point<int> globalMousePos (Desktop::getMousePosition());
  54932. const Point<int> localMousePos (globalPositionToRelative (globalMousePos));
  54933. const uint32 now = Time::getMillisecondCounter();
  54934. if (now > timeEnteredCurrentChildComp + 100
  54935. && reallyContains (localMousePos.getX(), localMousePos.getY(), true)
  54936. && currentChild->isValidComponent()
  54937. && (! disableMouseMoves)
  54938. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  54939. {
  54940. showSubMenuFor (currentChild);
  54941. }
  54942. if (globalMousePos != lastMouse || now > lastMouseMoveTime + 350)
  54943. {
  54944. highlightItemUnderMouse (globalMousePos, localMousePos);
  54945. }
  54946. bool overScrollArea = false;
  54947. if (isScrolling()
  54948. && (isOver || (isDown && ((unsigned int) localMousePos.getX()) < (unsigned int) getWidth()))
  54949. && ((isScrollZoneActive (false) && localMousePos.getY() < PopupMenuSettings::scrollZone)
  54950. || (isScrollZoneActive (true) && localMousePos.getY() > getHeight() - PopupMenuSettings::scrollZone)))
  54951. {
  54952. if (now > lastScroll + 20)
  54953. {
  54954. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  54955. int amount = 0;
  54956. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  54957. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  54958. alterChildYPos (localMousePos.getY() < PopupMenuSettings::scrollZone ? -amount : amount);
  54959. lastScroll = now;
  54960. }
  54961. overScrollArea = true;
  54962. lastMouse = Point<int> (-1, -1); // trigger a mouse-move
  54963. }
  54964. else
  54965. {
  54966. scrollAcceleration = 1.0;
  54967. }
  54968. const bool wasDown = isDown;
  54969. bool isOverAny = isOverAnyMenu();
  54970. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  54971. {
  54972. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54973. isOverAny = isOverAnyMenu();
  54974. }
  54975. if (hideOnExit && hasBeenOver && ! isOverAny)
  54976. {
  54977. hide (0);
  54978. }
  54979. else
  54980. {
  54981. isDown = hasBeenOver
  54982. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  54983. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  54984. bool anyFocused = Process::isForegroundProcess();
  54985. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  54986. {
  54987. // because no component at all may have focus, our test here will
  54988. // only be triggered when something has focus and then loses it.
  54989. anyFocused = ! hasAnyJuceCompHadFocus;
  54990. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  54991. {
  54992. if (ComponentPeer::getPeer (i)->isFocused())
  54993. {
  54994. anyFocused = true;
  54995. hasAnyJuceCompHadFocus = true;
  54996. break;
  54997. }
  54998. }
  54999. }
  55000. if (! anyFocused)
  55001. {
  55002. if (now > lastFocused + 10)
  55003. {
  55004. wasHiddenBecauseOfAppChange() = true;
  55005. dismissMenu (0);
  55006. return; // may have been deleted by the previous call..
  55007. }
  55008. }
  55009. else if (wasDown && now > menuCreationTime + 250
  55010. && ! (isDown || overScrollArea))
  55011. {
  55012. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  55013. if (isOver)
  55014. {
  55015. triggerCurrentlyHighlightedItem();
  55016. }
  55017. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  55018. {
  55019. dismissMenu (0);
  55020. }
  55021. return; // may have been deleted by the previous calls..
  55022. }
  55023. else
  55024. {
  55025. lastFocused = now;
  55026. }
  55027. }
  55028. }
  55029. static Array<Window*>& getActiveWindows()
  55030. {
  55031. static Array<Window*> activeMenuWindows;
  55032. return activeMenuWindows;
  55033. }
  55034. static bool& wasHiddenBecauseOfAppChange() throw()
  55035. {
  55036. static bool b = false;
  55037. return b;
  55038. }
  55039. juce_UseDebuggingNewOperator
  55040. private:
  55041. Window* owner;
  55042. PopupMenu::ItemComponent* currentChild;
  55043. ScopedPointer <Window> activeSubMenu;
  55044. Component* menuBarComponent;
  55045. ApplicationCommandManager** managerOfChosenCommand;
  55046. Component::SafePointer<Component> componentAttachedTo;
  55047. Component* componentAttachedToOriginal;
  55048. Rectangle<int> windowPos;
  55049. Point<int> lastMouse;
  55050. int minimumWidth, maximumNumColumns, standardItemHeight;
  55051. bool isOver, hasBeenOver, isDown, needsToScroll;
  55052. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  55053. int numColumns, contentHeight, childYOffset;
  55054. Array <int> columnWidths;
  55055. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  55056. double scrollAcceleration;
  55057. bool overlaps (const Rectangle<int>& r) const
  55058. {
  55059. return r.intersects (getBounds())
  55060. || (owner != 0 && owner->overlaps (r));
  55061. }
  55062. bool isOverAnyMenu() const
  55063. {
  55064. return (owner != 0) ? owner->isOverAnyMenu()
  55065. : isOverChildren();
  55066. }
  55067. bool isOverChildren() const
  55068. {
  55069. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55070. return isVisible()
  55071. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  55072. }
  55073. void updateMouseOverStatus (const Point<int>& globalMousePos)
  55074. {
  55075. const Point<int> relPos (globalPositionToRelative (globalMousePos));
  55076. isOver = reallyContains (relPos.getX(), relPos.getY(), true);
  55077. if (activeSubMenu != 0)
  55078. activeSubMenu->updateMouseOverStatus (globalMousePos);
  55079. }
  55080. bool treeContains (const Window* const window) const throw()
  55081. {
  55082. const Window* mw = this;
  55083. while (mw->owner != 0)
  55084. mw = mw->owner;
  55085. while (mw != 0)
  55086. {
  55087. if (mw == window)
  55088. return true;
  55089. mw = mw->activeSubMenu;
  55090. }
  55091. return false;
  55092. }
  55093. void calculateWindowPos (const int minX, const int maxX,
  55094. const int minY, const int maxY,
  55095. const bool alignToRectangle)
  55096. {
  55097. const Rectangle<int> mon (Desktop::getInstance()
  55098. .getMonitorAreaContaining (Point<int> ((minX + maxX) / 2,
  55099. (minY + maxY) / 2),
  55100. #if JUCE_MAC
  55101. true));
  55102. #else
  55103. false)); // on windows, don't stop the menu overlapping the taskbar
  55104. #endif
  55105. int x, y, widthToUse, heightToUse;
  55106. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  55107. if (alignToRectangle)
  55108. {
  55109. x = minX;
  55110. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  55111. const int spaceOver = minY - mon.getY();
  55112. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  55113. y = maxY;
  55114. else
  55115. y = minY - heightToUse;
  55116. }
  55117. else
  55118. {
  55119. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  55120. if (owner != 0)
  55121. {
  55122. if (owner->owner != 0)
  55123. {
  55124. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  55125. > owner->owner->getX() + owner->owner->getWidth() / 2);
  55126. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  55127. tendTowardsRight = true;
  55128. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  55129. tendTowardsRight = false;
  55130. }
  55131. else if (maxX + widthToUse < mon.getRight() - 32)
  55132. {
  55133. tendTowardsRight = true;
  55134. }
  55135. }
  55136. const int biggestSpace = jmax (mon.getRight() - maxX,
  55137. minX - mon.getX()) - 32;
  55138. if (biggestSpace < widthToUse)
  55139. {
  55140. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  55141. if (numColumns > 1)
  55142. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  55143. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  55144. }
  55145. if (tendTowardsRight)
  55146. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  55147. else
  55148. x = jmax (mon.getX() + 4, minX - widthToUse);
  55149. y = minY;
  55150. if ((minY + maxY) / 2 > mon.getCentreY())
  55151. y = jmax (mon.getY(), maxY - heightToUse);
  55152. }
  55153. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  55154. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  55155. windowPos.setBounds (x, y, widthToUse, heightToUse);
  55156. // sets this flag if it's big enough to obscure any of its parent menus
  55157. hideOnExit = (owner != 0)
  55158. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  55159. }
  55160. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  55161. {
  55162. numColumns = 0;
  55163. contentHeight = 0;
  55164. const int maxMenuH = getParentHeight() - 24;
  55165. int totalW;
  55166. do
  55167. {
  55168. ++numColumns;
  55169. totalW = workOutBestSize (maxMenuW);
  55170. if (totalW > maxMenuW)
  55171. {
  55172. numColumns = jmax (1, numColumns - 1);
  55173. totalW = workOutBestSize (maxMenuW); // to update col widths
  55174. break;
  55175. }
  55176. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  55177. {
  55178. break;
  55179. }
  55180. } while (numColumns < maximumNumColumns);
  55181. const int actualH = jmin (contentHeight, maxMenuH);
  55182. needsToScroll = contentHeight > actualH;
  55183. width = updateYPositions();
  55184. height = actualH + PopupMenuSettings::borderSize * 2;
  55185. }
  55186. int workOutBestSize (const int maxMenuW)
  55187. {
  55188. int totalW = 0;
  55189. contentHeight = 0;
  55190. int childNum = 0;
  55191. for (int col = 0; col < numColumns; ++col)
  55192. {
  55193. int i, colW = 50, colH = 0;
  55194. const int numChildren = jmin (getNumChildComponents() - childNum,
  55195. (getNumChildComponents() + numColumns - 1) / numColumns);
  55196. for (i = numChildren; --i >= 0;)
  55197. {
  55198. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  55199. colH += getChildComponent (childNum + i)->getHeight();
  55200. }
  55201. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  55202. columnWidths.set (col, colW);
  55203. totalW += colW;
  55204. contentHeight = jmax (contentHeight, colH);
  55205. childNum += numChildren;
  55206. }
  55207. if (totalW < minimumWidth)
  55208. {
  55209. totalW = minimumWidth;
  55210. for (int col = 0; col < numColumns; ++col)
  55211. columnWidths.set (0, totalW / numColumns);
  55212. }
  55213. return totalW;
  55214. }
  55215. void ensureItemIsVisible (const int itemId, int wantedY)
  55216. {
  55217. jassert (itemId != 0)
  55218. for (int i = getNumChildComponents(); --i >= 0;)
  55219. {
  55220. PopupMenu::ItemComponent* const m = (PopupMenu::ItemComponent*) getChildComponent (i);
  55221. if (m != 0
  55222. && m->itemInfo.itemId == itemId
  55223. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  55224. {
  55225. const int currentY = m->getY();
  55226. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  55227. {
  55228. if (wantedY < 0)
  55229. wantedY = jlimit (PopupMenuSettings::scrollZone,
  55230. jmax (PopupMenuSettings::scrollZone,
  55231. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  55232. currentY);
  55233. const Rectangle<int> mon (Desktop::getInstance().getMonitorAreaContaining (windowPos.getPosition(), true));
  55234. int deltaY = wantedY - currentY;
  55235. windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()),
  55236. jmin (windowPos.getHeight(), mon.getHeight()));
  55237. const int newY = jlimit (mon.getY(),
  55238. mon.getBottom() - windowPos.getHeight(),
  55239. windowPos.getY() + deltaY);
  55240. deltaY -= newY - windowPos.getY();
  55241. childYOffset -= deltaY;
  55242. windowPos.setPosition (windowPos.getX(), newY);
  55243. updateYPositions();
  55244. }
  55245. break;
  55246. }
  55247. }
  55248. }
  55249. void resizeToBestWindowPos()
  55250. {
  55251. Rectangle<int> r (windowPos);
  55252. if (childYOffset < 0)
  55253. {
  55254. r.setBounds (r.getX(), r.getY() - childYOffset,
  55255. r.getWidth(), r.getHeight() + childYOffset);
  55256. }
  55257. else if (childYOffset > 0)
  55258. {
  55259. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55260. if (spaceAtBottom > 0)
  55261. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55262. }
  55263. setBounds (r);
  55264. updateYPositions();
  55265. }
  55266. void alterChildYPos (const int delta)
  55267. {
  55268. if (isScrolling())
  55269. {
  55270. childYOffset += delta;
  55271. if (delta < 0)
  55272. {
  55273. childYOffset = jmax (childYOffset, 0);
  55274. }
  55275. else if (delta > 0)
  55276. {
  55277. childYOffset = jmin (childYOffset,
  55278. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  55279. }
  55280. updateYPositions();
  55281. }
  55282. else
  55283. {
  55284. childYOffset = 0;
  55285. }
  55286. resizeToBestWindowPos();
  55287. repaint();
  55288. }
  55289. int updateYPositions()
  55290. {
  55291. int x = 0;
  55292. int childNum = 0;
  55293. for (int col = 0; col < numColumns; ++col)
  55294. {
  55295. const int numChildren = jmin (getNumChildComponents() - childNum,
  55296. (getNumChildComponents() + numColumns - 1) / numColumns);
  55297. const int colW = columnWidths [col];
  55298. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  55299. for (int i = 0; i < numChildren; ++i)
  55300. {
  55301. Component* const c = getChildComponent (childNum + i);
  55302. c->setBounds (x, y, colW, c->getHeight());
  55303. y += c->getHeight();
  55304. }
  55305. x += colW;
  55306. childNum += numChildren;
  55307. }
  55308. return x;
  55309. }
  55310. bool isScrolling() const throw()
  55311. {
  55312. return childYOffset != 0 || needsToScroll;
  55313. }
  55314. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  55315. {
  55316. if (currentChild->isValidComponent())
  55317. currentChild->setHighlighted (false);
  55318. currentChild = child;
  55319. if (currentChild != 0)
  55320. {
  55321. currentChild->setHighlighted (true);
  55322. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55323. }
  55324. }
  55325. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  55326. {
  55327. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55328. activeSubMenu = 0;
  55329. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55330. {
  55331. const Point<int> topLeft (childComp->relativePositionToGlobal (Point<int>()));
  55332. const Point<int> bottomRight (childComp->relativePositionToGlobal (Point<int> (childComp->getWidth(), childComp->getHeight())));
  55333. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  55334. dismissOnMouseUp,
  55335. this,
  55336. topLeft.getX(), bottomRight.getX(), topLeft.getY(), bottomRight.getY(),
  55337. 0, maximumNumColumns,
  55338. standardItemHeight,
  55339. false, 0, menuBarComponent,
  55340. managerOfChosenCommand,
  55341. componentAttachedTo);
  55342. if (activeSubMenu != 0)
  55343. {
  55344. activeSubMenu->setVisible (true);
  55345. activeSubMenu->enterModalState (false);
  55346. activeSubMenu->toFront (false);
  55347. return true;
  55348. }
  55349. }
  55350. return false;
  55351. }
  55352. void highlightItemUnderMouse (const Point<int>& globalMousePos, const Point<int>& localMousePos)
  55353. {
  55354. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  55355. if (isOver)
  55356. hasBeenOver = true;
  55357. if (lastMouse.getDistanceFrom (globalMousePos) > 2)
  55358. {
  55359. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55360. if (disableMouseMoves && isOver)
  55361. disableMouseMoves = false;
  55362. }
  55363. if (disableMouseMoves)
  55364. return;
  55365. bool isMovingTowardsMenu = false;
  55366. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55367. if (isOver && (activeSubMenu != 0) && globalMousePos != lastMouse)
  55368. {
  55369. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55370. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55371. // extends from the last mouse pos to the submenu's rectangle..
  55372. float subX = (float) activeSubMenu->getScreenX();
  55373. if (activeSubMenu->getX() > getX())
  55374. {
  55375. lastMouse -= Point<int> (2, 0); // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55376. }
  55377. else
  55378. {
  55379. lastMouse += Point<int> (2, 0);
  55380. subX += activeSubMenu->getWidth();
  55381. }
  55382. Path areaTowardsSubMenu;
  55383. areaTowardsSubMenu.addTriangle ((float) lastMouse.getX(),
  55384. (float) lastMouse.getY(),
  55385. subX,
  55386. (float) activeSubMenu->getScreenY(),
  55387. subX,
  55388. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55389. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) globalMousePos.getX(), (float) globalMousePos.getY());
  55390. }
  55391. lastMouse = globalMousePos;
  55392. if (! isMovingTowardsMenu)
  55393. {
  55394. Component* c = getComponentAt (localMousePos.getX(), localMousePos.getY());
  55395. if (c == this)
  55396. c = 0;
  55397. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55398. if (mic == 0 && c != 0)
  55399. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55400. if (mic != currentChild
  55401. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55402. {
  55403. if (isOver && (c != 0) && (activeSubMenu != 0))
  55404. {
  55405. activeSubMenu->hide (0);
  55406. }
  55407. if (! isOver)
  55408. mic = 0;
  55409. setCurrentlyHighlightedChild (mic);
  55410. }
  55411. }
  55412. }
  55413. void triggerCurrentlyHighlightedItem()
  55414. {
  55415. if (currentChild->isValidComponent()
  55416. && currentChild->itemInfo.canBeTriggered()
  55417. && (currentChild->itemInfo.customComp == 0
  55418. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55419. {
  55420. dismissMenu (&currentChild->itemInfo);
  55421. }
  55422. }
  55423. void selectNextItem (const int delta)
  55424. {
  55425. disableTimerUntilMouseMoves();
  55426. PopupMenu::ItemComponent* mic = 0;
  55427. bool wasLastOne = (currentChild == 0);
  55428. const int numItems = getNumChildComponents();
  55429. for (int i = 0; i < numItems + 1; ++i)
  55430. {
  55431. int index = (delta > 0) ? i : (numItems - 1 - i);
  55432. index = (index + numItems) % numItems;
  55433. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55434. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55435. && wasLastOne)
  55436. break;
  55437. if (mic == currentChild)
  55438. wasLastOne = true;
  55439. }
  55440. setCurrentlyHighlightedChild (mic);
  55441. }
  55442. void disableTimerUntilMouseMoves()
  55443. {
  55444. disableMouseMoves = true;
  55445. if (owner != 0)
  55446. owner->disableTimerUntilMouseMoves();
  55447. }
  55448. Window (const Window&);
  55449. Window& operator= (const Window&);
  55450. };
  55451. PopupMenu::PopupMenu()
  55452. : lookAndFeel (0),
  55453. separatorPending (false)
  55454. {
  55455. }
  55456. PopupMenu::PopupMenu (const PopupMenu& other)
  55457. : lookAndFeel (other.lookAndFeel),
  55458. separatorPending (false)
  55459. {
  55460. items.ensureStorageAllocated (other.items.size());
  55461. for (int i = 0; i < other.items.size(); ++i)
  55462. items.add (new Item (*other.items.getUnchecked(i)));
  55463. }
  55464. PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55465. {
  55466. if (this != &other)
  55467. {
  55468. lookAndFeel = other.lookAndFeel;
  55469. clear();
  55470. items.ensureStorageAllocated (other.items.size());
  55471. for (int i = 0; i < other.items.size(); ++i)
  55472. items.add (new Item (*other.items.getUnchecked(i)));
  55473. }
  55474. return *this;
  55475. }
  55476. PopupMenu::~PopupMenu()
  55477. {
  55478. clear();
  55479. }
  55480. void PopupMenu::clear()
  55481. {
  55482. items.clear();
  55483. separatorPending = false;
  55484. }
  55485. void PopupMenu::addSeparatorIfPending()
  55486. {
  55487. if (separatorPending)
  55488. {
  55489. separatorPending = false;
  55490. if (items.size() > 0)
  55491. items.add (new Item());
  55492. }
  55493. }
  55494. void PopupMenu::addItem (const int itemResultId,
  55495. const String& itemText,
  55496. const bool isActive,
  55497. const bool isTicked,
  55498. const Image* const iconToUse)
  55499. {
  55500. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55501. // didn't pick anything, so you shouldn't use it as the id
  55502. // for an item..
  55503. addSeparatorIfPending();
  55504. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55505. iconToUse, Colours::black, false, 0, 0, 0));
  55506. }
  55507. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  55508. const int commandID,
  55509. const String& displayName)
  55510. {
  55511. jassert (commandManager != 0 && commandID != 0);
  55512. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  55513. if (registeredInfo != 0)
  55514. {
  55515. ApplicationCommandInfo info (*registeredInfo);
  55516. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  55517. addSeparatorIfPending();
  55518. items.add (new Item (commandID,
  55519. displayName.isNotEmpty() ? displayName
  55520. : info.shortName,
  55521. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  55522. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  55523. 0,
  55524. Colours::black,
  55525. false,
  55526. 0, 0,
  55527. commandManager));
  55528. }
  55529. }
  55530. void PopupMenu::addColouredItem (const int itemResultId,
  55531. const String& itemText,
  55532. const Colour& itemTextColour,
  55533. const bool isActive,
  55534. const bool isTicked,
  55535. const Image* const iconToUse)
  55536. {
  55537. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55538. // didn't pick anything, so you shouldn't use it as the id
  55539. // for an item..
  55540. addSeparatorIfPending();
  55541. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55542. iconToUse, itemTextColour, true, 0, 0, 0));
  55543. }
  55544. void PopupMenu::addCustomItem (const int itemResultId,
  55545. PopupMenuCustomComponent* const customComponent)
  55546. {
  55547. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55548. // didn't pick anything, so you shouldn't use it as the id
  55549. // for an item..
  55550. addSeparatorIfPending();
  55551. items.add (new Item (itemResultId, String::empty, true, false, 0,
  55552. Colours::black, false, customComponent, 0, 0));
  55553. }
  55554. class NormalComponentWrapper : public PopupMenuCustomComponent
  55555. {
  55556. public:
  55557. NormalComponentWrapper (Component* const comp,
  55558. const int w, const int h,
  55559. const bool triggerMenuItemAutomaticallyWhenClicked)
  55560. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  55561. width (w),
  55562. height (h)
  55563. {
  55564. addAndMakeVisible (comp);
  55565. }
  55566. ~NormalComponentWrapper() {}
  55567. void getIdealSize (int& idealWidth, int& idealHeight)
  55568. {
  55569. idealWidth = width;
  55570. idealHeight = height;
  55571. }
  55572. void resized()
  55573. {
  55574. if (getChildComponent(0) != 0)
  55575. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  55576. }
  55577. juce_UseDebuggingNewOperator
  55578. private:
  55579. const int width, height;
  55580. NormalComponentWrapper (const NormalComponentWrapper&);
  55581. NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  55582. };
  55583. void PopupMenu::addCustomItem (const int itemResultId,
  55584. Component* customComponent,
  55585. int idealWidth, int idealHeight,
  55586. const bool triggerMenuItemAutomaticallyWhenClicked)
  55587. {
  55588. addCustomItem (itemResultId,
  55589. new NormalComponentWrapper (customComponent,
  55590. idealWidth, idealHeight,
  55591. triggerMenuItemAutomaticallyWhenClicked));
  55592. }
  55593. void PopupMenu::addSubMenu (const String& subMenuName,
  55594. const PopupMenu& subMenu,
  55595. const bool isActive,
  55596. Image* const iconToUse,
  55597. const bool isTicked)
  55598. {
  55599. addSeparatorIfPending();
  55600. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  55601. iconToUse, Colours::black, false, 0, &subMenu, 0));
  55602. }
  55603. void PopupMenu::addSeparator()
  55604. {
  55605. separatorPending = true;
  55606. }
  55607. class HeaderItemComponent : public PopupMenuCustomComponent
  55608. {
  55609. public:
  55610. HeaderItemComponent (const String& name)
  55611. : PopupMenuCustomComponent (false)
  55612. {
  55613. setName (name);
  55614. }
  55615. ~HeaderItemComponent()
  55616. {
  55617. }
  55618. void paint (Graphics& g)
  55619. {
  55620. Font f (getLookAndFeel().getPopupMenuFont());
  55621. f.setBold (true);
  55622. g.setFont (f);
  55623. g.setColour (findColour (PopupMenu::headerTextColourId));
  55624. g.drawFittedText (getName(),
  55625. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  55626. Justification::bottomLeft, 1);
  55627. }
  55628. void getIdealSize (int& idealWidth,
  55629. int& idealHeight)
  55630. {
  55631. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  55632. idealHeight += idealHeight / 2;
  55633. idealWidth += idealWidth / 4;
  55634. }
  55635. juce_UseDebuggingNewOperator
  55636. };
  55637. void PopupMenu::addSectionHeader (const String& title)
  55638. {
  55639. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  55640. }
  55641. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  55642. const int itemIdThatMustBeVisible,
  55643. const int minimumWidth,
  55644. const int maximumNumColumns,
  55645. const int standardItemHeight,
  55646. const bool alignToRectangle,
  55647. Component* menuBarComponent,
  55648. ApplicationCommandManager** managerOfChosenCommand,
  55649. Component* const componentAttachedTo)
  55650. {
  55651. Window* const pw
  55652. = Window::create (*this,
  55653. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  55654. 0,
  55655. x, x + w,
  55656. y, y + h,
  55657. minimumWidth,
  55658. maximumNumColumns,
  55659. standardItemHeight,
  55660. alignToRectangle,
  55661. itemIdThatMustBeVisible,
  55662. menuBarComponent,
  55663. managerOfChosenCommand,
  55664. componentAttachedTo);
  55665. if (pw != 0)
  55666. pw->setVisible (true);
  55667. return pw;
  55668. }
  55669. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  55670. const int itemIdThatMustBeVisible,
  55671. const int minimumWidth,
  55672. const int maximumNumColumns,
  55673. const int standardItemHeight,
  55674. const bool alignToRectangle,
  55675. Component* const componentAttachedTo)
  55676. {
  55677. Component::SafePointer<Component> prevFocused (Component::getCurrentlyFocusedComponent());
  55678. Component::SafePointer<Component> prevTopLevel ((prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0);
  55679. Window::wasHiddenBecauseOfAppChange() = false;
  55680. int result = 0;
  55681. ApplicationCommandManager* managerOfChosenCommand = 0;
  55682. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  55683. itemIdThatMustBeVisible,
  55684. minimumWidth,
  55685. maximumNumColumns > 0 ? maximumNumColumns : 7,
  55686. standardItemHeight,
  55687. alignToRectangle, 0,
  55688. &managerOfChosenCommand,
  55689. componentAttachedTo));
  55690. if (popupComp != 0)
  55691. {
  55692. popupComp->enterModalState (false);
  55693. popupComp->toFront (false); // need to do this after making it modal, or it could
  55694. // be stuck behind other comps that are already modal..
  55695. result = popupComp->runModalLoop();
  55696. popupComp = 0;
  55697. if (! Window::wasHiddenBecauseOfAppChange())
  55698. {
  55699. if (prevTopLevel != 0)
  55700. prevTopLevel->toFront (true);
  55701. if (prevFocused != 0)
  55702. prevFocused->grabKeyboardFocus();
  55703. }
  55704. }
  55705. if (managerOfChosenCommand != 0 && result != 0)
  55706. {
  55707. ApplicationCommandTarget::InvocationInfo info (result);
  55708. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  55709. managerOfChosenCommand->invoke (info, true);
  55710. }
  55711. return result;
  55712. }
  55713. int PopupMenu::show (const int itemIdThatMustBeVisible,
  55714. const int minimumWidth,
  55715. const int maximumNumColumns,
  55716. const int standardItemHeight)
  55717. {
  55718. const Point<int> mousePos (Desktop::getMousePosition());
  55719. return showAt (mousePos.getX(), mousePos.getY(),
  55720. itemIdThatMustBeVisible,
  55721. minimumWidth,
  55722. maximumNumColumns,
  55723. standardItemHeight);
  55724. }
  55725. int PopupMenu::showAt (const int screenX,
  55726. const int screenY,
  55727. const int itemIdThatMustBeVisible,
  55728. const int minimumWidth,
  55729. const int maximumNumColumns,
  55730. const int standardItemHeight)
  55731. {
  55732. return showMenu (screenX, screenY, 1, 1,
  55733. itemIdThatMustBeVisible,
  55734. minimumWidth, maximumNumColumns,
  55735. standardItemHeight,
  55736. false, 0);
  55737. }
  55738. int PopupMenu::showAt (Component* componentToAttachTo,
  55739. const int itemIdThatMustBeVisible,
  55740. const int minimumWidth,
  55741. const int maximumNumColumns,
  55742. const int standardItemHeight)
  55743. {
  55744. if (componentToAttachTo != 0)
  55745. {
  55746. return showMenu (componentToAttachTo->getScreenX(),
  55747. componentToAttachTo->getScreenY(),
  55748. componentToAttachTo->getWidth(),
  55749. componentToAttachTo->getHeight(),
  55750. itemIdThatMustBeVisible,
  55751. minimumWidth,
  55752. maximumNumColumns,
  55753. standardItemHeight,
  55754. true, componentToAttachTo);
  55755. }
  55756. else
  55757. {
  55758. return show (itemIdThatMustBeVisible,
  55759. minimumWidth,
  55760. maximumNumColumns,
  55761. standardItemHeight);
  55762. }
  55763. }
  55764. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  55765. {
  55766. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  55767. {
  55768. Window* const pmw = Window::getActiveWindows()[i];
  55769. if (pmw != 0)
  55770. pmw->dismissMenu (0);
  55771. }
  55772. }
  55773. int PopupMenu::getNumItems() const throw()
  55774. {
  55775. int num = 0;
  55776. for (int i = items.size(); --i >= 0;)
  55777. if (! (items.getUnchecked(i))->isSeparator)
  55778. ++num;
  55779. return num;
  55780. }
  55781. bool PopupMenu::containsCommandItem (const int commandID) const
  55782. {
  55783. for (int i = items.size(); --i >= 0;)
  55784. {
  55785. const Item* mi = items.getUnchecked (i);
  55786. if ((mi->itemId == commandID && mi->commandManager != 0)
  55787. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  55788. {
  55789. return true;
  55790. }
  55791. }
  55792. return false;
  55793. }
  55794. bool PopupMenu::containsAnyActiveItems() const throw()
  55795. {
  55796. for (int i = items.size(); --i >= 0;)
  55797. {
  55798. const Item* const mi = items.getUnchecked (i);
  55799. if (mi->subMenu != 0)
  55800. {
  55801. if (mi->subMenu->containsAnyActiveItems())
  55802. return true;
  55803. }
  55804. else if (mi->active)
  55805. {
  55806. return true;
  55807. }
  55808. }
  55809. return false;
  55810. }
  55811. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  55812. {
  55813. lookAndFeel = newLookAndFeel;
  55814. }
  55815. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  55816. : isHighlighted (false),
  55817. isTriggeredAutomatically (isTriggeredAutomatically_)
  55818. {
  55819. }
  55820. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  55821. {
  55822. }
  55823. void PopupMenuCustomComponent::triggerMenuItem()
  55824. {
  55825. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  55826. if (mic != 0)
  55827. {
  55828. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  55829. if (pmw != 0)
  55830. {
  55831. pmw->dismissMenu (&mic->itemInfo);
  55832. }
  55833. else
  55834. {
  55835. // something must have gone wrong with the component hierarchy if this happens..
  55836. jassertfalse
  55837. }
  55838. }
  55839. else
  55840. {
  55841. // why isn't this component inside a menu? Not much point triggering the item if
  55842. // there's no menu.
  55843. jassertfalse
  55844. }
  55845. }
  55846. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  55847. : subMenu (0),
  55848. itemId (0),
  55849. isSeparator (false),
  55850. isTicked (false),
  55851. isEnabled (false),
  55852. isCustomComponent (false),
  55853. isSectionHeader (false),
  55854. customColour (0),
  55855. customImage (0),
  55856. menu (menu_),
  55857. index (0)
  55858. {
  55859. }
  55860. PopupMenu::MenuItemIterator::~MenuItemIterator()
  55861. {
  55862. }
  55863. bool PopupMenu::MenuItemIterator::next()
  55864. {
  55865. if (index >= menu.items.size())
  55866. return false;
  55867. const Item* const item = menu.items.getUnchecked (index);
  55868. ++index;
  55869. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  55870. subMenu = item->subMenu;
  55871. itemId = item->itemId;
  55872. isSeparator = item->isSeparator;
  55873. isTicked = item->isTicked;
  55874. isEnabled = item->active;
  55875. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  55876. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  55877. customColour = item->usesColour ? &(item->textColour) : 0;
  55878. customImage = item->image;
  55879. commandManager = item->commandManager;
  55880. return true;
  55881. }
  55882. END_JUCE_NAMESPACE
  55883. /*** End of inlined file: juce_PopupMenu.cpp ***/
  55884. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  55885. BEGIN_JUCE_NAMESPACE
  55886. ComponentDragger::ComponentDragger()
  55887. : constrainer (0)
  55888. {
  55889. }
  55890. ComponentDragger::~ComponentDragger()
  55891. {
  55892. }
  55893. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  55894. ComponentBoundsConstrainer* const constrainer_)
  55895. {
  55896. jassert (componentToDrag->isValidComponent());
  55897. if (componentToDrag != 0)
  55898. {
  55899. constrainer = constrainer_;
  55900. originalPos = componentToDrag->relativePositionToGlobal (Point<int>());
  55901. }
  55902. }
  55903. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  55904. {
  55905. jassert (componentToDrag->isValidComponent());
  55906. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  55907. if (componentToDrag != 0)
  55908. {
  55909. Rectangle<int> bounds (componentToDrag->getBounds().withPosition (originalPos));
  55910. const Component* const parentComp = componentToDrag->getParentComponent();
  55911. if (parentComp != 0)
  55912. bounds.setPosition (parentComp->globalPositionToRelative (originalPos));
  55913. bounds.setPosition (bounds.getPosition() + e.getOffsetFromDragStart());
  55914. if (constrainer != 0)
  55915. constrainer->setBoundsForComponent (componentToDrag, bounds, false, false, false, false);
  55916. else
  55917. componentToDrag->setBounds (bounds);
  55918. }
  55919. }
  55920. END_JUCE_NAMESPACE
  55921. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  55922. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  55923. BEGIN_JUCE_NAMESPACE
  55924. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  55925. bool juce_performDragDropText (const String& text, bool& shouldStop);
  55926. class DragImageComponent : public Component,
  55927. public Timer
  55928. {
  55929. public:
  55930. DragImageComponent (Image* const im,
  55931. const String& desc,
  55932. Component* const sourceComponent,
  55933. Component* const mouseDragSource_,
  55934. DragAndDropContainer* const o,
  55935. const Point<int>& imageOffset_)
  55936. : image (im),
  55937. source (sourceComponent),
  55938. mouseDragSource (mouseDragSource_),
  55939. owner (o),
  55940. dragDesc (desc),
  55941. imageOffset (imageOffset_),
  55942. hasCheckedForExternalDrag (false),
  55943. drawImage (true)
  55944. {
  55945. setSize (im->getWidth(), im->getHeight());
  55946. if (mouseDragSource == 0)
  55947. mouseDragSource = source;
  55948. mouseDragSource->addMouseListener (this, false);
  55949. startTimer (200);
  55950. setInterceptsMouseClicks (false, false);
  55951. setAlwaysOnTop (true);
  55952. }
  55953. ~DragImageComponent()
  55954. {
  55955. if (owner->dragImageComponent == this)
  55956. owner->dragImageComponent.release();
  55957. if (mouseDragSource != 0)
  55958. {
  55959. mouseDragSource->removeMouseListener (this);
  55960. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDesc, source))
  55961. getCurrentlyOver()->itemDragExit (dragDesc, source);
  55962. }
  55963. }
  55964. void paint (Graphics& g)
  55965. {
  55966. if (isOpaque())
  55967. g.fillAll (Colours::white);
  55968. if (drawImage)
  55969. {
  55970. g.setOpacity (1.0f);
  55971. g.drawImageAt (image, 0, 0);
  55972. }
  55973. }
  55974. DragAndDropTarget* findTarget (const Point<int>& screenPos, Point<int>& relativePos)
  55975. {
  55976. Component* hit = getParentComponent();
  55977. if (hit == 0)
  55978. {
  55979. hit = Desktop::getInstance().findComponentAt (screenPos);
  55980. }
  55981. else
  55982. {
  55983. const Point<int> relPos (hit->globalPositionToRelative (screenPos));
  55984. hit = hit->getComponentAt (relPos.getX(), relPos.getY());
  55985. }
  55986. // (note: use a local copy of the dragDesc member in case the callback runs
  55987. // a modal loop and deletes this object before the method completes)
  55988. const String dragDescLocal (dragDesc);
  55989. while (hit != 0)
  55990. {
  55991. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  55992. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55993. {
  55994. relativePos = hit->globalPositionToRelative (screenPos);
  55995. return ddt;
  55996. }
  55997. hit = hit->getParentComponent();
  55998. }
  55999. return 0;
  56000. }
  56001. void mouseUp (const MouseEvent& e)
  56002. {
  56003. if (e.originalComponent != this)
  56004. {
  56005. if (mouseDragSource != 0)
  56006. mouseDragSource->removeMouseListener (this);
  56007. bool dropAccepted = false;
  56008. DragAndDropTarget* ddt = 0;
  56009. Point<int> relPos;
  56010. if (isVisible())
  56011. {
  56012. setVisible (false);
  56013. ddt = findTarget (e.getScreenPosition(), relPos);
  56014. // fade this component and remove it - it'll be deleted later by the timer callback
  56015. dropAccepted = ddt != 0;
  56016. setVisible (true);
  56017. if (dropAccepted || source == 0)
  56018. {
  56019. fadeOutComponent (120);
  56020. }
  56021. else
  56022. {
  56023. const Point<int> target (source->relativePositionToGlobal (Point<int> (source->getWidth() / 2,
  56024. source->getHeight() / 2)));
  56025. const Point<int> ourCentre (relativePositionToGlobal (Point<int> (getWidth() / 2,
  56026. getHeight() / 2)));
  56027. fadeOutComponent (120,
  56028. target.getX() - ourCentre.getX(),
  56029. target.getY() - ourCentre.getY());
  56030. }
  56031. }
  56032. if (getParentComponent() != 0)
  56033. getParentComponent()->removeChildComponent (this);
  56034. if (dropAccepted && ddt != 0)
  56035. {
  56036. // (note: use a local copy of the dragDesc member in case the callback runs
  56037. // a modal loop and deletes this object before the method completes)
  56038. const String dragDescLocal (dragDesc);
  56039. currentlyOverComp = 0;
  56040. ddt->itemDropped (dragDescLocal, source, relPos.getX(), relPos.getY());
  56041. }
  56042. // careful - this object could now be deleted..
  56043. }
  56044. }
  56045. void updateLocation (const bool canDoExternalDrag, const Point<int>& screenPos)
  56046. {
  56047. // (note: use a local copy of the dragDesc member in case the callback runs
  56048. // a modal loop and deletes this object before it returns)
  56049. const String dragDescLocal (dragDesc);
  56050. Point<int> newPos (screenPos + imageOffset);
  56051. if (getParentComponent() != 0)
  56052. newPos = getParentComponent()->globalPositionToRelative (newPos);
  56053. //if (newX != getX() || newY != getY())
  56054. {
  56055. setTopLeftPosition (newPos.getX(), newPos.getY());
  56056. Point<int> relPos;
  56057. DragAndDropTarget* const ddt = findTarget (screenPos, relPos);
  56058. Component* ddtComp = dynamic_cast <Component*> (ddt);
  56059. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  56060. if (ddtComp != currentlyOverComp)
  56061. {
  56062. if (currentlyOverComp != 0 && source != 0
  56063. && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  56064. {
  56065. getCurrentlyOver()->itemDragExit (dragDescLocal, source);
  56066. }
  56067. currentlyOverComp = ddtComp;
  56068. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  56069. ddt->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY());
  56070. }
  56071. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  56072. getCurrentlyOver()->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY());
  56073. if (getCurrentlyOver() == 0
  56074. && canDoExternalDrag
  56075. && ! hasCheckedForExternalDrag)
  56076. {
  56077. if (Desktop::getInstance().findComponentAt (screenPos) == 0)
  56078. {
  56079. hasCheckedForExternalDrag = true;
  56080. StringArray files;
  56081. bool canMoveFiles = false;
  56082. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  56083. && files.size() > 0)
  56084. {
  56085. Component::SafePointer<Component> cdw (this);
  56086. setVisible (false);
  56087. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  56088. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  56089. if (cdw != 0)
  56090. delete this;
  56091. return;
  56092. }
  56093. }
  56094. }
  56095. }
  56096. }
  56097. void mouseDrag (const MouseEvent& e)
  56098. {
  56099. if (e.originalComponent != this)
  56100. updateLocation (true, e.getScreenPosition());
  56101. }
  56102. void timerCallback()
  56103. {
  56104. if (source == 0)
  56105. {
  56106. delete this;
  56107. }
  56108. else if (! isMouseButtonDownAnywhere())
  56109. {
  56110. if (mouseDragSource != 0)
  56111. mouseDragSource->removeMouseListener (this);
  56112. delete this;
  56113. }
  56114. }
  56115. private:
  56116. ScopedPointer<Image> image;
  56117. Component::SafePointer<Component> source;
  56118. Component::SafePointer<Component> mouseDragSource;
  56119. DragAndDropContainer* const owner;
  56120. Component::SafePointer<Component> currentlyOverComp;
  56121. DragAndDropTarget* getCurrentlyOver()
  56122. {
  56123. return dynamic_cast <DragAndDropTarget*> (static_cast <Component*> (currentlyOverComp));
  56124. }
  56125. String dragDesc;
  56126. const Point<int> imageOffset;
  56127. bool hasCheckedForExternalDrag, drawImage;
  56128. DragImageComponent (const DragImageComponent&);
  56129. DragImageComponent& operator= (const DragImageComponent&);
  56130. };
  56131. DragAndDropContainer::DragAndDropContainer()
  56132. {
  56133. }
  56134. DragAndDropContainer::~DragAndDropContainer()
  56135. {
  56136. dragImageComponent = 0;
  56137. }
  56138. void DragAndDropContainer::startDragging (const String& sourceDescription,
  56139. Component* sourceComponent,
  56140. Image* dragImage_,
  56141. const bool allowDraggingToExternalWindows,
  56142. const Point<int>* imageOffsetFromMouse)
  56143. {
  56144. ScopedPointer <Image> dragImage (dragImage_);
  56145. if (dragImageComponent == 0)
  56146. {
  56147. Component* const thisComp = dynamic_cast <Component*> (this);
  56148. if (thisComp == 0)
  56149. {
  56150. jassertfalse; // Your DragAndDropContainer needs to be a Component!
  56151. return;
  56152. }
  56153. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource (0);
  56154. if (draggingSource == 0 || ! draggingSource->isDragging())
  56155. {
  56156. jassertfalse; // You must call startDragging() from within a mouseDown or mouseDrag callback!
  56157. return;
  56158. }
  56159. const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
  56160. Point<int> imageOffset;
  56161. if (dragImage == 0)
  56162. {
  56163. dragImage = sourceComponent->createComponentSnapshot (Rectangle<int> (0, 0, sourceComponent->getWidth(), sourceComponent->getHeight()));
  56164. if (dragImage->getFormat() != Image::ARGB)
  56165. {
  56166. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  56167. Graphics g2 (*newIm);
  56168. g2.drawImageAt (dragImage, 0, 0);
  56169. dragImage = newIm;
  56170. }
  56171. dragImage->multiplyAllAlphas (0.6f);
  56172. const int lo = 150;
  56173. const int hi = 400;
  56174. Point<int> relPos (sourceComponent->globalPositionToRelative (lastMouseDown));
  56175. Point<int> clipped (Rectangle<int> (0, 0, dragImage->getWidth(), dragImage->getHeight())
  56176. .getConstrainedPoint (relPos));
  56177. for (int y = dragImage->getHeight(); --y >= 0;)
  56178. {
  56179. const double dy = (y - clipped.getY()) * (y - clipped.getY());
  56180. for (int x = dragImage->getWidth(); --x >= 0;)
  56181. {
  56182. const int dx = x - clipped.getX();
  56183. const int distance = roundToInt (sqrt (dx * dx + dy));
  56184. if (distance > lo)
  56185. {
  56186. const float alpha = (distance > hi) ? 0
  56187. : (hi - distance) / (float) (hi - lo)
  56188. + Random::getSystemRandom().nextFloat() * 0.008f;
  56189. dragImage->multiplyAlphaAt (x, y, alpha);
  56190. }
  56191. }
  56192. }
  56193. imageOffset = -clipped;
  56194. }
  56195. else
  56196. {
  56197. if (imageOffsetFromMouse == 0)
  56198. imageOffset = Point<int> (dragImage->getWidth() / -2,
  56199. dragImage->getHeight() / -2);
  56200. else
  56201. imageOffset = *imageOffsetFromMouse;
  56202. }
  56203. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  56204. draggingSource->getComponentUnderMouse(), this, imageOffset);
  56205. currentDragDesc = sourceDescription;
  56206. if (allowDraggingToExternalWindows)
  56207. {
  56208. if (! Desktop::canUseSemiTransparentWindows())
  56209. dragImageComponent->setOpaque (true);
  56210. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  56211. | ComponentPeer::windowIsTemporary
  56212. | ComponentPeer::windowIgnoresKeyPresses);
  56213. }
  56214. else
  56215. thisComp->addChildComponent (dragImageComponent);
  56216. static_cast <DragImageComponent*> (static_cast <Component*> (dragImageComponent))->updateLocation (false, lastMouseDown);
  56217. dragImageComponent->setVisible (true);
  56218. }
  56219. }
  56220. bool DragAndDropContainer::isDragAndDropActive() const
  56221. {
  56222. return dragImageComponent != 0;
  56223. }
  56224. const String DragAndDropContainer::getCurrentDragDescription() const
  56225. {
  56226. return (dragImageComponent != 0) ? currentDragDesc
  56227. : String::empty;
  56228. }
  56229. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  56230. {
  56231. if (c == 0)
  56232. return 0;
  56233. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56234. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  56235. }
  56236. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  56237. {
  56238. return false;
  56239. }
  56240. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  56241. {
  56242. }
  56243. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  56244. {
  56245. }
  56246. void DragAndDropTarget::itemDragExit (const String&, Component*)
  56247. {
  56248. }
  56249. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  56250. {
  56251. return true;
  56252. }
  56253. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56254. {
  56255. }
  56256. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56257. {
  56258. }
  56259. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56260. {
  56261. }
  56262. END_JUCE_NAMESPACE
  56263. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  56264. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  56265. BEGIN_JUCE_NAMESPACE
  56266. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw();
  56267. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw();
  56268. // isStandard set depending on which interface was used to create the cursor
  56269. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw();
  56270. static CriticalSection activeCursorListLock;
  56271. static VoidArray activeCursors;
  56272. class SharedMouseCursorInternal : public ReferenceCountedObject
  56273. {
  56274. public:
  56275. SharedMouseCursorInternal (const MouseCursor::StandardCursorType type) throw()
  56276. : standardType (type),
  56277. isStandard (true)
  56278. {
  56279. handle = juce_createStandardMouseCursor (standardType);
  56280. activeCursors.add (this);
  56281. }
  56282. SharedMouseCursorInternal (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56283. : standardType (MouseCursor::NormalCursor),
  56284. isStandard (false)
  56285. {
  56286. handle = juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY);
  56287. }
  56288. ~SharedMouseCursorInternal() throw()
  56289. {
  56290. juce_deleteMouseCursor (handle, isStandard);
  56291. activeCursors.removeValue (this);
  56292. }
  56293. void* getHandle() const throw()
  56294. {
  56295. return handle;
  56296. }
  56297. static SharedMouseCursorInternal* findInstance (MouseCursor::StandardCursorType type) throw()
  56298. {
  56299. for (int i = activeCursors.size(); --i >= 0;)
  56300. {
  56301. SharedMouseCursorInternal* const r = (SharedMouseCursorInternal*) activeCursors.getUnchecked(i);
  56302. if (r->standardType == type)
  56303. return r;
  56304. }
  56305. return new SharedMouseCursorInternal (type);
  56306. }
  56307. juce_UseDebuggingNewOperator
  56308. private:
  56309. void* handle;
  56310. const MouseCursor::StandardCursorType standardType;
  56311. const bool isStandard;
  56312. SharedMouseCursorInternal& operator= (const SharedMouseCursorInternal&);
  56313. };
  56314. MouseCursor::MouseCursor() throw()
  56315. {
  56316. const ScopedLock sl (activeCursorListLock);
  56317. cursorHandle = SharedMouseCursorInternal::findInstance (NormalCursor);
  56318. }
  56319. MouseCursor::MouseCursor (const StandardCursorType type) throw()
  56320. {
  56321. const ScopedLock sl (activeCursorListLock);
  56322. cursorHandle = SharedMouseCursorInternal::findInstance (type);
  56323. }
  56324. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56325. {
  56326. const ScopedLock sl (activeCursorListLock);
  56327. cursorHandle = new SharedMouseCursorInternal (image, hotSpotX, hotSpotY);
  56328. }
  56329. MouseCursor::MouseCursor (const MouseCursor& other) throw()
  56330. : cursorHandle (other.cursorHandle)
  56331. {
  56332. }
  56333. MouseCursor::~MouseCursor() throw()
  56334. {
  56335. }
  56336. MouseCursor& MouseCursor::operator= (const MouseCursor& other) throw()
  56337. {
  56338. cursorHandle = other.cursorHandle;
  56339. return *this;
  56340. }
  56341. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56342. {
  56343. return cursorHandle == other.cursorHandle;
  56344. }
  56345. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56346. {
  56347. return cursorHandle != other.cursorHandle;
  56348. }
  56349. void* MouseCursor::getHandle() const throw()
  56350. {
  56351. return cursorHandle->getHandle();
  56352. }
  56353. void MouseCursor::showWaitCursor() throw()
  56354. {
  56355. Desktop::getInstance().getMainMouseSource().showMouseCursor (MouseCursor::WaitCursor);
  56356. }
  56357. void MouseCursor::hideWaitCursor() throw()
  56358. {
  56359. Desktop::getInstance().getMainMouseSource().revealCursor();
  56360. }
  56361. END_JUCE_NAMESPACE
  56362. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56363. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56364. BEGIN_JUCE_NAMESPACE
  56365. MouseEvent::MouseEvent (MouseInputSource& source_,
  56366. const Point<int>& position,
  56367. const ModifierKeys& mods_,
  56368. Component* const originator,
  56369. const Time& eventTime_,
  56370. const Point<int> mouseDownPos_,
  56371. const Time& mouseDownTime_,
  56372. const int numberOfClicks_,
  56373. const bool mouseWasDragged) throw()
  56374. : x (position.getX()),
  56375. y (position.getY()),
  56376. mods (mods_),
  56377. eventComponent (originator),
  56378. originalComponent (originator),
  56379. eventTime (eventTime_),
  56380. source (source_),
  56381. mouseDownPos (mouseDownPos_),
  56382. mouseDownTime (mouseDownTime_),
  56383. numberOfClicks (numberOfClicks_),
  56384. wasMovedSinceMouseDown (mouseWasDragged)
  56385. {
  56386. }
  56387. MouseEvent::~MouseEvent() throw()
  56388. {
  56389. }
  56390. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  56391. {
  56392. if (otherComponent == 0)
  56393. {
  56394. jassertfalse
  56395. return *this;
  56396. }
  56397. return MouseEvent (source, eventComponent->relativePositionToOtherComponent (otherComponent, getPosition()),
  56398. mods, originalComponent, eventTime,
  56399. eventComponent->relativePositionToOtherComponent (otherComponent, mouseDownPos),
  56400. mouseDownTime, numberOfClicks, wasMovedSinceMouseDown);
  56401. }
  56402. const MouseEvent MouseEvent::withNewPosition (const Point<int>& newPosition) const throw()
  56403. {
  56404. return MouseEvent (source, newPosition, mods, originalComponent,
  56405. eventTime, mouseDownPos, mouseDownTime,
  56406. numberOfClicks, wasMovedSinceMouseDown);
  56407. }
  56408. bool MouseEvent::mouseWasClicked() const throw()
  56409. {
  56410. return ! wasMovedSinceMouseDown;
  56411. }
  56412. int MouseEvent::getMouseDownX() const throw()
  56413. {
  56414. return mouseDownPos.getX();
  56415. }
  56416. int MouseEvent::getMouseDownY() const throw()
  56417. {
  56418. return mouseDownPos.getY();
  56419. }
  56420. const Point<int> MouseEvent::getMouseDownPosition() const throw()
  56421. {
  56422. return mouseDownPos;
  56423. }
  56424. int MouseEvent::getDistanceFromDragStartX() const throw()
  56425. {
  56426. return x - mouseDownPos.getX();
  56427. }
  56428. int MouseEvent::getDistanceFromDragStartY() const throw()
  56429. {
  56430. return y - mouseDownPos.getY();
  56431. }
  56432. int MouseEvent::getDistanceFromDragStart() const throw()
  56433. {
  56434. return mouseDownPos.getDistanceFrom (getPosition());
  56435. }
  56436. const Point<int> MouseEvent::getOffsetFromDragStart() const throw()
  56437. {
  56438. return getPosition() - mouseDownPos;
  56439. }
  56440. int MouseEvent::getLengthOfMousePress() const throw()
  56441. {
  56442. if (mouseDownTime.toMilliseconds() > 0)
  56443. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56444. return 0;
  56445. }
  56446. const Point<int> MouseEvent::getPosition() const throw()
  56447. {
  56448. return Point<int> (x, y);
  56449. }
  56450. int MouseEvent::getScreenX() const
  56451. {
  56452. return getScreenPosition().getX();
  56453. }
  56454. int MouseEvent::getScreenY() const
  56455. {
  56456. return getScreenPosition().getY();
  56457. }
  56458. const Point<int> MouseEvent::getScreenPosition() const
  56459. {
  56460. return eventComponent->relativePositionToGlobal (Point<int> (x, y));
  56461. }
  56462. int MouseEvent::getMouseDownScreenX() const
  56463. {
  56464. return getMouseDownScreenPosition().getX();
  56465. }
  56466. int MouseEvent::getMouseDownScreenY() const
  56467. {
  56468. return getMouseDownScreenPosition().getY();
  56469. }
  56470. const Point<int> MouseEvent::getMouseDownScreenPosition() const
  56471. {
  56472. return eventComponent->relativePositionToGlobal (mouseDownPos);
  56473. }
  56474. static int doubleClickTimeOutMs = 400;
  56475. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  56476. {
  56477. doubleClickTimeOutMs = newTime;
  56478. }
  56479. int MouseEvent::getDoubleClickTimeout() throw()
  56480. {
  56481. return doubleClickTimeOutMs;
  56482. }
  56483. END_JUCE_NAMESPACE
  56484. /*** End of inlined file: juce_MouseEvent.cpp ***/
  56485. /*** Start of inlined file: juce_MouseInputSource.cpp ***/
  56486. BEGIN_JUCE_NAMESPACE
  56487. class MouseInputSourceInternal : public AsyncUpdater
  56488. {
  56489. public:
  56490. MouseInputSourceInternal (MouseInputSource& source_, const int index_, const bool isMouseDevice_)
  56491. : index (index_), isMouseDevice (isMouseDevice_), source (source_), lastPeer (0), lastTime (0),
  56492. isUnboundedMouseModeOn (false), isCursorVisibleUntilOffscreen (false), currentCursorHandle (0)
  56493. {
  56494. zerostruct (mouseDowns);
  56495. }
  56496. ~MouseInputSourceInternal()
  56497. {
  56498. }
  56499. bool isDragging() const throw()
  56500. {
  56501. return buttonState.isAnyMouseButtonDown();
  56502. }
  56503. Component* getComponentUnderMouse() const
  56504. {
  56505. return static_cast <Component*> (componentUnderMouse);
  56506. }
  56507. const ModifierKeys getCurrentModifiers() const
  56508. {
  56509. return ModifierKeys::getCurrentModifiers().withoutMouseButtons().withFlags (buttonState.getRawFlags());
  56510. }
  56511. ComponentPeer* getPeer()
  56512. {
  56513. if (! ComponentPeer::isValidPeer (lastPeer))
  56514. lastPeer = 0;
  56515. return lastPeer;
  56516. }
  56517. Component* findComponentAt (const Point<int>& screenPos)
  56518. {
  56519. ComponentPeer* const peer = getPeer();
  56520. if (peer != 0)
  56521. {
  56522. Component* const comp = peer->getComponent();
  56523. const Point<int> relativePos (comp->globalPositionToRelative (screenPos));
  56524. // (the contains() call is needed to test for overlapping desktop windows)
  56525. if (comp->contains (relativePos.getX(), relativePos.getY()))
  56526. return comp->getComponentAt (relativePos);
  56527. }
  56528. return 0;
  56529. }
  56530. const Point<int> getScreenPosition() const throw()
  56531. {
  56532. return lastScreenPos + unboundedMouseOffset;
  56533. }
  56534. void sendMouseEnter (Component* const comp, const Point<int>& screenPos, const int64 time)
  56535. {
  56536. //DBG ("Mouse " + String (source.getIndex()) + " enter: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56537. comp->internalMouseEnter (source, comp->globalPositionToRelative (screenPos), time);
  56538. }
  56539. void sendMouseExit (Component* const comp, const Point<int>& screenPos, const int64 time)
  56540. {
  56541. //DBG ("Mouse " + String (source.getIndex()) + " exit: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56542. comp->internalMouseExit (source, comp->globalPositionToRelative (screenPos), time);
  56543. }
  56544. void sendMouseMove (Component* const comp, const Point<int>& screenPos, const int64 time)
  56545. {
  56546. //DBG ("Mouse " + String (source.getIndex()) + " move: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56547. comp->internalMouseMove (source, comp->globalPositionToRelative (screenPos), time);
  56548. }
  56549. void sendMouseDown (Component* const comp, const Point<int>& screenPos, const int64 time)
  56550. {
  56551. //DBG ("Mouse " + String (source.getIndex()) + " down: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56552. comp->internalMouseDown (source, comp->globalPositionToRelative (screenPos), time);
  56553. }
  56554. void sendMouseDrag (Component* const comp, const Point<int>& screenPos, const int64 time)
  56555. {
  56556. //DBG ("Mouse " + String (source.getIndex()) + " drag: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56557. comp->internalMouseDrag (source, comp->globalPositionToRelative (screenPos), time);
  56558. }
  56559. void sendMouseUp (Component* const comp, const Point<int>& screenPos, const int64 time)
  56560. {
  56561. //DBG ("Mouse " + String (source.getIndex()) + " up: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56562. comp->internalMouseUp (source, comp->globalPositionToRelative (screenPos), time, getCurrentModifiers());
  56563. }
  56564. void sendMouseWheel (Component* const comp, const Point<int>& screenPos, const int64 time, float x, float y)
  56565. {
  56566. //DBG ("Mouse " + String (source.getIndex()) + " wheel: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56567. comp->internalMouseWheel (source, comp->globalPositionToRelative (screenPos), time, x, y);
  56568. }
  56569. void setButtons (const Point<int>& screenPos, const int64 time, const ModifierKeys& newButtonState)
  56570. {
  56571. if (buttonState != newButtonState)
  56572. {
  56573. // (ignore secondary clicks when there's already a button down)
  56574. if (buttonState.isAnyMouseButtonDown() == newButtonState.isAnyMouseButtonDown())
  56575. {
  56576. buttonState = newButtonState;
  56577. return;
  56578. }
  56579. if (buttonState.isAnyMouseButtonDown())
  56580. {
  56581. Component* const current = getComponentUnderMouse();
  56582. if (current != 0)
  56583. sendMouseUp (current, screenPos + unboundedMouseOffset, time);
  56584. enableUnboundedMouseMovement (false, false);
  56585. }
  56586. buttonState = newButtonState;
  56587. if (buttonState.isAnyMouseButtonDown())
  56588. {
  56589. Desktop::getInstance().incrementMouseClickCounter();
  56590. Component* const current = getComponentUnderMouse();
  56591. if (current != 0)
  56592. {
  56593. registerMouseDown (screenPos, time, current);
  56594. sendMouseDown (current, screenPos, time);
  56595. }
  56596. }
  56597. }
  56598. }
  56599. void setComponentUnderMouse (Component* const newComponent, const Point<int>& screenPos, const int64 time)
  56600. {
  56601. Component* current = getComponentUnderMouse();
  56602. if (newComponent != current)
  56603. {
  56604. Component::SafePointer<Component> safeNewComp (newComponent);
  56605. const ModifierKeys originalButtonState (buttonState);
  56606. if (current != 0)
  56607. {
  56608. setButtons (screenPos, time, ModifierKeys());
  56609. sendMouseExit (current, screenPos, time);
  56610. buttonState = originalButtonState;
  56611. }
  56612. componentUnderMouse = safeNewComp;
  56613. current = getComponentUnderMouse();
  56614. if (current != 0)
  56615. sendMouseEnter (current, screenPos, time);
  56616. revealCursor (false);
  56617. setButtons (screenPos, time, originalButtonState);
  56618. }
  56619. }
  56620. void setPeer (ComponentPeer* const newPeer, const Point<int>& screenPos, const int64 time)
  56621. {
  56622. ModifierKeys::updateCurrentModifiers();
  56623. if (newPeer != lastPeer)
  56624. {
  56625. setComponentUnderMouse (0, screenPos, time);
  56626. lastPeer = newPeer;
  56627. setComponentUnderMouse (findComponentAt (screenPos), screenPos, time);
  56628. }
  56629. }
  56630. void setScreenPos (const Point<int>& newScreenPos, const int64 time, const bool forceUpdate)
  56631. {
  56632. if (! isDragging())
  56633. setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time);
  56634. if (newScreenPos != lastScreenPos || forceUpdate)
  56635. {
  56636. cancelPendingUpdate();
  56637. lastScreenPos = newScreenPos;
  56638. Component* const current = getComponentUnderMouse();
  56639. if (current != 0)
  56640. {
  56641. if (isDragging())
  56642. {
  56643. registerMouseDrag (newScreenPos);
  56644. sendMouseDrag (current, newScreenPos + unboundedMouseOffset, time);
  56645. if (isUnboundedMouseModeOn)
  56646. handleUnboundedDrag (current);
  56647. }
  56648. else
  56649. {
  56650. sendMouseMove (current, newScreenPos, time);
  56651. }
  56652. }
  56653. revealCursor (false);
  56654. }
  56655. }
  56656. void handleEvent (ComponentPeer* const newPeer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& newMods)
  56657. {
  56658. jassert (newPeer != 0);
  56659. lastTime = time;
  56660. const Point<int> screenPos (newPeer->relativePositionToGlobal (positionWithinPeer));
  56661. if (isDragging() && newMods.isAnyMouseButtonDown())
  56662. {
  56663. setScreenPos (screenPos, time, false);
  56664. }
  56665. else
  56666. {
  56667. setPeer (newPeer, screenPos, time);
  56668. ComponentPeer* peer = getPeer();
  56669. if (peer != 0)
  56670. {
  56671. setButtons (screenPos, time, newMods);
  56672. peer = getPeer();
  56673. if (peer != 0)
  56674. setScreenPos (peer->relativePositionToGlobal (positionWithinPeer), time, false);
  56675. }
  56676. }
  56677. }
  56678. void handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, int64 time, float x, float y)
  56679. {
  56680. jassert (peer != 0);
  56681. lastTime = time;
  56682. const Point<int> screenPos (peer->relativePositionToGlobal (positionWithinPeer));
  56683. setPeer (peer, screenPos, time);
  56684. setScreenPos (screenPos, time, false);
  56685. triggerFakeMove();
  56686. if (! isDragging())
  56687. {
  56688. Component* current = getComponentUnderMouse();
  56689. if (current != 0)
  56690. sendMouseWheel (current, screenPos, time, x, y);
  56691. }
  56692. }
  56693. const Time getLastMouseDownTime() const throw()
  56694. {
  56695. return Time (mouseDowns[0].time);
  56696. }
  56697. const Point<int> getLastMouseDownPosition() const throw()
  56698. {
  56699. return mouseDowns[0].position;
  56700. }
  56701. int getNumberOfMultipleClicks() const throw()
  56702. {
  56703. int numClicks = 0;
  56704. if (mouseDowns[0].time != 0)
  56705. {
  56706. if (! mouseMovedSignificantlySincePressed)
  56707. ++numClicks;
  56708. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  56709. {
  56710. if (mouseDowns[0].time - mouseDowns[i].time < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  56711. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  56712. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  56713. && mouseDowns[0].component == mouseDowns[i].component)
  56714. {
  56715. ++numClicks;
  56716. }
  56717. else
  56718. {
  56719. break;
  56720. }
  56721. }
  56722. }
  56723. return numClicks;
  56724. }
  56725. bool hasMouseMovedSignificantlySincePressed() const throw()
  56726. {
  56727. return mouseMovedSignificantlySincePressed
  56728. || lastTime > mouseDowns[0].time + 300;
  56729. }
  56730. void triggerFakeMove()
  56731. {
  56732. triggerAsyncUpdate();
  56733. }
  56734. void handleAsyncUpdate()
  56735. {
  56736. if (! isDragging())
  56737. setScreenPos (Desktop::getMousePosition(), jmax (lastTime, Time::currentTimeMillis()), true);
  56738. }
  56739. void enableUnboundedMouseMovement (bool enable, bool keepCursorVisibleUntilOffscreen)
  56740. {
  56741. enable = enable && isDragging();
  56742. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  56743. if (enable != isUnboundedMouseModeOn)
  56744. {
  56745. if ((! enable) && ((! isCursorVisibleUntilOffscreen) || ! unboundedMouseOffset.isOrigin()))
  56746. {
  56747. // when released, return the mouse to within the component's bounds
  56748. Component* current = getComponentUnderMouse();
  56749. if (current != 0)
  56750. Desktop::setMousePosition (current->getScreenBounds()
  56751. .getConstrainedPoint (current->getMouseXYRelative()));
  56752. }
  56753. isUnboundedMouseModeOn = enable;
  56754. unboundedMouseOffset = Point<int>();
  56755. revealCursor (true);
  56756. }
  56757. }
  56758. void handleUnboundedDrag (Component* current)
  56759. {
  56760. const Rectangle<int> screenArea (current->getParentMonitorArea().expanded (-2, -2));
  56761. if (! screenArea.contains (lastScreenPos))
  56762. {
  56763. const Point<int> compPos (current->getScreenPosition());
  56764. int deltaX = 0, deltaY = 0;
  56765. if (lastScreenPos.getX() <= screenArea.getX() || lastScreenPos.getX() >= screenArea.getRight())
  56766. deltaX = compPos.getX() + current->getWidth() / 2 - lastScreenPos.getX();
  56767. if (lastScreenPos.getY() <= screenArea.getY() || lastScreenPos.getY() >= screenArea.getBottom())
  56768. deltaY = compPos.getY() + current->getHeight() / 2 - lastScreenPos.getY();
  56769. const Point<int> delta (deltaX, deltaY);
  56770. unboundedMouseOffset -= delta;
  56771. Desktop::setMousePosition (lastScreenPos + delta);
  56772. }
  56773. else if (isCursorVisibleUntilOffscreen
  56774. && (! unboundedMouseOffset.isOrigin())
  56775. && screenArea.contains (lastScreenPos + unboundedMouseOffset))
  56776. {
  56777. Desktop::setMousePosition (lastScreenPos + unboundedMouseOffset);
  56778. unboundedMouseOffset = Point<int>();
  56779. }
  56780. }
  56781. void showMouseCursor (MouseCursor cursor, bool forcedUpdate)
  56782. {
  56783. if (isUnboundedMouseModeOn && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen))
  56784. {
  56785. cursor = MouseCursor::NoCursor;
  56786. forcedUpdate = true;
  56787. }
  56788. if (forcedUpdate || cursor.getHandle() != currentCursorHandle)
  56789. {
  56790. currentCursorHandle = cursor.getHandle();
  56791. cursor.showInWindow (lastPeer);
  56792. }
  56793. }
  56794. void hideCursor()
  56795. {
  56796. showMouseCursor (MouseCursor::NoCursor, true);
  56797. }
  56798. void revealCursor (bool forcedUpdate)
  56799. {
  56800. MouseCursor mc (MouseCursor::NormalCursor);
  56801. Component* current = getComponentUnderMouse();
  56802. if (current != 0)
  56803. mc = current->getLookAndFeel().getMouseCursorFor (*current);
  56804. showMouseCursor (mc, forcedUpdate);
  56805. }
  56806. int index;
  56807. bool isMouseDevice;
  56808. Point<int> lastScreenPos;
  56809. ModifierKeys buttonState;
  56810. private:
  56811. MouseInputSource& source;
  56812. Component::SafePointer<Component> componentUnderMouse;
  56813. ComponentPeer* lastPeer;
  56814. Point<int> unboundedMouseOffset;
  56815. bool isUnboundedMouseModeOn, isCursorVisibleUntilOffscreen;
  56816. void* currentCursorHandle;
  56817. struct RecentMouseDown
  56818. {
  56819. Point<int> position;
  56820. int64 time;
  56821. Component* component;
  56822. };
  56823. RecentMouseDown mouseDowns[4];
  56824. bool mouseMovedSignificantlySincePressed;
  56825. int64 lastTime;
  56826. void registerMouseDown (const Point<int>& screenPos, const int64 time, Component* const component) throw()
  56827. {
  56828. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  56829. mouseDowns[i] = mouseDowns[i - 1];
  56830. mouseDowns[0].position = screenPos;
  56831. mouseDowns[0].time = time;
  56832. mouseDowns[0].component = component;
  56833. mouseMovedSignificantlySincePressed = false;
  56834. }
  56835. void registerMouseDrag (const Point<int>& screenPos) throw()
  56836. {
  56837. mouseMovedSignificantlySincePressed = mouseMovedSignificantlySincePressed
  56838. || mouseDowns[0].position.getDistanceFrom (screenPos) >= 4;
  56839. }
  56840. };
  56841. MouseInputSource::MouseInputSource (const int index, const bool isMouseDevice)
  56842. {
  56843. pimpl = new MouseInputSourceInternal (*this, index, isMouseDevice);
  56844. }
  56845. MouseInputSource::~MouseInputSource()
  56846. {
  56847. }
  56848. bool MouseInputSource::isMouse() const { return pimpl->isMouseDevice; }
  56849. bool MouseInputSource::isTouch() const { return ! isMouse(); }
  56850. bool MouseInputSource::canHover() const { return isMouse(); }
  56851. bool MouseInputSource::hasMouseWheel() const { return isMouse(); }
  56852. int MouseInputSource::getIndex() const { return pimpl->index; }
  56853. bool MouseInputSource::isDragging() const { return pimpl->isDragging(); }
  56854. const Point<int> MouseInputSource::getScreenPosition() const { return pimpl->getScreenPosition(); }
  56855. const ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); }
  56856. Component* MouseInputSource::getComponentUnderMouse() const { return pimpl->getComponentUnderMouse(); }
  56857. void MouseInputSource::triggerFakeMove() const { pimpl->triggerFakeMove(); }
  56858. int MouseInputSource::getNumberOfMultipleClicks() const throw() { return pimpl->getNumberOfMultipleClicks(); }
  56859. const Time MouseInputSource::getLastMouseDownTime() const throw() { return pimpl->getLastMouseDownTime(); }
  56860. const Point<int> MouseInputSource::getLastMouseDownPosition() const throw() { return pimpl->getLastMouseDownPosition(); }
  56861. bool MouseInputSource::hasMouseMovedSignificantlySincePressed() const throw() { return pimpl->hasMouseMovedSignificantlySincePressed(); }
  56862. bool MouseInputSource::canDoUnboundedMovement() const throw() { return isMouse(); }
  56863. void MouseInputSource::enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen) { pimpl->enableUnboundedMouseMovement (isEnabled, keepCursorVisibleUntilOffscreen); }
  56864. bool MouseInputSource::hasMouseCursor() const throw() { return isMouse(); }
  56865. void MouseInputSource::showMouseCursor (const MouseCursor& cursor) { pimpl->showMouseCursor (cursor, false); }
  56866. void MouseInputSource::hideCursor() { pimpl->hideCursor(); }
  56867. void MouseInputSource::revealCursor() { pimpl->revealCursor (false); }
  56868. void MouseInputSource::handleEvent (ComponentPeer* peer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& mods)
  56869. {
  56870. pimpl->handleEvent (peer, positionWithinPeer, time, mods.withOnlyMouseButtons());
  56871. }
  56872. void MouseInputSource::handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  56873. {
  56874. pimpl->handleWheel (peer, positionWithinPeer, time, x, y);
  56875. }
  56876. END_JUCE_NAMESPACE
  56877. /*** End of inlined file: juce_MouseInputSource.cpp ***/
  56878. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  56879. BEGIN_JUCE_NAMESPACE
  56880. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  56881. : source (0),
  56882. hoverTimeMillisecs (hoverTimeMillisecs_),
  56883. hasJustHovered (false)
  56884. {
  56885. internalTimer.owner = this;
  56886. }
  56887. MouseHoverDetector::~MouseHoverDetector()
  56888. {
  56889. setHoverComponent (0);
  56890. }
  56891. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  56892. {
  56893. hoverTimeMillisecs = newTimeInMillisecs;
  56894. }
  56895. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  56896. {
  56897. if (source != newSourceComponent)
  56898. {
  56899. internalTimer.stopTimer();
  56900. hasJustHovered = false;
  56901. if (source != 0)
  56902. {
  56903. // ! you need to delete the hover detector before deleting its component
  56904. jassert (source->isValidComponent());
  56905. source->removeMouseListener (&internalTimer);
  56906. }
  56907. source = newSourceComponent;
  56908. if (newSourceComponent != 0)
  56909. newSourceComponent->addMouseListener (&internalTimer, false);
  56910. }
  56911. }
  56912. void MouseHoverDetector::hoverTimerCallback()
  56913. {
  56914. internalTimer.stopTimer();
  56915. if (source != 0)
  56916. {
  56917. const Point<int> pos (source->getMouseXYRelative());
  56918. if (source->reallyContains (pos.getX(), pos.getY(), false))
  56919. {
  56920. hasJustHovered = true;
  56921. mouseHovered (pos.getX(), pos.getY());
  56922. }
  56923. }
  56924. }
  56925. void MouseHoverDetector::checkJustHoveredCallback()
  56926. {
  56927. if (hasJustHovered)
  56928. {
  56929. hasJustHovered = false;
  56930. mouseMovedAfterHover();
  56931. }
  56932. }
  56933. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  56934. {
  56935. owner->hoverTimerCallback();
  56936. }
  56937. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  56938. {
  56939. stopTimer();
  56940. owner->checkJustHoveredCallback();
  56941. }
  56942. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  56943. {
  56944. stopTimer();
  56945. owner->checkJustHoveredCallback();
  56946. }
  56947. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  56948. {
  56949. stopTimer();
  56950. owner->checkJustHoveredCallback();
  56951. }
  56952. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  56953. {
  56954. stopTimer();
  56955. owner->checkJustHoveredCallback();
  56956. }
  56957. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  56958. {
  56959. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  56960. {
  56961. lastX = e.x;
  56962. lastY = e.y;
  56963. if (owner->source != 0)
  56964. startTimer (owner->hoverTimeMillisecs);
  56965. owner->checkJustHoveredCallback();
  56966. }
  56967. }
  56968. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  56969. {
  56970. stopTimer();
  56971. owner->checkJustHoveredCallback();
  56972. }
  56973. END_JUCE_NAMESPACE
  56974. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  56975. /*** Start of inlined file: juce_MouseListener.cpp ***/
  56976. BEGIN_JUCE_NAMESPACE
  56977. void MouseListener::mouseEnter (const MouseEvent&)
  56978. {
  56979. }
  56980. void MouseListener::mouseExit (const MouseEvent&)
  56981. {
  56982. }
  56983. void MouseListener::mouseDown (const MouseEvent&)
  56984. {
  56985. }
  56986. void MouseListener::mouseUp (const MouseEvent&)
  56987. {
  56988. }
  56989. void MouseListener::mouseDrag (const MouseEvent&)
  56990. {
  56991. }
  56992. void MouseListener::mouseMove (const MouseEvent&)
  56993. {
  56994. }
  56995. void MouseListener::mouseDoubleClick (const MouseEvent&)
  56996. {
  56997. }
  56998. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  56999. {
  57000. }
  57001. END_JUCE_NAMESPACE
  57002. /*** End of inlined file: juce_MouseListener.cpp ***/
  57003. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  57004. BEGIN_JUCE_NAMESPACE
  57005. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  57006. const String& buttonTextWhenTrue,
  57007. const String& buttonTextWhenFalse)
  57008. : PropertyComponent (name),
  57009. onText (buttonTextWhenTrue),
  57010. offText (buttonTextWhenFalse)
  57011. {
  57012. createButton();
  57013. button->addButtonListener (this);
  57014. }
  57015. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  57016. const String& name,
  57017. const String& buttonText)
  57018. : PropertyComponent (name),
  57019. onText (buttonText),
  57020. offText (buttonText)
  57021. {
  57022. createButton();
  57023. button->setButtonText (buttonText);
  57024. button->getToggleStateValue().referTo (valueToControl);
  57025. button->setClickingTogglesState (true);
  57026. }
  57027. BooleanPropertyComponent::~BooleanPropertyComponent()
  57028. {
  57029. deleteAllChildren();
  57030. }
  57031. void BooleanPropertyComponent::createButton()
  57032. {
  57033. addAndMakeVisible (button = new ToggleButton (String::empty));
  57034. button->setClickingTogglesState (false);
  57035. }
  57036. void BooleanPropertyComponent::setState (const bool newState)
  57037. {
  57038. button->setToggleState (newState, true);
  57039. }
  57040. bool BooleanPropertyComponent::getState() const
  57041. {
  57042. return button->getToggleState();
  57043. }
  57044. void BooleanPropertyComponent::paint (Graphics& g)
  57045. {
  57046. PropertyComponent::paint (g);
  57047. const Rectangle<int> r (button->getBounds());
  57048. g.setColour (Colours::white);
  57049. g.fillRect (r);
  57050. g.setColour (findColour (ComboBox::outlineColourId));
  57051. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  57052. }
  57053. void BooleanPropertyComponent::refresh()
  57054. {
  57055. button->setToggleState (getState(), false);
  57056. button->setButtonText (button->getToggleState() ? onText : offText);
  57057. }
  57058. void BooleanPropertyComponent::buttonClicked (Button*)
  57059. {
  57060. setState (! getState());
  57061. }
  57062. END_JUCE_NAMESPACE
  57063. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  57064. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  57065. BEGIN_JUCE_NAMESPACE
  57066. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  57067. const bool triggerOnMouseDown)
  57068. : PropertyComponent (name)
  57069. {
  57070. addAndMakeVisible (button = new TextButton (String::empty));
  57071. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  57072. button->addButtonListener (this);
  57073. }
  57074. ButtonPropertyComponent::~ButtonPropertyComponent()
  57075. {
  57076. deleteAllChildren();
  57077. }
  57078. void ButtonPropertyComponent::refresh()
  57079. {
  57080. button->setButtonText (getButtonText());
  57081. }
  57082. void ButtonPropertyComponent::buttonClicked (Button*)
  57083. {
  57084. buttonClicked();
  57085. }
  57086. END_JUCE_NAMESPACE
  57087. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  57088. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57089. BEGIN_JUCE_NAMESPACE
  57090. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  57091. : PropertyComponent (name),
  57092. comboBox (0)
  57093. {
  57094. }
  57095. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  57096. const String& name,
  57097. const StringArray& choices_,
  57098. const Array <int>* choiceIDs)
  57099. : PropertyComponent (name),
  57100. choices (choices_),
  57101. comboBox (0)
  57102. {
  57103. createComboBox (choiceIDs);
  57104. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  57105. }
  57106. ChoicePropertyComponent::~ChoicePropertyComponent()
  57107. {
  57108. deleteAllChildren();
  57109. }
  57110. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  57111. {
  57112. // The array of IDs must contain the same number of values as the choices list!
  57113. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  57114. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  57115. for (int i = 0; i < choices.size(); ++i)
  57116. {
  57117. if (choices[i].isNotEmpty())
  57118. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  57119. : ((*choiceIDs)[i]));
  57120. else
  57121. comboBox->addSeparator();
  57122. }
  57123. comboBox->setEditableText (false);
  57124. }
  57125. void ChoicePropertyComponent::setIndex (const int newIndex)
  57126. {
  57127. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  57128. }
  57129. int ChoicePropertyComponent::getIndex() const
  57130. {
  57131. return comboBox->getSelectedItemIndex();
  57132. }
  57133. const StringArray& ChoicePropertyComponent::getChoices() const
  57134. {
  57135. return choices;
  57136. }
  57137. void ChoicePropertyComponent::refresh()
  57138. {
  57139. if (comboBox == 0)
  57140. {
  57141. createComboBox (0);
  57142. comboBox->addListener (this);
  57143. }
  57144. comboBox->setSelectedId (getIndex() + 1, true);
  57145. }
  57146. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  57147. {
  57148. const int newIndex = comboBox->getSelectedId() - 1;
  57149. if (newIndex != getIndex())
  57150. setIndex (newIndex);
  57151. }
  57152. END_JUCE_NAMESPACE
  57153. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57154. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  57155. BEGIN_JUCE_NAMESPACE
  57156. PropertyComponent::PropertyComponent (const String& name,
  57157. const int preferredHeight_)
  57158. : Component (name),
  57159. preferredHeight (preferredHeight_)
  57160. {
  57161. jassert (name.isNotEmpty());
  57162. }
  57163. PropertyComponent::~PropertyComponent()
  57164. {
  57165. }
  57166. void PropertyComponent::paint (Graphics& g)
  57167. {
  57168. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  57169. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  57170. }
  57171. void PropertyComponent::resized()
  57172. {
  57173. if (getNumChildComponents() > 0)
  57174. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  57175. }
  57176. void PropertyComponent::enablementChanged()
  57177. {
  57178. repaint();
  57179. }
  57180. END_JUCE_NAMESPACE
  57181. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  57182. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  57183. BEGIN_JUCE_NAMESPACE
  57184. class PropertyHolderComponent : public Component
  57185. {
  57186. public:
  57187. PropertyHolderComponent()
  57188. {
  57189. }
  57190. ~PropertyHolderComponent()
  57191. {
  57192. deleteAllChildren();
  57193. }
  57194. void paint (Graphics&)
  57195. {
  57196. }
  57197. void updateLayout (const int width);
  57198. void refreshAll() const;
  57199. };
  57200. class PropertySectionComponent : public Component
  57201. {
  57202. public:
  57203. PropertySectionComponent (const String& sectionTitle,
  57204. const Array <PropertyComponent*>& newProperties,
  57205. const bool open)
  57206. : Component (sectionTitle),
  57207. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  57208. isOpen_ (open)
  57209. {
  57210. for (int i = newProperties.size(); --i >= 0;)
  57211. {
  57212. addAndMakeVisible (newProperties.getUnchecked(i));
  57213. newProperties.getUnchecked(i)->refresh();
  57214. }
  57215. }
  57216. ~PropertySectionComponent()
  57217. {
  57218. deleteAllChildren();
  57219. }
  57220. void paint (Graphics& g)
  57221. {
  57222. if (titleHeight > 0)
  57223. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  57224. }
  57225. void resized()
  57226. {
  57227. int y = titleHeight;
  57228. for (int i = getNumChildComponents(); --i >= 0;)
  57229. {
  57230. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57231. if (pec != 0)
  57232. {
  57233. const int prefH = pec->getPreferredHeight();
  57234. pec->setBounds (1, y, getWidth() - 2, prefH);
  57235. y += prefH;
  57236. }
  57237. }
  57238. }
  57239. int getPreferredHeight() const
  57240. {
  57241. int y = titleHeight;
  57242. if (isOpen())
  57243. {
  57244. for (int i = 0; i < getNumChildComponents(); ++i)
  57245. {
  57246. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57247. if (pec != 0)
  57248. y += pec->getPreferredHeight();
  57249. }
  57250. }
  57251. return y;
  57252. }
  57253. void setOpen (const bool open)
  57254. {
  57255. if (isOpen_ != open)
  57256. {
  57257. isOpen_ = open;
  57258. for (int i = 0; i < getNumChildComponents(); ++i)
  57259. {
  57260. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57261. if (pec != 0)
  57262. pec->setVisible (open);
  57263. }
  57264. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57265. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57266. if (pp != 0)
  57267. pp->resized();
  57268. }
  57269. }
  57270. bool isOpen() const
  57271. {
  57272. return isOpen_;
  57273. }
  57274. void refreshAll() const
  57275. {
  57276. for (int i = 0; i < getNumChildComponents(); ++i)
  57277. {
  57278. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57279. if (pec != 0)
  57280. pec->refresh();
  57281. }
  57282. }
  57283. void mouseDown (const MouseEvent&)
  57284. {
  57285. }
  57286. void mouseUp (const MouseEvent& e)
  57287. {
  57288. if (e.getMouseDownX() < titleHeight
  57289. && e.x < titleHeight
  57290. && e.y < titleHeight
  57291. && e.getNumberOfClicks() != 2)
  57292. {
  57293. setOpen (! isOpen());
  57294. }
  57295. }
  57296. void mouseDoubleClick (const MouseEvent& e)
  57297. {
  57298. if (e.y < titleHeight)
  57299. setOpen (! isOpen());
  57300. }
  57301. private:
  57302. int titleHeight;
  57303. bool isOpen_;
  57304. };
  57305. void PropertyHolderComponent::updateLayout (const int width)
  57306. {
  57307. int y = 0;
  57308. for (int i = getNumChildComponents(); --i >= 0;)
  57309. {
  57310. PropertySectionComponent* const section
  57311. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57312. if (section != 0)
  57313. {
  57314. const int prefH = section->getPreferredHeight();
  57315. section->setBounds (0, y, width, prefH);
  57316. y += prefH;
  57317. }
  57318. }
  57319. setSize (width, y);
  57320. repaint();
  57321. }
  57322. void PropertyHolderComponent::refreshAll() const
  57323. {
  57324. for (int i = getNumChildComponents(); --i >= 0;)
  57325. {
  57326. PropertySectionComponent* const section
  57327. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57328. if (section != 0)
  57329. section->refreshAll();
  57330. }
  57331. }
  57332. PropertyPanel::PropertyPanel()
  57333. {
  57334. messageWhenEmpty = TRANS("(nothing selected)");
  57335. addAndMakeVisible (viewport = new Viewport());
  57336. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57337. viewport->setFocusContainer (true);
  57338. }
  57339. PropertyPanel::~PropertyPanel()
  57340. {
  57341. clear();
  57342. deleteAllChildren();
  57343. }
  57344. void PropertyPanel::paint (Graphics& g)
  57345. {
  57346. if (propertyHolderComponent->getNumChildComponents() == 0)
  57347. {
  57348. g.setColour (Colours::black.withAlpha (0.5f));
  57349. g.setFont (14.0f);
  57350. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57351. Justification::centred, true);
  57352. }
  57353. }
  57354. void PropertyPanel::resized()
  57355. {
  57356. viewport->setBounds (0, 0, getWidth(), getHeight());
  57357. updatePropHolderLayout();
  57358. }
  57359. void PropertyPanel::clear()
  57360. {
  57361. if (propertyHolderComponent->getNumChildComponents() > 0)
  57362. {
  57363. propertyHolderComponent->deleteAllChildren();
  57364. repaint();
  57365. }
  57366. }
  57367. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57368. {
  57369. if (propertyHolderComponent->getNumChildComponents() == 0)
  57370. repaint();
  57371. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57372. newProperties,
  57373. true), 0);
  57374. updatePropHolderLayout();
  57375. }
  57376. void PropertyPanel::addSection (const String& sectionTitle,
  57377. const Array <PropertyComponent*>& newProperties,
  57378. const bool shouldBeOpen)
  57379. {
  57380. jassert (sectionTitle.isNotEmpty());
  57381. if (propertyHolderComponent->getNumChildComponents() == 0)
  57382. repaint();
  57383. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57384. newProperties,
  57385. shouldBeOpen), 0);
  57386. updatePropHolderLayout();
  57387. }
  57388. void PropertyPanel::updatePropHolderLayout() const
  57389. {
  57390. const int maxWidth = viewport->getMaximumVisibleWidth();
  57391. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (maxWidth);
  57392. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57393. if (maxWidth != newMaxWidth)
  57394. {
  57395. // need to do this twice because of scrollbars changing the size, etc.
  57396. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (newMaxWidth);
  57397. }
  57398. }
  57399. void PropertyPanel::refreshAll() const
  57400. {
  57401. ((PropertyHolderComponent*) propertyHolderComponent)->refreshAll();
  57402. }
  57403. const StringArray PropertyPanel::getSectionNames() const
  57404. {
  57405. StringArray s;
  57406. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57407. {
  57408. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57409. if (section != 0 && section->getName().isNotEmpty())
  57410. s.add (section->getName());
  57411. }
  57412. return s;
  57413. }
  57414. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57415. {
  57416. int index = 0;
  57417. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57418. {
  57419. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57420. if (section != 0 && section->getName().isNotEmpty())
  57421. {
  57422. if (index == sectionIndex)
  57423. return section->isOpen();
  57424. ++index;
  57425. }
  57426. }
  57427. return false;
  57428. }
  57429. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57430. {
  57431. int index = 0;
  57432. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57433. {
  57434. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57435. if (section != 0 && section->getName().isNotEmpty())
  57436. {
  57437. if (index == sectionIndex)
  57438. {
  57439. section->setOpen (shouldBeOpen);
  57440. break;
  57441. }
  57442. ++index;
  57443. }
  57444. }
  57445. }
  57446. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57447. {
  57448. int index = 0;
  57449. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57450. {
  57451. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57452. if (section != 0 && section->getName().isNotEmpty())
  57453. {
  57454. if (index == sectionIndex)
  57455. {
  57456. section->setEnabled (shouldBeEnabled);
  57457. break;
  57458. }
  57459. ++index;
  57460. }
  57461. }
  57462. }
  57463. XmlElement* PropertyPanel::getOpennessState() const
  57464. {
  57465. XmlElement* const xml = new XmlElement (T("PROPERTYPANELSTATE"));
  57466. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57467. const StringArray sections (getSectionNames());
  57468. for (int i = 0; i < sections.size(); ++i)
  57469. {
  57470. if (sections[i].isNotEmpty())
  57471. {
  57472. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57473. e->setAttribute ("name", sections[i]);
  57474. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57475. }
  57476. }
  57477. return xml;
  57478. }
  57479. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57480. {
  57481. if (xml.hasTagName (T("PROPERTYPANELSTATE")))
  57482. {
  57483. const StringArray sections (getSectionNames());
  57484. forEachXmlChildElementWithTagName (xml, e, T("SECTION"))
  57485. {
  57486. setSectionOpen (sections.indexOf (e->getStringAttribute (T("name"))),
  57487. e->getBoolAttribute (T("open")));
  57488. }
  57489. viewport->setViewPosition (viewport->getViewPositionX(),
  57490. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57491. }
  57492. }
  57493. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57494. {
  57495. if (messageWhenEmpty != newMessage)
  57496. {
  57497. messageWhenEmpty = newMessage;
  57498. repaint();
  57499. }
  57500. }
  57501. const String& PropertyPanel::getMessageWhenEmpty() const
  57502. {
  57503. return messageWhenEmpty;
  57504. }
  57505. END_JUCE_NAMESPACE
  57506. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57507. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57508. BEGIN_JUCE_NAMESPACE
  57509. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57510. const double rangeMin,
  57511. const double rangeMax,
  57512. const double interval,
  57513. const double skewFactor)
  57514. : PropertyComponent (name)
  57515. {
  57516. addAndMakeVisible (slider = new Slider (name));
  57517. slider->setRange (rangeMin, rangeMax, interval);
  57518. slider->setSkewFactor (skewFactor);
  57519. slider->setSliderStyle (Slider::LinearBar);
  57520. slider->addListener (this);
  57521. }
  57522. SliderPropertyComponent::SliderPropertyComponent (Value& valueToControl,
  57523. const String& name,
  57524. const double rangeMin,
  57525. const double rangeMax,
  57526. const double interval,
  57527. const double skewFactor)
  57528. : PropertyComponent (name)
  57529. {
  57530. addAndMakeVisible (slider = new Slider (name));
  57531. slider->setRange (rangeMin, rangeMax, interval);
  57532. slider->setSkewFactor (skewFactor);
  57533. slider->setSliderStyle (Slider::LinearBar);
  57534. slider->getValueObject().referTo (valueToControl);
  57535. }
  57536. SliderPropertyComponent::~SliderPropertyComponent()
  57537. {
  57538. deleteAllChildren();
  57539. }
  57540. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57541. {
  57542. }
  57543. const double SliderPropertyComponent::getValue() const
  57544. {
  57545. return slider->getValue();
  57546. }
  57547. void SliderPropertyComponent::refresh()
  57548. {
  57549. slider->setValue (getValue(), false);
  57550. }
  57551. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57552. {
  57553. if (getValue() != slider->getValue())
  57554. setValue (slider->getValue());
  57555. }
  57556. END_JUCE_NAMESPACE
  57557. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57558. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57559. BEGIN_JUCE_NAMESPACE
  57560. class TextPropLabel : public Label
  57561. {
  57562. TextPropertyComponent& owner;
  57563. int maxChars;
  57564. bool isMultiline;
  57565. public:
  57566. TextPropLabel (TextPropertyComponent& owner_,
  57567. const int maxChars_, const bool isMultiline_)
  57568. : Label (String::empty, String::empty),
  57569. owner (owner_),
  57570. maxChars (maxChars_),
  57571. isMultiline (isMultiline_)
  57572. {
  57573. setEditable (true, true, false);
  57574. setColour (backgroundColourId, Colours::white);
  57575. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57576. }
  57577. ~TextPropLabel()
  57578. {
  57579. }
  57580. TextEditor* createEditorComponent()
  57581. {
  57582. TextEditor* const textEditor = Label::createEditorComponent();
  57583. textEditor->setInputRestrictions (maxChars);
  57584. if (isMultiline)
  57585. {
  57586. textEditor->setMultiLine (true, true);
  57587. textEditor->setReturnKeyStartsNewLine (true);
  57588. }
  57589. return textEditor;
  57590. }
  57591. void textWasEdited()
  57592. {
  57593. owner.textWasEdited();
  57594. }
  57595. };
  57596. TextPropertyComponent::TextPropertyComponent (const String& name,
  57597. const int maxNumChars,
  57598. const bool isMultiLine)
  57599. : PropertyComponent (name)
  57600. {
  57601. createEditor (maxNumChars, isMultiLine);
  57602. }
  57603. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57604. const String& name,
  57605. const int maxNumChars,
  57606. const bool isMultiLine)
  57607. : PropertyComponent (name)
  57608. {
  57609. createEditor (maxNumChars, isMultiLine);
  57610. textEditor->getTextValue().referTo (valueToControl);
  57611. }
  57612. TextPropertyComponent::~TextPropertyComponent()
  57613. {
  57614. deleteAllChildren();
  57615. }
  57616. void TextPropertyComponent::setText (const String& newText)
  57617. {
  57618. textEditor->setText (newText, true);
  57619. }
  57620. const String TextPropertyComponent::getText() const
  57621. {
  57622. return textEditor->getText();
  57623. }
  57624. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57625. {
  57626. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57627. if (isMultiLine)
  57628. {
  57629. textEditor->setJustificationType (Justification::topLeft);
  57630. preferredHeight = 120;
  57631. }
  57632. }
  57633. void TextPropertyComponent::refresh()
  57634. {
  57635. textEditor->setText (getText(), false);
  57636. }
  57637. void TextPropertyComponent::textWasEdited()
  57638. {
  57639. const String newText (textEditor->getText());
  57640. if (getText() != newText)
  57641. setText (newText);
  57642. }
  57643. END_JUCE_NAMESPACE
  57644. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57645. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57646. BEGIN_JUCE_NAMESPACE
  57647. class SimpleDeviceManagerInputLevelMeter : public Component,
  57648. public Timer
  57649. {
  57650. public:
  57651. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57652. : manager (manager_),
  57653. level (0)
  57654. {
  57655. startTimer (50);
  57656. manager->enableInputLevelMeasurement (true);
  57657. }
  57658. ~SimpleDeviceManagerInputLevelMeter()
  57659. {
  57660. manager->enableInputLevelMeasurement (false);
  57661. }
  57662. void timerCallback()
  57663. {
  57664. const float newLevel = (float) manager->getCurrentInputLevel();
  57665. if (fabsf (level - newLevel) > 0.005f)
  57666. {
  57667. level = newLevel;
  57668. repaint();
  57669. }
  57670. }
  57671. void paint (Graphics& g)
  57672. {
  57673. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57674. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57675. }
  57676. private:
  57677. AudioDeviceManager* const manager;
  57678. float level;
  57679. };
  57680. class MidiInputSelectorComponentListBox : public ListBox,
  57681. public ListBoxModel
  57682. {
  57683. public:
  57684. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57685. const String& noItemsMessage_,
  57686. const int minNumber_,
  57687. const int maxNumber_)
  57688. : ListBox (String::empty, 0),
  57689. deviceManager (deviceManager_),
  57690. noItemsMessage (noItemsMessage_),
  57691. minNumber (minNumber_),
  57692. maxNumber (maxNumber_)
  57693. {
  57694. items = MidiInput::getDevices();
  57695. setModel (this);
  57696. setOutlineThickness (1);
  57697. }
  57698. ~MidiInputSelectorComponentListBox()
  57699. {
  57700. }
  57701. int getNumRows()
  57702. {
  57703. return items.size();
  57704. }
  57705. void paintListBoxItem (int row,
  57706. Graphics& g,
  57707. int width, int height,
  57708. bool rowIsSelected)
  57709. {
  57710. if (((unsigned int) row) < (unsigned int) items.size())
  57711. {
  57712. if (rowIsSelected)
  57713. g.fillAll (findColour (TextEditor::highlightColourId)
  57714. .withMultipliedAlpha (0.3f));
  57715. const String item (items [row]);
  57716. bool enabled = deviceManager.isMidiInputEnabled (item);
  57717. const int x = getTickX();
  57718. const float tickW = height * 0.75f;
  57719. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57720. enabled, true, true, false);
  57721. g.setFont (height * 0.6f);
  57722. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57723. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57724. }
  57725. }
  57726. void listBoxItemClicked (int row, const MouseEvent& e)
  57727. {
  57728. selectRow (row);
  57729. if (e.x < getTickX())
  57730. flipEnablement (row);
  57731. }
  57732. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57733. {
  57734. flipEnablement (row);
  57735. }
  57736. void returnKeyPressed (int row)
  57737. {
  57738. flipEnablement (row);
  57739. }
  57740. void paint (Graphics& g)
  57741. {
  57742. ListBox::paint (g);
  57743. if (items.size() == 0)
  57744. {
  57745. g.setColour (Colours::grey);
  57746. g.setFont (13.0f);
  57747. g.drawText (noItemsMessage,
  57748. 0, 0, getWidth(), getHeight() / 2,
  57749. Justification::centred, true);
  57750. }
  57751. }
  57752. int getBestHeight (const int preferredHeight)
  57753. {
  57754. const int extra = getOutlineThickness() * 2;
  57755. return jmax (getRowHeight() * 2 + extra,
  57756. jmin (getRowHeight() * getNumRows() + extra,
  57757. preferredHeight));
  57758. }
  57759. juce_UseDebuggingNewOperator
  57760. private:
  57761. AudioDeviceManager& deviceManager;
  57762. const String noItemsMessage;
  57763. StringArray items;
  57764. int minNumber, maxNumber;
  57765. void flipEnablement (const int row)
  57766. {
  57767. if (((unsigned int) row) < (unsigned int) items.size())
  57768. {
  57769. const String item (items [row]);
  57770. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57771. }
  57772. }
  57773. int getTickX() const
  57774. {
  57775. return getRowHeight() + 5;
  57776. }
  57777. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57778. MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57779. };
  57780. class AudioDeviceSettingsPanel : public Component,
  57781. public ComboBoxListener,
  57782. public ChangeListener,
  57783. public ButtonListener
  57784. {
  57785. public:
  57786. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57787. AudioIODeviceType::DeviceSetupDetails& setup_,
  57788. const bool hideAdvancedOptionsWithButton)
  57789. : type (type_),
  57790. setup (setup_)
  57791. {
  57792. sampleRateDropDown = 0;
  57793. sampleRateLabel = 0;
  57794. bufferSizeDropDown = 0;
  57795. bufferSizeLabel = 0;
  57796. outputDeviceDropDown = 0;
  57797. outputDeviceLabel = 0;
  57798. inputDeviceDropDown = 0;
  57799. inputDeviceLabel = 0;
  57800. testButton = 0;
  57801. inputLevelMeter = 0;
  57802. showUIButton = 0;
  57803. inputChanList = 0;
  57804. outputChanList = 0;
  57805. inputChanLabel = 0;
  57806. outputChanLabel = 0;
  57807. showAdvancedSettingsButton = 0;
  57808. if (hideAdvancedOptionsWithButton)
  57809. {
  57810. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57811. showAdvancedSettingsButton->addButtonListener (this);
  57812. }
  57813. type->scanForDevices();
  57814. setup.manager->addChangeListener (this);
  57815. changeListenerCallback (0);
  57816. }
  57817. ~AudioDeviceSettingsPanel()
  57818. {
  57819. setup.manager->removeChangeListener (this);
  57820. deleteAndZero (outputDeviceLabel);
  57821. deleteAndZero (inputDeviceLabel);
  57822. deleteAndZero (sampleRateLabel);
  57823. deleteAndZero (bufferSizeLabel);
  57824. deleteAndZero (showUIButton);
  57825. deleteAndZero (inputChanLabel);
  57826. deleteAndZero (outputChanLabel);
  57827. deleteAndZero (showAdvancedSettingsButton);
  57828. deleteAllChildren();
  57829. }
  57830. void resized()
  57831. {
  57832. const int lx = proportionOfWidth (0.35f);
  57833. const int w = proportionOfWidth (0.4f);
  57834. const int h = 24;
  57835. const int space = 6;
  57836. const int dh = h + space;
  57837. int y = 0;
  57838. if (outputDeviceDropDown != 0)
  57839. {
  57840. outputDeviceDropDown->setBounds (lx, y, w, h);
  57841. if (testButton != 0)
  57842. testButton->setBounds (proportionOfWidth (0.77f),
  57843. outputDeviceDropDown->getY(),
  57844. proportionOfWidth (0.18f),
  57845. h);
  57846. y += dh;
  57847. }
  57848. if (inputDeviceDropDown != 0)
  57849. {
  57850. inputDeviceDropDown->setBounds (lx, y, w, h);
  57851. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  57852. inputDeviceDropDown->getY(),
  57853. proportionOfWidth (0.18f),
  57854. h);
  57855. y += dh;
  57856. }
  57857. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  57858. if (outputChanList != 0)
  57859. {
  57860. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  57861. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57862. y += bh + space;
  57863. }
  57864. if (inputChanList != 0)
  57865. {
  57866. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  57867. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57868. y += bh + space;
  57869. }
  57870. y += space * 2;
  57871. if (showAdvancedSettingsButton != 0)
  57872. {
  57873. showAdvancedSettingsButton->changeWidthToFitText (h);
  57874. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  57875. }
  57876. if (sampleRateDropDown != 0)
  57877. {
  57878. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  57879. || ! showAdvancedSettingsButton->isVisible());
  57880. sampleRateDropDown->setBounds (lx, y, w, h);
  57881. y += dh;
  57882. }
  57883. if (bufferSizeDropDown != 0)
  57884. {
  57885. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  57886. || ! showAdvancedSettingsButton->isVisible());
  57887. bufferSizeDropDown->setBounds (lx, y, w, h);
  57888. y += dh;
  57889. }
  57890. if (showUIButton != 0)
  57891. {
  57892. showUIButton->setVisible (showAdvancedSettingsButton == 0
  57893. || ! showAdvancedSettingsButton->isVisible());
  57894. showUIButton->changeWidthToFitText (h);
  57895. showUIButton->setTopLeftPosition (lx, y);
  57896. }
  57897. }
  57898. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  57899. {
  57900. if (comboBoxThatHasChanged == 0)
  57901. return;
  57902. AudioDeviceManager::AudioDeviceSetup config;
  57903. setup.manager->getAudioDeviceSetup (config);
  57904. String error;
  57905. if (comboBoxThatHasChanged == outputDeviceDropDown
  57906. || comboBoxThatHasChanged == inputDeviceDropDown)
  57907. {
  57908. if (outputDeviceDropDown != 0)
  57909. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57910. : outputDeviceDropDown->getText();
  57911. if (inputDeviceDropDown != 0)
  57912. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57913. : inputDeviceDropDown->getText();
  57914. if (! type->hasSeparateInputsAndOutputs())
  57915. config.inputDeviceName = config.outputDeviceName;
  57916. if (comboBoxThatHasChanged == inputDeviceDropDown)
  57917. config.useDefaultInputChannels = true;
  57918. else
  57919. config.useDefaultOutputChannels = true;
  57920. error = setup.manager->setAudioDeviceSetup (config, true);
  57921. showCorrectDeviceName (inputDeviceDropDown, true);
  57922. showCorrectDeviceName (outputDeviceDropDown, false);
  57923. updateControlPanelButton();
  57924. resized();
  57925. }
  57926. else if (comboBoxThatHasChanged == sampleRateDropDown)
  57927. {
  57928. if (sampleRateDropDown->getSelectedId() > 0)
  57929. {
  57930. config.sampleRate = sampleRateDropDown->getSelectedId();
  57931. error = setup.manager->setAudioDeviceSetup (config, true);
  57932. }
  57933. }
  57934. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  57935. {
  57936. if (bufferSizeDropDown->getSelectedId() > 0)
  57937. {
  57938. config.bufferSize = bufferSizeDropDown->getSelectedId();
  57939. error = setup.manager->setAudioDeviceSetup (config, true);
  57940. }
  57941. }
  57942. if (error.isNotEmpty())
  57943. {
  57944. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  57945. T("Error when trying to open audio device!"),
  57946. error);
  57947. }
  57948. }
  57949. void buttonClicked (Button* button)
  57950. {
  57951. if (button == showAdvancedSettingsButton)
  57952. {
  57953. showAdvancedSettingsButton->setVisible (false);
  57954. resized();
  57955. }
  57956. else if (button == showUIButton)
  57957. {
  57958. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  57959. if (device != 0 && device->showControlPanel())
  57960. {
  57961. setup.manager->closeAudioDevice();
  57962. setup.manager->restartLastAudioDevice();
  57963. getTopLevelComponent()->toFront (true);
  57964. }
  57965. }
  57966. else if (button == testButton && testButton != 0)
  57967. {
  57968. setup.manager->playTestSound();
  57969. }
  57970. }
  57971. void updateControlPanelButton()
  57972. {
  57973. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57974. deleteAndZero (showUIButton);
  57975. if (currentDevice != 0 && currentDevice->hasControlPanel())
  57976. {
  57977. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  57978. TRANS ("opens the device's own control panel")));
  57979. showUIButton->addButtonListener (this);
  57980. }
  57981. resized();
  57982. }
  57983. void changeListenerCallback (void*)
  57984. {
  57985. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57986. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  57987. {
  57988. if (outputDeviceDropDown == 0)
  57989. {
  57990. outputDeviceDropDown = new ComboBox (String::empty);
  57991. outputDeviceDropDown->addListener (this);
  57992. addAndMakeVisible (outputDeviceDropDown);
  57993. outputDeviceLabel = new Label (String::empty,
  57994. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  57995. : TRANS ("device:"));
  57996. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  57997. if (setup.maxNumOutputChannels > 0)
  57998. {
  57999. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  58000. testButton->addButtonListener (this);
  58001. }
  58002. }
  58003. addNamesToDeviceBox (*outputDeviceDropDown, false);
  58004. }
  58005. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  58006. {
  58007. if (inputDeviceDropDown == 0)
  58008. {
  58009. inputDeviceDropDown = new ComboBox (String::empty);
  58010. inputDeviceDropDown->addListener (this);
  58011. addAndMakeVisible (inputDeviceDropDown);
  58012. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  58013. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  58014. addAndMakeVisible (inputLevelMeter
  58015. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  58016. }
  58017. addNamesToDeviceBox (*inputDeviceDropDown, true);
  58018. }
  58019. updateControlPanelButton();
  58020. showCorrectDeviceName (inputDeviceDropDown, true);
  58021. showCorrectDeviceName (outputDeviceDropDown, false);
  58022. if (currentDevice != 0)
  58023. {
  58024. if (setup.maxNumOutputChannels > 0
  58025. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  58026. {
  58027. if (outputChanList == 0)
  58028. {
  58029. addAndMakeVisible (outputChanList
  58030. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  58031. TRANS ("(no audio output channels found)")));
  58032. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  58033. outputChanLabel->attachToComponent (outputChanList, true);
  58034. }
  58035. outputChanList->refresh();
  58036. }
  58037. else
  58038. {
  58039. deleteAndZero (outputChanLabel);
  58040. deleteAndZero (outputChanList);
  58041. }
  58042. if (setup.maxNumInputChannels > 0
  58043. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  58044. {
  58045. if (inputChanList == 0)
  58046. {
  58047. addAndMakeVisible (inputChanList
  58048. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  58049. TRANS ("(no audio input channels found)")));
  58050. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  58051. inputChanLabel->attachToComponent (inputChanList, true);
  58052. }
  58053. inputChanList->refresh();
  58054. }
  58055. else
  58056. {
  58057. deleteAndZero (inputChanLabel);
  58058. deleteAndZero (inputChanList);
  58059. }
  58060. // sample rate..
  58061. {
  58062. if (sampleRateDropDown == 0)
  58063. {
  58064. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  58065. sampleRateDropDown->addListener (this);
  58066. delete sampleRateLabel;
  58067. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  58068. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  58069. }
  58070. else
  58071. {
  58072. sampleRateDropDown->clear();
  58073. sampleRateDropDown->removeListener (this);
  58074. }
  58075. const int numRates = currentDevice->getNumSampleRates();
  58076. for (int i = 0; i < numRates; ++i)
  58077. {
  58078. const int rate = roundToInt (currentDevice->getSampleRate (i));
  58079. sampleRateDropDown->addItem (String (rate) + T(" Hz"), rate);
  58080. }
  58081. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  58082. sampleRateDropDown->addListener (this);
  58083. }
  58084. // buffer size
  58085. {
  58086. if (bufferSizeDropDown == 0)
  58087. {
  58088. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  58089. bufferSizeDropDown->addListener (this);
  58090. delete bufferSizeLabel;
  58091. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  58092. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  58093. }
  58094. else
  58095. {
  58096. bufferSizeDropDown->clear();
  58097. }
  58098. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  58099. double currentRate = currentDevice->getCurrentSampleRate();
  58100. if (currentRate == 0)
  58101. currentRate = 48000.0;
  58102. for (int i = 0; i < numBufferSizes; ++i)
  58103. {
  58104. const int bs = currentDevice->getBufferSizeSamples (i);
  58105. bufferSizeDropDown->addItem (String (bs)
  58106. + T(" samples (")
  58107. + String (bs * 1000.0 / currentRate, 1)
  58108. + T(" ms)"),
  58109. bs);
  58110. }
  58111. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  58112. }
  58113. }
  58114. else
  58115. {
  58116. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  58117. deleteAndZero (sampleRateLabel);
  58118. deleteAndZero (bufferSizeLabel);
  58119. deleteAndZero (sampleRateDropDown);
  58120. deleteAndZero (bufferSizeDropDown);
  58121. if (outputDeviceDropDown != 0)
  58122. outputDeviceDropDown->setSelectedId (-1, true);
  58123. if (inputDeviceDropDown != 0)
  58124. inputDeviceDropDown->setSelectedId (-1, true);
  58125. }
  58126. resized();
  58127. setSize (getWidth(), getLowestY() + 4);
  58128. }
  58129. private:
  58130. AudioIODeviceType* const type;
  58131. const AudioIODeviceType::DeviceSetupDetails setup;
  58132. ComboBox* outputDeviceDropDown;
  58133. ComboBox* inputDeviceDropDown;
  58134. ComboBox* sampleRateDropDown;
  58135. ComboBox* bufferSizeDropDown;
  58136. Label* outputDeviceLabel;
  58137. Label* inputDeviceLabel;
  58138. Label* sampleRateLabel;
  58139. Label* bufferSizeLabel;
  58140. Label* inputChanLabel;
  58141. Label* outputChanLabel;
  58142. TextButton* testButton;
  58143. Component* inputLevelMeter;
  58144. TextButton* showUIButton;
  58145. TextButton* showAdvancedSettingsButton;
  58146. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  58147. {
  58148. if (box != 0)
  58149. {
  58150. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  58151. const int index = type->getIndexOfDevice (currentDevice, isInput);
  58152. box->setSelectedId (index + 1, true);
  58153. if (testButton != 0 && ! isInput)
  58154. testButton->setEnabled (index >= 0);
  58155. }
  58156. }
  58157. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  58158. {
  58159. const StringArray devs (type->getDeviceNames (isInputs));
  58160. combo.clear (true);
  58161. for (int i = 0; i < devs.size(); ++i)
  58162. combo.addItem (devs[i], i + 1);
  58163. combo.addItem (TRANS("<< none >>"), -1);
  58164. combo.setSelectedId (-1, true);
  58165. }
  58166. int getLowestY() const
  58167. {
  58168. int y = 0;
  58169. for (int i = getNumChildComponents(); --i >= 0;)
  58170. y = jmax (y, getChildComponent (i)->getBottom());
  58171. return y;
  58172. }
  58173. public:
  58174. class ChannelSelectorListBox : public ListBox,
  58175. public ListBoxModel
  58176. {
  58177. public:
  58178. enum BoxType
  58179. {
  58180. audioInputType,
  58181. audioOutputType
  58182. };
  58183. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  58184. const BoxType type_,
  58185. const String& noItemsMessage_)
  58186. : ListBox (String::empty, 0),
  58187. setup (setup_),
  58188. type (type_),
  58189. noItemsMessage (noItemsMessage_)
  58190. {
  58191. refresh();
  58192. setModel (this);
  58193. setOutlineThickness (1);
  58194. }
  58195. ~ChannelSelectorListBox()
  58196. {
  58197. }
  58198. void refresh()
  58199. {
  58200. items.clear();
  58201. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58202. if (currentDevice != 0)
  58203. {
  58204. if (type == audioInputType)
  58205. items = currentDevice->getInputChannelNames();
  58206. else if (type == audioOutputType)
  58207. items = currentDevice->getOutputChannelNames();
  58208. if (setup.useStereoPairs)
  58209. {
  58210. StringArray pairs;
  58211. for (int i = 0; i < items.size(); i += 2)
  58212. {
  58213. String name (items[i]);
  58214. String name2 (items[i + 1]);
  58215. String commonBit;
  58216. for (int j = 0; j < name.length(); ++j)
  58217. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  58218. commonBit = name.substring (0, j);
  58219. pairs.add (name.trim()
  58220. + " + "
  58221. + name2.substring (commonBit.length()).trim());
  58222. }
  58223. items = pairs;
  58224. }
  58225. }
  58226. updateContent();
  58227. repaint();
  58228. }
  58229. int getNumRows()
  58230. {
  58231. return items.size();
  58232. }
  58233. void paintListBoxItem (int row,
  58234. Graphics& g,
  58235. int width, int height,
  58236. bool rowIsSelected)
  58237. {
  58238. if (((unsigned int) row) < (unsigned int) items.size())
  58239. {
  58240. if (rowIsSelected)
  58241. g.fillAll (findColour (TextEditor::highlightColourId)
  58242. .withMultipliedAlpha (0.3f));
  58243. const String item (items [row]);
  58244. bool enabled = false;
  58245. AudioDeviceManager::AudioDeviceSetup config;
  58246. setup.manager->getAudioDeviceSetup (config);
  58247. if (setup.useStereoPairs)
  58248. {
  58249. if (type == audioInputType)
  58250. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58251. else if (type == audioOutputType)
  58252. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58253. }
  58254. else
  58255. {
  58256. if (type == audioInputType)
  58257. enabled = config.inputChannels [row];
  58258. else if (type == audioOutputType)
  58259. enabled = config.outputChannels [row];
  58260. }
  58261. const int x = getTickX();
  58262. const float tickW = height * 0.75f;
  58263. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58264. enabled, true, true, false);
  58265. g.setFont (height * 0.6f);
  58266. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58267. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58268. }
  58269. }
  58270. void listBoxItemClicked (int row, const MouseEvent& e)
  58271. {
  58272. selectRow (row);
  58273. if (e.x < getTickX())
  58274. flipEnablement (row);
  58275. }
  58276. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58277. {
  58278. flipEnablement (row);
  58279. }
  58280. void returnKeyPressed (int row)
  58281. {
  58282. flipEnablement (row);
  58283. }
  58284. void paint (Graphics& g)
  58285. {
  58286. ListBox::paint (g);
  58287. if (items.size() == 0)
  58288. {
  58289. g.setColour (Colours::grey);
  58290. g.setFont (13.0f);
  58291. g.drawText (noItemsMessage,
  58292. 0, 0, getWidth(), getHeight() / 2,
  58293. Justification::centred, true);
  58294. }
  58295. }
  58296. int getBestHeight (int maxHeight)
  58297. {
  58298. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58299. getNumRows())
  58300. + getOutlineThickness() * 2;
  58301. }
  58302. juce_UseDebuggingNewOperator
  58303. private:
  58304. const AudioIODeviceType::DeviceSetupDetails setup;
  58305. const BoxType type;
  58306. const String noItemsMessage;
  58307. StringArray items;
  58308. void flipEnablement (const int row)
  58309. {
  58310. jassert (type == audioInputType || type == audioOutputType);
  58311. if (((unsigned int) row) < (unsigned int) items.size())
  58312. {
  58313. AudioDeviceManager::AudioDeviceSetup config;
  58314. setup.manager->getAudioDeviceSetup (config);
  58315. if (setup.useStereoPairs)
  58316. {
  58317. BitArray bits;
  58318. BitArray& original = (type == audioInputType ? config.inputChannels
  58319. : config.outputChannels);
  58320. int i;
  58321. for (i = 0; i < 256; i += 2)
  58322. bits.setBit (i / 2, original [i] || original [i + 1]);
  58323. if (type == audioInputType)
  58324. {
  58325. config.useDefaultInputChannels = false;
  58326. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58327. }
  58328. else
  58329. {
  58330. config.useDefaultOutputChannels = false;
  58331. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58332. }
  58333. for (i = 0; i < 256; ++i)
  58334. original.setBit (i, bits [i / 2]);
  58335. }
  58336. else
  58337. {
  58338. if (type == audioInputType)
  58339. {
  58340. config.useDefaultInputChannels = false;
  58341. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58342. }
  58343. else
  58344. {
  58345. config.useDefaultOutputChannels = false;
  58346. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58347. }
  58348. }
  58349. String error (setup.manager->setAudioDeviceSetup (config, true));
  58350. if (! error.isEmpty())
  58351. {
  58352. //xxx
  58353. }
  58354. }
  58355. }
  58356. static void flipBit (BitArray& chans, int index, int minNumber, int maxNumber)
  58357. {
  58358. const int numActive = chans.countNumberOfSetBits();
  58359. if (chans [index])
  58360. {
  58361. if (numActive > minNumber)
  58362. chans.setBit (index, false);
  58363. }
  58364. else
  58365. {
  58366. if (numActive >= maxNumber)
  58367. {
  58368. const int firstActiveChan = chans.findNextSetBit();
  58369. chans.setBit (index > firstActiveChan
  58370. ? firstActiveChan : chans.getHighestBit(),
  58371. false);
  58372. }
  58373. chans.setBit (index, true);
  58374. }
  58375. }
  58376. int getTickX() const
  58377. {
  58378. return getRowHeight() + 5;
  58379. }
  58380. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58381. ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58382. };
  58383. private:
  58384. ChannelSelectorListBox* inputChanList;
  58385. ChannelSelectorListBox* outputChanList;
  58386. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58387. AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58388. };
  58389. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58390. const int minInputChannels_,
  58391. const int maxInputChannels_,
  58392. const int minOutputChannels_,
  58393. const int maxOutputChannels_,
  58394. const bool showMidiInputOptions,
  58395. const bool showMidiOutputSelector,
  58396. const bool showChannelsAsStereoPairs_,
  58397. const bool hideAdvancedOptionsWithButton_)
  58398. : deviceManager (deviceManager_),
  58399. deviceTypeDropDown (0),
  58400. deviceTypeDropDownLabel (0),
  58401. audioDeviceSettingsComp (0),
  58402. minOutputChannels (minOutputChannels_),
  58403. maxOutputChannels (maxOutputChannels_),
  58404. minInputChannels (minInputChannels_),
  58405. maxInputChannels (maxInputChannels_),
  58406. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58407. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58408. {
  58409. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58410. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58411. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58412. {
  58413. deviceTypeDropDown = new ComboBox (String::empty);
  58414. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58415. {
  58416. deviceTypeDropDown
  58417. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58418. i + 1);
  58419. }
  58420. addAndMakeVisible (deviceTypeDropDown);
  58421. deviceTypeDropDown->addListener (this);
  58422. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58423. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58424. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58425. }
  58426. if (showMidiInputOptions)
  58427. {
  58428. addAndMakeVisible (midiInputsList
  58429. = new MidiInputSelectorComponentListBox (deviceManager,
  58430. TRANS("(no midi inputs available)"),
  58431. 0, 0));
  58432. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58433. midiInputsLabel->setJustificationType (Justification::topRight);
  58434. midiInputsLabel->attachToComponent (midiInputsList, true);
  58435. }
  58436. else
  58437. {
  58438. midiInputsList = 0;
  58439. midiInputsLabel = 0;
  58440. }
  58441. if (showMidiOutputSelector)
  58442. {
  58443. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58444. midiOutputSelector->addListener (this);
  58445. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58446. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58447. }
  58448. else
  58449. {
  58450. midiOutputSelector = 0;
  58451. midiOutputLabel = 0;
  58452. }
  58453. deviceManager_.addChangeListener (this);
  58454. changeListenerCallback (0);
  58455. }
  58456. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58457. {
  58458. deviceManager.removeChangeListener (this);
  58459. deleteAllChildren();
  58460. }
  58461. void AudioDeviceSelectorComponent::resized()
  58462. {
  58463. const int lx = proportionOfWidth (0.35f);
  58464. const int w = proportionOfWidth (0.4f);
  58465. const int h = 24;
  58466. const int space = 6;
  58467. const int dh = h + space;
  58468. int y = 15;
  58469. if (deviceTypeDropDown != 0)
  58470. {
  58471. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58472. y += dh + space * 2;
  58473. }
  58474. if (audioDeviceSettingsComp != 0)
  58475. {
  58476. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58477. y += audioDeviceSettingsComp->getHeight() + space;
  58478. }
  58479. if (midiInputsList != 0)
  58480. {
  58481. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58482. midiInputsList->setBounds (lx, y, w, bh);
  58483. y += bh + space;
  58484. }
  58485. if (midiOutputSelector != 0)
  58486. midiOutputSelector->setBounds (lx, y, w, h);
  58487. }
  58488. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58489. {
  58490. if (child == audioDeviceSettingsComp)
  58491. resized();
  58492. }
  58493. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58494. {
  58495. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58496. if (device != 0 && device->hasControlPanel())
  58497. {
  58498. if (device->showControlPanel())
  58499. deviceManager.restartLastAudioDevice();
  58500. getTopLevelComponent()->toFront (true);
  58501. }
  58502. }
  58503. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58504. {
  58505. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58506. {
  58507. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58508. if (type != 0)
  58509. {
  58510. deleteAndZero (audioDeviceSettingsComp);
  58511. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58512. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58513. }
  58514. }
  58515. else if (comboBoxThatHasChanged == midiOutputSelector)
  58516. {
  58517. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58518. }
  58519. }
  58520. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58521. {
  58522. if (deviceTypeDropDown != 0)
  58523. {
  58524. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58525. }
  58526. if (audioDeviceSettingsComp == 0
  58527. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58528. {
  58529. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58530. deleteAndZero (audioDeviceSettingsComp);
  58531. AudioIODeviceType* const type
  58532. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58533. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58534. if (type != 0)
  58535. {
  58536. AudioIODeviceType::DeviceSetupDetails details;
  58537. details.manager = &deviceManager;
  58538. details.minNumInputChannels = minInputChannels;
  58539. details.maxNumInputChannels = maxInputChannels;
  58540. details.minNumOutputChannels = minOutputChannels;
  58541. details.maxNumOutputChannels = maxOutputChannels;
  58542. details.useStereoPairs = showChannelsAsStereoPairs;
  58543. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58544. if (audioDeviceSettingsComp != 0)
  58545. {
  58546. addAndMakeVisible (audioDeviceSettingsComp);
  58547. audioDeviceSettingsComp->resized();
  58548. }
  58549. }
  58550. }
  58551. if (midiInputsList != 0)
  58552. {
  58553. midiInputsList->updateContent();
  58554. midiInputsList->repaint();
  58555. }
  58556. if (midiOutputSelector != 0)
  58557. {
  58558. midiOutputSelector->clear();
  58559. const StringArray midiOuts (MidiOutput::getDevices());
  58560. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58561. midiOutputSelector->addSeparator();
  58562. for (int i = 0; i < midiOuts.size(); ++i)
  58563. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58564. int current = -1;
  58565. if (deviceManager.getDefaultMidiOutput() != 0)
  58566. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58567. midiOutputSelector->setSelectedId (current, true);
  58568. }
  58569. resized();
  58570. }
  58571. END_JUCE_NAMESPACE
  58572. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58573. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58574. BEGIN_JUCE_NAMESPACE
  58575. BubbleComponent::BubbleComponent()
  58576. : side (0),
  58577. allowablePlacements (above | below | left | right),
  58578. arrowTipX (0.0f),
  58579. arrowTipY (0.0f)
  58580. {
  58581. setInterceptsMouseClicks (false, false);
  58582. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58583. setComponentEffect (&shadow);
  58584. }
  58585. BubbleComponent::~BubbleComponent()
  58586. {
  58587. }
  58588. void BubbleComponent::paint (Graphics& g)
  58589. {
  58590. int x = content.getX();
  58591. int y = content.getY();
  58592. int w = content.getWidth();
  58593. int h = content.getHeight();
  58594. int cw, ch;
  58595. getContentSize (cw, ch);
  58596. if (side == 3)
  58597. x += w - cw;
  58598. else if (side != 1)
  58599. x += (w - cw) / 2;
  58600. w = cw;
  58601. if (side == 2)
  58602. y += h - ch;
  58603. else if (side != 0)
  58604. y += (h - ch) / 2;
  58605. h = ch;
  58606. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58607. (float) x, (float) y,
  58608. (float) w, (float) h);
  58609. const int cx = x + (w - cw) / 2;
  58610. const int cy = y + (h - ch) / 2;
  58611. const int indent = 3;
  58612. g.setOrigin (cx + indent, cy + indent);
  58613. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58614. paintContent (g, cw - indent * 2, ch - indent * 2);
  58615. }
  58616. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58617. {
  58618. allowablePlacements = newPlacement;
  58619. }
  58620. void BubbleComponent::setPosition (Component* componentToPointTo)
  58621. {
  58622. jassert (componentToPointTo->isValidComponent());
  58623. Point<int> pos;
  58624. if (getParentComponent() != 0)
  58625. pos = componentToPointTo->relativePositionToOtherComponent (getParentComponent(), pos);
  58626. else
  58627. pos = componentToPointTo->relativePositionToGlobal (pos);
  58628. setPosition (Rectangle<int> (pos.getX(), pos.getY(), componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58629. }
  58630. void BubbleComponent::setPosition (const int arrowTipX_,
  58631. const int arrowTipY_)
  58632. {
  58633. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58634. }
  58635. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58636. {
  58637. Rectangle<int> availableSpace;
  58638. if (getParentComponent() != 0)
  58639. {
  58640. availableSpace.setSize (getParentComponent()->getWidth(),
  58641. getParentComponent()->getHeight());
  58642. }
  58643. else
  58644. {
  58645. availableSpace = getParentMonitorArea();
  58646. }
  58647. int x = 0;
  58648. int y = 0;
  58649. int w = 150;
  58650. int h = 30;
  58651. getContentSize (w, h);
  58652. w += 30;
  58653. h += 30;
  58654. const float edgeIndent = 2.0f;
  58655. const int arrowLength = jmin (10, h / 3, w / 3);
  58656. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58657. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58658. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58659. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58660. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58661. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58662. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58663. {
  58664. spaceLeft = spaceRight = 0;
  58665. }
  58666. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58667. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58668. {
  58669. spaceAbove = spaceBelow = 0;
  58670. }
  58671. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58672. {
  58673. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58674. arrowTipX = w * 0.5f;
  58675. content.setSize (w, h - arrowLength);
  58676. if (spaceAbove >= spaceBelow)
  58677. {
  58678. // above
  58679. y = rectangleToPointTo.getY() - h;
  58680. content.setPosition (0, 0);
  58681. arrowTipY = h - edgeIndent;
  58682. side = 2;
  58683. }
  58684. else
  58685. {
  58686. // below
  58687. y = rectangleToPointTo.getBottom();
  58688. content.setPosition (0, arrowLength);
  58689. arrowTipY = edgeIndent;
  58690. side = 0;
  58691. }
  58692. }
  58693. else
  58694. {
  58695. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58696. arrowTipY = h * 0.5f;
  58697. content.setSize (w - arrowLength, h);
  58698. if (spaceLeft > spaceRight)
  58699. {
  58700. // on the left
  58701. x = rectangleToPointTo.getX() - w;
  58702. content.setPosition (0, 0);
  58703. arrowTipX = w - edgeIndent;
  58704. side = 3;
  58705. }
  58706. else
  58707. {
  58708. // on the right
  58709. x = rectangleToPointTo.getRight();
  58710. content.setPosition (arrowLength, 0);
  58711. arrowTipX = edgeIndent;
  58712. side = 1;
  58713. }
  58714. }
  58715. setBounds (x, y, w, h);
  58716. }
  58717. END_JUCE_NAMESPACE
  58718. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58719. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58720. BEGIN_JUCE_NAMESPACE
  58721. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58722. : fadeOutLength (fadeOutLengthMs),
  58723. deleteAfterUse (false)
  58724. {
  58725. }
  58726. BubbleMessageComponent::~BubbleMessageComponent()
  58727. {
  58728. fadeOutComponent (fadeOutLength);
  58729. }
  58730. void BubbleMessageComponent::showAt (int x, int y,
  58731. const String& text,
  58732. const int numMillisecondsBeforeRemoving,
  58733. const bool removeWhenMouseClicked,
  58734. const bool deleteSelfAfterUse)
  58735. {
  58736. textLayout.clear();
  58737. textLayout.setText (text, Font (14.0f));
  58738. textLayout.layout (256, Justification::centredLeft, true);
  58739. setPosition (x, y);
  58740. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58741. }
  58742. void BubbleMessageComponent::showAt (Component* const component,
  58743. const String& text,
  58744. const int numMillisecondsBeforeRemoving,
  58745. const bool removeWhenMouseClicked,
  58746. const bool deleteSelfAfterUse)
  58747. {
  58748. textLayout.clear();
  58749. textLayout.setText (text, Font (14.0f));
  58750. textLayout.layout (256, Justification::centredLeft, true);
  58751. setPosition (component);
  58752. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58753. }
  58754. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58755. const bool removeWhenMouseClicked,
  58756. const bool deleteSelfAfterUse)
  58757. {
  58758. setVisible (true);
  58759. deleteAfterUse = deleteSelfAfterUse;
  58760. if (numMillisecondsBeforeRemoving > 0)
  58761. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58762. else
  58763. expiryTime = 0;
  58764. startTimer (77);
  58765. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58766. if (! (removeWhenMouseClicked && isShowing()))
  58767. mouseClickCounter += 0xfffff;
  58768. repaint();
  58769. }
  58770. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58771. {
  58772. w = textLayout.getWidth() + 16;
  58773. h = textLayout.getHeight() + 16;
  58774. }
  58775. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58776. {
  58777. g.setColour (findColour (TooltipWindow::textColourId));
  58778. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58779. }
  58780. void BubbleMessageComponent::timerCallback()
  58781. {
  58782. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58783. {
  58784. stopTimer();
  58785. setVisible (false);
  58786. if (deleteAfterUse)
  58787. delete this;
  58788. }
  58789. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58790. {
  58791. stopTimer();
  58792. fadeOutComponent (fadeOutLength);
  58793. if (deleteAfterUse)
  58794. delete this;
  58795. }
  58796. }
  58797. END_JUCE_NAMESPACE
  58798. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  58799. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  58800. BEGIN_JUCE_NAMESPACE
  58801. static const int swatchesPerRow = 8;
  58802. static const int swatchHeight = 22;
  58803. static const String colourComponentToHexString (int value)
  58804. {
  58805. return String::toHexString (value).toUpperCase().paddedLeft ('0', 2);
  58806. }
  58807. class ColourComponentSlider : public Slider
  58808. {
  58809. public:
  58810. ColourComponentSlider (const String& name)
  58811. : Slider (name)
  58812. {
  58813. setRange (0.0, 255.0, 1.0);
  58814. }
  58815. ~ColourComponentSlider()
  58816. {
  58817. }
  58818. const String getTextFromValue (double value)
  58819. {
  58820. return colourComponentToHexString ((int) value);
  58821. }
  58822. double getValueFromText (const String& text)
  58823. {
  58824. return (double) text.getHexValue32();
  58825. }
  58826. private:
  58827. ColourComponentSlider (const ColourComponentSlider&);
  58828. ColourComponentSlider& operator= (const ColourComponentSlider&);
  58829. };
  58830. class ColourSpaceMarker : public Component
  58831. {
  58832. public:
  58833. ColourSpaceMarker()
  58834. {
  58835. setInterceptsMouseClicks (false, false);
  58836. }
  58837. ~ColourSpaceMarker()
  58838. {
  58839. }
  58840. void paint (Graphics& g)
  58841. {
  58842. g.setColour (Colour::greyLevel (0.1f));
  58843. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  58844. g.setColour (Colour::greyLevel (0.9f));
  58845. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  58846. }
  58847. private:
  58848. ColourSpaceMarker (const ColourSpaceMarker&);
  58849. ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  58850. };
  58851. class ColourSpaceView : public Component
  58852. {
  58853. ColourSelector* const owner;
  58854. float& h;
  58855. float& s;
  58856. float& v;
  58857. float lastHue;
  58858. ColourSpaceMarker* marker;
  58859. const int edge;
  58860. public:
  58861. ColourSpaceView (ColourSelector* owner_,
  58862. float& h_, float& s_, float& v_,
  58863. const int edgeSize)
  58864. : owner (owner_),
  58865. h (h_), s (s_), v (v_),
  58866. lastHue (0.0f),
  58867. edge (edgeSize)
  58868. {
  58869. addAndMakeVisible (marker = new ColourSpaceMarker());
  58870. setMouseCursor (MouseCursor::CrosshairCursor);
  58871. }
  58872. ~ColourSpaceView()
  58873. {
  58874. deleteAllChildren();
  58875. }
  58876. void paint (Graphics& g)
  58877. {
  58878. if (colours == 0)
  58879. {
  58880. const int width = getWidth() / 2;
  58881. const int height = getHeight() / 2;
  58882. colours = new Image (Image::RGB, width, height, false);
  58883. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  58884. for (int y = 0; y < height; ++y)
  58885. {
  58886. const float v = 1.0f - y / (float) height;
  58887. for (int x = 0; x < width; ++x)
  58888. {
  58889. const float s = x / (float) width;
  58890. const Colour col (h, s, v, 1.0f);
  58891. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  58892. pix->set (col.getPixelARGB());
  58893. }
  58894. }
  58895. }
  58896. g.setOpacity (1.0f);
  58897. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  58898. 0, 0, colours->getWidth(), colours->getHeight());
  58899. }
  58900. void mouseDown (const MouseEvent& e)
  58901. {
  58902. mouseDrag (e);
  58903. }
  58904. void mouseDrag (const MouseEvent& e)
  58905. {
  58906. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  58907. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  58908. owner->setSV (s, v);
  58909. }
  58910. void updateIfNeeded()
  58911. {
  58912. if (lastHue != h)
  58913. {
  58914. lastHue = h;
  58915. colours = 0;
  58916. repaint();
  58917. }
  58918. updateMarker();
  58919. }
  58920. void resized()
  58921. {
  58922. colours = 0;
  58923. updateMarker();
  58924. }
  58925. private:
  58926. ScopedPointer <Image> colours;
  58927. void updateMarker() const throw()
  58928. {
  58929. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  58930. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  58931. edge * 2, edge * 2);
  58932. }
  58933. ColourSpaceView (const ColourSpaceView&);
  58934. ColourSpaceView& operator= (const ColourSpaceView&);
  58935. };
  58936. class HueSelectorMarker : public Component
  58937. {
  58938. public:
  58939. HueSelectorMarker()
  58940. {
  58941. setInterceptsMouseClicks (false, false);
  58942. }
  58943. ~HueSelectorMarker()
  58944. {
  58945. }
  58946. void paint (Graphics& g)
  58947. {
  58948. Path p;
  58949. p.addTriangle (1.0f, 1.0f,
  58950. getWidth() * 0.3f, getHeight() * 0.5f,
  58951. 1.0f, getHeight() - 1.0f);
  58952. p.addTriangle (getWidth() - 1.0f, 1.0f,
  58953. getWidth() * 0.7f, getHeight() * 0.5f,
  58954. getWidth() - 1.0f, getHeight() - 1.0f);
  58955. g.setColour (Colours::white.withAlpha (0.75f));
  58956. g.fillPath (p);
  58957. g.setColour (Colours::black.withAlpha (0.75f));
  58958. g.strokePath (p, PathStrokeType (1.2f));
  58959. }
  58960. private:
  58961. HueSelectorMarker (const HueSelectorMarker&);
  58962. HueSelectorMarker& operator= (const HueSelectorMarker&);
  58963. };
  58964. class HueSelectorComp : public Component
  58965. {
  58966. public:
  58967. HueSelectorComp (ColourSelector* owner_,
  58968. float& h_, float& s_, float& v_,
  58969. const int edgeSize)
  58970. : owner (owner_),
  58971. h (h_), s (s_), v (v_),
  58972. lastHue (0.0f),
  58973. edge (edgeSize)
  58974. {
  58975. addAndMakeVisible (marker = new HueSelectorMarker());
  58976. }
  58977. ~HueSelectorComp()
  58978. {
  58979. deleteAllChildren();
  58980. }
  58981. void paint (Graphics& g)
  58982. {
  58983. const float yScale = 1.0f / (getHeight() - edge * 2);
  58984. const Rectangle<int> clip (g.getClipBounds());
  58985. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  58986. {
  58987. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  58988. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  58989. }
  58990. }
  58991. void resized()
  58992. {
  58993. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  58994. getWidth(), edge * 2);
  58995. }
  58996. void mouseDown (const MouseEvent& e)
  58997. {
  58998. mouseDrag (e);
  58999. }
  59000. void mouseDrag (const MouseEvent& e)
  59001. {
  59002. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  59003. owner->setHue (hue);
  59004. }
  59005. void updateIfNeeded()
  59006. {
  59007. resized();
  59008. }
  59009. private:
  59010. ColourSelector* const owner;
  59011. float& h;
  59012. float& s;
  59013. float& v;
  59014. float lastHue;
  59015. HueSelectorMarker* marker;
  59016. const int edge;
  59017. HueSelectorComp (const HueSelectorComp&);
  59018. HueSelectorComp& operator= (const HueSelectorComp&);
  59019. };
  59020. class ColourSelector::SwatchComponent : public Component
  59021. {
  59022. public:
  59023. SwatchComponent (ColourSelector* owner_, int index_)
  59024. : owner (owner_),
  59025. index (index_)
  59026. {
  59027. }
  59028. ~SwatchComponent()
  59029. {
  59030. }
  59031. void paint (Graphics& g)
  59032. {
  59033. const Colour colour (owner->getSwatchColour (index));
  59034. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  59035. 6, 6,
  59036. Colour (0xffdddddd).overlaidWith (colour),
  59037. Colour (0xffffffff).overlaidWith (colour));
  59038. }
  59039. void mouseDown (const MouseEvent&)
  59040. {
  59041. PopupMenu m;
  59042. m.addItem (1, TRANS("Use this swatch as the current colour"));
  59043. m.addSeparator();
  59044. m.addItem (2, TRANS("Set this swatch to the current colour"));
  59045. const int r = m.showAt (this);
  59046. if (r == 1)
  59047. {
  59048. owner->setCurrentColour (owner->getSwatchColour (index));
  59049. }
  59050. else if (r == 2)
  59051. {
  59052. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  59053. {
  59054. owner->setSwatchColour (index, owner->getCurrentColour());
  59055. repaint();
  59056. }
  59057. }
  59058. }
  59059. private:
  59060. ColourSelector* const owner;
  59061. const int index;
  59062. SwatchComponent (const SwatchComponent&);
  59063. SwatchComponent& operator= (const SwatchComponent&);
  59064. };
  59065. ColourSelector::ColourSelector (const int flags_,
  59066. const int edgeGap_,
  59067. const int gapAroundColourSpaceComponent)
  59068. : colour (Colours::white),
  59069. flags (flags_),
  59070. topSpace (0),
  59071. edgeGap (edgeGap_)
  59072. {
  59073. // not much point having a selector with no components in it!
  59074. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  59075. updateHSV();
  59076. if ((flags & showSliders) != 0)
  59077. {
  59078. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  59079. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  59080. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  59081. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  59082. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  59083. for (int i = 4; --i >= 0;)
  59084. sliders[i]->addListener (this);
  59085. }
  59086. else
  59087. {
  59088. zeromem (sliders, sizeof (sliders));
  59089. }
  59090. if ((flags & showColourspace) != 0)
  59091. {
  59092. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  59093. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  59094. }
  59095. else
  59096. {
  59097. colourSpace = 0;
  59098. hueSelector = 0;
  59099. }
  59100. update();
  59101. }
  59102. ColourSelector::~ColourSelector()
  59103. {
  59104. dispatchPendingMessages();
  59105. swatchComponents.clear();
  59106. deleteAllChildren();
  59107. }
  59108. const Colour ColourSelector::getCurrentColour() const
  59109. {
  59110. return ((flags & showAlphaChannel) != 0) ? colour
  59111. : colour.withAlpha ((uint8) 0xff);
  59112. }
  59113. void ColourSelector::setCurrentColour (const Colour& c)
  59114. {
  59115. if (c != colour)
  59116. {
  59117. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  59118. updateHSV();
  59119. update();
  59120. }
  59121. }
  59122. void ColourSelector::setHue (float newH)
  59123. {
  59124. newH = jlimit (0.0f, 1.0f, newH);
  59125. if (h != newH)
  59126. {
  59127. h = newH;
  59128. colour = Colour (h, s, v, colour.getFloatAlpha());
  59129. update();
  59130. }
  59131. }
  59132. void ColourSelector::setSV (float newS, float newV)
  59133. {
  59134. newS = jlimit (0.0f, 1.0f, newS);
  59135. newV = jlimit (0.0f, 1.0f, newV);
  59136. if (s != newS || v != newV)
  59137. {
  59138. s = newS;
  59139. v = newV;
  59140. colour = Colour (h, s, v, colour.getFloatAlpha());
  59141. update();
  59142. }
  59143. }
  59144. void ColourSelector::updateHSV()
  59145. {
  59146. colour.getHSB (h, s, v);
  59147. }
  59148. void ColourSelector::update()
  59149. {
  59150. if (sliders[0] != 0)
  59151. {
  59152. sliders[0]->setValue ((int) colour.getRed());
  59153. sliders[1]->setValue ((int) colour.getGreen());
  59154. sliders[2]->setValue ((int) colour.getBlue());
  59155. sliders[3]->setValue ((int) colour.getAlpha());
  59156. }
  59157. if (colourSpace != 0)
  59158. {
  59159. ((ColourSpaceView*) colourSpace)->updateIfNeeded();
  59160. ((HueSelectorComp*) hueSelector)->updateIfNeeded();
  59161. }
  59162. if ((flags & showColourAtTop) != 0)
  59163. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  59164. sendChangeMessage (this);
  59165. }
  59166. void ColourSelector::paint (Graphics& g)
  59167. {
  59168. g.fillAll (findColour (backgroundColourId));
  59169. if ((flags & showColourAtTop) != 0)
  59170. {
  59171. const Colour colour (getCurrentColour());
  59172. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  59173. 10, 10,
  59174. Colour (0xffdddddd).overlaidWith (colour),
  59175. Colour (0xffffffff).overlaidWith (colour));
  59176. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  59177. g.setFont (14.0f, true);
  59178. g.drawText (((flags & showAlphaChannel) != 0)
  59179. ? colourComponentToHexString ((int) colour.getAlpha())
  59180. + colourComponentToHexString ((int) colour.getRed())
  59181. + colourComponentToHexString ((int) colour.getGreen())
  59182. + colourComponentToHexString ((int) colour.getBlue())
  59183. : colourComponentToHexString ((int) colour.getRed())
  59184. + colourComponentToHexString ((int) colour.getGreen())
  59185. + colourComponentToHexString ((int) colour.getBlue()),
  59186. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  59187. Justification::centred, false);
  59188. }
  59189. if ((flags & showSliders) != 0)
  59190. {
  59191. g.setColour (findColour (labelTextColourId));
  59192. g.setFont (11.0f);
  59193. for (int i = 4; --i >= 0;)
  59194. {
  59195. if (sliders[i]->isVisible())
  59196. g.drawText (sliders[i]->getName() + T(":"),
  59197. 0, sliders[i]->getY(),
  59198. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  59199. Justification::centredRight, false);
  59200. }
  59201. }
  59202. }
  59203. void ColourSelector::resized()
  59204. {
  59205. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  59206. const int numSwatches = getNumSwatches();
  59207. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  59208. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  59209. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  59210. int y = topSpace;
  59211. if ((flags & showColourspace) != 0)
  59212. {
  59213. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  59214. colourSpace->setBounds (edgeGap, y,
  59215. getWidth() - hueWidth - edgeGap - 4,
  59216. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  59217. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  59218. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  59219. colourSpace->getHeight());
  59220. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  59221. }
  59222. if ((flags & showSliders) != 0)
  59223. {
  59224. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  59225. for (int i = 0; i < numSliders; ++i)
  59226. {
  59227. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  59228. proportionOfWidth (0.72f), sliderHeight - 2);
  59229. y += sliderHeight;
  59230. }
  59231. }
  59232. if (numSwatches > 0)
  59233. {
  59234. const int startX = 8;
  59235. const int xGap = 4;
  59236. const int yGap = 4;
  59237. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59238. y += edgeGap;
  59239. if (swatchComponents.size() != numSwatches)
  59240. {
  59241. swatchComponents.clear();
  59242. for (int i = 0; i < numSwatches; ++i)
  59243. {
  59244. SwatchComponent* const sc = new SwatchComponent (this, i);
  59245. swatchComponents.add (sc);
  59246. addAndMakeVisible (sc);
  59247. }
  59248. }
  59249. int x = startX;
  59250. for (int i = 0; i < swatchComponents.size(); ++i)
  59251. {
  59252. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59253. sc->setBounds (x + xGap / 2,
  59254. y + yGap / 2,
  59255. swatchWidth - xGap,
  59256. swatchHeight - yGap);
  59257. if (((i + 1) % swatchesPerRow) == 0)
  59258. {
  59259. x = startX;
  59260. y += swatchHeight;
  59261. }
  59262. else
  59263. {
  59264. x += swatchWidth;
  59265. }
  59266. }
  59267. }
  59268. }
  59269. void ColourSelector::sliderValueChanged (Slider*)
  59270. {
  59271. if (sliders[0] != 0)
  59272. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59273. (uint8) sliders[1]->getValue(),
  59274. (uint8) sliders[2]->getValue(),
  59275. (uint8) sliders[3]->getValue()));
  59276. }
  59277. int ColourSelector::getNumSwatches() const
  59278. {
  59279. return 0;
  59280. }
  59281. const Colour ColourSelector::getSwatchColour (const int) const
  59282. {
  59283. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59284. return Colours::black;
  59285. }
  59286. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59287. {
  59288. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59289. }
  59290. END_JUCE_NAMESPACE
  59291. /*** End of inlined file: juce_ColourSelector.cpp ***/
  59292. /*** Start of inlined file: juce_DropShadower.cpp ***/
  59293. BEGIN_JUCE_NAMESPACE
  59294. class ShadowWindow : public Component
  59295. {
  59296. Component* owner;
  59297. Image** shadowImageSections;
  59298. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59299. public:
  59300. ShadowWindow (Component* const owner_,
  59301. const int type_,
  59302. Image** const shadowImageSections_)
  59303. : owner (owner_),
  59304. shadowImageSections (shadowImageSections_),
  59305. type (type_)
  59306. {
  59307. setInterceptsMouseClicks (false, false);
  59308. if (owner_->isOnDesktop())
  59309. {
  59310. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59311. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59312. | ComponentPeer::windowIsTemporary
  59313. | ComponentPeer::windowIgnoresKeyPresses);
  59314. }
  59315. else if (owner_->getParentComponent() != 0)
  59316. {
  59317. owner_->getParentComponent()->addChildComponent (this);
  59318. }
  59319. }
  59320. ~ShadowWindow()
  59321. {
  59322. }
  59323. void paint (Graphics& g)
  59324. {
  59325. Image* const topLeft = shadowImageSections [type * 3];
  59326. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59327. Image* const filler = shadowImageSections [type * 3 + 2];
  59328. g.setOpacity (1.0f);
  59329. if (type < 2)
  59330. {
  59331. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59332. g.drawImage (topLeft,
  59333. 0, 0, topLeft->getWidth(), imH,
  59334. 0, 0, topLeft->getWidth(), imH);
  59335. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59336. g.drawImage (bottomRight,
  59337. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59338. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59339. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59340. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59341. }
  59342. else
  59343. {
  59344. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59345. g.drawImage (topLeft,
  59346. 0, 0, imW, topLeft->getHeight(),
  59347. 0, 0, imW, topLeft->getHeight());
  59348. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59349. g.drawImage (bottomRight,
  59350. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59351. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59352. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59353. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59354. }
  59355. }
  59356. void resized()
  59357. {
  59358. repaint(); // (needed for correct repainting)
  59359. }
  59360. private:
  59361. ShadowWindow (const ShadowWindow&);
  59362. ShadowWindow& operator= (const ShadowWindow&);
  59363. };
  59364. DropShadower::DropShadower (const float alpha_,
  59365. const int xOffset_,
  59366. const int yOffset_,
  59367. const float blurRadius_)
  59368. : owner (0),
  59369. numShadows (0),
  59370. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59371. xOffset (xOffset_),
  59372. yOffset (yOffset_),
  59373. alpha (alpha_),
  59374. blurRadius (blurRadius_),
  59375. inDestructor (false),
  59376. reentrant (false)
  59377. {
  59378. }
  59379. DropShadower::~DropShadower()
  59380. {
  59381. if (owner != 0)
  59382. owner->removeComponentListener (this);
  59383. inDestructor = true;
  59384. deleteShadowWindows();
  59385. }
  59386. void DropShadower::deleteShadowWindows()
  59387. {
  59388. if (numShadows > 0)
  59389. {
  59390. int i;
  59391. for (i = numShadows; --i >= 0;)
  59392. delete shadowWindows[i];
  59393. for (i = 12; --i >= 0;)
  59394. delete shadowImageSections[i];
  59395. numShadows = 0;
  59396. }
  59397. }
  59398. void DropShadower::setOwner (Component* componentToFollow)
  59399. {
  59400. if (componentToFollow != owner)
  59401. {
  59402. if (owner != 0)
  59403. owner->removeComponentListener (this);
  59404. // (the component can't be null)
  59405. jassert (componentToFollow != 0);
  59406. owner = componentToFollow;
  59407. jassert (owner != 0);
  59408. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59409. owner->addComponentListener (this);
  59410. updateShadows();
  59411. }
  59412. }
  59413. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59414. {
  59415. updateShadows();
  59416. }
  59417. void DropShadower::componentBroughtToFront (Component&)
  59418. {
  59419. bringShadowWindowsToFront();
  59420. }
  59421. void DropShadower::componentChildrenChanged (Component&)
  59422. {
  59423. }
  59424. void DropShadower::componentParentHierarchyChanged (Component&)
  59425. {
  59426. deleteShadowWindows();
  59427. updateShadows();
  59428. }
  59429. void DropShadower::componentVisibilityChanged (Component&)
  59430. {
  59431. updateShadows();
  59432. }
  59433. void DropShadower::updateShadows()
  59434. {
  59435. if (reentrant || inDestructor || (owner == 0))
  59436. return;
  59437. reentrant = true;
  59438. ComponentPeer* const nw = owner->getPeer();
  59439. const bool isOwnerVisible = owner->isVisible()
  59440. && (nw == 0 || ! nw->isMinimised());
  59441. const bool createShadowWindows = numShadows == 0
  59442. && owner->getWidth() > 0
  59443. && owner->getHeight() > 0
  59444. && isOwnerVisible
  59445. && (Desktop::canUseSemiTransparentWindows()
  59446. || owner->getParentComponent() != 0);
  59447. if (createShadowWindows)
  59448. {
  59449. // keep a cached version of the image to save doing the gaussian too often
  59450. String imageId;
  59451. imageId << shadowEdge << T(',')
  59452. << xOffset << T(',')
  59453. << yOffset << T(',')
  59454. << alpha;
  59455. const int hash = imageId.hashCode();
  59456. Image* bigIm = ImageCache::getFromHashCode (hash);
  59457. if (bigIm == 0)
  59458. {
  59459. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59460. Graphics bigG (*bigIm);
  59461. bigG.setColour (Colours::black.withAlpha (alpha));
  59462. bigG.fillRect (shadowEdge + xOffset,
  59463. shadowEdge + yOffset,
  59464. bigIm->getWidth() - (shadowEdge * 2),
  59465. bigIm->getHeight() - (shadowEdge * 2));
  59466. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59467. blurKernel.createGaussianBlur (blurRadius);
  59468. blurKernel.applyToImage (*bigIm, 0,
  59469. xOffset,
  59470. yOffset,
  59471. bigIm->getWidth(),
  59472. bigIm->getHeight());
  59473. ImageCache::addImageToCache (bigIm, hash);
  59474. }
  59475. const int iw = bigIm->getWidth();
  59476. const int ih = bigIm->getHeight();
  59477. const int shadowEdge2 = shadowEdge * 2;
  59478. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59479. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59480. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59481. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59482. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59483. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59484. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59485. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59486. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59487. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59488. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59489. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59490. ImageCache::release (bigIm);
  59491. for (int i = 0; i < 4; ++i)
  59492. {
  59493. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59494. ++numShadows;
  59495. }
  59496. }
  59497. if (numShadows > 0)
  59498. {
  59499. for (int i = numShadows; --i >= 0;)
  59500. {
  59501. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59502. shadowWindows[i]->setVisible (isOwnerVisible);
  59503. }
  59504. const int x = owner->getX();
  59505. const int y = owner->getY() - shadowEdge;
  59506. const int w = owner->getWidth();
  59507. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59508. shadowWindows[0]->setBounds (x - shadowEdge,
  59509. y,
  59510. shadowEdge,
  59511. h);
  59512. shadowWindows[1]->setBounds (x + w,
  59513. y,
  59514. shadowEdge,
  59515. h);
  59516. shadowWindows[2]->setBounds (x,
  59517. y,
  59518. w,
  59519. shadowEdge);
  59520. shadowWindows[3]->setBounds (x,
  59521. owner->getBottom(),
  59522. w,
  59523. shadowEdge);
  59524. }
  59525. reentrant = false;
  59526. if (createShadowWindows)
  59527. bringShadowWindowsToFront();
  59528. }
  59529. void DropShadower::setShadowImage (Image* const src,
  59530. const int num,
  59531. const int w,
  59532. const int h,
  59533. const int sx,
  59534. const int sy)
  59535. {
  59536. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59537. Graphics g (*shadowImageSections[num]);
  59538. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59539. }
  59540. void DropShadower::bringShadowWindowsToFront()
  59541. {
  59542. if (! (inDestructor || reentrant))
  59543. {
  59544. updateShadows();
  59545. reentrant = true;
  59546. for (int i = numShadows; --i >= 0;)
  59547. shadowWindows[i]->toBehind (owner);
  59548. reentrant = false;
  59549. }
  59550. }
  59551. END_JUCE_NAMESPACE
  59552. /*** End of inlined file: juce_DropShadower.cpp ***/
  59553. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59554. BEGIN_JUCE_NAMESPACE
  59555. class MagnifyingPeer : public ComponentPeer
  59556. {
  59557. public:
  59558. MagnifyingPeer (Component* const component_,
  59559. MagnifierComponent* const magnifierComp_)
  59560. : ComponentPeer (component_, 0),
  59561. magnifierComp (magnifierComp_)
  59562. {
  59563. }
  59564. ~MagnifyingPeer()
  59565. {
  59566. }
  59567. void* getNativeHandle() const { return 0; }
  59568. void setVisible (bool) {}
  59569. void setTitle (const String&) {}
  59570. void setPosition (int, int) {}
  59571. void setSize (int, int) {}
  59572. void setBounds (int, int, int, int, const bool) {}
  59573. void setMinimised (bool) {}
  59574. bool isMinimised() const { return false; }
  59575. void setFullScreen (bool) {}
  59576. bool isFullScreen() const { return false; }
  59577. const BorderSize getFrameSize() const { return BorderSize (0); }
  59578. bool setAlwaysOnTop (bool) { return true; }
  59579. void toFront (bool) {}
  59580. void toBehind (ComponentPeer*) {}
  59581. void setIcon (const Image&) {}
  59582. bool isFocused() const
  59583. {
  59584. return magnifierComp->hasKeyboardFocus (true);
  59585. }
  59586. void grabFocus()
  59587. {
  59588. ComponentPeer* peer = magnifierComp->getPeer();
  59589. if (peer != 0)
  59590. peer->grabFocus();
  59591. }
  59592. void textInputRequired (const Point<int>& position)
  59593. {
  59594. ComponentPeer* peer = magnifierComp->getPeer();
  59595. if (peer != 0)
  59596. peer->textInputRequired (position);
  59597. }
  59598. const Rectangle<int> getBounds() const
  59599. {
  59600. return Rectangle<int> (magnifierComp->getScreenX(), magnifierComp->getScreenY(),
  59601. component->getWidth(), component->getHeight());
  59602. }
  59603. const Point<int> getScreenPosition() const
  59604. {
  59605. return magnifierComp->getScreenPosition();
  59606. }
  59607. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  59608. {
  59609. const double zoom = magnifierComp->getScaleFactor();
  59610. return magnifierComp->relativePositionToGlobal (Point<int> (roundToInt (relativePosition.getX() * zoom),
  59611. roundToInt (relativePosition.getY() * zoom)));
  59612. }
  59613. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  59614. {
  59615. const Point<int> p (magnifierComp->globalPositionToRelative (screenPosition));
  59616. const double zoom = magnifierComp->getScaleFactor();
  59617. return Point<int> (roundToInt (p.getX() / zoom),
  59618. roundToInt (p.getY() / zoom));
  59619. }
  59620. bool contains (const Point<int>& position, bool) const
  59621. {
  59622. return ((unsigned int) position.getX()) < (unsigned int) magnifierComp->getWidth()
  59623. && ((unsigned int) position.getY()) < (unsigned int) magnifierComp->getHeight();
  59624. }
  59625. void repaint (int x, int y, int w, int h)
  59626. {
  59627. const double zoom = magnifierComp->getScaleFactor();
  59628. magnifierComp->repaint ((int) (x * zoom),
  59629. (int) (y * zoom),
  59630. roundToInt (w * zoom) + 1,
  59631. roundToInt (h * zoom) + 1);
  59632. }
  59633. void performAnyPendingRepaintsNow()
  59634. {
  59635. }
  59636. juce_UseDebuggingNewOperator
  59637. private:
  59638. MagnifierComponent* const magnifierComp;
  59639. MagnifyingPeer (const MagnifyingPeer&);
  59640. MagnifyingPeer& operator= (const MagnifyingPeer&);
  59641. };
  59642. class PeerHolderComp : public Component
  59643. {
  59644. public:
  59645. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59646. : magnifierComp (magnifierComp_)
  59647. {
  59648. setVisible (true);
  59649. }
  59650. ~PeerHolderComp()
  59651. {
  59652. }
  59653. ComponentPeer* createNewPeer (int, void*)
  59654. {
  59655. return new MagnifyingPeer (this, magnifierComp);
  59656. }
  59657. void childBoundsChanged (Component* c)
  59658. {
  59659. if (c != 0)
  59660. {
  59661. setSize (c->getWidth(), c->getHeight());
  59662. magnifierComp->childBoundsChanged (this);
  59663. }
  59664. }
  59665. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59666. {
  59667. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59668. Component* const p = magnifierComp->getParentComponent();
  59669. if (p != 0)
  59670. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59671. }
  59672. private:
  59673. MagnifierComponent* const magnifierComp;
  59674. PeerHolderComp (const PeerHolderComp&);
  59675. PeerHolderComp& operator= (const PeerHolderComp&);
  59676. };
  59677. MagnifierComponent::MagnifierComponent (Component* const content_,
  59678. const bool deleteContentCompWhenNoLongerNeeded)
  59679. : content (content_),
  59680. scaleFactor (0.0),
  59681. peer (0),
  59682. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59683. quality (Graphics::lowResamplingQuality),
  59684. mouseSource (0, true)
  59685. {
  59686. holderComp = new PeerHolderComp (this);
  59687. setScaleFactor (1.0);
  59688. }
  59689. MagnifierComponent::~MagnifierComponent()
  59690. {
  59691. delete holderComp;
  59692. if (deleteContent)
  59693. delete content;
  59694. }
  59695. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59696. {
  59697. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59698. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59699. if (scaleFactor != newScaleFactor)
  59700. {
  59701. scaleFactor = newScaleFactor;
  59702. if (scaleFactor == 1.0)
  59703. {
  59704. holderComp->removeFromDesktop();
  59705. peer = 0;
  59706. addChildComponent (content);
  59707. childBoundsChanged (content);
  59708. }
  59709. else
  59710. {
  59711. holderComp->addAndMakeVisible (content);
  59712. holderComp->childBoundsChanged (content);
  59713. childBoundsChanged (holderComp);
  59714. holderComp->addToDesktop (0);
  59715. peer = holderComp->getPeer();
  59716. }
  59717. repaint();
  59718. }
  59719. }
  59720. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59721. {
  59722. quality = newQuality;
  59723. }
  59724. void MagnifierComponent::paint (Graphics& g)
  59725. {
  59726. const int w = holderComp->getWidth();
  59727. const int h = holderComp->getHeight();
  59728. if (w == 0 || h == 0)
  59729. return;
  59730. const Rectangle<int> r (g.getClipBounds());
  59731. const int srcX = (int) (r.getX() / scaleFactor);
  59732. const int srcY = (int) (r.getY() / scaleFactor);
  59733. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59734. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59735. if (scaleFactor >= 1.0)
  59736. {
  59737. ++srcW;
  59738. ++srcH;
  59739. }
  59740. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59741. temp.clear (srcX, srcY, srcW, srcH);
  59742. {
  59743. Graphics g2 (temp);
  59744. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59745. holderComp->paintEntireComponent (g2);
  59746. }
  59747. g.setImageResamplingQuality (quality);
  59748. g.drawImageTransformed (&temp, temp.getBounds(),
  59749. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  59750. false);
  59751. }
  59752. void MagnifierComponent::childBoundsChanged (Component* c)
  59753. {
  59754. if (c != 0)
  59755. setSize (roundToInt (c->getWidth() * scaleFactor),
  59756. roundToInt (c->getHeight() * scaleFactor));
  59757. }
  59758. void MagnifierComponent::passOnMouseEventToPeer (const MouseEvent& e)
  59759. {
  59760. if (peer != 0)
  59761. mouseSource.handleEvent (peer, Point<int> (scaleInt (e.x), scaleInt (e.y)),
  59762. e.eventTime.toMilliseconds(), ModifierKeys::getCurrentModifiers());
  59763. }
  59764. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59765. {
  59766. passOnMouseEventToPeer (e);
  59767. }
  59768. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59769. {
  59770. passOnMouseEventToPeer (e);
  59771. }
  59772. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59773. {
  59774. passOnMouseEventToPeer (e);
  59775. }
  59776. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59777. {
  59778. passOnMouseEventToPeer (e);
  59779. }
  59780. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59781. {
  59782. passOnMouseEventToPeer (e);
  59783. }
  59784. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59785. {
  59786. passOnMouseEventToPeer (e);
  59787. }
  59788. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59789. {
  59790. if (peer != 0)
  59791. peer->handleMouseWheel (e.source.getIndex(),
  59792. Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds(),
  59793. ix * 256.0f, iy * 256.0f);
  59794. else
  59795. Component::mouseWheelMove (e, ix, iy);
  59796. }
  59797. int MagnifierComponent::scaleInt (const int n) const
  59798. {
  59799. return roundToInt (n / scaleFactor);
  59800. }
  59801. END_JUCE_NAMESPACE
  59802. /*** End of inlined file: juce_MagnifierComponent.cpp ***/
  59803. /*** Start of inlined file: juce_MidiKeyboardComponent.cpp ***/
  59804. BEGIN_JUCE_NAMESPACE
  59805. class MidiKeyboardUpDownButton : public Button
  59806. {
  59807. public:
  59808. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59809. const int delta_)
  59810. : Button (String::empty),
  59811. owner (owner_),
  59812. delta (delta_)
  59813. {
  59814. setOpaque (true);
  59815. }
  59816. ~MidiKeyboardUpDownButton()
  59817. {
  59818. }
  59819. void clicked()
  59820. {
  59821. int note = owner->getLowestVisibleKey();
  59822. if (delta < 0)
  59823. note = (note - 1) / 12;
  59824. else
  59825. note = note / 12 + 1;
  59826. owner->setLowestVisibleKey (note * 12);
  59827. }
  59828. void paintButton (Graphics& g,
  59829. bool isMouseOverButton,
  59830. bool isButtonDown)
  59831. {
  59832. owner->drawUpDownButton (g, getWidth(), getHeight(),
  59833. isMouseOverButton, isButtonDown,
  59834. delta > 0);
  59835. }
  59836. private:
  59837. MidiKeyboardComponent* const owner;
  59838. const int delta;
  59839. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  59840. MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  59841. };
  59842. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  59843. const Orientation orientation_)
  59844. : state (state_),
  59845. xOffset (0),
  59846. blackNoteLength (1),
  59847. keyWidth (16.0f),
  59848. orientation (orientation_),
  59849. midiChannel (1),
  59850. midiInChannelMask (0xffff),
  59851. velocity (1.0f),
  59852. noteUnderMouse (-1),
  59853. mouseDownNote (-1),
  59854. rangeStart (0),
  59855. rangeEnd (127),
  59856. firstKey (12 * 4),
  59857. canScroll (true),
  59858. mouseDragging (false),
  59859. useMousePositionForVelocity (true),
  59860. keyMappingOctave (6),
  59861. octaveNumForMiddleC (3)
  59862. {
  59863. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  59864. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  59865. // initialise with a default set of querty key-mappings..
  59866. const char* const keymap = "awsedftgyhujkolp;";
  59867. for (int i = String (keymap).length(); --i >= 0;)
  59868. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  59869. setOpaque (true);
  59870. setWantsKeyboardFocus (true);
  59871. state.addListener (this);
  59872. }
  59873. MidiKeyboardComponent::~MidiKeyboardComponent()
  59874. {
  59875. state.removeListener (this);
  59876. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  59877. deleteAllChildren();
  59878. }
  59879. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  59880. {
  59881. keyWidth = widthInPixels;
  59882. resized();
  59883. }
  59884. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  59885. {
  59886. if (orientation != newOrientation)
  59887. {
  59888. orientation = newOrientation;
  59889. resized();
  59890. }
  59891. }
  59892. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  59893. const int highestNote)
  59894. {
  59895. jassert (lowestNote >= 0 && lowestNote <= 127);
  59896. jassert (highestNote >= 0 && highestNote <= 127);
  59897. jassert (lowestNote <= highestNote);
  59898. if (rangeStart != lowestNote || rangeEnd != highestNote)
  59899. {
  59900. rangeStart = jlimit (0, 127, lowestNote);
  59901. rangeEnd = jlimit (0, 127, highestNote);
  59902. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  59903. resized();
  59904. }
  59905. }
  59906. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  59907. {
  59908. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  59909. if (noteNumber != firstKey)
  59910. {
  59911. firstKey = noteNumber;
  59912. sendChangeMessage (this);
  59913. resized();
  59914. }
  59915. }
  59916. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  59917. {
  59918. if (canScroll != canScroll_)
  59919. {
  59920. canScroll = canScroll_;
  59921. resized();
  59922. }
  59923. }
  59924. void MidiKeyboardComponent::colourChanged()
  59925. {
  59926. repaint();
  59927. }
  59928. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  59929. {
  59930. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  59931. if (midiChannel != midiChannelNumber)
  59932. {
  59933. resetAnyKeysInUse();
  59934. midiChannel = jlimit (1, 16, midiChannelNumber);
  59935. }
  59936. }
  59937. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  59938. {
  59939. midiInChannelMask = midiChannelMask;
  59940. triggerAsyncUpdate();
  59941. }
  59942. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  59943. {
  59944. velocity = jlimit (0.0f, 1.0f, velocity_);
  59945. useMousePositionForVelocity = useMousePositionForVelocity_;
  59946. }
  59947. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  59948. {
  59949. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  59950. static const float blackNoteWidth = 0.7f;
  59951. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  59952. 1.0f, 2 - blackNoteWidth * 0.4f,
  59953. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  59954. 4.0f, 5 - blackNoteWidth * 0.5f,
  59955. 5.0f, 6 - blackNoteWidth * 0.3f,
  59956. 6.0f };
  59957. static const float widths[] = { 1.0f, blackNoteWidth,
  59958. 1.0f, blackNoteWidth,
  59959. 1.0f, 1.0f, blackNoteWidth,
  59960. 1.0f, blackNoteWidth,
  59961. 1.0f, blackNoteWidth,
  59962. 1.0f };
  59963. const int octave = midiNoteNumber / 12;
  59964. const int note = midiNoteNumber % 12;
  59965. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  59966. w = roundToInt (widths [note] * keyWidth);
  59967. }
  59968. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  59969. {
  59970. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  59971. int rx, rw;
  59972. getKeyPosition (rangeStart, keyWidth, rx, rw);
  59973. x -= xOffset + rx;
  59974. }
  59975. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  59976. {
  59977. int x, y;
  59978. getKeyPos (midiNoteNumber, x, y);
  59979. return x;
  59980. }
  59981. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  59982. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  59983. int MidiKeyboardComponent::xyToNote (const Point<int>& pos, float& mousePositionVelocity)
  59984. {
  59985. if (! reallyContains (pos.getX(), pos.getY(), false))
  59986. return -1;
  59987. Point<int> p (pos);
  59988. if (orientation != horizontalKeyboard)
  59989. {
  59990. p = Point<int> (p.getY(), p.getX());
  59991. if (orientation == verticalKeyboardFacingLeft)
  59992. p = Point<int> (p.getX(), getWidth() - p.getY());
  59993. else
  59994. p = Point<int> (getHeight() - p.getX(), p.getY());
  59995. }
  59996. return remappedXYToNote (p + Point<int> (xOffset, 0), mousePositionVelocity);
  59997. }
  59998. int MidiKeyboardComponent::remappedXYToNote (const Point<int>& pos, float& mousePositionVelocity) const
  59999. {
  60000. if (pos.getY() < blackNoteLength)
  60001. {
  60002. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  60003. {
  60004. for (int i = 0; i < 5; ++i)
  60005. {
  60006. const int note = octaveStart + blackNotes [i];
  60007. if (note >= rangeStart && note <= rangeEnd)
  60008. {
  60009. int kx, kw;
  60010. getKeyPos (note, kx, kw);
  60011. kx += xOffset;
  60012. if (pos.getX() >= kx && pos.getX() < kx + kw)
  60013. {
  60014. mousePositionVelocity = pos.getY() / (float) blackNoteLength;
  60015. return note;
  60016. }
  60017. }
  60018. }
  60019. }
  60020. }
  60021. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  60022. {
  60023. for (int i = 0; i < 7; ++i)
  60024. {
  60025. const int note = octaveStart + whiteNotes [i];
  60026. if (note >= rangeStart && note <= rangeEnd)
  60027. {
  60028. int kx, kw;
  60029. getKeyPos (note, kx, kw);
  60030. kx += xOffset;
  60031. if (pos.getX() >= kx && pos.getX() < kx + kw)
  60032. {
  60033. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  60034. mousePositionVelocity = pos.getY() / (float) whiteNoteLength;
  60035. return note;
  60036. }
  60037. }
  60038. }
  60039. }
  60040. mousePositionVelocity = 0;
  60041. return -1;
  60042. }
  60043. void MidiKeyboardComponent::repaintNote (const int noteNum)
  60044. {
  60045. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60046. {
  60047. int x, w;
  60048. getKeyPos (noteNum, x, w);
  60049. if (orientation == horizontalKeyboard)
  60050. repaint (x, 0, w, getHeight());
  60051. else if (orientation == verticalKeyboardFacingLeft)
  60052. repaint (0, x, getWidth(), w);
  60053. else if (orientation == verticalKeyboardFacingRight)
  60054. repaint (0, getHeight() - x - w, getWidth(), w);
  60055. }
  60056. }
  60057. void MidiKeyboardComponent::paint (Graphics& g)
  60058. {
  60059. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  60060. const Colour lineColour (findColour (keySeparatorLineColourId));
  60061. const Colour textColour (findColour (textLabelColourId));
  60062. int x, w, octave;
  60063. for (octave = 0; octave < 128; octave += 12)
  60064. {
  60065. for (int white = 0; white < 7; ++white)
  60066. {
  60067. const int noteNum = octave + whiteNotes [white];
  60068. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60069. {
  60070. getKeyPos (noteNum, x, w);
  60071. if (orientation == horizontalKeyboard)
  60072. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  60073. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60074. noteUnderMouse == noteNum,
  60075. lineColour, textColour);
  60076. else if (orientation == verticalKeyboardFacingLeft)
  60077. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  60078. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60079. noteUnderMouse == noteNum,
  60080. lineColour, textColour);
  60081. else if (orientation == verticalKeyboardFacingRight)
  60082. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  60083. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60084. noteUnderMouse == noteNum,
  60085. lineColour, textColour);
  60086. }
  60087. }
  60088. }
  60089. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  60090. if (orientation == verticalKeyboardFacingLeft)
  60091. {
  60092. x1 = getWidth() - 1.0f;
  60093. x2 = getWidth() - 5.0f;
  60094. }
  60095. else if (orientation == verticalKeyboardFacingRight)
  60096. x2 = 5.0f;
  60097. else
  60098. y2 = 5.0f;
  60099. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  60100. Colours::transparentBlack, x2, y2, false));
  60101. getKeyPos (rangeEnd, x, w);
  60102. x += w;
  60103. if (orientation == verticalKeyboardFacingLeft)
  60104. g.fillRect (getWidth() - 5, 0, 5, x);
  60105. else if (orientation == verticalKeyboardFacingRight)
  60106. g.fillRect (0, 0, 5, x);
  60107. else
  60108. g.fillRect (0, 0, x, 5);
  60109. g.setColour (lineColour);
  60110. if (orientation == verticalKeyboardFacingLeft)
  60111. g.fillRect (0, 0, 1, x);
  60112. else if (orientation == verticalKeyboardFacingRight)
  60113. g.fillRect (getWidth() - 1, 0, 1, x);
  60114. else
  60115. g.fillRect (0, getHeight() - 1, x, 1);
  60116. const Colour blackNoteColour (findColour (blackNoteColourId));
  60117. for (octave = 0; octave < 128; octave += 12)
  60118. {
  60119. for (int black = 0; black < 5; ++black)
  60120. {
  60121. const int noteNum = octave + blackNotes [black];
  60122. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60123. {
  60124. getKeyPos (noteNum, x, w);
  60125. if (orientation == horizontalKeyboard)
  60126. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  60127. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60128. noteUnderMouse == noteNum,
  60129. blackNoteColour);
  60130. else if (orientation == verticalKeyboardFacingLeft)
  60131. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  60132. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60133. noteUnderMouse == noteNum,
  60134. blackNoteColour);
  60135. else if (orientation == verticalKeyboardFacingRight)
  60136. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  60137. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60138. noteUnderMouse == noteNum,
  60139. blackNoteColour);
  60140. }
  60141. }
  60142. }
  60143. }
  60144. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  60145. Graphics& g, int x, int y, int w, int h,
  60146. bool isDown, bool isOver,
  60147. const Colour& lineColour,
  60148. const Colour& textColour)
  60149. {
  60150. Colour c (Colours::transparentWhite);
  60151. if (isDown)
  60152. c = findColour (keyDownOverlayColourId);
  60153. if (isOver)
  60154. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60155. g.setColour (c);
  60156. g.fillRect (x, y, w, h);
  60157. const String text (getWhiteNoteText (midiNoteNumber));
  60158. if (! text.isEmpty())
  60159. {
  60160. g.setColour (textColour);
  60161. Font f (jmin (12.0f, keyWidth * 0.9f));
  60162. f.setHorizontalScale (0.8f);
  60163. g.setFont (f);
  60164. Justification justification (Justification::centredBottom);
  60165. if (orientation == verticalKeyboardFacingLeft)
  60166. justification = Justification::centredLeft;
  60167. else if (orientation == verticalKeyboardFacingRight)
  60168. justification = Justification::centredRight;
  60169. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  60170. }
  60171. g.setColour (lineColour);
  60172. if (orientation == horizontalKeyboard)
  60173. g.fillRect (x, y, 1, h);
  60174. else if (orientation == verticalKeyboardFacingLeft)
  60175. g.fillRect (x, y, w, 1);
  60176. else if (orientation == verticalKeyboardFacingRight)
  60177. g.fillRect (x, y + h - 1, w, 1);
  60178. if (midiNoteNumber == rangeEnd)
  60179. {
  60180. if (orientation == horizontalKeyboard)
  60181. g.fillRect (x + w, y, 1, h);
  60182. else if (orientation == verticalKeyboardFacingLeft)
  60183. g.fillRect (x, y + h, w, 1);
  60184. else if (orientation == verticalKeyboardFacingRight)
  60185. g.fillRect (x, y - 1, w, 1);
  60186. }
  60187. }
  60188. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  60189. Graphics& g, int x, int y, int w, int h,
  60190. bool isDown, bool isOver,
  60191. const Colour& noteFillColour)
  60192. {
  60193. Colour c (noteFillColour);
  60194. if (isDown)
  60195. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  60196. if (isOver)
  60197. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60198. g.setColour (c);
  60199. g.fillRect (x, y, w, h);
  60200. if (isDown)
  60201. {
  60202. g.setColour (noteFillColour);
  60203. g.drawRect (x, y, w, h);
  60204. }
  60205. else
  60206. {
  60207. const int xIndent = jmax (1, jmin (w, h) / 8);
  60208. g.setColour (c.brighter());
  60209. if (orientation == horizontalKeyboard)
  60210. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  60211. else if (orientation == verticalKeyboardFacingLeft)
  60212. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  60213. else if (orientation == verticalKeyboardFacingRight)
  60214. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  60215. }
  60216. }
  60217. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  60218. {
  60219. octaveNumForMiddleC = octaveNumForMiddleC_;
  60220. repaint();
  60221. }
  60222. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  60223. {
  60224. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  60225. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  60226. return String::empty;
  60227. }
  60228. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  60229. const bool isMouseOver,
  60230. const bool isButtonDown,
  60231. const bool movesOctavesUp)
  60232. {
  60233. g.fillAll (findColour (upDownButtonBackgroundColourId));
  60234. float angle;
  60235. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  60236. angle = movesOctavesUp ? 0.0f : 0.5f;
  60237. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  60238. angle = movesOctavesUp ? 0.25f : 0.75f;
  60239. else
  60240. angle = movesOctavesUp ? 0.75f : 0.25f;
  60241. Path path;
  60242. path.lineTo (0.0f, 1.0f);
  60243. path.lineTo (1.0f, 0.5f);
  60244. path.closeSubPath();
  60245. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  60246. g.setColour (findColour (upDownButtonArrowColourId)
  60247. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  60248. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  60249. w - 2.0f,
  60250. h - 2.0f,
  60251. true));
  60252. }
  60253. void MidiKeyboardComponent::resized()
  60254. {
  60255. int w = getWidth();
  60256. int h = getHeight();
  60257. if (w > 0 && h > 0)
  60258. {
  60259. if (orientation != horizontalKeyboard)
  60260. swapVariables (w, h);
  60261. blackNoteLength = roundToInt (h * 0.7f);
  60262. int kx2, kw2;
  60263. getKeyPos (rangeEnd, kx2, kw2);
  60264. kx2 += kw2;
  60265. if (firstKey != rangeStart)
  60266. {
  60267. int kx1, kw1;
  60268. getKeyPos (rangeStart, kx1, kw1);
  60269. if (kx2 - kx1 <= w)
  60270. {
  60271. firstKey = rangeStart;
  60272. sendChangeMessage (this);
  60273. repaint();
  60274. }
  60275. }
  60276. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60277. scrollDown->setVisible (showScrollButtons);
  60278. scrollUp->setVisible (showScrollButtons);
  60279. xOffset = 0;
  60280. if (showScrollButtons)
  60281. {
  60282. const int scrollButtonW = jmin (12, w / 2);
  60283. if (orientation == horizontalKeyboard)
  60284. {
  60285. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60286. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60287. }
  60288. else if (orientation == verticalKeyboardFacingLeft)
  60289. {
  60290. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60291. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60292. }
  60293. else if (orientation == verticalKeyboardFacingRight)
  60294. {
  60295. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60296. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60297. }
  60298. int endOfLastKey, kw;
  60299. getKeyPos (rangeEnd, endOfLastKey, kw);
  60300. endOfLastKey += kw;
  60301. float mousePositionVelocity;
  60302. const int spaceAvailable = w - scrollButtonW * 2;
  60303. const int lastStartKey = remappedXYToNote (Point<int> (endOfLastKey - spaceAvailable, 0), mousePositionVelocity) + 1;
  60304. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60305. {
  60306. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60307. sendChangeMessage (this);
  60308. }
  60309. int newOffset = 0;
  60310. getKeyPos (firstKey, newOffset, kw);
  60311. xOffset = newOffset - scrollButtonW;
  60312. }
  60313. else
  60314. {
  60315. firstKey = rangeStart;
  60316. }
  60317. timerCallback();
  60318. repaint();
  60319. }
  60320. }
  60321. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60322. {
  60323. triggerAsyncUpdate();
  60324. }
  60325. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60326. {
  60327. triggerAsyncUpdate();
  60328. }
  60329. void MidiKeyboardComponent::handleAsyncUpdate()
  60330. {
  60331. for (int i = rangeStart; i <= rangeEnd; ++i)
  60332. {
  60333. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60334. {
  60335. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60336. repaintNote (i);
  60337. }
  60338. }
  60339. }
  60340. void MidiKeyboardComponent::resetAnyKeysInUse()
  60341. {
  60342. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60343. {
  60344. state.allNotesOff (midiChannel);
  60345. keysPressed.clear();
  60346. mouseDownNote = -1;
  60347. }
  60348. }
  60349. void MidiKeyboardComponent::updateNoteUnderMouse (const Point<int>& pos)
  60350. {
  60351. float mousePositionVelocity = 0.0f;
  60352. const int newNote = (mouseDragging || isMouseOver())
  60353. ? xyToNote (pos, mousePositionVelocity) : -1;
  60354. if (noteUnderMouse != newNote)
  60355. {
  60356. if (mouseDownNote >= 0)
  60357. {
  60358. state.noteOff (midiChannel, mouseDownNote);
  60359. mouseDownNote = -1;
  60360. }
  60361. if (mouseDragging && newNote >= 0)
  60362. {
  60363. if (! useMousePositionForVelocity)
  60364. mousePositionVelocity = 1.0f;
  60365. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60366. mouseDownNote = newNote;
  60367. }
  60368. repaintNote (noteUnderMouse);
  60369. noteUnderMouse = newNote;
  60370. repaintNote (noteUnderMouse);
  60371. }
  60372. else if (mouseDownNote >= 0 && ! mouseDragging)
  60373. {
  60374. state.noteOff (midiChannel, mouseDownNote);
  60375. mouseDownNote = -1;
  60376. }
  60377. }
  60378. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60379. {
  60380. updateNoteUnderMouse (e.getPosition());
  60381. stopTimer();
  60382. }
  60383. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60384. {
  60385. float mousePositionVelocity;
  60386. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60387. if (newNote >= 0)
  60388. mouseDraggedToKey (newNote, e);
  60389. updateNoteUnderMouse (e.getPosition());
  60390. }
  60391. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60392. {
  60393. return true;
  60394. }
  60395. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60396. {
  60397. }
  60398. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60399. {
  60400. float mousePositionVelocity;
  60401. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60402. mouseDragging = false;
  60403. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60404. {
  60405. repaintNote (noteUnderMouse);
  60406. noteUnderMouse = -1;
  60407. mouseDragging = true;
  60408. updateNoteUnderMouse (e.getPosition());
  60409. startTimer (500);
  60410. }
  60411. }
  60412. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60413. {
  60414. mouseDragging = false;
  60415. updateNoteUnderMouse (e.getPosition());
  60416. stopTimer();
  60417. }
  60418. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60419. {
  60420. updateNoteUnderMouse (e.getPosition());
  60421. }
  60422. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60423. {
  60424. updateNoteUnderMouse (e.getPosition());
  60425. }
  60426. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60427. {
  60428. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60429. }
  60430. void MidiKeyboardComponent::timerCallback()
  60431. {
  60432. updateNoteUnderMouse (getMouseXYRelative());
  60433. }
  60434. void MidiKeyboardComponent::clearKeyMappings()
  60435. {
  60436. resetAnyKeysInUse();
  60437. keyPressNotes.clear();
  60438. keyPresses.clear();
  60439. }
  60440. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60441. const int midiNoteOffsetFromC)
  60442. {
  60443. removeKeyPressForNote (midiNoteOffsetFromC);
  60444. keyPressNotes.add (midiNoteOffsetFromC);
  60445. keyPresses.add (key);
  60446. }
  60447. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60448. {
  60449. for (int i = keyPressNotes.size(); --i >= 0;)
  60450. {
  60451. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60452. {
  60453. keyPressNotes.remove (i);
  60454. keyPresses.remove (i);
  60455. }
  60456. }
  60457. }
  60458. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60459. {
  60460. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60461. keyMappingOctave = newOctaveNumber;
  60462. }
  60463. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60464. {
  60465. bool keyPressUsed = false;
  60466. for (int i = keyPresses.size(); --i >= 0;)
  60467. {
  60468. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60469. if (keyPresses.getReference(i).isCurrentlyDown())
  60470. {
  60471. if (! keysPressed [note])
  60472. {
  60473. keysPressed.setBit (note);
  60474. state.noteOn (midiChannel, note, velocity);
  60475. keyPressUsed = true;
  60476. }
  60477. }
  60478. else
  60479. {
  60480. if (keysPressed [note])
  60481. {
  60482. keysPressed.clearBit (note);
  60483. state.noteOff (midiChannel, note);
  60484. keyPressUsed = true;
  60485. }
  60486. }
  60487. }
  60488. return keyPressUsed;
  60489. }
  60490. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60491. {
  60492. resetAnyKeysInUse();
  60493. }
  60494. END_JUCE_NAMESPACE
  60495. /*** End of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60496. /*** Start of inlined file: juce_OpenGLComponent.cpp ***/
  60497. #if JUCE_OPENGL
  60498. BEGIN_JUCE_NAMESPACE
  60499. extern void juce_glViewport (const int w, const int h);
  60500. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60501. const int alphaBits_,
  60502. const int depthBufferBits_,
  60503. const int stencilBufferBits_) throw()
  60504. : redBits (bitsPerRGBComponent),
  60505. greenBits (bitsPerRGBComponent),
  60506. blueBits (bitsPerRGBComponent),
  60507. alphaBits (alphaBits_),
  60508. depthBufferBits (depthBufferBits_),
  60509. stencilBufferBits (stencilBufferBits_),
  60510. accumulationBufferRedBits (0),
  60511. accumulationBufferGreenBits (0),
  60512. accumulationBufferBlueBits (0),
  60513. accumulationBufferAlphaBits (0),
  60514. fullSceneAntiAliasingNumSamples (0)
  60515. {
  60516. }
  60517. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const throw()
  60518. {
  60519. return memcmp (this, &other, sizeof (other)) == 0;
  60520. }
  60521. static VoidArray knownContexts;
  60522. OpenGLContext::OpenGLContext() throw()
  60523. {
  60524. knownContexts.add (this);
  60525. }
  60526. OpenGLContext::~OpenGLContext()
  60527. {
  60528. knownContexts.removeValue (this);
  60529. }
  60530. OpenGLContext* OpenGLContext::getCurrentContext()
  60531. {
  60532. for (int i = knownContexts.size(); --i >= 0;)
  60533. {
  60534. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60535. if (oglc->isActive())
  60536. return oglc;
  60537. }
  60538. return 0;
  60539. }
  60540. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60541. {
  60542. public:
  60543. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60544. : ComponentMovementWatcher (owner_),
  60545. owner (owner_),
  60546. wasShowing (false)
  60547. {
  60548. }
  60549. ~OpenGLComponentWatcher() {}
  60550. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60551. {
  60552. owner->updateContextPosition();
  60553. }
  60554. void componentPeerChanged()
  60555. {
  60556. const ScopedLock sl (owner->getContextLock());
  60557. owner->deleteContext();
  60558. }
  60559. void componentVisibilityChanged (Component&)
  60560. {
  60561. const bool isShowingNow = owner->isShowing();
  60562. if (wasShowing != isShowingNow)
  60563. {
  60564. wasShowing = isShowingNow;
  60565. owner->updateContextPosition();
  60566. }
  60567. }
  60568. juce_UseDebuggingNewOperator
  60569. private:
  60570. OpenGLComponent* const owner;
  60571. bool wasShowing;
  60572. };
  60573. OpenGLComponent::OpenGLComponent()
  60574. : context (0),
  60575. contextToShareListsWith (0),
  60576. needToUpdateViewport (true)
  60577. {
  60578. setOpaque (true);
  60579. componentWatcher = new OpenGLComponentWatcher (this);
  60580. }
  60581. OpenGLComponent::~OpenGLComponent()
  60582. {
  60583. deleteContext();
  60584. componentWatcher = 0;
  60585. }
  60586. void OpenGLComponent::deleteContext()
  60587. {
  60588. const ScopedLock sl (contextLock);
  60589. deleteAndZero (context);
  60590. }
  60591. void OpenGLComponent::updateContextPosition()
  60592. {
  60593. needToUpdateViewport = true;
  60594. if (getWidth() > 0 && getHeight() > 0)
  60595. {
  60596. Component* const topComp = getTopLevelComponent();
  60597. if (topComp->getPeer() != 0)
  60598. {
  60599. const ScopedLock sl (contextLock);
  60600. if (context != 0)
  60601. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60602. getScreenY() - topComp->getScreenY(),
  60603. getWidth(),
  60604. getHeight(),
  60605. topComp->getHeight());
  60606. }
  60607. }
  60608. }
  60609. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60610. {
  60611. OpenGLPixelFormat pf;
  60612. const ScopedLock sl (contextLock);
  60613. if (context != 0)
  60614. pf = context->getPixelFormat();
  60615. return pf;
  60616. }
  60617. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60618. {
  60619. if (! (preferredPixelFormat == formatToUse))
  60620. {
  60621. const ScopedLock sl (contextLock);
  60622. deleteContext();
  60623. preferredPixelFormat = formatToUse;
  60624. }
  60625. }
  60626. void OpenGLComponent::shareWith (OpenGLContext* c)
  60627. {
  60628. if (contextToShareListsWith != c)
  60629. {
  60630. const ScopedLock sl (contextLock);
  60631. deleteContext();
  60632. contextToShareListsWith = c;
  60633. }
  60634. }
  60635. bool OpenGLComponent::makeCurrentContextActive()
  60636. {
  60637. if (context == 0)
  60638. {
  60639. const ScopedLock sl (contextLock);
  60640. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60641. {
  60642. context = OpenGLContext::createContextForWindow (this,
  60643. preferredPixelFormat,
  60644. contextToShareListsWith);
  60645. if (context != 0)
  60646. {
  60647. updateContextPosition();
  60648. if (context->makeActive())
  60649. newOpenGLContextCreated();
  60650. }
  60651. }
  60652. }
  60653. return context != 0 && context->makeActive();
  60654. }
  60655. void OpenGLComponent::makeCurrentContextInactive()
  60656. {
  60657. if (context != 0)
  60658. context->makeInactive();
  60659. }
  60660. bool OpenGLComponent::isActiveContext() const throw()
  60661. {
  60662. return context != 0 && context->isActive();
  60663. }
  60664. void OpenGLComponent::swapBuffers()
  60665. {
  60666. if (context != 0)
  60667. context->swapBuffers();
  60668. }
  60669. void OpenGLComponent::paint (Graphics&)
  60670. {
  60671. if (renderAndSwapBuffers())
  60672. {
  60673. ComponentPeer* const peer = getPeer();
  60674. if (peer != 0)
  60675. {
  60676. const Point<int> topLeft (getScreenPosition() - peer->getScreenPosition());
  60677. peer->addMaskedRegion (topLeft.getX(), topLeft.getY(), getWidth(), getHeight());
  60678. }
  60679. }
  60680. }
  60681. bool OpenGLComponent::renderAndSwapBuffers()
  60682. {
  60683. const ScopedLock sl (contextLock);
  60684. if (! makeCurrentContextActive())
  60685. return false;
  60686. if (needToUpdateViewport)
  60687. {
  60688. needToUpdateViewport = false;
  60689. juce_glViewport (getWidth(), getHeight());
  60690. }
  60691. renderOpenGL();
  60692. swapBuffers();
  60693. return true;
  60694. }
  60695. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60696. {
  60697. Component::internalRepaint (x, y, w, h);
  60698. if (context != 0)
  60699. context->repaint();
  60700. }
  60701. END_JUCE_NAMESPACE
  60702. #endif
  60703. /*** End of inlined file: juce_OpenGLComponent.cpp ***/
  60704. /*** Start of inlined file: juce_PreferencesPanel.cpp ***/
  60705. BEGIN_JUCE_NAMESPACE
  60706. PreferencesPanel::PreferencesPanel()
  60707. : buttonSize (70)
  60708. {
  60709. }
  60710. PreferencesPanel::~PreferencesPanel()
  60711. {
  60712. currentPage = 0;
  60713. deleteAllChildren();
  60714. }
  60715. void PreferencesPanel::addSettingsPage (const String& title,
  60716. const Drawable* icon,
  60717. const Drawable* overIcon,
  60718. const Drawable* downIcon)
  60719. {
  60720. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60721. button->setImages (icon, overIcon, downIcon);
  60722. button->setRadioGroupId (1);
  60723. button->addButtonListener (this);
  60724. button->setClickingTogglesState (true);
  60725. button->setWantsKeyboardFocus (false);
  60726. addAndMakeVisible (button);
  60727. resized();
  60728. if (currentPage == 0)
  60729. setCurrentPage (title);
  60730. }
  60731. void PreferencesPanel::addSettingsPage (const String& title,
  60732. const char* imageData,
  60733. const int imageDataSize)
  60734. {
  60735. DrawableImage icon, iconOver, iconDown;
  60736. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60737. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60738. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60739. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60740. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60741. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60742. }
  60743. class PrefsDialogWindow : public DialogWindow
  60744. {
  60745. public:
  60746. PrefsDialogWindow (const String& dialogtitle,
  60747. const Colour& backgroundColour)
  60748. : DialogWindow (dialogtitle, backgroundColour, true)
  60749. {
  60750. }
  60751. ~PrefsDialogWindow()
  60752. {
  60753. }
  60754. void closeButtonPressed()
  60755. {
  60756. exitModalState (0);
  60757. }
  60758. private:
  60759. PrefsDialogWindow (const PrefsDialogWindow&);
  60760. PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60761. };
  60762. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60763. int dialogWidth,
  60764. int dialogHeight,
  60765. const Colour& backgroundColour)
  60766. {
  60767. setSize (dialogWidth, dialogHeight);
  60768. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60769. dw.setContentComponent (this, true, true);
  60770. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60771. dw.runModalLoop();
  60772. dw.setContentComponent (0, false, false);
  60773. }
  60774. void PreferencesPanel::resized()
  60775. {
  60776. int x = 0;
  60777. for (int i = 0; i < getNumChildComponents(); ++i)
  60778. {
  60779. Component* c = getChildComponent (i);
  60780. if (dynamic_cast <DrawableButton*> (c) == 0)
  60781. {
  60782. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60783. }
  60784. else
  60785. {
  60786. c->setBounds (x, 0, buttonSize, buttonSize);
  60787. x += buttonSize;
  60788. }
  60789. }
  60790. }
  60791. void PreferencesPanel::paint (Graphics& g)
  60792. {
  60793. g.setColour (Colours::grey);
  60794. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60795. }
  60796. void PreferencesPanel::setCurrentPage (const String& pageName)
  60797. {
  60798. if (currentPageName != pageName)
  60799. {
  60800. currentPageName = pageName;
  60801. currentPage = 0;
  60802. currentPage = createComponentForPage (pageName);
  60803. if (currentPage != 0)
  60804. {
  60805. addAndMakeVisible (currentPage);
  60806. currentPage->toBack();
  60807. resized();
  60808. }
  60809. for (int i = 0; i < getNumChildComponents(); ++i)
  60810. {
  60811. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60812. if (db != 0 && db->getName() == pageName)
  60813. {
  60814. db->setToggleState (true, false);
  60815. break;
  60816. }
  60817. }
  60818. }
  60819. }
  60820. void PreferencesPanel::buttonClicked (Button*)
  60821. {
  60822. for (int i = 0; i < getNumChildComponents(); ++i)
  60823. {
  60824. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60825. if (db != 0 && db->getToggleState())
  60826. {
  60827. setCurrentPage (db->getName());
  60828. break;
  60829. }
  60830. }
  60831. }
  60832. END_JUCE_NAMESPACE
  60833. /*** End of inlined file: juce_PreferencesPanel.cpp ***/
  60834. /*** Start of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60835. #if JUCE_WINDOWS || JUCE_LINUX
  60836. BEGIN_JUCE_NAMESPACE
  60837. SystemTrayIconComponent::SystemTrayIconComponent()
  60838. {
  60839. addToDesktop (0);
  60840. }
  60841. SystemTrayIconComponent::~SystemTrayIconComponent()
  60842. {
  60843. }
  60844. END_JUCE_NAMESPACE
  60845. #endif
  60846. /*** End of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60847. /*** Start of inlined file: juce_AlertWindow.cpp ***/
  60848. BEGIN_JUCE_NAMESPACE
  60849. static const int titleH = 24;
  60850. static const int iconWidth = 80;
  60851. class AlertWindowTextEditor : public TextEditor
  60852. {
  60853. public:
  60854. static const tchar passwordChar;
  60855. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  60856. : TextEditor (name, isPasswordBox ? passwordChar : 0)
  60857. {
  60858. setSelectAllWhenFocused (true);
  60859. }
  60860. ~AlertWindowTextEditor()
  60861. {
  60862. }
  60863. void returnPressed()
  60864. {
  60865. // pass these up the component hierarchy to be trigger the buttons
  60866. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, T('\n')));
  60867. }
  60868. void escapePressed()
  60869. {
  60870. // pass these up the component hierarchy to be trigger the buttons
  60871. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  60872. }
  60873. private:
  60874. AlertWindowTextEditor (const AlertWindowTextEditor&);
  60875. AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  60876. };
  60877. #if JUCE_LINUX
  60878. const tchar AlertWindowTextEditor::passwordChar = 0x2022;
  60879. #else
  60880. const tchar AlertWindowTextEditor::passwordChar = 0x25cf;
  60881. #endif
  60882. AlertWindow::AlertWindow (const String& title,
  60883. const String& message,
  60884. AlertIconType iconType,
  60885. Component* associatedComponent_)
  60886. : TopLevelWindow (title, true),
  60887. alertIconType (iconType),
  60888. associatedComponent (associatedComponent_)
  60889. {
  60890. if (message.isEmpty())
  60891. text = T(" "); // to force an update if the message is empty
  60892. setMessage (message);
  60893. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  60894. {
  60895. Component* const c = Desktop::getInstance().getComponent (i);
  60896. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  60897. {
  60898. setAlwaysOnTop (true);
  60899. break;
  60900. }
  60901. }
  60902. if (JUCEApplication::getInstance() == 0)
  60903. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  60904. lookAndFeelChanged();
  60905. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  60906. }
  60907. AlertWindow::~AlertWindow()
  60908. {
  60909. for (int i = customComps.size(); --i >= 0;)
  60910. removeChildComponent ((Component*) customComps[i]);
  60911. deleteAllChildren();
  60912. }
  60913. void AlertWindow::userTriedToCloseWindow()
  60914. {
  60915. exitModalState (0);
  60916. }
  60917. void AlertWindow::setMessage (const String& message)
  60918. {
  60919. const String newMessage (message.substring (0, 2048));
  60920. if (text != newMessage)
  60921. {
  60922. text = newMessage;
  60923. font.setHeight (15.0f);
  60924. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  60925. textLayout.setText (getName() + T("\n\n"), titleFont);
  60926. textLayout.appendText (text, font);
  60927. updateLayout (true);
  60928. repaint();
  60929. }
  60930. }
  60931. void AlertWindow::buttonClicked (Button* button)
  60932. {
  60933. for (int i = 0; i < buttons.size(); i++)
  60934. {
  60935. TextButton* const c = (TextButton*) buttons[i];
  60936. if (button->getName() == c->getName())
  60937. {
  60938. if (c->getParentComponent() != 0)
  60939. c->getParentComponent()->exitModalState (c->getCommandID());
  60940. break;
  60941. }
  60942. }
  60943. }
  60944. void AlertWindow::addButton (const String& name,
  60945. const int returnValue,
  60946. const KeyPress& shortcutKey1,
  60947. const KeyPress& shortcutKey2)
  60948. {
  60949. TextButton* const b = new TextButton (name, String::empty);
  60950. b->setWantsKeyboardFocus (true);
  60951. b->setMouseClickGrabsKeyboardFocus (false);
  60952. b->setCommandToTrigger (0, returnValue, false);
  60953. b->addShortcut (shortcutKey1);
  60954. b->addShortcut (shortcutKey2);
  60955. b->addButtonListener (this);
  60956. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  60957. addAndMakeVisible (b, 0);
  60958. buttons.add (b);
  60959. updateLayout (false);
  60960. }
  60961. int AlertWindow::getNumButtons() const
  60962. {
  60963. return buttons.size();
  60964. }
  60965. void AlertWindow::addTextEditor (const String& name,
  60966. const String& initialContents,
  60967. const String& onScreenLabel,
  60968. const bool isPasswordBox)
  60969. {
  60970. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  60971. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  60972. tc->setFont (font);
  60973. tc->setText (initialContents);
  60974. tc->setCaretPosition (initialContents.length());
  60975. addAndMakeVisible (tc);
  60976. textBoxes.add (tc);
  60977. allComps.add (tc);
  60978. textboxNames.add (onScreenLabel);
  60979. updateLayout (false);
  60980. }
  60981. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  60982. {
  60983. for (int i = textBoxes.size(); --i >= 0;)
  60984. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  60985. return ((TextEditor*)textBoxes[i])->getText();
  60986. return String::empty;
  60987. }
  60988. void AlertWindow::addComboBox (const String& name,
  60989. const StringArray& items,
  60990. const String& onScreenLabel)
  60991. {
  60992. ComboBox* const cb = new ComboBox (name);
  60993. for (int i = 0; i < items.size(); ++i)
  60994. cb->addItem (items[i], i + 1);
  60995. addAndMakeVisible (cb);
  60996. cb->setSelectedItemIndex (0);
  60997. comboBoxes.add (cb);
  60998. allComps.add (cb);
  60999. comboBoxNames.add (onScreenLabel);
  61000. updateLayout (false);
  61001. }
  61002. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  61003. {
  61004. for (int i = comboBoxes.size(); --i >= 0;)
  61005. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  61006. return (ComboBox*) comboBoxes[i];
  61007. return 0;
  61008. }
  61009. class AlertTextComp : public TextEditor
  61010. {
  61011. public:
  61012. AlertTextComp (const String& message,
  61013. const Font& font)
  61014. {
  61015. setReadOnly (true);
  61016. setMultiLine (true, true);
  61017. setCaretVisible (false);
  61018. setScrollbarsShown (true);
  61019. lookAndFeelChanged();
  61020. setWantsKeyboardFocus (false);
  61021. setFont (font);
  61022. setText (message, false);
  61023. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  61024. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  61025. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  61026. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  61027. }
  61028. ~AlertTextComp()
  61029. {
  61030. }
  61031. int getPreferredWidth() const throw() { return bestWidth; }
  61032. void updateLayout (const int width)
  61033. {
  61034. TextLayout text;
  61035. text.appendText (getText(), getFont());
  61036. text.layout (width - 8, Justification::topLeft, true);
  61037. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  61038. }
  61039. private:
  61040. int bestWidth;
  61041. AlertTextComp (const AlertTextComp&);
  61042. AlertTextComp& operator= (const AlertTextComp&);
  61043. };
  61044. void AlertWindow::addTextBlock (const String& text)
  61045. {
  61046. AlertTextComp* const c = new AlertTextComp (text, font);
  61047. textBlocks.add (c);
  61048. allComps.add (c);
  61049. addAndMakeVisible (c);
  61050. updateLayout (false);
  61051. }
  61052. void AlertWindow::addProgressBarComponent (double& progressValue)
  61053. {
  61054. ProgressBar* const pb = new ProgressBar (progressValue);
  61055. progressBars.add (pb);
  61056. allComps.add (pb);
  61057. addAndMakeVisible (pb);
  61058. updateLayout (false);
  61059. }
  61060. void AlertWindow::addCustomComponent (Component* const component)
  61061. {
  61062. customComps.add (component);
  61063. allComps.add (component);
  61064. addAndMakeVisible (component);
  61065. updateLayout (false);
  61066. }
  61067. int AlertWindow::getNumCustomComponents() const
  61068. {
  61069. return customComps.size();
  61070. }
  61071. Component* AlertWindow::getCustomComponent (const int index) const
  61072. {
  61073. return (Component*) customComps [index];
  61074. }
  61075. Component* AlertWindow::removeCustomComponent (const int index)
  61076. {
  61077. Component* const c = getCustomComponent (index);
  61078. if (c != 0)
  61079. {
  61080. customComps.removeValue (c);
  61081. allComps.removeValue (c);
  61082. removeChildComponent (c);
  61083. updateLayout (false);
  61084. }
  61085. return c;
  61086. }
  61087. void AlertWindow::paint (Graphics& g)
  61088. {
  61089. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  61090. g.setColour (findColour (textColourId));
  61091. g.setFont (getLookAndFeel().getAlertWindowFont());
  61092. int i;
  61093. for (i = textBoxes.size(); --i >= 0;)
  61094. {
  61095. const TextEditor* const te = (TextEditor*) textBoxes[i];
  61096. g.drawFittedText (textboxNames[i],
  61097. te->getX(), te->getY() - 14,
  61098. te->getWidth(), 14,
  61099. Justification::centredLeft, 1);
  61100. }
  61101. for (i = comboBoxNames.size(); --i >= 0;)
  61102. {
  61103. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  61104. g.drawFittedText (comboBoxNames[i],
  61105. cb->getX(), cb->getY() - 14,
  61106. cb->getWidth(), 14,
  61107. Justification::centredLeft, 1);
  61108. }
  61109. for (i = customComps.size(); --i >= 0;)
  61110. {
  61111. const Component* const c = (Component*) customComps[i];
  61112. g.drawFittedText (c->getName(),
  61113. c->getX(), c->getY() - 14,
  61114. c->getWidth(), 14,
  61115. Justification::centredLeft, 1);
  61116. }
  61117. }
  61118. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  61119. {
  61120. const int wid = jmax (font.getStringWidth (text),
  61121. font.getStringWidth (getName()));
  61122. const int sw = (int) sqrt (font.getHeight() * wid);
  61123. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  61124. const int edgeGap = 10;
  61125. const int labelHeight = 18;
  61126. int iconSpace;
  61127. if (alertIconType == NoIcon)
  61128. {
  61129. textLayout.layout (w, Justification::horizontallyCentred, true);
  61130. iconSpace = 0;
  61131. }
  61132. else
  61133. {
  61134. textLayout.layout (w, Justification::left, true);
  61135. iconSpace = iconWidth;
  61136. }
  61137. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  61138. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61139. const int textLayoutH = textLayout.getHeight();
  61140. const int textBottom = 16 + titleH + textLayoutH;
  61141. int h = textBottom;
  61142. int buttonW = 40;
  61143. int i;
  61144. for (i = 0; i < buttons.size(); ++i)
  61145. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  61146. w = jmax (buttonW, w);
  61147. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  61148. if (buttons.size() > 0)
  61149. h += 20 + ((TextButton*) buttons[0])->getHeight();
  61150. for (i = customComps.size(); --i >= 0;)
  61151. {
  61152. Component* c = (Component*) customComps[i];
  61153. w = jmax (w, (c->getWidth() * 100) / 80);
  61154. h += 10 + c->getHeight();
  61155. if (c->getName().isNotEmpty())
  61156. h += labelHeight;
  61157. }
  61158. for (i = textBlocks.size(); --i >= 0;)
  61159. {
  61160. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61161. w = jmax (w, ac->getPreferredWidth());
  61162. }
  61163. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61164. for (i = textBlocks.size(); --i >= 0;)
  61165. {
  61166. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61167. ac->updateLayout ((int) (w * 0.8f));
  61168. h += ac->getHeight() + 10;
  61169. }
  61170. h = jmin (getParentHeight() - 50, h);
  61171. if (onlyIncreaseSize)
  61172. {
  61173. w = jmax (w, getWidth());
  61174. h = jmax (h, getHeight());
  61175. }
  61176. if (! isVisible())
  61177. {
  61178. centreAroundComponent (associatedComponent, w, h);
  61179. }
  61180. else
  61181. {
  61182. const int cx = getX() + getWidth() / 2;
  61183. const int cy = getY() + getHeight() / 2;
  61184. setBounds (cx - w / 2,
  61185. cy - h / 2,
  61186. w, h);
  61187. }
  61188. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  61189. const int spacer = 16;
  61190. int totalWidth = -spacer;
  61191. for (i = buttons.size(); --i >= 0;)
  61192. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  61193. int x = (w - totalWidth) / 2;
  61194. int y = (int) (getHeight() * 0.95f);
  61195. for (i = 0; i < buttons.size(); ++i)
  61196. {
  61197. TextButton* const c = (TextButton*) buttons[i];
  61198. int ny = proportionOfHeight (0.95f) - c->getHeight();
  61199. c->setTopLeftPosition (x, ny);
  61200. if (ny < y)
  61201. y = ny;
  61202. x += c->getWidth() + spacer;
  61203. c->toFront (false);
  61204. }
  61205. y = textBottom;
  61206. for (i = 0; i < allComps.size(); ++i)
  61207. {
  61208. Component* const c = (Component*) allComps[i];
  61209. int h = 22;
  61210. const int comboIndex = comboBoxes.indexOf (c);
  61211. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61212. y += labelHeight;
  61213. const int tbIndex = textBoxes.indexOf (c);
  61214. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61215. y += labelHeight;
  61216. if (customComps.contains (c))
  61217. {
  61218. if (c->getName().isNotEmpty())
  61219. y += labelHeight;
  61220. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  61221. h = c->getHeight();
  61222. }
  61223. else if (textBlocks.contains (c))
  61224. {
  61225. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61226. h = c->getHeight();
  61227. }
  61228. else
  61229. {
  61230. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61231. }
  61232. y += h + 10;
  61233. }
  61234. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61235. }
  61236. bool AlertWindow::containsAnyExtraComponents() const
  61237. {
  61238. return textBoxes.size()
  61239. + comboBoxes.size()
  61240. + progressBars.size()
  61241. + customComps.size() > 0;
  61242. }
  61243. void AlertWindow::mouseDown (const MouseEvent&)
  61244. {
  61245. dragger.startDraggingComponent (this, &constrainer);
  61246. }
  61247. void AlertWindow::mouseDrag (const MouseEvent& e)
  61248. {
  61249. dragger.dragComponent (this, e);
  61250. }
  61251. bool AlertWindow::keyPressed (const KeyPress& key)
  61252. {
  61253. for (int i = buttons.size(); --i >= 0;)
  61254. {
  61255. TextButton* const b = (TextButton*) buttons[i];
  61256. if (b->isRegisteredForShortcut (key))
  61257. {
  61258. b->triggerClick();
  61259. return true;
  61260. }
  61261. }
  61262. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61263. {
  61264. exitModalState (0);
  61265. return true;
  61266. }
  61267. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61268. {
  61269. ((TextButton*) buttons.getFirst())->triggerClick();
  61270. return true;
  61271. }
  61272. return false;
  61273. }
  61274. void AlertWindow::lookAndFeelChanged()
  61275. {
  61276. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61277. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61278. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61279. }
  61280. int AlertWindow::getDesktopWindowStyleFlags() const
  61281. {
  61282. return getLookAndFeel().getAlertBoxWindowFlags();
  61283. }
  61284. struct AlertWindowInfo
  61285. {
  61286. String title, message, button1, button2, button3;
  61287. AlertWindow::AlertIconType iconType;
  61288. int numButtons;
  61289. Component::SafePointer<Component> associatedComponent;
  61290. int run() const
  61291. {
  61292. return (int) (pointer_sized_int)
  61293. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61294. }
  61295. private:
  61296. int show() const
  61297. {
  61298. LookAndFeel& lf = associatedComponent != 0 ? associatedComponent->getLookAndFeel()
  61299. : LookAndFeel::getDefaultLookAndFeel();
  61300. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61301. iconType, numButtons, associatedComponent));
  61302. jassert (alertBox != 0); // you have to return one of these!
  61303. return alertBox->runModalLoop();
  61304. }
  61305. static void* showCallback (void* userData)
  61306. {
  61307. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61308. }
  61309. };
  61310. void AlertWindow::showMessageBox (AlertIconType iconType,
  61311. const String& title,
  61312. const String& message,
  61313. const String& buttonText,
  61314. Component* associatedComponent)
  61315. {
  61316. AlertWindowInfo info;
  61317. info.title = title;
  61318. info.message = message;
  61319. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61320. info.iconType = iconType;
  61321. info.numButtons = 1;
  61322. info.associatedComponent = associatedComponent;
  61323. info.run();
  61324. }
  61325. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61326. const String& title,
  61327. const String& message,
  61328. const String& button1Text,
  61329. const String& button2Text,
  61330. Component* associatedComponent)
  61331. {
  61332. AlertWindowInfo info;
  61333. info.title = title;
  61334. info.message = message;
  61335. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61336. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61337. info.iconType = iconType;
  61338. info.numButtons = 2;
  61339. info.associatedComponent = associatedComponent;
  61340. return info.run() != 0;
  61341. }
  61342. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61343. const String& title,
  61344. const String& message,
  61345. const String& button1Text,
  61346. const String& button2Text,
  61347. const String& button3Text,
  61348. Component* associatedComponent)
  61349. {
  61350. AlertWindowInfo info;
  61351. info.title = title;
  61352. info.message = message;
  61353. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61354. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61355. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61356. info.iconType = iconType;
  61357. info.numButtons = 3;
  61358. info.associatedComponent = associatedComponent;
  61359. return info.run();
  61360. }
  61361. END_JUCE_NAMESPACE
  61362. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61363. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61364. BEGIN_JUCE_NAMESPACE
  61365. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61366. static VoidArray heavyweightPeers;
  61367. ComponentPeer::ComponentPeer (Component* const component_,
  61368. const int styleFlags_) throw()
  61369. : component (component_),
  61370. styleFlags (styleFlags_),
  61371. lastPaintTime (0),
  61372. constrainer (0),
  61373. lastDragAndDropCompUnderMouse (0),
  61374. fakeMouseMessageSent (false),
  61375. isWindowMinimised (false)
  61376. {
  61377. heavyweightPeers.add (this);
  61378. }
  61379. ComponentPeer::~ComponentPeer()
  61380. {
  61381. heavyweightPeers.removeValue (this);
  61382. Desktop::getInstance().triggerFocusCallback();
  61383. }
  61384. int ComponentPeer::getNumPeers() throw()
  61385. {
  61386. return heavyweightPeers.size();
  61387. }
  61388. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61389. {
  61390. return (ComponentPeer*) heavyweightPeers [index];
  61391. }
  61392. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61393. {
  61394. for (int i = heavyweightPeers.size(); --i >= 0;)
  61395. {
  61396. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61397. if (peer->getComponent() == component)
  61398. return peer;
  61399. }
  61400. return 0;
  61401. }
  61402. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61403. {
  61404. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61405. }
  61406. void ComponentPeer::updateCurrentModifiers() throw()
  61407. {
  61408. ModifierKeys::updateCurrentModifiers();
  61409. }
  61410. void ComponentPeer::handleMouseEvent (const int touchIndex, const Point<int>& positionWithinPeer, const ModifierKeys& newMods, const int64 time)
  61411. {
  61412. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61413. jassert (mouse != 0); // not enough sources!
  61414. mouse->handleEvent (this, positionWithinPeer, time, newMods);
  61415. }
  61416. void ComponentPeer::handleMouseWheel (const int touchIndex, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  61417. {
  61418. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61419. jassert (mouse != 0); // not enough sources!
  61420. mouse->handleWheel (this, positionWithinPeer, time, x, y);
  61421. }
  61422. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61423. {
  61424. Graphics g (&contextToPaintTo);
  61425. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61426. g.saveState();
  61427. #endif
  61428. JUCE_TRY
  61429. {
  61430. component->paintEntireComponent (g);
  61431. }
  61432. JUCE_CATCH_EXCEPTION
  61433. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61434. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61435. // clearly when things are being repainted.
  61436. {
  61437. g.restoreState();
  61438. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61439. (uint8) Random::getSystemRandom().nextInt (255),
  61440. (uint8) Random::getSystemRandom().nextInt (255),
  61441. (uint8) 0x50));
  61442. }
  61443. #endif
  61444. }
  61445. bool ComponentPeer::handleKeyPress (const int keyCode,
  61446. const juce_wchar textCharacter)
  61447. {
  61448. updateCurrentModifiers();
  61449. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61450. ? Component::getCurrentlyFocusedComponent()
  61451. : component;
  61452. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61453. {
  61454. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61455. if (currentModalComp != 0)
  61456. target = currentModalComp;
  61457. }
  61458. const KeyPress keyInfo (keyCode,
  61459. ModifierKeys::getCurrentModifiers().getRawFlags()
  61460. & ModifierKeys::allKeyboardModifiers,
  61461. textCharacter);
  61462. bool keyWasUsed = false;
  61463. while (target != 0)
  61464. {
  61465. const Component::SafePointer<Component> deletionChecker (target);
  61466. if (target->keyListeners_ != 0)
  61467. {
  61468. for (int i = target->keyListeners_->size(); --i >= 0;)
  61469. {
  61470. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61471. if (keyWasUsed || deletionChecker == 0)
  61472. return keyWasUsed;
  61473. i = jmin (i, target->keyListeners_->size());
  61474. }
  61475. }
  61476. keyWasUsed = target->keyPressed (keyInfo);
  61477. if (keyWasUsed || deletionChecker == 0)
  61478. break;
  61479. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61480. {
  61481. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61482. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61483. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61484. break;
  61485. }
  61486. target = target->parentComponent_;
  61487. }
  61488. return keyWasUsed;
  61489. }
  61490. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61491. {
  61492. updateCurrentModifiers();
  61493. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61494. ? Component::getCurrentlyFocusedComponent()
  61495. : component;
  61496. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61497. {
  61498. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61499. if (currentModalComp != 0)
  61500. target = currentModalComp;
  61501. }
  61502. bool keyWasUsed = false;
  61503. while (target != 0)
  61504. {
  61505. const Component::SafePointer<Component> deletionChecker (target);
  61506. keyWasUsed = target->keyStateChanged (isKeyDown);
  61507. if (keyWasUsed || deletionChecker == 0)
  61508. break;
  61509. if (target->keyListeners_ != 0)
  61510. {
  61511. for (int i = target->keyListeners_->size(); --i >= 0;)
  61512. {
  61513. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61514. if (keyWasUsed || deletionChecker == 0)
  61515. return keyWasUsed;
  61516. i = jmin (i, target->keyListeners_->size());
  61517. }
  61518. }
  61519. target = target->parentComponent_;
  61520. }
  61521. return keyWasUsed;
  61522. }
  61523. void ComponentPeer::handleModifierKeysChange()
  61524. {
  61525. updateCurrentModifiers();
  61526. Component* target = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  61527. if (target == 0)
  61528. target = Component::getCurrentlyFocusedComponent();
  61529. if (target == 0)
  61530. target = component;
  61531. if (target != 0)
  61532. target->internalModifierKeysChanged();
  61533. }
  61534. TextInputTarget* ComponentPeer::findCurrentTextInputTarget()
  61535. {
  61536. Component* const c = Component::getCurrentlyFocusedComponent();
  61537. if (component->isParentOf (c))
  61538. return dynamic_cast <TextInputTarget*> (c);
  61539. return 0;
  61540. }
  61541. void ComponentPeer::handleBroughtToFront()
  61542. {
  61543. updateCurrentModifiers();
  61544. if (component != 0)
  61545. component->internalBroughtToFront();
  61546. }
  61547. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61548. {
  61549. constrainer = newConstrainer;
  61550. }
  61551. void ComponentPeer::handleMovedOrResized()
  61552. {
  61553. jassert (component->isValidComponent());
  61554. updateCurrentModifiers();
  61555. const bool nowMinimised = isMinimised();
  61556. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61557. {
  61558. const Component::SafePointer<Component> deletionChecker (component);
  61559. const Rectangle<int> newBounds (getBounds());
  61560. const bool wasMoved = (component->getPosition() != newBounds.getPosition());
  61561. const bool wasResized = (component->getWidth() != newBounds.getWidth() || component->getHeight() != newBounds.getHeight());
  61562. if (wasMoved || wasResized)
  61563. {
  61564. component->bounds_ = newBounds;
  61565. if (wasResized)
  61566. component->repaint();
  61567. component->sendMovedResizedMessages (wasMoved, wasResized);
  61568. if (deletionChecker == 0)
  61569. return;
  61570. }
  61571. }
  61572. if (isWindowMinimised != nowMinimised)
  61573. {
  61574. isWindowMinimised = nowMinimised;
  61575. component->minimisationStateChanged (nowMinimised);
  61576. component->sendVisibilityChangeMessage();
  61577. }
  61578. if (! isFullScreen())
  61579. lastNonFullscreenBounds = component->getBounds();
  61580. }
  61581. void ComponentPeer::handleFocusGain()
  61582. {
  61583. updateCurrentModifiers();
  61584. if (component->isParentOf (lastFocusedComponent))
  61585. {
  61586. Component::currentlyFocusedComponent = lastFocusedComponent;
  61587. Desktop::getInstance().triggerFocusCallback();
  61588. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61589. }
  61590. else
  61591. {
  61592. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61593. component->grabKeyboardFocus();
  61594. else
  61595. Component::bringModalComponentToFront();
  61596. }
  61597. }
  61598. void ComponentPeer::handleFocusLoss()
  61599. {
  61600. updateCurrentModifiers();
  61601. if (component->hasKeyboardFocus (true))
  61602. {
  61603. lastFocusedComponent = Component::currentlyFocusedComponent;
  61604. if (lastFocusedComponent != 0)
  61605. {
  61606. Component::currentlyFocusedComponent = 0;
  61607. Desktop::getInstance().triggerFocusCallback();
  61608. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61609. }
  61610. }
  61611. }
  61612. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61613. {
  61614. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61615. ? static_cast <Component*> (lastFocusedComponent)
  61616. : component;
  61617. }
  61618. void ComponentPeer::handleScreenSizeChange()
  61619. {
  61620. updateCurrentModifiers();
  61621. component->parentSizeChanged();
  61622. handleMovedOrResized();
  61623. }
  61624. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61625. {
  61626. lastNonFullscreenBounds = newBounds;
  61627. }
  61628. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61629. {
  61630. return lastNonFullscreenBounds;
  61631. }
  61632. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61633. const StringArray& files,
  61634. FileDragAndDropTarget* const lastOne)
  61635. {
  61636. while (c != 0)
  61637. {
  61638. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61639. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61640. return t;
  61641. c = c->getParentComponent();
  61642. }
  61643. return 0;
  61644. }
  61645. void ComponentPeer::handleFileDragMove (const StringArray& files, const Point<int>& position)
  61646. {
  61647. updateCurrentModifiers();
  61648. FileDragAndDropTarget* lastTarget
  61649. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61650. FileDragAndDropTarget* newTarget = 0;
  61651. Component* const compUnderMouse = component->getComponentAt (position);
  61652. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61653. {
  61654. lastDragAndDropCompUnderMouse = compUnderMouse;
  61655. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61656. if (newTarget != lastTarget)
  61657. {
  61658. if (lastTarget != 0)
  61659. lastTarget->fileDragExit (files);
  61660. dragAndDropTargetComponent = 0;
  61661. if (newTarget != 0)
  61662. {
  61663. dragAndDropTargetComponent = dynamic_cast <Component*> (newTarget);
  61664. const Point<int> pos (component->relativePositionToOtherComponent (dragAndDropTargetComponent, position));
  61665. newTarget->fileDragEnter (files, pos.getX(), pos.getY());
  61666. }
  61667. }
  61668. }
  61669. else
  61670. {
  61671. newTarget = lastTarget;
  61672. }
  61673. if (newTarget != 0)
  61674. {
  61675. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61676. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61677. newTarget->fileDragMove (files, pos.getX(), pos.getY());
  61678. }
  61679. }
  61680. void ComponentPeer::handleFileDragExit (const StringArray& files)
  61681. {
  61682. handleFileDragMove (files, Point<int> (-1, -1));
  61683. jassert (dragAndDropTargetComponent == 0);
  61684. lastDragAndDropCompUnderMouse = 0;
  61685. }
  61686. void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<int>& position)
  61687. {
  61688. handleFileDragMove (files, position);
  61689. if (dragAndDropTargetComponent != 0)
  61690. {
  61691. FileDragAndDropTarget* const target
  61692. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61693. dragAndDropTargetComponent = 0;
  61694. lastDragAndDropCompUnderMouse = 0;
  61695. if (target != 0)
  61696. {
  61697. Component* const targetComp = dynamic_cast <Component*> (target);
  61698. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61699. {
  61700. targetComp->internalModalInputAttempt();
  61701. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61702. return;
  61703. }
  61704. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61705. target->filesDropped (files, pos.getX(), pos.getY());
  61706. }
  61707. }
  61708. }
  61709. void ComponentPeer::handleUserClosingWindow()
  61710. {
  61711. updateCurrentModifiers();
  61712. component->userTriedToCloseWindow();
  61713. }
  61714. void ComponentPeer::bringModalComponentToFront()
  61715. {
  61716. Component::bringModalComponentToFront();
  61717. }
  61718. void ComponentPeer::clearMaskedRegion() throw()
  61719. {
  61720. maskedRegion.clear();
  61721. }
  61722. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  61723. {
  61724. maskedRegion.add (x, y, w, h);
  61725. }
  61726. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  61727. {
  61728. StringArray s;
  61729. s.add ("Software Renderer");
  61730. return s;
  61731. }
  61732. int ComponentPeer::getCurrentRenderingEngine() throw()
  61733. {
  61734. return 0;
  61735. }
  61736. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  61737. {
  61738. }
  61739. END_JUCE_NAMESPACE
  61740. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  61741. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  61742. BEGIN_JUCE_NAMESPACE
  61743. DialogWindow::DialogWindow (const String& name,
  61744. const Colour& backgroundColour_,
  61745. const bool escapeKeyTriggersCloseButton_,
  61746. const bool addToDesktop_)
  61747. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  61748. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  61749. {
  61750. }
  61751. DialogWindow::~DialogWindow()
  61752. {
  61753. }
  61754. void DialogWindow::resized()
  61755. {
  61756. DocumentWindow::resized();
  61757. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  61758. if (escapeKeyTriggersCloseButton
  61759. && getCloseButton() != 0
  61760. && ! getCloseButton()->isRegisteredForShortcut (esc))
  61761. {
  61762. getCloseButton()->addShortcut (esc);
  61763. }
  61764. }
  61765. class TempDialogWindow : public DialogWindow
  61766. {
  61767. public:
  61768. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  61769. : DialogWindow (title, colour, escapeCloses, true)
  61770. {
  61771. }
  61772. ~TempDialogWindow()
  61773. {
  61774. }
  61775. void closeButtonPressed()
  61776. {
  61777. setVisible (false);
  61778. }
  61779. private:
  61780. TempDialogWindow (const TempDialogWindow&);
  61781. TempDialogWindow& operator= (const TempDialogWindow&);
  61782. };
  61783. int DialogWindow::showModalDialog (const String& dialogTitle,
  61784. Component* contentComponent,
  61785. Component* componentToCentreAround,
  61786. const Colour& colour,
  61787. const bool escapeKeyTriggersCloseButton,
  61788. const bool shouldBeResizable,
  61789. const bool useBottomRightCornerResizer)
  61790. {
  61791. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  61792. dw.setContentComponent (contentComponent, true, true);
  61793. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  61794. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  61795. const int result = dw.runModalLoop();
  61796. dw.setContentComponent (0, false);
  61797. return result;
  61798. }
  61799. END_JUCE_NAMESPACE
  61800. /*** End of inlined file: juce_DialogWindow.cpp ***/
  61801. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  61802. BEGIN_JUCE_NAMESPACE
  61803. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  61804. {
  61805. public:
  61806. ButtonListenerProxy (DocumentWindow& owner_)
  61807. : owner (owner_)
  61808. {
  61809. }
  61810. void buttonClicked (Button* button)
  61811. {
  61812. if (button == owner.getMinimiseButton())
  61813. owner.minimiseButtonPressed();
  61814. else if (button == owner.getMaximiseButton())
  61815. owner.maximiseButtonPressed();
  61816. else if (button == owner.getCloseButton())
  61817. owner.closeButtonPressed();
  61818. }
  61819. juce_UseDebuggingNewOperator
  61820. private:
  61821. DocumentWindow& owner;
  61822. ButtonListenerProxy (const ButtonListenerProxy&);
  61823. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  61824. };
  61825. DocumentWindow::DocumentWindow (const String& title,
  61826. const Colour& backgroundColour,
  61827. const int requiredButtons_,
  61828. const bool addToDesktop_)
  61829. : ResizableWindow (title, backgroundColour, addToDesktop_),
  61830. titleBarHeight (26),
  61831. menuBarHeight (24),
  61832. requiredButtons (requiredButtons_),
  61833. #if JUCE_MAC
  61834. positionTitleBarButtonsOnLeft (true),
  61835. #else
  61836. positionTitleBarButtonsOnLeft (false),
  61837. #endif
  61838. drawTitleTextCentred (true),
  61839. menuBarModel (0)
  61840. {
  61841. setResizeLimits (128, 128, 32768, 32768);
  61842. lookAndFeelChanged();
  61843. }
  61844. DocumentWindow::~DocumentWindow()
  61845. {
  61846. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61847. titleBarButtons[i] = 0;
  61848. menuBar = 0;
  61849. }
  61850. void DocumentWindow::repaintTitleBar()
  61851. {
  61852. const Rectangle<int> titleBarArea (getTitleBarArea());
  61853. repaint (titleBarArea.getX(), titleBarArea.getY(),
  61854. titleBarArea.getWidth(), titleBarArea.getHeight());
  61855. }
  61856. void DocumentWindow::setName (const String& newName)
  61857. {
  61858. if (newName != getName())
  61859. {
  61860. Component::setName (newName);
  61861. repaintTitleBar();
  61862. }
  61863. }
  61864. void DocumentWindow::setIcon (const Image* imageToUse)
  61865. {
  61866. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  61867. repaintTitleBar();
  61868. }
  61869. void DocumentWindow::setTitleBarHeight (const int newHeight)
  61870. {
  61871. titleBarHeight = newHeight;
  61872. resized();
  61873. repaintTitleBar();
  61874. }
  61875. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  61876. const bool positionTitleBarButtonsOnLeft_)
  61877. {
  61878. requiredButtons = requiredButtons_;
  61879. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  61880. lookAndFeelChanged();
  61881. }
  61882. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  61883. {
  61884. drawTitleTextCentred = textShouldBeCentred;
  61885. repaintTitleBar();
  61886. }
  61887. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  61888. const int menuBarHeight_)
  61889. {
  61890. if (menuBarModel != menuBarModel_)
  61891. {
  61892. menuBar = 0;
  61893. menuBarModel = menuBarModel_;
  61894. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  61895. : getLookAndFeel().getDefaultMenuBarHeight();
  61896. if (menuBarModel != 0)
  61897. {
  61898. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61899. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  61900. menuBar->setEnabled (isActiveWindow());
  61901. }
  61902. resized();
  61903. }
  61904. }
  61905. void DocumentWindow::closeButtonPressed()
  61906. {
  61907. /* If you've got a close button, you have to override this method to get
  61908. rid of your window!
  61909. If the window is just a pop-up, you should override this method and make
  61910. it delete the window in whatever way is appropriate for your app. E.g. you
  61911. might just want to call "delete this".
  61912. If your app is centred around this window such that the whole app should quit when
  61913. the window is closed, then you will probably want to use this method as an opportunity
  61914. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  61915. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  61916. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  61917. or closing it via the taskbar icon on Windows).
  61918. */
  61919. jassertfalse
  61920. }
  61921. void DocumentWindow::minimiseButtonPressed()
  61922. {
  61923. setMinimised (true);
  61924. }
  61925. void DocumentWindow::maximiseButtonPressed()
  61926. {
  61927. setFullScreen (! isFullScreen());
  61928. }
  61929. void DocumentWindow::paint (Graphics& g)
  61930. {
  61931. ResizableWindow::paint (g);
  61932. if (resizableBorder == 0)
  61933. {
  61934. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  61935. const BorderSize border (getBorderThickness());
  61936. g.fillRect (0, 0, getWidth(), border.getTop());
  61937. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  61938. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  61939. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  61940. }
  61941. const Rectangle<int> titleBarArea (getTitleBarArea());
  61942. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  61943. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  61944. int titleSpaceX1 = 6;
  61945. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  61946. for (int i = 0; i < 3; ++i)
  61947. {
  61948. if (titleBarButtons[i] != 0)
  61949. {
  61950. if (positionTitleBarButtonsOnLeft)
  61951. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  61952. else
  61953. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  61954. }
  61955. }
  61956. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  61957. titleBarArea.getWidth(),
  61958. titleBarArea.getHeight(),
  61959. titleSpaceX1,
  61960. jmax (1, titleSpaceX2 - titleSpaceX1),
  61961. titleBarIcon,
  61962. ! drawTitleTextCentred);
  61963. }
  61964. void DocumentWindow::resized()
  61965. {
  61966. ResizableWindow::resized();
  61967. if (titleBarButtons[1] != 0)
  61968. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  61969. const Rectangle<int> titleBarArea (getTitleBarArea());
  61970. getLookAndFeel()
  61971. .positionDocumentWindowButtons (*this,
  61972. titleBarArea.getX(), titleBarArea.getY(),
  61973. titleBarArea.getWidth(), titleBarArea.getHeight(),
  61974. titleBarButtons[0],
  61975. titleBarButtons[1],
  61976. titleBarButtons[2],
  61977. positionTitleBarButtonsOnLeft);
  61978. if (menuBar != 0)
  61979. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  61980. titleBarArea.getWidth(), menuBarHeight);
  61981. }
  61982. const BorderSize DocumentWindow::getBorderThickness()
  61983. {
  61984. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  61985. ? 0 : (resizableBorder != 0 ? 4 : 1));
  61986. }
  61987. const BorderSize DocumentWindow::getContentComponentBorder()
  61988. {
  61989. BorderSize border (getBorderThickness());
  61990. border.setTop (border.getTop()
  61991. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  61992. + (menuBar != 0 ? menuBarHeight : 0));
  61993. return border;
  61994. }
  61995. int DocumentWindow::getTitleBarHeight() const
  61996. {
  61997. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  61998. }
  61999. const Rectangle<int> DocumentWindow::getTitleBarArea()
  62000. {
  62001. const BorderSize border (getBorderThickness());
  62002. return Rectangle<int> (border.getLeft(), border.getTop(),
  62003. getWidth() - border.getLeftAndRight(),
  62004. getTitleBarHeight());
  62005. }
  62006. Button* DocumentWindow::getCloseButton() const throw()
  62007. {
  62008. return titleBarButtons[2];
  62009. }
  62010. Button* DocumentWindow::getMinimiseButton() const throw()
  62011. {
  62012. return titleBarButtons[0];
  62013. }
  62014. Button* DocumentWindow::getMaximiseButton() const throw()
  62015. {
  62016. return titleBarButtons[1];
  62017. }
  62018. int DocumentWindow::getDesktopWindowStyleFlags() const
  62019. {
  62020. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  62021. if ((requiredButtons & minimiseButton) != 0)
  62022. flags |= ComponentPeer::windowHasMinimiseButton;
  62023. if ((requiredButtons & maximiseButton) != 0)
  62024. flags |= ComponentPeer::windowHasMaximiseButton;
  62025. if ((requiredButtons & closeButton) != 0)
  62026. flags |= ComponentPeer::windowHasCloseButton;
  62027. return flags;
  62028. }
  62029. void DocumentWindow::lookAndFeelChanged()
  62030. {
  62031. int i;
  62032. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  62033. titleBarButtons[i] = 0;
  62034. if (! isUsingNativeTitleBar())
  62035. {
  62036. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  62037. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  62038. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  62039. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  62040. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  62041. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  62042. for (i = 0; i < 3; ++i)
  62043. {
  62044. if (titleBarButtons[i] != 0)
  62045. {
  62046. if (buttonListener == 0)
  62047. buttonListener = new ButtonListenerProxy (*this);
  62048. titleBarButtons[i]->addButtonListener (buttonListener);
  62049. titleBarButtons[i]->setWantsKeyboardFocus (false);
  62050. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62051. Component::addAndMakeVisible (titleBarButtons[i]);
  62052. }
  62053. }
  62054. if (getCloseButton() != 0)
  62055. {
  62056. #if JUCE_MAC
  62057. getCloseButton()->addShortcut (KeyPress (T('w'), ModifierKeys::commandModifier, 0));
  62058. #else
  62059. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  62060. #endif
  62061. }
  62062. }
  62063. activeWindowStatusChanged();
  62064. ResizableWindow::lookAndFeelChanged();
  62065. }
  62066. void DocumentWindow::parentHierarchyChanged()
  62067. {
  62068. lookAndFeelChanged();
  62069. }
  62070. void DocumentWindow::activeWindowStatusChanged()
  62071. {
  62072. ResizableWindow::activeWindowStatusChanged();
  62073. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62074. if (titleBarButtons[i] != 0)
  62075. titleBarButtons[i]->setEnabled (isActiveWindow());
  62076. if (menuBar != 0)
  62077. menuBar->setEnabled (isActiveWindow());
  62078. }
  62079. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  62080. {
  62081. if (getTitleBarArea().contains (e.x, e.y)
  62082. && getMaximiseButton() != 0)
  62083. {
  62084. getMaximiseButton()->triggerClick();
  62085. }
  62086. }
  62087. void DocumentWindow::userTriedToCloseWindow()
  62088. {
  62089. closeButtonPressed();
  62090. }
  62091. END_JUCE_NAMESPACE
  62092. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  62093. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  62094. BEGIN_JUCE_NAMESPACE
  62095. ResizableWindow::ResizableWindow (const String& name,
  62096. const bool addToDesktop_)
  62097. : TopLevelWindow (name, addToDesktop_),
  62098. resizeToFitContent (false),
  62099. fullscreen (false),
  62100. lastNonFullScreenPos (50, 50, 256, 256),
  62101. constrainer (0)
  62102. #ifdef JUCE_DEBUG
  62103. , hasBeenResized (false)
  62104. #endif
  62105. {
  62106. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62107. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  62108. if (addToDesktop_)
  62109. Component::addToDesktop (getDesktopWindowStyleFlags());
  62110. }
  62111. ResizableWindow::ResizableWindow (const String& name,
  62112. const Colour& backgroundColour_,
  62113. const bool addToDesktop_)
  62114. : TopLevelWindow (name, addToDesktop_),
  62115. resizeToFitContent (false),
  62116. fullscreen (false),
  62117. lastNonFullScreenPos (50, 50, 256, 256),
  62118. constrainer (0)
  62119. #ifdef JUCE_DEBUG
  62120. , hasBeenResized (false)
  62121. #endif
  62122. {
  62123. setBackgroundColour (backgroundColour_);
  62124. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62125. if (addToDesktop_)
  62126. Component::addToDesktop (getDesktopWindowStyleFlags());
  62127. }
  62128. ResizableWindow::~ResizableWindow()
  62129. {
  62130. resizableCorner = 0;
  62131. resizableBorder = 0;
  62132. contentComponent = 0;
  62133. // have you been adding your own components directly to this window..? tut tut tut.
  62134. // Read the instructions for using a ResizableWindow!
  62135. jassert (getNumChildComponents() == 0);
  62136. }
  62137. int ResizableWindow::getDesktopWindowStyleFlags() const
  62138. {
  62139. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  62140. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  62141. flags |= ComponentPeer::windowIsResizable;
  62142. return flags;
  62143. }
  62144. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  62145. const bool deleteOldOne,
  62146. const bool resizeToFit)
  62147. {
  62148. resizeToFitContent = resizeToFit;
  62149. if (newContentComponent != (Component*) contentComponent)
  62150. {
  62151. if (! deleteOldOne)
  62152. removeChildComponent (contentComponent.release());
  62153. contentComponent = newContentComponent;
  62154. Component::addAndMakeVisible (contentComponent);
  62155. }
  62156. if (resizeToFit)
  62157. childBoundsChanged (contentComponent);
  62158. resized(); // must always be called to position the new content comp
  62159. }
  62160. void ResizableWindow::setContentComponentSize (int width, int height)
  62161. {
  62162. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  62163. const BorderSize border (getContentComponentBorder());
  62164. setSize (width + border.getLeftAndRight(),
  62165. height + border.getTopAndBottom());
  62166. }
  62167. const BorderSize ResizableWindow::getBorderThickness()
  62168. {
  62169. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  62170. }
  62171. const BorderSize ResizableWindow::getContentComponentBorder()
  62172. {
  62173. return getBorderThickness();
  62174. }
  62175. void ResizableWindow::moved()
  62176. {
  62177. updateLastPos();
  62178. }
  62179. void ResizableWindow::visibilityChanged()
  62180. {
  62181. TopLevelWindow::visibilityChanged();
  62182. updateLastPos();
  62183. }
  62184. void ResizableWindow::resized()
  62185. {
  62186. if (resizableBorder != 0)
  62187. {
  62188. resizableBorder->setVisible (! isFullScreen());
  62189. resizableBorder->setBorderThickness (getBorderThickness());
  62190. resizableBorder->setSize (getWidth(), getHeight());
  62191. resizableBorder->toBack();
  62192. }
  62193. if (resizableCorner != 0)
  62194. {
  62195. resizableCorner->setVisible (! isFullScreen());
  62196. const int resizerSize = 18;
  62197. resizableCorner->setBounds (getWidth() - resizerSize,
  62198. getHeight() - resizerSize,
  62199. resizerSize, resizerSize);
  62200. }
  62201. if (contentComponent != 0)
  62202. contentComponent->setBoundsInset (getContentComponentBorder());
  62203. updateLastPos();
  62204. #ifdef JUCE_DEBUG
  62205. hasBeenResized = true;
  62206. #endif
  62207. }
  62208. void ResizableWindow::childBoundsChanged (Component* child)
  62209. {
  62210. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62211. {
  62212. // not going to look very good if this component has a zero size..
  62213. jassert (child->getWidth() > 0);
  62214. jassert (child->getHeight() > 0);
  62215. const BorderSize borders (getContentComponentBorder());
  62216. setSize (child->getWidth() + borders.getLeftAndRight(),
  62217. child->getHeight() + borders.getTopAndBottom());
  62218. }
  62219. }
  62220. void ResizableWindow::activeWindowStatusChanged()
  62221. {
  62222. const BorderSize borders (getContentComponentBorder());
  62223. repaint (0, 0, getWidth(), borders.getTop());
  62224. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62225. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62226. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62227. }
  62228. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62229. const bool useBottomRightCornerResizer)
  62230. {
  62231. if (shouldBeResizable)
  62232. {
  62233. if (useBottomRightCornerResizer)
  62234. {
  62235. resizableBorder = 0;
  62236. if (resizableCorner == 0)
  62237. {
  62238. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62239. resizableCorner->setAlwaysOnTop (true);
  62240. }
  62241. }
  62242. else
  62243. {
  62244. resizableCorner = 0;
  62245. if (resizableBorder == 0)
  62246. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62247. }
  62248. }
  62249. else
  62250. {
  62251. resizableCorner = 0;
  62252. resizableBorder = 0;
  62253. }
  62254. if (isUsingNativeTitleBar())
  62255. recreateDesktopWindow();
  62256. childBoundsChanged (contentComponent);
  62257. resized();
  62258. }
  62259. bool ResizableWindow::isResizable() const throw()
  62260. {
  62261. return resizableCorner != 0
  62262. || resizableBorder != 0;
  62263. }
  62264. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62265. const int newMinimumHeight,
  62266. const int newMaximumWidth,
  62267. const int newMaximumHeight) throw()
  62268. {
  62269. // if you've set up a custom constrainer then these settings won't have any effect..
  62270. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62271. if (constrainer == 0)
  62272. setConstrainer (&defaultConstrainer);
  62273. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62274. newMaximumWidth, newMaximumHeight);
  62275. setBoundsConstrained (getBounds());
  62276. }
  62277. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62278. {
  62279. if (constrainer != newConstrainer)
  62280. {
  62281. constrainer = newConstrainer;
  62282. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62283. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62284. resizableCorner = 0;
  62285. resizableBorder = 0;
  62286. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62287. ComponentPeer* const peer = getPeer();
  62288. if (peer != 0)
  62289. peer->setConstrainer (newConstrainer);
  62290. }
  62291. }
  62292. void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds)
  62293. {
  62294. if (constrainer != 0)
  62295. constrainer->setBoundsForComponent (this, bounds, false, false, false, false);
  62296. else
  62297. setBounds (bounds);
  62298. }
  62299. void ResizableWindow::paint (Graphics& g)
  62300. {
  62301. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62302. getBorderThickness(), *this);
  62303. if (! isFullScreen())
  62304. {
  62305. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62306. getBorderThickness(), *this);
  62307. }
  62308. #ifdef JUCE_DEBUG
  62309. /* If this fails, then you've probably written a subclass with a resized()
  62310. callback but forgotten to make it call its parent class's resized() method.
  62311. It's important when you override methods like resized(), moved(),
  62312. etc., that you make sure the base class methods also get called.
  62313. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62314. because your content should all be inside the content component - and it's the
  62315. content component's resized() method that you should be using to do your
  62316. layout.
  62317. */
  62318. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62319. #endif
  62320. }
  62321. void ResizableWindow::lookAndFeelChanged()
  62322. {
  62323. resized();
  62324. if (isOnDesktop())
  62325. {
  62326. Component::addToDesktop (getDesktopWindowStyleFlags());
  62327. ComponentPeer* const peer = getPeer();
  62328. if (peer != 0)
  62329. peer->setConstrainer (constrainer);
  62330. }
  62331. }
  62332. const Colour ResizableWindow::getBackgroundColour() const throw()
  62333. {
  62334. return findColour (backgroundColourId, false);
  62335. }
  62336. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62337. {
  62338. Colour backgroundColour (newColour);
  62339. if (! Desktop::canUseSemiTransparentWindows())
  62340. backgroundColour = newColour.withAlpha (1.0f);
  62341. setColour (backgroundColourId, backgroundColour);
  62342. setOpaque (backgroundColour.isOpaque());
  62343. repaint();
  62344. }
  62345. bool ResizableWindow::isFullScreen() const
  62346. {
  62347. if (isOnDesktop())
  62348. {
  62349. ComponentPeer* const peer = getPeer();
  62350. return peer != 0 && peer->isFullScreen();
  62351. }
  62352. return fullscreen;
  62353. }
  62354. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62355. {
  62356. if (shouldBeFullScreen != isFullScreen())
  62357. {
  62358. updateLastPos();
  62359. fullscreen = shouldBeFullScreen;
  62360. if (isOnDesktop())
  62361. {
  62362. ComponentPeer* const peer = getPeer();
  62363. if (peer != 0)
  62364. {
  62365. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62366. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62367. peer->setFullScreen (shouldBeFullScreen);
  62368. if (! shouldBeFullScreen)
  62369. setBounds (lastPos);
  62370. }
  62371. else
  62372. {
  62373. jassertfalse
  62374. }
  62375. }
  62376. else
  62377. {
  62378. if (shouldBeFullScreen)
  62379. setBounds (0, 0, getParentWidth(), getParentHeight());
  62380. else
  62381. setBounds (lastNonFullScreenPos);
  62382. }
  62383. resized();
  62384. }
  62385. }
  62386. bool ResizableWindow::isMinimised() const
  62387. {
  62388. ComponentPeer* const peer = getPeer();
  62389. return (peer != 0) && peer->isMinimised();
  62390. }
  62391. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62392. {
  62393. if (shouldMinimise != isMinimised())
  62394. {
  62395. ComponentPeer* const peer = getPeer();
  62396. if (peer != 0)
  62397. {
  62398. updateLastPos();
  62399. peer->setMinimised (shouldMinimise);
  62400. }
  62401. else
  62402. {
  62403. jassertfalse
  62404. }
  62405. }
  62406. }
  62407. void ResizableWindow::updateLastPos()
  62408. {
  62409. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62410. {
  62411. lastNonFullScreenPos = getBounds();
  62412. }
  62413. }
  62414. void ResizableWindow::parentSizeChanged()
  62415. {
  62416. if (isFullScreen() && getParentComponent() != 0)
  62417. {
  62418. setBounds (0, 0, getParentWidth(), getParentHeight());
  62419. }
  62420. }
  62421. const String ResizableWindow::getWindowStateAsString()
  62422. {
  62423. updateLastPos();
  62424. return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString();
  62425. }
  62426. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62427. {
  62428. StringArray tokens;
  62429. tokens.addTokens (s, false);
  62430. tokens.removeEmptyStrings();
  62431. tokens.trim();
  62432. const bool fs = tokens[0].startsWithIgnoreCase (T("fs"));
  62433. const int firstCoord = fs ? 1 : 0;
  62434. if (tokens.size() != firstCoord + 4)
  62435. return false;
  62436. Rectangle<int> newPos (tokens[firstCoord].getIntValue(),
  62437. tokens[firstCoord + 1].getIntValue(),
  62438. tokens[firstCoord + 2].getIntValue(),
  62439. tokens[firstCoord + 3].getIntValue());
  62440. if (newPos.isEmpty())
  62441. return false;
  62442. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentre()));
  62443. ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0;
  62444. if (peer != 0)
  62445. peer->getFrameSize().addTo (newPos);
  62446. if (! screen.contains (newPos))
  62447. {
  62448. newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
  62449. jmin (newPos.getHeight(), screen.getHeight()));
  62450. newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()),
  62451. jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY()));
  62452. }
  62453. if (peer != 0)
  62454. {
  62455. peer->getFrameSize().subtractFrom (newPos);
  62456. peer->setNonFullScreenBounds (newPos);
  62457. }
  62458. lastNonFullScreenPos = newPos;
  62459. setFullScreen (fs);
  62460. if (! fs)
  62461. setBoundsConstrained (newPos);
  62462. return true;
  62463. }
  62464. void ResizableWindow::mouseDown (const MouseEvent&)
  62465. {
  62466. if (! isFullScreen())
  62467. dragger.startDraggingComponent (this, constrainer);
  62468. }
  62469. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62470. {
  62471. if (! isFullScreen())
  62472. dragger.dragComponent (this, e);
  62473. }
  62474. #ifdef JUCE_DEBUG
  62475. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62476. {
  62477. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62478. manages its child components automatically, and if you add your own it'll cause
  62479. trouble. Instead, use setContentComponent() to give it a component which
  62480. will be automatically resized and kept in the right place - then you can add
  62481. subcomponents to the content comp. See the notes for the ResizableWindow class
  62482. for more info.
  62483. If you really know what you're doing and want to avoid this assertion, just call
  62484. Component::addChildComponent directly.
  62485. */
  62486. jassertfalse
  62487. Component::addChildComponent (child, zOrder);
  62488. }
  62489. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62490. {
  62491. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62492. manages its child components automatically, and if you add your own it'll cause
  62493. trouble. Instead, use setContentComponent() to give it a component which
  62494. will be automatically resized and kept in the right place - then you can add
  62495. subcomponents to the content comp. See the notes for the ResizableWindow class
  62496. for more info.
  62497. If you really know what you're doing and want to avoid this assertion, just call
  62498. Component::addAndMakeVisible directly.
  62499. */
  62500. jassertfalse
  62501. Component::addAndMakeVisible (child, zOrder);
  62502. }
  62503. #endif
  62504. END_JUCE_NAMESPACE
  62505. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62506. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62507. BEGIN_JUCE_NAMESPACE
  62508. SplashScreen::SplashScreen()
  62509. : backgroundImage (0)
  62510. {
  62511. setOpaque (true);
  62512. }
  62513. SplashScreen::~SplashScreen()
  62514. {
  62515. ImageCache::releaseOrDelete (backgroundImage);
  62516. }
  62517. void SplashScreen::show (const String& title,
  62518. Image* const backgroundImage_,
  62519. const int minimumTimeToDisplayFor,
  62520. const bool useDropShadow,
  62521. const bool removeOnMouseClick)
  62522. {
  62523. backgroundImage = backgroundImage_;
  62524. jassert (backgroundImage_ != 0);
  62525. if (backgroundImage_ != 0)
  62526. {
  62527. setOpaque (! backgroundImage_->hasAlphaChannel());
  62528. show (title,
  62529. backgroundImage_->getWidth(),
  62530. backgroundImage_->getHeight(),
  62531. minimumTimeToDisplayFor,
  62532. useDropShadow,
  62533. removeOnMouseClick);
  62534. }
  62535. }
  62536. void SplashScreen::show (const String& title,
  62537. const int width,
  62538. const int height,
  62539. const int minimumTimeToDisplayFor,
  62540. const bool useDropShadow,
  62541. const bool removeOnMouseClick)
  62542. {
  62543. setName (title);
  62544. setAlwaysOnTop (true);
  62545. setVisible (true);
  62546. centreWithSize (width, height);
  62547. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62548. toFront (false);
  62549. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62550. repaint();
  62551. originalClickCounter = removeOnMouseClick
  62552. ? Desktop::getMouseButtonClickCounter()
  62553. : std::numeric_limits<int>::max();
  62554. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62555. startTimer (50);
  62556. }
  62557. void SplashScreen::paint (Graphics& g)
  62558. {
  62559. if (backgroundImage != 0)
  62560. {
  62561. g.setOpacity (1.0f);
  62562. g.drawImage (backgroundImage,
  62563. 0, 0, getWidth(), getHeight(),
  62564. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62565. }
  62566. }
  62567. void SplashScreen::timerCallback()
  62568. {
  62569. if (Time::getCurrentTime() > earliestTimeToDelete
  62570. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62571. {
  62572. delete this;
  62573. }
  62574. }
  62575. END_JUCE_NAMESPACE
  62576. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62577. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62578. BEGIN_JUCE_NAMESPACE
  62579. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62580. const bool hasProgressBar,
  62581. const bool hasCancelButton,
  62582. const int timeOutMsWhenCancelling_,
  62583. const String& cancelButtonText)
  62584. : Thread ("Juce Progress Window"),
  62585. progress (0.0),
  62586. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62587. {
  62588. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62589. .createAlertWindow (title, String::empty, cancelButtonText,
  62590. String::empty, String::empty,
  62591. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62592. if (hasProgressBar)
  62593. alertWindow->addProgressBarComponent (progress);
  62594. }
  62595. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62596. {
  62597. stopThread (timeOutMsWhenCancelling);
  62598. }
  62599. bool ThreadWithProgressWindow::runThread (const int priority)
  62600. {
  62601. startThread (priority);
  62602. startTimer (100);
  62603. {
  62604. const ScopedLock sl (messageLock);
  62605. alertWindow->setMessage (message);
  62606. }
  62607. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62608. stopThread (timeOutMsWhenCancelling);
  62609. alertWindow->setVisible (false);
  62610. return finishedNaturally;
  62611. }
  62612. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62613. {
  62614. progress = newProgress;
  62615. }
  62616. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62617. {
  62618. const ScopedLock sl (messageLock);
  62619. message = newStatusMessage;
  62620. }
  62621. void ThreadWithProgressWindow::timerCallback()
  62622. {
  62623. if (! isThreadRunning())
  62624. {
  62625. // thread has finished normally..
  62626. alertWindow->exitModalState (1);
  62627. alertWindow->setVisible (false);
  62628. }
  62629. else
  62630. {
  62631. const ScopedLock sl (messageLock);
  62632. alertWindow->setMessage (message);
  62633. }
  62634. }
  62635. END_JUCE_NAMESPACE
  62636. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62637. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62638. BEGIN_JUCE_NAMESPACE
  62639. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62640. const int millisecondsBeforeTipAppears_)
  62641. : Component ("tooltip"),
  62642. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62643. lastHideTime (0),
  62644. lastComponentUnderMouse (0),
  62645. changedCompsSinceShown (true)
  62646. {
  62647. startTimer (123);
  62648. setAlwaysOnTop (true);
  62649. setOpaque (true);
  62650. if (parentComponent != 0)
  62651. parentComponent->addChildComponent (this);
  62652. }
  62653. TooltipWindow::~TooltipWindow()
  62654. {
  62655. hide();
  62656. }
  62657. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  62658. {
  62659. millisecondsBeforeTipAppears = newTimeMs;
  62660. }
  62661. void TooltipWindow::paint (Graphics& g)
  62662. {
  62663. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  62664. }
  62665. void TooltipWindow::mouseEnter (const MouseEvent&)
  62666. {
  62667. hide();
  62668. }
  62669. void TooltipWindow::showFor (const String& tip)
  62670. {
  62671. jassert (tip.isNotEmpty());
  62672. tipShowing = tip;
  62673. Point<int> mousePos (Desktop::getMousePosition());
  62674. if (getParentComponent() != 0)
  62675. mousePos = getParentComponent()->globalPositionToRelative (mousePos);
  62676. int x, y, w, h;
  62677. getLookAndFeel().getTooltipSize (tip, w, h);
  62678. if (mousePos.getX() > getParentWidth() / 2)
  62679. x = mousePos.getX() - (w + 12);
  62680. else
  62681. x = mousePos.getX() + 24;
  62682. if (mousePos.getY() > getParentHeight() / 2)
  62683. y = mousePos.getY() - (h + 6);
  62684. else
  62685. y = mousePos.getY() + 6;
  62686. setBounds (x, y, w, h);
  62687. setVisible (true);
  62688. if (getParentComponent() == 0)
  62689. {
  62690. addToDesktop (ComponentPeer::windowHasDropShadow
  62691. | ComponentPeer::windowIsTemporary
  62692. | ComponentPeer::windowIgnoresKeyPresses);
  62693. }
  62694. toFront (false);
  62695. }
  62696. const String TooltipWindow::getTipFor (Component* const c)
  62697. {
  62698. if (c != 0
  62699. && Process::isForegroundProcess()
  62700. && ! Component::isMouseButtonDownAnywhere())
  62701. {
  62702. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  62703. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  62704. return ttc->getTooltip();
  62705. }
  62706. return String::empty;
  62707. }
  62708. void TooltipWindow::hide()
  62709. {
  62710. tipShowing = String::empty;
  62711. removeFromDesktop();
  62712. setVisible (false);
  62713. }
  62714. void TooltipWindow::timerCallback()
  62715. {
  62716. const unsigned int now = Time::getApproximateMillisecondCounter();
  62717. Component* const newComp = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  62718. const String newTip (getTipFor (newComp));
  62719. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  62720. lastComponentUnderMouse = newComp;
  62721. lastTipUnderMouse = newTip;
  62722. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  62723. const bool mouseWasClicked = clickCount > mouseClicks;
  62724. mouseClicks = clickCount;
  62725. const Point<int> mousePos (Desktop::getMousePosition());
  62726. const bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12;
  62727. lastMousePos = mousePos;
  62728. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  62729. lastCompChangeTime = now;
  62730. if (isVisible() || now < lastHideTime + 500)
  62731. {
  62732. // if a tip is currently visible (or has just disappeared), update to a new one
  62733. // immediately if needed..
  62734. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  62735. {
  62736. if (isVisible())
  62737. {
  62738. lastHideTime = now;
  62739. hide();
  62740. }
  62741. }
  62742. else if (tipChanged)
  62743. {
  62744. showFor (newTip);
  62745. }
  62746. }
  62747. else
  62748. {
  62749. // if there isn't currently a tip, but one is needed, only let it
  62750. // appear after a timeout..
  62751. if (newTip.isNotEmpty()
  62752. && newTip != tipShowing
  62753. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  62754. {
  62755. showFor (newTip);
  62756. }
  62757. }
  62758. }
  62759. END_JUCE_NAMESPACE
  62760. /*** End of inlined file: juce_TooltipWindow.cpp ***/
  62761. /*** Start of inlined file: juce_TopLevelWindow.cpp ***/
  62762. BEGIN_JUCE_NAMESPACE
  62763. class TopLevelWindowManager : public Timer,
  62764. public DeletedAtShutdown
  62765. {
  62766. public:
  62767. TopLevelWindowManager()
  62768. : currentActive (0)
  62769. {
  62770. }
  62771. ~TopLevelWindowManager()
  62772. {
  62773. clearSingletonInstance();
  62774. }
  62775. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  62776. void timerCallback()
  62777. {
  62778. startTimer (jmin (1731, getTimerInterval() * 2));
  62779. TopLevelWindow* active = 0;
  62780. if (Process::isForegroundProcess())
  62781. {
  62782. active = currentActive;
  62783. Component* const c = Component::getCurrentlyFocusedComponent();
  62784. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  62785. if (tlw == 0 && c != 0)
  62786. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  62787. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  62788. if (tlw != 0)
  62789. active = tlw;
  62790. }
  62791. if (active != currentActive)
  62792. {
  62793. currentActive = active;
  62794. for (int i = windows.size(); --i >= 0;)
  62795. {
  62796. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  62797. tlw->setWindowActive (isWindowActive (tlw));
  62798. i = jmin (i, windows.size() - 1);
  62799. }
  62800. Desktop::getInstance().triggerFocusCallback();
  62801. }
  62802. }
  62803. bool addWindow (TopLevelWindow* const w) throw()
  62804. {
  62805. windows.add (w);
  62806. startTimer (10);
  62807. return isWindowActive (w);
  62808. }
  62809. void removeWindow (TopLevelWindow* const w) throw()
  62810. {
  62811. startTimer (10);
  62812. if (currentActive == w)
  62813. currentActive = 0;
  62814. windows.removeValue (w);
  62815. if (windows.size() == 0)
  62816. deleteInstance();
  62817. }
  62818. VoidArray windows;
  62819. private:
  62820. TopLevelWindow* currentActive;
  62821. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  62822. {
  62823. return (tlw == currentActive
  62824. || tlw->isParentOf (currentActive)
  62825. || tlw->hasKeyboardFocus (true))
  62826. && tlw->isShowing();
  62827. }
  62828. TopLevelWindowManager (const TopLevelWindowManager&);
  62829. TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  62830. };
  62831. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  62832. void juce_CheckCurrentlyFocusedTopLevelWindow()
  62833. {
  62834. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  62835. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  62836. }
  62837. TopLevelWindow::TopLevelWindow (const String& name,
  62838. const bool addToDesktop_)
  62839. : Component (name),
  62840. useDropShadow (true),
  62841. useNativeTitleBar (false),
  62842. windowIsActive_ (false)
  62843. {
  62844. setOpaque (true);
  62845. if (addToDesktop_)
  62846. Component::addToDesktop (getDesktopWindowStyleFlags());
  62847. else
  62848. setDropShadowEnabled (true);
  62849. setWantsKeyboardFocus (true);
  62850. setBroughtToFrontOnMouseClick (true);
  62851. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  62852. }
  62853. TopLevelWindow::~TopLevelWindow()
  62854. {
  62855. shadower = 0;
  62856. TopLevelWindowManager::getInstance()->removeWindow (this);
  62857. }
  62858. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  62859. {
  62860. if (hasKeyboardFocus (true))
  62861. TopLevelWindowManager::getInstance()->timerCallback();
  62862. else
  62863. TopLevelWindowManager::getInstance()->startTimer (10);
  62864. }
  62865. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  62866. {
  62867. if (windowIsActive_ != isNowActive)
  62868. {
  62869. windowIsActive_ = isNowActive;
  62870. activeWindowStatusChanged();
  62871. }
  62872. }
  62873. void TopLevelWindow::activeWindowStatusChanged()
  62874. {
  62875. }
  62876. void TopLevelWindow::parentHierarchyChanged()
  62877. {
  62878. setDropShadowEnabled (useDropShadow);
  62879. }
  62880. void TopLevelWindow::visibilityChanged()
  62881. {
  62882. if (isShowing())
  62883. toFront (true);
  62884. }
  62885. int TopLevelWindow::getDesktopWindowStyleFlags() const
  62886. {
  62887. int flags = ComponentPeer::windowAppearsOnTaskbar;
  62888. if (useDropShadow)
  62889. flags |= ComponentPeer::windowHasDropShadow;
  62890. if (useNativeTitleBar)
  62891. flags |= ComponentPeer::windowHasTitleBar;
  62892. return flags;
  62893. }
  62894. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  62895. {
  62896. useDropShadow = useShadow;
  62897. if (isOnDesktop())
  62898. {
  62899. shadower = 0;
  62900. Component::addToDesktop (getDesktopWindowStyleFlags());
  62901. }
  62902. else
  62903. {
  62904. if (useShadow && isOpaque())
  62905. {
  62906. if (shadower == 0)
  62907. {
  62908. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  62909. if (shadower != 0)
  62910. shadower->setOwner (this);
  62911. }
  62912. }
  62913. else
  62914. {
  62915. shadower = 0;
  62916. }
  62917. }
  62918. }
  62919. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  62920. {
  62921. if (useNativeTitleBar != useNativeTitleBar_)
  62922. {
  62923. useNativeTitleBar = useNativeTitleBar_;
  62924. recreateDesktopWindow();
  62925. sendLookAndFeelChange();
  62926. }
  62927. }
  62928. void TopLevelWindow::recreateDesktopWindow()
  62929. {
  62930. if (isOnDesktop())
  62931. {
  62932. Component::addToDesktop (getDesktopWindowStyleFlags());
  62933. toFront (true);
  62934. }
  62935. }
  62936. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  62937. {
  62938. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  62939. because this class needs to make sure its layout corresponds with settings like whether
  62940. it's got a native title bar or not.
  62941. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  62942. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  62943. method, then add or remove whatever flags are necessary from this value before returning it.
  62944. */
  62945. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  62946. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  62947. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  62948. if (windowStyleFlags != getDesktopWindowStyleFlags())
  62949. sendLookAndFeelChange();
  62950. }
  62951. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  62952. {
  62953. if (c == 0)
  62954. c = TopLevelWindow::getActiveTopLevelWindow();
  62955. if (c == 0)
  62956. {
  62957. centreWithSize (width, height);
  62958. }
  62959. else
  62960. {
  62961. Point<int> p (c->relativePositionToGlobal (Point<int> ((c->getWidth() - width) / 2,
  62962. (c->getHeight() - height) / 2)));
  62963. Rectangle<int> parentArea (c->getParentMonitorArea());
  62964. if (getParentComponent() != 0)
  62965. {
  62966. p = getParentComponent()->globalPositionToRelative (p);
  62967. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  62968. }
  62969. parentArea.reduce (12, 12);
  62970. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), p.getX()),
  62971. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), p.getY()),
  62972. width, height);
  62973. }
  62974. }
  62975. int TopLevelWindow::getNumTopLevelWindows() throw()
  62976. {
  62977. return TopLevelWindowManager::getInstance()->windows.size();
  62978. }
  62979. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  62980. {
  62981. return (TopLevelWindow*) TopLevelWindowManager::getInstance()->windows [index];
  62982. }
  62983. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  62984. {
  62985. TopLevelWindow* best = 0;
  62986. int bestNumTWLParents = -1;
  62987. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  62988. {
  62989. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  62990. if (tlw->isActiveWindow())
  62991. {
  62992. int numTWLParents = 0;
  62993. const Component* c = tlw->getParentComponent();
  62994. while (c != 0)
  62995. {
  62996. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  62997. ++numTWLParents;
  62998. c = c->getParentComponent();
  62999. }
  63000. if (bestNumTWLParents < numTWLParents)
  63001. {
  63002. best = tlw;
  63003. bestNumTWLParents = numTWLParents;
  63004. }
  63005. }
  63006. }
  63007. return best;
  63008. }
  63009. END_JUCE_NAMESPACE
  63010. /*** End of inlined file: juce_TopLevelWindow.cpp ***/
  63011. /*** Start of inlined file: juce_Colour.cpp ***/
  63012. BEGIN_JUCE_NAMESPACE
  63013. static uint8 floatAlphaToInt (const float alpha)
  63014. {
  63015. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  63016. }
  63017. static const float oneOver255 = 1.0f / 255.0f;
  63018. Colour::Colour() throw()
  63019. : argb (0)
  63020. {
  63021. }
  63022. Colour::Colour (const Colour& other) throw()
  63023. : argb (other.argb)
  63024. {
  63025. }
  63026. Colour& Colour::operator= (const Colour& other) throw()
  63027. {
  63028. argb = other.argb;
  63029. return *this;
  63030. }
  63031. bool Colour::operator== (const Colour& other) const throw()
  63032. {
  63033. return argb.getARGB() == other.argb.getARGB();
  63034. }
  63035. bool Colour::operator!= (const Colour& other) const throw()
  63036. {
  63037. return argb.getARGB() != other.argb.getARGB();
  63038. }
  63039. Colour::Colour (const uint32 argb_) throw()
  63040. : argb (argb_)
  63041. {
  63042. }
  63043. Colour::Colour (const uint8 red,
  63044. const uint8 green,
  63045. const uint8 blue) throw()
  63046. {
  63047. argb.setARGB (0xff, red, green, blue);
  63048. }
  63049. const Colour Colour::fromRGB (const uint8 red,
  63050. const uint8 green,
  63051. const uint8 blue) throw()
  63052. {
  63053. return Colour (red, green, blue);
  63054. }
  63055. Colour::Colour (const uint8 red,
  63056. const uint8 green,
  63057. const uint8 blue,
  63058. const uint8 alpha) throw()
  63059. {
  63060. argb.setARGB (alpha, red, green, blue);
  63061. }
  63062. const Colour Colour::fromRGBA (const uint8 red,
  63063. const uint8 green,
  63064. const uint8 blue,
  63065. const uint8 alpha) throw()
  63066. {
  63067. return Colour (red, green, blue, alpha);
  63068. }
  63069. Colour::Colour (const uint8 red,
  63070. const uint8 green,
  63071. const uint8 blue,
  63072. const float alpha) throw()
  63073. {
  63074. argb.setARGB (floatAlphaToInt (alpha), red, green, blue);
  63075. }
  63076. const Colour Colour::fromRGBAFloat (const uint8 red,
  63077. const uint8 green,
  63078. const uint8 blue,
  63079. const float alpha) throw()
  63080. {
  63081. return Colour (red, green, blue, alpha);
  63082. }
  63083. static void convertHSBtoRGB (float h, float s, float v,
  63084. uint8& r, uint8& g, uint8& b) throw()
  63085. {
  63086. v = jlimit (0.0f, 1.0f, v);
  63087. v *= 255.0f;
  63088. const uint8 intV = (uint8) roundToInt (v);
  63089. if (s <= 0)
  63090. {
  63091. r = intV;
  63092. g = intV;
  63093. b = intV;
  63094. }
  63095. else
  63096. {
  63097. s = jmin (1.0f, s);
  63098. h = jlimit (0.0f, 1.0f, h);
  63099. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  63100. const float f = h - floorf (h);
  63101. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  63102. const float y = v * (1.0f - s * f);
  63103. const float z = v * (1.0f - (s * (1.0f - f)));
  63104. if (h < 1.0f)
  63105. {
  63106. r = intV;
  63107. g = (uint8) roundToInt (z);
  63108. b = x;
  63109. }
  63110. else if (h < 2.0f)
  63111. {
  63112. r = (uint8) roundToInt (y);
  63113. g = intV;
  63114. b = x;
  63115. }
  63116. else if (h < 3.0f)
  63117. {
  63118. r = x;
  63119. g = intV;
  63120. b = (uint8) roundToInt (z);
  63121. }
  63122. else if (h < 4.0f)
  63123. {
  63124. r = x;
  63125. g = (uint8) roundToInt (y);
  63126. b = intV;
  63127. }
  63128. else if (h < 5.0f)
  63129. {
  63130. r = (uint8) roundToInt (z);
  63131. g = x;
  63132. b = intV;
  63133. }
  63134. else if (h < 6.0f)
  63135. {
  63136. r = intV;
  63137. g = x;
  63138. b = (uint8) roundToInt (y);
  63139. }
  63140. else
  63141. {
  63142. r = 0;
  63143. g = 0;
  63144. b = 0;
  63145. }
  63146. }
  63147. }
  63148. Colour::Colour (const float hue,
  63149. const float saturation,
  63150. const float brightness,
  63151. const float alpha) throw()
  63152. {
  63153. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63154. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63155. argb.setARGB (floatAlphaToInt (alpha), r, g, b);
  63156. }
  63157. const Colour Colour::fromHSV (const float hue,
  63158. const float saturation,
  63159. const float brightness,
  63160. const float alpha) throw()
  63161. {
  63162. return Colour (hue, saturation, brightness, alpha);
  63163. }
  63164. Colour::Colour (const float hue,
  63165. const float saturation,
  63166. const float brightness,
  63167. const uint8 alpha) throw()
  63168. {
  63169. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63170. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63171. argb.setARGB (alpha, r, g, b);
  63172. }
  63173. Colour::~Colour() throw()
  63174. {
  63175. }
  63176. const PixelARGB Colour::getPixelARGB() const throw()
  63177. {
  63178. PixelARGB p (argb);
  63179. p.premultiply();
  63180. return p;
  63181. }
  63182. uint32 Colour::getARGB() const throw()
  63183. {
  63184. return argb.getARGB();
  63185. }
  63186. bool Colour::isTransparent() const throw()
  63187. {
  63188. return getAlpha() == 0;
  63189. }
  63190. bool Colour::isOpaque() const throw()
  63191. {
  63192. return getAlpha() == 0xff;
  63193. }
  63194. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  63195. {
  63196. PixelARGB newCol (argb);
  63197. newCol.setAlpha (newAlpha);
  63198. return Colour (newCol.getARGB());
  63199. }
  63200. const Colour Colour::withAlpha (const float newAlpha) const throw()
  63201. {
  63202. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  63203. PixelARGB newCol (argb);
  63204. newCol.setAlpha (floatAlphaToInt (newAlpha));
  63205. return Colour (newCol.getARGB());
  63206. }
  63207. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  63208. {
  63209. jassert (alphaMultiplier >= 0);
  63210. PixelARGB newCol (argb);
  63211. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  63212. return Colour (newCol.getARGB());
  63213. }
  63214. const Colour Colour::overlaidWith (const Colour& src) const throw()
  63215. {
  63216. const int destAlpha = getAlpha();
  63217. if (destAlpha > 0)
  63218. {
  63219. const int invA = 0xff - (int) src.getAlpha();
  63220. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  63221. if (resA > 0)
  63222. {
  63223. const int da = (invA * destAlpha) / resA;
  63224. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  63225. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  63226. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  63227. (uint8) resA);
  63228. }
  63229. return *this;
  63230. }
  63231. else
  63232. {
  63233. return src;
  63234. }
  63235. }
  63236. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63237. {
  63238. if (proportionOfOther <= 0)
  63239. return *this;
  63240. if (proportionOfOther >= 1.0f)
  63241. return other;
  63242. PixelARGB c1 (getPixelARGB());
  63243. const PixelARGB c2 (other.getPixelARGB());
  63244. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63245. c1.unpremultiply();
  63246. return Colour (c1.getARGB());
  63247. }
  63248. float Colour::getFloatRed() const throw()
  63249. {
  63250. return getRed() * oneOver255;
  63251. }
  63252. float Colour::getFloatGreen() const throw()
  63253. {
  63254. return getGreen() * oneOver255;
  63255. }
  63256. float Colour::getFloatBlue() const throw()
  63257. {
  63258. return getBlue() * oneOver255;
  63259. }
  63260. float Colour::getFloatAlpha() const throw()
  63261. {
  63262. return getAlpha() * oneOver255;
  63263. }
  63264. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63265. {
  63266. const int r = getRed();
  63267. const int g = getGreen();
  63268. const int b = getBlue();
  63269. const int hi = jmax (r, g, b);
  63270. const int lo = jmin (r, g, b);
  63271. if (hi != 0)
  63272. {
  63273. s = (hi - lo) / (float) hi;
  63274. if (s != 0)
  63275. {
  63276. const float invDiff = 1.0f / (hi - lo);
  63277. const float red = (hi - r) * invDiff;
  63278. const float green = (hi - g) * invDiff;
  63279. const float blue = (hi - b) * invDiff;
  63280. if (r == hi)
  63281. h = blue - green;
  63282. else if (g == hi)
  63283. h = 2.0f + red - blue;
  63284. else
  63285. h = 4.0f + green - red;
  63286. h *= 1.0f / 6.0f;
  63287. if (h < 0)
  63288. ++h;
  63289. }
  63290. else
  63291. {
  63292. h = 0;
  63293. }
  63294. }
  63295. else
  63296. {
  63297. s = 0;
  63298. h = 0;
  63299. }
  63300. v = hi * oneOver255;
  63301. }
  63302. float Colour::getHue() const throw()
  63303. {
  63304. float h, s, b;
  63305. getHSB (h, s, b);
  63306. return h;
  63307. }
  63308. const Colour Colour::withHue (const float hue) const throw()
  63309. {
  63310. float h, s, b;
  63311. getHSB (h, s, b);
  63312. return Colour (hue, s, b, getAlpha());
  63313. }
  63314. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63315. {
  63316. float h, s, b;
  63317. getHSB (h, s, b);
  63318. h += amountToRotate;
  63319. h -= floorf (h);
  63320. return Colour (h, s, b, getAlpha());
  63321. }
  63322. float Colour::getSaturation() const throw()
  63323. {
  63324. float h, s, b;
  63325. getHSB (h, s, b);
  63326. return s;
  63327. }
  63328. const Colour Colour::withSaturation (const float saturation) const throw()
  63329. {
  63330. float h, s, b;
  63331. getHSB (h, s, b);
  63332. return Colour (h, saturation, b, getAlpha());
  63333. }
  63334. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63335. {
  63336. float h, s, b;
  63337. getHSB (h, s, b);
  63338. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63339. }
  63340. float Colour::getBrightness() const throw()
  63341. {
  63342. float h, s, b;
  63343. getHSB (h, s, b);
  63344. return b;
  63345. }
  63346. const Colour Colour::withBrightness (const float brightness) const throw()
  63347. {
  63348. float h, s, b;
  63349. getHSB (h, s, b);
  63350. return Colour (h, s, brightness, getAlpha());
  63351. }
  63352. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63353. {
  63354. float h, s, b;
  63355. getHSB (h, s, b);
  63356. b *= amount;
  63357. if (b > 1.0f)
  63358. b = 1.0f;
  63359. return Colour (h, s, b, getAlpha());
  63360. }
  63361. const Colour Colour::brighter (float amount) const throw()
  63362. {
  63363. amount = 1.0f / (1.0f + amount);
  63364. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63365. (uint8) (255 - (amount * (255 - getGreen()))),
  63366. (uint8) (255 - (amount * (255 - getBlue()))),
  63367. getAlpha());
  63368. }
  63369. const Colour Colour::darker (float amount) const throw()
  63370. {
  63371. amount = 1.0f / (1.0f + amount);
  63372. return Colour ((uint8) (amount * getRed()),
  63373. (uint8) (amount * getGreen()),
  63374. (uint8) (amount * getBlue()),
  63375. getAlpha());
  63376. }
  63377. const Colour Colour::greyLevel (const float brightness) throw()
  63378. {
  63379. const uint8 level
  63380. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63381. return Colour (level, level, level);
  63382. }
  63383. const Colour Colour::contrasting (const float amount) const throw()
  63384. {
  63385. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63386. ? Colours::black
  63387. : Colours::white).withAlpha (amount));
  63388. }
  63389. const Colour Colour::contrasting (const Colour& colour1,
  63390. const Colour& colour2) throw()
  63391. {
  63392. const float b1 = colour1.getBrightness();
  63393. const float b2 = colour2.getBrightness();
  63394. float best = 0.0f;
  63395. float bestDist = 0.0f;
  63396. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63397. {
  63398. const float d1 = fabsf (i - b1);
  63399. const float d2 = fabsf (i - b2);
  63400. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63401. if (dist > bestDist)
  63402. {
  63403. best = i;
  63404. bestDist = dist;
  63405. }
  63406. }
  63407. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63408. .withBrightness (best);
  63409. }
  63410. const String Colour::toString() const throw()
  63411. {
  63412. return String::toHexString ((int) argb.getARGB());
  63413. }
  63414. const Colour Colour::fromString (const String& encodedColourString)
  63415. {
  63416. return Colour ((uint32) encodedColourString.getHexValue32());
  63417. }
  63418. END_JUCE_NAMESPACE
  63419. /*** End of inlined file: juce_Colour.cpp ***/
  63420. /*** Start of inlined file: juce_ColourGradient.cpp ***/
  63421. BEGIN_JUCE_NAMESPACE
  63422. ColourGradient::ColourGradient() throw()
  63423. {
  63424. #ifdef JUCE_DEBUG
  63425. x1 = 987654.0f;
  63426. #endif
  63427. }
  63428. ColourGradient::ColourGradient (const Colour& colour1,
  63429. const float x1_,
  63430. const float y1_,
  63431. const Colour& colour2,
  63432. const float x2_,
  63433. const float y2_,
  63434. const bool isRadial_) throw()
  63435. : x1 (x1_),
  63436. y1 (y1_),
  63437. x2 (x2_),
  63438. y2 (y2_),
  63439. isRadial (isRadial_)
  63440. {
  63441. colours.add (0);
  63442. colours.add (colour1.getARGB());
  63443. colours.add (1 << 16);
  63444. colours.add (colour2.getARGB());
  63445. }
  63446. ColourGradient::~ColourGradient() throw()
  63447. {
  63448. }
  63449. void ColourGradient::clearColours() throw()
  63450. {
  63451. colours.clear();
  63452. }
  63453. void ColourGradient::addColour (const double proportionAlongGradient,
  63454. const Colour& colour) throw()
  63455. {
  63456. // must be within the two end-points
  63457. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63458. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63459. int i;
  63460. for (i = 0; i < colours.size(); i += 2)
  63461. if (colours.getUnchecked(i) > pos)
  63462. break;
  63463. colours.insert (i, pos);
  63464. colours.insert (i + 1, colour.getARGB());
  63465. }
  63466. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63467. {
  63468. for (int i = 1; i < colours.size(); i += 2)
  63469. {
  63470. const Colour c (colours.getUnchecked(i));
  63471. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63472. }
  63473. }
  63474. int ColourGradient::getNumColours() const throw()
  63475. {
  63476. return colours.size() >> 1;
  63477. }
  63478. double ColourGradient::getColourPosition (const int index) const throw()
  63479. {
  63480. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63481. }
  63482. const Colour ColourGradient::getColour (const int index) const throw()
  63483. {
  63484. return Colour (colours [(index << 1) + 1]);
  63485. }
  63486. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63487. {
  63488. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63489. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63490. if (integerPos <= 0 || colours.size() <= 2)
  63491. return getColour (0);
  63492. int i = colours.size() - 2;
  63493. while (integerPos < (int) colours.getUnchecked(i))
  63494. i -= 2;
  63495. if (i >= colours.size() - 2)
  63496. return Colour (colours.getUnchecked(i));
  63497. const int pos1 = colours.getUnchecked (i);
  63498. const Colour col1 (colours.getUnchecked (i + 1));
  63499. const int pos2 = colours.getUnchecked (i + 2);
  63500. const Colour col2 (colours.getUnchecked (i + 3));
  63501. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63502. }
  63503. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63504. {
  63505. #ifdef JUCE_DEBUG
  63506. // trying to use the object without setting its co-ordinates? Have a careful read of
  63507. // the comments for the constructors.
  63508. jassert (x1 != 987654.0f);
  63509. #endif
  63510. const int numColours = colours.size() >> 1;
  63511. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63512. transform.transformPoint (tx1, ty1);
  63513. transform.transformPoint (tx2, ty2);
  63514. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63515. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63516. lookupTable.malloc (numEntries);
  63517. if (numColours >= 2)
  63518. {
  63519. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63520. PixelARGB pix1 (colours.getUnchecked (1));
  63521. pix1.premultiply();
  63522. int index = 0;
  63523. for (int j = 2; j < colours.size(); j += 2)
  63524. {
  63525. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63526. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63527. pix2.premultiply();
  63528. for (int i = 0; i < numToDo; ++i)
  63529. {
  63530. jassert (index >= 0 && index < numEntries);
  63531. lookupTable[index] = pix1;
  63532. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63533. ++index;
  63534. }
  63535. pix1 = pix2;
  63536. }
  63537. while (index < numEntries)
  63538. lookupTable [index++] = pix1;
  63539. }
  63540. else
  63541. {
  63542. jassertfalse // no colours specified!
  63543. }
  63544. return numEntries;
  63545. }
  63546. bool ColourGradient::isOpaque() const throw()
  63547. {
  63548. for (int i = 1; i < colours.size(); i += 2)
  63549. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63550. return false;
  63551. return true;
  63552. }
  63553. bool ColourGradient::isInvisible() const throw()
  63554. {
  63555. for (int i = 1; i < colours.size(); i += 2)
  63556. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63557. return false;
  63558. return true;
  63559. }
  63560. END_JUCE_NAMESPACE
  63561. /*** End of inlined file: juce_ColourGradient.cpp ***/
  63562. /*** Start of inlined file: juce_Colours.cpp ***/
  63563. BEGIN_JUCE_NAMESPACE
  63564. const Colour Colours::transparentBlack (0);
  63565. const Colour Colours::transparentWhite (0x00ffffff);
  63566. const Colour Colours::aliceblue (0xfff0f8ff);
  63567. const Colour Colours::antiquewhite (0xfffaebd7);
  63568. const Colour Colours::aqua (0xff00ffff);
  63569. const Colour Colours::aquamarine (0xff7fffd4);
  63570. const Colour Colours::azure (0xfff0ffff);
  63571. const Colour Colours::beige (0xfff5f5dc);
  63572. const Colour Colours::bisque (0xffffe4c4);
  63573. const Colour Colours::black (0xff000000);
  63574. const Colour Colours::blanchedalmond (0xffffebcd);
  63575. const Colour Colours::blue (0xff0000ff);
  63576. const Colour Colours::blueviolet (0xff8a2be2);
  63577. const Colour Colours::brown (0xffa52a2a);
  63578. const Colour Colours::burlywood (0xffdeb887);
  63579. const Colour Colours::cadetblue (0xff5f9ea0);
  63580. const Colour Colours::chartreuse (0xff7fff00);
  63581. const Colour Colours::chocolate (0xffd2691e);
  63582. const Colour Colours::coral (0xffff7f50);
  63583. const Colour Colours::cornflowerblue (0xff6495ed);
  63584. const Colour Colours::cornsilk (0xfffff8dc);
  63585. const Colour Colours::crimson (0xffdc143c);
  63586. const Colour Colours::cyan (0xff00ffff);
  63587. const Colour Colours::darkblue (0xff00008b);
  63588. const Colour Colours::darkcyan (0xff008b8b);
  63589. const Colour Colours::darkgoldenrod (0xffb8860b);
  63590. const Colour Colours::darkgrey (0xff555555);
  63591. const Colour Colours::darkgreen (0xff006400);
  63592. const Colour Colours::darkkhaki (0xffbdb76b);
  63593. const Colour Colours::darkmagenta (0xff8b008b);
  63594. const Colour Colours::darkolivegreen (0xff556b2f);
  63595. const Colour Colours::darkorange (0xffff8c00);
  63596. const Colour Colours::darkorchid (0xff9932cc);
  63597. const Colour Colours::darkred (0xff8b0000);
  63598. const Colour Colours::darksalmon (0xffe9967a);
  63599. const Colour Colours::darkseagreen (0xff8fbc8f);
  63600. const Colour Colours::darkslateblue (0xff483d8b);
  63601. const Colour Colours::darkslategrey (0xff2f4f4f);
  63602. const Colour Colours::darkturquoise (0xff00ced1);
  63603. const Colour Colours::darkviolet (0xff9400d3);
  63604. const Colour Colours::deeppink (0xffff1493);
  63605. const Colour Colours::deepskyblue (0xff00bfff);
  63606. const Colour Colours::dimgrey (0xff696969);
  63607. const Colour Colours::dodgerblue (0xff1e90ff);
  63608. const Colour Colours::firebrick (0xffb22222);
  63609. const Colour Colours::floralwhite (0xfffffaf0);
  63610. const Colour Colours::forestgreen (0xff228b22);
  63611. const Colour Colours::fuchsia (0xffff00ff);
  63612. const Colour Colours::gainsboro (0xffdcdcdc);
  63613. const Colour Colours::gold (0xffffd700);
  63614. const Colour Colours::goldenrod (0xffdaa520);
  63615. const Colour Colours::grey (0xff808080);
  63616. const Colour Colours::green (0xff008000);
  63617. const Colour Colours::greenyellow (0xffadff2f);
  63618. const Colour Colours::honeydew (0xfff0fff0);
  63619. const Colour Colours::hotpink (0xffff69b4);
  63620. const Colour Colours::indianred (0xffcd5c5c);
  63621. const Colour Colours::indigo (0xff4b0082);
  63622. const Colour Colours::ivory (0xfffffff0);
  63623. const Colour Colours::khaki (0xfff0e68c);
  63624. const Colour Colours::lavender (0xffe6e6fa);
  63625. const Colour Colours::lavenderblush (0xfffff0f5);
  63626. const Colour Colours::lemonchiffon (0xfffffacd);
  63627. const Colour Colours::lightblue (0xffadd8e6);
  63628. const Colour Colours::lightcoral (0xfff08080);
  63629. const Colour Colours::lightcyan (0xffe0ffff);
  63630. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63631. const Colour Colours::lightgreen (0xff90ee90);
  63632. const Colour Colours::lightgrey (0xffd3d3d3);
  63633. const Colour Colours::lightpink (0xffffb6c1);
  63634. const Colour Colours::lightsalmon (0xffffa07a);
  63635. const Colour Colours::lightseagreen (0xff20b2aa);
  63636. const Colour Colours::lightskyblue (0xff87cefa);
  63637. const Colour Colours::lightslategrey (0xff778899);
  63638. const Colour Colours::lightsteelblue (0xffb0c4de);
  63639. const Colour Colours::lightyellow (0xffffffe0);
  63640. const Colour Colours::lime (0xff00ff00);
  63641. const Colour Colours::limegreen (0xff32cd32);
  63642. const Colour Colours::linen (0xfffaf0e6);
  63643. const Colour Colours::magenta (0xffff00ff);
  63644. const Colour Colours::maroon (0xff800000);
  63645. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63646. const Colour Colours::mediumblue (0xff0000cd);
  63647. const Colour Colours::mediumorchid (0xffba55d3);
  63648. const Colour Colours::mediumpurple (0xff9370db);
  63649. const Colour Colours::mediumseagreen (0xff3cb371);
  63650. const Colour Colours::mediumslateblue (0xff7b68ee);
  63651. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63652. const Colour Colours::mediumturquoise (0xff48d1cc);
  63653. const Colour Colours::mediumvioletred (0xffc71585);
  63654. const Colour Colours::midnightblue (0xff191970);
  63655. const Colour Colours::mintcream (0xfff5fffa);
  63656. const Colour Colours::mistyrose (0xffffe4e1);
  63657. const Colour Colours::navajowhite (0xffffdead);
  63658. const Colour Colours::navy (0xff000080);
  63659. const Colour Colours::oldlace (0xfffdf5e6);
  63660. const Colour Colours::olive (0xff808000);
  63661. const Colour Colours::olivedrab (0xff6b8e23);
  63662. const Colour Colours::orange (0xffffa500);
  63663. const Colour Colours::orangered (0xffff4500);
  63664. const Colour Colours::orchid (0xffda70d6);
  63665. const Colour Colours::palegoldenrod (0xffeee8aa);
  63666. const Colour Colours::palegreen (0xff98fb98);
  63667. const Colour Colours::paleturquoise (0xffafeeee);
  63668. const Colour Colours::palevioletred (0xffdb7093);
  63669. const Colour Colours::papayawhip (0xffffefd5);
  63670. const Colour Colours::peachpuff (0xffffdab9);
  63671. const Colour Colours::peru (0xffcd853f);
  63672. const Colour Colours::pink (0xffffc0cb);
  63673. const Colour Colours::plum (0xffdda0dd);
  63674. const Colour Colours::powderblue (0xffb0e0e6);
  63675. const Colour Colours::purple (0xff800080);
  63676. const Colour Colours::red (0xffff0000);
  63677. const Colour Colours::rosybrown (0xffbc8f8f);
  63678. const Colour Colours::royalblue (0xff4169e1);
  63679. const Colour Colours::saddlebrown (0xff8b4513);
  63680. const Colour Colours::salmon (0xfffa8072);
  63681. const Colour Colours::sandybrown (0xfff4a460);
  63682. const Colour Colours::seagreen (0xff2e8b57);
  63683. const Colour Colours::seashell (0xfffff5ee);
  63684. const Colour Colours::sienna (0xffa0522d);
  63685. const Colour Colours::silver (0xffc0c0c0);
  63686. const Colour Colours::skyblue (0xff87ceeb);
  63687. const Colour Colours::slateblue (0xff6a5acd);
  63688. const Colour Colours::slategrey (0xff708090);
  63689. const Colour Colours::snow (0xfffffafa);
  63690. const Colour Colours::springgreen (0xff00ff7f);
  63691. const Colour Colours::steelblue (0xff4682b4);
  63692. const Colour Colours::tan (0xffd2b48c);
  63693. const Colour Colours::teal (0xff008080);
  63694. const Colour Colours::thistle (0xffd8bfd8);
  63695. const Colour Colours::tomato (0xffff6347);
  63696. const Colour Colours::turquoise (0xff40e0d0);
  63697. const Colour Colours::violet (0xffee82ee);
  63698. const Colour Colours::wheat (0xfff5deb3);
  63699. const Colour Colours::white (0xffffffff);
  63700. const Colour Colours::whitesmoke (0xfff5f5f5);
  63701. const Colour Colours::yellow (0xffffff00);
  63702. const Colour Colours::yellowgreen (0xff9acd32);
  63703. const Colour Colours::findColourForName (const String& colourName,
  63704. const Colour& defaultColour)
  63705. {
  63706. static const int presets[] =
  63707. {
  63708. // (first value is the string's hashcode, second is ARGB)
  63709. 0x05978fff, 0xff000000, /* black */
  63710. 0x06bdcc29, 0xffffffff, /* white */
  63711. 0x002e305a, 0xff0000ff, /* blue */
  63712. 0x00308adf, 0xff808080, /* grey */
  63713. 0x05e0cf03, 0xff008000, /* green */
  63714. 0x0001b891, 0xffff0000, /* red */
  63715. 0xd43c6474, 0xffffff00, /* yellow */
  63716. 0x620886da, 0xfff0f8ff, /* aliceblue */
  63717. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  63718. 0x002dcebc, 0xff00ffff, /* aqua */
  63719. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  63720. 0x0590228f, 0xfff0ffff, /* azure */
  63721. 0x05947fe4, 0xfff5f5dc, /* beige */
  63722. 0xad388e35, 0xffffe4c4, /* bisque */
  63723. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  63724. 0x39129959, 0xff8a2be2, /* blueviolet */
  63725. 0x059a8136, 0xffa52a2a, /* brown */
  63726. 0x89cea8f9, 0xffdeb887, /* burlywood */
  63727. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  63728. 0x6b748956, 0xff7fff00, /* chartreuse */
  63729. 0x2903623c, 0xffd2691e, /* chocolate */
  63730. 0x05a74431, 0xffff7f50, /* coral */
  63731. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  63732. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  63733. 0x3d8c4edf, 0xffdc143c, /* crimson */
  63734. 0x002ed323, 0xff00ffff, /* cyan */
  63735. 0x67cc74d0, 0xff00008b, /* darkblue */
  63736. 0x67cd1799, 0xff008b8b, /* darkcyan */
  63737. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  63738. 0x67cecf55, 0xff555555, /* darkgrey */
  63739. 0x920b194d, 0xff006400, /* darkgreen */
  63740. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  63741. 0x5c293873, 0xff8b008b, /* darkmagenta */
  63742. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  63743. 0xbcfd2524, 0xffff8c00, /* darkorange */
  63744. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  63745. 0x55ee0d5b, 0xff8b0000, /* darkred */
  63746. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  63747. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  63748. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  63749. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  63750. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  63751. 0xc8769375, 0xff9400d3, /* darkviolet */
  63752. 0x25832862, 0xffff1493, /* deeppink */
  63753. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  63754. 0x634c8b67, 0xff696969, /* dimgrey */
  63755. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  63756. 0xef19e3cb, 0xffb22222, /* firebrick */
  63757. 0xb852b195, 0xfffffaf0, /* floralwhite */
  63758. 0xd086fd06, 0xff228b22, /* forestgreen */
  63759. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  63760. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  63761. 0x00308060, 0xffffd700, /* gold */
  63762. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  63763. 0xbab8a537, 0xffadff2f, /* greenyellow */
  63764. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  63765. 0x41892743, 0xffff69b4, /* hotpink */
  63766. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  63767. 0xb969fed2, 0xff4b0082, /* indigo */
  63768. 0x05fef6a9, 0xfffffff0, /* ivory */
  63769. 0x06149302, 0xfff0e68c, /* khaki */
  63770. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  63771. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  63772. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  63773. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  63774. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  63775. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  63776. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  63777. 0xf40157ad, 0xff90ee90, /* lightgreen */
  63778. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  63779. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  63780. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  63781. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  63782. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  63783. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  63784. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  63785. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  63786. 0x0032afd5, 0xff00ff00, /* lime */
  63787. 0x607bbc4e, 0xff32cd32, /* limegreen */
  63788. 0x06234efa, 0xfffaf0e6, /* linen */
  63789. 0x316858a9, 0xffff00ff, /* magenta */
  63790. 0xbf8ca470, 0xff800000, /* maroon */
  63791. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  63792. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  63793. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  63794. 0x07556b71, 0xff9370db, /* mediumpurple */
  63795. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  63796. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  63797. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  63798. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  63799. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  63800. 0x168eb32a, 0xff191970, /* midnightblue */
  63801. 0x4306b960, 0xfff5fffa, /* mintcream */
  63802. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  63803. 0xe97218a6, 0xffffdead, /* navajowhite */
  63804. 0x00337bb6, 0xff000080, /* navy */
  63805. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  63806. 0x064ee1db, 0xff808000, /* olive */
  63807. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  63808. 0xc3de262e, 0xffffa500, /* orange */
  63809. 0x58bebba3, 0xffff4500, /* orangered */
  63810. 0xc3def8a3, 0xffda70d6, /* orchid */
  63811. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  63812. 0x3d9dd619, 0xff98fb98, /* palegreen */
  63813. 0x74022737, 0xffafeeee, /* paleturquoise */
  63814. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  63815. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  63816. 0x93e1b776, 0xffffdab9, /* peachpuff */
  63817. 0x003472f8, 0xffcd853f, /* peru */
  63818. 0x00348176, 0xffffc0cb, /* pink */
  63819. 0x00348d94, 0xffdda0dd, /* plum */
  63820. 0xd036be93, 0xffb0e0e6, /* powderblue */
  63821. 0xc5c507bc, 0xff800080, /* purple */
  63822. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  63823. 0xbd9413e1, 0xff4169e1, /* royalblue */
  63824. 0xf456044f, 0xff8b4513, /* saddlebrown */
  63825. 0xc9c6f66e, 0xfffa8072, /* salmon */
  63826. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  63827. 0x34636c14, 0xff2e8b57, /* seagreen */
  63828. 0x3507fb41, 0xfffff5ee, /* seashell */
  63829. 0xca348772, 0xffa0522d, /* sienna */
  63830. 0xca37d30d, 0xffc0c0c0, /* silver */
  63831. 0x80da74fb, 0xff87ceeb, /* skyblue */
  63832. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  63833. 0x44ab37f8, 0xff708090, /* slategrey */
  63834. 0x0035f183, 0xfffffafa, /* snow */
  63835. 0xd5440d16, 0xff00ff7f, /* springgreen */
  63836. 0x3e1524a5, 0xff4682b4, /* steelblue */
  63837. 0x0001bfa1, 0xffd2b48c, /* tan */
  63838. 0x0036425c, 0xff008080, /* teal */
  63839. 0xafc8858f, 0xffd8bfd8, /* thistle */
  63840. 0xcc41600a, 0xffff6347, /* tomato */
  63841. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  63842. 0xcf57947f, 0xffee82ee, /* violet */
  63843. 0x06bdbae7, 0xfff5deb3, /* wheat */
  63844. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  63845. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  63846. };
  63847. const int hash = colourName.trim().toLowerCase().hashCode();
  63848. for (int i = 0; i < numElementsInArray (presets); i += 2)
  63849. if (presets [i] == hash)
  63850. return Colour (presets [i + 1]);
  63851. return defaultColour;
  63852. }
  63853. END_JUCE_NAMESPACE
  63854. /*** End of inlined file: juce_Colours.cpp ***/
  63855. /*** Start of inlined file: juce_EdgeTable.cpp ***/
  63856. BEGIN_JUCE_NAMESPACE
  63857. const int juce_edgeTableDefaultEdgesPerLine = 32;
  63858. EdgeTable::EdgeTable (const Rectangle<int>& bounds_,
  63859. const Path& path, const AffineTransform& transform)
  63860. : bounds (bounds_),
  63861. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63862. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63863. needToCheckEmptinesss (true)
  63864. {
  63865. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  63866. int* t = table;
  63867. for (int i = bounds.getHeight(); --i >= 0;)
  63868. {
  63869. *t = 0;
  63870. t += lineStrideElements;
  63871. }
  63872. const int topLimit = bounds.getY() << 8;
  63873. const int heightLimit = bounds.getHeight() << 8;
  63874. const int leftLimit = bounds.getX() << 8;
  63875. const int rightLimit = bounds.getRight() << 8;
  63876. PathFlatteningIterator iter (path, transform);
  63877. while (iter.next())
  63878. {
  63879. int y1 = roundToInt (iter.y1 * 256.0f);
  63880. int y2 = roundToInt (iter.y2 * 256.0f);
  63881. if (y1 != y2)
  63882. {
  63883. y1 -= topLimit;
  63884. y2 -= topLimit;
  63885. const int startY = y1;
  63886. int direction = -1;
  63887. if (y1 > y2)
  63888. {
  63889. swapVariables (y1, y2);
  63890. direction = 1;
  63891. }
  63892. if (y1 < 0)
  63893. y1 = 0;
  63894. if (y2 > heightLimit)
  63895. y2 = heightLimit;
  63896. if (y1 < y2)
  63897. {
  63898. const double startX = 256.0f * iter.x1;
  63899. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  63900. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  63901. do
  63902. {
  63903. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  63904. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  63905. if (x < leftLimit)
  63906. x = leftLimit;
  63907. else if (x >= rightLimit)
  63908. x = rightLimit - 1;
  63909. addEdgePoint (x, y1 >> 8, direction * step);
  63910. y1 += step;
  63911. }
  63912. while (y1 < y2);
  63913. }
  63914. }
  63915. }
  63916. sanitiseLevels (path.isUsingNonZeroWinding());
  63917. }
  63918. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd)
  63919. : bounds (rectangleToAdd),
  63920. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63921. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63922. needToCheckEmptinesss (true)
  63923. {
  63924. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63925. table[0] = 0;
  63926. const int x1 = rectangleToAdd.getX() << 8;
  63927. const int x2 = rectangleToAdd.getRight() << 8;
  63928. int* t = table;
  63929. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  63930. {
  63931. t[0] = 2;
  63932. t[1] = x1;
  63933. t[2] = 255;
  63934. t[3] = x2;
  63935. t[4] = 0;
  63936. t += lineStrideElements;
  63937. }
  63938. }
  63939. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd)
  63940. : bounds (rectanglesToAdd.getBounds()),
  63941. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63942. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63943. needToCheckEmptinesss (true)
  63944. {
  63945. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63946. int* t = table;
  63947. for (int i = bounds.getHeight(); --i >= 0;)
  63948. {
  63949. *t = 0;
  63950. t += lineStrideElements;
  63951. }
  63952. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  63953. {
  63954. const Rectangle<int>* const r = iter.getRectangle();
  63955. const int x1 = r->getX() << 8;
  63956. const int x2 = r->getRight() << 8;
  63957. int y = r->getY() - bounds.getY();
  63958. for (int j = r->getHeight(); --j >= 0;)
  63959. {
  63960. addEdgePoint (x1, y, 255);
  63961. addEdgePoint (x2, y, -255);
  63962. ++y;
  63963. }
  63964. }
  63965. sanitiseLevels (true);
  63966. }
  63967. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h)
  63968. : bounds (Rectangle<int> ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  63969. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63970. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63971. needToCheckEmptinesss (true)
  63972. {
  63973. jassert (w > 0 && h > 0);
  63974. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63975. table[0] = 0;
  63976. const int x1 = roundToInt (x * 256.0f);
  63977. const int x2 = roundToInt ((x + w) * 256.0f);
  63978. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  63979. jassert (y1 < 256);
  63980. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  63981. if (x2 <= x1 || y2 <= y1)
  63982. {
  63983. bounds.setHeight (0);
  63984. return;
  63985. }
  63986. int lineY = 0;
  63987. int* t = table;
  63988. if ((y1 >> 8) == (y2 >> 8))
  63989. {
  63990. t[0] = 2;
  63991. t[1] = x1;
  63992. t[2] = y2 - y1;
  63993. t[3] = x2;
  63994. t[4] = 0;
  63995. ++lineY;
  63996. t += lineStrideElements;
  63997. }
  63998. else
  63999. {
  64000. t[0] = 2;
  64001. t[1] = x1;
  64002. t[2] = 255 - (y1 & 255);
  64003. t[3] = x2;
  64004. t[4] = 0;
  64005. ++lineY;
  64006. t += lineStrideElements;
  64007. while (lineY < (y2 >> 8))
  64008. {
  64009. t[0] = 2;
  64010. t[1] = x1;
  64011. t[2] = 255;
  64012. t[3] = x2;
  64013. t[4] = 0;
  64014. ++lineY;
  64015. t += lineStrideElements;
  64016. }
  64017. jassert (lineY < bounds.getHeight());
  64018. t[0] = 2;
  64019. t[1] = x1;
  64020. t[2] = y2 & 255;
  64021. t[3] = x2;
  64022. t[4] = 0;
  64023. ++lineY;
  64024. t += lineStrideElements;
  64025. }
  64026. while (lineY < bounds.getHeight())
  64027. {
  64028. t[0] = 0;
  64029. t += lineStrideElements;
  64030. ++lineY;
  64031. }
  64032. }
  64033. EdgeTable::EdgeTable (const EdgeTable& other)
  64034. : table (0)
  64035. {
  64036. operator= (other);
  64037. }
  64038. EdgeTable& EdgeTable::operator= (const EdgeTable& other)
  64039. {
  64040. bounds = other.bounds;
  64041. maxEdgesPerLine = other.maxEdgesPerLine;
  64042. lineStrideElements = other.lineStrideElements;
  64043. needToCheckEmptinesss = other.needToCheckEmptinesss;
  64044. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64045. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  64046. return *this;
  64047. }
  64048. EdgeTable::~EdgeTable()
  64049. {
  64050. }
  64051. void EdgeTable::copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  64052. {
  64053. while (--numLines >= 0)
  64054. {
  64055. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  64056. src += srcLineStride;
  64057. dest += destLineStride;
  64058. }
  64059. }
  64060. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  64061. {
  64062. // Convert the table from relative windings to absolute levels..
  64063. int* lineStart = table;
  64064. for (int i = bounds.getHeight(); --i >= 0;)
  64065. {
  64066. int* line = lineStart;
  64067. lineStart += lineStrideElements;
  64068. int num = *line;
  64069. if (num == 0)
  64070. continue;
  64071. int level = 0;
  64072. if (useNonZeroWinding)
  64073. {
  64074. while (--num > 0)
  64075. {
  64076. line += 2;
  64077. level += *line;
  64078. int corrected = abs (level);
  64079. if (corrected >> 8)
  64080. corrected = 255;
  64081. *line = corrected;
  64082. }
  64083. }
  64084. else
  64085. {
  64086. while (--num > 0)
  64087. {
  64088. line += 2;
  64089. level += *line;
  64090. int corrected = abs (level);
  64091. if (corrected >> 8)
  64092. {
  64093. corrected &= 511;
  64094. if (corrected >> 8)
  64095. corrected = 511 - corrected;
  64096. }
  64097. *line = corrected;
  64098. }
  64099. }
  64100. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  64101. }
  64102. }
  64103. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  64104. {
  64105. if (newNumEdgesPerLine != maxEdgesPerLine)
  64106. {
  64107. maxEdgesPerLine = newNumEdgesPerLine;
  64108. jassert (bounds.getHeight() > 0);
  64109. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  64110. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  64111. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  64112. table.swapWith (newTable);
  64113. lineStrideElements = newLineStrideElements;
  64114. }
  64115. }
  64116. void EdgeTable::optimiseTable() throw()
  64117. {
  64118. int maxLineElements = 0;
  64119. for (int i = bounds.getHeight(); --i >= 0;)
  64120. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  64121. remapTableForNumEdges (maxLineElements);
  64122. }
  64123. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  64124. {
  64125. jassert (y >= 0 && y < bounds.getHeight());
  64126. int* line = table + lineStrideElements * y;
  64127. const int numPoints = line[0];
  64128. int n = numPoints << 1;
  64129. if (n > 0)
  64130. {
  64131. while (n > 0)
  64132. {
  64133. const int cx = line [n - 1];
  64134. if (cx <= x)
  64135. {
  64136. if (cx == x)
  64137. {
  64138. line [n] += winding;
  64139. return;
  64140. }
  64141. break;
  64142. }
  64143. n -= 2;
  64144. }
  64145. if (numPoints >= maxEdgesPerLine)
  64146. {
  64147. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64148. jassert (numPoints < maxEdgesPerLine);
  64149. line = table + lineStrideElements * y;
  64150. }
  64151. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  64152. }
  64153. line [n + 1] = x;
  64154. line [n + 2] = winding;
  64155. line[0]++;
  64156. }
  64157. void EdgeTable::translate (float dx, int dy) throw()
  64158. {
  64159. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  64160. int* lineStart = table;
  64161. const int intDx = (int) (dx * 256.0f);
  64162. for (int i = bounds.getHeight(); --i >= 0;)
  64163. {
  64164. int* line = lineStart;
  64165. lineStart += lineStrideElements;
  64166. int num = *line++;
  64167. while (--num >= 0)
  64168. {
  64169. *line += intDx;
  64170. line += 2;
  64171. }
  64172. }
  64173. }
  64174. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  64175. {
  64176. jassert (y >= 0 && y < bounds.getHeight());
  64177. int* dest = table + lineStrideElements * y;
  64178. if (dest[0] == 0)
  64179. return;
  64180. int otherNumPoints = *otherLine;
  64181. if (otherNumPoints == 0)
  64182. {
  64183. *dest = 0;
  64184. return;
  64185. }
  64186. const int right = bounds.getRight() << 8;
  64187. // optimise for the common case where our line lies entirely within a
  64188. // single pair of points, as happens when clipping to a simple rect.
  64189. if (otherNumPoints == 2 && otherLine[2] >= 255)
  64190. {
  64191. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  64192. return;
  64193. }
  64194. ++otherLine;
  64195. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  64196. int* temp = (int*) alloca (lineSizeBytes);
  64197. memcpy (temp, dest, lineSizeBytes);
  64198. const int* src1 = temp;
  64199. int srcNum1 = *src1++;
  64200. int x1 = *src1++;
  64201. const int* src2 = otherLine;
  64202. int srcNum2 = otherNumPoints;
  64203. int x2 = *src2++;
  64204. int destIndex = 0, destTotal = 0;
  64205. int level1 = 0, level2 = 0;
  64206. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  64207. while (srcNum1 > 0 && srcNum2 > 0)
  64208. {
  64209. int nextX;
  64210. if (x1 < x2)
  64211. {
  64212. nextX = x1;
  64213. level1 = *src1++;
  64214. x1 = *src1++;
  64215. --srcNum1;
  64216. }
  64217. else if (x1 == x2)
  64218. {
  64219. nextX = x1;
  64220. level1 = *src1++;
  64221. level2 = *src2++;
  64222. x1 = *src1++;
  64223. x2 = *src2++;
  64224. --srcNum1;
  64225. --srcNum2;
  64226. }
  64227. else
  64228. {
  64229. nextX = x2;
  64230. level2 = *src2++;
  64231. x2 = *src2++;
  64232. --srcNum2;
  64233. }
  64234. if (nextX > lastX)
  64235. {
  64236. if (nextX >= right)
  64237. break;
  64238. lastX = nextX;
  64239. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64240. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64241. if (nextLevel != lastLevel)
  64242. {
  64243. if (destTotal >= maxEdgesPerLine)
  64244. {
  64245. dest[0] = destTotal;
  64246. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64247. dest = table + lineStrideElements * y;
  64248. }
  64249. ++destTotal;
  64250. lastLevel = nextLevel;
  64251. dest[++destIndex] = nextX;
  64252. dest[++destIndex] = nextLevel;
  64253. }
  64254. }
  64255. }
  64256. if (lastLevel > 0)
  64257. {
  64258. if (destTotal >= maxEdgesPerLine)
  64259. {
  64260. dest[0] = destTotal;
  64261. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64262. dest = table + lineStrideElements * y;
  64263. }
  64264. ++destTotal;
  64265. dest[++destIndex] = right;
  64266. dest[++destIndex] = 0;
  64267. }
  64268. dest[0] = destTotal;
  64269. #if JUCE_DEBUG
  64270. int last = std::numeric_limits<int>::min();
  64271. for (int i = 0; i < dest[0]; ++i)
  64272. {
  64273. jassert (dest[i * 2 + 1] > last);
  64274. last = dest[i * 2 + 1];
  64275. }
  64276. jassert (dest [dest[0] * 2] == 0);
  64277. #endif
  64278. }
  64279. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  64280. {
  64281. int* lastItem = dest + (dest[0] * 2 - 1);
  64282. if (x2 < lastItem[0])
  64283. {
  64284. if (x2 <= dest[1])
  64285. {
  64286. dest[0] = 0;
  64287. return;
  64288. }
  64289. while (x2 < lastItem[-2])
  64290. {
  64291. --(dest[0]);
  64292. lastItem -= 2;
  64293. }
  64294. lastItem[0] = x2;
  64295. lastItem[1] = 0;
  64296. }
  64297. if (x1 > dest[1])
  64298. {
  64299. while (lastItem[0] > x1)
  64300. lastItem -= 2;
  64301. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  64302. if (itemsRemoved > 0)
  64303. {
  64304. dest[0] -= itemsRemoved;
  64305. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64306. }
  64307. dest[1] = x1;
  64308. }
  64309. }
  64310. void EdgeTable::clipToRectangle (const Rectangle<int>& r) throw()
  64311. {
  64312. const Rectangle<int> clipped (r.getIntersection (bounds));
  64313. if (clipped.isEmpty())
  64314. {
  64315. needToCheckEmptinesss = false;
  64316. bounds.setHeight (0);
  64317. }
  64318. else
  64319. {
  64320. const int top = clipped.getY() - bounds.getY();
  64321. const int bottom = clipped.getBottom() - bounds.getY();
  64322. if (bottom < bounds.getHeight())
  64323. bounds.setHeight (bottom);
  64324. if (clipped.getRight() < bounds.getRight())
  64325. bounds.setRight (clipped.getRight());
  64326. for (int i = top; --i >= 0;)
  64327. table [lineStrideElements * i] = 0;
  64328. if (clipped.getX() > bounds.getX())
  64329. {
  64330. const int x1 = clipped.getX() << 8;
  64331. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64332. int* line = table + lineStrideElements * top;
  64333. for (int i = bottom - top; --i >= 0;)
  64334. {
  64335. if (line[0] != 0)
  64336. clipEdgeTableLineToRange (line, x1, x2);
  64337. line += lineStrideElements;
  64338. }
  64339. }
  64340. needToCheckEmptinesss = true;
  64341. }
  64342. }
  64343. void EdgeTable::excludeRectangle (const Rectangle<int>& r) throw()
  64344. {
  64345. const Rectangle<int> clipped (r.getIntersection (bounds));
  64346. if (! clipped.isEmpty())
  64347. {
  64348. const int top = clipped.getY() - bounds.getY();
  64349. const int bottom = clipped.getBottom() - bounds.getY();
  64350. //XXX optimise here by shortening the table if it fills top or bottom
  64351. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  64352. clipped.getX() << 8, 0,
  64353. clipped.getRight() << 8, 255,
  64354. std::numeric_limits<int>::max(), 0 };
  64355. for (int i = top; i < bottom; ++i)
  64356. intersectWithEdgeTableLine (i, rectLine);
  64357. needToCheckEmptinesss = true;
  64358. }
  64359. }
  64360. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64361. {
  64362. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  64363. if (clipped.isEmpty())
  64364. {
  64365. needToCheckEmptinesss = false;
  64366. bounds.setHeight (0);
  64367. }
  64368. else
  64369. {
  64370. const int top = clipped.getY() - bounds.getY();
  64371. const int bottom = clipped.getBottom() - bounds.getY();
  64372. if (bottom < bounds.getHeight())
  64373. bounds.setHeight (bottom);
  64374. if (clipped.getRight() < bounds.getRight())
  64375. bounds.setRight (clipped.getRight());
  64376. int i = 0;
  64377. for (i = top; --i >= 0;)
  64378. table [lineStrideElements * i] = 0;
  64379. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64380. for (i = top; i < bottom; ++i)
  64381. {
  64382. intersectWithEdgeTableLine (i, otherLine);
  64383. otherLine += other.lineStrideElements;
  64384. }
  64385. needToCheckEmptinesss = true;
  64386. }
  64387. }
  64388. void EdgeTable::clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels) throw()
  64389. {
  64390. y -= bounds.getY();
  64391. if (y < 0 || y >= bounds.getHeight())
  64392. return;
  64393. needToCheckEmptinesss = true;
  64394. if (numPixels <= 0)
  64395. {
  64396. table [lineStrideElements * y] = 0;
  64397. return;
  64398. }
  64399. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64400. int destIndex = 0, lastLevel = 0;
  64401. while (--numPixels >= 0)
  64402. {
  64403. const int alpha = *mask;
  64404. mask += maskStride;
  64405. if (alpha != lastLevel)
  64406. {
  64407. tempLine[++destIndex] = (x << 8);
  64408. tempLine[++destIndex] = alpha;
  64409. lastLevel = alpha;
  64410. }
  64411. ++x;
  64412. }
  64413. if (lastLevel > 0)
  64414. {
  64415. tempLine[++destIndex] = (x << 8);
  64416. tempLine[++destIndex] = 0;
  64417. }
  64418. tempLine[0] = destIndex >> 1;
  64419. intersectWithEdgeTableLine (y, tempLine);
  64420. }
  64421. bool EdgeTable::isEmpty() throw()
  64422. {
  64423. if (needToCheckEmptinesss)
  64424. {
  64425. needToCheckEmptinesss = false;
  64426. int* t = table;
  64427. for (int i = bounds.getHeight(); --i >= 0;)
  64428. {
  64429. if (t[0] > 1)
  64430. return false;
  64431. t += lineStrideElements;
  64432. }
  64433. bounds.setHeight (0);
  64434. }
  64435. return bounds.getHeight() == 0;
  64436. }
  64437. END_JUCE_NAMESPACE
  64438. /*** End of inlined file: juce_EdgeTable.cpp ***/
  64439. /*** Start of inlined file: juce_FillType.cpp ***/
  64440. BEGIN_JUCE_NAMESPACE
  64441. FillType::FillType() throw()
  64442. : colour (0xff000000), image (0)
  64443. {
  64444. }
  64445. FillType::FillType (const Colour& colour_) throw()
  64446. : colour (colour_), image (0)
  64447. {
  64448. }
  64449. FillType::FillType (const ColourGradient& gradient_) throw()
  64450. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64451. {
  64452. }
  64453. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64454. : colour (0xff000000), image (&image_), transform (transform_)
  64455. {
  64456. }
  64457. FillType::FillType (const FillType& other) throw()
  64458. : colour (other.colour),
  64459. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64460. image (other.image), transform (other.transform)
  64461. {
  64462. }
  64463. FillType& FillType::operator= (const FillType& other) throw()
  64464. {
  64465. if (this != &other)
  64466. {
  64467. colour = other.colour;
  64468. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64469. image = other.image;
  64470. transform = other.transform;
  64471. }
  64472. return *this;
  64473. }
  64474. FillType::~FillType() throw()
  64475. {
  64476. }
  64477. void FillType::setColour (const Colour& newColour) throw()
  64478. {
  64479. gradient = 0;
  64480. image = 0;
  64481. colour = newColour;
  64482. }
  64483. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64484. {
  64485. if (gradient != 0)
  64486. {
  64487. *gradient = newGradient;
  64488. }
  64489. else
  64490. {
  64491. image = 0;
  64492. gradient = new ColourGradient (newGradient);
  64493. colour = Colours::black;
  64494. }
  64495. }
  64496. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64497. {
  64498. gradient = 0;
  64499. image = &image_;
  64500. transform = transform_;
  64501. colour = Colours::black;
  64502. }
  64503. void FillType::setOpacity (const float newOpacity) throw()
  64504. {
  64505. colour = colour.withAlpha (newOpacity);
  64506. }
  64507. END_JUCE_NAMESPACE
  64508. /*** End of inlined file: juce_FillType.cpp ***/
  64509. /*** Start of inlined file: juce_Graphics.cpp ***/
  64510. BEGIN_JUCE_NAMESPACE
  64511. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64512. template <typename Type>
  64513. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64514. {
  64515. const int maxVal = 0x3fffffff;
  64516. return (int) x >= -maxVal && (int) x <= maxVal
  64517. && (int) y >= -maxVal && (int) y <= maxVal
  64518. && (int) w >= -maxVal && (int) w <= maxVal
  64519. && (int) h >= -maxVal && (int) h <= maxVal;
  64520. }
  64521. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64522. {
  64523. }
  64524. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64525. {
  64526. }
  64527. Graphics::Graphics (Image& imageToDrawOnto) throw()
  64528. : context (imageToDrawOnto.createLowLevelContext()),
  64529. contextToDelete (context),
  64530. saveStatePending (false)
  64531. {
  64532. }
  64533. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64534. : context (internalContext),
  64535. saveStatePending (false)
  64536. {
  64537. }
  64538. Graphics::~Graphics() throw()
  64539. {
  64540. }
  64541. void Graphics::resetToDefaultState() throw()
  64542. {
  64543. saveStateIfPending();
  64544. context->setFill (FillType());
  64545. context->setFont (Font());
  64546. context->setInterpolationQuality (defaultQuality);
  64547. }
  64548. bool Graphics::isVectorDevice() const throw()
  64549. {
  64550. return context->isVectorDevice();
  64551. }
  64552. bool Graphics::reduceClipRegion (const int x, const int y,
  64553. const int w, const int h) throw()
  64554. {
  64555. saveStateIfPending();
  64556. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64557. }
  64558. bool Graphics::reduceClipRegion (const RectangleList& clipRegion) throw()
  64559. {
  64560. saveStateIfPending();
  64561. return context->clipToRectangleList (clipRegion);
  64562. }
  64563. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform) throw()
  64564. {
  64565. saveStateIfPending();
  64566. context->clipToPath (path, transform);
  64567. return ! context->isClipEmpty();
  64568. }
  64569. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform) throw()
  64570. {
  64571. saveStateIfPending();
  64572. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64573. return ! context->isClipEmpty();
  64574. }
  64575. void Graphics::excludeClipRegion (const Rectangle<int>& rectangleToExclude) throw()
  64576. {
  64577. saveStateIfPending();
  64578. context->excludeClipRectangle (rectangleToExclude);
  64579. }
  64580. bool Graphics::isClipEmpty() const throw()
  64581. {
  64582. return context->isClipEmpty();
  64583. }
  64584. const Rectangle<int> Graphics::getClipBounds() const throw()
  64585. {
  64586. return context->getClipBounds();
  64587. }
  64588. void Graphics::saveState() throw()
  64589. {
  64590. saveStateIfPending();
  64591. saveStatePending = true;
  64592. }
  64593. void Graphics::restoreState() throw()
  64594. {
  64595. if (saveStatePending)
  64596. saveStatePending = false;
  64597. else
  64598. context->restoreState();
  64599. }
  64600. void Graphics::saveStateIfPending() throw()
  64601. {
  64602. if (saveStatePending)
  64603. {
  64604. saveStatePending = false;
  64605. context->saveState();
  64606. }
  64607. }
  64608. void Graphics::setOrigin (const int newOriginX,
  64609. const int newOriginY) throw()
  64610. {
  64611. saveStateIfPending();
  64612. context->setOrigin (newOriginX, newOriginY);
  64613. }
  64614. bool Graphics::clipRegionIntersects (const int x, const int y,
  64615. const int w, const int h) const throw()
  64616. {
  64617. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64618. }
  64619. void Graphics::setColour (const Colour& newColour) throw()
  64620. {
  64621. saveStateIfPending();
  64622. context->setFill (FillType (newColour));
  64623. }
  64624. void Graphics::setOpacity (const float newOpacity) throw()
  64625. {
  64626. saveStateIfPending();
  64627. context->setOpacity (newOpacity);
  64628. }
  64629. void Graphics::setGradientFill (const ColourGradient& gradient) throw()
  64630. {
  64631. saveStateIfPending();
  64632. context->setFill (FillType (gradient));
  64633. }
  64634. void Graphics::setTiledImageFill (const Image& imageToUse,
  64635. const int anchorX,
  64636. const int anchorY,
  64637. const float opacity) throw()
  64638. {
  64639. saveStateIfPending();
  64640. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64641. context->setOpacity (opacity);
  64642. }
  64643. void Graphics::setFillType (const FillType& newFill) throw()
  64644. {
  64645. saveStateIfPending();
  64646. context->setFill (newFill);
  64647. }
  64648. void Graphics::setFont (const Font& newFont) throw()
  64649. {
  64650. saveStateIfPending();
  64651. context->setFont (newFont);
  64652. }
  64653. void Graphics::setFont (const float newFontHeight,
  64654. const int newFontStyleFlags) throw()
  64655. {
  64656. saveStateIfPending();
  64657. Font f (context->getFont());
  64658. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  64659. context->setFont (f);
  64660. }
  64661. void Graphics::drawSingleLineText (const String& text,
  64662. const int startX,
  64663. const int baselineY) const throw()
  64664. {
  64665. if (text.isNotEmpty()
  64666. && startX < context->getClipBounds().getRight())
  64667. {
  64668. GlyphArrangement arr;
  64669. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  64670. arr.draw (*this);
  64671. }
  64672. }
  64673. void Graphics::drawTextAsPath (const String& text,
  64674. const AffineTransform& transform) const throw()
  64675. {
  64676. if (text.isNotEmpty())
  64677. {
  64678. GlyphArrangement arr;
  64679. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  64680. arr.draw (*this, transform);
  64681. }
  64682. }
  64683. void Graphics::drawMultiLineText (const String& text,
  64684. const int startX,
  64685. const int baselineY,
  64686. const int maximumLineWidth) const throw()
  64687. {
  64688. if (text.isNotEmpty()
  64689. && startX < context->getClipBounds().getRight())
  64690. {
  64691. GlyphArrangement arr;
  64692. arr.addJustifiedText (context->getFont(), text,
  64693. (float) startX, (float) baselineY, (float) maximumLineWidth,
  64694. Justification::left);
  64695. arr.draw (*this);
  64696. }
  64697. }
  64698. void Graphics::drawText (const String& text,
  64699. const int x,
  64700. const int y,
  64701. const int width,
  64702. const int height,
  64703. const Justification& justificationType,
  64704. const bool useEllipsesIfTooBig) const throw()
  64705. {
  64706. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64707. {
  64708. GlyphArrangement arr;
  64709. arr.addCurtailedLineOfText (context->getFont(), text,
  64710. 0.0f, 0.0f, (float)width,
  64711. useEllipsesIfTooBig);
  64712. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  64713. (float) x, (float) y,
  64714. (float) width, (float) height,
  64715. justificationType);
  64716. arr.draw (*this);
  64717. }
  64718. }
  64719. void Graphics::drawFittedText (const String& text,
  64720. const int x,
  64721. const int y,
  64722. const int width,
  64723. const int height,
  64724. const Justification& justification,
  64725. const int maximumNumberOfLines,
  64726. const float minimumHorizontalScale) const throw()
  64727. {
  64728. if (text.isNotEmpty()
  64729. && width > 0 && height > 0
  64730. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64731. {
  64732. GlyphArrangement arr;
  64733. arr.addFittedText (context->getFont(), text,
  64734. (float) x, (float) y,
  64735. (float) width, (float) height,
  64736. justification,
  64737. maximumNumberOfLines,
  64738. minimumHorizontalScale);
  64739. arr.draw (*this);
  64740. }
  64741. }
  64742. void Graphics::fillRect (int x,
  64743. int y,
  64744. int width,
  64745. int height) const throw()
  64746. {
  64747. // passing in a silly number can cause maths problems in rendering!
  64748. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64749. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64750. }
  64751. void Graphics::fillRect (const Rectangle<int>& r) const throw()
  64752. {
  64753. context->fillRect (r, false);
  64754. }
  64755. void Graphics::fillRect (const float x,
  64756. const float y,
  64757. const float width,
  64758. const float height) const throw()
  64759. {
  64760. // passing in a silly number can cause maths problems in rendering!
  64761. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64762. Path p;
  64763. p.addRectangle (x, y, width, height);
  64764. fillPath (p);
  64765. }
  64766. void Graphics::setPixel (int x, int y) const throw()
  64767. {
  64768. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  64769. }
  64770. void Graphics::fillAll() const throw()
  64771. {
  64772. fillRect (context->getClipBounds());
  64773. }
  64774. void Graphics::fillAll (const Colour& colourToUse) const throw()
  64775. {
  64776. if (! colourToUse.isTransparent())
  64777. {
  64778. const Rectangle<int> clip (context->getClipBounds());
  64779. context->saveState();
  64780. context->setFill (FillType (colourToUse));
  64781. context->fillRect (clip, false);
  64782. context->restoreState();
  64783. }
  64784. }
  64785. void Graphics::fillPath (const Path& path,
  64786. const AffineTransform& transform) const throw()
  64787. {
  64788. if ((! context->isClipEmpty()) && ! path.isEmpty())
  64789. context->fillPath (path, transform);
  64790. }
  64791. void Graphics::strokePath (const Path& path,
  64792. const PathStrokeType& strokeType,
  64793. const AffineTransform& transform) const throw()
  64794. {
  64795. Path stroke;
  64796. strokeType.createStrokedPath (stroke, path, transform);
  64797. fillPath (stroke);
  64798. }
  64799. void Graphics::drawRect (const int x,
  64800. const int y,
  64801. const int width,
  64802. const int height,
  64803. const int lineThickness) const throw()
  64804. {
  64805. // passing in a silly number can cause maths problems in rendering!
  64806. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64807. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  64808. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64809. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64810. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  64811. }
  64812. void Graphics::drawRect (const float x,
  64813. const float y,
  64814. const float width,
  64815. const float height,
  64816. const float lineThickness) const throw()
  64817. {
  64818. // passing in a silly number can cause maths problems in rendering!
  64819. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64820. Path p;
  64821. p.addRectangle (x, y, width, lineThickness);
  64822. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64823. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64824. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  64825. fillPath (p);
  64826. }
  64827. void Graphics::drawRect (const Rectangle<int>& r,
  64828. const int lineThickness) const throw()
  64829. {
  64830. drawRect (r.getX(), r.getY(),
  64831. r.getWidth(), r.getHeight(),
  64832. lineThickness);
  64833. }
  64834. void Graphics::drawBevel (const int x,
  64835. const int y,
  64836. const int width,
  64837. const int height,
  64838. const int bevelThickness,
  64839. const Colour& topLeftColour,
  64840. const Colour& bottomRightColour,
  64841. const bool useGradient,
  64842. const bool sharpEdgeOnOutside) const throw()
  64843. {
  64844. // passing in a silly number can cause maths problems in rendering!
  64845. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64846. if (clipRegionIntersects (x, y, width, height))
  64847. {
  64848. context->saveState();
  64849. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  64850. const float ramp = oldOpacity / bevelThickness;
  64851. for (int i = bevelThickness; --i >= 0;)
  64852. {
  64853. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  64854. : oldOpacity;
  64855. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op)));
  64856. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  64857. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op * 0.75f)));
  64858. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  64859. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op)));
  64860. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  64861. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op * 0.75f)));
  64862. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  64863. }
  64864. context->restoreState();
  64865. }
  64866. }
  64867. void Graphics::fillEllipse (const float x,
  64868. const float y,
  64869. const float width,
  64870. const float height) const throw()
  64871. {
  64872. // passing in a silly number can cause maths problems in rendering!
  64873. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64874. Path p;
  64875. p.addEllipse (x, y, width, height);
  64876. fillPath (p);
  64877. }
  64878. void Graphics::drawEllipse (const float x,
  64879. const float y,
  64880. const float width,
  64881. const float height,
  64882. const float lineThickness) const throw()
  64883. {
  64884. // passing in a silly number can cause maths problems in rendering!
  64885. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64886. Path p;
  64887. p.addEllipse (x, y, width, height);
  64888. strokePath (p, PathStrokeType (lineThickness));
  64889. }
  64890. void Graphics::fillRoundedRectangle (const float x,
  64891. const float y,
  64892. const float width,
  64893. const float height,
  64894. const float cornerSize) const throw()
  64895. {
  64896. // passing in a silly number can cause maths problems in rendering!
  64897. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64898. Path p;
  64899. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64900. fillPath (p);
  64901. }
  64902. void Graphics::fillRoundedRectangle (const Rectangle<int>& r,
  64903. const float cornerSize) const throw()
  64904. {
  64905. fillRoundedRectangle ((float) r.getX(),
  64906. (float) r.getY(),
  64907. (float) r.getWidth(),
  64908. (float) r.getHeight(),
  64909. cornerSize);
  64910. }
  64911. void Graphics::drawRoundedRectangle (const float x,
  64912. const float y,
  64913. const float width,
  64914. const float height,
  64915. const float cornerSize,
  64916. const float lineThickness) const throw()
  64917. {
  64918. // passing in a silly number can cause maths problems in rendering!
  64919. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64920. Path p;
  64921. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64922. strokePath (p, PathStrokeType (lineThickness));
  64923. }
  64924. void Graphics::drawRoundedRectangle (const Rectangle<int>& r,
  64925. const float cornerSize,
  64926. const float lineThickness) const throw()
  64927. {
  64928. drawRoundedRectangle ((float) r.getX(),
  64929. (float) r.getY(),
  64930. (float) r.getWidth(),
  64931. (float) r.getHeight(),
  64932. cornerSize, lineThickness);
  64933. }
  64934. void Graphics::drawArrow (const float startX,
  64935. const float startY,
  64936. const float endX,
  64937. const float endY,
  64938. const float lineThickness,
  64939. const float arrowheadWidth,
  64940. const float arrowheadLength) const throw()
  64941. {
  64942. Path p;
  64943. p.addArrow (startX, startY, endX, endY,
  64944. lineThickness, arrowheadWidth, arrowheadLength);
  64945. fillPath (p);
  64946. }
  64947. void Graphics::fillCheckerBoard (int x, int y,
  64948. int width, int height,
  64949. const int checkWidth,
  64950. const int checkHeight,
  64951. const Colour& colour1,
  64952. const Colour& colour2) const throw()
  64953. {
  64954. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  64955. if (checkWidth > 0 && checkHeight > 0)
  64956. {
  64957. context->saveState();
  64958. if (colour1 == colour2)
  64959. {
  64960. context->setFill (FillType (colour1));
  64961. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64962. }
  64963. else
  64964. {
  64965. const Rectangle<int> clip (context->getClipBounds());
  64966. const int right = jmin (x + width, clip.getRight());
  64967. const int bottom = jmin (y + height, clip.getBottom());
  64968. int cy = 0;
  64969. while (y < bottom)
  64970. {
  64971. int cx = cy;
  64972. for (int xx = x; xx < right; xx += checkWidth)
  64973. {
  64974. context->setFill (FillType (((cx++ & 1) == 0) ? colour1 : colour2));
  64975. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  64976. false);
  64977. }
  64978. ++cy;
  64979. y += checkHeight;
  64980. }
  64981. }
  64982. context->restoreState();
  64983. }
  64984. }
  64985. void Graphics::drawVerticalLine (const int x, float top, float bottom) const throw()
  64986. {
  64987. context->drawVerticalLine (x, top, bottom);
  64988. }
  64989. void Graphics::drawHorizontalLine (const int y, float left, float right) const throw()
  64990. {
  64991. context->drawHorizontalLine (y, left, right);
  64992. }
  64993. void Graphics::drawLine (float x1, float y1, float x2, float y2) const throw()
  64994. {
  64995. context->drawLine (x1, y1, x2, y2);
  64996. }
  64997. void Graphics::drawLine (const float startX,
  64998. const float startY,
  64999. const float endX,
  65000. const float endY,
  65001. const float lineThickness) const throw()
  65002. {
  65003. Path p;
  65004. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  65005. fillPath (p);
  65006. }
  65007. void Graphics::drawLine (const Line& line) const throw()
  65008. {
  65009. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  65010. }
  65011. void Graphics::drawLine (const Line& line,
  65012. const float lineThickness) const throw()
  65013. {
  65014. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  65015. }
  65016. void Graphics::drawDashedLine (const float startX,
  65017. const float startY,
  65018. const float endX,
  65019. const float endY,
  65020. const float* const dashLengths,
  65021. const int numDashLengths,
  65022. const float lineThickness) const throw()
  65023. {
  65024. const double dx = endX - startX;
  65025. const double dy = endY - startY;
  65026. const double totalLen = juce_hypot (dx, dy);
  65027. if (totalLen >= 0.5)
  65028. {
  65029. const double onePixAlpha = 1.0 / totalLen;
  65030. double alpha = 0.0;
  65031. float x = startX;
  65032. float y = startY;
  65033. int n = 0;
  65034. while (alpha < 1.0f)
  65035. {
  65036. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  65037. n = n % numDashLengths;
  65038. const float oldX = x;
  65039. const float oldY = y;
  65040. x = (float) (startX + dx * alpha);
  65041. y = (float) (startY + dy * alpha);
  65042. if ((n & 1) != 0)
  65043. {
  65044. if (lineThickness != 1.0f)
  65045. drawLine (oldX, oldY, x, y, lineThickness);
  65046. else
  65047. drawLine (oldX, oldY, x, y);
  65048. }
  65049. }
  65050. }
  65051. }
  65052. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality) throw()
  65053. {
  65054. saveStateIfPending();
  65055. context->setInterpolationQuality (newQuality);
  65056. }
  65057. void Graphics::drawImageAt (const Image* const imageToDraw,
  65058. const int topLeftX,
  65059. const int topLeftY,
  65060. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65061. {
  65062. if (imageToDraw != 0)
  65063. {
  65064. const int imageW = imageToDraw->getWidth();
  65065. const int imageH = imageToDraw->getHeight();
  65066. drawImage (imageToDraw,
  65067. topLeftX, topLeftY, imageW, imageH,
  65068. 0, 0, imageW, imageH,
  65069. fillAlphaChannelWithCurrentBrush);
  65070. }
  65071. }
  65072. void Graphics::drawImageWithin (const Image* const imageToDraw,
  65073. const int destX,
  65074. const int destY,
  65075. const int destW,
  65076. const int destH,
  65077. const RectanglePlacement& placementWithinTarget,
  65078. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65079. {
  65080. // passing in a silly number can cause maths problems in rendering!
  65081. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  65082. if (imageToDraw != 0)
  65083. {
  65084. const int imageW = imageToDraw->getWidth();
  65085. const int imageH = imageToDraw->getHeight();
  65086. if (imageW > 0 && imageH > 0)
  65087. {
  65088. double newX = 0.0, newY = 0.0;
  65089. double newW = imageW;
  65090. double newH = imageH;
  65091. placementWithinTarget.applyTo (newX, newY, newW, newH,
  65092. destX, destY, destW, destH);
  65093. if (newW > 0 && newH > 0)
  65094. {
  65095. drawImage (imageToDraw,
  65096. roundToInt (newX), roundToInt (newY),
  65097. roundToInt (newW), roundToInt (newH),
  65098. 0, 0, imageW, imageH,
  65099. fillAlphaChannelWithCurrentBrush);
  65100. }
  65101. }
  65102. }
  65103. }
  65104. void Graphics::drawImage (const Image* const imageToDraw,
  65105. int dx, int dy, int dw, int dh,
  65106. int sx, int sy, int sw, int sh,
  65107. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65108. {
  65109. // passing in a silly number can cause maths problems in rendering!
  65110. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  65111. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  65112. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  65113. {
  65114. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  65115. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  65116. .translated ((float) dx, (float) dy),
  65117. fillAlphaChannelWithCurrentBrush);
  65118. }
  65119. }
  65120. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  65121. const Rectangle<int>& imageSubRegion,
  65122. const AffineTransform& transform,
  65123. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65124. {
  65125. if (imageToDraw != 0 && ! context->isClipEmpty())
  65126. {
  65127. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  65128. if (fillAlphaChannelWithCurrentBrush)
  65129. {
  65130. context->saveState();
  65131. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  65132. fillAll();
  65133. context->restoreState();
  65134. }
  65135. else
  65136. {
  65137. context->drawImage (*imageToDraw, srcClip, transform, false);
  65138. }
  65139. }
  65140. }
  65141. END_JUCE_NAMESPACE
  65142. /*** End of inlined file: juce_Graphics.cpp ***/
  65143. /*** Start of inlined file: juce_Justification.cpp ***/
  65144. BEGIN_JUCE_NAMESPACE
  65145. Justification::Justification (const Justification& other) throw()
  65146. : flags (other.flags)
  65147. {
  65148. }
  65149. Justification& Justification::operator= (const Justification& other) throw()
  65150. {
  65151. flags = other.flags;
  65152. return *this;
  65153. }
  65154. int Justification::getOnlyVerticalFlags() const throw()
  65155. {
  65156. return flags & (top | bottom | verticallyCentred);
  65157. }
  65158. int Justification::getOnlyHorizontalFlags() const throw()
  65159. {
  65160. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  65161. }
  65162. void Justification::applyToRectangle (int& x, int& y,
  65163. const int w, const int h,
  65164. const int spaceX, const int spaceY,
  65165. const int spaceW, const int spaceH) const throw()
  65166. {
  65167. if ((flags & horizontallyCentred) != 0)
  65168. {
  65169. x = spaceX + ((spaceW - w) >> 1);
  65170. }
  65171. else if ((flags & right) != 0)
  65172. {
  65173. x = spaceX + spaceW - w;
  65174. }
  65175. else
  65176. {
  65177. x = spaceX;
  65178. }
  65179. if ((flags & verticallyCentred) != 0)
  65180. {
  65181. y = spaceY + ((spaceH - h) >> 1);
  65182. }
  65183. else if ((flags & bottom) != 0)
  65184. {
  65185. y = spaceY + spaceH - h;
  65186. }
  65187. else
  65188. {
  65189. y = spaceY;
  65190. }
  65191. }
  65192. END_JUCE_NAMESPACE
  65193. /*** End of inlined file: juce_Justification.cpp ***/
  65194. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65195. BEGIN_JUCE_NAMESPACE
  65196. // this will throw an assertion if you try to draw something that's not
  65197. // possible in postscript
  65198. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  65199. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  65200. #define notPossibleInPostscriptAssert jassertfalse
  65201. #else
  65202. #define notPossibleInPostscriptAssert
  65203. #endif
  65204. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  65205. const String& documentTitle,
  65206. const int totalWidth_,
  65207. const int totalHeight_)
  65208. : out (resultingPostScript),
  65209. totalWidth (totalWidth_),
  65210. totalHeight (totalHeight_),
  65211. needToClip (true)
  65212. {
  65213. stateStack.add (new SavedState());
  65214. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  65215. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  65216. out << "%!PS-Adobe-3.0 EPSF-3.0"
  65217. "\n%%BoundingBox: 0 0 600 824"
  65218. "\n%%Pages: 0"
  65219. "\n%%Creator: Raw Material Software JUCE"
  65220. "\n%%Title: " << documentTitle <<
  65221. "\n%%CreationDate: none"
  65222. "\n%%LanguageLevel: 2"
  65223. "\n%%EndComments"
  65224. "\n%%BeginProlog"
  65225. "\n%%BeginResource: JRes"
  65226. "\n/bd {bind def} bind def"
  65227. "\n/c {setrgbcolor} bd"
  65228. "\n/m {moveto} bd"
  65229. "\n/l {lineto} bd"
  65230. "\n/rl {rlineto} bd"
  65231. "\n/ct {curveto} bd"
  65232. "\n/cp {closepath} bd"
  65233. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  65234. "\n/doclip {initclip newpath} bd"
  65235. "\n/endclip {clip newpath} bd"
  65236. "\n%%EndResource"
  65237. "\n%%EndProlog"
  65238. "\n%%BeginSetup"
  65239. "\n%%EndSetup"
  65240. "\n%%Page: 1 1"
  65241. "\n%%BeginPageSetup"
  65242. "\n%%EndPageSetup\n\n"
  65243. << "40 800 translate\n"
  65244. << scale << ' ' << scale << " scale\n\n";
  65245. }
  65246. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  65247. {
  65248. }
  65249. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  65250. {
  65251. return true;
  65252. }
  65253. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  65254. {
  65255. if (x != 0 || y != 0)
  65256. {
  65257. stateStack.getLast()->xOffset += x;
  65258. stateStack.getLast()->yOffset += y;
  65259. needToClip = true;
  65260. }
  65261. }
  65262. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  65263. {
  65264. needToClip = true;
  65265. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65266. }
  65267. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  65268. {
  65269. needToClip = true;
  65270. return stateStack.getLast()->clip.clipTo (clipRegion);
  65271. }
  65272. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  65273. {
  65274. needToClip = true;
  65275. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65276. }
  65277. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65278. {
  65279. writeClip();
  65280. Path p (path);
  65281. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65282. writePath (p);
  65283. out << "clip\n";
  65284. }
  65285. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  65286. {
  65287. needToClip = true;
  65288. jassertfalse // xxx
  65289. }
  65290. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  65291. {
  65292. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65293. }
  65294. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65295. {
  65296. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65297. -stateStack.getLast()->yOffset);
  65298. }
  65299. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65300. {
  65301. return stateStack.getLast()->clip.isEmpty();
  65302. }
  65303. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65304. : xOffset (0),
  65305. yOffset (0)
  65306. {
  65307. }
  65308. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65309. {
  65310. }
  65311. void LowLevelGraphicsPostScriptRenderer::saveState()
  65312. {
  65313. stateStack.add (new SavedState (*stateStack.getLast()));
  65314. }
  65315. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65316. {
  65317. jassert (stateStack.size() > 0);
  65318. if (stateStack.size() > 0)
  65319. stateStack.removeLast();
  65320. }
  65321. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65322. {
  65323. if (needToClip)
  65324. {
  65325. needToClip = false;
  65326. out << "doclip ";
  65327. int itemsOnLine = 0;
  65328. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65329. {
  65330. if (++itemsOnLine == 6)
  65331. {
  65332. itemsOnLine = 0;
  65333. out << '\n';
  65334. }
  65335. const Rectangle<int>& r = *i.getRectangle();
  65336. out << r.getX() << ' ' << -r.getY() << ' '
  65337. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65338. }
  65339. out << "endclip\n";
  65340. }
  65341. }
  65342. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65343. {
  65344. Colour c (Colours::white.overlaidWith (colour));
  65345. if (lastColour != c)
  65346. {
  65347. lastColour = c;
  65348. out << String (c.getFloatRed(), 3) << ' '
  65349. << String (c.getFloatGreen(), 3) << ' '
  65350. << String (c.getFloatBlue(), 3) << " c\n";
  65351. }
  65352. }
  65353. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65354. {
  65355. out << String (x, 2) << ' '
  65356. << String (-y, 2) << ' ';
  65357. }
  65358. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65359. {
  65360. out << "newpath ";
  65361. float lastX = 0.0f;
  65362. float lastY = 0.0f;
  65363. int itemsOnLine = 0;
  65364. Path::Iterator i (path);
  65365. while (i.next())
  65366. {
  65367. if (++itemsOnLine == 4)
  65368. {
  65369. itemsOnLine = 0;
  65370. out << '\n';
  65371. }
  65372. switch (i.elementType)
  65373. {
  65374. case Path::Iterator::startNewSubPath:
  65375. writeXY (i.x1, i.y1);
  65376. lastX = i.x1;
  65377. lastY = i.y1;
  65378. out << "m ";
  65379. break;
  65380. case Path::Iterator::lineTo:
  65381. writeXY (i.x1, i.y1);
  65382. lastX = i.x1;
  65383. lastY = i.y1;
  65384. out << "l ";
  65385. break;
  65386. case Path::Iterator::quadraticTo:
  65387. {
  65388. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65389. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65390. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65391. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65392. writeXY (cp1x, cp1y);
  65393. writeXY (cp2x, cp2y);
  65394. writeXY (i.x2, i.y2);
  65395. out << "ct ";
  65396. lastX = i.x2;
  65397. lastY = i.y2;
  65398. }
  65399. break;
  65400. case Path::Iterator::cubicTo:
  65401. writeXY (i.x1, i.y1);
  65402. writeXY (i.x2, i.y2);
  65403. writeXY (i.x3, i.y3);
  65404. out << "ct ";
  65405. lastX = i.x3;
  65406. lastY = i.y3;
  65407. break;
  65408. case Path::Iterator::closePath:
  65409. out << "cp ";
  65410. break;
  65411. default:
  65412. jassertfalse
  65413. break;
  65414. }
  65415. }
  65416. out << '\n';
  65417. }
  65418. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65419. {
  65420. out << "[ "
  65421. << trans.mat00 << ' '
  65422. << trans.mat10 << ' '
  65423. << trans.mat01 << ' '
  65424. << trans.mat11 << ' '
  65425. << trans.mat02 << ' '
  65426. << trans.mat12 << " ] concat ";
  65427. }
  65428. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65429. {
  65430. stateStack.getLast()->fillType = fillType;
  65431. }
  65432. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65433. {
  65434. }
  65435. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65436. {
  65437. }
  65438. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65439. {
  65440. if (stateStack.getLast()->fillType.isColour())
  65441. {
  65442. writeClip();
  65443. writeColour (stateStack.getLast()->fillType.colour);
  65444. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65445. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65446. }
  65447. else
  65448. {
  65449. Path p;
  65450. p.addRectangle (r);
  65451. fillPath (p, AffineTransform::identity);
  65452. }
  65453. }
  65454. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65455. {
  65456. if (stateStack.getLast()->fillType.isColour())
  65457. {
  65458. writeClip();
  65459. Path p (path);
  65460. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65461. (float) stateStack.getLast()->yOffset));
  65462. writePath (p);
  65463. writeColour (stateStack.getLast()->fillType.colour);
  65464. out << "fill\n";
  65465. }
  65466. else if (stateStack.getLast()->fillType.isGradient())
  65467. {
  65468. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65469. // postscript can't do semi-transparent ones.
  65470. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65471. writeClip();
  65472. out << "gsave ";
  65473. {
  65474. Path p (path);
  65475. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65476. writePath (p);
  65477. out << "clip\n";
  65478. }
  65479. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65480. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65481. // time-being, this just fills it with the average colour..
  65482. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65483. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65484. out << "grestore\n";
  65485. }
  65486. }
  65487. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65488. const int sx, const int sy,
  65489. const int maxW, const int maxH) const
  65490. {
  65491. out << "{<\n";
  65492. const int w = jmin (maxW, im.getWidth());
  65493. const int h = jmin (maxH, im.getHeight());
  65494. int charsOnLine = 0;
  65495. const Image::BitmapData srcData (im, 0, 0, w, h);
  65496. Colour pixel;
  65497. for (int y = h; --y >= 0;)
  65498. {
  65499. for (int x = 0; x < w; ++x)
  65500. {
  65501. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65502. if (x >= sx && y >= sy)
  65503. {
  65504. if (im.isARGB())
  65505. {
  65506. PixelARGB p (*(const PixelARGB*) pixelData);
  65507. p.unpremultiply();
  65508. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65509. }
  65510. else if (im.isRGB())
  65511. {
  65512. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65513. }
  65514. else
  65515. {
  65516. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65517. }
  65518. }
  65519. else
  65520. {
  65521. pixel = Colours::transparentWhite;
  65522. }
  65523. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65524. out << String::toHexString (pixelValues, 3, 0);
  65525. charsOnLine += 3;
  65526. if (charsOnLine > 100)
  65527. {
  65528. out << '\n';
  65529. charsOnLine = 0;
  65530. }
  65531. }
  65532. }
  65533. out << "\n>}\n";
  65534. }
  65535. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65536. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65537. {
  65538. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65539. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65540. writeClip();
  65541. out << "gsave ";
  65542. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65543. .scaled (1.0f, -1.0f));
  65544. RectangleList imageClip;
  65545. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65546. imageClip.clipTo (srcClip);
  65547. out << "newpath ";
  65548. int itemsOnLine = 0;
  65549. for (RectangleList::Iterator i (imageClip); i.next();)
  65550. {
  65551. if (++itemsOnLine == 6)
  65552. {
  65553. out << '\n';
  65554. itemsOnLine = 0;
  65555. }
  65556. const Rectangle<int>& r = *i.getRectangle();
  65557. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65558. }
  65559. out << " clip newpath\n";
  65560. out << w << ' ' << h << " scale\n";
  65561. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65562. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65563. out << "false 3 colorimage grestore\n";
  65564. needToClip = true;
  65565. }
  65566. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65567. {
  65568. Path p;
  65569. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65570. fillPath (p, AffineTransform::identity);
  65571. }
  65572. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65573. {
  65574. drawLine (x, top, x, bottom);
  65575. }
  65576. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65577. {
  65578. drawLine (left, y, right, y);
  65579. }
  65580. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65581. {
  65582. stateStack.getLast()->font = newFont;
  65583. }
  65584. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65585. {
  65586. return stateStack.getLast()->font;
  65587. }
  65588. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65589. {
  65590. Path p;
  65591. Font& font = stateStack.getLast()->font;
  65592. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65593. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65594. }
  65595. END_JUCE_NAMESPACE
  65596. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65597. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65598. BEGIN_JUCE_NAMESPACE
  65599. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65600. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65601. #endif
  65602. #if JUCE_MSVC && JUCE_DEBUG
  65603. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65604. #endif
  65605. #if JUCE_MSVC
  65606. #pragma warning (push)
  65607. #pragma warning (disable: 4127) // "expression is constant" warning
  65608. #endif
  65609. template <class PixelType, bool replaceExisting = false>
  65610. class SolidColourEdgeTableRenderer
  65611. {
  65612. public:
  65613. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65614. : data (data_),
  65615. sourceColour (colour)
  65616. {
  65617. if (sizeof (PixelType) == 3)
  65618. {
  65619. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65620. && sourceColour.getGreen() == sourceColour.getBlue();
  65621. filler[0].set (sourceColour);
  65622. filler[1].set (sourceColour);
  65623. filler[2].set (sourceColour);
  65624. filler[3].set (sourceColour);
  65625. }
  65626. }
  65627. forcedinline void setEdgeTableYPos (const int y) throw()
  65628. {
  65629. linePixels = (PixelType*) data.getLinePointer (y);
  65630. }
  65631. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65632. {
  65633. if (replaceExisting)
  65634. linePixels[x].set (sourceColour);
  65635. else
  65636. linePixels[x].blend (sourceColour, alphaLevel);
  65637. }
  65638. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65639. {
  65640. PixelARGB p (sourceColour);
  65641. p.multiplyAlpha (alphaLevel);
  65642. PixelType* dest = linePixels + x;
  65643. if (replaceExisting || p.getAlpha() >= 0xff)
  65644. replaceLine (dest, p, width);
  65645. else
  65646. blendLine (dest, p, width);
  65647. }
  65648. private:
  65649. const Image::BitmapData& data;
  65650. PixelType* linePixels;
  65651. PixelARGB sourceColour;
  65652. PixelRGB filler [4];
  65653. bool areRGBComponentsEqual;
  65654. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const
  65655. {
  65656. do
  65657. {
  65658. dest->blend (colour);
  65659. ++dest;
  65660. } while (--width > 0);
  65661. }
  65662. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  65663. {
  65664. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  65665. {
  65666. memset (dest, colour.getRed(), width * 3);
  65667. }
  65668. else
  65669. {
  65670. if (width >> 5)
  65671. {
  65672. const int* const intFiller = (const int*) filler;
  65673. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  65674. {
  65675. dest->set (colour);
  65676. ++dest;
  65677. --width;
  65678. }
  65679. while (width > 4)
  65680. {
  65681. ((int*) dest) [0] = intFiller[0];
  65682. ((int*) dest) [1] = intFiller[1];
  65683. ((int*) dest) [2] = intFiller[2];
  65684. dest = (PixelRGB*) (((uint8*) dest) + 12);
  65685. width -= 4;
  65686. }
  65687. }
  65688. while (--width >= 0)
  65689. {
  65690. dest->set (colour);
  65691. ++dest;
  65692. }
  65693. }
  65694. }
  65695. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  65696. {
  65697. memset (dest, colour.getAlpha(), width);
  65698. }
  65699. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  65700. {
  65701. do
  65702. {
  65703. dest->set (colour);
  65704. ++dest;
  65705. } while (--width > 0);
  65706. }
  65707. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  65708. SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  65709. };
  65710. class LinearGradientPixelGenerator
  65711. {
  65712. public:
  65713. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  65714. : lookupTable (lookupTable_), numEntries (numEntries_)
  65715. {
  65716. jassert (numEntries_ >= 0);
  65717. float x1 = gradient.x1;
  65718. float y1 = gradient.y1;
  65719. float x2 = gradient.x2;
  65720. float y2 = gradient.y2;
  65721. if (! transform.isIdentity())
  65722. {
  65723. const Line l (x2, y2, x1, y1);
  65724. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  65725. float x3 = p3.getX();
  65726. float y3 = p3.getY();
  65727. transform.transformPoint (x1, y1);
  65728. transform.transformPoint (x2, y2);
  65729. transform.transformPoint (x3, y3);
  65730. const Line l2 (x2, y2, x3, y3);
  65731. const float prop = l2.findNearestPointTo (x1, y1);
  65732. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  65733. x2 = newP2.getX();
  65734. y2 = newP2.getY();
  65735. }
  65736. vertical = fabs (x1 - x2) < 0.001f;
  65737. horizontal = fabs (y1 - y2) < 0.001f;
  65738. if (vertical)
  65739. {
  65740. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  65741. start = roundToInt (y1 * scale);
  65742. }
  65743. else if (horizontal)
  65744. {
  65745. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  65746. start = roundToInt (x1 * scale);
  65747. }
  65748. else
  65749. {
  65750. grad = (y2 - y1) / (double) (x1 - x2);
  65751. yTerm = y1 - x1 / grad;
  65752. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  65753. grad *= scale;
  65754. }
  65755. }
  65756. forcedinline void setY (const int y) throw()
  65757. {
  65758. if (vertical)
  65759. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  65760. else if (! horizontal)
  65761. start = roundToInt ((y - yTerm) * grad);
  65762. }
  65763. inline const PixelARGB getPixel (const int x) const throw()
  65764. {
  65765. return vertical ? linePix
  65766. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  65767. }
  65768. private:
  65769. const PixelARGB* const lookupTable;
  65770. const int numEntries;
  65771. PixelARGB linePix;
  65772. int start, scale;
  65773. double grad, yTerm;
  65774. bool vertical, horizontal;
  65775. enum { numScaleBits = 12 };
  65776. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  65777. LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  65778. };
  65779. class RadialGradientPixelGenerator
  65780. {
  65781. public:
  65782. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  65783. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65784. : lookupTable (lookupTable_),
  65785. numEntries (numEntries_),
  65786. gx1 (gradient.x1),
  65787. gy1 (gradient.y1)
  65788. {
  65789. jassert (numEntries_ >= 0);
  65790. const float gdx = gradient.x1 - gradient.x2;
  65791. const float gdy = gradient.y1 - gradient.y2;
  65792. maxDist = gdx * gdx + gdy * gdy;
  65793. invScale = numEntries / sqrt (maxDist);
  65794. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  65795. }
  65796. forcedinline void setY (const int y) throw()
  65797. {
  65798. dy = y - gy1;
  65799. dy *= dy;
  65800. }
  65801. inline const PixelARGB getPixel (const int px) const throw()
  65802. {
  65803. double x = px - gx1;
  65804. x *= x;
  65805. x += dy;
  65806. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  65807. }
  65808. protected:
  65809. const PixelARGB* const lookupTable;
  65810. const int numEntries;
  65811. const double gx1, gy1;
  65812. double maxDist, invScale, dy;
  65813. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  65814. RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  65815. };
  65816. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  65817. {
  65818. public:
  65819. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  65820. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65821. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  65822. inverseTransform (transform.inverted())
  65823. {
  65824. tM10 = inverseTransform.mat10;
  65825. tM00 = inverseTransform.mat00;
  65826. }
  65827. forcedinline void setY (const int y) throw()
  65828. {
  65829. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  65830. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  65831. }
  65832. inline const PixelARGB getPixel (const int px) const throw()
  65833. {
  65834. double x = px;
  65835. const double y = tM10 * x + lineYM11;
  65836. x = tM00 * x + lineYM01;
  65837. x *= x;
  65838. x += y * y;
  65839. if (x >= maxDist)
  65840. return lookupTable [numEntries];
  65841. else
  65842. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  65843. }
  65844. private:
  65845. double tM10, tM00, lineYM01, lineYM11;
  65846. const AffineTransform inverseTransform;
  65847. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  65848. TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  65849. };
  65850. template <class PixelType, class GradientType>
  65851. class GradientEdgeTableRenderer : public GradientType
  65852. {
  65853. public:
  65854. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  65855. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65856. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  65857. destData (destData_)
  65858. {
  65859. }
  65860. forcedinline void setEdgeTableYPos (const int y) throw()
  65861. {
  65862. linePixels = (PixelType*) destData.getLinePointer (y);
  65863. GradientType::setY (y);
  65864. }
  65865. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65866. {
  65867. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  65868. }
  65869. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  65870. {
  65871. PixelType* dest = linePixels + x;
  65872. if (alphaLevel < 0xff)
  65873. {
  65874. do
  65875. {
  65876. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  65877. } while (--width > 0);
  65878. }
  65879. else
  65880. {
  65881. do
  65882. {
  65883. (dest++)->blend (GradientType::getPixel (x++));
  65884. } while (--width > 0);
  65885. }
  65886. }
  65887. private:
  65888. const Image::BitmapData& destData;
  65889. PixelType* linePixels;
  65890. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  65891. GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  65892. };
  65893. static forcedinline int safeModulo (int n, const int divisor) throw()
  65894. {
  65895. jassert (divisor > 0);
  65896. n %= divisor;
  65897. return (n < 0) ? (n + divisor) : n;
  65898. }
  65899. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65900. class ImageFillEdgeTableRenderer
  65901. {
  65902. public:
  65903. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65904. const Image::BitmapData& srcData_,
  65905. const int extraAlpha_,
  65906. const int x, const int y) throw()
  65907. : destData (destData_),
  65908. srcData (srcData_),
  65909. extraAlpha (extraAlpha_ + 1),
  65910. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  65911. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  65912. {
  65913. }
  65914. forcedinline void setEdgeTableYPos (int y) throw()
  65915. {
  65916. linePixels = (DestPixelType*) destData.getLinePointer (y);
  65917. y -= yOffset;
  65918. if (repeatPattern)
  65919. {
  65920. jassert (y >= 0);
  65921. y %= srcData.height;
  65922. }
  65923. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  65924. }
  65925. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  65926. {
  65927. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65928. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  65929. }
  65930. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  65931. {
  65932. DestPixelType* dest = linePixels + x;
  65933. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65934. x -= xOffset;
  65935. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  65936. if (alphaLevel < 0xfe)
  65937. {
  65938. do
  65939. {
  65940. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  65941. } while (--width > 0);
  65942. }
  65943. else
  65944. {
  65945. if (repeatPattern)
  65946. {
  65947. do
  65948. {
  65949. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  65950. } while (--width > 0);
  65951. }
  65952. else
  65953. {
  65954. copyRow (dest, sourceLineStart + x, width);
  65955. }
  65956. }
  65957. }
  65958. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  65959. {
  65960. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  65961. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  65962. uint8* mask = (uint8*) (s + x - xOffset);
  65963. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  65964. mask += PixelARGB::indexA;
  65965. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  65966. }
  65967. private:
  65968. const Image::BitmapData& destData;
  65969. const Image::BitmapData& srcData;
  65970. const int extraAlpha, xOffset, yOffset;
  65971. DestPixelType* linePixels;
  65972. SrcPixelType* sourceLineStart;
  65973. template <class PixelType1, class PixelType2>
  65974. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  65975. {
  65976. do
  65977. {
  65978. dest++ ->blend (*src++);
  65979. } while (--width > 0);
  65980. }
  65981. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  65982. {
  65983. memcpy (dest, src, width * sizeof (PixelRGB));
  65984. }
  65985. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  65986. ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  65987. };
  65988. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65989. class TransformedImageFillEdgeTableRenderer
  65990. {
  65991. public:
  65992. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65993. const Image::BitmapData& srcData_,
  65994. const AffineTransform& transform,
  65995. const int extraAlpha_,
  65996. const bool betterQuality_) throw()
  65997. : interpolator (transform),
  65998. destData (destData_),
  65999. srcData (srcData_),
  66000. extraAlpha (extraAlpha_ + 1),
  66001. betterQuality (betterQuality_),
  66002. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  66003. pixelOffsetInt (betterQuality_ ? -128 : 0),
  66004. maxX (srcData_.width - 1),
  66005. maxY (srcData_.height - 1),
  66006. scratchSize (2048)
  66007. {
  66008. scratchBuffer.malloc (scratchSize);
  66009. }
  66010. ~TransformedImageFillEdgeTableRenderer() throw()
  66011. {
  66012. }
  66013. forcedinline void setEdgeTableYPos (const int newY) throw()
  66014. {
  66015. y = newY;
  66016. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  66017. }
  66018. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  66019. {
  66020. alphaLevel *= extraAlpha;
  66021. alphaLevel >>= 8;
  66022. SrcPixelType p;
  66023. generate (&p, x, 1);
  66024. linePixels[x].blend (p, alphaLevel);
  66025. }
  66026. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  66027. {
  66028. if (width > scratchSize)
  66029. {
  66030. scratchSize = width;
  66031. scratchBuffer.malloc (scratchSize);
  66032. }
  66033. SrcPixelType* span = scratchBuffer;
  66034. generate (span, x, width);
  66035. DestPixelType* dest = linePixels + x;
  66036. alphaLevel *= extraAlpha;
  66037. alphaLevel >>= 8;
  66038. if (alphaLevel < 0xfe)
  66039. {
  66040. do
  66041. {
  66042. dest++ ->blend (*span++, alphaLevel);
  66043. } while (--width > 0);
  66044. }
  66045. else
  66046. {
  66047. do
  66048. {
  66049. dest++ ->blend (*span++);
  66050. } while (--width > 0);
  66051. }
  66052. }
  66053. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  66054. {
  66055. if (width > scratchSize)
  66056. {
  66057. scratchSize = width;
  66058. scratchBuffer.malloc (scratchSize);
  66059. }
  66060. y = y_;
  66061. generate (scratchBuffer, x, width);
  66062. const uint8* mask = reinterpret_cast <uint8*> (scratchBuffer.getData());
  66063. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66064. mask += PixelARGB::indexA;
  66065. et.clipLineToMask (x, y_, mask, sizeof (SrcPixelType), width);
  66066. }
  66067. private:
  66068. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  66069. {
  66070. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66071. do
  66072. {
  66073. int hiResX, hiResY;
  66074. this->interpolator.next (hiResX, hiResY);
  66075. hiResX += pixelOffsetInt;
  66076. hiResY += pixelOffsetInt;
  66077. int loResX = hiResX >> 8;
  66078. int loResY = hiResY >> 8;
  66079. if (repeatPattern)
  66080. {
  66081. loResX = safeModulo (loResX, srcData.width);
  66082. loResY = safeModulo (loResY, srcData.height);
  66083. }
  66084. if (betterQuality
  66085. && ((unsigned int) loResX) < (unsigned int) maxX
  66086. && ((unsigned int) loResY) < (unsigned int) maxY)
  66087. {
  66088. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  66089. hiResX &= 255;
  66090. hiResY &= 255;
  66091. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66092. uint32 weight = (256 - hiResX) * (256 - hiResY);
  66093. c[0] += weight * src[0];
  66094. c[1] += weight * src[1];
  66095. c[2] += weight * src[2];
  66096. c[3] += weight * src[3];
  66097. weight = hiResX * (256 - hiResY);
  66098. c[0] += weight * src[4];
  66099. c[1] += weight * src[5];
  66100. c[2] += weight * src[6];
  66101. c[3] += weight * src[7];
  66102. src += this->srcData.lineStride;
  66103. weight = (256 - hiResX) * hiResY;
  66104. c[0] += weight * src[0];
  66105. c[1] += weight * src[1];
  66106. c[2] += weight * src[2];
  66107. c[3] += weight * src[3];
  66108. weight = hiResX * hiResY;
  66109. c[0] += weight * src[4];
  66110. c[1] += weight * src[5];
  66111. c[2] += weight * src[6];
  66112. c[3] += weight * src[7];
  66113. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  66114. (uint8) (c[PixelARGB::indexR] >> 16),
  66115. (uint8) (c[PixelARGB::indexG] >> 16),
  66116. (uint8) (c[PixelARGB::indexB] >> 16));
  66117. }
  66118. else
  66119. {
  66120. if (! repeatPattern)
  66121. {
  66122. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66123. if (loResX < 0) loResX = 0;
  66124. if (loResY < 0) loResY = 0;
  66125. if (loResX > maxX) loResX = maxX;
  66126. if (loResY > maxY) loResY = maxY;
  66127. }
  66128. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  66129. }
  66130. ++dest;
  66131. } while (--numPixels > 0);
  66132. }
  66133. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  66134. {
  66135. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66136. do
  66137. {
  66138. int hiResX, hiResY;
  66139. this->interpolator.next (hiResX, hiResY);
  66140. hiResX += pixelOffsetInt;
  66141. hiResY += pixelOffsetInt;
  66142. int loResX = hiResX >> 8;
  66143. int loResY = hiResY >> 8;
  66144. if (repeatPattern)
  66145. {
  66146. loResX = safeModulo (loResX, srcData.width);
  66147. loResY = safeModulo (loResY, srcData.height);
  66148. }
  66149. if (betterQuality
  66150. && ((unsigned int) loResX) < (unsigned int) maxX
  66151. && ((unsigned int) loResY) < (unsigned int) maxY)
  66152. {
  66153. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  66154. hiResX &= 255;
  66155. hiResY &= 255;
  66156. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66157. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  66158. c[0] += weight * src[0];
  66159. c[1] += weight * src[1];
  66160. c[2] += weight * src[2];
  66161. weight = hiResX * (256 - hiResY);
  66162. c[0] += weight * src[3];
  66163. c[1] += weight * src[4];
  66164. c[2] += weight * src[5];
  66165. src += this->srcData.lineStride;
  66166. weight = (256 - hiResX) * hiResY;
  66167. c[0] += weight * src[0];
  66168. c[1] += weight * src[1];
  66169. c[2] += weight * src[2];
  66170. weight = hiResX * hiResY;
  66171. c[0] += weight * src[3];
  66172. c[1] += weight * src[4];
  66173. c[2] += weight * src[5];
  66174. dest->setARGB ((uint8) 255,
  66175. (uint8) (c[PixelRGB::indexR] >> 16),
  66176. (uint8) (c[PixelRGB::indexG] >> 16),
  66177. (uint8) (c[PixelRGB::indexB] >> 16));
  66178. }
  66179. else
  66180. {
  66181. if (! repeatPattern)
  66182. {
  66183. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66184. if (loResX < 0) loResX = 0;
  66185. if (loResY < 0) loResY = 0;
  66186. if (loResX > maxX) loResX = maxX;
  66187. if (loResY > maxY) loResY = maxY;
  66188. }
  66189. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  66190. }
  66191. ++dest;
  66192. } while (--numPixels > 0);
  66193. }
  66194. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  66195. {
  66196. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66197. do
  66198. {
  66199. int hiResX, hiResY;
  66200. this->interpolator.next (hiResX, hiResY);
  66201. hiResX += pixelOffsetInt;
  66202. hiResY += pixelOffsetInt;
  66203. int loResX = hiResX >> 8;
  66204. int loResY = hiResY >> 8;
  66205. if (repeatPattern)
  66206. {
  66207. loResX = safeModulo (loResX, srcData.width);
  66208. loResY = safeModulo (loResY, srcData.height);
  66209. }
  66210. if (betterQuality
  66211. && ((unsigned int) loResX) < (unsigned int) maxX
  66212. && ((unsigned int) loResY) < (unsigned int) maxY)
  66213. {
  66214. hiResX &= 255;
  66215. hiResY &= 255;
  66216. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66217. uint32 c = 256 * 128;
  66218. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  66219. c += src[1] * (hiResX * (256 - hiResY));
  66220. src += this->srcData.lineStride;
  66221. c += src[0] * ((256 - hiResX) * hiResY);
  66222. c += src[1] * (hiResX * hiResY);
  66223. *((uint8*) dest) = (uint8) c;
  66224. }
  66225. else
  66226. {
  66227. if (! repeatPattern)
  66228. {
  66229. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66230. if (loResX < 0) loResX = 0;
  66231. if (loResY < 0) loResY = 0;
  66232. if (loResX > maxX) loResX = maxX;
  66233. if (loResY > maxY) loResY = maxY;
  66234. }
  66235. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  66236. }
  66237. ++dest;
  66238. } while (--numPixels > 0);
  66239. }
  66240. class TransformedImageSpanInterpolator
  66241. {
  66242. public:
  66243. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  66244. : inverseTransform (transform.inverted())
  66245. {}
  66246. void setStartOfLine (float x, float y, const int numPixels) throw()
  66247. {
  66248. float x1 = x, y1 = y;
  66249. inverseTransform.transformPoint (x1, y1);
  66250. x += numPixels;
  66251. inverseTransform.transformPoint (x, y);
  66252. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  66253. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  66254. }
  66255. void next (int& x, int& y) throw()
  66256. {
  66257. x = xBresenham.n;
  66258. xBresenham.stepToNext();
  66259. y = yBresenham.n;
  66260. yBresenham.stepToNext();
  66261. }
  66262. private:
  66263. class BresenhamInterpolator
  66264. {
  66265. public:
  66266. BresenhamInterpolator() throw() {}
  66267. void set (const int n1, const int n2, const int numSteps_) throw()
  66268. {
  66269. numSteps = jmax (1, numSteps_);
  66270. step = (n2 - n1) / numSteps;
  66271. remainder = modulo = (n2 - n1) % numSteps;
  66272. n = n1;
  66273. if (modulo <= 0)
  66274. {
  66275. modulo += numSteps;
  66276. remainder += numSteps;
  66277. --step;
  66278. }
  66279. modulo -= numSteps;
  66280. }
  66281. forcedinline void stepToNext() throw()
  66282. {
  66283. modulo += remainder;
  66284. n += step;
  66285. if (modulo > 0)
  66286. {
  66287. modulo -= numSteps;
  66288. ++n;
  66289. }
  66290. }
  66291. int n;
  66292. private:
  66293. int numSteps, step, modulo, remainder;
  66294. };
  66295. const AffineTransform inverseTransform;
  66296. BresenhamInterpolator xBresenham, yBresenham;
  66297. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66298. TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66299. };
  66300. TransformedImageSpanInterpolator interpolator;
  66301. const Image::BitmapData& destData;
  66302. const Image::BitmapData& srcData;
  66303. const int extraAlpha;
  66304. const bool betterQuality;
  66305. const float pixelOffset;
  66306. const int pixelOffsetInt, maxX, maxY;
  66307. int y;
  66308. DestPixelType* linePixels;
  66309. HeapBlock <SrcPixelType> scratchBuffer;
  66310. int scratchSize;
  66311. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66312. TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66313. };
  66314. class LLGCSavedState
  66315. {
  66316. public:
  66317. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  66318. const Font& font_, const FillType& fillType_,
  66319. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66320. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66321. xOffset (xOffset_), yOffset (yOffset_),
  66322. font (font_), fillType (fillType_),
  66323. interpolationQuality (interpolationQuality_)
  66324. {
  66325. }
  66326. LLGCSavedState (const LLGCSavedState& other) throw()
  66327. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66328. yOffset (other.yOffset), font (other.font),
  66329. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66330. {
  66331. }
  66332. ~LLGCSavedState() throw()
  66333. {
  66334. }
  66335. bool clipToRectangle (const Rectangle<int>& r) throw()
  66336. {
  66337. dupeEdgeTableIfMultiplyReferenced();
  66338. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66339. return ! edgeTable->edgeTable.isEmpty();
  66340. }
  66341. bool clipToRectangleList (const RectangleList& r) throw()
  66342. {
  66343. dupeEdgeTableIfMultiplyReferenced();
  66344. RectangleList offsetList (r);
  66345. offsetList.offsetAll (xOffset, yOffset);
  66346. EdgeTable e2 (offsetList);
  66347. edgeTable->edgeTable.clipToEdgeTable (e2);
  66348. return ! edgeTable->edgeTable.isEmpty();
  66349. }
  66350. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  66351. {
  66352. dupeEdgeTableIfMultiplyReferenced();
  66353. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66354. return ! edgeTable->edgeTable.isEmpty();
  66355. }
  66356. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66357. {
  66358. dupeEdgeTableIfMultiplyReferenced();
  66359. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66360. edgeTable->edgeTable.clipToEdgeTable (et);
  66361. }
  66362. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66363. {
  66364. et.clipToEdgeTable (edgeTable->edgeTable);
  66365. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66366. if (fillType.isGradient())
  66367. {
  66368. jassert (! replaceContents); // that option is just for solid colours
  66369. ColourGradient g2 (*(fillType.gradient));
  66370. g2.multiplyOpacity (fillType.getOpacity());
  66371. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66372. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66373. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66374. const bool isIdentity = transform.isOnlyTranslation();
  66375. if (isIdentity)
  66376. {
  66377. // If our translation doesn't involve any distortion, we can speed it up..
  66378. transform.transformPoint (g2.x1, g2.y1);
  66379. transform.transformPoint (g2.x2, g2.y2);
  66380. transform = AffineTransform::identity;
  66381. }
  66382. HeapBlock <PixelARGB> lookupTable;
  66383. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66384. jassert (numLookupEntries > 0);
  66385. switch (image.getFormat())
  66386. {
  66387. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66388. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66389. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66390. }
  66391. }
  66392. else if (fillType.isTiledImage())
  66393. {
  66394. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66395. }
  66396. else
  66397. {
  66398. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66399. switch (image.getFormat())
  66400. {
  66401. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66402. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66403. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66404. }
  66405. }
  66406. }
  66407. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66408. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66409. {
  66410. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66411. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66412. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66413. const int alpha = fillType.colour.getAlpha();
  66414. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66415. if (transform.isOnlyTranslation())
  66416. {
  66417. // If our translation doesn't involve any distortion, just use a simple blit..
  66418. int tx = (int) (transform.getTranslationX() * 256.0f);
  66419. int ty = (int) (transform.getTranslationY() * 256.0f);
  66420. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66421. {
  66422. tx = ((tx + 128) >> 8);
  66423. ty = ((ty + 128) >> 8);
  66424. if (tiledFillClipRegion != 0)
  66425. {
  66426. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66427. }
  66428. else
  66429. {
  66430. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66431. et.clipToEdgeTable (edgeTable->edgeTable);
  66432. if (! et.isEmpty())
  66433. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66434. }
  66435. return;
  66436. }
  66437. }
  66438. if (transform.isSingularity())
  66439. return;
  66440. if (tiledFillClipRegion != 0)
  66441. {
  66442. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66443. }
  66444. else
  66445. {
  66446. Path p;
  66447. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66448. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66449. et.clipToEdgeTable (edgeTable->edgeTable);
  66450. if (! et.isEmpty())
  66451. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66452. }
  66453. }
  66454. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66455. {
  66456. if (! image.hasAlphaChannel())
  66457. {
  66458. Path p;
  66459. p.addRectangle (srcClip);
  66460. clipToPath (p, t);
  66461. return;
  66462. }
  66463. dupeEdgeTableIfMultiplyReferenced();
  66464. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66465. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66466. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66467. EdgeTable& et = edgeTable->edgeTable;
  66468. if (transform.isOnlyTranslation())
  66469. {
  66470. // If our translation doesn't involve any distortion, just use a simple blit..
  66471. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66472. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66473. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66474. {
  66475. const int imageX = ((tx + 128) >> 8);
  66476. const int imageY = ((ty + 128) >> 8);
  66477. if (image.getFormat() == Image::ARGB)
  66478. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66479. else
  66480. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66481. return;
  66482. }
  66483. }
  66484. if (transform.isSingularity())
  66485. {
  66486. et.clipToRectangle (Rectangle<int>());
  66487. return;
  66488. }
  66489. {
  66490. Path p;
  66491. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66492. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66493. et.clipToEdgeTable (et2);
  66494. }
  66495. if (! et.isEmpty())
  66496. {
  66497. if (image.getFormat() == Image::ARGB)
  66498. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66499. else
  66500. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66501. }
  66502. }
  66503. template <class SrcPixelType>
  66504. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66505. {
  66506. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66507. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66508. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66509. et.getMaximumBounds().getWidth());
  66510. }
  66511. template <class SrcPixelType>
  66512. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66513. {
  66514. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66515. et.clipToRectangle (r);
  66516. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66517. for (int y = 0; y < r.getHeight(); ++y)
  66518. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66519. }
  66520. class EdgeTableHolder : public ReferenceCountedObject
  66521. {
  66522. public:
  66523. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66524. EdgeTable edgeTable;
  66525. };
  66526. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66527. int xOffset, yOffset;
  66528. Font font;
  66529. FillType fillType;
  66530. Graphics::ResamplingQuality interpolationQuality;
  66531. private:
  66532. LLGCSavedState& operator= (const LLGCSavedState&);
  66533. void dupeEdgeTableIfMultiplyReferenced() throw()
  66534. {
  66535. if (edgeTable->getReferenceCount() > 1)
  66536. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66537. }
  66538. template <class DestPixelType>
  66539. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66540. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66541. {
  66542. jassert (destData.pixelStride == sizeof (DestPixelType));
  66543. if (g.isRadial)
  66544. {
  66545. if (isIdentity)
  66546. {
  66547. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66548. et.iterate (renderer);
  66549. }
  66550. else
  66551. {
  66552. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66553. et.iterate (renderer);
  66554. }
  66555. }
  66556. else
  66557. {
  66558. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66559. et.iterate (renderer);
  66560. }
  66561. }
  66562. template <class DestPixelType>
  66563. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66564. {
  66565. jassert (destData.pixelStride == sizeof (DestPixelType));
  66566. if (replaceContents)
  66567. {
  66568. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66569. et.iterate (r);
  66570. }
  66571. else
  66572. {
  66573. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66574. et.iterate (r);
  66575. }
  66576. }
  66577. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66578. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66579. {
  66580. switch (destImage.getFormat())
  66581. {
  66582. case Image::ARGB:
  66583. switch (srcImage.getFormat())
  66584. {
  66585. case Image::ARGB:
  66586. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66587. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66588. break;
  66589. case Image::RGB:
  66590. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66591. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66592. break;
  66593. default:
  66594. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66595. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66596. break;
  66597. }
  66598. break;
  66599. case Image::RGB:
  66600. switch (srcImage.getFormat())
  66601. {
  66602. case Image::ARGB:
  66603. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66604. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66605. break;
  66606. case Image::RGB:
  66607. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66608. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66609. break;
  66610. default:
  66611. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66612. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66613. break;
  66614. }
  66615. break;
  66616. default:
  66617. switch (srcImage.getFormat())
  66618. {
  66619. case Image::ARGB:
  66620. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66621. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66622. break;
  66623. case Image::RGB:
  66624. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66625. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66626. break;
  66627. default:
  66628. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66629. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66630. break;
  66631. }
  66632. break;
  66633. }
  66634. }
  66635. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66636. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66637. {
  66638. switch (destImage.getFormat())
  66639. {
  66640. case Image::ARGB:
  66641. switch (srcImage.getFormat())
  66642. {
  66643. case Image::ARGB:
  66644. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66645. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66646. break;
  66647. case Image::RGB:
  66648. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66649. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66650. break;
  66651. default:
  66652. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66653. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66654. break;
  66655. }
  66656. break;
  66657. case Image::RGB:
  66658. switch (srcImage.getFormat())
  66659. {
  66660. case Image::ARGB:
  66661. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66662. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66663. break;
  66664. case Image::RGB:
  66665. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66666. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66667. break;
  66668. default:
  66669. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66670. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66671. break;
  66672. }
  66673. break;
  66674. default:
  66675. switch (srcImage.getFormat())
  66676. {
  66677. case Image::ARGB:
  66678. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66679. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66680. break;
  66681. case Image::RGB:
  66682. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66683. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66684. break;
  66685. default:
  66686. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66687. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66688. break;
  66689. }
  66690. break;
  66691. }
  66692. }
  66693. };
  66694. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  66695. : image (image_)
  66696. {
  66697. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  66698. FillType(), Graphics::mediumResamplingQuality);
  66699. }
  66700. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  66701. {
  66702. }
  66703. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  66704. {
  66705. return false;
  66706. }
  66707. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  66708. {
  66709. currentState->xOffset += x;
  66710. currentState->yOffset += y;
  66711. }
  66712. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  66713. {
  66714. return currentState->clipToRectangle (r);
  66715. }
  66716. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  66717. {
  66718. return currentState->clipToRectangleList (clipRegion);
  66719. }
  66720. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  66721. {
  66722. currentState->excludeClipRectangle (r);
  66723. }
  66724. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  66725. {
  66726. currentState->clipToPath (path, transform);
  66727. }
  66728. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  66729. {
  66730. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  66731. }
  66732. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  66733. {
  66734. return currentState->edgeTable->edgeTable.getMaximumBounds()
  66735. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  66736. }
  66737. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  66738. {
  66739. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  66740. }
  66741. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  66742. {
  66743. return currentState->edgeTable->edgeTable.isEmpty();
  66744. }
  66745. void LowLevelGraphicsSoftwareRenderer::saveState()
  66746. {
  66747. stateStack.add (new LLGCSavedState (*currentState));
  66748. }
  66749. void LowLevelGraphicsSoftwareRenderer::restoreState()
  66750. {
  66751. LLGCSavedState* const top = stateStack.getLast();
  66752. if (top != 0)
  66753. {
  66754. currentState = top;
  66755. stateStack.removeLast (1, false);
  66756. }
  66757. else
  66758. {
  66759. jassertfalse // trying to pop with an empty stack!
  66760. }
  66761. }
  66762. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  66763. {
  66764. currentState->fillType = fillType;
  66765. }
  66766. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  66767. {
  66768. currentState->fillType.setOpacity (newOpacity);
  66769. }
  66770. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  66771. {
  66772. currentState->interpolationQuality = quality;
  66773. }
  66774. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  66775. {
  66776. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  66777. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  66778. if (! clipped.isEmpty())
  66779. {
  66780. EdgeTable et (clipped);
  66781. currentState->fillEdgeTable (image, et, replaceExistingContents);
  66782. }
  66783. }
  66784. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  66785. {
  66786. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  66787. path, transform.translated ((float) currentState->xOffset,
  66788. (float) currentState->yOffset));
  66789. currentState->fillEdgeTable (image, et);
  66790. }
  66791. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  66792. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  66793. {
  66794. jassert (sourceImage.getBounds().contains (srcClip));
  66795. currentState->renderImage (image, sourceImage, srcClip, transform,
  66796. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  66797. }
  66798. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  66799. {
  66800. Path p;
  66801. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  66802. fillPath (p, AffineTransform::identity);
  66803. }
  66804. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  66805. {
  66806. if (bottom > top)
  66807. {
  66808. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  66809. currentState->fillEdgeTable (image, et);
  66810. }
  66811. }
  66812. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  66813. {
  66814. if (right > left)
  66815. {
  66816. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  66817. (float) (right - left), 1.0f);
  66818. currentState->fillEdgeTable (image, et);
  66819. }
  66820. }
  66821. class GlyphCache : private DeletedAtShutdown
  66822. {
  66823. public:
  66824. GlyphCache() throw()
  66825. : accessCounter (0), hits (0), misses (0)
  66826. {
  66827. for (int i = 120; --i >= 0;)
  66828. glyphs.add (new CachedGlyph());
  66829. }
  66830. ~GlyphCache() throw()
  66831. {
  66832. clearSingletonInstance();
  66833. }
  66834. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  66835. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  66836. {
  66837. ++accessCounter;
  66838. int oldestCounter = std::numeric_limits<int>::max();
  66839. CachedGlyph* oldest = 0;
  66840. for (int i = glyphs.size(); --i >= 0;)
  66841. {
  66842. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  66843. if (glyph->glyph == glyphNumber && glyph->font == font)
  66844. {
  66845. ++hits;
  66846. glyph->lastAccessCount = accessCounter;
  66847. glyph->draw (state, image, x, y);
  66848. return;
  66849. }
  66850. if (glyph->lastAccessCount <= oldestCounter)
  66851. {
  66852. oldestCounter = glyph->lastAccessCount;
  66853. oldest = glyph;
  66854. }
  66855. }
  66856. if (hits + ++misses > (glyphs.size() << 4))
  66857. {
  66858. if (misses * 2 > hits)
  66859. {
  66860. for (int i = 32; --i >= 0;)
  66861. glyphs.add (new CachedGlyph());
  66862. }
  66863. hits = misses = 0;
  66864. oldest = glyphs.getLast();
  66865. }
  66866. jassert (oldest != 0);
  66867. oldest->lastAccessCount = accessCounter;
  66868. oldest->generate (font, glyphNumber);
  66869. oldest->draw (state, image, x, y);
  66870. }
  66871. class CachedGlyph
  66872. {
  66873. public:
  66874. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  66875. ~CachedGlyph() {}
  66876. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  66877. {
  66878. if (edgeTable != 0)
  66879. {
  66880. EdgeTable et (*edgeTable);
  66881. et.translate (x, roundToInt (y));
  66882. state.fillEdgeTable (image, et, false);
  66883. }
  66884. }
  66885. void generate (const Font& newFont, const int glyphNumber) throw()
  66886. {
  66887. font = newFont;
  66888. glyph = glyphNumber;
  66889. edgeTable = 0;
  66890. Path glyphPath;
  66891. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  66892. if (! glyphPath.isEmpty())
  66893. {
  66894. const float fontHeight = font.getHeight();
  66895. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  66896. .translated (0.0f, -0.5f));
  66897. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  66898. glyphPath, transform);
  66899. }
  66900. }
  66901. int glyph, lastAccessCount;
  66902. Font font;
  66903. juce_UseDebuggingNewOperator
  66904. private:
  66905. ScopedPointer <EdgeTable> edgeTable;
  66906. CachedGlyph (const CachedGlyph&);
  66907. CachedGlyph& operator= (const CachedGlyph&);
  66908. };
  66909. juce_UseDebuggingNewOperator
  66910. private:
  66911. OwnedArray <CachedGlyph> glyphs;
  66912. int accessCounter, hits, misses;
  66913. GlyphCache (const GlyphCache&);
  66914. GlyphCache& operator= (const GlyphCache&);
  66915. };
  66916. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  66917. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  66918. {
  66919. currentState->font = newFont;
  66920. }
  66921. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  66922. {
  66923. return currentState->font;
  66924. }
  66925. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  66926. {
  66927. Font& f = currentState->font;
  66928. if (transform.isOnlyTranslation())
  66929. {
  66930. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  66931. transform.getTranslationX() + (float) currentState->xOffset,
  66932. transform.getTranslationY() + (float) currentState->yOffset);
  66933. }
  66934. else
  66935. {
  66936. Path p;
  66937. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  66938. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  66939. }
  66940. }
  66941. #if JUCE_MSVC
  66942. #pragma warning (pop)
  66943. #endif
  66944. END_JUCE_NAMESPACE
  66945. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  66946. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  66947. BEGIN_JUCE_NAMESPACE
  66948. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  66949. : flags (other.flags)
  66950. {
  66951. }
  66952. RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  66953. {
  66954. flags = other.flags;
  66955. return *this;
  66956. }
  66957. void RectanglePlacement::applyTo (double& x, double& y,
  66958. double& w, double& h,
  66959. const double dx, const double dy,
  66960. const double dw, const double dh) const throw()
  66961. {
  66962. if (w == 0 || h == 0)
  66963. return;
  66964. if ((flags & stretchToFit) != 0)
  66965. {
  66966. x = dx;
  66967. y = dy;
  66968. w = dw;
  66969. h = dh;
  66970. }
  66971. else
  66972. {
  66973. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  66974. : jmin (dw / w, dh / h);
  66975. if ((flags & onlyReduceInSize) != 0)
  66976. scale = jmin (scale, 1.0);
  66977. if ((flags & onlyIncreaseInSize) != 0)
  66978. scale = jmax (scale, 1.0);
  66979. w *= scale;
  66980. h *= scale;
  66981. if ((flags & xLeft) != 0)
  66982. x = dx;
  66983. else if ((flags & xRight) != 0)
  66984. x = dx + dw - w;
  66985. else
  66986. x = dx + (dw - w) * 0.5;
  66987. if ((flags & yTop) != 0)
  66988. y = dy;
  66989. else if ((flags & yBottom) != 0)
  66990. y = dy + dh - h;
  66991. else
  66992. y = dy + (dh - h) * 0.5;
  66993. }
  66994. }
  66995. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  66996. float w, float h,
  66997. const float dx, const float dy,
  66998. const float dw, const float dh) const throw()
  66999. {
  67000. if (w == 0 || h == 0)
  67001. return AffineTransform::identity;
  67002. const float scaleX = dw / w;
  67003. const float scaleY = dh / h;
  67004. if ((flags & stretchToFit) != 0)
  67005. return AffineTransform::translation (-x, -y)
  67006. .scaled (scaleX, scaleY)
  67007. .translated (dx, dy);
  67008. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  67009. : jmin (scaleX, scaleY);
  67010. if ((flags & onlyReduceInSize) != 0)
  67011. scale = jmin (scale, 1.0f);
  67012. if ((flags & onlyIncreaseInSize) != 0)
  67013. scale = jmax (scale, 1.0f);
  67014. w *= scale;
  67015. h *= scale;
  67016. float newX = dx;
  67017. if ((flags & xRight) != 0)
  67018. newX += dw - w; // right
  67019. else if ((flags & xLeft) == 0)
  67020. newX += (dw - w) / 2.0f; // centre
  67021. float newY = dy;
  67022. if ((flags & yBottom) != 0)
  67023. newY += dh - h; // bottom
  67024. else if ((flags & yTop) == 0)
  67025. newY += (dh - h) / 2.0f; // centre
  67026. return AffineTransform::translation (-x, -y)
  67027. .scaled (scale, scale)
  67028. .translated (newX, newY);
  67029. }
  67030. END_JUCE_NAMESPACE
  67031. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  67032. /*** Start of inlined file: juce_Drawable.cpp ***/
  67033. BEGIN_JUCE_NAMESPACE
  67034. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  67035. const AffineTransform& transform_,
  67036. const float opacity_) throw()
  67037. : g (g_),
  67038. transform (transform_),
  67039. opacity (opacity_)
  67040. {
  67041. }
  67042. Drawable::Drawable()
  67043. {
  67044. }
  67045. Drawable::~Drawable()
  67046. {
  67047. }
  67048. void Drawable::draw (Graphics& g, const float opacity,
  67049. const AffineTransform& transform) const
  67050. {
  67051. render (RenderingContext (g, transform, opacity));
  67052. }
  67053. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  67054. {
  67055. draw (g, opacity, AffineTransform::translation (x, y));
  67056. }
  67057. void Drawable::drawWithin (Graphics& g,
  67058. const int destX,
  67059. const int destY,
  67060. const int destW,
  67061. const int destH,
  67062. const RectanglePlacement& placement,
  67063. const float opacity) const
  67064. {
  67065. if (destW > 0 && destH > 0)
  67066. {
  67067. Rectangle<float> bounds (getBounds());
  67068. draw (g, opacity,
  67069. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  67070. (float) destX, (float) destY,
  67071. (float) destW, (float) destH));
  67072. }
  67073. }
  67074. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  67075. {
  67076. Drawable* result = 0;
  67077. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  67078. if (image != 0)
  67079. {
  67080. DrawableImage* const di = new DrawableImage();
  67081. di->setImage (image, true);
  67082. result = di;
  67083. }
  67084. else
  67085. {
  67086. const String asString (String::createStringFromData (data, (int) numBytes));
  67087. XmlDocument doc (asString);
  67088. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  67089. if (outer != 0 && outer->hasTagName (T("svg")))
  67090. {
  67091. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  67092. if (svg != 0)
  67093. result = Drawable::createFromSVG (*svg);
  67094. }
  67095. }
  67096. return result;
  67097. }
  67098. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  67099. {
  67100. MemoryBlock mb;
  67101. dataSource.readIntoMemoryBlock (mb);
  67102. return createFromImageData (mb.getData(), mb.getSize());
  67103. }
  67104. Drawable* Drawable::createFromImageFile (const File& file)
  67105. {
  67106. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  67107. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  67108. }
  67109. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  67110. {
  67111. Drawable* d = DrawablePath::createFromValueTree (tree);
  67112. if (d == 0)
  67113. {
  67114. d = DrawableComposite::createFromValueTree (tree);
  67115. if (d == 0)
  67116. {
  67117. d = DrawableImage::createFromValueTree (tree);
  67118. if (d == 0)
  67119. d = DrawableText::createFromValueTree (tree);
  67120. }
  67121. }
  67122. return d;
  67123. }
  67124. END_JUCE_NAMESPACE
  67125. /*** End of inlined file: juce_Drawable.cpp ***/
  67126. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  67127. BEGIN_JUCE_NAMESPACE
  67128. DrawableComposite::DrawableComposite()
  67129. {
  67130. }
  67131. DrawableComposite::~DrawableComposite()
  67132. {
  67133. }
  67134. void DrawableComposite::insertDrawable (Drawable* drawable,
  67135. const AffineTransform& transform,
  67136. const int index)
  67137. {
  67138. if (drawable != 0)
  67139. {
  67140. if (! drawables.contains (drawable))
  67141. {
  67142. drawables.insert (index, drawable);
  67143. if (transform.isIdentity())
  67144. transforms.insert (index, 0);
  67145. else
  67146. transforms.insert (index, new AffineTransform (transform));
  67147. }
  67148. else
  67149. {
  67150. jassertfalse // trying to add a drawable that's already in here!
  67151. }
  67152. }
  67153. }
  67154. void DrawableComposite::insertDrawable (const Drawable& drawable,
  67155. const AffineTransform& transform,
  67156. const int index)
  67157. {
  67158. insertDrawable (drawable.createCopy(), transform, index);
  67159. }
  67160. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  67161. {
  67162. drawables.remove (index, deleteDrawable);
  67163. transforms.remove (index);
  67164. }
  67165. void DrawableComposite::bringToFront (const int index)
  67166. {
  67167. if (index >= 0 && index < drawables.size() - 1)
  67168. {
  67169. drawables.move (index, -1);
  67170. transforms.move (index, -1);
  67171. }
  67172. }
  67173. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  67174. {
  67175. if (drawables.size() > 0 && context.opacity > 0)
  67176. {
  67177. if (context.opacity >= 1.0f || drawables.size() == 1)
  67178. {
  67179. Drawable::RenderingContext contextCopy (context);
  67180. for (int i = 0; i < drawables.size(); ++i)
  67181. {
  67182. const AffineTransform* const t = transforms.getUnchecked(i);
  67183. contextCopy.transform = (t == 0) ? context.transform
  67184. : t->followedBy (context.transform);
  67185. drawables.getUnchecked(i)->render (contextCopy);
  67186. }
  67187. }
  67188. else
  67189. {
  67190. // To correctly render a whole composite layer with an overall transparency,
  67191. // we need to render everything opaquely into a temp buffer, then blend that
  67192. // with the target opacity...
  67193. const Rectangle<int> clipBounds (context.g.getClipBounds());
  67194. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  67195. {
  67196. Graphics tempG (tempImage);
  67197. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  67198. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  67199. render (tempContext);
  67200. }
  67201. context.g.setOpacity (context.opacity);
  67202. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  67203. }
  67204. }
  67205. }
  67206. const Rectangle<float> DrawableComposite::getBounds() const
  67207. {
  67208. Rectangle<float> bounds;
  67209. for (int i = 0; i < drawables.size(); ++i)
  67210. {
  67211. const Drawable* const d = drawables.getUnchecked(i);
  67212. const AffineTransform* const t = transforms.getUnchecked(i);
  67213. const Rectangle<float> childBounds (t == 0 ? d->getBounds()
  67214. : d->getBounds().transformed (*t));
  67215. if (bounds.isEmpty())
  67216. bounds = childBounds;
  67217. else if (! childBounds.isEmpty())
  67218. bounds = bounds.getUnion (childBounds);
  67219. }
  67220. return bounds;
  67221. }
  67222. bool DrawableComposite::hitTest (float x, float y) const
  67223. {
  67224. for (int i = 0; i < drawables.size(); ++i)
  67225. {
  67226. float tx = x;
  67227. float ty = y;
  67228. const AffineTransform* const t = transforms.getUnchecked(i);
  67229. if (t != 0)
  67230. t->inverted().transformPoint (tx, ty);
  67231. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  67232. return true;
  67233. }
  67234. return false;
  67235. }
  67236. Drawable* DrawableComposite::createCopy() const
  67237. {
  67238. DrawableComposite* const dc = new DrawableComposite();
  67239. for (int i = 0; i < drawables.size(); ++i)
  67240. {
  67241. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  67242. const AffineTransform* const t = transforms.getUnchecked(i);
  67243. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  67244. }
  67245. return dc;
  67246. }
  67247. ValueTree DrawableComposite::createValueTree() const throw()
  67248. {
  67249. ValueTree v (T("Group"));
  67250. if (getName().isNotEmpty())
  67251. v.setProperty ("id", getName(), 0);
  67252. for (int i = 0; i < drawables.size(); ++i)
  67253. {
  67254. Drawable* const d = drawables.getUnchecked(i);
  67255. ValueTree child (d->createValueTree());
  67256. AffineTransform* transform = transforms.getUnchecked(i);
  67257. if (transform != 0)
  67258. {
  67259. String t;
  67260. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  67261. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  67262. child.setProperty ("transform", t, 0);
  67263. }
  67264. v.addChild (child, -1, 0);
  67265. }
  67266. return v;
  67267. }
  67268. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  67269. {
  67270. if (! tree.hasType ("Group"))
  67271. return 0;
  67272. DrawableComposite* dc = new DrawableComposite();
  67273. dc->setName (tree ["id"]);
  67274. for (int i = 0; i < tree.getNumChildren(); ++i)
  67275. {
  67276. ValueTree childTree (tree.getChild (i));
  67277. Drawable* d = Drawable::createFromValueTree (childTree);
  67278. if (d != 0)
  67279. {
  67280. AffineTransform transform;
  67281. const String transformAtt (childTree ["transform"].toString());
  67282. if (transformAtt.isNotEmpty())
  67283. {
  67284. StringArray tokens;
  67285. tokens.addTokens (transformAtt.trim(), false);
  67286. tokens.removeEmptyStrings (true);
  67287. if (tokens.size() == 6)
  67288. {
  67289. float f[6];
  67290. for (int j = 0; j < 6; ++j)
  67291. f[j] = (float) tokens[j].getDoubleValue();
  67292. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67293. }
  67294. }
  67295. dc->insertDrawable (d, transform);
  67296. }
  67297. }
  67298. return dc;
  67299. }
  67300. END_JUCE_NAMESPACE
  67301. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  67302. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  67303. BEGIN_JUCE_NAMESPACE
  67304. DrawableImage::DrawableImage()
  67305. : image (0),
  67306. canDeleteImage (false),
  67307. opacity (1.0f),
  67308. overlayColour (0x00000000)
  67309. {
  67310. }
  67311. DrawableImage::~DrawableImage()
  67312. {
  67313. clearImage();
  67314. }
  67315. void DrawableImage::clearImage()
  67316. {
  67317. if (canDeleteImage && image != 0)
  67318. ImageCache::releaseOrDelete (image);
  67319. image = 0;
  67320. }
  67321. void DrawableImage::setImage (const Image& imageToCopy)
  67322. {
  67323. clearImage();
  67324. image = new Image (imageToCopy);
  67325. canDeleteImage = true;
  67326. }
  67327. void DrawableImage::setImage (Image* imageToUse,
  67328. const bool releaseWhenNotNeeded)
  67329. {
  67330. clearImage();
  67331. image = imageToUse;
  67332. canDeleteImage = releaseWhenNotNeeded;
  67333. }
  67334. void DrawableImage::setOpacity (const float newOpacity)
  67335. {
  67336. opacity = newOpacity;
  67337. }
  67338. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67339. {
  67340. overlayColour = newOverlayColour;
  67341. }
  67342. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67343. {
  67344. if (image != 0)
  67345. {
  67346. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67347. {
  67348. context.g.setOpacity (context.opacity * opacity);
  67349. context.g.drawImageTransformed (image, image->getBounds(),
  67350. context.transform, false);
  67351. }
  67352. if (! overlayColour.isTransparent())
  67353. {
  67354. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67355. context.g.drawImageTransformed (image, image->getBounds(),
  67356. context.transform, true);
  67357. }
  67358. }
  67359. }
  67360. const Rectangle<float> DrawableImage::getBounds() const
  67361. {
  67362. if (image == 0)
  67363. return Rectangle<float>();
  67364. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  67365. }
  67366. bool DrawableImage::hitTest (float x, float y) const
  67367. {
  67368. return image != 0
  67369. && x >= 0.0f
  67370. && y >= 0.0f
  67371. && x < image->getWidth()
  67372. && y < image->getHeight()
  67373. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67374. }
  67375. Drawable* DrawableImage::createCopy() const
  67376. {
  67377. DrawableImage* const di = new DrawableImage();
  67378. di->opacity = opacity;
  67379. di->overlayColour = overlayColour;
  67380. if (image != 0)
  67381. {
  67382. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67383. {
  67384. di->setImage (*image);
  67385. }
  67386. else
  67387. {
  67388. ImageCache::incReferenceCount (image);
  67389. di->setImage (image, true);
  67390. }
  67391. }
  67392. return di;
  67393. }
  67394. ValueTree DrawableImage::createValueTree() const throw()
  67395. {
  67396. ValueTree v (T("Image"));
  67397. if (getName().isNotEmpty())
  67398. v.setProperty ("id", getName(), 0);
  67399. if (opacity < 1.0f)
  67400. v.setProperty ("opacity", (double) opacity, 0);
  67401. if (! overlayColour.isTransparent())
  67402. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67403. if (image != 0)
  67404. {
  67405. MemoryOutputStream imageData;
  67406. PNGImageFormat pngFormat;
  67407. if (pngFormat.writeImageToStream (*image, imageData))
  67408. {
  67409. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67410. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67411. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67412. v.setProperty ("data", base64, 0);
  67413. }
  67414. }
  67415. return v;
  67416. }
  67417. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67418. {
  67419. if (! tree.hasType ("Image"))
  67420. return 0;
  67421. DrawableImage* di = new DrawableImage();
  67422. di->setName (tree ["id"]);
  67423. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67424. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67425. MemoryBlock imageData;
  67426. if (imageData.fromBase64Encoding (tree ["data"]))
  67427. {
  67428. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67429. if (im == 0)
  67430. return false;
  67431. di->setImage (im, true);
  67432. }
  67433. return di;
  67434. }
  67435. END_JUCE_NAMESPACE
  67436. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67437. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67438. BEGIN_JUCE_NAMESPACE
  67439. DrawablePath::DrawablePath()
  67440. : mainFill (FillType (Colours::black)),
  67441. strokeFill (FillType (Colours::transparentBlack)),
  67442. strokeType (0.0f)
  67443. {
  67444. }
  67445. DrawablePath::~DrawablePath()
  67446. {
  67447. }
  67448. void DrawablePath::setPath (const Path& newPath) throw()
  67449. {
  67450. path = newPath;
  67451. updateOutline();
  67452. }
  67453. void DrawablePath::setFill (const FillType& newFill) throw()
  67454. {
  67455. mainFill = newFill;
  67456. }
  67457. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67458. {
  67459. strokeFill = newFill;
  67460. }
  67461. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67462. {
  67463. strokeType = newStrokeType;
  67464. updateOutline();
  67465. }
  67466. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67467. {
  67468. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67469. }
  67470. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67471. {
  67472. {
  67473. FillType f (mainFill);
  67474. if (f.isGradient())
  67475. f.gradient->multiplyOpacity (context.opacity);
  67476. f.transform = f.transform.followedBy (context.transform);
  67477. context.g.setFillType (f);
  67478. context.g.fillPath (path, context.transform);
  67479. }
  67480. if (strokeType.getStrokeThickness() > 0.0f)
  67481. {
  67482. FillType f (strokeFill);
  67483. if (f.isGradient())
  67484. f.gradient->multiplyOpacity (context.opacity);
  67485. f.transform = f.transform.followedBy (context.transform);
  67486. context.g.setFillType (f);
  67487. context.g.fillPath (stroke, context.transform);
  67488. }
  67489. }
  67490. void DrawablePath::updateOutline()
  67491. {
  67492. stroke.clear();
  67493. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67494. }
  67495. const Rectangle<float> DrawablePath::getBounds() const
  67496. {
  67497. if (strokeType.getStrokeThickness() > 0.0f)
  67498. return stroke.getBounds();
  67499. else
  67500. return path.getBounds();
  67501. }
  67502. bool DrawablePath::hitTest (float x, float y) const
  67503. {
  67504. return path.contains (x, y)
  67505. || stroke.contains (x, y);
  67506. }
  67507. Drawable* DrawablePath::createCopy() const
  67508. {
  67509. DrawablePath* const dp = new DrawablePath();
  67510. dp->path = path;
  67511. dp->stroke = stroke;
  67512. dp->mainFill = mainFill;
  67513. dp->strokeFill = strokeFill;
  67514. dp->strokeType = strokeType;
  67515. return dp;
  67516. }
  67517. static const FillType readFillTypeFromTree (const ValueTree& v)
  67518. {
  67519. const String type (v["type"].toString());
  67520. if (type.equalsIgnoreCase (T("solid")))
  67521. {
  67522. const String colour (v ["colour"].toString());
  67523. return FillType (Colour (colour.isEmpty() ? (uint32) 0xff000000
  67524. : (uint32) colour.getHexValue32()));
  67525. }
  67526. else if (type.equalsIgnoreCase ("gradient"))
  67527. {
  67528. ColourGradient g;
  67529. g.x1 = v["x1"];
  67530. g.y1 = v["y1"];
  67531. g.x2 = v["x2"];
  67532. g.y2 = v["y2"];
  67533. g.isRadial = v["radial"];
  67534. StringArray colours;
  67535. colours.addTokens (v["colours"].toString(), false);
  67536. for (int i = 0; i < colours.size() / 2; ++i)
  67537. g.addColour (colours[i * 2].getDoubleValue(),
  67538. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67539. return FillType (g);
  67540. }
  67541. jassertfalse
  67542. return FillType();
  67543. }
  67544. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67545. {
  67546. ValueTree v (tagName);
  67547. if (fillType.isColour())
  67548. {
  67549. v.setProperty ("type", T("solid"), 0);
  67550. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67551. }
  67552. else if (fillType.isGradient())
  67553. {
  67554. v.setProperty ("type", T("gradient"), 0);
  67555. v.setProperty ("x1", fillType.gradient->x1, 0);
  67556. v.setProperty ("y1", fillType.gradient->y1, 0);
  67557. v.setProperty ("x2", fillType.gradient->x2, 0);
  67558. v.setProperty ("y2", fillType.gradient->y2, 0);
  67559. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67560. String s;
  67561. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67562. s << " " << fillType.gradient->getColourPosition (i)
  67563. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67564. v.setProperty ("colours", s.trimStart(), 0);
  67565. }
  67566. else
  67567. {
  67568. jassertfalse //xxx
  67569. }
  67570. return v;
  67571. }
  67572. ValueTree DrawablePath::createValueTree() const throw()
  67573. {
  67574. ValueTree v (T("Path"));
  67575. v.addChild (createTreeForFillType (T("fill"), mainFill), -1, 0);
  67576. v.addChild (createTreeForFillType (T("stroke"), strokeFill), -1, 0);
  67577. if (getName().isNotEmpty())
  67578. v.setProperty ("id", getName(), 0);
  67579. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67580. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67581. ? T("miter") : (strokeType.getJointStyle() == PathStrokeType::curved ? T("curved") : T("bevel")), 0);
  67582. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67583. ? T("butt") : (strokeType.getEndStyle() == PathStrokeType::square ? T("square") : T("round")), 0);
  67584. v.setProperty ("path", path.toString(), 0);
  67585. return v;
  67586. }
  67587. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67588. {
  67589. if (! tree.hasType ("Path"))
  67590. return 0;
  67591. DrawablePath* p = new DrawablePath();
  67592. p->setName (tree ["id"]);
  67593. p->mainFill = readFillTypeFromTree (tree.getChildWithName (T("fill")));
  67594. p->strokeFill = readFillTypeFromTree (tree.getChildWithName (T("stroke")));
  67595. const String jointStyle (tree ["jointStyle"].toString());
  67596. const String endStyle (tree ["capStyle"].toString());
  67597. p->strokeType
  67598. = PathStrokeType (tree ["strokeWidth"],
  67599. jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved
  67600. : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled
  67601. : PathStrokeType::mitered),
  67602. endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square
  67603. : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded
  67604. : PathStrokeType::butt));
  67605. p->path.clear();
  67606. p->path.restoreFromString (tree ["path"]);
  67607. p->updateOutline();
  67608. return p;
  67609. }
  67610. END_JUCE_NAMESPACE
  67611. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67612. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67613. BEGIN_JUCE_NAMESPACE
  67614. DrawableText::DrawableText()
  67615. : colour (Colours::white)
  67616. {
  67617. }
  67618. DrawableText::~DrawableText()
  67619. {
  67620. }
  67621. void DrawableText::setText (const GlyphArrangement& newText)
  67622. {
  67623. text = newText;
  67624. }
  67625. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67626. {
  67627. text.clear();
  67628. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67629. }
  67630. void DrawableText::setColour (const Colour& newColour)
  67631. {
  67632. colour = newColour;
  67633. }
  67634. void DrawableText::render (const Drawable::RenderingContext& context) const
  67635. {
  67636. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67637. text.draw (context.g, context.transform);
  67638. }
  67639. const Rectangle<float> DrawableText::getBounds() const
  67640. {
  67641. float x, y, w, h;
  67642. text.getBoundingBox (0, -1, x, y, w, h, false); // (really returns top, left, bottom, right)
  67643. w -= x;
  67644. h -= y;
  67645. return Rectangle<float> (x, y, w, h);
  67646. }
  67647. bool DrawableText::hitTest (float x, float y) const
  67648. {
  67649. return text.findGlyphIndexAt (x, y) >= 0;
  67650. }
  67651. Drawable* DrawableText::createCopy() const
  67652. {
  67653. DrawableText* const dt = new DrawableText();
  67654. dt->text = text;
  67655. dt->colour = colour;
  67656. return dt;
  67657. }
  67658. ValueTree DrawableText::createValueTree() const throw()
  67659. {
  67660. ValueTree v (T("Text"));
  67661. if (getName().isNotEmpty())
  67662. v.setProperty ("id", getName(), 0);
  67663. jassertfalse // xxx not finished!
  67664. return v;
  67665. }
  67666. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  67667. {
  67668. if (! tree.hasType ("Text"))
  67669. return 0;
  67670. DrawableText* dt = new DrawableText();
  67671. dt->setName (tree ["id"]);
  67672. jassertfalse // xxx not finished!
  67673. return dt;
  67674. }
  67675. END_JUCE_NAMESPACE
  67676. /*** End of inlined file: juce_DrawableText.cpp ***/
  67677. /*** Start of inlined file: juce_SVGParser.cpp ***/
  67678. BEGIN_JUCE_NAMESPACE
  67679. class SVGState
  67680. {
  67681. public:
  67682. SVGState (const XmlElement* const topLevel)
  67683. : topLevelXml (topLevel),
  67684. elementX (0), elementY (0),
  67685. width (512), height (512),
  67686. viewBoxW (0), viewBoxH (0)
  67687. {
  67688. }
  67689. ~SVGState()
  67690. {
  67691. }
  67692. Drawable* parseSVGElement (const XmlElement& xml)
  67693. {
  67694. if (! xml.hasTagName (T("svg")))
  67695. return 0;
  67696. DrawableComposite* const drawable = new DrawableComposite();
  67697. drawable->setName (xml.getStringAttribute (T("id")));
  67698. SVGState newState (*this);
  67699. if (xml.hasAttribute (T("transform")))
  67700. newState.addTransform (xml);
  67701. newState.elementX = getCoordLength (xml.getStringAttribute (T("x"), String (newState.elementX)), viewBoxW);
  67702. newState.elementY = getCoordLength (xml.getStringAttribute (T("y"), String (newState.elementY)), viewBoxH);
  67703. newState.width = getCoordLength (xml.getStringAttribute (T("width"), String (newState.width)), viewBoxW);
  67704. newState.height = getCoordLength (xml.getStringAttribute (T("height"), String (newState.height)), viewBoxH);
  67705. if (xml.hasAttribute (T("viewBox")))
  67706. {
  67707. const String viewParams (xml.getStringAttribute (T("viewBox")));
  67708. int i = 0;
  67709. float vx, vy, vw, vh;
  67710. if (parseCoords (viewParams, vx, vy, i, true)
  67711. && parseCoords (viewParams, vw, vh, i, true)
  67712. && vw > 0
  67713. && vh > 0)
  67714. {
  67715. newState.viewBoxW = vw;
  67716. newState.viewBoxH = vh;
  67717. int placementFlags = 0;
  67718. const String aspect (xml.getStringAttribute (T("preserveAspectRatio")));
  67719. if (aspect.containsIgnoreCase (T("none")))
  67720. {
  67721. placementFlags = RectanglePlacement::stretchToFit;
  67722. }
  67723. else
  67724. {
  67725. if (aspect.containsIgnoreCase (T("slice")))
  67726. placementFlags |= RectanglePlacement::fillDestination;
  67727. if (aspect.containsIgnoreCase (T("xMin")))
  67728. placementFlags |= RectanglePlacement::xLeft;
  67729. else if (aspect.containsIgnoreCase (T("xMax")))
  67730. placementFlags |= RectanglePlacement::xRight;
  67731. else
  67732. placementFlags |= RectanglePlacement::xMid;
  67733. if (aspect.containsIgnoreCase (T("yMin")))
  67734. placementFlags |= RectanglePlacement::yTop;
  67735. else if (aspect.containsIgnoreCase (T("yMax")))
  67736. placementFlags |= RectanglePlacement::yBottom;
  67737. else
  67738. placementFlags |= RectanglePlacement::yMid;
  67739. }
  67740. const RectanglePlacement placement (placementFlags);
  67741. newState.transform
  67742. = placement.getTransformToFit (vx, vy, vw, vh,
  67743. 0.0f, 0.0f, newState.width, newState.height)
  67744. .followedBy (newState.transform);
  67745. }
  67746. }
  67747. else
  67748. {
  67749. if (viewBoxW == 0)
  67750. newState.viewBoxW = newState.width;
  67751. if (viewBoxH == 0)
  67752. newState.viewBoxH = newState.height;
  67753. }
  67754. newState.parseSubElements (xml, drawable);
  67755. return drawable;
  67756. }
  67757. private:
  67758. const XmlElement* const topLevelXml;
  67759. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  67760. AffineTransform transform;
  67761. String cssStyleText;
  67762. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  67763. {
  67764. forEachXmlChildElement (xml, e)
  67765. {
  67766. Drawable* d = 0;
  67767. if (e->hasTagName (T("g")))
  67768. d = parseGroupElement (*e);
  67769. else if (e->hasTagName (T("svg")))
  67770. d = parseSVGElement (*e);
  67771. else if (e->hasTagName (T("path")))
  67772. d = parsePath (*e);
  67773. else if (e->hasTagName (T("rect")))
  67774. d = parseRect (*e);
  67775. else if (e->hasTagName (T("circle")))
  67776. d = parseCircle (*e);
  67777. else if (e->hasTagName (T("ellipse")))
  67778. d = parseEllipse (*e);
  67779. else if (e->hasTagName (T("line")))
  67780. d = parseLine (*e);
  67781. else if (e->hasTagName (T("polyline")))
  67782. d = parsePolygon (*e, true);
  67783. else if (e->hasTagName (T("polygon")))
  67784. d = parsePolygon (*e, false);
  67785. else if (e->hasTagName (T("text")))
  67786. d = parseText (*e);
  67787. else if (e->hasTagName (T("switch")))
  67788. d = parseSwitch (*e);
  67789. else if (e->hasTagName (T("style")))
  67790. parseCSSStyle (*e);
  67791. parentDrawable->insertDrawable (d);
  67792. }
  67793. }
  67794. DrawableComposite* parseSwitch (const XmlElement& xml)
  67795. {
  67796. const XmlElement* const group = xml.getChildByName (T("g"));
  67797. if (group != 0)
  67798. return parseGroupElement (*group);
  67799. return 0;
  67800. }
  67801. DrawableComposite* parseGroupElement (const XmlElement& xml)
  67802. {
  67803. DrawableComposite* const drawable = new DrawableComposite();
  67804. drawable->setName (xml.getStringAttribute (T("id")));
  67805. if (xml.hasAttribute (T("transform")))
  67806. {
  67807. SVGState newState (*this);
  67808. newState.addTransform (xml);
  67809. newState.parseSubElements (xml, drawable);
  67810. }
  67811. else
  67812. {
  67813. parseSubElements (xml, drawable);
  67814. }
  67815. return drawable;
  67816. }
  67817. Drawable* parsePath (const XmlElement& xml) const
  67818. {
  67819. const String d (xml.getStringAttribute (T("d")).trimStart());
  67820. Path path;
  67821. if (getStyleAttribute (&xml, T("fill-rule")).trim().equalsIgnoreCase (T("evenodd")))
  67822. path.setUsingNonZeroWinding (false);
  67823. int index = 0;
  67824. float lastX = 0, lastY = 0;
  67825. float lastX2 = 0, lastY2 = 0;
  67826. tchar lastCommandChar = 0;
  67827. bool isRelative = true;
  67828. bool carryOn = true;
  67829. const String validCommandChars (T("MmLlHhVvCcSsQqTtAaZz"));
  67830. for (;;)
  67831. {
  67832. float x, y, x2, y2, x3, y3;
  67833. if (validCommandChars.containsChar (d[index]))
  67834. {
  67835. lastCommandChar = d [index++];
  67836. isRelative = (lastCommandChar >= 'a' && lastCommandChar <= 'z');
  67837. }
  67838. switch (lastCommandChar)
  67839. {
  67840. case T('M'):
  67841. case T('m'):
  67842. case T('L'):
  67843. case T('l'):
  67844. if (parseCoords (d, x, y, index, false))
  67845. {
  67846. if (isRelative)
  67847. {
  67848. x += lastX;
  67849. y += lastY;
  67850. }
  67851. if (lastCommandChar == T('M') || lastCommandChar == T('m'))
  67852. path.startNewSubPath (x, y);
  67853. else
  67854. path.lineTo (x, y);
  67855. lastX2 = lastX;
  67856. lastY2 = lastY;
  67857. lastX = x;
  67858. lastY = y;
  67859. }
  67860. else
  67861. {
  67862. ++index;
  67863. }
  67864. break;
  67865. case T('H'):
  67866. case T('h'):
  67867. if (parseCoord (d, x, index, false, true))
  67868. {
  67869. if (isRelative)
  67870. x += lastX;
  67871. path.lineTo (x, lastY);
  67872. lastX2 = lastX;
  67873. lastX = x;
  67874. }
  67875. else
  67876. {
  67877. ++index;
  67878. }
  67879. break;
  67880. case T('V'):
  67881. case T('v'):
  67882. if (parseCoord (d, y, index, false, false))
  67883. {
  67884. if (isRelative)
  67885. y += lastY;
  67886. path.lineTo (lastX, y);
  67887. lastY2 = lastY;
  67888. lastY = y;
  67889. }
  67890. else
  67891. {
  67892. ++index;
  67893. }
  67894. break;
  67895. case T('C'):
  67896. case T('c'):
  67897. if (parseCoords (d, x, y, index, false)
  67898. && parseCoords (d, x2, y2, index, false)
  67899. && parseCoords (d, x3, y3, index, false))
  67900. {
  67901. if (isRelative)
  67902. {
  67903. x += lastX;
  67904. y += lastY;
  67905. x2 += lastX;
  67906. y2 += lastY;
  67907. x3 += lastX;
  67908. y3 += lastY;
  67909. }
  67910. path.cubicTo (x, y, x2, y2, x3, y3);
  67911. lastX2 = x2;
  67912. lastY2 = y2;
  67913. lastX = x3;
  67914. lastY = y3;
  67915. }
  67916. else
  67917. {
  67918. ++index;
  67919. }
  67920. break;
  67921. case T('S'):
  67922. case T('s'):
  67923. if (parseCoords (d, x, y, index, false)
  67924. && parseCoords (d, x3, y3, index, false))
  67925. {
  67926. if (isRelative)
  67927. {
  67928. x += lastX;
  67929. y += lastY;
  67930. x3 += lastX;
  67931. y3 += lastY;
  67932. }
  67933. x2 = lastX + (lastX - lastX2);
  67934. y2 = lastY + (lastY - lastY2);
  67935. path.cubicTo (x2, y2, x, y, x3, y3);
  67936. lastX2 = x;
  67937. lastY2 = y;
  67938. lastX = x3;
  67939. lastY = y3;
  67940. }
  67941. else
  67942. {
  67943. ++index;
  67944. }
  67945. break;
  67946. case T('Q'):
  67947. case T('q'):
  67948. if (parseCoords (d, x, y, index, false)
  67949. && parseCoords (d, x2, y2, index, false))
  67950. {
  67951. if (isRelative)
  67952. {
  67953. x += lastX;
  67954. y += lastY;
  67955. x2 += lastX;
  67956. y2 += lastY;
  67957. }
  67958. path.quadraticTo (x, y, x2, y2);
  67959. lastX2 = x;
  67960. lastY2 = y;
  67961. lastX = x2;
  67962. lastY = y2;
  67963. }
  67964. else
  67965. {
  67966. ++index;
  67967. }
  67968. break;
  67969. case T('T'):
  67970. case T('t'):
  67971. if (parseCoords (d, x, y, index, false))
  67972. {
  67973. if (isRelative)
  67974. {
  67975. x += lastX;
  67976. y += lastY;
  67977. }
  67978. x2 = lastX + (lastX - lastX2);
  67979. y2 = lastY + (lastY - lastY2);
  67980. path.quadraticTo (x2, y2, x, y);
  67981. lastX2 = x2;
  67982. lastY2 = y2;
  67983. lastX = x;
  67984. lastY = y;
  67985. }
  67986. else
  67987. {
  67988. ++index;
  67989. }
  67990. break;
  67991. case T('A'):
  67992. case T('a'):
  67993. if (parseCoords (d, x, y, index, false))
  67994. {
  67995. String num;
  67996. if (parseNextNumber (d, num, index, false))
  67997. {
  67998. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  67999. if (parseNextNumber (d, num, index, false))
  68000. {
  68001. const bool largeArc = num.getIntValue() != 0;
  68002. if (parseNextNumber (d, num, index, false))
  68003. {
  68004. const bool sweep = num.getIntValue() != 0;
  68005. if (parseCoords (d, x2, y2, index, false))
  68006. {
  68007. if (isRelative)
  68008. {
  68009. x2 += lastX;
  68010. y2 += lastY;
  68011. }
  68012. if (lastX != x2 || lastY != y2)
  68013. {
  68014. double centreX, centreY, startAngle, deltaAngle;
  68015. double rx = x, ry = y;
  68016. endpointToCentreParameters (lastX, lastY, x2, y2,
  68017. angle, largeArc, sweep,
  68018. rx, ry, centreX, centreY,
  68019. startAngle, deltaAngle);
  68020. path.addCentredArc ((float) centreX, (float) centreY,
  68021. (float) rx, (float) ry,
  68022. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  68023. false);
  68024. path.lineTo (x2, y2);
  68025. }
  68026. lastX2 = lastX;
  68027. lastY2 = lastY;
  68028. lastX = x2;
  68029. lastY = y2;
  68030. }
  68031. }
  68032. }
  68033. }
  68034. }
  68035. else
  68036. {
  68037. ++index;
  68038. }
  68039. break;
  68040. case T('Z'):
  68041. case T('z'):
  68042. path.closeSubPath();
  68043. while (CharacterFunctions::isWhitespace (d [index]))
  68044. ++index;
  68045. break;
  68046. default:
  68047. carryOn = false;
  68048. break;
  68049. }
  68050. if (! carryOn)
  68051. break;
  68052. }
  68053. return parseShape (xml, path);
  68054. }
  68055. Drawable* parseRect (const XmlElement& xml) const
  68056. {
  68057. Path rect;
  68058. const bool hasRX = xml.hasAttribute (T("rx"));
  68059. const bool hasRY = xml.hasAttribute (T("ry"));
  68060. if (hasRX || hasRY)
  68061. {
  68062. float rx = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68063. float ry = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68064. if (! hasRX)
  68065. rx = ry;
  68066. else if (! hasRY)
  68067. ry = rx;
  68068. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68069. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68070. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68071. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH),
  68072. rx, ry);
  68073. }
  68074. else
  68075. {
  68076. rect.addRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68077. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68078. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68079. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH));
  68080. }
  68081. return parseShape (xml, rect);
  68082. }
  68083. Drawable* parseCircle (const XmlElement& xml) const
  68084. {
  68085. Path circle;
  68086. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68087. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68088. const float radius = getCoordLength (xml.getStringAttribute (T("r")), viewBoxW);
  68089. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  68090. return parseShape (xml, circle);
  68091. }
  68092. Drawable* parseEllipse (const XmlElement& xml) const
  68093. {
  68094. Path ellipse;
  68095. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68096. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68097. const float radiusX = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68098. const float radiusY = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68099. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  68100. return parseShape (xml, ellipse);
  68101. }
  68102. Drawable* parseLine (const XmlElement& xml) const
  68103. {
  68104. Path line;
  68105. const float x1 = getCoordLength (xml.getStringAttribute (T("x1")), viewBoxW);
  68106. const float y1 = getCoordLength (xml.getStringAttribute (T("y1")), viewBoxH);
  68107. const float x2 = getCoordLength (xml.getStringAttribute (T("x2")), viewBoxW);
  68108. const float y2 = getCoordLength (xml.getStringAttribute (T("y2")), viewBoxH);
  68109. line.startNewSubPath (x1, y1);
  68110. line.lineTo (x2, y2);
  68111. return parseShape (xml, line);
  68112. }
  68113. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  68114. {
  68115. const String points (xml.getStringAttribute (T("points")));
  68116. Path path;
  68117. int index = 0;
  68118. float x, y;
  68119. if (parseCoords (points, x, y, index, true))
  68120. {
  68121. float firstX = x;
  68122. float firstY = y;
  68123. float lastX = 0, lastY = 0;
  68124. path.startNewSubPath (x, y);
  68125. while (parseCoords (points, x, y, index, true))
  68126. {
  68127. lastX = x;
  68128. lastY = y;
  68129. path.lineTo (x, y);
  68130. }
  68131. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  68132. path.closeSubPath();
  68133. }
  68134. return parseShape (xml, path);
  68135. }
  68136. Drawable* parseShape (const XmlElement& xml, Path& path,
  68137. const bool shouldParseTransform = true) const
  68138. {
  68139. if (shouldParseTransform && xml.hasAttribute (T("transform")))
  68140. {
  68141. SVGState newState (*this);
  68142. newState.addTransform (xml);
  68143. return newState.parseShape (xml, path, false);
  68144. }
  68145. DrawablePath* dp = new DrawablePath();
  68146. dp->setName (xml.getStringAttribute (T("id")));
  68147. dp->setFill (FillType (Colours::transparentBlack));
  68148. path.applyTransform (transform);
  68149. dp->setPath (path);
  68150. Path::Iterator iter (path);
  68151. bool containsClosedSubPath = false;
  68152. while (iter.next())
  68153. {
  68154. if (iter.elementType == Path::Iterator::closePath)
  68155. {
  68156. containsClosedSubPath = true;
  68157. break;
  68158. }
  68159. }
  68160. dp->setFill (getPathFillType (path,
  68161. getStyleAttribute (&xml, T("fill")),
  68162. getStyleAttribute (&xml, T("fill-opacity")),
  68163. getStyleAttribute (&xml, T("opacity")),
  68164. containsClosedSubPath ? Colours::black
  68165. : Colours::transparentBlack));
  68166. const String strokeType (getStyleAttribute (&xml, T("stroke")));
  68167. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase (T("none")))
  68168. {
  68169. dp->setStrokeFill (getPathFillType (path, strokeType,
  68170. getStyleAttribute (&xml, T("stroke-opacity")),
  68171. getStyleAttribute (&xml, T("opacity")),
  68172. Colours::transparentBlack));
  68173. dp->setStrokeType (getStrokeFor (&xml));
  68174. }
  68175. return dp;
  68176. }
  68177. const XmlElement* findLinkedElement (const XmlElement* e) const
  68178. {
  68179. const String id (e->getStringAttribute (T("xlink:href")));
  68180. if (! id.startsWithChar (T('#')))
  68181. return 0;
  68182. return findElementForId (topLevelXml, id.substring (1));
  68183. }
  68184. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  68185. {
  68186. if (fillXml == 0)
  68187. return;
  68188. forEachXmlChildElementWithTagName (*fillXml, e, T("stop"))
  68189. {
  68190. int index = 0;
  68191. Colour col (parseColour (getStyleAttribute (e, T("stop-color")), index, Colours::black));
  68192. const String opacity (getStyleAttribute (e, T("stop-opacity"), T("1")));
  68193. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  68194. double offset = e->getDoubleAttribute (T("offset"));
  68195. if (e->getStringAttribute (T("offset")).containsChar (T('%')))
  68196. offset *= 0.01;
  68197. cg.addColour (jlimit (0.0, 1.0, offset), col);
  68198. }
  68199. }
  68200. const FillType getPathFillType (const Path& path,
  68201. const String& fill,
  68202. const String& fillOpacity,
  68203. const String& overallOpacity,
  68204. const Colour& defaultColour) const
  68205. {
  68206. float opacity = 1.0f;
  68207. if (overallOpacity.isNotEmpty())
  68208. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  68209. if (fillOpacity.isNotEmpty())
  68210. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  68211. if (fill.startsWithIgnoreCase (T("url")))
  68212. {
  68213. const String id (fill.fromFirstOccurrenceOf (T("#"), false, false)
  68214. .upToLastOccurrenceOf (T(")"), false, false).trim());
  68215. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  68216. if (fillXml != 0
  68217. && (fillXml->hasTagName (T("linearGradient"))
  68218. || fillXml->hasTagName (T("radialGradient"))))
  68219. {
  68220. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  68221. ColourGradient gradient;
  68222. addGradientStopsIn (gradient, inheritedFrom);
  68223. addGradientStopsIn (gradient, fillXml);
  68224. if (gradient.getNumColours() > 0)
  68225. {
  68226. gradient.addColour (0.0, gradient.getColour (0));
  68227. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  68228. }
  68229. else
  68230. {
  68231. gradient.addColour (0.0, Colours::black);
  68232. gradient.addColour (1.0, Colours::black);
  68233. }
  68234. if (overallOpacity.isNotEmpty())
  68235. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  68236. jassert (gradient.getNumColours() > 0);
  68237. gradient.isRadial = fillXml->hasTagName (T("radialGradient"));
  68238. float width = viewBoxW;
  68239. float height = viewBoxH;
  68240. float dx = 0.0f;
  68241. float dy = 0.0f;
  68242. const bool userSpace = fillXml->getStringAttribute (T("gradientUnits")).equalsIgnoreCase (T("userSpaceOnUse"));
  68243. if (! userSpace)
  68244. {
  68245. const Rectangle<float> bounds (path.getBounds());
  68246. dx = bounds.getX();
  68247. dy = bounds.getY();
  68248. width = bounds.getWidth();
  68249. height = bounds.getHeight();
  68250. }
  68251. if (gradient.isRadial)
  68252. {
  68253. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("cx"), T("50%")), width);
  68254. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("cy"), T("50%")), height);
  68255. const float radius = getCoordLength (fillXml->getStringAttribute (T("r"), T("50%")), width);
  68256. gradient.x2 = gradient.x1 + radius;
  68257. gradient.y2 = gradient.y1;
  68258. //xxx (the fx, fy focal point isn't handled properly here..)
  68259. }
  68260. else
  68261. {
  68262. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("x1"), T("0%")), width);
  68263. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("y1"), T("0%")), height);
  68264. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute (T("x2"), T("100%")), width);
  68265. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute (T("y2"), T("0%")), height);
  68266. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  68267. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  68268. }
  68269. FillType type (gradient);
  68270. type.transform = parseTransform (fillXml->getStringAttribute (T("gradientTransform")))
  68271. .followedBy (transform);
  68272. return type;
  68273. }
  68274. }
  68275. if (fill.equalsIgnoreCase (T("none")))
  68276. return Colours::transparentBlack;
  68277. int i = 0;
  68278. const Colour colour (parseColour (fill, i, defaultColour));
  68279. return colour.withMultipliedAlpha (opacity);
  68280. }
  68281. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68282. {
  68283. const String width (getStyleAttribute (xml, T("stroke-width")));
  68284. const String cap (getStyleAttribute (xml, T("stroke-linecap")));
  68285. const String join (getStyleAttribute (xml, T("stroke-linejoin")));
  68286. //const String mitreLimit (getStyleAttribute (xml, T("stroke-miterlimit")));
  68287. //const String dashArray (getStyleAttribute (xml, T("stroke-dasharray")));
  68288. //const String dashOffset (getStyleAttribute (xml, T("stroke-dashoffset")));
  68289. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68290. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68291. if (join.equalsIgnoreCase (T("round")))
  68292. joinStyle = PathStrokeType::curved;
  68293. else if (join.equalsIgnoreCase (T("bevel")))
  68294. joinStyle = PathStrokeType::beveled;
  68295. if (cap.equalsIgnoreCase (T("round")))
  68296. capStyle = PathStrokeType::rounded;
  68297. else if (cap.equalsIgnoreCase (T("square")))
  68298. capStyle = PathStrokeType::square;
  68299. float ox = 0.0f, oy = 0.0f;
  68300. transform.transformPoint (ox, oy);
  68301. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68302. transform.transformPoint (x, y);
  68303. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68304. joinStyle, capStyle);
  68305. }
  68306. Drawable* parseText (const XmlElement& xml)
  68307. {
  68308. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68309. getCoordList (xCoords, getInheritedAttribute (&xml, T("x")), true, true);
  68310. getCoordList (yCoords, getInheritedAttribute (&xml, T("y")), true, false);
  68311. getCoordList (dxCoords, getInheritedAttribute (&xml, T("dx")), true, true);
  68312. getCoordList (dyCoords, getInheritedAttribute (&xml, T("dy")), true, false);
  68313. //xxx not done text yet!
  68314. forEachXmlChildElement (xml, e)
  68315. {
  68316. if (e->isTextElement())
  68317. {
  68318. const String text (e->getText());
  68319. Path path;
  68320. Drawable* s = parseShape (*e, path);
  68321. delete s;
  68322. }
  68323. else if (e->hasTagName (T("tspan")))
  68324. {
  68325. Drawable* s = parseText (*e);
  68326. delete s;
  68327. }
  68328. }
  68329. return 0;
  68330. }
  68331. void addTransform (const XmlElement& xml)
  68332. {
  68333. transform = parseTransform (xml.getStringAttribute (T("transform")))
  68334. .followedBy (transform);
  68335. }
  68336. bool parseCoord (const String& s, float& value, int& index,
  68337. const bool allowUnits, const bool isX) const
  68338. {
  68339. String number;
  68340. if (! parseNextNumber (s, number, index, allowUnits))
  68341. {
  68342. value = 0;
  68343. return false;
  68344. }
  68345. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68346. return true;
  68347. }
  68348. bool parseCoords (const String& s, float& x, float& y,
  68349. int& index, const bool allowUnits) const
  68350. {
  68351. return parseCoord (s, x, index, allowUnits, true)
  68352. && parseCoord (s, y, index, allowUnits, false);
  68353. }
  68354. float getCoordLength (const String& s, const float sizeForProportions) const
  68355. {
  68356. float n = s.getFloatValue();
  68357. const int len = s.length();
  68358. if (len > 2)
  68359. {
  68360. const float dpi = 96.0f;
  68361. const tchar n1 = s [len - 2];
  68362. const tchar n2 = s [len - 1];
  68363. if (n1 == T('i') && n2 == T('n'))
  68364. n *= dpi;
  68365. else if (n1 == T('m') && n2 == T('m'))
  68366. n *= dpi / 25.4f;
  68367. else if (n1 == T('c') && n2 == T('m'))
  68368. n *= dpi / 2.54f;
  68369. else if (n1 == T('p') && n2 == T('c'))
  68370. n *= 15.0f;
  68371. else if (n2 == T('%'))
  68372. n *= 0.01f * sizeForProportions;
  68373. }
  68374. return n;
  68375. }
  68376. void getCoordList (Array <float>& coords, const String& list,
  68377. const bool allowUnits, const bool isX) const
  68378. {
  68379. int index = 0;
  68380. float value;
  68381. while (parseCoord (list, value, index, allowUnits, isX))
  68382. coords.add (value);
  68383. }
  68384. void parseCSSStyle (const XmlElement& xml)
  68385. {
  68386. cssStyleText = xml.getAllSubText() + T("\n") + cssStyleText;
  68387. }
  68388. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68389. const String& defaultValue = String::empty) const
  68390. {
  68391. if (xml->hasAttribute (attributeName))
  68392. return xml->getStringAttribute (attributeName, defaultValue);
  68393. const String styleAtt (xml->getStringAttribute (T("style")));
  68394. if (styleAtt.isNotEmpty())
  68395. {
  68396. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68397. if (value.isNotEmpty())
  68398. return value;
  68399. }
  68400. else if (xml->hasAttribute (T("class")))
  68401. {
  68402. const String className (T(".") + xml->getStringAttribute (T("class")));
  68403. int index = cssStyleText.indexOfIgnoreCase (className + T(" "));
  68404. if (index < 0)
  68405. index = cssStyleText.indexOfIgnoreCase (className + T("{"));
  68406. if (index >= 0)
  68407. {
  68408. const int openBracket = cssStyleText.indexOfChar (index, T('{'));
  68409. if (openBracket > index)
  68410. {
  68411. const int closeBracket = cssStyleText.indexOfChar (openBracket, T('}'));
  68412. if (closeBracket > openBracket)
  68413. {
  68414. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68415. if (value.isNotEmpty())
  68416. return value;
  68417. }
  68418. }
  68419. }
  68420. }
  68421. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68422. if (xml != 0)
  68423. return getStyleAttribute (xml, attributeName, defaultValue);
  68424. return defaultValue;
  68425. }
  68426. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68427. {
  68428. if (xml->hasAttribute (attributeName))
  68429. return xml->getStringAttribute (attributeName);
  68430. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68431. if (xml != 0)
  68432. return getInheritedAttribute (xml, attributeName);
  68433. return String::empty;
  68434. }
  68435. static bool isIdentifierChar (const tchar c)
  68436. {
  68437. return CharacterFunctions::isLetter (c) || c == T('-');
  68438. }
  68439. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68440. {
  68441. int i = 0;
  68442. for (;;)
  68443. {
  68444. i = list.indexOf (i, attributeName);
  68445. if (i < 0)
  68446. break;
  68447. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68448. && ! isIdentifierChar (list [i + attributeName.length()]))
  68449. {
  68450. i = list.indexOfChar (i, T(':'));
  68451. if (i < 0)
  68452. break;
  68453. int end = list.indexOfChar (i, T(';'));
  68454. if (end < 0)
  68455. end = 0x7ffff;
  68456. return list.substring (i + 1, end).trim();
  68457. }
  68458. ++i;
  68459. }
  68460. return defaultValue;
  68461. }
  68462. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68463. {
  68464. const tchar* const s = (const tchar*) source;
  68465. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68466. ++index;
  68467. int start = index;
  68468. if (CharacterFunctions::isDigit (s[index]) || s[index] == T('.') || s[index] == T('-'))
  68469. ++index;
  68470. while (CharacterFunctions::isDigit (s[index]) || s[index] == T('.'))
  68471. ++index;
  68472. if ((s[index] == T('e') || s[index] == T('E'))
  68473. && (CharacterFunctions::isDigit (s[index + 1])
  68474. || s[index + 1] == T('-')
  68475. || s[index + 1] == T('+')))
  68476. {
  68477. index += 2;
  68478. while (CharacterFunctions::isDigit (s[index]))
  68479. ++index;
  68480. }
  68481. if (allowUnits)
  68482. {
  68483. while (CharacterFunctions::isLetter (s[index]))
  68484. ++index;
  68485. }
  68486. if (index == start)
  68487. return false;
  68488. value = String (s + start, index - start);
  68489. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68490. ++index;
  68491. return true;
  68492. }
  68493. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68494. {
  68495. if (s [index] == T('#'))
  68496. {
  68497. uint32 hex [6];
  68498. zeromem (hex, sizeof (hex));
  68499. int numChars = 0;
  68500. for (int i = 6; --i >= 0;)
  68501. {
  68502. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68503. if (hexValue >= 0)
  68504. hex [numChars++] = hexValue;
  68505. else
  68506. break;
  68507. }
  68508. if (numChars <= 3)
  68509. return Colour ((uint8) (hex [0] * 0x11),
  68510. (uint8) (hex [1] * 0x11),
  68511. (uint8) (hex [2] * 0x11));
  68512. else
  68513. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68514. (uint8) ((hex [2] << 4) + hex [3]),
  68515. (uint8) ((hex [4] << 4) + hex [5]));
  68516. }
  68517. else if (s [index] == T('r')
  68518. && s [index + 1] == T('g')
  68519. && s [index + 2] == T('b'))
  68520. {
  68521. const int openBracket = s.indexOfChar (index, T('('));
  68522. const int closeBracket = s.indexOfChar (openBracket, T(')'));
  68523. if (openBracket >= 3 && closeBracket > openBracket)
  68524. {
  68525. index = closeBracket;
  68526. StringArray tokens;
  68527. tokens.addTokens (s.substring (openBracket + 1, closeBracket), T(","), T(""));
  68528. tokens.trim();
  68529. tokens.removeEmptyStrings();
  68530. if (tokens[0].containsChar (T('%')))
  68531. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68532. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68533. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68534. else
  68535. return Colour ((uint8) tokens[0].getIntValue(),
  68536. (uint8) tokens[1].getIntValue(),
  68537. (uint8) tokens[2].getIntValue());
  68538. }
  68539. }
  68540. return Colours::findColourForName (s, defaultColour);
  68541. }
  68542. static const AffineTransform parseTransform (String t)
  68543. {
  68544. AffineTransform result;
  68545. while (t.isNotEmpty())
  68546. {
  68547. StringArray tokens;
  68548. tokens.addTokens (t.fromFirstOccurrenceOf (T("("), false, false)
  68549. .upToFirstOccurrenceOf (T(")"), false, false),
  68550. T(", "), 0);
  68551. tokens.removeEmptyStrings (true);
  68552. float numbers [6];
  68553. for (int i = 0; i < 6; ++i)
  68554. numbers[i] = tokens[i].getFloatValue();
  68555. AffineTransform trans;
  68556. if (t.startsWithIgnoreCase (T("matrix")))
  68557. {
  68558. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68559. numbers[1], numbers[3], numbers[5]);
  68560. }
  68561. else if (t.startsWithIgnoreCase (T("translate")))
  68562. {
  68563. jassert (tokens.size() == 2);
  68564. trans = AffineTransform::translation (numbers[0], numbers[1]);
  68565. }
  68566. else if (t.startsWithIgnoreCase (T("scale")))
  68567. {
  68568. if (tokens.size() == 1)
  68569. trans = AffineTransform::scale (numbers[0], numbers[0]);
  68570. else
  68571. trans = AffineTransform::scale (numbers[0], numbers[1]);
  68572. }
  68573. else if (t.startsWithIgnoreCase (T("rotate")))
  68574. {
  68575. if (tokens.size() != 3)
  68576. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi));
  68577. else
  68578. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi),
  68579. numbers[1], numbers[2]);
  68580. }
  68581. else if (t.startsWithIgnoreCase (T("skewX")))
  68582. {
  68583. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68584. 0.0f, 1.0f, 0.0f);
  68585. }
  68586. else if (t.startsWithIgnoreCase (T("skewY")))
  68587. {
  68588. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68589. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68590. }
  68591. result = trans.followedBy (result);
  68592. t = t.fromFirstOccurrenceOf (T(")"), false, false).trimStart();
  68593. }
  68594. return result;
  68595. }
  68596. static void endpointToCentreParameters (const double x1, const double y1,
  68597. const double x2, const double y2,
  68598. const double angle,
  68599. const bool largeArc, const bool sweep,
  68600. double& rx, double& ry,
  68601. double& centreX, double& centreY,
  68602. double& startAngle, double& deltaAngle)
  68603. {
  68604. const double midX = (x1 - x2) * 0.5;
  68605. const double midY = (y1 - y2) * 0.5;
  68606. const double cosAngle = cos (angle);
  68607. const double sinAngle = sin (angle);
  68608. const double xp = cosAngle * midX + sinAngle * midY;
  68609. const double yp = cosAngle * midY - sinAngle * midX;
  68610. const double xp2 = xp * xp;
  68611. const double yp2 = yp * yp;
  68612. double rx2 = rx * rx;
  68613. double ry2 = ry * ry;
  68614. const double s = (xp2 / rx2) + (yp2 / ry2);
  68615. double c;
  68616. if (s <= 1.0)
  68617. {
  68618. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68619. / (( rx2 * yp2) + (ry2 * xp2))));
  68620. if (largeArc == sweep)
  68621. c = -c;
  68622. }
  68623. else
  68624. {
  68625. const double s2 = sqrt (s);
  68626. rx *= s2;
  68627. ry *= s2;
  68628. rx2 = rx * rx;
  68629. ry2 = ry * ry;
  68630. c = 0;
  68631. }
  68632. const double cpx = ((rx * yp) / ry) * c;
  68633. const double cpy = ((-ry * xp) / rx) * c;
  68634. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68635. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68636. const double ux = (xp - cpx) / rx;
  68637. const double uy = (yp - cpy) / ry;
  68638. const double vx = (-xp - cpx) / rx;
  68639. const double vy = (-yp - cpy) / ry;
  68640. const double length = juce_hypot (ux, uy);
  68641. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68642. if (uy < 0)
  68643. startAngle = -startAngle;
  68644. startAngle += double_Pi * 0.5;
  68645. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68646. / (length * juce_hypot (vx, vy))));
  68647. if ((ux * vy) - (uy * vx) < 0)
  68648. deltaAngle = -deltaAngle;
  68649. if (sweep)
  68650. {
  68651. if (deltaAngle < 0)
  68652. deltaAngle += double_Pi * 2.0;
  68653. }
  68654. else
  68655. {
  68656. if (deltaAngle > 0)
  68657. deltaAngle -= double_Pi * 2.0;
  68658. }
  68659. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  68660. }
  68661. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  68662. {
  68663. forEachXmlChildElement (*parent, e)
  68664. {
  68665. if (e->compareAttribute (T("id"), id))
  68666. return e;
  68667. const XmlElement* const found = findElementForId (e, id);
  68668. if (found != 0)
  68669. return found;
  68670. }
  68671. return 0;
  68672. }
  68673. SVGState& operator= (const SVGState&);
  68674. };
  68675. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  68676. {
  68677. SVGState state (&svgDocument);
  68678. return state.parseSVGElement (svgDocument);
  68679. }
  68680. END_JUCE_NAMESPACE
  68681. /*** End of inlined file: juce_SVGParser.cpp ***/
  68682. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  68683. BEGIN_JUCE_NAMESPACE
  68684. #if JUCE_MSVC
  68685. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  68686. #endif
  68687. DropShadowEffect::DropShadowEffect()
  68688. : offsetX (0),
  68689. offsetY (0),
  68690. radius (4),
  68691. opacity (0.6f)
  68692. {
  68693. }
  68694. DropShadowEffect::~DropShadowEffect()
  68695. {
  68696. }
  68697. void DropShadowEffect::setShadowProperties (const float newRadius,
  68698. const float newOpacity,
  68699. const int newShadowOffsetX,
  68700. const int newShadowOffsetY)
  68701. {
  68702. radius = jmax (1.1f, newRadius);
  68703. offsetX = newShadowOffsetX;
  68704. offsetY = newShadowOffsetY;
  68705. opacity = newOpacity;
  68706. }
  68707. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  68708. {
  68709. const int w = image.getWidth();
  68710. const int h = image.getHeight();
  68711. Image shadowImage (Image::SingleChannel, w, h, false);
  68712. const Image::BitmapData srcData (image, 0, 0, w, h);
  68713. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  68714. const int filter = roundToInt (63.0f / radius);
  68715. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  68716. for (int x = w; --x >= 0;)
  68717. {
  68718. int shadowAlpha = 0;
  68719. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  68720. uint8* shadowPix = destData.data + x;
  68721. for (int y = h; --y >= 0;)
  68722. {
  68723. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  68724. *shadowPix = (uint8) shadowAlpha;
  68725. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  68726. shadowPix += destData.lineStride;
  68727. }
  68728. }
  68729. for (int y = h; --y >= 0;)
  68730. {
  68731. int shadowAlpha = 0;
  68732. uint8* shadowPix = destData.getLinePointer (y);
  68733. for (int x = w; --x >= 0;)
  68734. {
  68735. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  68736. *shadowPix++ = (uint8) shadowAlpha;
  68737. }
  68738. }
  68739. g.setColour (Colours::black.withAlpha (opacity));
  68740. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  68741. g.setOpacity (1.0f);
  68742. g.drawImageAt (&image, 0, 0);
  68743. }
  68744. END_JUCE_NAMESPACE
  68745. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  68746. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  68747. BEGIN_JUCE_NAMESPACE
  68748. GlowEffect::GlowEffect()
  68749. : radius (2.0f),
  68750. colour (Colours::white)
  68751. {
  68752. }
  68753. GlowEffect::~GlowEffect()
  68754. {
  68755. }
  68756. void GlowEffect::setGlowProperties (const float newRadius,
  68757. const Colour& newColour)
  68758. {
  68759. radius = newRadius;
  68760. colour = newColour;
  68761. }
  68762. void GlowEffect::applyEffect (Image& image, Graphics& g)
  68763. {
  68764. const int w = image.getWidth();
  68765. const int h = image.getHeight();
  68766. Image temp (image.getFormat(), w, h, true);
  68767. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  68768. blurKernel.createGaussianBlur (radius);
  68769. blurKernel.rescaleAllValues (radius);
  68770. blurKernel.applyToImage (temp, &image, 0, 0, w, h);
  68771. g.setColour (colour);
  68772. g.drawImageAt (&temp, 0, 0, true);
  68773. g.setOpacity (1.0f);
  68774. g.drawImageAt (&image, 0, 0, false);
  68775. }
  68776. END_JUCE_NAMESPACE
  68777. /*** End of inlined file: juce_GlowEffect.cpp ***/
  68778. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68779. BEGIN_JUCE_NAMESPACE
  68780. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  68781. : opacity (opacity_)
  68782. {
  68783. }
  68784. ReduceOpacityEffect::~ReduceOpacityEffect()
  68785. {
  68786. }
  68787. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  68788. {
  68789. opacity = jlimit (0.0f, 1.0f, newOpacity);
  68790. }
  68791. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  68792. {
  68793. g.setOpacity (opacity);
  68794. g.drawImageAt (&image, 0, 0);
  68795. }
  68796. END_JUCE_NAMESPACE
  68797. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68798. /*** Start of inlined file: juce_Font.cpp ***/
  68799. BEGIN_JUCE_NAMESPACE
  68800. static const float minFontHeight = 0.1f;
  68801. static const float maxFontHeight = 10000.0f;
  68802. static const float defaultFontHeight = 14.0f;
  68803. static const tchar* const juce_defaultFontNameSans = T("<Sans-Serif>");
  68804. static const tchar* const juce_defaultFontNameSerif = T("<Serif>");
  68805. static const tchar* const juce_defaultFontNameMono = T("<Monospaced>");
  68806. void clearUpDefaultFontNames() throw(); // in juce_LookAndFeel.cpp
  68807. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  68808. const float kerning_, const float ascent_, const int styleFlags_,
  68809. Typeface* const typeface_) throw()
  68810. : typefaceName (typefaceName_),
  68811. height (height_),
  68812. horizontalScale (horizontalScale_),
  68813. kerning (kerning_),
  68814. ascent (ascent_),
  68815. styleFlags (styleFlags_),
  68816. typeface (typeface_)
  68817. {
  68818. }
  68819. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  68820. : typefaceName (other.typefaceName),
  68821. height (other.height),
  68822. horizontalScale (other.horizontalScale),
  68823. kerning (other.kerning),
  68824. ascent (other.ascent),
  68825. styleFlags (other.styleFlags),
  68826. typeface (other.typeface)
  68827. {
  68828. }
  68829. Font::Font() throw()
  68830. : font (new SharedFontInternal (juce_defaultFontNameSans, defaultFontHeight,
  68831. 1.0f, 0, 0, Font::plain, 0))
  68832. {
  68833. }
  68834. Font::Font (const float fontHeight, const int styleFlags_) throw()
  68835. : font (new SharedFontInternal (juce_defaultFontNameSans, jlimit (minFontHeight, maxFontHeight, fontHeight),
  68836. 1.0f, 0, 0, styleFlags_, 0))
  68837. {
  68838. }
  68839. Font::Font (const String& typefaceName_,
  68840. const float fontHeight,
  68841. const int styleFlags_) throw()
  68842. : font (new SharedFontInternal (typefaceName_, jlimit (minFontHeight, maxFontHeight, fontHeight),
  68843. 1.0f, 0, 0, styleFlags_, 0))
  68844. {
  68845. }
  68846. Font::Font (const Font& other) throw()
  68847. : font (other.font)
  68848. {
  68849. }
  68850. Font& Font::operator= (const Font& other) throw()
  68851. {
  68852. font = other.font;
  68853. return *this;
  68854. }
  68855. Font::~Font() throw()
  68856. {
  68857. }
  68858. Font::Font (const Typeface::Ptr& typeface) throw()
  68859. : font (new SharedFontInternal (typeface->getName(), defaultFontHeight,
  68860. 1.0f, 0, 0, Font::plain, typeface))
  68861. {
  68862. }
  68863. bool Font::operator== (const Font& other) const throw()
  68864. {
  68865. return font == other.font
  68866. || (font->height == other.font->height
  68867. && font->styleFlags == other.font->styleFlags
  68868. && font->horizontalScale == other.font->horizontalScale
  68869. && font->kerning == other.font->kerning
  68870. && font->typefaceName == other.font->typefaceName);
  68871. }
  68872. bool Font::operator!= (const Font& other) const throw()
  68873. {
  68874. return ! operator== (other);
  68875. }
  68876. void Font::dupeInternalIfShared() throw()
  68877. {
  68878. if (font->getReferenceCount() > 1)
  68879. font = new SharedFontInternal (*font);
  68880. }
  68881. const String Font::getDefaultSansSerifFontName() throw()
  68882. {
  68883. return juce_defaultFontNameSans;
  68884. }
  68885. const String Font::getDefaultSerifFontName() throw()
  68886. {
  68887. return juce_defaultFontNameSerif;
  68888. }
  68889. const String Font::getDefaultMonospacedFontName() throw()
  68890. {
  68891. return juce_defaultFontNameMono;
  68892. }
  68893. void Font::setTypefaceName (const String& faceName) throw()
  68894. {
  68895. if (faceName != font->typefaceName)
  68896. {
  68897. dupeInternalIfShared();
  68898. font->typefaceName = faceName;
  68899. font->typeface = 0;
  68900. font->ascent = 0;
  68901. }
  68902. }
  68903. static String fallbackFont;
  68904. const String Font::getFallbackFontName() throw()
  68905. {
  68906. return fallbackFont;
  68907. }
  68908. void Font::setFallbackFontName (const String& name) throw()
  68909. {
  68910. fallbackFont = name;
  68911. }
  68912. void Font::setHeight (float newHeight) throw()
  68913. {
  68914. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  68915. if (font->height != newHeight)
  68916. {
  68917. dupeInternalIfShared();
  68918. font->height = newHeight;
  68919. }
  68920. }
  68921. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  68922. {
  68923. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  68924. if (font->height != newHeight)
  68925. {
  68926. dupeInternalIfShared();
  68927. font->horizontalScale *= (font->height / newHeight);
  68928. font->height = newHeight;
  68929. }
  68930. }
  68931. void Font::setStyleFlags (const int newFlags) throw()
  68932. {
  68933. if (font->styleFlags != newFlags)
  68934. {
  68935. dupeInternalIfShared();
  68936. font->styleFlags = newFlags;
  68937. font->typeface = 0;
  68938. font->ascent = 0;
  68939. }
  68940. }
  68941. void Font::setSizeAndStyle (float newHeight,
  68942. const int newStyleFlags,
  68943. const float newHorizontalScale,
  68944. const float newKerningAmount) throw()
  68945. {
  68946. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  68947. if (font->height != newHeight
  68948. || font->horizontalScale != newHorizontalScale
  68949. || font->kerning != newKerningAmount)
  68950. {
  68951. dupeInternalIfShared();
  68952. font->height = newHeight;
  68953. font->horizontalScale = newHorizontalScale;
  68954. font->kerning = newKerningAmount;
  68955. }
  68956. setStyleFlags (newStyleFlags);
  68957. }
  68958. void Font::setHorizontalScale (const float scaleFactor) throw()
  68959. {
  68960. dupeInternalIfShared();
  68961. font->horizontalScale = scaleFactor;
  68962. }
  68963. void Font::setExtraKerningFactor (const float extraKerning) throw()
  68964. {
  68965. dupeInternalIfShared();
  68966. font->kerning = extraKerning;
  68967. }
  68968. void Font::setBold (const bool shouldBeBold) throw()
  68969. {
  68970. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  68971. : (font->styleFlags & ~bold));
  68972. }
  68973. bool Font::isBold() const throw()
  68974. {
  68975. return (font->styleFlags & bold) != 0;
  68976. }
  68977. void Font::setItalic (const bool shouldBeItalic) throw()
  68978. {
  68979. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  68980. : (font->styleFlags & ~italic));
  68981. }
  68982. bool Font::isItalic() const throw()
  68983. {
  68984. return (font->styleFlags & italic) != 0;
  68985. }
  68986. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  68987. {
  68988. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  68989. : (font->styleFlags & ~underlined));
  68990. }
  68991. bool Font::isUnderlined() const throw()
  68992. {
  68993. return (font->styleFlags & underlined) != 0;
  68994. }
  68995. float Font::getAscent() const throw()
  68996. {
  68997. if (font->ascent == 0)
  68998. font->ascent = getTypeface()->getAscent();
  68999. return font->height * font->ascent;
  69000. }
  69001. float Font::getDescent() const throw()
  69002. {
  69003. return font->height - getAscent();
  69004. }
  69005. int Font::getStringWidth (const String& text) const throw()
  69006. {
  69007. return roundToInt (getStringWidthFloat (text));
  69008. }
  69009. float Font::getStringWidthFloat (const String& text) const throw()
  69010. {
  69011. float w = getTypeface()->getStringWidth (text);
  69012. if (font->kerning != 0)
  69013. w += font->kerning * text.length();
  69014. return w * font->height * font->horizontalScale;
  69015. }
  69016. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  69017. {
  69018. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  69019. const float scale = font->height * font->horizontalScale;
  69020. const int num = xOffsets.size();
  69021. if (num > 0)
  69022. {
  69023. float* const x = &(xOffsets.getReference(0));
  69024. if (font->kerning != 0)
  69025. {
  69026. for (int i = 0; i < num; ++i)
  69027. x[i] = (x[i] + i * font->kerning) * scale;
  69028. }
  69029. else
  69030. {
  69031. for (int i = 0; i < num; ++i)
  69032. x[i] *= scale;
  69033. }
  69034. }
  69035. }
  69036. void Font::findFonts (Array<Font>& destArray) throw()
  69037. {
  69038. const StringArray names (findAllTypefaceNames());
  69039. for (int i = 0; i < names.size(); ++i)
  69040. destArray.add (Font (names[i], defaultFontHeight, Font::plain));
  69041. }
  69042. class TypefaceCache : public DeletedAtShutdown
  69043. {
  69044. public:
  69045. TypefaceCache (int numToCache = 10) throw()
  69046. : counter (1)
  69047. {
  69048. while (--numToCache >= 0)
  69049. faces.add (new CachedFace());
  69050. }
  69051. ~TypefaceCache()
  69052. {
  69053. clearUpDefaultFontNames();
  69054. clearSingletonInstance();
  69055. }
  69056. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  69057. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  69058. {
  69059. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  69060. const String faceName (font.getTypefaceName());
  69061. int i;
  69062. for (i = faces.size(); --i >= 0;)
  69063. {
  69064. CachedFace* const face = faces.getUnchecked(i);
  69065. if (face->flags == flags
  69066. && face->typefaceName == faceName)
  69067. {
  69068. face->lastUsageCount = ++counter;
  69069. return face->typeFace;
  69070. }
  69071. }
  69072. int replaceIndex = 0;
  69073. int bestLastUsageCount = std::numeric_limits<int>::max();
  69074. for (i = faces.size(); --i >= 0;)
  69075. {
  69076. const int lu = faces.getUnchecked(i)->lastUsageCount;
  69077. if (bestLastUsageCount > lu)
  69078. {
  69079. bestLastUsageCount = lu;
  69080. replaceIndex = i;
  69081. }
  69082. }
  69083. CachedFace* const face = faces.getUnchecked (replaceIndex);
  69084. face->typefaceName = faceName;
  69085. face->flags = flags;
  69086. face->lastUsageCount = ++counter;
  69087. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  69088. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  69089. return face->typeFace;
  69090. }
  69091. juce_UseDebuggingNewOperator
  69092. private:
  69093. struct CachedFace
  69094. {
  69095. CachedFace() throw()
  69096. : lastUsageCount (0), flags (-1)
  69097. {
  69098. }
  69099. String typefaceName;
  69100. int lastUsageCount;
  69101. int flags;
  69102. Typeface::Ptr typeFace;
  69103. };
  69104. int counter;
  69105. OwnedArray <CachedFace> faces;
  69106. TypefaceCache (const TypefaceCache&);
  69107. TypefaceCache& operator= (const TypefaceCache&);
  69108. };
  69109. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  69110. Typeface* Font::getTypeface() const throw()
  69111. {
  69112. if (font->typeface == 0)
  69113. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  69114. return font->typeface;
  69115. }
  69116. END_JUCE_NAMESPACE
  69117. /*** End of inlined file: juce_Font.cpp ***/
  69118. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  69119. BEGIN_JUCE_NAMESPACE
  69120. PositionedGlyph::PositionedGlyph()
  69121. {
  69122. }
  69123. void PositionedGlyph::draw (const Graphics& g) const
  69124. {
  69125. if (! isWhitespace())
  69126. {
  69127. g.getInternalContext()->setFont (font);
  69128. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  69129. }
  69130. }
  69131. void PositionedGlyph::draw (const Graphics& g,
  69132. const AffineTransform& transform) const
  69133. {
  69134. if (! isWhitespace())
  69135. {
  69136. g.getInternalContext()->setFont (font);
  69137. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  69138. .followedBy (transform));
  69139. }
  69140. }
  69141. void PositionedGlyph::createPath (Path& path) const
  69142. {
  69143. if (! isWhitespace())
  69144. {
  69145. Typeface* const t = font.getTypeface();
  69146. if (t != 0)
  69147. {
  69148. Path p;
  69149. t->getOutlineForGlyph (glyph, p);
  69150. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  69151. .translated (x, y));
  69152. }
  69153. }
  69154. }
  69155. bool PositionedGlyph::hitTest (float px, float py) const
  69156. {
  69157. if (px >= getLeft() && px < getRight()
  69158. && py >= getTop() && py < getBottom()
  69159. && ! isWhitespace())
  69160. {
  69161. Typeface* const t = font.getTypeface();
  69162. if (t != 0)
  69163. {
  69164. Path p;
  69165. t->getOutlineForGlyph (glyph, p);
  69166. AffineTransform::translation (-x, -y)
  69167. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  69168. .transformPoint (px, py);
  69169. return p.contains (px, py);
  69170. }
  69171. }
  69172. return false;
  69173. }
  69174. void PositionedGlyph::moveBy (const float deltaX,
  69175. const float deltaY)
  69176. {
  69177. x += deltaX;
  69178. y += deltaY;
  69179. }
  69180. GlyphArrangement::GlyphArrangement()
  69181. {
  69182. glyphs.ensureStorageAllocated (128);
  69183. }
  69184. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  69185. {
  69186. addGlyphArrangement (other);
  69187. }
  69188. GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  69189. {
  69190. if (this != &other)
  69191. {
  69192. clear();
  69193. addGlyphArrangement (other);
  69194. }
  69195. return *this;
  69196. }
  69197. GlyphArrangement::~GlyphArrangement()
  69198. {
  69199. }
  69200. void GlyphArrangement::clear()
  69201. {
  69202. glyphs.clear();
  69203. }
  69204. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  69205. {
  69206. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  69207. return *glyphs [index];
  69208. }
  69209. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  69210. {
  69211. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  69212. for (int i = 0; i < other.glyphs.size(); ++i)
  69213. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  69214. }
  69215. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  69216. {
  69217. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  69218. }
  69219. void GlyphArrangement::addLineOfText (const Font& font,
  69220. const String& text,
  69221. const float xOffset,
  69222. const float yOffset)
  69223. {
  69224. addCurtailedLineOfText (font, text,
  69225. xOffset, yOffset,
  69226. 1.0e10f, false);
  69227. }
  69228. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  69229. const String& text,
  69230. float xOffset,
  69231. const float yOffset,
  69232. const float maxWidthPixels,
  69233. const bool useEllipsis)
  69234. {
  69235. int textLen = text.length();
  69236. if (textLen > 0)
  69237. {
  69238. Array <int> newGlyphs;
  69239. Array <float> xOffsets;
  69240. font.getGlyphPositions (text, newGlyphs, xOffsets);
  69241. const juce_wchar* const unicodeText = (const juce_wchar*) text;
  69242. textLen = jmin (textLen, newGlyphs.size());
  69243. for (int i = 0; i < textLen; ++i)
  69244. {
  69245. const float thisX = xOffsets.getUnchecked (i);
  69246. const float nextX = xOffsets.getUnchecked (i + 1);
  69247. if (nextX > maxWidthPixels + 1.0f)
  69248. {
  69249. // curtail the string if it's too wide..
  69250. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  69251. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  69252. break;
  69253. }
  69254. else
  69255. {
  69256. PositionedGlyph* const pg = new PositionedGlyph();
  69257. pg->x = xOffset + thisX;
  69258. pg->y = yOffset;
  69259. pg->w = nextX - thisX;
  69260. pg->font = font;
  69261. pg->glyph = newGlyphs.getUnchecked(i);
  69262. pg->character = unicodeText[i];
  69263. glyphs.add (pg);
  69264. }
  69265. }
  69266. }
  69267. }
  69268. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69269. const int startIndex, int endIndex)
  69270. {
  69271. int numDeleted = 0;
  69272. if (glyphs.size() > 0)
  69273. {
  69274. Array<int> dotGlyphs;
  69275. Array<float> dotXs;
  69276. font.getGlyphPositions (T(".."), dotGlyphs, dotXs);
  69277. const float dx = dotXs[1];
  69278. float xOffset = 0.0f, yOffset = 0.0f;
  69279. while (endIndex > startIndex)
  69280. {
  69281. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69282. xOffset = pg->x;
  69283. yOffset = pg->y;
  69284. glyphs.remove (endIndex);
  69285. ++numDeleted;
  69286. if (xOffset + dx * 3 <= maxXPos)
  69287. break;
  69288. }
  69289. for (int i = 3; --i >= 0;)
  69290. {
  69291. PositionedGlyph* const pg = new PositionedGlyph();
  69292. pg->x = xOffset;
  69293. pg->y = yOffset;
  69294. pg->w = dx;
  69295. pg->font = font;
  69296. pg->character = '.';
  69297. pg->glyph = dotGlyphs.getFirst();
  69298. glyphs.insert (endIndex++, pg);
  69299. --numDeleted;
  69300. xOffset += dx;
  69301. if (xOffset > maxXPos)
  69302. break;
  69303. }
  69304. }
  69305. return numDeleted;
  69306. }
  69307. void GlyphArrangement::addJustifiedText (const Font& font,
  69308. const String& text,
  69309. float x, float y,
  69310. const float maxLineWidth,
  69311. const Justification& horizontalLayout)
  69312. {
  69313. int lineStartIndex = glyphs.size();
  69314. addLineOfText (font, text, x, y);
  69315. const float originalY = y;
  69316. while (lineStartIndex < glyphs.size())
  69317. {
  69318. int i = lineStartIndex;
  69319. if (glyphs.getUnchecked(i)->getCharacter() != T('\n')
  69320. && glyphs.getUnchecked(i)->getCharacter() != T('\r'))
  69321. ++i;
  69322. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69323. int lastWordBreakIndex = -1;
  69324. while (i < glyphs.size())
  69325. {
  69326. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69327. const juce_wchar c = pg->getCharacter();
  69328. if (c == T('\r') || c == T('\n'))
  69329. {
  69330. ++i;
  69331. if (c == T('\r') && i < glyphs.size()
  69332. && glyphs.getUnchecked(i)->getCharacter() == T('\n'))
  69333. ++i;
  69334. break;
  69335. }
  69336. else if (pg->isWhitespace())
  69337. {
  69338. lastWordBreakIndex = i + 1;
  69339. }
  69340. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69341. {
  69342. if (lastWordBreakIndex >= 0)
  69343. i = lastWordBreakIndex;
  69344. break;
  69345. }
  69346. ++i;
  69347. }
  69348. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69349. float currentLineEndX = currentLineStartX;
  69350. for (int j = i; --j >= lineStartIndex;)
  69351. {
  69352. if (! glyphs.getUnchecked (j)->isWhitespace())
  69353. {
  69354. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69355. break;
  69356. }
  69357. }
  69358. float deltaX = 0.0f;
  69359. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69360. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69361. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69362. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69363. else if (horizontalLayout.testFlags (Justification::right))
  69364. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69365. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69366. x + deltaX - currentLineStartX, y - originalY);
  69367. lineStartIndex = i;
  69368. y += font.getHeight();
  69369. }
  69370. }
  69371. void GlyphArrangement::addFittedText (const Font& f,
  69372. const String& text,
  69373. const float x, const float y,
  69374. const float width, const float height,
  69375. const Justification& layout,
  69376. int maximumLines,
  69377. const float minimumHorizontalScale)
  69378. {
  69379. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69380. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69381. if (text.containsAnyOf (T("\r\n")))
  69382. {
  69383. GlyphArrangement ga;
  69384. ga.addJustifiedText (f, text, x, y, width, layout);
  69385. float l, t, r, b;
  69386. ga.getBoundingBox (0, -1, l, t, r, b, false);
  69387. float dy = y - t;
  69388. if (layout.testFlags (Justification::verticallyCentred))
  69389. dy += (height - (b - t)) * 0.5f;
  69390. else if (layout.testFlags (Justification::bottom))
  69391. dy += height - (b - t);
  69392. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69393. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69394. for (int i = 0; i < ga.glyphs.size(); ++i)
  69395. glyphs.add (ga.glyphs.getUnchecked (i));
  69396. ga.glyphs.clear (false);
  69397. return;
  69398. }
  69399. int startIndex = glyphs.size();
  69400. addLineOfText (f, text.trim(), x, y);
  69401. if (glyphs.size() > startIndex)
  69402. {
  69403. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69404. - glyphs.getUnchecked (startIndex)->getLeft();
  69405. if (lineWidth <= 0)
  69406. return;
  69407. if (lineWidth * minimumHorizontalScale < width)
  69408. {
  69409. if (lineWidth > width)
  69410. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69411. width / lineWidth);
  69412. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69413. x, y, width, height, layout);
  69414. }
  69415. else if (maximumLines <= 1)
  69416. {
  69417. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69418. x, y, width, height, f, layout, minimumHorizontalScale);
  69419. }
  69420. else
  69421. {
  69422. Font font (f);
  69423. String txt (text.trim());
  69424. const int length = txt.length();
  69425. const int originalStartIndex = startIndex;
  69426. int numLines = 1;
  69427. if (length <= 12 && ! txt.containsAnyOf (T(" -\t\r\n")))
  69428. maximumLines = 1;
  69429. maximumLines = jmin (maximumLines, length);
  69430. while (numLines < maximumLines)
  69431. {
  69432. ++numLines;
  69433. const float newFontHeight = height / (float) numLines;
  69434. if (newFontHeight < font.getHeight())
  69435. {
  69436. font.setHeight (jmax (8.0f, newFontHeight));
  69437. removeRangeOfGlyphs (startIndex, -1);
  69438. addLineOfText (font, txt, x, y);
  69439. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69440. - glyphs.getUnchecked (startIndex)->getLeft();
  69441. }
  69442. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69443. break;
  69444. }
  69445. if (numLines < 1)
  69446. numLines = 1;
  69447. float lineY = y;
  69448. float widthPerLine = lineWidth / numLines;
  69449. int lastLineStartIndex = 0;
  69450. for (int line = 0; line < numLines; ++line)
  69451. {
  69452. int i = startIndex;
  69453. lastLineStartIndex = i;
  69454. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69455. if (line == numLines - 1)
  69456. {
  69457. widthPerLine = width;
  69458. i = glyphs.size();
  69459. }
  69460. else
  69461. {
  69462. while (i < glyphs.size())
  69463. {
  69464. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69465. if (lineWidth > widthPerLine)
  69466. {
  69467. // got to a point where the line's too long, so skip forward to find a
  69468. // good place to break it..
  69469. const int searchStartIndex = i;
  69470. while (i < glyphs.size())
  69471. {
  69472. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69473. {
  69474. if (glyphs.getUnchecked (i)->isWhitespace()
  69475. || glyphs.getUnchecked (i)->getCharacter() == T('-'))
  69476. {
  69477. ++i;
  69478. break;
  69479. }
  69480. }
  69481. else
  69482. {
  69483. // can't find a suitable break, so try looking backwards..
  69484. i = searchStartIndex;
  69485. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69486. {
  69487. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69488. || glyphs.getUnchecked (i - back)->getCharacter() == T('-'))
  69489. {
  69490. i -= back - 1;
  69491. break;
  69492. }
  69493. }
  69494. break;
  69495. }
  69496. ++i;
  69497. }
  69498. break;
  69499. }
  69500. ++i;
  69501. }
  69502. int wsStart = i;
  69503. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69504. --wsStart;
  69505. int wsEnd = i;
  69506. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69507. ++wsEnd;
  69508. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69509. i = jmax (wsStart, startIndex + 1);
  69510. }
  69511. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69512. x, lineY, width, font.getHeight(), font,
  69513. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69514. minimumHorizontalScale);
  69515. startIndex = i;
  69516. lineY += font.getHeight();
  69517. if (startIndex >= glyphs.size())
  69518. break;
  69519. }
  69520. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69521. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69522. }
  69523. }
  69524. }
  69525. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69526. const float dx, const float dy)
  69527. {
  69528. jassert (startIndex >= 0);
  69529. if (dx != 0.0f || dy != 0.0f)
  69530. {
  69531. if (num < 0 || startIndex + num > glyphs.size())
  69532. num = glyphs.size() - startIndex;
  69533. while (--num >= 0)
  69534. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69535. }
  69536. }
  69537. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69538. const Justification& justification, float minimumHorizontalScale)
  69539. {
  69540. int numDeleted = 0;
  69541. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69542. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69543. if (lineWidth > w)
  69544. {
  69545. if (minimumHorizontalScale < 1.0f)
  69546. {
  69547. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69548. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69549. }
  69550. if (lineWidth > w)
  69551. {
  69552. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69553. numGlyphs -= numDeleted;
  69554. }
  69555. }
  69556. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69557. return numDeleted;
  69558. }
  69559. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69560. const float horizontalScaleFactor)
  69561. {
  69562. jassert (startIndex >= 0);
  69563. if (num < 0 || startIndex + num > glyphs.size())
  69564. num = glyphs.size() - startIndex;
  69565. if (num > 0)
  69566. {
  69567. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69568. while (--num >= 0)
  69569. {
  69570. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69571. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69572. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69573. pg->w *= horizontalScaleFactor;
  69574. }
  69575. }
  69576. }
  69577. void GlyphArrangement::getBoundingBox (int startIndex, int num,
  69578. float& left,
  69579. float& top,
  69580. float& right,
  69581. float& bottom,
  69582. const bool includeWhitespace) const
  69583. {
  69584. jassert (startIndex >= 0);
  69585. if (num < 0 || startIndex + num > glyphs.size())
  69586. num = glyphs.size() - startIndex;
  69587. left = 0.0f;
  69588. top = 0.0f;
  69589. right = 0.0f;
  69590. bottom = 0.0f;
  69591. bool isFirst = true;
  69592. while (--num >= 0)
  69593. {
  69594. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69595. if (includeWhitespace || ! pg->isWhitespace())
  69596. {
  69597. if (isFirst)
  69598. {
  69599. isFirst = false;
  69600. left = pg->getLeft();
  69601. top = pg->getTop();
  69602. right = pg->getRight();
  69603. bottom = pg->getBottom();
  69604. }
  69605. else
  69606. {
  69607. left = jmin (left, pg->getLeft());
  69608. top = jmin (top, pg->getTop());
  69609. right = jmax (right, pg->getRight());
  69610. bottom = jmax (bottom, pg->getBottom());
  69611. }
  69612. }
  69613. }
  69614. }
  69615. void GlyphArrangement::justifyGlyphs (const int startIndex,
  69616. const int num,
  69617. const float x, const float y,
  69618. const float width, const float height,
  69619. const Justification& justification)
  69620. {
  69621. jassert (num >= 0 && startIndex >= 0);
  69622. if (glyphs.size() > 0 && num > 0)
  69623. {
  69624. float left, top, right, bottom;
  69625. getBoundingBox (startIndex, num, left, top, right, bottom,
  69626. ! justification.testFlags (Justification::horizontallyJustified
  69627. | Justification::horizontallyCentred));
  69628. float deltaX = 0.0f;
  69629. if (justification.testFlags (Justification::horizontallyJustified))
  69630. deltaX = x - left;
  69631. else if (justification.testFlags (Justification::horizontallyCentred))
  69632. deltaX = x + (width - (right - left)) * 0.5f - left;
  69633. else if (justification.testFlags (Justification::right))
  69634. deltaX = (x + width) - right;
  69635. else
  69636. deltaX = x - left;
  69637. float deltaY = 0.0f;
  69638. if (justification.testFlags (Justification::top))
  69639. deltaY = y - top;
  69640. else if (justification.testFlags (Justification::bottom))
  69641. deltaY = (y + height) - bottom;
  69642. else
  69643. deltaY = y + (height - (bottom - top)) * 0.5f - top;
  69644. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69645. if (justification.testFlags (Justification::horizontallyJustified))
  69646. {
  69647. int lineStart = 0;
  69648. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69649. int i;
  69650. for (i = 0; i < num; ++i)
  69651. {
  69652. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69653. if (glyphY != baseY)
  69654. {
  69655. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69656. lineStart = i;
  69657. baseY = glyphY;
  69658. }
  69659. }
  69660. if (i > lineStart)
  69661. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69662. }
  69663. }
  69664. }
  69665. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  69666. {
  69667. if (start + num < glyphs.size()
  69668. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\r')
  69669. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\n'))
  69670. {
  69671. int numSpaces = 0;
  69672. int spacesAtEnd = 0;
  69673. for (int i = 0; i < num; ++i)
  69674. {
  69675. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69676. {
  69677. ++spacesAtEnd;
  69678. ++numSpaces;
  69679. }
  69680. else
  69681. {
  69682. spacesAtEnd = 0;
  69683. }
  69684. }
  69685. numSpaces -= spacesAtEnd;
  69686. if (numSpaces > 0)
  69687. {
  69688. const float startX = glyphs.getUnchecked (start)->getLeft();
  69689. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  69690. const float extraPaddingBetweenWords
  69691. = (targetWidth - (endX - startX)) / (float) numSpaces;
  69692. float deltaX = 0.0f;
  69693. for (int i = 0; i < num; ++i)
  69694. {
  69695. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  69696. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69697. deltaX += extraPaddingBetweenWords;
  69698. }
  69699. }
  69700. }
  69701. }
  69702. void GlyphArrangement::draw (const Graphics& g) const
  69703. {
  69704. for (int i = 0; i < glyphs.size(); ++i)
  69705. {
  69706. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69707. if (pg->font.isUnderlined())
  69708. {
  69709. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69710. float nextX = pg->x + pg->w;
  69711. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69712. nextX = glyphs.getUnchecked (i + 1)->x;
  69713. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  69714. nextX - pg->x, lineThickness);
  69715. }
  69716. pg->draw (g);
  69717. }
  69718. }
  69719. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  69720. {
  69721. for (int i = 0; i < glyphs.size(); ++i)
  69722. {
  69723. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69724. if (pg->font.isUnderlined())
  69725. {
  69726. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69727. float nextX = pg->x + pg->w;
  69728. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69729. nextX = glyphs.getUnchecked (i + 1)->x;
  69730. Path p;
  69731. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  69732. nextX, pg->y + lineThickness * 2.0f,
  69733. lineThickness);
  69734. g.fillPath (p, transform);
  69735. }
  69736. pg->draw (g, transform);
  69737. }
  69738. }
  69739. void GlyphArrangement::createPath (Path& path) const
  69740. {
  69741. for (int i = 0; i < glyphs.size(); ++i)
  69742. glyphs.getUnchecked (i)->createPath (path);
  69743. }
  69744. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  69745. {
  69746. for (int i = 0; i < glyphs.size(); ++i)
  69747. if (glyphs.getUnchecked (i)->hitTest (x, y))
  69748. return i;
  69749. return -1;
  69750. }
  69751. END_JUCE_NAMESPACE
  69752. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  69753. /*** Start of inlined file: juce_TextLayout.cpp ***/
  69754. BEGIN_JUCE_NAMESPACE
  69755. class TextLayout::Token
  69756. {
  69757. public:
  69758. String text;
  69759. Font font;
  69760. int x, y, w, h;
  69761. int line, lineHeight;
  69762. bool isWhitespace, isNewLine;
  69763. Token (const String& t,
  69764. const Font& f,
  69765. const bool isWhitespace_) throw()
  69766. : text (t),
  69767. font (f),
  69768. x(0),
  69769. y(0),
  69770. isWhitespace (isWhitespace_)
  69771. {
  69772. w = font.getStringWidth (t);
  69773. h = roundToInt (f.getHeight());
  69774. isNewLine = t.containsAnyOf (T("\r\n"));
  69775. }
  69776. Token (const Token& other) throw()
  69777. : text (other.text),
  69778. font (other.font),
  69779. x (other.x),
  69780. y (other.y),
  69781. w (other.w),
  69782. h (other.h),
  69783. line (other.line),
  69784. lineHeight (other.lineHeight),
  69785. isWhitespace (other.isWhitespace),
  69786. isNewLine (other.isNewLine)
  69787. {
  69788. }
  69789. ~Token() throw()
  69790. {
  69791. }
  69792. void draw (Graphics& g,
  69793. const int xOffset,
  69794. const int yOffset) throw()
  69795. {
  69796. if (! isWhitespace)
  69797. {
  69798. g.setFont (font);
  69799. g.drawSingleLineText (text.trimEnd(),
  69800. xOffset + x,
  69801. yOffset + y + (lineHeight - h)
  69802. + roundToInt (font.getAscent()));
  69803. }
  69804. }
  69805. juce_UseDebuggingNewOperator
  69806. };
  69807. TextLayout::TextLayout() throw()
  69808. : totalLines (0)
  69809. {
  69810. tokens.ensureStorageAllocated (64);
  69811. }
  69812. TextLayout::TextLayout (const String& text,
  69813. const Font& font) throw()
  69814. : totalLines (0)
  69815. {
  69816. tokens.ensureStorageAllocated (64);
  69817. appendText (text, font);
  69818. }
  69819. TextLayout::TextLayout (const TextLayout& other) throw()
  69820. : totalLines (0)
  69821. {
  69822. *this = other;
  69823. }
  69824. TextLayout& TextLayout::operator= (const TextLayout& other) throw()
  69825. {
  69826. if (this != &other)
  69827. {
  69828. clear();
  69829. totalLines = other.totalLines;
  69830. for (int i = 0; i < other.tokens.size(); ++i)
  69831. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  69832. }
  69833. return *this;
  69834. }
  69835. TextLayout::~TextLayout() throw()
  69836. {
  69837. clear();
  69838. }
  69839. void TextLayout::clear() throw()
  69840. {
  69841. tokens.clear();
  69842. totalLines = 0;
  69843. }
  69844. void TextLayout::appendText (const String& text,
  69845. const Font& font) throw()
  69846. {
  69847. const tchar* t = text;
  69848. String currentString;
  69849. int lastCharType = 0;
  69850. for (;;)
  69851. {
  69852. const tchar c = *t++;
  69853. if (c == 0)
  69854. break;
  69855. int charType;
  69856. if (c == T('\r') || c == T('\n'))
  69857. {
  69858. charType = 0;
  69859. }
  69860. else if (CharacterFunctions::isWhitespace (c))
  69861. {
  69862. charType = 2;
  69863. }
  69864. else
  69865. {
  69866. charType = 1;
  69867. }
  69868. if (charType == 0 || charType != lastCharType)
  69869. {
  69870. if (currentString.isNotEmpty())
  69871. {
  69872. tokens.add (new Token (currentString, font,
  69873. lastCharType == 2 || lastCharType == 0));
  69874. }
  69875. currentString = String::charToString (c);
  69876. if (c == T('\r') && *t == T('\n'))
  69877. currentString += *t++;
  69878. }
  69879. else
  69880. {
  69881. currentString += c;
  69882. }
  69883. lastCharType = charType;
  69884. }
  69885. if (currentString.isNotEmpty())
  69886. tokens.add (new Token (currentString, font, lastCharType == 2));
  69887. }
  69888. void TextLayout::setText (const String& text, const Font& font) throw()
  69889. {
  69890. clear();
  69891. appendText (text, font);
  69892. }
  69893. void TextLayout::layout (int maxWidth,
  69894. const Justification& justification,
  69895. const bool attemptToBalanceLineLengths) throw()
  69896. {
  69897. if (attemptToBalanceLineLengths)
  69898. {
  69899. const int originalW = maxWidth;
  69900. int bestWidth = maxWidth;
  69901. float bestLineProportion = 0.0f;
  69902. while (maxWidth > originalW / 2)
  69903. {
  69904. layout (maxWidth, justification, false);
  69905. if (getNumLines() <= 1)
  69906. return;
  69907. const int lastLineW = getLineWidth (getNumLines() - 1);
  69908. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  69909. const float prop = lastLineW / (float) lastButOneLineW;
  69910. if (prop > 0.9f)
  69911. return;
  69912. if (prop > bestLineProportion)
  69913. {
  69914. bestLineProportion = prop;
  69915. bestWidth = maxWidth;
  69916. }
  69917. maxWidth -= 10;
  69918. }
  69919. layout (bestWidth, justification, false);
  69920. }
  69921. else
  69922. {
  69923. int x = 0;
  69924. int y = 0;
  69925. int h = 0;
  69926. totalLines = 0;
  69927. int i;
  69928. for (i = 0; i < tokens.size(); ++i)
  69929. {
  69930. Token* const t = tokens.getUnchecked(i);
  69931. t->x = x;
  69932. t->y = y;
  69933. t->line = totalLines;
  69934. x += t->w;
  69935. h = jmax (h, t->h);
  69936. const Token* nextTok = tokens [i + 1];
  69937. if (nextTok == 0)
  69938. break;
  69939. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  69940. {
  69941. // finished a line, so go back and update the heights of the things on it
  69942. for (int j = i; j >= 0; --j)
  69943. {
  69944. Token* const tok = tokens.getUnchecked(j);
  69945. if (tok->line == totalLines)
  69946. tok->lineHeight = h;
  69947. else
  69948. break;
  69949. }
  69950. x = 0;
  69951. y += h;
  69952. h = 0;
  69953. ++totalLines;
  69954. }
  69955. }
  69956. // finished a line, so go back and update the heights of the things on it
  69957. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  69958. {
  69959. Token* const t = tokens.getUnchecked(j);
  69960. if (t->line == totalLines)
  69961. t->lineHeight = h;
  69962. else
  69963. break;
  69964. }
  69965. ++totalLines;
  69966. if (! justification.testFlags (Justification::left))
  69967. {
  69968. int totalW = getWidth();
  69969. for (i = totalLines; --i >= 0;)
  69970. {
  69971. const int lineW = getLineWidth (i);
  69972. int dx = 0;
  69973. if (justification.testFlags (Justification::horizontallyCentred))
  69974. dx = (totalW - lineW) / 2;
  69975. else if (justification.testFlags (Justification::right))
  69976. dx = totalW - lineW;
  69977. for (int j = tokens.size(); --j >= 0;)
  69978. {
  69979. Token* const t = tokens.getUnchecked(j);
  69980. if (t->line == i)
  69981. t->x += dx;
  69982. }
  69983. }
  69984. }
  69985. }
  69986. }
  69987. int TextLayout::getLineWidth (const int lineNumber) const throw()
  69988. {
  69989. int maxW = 0;
  69990. for (int i = tokens.size(); --i >= 0;)
  69991. {
  69992. const Token* const t = tokens.getUnchecked(i);
  69993. if (t->line == lineNumber && ! t->isWhitespace)
  69994. maxW = jmax (maxW, t->x + t->w);
  69995. }
  69996. return maxW;
  69997. }
  69998. int TextLayout::getWidth() const throw()
  69999. {
  70000. int maxW = 0;
  70001. for (int i = tokens.size(); --i >= 0;)
  70002. {
  70003. const Token* const t = tokens.getUnchecked(i);
  70004. if (! t->isWhitespace)
  70005. maxW = jmax (maxW, t->x + t->w);
  70006. }
  70007. return maxW;
  70008. }
  70009. int TextLayout::getHeight() const throw()
  70010. {
  70011. int maxH = 0;
  70012. for (int i = tokens.size(); --i >= 0;)
  70013. {
  70014. const Token* const t = tokens.getUnchecked(i);
  70015. if (! t->isWhitespace)
  70016. maxH = jmax (maxH, t->y + t->h);
  70017. }
  70018. return maxH;
  70019. }
  70020. void TextLayout::draw (Graphics& g,
  70021. const int xOffset,
  70022. const int yOffset) const throw()
  70023. {
  70024. for (int i = tokens.size(); --i >= 0;)
  70025. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  70026. }
  70027. void TextLayout::drawWithin (Graphics& g,
  70028. int x, int y, int w, int h,
  70029. const Justification& justification) const throw()
  70030. {
  70031. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  70032. x, y, w, h);
  70033. draw (g, x, y);
  70034. }
  70035. END_JUCE_NAMESPACE
  70036. /*** End of inlined file: juce_TextLayout.cpp ***/
  70037. /*** Start of inlined file: juce_Typeface.cpp ***/
  70038. BEGIN_JUCE_NAMESPACE
  70039. Typeface::Typeface (const String& name_) throw()
  70040. : name (name_)
  70041. {
  70042. }
  70043. Typeface::~Typeface()
  70044. {
  70045. }
  70046. class CustomTypeface::GlyphInfo
  70047. {
  70048. public:
  70049. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  70050. : character (character_), path (path_), width (width_)
  70051. {
  70052. }
  70053. ~GlyphInfo() throw()
  70054. {
  70055. }
  70056. struct KerningPair
  70057. {
  70058. juce_wchar character2;
  70059. float kerningAmount;
  70060. };
  70061. void addKerningPair (const juce_wchar subsequentCharacter,
  70062. const float extraKerningAmount) throw()
  70063. {
  70064. KerningPair kp;
  70065. kp.character2 = subsequentCharacter;
  70066. kp.kerningAmount = extraKerningAmount;
  70067. kerningPairs.add (kp);
  70068. }
  70069. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  70070. {
  70071. if (subsequentCharacter != 0)
  70072. {
  70073. for (int i = kerningPairs.size(); --i >= 0;)
  70074. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  70075. return width + kerningPairs.getReference(i).kerningAmount;
  70076. }
  70077. return width;
  70078. }
  70079. const juce_wchar character;
  70080. const Path path;
  70081. float width;
  70082. Array <KerningPair> kerningPairs;
  70083. juce_UseDebuggingNewOperator
  70084. private:
  70085. GlyphInfo (const GlyphInfo&);
  70086. GlyphInfo& operator= (const GlyphInfo&);
  70087. };
  70088. CustomTypeface::CustomTypeface()
  70089. : Typeface (String::empty)
  70090. {
  70091. clear();
  70092. }
  70093. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  70094. : Typeface (String::empty)
  70095. {
  70096. clear();
  70097. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  70098. BufferedInputStream in (&gzin, 32768, false);
  70099. name = in.readString();
  70100. isBold = in.readBool();
  70101. isItalic = in.readBool();
  70102. ascent = in.readFloat();
  70103. defaultCharacter = (juce_wchar) in.readShort();
  70104. int i, numChars = in.readInt();
  70105. for (i = 0; i < numChars; ++i)
  70106. {
  70107. const juce_wchar c = (juce_wchar) in.readShort();
  70108. const float width = in.readFloat();
  70109. Path p;
  70110. p.loadPathFromStream (in);
  70111. addGlyph (c, p, width);
  70112. }
  70113. const int numKerningPairs = in.readInt();
  70114. for (i = 0; i < numKerningPairs; ++i)
  70115. {
  70116. const juce_wchar char1 = (juce_wchar) in.readShort();
  70117. const juce_wchar char2 = (juce_wchar) in.readShort();
  70118. addKerningPair (char1, char2, in.readFloat());
  70119. }
  70120. }
  70121. CustomTypeface::~CustomTypeface()
  70122. {
  70123. }
  70124. void CustomTypeface::clear()
  70125. {
  70126. defaultCharacter = 0;
  70127. ascent = 1.0f;
  70128. isBold = isItalic = false;
  70129. zeromem (lookupTable, sizeof (lookupTable));
  70130. glyphs.clear();
  70131. }
  70132. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  70133. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  70134. {
  70135. name = name_;
  70136. defaultCharacter = defaultCharacter_;
  70137. ascent = ascent_;
  70138. isBold = isBold_;
  70139. isItalic = isItalic_;
  70140. }
  70141. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  70142. {
  70143. // Check that you're not trying to add the same character twice..
  70144. jassert (findGlyph (character, false) == 0);
  70145. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  70146. lookupTable [character] = (short) glyphs.size();
  70147. glyphs.add (new GlyphInfo (character, path, width));
  70148. }
  70149. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  70150. {
  70151. if (extraAmount != 0)
  70152. {
  70153. GlyphInfo* const g = findGlyph (char1, true);
  70154. jassert (g != 0); // can only add kerning pairs for characters that exist!
  70155. if (g != 0)
  70156. g->addKerningPair (char2, extraAmount);
  70157. }
  70158. }
  70159. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  70160. {
  70161. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  70162. return glyphs [(int) lookupTable [(int) character]];
  70163. for (int i = 0; i < glyphs.size(); ++i)
  70164. {
  70165. GlyphInfo* const g = glyphs.getUnchecked(i);
  70166. if (g->character == character)
  70167. return g;
  70168. }
  70169. if (loadIfNeeded && loadGlyphIfPossible (character))
  70170. return findGlyph (character, false);
  70171. return 0;
  70172. }
  70173. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  70174. {
  70175. GlyphInfo* glyph = findGlyph (character, true);
  70176. if (glyph == 0)
  70177. {
  70178. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  70179. glyph = findGlyph (L' ', true);
  70180. if (glyph == 0)
  70181. {
  70182. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  70183. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  70184. if (fallbackTypeface != 0 && fallbackTypeface != this)
  70185. {
  70186. //xxx
  70187. }
  70188. if (glyph == 0)
  70189. glyph = findGlyph (defaultCharacter, true);
  70190. }
  70191. }
  70192. return glyph;
  70193. }
  70194. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  70195. {
  70196. return false;
  70197. }
  70198. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  70199. {
  70200. for (int i = 0; i < numCharacters; ++i)
  70201. {
  70202. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  70203. Array <int> glyphIndexes;
  70204. Array <float> offsets;
  70205. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  70206. const int glyphIndex = glyphIndexes.getFirst();
  70207. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  70208. {
  70209. const float glyphWidth = offsets[1];
  70210. Path p;
  70211. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  70212. addGlyph (c, p, glyphWidth);
  70213. for (int j = glyphs.size() - 1; --j >= 0;)
  70214. {
  70215. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  70216. glyphIndexes.clearQuick();
  70217. offsets.clearQuick();
  70218. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  70219. if (offsets.size() > 1)
  70220. addKerningPair (c, char2, offsets[1] - glyphWidth);
  70221. }
  70222. }
  70223. }
  70224. }
  70225. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  70226. {
  70227. GZIPCompressorOutputStream out (&outputStream);
  70228. out.writeString (name);
  70229. out.writeBool (isBold);
  70230. out.writeBool (isItalic);
  70231. out.writeFloat (ascent);
  70232. out.writeShort ((short) (unsigned short) defaultCharacter);
  70233. out.writeInt (glyphs.size());
  70234. int i, numKerningPairs = 0;
  70235. for (i = 0; i < glyphs.size(); ++i)
  70236. {
  70237. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70238. out.writeShort ((short) (unsigned short) g->character);
  70239. out.writeFloat (g->width);
  70240. g->path.writePathToStream (out);
  70241. numKerningPairs += g->kerningPairs.size();
  70242. }
  70243. out.writeInt (numKerningPairs);
  70244. for (i = 0; i < glyphs.size(); ++i)
  70245. {
  70246. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70247. for (int j = 0; j < g->kerningPairs.size(); ++j)
  70248. {
  70249. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  70250. out.writeShort ((short) (unsigned short) g->character);
  70251. out.writeShort ((short) (unsigned short) p.character2);
  70252. out.writeFloat (p.kerningAmount);
  70253. }
  70254. }
  70255. return true;
  70256. }
  70257. float CustomTypeface::getAscent() const
  70258. {
  70259. return ascent;
  70260. }
  70261. float CustomTypeface::getDescent() const
  70262. {
  70263. return 1.0f - ascent;
  70264. }
  70265. float CustomTypeface::getStringWidth (const String& text)
  70266. {
  70267. float x = 0;
  70268. const juce_wchar* t = (const juce_wchar*) text;
  70269. while (*t != 0)
  70270. {
  70271. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  70272. if (glyph != 0)
  70273. x += glyph->getHorizontalSpacing (*t);
  70274. }
  70275. return x;
  70276. }
  70277. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  70278. {
  70279. xOffsets.add (0);
  70280. float x = 0;
  70281. const juce_wchar* t = (const juce_wchar*) text;
  70282. while (*t != 0)
  70283. {
  70284. const juce_wchar c = *t++;
  70285. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  70286. if (glyph != 0)
  70287. {
  70288. x += glyph->getHorizontalSpacing (*t);
  70289. resultGlyphs.add ((int) glyph->character);
  70290. xOffsets.add (x);
  70291. }
  70292. }
  70293. }
  70294. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70295. {
  70296. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70297. if (glyph != 0)
  70298. {
  70299. path = glyph->path;
  70300. return true;
  70301. }
  70302. return false;
  70303. }
  70304. END_JUCE_NAMESPACE
  70305. /*** End of inlined file: juce_Typeface.cpp ***/
  70306. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  70307. BEGIN_JUCE_NAMESPACE
  70308. AffineTransform::AffineTransform() throw()
  70309. : mat00 (1.0f),
  70310. mat01 (0),
  70311. mat02 (0),
  70312. mat10 (0),
  70313. mat11 (1.0f),
  70314. mat12 (0)
  70315. {
  70316. }
  70317. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70318. : mat00 (other.mat00),
  70319. mat01 (other.mat01),
  70320. mat02 (other.mat02),
  70321. mat10 (other.mat10),
  70322. mat11 (other.mat11),
  70323. mat12 (other.mat12)
  70324. {
  70325. }
  70326. AffineTransform::AffineTransform (const float mat00_,
  70327. const float mat01_,
  70328. const float mat02_,
  70329. const float mat10_,
  70330. const float mat11_,
  70331. const float mat12_) throw()
  70332. : mat00 (mat00_),
  70333. mat01 (mat01_),
  70334. mat02 (mat02_),
  70335. mat10 (mat10_),
  70336. mat11 (mat11_),
  70337. mat12 (mat12_)
  70338. {
  70339. }
  70340. AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70341. {
  70342. mat00 = other.mat00;
  70343. mat01 = other.mat01;
  70344. mat02 = other.mat02;
  70345. mat10 = other.mat10;
  70346. mat11 = other.mat11;
  70347. mat12 = other.mat12;
  70348. return *this;
  70349. }
  70350. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70351. {
  70352. return mat00 == other.mat00
  70353. && mat01 == other.mat01
  70354. && mat02 == other.mat02
  70355. && mat10 == other.mat10
  70356. && mat11 == other.mat11
  70357. && mat12 == other.mat12;
  70358. }
  70359. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70360. {
  70361. return ! operator== (other);
  70362. }
  70363. bool AffineTransform::isIdentity() const throw()
  70364. {
  70365. return (mat01 == 0)
  70366. && (mat02 == 0)
  70367. && (mat10 == 0)
  70368. && (mat12 == 0)
  70369. && (mat00 == 1.0f)
  70370. && (mat11 == 1.0f);
  70371. }
  70372. const AffineTransform AffineTransform::identity;
  70373. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70374. {
  70375. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70376. other.mat00 * mat01 + other.mat01 * mat11,
  70377. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70378. other.mat10 * mat00 + other.mat11 * mat10,
  70379. other.mat10 * mat01 + other.mat11 * mat11,
  70380. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70381. }
  70382. const AffineTransform AffineTransform::followedBy (const float omat00,
  70383. const float omat01,
  70384. const float omat02,
  70385. const float omat10,
  70386. const float omat11,
  70387. const float omat12) const throw()
  70388. {
  70389. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70390. omat00 * mat01 + omat01 * mat11,
  70391. omat00 * mat02 + omat01 * mat12 + omat02,
  70392. omat10 * mat00 + omat11 * mat10,
  70393. omat10 * mat01 + omat11 * mat11,
  70394. omat10 * mat02 + omat11 * mat12 + omat12);
  70395. }
  70396. const AffineTransform AffineTransform::translated (const float dx,
  70397. const float dy) const throw()
  70398. {
  70399. return AffineTransform (mat00, mat01, mat02 + dx,
  70400. mat10, mat11, mat12 + dy);
  70401. }
  70402. const AffineTransform AffineTransform::translation (const float dx,
  70403. const float dy) throw()
  70404. {
  70405. return AffineTransform (1.0f, 0, dx,
  70406. 0, 1.0f, dy);
  70407. }
  70408. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70409. {
  70410. const float cosRad = cosf (rad);
  70411. const float sinRad = sinf (rad);
  70412. return followedBy (cosRad, -sinRad, 0,
  70413. sinRad, cosRad, 0);
  70414. }
  70415. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70416. {
  70417. const float cosRad = cosf (rad);
  70418. const float sinRad = sinf (rad);
  70419. return AffineTransform (cosRad, -sinRad, 0,
  70420. sinRad, cosRad, 0);
  70421. }
  70422. const AffineTransform AffineTransform::rotated (const float angle,
  70423. const float pivotX,
  70424. const float pivotY) const throw()
  70425. {
  70426. return translated (-pivotX, -pivotY)
  70427. .rotated (angle)
  70428. .translated (pivotX, pivotY);
  70429. }
  70430. const AffineTransform AffineTransform::rotation (const float angle,
  70431. const float pivotX,
  70432. const float pivotY) throw()
  70433. {
  70434. return translation (-pivotX, -pivotY)
  70435. .rotated (angle)
  70436. .translated (pivotX, pivotY);
  70437. }
  70438. const AffineTransform AffineTransform::scaled (const float factorX,
  70439. const float factorY) const throw()
  70440. {
  70441. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70442. factorY * mat10, factorY * mat11, factorY * mat12);
  70443. }
  70444. const AffineTransform AffineTransform::scale (const float factorX,
  70445. const float factorY) throw()
  70446. {
  70447. return AffineTransform (factorX, 0, 0,
  70448. 0, factorY, 0);
  70449. }
  70450. const AffineTransform AffineTransform::sheared (const float shearX,
  70451. const float shearY) const throw()
  70452. {
  70453. return followedBy (1.0f, shearX, 0,
  70454. shearY, 1.0f, 0);
  70455. }
  70456. const AffineTransform AffineTransform::inverted() const throw()
  70457. {
  70458. double determinant = (mat00 * mat11 - mat10 * mat01);
  70459. if (determinant != 0.0)
  70460. {
  70461. determinant = 1.0 / determinant;
  70462. const float dst00 = (float) (mat11 * determinant);
  70463. const float dst10 = (float) (-mat10 * determinant);
  70464. const float dst01 = (float) (-mat01 * determinant);
  70465. const float dst11 = (float) (mat00 * determinant);
  70466. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70467. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70468. }
  70469. else
  70470. {
  70471. // singularity..
  70472. return *this;
  70473. }
  70474. }
  70475. bool AffineTransform::isSingularity() const throw()
  70476. {
  70477. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70478. }
  70479. bool AffineTransform::isOnlyTranslation() const throw()
  70480. {
  70481. return (mat01 == 0)
  70482. && (mat10 == 0)
  70483. && (mat00 == 1.0f)
  70484. && (mat11 == 1.0f);
  70485. }
  70486. void AffineTransform::transformPoint (float& x,
  70487. float& y) const throw()
  70488. {
  70489. const float oldX = x;
  70490. x = mat00 * oldX + mat01 * y + mat02;
  70491. y = mat10 * oldX + mat11 * y + mat12;
  70492. }
  70493. void AffineTransform::transformPoint (double& x,
  70494. double& y) const throw()
  70495. {
  70496. const double oldX = x;
  70497. x = mat00 * oldX + mat01 * y + mat02;
  70498. y = mat10 * oldX + mat11 * y + mat12;
  70499. }
  70500. END_JUCE_NAMESPACE
  70501. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70502. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70503. BEGIN_JUCE_NAMESPACE
  70504. BorderSize::BorderSize() throw()
  70505. : top (0),
  70506. left (0),
  70507. bottom (0),
  70508. right (0)
  70509. {
  70510. }
  70511. BorderSize::BorderSize (const BorderSize& other) throw()
  70512. : top (other.top),
  70513. left (other.left),
  70514. bottom (other.bottom),
  70515. right (other.right)
  70516. {
  70517. }
  70518. BorderSize::BorderSize (const int topGap,
  70519. const int leftGap,
  70520. const int bottomGap,
  70521. const int rightGap) throw()
  70522. : top (topGap),
  70523. left (leftGap),
  70524. bottom (bottomGap),
  70525. right (rightGap)
  70526. {
  70527. }
  70528. BorderSize::BorderSize (const int allGaps) throw()
  70529. : top (allGaps),
  70530. left (allGaps),
  70531. bottom (allGaps),
  70532. right (allGaps)
  70533. {
  70534. }
  70535. BorderSize::~BorderSize() throw()
  70536. {
  70537. }
  70538. void BorderSize::setTop (const int newTopGap) throw()
  70539. {
  70540. top = newTopGap;
  70541. }
  70542. void BorderSize::setLeft (const int newLeftGap) throw()
  70543. {
  70544. left = newLeftGap;
  70545. }
  70546. void BorderSize::setBottom (const int newBottomGap) throw()
  70547. {
  70548. bottom = newBottomGap;
  70549. }
  70550. void BorderSize::setRight (const int newRightGap) throw()
  70551. {
  70552. right = newRightGap;
  70553. }
  70554. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70555. {
  70556. return Rectangle<int> (r.getX() + left,
  70557. r.getY() + top,
  70558. r.getWidth() - (left + right),
  70559. r.getHeight() - (top + bottom));
  70560. }
  70561. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70562. {
  70563. r.setBounds (r.getX() + left,
  70564. r.getY() + top,
  70565. r.getWidth() - (left + right),
  70566. r.getHeight() - (top + bottom));
  70567. }
  70568. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70569. {
  70570. return Rectangle<int> (r.getX() - left,
  70571. r.getY() - top,
  70572. r.getWidth() + (left + right),
  70573. r.getHeight() + (top + bottom));
  70574. }
  70575. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70576. {
  70577. r.setBounds (r.getX() - left,
  70578. r.getY() - top,
  70579. r.getWidth() + (left + right),
  70580. r.getHeight() + (top + bottom));
  70581. }
  70582. bool BorderSize::operator== (const BorderSize& other) const throw()
  70583. {
  70584. return top == other.top
  70585. && left == other.left
  70586. && bottom == other.bottom
  70587. && right == other.right;
  70588. }
  70589. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70590. {
  70591. return ! operator== (other);
  70592. }
  70593. END_JUCE_NAMESPACE
  70594. /*** End of inlined file: juce_BorderSize.cpp ***/
  70595. /*** Start of inlined file: juce_Line.cpp ***/
  70596. BEGIN_JUCE_NAMESPACE
  70597. static bool juce_lineIntersection (const float x1, const float y1,
  70598. const float x2, const float y2,
  70599. const float x3, const float y3,
  70600. const float x4, const float y4,
  70601. float& intersectionX,
  70602. float& intersectionY) throw()
  70603. {
  70604. if (x2 != x3 || y2 != y3)
  70605. {
  70606. const float dx1 = x2 - x1;
  70607. const float dy1 = y2 - y1;
  70608. const float dx2 = x4 - x3;
  70609. const float dy2 = y4 - y3;
  70610. const float divisor = dx1 * dy2 - dx2 * dy1;
  70611. if (divisor == 0)
  70612. {
  70613. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70614. {
  70615. if (dy1 == 0 && dy2 != 0)
  70616. {
  70617. const float along = (y1 - y3) / dy2;
  70618. intersectionX = x3 + along * dx2;
  70619. intersectionY = y1;
  70620. return along >= 0 && along <= 1.0f;
  70621. }
  70622. else if (dy2 == 0 && dy1 != 0)
  70623. {
  70624. const float along = (y3 - y1) / dy1;
  70625. intersectionX = x1 + along * dx1;
  70626. intersectionY = y3;
  70627. return along >= 0 && along <= 1.0f;
  70628. }
  70629. else if (dx1 == 0 && dx2 != 0)
  70630. {
  70631. const float along = (x1 - x3) / dx2;
  70632. intersectionX = x1;
  70633. intersectionY = y3 + along * dy2;
  70634. return along >= 0 && along <= 1.0f;
  70635. }
  70636. else if (dx2 == 0 && dx1 != 0)
  70637. {
  70638. const float along = (x3 - x1) / dx1;
  70639. intersectionX = x3;
  70640. intersectionY = y1 + along * dy1;
  70641. return along >= 0 && along <= 1.0f;
  70642. }
  70643. }
  70644. intersectionX = 0.5f * (x2 + x3);
  70645. intersectionY = 0.5f * (y2 + y3);
  70646. return false;
  70647. }
  70648. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70649. intersectionX = x1 + along1 * dx1;
  70650. intersectionY = y1 + along1 * dy1;
  70651. if (along1 < 0 || along1 > 1.0f)
  70652. return false;
  70653. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70654. return along2 >= 0 && along2 <= 1.0f;
  70655. }
  70656. intersectionX = x2;
  70657. intersectionY = y2;
  70658. return true;
  70659. }
  70660. Line::Line() throw()
  70661. : startX (0.0f),
  70662. startY (0.0f),
  70663. endX (0.0f),
  70664. endY (0.0f)
  70665. {
  70666. }
  70667. Line::Line (const Line& other) throw()
  70668. : startX (other.startX),
  70669. startY (other.startY),
  70670. endX (other.endX),
  70671. endY (other.endY)
  70672. {
  70673. }
  70674. Line::Line (const float startX_, const float startY_,
  70675. const float endX_, const float endY_) throw()
  70676. : startX (startX_),
  70677. startY (startY_),
  70678. endX (endX_),
  70679. endY (endY_)
  70680. {
  70681. }
  70682. Line::Line (const Point<float>& start,
  70683. const Point<float>& end) throw()
  70684. : startX (start.getX()),
  70685. startY (start.getY()),
  70686. endX (end.getX()),
  70687. endY (end.getY())
  70688. {
  70689. }
  70690. Line& Line::operator= (const Line& other) throw()
  70691. {
  70692. startX = other.startX;
  70693. startY = other.startY;
  70694. endX = other.endX;
  70695. endY = other.endY;
  70696. return *this;
  70697. }
  70698. Line::~Line() throw()
  70699. {
  70700. }
  70701. const Point<float> Line::getStart() const throw()
  70702. {
  70703. return Point<float> (startX, startY);
  70704. }
  70705. const Point<float> Line::getEnd() const throw()
  70706. {
  70707. return Point<float> (endX, endY);
  70708. }
  70709. void Line::setStart (const float newStartX,
  70710. const float newStartY) throw()
  70711. {
  70712. startX = newStartX;
  70713. startY = newStartY;
  70714. }
  70715. void Line::setStart (const Point<float>& newStart) throw()
  70716. {
  70717. startX = newStart.getX();
  70718. startY = newStart.getY();
  70719. }
  70720. void Line::setEnd (const float newEndX,
  70721. const float newEndY) throw()
  70722. {
  70723. endX = newEndX;
  70724. endY = newEndY;
  70725. }
  70726. void Line::setEnd (const Point<float>& newEnd) throw()
  70727. {
  70728. endX = newEnd.getX();
  70729. endY = newEnd.getY();
  70730. }
  70731. bool Line::operator== (const Line& other) const throw()
  70732. {
  70733. return startX == other.startX
  70734. && startY == other.startY
  70735. && endX == other.endX
  70736. && endY == other.endY;
  70737. }
  70738. bool Line::operator!= (const Line& other) const throw()
  70739. {
  70740. return startX != other.startX
  70741. || startY != other.startY
  70742. || endX != other.endX
  70743. || endY != other.endY;
  70744. }
  70745. void Line::applyTransform (const AffineTransform& transform) throw()
  70746. {
  70747. transform.transformPoint (startX, startY);
  70748. transform.transformPoint (endX, endY);
  70749. }
  70750. float Line::getLength() const throw()
  70751. {
  70752. return (float) juce_hypot (startX - endX,
  70753. startY - endY);
  70754. }
  70755. float Line::getAngle() const throw()
  70756. {
  70757. return atan2f (endX - startX,
  70758. endY - startY);
  70759. }
  70760. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  70761. {
  70762. const float alpha = distanceFromStart / getLength();
  70763. return Point<float> (startX + (endX - startX) * alpha,
  70764. startY + (endY - startY) * alpha);
  70765. }
  70766. const Point<float> Line::getPointAlongLine (const float offsetX,
  70767. const float offsetY) const throw()
  70768. {
  70769. const float dx = endX - startX;
  70770. const float dy = endY - startY;
  70771. const double length = juce_hypot (dx, dy);
  70772. if (length == 0)
  70773. return Point<float> (startX, startY);
  70774. else
  70775. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  70776. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  70777. }
  70778. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  70779. {
  70780. return Point<float> (startX + (endX - startX) * alpha,
  70781. startY + (endY - startY) * alpha);
  70782. }
  70783. float Line::getDistanceFromLine (const float x,
  70784. const float y) const throw()
  70785. {
  70786. const double dx = endX - startX;
  70787. const double dy = endY - startY;
  70788. const double length = dx * dx + dy * dy;
  70789. if (length > 0)
  70790. {
  70791. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  70792. if (prop >= 0.0f && prop < 1.0f)
  70793. {
  70794. return (float) juce_hypot (x - (startX + prop * dx),
  70795. y - (startY + prop * dy));
  70796. }
  70797. }
  70798. return (float) jmin (juce_hypot (x - startX, y - startY),
  70799. juce_hypot (x - endX, y - endY));
  70800. }
  70801. float Line::findNearestPointTo (const float x,
  70802. const float y) const throw()
  70803. {
  70804. const double dx = endX - startX;
  70805. const double dy = endY - startY;
  70806. const double length = dx * dx + dy * dy;
  70807. if (length <= 0.0)
  70808. return 0.0f;
  70809. return jlimit (0.0f, 1.0f,
  70810. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  70811. }
  70812. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  70813. {
  70814. const float length = getLength();
  70815. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  70816. getEnd());
  70817. }
  70818. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  70819. {
  70820. const float length = getLength();
  70821. return Line (getStart(),
  70822. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  70823. }
  70824. bool Line::clipToPath (const Path& path,
  70825. const bool keepSectionOutsidePath) throw()
  70826. {
  70827. const bool startInside = path.contains (startX, startY);
  70828. const bool endInside = path.contains (endX, endY);
  70829. if (startInside == endInside)
  70830. {
  70831. if (keepSectionOutsidePath != startInside)
  70832. {
  70833. // entirely outside the path
  70834. return false;
  70835. }
  70836. else
  70837. {
  70838. // entirely inside the path
  70839. startX = 0.0f;
  70840. startY = 0.0f;
  70841. endX = 0.0f;
  70842. endY = 0.0f;
  70843. return true;
  70844. }
  70845. }
  70846. else
  70847. {
  70848. bool changed = false;
  70849. PathFlatteningIterator iter (path, AffineTransform::identity);
  70850. while (iter.next())
  70851. {
  70852. float ix, iy;
  70853. if (intersects (Line (iter.x1, iter.y1,
  70854. iter.x2, iter.y2),
  70855. ix, iy))
  70856. {
  70857. if ((startInside && keepSectionOutsidePath)
  70858. || (endInside && ! keepSectionOutsidePath))
  70859. {
  70860. setStart (ix, iy);
  70861. }
  70862. else
  70863. {
  70864. setEnd (ix, iy);
  70865. }
  70866. changed = true;
  70867. }
  70868. }
  70869. return changed;
  70870. }
  70871. }
  70872. bool Line::intersects (const Line& line,
  70873. float& intersectionX,
  70874. float& intersectionY) const throw()
  70875. {
  70876. return juce_lineIntersection (startX, startY,
  70877. endX, endY,
  70878. line.startX, line.startY,
  70879. line.endX, line.endY,
  70880. intersectionX,
  70881. intersectionY);
  70882. }
  70883. bool Line::isVertical() const throw()
  70884. {
  70885. return startX == endX;
  70886. }
  70887. bool Line::isHorizontal() const throw()
  70888. {
  70889. return startY == endY;
  70890. }
  70891. bool Line::isPointAbove (const float x, const float y) const throw()
  70892. {
  70893. return startX != endX
  70894. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  70895. }
  70896. END_JUCE_NAMESPACE
  70897. /*** End of inlined file: juce_Line.cpp ***/
  70898. /*** Start of inlined file: juce_Path.cpp ***/
  70899. BEGIN_JUCE_NAMESPACE
  70900. // tests that some co-ords aren't NaNs
  70901. #define CHECK_COORDS_ARE_VALID(x, y) \
  70902. jassert (x == x && y == y);
  70903. const float Path::lineMarker = 100001.0f;
  70904. const float Path::moveMarker = 100002.0f;
  70905. const float Path::quadMarker = 100003.0f;
  70906. const float Path::cubicMarker = 100004.0f;
  70907. const float Path::closeSubPathMarker = 100005.0f;
  70908. static const int defaultGranularity = 32;
  70909. Path::Path() throw()
  70910. : numElements (0),
  70911. pathXMin (0),
  70912. pathXMax (0),
  70913. pathYMin (0),
  70914. pathYMax (0),
  70915. useNonZeroWinding (true)
  70916. {
  70917. }
  70918. Path::~Path() throw()
  70919. {
  70920. }
  70921. Path::Path (const Path& other) throw()
  70922. : numElements (other.numElements),
  70923. pathXMin (other.pathXMin),
  70924. pathXMax (other.pathXMax),
  70925. pathYMin (other.pathYMin),
  70926. pathYMax (other.pathYMax),
  70927. useNonZeroWinding (other.useNonZeroWinding)
  70928. {
  70929. if (numElements > 0)
  70930. {
  70931. data.setAllocatedSize (numElements);
  70932. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70933. }
  70934. }
  70935. Path& Path::operator= (const Path& other) throw()
  70936. {
  70937. if (this != &other)
  70938. {
  70939. data.ensureAllocatedSize (other.numElements);
  70940. numElements = other.numElements;
  70941. pathXMin = other.pathXMin;
  70942. pathXMax = other.pathXMax;
  70943. pathYMin = other.pathYMin;
  70944. pathYMax = other.pathYMax;
  70945. useNonZeroWinding = other.useNonZeroWinding;
  70946. if (numElements > 0)
  70947. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70948. }
  70949. return *this;
  70950. }
  70951. void Path::clear() throw()
  70952. {
  70953. numElements = 0;
  70954. pathXMin = 0;
  70955. pathYMin = 0;
  70956. pathYMax = 0;
  70957. pathXMax = 0;
  70958. }
  70959. void Path::swapWithPath (Path& other)
  70960. {
  70961. data.swapWith (other.data);
  70962. swapVariables <int> (numElements, other.numElements);
  70963. swapVariables <float> (pathXMin, other.pathXMin);
  70964. swapVariables <float> (pathXMax, other.pathXMax);
  70965. swapVariables <float> (pathYMin, other.pathYMin);
  70966. swapVariables <float> (pathYMax, other.pathYMax);
  70967. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  70968. }
  70969. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  70970. {
  70971. useNonZeroWinding = isNonZero;
  70972. }
  70973. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  70974. const bool preserveProportions) throw()
  70975. {
  70976. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  70977. }
  70978. bool Path::isEmpty() const throw()
  70979. {
  70980. int i = 0;
  70981. while (i < numElements)
  70982. {
  70983. const float type = data.elements [i++];
  70984. if (type == moveMarker)
  70985. {
  70986. i += 2;
  70987. }
  70988. else if (type == lineMarker
  70989. || type == quadMarker
  70990. || type == cubicMarker)
  70991. {
  70992. return false;
  70993. }
  70994. }
  70995. return true;
  70996. }
  70997. const Rectangle<float> Path::getBounds () const throw()
  70998. {
  70999. return Rectangle<float> (pathXMin, pathYMin,
  71000. pathXMax - pathXMin,
  71001. pathYMax - pathYMin);
  71002. }
  71003. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  71004. {
  71005. return getBounds().transformed (transform);
  71006. }
  71007. void Path::startNewSubPath (const float x,
  71008. const float y) throw()
  71009. {
  71010. CHECK_COORDS_ARE_VALID (x, y);
  71011. if (numElements == 0)
  71012. {
  71013. pathXMin = pathXMax = x;
  71014. pathYMin = pathYMax = y;
  71015. }
  71016. else
  71017. {
  71018. pathXMin = jmin (pathXMin, x);
  71019. pathXMax = jmax (pathXMax, x);
  71020. pathYMin = jmin (pathYMin, y);
  71021. pathYMax = jmax (pathYMax, y);
  71022. }
  71023. data.ensureAllocatedSize (numElements + 3);
  71024. data.elements [numElements++] = moveMarker;
  71025. data.elements [numElements++] = x;
  71026. data.elements [numElements++] = y;
  71027. }
  71028. void Path::lineTo (const float x, const float y) throw()
  71029. {
  71030. CHECK_COORDS_ARE_VALID (x, y);
  71031. if (numElements == 0)
  71032. startNewSubPath (0, 0);
  71033. data.ensureAllocatedSize (numElements + 3);
  71034. data.elements [numElements++] = lineMarker;
  71035. data.elements [numElements++] = x;
  71036. data.elements [numElements++] = y;
  71037. pathXMin = jmin (pathXMin, x);
  71038. pathXMax = jmax (pathXMax, x);
  71039. pathYMin = jmin (pathYMin, y);
  71040. pathYMax = jmax (pathYMax, y);
  71041. }
  71042. void Path::quadraticTo (const float x1, const float y1,
  71043. const float x2, const float y2) throw()
  71044. {
  71045. CHECK_COORDS_ARE_VALID (x1, y1);
  71046. CHECK_COORDS_ARE_VALID (x2, y2);
  71047. if (numElements == 0)
  71048. startNewSubPath (0, 0);
  71049. data.ensureAllocatedSize (numElements + 5);
  71050. data.elements [numElements++] = quadMarker;
  71051. data.elements [numElements++] = x1;
  71052. data.elements [numElements++] = y1;
  71053. data.elements [numElements++] = x2;
  71054. data.elements [numElements++] = y2;
  71055. pathXMin = jmin (pathXMin, x1, x2);
  71056. pathXMax = jmax (pathXMax, x1, x2);
  71057. pathYMin = jmin (pathYMin, y1, y2);
  71058. pathYMax = jmax (pathYMax, y1, y2);
  71059. }
  71060. void Path::cubicTo (const float x1, const float y1,
  71061. const float x2, const float y2,
  71062. const float x3, const float y3) throw()
  71063. {
  71064. CHECK_COORDS_ARE_VALID (x1, y1);
  71065. CHECK_COORDS_ARE_VALID (x2, y2);
  71066. CHECK_COORDS_ARE_VALID (x3, y3);
  71067. if (numElements == 0)
  71068. startNewSubPath (0, 0);
  71069. data.ensureAllocatedSize (numElements + 7);
  71070. data.elements [numElements++] = cubicMarker;
  71071. data.elements [numElements++] = x1;
  71072. data.elements [numElements++] = y1;
  71073. data.elements [numElements++] = x2;
  71074. data.elements [numElements++] = y2;
  71075. data.elements [numElements++] = x3;
  71076. data.elements [numElements++] = y3;
  71077. pathXMin = jmin (pathXMin, x1, x2, x3);
  71078. pathXMax = jmax (pathXMax, x1, x2, x3);
  71079. pathYMin = jmin (pathYMin, y1, y2, y3);
  71080. pathYMax = jmax (pathYMax, y1, y2, y3);
  71081. }
  71082. void Path::closeSubPath() throw()
  71083. {
  71084. if (numElements > 0
  71085. && data.elements [numElements - 1] != closeSubPathMarker)
  71086. {
  71087. data.ensureAllocatedSize (numElements + 1);
  71088. data.elements [numElements++] = closeSubPathMarker;
  71089. }
  71090. }
  71091. const Point<float> Path::getCurrentPosition() const
  71092. {
  71093. int i = numElements - 1;
  71094. if (i > 0 && data.elements[i] == closeSubPathMarker)
  71095. {
  71096. while (i >= 0)
  71097. {
  71098. if (data.elements[i] == moveMarker)
  71099. {
  71100. i += 2;
  71101. break;
  71102. }
  71103. --i;
  71104. }
  71105. }
  71106. if (i > 0)
  71107. return Point<float> (data.elements [i - 1], data.elements [i]);
  71108. return Point<float>();
  71109. }
  71110. void Path::addRectangle (const float x, const float y,
  71111. const float w, const float h) throw()
  71112. {
  71113. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  71114. if (w < 0)
  71115. swapVariables (x1, x2);
  71116. if (h < 0)
  71117. swapVariables (y1, y2);
  71118. data.ensureAllocatedSize (numElements + 13);
  71119. if (numElements == 0)
  71120. {
  71121. pathXMin = x1;
  71122. pathXMax = x2;
  71123. pathYMin = y1;
  71124. pathYMax = y2;
  71125. }
  71126. else
  71127. {
  71128. pathXMin = jmin (pathXMin, x1);
  71129. pathXMax = jmax (pathXMax, x2);
  71130. pathYMin = jmin (pathYMin, y1);
  71131. pathYMax = jmax (pathYMax, y2);
  71132. }
  71133. data.elements [numElements++] = moveMarker;
  71134. data.elements [numElements++] = x1;
  71135. data.elements [numElements++] = y2;
  71136. data.elements [numElements++] = lineMarker;
  71137. data.elements [numElements++] = x1;
  71138. data.elements [numElements++] = y1;
  71139. data.elements [numElements++] = lineMarker;
  71140. data.elements [numElements++] = x2;
  71141. data.elements [numElements++] = y1;
  71142. data.elements [numElements++] = lineMarker;
  71143. data.elements [numElements++] = x2;
  71144. data.elements [numElements++] = y2;
  71145. data.elements [numElements++] = closeSubPathMarker;
  71146. }
  71147. void Path::addRectangle (const Rectangle<int>& rectangle) throw()
  71148. {
  71149. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  71150. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  71151. }
  71152. void Path::addRoundedRectangle (const float x, const float y,
  71153. const float w, const float h,
  71154. float csx,
  71155. float csy) throw()
  71156. {
  71157. csx = jmin (csx, w * 0.5f);
  71158. csy = jmin (csy, h * 0.5f);
  71159. const float cs45x = csx * 0.45f;
  71160. const float cs45y = csy * 0.45f;
  71161. const float x2 = x + w;
  71162. const float y2 = y + h;
  71163. startNewSubPath (x + csx, y);
  71164. lineTo (x2 - csx, y);
  71165. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  71166. lineTo (x2, y2 - csy);
  71167. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  71168. lineTo (x + csx, y2);
  71169. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  71170. lineTo (x, y + csy);
  71171. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  71172. closeSubPath();
  71173. }
  71174. void Path::addRoundedRectangle (const float x, const float y,
  71175. const float w, const float h,
  71176. float cs) throw()
  71177. {
  71178. addRoundedRectangle (x, y, w, h, cs, cs);
  71179. }
  71180. void Path::addTriangle (const float x1, const float y1,
  71181. const float x2, const float y2,
  71182. const float x3, const float y3) throw()
  71183. {
  71184. startNewSubPath (x1, y1);
  71185. lineTo (x2, y2);
  71186. lineTo (x3, y3);
  71187. closeSubPath();
  71188. }
  71189. void Path::addQuadrilateral (const float x1, const float y1,
  71190. const float x2, const float y2,
  71191. const float x3, const float y3,
  71192. const float x4, const float y4) throw()
  71193. {
  71194. startNewSubPath (x1, y1);
  71195. lineTo (x2, y2);
  71196. lineTo (x3, y3);
  71197. lineTo (x4, y4);
  71198. closeSubPath();
  71199. }
  71200. void Path::addEllipse (const float x, const float y,
  71201. const float w, const float h) throw()
  71202. {
  71203. const float hw = w * 0.5f;
  71204. const float hw55 = hw * 0.55f;
  71205. const float hh = h * 0.5f;
  71206. const float hh45 = hh * 0.55f;
  71207. const float cx = x + hw;
  71208. const float cy = y + hh;
  71209. startNewSubPath (cx, cy - hh);
  71210. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  71211. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  71212. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  71213. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  71214. closeSubPath();
  71215. }
  71216. void Path::addArc (const float x, const float y,
  71217. const float w, const float h,
  71218. const float fromRadians,
  71219. const float toRadians,
  71220. const bool startAsNewSubPath) throw()
  71221. {
  71222. const float radiusX = w / 2.0f;
  71223. const float radiusY = h / 2.0f;
  71224. addCentredArc (x + radiusX,
  71225. y + radiusY,
  71226. radiusX, radiusY,
  71227. 0.0f,
  71228. fromRadians, toRadians,
  71229. startAsNewSubPath);
  71230. }
  71231. static const float ellipseAngularIncrement = 0.05f;
  71232. void Path::addCentredArc (const float centreX, const float centreY,
  71233. const float radiusX, const float radiusY,
  71234. const float rotationOfEllipse,
  71235. const float fromRadians,
  71236. const float toRadians,
  71237. const bool startAsNewSubPath) throw()
  71238. {
  71239. if (radiusX > 0.0f && radiusY > 0.0f)
  71240. {
  71241. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  71242. float angle = fromRadians;
  71243. if (startAsNewSubPath)
  71244. {
  71245. float x = centreX + radiusX * sinf (angle);
  71246. float y = centreY - radiusY * cosf (angle);
  71247. if (rotationOfEllipse != 0)
  71248. rotation.transformPoint (x, y);
  71249. startNewSubPath (x, y);
  71250. }
  71251. if (fromRadians < toRadians)
  71252. {
  71253. if (startAsNewSubPath)
  71254. angle += ellipseAngularIncrement;
  71255. while (angle < toRadians)
  71256. {
  71257. float x = centreX + radiusX * sinf (angle);
  71258. float y = centreY - radiusY * cosf (angle);
  71259. if (rotationOfEllipse != 0)
  71260. rotation.transformPoint (x, y);
  71261. lineTo (x, y);
  71262. angle += ellipseAngularIncrement;
  71263. }
  71264. }
  71265. else
  71266. {
  71267. if (startAsNewSubPath)
  71268. angle -= ellipseAngularIncrement;
  71269. while (angle > toRadians)
  71270. {
  71271. float x = centreX + radiusX * sinf (angle);
  71272. float y = centreY - radiusY * cosf (angle);
  71273. if (rotationOfEllipse != 0)
  71274. rotation.transformPoint (x, y);
  71275. lineTo (x, y);
  71276. angle -= ellipseAngularIncrement;
  71277. }
  71278. }
  71279. float x = centreX + radiusX * sinf (toRadians);
  71280. float y = centreY - radiusY * cosf (toRadians);
  71281. if (rotationOfEllipse != 0)
  71282. rotation.transformPoint (x, y);
  71283. lineTo (x, y);
  71284. }
  71285. }
  71286. void Path::addPieSegment (const float x, const float y,
  71287. const float width, const float height,
  71288. const float fromRadians,
  71289. const float toRadians,
  71290. const float innerCircleProportionalSize)
  71291. {
  71292. float hw = width * 0.5f;
  71293. float hh = height * 0.5f;
  71294. const float centreX = x + hw;
  71295. const float centreY = y + hh;
  71296. startNewSubPath (centreX + hw * sinf (fromRadians),
  71297. centreY - hh * cosf (fromRadians));
  71298. addArc (x, y, width, height, fromRadians, toRadians);
  71299. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71300. {
  71301. closeSubPath();
  71302. if (innerCircleProportionalSize > 0)
  71303. {
  71304. hw *= innerCircleProportionalSize;
  71305. hh *= innerCircleProportionalSize;
  71306. startNewSubPath (centreX + hw * sinf (toRadians),
  71307. centreY - hh * cosf (toRadians));
  71308. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71309. toRadians, fromRadians);
  71310. }
  71311. }
  71312. else
  71313. {
  71314. if (innerCircleProportionalSize > 0)
  71315. {
  71316. hw *= innerCircleProportionalSize;
  71317. hh *= innerCircleProportionalSize;
  71318. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71319. toRadians, fromRadians);
  71320. }
  71321. else
  71322. {
  71323. lineTo (centreX, centreY);
  71324. }
  71325. }
  71326. closeSubPath();
  71327. }
  71328. static void perpendicularOffset (const float x1, const float y1,
  71329. const float x2, const float y2,
  71330. const float offsetX, const float offsetY,
  71331. float& resultX, float& resultY) throw()
  71332. {
  71333. const float dx = x2 - x1;
  71334. const float dy = y2 - y1;
  71335. const float len = juce_hypotf (dx, dy);
  71336. if (len == 0)
  71337. {
  71338. resultX = x1;
  71339. resultY = y1;
  71340. }
  71341. else
  71342. {
  71343. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  71344. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  71345. }
  71346. }
  71347. void Path::addLineSegment (const float startX, const float startY,
  71348. const float endX, const float endY,
  71349. float lineThickness) throw()
  71350. {
  71351. lineThickness *= 0.5f;
  71352. float x, y;
  71353. perpendicularOffset (startX, startY, endX, endY,
  71354. 0, lineThickness, x, y);
  71355. startNewSubPath (x, y);
  71356. perpendicularOffset (startX, startY, endX, endY,
  71357. 0, -lineThickness, x, y);
  71358. lineTo (x, y);
  71359. perpendicularOffset (endX, endY, startX, startY,
  71360. 0, lineThickness, x, y);
  71361. lineTo (x, y);
  71362. perpendicularOffset (endX, endY, startX, startY,
  71363. 0, -lineThickness, x, y);
  71364. lineTo (x, y);
  71365. closeSubPath();
  71366. }
  71367. void Path::addArrow (const float startX, const float startY,
  71368. const float endX, const float endY,
  71369. float lineThickness,
  71370. float arrowheadWidth,
  71371. float arrowheadLength) throw()
  71372. {
  71373. lineThickness *= 0.5f;
  71374. arrowheadWidth *= 0.5f;
  71375. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71376. startY - endY));
  71377. float x, y;
  71378. perpendicularOffset (startX, startY, endX, endY,
  71379. 0, lineThickness, x, y);
  71380. startNewSubPath (x, y);
  71381. perpendicularOffset (startX, startY, endX, endY,
  71382. 0, -lineThickness, x, y);
  71383. lineTo (x, y);
  71384. perpendicularOffset (endX, endY, startX, startY,
  71385. arrowheadLength, lineThickness, x, y);
  71386. lineTo (x, y);
  71387. perpendicularOffset (endX, endY, startX, startY,
  71388. arrowheadLength, arrowheadWidth, x, y);
  71389. lineTo (x, y);
  71390. perpendicularOffset (endX, endY, startX, startY,
  71391. 0, 0, x, y);
  71392. lineTo (x, y);
  71393. perpendicularOffset (endX, endY, startX, startY,
  71394. arrowheadLength, -arrowheadWidth, x, y);
  71395. lineTo (x, y);
  71396. perpendicularOffset (endX, endY, startX, startY,
  71397. arrowheadLength, -lineThickness, x, y);
  71398. lineTo (x, y);
  71399. closeSubPath();
  71400. }
  71401. void Path::addStar (const float centreX,
  71402. const float centreY,
  71403. const int numberOfPoints,
  71404. const float innerRadius,
  71405. const float outerRadius,
  71406. const float startAngle)
  71407. {
  71408. jassert (numberOfPoints > 1); // this would be silly.
  71409. if (numberOfPoints > 1)
  71410. {
  71411. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71412. for (int i = 0; i < numberOfPoints; ++i)
  71413. {
  71414. float angle = startAngle + i * angleBetweenPoints;
  71415. const float x = centreX + outerRadius * sinf (angle);
  71416. const float y = centreY - outerRadius * cosf (angle);
  71417. if (i == 0)
  71418. startNewSubPath (x, y);
  71419. else
  71420. lineTo (x, y);
  71421. angle += angleBetweenPoints * 0.5f;
  71422. lineTo (centreX + innerRadius * sinf (angle),
  71423. centreY - innerRadius * cosf (angle));
  71424. }
  71425. closeSubPath();
  71426. }
  71427. }
  71428. void Path::addBubble (float x, float y,
  71429. float w, float h,
  71430. float cs,
  71431. float tipX,
  71432. float tipY,
  71433. int whichSide,
  71434. float arrowPos,
  71435. float arrowWidth)
  71436. {
  71437. if (w > 1.0f && h > 1.0f)
  71438. {
  71439. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71440. const float cs2 = 2.0f * cs;
  71441. startNewSubPath (x + cs, y);
  71442. if (whichSide == 0)
  71443. {
  71444. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71445. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71446. lineTo (arrowX1, y);
  71447. lineTo (tipX, tipY);
  71448. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71449. }
  71450. lineTo (x + w - cs, y);
  71451. if (cs > 0.0f)
  71452. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71453. if (whichSide == 3)
  71454. {
  71455. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71456. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71457. lineTo (x + w, arrowY1);
  71458. lineTo (tipX, tipY);
  71459. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71460. }
  71461. lineTo (x + w, y + h - cs);
  71462. if (cs > 0.0f)
  71463. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71464. if (whichSide == 2)
  71465. {
  71466. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71467. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71468. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71469. lineTo (tipX, tipY);
  71470. lineTo (arrowX1, y + h);
  71471. }
  71472. lineTo (x + cs, y + h);
  71473. if (cs > 0.0f)
  71474. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71475. if (whichSide == 1)
  71476. {
  71477. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71478. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71479. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71480. lineTo (tipX, tipY);
  71481. lineTo (x, arrowY1);
  71482. }
  71483. lineTo (x, y + cs);
  71484. if (cs > 0.0f)
  71485. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - ellipseAngularIncrement);
  71486. closeSubPath();
  71487. }
  71488. }
  71489. void Path::addPath (const Path& other) throw()
  71490. {
  71491. int i = 0;
  71492. while (i < other.numElements)
  71493. {
  71494. const float type = other.data.elements [i++];
  71495. if (type == moveMarker)
  71496. {
  71497. startNewSubPath (other.data.elements [i],
  71498. other.data.elements [i + 1]);
  71499. i += 2;
  71500. }
  71501. else if (type == lineMarker)
  71502. {
  71503. lineTo (other.data.elements [i],
  71504. other.data.elements [i + 1]);
  71505. i += 2;
  71506. }
  71507. else if (type == quadMarker)
  71508. {
  71509. quadraticTo (other.data.elements [i],
  71510. other.data.elements [i + 1],
  71511. other.data.elements [i + 2],
  71512. other.data.elements [i + 3]);
  71513. i += 4;
  71514. }
  71515. else if (type == cubicMarker)
  71516. {
  71517. cubicTo (other.data.elements [i],
  71518. other.data.elements [i + 1],
  71519. other.data.elements [i + 2],
  71520. other.data.elements [i + 3],
  71521. other.data.elements [i + 4],
  71522. other.data.elements [i + 5]);
  71523. i += 6;
  71524. }
  71525. else if (type == closeSubPathMarker)
  71526. {
  71527. closeSubPath();
  71528. }
  71529. else
  71530. {
  71531. // something's gone wrong with the element list!
  71532. jassertfalse
  71533. }
  71534. }
  71535. }
  71536. void Path::addPath (const Path& other,
  71537. const AffineTransform& transformToApply) throw()
  71538. {
  71539. int i = 0;
  71540. while (i < other.numElements)
  71541. {
  71542. const float type = other.data.elements [i++];
  71543. if (type == closeSubPathMarker)
  71544. {
  71545. closeSubPath();
  71546. }
  71547. else
  71548. {
  71549. float x = other.data.elements [i++];
  71550. float y = other.data.elements [i++];
  71551. transformToApply.transformPoint (x, y);
  71552. if (type == moveMarker)
  71553. {
  71554. startNewSubPath (x, y);
  71555. }
  71556. else if (type == lineMarker)
  71557. {
  71558. lineTo (x, y);
  71559. }
  71560. else if (type == quadMarker)
  71561. {
  71562. float x2 = other.data.elements [i++];
  71563. float y2 = other.data.elements [i++];
  71564. transformToApply.transformPoint (x2, y2);
  71565. quadraticTo (x, y, x2, y2);
  71566. }
  71567. else if (type == cubicMarker)
  71568. {
  71569. float x2 = other.data.elements [i++];
  71570. float y2 = other.data.elements [i++];
  71571. float x3 = other.data.elements [i++];
  71572. float y3 = other.data.elements [i++];
  71573. transformToApply.transformPoint (x2, y2);
  71574. transformToApply.transformPoint (x3, y3);
  71575. cubicTo (x, y, x2, y2, x3, y3);
  71576. }
  71577. else
  71578. {
  71579. // something's gone wrong with the element list!
  71580. jassertfalse
  71581. }
  71582. }
  71583. }
  71584. }
  71585. void Path::applyTransform (const AffineTransform& transform) throw()
  71586. {
  71587. int i = 0;
  71588. pathYMin = pathXMin = 0;
  71589. pathYMax = pathXMax = 0;
  71590. bool setMaxMin = false;
  71591. while (i < numElements)
  71592. {
  71593. const float type = data.elements [i++];
  71594. if (type == moveMarker)
  71595. {
  71596. transform.transformPoint (data.elements [i],
  71597. data.elements [i + 1]);
  71598. if (setMaxMin)
  71599. {
  71600. pathXMin = jmin (pathXMin, data.elements [i]);
  71601. pathXMax = jmax (pathXMax, data.elements [i]);
  71602. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71603. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71604. }
  71605. else
  71606. {
  71607. pathXMin = pathXMax = data.elements [i];
  71608. pathYMin = pathYMax = data.elements [i + 1];
  71609. setMaxMin = true;
  71610. }
  71611. i += 2;
  71612. }
  71613. else if (type == lineMarker)
  71614. {
  71615. transform.transformPoint (data.elements [i],
  71616. data.elements [i + 1]);
  71617. pathXMin = jmin (pathXMin, data.elements [i]);
  71618. pathXMax = jmax (pathXMax, data.elements [i]);
  71619. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71620. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71621. i += 2;
  71622. }
  71623. else if (type == quadMarker)
  71624. {
  71625. transform.transformPoint (data.elements [i],
  71626. data.elements [i + 1]);
  71627. transform.transformPoint (data.elements [i + 2],
  71628. data.elements [i + 3]);
  71629. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71630. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71631. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71632. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71633. i += 4;
  71634. }
  71635. else if (type == cubicMarker)
  71636. {
  71637. transform.transformPoint (data.elements [i],
  71638. data.elements [i + 1]);
  71639. transform.transformPoint (data.elements [i + 2],
  71640. data.elements [i + 3]);
  71641. transform.transformPoint (data.elements [i + 4],
  71642. data.elements [i + 5]);
  71643. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71644. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71645. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71646. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71647. i += 6;
  71648. }
  71649. }
  71650. }
  71651. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71652. const float w, const float h,
  71653. const bool preserveProportions,
  71654. const Justification& justification) const throw()
  71655. {
  71656. Rectangle<float> bounds (getBounds());
  71657. if (preserveProportions)
  71658. {
  71659. if (w <= 0 || h <= 0 || bounds.isEmpty())
  71660. return AffineTransform::identity;
  71661. float newW, newH;
  71662. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  71663. if (srcRatio > h / w)
  71664. {
  71665. newW = h / srcRatio;
  71666. newH = h;
  71667. }
  71668. else
  71669. {
  71670. newW = w;
  71671. newH = w * srcRatio;
  71672. }
  71673. float newXCentre = x;
  71674. float newYCentre = y;
  71675. if (justification.testFlags (Justification::left))
  71676. newXCentre += newW * 0.5f;
  71677. else if (justification.testFlags (Justification::right))
  71678. newXCentre += w - newW * 0.5f;
  71679. else
  71680. newXCentre += w * 0.5f;
  71681. if (justification.testFlags (Justification::top))
  71682. newYCentre += newH * 0.5f;
  71683. else if (justification.testFlags (Justification::bottom))
  71684. newYCentre += h - newH * 0.5f;
  71685. else
  71686. newYCentre += h * 0.5f;
  71687. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  71688. bounds.getHeight() * -0.5f - bounds.getY())
  71689. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  71690. .translated (newXCentre, newYCentre);
  71691. }
  71692. else
  71693. {
  71694. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  71695. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  71696. .translated (x, y);
  71697. }
  71698. }
  71699. bool Path::contains (const float x, const float y, const float tolerence) const throw()
  71700. {
  71701. if (x <= pathXMin || x >= pathXMax
  71702. || y <= pathYMin || y >= pathYMax)
  71703. return false;
  71704. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71705. int positiveCrossings = 0;
  71706. int negativeCrossings = 0;
  71707. while (i.next())
  71708. {
  71709. if ((i.y1 <= y && i.y2 > y)
  71710. || (i.y2 <= y && i.y1 > y))
  71711. {
  71712. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  71713. if (intersectX <= x)
  71714. {
  71715. if (i.y1 < i.y2)
  71716. ++positiveCrossings;
  71717. else
  71718. ++negativeCrossings;
  71719. }
  71720. }
  71721. }
  71722. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  71723. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  71724. }
  71725. bool Path::intersectsLine (const float x1, const float y1,
  71726. const float x2, const float y2,
  71727. const float tolerence) throw()
  71728. {
  71729. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71730. const Line line1 (x1, y1, x2, y2);
  71731. while (i.next())
  71732. {
  71733. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  71734. float ix, iy;
  71735. if (line1.intersects (line2, ix, iy))
  71736. return true;
  71737. }
  71738. return false;
  71739. }
  71740. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const throw()
  71741. {
  71742. if (cornerRadius <= 0.01f)
  71743. return *this;
  71744. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  71745. int n = 0;
  71746. bool lastWasLine = false, firstWasLine = false;
  71747. Path p;
  71748. while (n < numElements)
  71749. {
  71750. const float type = data.elements [n++];
  71751. if (type == moveMarker)
  71752. {
  71753. indexOfPathStart = p.numElements;
  71754. indexOfPathStartThis = n - 1;
  71755. const float x = data.elements [n++];
  71756. const float y = data.elements [n++];
  71757. p.startNewSubPath (x, y);
  71758. lastWasLine = false;
  71759. firstWasLine = (data.elements [n] == lineMarker);
  71760. }
  71761. else if (type == lineMarker || type == closeSubPathMarker)
  71762. {
  71763. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  71764. if (type == lineMarker)
  71765. {
  71766. endX = data.elements [n++];
  71767. endY = data.elements [n++];
  71768. if (n > 8)
  71769. {
  71770. startX = data.elements [n - 8];
  71771. startY = data.elements [n - 7];
  71772. joinX = data.elements [n - 5];
  71773. joinY = data.elements [n - 4];
  71774. }
  71775. }
  71776. else
  71777. {
  71778. endX = data.elements [indexOfPathStartThis + 1];
  71779. endY = data.elements [indexOfPathStartThis + 2];
  71780. if (n > 6)
  71781. {
  71782. startX = data.elements [n - 6];
  71783. startY = data.elements [n - 5];
  71784. joinX = data.elements [n - 3];
  71785. joinY = data.elements [n - 2];
  71786. }
  71787. }
  71788. if (lastWasLine)
  71789. {
  71790. const double len1 = juce_hypot (startX - joinX,
  71791. startY - joinY);
  71792. if (len1 > 0)
  71793. {
  71794. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71795. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71796. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71797. }
  71798. const double len2 = juce_hypot (endX - joinX,
  71799. endY - joinY);
  71800. if (len2 > 0)
  71801. {
  71802. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71803. p.quadraticTo (joinX, joinY,
  71804. (float) (joinX + (endX - joinX) * propNeeded),
  71805. (float) (joinY + (endY - joinY) * propNeeded));
  71806. }
  71807. p.lineTo (endX, endY);
  71808. }
  71809. else if (type == lineMarker)
  71810. {
  71811. p.lineTo (endX, endY);
  71812. lastWasLine = true;
  71813. }
  71814. if (type == closeSubPathMarker)
  71815. {
  71816. if (firstWasLine)
  71817. {
  71818. startX = data.elements [n - 3];
  71819. startY = data.elements [n - 2];
  71820. joinX = endX;
  71821. joinY = endY;
  71822. endX = data.elements [indexOfPathStartThis + 4];
  71823. endY = data.elements [indexOfPathStartThis + 5];
  71824. const double len1 = juce_hypot (startX - joinX,
  71825. startY - joinY);
  71826. if (len1 > 0)
  71827. {
  71828. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71829. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71830. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71831. }
  71832. const double len2 = juce_hypot (endX - joinX,
  71833. endY - joinY);
  71834. if (len2 > 0)
  71835. {
  71836. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71837. endX = (float) (joinX + (endX - joinX) * propNeeded);
  71838. endY = (float) (joinY + (endY - joinY) * propNeeded);
  71839. p.quadraticTo (joinX, joinY, endX, endY);
  71840. p.data.elements [indexOfPathStart + 1] = endX;
  71841. p.data.elements [indexOfPathStart + 2] = endY;
  71842. }
  71843. }
  71844. p.closeSubPath();
  71845. }
  71846. }
  71847. else if (type == quadMarker)
  71848. {
  71849. lastWasLine = false;
  71850. const float x1 = data.elements [n++];
  71851. const float y1 = data.elements [n++];
  71852. const float x2 = data.elements [n++];
  71853. const float y2 = data.elements [n++];
  71854. p.quadraticTo (x1, y1, x2, y2);
  71855. }
  71856. else if (type == cubicMarker)
  71857. {
  71858. lastWasLine = false;
  71859. const float x1 = data.elements [n++];
  71860. const float y1 = data.elements [n++];
  71861. const float x2 = data.elements [n++];
  71862. const float y2 = data.elements [n++];
  71863. const float x3 = data.elements [n++];
  71864. const float y3 = data.elements [n++];
  71865. p.cubicTo (x1, y1, x2, y2, x3, y3);
  71866. }
  71867. }
  71868. return p;
  71869. }
  71870. void Path::loadPathFromStream (InputStream& source)
  71871. {
  71872. while (! source.isExhausted())
  71873. {
  71874. switch (source.readByte())
  71875. {
  71876. case 'm':
  71877. {
  71878. const float x = source.readFloat();
  71879. const float y = source.readFloat();
  71880. startNewSubPath (x, y);
  71881. break;
  71882. }
  71883. case 'l':
  71884. {
  71885. const float x = source.readFloat();
  71886. const float y = source.readFloat();
  71887. lineTo (x, y);
  71888. break;
  71889. }
  71890. case 'q':
  71891. {
  71892. const float x1 = source.readFloat();
  71893. const float y1 = source.readFloat();
  71894. const float x2 = source.readFloat();
  71895. const float y2 = source.readFloat();
  71896. quadraticTo (x1, y1, x2, y2);
  71897. break;
  71898. }
  71899. case 'b':
  71900. {
  71901. const float x1 = source.readFloat();
  71902. const float y1 = source.readFloat();
  71903. const float x2 = source.readFloat();
  71904. const float y2 = source.readFloat();
  71905. const float x3 = source.readFloat();
  71906. const float y3 = source.readFloat();
  71907. cubicTo (x1, y1, x2, y2, x3, y3);
  71908. break;
  71909. }
  71910. case 'c':
  71911. closeSubPath();
  71912. break;
  71913. case 'n':
  71914. useNonZeroWinding = true;
  71915. break;
  71916. case 'z':
  71917. useNonZeroWinding = false;
  71918. break;
  71919. case 'e':
  71920. return; // end of path marker
  71921. default:
  71922. jassertfalse // illegal char in the stream
  71923. break;
  71924. }
  71925. }
  71926. }
  71927. void Path::loadPathFromData (const unsigned char* const data,
  71928. const int numberOfBytes) throw()
  71929. {
  71930. MemoryInputStream in ((const char*) data, numberOfBytes, false);
  71931. loadPathFromStream (in);
  71932. }
  71933. void Path::writePathToStream (OutputStream& dest) const
  71934. {
  71935. dest.writeByte ((useNonZeroWinding) ? 'n' : 'z');
  71936. int i = 0;
  71937. while (i < numElements)
  71938. {
  71939. const float type = data.elements [i++];
  71940. if (type == moveMarker)
  71941. {
  71942. dest.writeByte ('m');
  71943. dest.writeFloat (data.elements [i++]);
  71944. dest.writeFloat (data.elements [i++]);
  71945. }
  71946. else if (type == lineMarker)
  71947. {
  71948. dest.writeByte ('l');
  71949. dest.writeFloat (data.elements [i++]);
  71950. dest.writeFloat (data.elements [i++]);
  71951. }
  71952. else if (type == quadMarker)
  71953. {
  71954. dest.writeByte ('q');
  71955. dest.writeFloat (data.elements [i++]);
  71956. dest.writeFloat (data.elements [i++]);
  71957. dest.writeFloat (data.elements [i++]);
  71958. dest.writeFloat (data.elements [i++]);
  71959. }
  71960. else if (type == cubicMarker)
  71961. {
  71962. dest.writeByte ('b');
  71963. dest.writeFloat (data.elements [i++]);
  71964. dest.writeFloat (data.elements [i++]);
  71965. dest.writeFloat (data.elements [i++]);
  71966. dest.writeFloat (data.elements [i++]);
  71967. dest.writeFloat (data.elements [i++]);
  71968. dest.writeFloat (data.elements [i++]);
  71969. }
  71970. else if (type == closeSubPathMarker)
  71971. {
  71972. dest.writeByte ('c');
  71973. }
  71974. }
  71975. dest.writeByte ('e'); // marks the end-of-path
  71976. }
  71977. const String Path::toString() const
  71978. {
  71979. MemoryOutputStream s (2048, 2048);
  71980. if (! useNonZeroWinding)
  71981. s << "a ";
  71982. int i = 0;
  71983. float lastMarker = 0.0f;
  71984. while (i < numElements)
  71985. {
  71986. const float marker = data.elements [i++];
  71987. char markerChar = 0;
  71988. int numCoords = 0;
  71989. if (marker == moveMarker)
  71990. {
  71991. markerChar = 'm';
  71992. numCoords = 2;
  71993. }
  71994. else if (marker == lineMarker)
  71995. {
  71996. markerChar = 'l';
  71997. numCoords = 2;
  71998. }
  71999. else if (marker == quadMarker)
  72000. {
  72001. markerChar = 'q';
  72002. numCoords = 4;
  72003. }
  72004. else if (marker == cubicMarker)
  72005. {
  72006. markerChar = 'c';
  72007. numCoords = 6;
  72008. }
  72009. else
  72010. {
  72011. jassert (marker == closeSubPathMarker);
  72012. markerChar = 'z';
  72013. }
  72014. if (marker != lastMarker)
  72015. {
  72016. s << markerChar << ' ';
  72017. lastMarker = marker;
  72018. }
  72019. while (--numCoords >= 0 && i < numElements)
  72020. {
  72021. String n (data.elements [i++], 3);
  72022. if (n.endsWithChar (T('0')))
  72023. {
  72024. do
  72025. {
  72026. n = n.dropLastCharacters (1);
  72027. } while (n.endsWithChar (T('0')));
  72028. if (n.endsWithChar (T('.')))
  72029. n = n.dropLastCharacters (1);
  72030. }
  72031. s << n << ' ';
  72032. }
  72033. }
  72034. const char* const result = (const char*) s.getData();
  72035. size_t len = s.getDataSize();
  72036. while (len > 0 && CharacterFunctions::isWhitespace (result [len - 1]))
  72037. --len;
  72038. return String (result, len);
  72039. }
  72040. static const String nextToken (const tchar*& t)
  72041. {
  72042. while (CharacterFunctions::isWhitespace (*t))
  72043. ++t;
  72044. const tchar* const start = t;
  72045. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  72046. ++t;
  72047. const int length = (int) (t - start);
  72048. while (CharacterFunctions::isWhitespace (*t))
  72049. ++t;
  72050. return String (start, length);
  72051. }
  72052. void Path::restoreFromString (const String& stringVersion)
  72053. {
  72054. clear();
  72055. setUsingNonZeroWinding (true);
  72056. const tchar* t = stringVersion;
  72057. tchar marker = T('m');
  72058. int numValues = 2;
  72059. float values [6];
  72060. while (*t != 0)
  72061. {
  72062. const String token (nextToken (t));
  72063. const tchar firstChar = token[0];
  72064. int startNum = 0;
  72065. if (firstChar == T('m') || firstChar == T('l'))
  72066. {
  72067. marker = firstChar;
  72068. numValues = 2;
  72069. }
  72070. else if (firstChar == T('q'))
  72071. {
  72072. marker = firstChar;
  72073. numValues = 4;
  72074. }
  72075. else if (firstChar == T('c'))
  72076. {
  72077. marker = firstChar;
  72078. numValues = 6;
  72079. }
  72080. else if (firstChar == T('z'))
  72081. {
  72082. marker = firstChar;
  72083. numValues = 0;
  72084. }
  72085. else if (firstChar == T('a'))
  72086. {
  72087. setUsingNonZeroWinding (false);
  72088. continue;
  72089. }
  72090. else
  72091. {
  72092. ++startNum;
  72093. values [0] = token.getFloatValue();
  72094. }
  72095. for (int i = startNum; i < numValues; ++i)
  72096. values [i] = nextToken (t).getFloatValue();
  72097. switch (marker)
  72098. {
  72099. case T('m'):
  72100. startNewSubPath (values[0], values[1]);
  72101. break;
  72102. case T('l'):
  72103. lineTo (values[0], values[1]);
  72104. break;
  72105. case T('q'):
  72106. quadraticTo (values[0], values[1],
  72107. values[2], values[3]);
  72108. break;
  72109. case T('c'):
  72110. cubicTo (values[0], values[1],
  72111. values[2], values[3],
  72112. values[4], values[5]);
  72113. break;
  72114. case T('z'):
  72115. closeSubPath();
  72116. break;
  72117. default:
  72118. jassertfalse // illegal string format?
  72119. break;
  72120. }
  72121. }
  72122. }
  72123. Path::Iterator::Iterator (const Path& path_)
  72124. : path (path_),
  72125. index (0)
  72126. {
  72127. }
  72128. Path::Iterator::~Iterator()
  72129. {
  72130. }
  72131. bool Path::Iterator::next()
  72132. {
  72133. const float* const elements = path.data.elements;
  72134. if (index < path.numElements)
  72135. {
  72136. const float type = elements [index++];
  72137. if (type == moveMarker)
  72138. {
  72139. elementType = startNewSubPath;
  72140. x1 = elements [index++];
  72141. y1 = elements [index++];
  72142. }
  72143. else if (type == lineMarker)
  72144. {
  72145. elementType = lineTo;
  72146. x1 = elements [index++];
  72147. y1 = elements [index++];
  72148. }
  72149. else if (type == quadMarker)
  72150. {
  72151. elementType = quadraticTo;
  72152. x1 = elements [index++];
  72153. y1 = elements [index++];
  72154. x2 = elements [index++];
  72155. y2 = elements [index++];
  72156. }
  72157. else if (type == cubicMarker)
  72158. {
  72159. elementType = cubicTo;
  72160. x1 = elements [index++];
  72161. y1 = elements [index++];
  72162. x2 = elements [index++];
  72163. y2 = elements [index++];
  72164. x3 = elements [index++];
  72165. y3 = elements [index++];
  72166. }
  72167. else if (type == closeSubPathMarker)
  72168. {
  72169. elementType = closePath;
  72170. }
  72171. return true;
  72172. }
  72173. return false;
  72174. }
  72175. END_JUCE_NAMESPACE
  72176. /*** End of inlined file: juce_Path.cpp ***/
  72177. /*** Start of inlined file: juce_PathIterator.cpp ***/
  72178. BEGIN_JUCE_NAMESPACE
  72179. #if JUCE_MSVC
  72180. #pragma optimize ("t", on)
  72181. #endif
  72182. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  72183. const AffineTransform& transform_,
  72184. float tolerence_) throw()
  72185. : x2 (0),
  72186. y2 (0),
  72187. closesSubPath (false),
  72188. subPathIndex (-1),
  72189. path (path_),
  72190. transform (transform_),
  72191. points (path_.data.elements),
  72192. tolerence (tolerence_ * tolerence_),
  72193. subPathCloseX (0),
  72194. subPathCloseY (0),
  72195. stackBase (32),
  72196. index (0),
  72197. stackSize (32)
  72198. {
  72199. isIdentityTransform = transform.isIdentity();
  72200. stackPos = stackBase;
  72201. }
  72202. PathFlatteningIterator::~PathFlatteningIterator() throw()
  72203. {
  72204. }
  72205. bool PathFlatteningIterator::next() throw()
  72206. {
  72207. x1 = x2;
  72208. y1 = y2;
  72209. float x3 = 0;
  72210. float y3 = 0;
  72211. float x4 = 0;
  72212. float y4 = 0;
  72213. float type;
  72214. for (;;)
  72215. {
  72216. if (stackPos == stackBase)
  72217. {
  72218. if (index >= path.numElements)
  72219. {
  72220. return false;
  72221. }
  72222. else
  72223. {
  72224. type = points [index++];
  72225. if (type != Path::closeSubPathMarker)
  72226. {
  72227. x2 = points [index++];
  72228. y2 = points [index++];
  72229. if (! isIdentityTransform)
  72230. transform.transformPoint (x2, y2);
  72231. if (type == Path::quadMarker)
  72232. {
  72233. x3 = points [index++];
  72234. y3 = points [index++];
  72235. if (! isIdentityTransform)
  72236. transform.transformPoint (x3, y3);
  72237. }
  72238. else if (type == Path::cubicMarker)
  72239. {
  72240. x3 = points [index++];
  72241. y3 = points [index++];
  72242. x4 = points [index++];
  72243. y4 = points [index++];
  72244. if (! isIdentityTransform)
  72245. {
  72246. transform.transformPoint (x3, y3);
  72247. transform.transformPoint (x4, y4);
  72248. }
  72249. }
  72250. }
  72251. }
  72252. }
  72253. else
  72254. {
  72255. type = *--stackPos;
  72256. if (type != Path::closeSubPathMarker)
  72257. {
  72258. x2 = *--stackPos;
  72259. y2 = *--stackPos;
  72260. if (type == Path::quadMarker)
  72261. {
  72262. x3 = *--stackPos;
  72263. y3 = *--stackPos;
  72264. }
  72265. else if (type == Path::cubicMarker)
  72266. {
  72267. x3 = *--stackPos;
  72268. y3 = *--stackPos;
  72269. x4 = *--stackPos;
  72270. y4 = *--stackPos;
  72271. }
  72272. }
  72273. }
  72274. if (type == Path::lineMarker)
  72275. {
  72276. ++subPathIndex;
  72277. closesSubPath = (stackPos == stackBase)
  72278. && (index < path.numElements)
  72279. && (points [index] == Path::closeSubPathMarker)
  72280. && x2 == subPathCloseX
  72281. && y2 == subPathCloseY;
  72282. return true;
  72283. }
  72284. else if (type == Path::quadMarker)
  72285. {
  72286. const int offset = (int) (stackPos - stackBase);
  72287. if (offset >= stackSize - 10)
  72288. {
  72289. stackSize <<= 1;
  72290. stackBase.realloc (stackSize);
  72291. stackPos = stackBase + offset;
  72292. }
  72293. const float dx1 = x1 - x2;
  72294. const float dy1 = y1 - y2;
  72295. const float dx2 = x2 - x3;
  72296. const float dy2 = y2 - y3;
  72297. const float m1x = (x1 + x2) * 0.5f;
  72298. const float m1y = (y1 + y2) * 0.5f;
  72299. const float m2x = (x2 + x3) * 0.5f;
  72300. const float m2y = (y2 + y3) * 0.5f;
  72301. const float m3x = (m1x + m2x) * 0.5f;
  72302. const float m3y = (m1y + m2y) * 0.5f;
  72303. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72304. {
  72305. *stackPos++ = y3;
  72306. *stackPos++ = x3;
  72307. *stackPos++ = m2y;
  72308. *stackPos++ = m2x;
  72309. *stackPos++ = Path::quadMarker;
  72310. *stackPos++ = m3y;
  72311. *stackPos++ = m3x;
  72312. *stackPos++ = m1y;
  72313. *stackPos++ = m1x;
  72314. *stackPos++ = Path::quadMarker;
  72315. }
  72316. else
  72317. {
  72318. *stackPos++ = y3;
  72319. *stackPos++ = x3;
  72320. *stackPos++ = Path::lineMarker;
  72321. *stackPos++ = m3y;
  72322. *stackPos++ = m3x;
  72323. *stackPos++ = Path::lineMarker;
  72324. }
  72325. jassert (stackPos < stackBase + stackSize);
  72326. }
  72327. else if (type == Path::cubicMarker)
  72328. {
  72329. const int offset = (int) (stackPos - stackBase);
  72330. if (offset >= stackSize - 16)
  72331. {
  72332. stackSize <<= 1;
  72333. stackBase.realloc (stackSize);
  72334. stackPos = stackBase + offset;
  72335. }
  72336. const float dx1 = x1 - x2;
  72337. const float dy1 = y1 - y2;
  72338. const float dx2 = x2 - x3;
  72339. const float dy2 = y2 - y3;
  72340. const float dx3 = x3 - x4;
  72341. const float dy3 = y3 - y4;
  72342. const float m1x = (x1 + x2) * 0.5f;
  72343. const float m1y = (y1 + y2) * 0.5f;
  72344. const float m2x = (x3 + x2) * 0.5f;
  72345. const float m2y = (y3 + y2) * 0.5f;
  72346. const float m3x = (x3 + x4) * 0.5f;
  72347. const float m3y = (y3 + y4) * 0.5f;
  72348. const float m4x = (m1x + m2x) * 0.5f;
  72349. const float m4y = (m1y + m2y) * 0.5f;
  72350. const float m5x = (m3x + m2x) * 0.5f;
  72351. const float m5y = (m3y + m2y) * 0.5f;
  72352. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72353. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72354. {
  72355. *stackPos++ = y4;
  72356. *stackPos++ = x4;
  72357. *stackPos++ = m3y;
  72358. *stackPos++ = m3x;
  72359. *stackPos++ = m5y;
  72360. *stackPos++ = m5x;
  72361. *stackPos++ = Path::cubicMarker;
  72362. *stackPos++ = (m4y + m5y) * 0.5f;
  72363. *stackPos++ = (m4x + m5x) * 0.5f;
  72364. *stackPos++ = m4y;
  72365. *stackPos++ = m4x;
  72366. *stackPos++ = m1y;
  72367. *stackPos++ = m1x;
  72368. *stackPos++ = Path::cubicMarker;
  72369. }
  72370. else
  72371. {
  72372. *stackPos++ = y4;
  72373. *stackPos++ = x4;
  72374. *stackPos++ = Path::lineMarker;
  72375. *stackPos++ = m5y;
  72376. *stackPos++ = m5x;
  72377. *stackPos++ = Path::lineMarker;
  72378. *stackPos++ = m4y;
  72379. *stackPos++ = m4x;
  72380. *stackPos++ = Path::lineMarker;
  72381. }
  72382. }
  72383. else if (type == Path::closeSubPathMarker)
  72384. {
  72385. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72386. {
  72387. x1 = x2;
  72388. y1 = y2;
  72389. x2 = subPathCloseX;
  72390. y2 = subPathCloseY;
  72391. closesSubPath = true;
  72392. return true;
  72393. }
  72394. }
  72395. else
  72396. {
  72397. jassert (type == Path::moveMarker);
  72398. subPathIndex = -1;
  72399. subPathCloseX = x1 = x2;
  72400. subPathCloseY = y1 = y2;
  72401. }
  72402. }
  72403. }
  72404. END_JUCE_NAMESPACE
  72405. /*** End of inlined file: juce_PathIterator.cpp ***/
  72406. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72407. BEGIN_JUCE_NAMESPACE
  72408. PathStrokeType::PathStrokeType (const float strokeThickness,
  72409. const JointStyle jointStyle_,
  72410. const EndCapStyle endStyle_) throw()
  72411. : thickness (strokeThickness),
  72412. jointStyle (jointStyle_),
  72413. endStyle (endStyle_)
  72414. {
  72415. }
  72416. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72417. : thickness (other.thickness),
  72418. jointStyle (other.jointStyle),
  72419. endStyle (other.endStyle)
  72420. {
  72421. }
  72422. PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72423. {
  72424. thickness = other.thickness;
  72425. jointStyle = other.jointStyle;
  72426. endStyle = other.endStyle;
  72427. return *this;
  72428. }
  72429. PathStrokeType::~PathStrokeType() throw()
  72430. {
  72431. }
  72432. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72433. {
  72434. return thickness == other.thickness
  72435. && jointStyle == other.jointStyle
  72436. && endStyle == other.endStyle;
  72437. }
  72438. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72439. {
  72440. return ! operator== (other);
  72441. }
  72442. static bool lineIntersection (const float x1, const float y1,
  72443. const float x2, const float y2,
  72444. const float x3, const float y3,
  72445. const float x4, const float y4,
  72446. float& intersectionX,
  72447. float& intersectionY,
  72448. float& distanceBeyondLine1EndSquared) throw()
  72449. {
  72450. if (x2 != x3 || y2 != y3)
  72451. {
  72452. const float dx1 = x2 - x1;
  72453. const float dy1 = y2 - y1;
  72454. const float dx2 = x4 - x3;
  72455. const float dy2 = y4 - y3;
  72456. const float divisor = dx1 * dy2 - dx2 * dy1;
  72457. if (divisor == 0)
  72458. {
  72459. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72460. {
  72461. if (dy1 == 0 && dy2 != 0)
  72462. {
  72463. const float along = (y1 - y3) / dy2;
  72464. intersectionX = x3 + along * dx2;
  72465. intersectionY = y1;
  72466. distanceBeyondLine1EndSquared = intersectionX - x2;
  72467. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72468. if ((x2 > x1) == (intersectionX < x2))
  72469. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72470. return along >= 0 && along <= 1.0f;
  72471. }
  72472. else if (dy2 == 0 && dy1 != 0)
  72473. {
  72474. const float along = (y3 - y1) / dy1;
  72475. intersectionX = x1 + along * dx1;
  72476. intersectionY = y3;
  72477. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72478. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72479. if (along < 1.0f)
  72480. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72481. return along >= 0 && along <= 1.0f;
  72482. }
  72483. else if (dx1 == 0 && dx2 != 0)
  72484. {
  72485. const float along = (x1 - x3) / dx2;
  72486. intersectionX = x1;
  72487. intersectionY = y3 + along * dy2;
  72488. distanceBeyondLine1EndSquared = intersectionY - y2;
  72489. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72490. if ((y2 > y1) == (intersectionY < y2))
  72491. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72492. return along >= 0 && along <= 1.0f;
  72493. }
  72494. else if (dx2 == 0 && dx1 != 0)
  72495. {
  72496. const float along = (x3 - x1) / dx1;
  72497. intersectionX = x3;
  72498. intersectionY = y1 + along * dy1;
  72499. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72500. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72501. if (along < 1.0f)
  72502. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72503. return along >= 0 && along <= 1.0f;
  72504. }
  72505. }
  72506. intersectionX = 0.5f * (x2 + x3);
  72507. intersectionY = 0.5f * (y2 + y3);
  72508. distanceBeyondLine1EndSquared = 0.0f;
  72509. return false;
  72510. }
  72511. else
  72512. {
  72513. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72514. intersectionX = x1 + along1 * dx1;
  72515. intersectionY = y1 + along1 * dy1;
  72516. if (along1 >= 0 && along1 <= 1.0f)
  72517. {
  72518. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72519. if (along2 >= 0 && along2 <= divisor)
  72520. {
  72521. distanceBeyondLine1EndSquared = 0.0f;
  72522. return true;
  72523. }
  72524. }
  72525. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72526. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72527. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72528. if (along1 < 1.0f)
  72529. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72530. return false;
  72531. }
  72532. }
  72533. intersectionX = x2;
  72534. intersectionY = y2;
  72535. distanceBeyondLine1EndSquared = 0.0f;
  72536. return true;
  72537. }
  72538. namespace PathFunctions
  72539. {
  72540. // part of stroke drawing stuff
  72541. static void addEdgeAndJoint (Path& destPath,
  72542. const PathStrokeType::JointStyle style,
  72543. const float maxMiterExtensionSquared, const float width,
  72544. const float x1, const float y1,
  72545. const float x2, const float y2,
  72546. const float x3, const float y3,
  72547. const float x4, const float y4,
  72548. const float midX, const float midY)
  72549. {
  72550. if (style == PathStrokeType::beveled
  72551. || (x3 == x4 && y3 == y4)
  72552. || (x1 == x2 && y1 == y2))
  72553. {
  72554. destPath.lineTo (x2, y2);
  72555. destPath.lineTo (x3, y3);
  72556. }
  72557. else
  72558. {
  72559. float jx, jy, distanceBeyondLine1EndSquared;
  72560. // if they intersect, use this point..
  72561. if (lineIntersection (x1, y1, x2, y2,
  72562. x3, y3, x4, y4,
  72563. jx, jy, distanceBeyondLine1EndSquared))
  72564. {
  72565. destPath.lineTo (jx, jy);
  72566. }
  72567. else
  72568. {
  72569. if (style == PathStrokeType::mitered)
  72570. {
  72571. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72572. && distanceBeyondLine1EndSquared > 0.0f)
  72573. {
  72574. destPath.lineTo (jx, jy);
  72575. }
  72576. else
  72577. {
  72578. // the end sticks out too far, so just use a blunt joint
  72579. destPath.lineTo (x2, y2);
  72580. destPath.lineTo (x3, y3);
  72581. }
  72582. }
  72583. else
  72584. {
  72585. // curved joints
  72586. float angle1 = atan2f (x2 - midX, y2 - midY);
  72587. float angle2 = atan2f (x3 - midX, y3 - midY);
  72588. const float angleIncrement = 0.1f;
  72589. destPath.lineTo (x2, y2);
  72590. if (fabs (angle1 - angle2) > angleIncrement)
  72591. {
  72592. if (angle2 > angle1 + float_Pi
  72593. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72594. {
  72595. if (angle2 > angle1)
  72596. angle2 -= float_Pi * 2.0f;
  72597. jassert (angle1 <= angle2 + float_Pi);
  72598. angle1 -= angleIncrement;
  72599. while (angle1 > angle2)
  72600. {
  72601. destPath.lineTo (midX + width * sinf (angle1),
  72602. midY + width * cosf (angle1));
  72603. angle1 -= angleIncrement;
  72604. }
  72605. }
  72606. else
  72607. {
  72608. if (angle1 > angle2)
  72609. angle1 -= float_Pi * 2.0f;
  72610. jassert (angle1 >= angle2 - float_Pi);
  72611. angle1 += angleIncrement;
  72612. while (angle1 < angle2)
  72613. {
  72614. destPath.lineTo (midX + width * sinf (angle1),
  72615. midY + width * cosf (angle1));
  72616. angle1 += angleIncrement;
  72617. }
  72618. }
  72619. }
  72620. destPath.lineTo (x3, y3);
  72621. }
  72622. }
  72623. }
  72624. }
  72625. static void addLineEnd (Path& destPath,
  72626. const PathStrokeType::EndCapStyle style,
  72627. const float x1, const float y1,
  72628. const float x2, const float y2,
  72629. const float width)
  72630. {
  72631. if (style == PathStrokeType::butt)
  72632. {
  72633. destPath.lineTo (x2, y2);
  72634. }
  72635. else
  72636. {
  72637. float offx1, offy1, offx2, offy2;
  72638. float dx = x2 - x1;
  72639. float dy = y2 - y1;
  72640. const float len = juce_hypotf (dx, dy);
  72641. if (len == 0)
  72642. {
  72643. offx1 = offx2 = x1;
  72644. offy1 = offy2 = y1;
  72645. }
  72646. else
  72647. {
  72648. const float offset = width / len;
  72649. dx *= offset;
  72650. dy *= offset;
  72651. offx1 = x1 + dy;
  72652. offy1 = y1 - dx;
  72653. offx2 = x2 + dy;
  72654. offy2 = y2 - dx;
  72655. }
  72656. if (style == PathStrokeType::square)
  72657. {
  72658. // sqaure ends
  72659. destPath.lineTo (offx1, offy1);
  72660. destPath.lineTo (offx2, offy2);
  72661. destPath.lineTo (x2, y2);
  72662. }
  72663. else
  72664. {
  72665. // rounded ends
  72666. const float midx = (offx1 + offx2) * 0.5f;
  72667. const float midy = (offy1 + offy2) * 0.5f;
  72668. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  72669. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  72670. midx, midy);
  72671. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  72672. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  72673. x2, y2);
  72674. }
  72675. }
  72676. }
  72677. struct LineSection
  72678. {
  72679. LineSection() {}
  72680. LineSection (int) {}
  72681. float x1, y1, x2, y2; // original line
  72682. float lx1, ly1, lx2, ly2; // the left-hand stroke
  72683. float rx1, ry1, rx2, ry2; // the right-hand stroke
  72684. };
  72685. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  72686. const bool isClosed,
  72687. const float width, const float maxMiterExtensionSquared,
  72688. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle)
  72689. {
  72690. jassert (subPath.size() > 0);
  72691. const LineSection& firstLine = subPath.getReference (0);
  72692. float lastX1 = firstLine.lx1;
  72693. float lastY1 = firstLine.ly1;
  72694. float lastX2 = firstLine.lx2;
  72695. float lastY2 = firstLine.ly2;
  72696. if (isClosed)
  72697. {
  72698. destPath.startNewSubPath (lastX1, lastY1);
  72699. }
  72700. else
  72701. {
  72702. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  72703. addLineEnd (destPath, endStyle,
  72704. firstLine.rx2, firstLine.ry2,
  72705. lastX1, lastY1,
  72706. width);
  72707. }
  72708. int i;
  72709. for (i = 1; i < subPath.size(); ++i)
  72710. {
  72711. const LineSection& l = subPath.getReference (i);
  72712. addEdgeAndJoint (destPath, jointStyle,
  72713. maxMiterExtensionSquared, width,
  72714. lastX1, lastY1, lastX2, lastY2,
  72715. l.lx1, l.ly1, l.lx2, l.ly2,
  72716. l.x1, l.y1);
  72717. lastX1 = l.lx1;
  72718. lastY1 = l.ly1;
  72719. lastX2 = l.lx2;
  72720. lastY2 = l.ly2;
  72721. }
  72722. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  72723. if (isClosed)
  72724. {
  72725. const LineSection& l = subPath.getReference (0);
  72726. addEdgeAndJoint (destPath, jointStyle,
  72727. maxMiterExtensionSquared, width,
  72728. lastX1, lastY1, lastX2, lastY2,
  72729. l.lx1, l.ly1, l.lx2, l.ly2,
  72730. l.x1, l.y1);
  72731. destPath.closeSubPath();
  72732. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  72733. }
  72734. else
  72735. {
  72736. destPath.lineTo (lastX2, lastY2);
  72737. addLineEnd (destPath, endStyle,
  72738. lastX2, lastY2,
  72739. lastLine.rx1, lastLine.ry1,
  72740. width);
  72741. }
  72742. lastX1 = lastLine.rx1;
  72743. lastY1 = lastLine.ry1;
  72744. lastX2 = lastLine.rx2;
  72745. lastY2 = lastLine.ry2;
  72746. for (i = subPath.size() - 1; --i >= 0;)
  72747. {
  72748. const LineSection& l = subPath.getReference (i);
  72749. addEdgeAndJoint (destPath, jointStyle,
  72750. maxMiterExtensionSquared, width,
  72751. lastX1, lastY1, lastX2, lastY2,
  72752. l.rx1, l.ry1, l.rx2, l.ry2,
  72753. l.x2, l.y2);
  72754. lastX1 = l.rx1;
  72755. lastY1 = l.ry1;
  72756. lastX2 = l.rx2;
  72757. lastY2 = l.ry2;
  72758. }
  72759. if (isClosed)
  72760. {
  72761. addEdgeAndJoint (destPath, jointStyle,
  72762. maxMiterExtensionSquared, width,
  72763. lastX1, lastY1, lastX2, lastY2,
  72764. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  72765. lastLine.x2, lastLine.y2);
  72766. }
  72767. else
  72768. {
  72769. // do the last line
  72770. destPath.lineTo (lastX2, lastY2);
  72771. }
  72772. destPath.closeSubPath();
  72773. }
  72774. }
  72775. void PathStrokeType::createStrokedPath (Path& destPath,
  72776. const Path& source,
  72777. const AffineTransform& transform,
  72778. const float extraAccuracy) const
  72779. {
  72780. if (thickness <= 0)
  72781. {
  72782. destPath.clear();
  72783. return;
  72784. }
  72785. const Path* sourcePath = &source;
  72786. Path temp;
  72787. if (sourcePath == &destPath)
  72788. {
  72789. destPath.swapWithPath (temp);
  72790. sourcePath = &temp;
  72791. }
  72792. else
  72793. {
  72794. destPath.clear();
  72795. }
  72796. destPath.setUsingNonZeroWinding (true);
  72797. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  72798. const float width = 0.5f * thickness;
  72799. // Iterate the path, creating a list of the
  72800. // left/right-hand lines along either side of it...
  72801. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  72802. using namespace PathFunctions;
  72803. Array <LineSection> subPath;
  72804. LineSection l;
  72805. l.x1 = 0;
  72806. l.y1 = 0;
  72807. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  72808. while (it.next())
  72809. {
  72810. if (it.subPathIndex == 0)
  72811. {
  72812. if (subPath.size() > 0)
  72813. {
  72814. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72815. subPath.clearQuick();
  72816. }
  72817. l.x1 = it.x1;
  72818. l.y1 = it.y1;
  72819. }
  72820. l.x2 = it.x2;
  72821. l.y2 = it.y2;
  72822. float dx = l.x2 - l.x1;
  72823. float dy = l.y2 - l.y1;
  72824. const float hypotSquared = dx*dx + dy*dy;
  72825. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  72826. {
  72827. const float len = sqrtf (hypotSquared);
  72828. if (len == 0)
  72829. {
  72830. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  72831. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  72832. }
  72833. else
  72834. {
  72835. const float offset = width / len;
  72836. dx *= offset;
  72837. dy *= offset;
  72838. l.rx2 = l.x1 - dy;
  72839. l.ry2 = l.y1 + dx;
  72840. l.lx1 = l.x1 + dy;
  72841. l.ly1 = l.y1 - dx;
  72842. l.lx2 = l.x2 + dy;
  72843. l.ly2 = l.y2 - dx;
  72844. l.rx1 = l.x2 - dy;
  72845. l.ry1 = l.y2 + dx;
  72846. }
  72847. subPath.add (l);
  72848. if (it.closesSubPath)
  72849. {
  72850. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72851. subPath.clearQuick();
  72852. }
  72853. else
  72854. {
  72855. l.x1 = it.x2;
  72856. l.y1 = it.y2;
  72857. }
  72858. }
  72859. }
  72860. if (subPath.size() > 0)
  72861. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72862. }
  72863. void PathStrokeType::createDashedStroke (Path& destPath,
  72864. const Path& sourcePath,
  72865. const float* dashLengths,
  72866. int numDashLengths,
  72867. const AffineTransform& transform,
  72868. const float extraAccuracy) const
  72869. {
  72870. if (thickness <= 0)
  72871. return;
  72872. // this should really be an even number..
  72873. jassert ((numDashLengths & 1) == 0);
  72874. Path newDestPath;
  72875. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  72876. bool first = true;
  72877. int dashNum = 0;
  72878. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  72879. float dx = 0.0f, dy = 0.0f;
  72880. for (;;)
  72881. {
  72882. const bool isSolid = ((dashNum & 1) == 0);
  72883. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  72884. jassert (dashLen > 0); // must be a positive increment!
  72885. if (dashLen <= 0)
  72886. break;
  72887. pos += dashLen;
  72888. while (pos > lineEndPos)
  72889. {
  72890. if (! it.next())
  72891. {
  72892. if (isSolid && ! first)
  72893. newDestPath.lineTo (it.x2, it.y2);
  72894. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  72895. return;
  72896. }
  72897. if (isSolid && ! first)
  72898. newDestPath.lineTo (it.x1, it.y1);
  72899. else
  72900. newDestPath.startNewSubPath (it.x1, it.y1);
  72901. dx = it.x2 - it.x1;
  72902. dy = it.y2 - it.y1;
  72903. lineLen = juce_hypotf (dx, dy);
  72904. lineEndPos += lineLen;
  72905. first = it.closesSubPath;
  72906. }
  72907. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  72908. if (isSolid)
  72909. newDestPath.lineTo (it.x1 + dx * alpha,
  72910. it.y1 + dy * alpha);
  72911. else
  72912. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  72913. it.y1 + dy * alpha);
  72914. }
  72915. }
  72916. END_JUCE_NAMESPACE
  72917. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  72918. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  72919. BEGIN_JUCE_NAMESPACE
  72920. PositionedRectangle::PositionedRectangle() throw()
  72921. : x (0.0),
  72922. y (0.0),
  72923. w (0.0),
  72924. h (0.0),
  72925. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72926. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72927. wMode (absoluteSize),
  72928. hMode (absoluteSize)
  72929. {
  72930. }
  72931. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  72932. : x (other.x),
  72933. y (other.y),
  72934. w (other.w),
  72935. h (other.h),
  72936. xMode (other.xMode),
  72937. yMode (other.yMode),
  72938. wMode (other.wMode),
  72939. hMode (other.hMode)
  72940. {
  72941. }
  72942. PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  72943. {
  72944. x = other.x;
  72945. y = other.y;
  72946. w = other.w;
  72947. h = other.h;
  72948. xMode = other.xMode;
  72949. yMode = other.yMode;
  72950. wMode = other.wMode;
  72951. hMode = other.hMode;
  72952. return *this;
  72953. }
  72954. PositionedRectangle::~PositionedRectangle() throw()
  72955. {
  72956. }
  72957. bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  72958. {
  72959. return x == other.x
  72960. && y == other.y
  72961. && w == other.w
  72962. && h == other.h
  72963. && xMode == other.xMode
  72964. && yMode == other.yMode
  72965. && wMode == other.wMode
  72966. && hMode == other.hMode;
  72967. }
  72968. bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  72969. {
  72970. return ! operator== (other);
  72971. }
  72972. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  72973. {
  72974. StringArray tokens;
  72975. tokens.addTokens (stringVersion, false);
  72976. decodePosString (tokens [0], xMode, x);
  72977. decodePosString (tokens [1], yMode, y);
  72978. decodeSizeString (tokens [2], wMode, w);
  72979. decodeSizeString (tokens [3], hMode, h);
  72980. }
  72981. const String PositionedRectangle::toString() const throw()
  72982. {
  72983. String s;
  72984. s.preallocateStorage (12);
  72985. addPosDescription (s, xMode, x);
  72986. s << T(' ');
  72987. addPosDescription (s, yMode, y);
  72988. s << T(' ');
  72989. addSizeDescription (s, wMode, w);
  72990. s << T(' ');
  72991. addSizeDescription (s, hMode, h);
  72992. return s;
  72993. }
  72994. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  72995. {
  72996. jassert (! target.isEmpty());
  72997. double x_, y_, w_, h_;
  72998. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72999. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73000. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  73001. roundToInt (w_), roundToInt (h_));
  73002. }
  73003. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  73004. double& x_, double& y_,
  73005. double& w_, double& h_) const throw()
  73006. {
  73007. jassert (! target.isEmpty());
  73008. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  73009. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73010. }
  73011. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  73012. {
  73013. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  73014. }
  73015. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  73016. const Rectangle<int>& target) throw()
  73017. {
  73018. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  73019. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  73020. }
  73021. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  73022. const double newW, const double newH,
  73023. const Rectangle<int>& target) throw()
  73024. {
  73025. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  73026. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  73027. }
  73028. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  73029. {
  73030. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  73031. updateFrom (comp.getBounds(), Rectangle<int>());
  73032. else
  73033. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  73034. }
  73035. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  73036. {
  73037. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73038. }
  73039. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  73040. {
  73041. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  73042. | absoluteFromParentBottomRight
  73043. | absoluteFromParentCentre
  73044. | proportionOfParentSize));
  73045. }
  73046. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  73047. {
  73048. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73049. }
  73050. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  73051. {
  73052. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  73053. | absoluteFromParentBottomRight
  73054. | absoluteFromParentCentre
  73055. | proportionOfParentSize));
  73056. }
  73057. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  73058. {
  73059. return (SizeMode) wMode;
  73060. }
  73061. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  73062. {
  73063. return (SizeMode) hMode;
  73064. }
  73065. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  73066. const PositionMode xMode_,
  73067. const AnchorPoint yAnchor,
  73068. const PositionMode yMode_,
  73069. const SizeMode widthMode,
  73070. const SizeMode heightMode,
  73071. const Rectangle<int>& target) throw()
  73072. {
  73073. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  73074. {
  73075. double tx, tw;
  73076. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  73077. xMode = (uint8) (xAnchor | xMode_);
  73078. wMode = (uint8) widthMode;
  73079. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  73080. }
  73081. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  73082. {
  73083. double ty, th;
  73084. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  73085. yMode = (uint8) (yAnchor | yMode_);
  73086. hMode = (uint8) heightMode;
  73087. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  73088. }
  73089. }
  73090. bool PositionedRectangle::isPositionAbsolute() const throw()
  73091. {
  73092. return xMode == absoluteFromParentTopLeft
  73093. && yMode == absoluteFromParentTopLeft
  73094. && wMode == absoluteSize
  73095. && hMode == absoluteSize;
  73096. }
  73097. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  73098. {
  73099. if ((mode & proportionOfParentSize) != 0)
  73100. {
  73101. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73102. }
  73103. else
  73104. {
  73105. s << (roundToInt (value * 100.0) / 100.0);
  73106. if ((mode & absoluteFromParentBottomRight) != 0)
  73107. s << T('R');
  73108. else if ((mode & absoluteFromParentCentre) != 0)
  73109. s << T('C');
  73110. }
  73111. if ((mode & anchorAtRightOrBottom) != 0)
  73112. s << T('r');
  73113. else if ((mode & anchorAtCentre) != 0)
  73114. s << T('c');
  73115. }
  73116. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  73117. {
  73118. if (mode == proportionalSize)
  73119. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73120. else if (mode == parentSizeMinusAbsolute)
  73121. s << (roundToInt (value * 100.0) / 100.0) << T('M');
  73122. else
  73123. s << (roundToInt (value * 100.0) / 100.0);
  73124. }
  73125. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  73126. {
  73127. if (s.containsChar (T('r')))
  73128. mode = anchorAtRightOrBottom;
  73129. else if (s.containsChar (T('c')))
  73130. mode = anchorAtCentre;
  73131. else
  73132. mode = anchorAtLeftOrTop;
  73133. if (s.containsChar (T('%')))
  73134. {
  73135. mode |= proportionOfParentSize;
  73136. value = s.removeCharacters (T("%rcRC")).getDoubleValue() / 100.0;
  73137. }
  73138. else
  73139. {
  73140. if (s.containsChar (T('R')))
  73141. mode |= absoluteFromParentBottomRight;
  73142. else if (s.containsChar (T('C')))
  73143. mode |= absoluteFromParentCentre;
  73144. else
  73145. mode |= absoluteFromParentTopLeft;
  73146. value = s.removeCharacters (T("rcRC")).getDoubleValue();
  73147. }
  73148. }
  73149. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  73150. {
  73151. if (s.containsChar (T('%')))
  73152. {
  73153. mode = proportionalSize;
  73154. value = s.upToFirstOccurrenceOf (T("%"), false, false).getDoubleValue() / 100.0;
  73155. }
  73156. else if (s.containsChar (T('M')))
  73157. {
  73158. mode = parentSizeMinusAbsolute;
  73159. value = s.getDoubleValue();
  73160. }
  73161. else
  73162. {
  73163. mode = absoluteSize;
  73164. value = s.getDoubleValue();
  73165. }
  73166. }
  73167. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  73168. const double x_, const double w_,
  73169. const uint8 xMode_, const uint8 wMode_,
  73170. const int parentPos,
  73171. const int parentSize) const throw()
  73172. {
  73173. if (wMode_ == proportionalSize)
  73174. wOut = roundToInt (w_ * parentSize);
  73175. else if (wMode_ == parentSizeMinusAbsolute)
  73176. wOut = jmax (0, parentSize - roundToInt (w_));
  73177. else
  73178. wOut = roundToInt (w_);
  73179. if ((xMode_ & proportionOfParentSize) != 0)
  73180. xOut = parentPos + x_ * parentSize;
  73181. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73182. xOut = (parentPos + parentSize) - x_;
  73183. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73184. xOut = x_ + (parentPos + parentSize / 2);
  73185. else
  73186. xOut = x_ + parentPos;
  73187. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73188. xOut -= wOut;
  73189. else if ((xMode_ & anchorAtCentre) != 0)
  73190. xOut -= wOut / 2;
  73191. }
  73192. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  73193. double x_, const double w_,
  73194. const uint8 xMode_, const uint8 wMode_,
  73195. const int parentPos,
  73196. const int parentSize) const throw()
  73197. {
  73198. if (wMode_ == proportionalSize)
  73199. {
  73200. if (parentSize > 0)
  73201. wOut = w_ / parentSize;
  73202. }
  73203. else if (wMode_ == parentSizeMinusAbsolute)
  73204. wOut = parentSize - w_;
  73205. else
  73206. wOut = w_;
  73207. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73208. x_ += w_;
  73209. else if ((xMode_ & anchorAtCentre) != 0)
  73210. x_ += w_ / 2;
  73211. if ((xMode_ & proportionOfParentSize) != 0)
  73212. {
  73213. if (parentSize > 0)
  73214. xOut = (x_ - parentPos) / parentSize;
  73215. }
  73216. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73217. xOut = (parentPos + parentSize) - x_;
  73218. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73219. xOut = x_ - (parentPos + parentSize / 2);
  73220. else
  73221. xOut = x_ - parentPos;
  73222. }
  73223. END_JUCE_NAMESPACE
  73224. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  73225. /*** Start of inlined file: juce_RectangleList.cpp ***/
  73226. BEGIN_JUCE_NAMESPACE
  73227. RectangleList::RectangleList() throw()
  73228. {
  73229. }
  73230. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  73231. {
  73232. if (! rect.isEmpty())
  73233. rects.add (rect);
  73234. }
  73235. RectangleList::RectangleList (const RectangleList& other) throw()
  73236. : rects (other.rects)
  73237. {
  73238. }
  73239. RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  73240. {
  73241. rects = other.rects;
  73242. return *this;
  73243. }
  73244. RectangleList::~RectangleList() throw()
  73245. {
  73246. }
  73247. void RectangleList::clear() throw()
  73248. {
  73249. rects.clearQuick();
  73250. }
  73251. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  73252. {
  73253. if (((unsigned int) index) < (unsigned int) rects.size())
  73254. return rects.getReference (index);
  73255. return Rectangle<int>();
  73256. }
  73257. bool RectangleList::isEmpty() const throw()
  73258. {
  73259. return rects.size() == 0;
  73260. }
  73261. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  73262. : current (0),
  73263. owner (list),
  73264. index (list.rects.size())
  73265. {
  73266. }
  73267. RectangleList::Iterator::~Iterator() throw()
  73268. {
  73269. }
  73270. bool RectangleList::Iterator::next() throw()
  73271. {
  73272. if (--index >= 0)
  73273. {
  73274. current = & (owner.rects.getReference (index));
  73275. return true;
  73276. }
  73277. return false;
  73278. }
  73279. void RectangleList::add (const Rectangle<int>& rect) throw()
  73280. {
  73281. if (! rect.isEmpty())
  73282. {
  73283. if (rects.size() == 0)
  73284. {
  73285. rects.add (rect);
  73286. }
  73287. else
  73288. {
  73289. bool anyOverlaps = false;
  73290. int i;
  73291. for (i = rects.size(); --i >= 0;)
  73292. {
  73293. Rectangle<int>& ourRect = rects.getReference (i);
  73294. if (rect.intersects (ourRect))
  73295. {
  73296. if (rect.contains (ourRect))
  73297. rects.remove (i);
  73298. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73299. anyOverlaps = true;
  73300. }
  73301. }
  73302. if (anyOverlaps && rects.size() > 0)
  73303. {
  73304. RectangleList r (rect);
  73305. for (i = rects.size(); --i >= 0;)
  73306. {
  73307. const Rectangle<int>& ourRect = rects.getReference (i);
  73308. if (rect.intersects (ourRect))
  73309. {
  73310. r.subtract (ourRect);
  73311. if (r.rects.size() == 0)
  73312. return;
  73313. }
  73314. }
  73315. for (i = r.getNumRectangles(); --i >= 0;)
  73316. rects.add (r.rects.getReference (i));
  73317. }
  73318. else
  73319. {
  73320. rects.add (rect);
  73321. }
  73322. }
  73323. }
  73324. }
  73325. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  73326. {
  73327. rects.add (rect);
  73328. }
  73329. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73330. {
  73331. if (rects.size() == 0)
  73332. {
  73333. if (w > 0 && h > 0)
  73334. rects.add (Rectangle<int> (x, y, w, h));
  73335. }
  73336. else
  73337. {
  73338. add (Rectangle<int> (x, y, w, h));
  73339. }
  73340. }
  73341. void RectangleList::add (const RectangleList& other) throw()
  73342. {
  73343. for (int i = 0; i < other.rects.size(); ++i)
  73344. add (other.rects.getReference (i));
  73345. }
  73346. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  73347. {
  73348. const int originalNumRects = rects.size();
  73349. if (originalNumRects > 0)
  73350. {
  73351. const int x1 = rect.x;
  73352. const int y1 = rect.y;
  73353. const int x2 = x1 + rect.w;
  73354. const int y2 = y1 + rect.h;
  73355. for (int i = getNumRectangles(); --i >= 0;)
  73356. {
  73357. Rectangle<int>& r = rects.getReference (i);
  73358. const int rx1 = r.x;
  73359. const int ry1 = r.y;
  73360. const int rx2 = rx1 + r.w;
  73361. const int ry2 = ry1 + r.h;
  73362. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  73363. {
  73364. if (x1 > rx1 && x1 < rx2)
  73365. {
  73366. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  73367. {
  73368. r.w = x1 - rx1;
  73369. }
  73370. else
  73371. {
  73372. r.x = x1;
  73373. r.w = rx2 - x1;
  73374. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  73375. i += 2;
  73376. }
  73377. }
  73378. else if (x2 > rx1 && x2 < rx2)
  73379. {
  73380. r.x = x2;
  73381. r.w = rx2 - x2;
  73382. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  73383. {
  73384. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  73385. i += 2;
  73386. }
  73387. }
  73388. else if (y1 > ry1 && y1 < ry2)
  73389. {
  73390. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  73391. {
  73392. r.h = y1 - ry1;
  73393. }
  73394. else
  73395. {
  73396. r.y = y1;
  73397. r.h = ry2 - y1;
  73398. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  73399. i += 2;
  73400. }
  73401. }
  73402. else if (y2 > ry1 && y2 < ry2)
  73403. {
  73404. r.y = y2;
  73405. r.h = ry2 - y2;
  73406. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73407. {
  73408. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73409. i += 2;
  73410. }
  73411. }
  73412. else
  73413. {
  73414. rects.remove (i);
  73415. }
  73416. }
  73417. }
  73418. if (rects.size() > originalNumRects + 10)
  73419. consolidate();
  73420. }
  73421. }
  73422. void RectangleList::subtract (const RectangleList& otherList) throw()
  73423. {
  73424. for (int i = otherList.rects.size(); --i >= 0;)
  73425. subtract (otherList.rects.getReference (i));
  73426. }
  73427. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73428. {
  73429. bool notEmpty = false;
  73430. if (rect.isEmpty())
  73431. {
  73432. clear();
  73433. }
  73434. else
  73435. {
  73436. for (int i = rects.size(); --i >= 0;)
  73437. {
  73438. Rectangle<int>& r = rects.getReference (i);
  73439. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73440. rects.remove (i);
  73441. else
  73442. notEmpty = true;
  73443. }
  73444. }
  73445. return notEmpty;
  73446. }
  73447. bool RectangleList::clipTo (const RectangleList& other) throw()
  73448. {
  73449. if (rects.size() == 0)
  73450. return false;
  73451. RectangleList result;
  73452. for (int j = 0; j < rects.size(); ++j)
  73453. {
  73454. const Rectangle<int>& rect = rects.getReference (j);
  73455. for (int i = other.rects.size(); --i >= 0;)
  73456. {
  73457. Rectangle<int> r (other.rects.getReference (i));
  73458. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73459. result.rects.add (r);
  73460. }
  73461. }
  73462. swapWith (result);
  73463. return ! isEmpty();
  73464. }
  73465. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73466. {
  73467. destRegion.clear();
  73468. if (! rect.isEmpty())
  73469. {
  73470. for (int i = rects.size(); --i >= 0;)
  73471. {
  73472. Rectangle<int> r (rects.getReference (i));
  73473. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73474. destRegion.rects.add (r);
  73475. }
  73476. }
  73477. return destRegion.rects.size() > 0;
  73478. }
  73479. void RectangleList::swapWith (RectangleList& otherList) throw()
  73480. {
  73481. rects.swapWithArray (otherList.rects);
  73482. }
  73483. void RectangleList::consolidate() throw()
  73484. {
  73485. int i;
  73486. for (i = 0; i < getNumRectangles() - 1; ++i)
  73487. {
  73488. Rectangle<int>& r = rects.getReference (i);
  73489. const int rx1 = r.x;
  73490. const int ry1 = r.y;
  73491. const int rx2 = rx1 + r.w;
  73492. const int ry2 = ry1 + r.h;
  73493. for (int j = rects.size(); --j > i;)
  73494. {
  73495. Rectangle<int>& r2 = rects.getReference (j);
  73496. const int jrx1 = r2.x;
  73497. const int jry1 = r2.y;
  73498. const int jrx2 = jrx1 + r2.w;
  73499. const int jry2 = jry1 + r2.h;
  73500. // if the vertical edges of any blocks are touching and their horizontals don't
  73501. // line up, split them horizontally..
  73502. if (jrx1 == rx2 || jrx2 == rx1)
  73503. {
  73504. if (jry1 > ry1 && jry1 < ry2)
  73505. {
  73506. r.h = jry1 - ry1;
  73507. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73508. i = -1;
  73509. break;
  73510. }
  73511. if (jry2 > ry1 && jry2 < ry2)
  73512. {
  73513. r.h = jry2 - ry1;
  73514. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73515. i = -1;
  73516. break;
  73517. }
  73518. else if (ry1 > jry1 && ry1 < jry2)
  73519. {
  73520. r2.h = ry1 - jry1;
  73521. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73522. i = -1;
  73523. break;
  73524. }
  73525. else if (ry2 > jry1 && ry2 < jry2)
  73526. {
  73527. r2.h = ry2 - jry1;
  73528. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73529. i = -1;
  73530. break;
  73531. }
  73532. }
  73533. }
  73534. }
  73535. for (i = 0; i < rects.size() - 1; ++i)
  73536. {
  73537. Rectangle<int>& r = rects.getReference (i);
  73538. for (int j = rects.size(); --j > i;)
  73539. {
  73540. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73541. {
  73542. rects.remove (j);
  73543. i = -1;
  73544. break;
  73545. }
  73546. }
  73547. }
  73548. }
  73549. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73550. {
  73551. for (int i = getNumRectangles(); --i >= 0;)
  73552. if (rects.getReference (i).contains (x, y))
  73553. return true;
  73554. return false;
  73555. }
  73556. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73557. {
  73558. if (rects.size() > 1)
  73559. {
  73560. RectangleList r (rectangleToCheck);
  73561. for (int i = rects.size(); --i >= 0;)
  73562. {
  73563. r.subtract (rects.getReference (i));
  73564. if (r.rects.size() == 0)
  73565. return true;
  73566. }
  73567. }
  73568. else if (rects.size() > 0)
  73569. {
  73570. return rects.getReference (0).contains (rectangleToCheck);
  73571. }
  73572. return false;
  73573. }
  73574. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73575. {
  73576. for (int i = rects.size(); --i >= 0;)
  73577. if (rects.getReference (i).intersects (rectangleToCheck))
  73578. return true;
  73579. return false;
  73580. }
  73581. bool RectangleList::intersects (const RectangleList& other) const throw()
  73582. {
  73583. for (int i = rects.size(); --i >= 0;)
  73584. if (other.intersectsRectangle (rects.getReference (i)))
  73585. return true;
  73586. return false;
  73587. }
  73588. const Rectangle<int> RectangleList::getBounds() const throw()
  73589. {
  73590. if (rects.size() <= 1)
  73591. {
  73592. if (rects.size() == 0)
  73593. return Rectangle<int>();
  73594. else
  73595. return rects.getReference (0);
  73596. }
  73597. else
  73598. {
  73599. const Rectangle<int>& r = rects.getReference (0);
  73600. int minX = r.x;
  73601. int minY = r.y;
  73602. int maxX = minX + r.w;
  73603. int maxY = minY + r.h;
  73604. for (int i = rects.size(); --i > 0;)
  73605. {
  73606. const Rectangle<int>& r2 = rects.getReference (i);
  73607. minX = jmin (minX, r2.x);
  73608. minY = jmin (minY, r2.y);
  73609. maxX = jmax (maxX, r2.getRight());
  73610. maxY = jmax (maxY, r2.getBottom());
  73611. }
  73612. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73613. }
  73614. }
  73615. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73616. {
  73617. for (int i = rects.size(); --i >= 0;)
  73618. {
  73619. Rectangle<int>& r = rects.getReference (i);
  73620. r.x += dx;
  73621. r.y += dy;
  73622. }
  73623. }
  73624. const Path RectangleList::toPath() const throw()
  73625. {
  73626. Path p;
  73627. for (int i = rects.size(); --i >= 0;)
  73628. {
  73629. const Rectangle<int>& r = rects.getReference (i);
  73630. p.addRectangle ((float) r.x,
  73631. (float) r.y,
  73632. (float) r.w,
  73633. (float) r.h);
  73634. }
  73635. return p;
  73636. }
  73637. END_JUCE_NAMESPACE
  73638. /*** End of inlined file: juce_RectangleList.cpp ***/
  73639. /*** Start of inlined file: juce_Image.cpp ***/
  73640. BEGIN_JUCE_NAMESPACE
  73641. static const int fullAlphaThreshold = 253;
  73642. Image::Image (const PixelFormat format_,
  73643. const int imageWidth_,
  73644. const int imageHeight_)
  73645. : format (format_),
  73646. imageWidth (imageWidth_),
  73647. imageHeight (imageHeight_),
  73648. imageData (0)
  73649. {
  73650. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73651. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73652. // actual image will be at least 1x1.
  73653. }
  73654. Image::Image (const PixelFormat format_,
  73655. const int imageWidth_,
  73656. const int imageHeight_,
  73657. const bool clearImage)
  73658. : format (format_),
  73659. imageWidth (imageWidth_),
  73660. imageHeight (imageHeight_)
  73661. {
  73662. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73663. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73664. // actual image will be at least 1x1.
  73665. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73666. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  73667. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  73668. imageData = imageDataAllocated;
  73669. }
  73670. Image::Image (const Image& other)
  73671. : format (other.format),
  73672. imageWidth (other.imageWidth),
  73673. imageHeight (other.imageHeight)
  73674. {
  73675. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73676. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  73677. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  73678. imageData = imageDataAllocated;
  73679. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  73680. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  73681. }
  73682. Image::~Image()
  73683. {
  73684. }
  73685. LowLevelGraphicsContext* Image::createLowLevelContext()
  73686. {
  73687. return new LowLevelGraphicsSoftwareRenderer (*this);
  73688. }
  73689. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  73690. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73691. lineStride (image.lineStride),
  73692. pixelStride (image.pixelStride),
  73693. width (w),
  73694. height (h)
  73695. {
  73696. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73697. }
  73698. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  73699. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73700. lineStride (image.lineStride),
  73701. pixelStride (image.pixelStride),
  73702. width (w),
  73703. height (h)
  73704. {
  73705. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73706. }
  73707. Image::BitmapData::~BitmapData()
  73708. {
  73709. }
  73710. void Image::setPixelData (int x, int y, int w, int h,
  73711. const uint8* sourcePixelData, int sourceLineStride)
  73712. {
  73713. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  73714. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  73715. {
  73716. const BitmapData dest (*this, x, y, w, h, true);
  73717. for (int i = 0; i < h; ++i)
  73718. {
  73719. memcpy (dest.getLinePointer(i),
  73720. sourcePixelData + sourceLineStride * i,
  73721. w * dest.pixelStride);
  73722. }
  73723. }
  73724. }
  73725. void Image::clear (int dx, int dy, int dw, int dh,
  73726. const Colour& colourToClearTo)
  73727. {
  73728. const PixelARGB col (colourToClearTo.getPixelARGB());
  73729. const BitmapData destData (*this, dx, dy, dw, dh, true);
  73730. uint8* dest = destData.data;
  73731. while (--dh >= 0)
  73732. {
  73733. uint8* line = dest;
  73734. dest += destData.lineStride;
  73735. if (isARGB())
  73736. {
  73737. for (int x = dw; --x >= 0;)
  73738. {
  73739. ((PixelARGB*) line)->set (col);
  73740. line += destData.pixelStride;
  73741. }
  73742. }
  73743. else if (isRGB())
  73744. {
  73745. for (int x = dw; --x >= 0;)
  73746. {
  73747. ((PixelRGB*) line)->set (col);
  73748. line += destData.pixelStride;
  73749. }
  73750. }
  73751. else
  73752. {
  73753. for (int x = dw; --x >= 0;)
  73754. {
  73755. *line = col.getAlpha();
  73756. line += destData.pixelStride;
  73757. }
  73758. }
  73759. }
  73760. }
  73761. Image* Image::createCopy (int newWidth, int newHeight,
  73762. const Graphics::ResamplingQuality quality) const
  73763. {
  73764. if (newWidth < 0)
  73765. newWidth = imageWidth;
  73766. if (newHeight < 0)
  73767. newHeight = imageHeight;
  73768. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  73769. Graphics g (*newImage);
  73770. g.setImageResamplingQuality (quality);
  73771. g.drawImage (this,
  73772. 0, 0, newWidth, newHeight,
  73773. 0, 0, imageWidth, imageHeight,
  73774. false);
  73775. return newImage;
  73776. }
  73777. Image* Image::createCopyOfAlphaChannel() const
  73778. {
  73779. jassert (format != SingleChannel);
  73780. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  73781. if (! hasAlphaChannel())
  73782. {
  73783. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  73784. }
  73785. else
  73786. {
  73787. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  73788. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  73789. for (int y = 0; y < imageHeight; ++y)
  73790. {
  73791. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  73792. uint8* dst = destData.getLinePointer (y);
  73793. for (int x = imageWidth; --x >= 0;)
  73794. {
  73795. *dst++ = src->getAlpha();
  73796. ++src;
  73797. }
  73798. }
  73799. }
  73800. return newImage;
  73801. }
  73802. const Colour Image::getPixelAt (const int x, const int y) const
  73803. {
  73804. Colour c;
  73805. if (((unsigned int) x) < (unsigned int) imageWidth
  73806. && ((unsigned int) y) < (unsigned int) imageHeight)
  73807. {
  73808. const BitmapData srcData (*this, x, y, 1, 1);
  73809. if (isARGB())
  73810. {
  73811. PixelARGB p (*(const PixelARGB*) srcData.data);
  73812. p.unpremultiply();
  73813. c = Colour (p.getARGB());
  73814. }
  73815. else if (isRGB())
  73816. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  73817. else
  73818. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  73819. }
  73820. return c;
  73821. }
  73822. void Image::setPixelAt (const int x, const int y,
  73823. const Colour& colour)
  73824. {
  73825. if (((unsigned int) x) < (unsigned int) imageWidth
  73826. && ((unsigned int) y) < (unsigned int) imageHeight)
  73827. {
  73828. const BitmapData destData (*this, x, y, 1, 1, true);
  73829. const PixelARGB col (colour.getPixelARGB());
  73830. if (isARGB())
  73831. ((PixelARGB*) destData.data)->set (col);
  73832. else if (isRGB())
  73833. ((PixelRGB*) destData.data)->set (col);
  73834. else
  73835. *(destData.data) = col.getAlpha();
  73836. }
  73837. }
  73838. void Image::multiplyAlphaAt (const int x, const int y,
  73839. const float multiplier)
  73840. {
  73841. if (((unsigned int) x) < (unsigned int) imageWidth
  73842. && ((unsigned int) y) < (unsigned int) imageHeight
  73843. && hasAlphaChannel())
  73844. {
  73845. const BitmapData destData (*this, x, y, 1, 1, true);
  73846. if (isARGB())
  73847. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  73848. else
  73849. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  73850. }
  73851. }
  73852. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  73853. {
  73854. if (hasAlphaChannel())
  73855. {
  73856. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73857. if (isARGB())
  73858. {
  73859. for (int y = 0; y < imageHeight; ++y)
  73860. {
  73861. uint8* p = destData.getLinePointer (y);
  73862. for (int x = 0; x < imageWidth; ++x)
  73863. {
  73864. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  73865. p += destData.pixelStride;
  73866. }
  73867. }
  73868. }
  73869. else
  73870. {
  73871. for (int y = 0; y < imageHeight; ++y)
  73872. {
  73873. uint8* p = destData.getLinePointer (y);
  73874. for (int x = 0; x < imageWidth; ++x)
  73875. {
  73876. *p = (uint8) (*p * amountToMultiplyBy);
  73877. p += destData.pixelStride;
  73878. }
  73879. }
  73880. }
  73881. }
  73882. else
  73883. {
  73884. jassertfalse // can't do this without an alpha-channel!
  73885. }
  73886. }
  73887. void Image::desaturate()
  73888. {
  73889. if (isARGB() || isRGB())
  73890. {
  73891. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73892. if (isARGB())
  73893. {
  73894. for (int y = 0; y < imageHeight; ++y)
  73895. {
  73896. uint8* p = destData.getLinePointer (y);
  73897. for (int x = 0; x < imageWidth; ++x)
  73898. {
  73899. ((PixelARGB*) p)->desaturate();
  73900. p += destData.pixelStride;
  73901. }
  73902. }
  73903. }
  73904. else
  73905. {
  73906. for (int y = 0; y < imageHeight; ++y)
  73907. {
  73908. uint8* p = destData.getLinePointer (y);
  73909. for (int x = 0; x < imageWidth; ++x)
  73910. {
  73911. ((PixelRGB*) p)->desaturate();
  73912. p += destData.pixelStride;
  73913. }
  73914. }
  73915. }
  73916. }
  73917. }
  73918. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  73919. {
  73920. if (hasAlphaChannel())
  73921. {
  73922. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  73923. SparseSet <int> pixelsOnRow;
  73924. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  73925. for (int y = 0; y < imageHeight; ++y)
  73926. {
  73927. pixelsOnRow.clear();
  73928. const uint8* lineData = srcData.getLinePointer (y);
  73929. if (isARGB())
  73930. {
  73931. for (int x = 0; x < imageWidth; ++x)
  73932. {
  73933. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  73934. pixelsOnRow.addRange (x, 1);
  73935. lineData += srcData.pixelStride;
  73936. }
  73937. }
  73938. else
  73939. {
  73940. for (int x = 0; x < imageWidth; ++x)
  73941. {
  73942. if (*lineData >= threshold)
  73943. pixelsOnRow.addRange (x, 1);
  73944. lineData += srcData.pixelStride;
  73945. }
  73946. }
  73947. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  73948. {
  73949. int x, w;
  73950. if (pixelsOnRow.getRange (i, x, w))
  73951. result.add (Rectangle<int> (x, y, w, 1));
  73952. }
  73953. result.consolidate();
  73954. }
  73955. }
  73956. else
  73957. {
  73958. result.add (0, 0, imageWidth, imageHeight);
  73959. }
  73960. }
  73961. void Image::moveImageSection (int dx, int dy,
  73962. int sx, int sy,
  73963. int w, int h)
  73964. {
  73965. if (dx < 0)
  73966. {
  73967. w += dx;
  73968. sx -= dx;
  73969. dx = 0;
  73970. }
  73971. if (dy < 0)
  73972. {
  73973. h += dy;
  73974. sy -= dy;
  73975. dy = 0;
  73976. }
  73977. if (sx < 0)
  73978. {
  73979. w += sx;
  73980. dx -= sx;
  73981. sx = 0;
  73982. }
  73983. if (sy < 0)
  73984. {
  73985. h += sy;
  73986. dy -= sy;
  73987. sy = 0;
  73988. }
  73989. const int minX = jmin (dx, sx);
  73990. const int minY = jmin (dy, sy);
  73991. w = jmin (w, getWidth() - jmax (sx, dx));
  73992. h = jmin (h, getHeight() - jmax (sy, dy));
  73993. if (w > 0 && h > 0)
  73994. {
  73995. const int maxX = jmax (dx, sx) + w;
  73996. const int maxY = jmax (dy, sy) + h;
  73997. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  73998. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  73999. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  74000. const int lineSize = destData.pixelStride * w;
  74001. if (dy > sy)
  74002. {
  74003. while (--h >= 0)
  74004. {
  74005. const int offset = h * destData.lineStride;
  74006. memmove (dst + offset, src + offset, lineSize);
  74007. }
  74008. }
  74009. else if (dst != src)
  74010. {
  74011. while (--h >= 0)
  74012. {
  74013. memmove (dst, src, lineSize);
  74014. dst += destData.lineStride;
  74015. src += destData.lineStride;
  74016. }
  74017. }
  74018. }
  74019. }
  74020. END_JUCE_NAMESPACE
  74021. /*** End of inlined file: juce_Image.cpp ***/
  74022. /*** Start of inlined file: juce_ImageCache.cpp ***/
  74023. BEGIN_JUCE_NAMESPACE
  74024. struct ImageCacheItem
  74025. {
  74026. ScopedPointer <Image> image;
  74027. int64 hashCode;
  74028. int refCount;
  74029. uint32 releaseTime;
  74030. juce_UseDebuggingNewOperator
  74031. };
  74032. static ImageCache* instance = 0;
  74033. static int cacheTimeout = 5000;
  74034. ImageCache::ImageCache()
  74035. {
  74036. }
  74037. ImageCache::~ImageCache()
  74038. {
  74039. jassert (instance == this);
  74040. instance = 0;
  74041. }
  74042. Image* ImageCache::getFromHashCode (const int64 hashCode)
  74043. {
  74044. if (instance != 0)
  74045. {
  74046. const ScopedLock sl (instance->lock);
  74047. for (int i = instance->images.size(); --i >= 0;)
  74048. {
  74049. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74050. if (ci->hashCode == hashCode)
  74051. {
  74052. ci->refCount++;
  74053. return ci->image;
  74054. }
  74055. }
  74056. }
  74057. return 0;
  74058. }
  74059. void ImageCache::addImageToCache (Image* const image,
  74060. const int64 hashCode)
  74061. {
  74062. if (image != 0)
  74063. {
  74064. if (instance == 0)
  74065. instance = new ImageCache();
  74066. ImageCacheItem* const newC = new ImageCacheItem();
  74067. newC->hashCode = hashCode;
  74068. newC->image = image;
  74069. newC->refCount = 1;
  74070. newC->releaseTime = 0;
  74071. const ScopedLock sl (instance->lock);
  74072. instance->images.add (newC);
  74073. }
  74074. }
  74075. void ImageCache::release (Image* const imageToRelease)
  74076. {
  74077. if (imageToRelease != 0 && instance != 0)
  74078. {
  74079. const ScopedLock sl (instance->lock);
  74080. for (int i = instance->images.size(); --i >= 0;)
  74081. {
  74082. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74083. if ((Image*) ci->image == imageToRelease)
  74084. {
  74085. if (--(ci->refCount) == 0)
  74086. ci->releaseTime = Time::getApproximateMillisecondCounter();
  74087. if (! instance->isTimerRunning())
  74088. instance->startTimer (999);
  74089. break;
  74090. }
  74091. }
  74092. }
  74093. }
  74094. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  74095. {
  74096. if (isImageInCache (imageToRelease))
  74097. release (imageToRelease);
  74098. else
  74099. delete imageToRelease;
  74100. }
  74101. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  74102. {
  74103. if (instance != 0)
  74104. {
  74105. const ScopedLock sl (instance->lock);
  74106. for (int i = instance->images.size(); --i >= 0;)
  74107. if ((Image*) instance->images.getUnchecked(i)->image == imageToLookFor)
  74108. return true;
  74109. }
  74110. return false;
  74111. }
  74112. void ImageCache::incReferenceCount (Image* const image)
  74113. {
  74114. if (instance != 0)
  74115. {
  74116. const ScopedLock sl (instance->lock);
  74117. for (int i = instance->images.size(); --i >= 0;)
  74118. {
  74119. ImageCacheItem* const ci = (ImageCacheItem*) instance->images.getUnchecked(i);
  74120. if ((Image*) ci->image == image)
  74121. {
  74122. ci->refCount++;
  74123. return;
  74124. }
  74125. }
  74126. }
  74127. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  74128. }
  74129. void ImageCache::timerCallback()
  74130. {
  74131. int numberStillNeedingReleasing = 0;
  74132. const unsigned int now = Time::getApproximateMillisecondCounter();
  74133. const ScopedLock sl (lock);
  74134. for (int i = images.size(); --i >= 0;)
  74135. {
  74136. ImageCacheItem* const ci = images.getUnchecked(i);
  74137. if (ci->refCount <= 0)
  74138. {
  74139. if (now > ci->releaseTime + cacheTimeout
  74140. || now < ci->releaseTime - 1000)
  74141. {
  74142. images.remove (i);
  74143. }
  74144. else
  74145. {
  74146. ++numberStillNeedingReleasing;
  74147. }
  74148. }
  74149. }
  74150. if (numberStillNeedingReleasing == 0)
  74151. stopTimer();
  74152. }
  74153. Image* ImageCache::getFromFile (const File& file)
  74154. {
  74155. const int64 hashCode = file.hashCode64();
  74156. Image* image = getFromHashCode (hashCode);
  74157. if (image == 0)
  74158. {
  74159. image = ImageFileFormat::loadFrom (file);
  74160. addImageToCache (image, hashCode);
  74161. }
  74162. return image;
  74163. }
  74164. Image* ImageCache::getFromMemory (const void* imageData,
  74165. const int dataSize)
  74166. {
  74167. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  74168. Image* image = getFromHashCode (hashCode);
  74169. if (image == 0)
  74170. {
  74171. image = ImageFileFormat::loadFrom (imageData, dataSize);
  74172. addImageToCache (image, hashCode);
  74173. }
  74174. return image;
  74175. }
  74176. void ImageCache::setCacheTimeout (const int millisecs)
  74177. {
  74178. cacheTimeout = millisecs;
  74179. }
  74180. END_JUCE_NAMESPACE
  74181. /*** End of inlined file: juce_ImageCache.cpp ***/
  74182. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74183. BEGIN_JUCE_NAMESPACE
  74184. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  74185. : values (size_ * size_),
  74186. size (size_)
  74187. {
  74188. clear();
  74189. }
  74190. ImageConvolutionKernel::~ImageConvolutionKernel()
  74191. {
  74192. }
  74193. float ImageConvolutionKernel::getKernelValue (const int x, const int y) const throw()
  74194. {
  74195. if (((unsigned int) x) < (unsigned int) size
  74196. && ((unsigned int) y) < (unsigned int) size)
  74197. {
  74198. return values [x + y * size];
  74199. }
  74200. else
  74201. {
  74202. jassertfalse;
  74203. return 0;
  74204. }
  74205. }
  74206. void ImageConvolutionKernel::setKernelValue (const int x, const int y, const float value) throw()
  74207. {
  74208. if (((unsigned int) x) < (unsigned int) size
  74209. && ((unsigned int) y) < (unsigned int) size)
  74210. {
  74211. values [x + y * size] = value;
  74212. }
  74213. else
  74214. {
  74215. jassertfalse;
  74216. }
  74217. }
  74218. void ImageConvolutionKernel::clear()
  74219. {
  74220. for (int i = size * size; --i >= 0;)
  74221. values[i] = 0;
  74222. }
  74223. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  74224. {
  74225. double currentTotal = 0.0;
  74226. for (int i = size * size; --i >= 0;)
  74227. currentTotal += values[i];
  74228. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  74229. }
  74230. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  74231. {
  74232. for (int i = size * size; --i >= 0;)
  74233. values[i] *= multiplier;
  74234. }
  74235. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  74236. {
  74237. const double radiusFactor = -1.0 / (radius * radius * 2);
  74238. const int centre = size >> 1;
  74239. for (int y = size; --y >= 0;)
  74240. {
  74241. for (int x = size; --x >= 0;)
  74242. {
  74243. const int cx = x - centre;
  74244. const int cy = y - centre;
  74245. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  74246. }
  74247. }
  74248. setOverallSum (1.0f);
  74249. }
  74250. void ImageConvolutionKernel::applyToImage (Image& destImage,
  74251. const Image* sourceImage,
  74252. int dx,
  74253. int dy,
  74254. int dw,
  74255. int dh) const
  74256. {
  74257. ScopedPointer <Image> imageCreated;
  74258. if (sourceImage == 0)
  74259. {
  74260. sourceImage = imageCreated = destImage.createCopy();
  74261. }
  74262. else
  74263. {
  74264. jassert (sourceImage->getWidth() == destImage.getWidth()
  74265. && sourceImage->getHeight() == destImage.getHeight()
  74266. && sourceImage->getFormat() == destImage.getFormat());
  74267. if (sourceImage->getWidth() != destImage.getWidth()
  74268. || sourceImage->getHeight() != destImage.getHeight()
  74269. || sourceImage->getFormat() != destImage.getFormat())
  74270. return;
  74271. }
  74272. const int imageWidth = destImage.getWidth();
  74273. const int imageHeight = destImage.getHeight();
  74274. if (dx >= imageWidth || dy >= imageHeight)
  74275. return;
  74276. if (dx + dw > imageWidth)
  74277. dw = imageWidth - dx;
  74278. if (dy + dh > imageHeight)
  74279. dh = imageHeight - dy;
  74280. const int dx2 = dx + dw;
  74281. const int dy2 = dy + dh;
  74282. const Image::BitmapData destData (destImage, dx, dy, dw, dh, true);
  74283. uint8* line = destData.data;
  74284. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  74285. if (destData.pixelStride == 4)
  74286. {
  74287. for (int y = dy; y < dy2; ++y)
  74288. {
  74289. uint8* dest = line;
  74290. line += destData.lineStride;
  74291. for (int x = dx; x < dx2; ++x)
  74292. {
  74293. float c1 = 0;
  74294. float c2 = 0;
  74295. float c3 = 0;
  74296. float c4 = 0;
  74297. for (int yy = 0; yy < size; ++yy)
  74298. {
  74299. const int sy = y + yy - (size >> 1);
  74300. if (sy >= imageHeight)
  74301. break;
  74302. if (sy >= 0)
  74303. {
  74304. int sx = x - (size >> 1);
  74305. const uint8* src = srcData.getPixelPointer (sx, sy);
  74306. for (int xx = 0; xx < size; ++xx)
  74307. {
  74308. if (sx >= imageWidth)
  74309. break;
  74310. if (sx >= 0)
  74311. {
  74312. const float kernelMult = values [xx + yy * size];
  74313. c1 += kernelMult * *src++;
  74314. c2 += kernelMult * *src++;
  74315. c3 += kernelMult * *src++;
  74316. c4 += kernelMult * *src++;
  74317. }
  74318. else
  74319. {
  74320. src += 4;
  74321. }
  74322. ++sx;
  74323. }
  74324. }
  74325. }
  74326. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  74327. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  74328. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  74329. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  74330. }
  74331. }
  74332. }
  74333. else if (destData.pixelStride == 3)
  74334. {
  74335. for (int y = dy; y < dy2; ++y)
  74336. {
  74337. uint8* dest = line;
  74338. line += destData.lineStride;
  74339. for (int x = dx; x < dx2; ++x)
  74340. {
  74341. float c1 = 0;
  74342. float c2 = 0;
  74343. float c3 = 0;
  74344. for (int yy = 0; yy < size; ++yy)
  74345. {
  74346. const int sy = y + yy - (size >> 1);
  74347. if (sy >= imageHeight)
  74348. break;
  74349. if (sy >= 0)
  74350. {
  74351. int sx = x - (size >> 1);
  74352. const uint8* src = srcData.getPixelPointer (sx, sy);
  74353. for (int xx = 0; xx < size; ++xx)
  74354. {
  74355. if (sx >= imageWidth)
  74356. break;
  74357. if (sx >= 0)
  74358. {
  74359. const float kernelMult = values [xx + yy * size];
  74360. c1 += kernelMult * *src++;
  74361. c2 += kernelMult * *src++;
  74362. c3 += kernelMult * *src++;
  74363. }
  74364. else
  74365. {
  74366. src += 3;
  74367. }
  74368. ++sx;
  74369. }
  74370. }
  74371. }
  74372. *dest++ = (uint8) roundToInt (c1);
  74373. *dest++ = (uint8) roundToInt (c2);
  74374. *dest++ = (uint8) roundToInt (c3);
  74375. }
  74376. }
  74377. }
  74378. }
  74379. END_JUCE_NAMESPACE
  74380. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74381. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  74382. BEGIN_JUCE_NAMESPACE
  74383. /*** Start of inlined file: juce_GIFLoader.h ***/
  74384. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  74385. #define __JUCE_GIFLOADER_JUCEHEADER__
  74386. #ifndef DOXYGEN
  74387. class GIFLoader
  74388. {
  74389. public:
  74390. GIFLoader (InputStream& in);
  74391. ~GIFLoader();
  74392. Image* getImage() const { return image; }
  74393. private:
  74394. Image* image;
  74395. InputStream& input;
  74396. uint8 buffer [300];
  74397. uint8 palette [256][4];
  74398. bool dataBlockIsZero, fresh, finished;
  74399. int currentBit, lastBit, lastByteIndex;
  74400. int codeSize, setCodeSize;
  74401. int maxCode, maxCodeSize;
  74402. int firstcode, oldcode;
  74403. int clearCode, end_code;
  74404. enum { maxGifCode = 1 << 12 };
  74405. int table [2] [maxGifCode];
  74406. int stack [2 * maxGifCode];
  74407. int *sp;
  74408. bool getSizeFromHeader (int& width, int& height);
  74409. bool readPalette (const int numCols);
  74410. int readDataBlock (unsigned char* dest);
  74411. int processExtension (int type, int& transparent);
  74412. int readLZWByte (bool initialise, int input_code_size);
  74413. int getCode (int code_size, bool initialise);
  74414. bool readImage (int width, int height, int interlace, int transparent);
  74415. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74416. GIFLoader (const GIFLoader&);
  74417. GIFLoader& operator= (const GIFLoader&);
  74418. };
  74419. #endif // DOXYGEN
  74420. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74421. /*** End of inlined file: juce_GIFLoader.h ***/
  74422. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74423. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74424. PNGImageFormat::PNGImageFormat() {}
  74425. PNGImageFormat::~PNGImageFormat() {}
  74426. const String PNGImageFormat::getFormatName()
  74427. {
  74428. return T("PNG");
  74429. }
  74430. bool PNGImageFormat::canUnderstand (InputStream& in)
  74431. {
  74432. const int bytesNeeded = 4;
  74433. char header [bytesNeeded];
  74434. return in.read (header, bytesNeeded) == bytesNeeded
  74435. && header[1] == 'P'
  74436. && header[2] == 'N'
  74437. && header[3] == 'G';
  74438. }
  74439. Image* PNGImageFormat::decodeImage (InputStream& in)
  74440. {
  74441. return juce_loadPNGImageFromStream (in);
  74442. }
  74443. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74444. OutputStream& destStream)
  74445. {
  74446. return juce_writePNGImageToStream (sourceImage, destStream);
  74447. }
  74448. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74449. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74450. JPEGImageFormat::JPEGImageFormat()
  74451. : quality (-1.0f)
  74452. {
  74453. }
  74454. JPEGImageFormat::~JPEGImageFormat() {}
  74455. void JPEGImageFormat::setQuality (const float newQuality)
  74456. {
  74457. quality = newQuality;
  74458. }
  74459. const String JPEGImageFormat::getFormatName()
  74460. {
  74461. return T("JPEG");
  74462. }
  74463. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74464. {
  74465. const int bytesNeeded = 10;
  74466. uint8 header [bytesNeeded];
  74467. if (in.read (header, bytesNeeded) == bytesNeeded)
  74468. {
  74469. return header[0] == 0xff
  74470. && header[1] == 0xd8
  74471. && header[2] == 0xff
  74472. && (header[3] == 0xe0 || header[3] == 0xe1);
  74473. }
  74474. return false;
  74475. }
  74476. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74477. {
  74478. return juce_loadJPEGImageFromStream (in);
  74479. }
  74480. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74481. OutputStream& destStream)
  74482. {
  74483. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74484. }
  74485. class GIFImageFormat : public ImageFileFormat
  74486. {
  74487. public:
  74488. GIFImageFormat() {}
  74489. ~GIFImageFormat() {}
  74490. const String getFormatName()
  74491. {
  74492. return T("GIF");
  74493. }
  74494. bool canUnderstand (InputStream& in)
  74495. {
  74496. const int bytesNeeded = 4;
  74497. char header [bytesNeeded];
  74498. return (in.read (header, bytesNeeded) == bytesNeeded)
  74499. && header[0] == 'G'
  74500. && header[1] == 'I'
  74501. && header[2] == 'F';
  74502. }
  74503. Image* decodeImage (InputStream& in)
  74504. {
  74505. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74506. return loader->getImage();
  74507. }
  74508. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74509. {
  74510. return false;
  74511. }
  74512. };
  74513. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74514. {
  74515. static PNGImageFormat png;
  74516. static JPEGImageFormat jpg;
  74517. static GIFImageFormat gif;
  74518. ImageFileFormat* formats[4];
  74519. int numFormats = 0;
  74520. formats [numFormats++] = &png;
  74521. formats [numFormats++] = &jpg;
  74522. formats [numFormats++] = &gif;
  74523. const int64 streamPos = input.getPosition();
  74524. for (int i = 0; i < numFormats; ++i)
  74525. {
  74526. const bool found = formats[i]->canUnderstand (input);
  74527. input.setPosition (streamPos);
  74528. if (found)
  74529. return formats[i];
  74530. }
  74531. return 0;
  74532. }
  74533. Image* ImageFileFormat::loadFrom (InputStream& input)
  74534. {
  74535. ImageFileFormat* const format = findImageFormatForStream (input);
  74536. if (format != 0)
  74537. return format->decodeImage (input);
  74538. return 0;
  74539. }
  74540. Image* ImageFileFormat::loadFrom (const File& file)
  74541. {
  74542. InputStream* const in = file.createInputStream();
  74543. if (in != 0)
  74544. {
  74545. BufferedInputStream b (in, 8192, true);
  74546. return loadFrom (b);
  74547. }
  74548. return 0;
  74549. }
  74550. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74551. {
  74552. if (rawData != 0 && numBytes > 4)
  74553. {
  74554. MemoryInputStream stream (rawData, numBytes, false);
  74555. return loadFrom (stream);
  74556. }
  74557. return 0;
  74558. }
  74559. END_JUCE_NAMESPACE
  74560. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74561. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74562. BEGIN_JUCE_NAMESPACE
  74563. GIFLoader::GIFLoader (InputStream& in)
  74564. : image (0),
  74565. input (in),
  74566. dataBlockIsZero (false),
  74567. fresh (false),
  74568. finished (false)
  74569. {
  74570. currentBit = lastBit = lastByteIndex = 0;
  74571. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74572. firstcode = oldcode = 0;
  74573. clearCode = end_code = 0;
  74574. int imageWidth, imageHeight;
  74575. int transparent = -1;
  74576. if (! getSizeFromHeader (imageWidth, imageHeight))
  74577. return;
  74578. if ((imageWidth <= 0) || (imageHeight <= 0))
  74579. return;
  74580. unsigned char buf [16];
  74581. if (in.read (buf, 3) != 3)
  74582. return;
  74583. int numColours = 2 << (buf[0] & 7);
  74584. if ((buf[0] & 0x80) != 0)
  74585. readPalette (numColours);
  74586. for (;;)
  74587. {
  74588. if (input.read (buf, 1) != 1)
  74589. break;
  74590. if (buf[0] == ';')
  74591. break;
  74592. if (buf[0] == '!')
  74593. {
  74594. if (input.read (buf, 1) != 1)
  74595. break;
  74596. if (processExtension (buf[0], transparent) < 0)
  74597. break;
  74598. continue;
  74599. }
  74600. if (buf[0] != ',')
  74601. continue;
  74602. if (input.read (buf, 9) != 9)
  74603. break;
  74604. imageWidth = makeWord (buf[4], buf[5]);
  74605. imageHeight = makeWord (buf[6], buf[7]);
  74606. numColours = 2 << (buf[8] & 7);
  74607. if ((buf[8] & 0x80) != 0)
  74608. if (! readPalette (numColours))
  74609. break;
  74610. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74611. imageWidth, imageHeight, (transparent >= 0));
  74612. readImage (imageWidth, imageHeight,
  74613. (buf[8] & 0x40) != 0,
  74614. transparent);
  74615. break;
  74616. }
  74617. }
  74618. GIFLoader::~GIFLoader()
  74619. {
  74620. }
  74621. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74622. {
  74623. unsigned char b [8];
  74624. if (input.read (b, 6) == 6)
  74625. {
  74626. if ((strncmp ("GIF87a", (char*) b, 6) == 0)
  74627. || (strncmp ("GIF89a", (char*) b, 6) == 0))
  74628. {
  74629. if (input.read (b, 4) == 4)
  74630. {
  74631. w = makeWord (b[0], b[1]);
  74632. h = makeWord (b[2], b[3]);
  74633. return true;
  74634. }
  74635. }
  74636. }
  74637. return false;
  74638. }
  74639. bool GIFLoader::readPalette (const int numCols)
  74640. {
  74641. unsigned char rgb[4];
  74642. for (int i = 0; i < numCols; ++i)
  74643. {
  74644. input.read (rgb, 3);
  74645. palette [i][0] = rgb[0];
  74646. palette [i][1] = rgb[1];
  74647. palette [i][2] = rgb[2];
  74648. palette [i][3] = 0xff;
  74649. }
  74650. return true;
  74651. }
  74652. int GIFLoader::readDataBlock (unsigned char* const dest)
  74653. {
  74654. unsigned char n;
  74655. if (input.read (&n, 1) == 1)
  74656. {
  74657. dataBlockIsZero = (n == 0);
  74658. if (dataBlockIsZero || (input.read (dest, n) == n))
  74659. return n;
  74660. }
  74661. return -1;
  74662. }
  74663. int GIFLoader::processExtension (const int type, int& transparent)
  74664. {
  74665. unsigned char b [300];
  74666. int n = 0;
  74667. if (type == 0xf9)
  74668. {
  74669. n = readDataBlock (b);
  74670. if (n < 0)
  74671. return 1;
  74672. if ((b[0] & 0x1) != 0)
  74673. transparent = b[3];
  74674. }
  74675. do
  74676. {
  74677. n = readDataBlock (b);
  74678. }
  74679. while (n > 0);
  74680. return n;
  74681. }
  74682. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  74683. {
  74684. if (initialise)
  74685. {
  74686. currentBit = 0;
  74687. lastBit = 0;
  74688. finished = false;
  74689. return 0;
  74690. }
  74691. if ((currentBit + codeSize_) >= lastBit)
  74692. {
  74693. if (finished)
  74694. return -1;
  74695. buffer[0] = buffer [lastByteIndex - 2];
  74696. buffer[1] = buffer [lastByteIndex - 1];
  74697. const int n = readDataBlock (&buffer[2]);
  74698. if (n == 0)
  74699. finished = true;
  74700. lastByteIndex = 2 + n;
  74701. currentBit = (currentBit - lastBit) + 16;
  74702. lastBit = (2 + n) * 8 ;
  74703. }
  74704. int result = 0;
  74705. int i = currentBit;
  74706. for (int j = 0; j < codeSize_; ++j)
  74707. {
  74708. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  74709. ++i;
  74710. }
  74711. currentBit += codeSize_;
  74712. return result;
  74713. }
  74714. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  74715. {
  74716. int code, incode, i;
  74717. if (initialise)
  74718. {
  74719. setCodeSize = inputCodeSize;
  74720. codeSize = setCodeSize + 1;
  74721. clearCode = 1 << setCodeSize;
  74722. end_code = clearCode + 1;
  74723. maxCodeSize = 2 * clearCode;
  74724. maxCode = clearCode + 2;
  74725. getCode (0, true);
  74726. fresh = true;
  74727. for (i = 0; i < clearCode; ++i)
  74728. {
  74729. table[0][i] = 0;
  74730. table[1][i] = i;
  74731. }
  74732. for (; i < maxGifCode; ++i)
  74733. {
  74734. table[0][i] = 0;
  74735. table[1][i] = 0;
  74736. }
  74737. sp = stack;
  74738. return 0;
  74739. }
  74740. else if (fresh)
  74741. {
  74742. fresh = false;
  74743. do
  74744. {
  74745. firstcode = oldcode
  74746. = getCode (codeSize, false);
  74747. }
  74748. while (firstcode == clearCode);
  74749. return firstcode;
  74750. }
  74751. if (sp > stack)
  74752. return *--sp;
  74753. while ((code = getCode (codeSize, false)) >= 0)
  74754. {
  74755. if (code == clearCode)
  74756. {
  74757. for (i = 0; i < clearCode; ++i)
  74758. {
  74759. table[0][i] = 0;
  74760. table[1][i] = i;
  74761. }
  74762. for (; i < maxGifCode; ++i)
  74763. {
  74764. table[0][i] = 0;
  74765. table[1][i] = 0;
  74766. }
  74767. codeSize = setCodeSize + 1;
  74768. maxCodeSize = 2 * clearCode;
  74769. maxCode = clearCode + 2;
  74770. sp = stack;
  74771. firstcode = oldcode = getCode (codeSize, false);
  74772. return firstcode;
  74773. }
  74774. else if (code == end_code)
  74775. {
  74776. if (dataBlockIsZero)
  74777. return -2;
  74778. unsigned char buf [260];
  74779. int n;
  74780. while ((n = readDataBlock (buf)) > 0)
  74781. {}
  74782. if (n != 0)
  74783. return -2;
  74784. }
  74785. incode = code;
  74786. if (code >= maxCode)
  74787. {
  74788. *sp++ = firstcode;
  74789. code = oldcode;
  74790. }
  74791. while (code >= clearCode)
  74792. {
  74793. *sp++ = table[1][code];
  74794. if (code == table[0][code])
  74795. return -2;
  74796. code = table[0][code];
  74797. }
  74798. *sp++ = firstcode = table[1][code];
  74799. if ((code = maxCode) < maxGifCode)
  74800. {
  74801. table[0][code] = oldcode;
  74802. table[1][code] = firstcode;
  74803. ++maxCode;
  74804. if ((maxCode >= maxCodeSize)
  74805. && (maxCodeSize < maxGifCode))
  74806. {
  74807. maxCodeSize <<= 1;
  74808. ++codeSize;
  74809. }
  74810. }
  74811. oldcode = incode;
  74812. if (sp > stack)
  74813. return *--sp;
  74814. }
  74815. return code;
  74816. }
  74817. bool GIFLoader::readImage (const int width, const int height,
  74818. const int interlace, const int transparent)
  74819. {
  74820. unsigned char c;
  74821. if (input.read (&c, 1) != 1
  74822. || readLZWByte (true, c) < 0)
  74823. return false;
  74824. if (transparent >= 0)
  74825. {
  74826. palette [transparent][0] = 0;
  74827. palette [transparent][1] = 0;
  74828. palette [transparent][2] = 0;
  74829. palette [transparent][3] = 0;
  74830. }
  74831. int index;
  74832. int xpos = 0, ypos = 0, pass = 0;
  74833. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  74834. uint8* p = destData.data;
  74835. const bool hasAlpha = image->hasAlphaChannel();
  74836. while ((index = readLZWByte (false, c)) >= 0)
  74837. {
  74838. const uint8* const paletteEntry = palette [index];
  74839. if (hasAlpha)
  74840. {
  74841. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  74842. paletteEntry[0],
  74843. paletteEntry[1],
  74844. paletteEntry[2]);
  74845. ((PixelARGB*) p)->premultiply();
  74846. }
  74847. else
  74848. {
  74849. ((PixelRGB*) p)->setARGB (0,
  74850. paletteEntry[0],
  74851. paletteEntry[1],
  74852. paletteEntry[2]);
  74853. }
  74854. p += destData.pixelStride;
  74855. ++xpos;
  74856. if (xpos == width)
  74857. {
  74858. xpos = 0;
  74859. if (interlace)
  74860. {
  74861. switch (pass)
  74862. {
  74863. case 0:
  74864. case 1:
  74865. ypos += 8;
  74866. break;
  74867. case 2:
  74868. ypos += 4;
  74869. break;
  74870. case 3:
  74871. ypos += 2;
  74872. break;
  74873. }
  74874. while (ypos >= height)
  74875. {
  74876. ++pass;
  74877. switch (pass)
  74878. {
  74879. case 1:
  74880. ypos = 4;
  74881. break;
  74882. case 2:
  74883. ypos = 2;
  74884. break;
  74885. case 3:
  74886. ypos = 1;
  74887. break;
  74888. default:
  74889. return true;
  74890. }
  74891. }
  74892. }
  74893. else
  74894. {
  74895. ++ypos;
  74896. }
  74897. p = destData.getPixelPointer (xpos, ypos);
  74898. }
  74899. if (ypos >= height)
  74900. break;
  74901. }
  74902. return true;
  74903. }
  74904. END_JUCE_NAMESPACE
  74905. /*** End of inlined file: juce_GIFLoader.cpp ***/
  74906. #endif
  74907. //==============================================================================
  74908. // some files include lots of library code, so leave them to the end to avoid cluttering
  74909. // up the build for the clean files.
  74910. #if JUCE_BUILD_CORE
  74911. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  74912. namespace zlibNamespace
  74913. {
  74914. #if JUCE_INCLUDE_ZLIB_CODE
  74915. #undef OS_CODE
  74916. #undef fdopen
  74917. /*** Start of inlined file: zlib.h ***/
  74918. #ifndef ZLIB_H
  74919. #define ZLIB_H
  74920. /*** Start of inlined file: zconf.h ***/
  74921. #ifndef ZCONF_H
  74922. #define ZCONF_H
  74923. // *** Just a few hacks here to make it compile nicely with Juce..
  74924. #define Z_PREFIX 1
  74925. #undef __MACTYPES__
  74926. #ifdef _MSC_VER
  74927. #pragma warning (disable : 4131 4127 4244 4267)
  74928. #endif
  74929. #ifdef Z_PREFIX
  74930. # define deflateInit_ z_deflateInit_
  74931. # define deflate z_deflate
  74932. # define deflateEnd z_deflateEnd
  74933. # define inflateInit_ z_inflateInit_
  74934. # define inflate z_inflate
  74935. # define inflateEnd z_inflateEnd
  74936. # define deflateInit2_ z_deflateInit2_
  74937. # define deflateSetDictionary z_deflateSetDictionary
  74938. # define deflateCopy z_deflateCopy
  74939. # define deflateReset z_deflateReset
  74940. # define deflateParams z_deflateParams
  74941. # define deflateBound z_deflateBound
  74942. # define deflatePrime z_deflatePrime
  74943. # define inflateInit2_ z_inflateInit2_
  74944. # define inflateSetDictionary z_inflateSetDictionary
  74945. # define inflateSync z_inflateSync
  74946. # define inflateSyncPoint z_inflateSyncPoint
  74947. # define inflateCopy z_inflateCopy
  74948. # define inflateReset z_inflateReset
  74949. # define inflateBack z_inflateBack
  74950. # define inflateBackEnd z_inflateBackEnd
  74951. # define compress z_compress
  74952. # define compress2 z_compress2
  74953. # define compressBound z_compressBound
  74954. # define uncompress z_uncompress
  74955. # define adler32 z_adler32
  74956. # define crc32 z_crc32
  74957. # define get_crc_table z_get_crc_table
  74958. # define zError z_zError
  74959. # define alloc_func z_alloc_func
  74960. # define free_func z_free_func
  74961. # define in_func z_in_func
  74962. # define out_func z_out_func
  74963. # define Byte z_Byte
  74964. # define uInt z_uInt
  74965. # define uLong z_uLong
  74966. # define Bytef z_Bytef
  74967. # define charf z_charf
  74968. # define intf z_intf
  74969. # define uIntf z_uIntf
  74970. # define uLongf z_uLongf
  74971. # define voidpf z_voidpf
  74972. # define voidp z_voidp
  74973. #endif
  74974. #if defined(__MSDOS__) && !defined(MSDOS)
  74975. # define MSDOS
  74976. #endif
  74977. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  74978. # define OS2
  74979. #endif
  74980. #if defined(_WINDOWS) && !defined(WINDOWS)
  74981. # define WINDOWS
  74982. #endif
  74983. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  74984. # ifndef WIN32
  74985. # define WIN32
  74986. # endif
  74987. #endif
  74988. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  74989. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  74990. # ifndef SYS16BIT
  74991. # define SYS16BIT
  74992. # endif
  74993. # endif
  74994. #endif
  74995. #ifdef SYS16BIT
  74996. # define MAXSEG_64K
  74997. #endif
  74998. #ifdef MSDOS
  74999. # define UNALIGNED_OK
  75000. #endif
  75001. #ifdef __STDC_VERSION__
  75002. # ifndef STDC
  75003. # define STDC
  75004. # endif
  75005. # if __STDC_VERSION__ >= 199901L
  75006. # ifndef STDC99
  75007. # define STDC99
  75008. # endif
  75009. # endif
  75010. #endif
  75011. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  75012. # define STDC
  75013. #endif
  75014. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  75015. # define STDC
  75016. #endif
  75017. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  75018. # define STDC
  75019. #endif
  75020. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  75021. # define STDC
  75022. #endif
  75023. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  75024. # define STDC
  75025. #endif
  75026. #ifndef STDC
  75027. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  75028. # define const /* note: need a more gentle solution here */
  75029. # endif
  75030. #endif
  75031. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  75032. # define NO_DUMMY_DECL
  75033. #endif
  75034. #ifndef MAX_MEM_LEVEL
  75035. # ifdef MAXSEG_64K
  75036. # define MAX_MEM_LEVEL 8
  75037. # else
  75038. # define MAX_MEM_LEVEL 9
  75039. # endif
  75040. #endif
  75041. #ifndef MAX_WBITS
  75042. # define MAX_WBITS 15 /* 32K LZ77 window */
  75043. #endif
  75044. #ifndef OF /* function prototypes */
  75045. # ifdef STDC
  75046. # define OF(args) args
  75047. # else
  75048. # define OF(args) ()
  75049. # endif
  75050. #endif
  75051. #ifdef SYS16BIT
  75052. # if defined(M_I86SM) || defined(M_I86MM)
  75053. # define SMALL_MEDIUM
  75054. # ifdef _MSC_VER
  75055. # define FAR _far
  75056. # else
  75057. # define FAR far
  75058. # endif
  75059. # endif
  75060. # if (defined(__SMALL__) || defined(__MEDIUM__))
  75061. # define SMALL_MEDIUM
  75062. # ifdef __BORLANDC__
  75063. # define FAR _far
  75064. # else
  75065. # define FAR far
  75066. # endif
  75067. # endif
  75068. #endif
  75069. #if defined(WINDOWS) || defined(WIN32)
  75070. # ifdef ZLIB_DLL
  75071. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  75072. # ifdef ZLIB_INTERNAL
  75073. # define ZEXTERN extern __declspec(dllexport)
  75074. # else
  75075. # define ZEXTERN extern __declspec(dllimport)
  75076. # endif
  75077. # endif
  75078. # endif /* ZLIB_DLL */
  75079. # ifdef ZLIB_WINAPI
  75080. # ifdef FAR
  75081. # undef FAR
  75082. # endif
  75083. # include <windows.h>
  75084. # define ZEXPORT WINAPI
  75085. # ifdef WIN32
  75086. # define ZEXPORTVA WINAPIV
  75087. # else
  75088. # define ZEXPORTVA FAR CDECL
  75089. # endif
  75090. # endif
  75091. #endif
  75092. #if defined (__BEOS__)
  75093. # ifdef ZLIB_DLL
  75094. # ifdef ZLIB_INTERNAL
  75095. # define ZEXPORT __declspec(dllexport)
  75096. # define ZEXPORTVA __declspec(dllexport)
  75097. # else
  75098. # define ZEXPORT __declspec(dllimport)
  75099. # define ZEXPORTVA __declspec(dllimport)
  75100. # endif
  75101. # endif
  75102. #endif
  75103. #ifndef ZEXTERN
  75104. # define ZEXTERN extern
  75105. #endif
  75106. #ifndef ZEXPORT
  75107. # define ZEXPORT
  75108. #endif
  75109. #ifndef ZEXPORTVA
  75110. # define ZEXPORTVA
  75111. #endif
  75112. #ifndef FAR
  75113. # define FAR
  75114. #endif
  75115. #if !defined(__MACTYPES__)
  75116. typedef unsigned char Byte; /* 8 bits */
  75117. #endif
  75118. typedef unsigned int uInt; /* 16 bits or more */
  75119. typedef unsigned long uLong; /* 32 bits or more */
  75120. #ifdef SMALL_MEDIUM
  75121. # define Bytef Byte FAR
  75122. #else
  75123. typedef Byte FAR Bytef;
  75124. #endif
  75125. typedef char FAR charf;
  75126. typedef int FAR intf;
  75127. typedef uInt FAR uIntf;
  75128. typedef uLong FAR uLongf;
  75129. #ifdef STDC
  75130. typedef void const *voidpc;
  75131. typedef void FAR *voidpf;
  75132. typedef void *voidp;
  75133. #else
  75134. typedef Byte const *voidpc;
  75135. typedef Byte FAR *voidpf;
  75136. typedef Byte *voidp;
  75137. #endif
  75138. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  75139. # include <sys/types.h> /* for off_t */
  75140. # include <unistd.h> /* for SEEK_* and off_t */
  75141. # ifdef VMS
  75142. # include <unixio.h> /* for off_t */
  75143. # endif
  75144. # define z_off_t off_t
  75145. #endif
  75146. #ifndef SEEK_SET
  75147. # define SEEK_SET 0 /* Seek from beginning of file. */
  75148. # define SEEK_CUR 1 /* Seek from current position. */
  75149. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  75150. #endif
  75151. #ifndef z_off_t
  75152. # define z_off_t long
  75153. #endif
  75154. #if defined(__OS400__)
  75155. # define NO_vsnprintf
  75156. #endif
  75157. #if defined(__MVS__)
  75158. # define NO_vsnprintf
  75159. # ifdef FAR
  75160. # undef FAR
  75161. # endif
  75162. #endif
  75163. #if defined(__MVS__)
  75164. # pragma map(deflateInit_,"DEIN")
  75165. # pragma map(deflateInit2_,"DEIN2")
  75166. # pragma map(deflateEnd,"DEEND")
  75167. # pragma map(deflateBound,"DEBND")
  75168. # pragma map(inflateInit_,"ININ")
  75169. # pragma map(inflateInit2_,"ININ2")
  75170. # pragma map(inflateEnd,"INEND")
  75171. # pragma map(inflateSync,"INSY")
  75172. # pragma map(inflateSetDictionary,"INSEDI")
  75173. # pragma map(compressBound,"CMBND")
  75174. # pragma map(inflate_table,"INTABL")
  75175. # pragma map(inflate_fast,"INFA")
  75176. # pragma map(inflate_copyright,"INCOPY")
  75177. #endif
  75178. #endif /* ZCONF_H */
  75179. /*** End of inlined file: zconf.h ***/
  75180. #ifdef __cplusplus
  75181. extern "C" {
  75182. #endif
  75183. #define ZLIB_VERSION "1.2.3"
  75184. #define ZLIB_VERNUM 0x1230
  75185. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  75186. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  75187. struct internal_state;
  75188. typedef struct z_stream_s {
  75189. Bytef *next_in; /* next input byte */
  75190. uInt avail_in; /* number of bytes available at next_in */
  75191. uLong total_in; /* total nb of input bytes read so far */
  75192. Bytef *next_out; /* next output byte should be put there */
  75193. uInt avail_out; /* remaining free space at next_out */
  75194. uLong total_out; /* total nb of bytes output so far */
  75195. char *msg; /* last error message, NULL if no error */
  75196. struct internal_state FAR *state; /* not visible by applications */
  75197. alloc_func zalloc; /* used to allocate the internal state */
  75198. free_func zfree; /* used to free the internal state */
  75199. voidpf opaque; /* private data object passed to zalloc and zfree */
  75200. int data_type; /* best guess about the data type: binary or text */
  75201. uLong adler; /* adler32 value of the uncompressed data */
  75202. uLong reserved; /* reserved for future use */
  75203. } z_stream;
  75204. typedef z_stream FAR *z_streamp;
  75205. typedef struct gz_header_s {
  75206. int text; /* true if compressed data believed to be text */
  75207. uLong time; /* modification time */
  75208. int xflags; /* extra flags (not used when writing a gzip file) */
  75209. int os; /* operating system */
  75210. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  75211. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  75212. uInt extra_max; /* space at extra (only when reading header) */
  75213. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  75214. uInt name_max; /* space at name (only when reading header) */
  75215. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  75216. uInt comm_max; /* space at comment (only when reading header) */
  75217. int hcrc; /* true if there was or will be a header crc */
  75218. int done; /* true when done reading gzip header (not used
  75219. when writing a gzip file) */
  75220. } gz_header;
  75221. typedef gz_header FAR *gz_headerp;
  75222. #define Z_NO_FLUSH 0
  75223. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  75224. #define Z_SYNC_FLUSH 2
  75225. #define Z_FULL_FLUSH 3
  75226. #define Z_FINISH 4
  75227. #define Z_BLOCK 5
  75228. #define Z_OK 0
  75229. #define Z_STREAM_END 1
  75230. #define Z_NEED_DICT 2
  75231. #define Z_ERRNO (-1)
  75232. #define Z_STREAM_ERROR (-2)
  75233. #define Z_DATA_ERROR (-3)
  75234. #define Z_MEM_ERROR (-4)
  75235. #define Z_BUF_ERROR (-5)
  75236. #define Z_VERSION_ERROR (-6)
  75237. #define Z_NO_COMPRESSION 0
  75238. #define Z_BEST_SPEED 1
  75239. #define Z_BEST_COMPRESSION 9
  75240. #define Z_DEFAULT_COMPRESSION (-1)
  75241. #define Z_FILTERED 1
  75242. #define Z_HUFFMAN_ONLY 2
  75243. #define Z_RLE 3
  75244. #define Z_FIXED 4
  75245. #define Z_DEFAULT_STRATEGY 0
  75246. #define Z_BINARY 0
  75247. #define Z_TEXT 1
  75248. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  75249. #define Z_UNKNOWN 2
  75250. #define Z_DEFLATED 8
  75251. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  75252. #define zlib_version zlibVersion()
  75253. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  75254. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  75255. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  75256. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  75257. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  75258. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  75259. const Bytef *dictionary,
  75260. uInt dictLength));
  75261. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  75262. z_streamp source));
  75263. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  75264. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  75265. int level,
  75266. int strategy));
  75267. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  75268. int good_length,
  75269. int max_lazy,
  75270. int nice_length,
  75271. int max_chain));
  75272. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  75273. uLong sourceLen));
  75274. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  75275. int bits,
  75276. int value));
  75277. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  75278. gz_headerp head));
  75279. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  75280. const Bytef *dictionary,
  75281. uInt dictLength));
  75282. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  75283. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  75284. z_streamp source));
  75285. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  75286. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  75287. int bits,
  75288. int value));
  75289. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  75290. gz_headerp head));
  75291. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  75292. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  75293. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  75294. in_func in, void FAR *in_desc,
  75295. out_func out, void FAR *out_desc));
  75296. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  75297. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  75298. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  75299. const Bytef *source, uLong sourceLen));
  75300. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75301. const Bytef *source, uLong sourceLen,
  75302. int level));
  75303. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75304. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75305. const Bytef *source, uLong sourceLen));
  75306. typedef voidp gzFile;
  75307. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75308. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75309. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75310. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75311. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75312. voidpc buf, unsigned len));
  75313. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75314. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75315. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75316. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75317. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75318. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75319. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75320. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  75321. z_off_t offset, int whence));
  75322. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  75323. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  75324. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  75325. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  75326. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  75327. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  75328. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  75329. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  75330. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75331. z_off_t len2));
  75332. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75333. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75334. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75335. const char *version, int stream_size));
  75336. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75337. const char *version, int stream_size));
  75338. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75339. int windowBits, int memLevel,
  75340. int strategy, const char *version,
  75341. int stream_size));
  75342. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75343. const char *version, int stream_size));
  75344. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75345. unsigned char FAR *window,
  75346. const char *version,
  75347. int stream_size));
  75348. #define deflateInit(strm, level) \
  75349. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75350. #define inflateInit(strm) \
  75351. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75352. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75353. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75354. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75355. #define inflateInit2(strm, windowBits) \
  75356. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75357. #define inflateBackInit(strm, windowBits, window) \
  75358. inflateBackInit_((strm), (windowBits), (window), \
  75359. ZLIB_VERSION, sizeof(z_stream))
  75360. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75361. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75362. #endif
  75363. ZEXTERN const char * ZEXPORT zError OF((int));
  75364. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75365. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75366. #ifdef __cplusplus
  75367. }
  75368. #endif
  75369. #endif /* ZLIB_H */
  75370. /*** End of inlined file: zlib.h ***/
  75371. #undef OS_CODE
  75372. #else
  75373. #include <zlib.h>
  75374. #endif
  75375. }
  75376. BEGIN_JUCE_NAMESPACE
  75377. using namespace zlibNamespace;
  75378. // internal helper object that holds the zlib structures so they don't have to be
  75379. // included publicly.
  75380. class GZIPCompressorHelper
  75381. {
  75382. public:
  75383. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  75384. : data (0),
  75385. dataSize (0),
  75386. compLevel (compressionLevel),
  75387. strategy (0),
  75388. setParams (true),
  75389. streamIsValid (false),
  75390. finished (false),
  75391. shouldFinish (false)
  75392. {
  75393. zerostruct (stream);
  75394. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  75395. nowrap ? -MAX_WBITS : MAX_WBITS,
  75396. 8, strategy) == Z_OK);
  75397. }
  75398. ~GZIPCompressorHelper()
  75399. {
  75400. if (streamIsValid)
  75401. deflateEnd (&stream);
  75402. }
  75403. bool needsInput() const throw()
  75404. {
  75405. return dataSize <= 0;
  75406. }
  75407. void setInput (uint8* const newData, const int size) throw()
  75408. {
  75409. data = newData;
  75410. dataSize = size;
  75411. }
  75412. int doNextBlock (uint8* const dest, const int destSize) throw()
  75413. {
  75414. if (streamIsValid)
  75415. {
  75416. stream.next_in = data;
  75417. stream.next_out = dest;
  75418. stream.avail_in = dataSize;
  75419. stream.avail_out = destSize;
  75420. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75421. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75422. setParams = false;
  75423. switch (result)
  75424. {
  75425. case Z_STREAM_END:
  75426. finished = true;
  75427. // Deliberate fall-through..
  75428. case Z_OK:
  75429. data += dataSize - stream.avail_in;
  75430. dataSize = stream.avail_in;
  75431. return destSize - stream.avail_out;
  75432. default:
  75433. break;
  75434. }
  75435. }
  75436. return 0;
  75437. }
  75438. private:
  75439. z_stream stream;
  75440. uint8* data;
  75441. int dataSize, compLevel, strategy;
  75442. bool setParams, streamIsValid;
  75443. public:
  75444. bool finished, shouldFinish;
  75445. };
  75446. const int gzipCompBufferSize = 32768;
  75447. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75448. int compressionLevel,
  75449. const bool deleteDestStream,
  75450. const bool noWrap)
  75451. : destStream (destStream_),
  75452. streamToDelete (deleteDestStream ? destStream_ : 0),
  75453. buffer (gzipCompBufferSize)
  75454. {
  75455. if (compressionLevel < 1 || compressionLevel > 9)
  75456. compressionLevel = -1;
  75457. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75458. }
  75459. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75460. {
  75461. flush();
  75462. }
  75463. void GZIPCompressorOutputStream::flush()
  75464. {
  75465. if (! helper->finished)
  75466. {
  75467. helper->shouldFinish = true;
  75468. while (! helper->finished)
  75469. doNextBlock();
  75470. }
  75471. destStream->flush();
  75472. }
  75473. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75474. {
  75475. if (! helper->finished)
  75476. {
  75477. helper->setInput ((uint8*) destBuffer, howMany);
  75478. while (! helper->needsInput())
  75479. {
  75480. if (! doNextBlock())
  75481. return false;
  75482. }
  75483. }
  75484. return true;
  75485. }
  75486. bool GZIPCompressorOutputStream::doNextBlock()
  75487. {
  75488. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75489. if (len > 0)
  75490. return destStream->write (buffer, len);
  75491. else
  75492. return true;
  75493. }
  75494. int64 GZIPCompressorOutputStream::getPosition()
  75495. {
  75496. return destStream->getPosition();
  75497. }
  75498. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75499. {
  75500. jassertfalse // can't do it!
  75501. return false;
  75502. }
  75503. END_JUCE_NAMESPACE
  75504. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75505. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75506. #if JUCE_MSVC
  75507. #pragma warning (push)
  75508. #pragma warning (disable: 4309 4305)
  75509. #endif
  75510. namespace zlibNamespace
  75511. {
  75512. #if JUCE_INCLUDE_ZLIB_CODE
  75513. extern "C"
  75514. {
  75515. #undef OS_CODE
  75516. #undef fdopen
  75517. #define ZLIB_INTERNAL
  75518. #define NO_DUMMY_DECL
  75519. /*** Start of inlined file: adler32.c ***/
  75520. #define ZLIB_INTERNAL
  75521. #define BASE 65521UL /* largest prime smaller than 65536 */
  75522. #define NMAX 5552
  75523. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75524. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75525. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75526. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75527. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75528. #ifdef NO_DIVIDE
  75529. # define MOD(a) \
  75530. do { \
  75531. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75532. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75533. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75534. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75535. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75536. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75537. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75538. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75539. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75540. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75541. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75542. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75543. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75544. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75545. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75546. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75547. if (a >= BASE) a -= BASE; \
  75548. } while (0)
  75549. # define MOD4(a) \
  75550. do { \
  75551. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75552. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75553. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75554. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75555. if (a >= BASE) a -= BASE; \
  75556. } while (0)
  75557. #else
  75558. # define MOD(a) a %= BASE
  75559. # define MOD4(a) a %= BASE
  75560. #endif
  75561. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75562. {
  75563. unsigned long sum2;
  75564. unsigned n;
  75565. sum2 = (adler >> 16) & 0xffff;
  75566. adler &= 0xffff;
  75567. if (len == 1) {
  75568. adler += buf[0];
  75569. if (adler >= BASE)
  75570. adler -= BASE;
  75571. sum2 += adler;
  75572. if (sum2 >= BASE)
  75573. sum2 -= BASE;
  75574. return adler | (sum2 << 16);
  75575. }
  75576. if (buf == Z_NULL)
  75577. return 1L;
  75578. if (len < 16) {
  75579. while (len--) {
  75580. adler += *buf++;
  75581. sum2 += adler;
  75582. }
  75583. if (adler >= BASE)
  75584. adler -= BASE;
  75585. MOD4(sum2); /* only added so many BASE's */
  75586. return adler | (sum2 << 16);
  75587. }
  75588. while (len >= NMAX) {
  75589. len -= NMAX;
  75590. n = NMAX / 16; /* NMAX is divisible by 16 */
  75591. do {
  75592. DO16(buf); /* 16 sums unrolled */
  75593. buf += 16;
  75594. } while (--n);
  75595. MOD(adler);
  75596. MOD(sum2);
  75597. }
  75598. if (len) { /* avoid modulos if none remaining */
  75599. while (len >= 16) {
  75600. len -= 16;
  75601. DO16(buf);
  75602. buf += 16;
  75603. }
  75604. while (len--) {
  75605. adler += *buf++;
  75606. sum2 += adler;
  75607. }
  75608. MOD(adler);
  75609. MOD(sum2);
  75610. }
  75611. return adler | (sum2 << 16);
  75612. }
  75613. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75614. {
  75615. unsigned long sum1;
  75616. unsigned long sum2;
  75617. unsigned rem;
  75618. rem = (unsigned)(len2 % BASE);
  75619. sum1 = adler1 & 0xffff;
  75620. sum2 = rem * sum1;
  75621. MOD(sum2);
  75622. sum1 += (adler2 & 0xffff) + BASE - 1;
  75623. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75624. if (sum1 > BASE) sum1 -= BASE;
  75625. if (sum1 > BASE) sum1 -= BASE;
  75626. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75627. if (sum2 > BASE) sum2 -= BASE;
  75628. return sum1 | (sum2 << 16);
  75629. }
  75630. /*** End of inlined file: adler32.c ***/
  75631. /*** Start of inlined file: compress.c ***/
  75632. #define ZLIB_INTERNAL
  75633. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75634. uLong sourceLen, int level)
  75635. {
  75636. z_stream stream;
  75637. int err;
  75638. stream.next_in = (Bytef*)source;
  75639. stream.avail_in = (uInt)sourceLen;
  75640. #ifdef MAXSEG_64K
  75641. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75642. #endif
  75643. stream.next_out = dest;
  75644. stream.avail_out = (uInt)*destLen;
  75645. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75646. stream.zalloc = (alloc_func)0;
  75647. stream.zfree = (free_func)0;
  75648. stream.opaque = (voidpf)0;
  75649. err = deflateInit(&stream, level);
  75650. if (err != Z_OK) return err;
  75651. err = deflate(&stream, Z_FINISH);
  75652. if (err != Z_STREAM_END) {
  75653. deflateEnd(&stream);
  75654. return err == Z_OK ? Z_BUF_ERROR : err;
  75655. }
  75656. *destLen = stream.total_out;
  75657. err = deflateEnd(&stream);
  75658. return err;
  75659. }
  75660. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75661. {
  75662. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75663. }
  75664. uLong ZEXPORT compressBound (uLong sourceLen)
  75665. {
  75666. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75667. }
  75668. /*** End of inlined file: compress.c ***/
  75669. #undef DO1
  75670. #undef DO8
  75671. /*** Start of inlined file: crc32.c ***/
  75672. #ifdef MAKECRCH
  75673. # include <stdio.h>
  75674. # ifndef DYNAMIC_CRC_TABLE
  75675. # define DYNAMIC_CRC_TABLE
  75676. # endif /* !DYNAMIC_CRC_TABLE */
  75677. #endif /* MAKECRCH */
  75678. /*** Start of inlined file: zutil.h ***/
  75679. #ifndef ZUTIL_H
  75680. #define ZUTIL_H
  75681. #define ZLIB_INTERNAL
  75682. #ifdef STDC
  75683. # ifndef _WIN32_WCE
  75684. # include <stddef.h>
  75685. # endif
  75686. # include <string.h>
  75687. # include <stdlib.h>
  75688. #endif
  75689. #ifdef NO_ERRNO_H
  75690. # ifdef _WIN32_WCE
  75691. # define errno z_errno
  75692. # endif
  75693. extern int errno;
  75694. #else
  75695. # ifndef _WIN32_WCE
  75696. # include <errno.h>
  75697. # endif
  75698. #endif
  75699. #ifndef local
  75700. # define local static
  75701. #endif
  75702. typedef unsigned char uch;
  75703. typedef uch FAR uchf;
  75704. typedef unsigned short ush;
  75705. typedef ush FAR ushf;
  75706. typedef unsigned long ulg;
  75707. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  75708. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  75709. #define ERR_RETURN(strm,err) \
  75710. return (strm->msg = (char*)ERR_MSG(err), (err))
  75711. #ifndef DEF_WBITS
  75712. # define DEF_WBITS MAX_WBITS
  75713. #endif
  75714. #if MAX_MEM_LEVEL >= 8
  75715. # define DEF_MEM_LEVEL 8
  75716. #else
  75717. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  75718. #endif
  75719. #define STORED_BLOCK 0
  75720. #define STATIC_TREES 1
  75721. #define DYN_TREES 2
  75722. #define MIN_MATCH 3
  75723. #define MAX_MATCH 258
  75724. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  75725. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  75726. # define OS_CODE 0x00
  75727. # if defined(__TURBOC__) || defined(__BORLANDC__)
  75728. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  75729. void _Cdecl farfree( void *block );
  75730. void *_Cdecl farmalloc( unsigned long nbytes );
  75731. # else
  75732. # include <alloc.h>
  75733. # endif
  75734. # else /* MSC or DJGPP */
  75735. # include <malloc.h>
  75736. # endif
  75737. #endif
  75738. #ifdef AMIGA
  75739. # define OS_CODE 0x01
  75740. #endif
  75741. #if defined(VAXC) || defined(VMS)
  75742. # define OS_CODE 0x02
  75743. # define F_OPEN(name, mode) \
  75744. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  75745. #endif
  75746. #if defined(ATARI) || defined(atarist)
  75747. # define OS_CODE 0x05
  75748. #endif
  75749. #ifdef OS2
  75750. # define OS_CODE 0x06
  75751. # ifdef M_I86
  75752. #include <malloc.h>
  75753. # endif
  75754. #endif
  75755. #if defined(MACOS) || TARGET_OS_MAC
  75756. # define OS_CODE 0x07
  75757. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  75758. # include <unix.h> /* for fdopen */
  75759. # else
  75760. # ifndef fdopen
  75761. # define fdopen(fd,mode) NULL /* No fdopen() */
  75762. # endif
  75763. # endif
  75764. #endif
  75765. #ifdef TOPS20
  75766. # define OS_CODE 0x0a
  75767. #endif
  75768. #ifdef WIN32
  75769. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  75770. # define OS_CODE 0x0b
  75771. # endif
  75772. #endif
  75773. #ifdef __50SERIES /* Prime/PRIMOS */
  75774. # define OS_CODE 0x0f
  75775. #endif
  75776. #if defined(_BEOS_) || defined(RISCOS)
  75777. # define fdopen(fd,mode) NULL /* No fdopen() */
  75778. #endif
  75779. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  75780. # if defined(_WIN32_WCE)
  75781. # define fdopen(fd,mode) NULL /* No fdopen() */
  75782. # ifndef _PTRDIFF_T_DEFINED
  75783. typedef int ptrdiff_t;
  75784. # define _PTRDIFF_T_DEFINED
  75785. # endif
  75786. # else
  75787. # define fdopen(fd,type) _fdopen(fd,type)
  75788. # endif
  75789. #endif
  75790. #ifndef OS_CODE
  75791. # define OS_CODE 0x03 /* assume Unix */
  75792. #endif
  75793. #ifndef F_OPEN
  75794. # define F_OPEN(name, mode) fopen((name), (mode))
  75795. #endif
  75796. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  75797. # ifndef HAVE_VSNPRINTF
  75798. # define HAVE_VSNPRINTF
  75799. # endif
  75800. #endif
  75801. #if defined(__CYGWIN__)
  75802. # ifndef HAVE_VSNPRINTF
  75803. # define HAVE_VSNPRINTF
  75804. # endif
  75805. #endif
  75806. #ifndef HAVE_VSNPRINTF
  75807. # ifdef MSDOS
  75808. # define NO_vsnprintf
  75809. # endif
  75810. # ifdef __TURBOC__
  75811. # define NO_vsnprintf
  75812. # endif
  75813. # ifdef WIN32
  75814. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  75815. # define vsnprintf _vsnprintf
  75816. # endif
  75817. # endif
  75818. # ifdef __SASC
  75819. # define NO_vsnprintf
  75820. # endif
  75821. #endif
  75822. #ifdef VMS
  75823. # define NO_vsnprintf
  75824. #endif
  75825. #if defined(pyr)
  75826. # define NO_MEMCPY
  75827. #endif
  75828. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  75829. # define NO_MEMCPY
  75830. #endif
  75831. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  75832. # define HAVE_MEMCPY
  75833. #endif
  75834. #ifdef HAVE_MEMCPY
  75835. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  75836. # define zmemcpy _fmemcpy
  75837. # define zmemcmp _fmemcmp
  75838. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  75839. # else
  75840. # define zmemcpy memcpy
  75841. # define zmemcmp memcmp
  75842. # define zmemzero(dest, len) memset(dest, 0, len)
  75843. # endif
  75844. #else
  75845. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  75846. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  75847. extern void zmemzero OF((Bytef* dest, uInt len));
  75848. #endif
  75849. #ifdef DEBUG
  75850. # include <stdio.h>
  75851. extern int z_verbose;
  75852. extern void z_error OF((const char *m));
  75853. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  75854. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  75855. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  75856. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  75857. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  75858. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  75859. #else
  75860. # define Assert(cond,msg)
  75861. # define Trace(x)
  75862. # define Tracev(x)
  75863. # define Tracevv(x)
  75864. # define Tracec(c,x)
  75865. # define Tracecv(c,x)
  75866. #endif
  75867. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  75868. void zcfree OF((voidpf opaque, voidpf ptr));
  75869. #define ZALLOC(strm, items, size) \
  75870. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  75871. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  75872. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  75873. #endif /* ZUTIL_H */
  75874. /*** End of inlined file: zutil.h ***/
  75875. /* for STDC and FAR definitions */
  75876. #define local static
  75877. #ifndef NOBYFOUR
  75878. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  75879. # include <limits.h>
  75880. # define BYFOUR
  75881. # if (UINT_MAX == 0xffffffffUL)
  75882. typedef unsigned int u4;
  75883. # else
  75884. # if (ULONG_MAX == 0xffffffffUL)
  75885. typedef unsigned long u4;
  75886. # else
  75887. # if (USHRT_MAX == 0xffffffffUL)
  75888. typedef unsigned short u4;
  75889. # else
  75890. # undef BYFOUR /* can't find a four-byte integer type! */
  75891. # endif
  75892. # endif
  75893. # endif
  75894. # endif /* STDC */
  75895. #endif /* !NOBYFOUR */
  75896. #ifdef BYFOUR
  75897. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  75898. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  75899. local unsigned long crc32_little OF((unsigned long,
  75900. const unsigned char FAR *, unsigned));
  75901. local unsigned long crc32_big OF((unsigned long,
  75902. const unsigned char FAR *, unsigned));
  75903. # define TBLS 8
  75904. #else
  75905. # define TBLS 1
  75906. #endif /* BYFOUR */
  75907. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  75908. unsigned long vec));
  75909. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  75910. #ifdef DYNAMIC_CRC_TABLE
  75911. local volatile int crc_table_empty = 1;
  75912. local unsigned long FAR crc_table[TBLS][256];
  75913. local void make_crc_table OF((void));
  75914. #ifdef MAKECRCH
  75915. local void write_table OF((FILE *, const unsigned long FAR *));
  75916. #endif /* MAKECRCH */
  75917. local void make_crc_table()
  75918. {
  75919. unsigned long c;
  75920. int n, k;
  75921. unsigned long poly; /* polynomial exclusive-or pattern */
  75922. static volatile int first = 1; /* flag to limit concurrent making */
  75923. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  75924. if (first) {
  75925. first = 0;
  75926. poly = 0UL;
  75927. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  75928. poly |= 1UL << (31 - p[n]);
  75929. for (n = 0; n < 256; n++) {
  75930. c = (unsigned long)n;
  75931. for (k = 0; k < 8; k++)
  75932. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  75933. crc_table[0][n] = c;
  75934. }
  75935. #ifdef BYFOUR
  75936. for (n = 0; n < 256; n++) {
  75937. c = crc_table[0][n];
  75938. crc_table[4][n] = REV(c);
  75939. for (k = 1; k < 4; k++) {
  75940. c = crc_table[0][c & 0xff] ^ (c >> 8);
  75941. crc_table[k][n] = c;
  75942. crc_table[k + 4][n] = REV(c);
  75943. }
  75944. }
  75945. #endif /* BYFOUR */
  75946. crc_table_empty = 0;
  75947. }
  75948. else { /* not first */
  75949. while (crc_table_empty)
  75950. ;
  75951. }
  75952. #ifdef MAKECRCH
  75953. {
  75954. FILE *out;
  75955. out = fopen("crc32.h", "w");
  75956. if (out == NULL) return;
  75957. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  75958. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  75959. fprintf(out, "local const unsigned long FAR ");
  75960. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  75961. write_table(out, crc_table[0]);
  75962. # ifdef BYFOUR
  75963. fprintf(out, "#ifdef BYFOUR\n");
  75964. for (k = 1; k < 8; k++) {
  75965. fprintf(out, " },\n {\n");
  75966. write_table(out, crc_table[k]);
  75967. }
  75968. fprintf(out, "#endif\n");
  75969. # endif /* BYFOUR */
  75970. fprintf(out, " }\n};\n");
  75971. fclose(out);
  75972. }
  75973. #endif /* MAKECRCH */
  75974. }
  75975. #ifdef MAKECRCH
  75976. local void write_table(out, table)
  75977. FILE *out;
  75978. const unsigned long FAR *table;
  75979. {
  75980. int n;
  75981. for (n = 0; n < 256; n++)
  75982. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  75983. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  75984. }
  75985. #endif /* MAKECRCH */
  75986. #else /* !DYNAMIC_CRC_TABLE */
  75987. /*** Start of inlined file: crc32.h ***/
  75988. local const unsigned long FAR crc_table[TBLS][256] =
  75989. {
  75990. {
  75991. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  75992. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  75993. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  75994. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  75995. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  75996. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  75997. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  75998. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  75999. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  76000. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  76001. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  76002. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  76003. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  76004. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  76005. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  76006. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  76007. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  76008. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  76009. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  76010. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  76011. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  76012. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  76013. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  76014. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  76015. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  76016. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  76017. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  76018. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  76019. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  76020. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  76021. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  76022. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  76023. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  76024. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  76025. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  76026. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  76027. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  76028. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  76029. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  76030. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  76031. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  76032. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  76033. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  76034. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  76035. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  76036. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  76037. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  76038. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  76039. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  76040. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  76041. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  76042. 0x2d02ef8dUL
  76043. #ifdef BYFOUR
  76044. },
  76045. {
  76046. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  76047. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  76048. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  76049. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  76050. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  76051. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  76052. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  76053. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  76054. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  76055. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  76056. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  76057. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  76058. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  76059. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  76060. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  76061. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  76062. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  76063. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  76064. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  76065. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  76066. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  76067. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  76068. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  76069. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  76070. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  76071. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  76072. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  76073. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  76074. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  76075. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  76076. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  76077. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  76078. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  76079. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  76080. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  76081. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  76082. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  76083. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  76084. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  76085. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  76086. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  76087. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  76088. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  76089. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  76090. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  76091. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  76092. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  76093. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  76094. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  76095. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  76096. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  76097. 0x9324fd72UL
  76098. },
  76099. {
  76100. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  76101. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  76102. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  76103. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  76104. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  76105. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  76106. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  76107. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  76108. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  76109. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  76110. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  76111. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  76112. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  76113. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  76114. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  76115. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  76116. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  76117. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  76118. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  76119. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  76120. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  76121. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  76122. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  76123. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  76124. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  76125. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  76126. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  76127. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  76128. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  76129. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  76130. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  76131. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  76132. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  76133. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  76134. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  76135. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  76136. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  76137. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  76138. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  76139. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  76140. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  76141. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  76142. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  76143. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  76144. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  76145. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  76146. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  76147. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  76148. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  76149. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  76150. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  76151. 0xbe9834edUL
  76152. },
  76153. {
  76154. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  76155. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  76156. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  76157. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  76158. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  76159. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  76160. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  76161. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  76162. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  76163. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  76164. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  76165. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  76166. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  76167. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  76168. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  76169. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  76170. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  76171. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  76172. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  76173. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  76174. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  76175. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  76176. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  76177. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  76178. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  76179. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  76180. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  76181. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  76182. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  76183. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  76184. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  76185. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  76186. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  76187. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  76188. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  76189. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  76190. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  76191. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  76192. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  76193. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  76194. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  76195. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  76196. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  76197. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  76198. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  76199. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  76200. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  76201. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  76202. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  76203. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  76204. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  76205. 0xde0506f1UL
  76206. },
  76207. {
  76208. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  76209. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  76210. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  76211. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  76212. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  76213. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  76214. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  76215. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  76216. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  76217. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  76218. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  76219. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  76220. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  76221. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  76222. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  76223. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  76224. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  76225. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  76226. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  76227. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  76228. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  76229. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  76230. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  76231. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  76232. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  76233. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  76234. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  76235. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  76236. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  76237. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  76238. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  76239. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  76240. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  76241. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  76242. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  76243. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  76244. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  76245. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  76246. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  76247. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  76248. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  76249. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  76250. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  76251. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  76252. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  76253. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  76254. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  76255. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  76256. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  76257. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  76258. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  76259. 0x8def022dUL
  76260. },
  76261. {
  76262. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  76263. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  76264. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  76265. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  76266. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  76267. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  76268. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  76269. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  76270. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  76271. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  76272. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  76273. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  76274. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  76275. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  76276. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  76277. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  76278. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  76279. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  76280. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  76281. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  76282. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  76283. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  76284. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  76285. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  76286. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  76287. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  76288. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  76289. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  76290. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  76291. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  76292. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  76293. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  76294. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  76295. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  76296. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  76297. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76298. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76299. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76300. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76301. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76302. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76303. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76304. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76305. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76306. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76307. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76308. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76309. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76310. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76311. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76312. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76313. 0x72fd2493UL
  76314. },
  76315. {
  76316. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76317. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76318. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76319. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76320. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76321. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  76322. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  76323. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  76324. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  76325. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  76326. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  76327. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  76328. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76329. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76330. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76331. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76332. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76333. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76334. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76335. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76336. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76337. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76338. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76339. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76340. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76341. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76342. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76343. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76344. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76345. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76346. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76347. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76348. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76349. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76350. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76351. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76352. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76353. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76354. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76355. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76356. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76357. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76358. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76359. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76360. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76361. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76362. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76363. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76364. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76365. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76366. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76367. 0xed3498beUL
  76368. },
  76369. {
  76370. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  76371. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  76372. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  76373. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  76374. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  76375. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  76376. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  76377. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  76378. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  76379. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  76380. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  76381. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  76382. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  76383. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  76384. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  76385. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  76386. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  76387. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  76388. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  76389. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  76390. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  76391. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  76392. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  76393. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  76394. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  76395. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  76396. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  76397. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  76398. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  76399. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  76400. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  76401. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  76402. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  76403. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  76404. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  76405. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  76406. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  76407. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  76408. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76409. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76410. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76411. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76412. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76413. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76414. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76415. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76416. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76417. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76418. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76419. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76420. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76421. 0xf10605deUL
  76422. #endif
  76423. }
  76424. };
  76425. /*** End of inlined file: crc32.h ***/
  76426. #endif /* DYNAMIC_CRC_TABLE */
  76427. const unsigned long FAR * ZEXPORT get_crc_table()
  76428. {
  76429. #ifdef DYNAMIC_CRC_TABLE
  76430. if (crc_table_empty)
  76431. make_crc_table();
  76432. #endif /* DYNAMIC_CRC_TABLE */
  76433. return (const unsigned long FAR *)crc_table;
  76434. }
  76435. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76436. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76437. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76438. {
  76439. if (buf == Z_NULL) return 0UL;
  76440. #ifdef DYNAMIC_CRC_TABLE
  76441. if (crc_table_empty)
  76442. make_crc_table();
  76443. #endif /* DYNAMIC_CRC_TABLE */
  76444. #ifdef BYFOUR
  76445. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76446. u4 endian;
  76447. endian = 1;
  76448. if (*((unsigned char *)(&endian)))
  76449. return crc32_little(crc, buf, len);
  76450. else
  76451. return crc32_big(crc, buf, len);
  76452. }
  76453. #endif /* BYFOUR */
  76454. crc = crc ^ 0xffffffffUL;
  76455. while (len >= 8) {
  76456. DO8;
  76457. len -= 8;
  76458. }
  76459. if (len) do {
  76460. DO1;
  76461. } while (--len);
  76462. return crc ^ 0xffffffffUL;
  76463. }
  76464. #ifdef BYFOUR
  76465. #define DOLIT4 c ^= *buf4++; \
  76466. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76467. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76468. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76469. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76470. {
  76471. register u4 c;
  76472. register const u4 FAR *buf4;
  76473. c = (u4)crc;
  76474. c = ~c;
  76475. while (len && ((ptrdiff_t)buf & 3)) {
  76476. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76477. len--;
  76478. }
  76479. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76480. while (len >= 32) {
  76481. DOLIT32;
  76482. len -= 32;
  76483. }
  76484. while (len >= 4) {
  76485. DOLIT4;
  76486. len -= 4;
  76487. }
  76488. buf = (const unsigned char FAR *)buf4;
  76489. if (len) do {
  76490. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76491. } while (--len);
  76492. c = ~c;
  76493. return (unsigned long)c;
  76494. }
  76495. #define DOBIG4 c ^= *++buf4; \
  76496. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76497. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76498. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76499. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76500. {
  76501. register u4 c;
  76502. register const u4 FAR *buf4;
  76503. c = REV((u4)crc);
  76504. c = ~c;
  76505. while (len && ((ptrdiff_t)buf & 3)) {
  76506. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76507. len--;
  76508. }
  76509. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76510. buf4--;
  76511. while (len >= 32) {
  76512. DOBIG32;
  76513. len -= 32;
  76514. }
  76515. while (len >= 4) {
  76516. DOBIG4;
  76517. len -= 4;
  76518. }
  76519. buf4++;
  76520. buf = (const unsigned char FAR *)buf4;
  76521. if (len) do {
  76522. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76523. } while (--len);
  76524. c = ~c;
  76525. return (unsigned long)(REV(c));
  76526. }
  76527. #endif /* BYFOUR */
  76528. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76529. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76530. {
  76531. unsigned long sum;
  76532. sum = 0;
  76533. while (vec) {
  76534. if (vec & 1)
  76535. sum ^= *mat;
  76536. vec >>= 1;
  76537. mat++;
  76538. }
  76539. return sum;
  76540. }
  76541. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76542. {
  76543. int n;
  76544. for (n = 0; n < GF2_DIM; n++)
  76545. square[n] = gf2_matrix_times(mat, mat[n]);
  76546. }
  76547. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76548. {
  76549. int n;
  76550. unsigned long row;
  76551. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76552. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76553. if (len2 == 0)
  76554. return crc1;
  76555. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76556. row = 1;
  76557. for (n = 1; n < GF2_DIM; n++) {
  76558. odd[n] = row;
  76559. row <<= 1;
  76560. }
  76561. gf2_matrix_square(even, odd);
  76562. gf2_matrix_square(odd, even);
  76563. do {
  76564. gf2_matrix_square(even, odd);
  76565. if (len2 & 1)
  76566. crc1 = gf2_matrix_times(even, crc1);
  76567. len2 >>= 1;
  76568. if (len2 == 0)
  76569. break;
  76570. gf2_matrix_square(odd, even);
  76571. if (len2 & 1)
  76572. crc1 = gf2_matrix_times(odd, crc1);
  76573. len2 >>= 1;
  76574. } while (len2 != 0);
  76575. crc1 ^= crc2;
  76576. return crc1;
  76577. }
  76578. /*** End of inlined file: crc32.c ***/
  76579. /*** Start of inlined file: deflate.c ***/
  76580. /*** Start of inlined file: deflate.h ***/
  76581. #ifndef DEFLATE_H
  76582. #define DEFLATE_H
  76583. #ifndef NO_GZIP
  76584. # define GZIP
  76585. #endif
  76586. #define NO_DUMMY_DECL
  76587. #define LENGTH_CODES 29
  76588. #define LITERALS 256
  76589. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76590. #define D_CODES 30
  76591. #define BL_CODES 19
  76592. #define HEAP_SIZE (2*L_CODES+1)
  76593. #define MAX_BITS 15
  76594. #define INIT_STATE 42
  76595. #define EXTRA_STATE 69
  76596. #define NAME_STATE 73
  76597. #define COMMENT_STATE 91
  76598. #define HCRC_STATE 103
  76599. #define BUSY_STATE 113
  76600. #define FINISH_STATE 666
  76601. typedef struct ct_data_s {
  76602. union {
  76603. ush freq; /* frequency count */
  76604. ush code; /* bit string */
  76605. } fc;
  76606. union {
  76607. ush dad; /* father node in Huffman tree */
  76608. ush len; /* length of bit string */
  76609. } dl;
  76610. } FAR ct_data;
  76611. #define Freq fc.freq
  76612. #define Code fc.code
  76613. #define Dad dl.dad
  76614. #define Len dl.len
  76615. typedef struct static_tree_desc_s static_tree_desc;
  76616. typedef struct tree_desc_s {
  76617. ct_data *dyn_tree; /* the dynamic tree */
  76618. int max_code; /* largest code with non zero frequency */
  76619. static_tree_desc *stat_desc; /* the corresponding static tree */
  76620. } FAR tree_desc;
  76621. typedef ush Pos;
  76622. typedef Pos FAR Posf;
  76623. typedef unsigned IPos;
  76624. typedef struct internal_state {
  76625. z_streamp strm; /* pointer back to this zlib stream */
  76626. int status; /* as the name implies */
  76627. Bytef *pending_buf; /* output still pending */
  76628. ulg pending_buf_size; /* size of pending_buf */
  76629. Bytef *pending_out; /* next pending byte to output to the stream */
  76630. uInt pending; /* nb of bytes in the pending buffer */
  76631. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76632. gz_headerp gzhead; /* gzip header information to write */
  76633. uInt gzindex; /* where in extra, name, or comment */
  76634. Byte method; /* STORED (for zip only) or DEFLATED */
  76635. int last_flush; /* value of flush param for previous deflate call */
  76636. uInt w_size; /* LZ77 window size (32K by default) */
  76637. uInt w_bits; /* log2(w_size) (8..16) */
  76638. uInt w_mask; /* w_size - 1 */
  76639. Bytef *window;
  76640. ulg window_size;
  76641. Posf *prev;
  76642. Posf *head; /* Heads of the hash chains or NIL. */
  76643. uInt ins_h; /* hash index of string to be inserted */
  76644. uInt hash_size; /* number of elements in hash table */
  76645. uInt hash_bits; /* log2(hash_size) */
  76646. uInt hash_mask; /* hash_size-1 */
  76647. uInt hash_shift;
  76648. long block_start;
  76649. uInt match_length; /* length of best match */
  76650. IPos prev_match; /* previous match */
  76651. int match_available; /* set if previous match exists */
  76652. uInt strstart; /* start of string to insert */
  76653. uInt match_start; /* start of matching string */
  76654. uInt lookahead; /* number of valid bytes ahead in window */
  76655. uInt prev_length;
  76656. uInt max_chain_length;
  76657. uInt max_lazy_match;
  76658. # define max_insert_length max_lazy_match
  76659. int level; /* compression level (1..9) */
  76660. int strategy; /* favor or force Huffman coding*/
  76661. uInt good_match;
  76662. int nice_match; /* Stop searching when current match exceeds this */
  76663. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76664. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76665. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76666. struct tree_desc_s l_desc; /* desc. for literal tree */
  76667. struct tree_desc_s d_desc; /* desc. for distance tree */
  76668. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76669. ush bl_count[MAX_BITS+1];
  76670. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  76671. int heap_len; /* number of elements in the heap */
  76672. int heap_max; /* element of largest frequency */
  76673. uch depth[2*L_CODES+1];
  76674. uchf *l_buf; /* buffer for literals or lengths */
  76675. uInt lit_bufsize;
  76676. uInt last_lit; /* running index in l_buf */
  76677. ushf *d_buf;
  76678. ulg opt_len; /* bit length of current block with optimal trees */
  76679. ulg static_len; /* bit length of current block with static trees */
  76680. uInt matches; /* number of string matches in current block */
  76681. int last_eob_len; /* bit length of EOB code for last block */
  76682. #ifdef DEBUG
  76683. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  76684. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  76685. #endif
  76686. ush bi_buf;
  76687. int bi_valid;
  76688. } FAR deflate_state;
  76689. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  76690. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76691. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  76692. void _tr_init OF((deflate_state *s));
  76693. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  76694. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76695. int eof));
  76696. void _tr_align OF((deflate_state *s));
  76697. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76698. int eof));
  76699. #define d_code(dist) \
  76700. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  76701. #ifndef DEBUG
  76702. #if defined(GEN_TREES_H) || !defined(STDC)
  76703. extern uch _length_code[];
  76704. extern uch _dist_code[];
  76705. #else
  76706. extern const uch _length_code[];
  76707. extern const uch _dist_code[];
  76708. #endif
  76709. # define _tr_tally_lit(s, c, flush) \
  76710. { uch cc = (c); \
  76711. s->d_buf[s->last_lit] = 0; \
  76712. s->l_buf[s->last_lit++] = cc; \
  76713. s->dyn_ltree[cc].Freq++; \
  76714. flush = (s->last_lit == s->lit_bufsize-1); \
  76715. }
  76716. # define _tr_tally_dist(s, distance, length, flush) \
  76717. { uch len = (length); \
  76718. ush dist = (distance); \
  76719. s->d_buf[s->last_lit] = dist; \
  76720. s->l_buf[s->last_lit++] = len; \
  76721. dist--; \
  76722. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  76723. s->dyn_dtree[d_code(dist)].Freq++; \
  76724. flush = (s->last_lit == s->lit_bufsize-1); \
  76725. }
  76726. #else
  76727. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  76728. # define _tr_tally_dist(s, distance, length, flush) \
  76729. flush = _tr_tally(s, distance, length)
  76730. #endif
  76731. #endif /* DEFLATE_H */
  76732. /*** End of inlined file: deflate.h ***/
  76733. const char deflate_copyright[] =
  76734. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  76735. typedef enum {
  76736. need_more, /* block not completed, need more input or more output */
  76737. block_done, /* block flush performed */
  76738. finish_started, /* finish started, need only more output at next deflate */
  76739. finish_done /* finish done, accept no more input or output */
  76740. } block_state;
  76741. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  76742. local void fill_window OF((deflate_state *s));
  76743. local block_state deflate_stored OF((deflate_state *s, int flush));
  76744. local block_state deflate_fast OF((deflate_state *s, int flush));
  76745. #ifndef FASTEST
  76746. local block_state deflate_slow OF((deflate_state *s, int flush));
  76747. #endif
  76748. local void lm_init OF((deflate_state *s));
  76749. local void putShortMSB OF((deflate_state *s, uInt b));
  76750. local void flush_pending OF((z_streamp strm));
  76751. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  76752. #ifndef FASTEST
  76753. #ifdef ASMV
  76754. void match_init OF((void)); /* asm code initialization */
  76755. uInt longest_match OF((deflate_state *s, IPos cur_match));
  76756. #else
  76757. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  76758. #endif
  76759. #endif
  76760. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  76761. #ifdef DEBUG
  76762. local void check_match OF((deflate_state *s, IPos start, IPos match,
  76763. int length));
  76764. #endif
  76765. #define NIL 0
  76766. #ifndef TOO_FAR
  76767. # define TOO_FAR 4096
  76768. #endif
  76769. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76770. typedef struct config_s {
  76771. ush good_length; /* reduce lazy search above this match length */
  76772. ush max_lazy; /* do not perform lazy search above this match length */
  76773. ush nice_length; /* quit search above this match length */
  76774. ush max_chain;
  76775. compress_func func;
  76776. } config;
  76777. #ifdef FASTEST
  76778. local const config configuration_table[2] = {
  76779. {0, 0, 0, 0, deflate_stored}, /* store only */
  76780. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  76781. #else
  76782. local const config configuration_table[10] = {
  76783. {0, 0, 0, 0, deflate_stored}, /* store only */
  76784. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  76785. {4, 5, 16, 8, deflate_fast},
  76786. {4, 6, 32, 32, deflate_fast},
  76787. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  76788. {8, 16, 32, 32, deflate_slow},
  76789. {8, 16, 128, 128, deflate_slow},
  76790. {8, 32, 128, 256, deflate_slow},
  76791. {32, 128, 258, 1024, deflate_slow},
  76792. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  76793. #endif
  76794. #define EQUAL 0
  76795. #ifndef NO_DUMMY_DECL
  76796. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  76797. #endif
  76798. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  76799. #ifdef FASTEST
  76800. #define INSERT_STRING(s, str, match_head) \
  76801. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76802. match_head = s->head[s->ins_h], \
  76803. s->head[s->ins_h] = (Pos)(str))
  76804. #else
  76805. #define INSERT_STRING(s, str, match_head) \
  76806. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76807. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  76808. s->head[s->ins_h] = (Pos)(str))
  76809. #endif
  76810. #define CLEAR_HASH(s) \
  76811. s->head[s->hash_size-1] = NIL; \
  76812. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  76813. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  76814. {
  76815. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  76816. Z_DEFAULT_STRATEGY, version, stream_size);
  76817. }
  76818. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  76819. {
  76820. deflate_state *s;
  76821. int wrap = 1;
  76822. static const char my_version[] = ZLIB_VERSION;
  76823. ushf *overlay;
  76824. if (version == Z_NULL || version[0] != my_version[0] ||
  76825. stream_size != sizeof(z_stream)) {
  76826. return Z_VERSION_ERROR;
  76827. }
  76828. if (strm == Z_NULL) return Z_STREAM_ERROR;
  76829. strm->msg = Z_NULL;
  76830. if (strm->zalloc == (alloc_func)0) {
  76831. strm->zalloc = zcalloc;
  76832. strm->opaque = (voidpf)0;
  76833. }
  76834. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  76835. #ifdef FASTEST
  76836. if (level != 0) level = 1;
  76837. #else
  76838. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76839. #endif
  76840. if (windowBits < 0) { /* suppress zlib wrapper */
  76841. wrap = 0;
  76842. windowBits = -windowBits;
  76843. }
  76844. #ifdef GZIP
  76845. else if (windowBits > 15) {
  76846. wrap = 2; /* write gzip wrapper instead */
  76847. windowBits -= 16;
  76848. }
  76849. #endif
  76850. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  76851. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  76852. strategy < 0 || strategy > Z_FIXED) {
  76853. return Z_STREAM_ERROR;
  76854. }
  76855. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  76856. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  76857. if (s == Z_NULL) return Z_MEM_ERROR;
  76858. strm->state = (struct internal_state FAR *)s;
  76859. s->strm = strm;
  76860. s->wrap = wrap;
  76861. s->gzhead = Z_NULL;
  76862. s->w_bits = windowBits;
  76863. s->w_size = 1 << s->w_bits;
  76864. s->w_mask = s->w_size - 1;
  76865. s->hash_bits = memLevel + 7;
  76866. s->hash_size = 1 << s->hash_bits;
  76867. s->hash_mask = s->hash_size - 1;
  76868. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  76869. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  76870. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  76871. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  76872. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  76873. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  76874. s->pending_buf = (uchf *) overlay;
  76875. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  76876. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  76877. s->pending_buf == Z_NULL) {
  76878. s->status = FINISH_STATE;
  76879. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  76880. deflateEnd (strm);
  76881. return Z_MEM_ERROR;
  76882. }
  76883. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  76884. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  76885. s->level = level;
  76886. s->strategy = strategy;
  76887. s->method = (Byte)method;
  76888. return deflateReset(strm);
  76889. }
  76890. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  76891. {
  76892. deflate_state *s;
  76893. uInt length = dictLength;
  76894. uInt n;
  76895. IPos hash_head = 0;
  76896. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  76897. strm->state->wrap == 2 ||
  76898. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  76899. return Z_STREAM_ERROR;
  76900. s = strm->state;
  76901. if (s->wrap)
  76902. strm->adler = adler32(strm->adler, dictionary, dictLength);
  76903. if (length < MIN_MATCH) return Z_OK;
  76904. if (length > MAX_DIST(s)) {
  76905. length = MAX_DIST(s);
  76906. dictionary += dictLength - length; /* use the tail of the dictionary */
  76907. }
  76908. zmemcpy(s->window, dictionary, length);
  76909. s->strstart = length;
  76910. s->block_start = (long)length;
  76911. s->ins_h = s->window[0];
  76912. UPDATE_HASH(s, s->ins_h, s->window[1]);
  76913. for (n = 0; n <= length - MIN_MATCH; n++) {
  76914. INSERT_STRING(s, n, hash_head);
  76915. }
  76916. if (hash_head) hash_head = 0; /* to make compiler happy */
  76917. return Z_OK;
  76918. }
  76919. int ZEXPORT deflateReset (z_streamp strm)
  76920. {
  76921. deflate_state *s;
  76922. if (strm == Z_NULL || strm->state == Z_NULL ||
  76923. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  76924. return Z_STREAM_ERROR;
  76925. }
  76926. strm->total_in = strm->total_out = 0;
  76927. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  76928. strm->data_type = Z_UNKNOWN;
  76929. s = (deflate_state *)strm->state;
  76930. s->pending = 0;
  76931. s->pending_out = s->pending_buf;
  76932. if (s->wrap < 0) {
  76933. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  76934. }
  76935. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  76936. strm->adler =
  76937. #ifdef GZIP
  76938. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  76939. #endif
  76940. adler32(0L, Z_NULL, 0);
  76941. s->last_flush = Z_NO_FLUSH;
  76942. _tr_init(s);
  76943. lm_init(s);
  76944. return Z_OK;
  76945. }
  76946. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  76947. {
  76948. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76949. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  76950. strm->state->gzhead = head;
  76951. return Z_OK;
  76952. }
  76953. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  76954. {
  76955. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76956. strm->state->bi_valid = bits;
  76957. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  76958. return Z_OK;
  76959. }
  76960. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  76961. {
  76962. deflate_state *s;
  76963. compress_func func;
  76964. int err = Z_OK;
  76965. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76966. s = strm->state;
  76967. #ifdef FASTEST
  76968. if (level != 0) level = 1;
  76969. #else
  76970. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76971. #endif
  76972. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  76973. return Z_STREAM_ERROR;
  76974. }
  76975. func = configuration_table[s->level].func;
  76976. if (func != configuration_table[level].func && strm->total_in != 0) {
  76977. err = deflate(strm, Z_PARTIAL_FLUSH);
  76978. }
  76979. if (s->level != level) {
  76980. s->level = level;
  76981. s->max_lazy_match = configuration_table[level].max_lazy;
  76982. s->good_match = configuration_table[level].good_length;
  76983. s->nice_match = configuration_table[level].nice_length;
  76984. s->max_chain_length = configuration_table[level].max_chain;
  76985. }
  76986. s->strategy = strategy;
  76987. return err;
  76988. }
  76989. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  76990. {
  76991. deflate_state *s;
  76992. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76993. s = strm->state;
  76994. s->good_match = good_length;
  76995. s->max_lazy_match = max_lazy;
  76996. s->nice_match = nice_length;
  76997. s->max_chain_length = max_chain;
  76998. return Z_OK;
  76999. }
  77000. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  77001. {
  77002. deflate_state *s;
  77003. uLong destLen;
  77004. destLen = sourceLen +
  77005. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  77006. if (strm == Z_NULL || strm->state == Z_NULL)
  77007. return destLen;
  77008. s = strm->state;
  77009. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  77010. return destLen;
  77011. return compressBound(sourceLen);
  77012. }
  77013. local void putShortMSB (deflate_state *s, uInt b)
  77014. {
  77015. put_byte(s, (Byte)(b >> 8));
  77016. put_byte(s, (Byte)(b & 0xff));
  77017. }
  77018. local void flush_pending (z_streamp strm)
  77019. {
  77020. unsigned len = strm->state->pending;
  77021. if (len > strm->avail_out) len = strm->avail_out;
  77022. if (len == 0) return;
  77023. zmemcpy(strm->next_out, strm->state->pending_out, len);
  77024. strm->next_out += len;
  77025. strm->state->pending_out += len;
  77026. strm->total_out += len;
  77027. strm->avail_out -= len;
  77028. strm->state->pending -= len;
  77029. if (strm->state->pending == 0) {
  77030. strm->state->pending_out = strm->state->pending_buf;
  77031. }
  77032. }
  77033. int ZEXPORT deflate (z_streamp strm, int flush)
  77034. {
  77035. int old_flush; /* value of flush param for previous deflate call */
  77036. deflate_state *s;
  77037. if (strm == Z_NULL || strm->state == Z_NULL ||
  77038. flush > Z_FINISH || flush < 0) {
  77039. return Z_STREAM_ERROR;
  77040. }
  77041. s = strm->state;
  77042. if (strm->next_out == Z_NULL ||
  77043. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  77044. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  77045. ERR_RETURN(strm, Z_STREAM_ERROR);
  77046. }
  77047. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  77048. s->strm = strm; /* just in case */
  77049. old_flush = s->last_flush;
  77050. s->last_flush = flush;
  77051. if (s->status == INIT_STATE) {
  77052. #ifdef GZIP
  77053. if (s->wrap == 2) {
  77054. strm->adler = crc32(0L, Z_NULL, 0);
  77055. put_byte(s, 31);
  77056. put_byte(s, 139);
  77057. put_byte(s, 8);
  77058. if (s->gzhead == NULL) {
  77059. put_byte(s, 0);
  77060. put_byte(s, 0);
  77061. put_byte(s, 0);
  77062. put_byte(s, 0);
  77063. put_byte(s, 0);
  77064. put_byte(s, s->level == 9 ? 2 :
  77065. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77066. 4 : 0));
  77067. put_byte(s, OS_CODE);
  77068. s->status = BUSY_STATE;
  77069. }
  77070. else {
  77071. put_byte(s, (s->gzhead->text ? 1 : 0) +
  77072. (s->gzhead->hcrc ? 2 : 0) +
  77073. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  77074. (s->gzhead->name == Z_NULL ? 0 : 8) +
  77075. (s->gzhead->comment == Z_NULL ? 0 : 16)
  77076. );
  77077. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  77078. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  77079. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  77080. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  77081. put_byte(s, s->level == 9 ? 2 :
  77082. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77083. 4 : 0));
  77084. put_byte(s, s->gzhead->os & 0xff);
  77085. if (s->gzhead->extra != NULL) {
  77086. put_byte(s, s->gzhead->extra_len & 0xff);
  77087. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  77088. }
  77089. if (s->gzhead->hcrc)
  77090. strm->adler = crc32(strm->adler, s->pending_buf,
  77091. s->pending);
  77092. s->gzindex = 0;
  77093. s->status = EXTRA_STATE;
  77094. }
  77095. }
  77096. else
  77097. #endif
  77098. {
  77099. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  77100. uInt level_flags;
  77101. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  77102. level_flags = 0;
  77103. else if (s->level < 6)
  77104. level_flags = 1;
  77105. else if (s->level == 6)
  77106. level_flags = 2;
  77107. else
  77108. level_flags = 3;
  77109. header |= (level_flags << 6);
  77110. if (s->strstart != 0) header |= PRESET_DICT;
  77111. header += 31 - (header % 31);
  77112. s->status = BUSY_STATE;
  77113. putShortMSB(s, header);
  77114. if (s->strstart != 0) {
  77115. putShortMSB(s, (uInt)(strm->adler >> 16));
  77116. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77117. }
  77118. strm->adler = adler32(0L, Z_NULL, 0);
  77119. }
  77120. }
  77121. #ifdef GZIP
  77122. if (s->status == EXTRA_STATE) {
  77123. if (s->gzhead->extra != NULL) {
  77124. uInt beg = s->pending; /* start of bytes to update crc */
  77125. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  77126. if (s->pending == s->pending_buf_size) {
  77127. if (s->gzhead->hcrc && s->pending > beg)
  77128. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77129. s->pending - beg);
  77130. flush_pending(strm);
  77131. beg = s->pending;
  77132. if (s->pending == s->pending_buf_size)
  77133. break;
  77134. }
  77135. put_byte(s, s->gzhead->extra[s->gzindex]);
  77136. s->gzindex++;
  77137. }
  77138. if (s->gzhead->hcrc && s->pending > beg)
  77139. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77140. s->pending - beg);
  77141. if (s->gzindex == s->gzhead->extra_len) {
  77142. s->gzindex = 0;
  77143. s->status = NAME_STATE;
  77144. }
  77145. }
  77146. else
  77147. s->status = NAME_STATE;
  77148. }
  77149. if (s->status == NAME_STATE) {
  77150. if (s->gzhead->name != NULL) {
  77151. uInt beg = s->pending; /* start of bytes to update crc */
  77152. int val;
  77153. do {
  77154. if (s->pending == s->pending_buf_size) {
  77155. if (s->gzhead->hcrc && s->pending > beg)
  77156. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77157. s->pending - beg);
  77158. flush_pending(strm);
  77159. beg = s->pending;
  77160. if (s->pending == s->pending_buf_size) {
  77161. val = 1;
  77162. break;
  77163. }
  77164. }
  77165. val = s->gzhead->name[s->gzindex++];
  77166. put_byte(s, val);
  77167. } while (val != 0);
  77168. if (s->gzhead->hcrc && s->pending > beg)
  77169. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77170. s->pending - beg);
  77171. if (val == 0) {
  77172. s->gzindex = 0;
  77173. s->status = COMMENT_STATE;
  77174. }
  77175. }
  77176. else
  77177. s->status = COMMENT_STATE;
  77178. }
  77179. if (s->status == COMMENT_STATE) {
  77180. if (s->gzhead->comment != NULL) {
  77181. uInt beg = s->pending; /* start of bytes to update crc */
  77182. int val;
  77183. do {
  77184. if (s->pending == s->pending_buf_size) {
  77185. if (s->gzhead->hcrc && s->pending > beg)
  77186. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77187. s->pending - beg);
  77188. flush_pending(strm);
  77189. beg = s->pending;
  77190. if (s->pending == s->pending_buf_size) {
  77191. val = 1;
  77192. break;
  77193. }
  77194. }
  77195. val = s->gzhead->comment[s->gzindex++];
  77196. put_byte(s, val);
  77197. } while (val != 0);
  77198. if (s->gzhead->hcrc && s->pending > beg)
  77199. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77200. s->pending - beg);
  77201. if (val == 0)
  77202. s->status = HCRC_STATE;
  77203. }
  77204. else
  77205. s->status = HCRC_STATE;
  77206. }
  77207. if (s->status == HCRC_STATE) {
  77208. if (s->gzhead->hcrc) {
  77209. if (s->pending + 2 > s->pending_buf_size)
  77210. flush_pending(strm);
  77211. if (s->pending + 2 <= s->pending_buf_size) {
  77212. put_byte(s, (Byte)(strm->adler & 0xff));
  77213. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77214. strm->adler = crc32(0L, Z_NULL, 0);
  77215. s->status = BUSY_STATE;
  77216. }
  77217. }
  77218. else
  77219. s->status = BUSY_STATE;
  77220. }
  77221. #endif
  77222. if (s->pending != 0) {
  77223. flush_pending(strm);
  77224. if (strm->avail_out == 0) {
  77225. s->last_flush = -1;
  77226. return Z_OK;
  77227. }
  77228. } else if (strm->avail_in == 0 && flush <= old_flush &&
  77229. flush != Z_FINISH) {
  77230. ERR_RETURN(strm, Z_BUF_ERROR);
  77231. }
  77232. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  77233. ERR_RETURN(strm, Z_BUF_ERROR);
  77234. }
  77235. if (strm->avail_in != 0 || s->lookahead != 0 ||
  77236. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  77237. block_state bstate;
  77238. bstate = (*(configuration_table[s->level].func))(s, flush);
  77239. if (bstate == finish_started || bstate == finish_done) {
  77240. s->status = FINISH_STATE;
  77241. }
  77242. if (bstate == need_more || bstate == finish_started) {
  77243. if (strm->avail_out == 0) {
  77244. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  77245. }
  77246. return Z_OK;
  77247. }
  77248. if (bstate == block_done) {
  77249. if (flush == Z_PARTIAL_FLUSH) {
  77250. _tr_align(s);
  77251. } else { /* FULL_FLUSH or SYNC_FLUSH */
  77252. _tr_stored_block(s, (char*)0, 0L, 0);
  77253. if (flush == Z_FULL_FLUSH) {
  77254. CLEAR_HASH(s); /* forget history */
  77255. }
  77256. }
  77257. flush_pending(strm);
  77258. if (strm->avail_out == 0) {
  77259. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  77260. return Z_OK;
  77261. }
  77262. }
  77263. }
  77264. Assert(strm->avail_out > 0, "bug2");
  77265. if (flush != Z_FINISH) return Z_OK;
  77266. if (s->wrap <= 0) return Z_STREAM_END;
  77267. #ifdef GZIP
  77268. if (s->wrap == 2) {
  77269. put_byte(s, (Byte)(strm->adler & 0xff));
  77270. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77271. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  77272. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  77273. put_byte(s, (Byte)(strm->total_in & 0xff));
  77274. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  77275. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  77276. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  77277. }
  77278. else
  77279. #endif
  77280. {
  77281. putShortMSB(s, (uInt)(strm->adler >> 16));
  77282. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77283. }
  77284. flush_pending(strm);
  77285. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  77286. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  77287. }
  77288. int ZEXPORT deflateEnd (z_streamp strm)
  77289. {
  77290. int status;
  77291. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77292. status = strm->state->status;
  77293. if (status != INIT_STATE &&
  77294. status != EXTRA_STATE &&
  77295. status != NAME_STATE &&
  77296. status != COMMENT_STATE &&
  77297. status != HCRC_STATE &&
  77298. status != BUSY_STATE &&
  77299. status != FINISH_STATE) {
  77300. return Z_STREAM_ERROR;
  77301. }
  77302. TRY_FREE(strm, strm->state->pending_buf);
  77303. TRY_FREE(strm, strm->state->head);
  77304. TRY_FREE(strm, strm->state->prev);
  77305. TRY_FREE(strm, strm->state->window);
  77306. ZFREE(strm, strm->state);
  77307. strm->state = Z_NULL;
  77308. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77309. }
  77310. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77311. {
  77312. #ifdef MAXSEG_64K
  77313. return Z_STREAM_ERROR;
  77314. #else
  77315. deflate_state *ds;
  77316. deflate_state *ss;
  77317. ushf *overlay;
  77318. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77319. return Z_STREAM_ERROR;
  77320. }
  77321. ss = source->state;
  77322. zmemcpy(dest, source, sizeof(z_stream));
  77323. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  77324. if (ds == Z_NULL) return Z_MEM_ERROR;
  77325. dest->state = (struct internal_state FAR *) ds;
  77326. zmemcpy(ds, ss, sizeof(deflate_state));
  77327. ds->strm = dest;
  77328. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77329. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77330. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77331. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77332. ds->pending_buf = (uchf *) overlay;
  77333. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77334. ds->pending_buf == Z_NULL) {
  77335. deflateEnd (dest);
  77336. return Z_MEM_ERROR;
  77337. }
  77338. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77339. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77340. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77341. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77342. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77343. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77344. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77345. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77346. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77347. ds->bl_desc.dyn_tree = ds->bl_tree;
  77348. return Z_OK;
  77349. #endif /* MAXSEG_64K */
  77350. }
  77351. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77352. {
  77353. unsigned len = strm->avail_in;
  77354. if (len > size) len = size;
  77355. if (len == 0) return 0;
  77356. strm->avail_in -= len;
  77357. if (strm->state->wrap == 1) {
  77358. strm->adler = adler32(strm->adler, strm->next_in, len);
  77359. }
  77360. #ifdef GZIP
  77361. else if (strm->state->wrap == 2) {
  77362. strm->adler = crc32(strm->adler, strm->next_in, len);
  77363. }
  77364. #endif
  77365. zmemcpy(buf, strm->next_in, len);
  77366. strm->next_in += len;
  77367. strm->total_in += len;
  77368. return (int)len;
  77369. }
  77370. local void lm_init (deflate_state *s)
  77371. {
  77372. s->window_size = (ulg)2L*s->w_size;
  77373. CLEAR_HASH(s);
  77374. s->max_lazy_match = configuration_table[s->level].max_lazy;
  77375. s->good_match = configuration_table[s->level].good_length;
  77376. s->nice_match = configuration_table[s->level].nice_length;
  77377. s->max_chain_length = configuration_table[s->level].max_chain;
  77378. s->strstart = 0;
  77379. s->block_start = 0L;
  77380. s->lookahead = 0;
  77381. s->match_length = s->prev_length = MIN_MATCH-1;
  77382. s->match_available = 0;
  77383. s->ins_h = 0;
  77384. #ifndef FASTEST
  77385. #ifdef ASMV
  77386. match_init(); /* initialize the asm code */
  77387. #endif
  77388. #endif
  77389. }
  77390. #ifndef FASTEST
  77391. #ifndef ASMV
  77392. local uInt longest_match(deflate_state *s, IPos cur_match)
  77393. {
  77394. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  77395. register Bytef *scan = s->window + s->strstart; /* current string */
  77396. register Bytef *match; /* matched string */
  77397. register int len; /* length of current match */
  77398. int best_len = s->prev_length; /* best match length so far */
  77399. int nice_match = s->nice_match; /* stop if match long enough */
  77400. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  77401. s->strstart - (IPos)MAX_DIST(s) : NIL;
  77402. Posf *prev = s->prev;
  77403. uInt wmask = s->w_mask;
  77404. #ifdef UNALIGNED_OK
  77405. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  77406. register ush scan_start = *(ushf*)scan;
  77407. register ush scan_end = *(ushf*)(scan+best_len-1);
  77408. #else
  77409. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77410. register Byte scan_end1 = scan[best_len-1];
  77411. register Byte scan_end = scan[best_len];
  77412. #endif
  77413. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77414. if (s->prev_length >= s->good_match) {
  77415. chain_length >>= 2;
  77416. }
  77417. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77418. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77419. do {
  77420. Assert(cur_match < s->strstart, "no future");
  77421. match = s->window + cur_match;
  77422. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77423. if (*(ushf*)(match+best_len-1) != scan_end ||
  77424. *(ushf*)match != scan_start) continue;
  77425. Assert(scan[2] == match[2], "scan[2]?");
  77426. scan++, match++;
  77427. do {
  77428. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77429. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77430. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77431. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77432. scan < strend);
  77433. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77434. if (*scan == *match) scan++;
  77435. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77436. scan = strend - (MAX_MATCH-1);
  77437. #else /* UNALIGNED_OK */
  77438. if (match[best_len] != scan_end ||
  77439. match[best_len-1] != scan_end1 ||
  77440. *match != *scan ||
  77441. *++match != scan[1]) continue;
  77442. scan += 2, match++;
  77443. Assert(*scan == *match, "match[2]?");
  77444. do {
  77445. } while (*++scan == *++match && *++scan == *++match &&
  77446. *++scan == *++match && *++scan == *++match &&
  77447. *++scan == *++match && *++scan == *++match &&
  77448. *++scan == *++match && *++scan == *++match &&
  77449. scan < strend);
  77450. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77451. len = MAX_MATCH - (int)(strend - scan);
  77452. scan = strend - MAX_MATCH;
  77453. #endif /* UNALIGNED_OK */
  77454. if (len > best_len) {
  77455. s->match_start = cur_match;
  77456. best_len = len;
  77457. if (len >= nice_match) break;
  77458. #ifdef UNALIGNED_OK
  77459. scan_end = *(ushf*)(scan+best_len-1);
  77460. #else
  77461. scan_end1 = scan[best_len-1];
  77462. scan_end = scan[best_len];
  77463. #endif
  77464. }
  77465. } while ((cur_match = prev[cur_match & wmask]) > limit
  77466. && --chain_length != 0);
  77467. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77468. return s->lookahead;
  77469. }
  77470. #endif /* ASMV */
  77471. #endif /* FASTEST */
  77472. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77473. {
  77474. register Bytef *scan = s->window + s->strstart; /* current string */
  77475. register Bytef *match; /* matched string */
  77476. register int len; /* length of current match */
  77477. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77478. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77479. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77480. Assert(cur_match < s->strstart, "no future");
  77481. match = s->window + cur_match;
  77482. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77483. scan += 2, match += 2;
  77484. Assert(*scan == *match, "match[2]?");
  77485. do {
  77486. } while (*++scan == *++match && *++scan == *++match &&
  77487. *++scan == *++match && *++scan == *++match &&
  77488. *++scan == *++match && *++scan == *++match &&
  77489. *++scan == *++match && *++scan == *++match &&
  77490. scan < strend);
  77491. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77492. len = MAX_MATCH - (int)(strend - scan);
  77493. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77494. s->match_start = cur_match;
  77495. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77496. }
  77497. #ifdef DEBUG
  77498. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77499. {
  77500. if (zmemcmp(s->window + match,
  77501. s->window + start, length) != EQUAL) {
  77502. fprintf(stderr, " start %u, match %u, length %d\n",
  77503. start, match, length);
  77504. do {
  77505. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77506. } while (--length != 0);
  77507. z_error("invalid match");
  77508. }
  77509. if (z_verbose > 1) {
  77510. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77511. do { putc(s->window[start++], stderr); } while (--length != 0);
  77512. }
  77513. }
  77514. #else
  77515. # define check_match(s, start, match, length)
  77516. #endif /* DEBUG */
  77517. local void fill_window (deflate_state *s)
  77518. {
  77519. register unsigned n, m;
  77520. register Posf *p;
  77521. unsigned more; /* Amount of free space at the end of the window. */
  77522. uInt wsize = s->w_size;
  77523. do {
  77524. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77525. if (sizeof(int) <= 2) {
  77526. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77527. more = wsize;
  77528. } else if (more == (unsigned)(-1)) {
  77529. more--;
  77530. }
  77531. }
  77532. if (s->strstart >= wsize+MAX_DIST(s)) {
  77533. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77534. s->match_start -= wsize;
  77535. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77536. s->block_start -= (long) wsize;
  77537. n = s->hash_size;
  77538. p = &s->head[n];
  77539. do {
  77540. m = *--p;
  77541. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77542. } while (--n);
  77543. n = wsize;
  77544. #ifndef FASTEST
  77545. p = &s->prev[n];
  77546. do {
  77547. m = *--p;
  77548. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77549. } while (--n);
  77550. #endif
  77551. more += wsize;
  77552. }
  77553. if (s->strm->avail_in == 0) return;
  77554. Assert(more >= 2, "more < 2");
  77555. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77556. s->lookahead += n;
  77557. if (s->lookahead >= MIN_MATCH) {
  77558. s->ins_h = s->window[s->strstart];
  77559. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77560. #if MIN_MATCH != 3
  77561. Call UPDATE_HASH() MIN_MATCH-3 more times
  77562. #endif
  77563. }
  77564. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77565. }
  77566. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77567. _tr_flush_block(s, (s->block_start >= 0L ? \
  77568. (charf *)&s->window[(unsigned)s->block_start] : \
  77569. (charf *)Z_NULL), \
  77570. (ulg)((long)s->strstart - s->block_start), \
  77571. (eof)); \
  77572. s->block_start = s->strstart; \
  77573. flush_pending(s->strm); \
  77574. Tracev((stderr,"[FLUSH]")); \
  77575. }
  77576. #define FLUSH_BLOCK(s, eof) { \
  77577. FLUSH_BLOCK_ONLY(s, eof); \
  77578. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77579. }
  77580. local block_state deflate_stored(deflate_state *s, int flush)
  77581. {
  77582. ulg max_block_size = 0xffff;
  77583. ulg max_start;
  77584. if (max_block_size > s->pending_buf_size - 5) {
  77585. max_block_size = s->pending_buf_size - 5;
  77586. }
  77587. for (;;) {
  77588. if (s->lookahead <= 1) {
  77589. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77590. s->block_start >= (long)s->w_size, "slide too late");
  77591. fill_window(s);
  77592. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77593. if (s->lookahead == 0) break; /* flush the current block */
  77594. }
  77595. Assert(s->block_start >= 0L, "block gone");
  77596. s->strstart += s->lookahead;
  77597. s->lookahead = 0;
  77598. max_start = s->block_start + max_block_size;
  77599. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77600. s->lookahead = (uInt)(s->strstart - max_start);
  77601. s->strstart = (uInt)max_start;
  77602. FLUSH_BLOCK(s, 0);
  77603. }
  77604. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77605. FLUSH_BLOCK(s, 0);
  77606. }
  77607. }
  77608. FLUSH_BLOCK(s, flush == Z_FINISH);
  77609. return flush == Z_FINISH ? finish_done : block_done;
  77610. }
  77611. local block_state deflate_fast(deflate_state *s, int flush)
  77612. {
  77613. IPos hash_head = NIL; /* head of the hash chain */
  77614. int bflush; /* set if current block must be flushed */
  77615. for (;;) {
  77616. if (s->lookahead < MIN_LOOKAHEAD) {
  77617. fill_window(s);
  77618. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77619. return need_more;
  77620. }
  77621. if (s->lookahead == 0) break; /* flush the current block */
  77622. }
  77623. if (s->lookahead >= MIN_MATCH) {
  77624. INSERT_STRING(s, s->strstart, hash_head);
  77625. }
  77626. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77627. #ifdef FASTEST
  77628. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77629. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77630. s->match_length = longest_match_fast (s, hash_head);
  77631. }
  77632. #else
  77633. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77634. s->match_length = longest_match (s, hash_head);
  77635. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77636. s->match_length = longest_match_fast (s, hash_head);
  77637. }
  77638. #endif
  77639. }
  77640. if (s->match_length >= MIN_MATCH) {
  77641. check_match(s, s->strstart, s->match_start, s->match_length);
  77642. _tr_tally_dist(s, s->strstart - s->match_start,
  77643. s->match_length - MIN_MATCH, bflush);
  77644. s->lookahead -= s->match_length;
  77645. #ifndef FASTEST
  77646. if (s->match_length <= s->max_insert_length &&
  77647. s->lookahead >= MIN_MATCH) {
  77648. s->match_length--; /* string at strstart already in table */
  77649. do {
  77650. s->strstart++;
  77651. INSERT_STRING(s, s->strstart, hash_head);
  77652. } while (--s->match_length != 0);
  77653. s->strstart++;
  77654. } else
  77655. #endif
  77656. {
  77657. s->strstart += s->match_length;
  77658. s->match_length = 0;
  77659. s->ins_h = s->window[s->strstart];
  77660. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77661. #if MIN_MATCH != 3
  77662. Call UPDATE_HASH() MIN_MATCH-3 more times
  77663. #endif
  77664. }
  77665. } else {
  77666. Tracevv((stderr,"%c", s->window[s->strstart]));
  77667. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77668. s->lookahead--;
  77669. s->strstart++;
  77670. }
  77671. if (bflush) FLUSH_BLOCK(s, 0);
  77672. }
  77673. FLUSH_BLOCK(s, flush == Z_FINISH);
  77674. return flush == Z_FINISH ? finish_done : block_done;
  77675. }
  77676. #ifndef FASTEST
  77677. local block_state deflate_slow(deflate_state *s, int flush)
  77678. {
  77679. IPos hash_head = NIL; /* head of hash chain */
  77680. int bflush; /* set if current block must be flushed */
  77681. for (;;) {
  77682. if (s->lookahead < MIN_LOOKAHEAD) {
  77683. fill_window(s);
  77684. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77685. return need_more;
  77686. }
  77687. if (s->lookahead == 0) break; /* flush the current block */
  77688. }
  77689. if (s->lookahead >= MIN_MATCH) {
  77690. INSERT_STRING(s, s->strstart, hash_head);
  77691. }
  77692. s->prev_length = s->match_length, s->prev_match = s->match_start;
  77693. s->match_length = MIN_MATCH-1;
  77694. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  77695. s->strstart - hash_head <= MAX_DIST(s)) {
  77696. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77697. s->match_length = longest_match (s, hash_head);
  77698. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77699. s->match_length = longest_match_fast (s, hash_head);
  77700. }
  77701. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  77702. #if TOO_FAR <= 32767
  77703. || (s->match_length == MIN_MATCH &&
  77704. s->strstart - s->match_start > TOO_FAR)
  77705. #endif
  77706. )) {
  77707. s->match_length = MIN_MATCH-1;
  77708. }
  77709. }
  77710. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  77711. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  77712. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  77713. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  77714. s->prev_length - MIN_MATCH, bflush);
  77715. s->lookahead -= s->prev_length-1;
  77716. s->prev_length -= 2;
  77717. do {
  77718. if (++s->strstart <= max_insert) {
  77719. INSERT_STRING(s, s->strstart, hash_head);
  77720. }
  77721. } while (--s->prev_length != 0);
  77722. s->match_available = 0;
  77723. s->match_length = MIN_MATCH-1;
  77724. s->strstart++;
  77725. if (bflush) FLUSH_BLOCK(s, 0);
  77726. } else if (s->match_available) {
  77727. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77728. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77729. if (bflush) {
  77730. FLUSH_BLOCK_ONLY(s, 0);
  77731. }
  77732. s->strstart++;
  77733. s->lookahead--;
  77734. if (s->strm->avail_out == 0) return need_more;
  77735. } else {
  77736. s->match_available = 1;
  77737. s->strstart++;
  77738. s->lookahead--;
  77739. }
  77740. }
  77741. Assert (flush != Z_NO_FLUSH, "no flush?");
  77742. if (s->match_available) {
  77743. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77744. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77745. s->match_available = 0;
  77746. }
  77747. FLUSH_BLOCK(s, flush == Z_FINISH);
  77748. return flush == Z_FINISH ? finish_done : block_done;
  77749. }
  77750. #endif /* FASTEST */
  77751. #if 0
  77752. local block_state deflate_rle(s, flush)
  77753. deflate_state *s;
  77754. int flush;
  77755. {
  77756. int bflush; /* set if current block must be flushed */
  77757. uInt run; /* length of run */
  77758. uInt max; /* maximum length of run */
  77759. uInt prev; /* byte at distance one to match */
  77760. Bytef *scan; /* scan for end of run */
  77761. for (;;) {
  77762. if (s->lookahead < MAX_MATCH) {
  77763. fill_window(s);
  77764. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  77765. return need_more;
  77766. }
  77767. if (s->lookahead == 0) break; /* flush the current block */
  77768. }
  77769. run = 0;
  77770. if (s->strstart > 0) { /* if there is a previous byte, that is */
  77771. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  77772. scan = s->window + s->strstart - 1;
  77773. prev = *scan++;
  77774. do {
  77775. if (*scan++ != prev)
  77776. break;
  77777. } while (++run < max);
  77778. }
  77779. if (run >= MIN_MATCH) {
  77780. check_match(s, s->strstart, s->strstart - 1, run);
  77781. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  77782. s->lookahead -= run;
  77783. s->strstart += run;
  77784. } else {
  77785. Tracevv((stderr,"%c", s->window[s->strstart]));
  77786. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77787. s->lookahead--;
  77788. s->strstart++;
  77789. }
  77790. if (bflush) FLUSH_BLOCK(s, 0);
  77791. }
  77792. FLUSH_BLOCK(s, flush == Z_FINISH);
  77793. return flush == Z_FINISH ? finish_done : block_done;
  77794. }
  77795. #endif
  77796. /*** End of inlined file: deflate.c ***/
  77797. /*** Start of inlined file: inffast.c ***/
  77798. /*** Start of inlined file: inftrees.h ***/
  77799. #ifndef _INFTREES_H_
  77800. #define _INFTREES_H_
  77801. typedef struct {
  77802. unsigned char op; /* operation, extra bits, table bits */
  77803. unsigned char bits; /* bits in this part of the code */
  77804. unsigned short val; /* offset in table or code value */
  77805. } code;
  77806. #define ENOUGH 2048
  77807. #define MAXD 592
  77808. typedef enum {
  77809. CODES,
  77810. LENS,
  77811. DISTS
  77812. } codetype;
  77813. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  77814. unsigned codes, code FAR * FAR *table,
  77815. unsigned FAR *bits, unsigned short FAR *work));
  77816. #endif
  77817. /*** End of inlined file: inftrees.h ***/
  77818. /*** Start of inlined file: inflate.h ***/
  77819. #ifndef _INFLATE_H_
  77820. #define _INFLATE_H_
  77821. #ifndef NO_GZIP
  77822. # define GUNZIP
  77823. #endif
  77824. typedef enum {
  77825. HEAD, /* i: waiting for magic header */
  77826. FLAGS, /* i: waiting for method and flags (gzip) */
  77827. TIME, /* i: waiting for modification time (gzip) */
  77828. OS, /* i: waiting for extra flags and operating system (gzip) */
  77829. EXLEN, /* i: waiting for extra length (gzip) */
  77830. EXTRA, /* i: waiting for extra bytes (gzip) */
  77831. NAME, /* i: waiting for end of file name (gzip) */
  77832. COMMENT, /* i: waiting for end of comment (gzip) */
  77833. HCRC, /* i: waiting for header crc (gzip) */
  77834. DICTID, /* i: waiting for dictionary check value */
  77835. DICT, /* waiting for inflateSetDictionary() call */
  77836. TYPE, /* i: waiting for type bits, including last-flag bit */
  77837. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  77838. STORED, /* i: waiting for stored size (length and complement) */
  77839. COPY, /* i/o: waiting for input or output to copy stored block */
  77840. TABLE, /* i: waiting for dynamic block table lengths */
  77841. LENLENS, /* i: waiting for code length code lengths */
  77842. CODELENS, /* i: waiting for length/lit and distance code lengths */
  77843. LEN, /* i: waiting for length/lit code */
  77844. LENEXT, /* i: waiting for length extra bits */
  77845. DIST, /* i: waiting for distance code */
  77846. DISTEXT, /* i: waiting for distance extra bits */
  77847. MATCH, /* o: waiting for output space to copy string */
  77848. LIT, /* o: waiting for output space to write literal */
  77849. CHECK, /* i: waiting for 32-bit check value */
  77850. LENGTH, /* i: waiting for 32-bit length (gzip) */
  77851. DONE, /* finished check, done -- remain here until reset */
  77852. BAD, /* got a data error -- remain here until reset */
  77853. MEM, /* got an inflate() memory error -- remain here until reset */
  77854. SYNC /* looking for synchronization bytes to restart inflate() */
  77855. } inflate_mode;
  77856. struct inflate_state {
  77857. inflate_mode mode; /* current inflate mode */
  77858. int last; /* true if processing last block */
  77859. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  77860. int havedict; /* true if dictionary provided */
  77861. int flags; /* gzip header method and flags (0 if zlib) */
  77862. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  77863. unsigned long check; /* protected copy of check value */
  77864. unsigned long total; /* protected copy of output count */
  77865. gz_headerp head; /* where to save gzip header information */
  77866. unsigned wbits; /* log base 2 of requested window size */
  77867. unsigned wsize; /* window size or zero if not using window */
  77868. unsigned whave; /* valid bytes in the window */
  77869. unsigned write; /* window write index */
  77870. unsigned char FAR *window; /* allocated sliding window, if needed */
  77871. unsigned long hold; /* input bit accumulator */
  77872. unsigned bits; /* number of bits in "in" */
  77873. unsigned length; /* literal or length of data to copy */
  77874. unsigned offset; /* distance back to copy string from */
  77875. unsigned extra; /* extra bits needed */
  77876. code const FAR *lencode; /* starting table for length/literal codes */
  77877. code const FAR *distcode; /* starting table for distance codes */
  77878. unsigned lenbits; /* index bits for lencode */
  77879. unsigned distbits; /* index bits for distcode */
  77880. unsigned ncode; /* number of code length code lengths */
  77881. unsigned nlen; /* number of length code lengths */
  77882. unsigned ndist; /* number of distance code lengths */
  77883. unsigned have; /* number of code lengths in lens[] */
  77884. code FAR *next; /* next available space in codes[] */
  77885. unsigned short lens[320]; /* temporary storage for code lengths */
  77886. unsigned short work[288]; /* work area for code table building */
  77887. code codes[ENOUGH]; /* space for code tables */
  77888. };
  77889. #endif
  77890. /*** End of inlined file: inflate.h ***/
  77891. /*** Start of inlined file: inffast.h ***/
  77892. void inflate_fast OF((z_streamp strm, unsigned start));
  77893. /*** End of inlined file: inffast.h ***/
  77894. #ifndef ASMINF
  77895. #ifdef POSTINC
  77896. # define OFF 0
  77897. # define PUP(a) *(a)++
  77898. #else
  77899. # define OFF 1
  77900. # define PUP(a) *++(a)
  77901. #endif
  77902. void inflate_fast (z_streamp strm, unsigned start)
  77903. {
  77904. struct inflate_state FAR *state;
  77905. unsigned char FAR *in; /* local strm->next_in */
  77906. unsigned char FAR *last; /* while in < last, enough input available */
  77907. unsigned char FAR *out; /* local strm->next_out */
  77908. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  77909. unsigned char FAR *end; /* while out < end, enough space available */
  77910. #ifdef INFLATE_STRICT
  77911. unsigned dmax; /* maximum distance from zlib header */
  77912. #endif
  77913. unsigned wsize; /* window size or zero if not using window */
  77914. unsigned whave; /* valid bytes in the window */
  77915. unsigned write; /* window write index */
  77916. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  77917. unsigned long hold; /* local strm->hold */
  77918. unsigned bits; /* local strm->bits */
  77919. code const FAR *lcode; /* local strm->lencode */
  77920. code const FAR *dcode; /* local strm->distcode */
  77921. unsigned lmask; /* mask for first level of length codes */
  77922. unsigned dmask; /* mask for first level of distance codes */
  77923. code thisx; /* retrieved table entry */
  77924. unsigned op; /* code bits, operation, extra bits, or */
  77925. unsigned len; /* match length, unused bytes */
  77926. unsigned dist; /* match distance */
  77927. unsigned char FAR *from; /* where to copy match from */
  77928. state = (struct inflate_state FAR *)strm->state;
  77929. in = strm->next_in - OFF;
  77930. last = in + (strm->avail_in - 5);
  77931. out = strm->next_out - OFF;
  77932. beg = out - (start - strm->avail_out);
  77933. end = out + (strm->avail_out - 257);
  77934. #ifdef INFLATE_STRICT
  77935. dmax = state->dmax;
  77936. #endif
  77937. wsize = state->wsize;
  77938. whave = state->whave;
  77939. write = state->write;
  77940. window = state->window;
  77941. hold = state->hold;
  77942. bits = state->bits;
  77943. lcode = state->lencode;
  77944. dcode = state->distcode;
  77945. lmask = (1U << state->lenbits) - 1;
  77946. dmask = (1U << state->distbits) - 1;
  77947. do {
  77948. if (bits < 15) {
  77949. hold += (unsigned long)(PUP(in)) << bits;
  77950. bits += 8;
  77951. hold += (unsigned long)(PUP(in)) << bits;
  77952. bits += 8;
  77953. }
  77954. thisx = lcode[hold & lmask];
  77955. dolen:
  77956. op = (unsigned)(thisx.bits);
  77957. hold >>= op;
  77958. bits -= op;
  77959. op = (unsigned)(thisx.op);
  77960. if (op == 0) { /* literal */
  77961. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  77962. "inflate: literal '%c'\n" :
  77963. "inflate: literal 0x%02x\n", thisx.val));
  77964. PUP(out) = (unsigned char)(thisx.val);
  77965. }
  77966. else if (op & 16) { /* length base */
  77967. len = (unsigned)(thisx.val);
  77968. op &= 15; /* number of extra bits */
  77969. if (op) {
  77970. if (bits < op) {
  77971. hold += (unsigned long)(PUP(in)) << bits;
  77972. bits += 8;
  77973. }
  77974. len += (unsigned)hold & ((1U << op) - 1);
  77975. hold >>= op;
  77976. bits -= op;
  77977. }
  77978. Tracevv((stderr, "inflate: length %u\n", len));
  77979. if (bits < 15) {
  77980. hold += (unsigned long)(PUP(in)) << bits;
  77981. bits += 8;
  77982. hold += (unsigned long)(PUP(in)) << bits;
  77983. bits += 8;
  77984. }
  77985. thisx = dcode[hold & dmask];
  77986. dodist:
  77987. op = (unsigned)(thisx.bits);
  77988. hold >>= op;
  77989. bits -= op;
  77990. op = (unsigned)(thisx.op);
  77991. if (op & 16) { /* distance base */
  77992. dist = (unsigned)(thisx.val);
  77993. op &= 15; /* number of extra bits */
  77994. if (bits < op) {
  77995. hold += (unsigned long)(PUP(in)) << bits;
  77996. bits += 8;
  77997. if (bits < op) {
  77998. hold += (unsigned long)(PUP(in)) << bits;
  77999. bits += 8;
  78000. }
  78001. }
  78002. dist += (unsigned)hold & ((1U << op) - 1);
  78003. #ifdef INFLATE_STRICT
  78004. if (dist > dmax) {
  78005. strm->msg = (char *)"invalid distance too far back";
  78006. state->mode = BAD;
  78007. break;
  78008. }
  78009. #endif
  78010. hold >>= op;
  78011. bits -= op;
  78012. Tracevv((stderr, "inflate: distance %u\n", dist));
  78013. op = (unsigned)(out - beg); /* max distance in output */
  78014. if (dist > op) { /* see if copy from window */
  78015. op = dist - op; /* distance back in window */
  78016. if (op > whave) {
  78017. strm->msg = (char *)"invalid distance too far back";
  78018. state->mode = BAD;
  78019. break;
  78020. }
  78021. from = window - OFF;
  78022. if (write == 0) { /* very common case */
  78023. from += wsize - op;
  78024. if (op < len) { /* some from window */
  78025. len -= op;
  78026. do {
  78027. PUP(out) = PUP(from);
  78028. } while (--op);
  78029. from = out - dist; /* rest from output */
  78030. }
  78031. }
  78032. else if (write < op) { /* wrap around window */
  78033. from += wsize + write - op;
  78034. op -= write;
  78035. if (op < len) { /* some from end of window */
  78036. len -= op;
  78037. do {
  78038. PUP(out) = PUP(from);
  78039. } while (--op);
  78040. from = window - OFF;
  78041. if (write < len) { /* some from start of window */
  78042. op = write;
  78043. len -= op;
  78044. do {
  78045. PUP(out) = PUP(from);
  78046. } while (--op);
  78047. from = out - dist; /* rest from output */
  78048. }
  78049. }
  78050. }
  78051. else { /* contiguous in window */
  78052. from += write - op;
  78053. if (op < len) { /* some from window */
  78054. len -= op;
  78055. do {
  78056. PUP(out) = PUP(from);
  78057. } while (--op);
  78058. from = out - dist; /* rest from output */
  78059. }
  78060. }
  78061. while (len > 2) {
  78062. PUP(out) = PUP(from);
  78063. PUP(out) = PUP(from);
  78064. PUP(out) = PUP(from);
  78065. len -= 3;
  78066. }
  78067. if (len) {
  78068. PUP(out) = PUP(from);
  78069. if (len > 1)
  78070. PUP(out) = PUP(from);
  78071. }
  78072. }
  78073. else {
  78074. from = out - dist; /* copy direct from output */
  78075. do { /* minimum length is three */
  78076. PUP(out) = PUP(from);
  78077. PUP(out) = PUP(from);
  78078. PUP(out) = PUP(from);
  78079. len -= 3;
  78080. } while (len > 2);
  78081. if (len) {
  78082. PUP(out) = PUP(from);
  78083. if (len > 1)
  78084. PUP(out) = PUP(from);
  78085. }
  78086. }
  78087. }
  78088. else if ((op & 64) == 0) { /* 2nd level distance code */
  78089. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  78090. goto dodist;
  78091. }
  78092. else {
  78093. strm->msg = (char *)"invalid distance code";
  78094. state->mode = BAD;
  78095. break;
  78096. }
  78097. }
  78098. else if ((op & 64) == 0) { /* 2nd level length code */
  78099. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  78100. goto dolen;
  78101. }
  78102. else if (op & 32) { /* end-of-block */
  78103. Tracevv((stderr, "inflate: end of block\n"));
  78104. state->mode = TYPE;
  78105. break;
  78106. }
  78107. else {
  78108. strm->msg = (char *)"invalid literal/length code";
  78109. state->mode = BAD;
  78110. break;
  78111. }
  78112. } while (in < last && out < end);
  78113. len = bits >> 3;
  78114. in -= len;
  78115. bits -= len << 3;
  78116. hold &= (1U << bits) - 1;
  78117. strm->next_in = in + OFF;
  78118. strm->next_out = out + OFF;
  78119. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  78120. strm->avail_out = (unsigned)(out < end ?
  78121. 257 + (end - out) : 257 - (out - end));
  78122. state->hold = hold;
  78123. state->bits = bits;
  78124. return;
  78125. }
  78126. #endif /* !ASMINF */
  78127. /*** End of inlined file: inffast.c ***/
  78128. #undef PULLBYTE
  78129. #undef LOAD
  78130. #undef RESTORE
  78131. #undef INITBITS
  78132. #undef NEEDBITS
  78133. #undef DROPBITS
  78134. #undef BYTEBITS
  78135. /*** Start of inlined file: inflate.c ***/
  78136. /*** Start of inlined file: inffast.h ***/
  78137. void inflate_fast OF((z_streamp strm, unsigned start));
  78138. /*** End of inlined file: inffast.h ***/
  78139. #ifdef MAKEFIXED
  78140. # ifndef BUILDFIXED
  78141. # define BUILDFIXED
  78142. # endif
  78143. #endif
  78144. local void fixedtables OF((struct inflate_state FAR *state));
  78145. local int updatewindow OF((z_streamp strm, unsigned out));
  78146. #ifdef BUILDFIXED
  78147. void makefixed OF((void));
  78148. #endif
  78149. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  78150. unsigned len));
  78151. int ZEXPORT inflateReset (z_streamp strm)
  78152. {
  78153. struct inflate_state FAR *state;
  78154. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78155. state = (struct inflate_state FAR *)strm->state;
  78156. strm->total_in = strm->total_out = state->total = 0;
  78157. strm->msg = Z_NULL;
  78158. strm->adler = 1; /* to support ill-conceived Java test suite */
  78159. state->mode = HEAD;
  78160. state->last = 0;
  78161. state->havedict = 0;
  78162. state->dmax = 32768U;
  78163. state->head = Z_NULL;
  78164. state->wsize = 0;
  78165. state->whave = 0;
  78166. state->write = 0;
  78167. state->hold = 0;
  78168. state->bits = 0;
  78169. state->lencode = state->distcode = state->next = state->codes;
  78170. Tracev((stderr, "inflate: reset\n"));
  78171. return Z_OK;
  78172. }
  78173. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  78174. {
  78175. struct inflate_state FAR *state;
  78176. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78177. state = (struct inflate_state FAR *)strm->state;
  78178. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  78179. value &= (1L << bits) - 1;
  78180. state->hold += value << state->bits;
  78181. state->bits += bits;
  78182. return Z_OK;
  78183. }
  78184. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  78185. {
  78186. struct inflate_state FAR *state;
  78187. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  78188. stream_size != (int)(sizeof(z_stream)))
  78189. return Z_VERSION_ERROR;
  78190. if (strm == Z_NULL) return Z_STREAM_ERROR;
  78191. strm->msg = Z_NULL; /* in case we return an error */
  78192. if (strm->zalloc == (alloc_func)0) {
  78193. strm->zalloc = zcalloc;
  78194. strm->opaque = (voidpf)0;
  78195. }
  78196. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  78197. state = (struct inflate_state FAR *)
  78198. ZALLOC(strm, 1, sizeof(struct inflate_state));
  78199. if (state == Z_NULL) return Z_MEM_ERROR;
  78200. Tracev((stderr, "inflate: allocated\n"));
  78201. strm->state = (struct internal_state FAR *)state;
  78202. if (windowBits < 0) {
  78203. state->wrap = 0;
  78204. windowBits = -windowBits;
  78205. }
  78206. else {
  78207. state->wrap = (windowBits >> 4) + 1;
  78208. #ifdef GUNZIP
  78209. if (windowBits < 48) windowBits &= 15;
  78210. #endif
  78211. }
  78212. if (windowBits < 8 || windowBits > 15) {
  78213. ZFREE(strm, state);
  78214. strm->state = Z_NULL;
  78215. return Z_STREAM_ERROR;
  78216. }
  78217. state->wbits = (unsigned)windowBits;
  78218. state->window = Z_NULL;
  78219. return inflateReset(strm);
  78220. }
  78221. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  78222. {
  78223. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  78224. }
  78225. local void fixedtables (struct inflate_state FAR *state)
  78226. {
  78227. #ifdef BUILDFIXED
  78228. static int virgin = 1;
  78229. static code *lenfix, *distfix;
  78230. static code fixed[544];
  78231. if (virgin) {
  78232. unsigned sym, bits;
  78233. static code *next;
  78234. sym = 0;
  78235. while (sym < 144) state->lens[sym++] = 8;
  78236. while (sym < 256) state->lens[sym++] = 9;
  78237. while (sym < 280) state->lens[sym++] = 7;
  78238. while (sym < 288) state->lens[sym++] = 8;
  78239. next = fixed;
  78240. lenfix = next;
  78241. bits = 9;
  78242. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  78243. sym = 0;
  78244. while (sym < 32) state->lens[sym++] = 5;
  78245. distfix = next;
  78246. bits = 5;
  78247. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  78248. virgin = 0;
  78249. }
  78250. #else /* !BUILDFIXED */
  78251. /*** Start of inlined file: inffixed.h ***/
  78252. static const code lenfix[512] = {
  78253. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  78254. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  78255. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  78256. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  78257. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  78258. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  78259. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  78260. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  78261. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  78262. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  78263. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  78264. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  78265. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  78266. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  78267. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  78268. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  78269. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  78270. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  78271. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  78272. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  78273. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  78274. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  78275. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  78276. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  78277. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  78278. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  78279. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  78280. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  78281. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  78282. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  78283. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  78284. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  78285. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  78286. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  78287. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  78288. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  78289. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  78290. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  78291. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  78292. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  78293. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  78294. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  78295. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  78296. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  78297. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78298. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78299. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78300. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78301. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78302. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78303. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78304. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78305. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78306. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78307. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78308. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78309. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78310. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78311. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78312. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78313. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78314. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78315. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78316. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78317. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78318. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78319. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78320. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78321. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  78322. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  78323. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  78324. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  78325. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  78326. {0,9,255}
  78327. };
  78328. static const code distfix[32] = {
  78329. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78330. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78331. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78332. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78333. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78334. {22,5,193},{64,5,0}
  78335. };
  78336. /*** End of inlined file: inffixed.h ***/
  78337. #endif /* BUILDFIXED */
  78338. state->lencode = lenfix;
  78339. state->lenbits = 9;
  78340. state->distcode = distfix;
  78341. state->distbits = 5;
  78342. }
  78343. #ifdef MAKEFIXED
  78344. #include <stdio.h>
  78345. void makefixed()
  78346. {
  78347. unsigned low, size;
  78348. struct inflate_state state;
  78349. fixedtables(&state);
  78350. puts(" /* inffixed.h -- table for decoding fixed codes");
  78351. puts(" * Generated automatically by makefixed().");
  78352. puts(" */");
  78353. puts("");
  78354. puts(" /* WARNING: this file should *not* be used by applications.");
  78355. puts(" It is part of the implementation of this library and is");
  78356. puts(" subject to change. Applications should only use zlib.h.");
  78357. puts(" */");
  78358. puts("");
  78359. size = 1U << 9;
  78360. printf(" static const code lenfix[%u] = {", size);
  78361. low = 0;
  78362. for (;;) {
  78363. if ((low % 7) == 0) printf("\n ");
  78364. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78365. state.lencode[low].val);
  78366. if (++low == size) break;
  78367. putchar(',');
  78368. }
  78369. puts("\n };");
  78370. size = 1U << 5;
  78371. printf("\n static const code distfix[%u] = {", size);
  78372. low = 0;
  78373. for (;;) {
  78374. if ((low % 6) == 0) printf("\n ");
  78375. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  78376. state.distcode[low].val);
  78377. if (++low == size) break;
  78378. putchar(',');
  78379. }
  78380. puts("\n };");
  78381. }
  78382. #endif /* MAKEFIXED */
  78383. local int updatewindow (z_streamp strm, unsigned out)
  78384. {
  78385. struct inflate_state FAR *state;
  78386. unsigned copy, dist;
  78387. state = (struct inflate_state FAR *)strm->state;
  78388. if (state->window == Z_NULL) {
  78389. state->window = (unsigned char FAR *)
  78390. ZALLOC(strm, 1U << state->wbits,
  78391. sizeof(unsigned char));
  78392. if (state->window == Z_NULL) return 1;
  78393. }
  78394. if (state->wsize == 0) {
  78395. state->wsize = 1U << state->wbits;
  78396. state->write = 0;
  78397. state->whave = 0;
  78398. }
  78399. copy = out - strm->avail_out;
  78400. if (copy >= state->wsize) {
  78401. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  78402. state->write = 0;
  78403. state->whave = state->wsize;
  78404. }
  78405. else {
  78406. dist = state->wsize - state->write;
  78407. if (dist > copy) dist = copy;
  78408. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78409. copy -= dist;
  78410. if (copy) {
  78411. zmemcpy(state->window, strm->next_out - copy, copy);
  78412. state->write = copy;
  78413. state->whave = state->wsize;
  78414. }
  78415. else {
  78416. state->write += dist;
  78417. if (state->write == state->wsize) state->write = 0;
  78418. if (state->whave < state->wsize) state->whave += dist;
  78419. }
  78420. }
  78421. return 0;
  78422. }
  78423. #ifdef GUNZIP
  78424. # define UPDATE(check, buf, len) \
  78425. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78426. #else
  78427. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78428. #endif
  78429. #ifdef GUNZIP
  78430. # define CRC2(check, word) \
  78431. do { \
  78432. hbuf[0] = (unsigned char)(word); \
  78433. hbuf[1] = (unsigned char)((word) >> 8); \
  78434. check = crc32(check, hbuf, 2); \
  78435. } while (0)
  78436. # define CRC4(check, word) \
  78437. do { \
  78438. hbuf[0] = (unsigned char)(word); \
  78439. hbuf[1] = (unsigned char)((word) >> 8); \
  78440. hbuf[2] = (unsigned char)((word) >> 16); \
  78441. hbuf[3] = (unsigned char)((word) >> 24); \
  78442. check = crc32(check, hbuf, 4); \
  78443. } while (0)
  78444. #endif
  78445. #define LOAD() \
  78446. do { \
  78447. put = strm->next_out; \
  78448. left = strm->avail_out; \
  78449. next = strm->next_in; \
  78450. have = strm->avail_in; \
  78451. hold = state->hold; \
  78452. bits = state->bits; \
  78453. } while (0)
  78454. #define RESTORE() \
  78455. do { \
  78456. strm->next_out = put; \
  78457. strm->avail_out = left; \
  78458. strm->next_in = next; \
  78459. strm->avail_in = have; \
  78460. state->hold = hold; \
  78461. state->bits = bits; \
  78462. } while (0)
  78463. #define INITBITS() \
  78464. do { \
  78465. hold = 0; \
  78466. bits = 0; \
  78467. } while (0)
  78468. #define PULLBYTE() \
  78469. do { \
  78470. if (have == 0) goto inf_leave; \
  78471. have--; \
  78472. hold += (unsigned long)(*next++) << bits; \
  78473. bits += 8; \
  78474. } while (0)
  78475. #define NEEDBITS(n) \
  78476. do { \
  78477. while (bits < (unsigned)(n)) \
  78478. PULLBYTE(); \
  78479. } while (0)
  78480. #define BITS(n) \
  78481. ((unsigned)hold & ((1U << (n)) - 1))
  78482. #define DROPBITS(n) \
  78483. do { \
  78484. hold >>= (n); \
  78485. bits -= (unsigned)(n); \
  78486. } while (0)
  78487. #define BYTEBITS() \
  78488. do { \
  78489. hold >>= bits & 7; \
  78490. bits -= bits & 7; \
  78491. } while (0)
  78492. #define REVERSE(q) \
  78493. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78494. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78495. int ZEXPORT inflate (z_streamp strm, int flush)
  78496. {
  78497. struct inflate_state FAR *state;
  78498. unsigned char FAR *next; /* next input */
  78499. unsigned char FAR *put; /* next output */
  78500. unsigned have, left; /* available input and output */
  78501. unsigned long hold; /* bit buffer */
  78502. unsigned bits; /* bits in bit buffer */
  78503. unsigned in, out; /* save starting available input and output */
  78504. unsigned copy; /* number of stored or match bytes to copy */
  78505. unsigned char FAR *from; /* where to copy match bytes from */
  78506. code thisx; /* current decoding table entry */
  78507. code last; /* parent table entry */
  78508. unsigned len; /* length to copy for repeats, bits to drop */
  78509. int ret; /* return code */
  78510. #ifdef GUNZIP
  78511. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78512. #endif
  78513. static const unsigned short order[19] = /* permutation of code lengths */
  78514. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78515. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78516. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78517. return Z_STREAM_ERROR;
  78518. state = (struct inflate_state FAR *)strm->state;
  78519. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78520. LOAD();
  78521. in = have;
  78522. out = left;
  78523. ret = Z_OK;
  78524. for (;;)
  78525. switch (state->mode) {
  78526. case HEAD:
  78527. if (state->wrap == 0) {
  78528. state->mode = TYPEDO;
  78529. break;
  78530. }
  78531. NEEDBITS(16);
  78532. #ifdef GUNZIP
  78533. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78534. state->check = crc32(0L, Z_NULL, 0);
  78535. CRC2(state->check, hold);
  78536. INITBITS();
  78537. state->mode = FLAGS;
  78538. break;
  78539. }
  78540. state->flags = 0; /* expect zlib header */
  78541. if (state->head != Z_NULL)
  78542. state->head->done = -1;
  78543. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78544. #else
  78545. if (
  78546. #endif
  78547. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78548. strm->msg = (char *)"incorrect header check";
  78549. state->mode = BAD;
  78550. break;
  78551. }
  78552. if (BITS(4) != Z_DEFLATED) {
  78553. strm->msg = (char *)"unknown compression method";
  78554. state->mode = BAD;
  78555. break;
  78556. }
  78557. DROPBITS(4);
  78558. len = BITS(4) + 8;
  78559. if (len > state->wbits) {
  78560. strm->msg = (char *)"invalid window size";
  78561. state->mode = BAD;
  78562. break;
  78563. }
  78564. state->dmax = 1U << len;
  78565. Tracev((stderr, "inflate: zlib header ok\n"));
  78566. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78567. state->mode = hold & 0x200 ? DICTID : TYPE;
  78568. INITBITS();
  78569. break;
  78570. #ifdef GUNZIP
  78571. case FLAGS:
  78572. NEEDBITS(16);
  78573. state->flags = (int)(hold);
  78574. if ((state->flags & 0xff) != Z_DEFLATED) {
  78575. strm->msg = (char *)"unknown compression method";
  78576. state->mode = BAD;
  78577. break;
  78578. }
  78579. if (state->flags & 0xe000) {
  78580. strm->msg = (char *)"unknown header flags set";
  78581. state->mode = BAD;
  78582. break;
  78583. }
  78584. if (state->head != Z_NULL)
  78585. state->head->text = (int)((hold >> 8) & 1);
  78586. if (state->flags & 0x0200) CRC2(state->check, hold);
  78587. INITBITS();
  78588. state->mode = TIME;
  78589. case TIME:
  78590. NEEDBITS(32);
  78591. if (state->head != Z_NULL)
  78592. state->head->time = hold;
  78593. if (state->flags & 0x0200) CRC4(state->check, hold);
  78594. INITBITS();
  78595. state->mode = OS;
  78596. case OS:
  78597. NEEDBITS(16);
  78598. if (state->head != Z_NULL) {
  78599. state->head->xflags = (int)(hold & 0xff);
  78600. state->head->os = (int)(hold >> 8);
  78601. }
  78602. if (state->flags & 0x0200) CRC2(state->check, hold);
  78603. INITBITS();
  78604. state->mode = EXLEN;
  78605. case EXLEN:
  78606. if (state->flags & 0x0400) {
  78607. NEEDBITS(16);
  78608. state->length = (unsigned)(hold);
  78609. if (state->head != Z_NULL)
  78610. state->head->extra_len = (unsigned)hold;
  78611. if (state->flags & 0x0200) CRC2(state->check, hold);
  78612. INITBITS();
  78613. }
  78614. else if (state->head != Z_NULL)
  78615. state->head->extra = Z_NULL;
  78616. state->mode = EXTRA;
  78617. case EXTRA:
  78618. if (state->flags & 0x0400) {
  78619. copy = state->length;
  78620. if (copy > have) copy = have;
  78621. if (copy) {
  78622. if (state->head != Z_NULL &&
  78623. state->head->extra != Z_NULL) {
  78624. len = state->head->extra_len - state->length;
  78625. zmemcpy(state->head->extra + len, next,
  78626. len + copy > state->head->extra_max ?
  78627. state->head->extra_max - len : copy);
  78628. }
  78629. if (state->flags & 0x0200)
  78630. state->check = crc32(state->check, next, copy);
  78631. have -= copy;
  78632. next += copy;
  78633. state->length -= copy;
  78634. }
  78635. if (state->length) goto inf_leave;
  78636. }
  78637. state->length = 0;
  78638. state->mode = NAME;
  78639. case NAME:
  78640. if (state->flags & 0x0800) {
  78641. if (have == 0) goto inf_leave;
  78642. copy = 0;
  78643. do {
  78644. len = (unsigned)(next[copy++]);
  78645. if (state->head != Z_NULL &&
  78646. state->head->name != Z_NULL &&
  78647. state->length < state->head->name_max)
  78648. state->head->name[state->length++] = len;
  78649. } while (len && copy < have);
  78650. if (state->flags & 0x0200)
  78651. state->check = crc32(state->check, next, copy);
  78652. have -= copy;
  78653. next += copy;
  78654. if (len) goto inf_leave;
  78655. }
  78656. else if (state->head != Z_NULL)
  78657. state->head->name = Z_NULL;
  78658. state->length = 0;
  78659. state->mode = COMMENT;
  78660. case COMMENT:
  78661. if (state->flags & 0x1000) {
  78662. if (have == 0) goto inf_leave;
  78663. copy = 0;
  78664. do {
  78665. len = (unsigned)(next[copy++]);
  78666. if (state->head != Z_NULL &&
  78667. state->head->comment != Z_NULL &&
  78668. state->length < state->head->comm_max)
  78669. state->head->comment[state->length++] = len;
  78670. } while (len && copy < have);
  78671. if (state->flags & 0x0200)
  78672. state->check = crc32(state->check, next, copy);
  78673. have -= copy;
  78674. next += copy;
  78675. if (len) goto inf_leave;
  78676. }
  78677. else if (state->head != Z_NULL)
  78678. state->head->comment = Z_NULL;
  78679. state->mode = HCRC;
  78680. case HCRC:
  78681. if (state->flags & 0x0200) {
  78682. NEEDBITS(16);
  78683. if (hold != (state->check & 0xffff)) {
  78684. strm->msg = (char *)"header crc mismatch";
  78685. state->mode = BAD;
  78686. break;
  78687. }
  78688. INITBITS();
  78689. }
  78690. if (state->head != Z_NULL) {
  78691. state->head->hcrc = (int)((state->flags >> 9) & 1);
  78692. state->head->done = 1;
  78693. }
  78694. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  78695. state->mode = TYPE;
  78696. break;
  78697. #endif
  78698. case DICTID:
  78699. NEEDBITS(32);
  78700. strm->adler = state->check = REVERSE(hold);
  78701. INITBITS();
  78702. state->mode = DICT;
  78703. case DICT:
  78704. if (state->havedict == 0) {
  78705. RESTORE();
  78706. return Z_NEED_DICT;
  78707. }
  78708. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78709. state->mode = TYPE;
  78710. case TYPE:
  78711. if (flush == Z_BLOCK) goto inf_leave;
  78712. case TYPEDO:
  78713. if (state->last) {
  78714. BYTEBITS();
  78715. state->mode = CHECK;
  78716. break;
  78717. }
  78718. NEEDBITS(3);
  78719. state->last = BITS(1);
  78720. DROPBITS(1);
  78721. switch (BITS(2)) {
  78722. case 0: /* stored block */
  78723. Tracev((stderr, "inflate: stored block%s\n",
  78724. state->last ? " (last)" : ""));
  78725. state->mode = STORED;
  78726. break;
  78727. case 1: /* fixed block */
  78728. fixedtables(state);
  78729. Tracev((stderr, "inflate: fixed codes block%s\n",
  78730. state->last ? " (last)" : ""));
  78731. state->mode = LEN; /* decode codes */
  78732. break;
  78733. case 2: /* dynamic block */
  78734. Tracev((stderr, "inflate: dynamic codes block%s\n",
  78735. state->last ? " (last)" : ""));
  78736. state->mode = TABLE;
  78737. break;
  78738. case 3:
  78739. strm->msg = (char *)"invalid block type";
  78740. state->mode = BAD;
  78741. }
  78742. DROPBITS(2);
  78743. break;
  78744. case STORED:
  78745. BYTEBITS(); /* go to byte boundary */
  78746. NEEDBITS(32);
  78747. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  78748. strm->msg = (char *)"invalid stored block lengths";
  78749. state->mode = BAD;
  78750. break;
  78751. }
  78752. state->length = (unsigned)hold & 0xffff;
  78753. Tracev((stderr, "inflate: stored length %u\n",
  78754. state->length));
  78755. INITBITS();
  78756. state->mode = COPY;
  78757. case COPY:
  78758. copy = state->length;
  78759. if (copy) {
  78760. if (copy > have) copy = have;
  78761. if (copy > left) copy = left;
  78762. if (copy == 0) goto inf_leave;
  78763. zmemcpy(put, next, copy);
  78764. have -= copy;
  78765. next += copy;
  78766. left -= copy;
  78767. put += copy;
  78768. state->length -= copy;
  78769. break;
  78770. }
  78771. Tracev((stderr, "inflate: stored end\n"));
  78772. state->mode = TYPE;
  78773. break;
  78774. case TABLE:
  78775. NEEDBITS(14);
  78776. state->nlen = BITS(5) + 257;
  78777. DROPBITS(5);
  78778. state->ndist = BITS(5) + 1;
  78779. DROPBITS(5);
  78780. state->ncode = BITS(4) + 4;
  78781. DROPBITS(4);
  78782. #ifndef PKZIP_BUG_WORKAROUND
  78783. if (state->nlen > 286 || state->ndist > 30) {
  78784. strm->msg = (char *)"too many length or distance symbols";
  78785. state->mode = BAD;
  78786. break;
  78787. }
  78788. #endif
  78789. Tracev((stderr, "inflate: table sizes ok\n"));
  78790. state->have = 0;
  78791. state->mode = LENLENS;
  78792. case LENLENS:
  78793. while (state->have < state->ncode) {
  78794. NEEDBITS(3);
  78795. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  78796. DROPBITS(3);
  78797. }
  78798. while (state->have < 19)
  78799. state->lens[order[state->have++]] = 0;
  78800. state->next = state->codes;
  78801. state->lencode = (code const FAR *)(state->next);
  78802. state->lenbits = 7;
  78803. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  78804. &(state->lenbits), state->work);
  78805. if (ret) {
  78806. strm->msg = (char *)"invalid code lengths set";
  78807. state->mode = BAD;
  78808. break;
  78809. }
  78810. Tracev((stderr, "inflate: code lengths ok\n"));
  78811. state->have = 0;
  78812. state->mode = CODELENS;
  78813. case CODELENS:
  78814. while (state->have < state->nlen + state->ndist) {
  78815. for (;;) {
  78816. thisx = state->lencode[BITS(state->lenbits)];
  78817. if ((unsigned)(thisx.bits) <= bits) break;
  78818. PULLBYTE();
  78819. }
  78820. if (thisx.val < 16) {
  78821. NEEDBITS(thisx.bits);
  78822. DROPBITS(thisx.bits);
  78823. state->lens[state->have++] = thisx.val;
  78824. }
  78825. else {
  78826. if (thisx.val == 16) {
  78827. NEEDBITS(thisx.bits + 2);
  78828. DROPBITS(thisx.bits);
  78829. if (state->have == 0) {
  78830. strm->msg = (char *)"invalid bit length repeat";
  78831. state->mode = BAD;
  78832. break;
  78833. }
  78834. len = state->lens[state->have - 1];
  78835. copy = 3 + BITS(2);
  78836. DROPBITS(2);
  78837. }
  78838. else if (thisx.val == 17) {
  78839. NEEDBITS(thisx.bits + 3);
  78840. DROPBITS(thisx.bits);
  78841. len = 0;
  78842. copy = 3 + BITS(3);
  78843. DROPBITS(3);
  78844. }
  78845. else {
  78846. NEEDBITS(thisx.bits + 7);
  78847. DROPBITS(thisx.bits);
  78848. len = 0;
  78849. copy = 11 + BITS(7);
  78850. DROPBITS(7);
  78851. }
  78852. if (state->have + copy > state->nlen + state->ndist) {
  78853. strm->msg = (char *)"invalid bit length repeat";
  78854. state->mode = BAD;
  78855. break;
  78856. }
  78857. while (copy--)
  78858. state->lens[state->have++] = (unsigned short)len;
  78859. }
  78860. }
  78861. if (state->mode == BAD) break;
  78862. state->next = state->codes;
  78863. state->lencode = (code const FAR *)(state->next);
  78864. state->lenbits = 9;
  78865. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  78866. &(state->lenbits), state->work);
  78867. if (ret) {
  78868. strm->msg = (char *)"invalid literal/lengths set";
  78869. state->mode = BAD;
  78870. break;
  78871. }
  78872. state->distcode = (code const FAR *)(state->next);
  78873. state->distbits = 6;
  78874. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  78875. &(state->next), &(state->distbits), state->work);
  78876. if (ret) {
  78877. strm->msg = (char *)"invalid distances set";
  78878. state->mode = BAD;
  78879. break;
  78880. }
  78881. Tracev((stderr, "inflate: codes ok\n"));
  78882. state->mode = LEN;
  78883. case LEN:
  78884. if (have >= 6 && left >= 258) {
  78885. RESTORE();
  78886. inflate_fast(strm, out);
  78887. LOAD();
  78888. break;
  78889. }
  78890. for (;;) {
  78891. thisx = state->lencode[BITS(state->lenbits)];
  78892. if ((unsigned)(thisx.bits) <= bits) break;
  78893. PULLBYTE();
  78894. }
  78895. if (thisx.op && (thisx.op & 0xf0) == 0) {
  78896. last = thisx;
  78897. for (;;) {
  78898. thisx = state->lencode[last.val +
  78899. (BITS(last.bits + last.op) >> last.bits)];
  78900. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78901. PULLBYTE();
  78902. }
  78903. DROPBITS(last.bits);
  78904. }
  78905. DROPBITS(thisx.bits);
  78906. state->length = (unsigned)thisx.val;
  78907. if ((int)(thisx.op) == 0) {
  78908. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78909. "inflate: literal '%c'\n" :
  78910. "inflate: literal 0x%02x\n", thisx.val));
  78911. state->mode = LIT;
  78912. break;
  78913. }
  78914. if (thisx.op & 32) {
  78915. Tracevv((stderr, "inflate: end of block\n"));
  78916. state->mode = TYPE;
  78917. break;
  78918. }
  78919. if (thisx.op & 64) {
  78920. strm->msg = (char *)"invalid literal/length code";
  78921. state->mode = BAD;
  78922. break;
  78923. }
  78924. state->extra = (unsigned)(thisx.op) & 15;
  78925. state->mode = LENEXT;
  78926. case LENEXT:
  78927. if (state->extra) {
  78928. NEEDBITS(state->extra);
  78929. state->length += BITS(state->extra);
  78930. DROPBITS(state->extra);
  78931. }
  78932. Tracevv((stderr, "inflate: length %u\n", state->length));
  78933. state->mode = DIST;
  78934. case DIST:
  78935. for (;;) {
  78936. thisx = state->distcode[BITS(state->distbits)];
  78937. if ((unsigned)(thisx.bits) <= bits) break;
  78938. PULLBYTE();
  78939. }
  78940. if ((thisx.op & 0xf0) == 0) {
  78941. last = thisx;
  78942. for (;;) {
  78943. thisx = state->distcode[last.val +
  78944. (BITS(last.bits + last.op) >> last.bits)];
  78945. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78946. PULLBYTE();
  78947. }
  78948. DROPBITS(last.bits);
  78949. }
  78950. DROPBITS(thisx.bits);
  78951. if (thisx.op & 64) {
  78952. strm->msg = (char *)"invalid distance code";
  78953. state->mode = BAD;
  78954. break;
  78955. }
  78956. state->offset = (unsigned)thisx.val;
  78957. state->extra = (unsigned)(thisx.op) & 15;
  78958. state->mode = DISTEXT;
  78959. case DISTEXT:
  78960. if (state->extra) {
  78961. NEEDBITS(state->extra);
  78962. state->offset += BITS(state->extra);
  78963. DROPBITS(state->extra);
  78964. }
  78965. #ifdef INFLATE_STRICT
  78966. if (state->offset > state->dmax) {
  78967. strm->msg = (char *)"invalid distance too far back";
  78968. state->mode = BAD;
  78969. break;
  78970. }
  78971. #endif
  78972. if (state->offset > state->whave + out - left) {
  78973. strm->msg = (char *)"invalid distance too far back";
  78974. state->mode = BAD;
  78975. break;
  78976. }
  78977. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  78978. state->mode = MATCH;
  78979. case MATCH:
  78980. if (left == 0) goto inf_leave;
  78981. copy = out - left;
  78982. if (state->offset > copy) { /* copy from window */
  78983. copy = state->offset - copy;
  78984. if (copy > state->write) {
  78985. copy -= state->write;
  78986. from = state->window + (state->wsize - copy);
  78987. }
  78988. else
  78989. from = state->window + (state->write - copy);
  78990. if (copy > state->length) copy = state->length;
  78991. }
  78992. else { /* copy from output */
  78993. from = put - state->offset;
  78994. copy = state->length;
  78995. }
  78996. if (copy > left) copy = left;
  78997. left -= copy;
  78998. state->length -= copy;
  78999. do {
  79000. *put++ = *from++;
  79001. } while (--copy);
  79002. if (state->length == 0) state->mode = LEN;
  79003. break;
  79004. case LIT:
  79005. if (left == 0) goto inf_leave;
  79006. *put++ = (unsigned char)(state->length);
  79007. left--;
  79008. state->mode = LEN;
  79009. break;
  79010. case CHECK:
  79011. if (state->wrap) {
  79012. NEEDBITS(32);
  79013. out -= left;
  79014. strm->total_out += out;
  79015. state->total += out;
  79016. if (out)
  79017. strm->adler = state->check =
  79018. UPDATE(state->check, put - out, out);
  79019. out = left;
  79020. if ((
  79021. #ifdef GUNZIP
  79022. state->flags ? hold :
  79023. #endif
  79024. REVERSE(hold)) != state->check) {
  79025. strm->msg = (char *)"incorrect data check";
  79026. state->mode = BAD;
  79027. break;
  79028. }
  79029. INITBITS();
  79030. Tracev((stderr, "inflate: check matches trailer\n"));
  79031. }
  79032. #ifdef GUNZIP
  79033. state->mode = LENGTH;
  79034. case LENGTH:
  79035. if (state->wrap && state->flags) {
  79036. NEEDBITS(32);
  79037. if (hold != (state->total & 0xffffffffUL)) {
  79038. strm->msg = (char *)"incorrect length check";
  79039. state->mode = BAD;
  79040. break;
  79041. }
  79042. INITBITS();
  79043. Tracev((stderr, "inflate: length matches trailer\n"));
  79044. }
  79045. #endif
  79046. state->mode = DONE;
  79047. case DONE:
  79048. ret = Z_STREAM_END;
  79049. goto inf_leave;
  79050. case BAD:
  79051. ret = Z_DATA_ERROR;
  79052. goto inf_leave;
  79053. case MEM:
  79054. return Z_MEM_ERROR;
  79055. case SYNC:
  79056. default:
  79057. return Z_STREAM_ERROR;
  79058. }
  79059. inf_leave:
  79060. RESTORE();
  79061. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  79062. if (updatewindow(strm, out)) {
  79063. state->mode = MEM;
  79064. return Z_MEM_ERROR;
  79065. }
  79066. in -= strm->avail_in;
  79067. out -= strm->avail_out;
  79068. strm->total_in += in;
  79069. strm->total_out += out;
  79070. state->total += out;
  79071. if (state->wrap && out)
  79072. strm->adler = state->check =
  79073. UPDATE(state->check, strm->next_out - out, out);
  79074. strm->data_type = state->bits + (state->last ? 64 : 0) +
  79075. (state->mode == TYPE ? 128 : 0);
  79076. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  79077. ret = Z_BUF_ERROR;
  79078. return ret;
  79079. }
  79080. int ZEXPORT inflateEnd (z_streamp strm)
  79081. {
  79082. struct inflate_state FAR *state;
  79083. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  79084. return Z_STREAM_ERROR;
  79085. state = (struct inflate_state FAR *)strm->state;
  79086. if (state->window != Z_NULL) ZFREE(strm, state->window);
  79087. ZFREE(strm, strm->state);
  79088. strm->state = Z_NULL;
  79089. Tracev((stderr, "inflate: end\n"));
  79090. return Z_OK;
  79091. }
  79092. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  79093. {
  79094. struct inflate_state FAR *state;
  79095. unsigned long id_;
  79096. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79097. state = (struct inflate_state FAR *)strm->state;
  79098. if (state->wrap != 0 && state->mode != DICT)
  79099. return Z_STREAM_ERROR;
  79100. if (state->mode == DICT) {
  79101. id_ = adler32(0L, Z_NULL, 0);
  79102. id_ = adler32(id_, dictionary, dictLength);
  79103. if (id_ != state->check)
  79104. return Z_DATA_ERROR;
  79105. }
  79106. if (updatewindow(strm, strm->avail_out)) {
  79107. state->mode = MEM;
  79108. return Z_MEM_ERROR;
  79109. }
  79110. if (dictLength > state->wsize) {
  79111. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  79112. state->wsize);
  79113. state->whave = state->wsize;
  79114. }
  79115. else {
  79116. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  79117. dictLength);
  79118. state->whave = dictLength;
  79119. }
  79120. state->havedict = 1;
  79121. Tracev((stderr, "inflate: dictionary set\n"));
  79122. return Z_OK;
  79123. }
  79124. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  79125. {
  79126. struct inflate_state FAR *state;
  79127. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79128. state = (struct inflate_state FAR *)strm->state;
  79129. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  79130. state->head = head;
  79131. head->done = 0;
  79132. return Z_OK;
  79133. }
  79134. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  79135. {
  79136. unsigned got;
  79137. unsigned next;
  79138. got = *have;
  79139. next = 0;
  79140. while (next < len && got < 4) {
  79141. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  79142. got++;
  79143. else if (buf[next])
  79144. got = 0;
  79145. else
  79146. got = 4 - got;
  79147. next++;
  79148. }
  79149. *have = got;
  79150. return next;
  79151. }
  79152. int ZEXPORT inflateSync (z_streamp strm)
  79153. {
  79154. unsigned len; /* number of bytes to look at or looked at */
  79155. unsigned long in, out; /* temporary to save total_in and total_out */
  79156. unsigned char buf[4]; /* to restore bit buffer to byte string */
  79157. struct inflate_state FAR *state;
  79158. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79159. state = (struct inflate_state FAR *)strm->state;
  79160. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  79161. if (state->mode != SYNC) {
  79162. state->mode = SYNC;
  79163. state->hold <<= state->bits & 7;
  79164. state->bits -= state->bits & 7;
  79165. len = 0;
  79166. while (state->bits >= 8) {
  79167. buf[len++] = (unsigned char)(state->hold);
  79168. state->hold >>= 8;
  79169. state->bits -= 8;
  79170. }
  79171. state->have = 0;
  79172. syncsearch(&(state->have), buf, len);
  79173. }
  79174. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  79175. strm->avail_in -= len;
  79176. strm->next_in += len;
  79177. strm->total_in += len;
  79178. if (state->have != 4) return Z_DATA_ERROR;
  79179. in = strm->total_in; out = strm->total_out;
  79180. inflateReset(strm);
  79181. strm->total_in = in; strm->total_out = out;
  79182. state->mode = TYPE;
  79183. return Z_OK;
  79184. }
  79185. int ZEXPORT inflateSyncPoint (z_streamp strm)
  79186. {
  79187. struct inflate_state FAR *state;
  79188. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79189. state = (struct inflate_state FAR *)strm->state;
  79190. return state->mode == STORED && state->bits == 0;
  79191. }
  79192. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  79193. {
  79194. struct inflate_state FAR *state;
  79195. struct inflate_state FAR *copy;
  79196. unsigned char FAR *window;
  79197. unsigned wsize;
  79198. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  79199. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  79200. return Z_STREAM_ERROR;
  79201. state = (struct inflate_state FAR *)source->state;
  79202. copy = (struct inflate_state FAR *)
  79203. ZALLOC(source, 1, sizeof(struct inflate_state));
  79204. if (copy == Z_NULL) return Z_MEM_ERROR;
  79205. window = Z_NULL;
  79206. if (state->window != Z_NULL) {
  79207. window = (unsigned char FAR *)
  79208. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  79209. if (window == Z_NULL) {
  79210. ZFREE(source, copy);
  79211. return Z_MEM_ERROR;
  79212. }
  79213. }
  79214. zmemcpy(dest, source, sizeof(z_stream));
  79215. zmemcpy(copy, state, sizeof(struct inflate_state));
  79216. if (state->lencode >= state->codes &&
  79217. state->lencode <= state->codes + ENOUGH - 1) {
  79218. copy->lencode = copy->codes + (state->lencode - state->codes);
  79219. copy->distcode = copy->codes + (state->distcode - state->codes);
  79220. }
  79221. copy->next = copy->codes + (state->next - state->codes);
  79222. if (window != Z_NULL) {
  79223. wsize = 1U << state->wbits;
  79224. zmemcpy(window, state->window, wsize);
  79225. }
  79226. copy->window = window;
  79227. dest->state = (struct internal_state FAR *)copy;
  79228. return Z_OK;
  79229. }
  79230. /*** End of inlined file: inflate.c ***/
  79231. /*** Start of inlined file: inftrees.c ***/
  79232. #define MAXBITS 15
  79233. const char inflate_copyright[] =
  79234. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  79235. int inflate_table (codetype type,
  79236. unsigned short FAR *lens,
  79237. unsigned codes,
  79238. code FAR * FAR *table,
  79239. unsigned FAR *bits,
  79240. unsigned short FAR *work)
  79241. {
  79242. unsigned len; /* a code's length in bits */
  79243. unsigned sym; /* index of code symbols */
  79244. unsigned min, max; /* minimum and maximum code lengths */
  79245. unsigned root; /* number of index bits for root table */
  79246. unsigned curr; /* number of index bits for current table */
  79247. unsigned drop; /* code bits to drop for sub-table */
  79248. int left; /* number of prefix codes available */
  79249. unsigned used; /* code entries in table used */
  79250. unsigned huff; /* Huffman code */
  79251. unsigned incr; /* for incrementing code, index */
  79252. unsigned fill; /* index for replicating entries */
  79253. unsigned low; /* low bits for current root entry */
  79254. unsigned mask; /* mask for low root bits */
  79255. code thisx; /* table entry for duplication */
  79256. code FAR *next; /* next available space in table */
  79257. const unsigned short FAR *base; /* base value table to use */
  79258. const unsigned short FAR *extra; /* extra bits table to use */
  79259. int end; /* use base and extra for symbol > end */
  79260. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  79261. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  79262. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  79263. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  79264. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  79265. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  79266. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  79267. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  79268. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  79269. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  79270. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  79271. 8193, 12289, 16385, 24577, 0, 0};
  79272. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  79273. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  79274. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  79275. 28, 28, 29, 29, 64, 64};
  79276. for (len = 0; len <= MAXBITS; len++)
  79277. count[len] = 0;
  79278. for (sym = 0; sym < codes; sym++)
  79279. count[lens[sym]]++;
  79280. root = *bits;
  79281. for (max = MAXBITS; max >= 1; max--)
  79282. if (count[max] != 0) break;
  79283. if (root > max) root = max;
  79284. if (max == 0) { /* no symbols to code at all */
  79285. thisx.op = (unsigned char)64; /* invalid code marker */
  79286. thisx.bits = (unsigned char)1;
  79287. thisx.val = (unsigned short)0;
  79288. *(*table)++ = thisx; /* make a table to force an error */
  79289. *(*table)++ = thisx;
  79290. *bits = 1;
  79291. return 0; /* no symbols, but wait for decoding to report error */
  79292. }
  79293. for (min = 1; min <= MAXBITS; min++)
  79294. if (count[min] != 0) break;
  79295. if (root < min) root = min;
  79296. left = 1;
  79297. for (len = 1; len <= MAXBITS; len++) {
  79298. left <<= 1;
  79299. left -= count[len];
  79300. if (left < 0) return -1; /* over-subscribed */
  79301. }
  79302. if (left > 0 && (type == CODES || max != 1))
  79303. return -1; /* incomplete set */
  79304. offs[1] = 0;
  79305. for (len = 1; len < MAXBITS; len++)
  79306. offs[len + 1] = offs[len] + count[len];
  79307. for (sym = 0; sym < codes; sym++)
  79308. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79309. switch (type) {
  79310. case CODES:
  79311. base = extra = work; /* dummy value--not used */
  79312. end = 19;
  79313. break;
  79314. case LENS:
  79315. base = lbase;
  79316. base -= 257;
  79317. extra = lext;
  79318. extra -= 257;
  79319. end = 256;
  79320. break;
  79321. default: /* DISTS */
  79322. base = dbase;
  79323. extra = dext;
  79324. end = -1;
  79325. }
  79326. huff = 0; /* starting code */
  79327. sym = 0; /* starting code symbol */
  79328. len = min; /* starting code length */
  79329. next = *table; /* current table to fill in */
  79330. curr = root; /* current table index bits */
  79331. drop = 0; /* current bits to drop from code for index */
  79332. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79333. used = 1U << root; /* use root table entries */
  79334. mask = used - 1; /* mask for comparing low */
  79335. if (type == LENS && used >= ENOUGH - MAXD)
  79336. return 1;
  79337. for (;;) {
  79338. thisx.bits = (unsigned char)(len - drop);
  79339. if ((int)(work[sym]) < end) {
  79340. thisx.op = (unsigned char)0;
  79341. thisx.val = work[sym];
  79342. }
  79343. else if ((int)(work[sym]) > end) {
  79344. thisx.op = (unsigned char)(extra[work[sym]]);
  79345. thisx.val = base[work[sym]];
  79346. }
  79347. else {
  79348. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79349. thisx.val = 0;
  79350. }
  79351. incr = 1U << (len - drop);
  79352. fill = 1U << curr;
  79353. min = fill; /* save offset to next table */
  79354. do {
  79355. fill -= incr;
  79356. next[(huff >> drop) + fill] = thisx;
  79357. } while (fill != 0);
  79358. incr = 1U << (len - 1);
  79359. while (huff & incr)
  79360. incr >>= 1;
  79361. if (incr != 0) {
  79362. huff &= incr - 1;
  79363. huff += incr;
  79364. }
  79365. else
  79366. huff = 0;
  79367. sym++;
  79368. if (--(count[len]) == 0) {
  79369. if (len == max) break;
  79370. len = lens[work[sym]];
  79371. }
  79372. if (len > root && (huff & mask) != low) {
  79373. if (drop == 0)
  79374. drop = root;
  79375. next += min; /* here min is 1 << curr */
  79376. curr = len - drop;
  79377. left = (int)(1 << curr);
  79378. while (curr + drop < max) {
  79379. left -= count[curr + drop];
  79380. if (left <= 0) break;
  79381. curr++;
  79382. left <<= 1;
  79383. }
  79384. used += 1U << curr;
  79385. if (type == LENS && used >= ENOUGH - MAXD)
  79386. return 1;
  79387. low = huff & mask;
  79388. (*table)[low].op = (unsigned char)curr;
  79389. (*table)[low].bits = (unsigned char)root;
  79390. (*table)[low].val = (unsigned short)(next - *table);
  79391. }
  79392. }
  79393. thisx.op = (unsigned char)64; /* invalid code marker */
  79394. thisx.bits = (unsigned char)(len - drop);
  79395. thisx.val = (unsigned short)0;
  79396. while (huff != 0) {
  79397. if (drop != 0 && (huff & mask) != low) {
  79398. drop = 0;
  79399. len = root;
  79400. next = *table;
  79401. thisx.bits = (unsigned char)len;
  79402. }
  79403. next[huff >> drop] = thisx;
  79404. incr = 1U << (len - 1);
  79405. while (huff & incr)
  79406. incr >>= 1;
  79407. if (incr != 0) {
  79408. huff &= incr - 1;
  79409. huff += incr;
  79410. }
  79411. else
  79412. huff = 0;
  79413. }
  79414. *table += used;
  79415. *bits = root;
  79416. return 0;
  79417. }
  79418. /*** End of inlined file: inftrees.c ***/
  79419. /*** Start of inlined file: trees.c ***/
  79420. #ifdef DEBUG
  79421. # include <ctype.h>
  79422. #endif
  79423. #define MAX_BL_BITS 7
  79424. #define END_BLOCK 256
  79425. #define REP_3_6 16
  79426. #define REPZ_3_10 17
  79427. #define REPZ_11_138 18
  79428. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79429. = {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};
  79430. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79431. = {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};
  79432. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79433. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79434. local const uch bl_order[BL_CODES]
  79435. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79436. #define Buf_size (8 * 2*sizeof(char))
  79437. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79438. #if defined(GEN_TREES_H) || !defined(STDC)
  79439. local ct_data static_ltree[L_CODES+2];
  79440. local ct_data static_dtree[D_CODES];
  79441. uch _dist_code[DIST_CODE_LEN];
  79442. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79443. local int base_length[LENGTH_CODES];
  79444. local int base_dist[D_CODES];
  79445. #else
  79446. /*** Start of inlined file: trees.h ***/
  79447. local const ct_data static_ltree[L_CODES+2] = {
  79448. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79449. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79450. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79451. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79452. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79453. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79454. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79455. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79456. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79457. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79458. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79459. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79460. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79461. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79462. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79463. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79464. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79465. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79466. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79467. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79468. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79469. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79470. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79471. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79472. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79473. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79474. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79475. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79476. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79477. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79478. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79479. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79480. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79481. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79482. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79483. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79484. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79485. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79486. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79487. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79488. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79489. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79490. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79491. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79492. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79493. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79494. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79495. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79496. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79497. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79498. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79499. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79500. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79501. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79502. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79503. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79504. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79505. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79506. };
  79507. local const ct_data static_dtree[D_CODES] = {
  79508. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79509. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79510. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79511. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79512. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79513. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79514. };
  79515. const uch _dist_code[DIST_CODE_LEN] = {
  79516. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79517. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79518. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79519. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79520. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79521. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79522. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79523. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79524. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79525. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79526. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79527. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79528. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79529. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79530. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79531. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79532. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79533. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79534. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79535. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79536. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79537. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79538. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79539. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79540. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79541. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79542. };
  79543. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79544. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79545. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79546. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79547. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79548. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79549. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79550. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79551. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79552. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79553. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79554. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79555. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79556. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79557. };
  79558. local const int base_length[LENGTH_CODES] = {
  79559. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79560. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79561. };
  79562. local const int base_dist[D_CODES] = {
  79563. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79564. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79565. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79566. };
  79567. /*** End of inlined file: trees.h ***/
  79568. #endif /* GEN_TREES_H */
  79569. struct static_tree_desc_s {
  79570. const ct_data *static_tree; /* static tree or NULL */
  79571. const intf *extra_bits; /* extra bits for each code or NULL */
  79572. int extra_base; /* base index for extra_bits */
  79573. int elems; /* max number of elements in the tree */
  79574. int max_length; /* max bit length for the codes */
  79575. };
  79576. local static_tree_desc static_l_desc =
  79577. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79578. local static_tree_desc static_d_desc =
  79579. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79580. local static_tree_desc static_bl_desc =
  79581. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79582. local void tr_static_init OF((void));
  79583. local void init_block OF((deflate_state *s));
  79584. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79585. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79586. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79587. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79588. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79589. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79590. local int build_bl_tree OF((deflate_state *s));
  79591. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79592. int blcodes));
  79593. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79594. ct_data *dtree));
  79595. local void set_data_type OF((deflate_state *s));
  79596. local unsigned bi_reverse OF((unsigned value, int length));
  79597. local void bi_windup OF((deflate_state *s));
  79598. local void bi_flush OF((deflate_state *s));
  79599. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79600. int header));
  79601. #ifdef GEN_TREES_H
  79602. local void gen_trees_header OF((void));
  79603. #endif
  79604. #ifndef DEBUG
  79605. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79606. #else /* DEBUG */
  79607. # define send_code(s, c, tree) \
  79608. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79609. send_bits(s, tree[c].Code, tree[c].Len); }
  79610. #endif
  79611. #define put_short(s, w) { \
  79612. put_byte(s, (uch)((w) & 0xff)); \
  79613. put_byte(s, (uch)((ush)(w) >> 8)); \
  79614. }
  79615. #ifdef DEBUG
  79616. local void send_bits OF((deflate_state *s, int value, int length));
  79617. local void send_bits (deflate_state *s, int value, int length)
  79618. {
  79619. Tracevv((stderr," l %2d v %4x ", length, value));
  79620. Assert(length > 0 && length <= 15, "invalid length");
  79621. s->bits_sent += (ulg)length;
  79622. if (s->bi_valid > (int)Buf_size - length) {
  79623. s->bi_buf |= (value << s->bi_valid);
  79624. put_short(s, s->bi_buf);
  79625. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79626. s->bi_valid += length - Buf_size;
  79627. } else {
  79628. s->bi_buf |= value << s->bi_valid;
  79629. s->bi_valid += length;
  79630. }
  79631. }
  79632. #else /* !DEBUG */
  79633. #define send_bits(s, value, length) \
  79634. { int len = length;\
  79635. if (s->bi_valid > (int)Buf_size - len) {\
  79636. int val = value;\
  79637. s->bi_buf |= (val << s->bi_valid);\
  79638. put_short(s, s->bi_buf);\
  79639. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79640. s->bi_valid += len - Buf_size;\
  79641. } else {\
  79642. s->bi_buf |= (value) << s->bi_valid;\
  79643. s->bi_valid += len;\
  79644. }\
  79645. }
  79646. #endif /* DEBUG */
  79647. local void tr_static_init()
  79648. {
  79649. #if defined(GEN_TREES_H) || !defined(STDC)
  79650. static int static_init_done = 0;
  79651. int n; /* iterates over tree elements */
  79652. int bits; /* bit counter */
  79653. int length; /* length value */
  79654. int code; /* code value */
  79655. int dist; /* distance index */
  79656. ush bl_count[MAX_BITS+1];
  79657. if (static_init_done) return;
  79658. static_l_desc.static_tree = static_ltree;
  79659. static_l_desc.extra_bits = extra_lbits;
  79660. static_d_desc.static_tree = static_dtree;
  79661. static_d_desc.extra_bits = extra_dbits;
  79662. static_bl_desc.extra_bits = extra_blbits;
  79663. length = 0;
  79664. for (code = 0; code < LENGTH_CODES-1; code++) {
  79665. base_length[code] = length;
  79666. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79667. _length_code[length++] = (uch)code;
  79668. }
  79669. }
  79670. Assert (length == 256, "tr_static_init: length != 256");
  79671. _length_code[length-1] = (uch)code;
  79672. dist = 0;
  79673. for (code = 0 ; code < 16; code++) {
  79674. base_dist[code] = dist;
  79675. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  79676. _dist_code[dist++] = (uch)code;
  79677. }
  79678. }
  79679. Assert (dist == 256, "tr_static_init: dist != 256");
  79680. dist >>= 7; /* from now on, all distances are divided by 128 */
  79681. for ( ; code < D_CODES; code++) {
  79682. base_dist[code] = dist << 7;
  79683. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  79684. _dist_code[256 + dist++] = (uch)code;
  79685. }
  79686. }
  79687. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  79688. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  79689. n = 0;
  79690. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  79691. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  79692. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  79693. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  79694. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  79695. for (n = 0; n < D_CODES; n++) {
  79696. static_dtree[n].Len = 5;
  79697. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  79698. }
  79699. static_init_done = 1;
  79700. # ifdef GEN_TREES_H
  79701. gen_trees_header();
  79702. # endif
  79703. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  79704. }
  79705. #ifdef GEN_TREES_H
  79706. # ifndef DEBUG
  79707. # include <stdio.h>
  79708. # endif
  79709. # define SEPARATOR(i, last, width) \
  79710. ((i) == (last)? "\n};\n\n" : \
  79711. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  79712. void gen_trees_header()
  79713. {
  79714. FILE *header = fopen("trees.h", "w");
  79715. int i;
  79716. Assert (header != NULL, "Can't open trees.h");
  79717. fprintf(header,
  79718. "/* header created automatically with -DGEN_TREES_H */\n\n");
  79719. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  79720. for (i = 0; i < L_CODES+2; i++) {
  79721. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  79722. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  79723. }
  79724. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  79725. for (i = 0; i < D_CODES; i++) {
  79726. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  79727. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  79728. }
  79729. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  79730. for (i = 0; i < DIST_CODE_LEN; i++) {
  79731. fprintf(header, "%2u%s", _dist_code[i],
  79732. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  79733. }
  79734. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  79735. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  79736. fprintf(header, "%2u%s", _length_code[i],
  79737. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  79738. }
  79739. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  79740. for (i = 0; i < LENGTH_CODES; i++) {
  79741. fprintf(header, "%1u%s", base_length[i],
  79742. SEPARATOR(i, LENGTH_CODES-1, 20));
  79743. }
  79744. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  79745. for (i = 0; i < D_CODES; i++) {
  79746. fprintf(header, "%5u%s", base_dist[i],
  79747. SEPARATOR(i, D_CODES-1, 10));
  79748. }
  79749. fclose(header);
  79750. }
  79751. #endif /* GEN_TREES_H */
  79752. void _tr_init(deflate_state *s)
  79753. {
  79754. tr_static_init();
  79755. s->l_desc.dyn_tree = s->dyn_ltree;
  79756. s->l_desc.stat_desc = &static_l_desc;
  79757. s->d_desc.dyn_tree = s->dyn_dtree;
  79758. s->d_desc.stat_desc = &static_d_desc;
  79759. s->bl_desc.dyn_tree = s->bl_tree;
  79760. s->bl_desc.stat_desc = &static_bl_desc;
  79761. s->bi_buf = 0;
  79762. s->bi_valid = 0;
  79763. s->last_eob_len = 8; /* enough lookahead for inflate */
  79764. #ifdef DEBUG
  79765. s->compressed_len = 0L;
  79766. s->bits_sent = 0L;
  79767. #endif
  79768. init_block(s);
  79769. }
  79770. local void init_block (deflate_state *s)
  79771. {
  79772. int n; /* iterates over tree elements */
  79773. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  79774. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  79775. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  79776. s->dyn_ltree[END_BLOCK].Freq = 1;
  79777. s->opt_len = s->static_len = 0L;
  79778. s->last_lit = s->matches = 0;
  79779. }
  79780. #define SMALLEST 1
  79781. #define pqremove(s, tree, top) \
  79782. {\
  79783. top = s->heap[SMALLEST]; \
  79784. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  79785. pqdownheap(s, tree, SMALLEST); \
  79786. }
  79787. #define smaller(tree, n, m, depth) \
  79788. (tree[n].Freq < tree[m].Freq || \
  79789. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  79790. local void pqdownheap (deflate_state *s,
  79791. ct_data *tree, /* the tree to restore */
  79792. int k) /* node to move down */
  79793. {
  79794. int v = s->heap[k];
  79795. int j = k << 1; /* left son of k */
  79796. while (j <= s->heap_len) {
  79797. if (j < s->heap_len &&
  79798. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  79799. j++;
  79800. }
  79801. if (smaller(tree, v, s->heap[j], s->depth)) break;
  79802. s->heap[k] = s->heap[j]; k = j;
  79803. j <<= 1;
  79804. }
  79805. s->heap[k] = v;
  79806. }
  79807. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  79808. {
  79809. ct_data *tree = desc->dyn_tree;
  79810. int max_code = desc->max_code;
  79811. const ct_data *stree = desc->stat_desc->static_tree;
  79812. const intf *extra = desc->stat_desc->extra_bits;
  79813. int base = desc->stat_desc->extra_base;
  79814. int max_length = desc->stat_desc->max_length;
  79815. int h; /* heap index */
  79816. int n, m; /* iterate over the tree elements */
  79817. int bits; /* bit length */
  79818. int xbits; /* extra bits */
  79819. ush f; /* frequency */
  79820. int overflow = 0; /* number of elements with bit length too large */
  79821. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  79822. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  79823. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  79824. n = s->heap[h];
  79825. bits = tree[tree[n].Dad].Len + 1;
  79826. if (bits > max_length) bits = max_length, overflow++;
  79827. tree[n].Len = (ush)bits;
  79828. if (n > max_code) continue; /* not a leaf node */
  79829. s->bl_count[bits]++;
  79830. xbits = 0;
  79831. if (n >= base) xbits = extra[n-base];
  79832. f = tree[n].Freq;
  79833. s->opt_len += (ulg)f * (bits + xbits);
  79834. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  79835. }
  79836. if (overflow == 0) return;
  79837. Trace((stderr,"\nbit length overflow\n"));
  79838. do {
  79839. bits = max_length-1;
  79840. while (s->bl_count[bits] == 0) bits--;
  79841. s->bl_count[bits]--; /* move one leaf down the tree */
  79842. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  79843. s->bl_count[max_length]--;
  79844. overflow -= 2;
  79845. } while (overflow > 0);
  79846. for (bits = max_length; bits != 0; bits--) {
  79847. n = s->bl_count[bits];
  79848. while (n != 0) {
  79849. m = s->heap[--h];
  79850. if (m > max_code) continue;
  79851. if ((unsigned) tree[m].Len != (unsigned) bits) {
  79852. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  79853. s->opt_len += ((long)bits - (long)tree[m].Len)
  79854. *(long)tree[m].Freq;
  79855. tree[m].Len = (ush)bits;
  79856. }
  79857. n--;
  79858. }
  79859. }
  79860. }
  79861. local void gen_codes (ct_data *tree, /* the tree to decorate */
  79862. int max_code, /* largest code with non zero frequency */
  79863. ushf *bl_count) /* number of codes at each bit length */
  79864. {
  79865. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  79866. ush code = 0; /* running code value */
  79867. int bits; /* bit index */
  79868. int n; /* code index */
  79869. for (bits = 1; bits <= MAX_BITS; bits++) {
  79870. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  79871. }
  79872. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  79873. "inconsistent bit counts");
  79874. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  79875. for (n = 0; n <= max_code; n++) {
  79876. int len = tree[n].Len;
  79877. if (len == 0) continue;
  79878. tree[n].Code = bi_reverse(next_code[len]++, len);
  79879. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  79880. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  79881. }
  79882. }
  79883. local void build_tree (deflate_state *s,
  79884. tree_desc *desc) /* the tree descriptor */
  79885. {
  79886. ct_data *tree = desc->dyn_tree;
  79887. const ct_data *stree = desc->stat_desc->static_tree;
  79888. int elems = desc->stat_desc->elems;
  79889. int n, m; /* iterate over heap elements */
  79890. int max_code = -1; /* largest code with non zero frequency */
  79891. int node; /* new node being created */
  79892. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  79893. for (n = 0; n < elems; n++) {
  79894. if (tree[n].Freq != 0) {
  79895. s->heap[++(s->heap_len)] = max_code = n;
  79896. s->depth[n] = 0;
  79897. } else {
  79898. tree[n].Len = 0;
  79899. }
  79900. }
  79901. while (s->heap_len < 2) {
  79902. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  79903. tree[node].Freq = 1;
  79904. s->depth[node] = 0;
  79905. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  79906. }
  79907. desc->max_code = max_code;
  79908. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  79909. node = elems; /* next internal node of the tree */
  79910. do {
  79911. pqremove(s, tree, n); /* n = node of least frequency */
  79912. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  79913. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  79914. s->heap[--(s->heap_max)] = m;
  79915. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  79916. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  79917. s->depth[n] : s->depth[m]) + 1);
  79918. tree[n].Dad = tree[m].Dad = (ush)node;
  79919. #ifdef DUMP_BL_TREE
  79920. if (tree == s->bl_tree) {
  79921. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  79922. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  79923. }
  79924. #endif
  79925. s->heap[SMALLEST] = node++;
  79926. pqdownheap(s, tree, SMALLEST);
  79927. } while (s->heap_len >= 2);
  79928. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  79929. gen_bitlen(s, (tree_desc *)desc);
  79930. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  79931. }
  79932. local void scan_tree (deflate_state *s,
  79933. ct_data *tree, /* the tree to be scanned */
  79934. int max_code) /* and its largest code of non zero frequency */
  79935. {
  79936. int n; /* iterates over all tree elements */
  79937. int prevlen = -1; /* last emitted length */
  79938. int curlen; /* length of current code */
  79939. int nextlen = tree[0].Len; /* length of next code */
  79940. int count = 0; /* repeat count of the current code */
  79941. int max_count = 7; /* max repeat count */
  79942. int min_count = 4; /* min repeat count */
  79943. if (nextlen == 0) max_count = 138, min_count = 3;
  79944. tree[max_code+1].Len = (ush)0xffff; /* guard */
  79945. for (n = 0; n <= max_code; n++) {
  79946. curlen = nextlen; nextlen = tree[n+1].Len;
  79947. if (++count < max_count && curlen == nextlen) {
  79948. continue;
  79949. } else if (count < min_count) {
  79950. s->bl_tree[curlen].Freq += count;
  79951. } else if (curlen != 0) {
  79952. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  79953. s->bl_tree[REP_3_6].Freq++;
  79954. } else if (count <= 10) {
  79955. s->bl_tree[REPZ_3_10].Freq++;
  79956. } else {
  79957. s->bl_tree[REPZ_11_138].Freq++;
  79958. }
  79959. count = 0; prevlen = curlen;
  79960. if (nextlen == 0) {
  79961. max_count = 138, min_count = 3;
  79962. } else if (curlen == nextlen) {
  79963. max_count = 6, min_count = 3;
  79964. } else {
  79965. max_count = 7, min_count = 4;
  79966. }
  79967. }
  79968. }
  79969. local void send_tree (deflate_state *s,
  79970. ct_data *tree, /* the tree to be scanned */
  79971. int max_code) /* and its largest code of non zero frequency */
  79972. {
  79973. int n; /* iterates over all tree elements */
  79974. int prevlen = -1; /* last emitted length */
  79975. int curlen; /* length of current code */
  79976. int nextlen = tree[0].Len; /* length of next code */
  79977. int count = 0; /* repeat count of the current code */
  79978. int max_count = 7; /* max repeat count */
  79979. int min_count = 4; /* min repeat count */
  79980. /* guard already set */
  79981. if (nextlen == 0) max_count = 138, min_count = 3;
  79982. for (n = 0; n <= max_code; n++) {
  79983. curlen = nextlen; nextlen = tree[n+1].Len;
  79984. if (++count < max_count && curlen == nextlen) {
  79985. continue;
  79986. } else if (count < min_count) {
  79987. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  79988. } else if (curlen != 0) {
  79989. if (curlen != prevlen) {
  79990. send_code(s, curlen, s->bl_tree); count--;
  79991. }
  79992. Assert(count >= 3 && count <= 6, " 3_6?");
  79993. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  79994. } else if (count <= 10) {
  79995. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  79996. } else {
  79997. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  79998. }
  79999. count = 0; prevlen = curlen;
  80000. if (nextlen == 0) {
  80001. max_count = 138, min_count = 3;
  80002. } else if (curlen == nextlen) {
  80003. max_count = 6, min_count = 3;
  80004. } else {
  80005. max_count = 7, min_count = 4;
  80006. }
  80007. }
  80008. }
  80009. local int build_bl_tree (deflate_state *s)
  80010. {
  80011. int max_blindex; /* index of last bit length code of non zero freq */
  80012. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  80013. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  80014. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  80015. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  80016. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  80017. }
  80018. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  80019. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  80020. s->opt_len, s->static_len));
  80021. return max_blindex;
  80022. }
  80023. local void send_all_trees (deflate_state *s,
  80024. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  80025. {
  80026. int rank; /* index in bl_order */
  80027. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  80028. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  80029. "too many codes");
  80030. Tracev((stderr, "\nbl counts: "));
  80031. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  80032. send_bits(s, dcodes-1, 5);
  80033. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  80034. for (rank = 0; rank < blcodes; rank++) {
  80035. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  80036. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  80037. }
  80038. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  80039. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  80040. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  80041. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  80042. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  80043. }
  80044. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  80045. {
  80046. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  80047. #ifdef DEBUG
  80048. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  80049. s->compressed_len += (stored_len + 4) << 3;
  80050. #endif
  80051. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  80052. }
  80053. void _tr_align (deflate_state *s)
  80054. {
  80055. send_bits(s, STATIC_TREES<<1, 3);
  80056. send_code(s, END_BLOCK, static_ltree);
  80057. #ifdef DEBUG
  80058. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  80059. #endif
  80060. bi_flush(s);
  80061. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  80062. send_bits(s, STATIC_TREES<<1, 3);
  80063. send_code(s, END_BLOCK, static_ltree);
  80064. #ifdef DEBUG
  80065. s->compressed_len += 10L;
  80066. #endif
  80067. bi_flush(s);
  80068. }
  80069. s->last_eob_len = 7;
  80070. }
  80071. void _tr_flush_block (deflate_state *s,
  80072. charf *buf, /* input block, or NULL if too old */
  80073. ulg stored_len, /* length of input block */
  80074. int eof) /* true if this is the last block for a file */
  80075. {
  80076. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  80077. int max_blindex = 0; /* index of last bit length code of non zero freq */
  80078. if (s->level > 0) {
  80079. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  80080. set_data_type(s);
  80081. build_tree(s, (tree_desc *)(&(s->l_desc)));
  80082. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  80083. s->static_len));
  80084. build_tree(s, (tree_desc *)(&(s->d_desc)));
  80085. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  80086. s->static_len));
  80087. max_blindex = build_bl_tree(s);
  80088. opt_lenb = (s->opt_len+3+7)>>3;
  80089. static_lenb = (s->static_len+3+7)>>3;
  80090. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  80091. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  80092. s->last_lit));
  80093. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  80094. } else {
  80095. Assert(buf != (char*)0, "lost buf");
  80096. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  80097. }
  80098. #ifdef FORCE_STORED
  80099. if (buf != (char*)0) { /* force stored block */
  80100. #else
  80101. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  80102. #endif
  80103. _tr_stored_block(s, buf, stored_len, eof);
  80104. #ifdef FORCE_STATIC
  80105. } else if (static_lenb >= 0) { /* force static trees */
  80106. #else
  80107. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  80108. #endif
  80109. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  80110. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  80111. #ifdef DEBUG
  80112. s->compressed_len += 3 + s->static_len;
  80113. #endif
  80114. } else {
  80115. send_bits(s, (DYN_TREES<<1)+eof, 3);
  80116. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  80117. max_blindex+1);
  80118. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  80119. #ifdef DEBUG
  80120. s->compressed_len += 3 + s->opt_len;
  80121. #endif
  80122. }
  80123. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  80124. init_block(s);
  80125. if (eof) {
  80126. bi_windup(s);
  80127. #ifdef DEBUG
  80128. s->compressed_len += 7; /* align on byte boundary */
  80129. #endif
  80130. }
  80131. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  80132. s->compressed_len-7*eof));
  80133. }
  80134. int _tr_tally (deflate_state *s,
  80135. unsigned dist, /* distance of matched string */
  80136. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  80137. {
  80138. s->d_buf[s->last_lit] = (ush)dist;
  80139. s->l_buf[s->last_lit++] = (uch)lc;
  80140. if (dist == 0) {
  80141. s->dyn_ltree[lc].Freq++;
  80142. } else {
  80143. s->matches++;
  80144. dist--; /* dist = match distance - 1 */
  80145. Assert((ush)dist < (ush)MAX_DIST(s) &&
  80146. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  80147. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  80148. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  80149. s->dyn_dtree[d_code(dist)].Freq++;
  80150. }
  80151. #ifdef TRUNCATE_BLOCK
  80152. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  80153. ulg out_length = (ulg)s->last_lit*8L;
  80154. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  80155. int dcode;
  80156. for (dcode = 0; dcode < D_CODES; dcode++) {
  80157. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  80158. (5L+extra_dbits[dcode]);
  80159. }
  80160. out_length >>= 3;
  80161. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  80162. s->last_lit, in_length, out_length,
  80163. 100L - out_length*100L/in_length));
  80164. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  80165. }
  80166. #endif
  80167. return (s->last_lit == s->lit_bufsize-1);
  80168. }
  80169. local void compress_block (deflate_state *s,
  80170. ct_data *ltree, /* literal tree */
  80171. ct_data *dtree) /* distance tree */
  80172. {
  80173. unsigned dist; /* distance of matched string */
  80174. int lc; /* match length or unmatched char (if dist == 0) */
  80175. unsigned lx = 0; /* running index in l_buf */
  80176. unsigned code; /* the code to send */
  80177. int extra; /* number of extra bits to send */
  80178. if (s->last_lit != 0) do {
  80179. dist = s->d_buf[lx];
  80180. lc = s->l_buf[lx++];
  80181. if (dist == 0) {
  80182. send_code(s, lc, ltree); /* send a literal byte */
  80183. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  80184. } else {
  80185. code = _length_code[lc];
  80186. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  80187. extra = extra_lbits[code];
  80188. if (extra != 0) {
  80189. lc -= base_length[code];
  80190. send_bits(s, lc, extra); /* send the extra length bits */
  80191. }
  80192. dist--; /* dist is now the match distance - 1 */
  80193. code = d_code(dist);
  80194. Assert (code < D_CODES, "bad d_code");
  80195. send_code(s, code, dtree); /* send the distance code */
  80196. extra = extra_dbits[code];
  80197. if (extra != 0) {
  80198. dist -= base_dist[code];
  80199. send_bits(s, dist, extra); /* send the extra distance bits */
  80200. }
  80201. } /* literal or match pair ? */
  80202. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  80203. "pendingBuf overflow");
  80204. } while (lx < s->last_lit);
  80205. send_code(s, END_BLOCK, ltree);
  80206. s->last_eob_len = ltree[END_BLOCK].Len;
  80207. }
  80208. local void set_data_type (deflate_state *s)
  80209. {
  80210. int n;
  80211. for (n = 0; n < 9; n++)
  80212. if (s->dyn_ltree[n].Freq != 0)
  80213. break;
  80214. if (n == 9)
  80215. for (n = 14; n < 32; n++)
  80216. if (s->dyn_ltree[n].Freq != 0)
  80217. break;
  80218. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  80219. }
  80220. local unsigned bi_reverse (unsigned code, int len)
  80221. {
  80222. register unsigned res = 0;
  80223. do {
  80224. res |= code & 1;
  80225. code >>= 1, res <<= 1;
  80226. } while (--len > 0);
  80227. return res >> 1;
  80228. }
  80229. local void bi_flush (deflate_state *s)
  80230. {
  80231. if (s->bi_valid == 16) {
  80232. put_short(s, s->bi_buf);
  80233. s->bi_buf = 0;
  80234. s->bi_valid = 0;
  80235. } else if (s->bi_valid >= 8) {
  80236. put_byte(s, (Byte)s->bi_buf);
  80237. s->bi_buf >>= 8;
  80238. s->bi_valid -= 8;
  80239. }
  80240. }
  80241. local void bi_windup (deflate_state *s)
  80242. {
  80243. if (s->bi_valid > 8) {
  80244. put_short(s, s->bi_buf);
  80245. } else if (s->bi_valid > 0) {
  80246. put_byte(s, (Byte)s->bi_buf);
  80247. }
  80248. s->bi_buf = 0;
  80249. s->bi_valid = 0;
  80250. #ifdef DEBUG
  80251. s->bits_sent = (s->bits_sent+7) & ~7;
  80252. #endif
  80253. }
  80254. local void copy_block(deflate_state *s,
  80255. charf *buf, /* the input data */
  80256. unsigned len, /* its length */
  80257. int header) /* true if block header must be written */
  80258. {
  80259. bi_windup(s); /* align on byte boundary */
  80260. s->last_eob_len = 8; /* enough lookahead for inflate */
  80261. if (header) {
  80262. put_short(s, (ush)len);
  80263. put_short(s, (ush)~len);
  80264. #ifdef DEBUG
  80265. s->bits_sent += 2*16;
  80266. #endif
  80267. }
  80268. #ifdef DEBUG
  80269. s->bits_sent += (ulg)len<<3;
  80270. #endif
  80271. while (len--) {
  80272. put_byte(s, *buf++);
  80273. }
  80274. }
  80275. /*** End of inlined file: trees.c ***/
  80276. /*** Start of inlined file: zutil.c ***/
  80277. #ifndef NO_DUMMY_DECL
  80278. struct internal_state {int dummy;}; /* for buggy compilers */
  80279. #endif
  80280. const char * const z_errmsg[10] = {
  80281. "need dictionary", /* Z_NEED_DICT 2 */
  80282. "stream end", /* Z_STREAM_END 1 */
  80283. "", /* Z_OK 0 */
  80284. "file error", /* Z_ERRNO (-1) */
  80285. "stream error", /* Z_STREAM_ERROR (-2) */
  80286. "data error", /* Z_DATA_ERROR (-3) */
  80287. "insufficient memory", /* Z_MEM_ERROR (-4) */
  80288. "buffer error", /* Z_BUF_ERROR (-5) */
  80289. "incompatible version",/* Z_VERSION_ERROR (-6) */
  80290. ""};
  80291. #ifdef DEBUG
  80292. # ifndef verbose
  80293. # define verbose 0
  80294. # endif
  80295. int z_verbose = verbose;
  80296. void z_error (const char *m)
  80297. {
  80298. fprintf(stderr, "%s\n", m);
  80299. exit(1);
  80300. }
  80301. #endif
  80302. const char * ZEXPORT zError(int err)
  80303. {
  80304. return ERR_MSG(err);
  80305. }
  80306. #if defined(_WIN32_WCE)
  80307. int errno = 0;
  80308. #endif
  80309. #ifndef HAVE_MEMCPY
  80310. void zmemcpy(dest, source, len)
  80311. Bytef* dest;
  80312. const Bytef* source;
  80313. uInt len;
  80314. {
  80315. if (len == 0) return;
  80316. do {
  80317. *dest++ = *source++; /* ??? to be unrolled */
  80318. } while (--len != 0);
  80319. }
  80320. int zmemcmp(s1, s2, len)
  80321. const Bytef* s1;
  80322. const Bytef* s2;
  80323. uInt len;
  80324. {
  80325. uInt j;
  80326. for (j = 0; j < len; j++) {
  80327. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  80328. }
  80329. return 0;
  80330. }
  80331. void zmemzero(dest, len)
  80332. Bytef* dest;
  80333. uInt len;
  80334. {
  80335. if (len == 0) return;
  80336. do {
  80337. *dest++ = 0; /* ??? to be unrolled */
  80338. } while (--len != 0);
  80339. }
  80340. #endif
  80341. #ifdef SYS16BIT
  80342. #ifdef __TURBOC__
  80343. # define MY_ZCALLOC
  80344. #define MAX_PTR 10
  80345. local int next_ptr = 0;
  80346. typedef struct ptr_table_s {
  80347. voidpf org_ptr;
  80348. voidpf new_ptr;
  80349. } ptr_table;
  80350. local ptr_table table[MAX_PTR];
  80351. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80352. {
  80353. voidpf buf = opaque; /* just to make some compilers happy */
  80354. ulg bsize = (ulg)items*size;
  80355. if (bsize < 65520L) {
  80356. buf = farmalloc(bsize);
  80357. if (*(ush*)&buf != 0) return buf;
  80358. } else {
  80359. buf = farmalloc(bsize + 16L);
  80360. }
  80361. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80362. table[next_ptr].org_ptr = buf;
  80363. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80364. *(ush*)&buf = 0;
  80365. table[next_ptr++].new_ptr = buf;
  80366. return buf;
  80367. }
  80368. void zcfree (voidpf opaque, voidpf ptr)
  80369. {
  80370. int n;
  80371. if (*(ush*)&ptr != 0) { /* object < 64K */
  80372. farfree(ptr);
  80373. return;
  80374. }
  80375. for (n = 0; n < next_ptr; n++) {
  80376. if (ptr != table[n].new_ptr) continue;
  80377. farfree(table[n].org_ptr);
  80378. while (++n < next_ptr) {
  80379. table[n-1] = table[n];
  80380. }
  80381. next_ptr--;
  80382. return;
  80383. }
  80384. ptr = opaque; /* just to make some compilers happy */
  80385. Assert(0, "zcfree: ptr not found");
  80386. }
  80387. #endif /* __TURBOC__ */
  80388. #ifdef M_I86
  80389. # define MY_ZCALLOC
  80390. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  80391. # define _halloc halloc
  80392. # define _hfree hfree
  80393. #endif
  80394. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80395. {
  80396. if (opaque) opaque = 0; /* to make compiler happy */
  80397. return _halloc((long)items, size);
  80398. }
  80399. void zcfree (voidpf opaque, voidpf ptr)
  80400. {
  80401. if (opaque) opaque = 0; /* to make compiler happy */
  80402. _hfree(ptr);
  80403. }
  80404. #endif /* M_I86 */
  80405. #endif /* SYS16BIT */
  80406. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  80407. #ifndef STDC
  80408. extern voidp malloc OF((uInt size));
  80409. extern voidp calloc OF((uInt items, uInt size));
  80410. extern void free OF((voidpf ptr));
  80411. #endif
  80412. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80413. {
  80414. if (opaque) items += size - size; /* make compiler happy */
  80415. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80416. (voidpf)calloc(items, size);
  80417. }
  80418. void zcfree (voidpf opaque, voidpf ptr)
  80419. {
  80420. free(ptr);
  80421. if (opaque) return; /* make compiler happy */
  80422. }
  80423. #endif /* MY_ZCALLOC */
  80424. /*** End of inlined file: zutil.c ***/
  80425. #undef Byte
  80426. }
  80427. #else
  80428. #include <zlib.h>
  80429. #endif
  80430. }
  80431. #if JUCE_MSVC
  80432. #pragma warning (pop)
  80433. #endif
  80434. BEGIN_JUCE_NAMESPACE
  80435. using namespace zlibNamespace;
  80436. // internal helper object that holds the zlib structures so they don't have to be
  80437. // included publicly.
  80438. class GZIPDecompressHelper
  80439. {
  80440. public:
  80441. GZIPDecompressHelper (const bool noWrap) throw()
  80442. : data (0),
  80443. dataSize (0),
  80444. finished (true),
  80445. needsDictionary (false),
  80446. error (true),
  80447. streamIsValid (false)
  80448. {
  80449. zerostruct (stream);
  80450. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80451. finished = error = ! streamIsValid;
  80452. }
  80453. ~GZIPDecompressHelper() throw()
  80454. {
  80455. if (streamIsValid)
  80456. inflateEnd (&stream);
  80457. }
  80458. bool needsInput() const throw() { return dataSize <= 0; }
  80459. void setInput (uint8* const data_, const int size) throw()
  80460. {
  80461. data = data_;
  80462. dataSize = size;
  80463. }
  80464. int doNextBlock (uint8* const dest, const int destSize) throw()
  80465. {
  80466. if (streamIsValid && data != 0 && ! finished)
  80467. {
  80468. stream.next_in = data;
  80469. stream.next_out = dest;
  80470. stream.avail_in = dataSize;
  80471. stream.avail_out = destSize;
  80472. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80473. {
  80474. case Z_STREAM_END:
  80475. finished = true;
  80476. // deliberate fall-through
  80477. case Z_OK:
  80478. data += dataSize - stream.avail_in;
  80479. dataSize = stream.avail_in;
  80480. return destSize - stream.avail_out;
  80481. case Z_NEED_DICT:
  80482. needsDictionary = true;
  80483. data += dataSize - stream.avail_in;
  80484. dataSize = stream.avail_in;
  80485. break;
  80486. case Z_DATA_ERROR:
  80487. case Z_MEM_ERROR:
  80488. error = true;
  80489. default:
  80490. break;
  80491. }
  80492. }
  80493. return 0;
  80494. }
  80495. private:
  80496. z_stream stream;
  80497. uint8* data;
  80498. int dataSize;
  80499. public:
  80500. bool finished, needsDictionary, error, streamIsValid;
  80501. };
  80502. const int gzipDecompBufferSize = 32768;
  80503. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80504. const bool deleteSourceWhenDestroyed,
  80505. const bool noWrap_,
  80506. const int64 uncompressedStreamLength_)
  80507. : sourceStream (sourceStream_),
  80508. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80509. uncompressedStreamLength (uncompressedStreamLength_),
  80510. noWrap (noWrap_),
  80511. isEof (false),
  80512. activeBufferSize (0),
  80513. originalSourcePos (sourceStream_->getPosition()),
  80514. currentPos (0),
  80515. buffer (gzipDecompBufferSize),
  80516. helper (new GZIPDecompressHelper (noWrap_))
  80517. {
  80518. }
  80519. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80520. {
  80521. }
  80522. int64 GZIPDecompressorInputStream::getTotalLength()
  80523. {
  80524. return uncompressedStreamLength;
  80525. }
  80526. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80527. {
  80528. if ((howMany > 0) && ! isEof)
  80529. {
  80530. jassert (destBuffer != 0);
  80531. if (destBuffer != 0)
  80532. {
  80533. int numRead = 0;
  80534. uint8* d = (uint8*) destBuffer;
  80535. while (! helper->error)
  80536. {
  80537. const int n = helper->doNextBlock (d, howMany);
  80538. currentPos += n;
  80539. if (n == 0)
  80540. {
  80541. if (helper->finished || helper->needsDictionary)
  80542. {
  80543. isEof = true;
  80544. return numRead;
  80545. }
  80546. if (helper->needsInput())
  80547. {
  80548. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80549. if (activeBufferSize > 0)
  80550. {
  80551. helper->setInput ((uint8*) buffer, activeBufferSize);
  80552. }
  80553. else
  80554. {
  80555. isEof = true;
  80556. return numRead;
  80557. }
  80558. }
  80559. }
  80560. else
  80561. {
  80562. numRead += n;
  80563. howMany -= n;
  80564. d += n;
  80565. if (howMany <= 0)
  80566. return numRead;
  80567. }
  80568. }
  80569. }
  80570. }
  80571. return 0;
  80572. }
  80573. bool GZIPDecompressorInputStream::isExhausted()
  80574. {
  80575. return helper->error || isEof;
  80576. }
  80577. int64 GZIPDecompressorInputStream::getPosition()
  80578. {
  80579. return currentPos;
  80580. }
  80581. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80582. {
  80583. if (newPos < currentPos)
  80584. {
  80585. // to go backwards, reset the stream and start again..
  80586. isEof = false;
  80587. activeBufferSize = 0;
  80588. currentPos = 0;
  80589. helper = new GZIPDecompressHelper (noWrap);
  80590. sourceStream->setPosition (originalSourcePos);
  80591. }
  80592. skipNextBytes (newPos - currentPos);
  80593. return true;
  80594. }
  80595. END_JUCE_NAMESPACE
  80596. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80597. #endif
  80598. #if JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  80599. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80600. #if JUCE_USE_FLAC
  80601. #if JUCE_WINDOWS
  80602. #include <windows.h>
  80603. #endif
  80604. #ifdef _MSC_VER
  80605. #pragma warning (disable : 4505)
  80606. #pragma warning (push)
  80607. #endif
  80608. namespace FlacNamespace
  80609. {
  80610. #if JUCE_INCLUDE_FLAC_CODE
  80611. #define FLAC__NO_DLL 1
  80612. #if ! defined (SIZE_MAX)
  80613. #define SIZE_MAX 0xffffffff
  80614. #endif
  80615. #define __STDC_LIMIT_MACROS 1
  80616. /*** Start of inlined file: all.h ***/
  80617. #ifndef FLAC__ALL_H
  80618. #define FLAC__ALL_H
  80619. /*** Start of inlined file: export.h ***/
  80620. #ifndef FLAC__EXPORT_H
  80621. #define FLAC__EXPORT_H
  80622. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80623. #define FLAC_API
  80624. #else
  80625. #ifdef FLAC_API_EXPORTS
  80626. #define FLAC_API _declspec(dllexport)
  80627. #else
  80628. #define FLAC_API _declspec(dllimport)
  80629. #endif
  80630. #endif
  80631. #define FLAC_API_VERSION_CURRENT 10
  80632. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80633. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80634. #ifdef __cplusplus
  80635. extern "C" {
  80636. #endif
  80637. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80638. #ifdef __cplusplus
  80639. }
  80640. #endif
  80641. #endif
  80642. /*** End of inlined file: export.h ***/
  80643. /*** Start of inlined file: assert.h ***/
  80644. #ifndef FLAC__ASSERT_H
  80645. #define FLAC__ASSERT_H
  80646. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80647. #ifdef DEBUG
  80648. #include <assert.h>
  80649. #define FLAC__ASSERT(x) assert(x)
  80650. #define FLAC__ASSERT_DECLARATION(x) x
  80651. #else
  80652. #define FLAC__ASSERT(x)
  80653. #define FLAC__ASSERT_DECLARATION(x)
  80654. #endif
  80655. #endif
  80656. /*** End of inlined file: assert.h ***/
  80657. /*** Start of inlined file: callback.h ***/
  80658. #ifndef FLAC__CALLBACK_H
  80659. #define FLAC__CALLBACK_H
  80660. /*** Start of inlined file: ordinals.h ***/
  80661. #ifndef FLAC__ORDINALS_H
  80662. #define FLAC__ORDINALS_H
  80663. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80664. #include <inttypes.h>
  80665. #endif
  80666. typedef signed char FLAC__int8;
  80667. typedef unsigned char FLAC__uint8;
  80668. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80669. typedef __int16 FLAC__int16;
  80670. typedef __int32 FLAC__int32;
  80671. typedef __int64 FLAC__int64;
  80672. typedef unsigned __int16 FLAC__uint16;
  80673. typedef unsigned __int32 FLAC__uint32;
  80674. typedef unsigned __int64 FLAC__uint64;
  80675. #elif defined(__EMX__)
  80676. typedef short FLAC__int16;
  80677. typedef long FLAC__int32;
  80678. typedef long long FLAC__int64;
  80679. typedef unsigned short FLAC__uint16;
  80680. typedef unsigned long FLAC__uint32;
  80681. typedef unsigned long long FLAC__uint64;
  80682. #else
  80683. typedef int16_t FLAC__int16;
  80684. typedef int32_t FLAC__int32;
  80685. typedef int64_t FLAC__int64;
  80686. typedef uint16_t FLAC__uint16;
  80687. typedef uint32_t FLAC__uint32;
  80688. typedef uint64_t FLAC__uint64;
  80689. #endif
  80690. typedef int FLAC__bool;
  80691. typedef FLAC__uint8 FLAC__byte;
  80692. #ifdef true
  80693. #undef true
  80694. #endif
  80695. #ifdef false
  80696. #undef false
  80697. #endif
  80698. #ifndef __cplusplus
  80699. #define true 1
  80700. #define false 0
  80701. #endif
  80702. #endif
  80703. /*** End of inlined file: ordinals.h ***/
  80704. #include <stdlib.h> /* for size_t */
  80705. #ifdef __cplusplus
  80706. extern "C" {
  80707. #endif
  80708. typedef void* FLAC__IOHandle;
  80709. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80710. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80711. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  80712. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  80713. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  80714. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  80715. typedef struct {
  80716. FLAC__IOCallback_Read read;
  80717. FLAC__IOCallback_Write write;
  80718. FLAC__IOCallback_Seek seek;
  80719. FLAC__IOCallback_Tell tell;
  80720. FLAC__IOCallback_Eof eof;
  80721. FLAC__IOCallback_Close close;
  80722. } FLAC__IOCallbacks;
  80723. #ifdef __cplusplus
  80724. }
  80725. #endif
  80726. #endif
  80727. /*** End of inlined file: callback.h ***/
  80728. /*** Start of inlined file: format.h ***/
  80729. #ifndef FLAC__FORMAT_H
  80730. #define FLAC__FORMAT_H
  80731. #ifdef __cplusplus
  80732. extern "C" {
  80733. #endif
  80734. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  80735. #define FLAC__MIN_BLOCK_SIZE (16u)
  80736. #define FLAC__MAX_BLOCK_SIZE (65535u)
  80737. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  80738. #define FLAC__MAX_CHANNELS (8u)
  80739. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  80740. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  80741. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  80742. #define FLAC__MAX_SAMPLE_RATE (655350u)
  80743. #define FLAC__MAX_LPC_ORDER (32u)
  80744. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  80745. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  80746. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  80747. #define FLAC__MAX_FIXED_ORDER (4u)
  80748. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  80749. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  80750. extern FLAC_API const char *FLAC__VERSION_STRING;
  80751. extern FLAC_API const char *FLAC__VENDOR_STRING;
  80752. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  80753. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  80754. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  80755. #define FLAC__STREAM_SYNC_LENGTH (4u)
  80756. typedef enum {
  80757. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  80758. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  80759. } FLAC__EntropyCodingMethodType;
  80760. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  80761. typedef struct {
  80762. unsigned *parameters;
  80763. unsigned *raw_bits;
  80764. unsigned capacity_by_order;
  80765. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  80766. typedef struct {
  80767. unsigned order;
  80768. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  80769. } FLAC__EntropyCodingMethod_PartitionedRice;
  80770. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  80771. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  80772. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  80773. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  80774. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  80775. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  80776. typedef struct {
  80777. FLAC__EntropyCodingMethodType type;
  80778. union {
  80779. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  80780. } data;
  80781. } FLAC__EntropyCodingMethod;
  80782. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  80783. typedef enum {
  80784. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  80785. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  80786. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  80787. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  80788. } FLAC__SubframeType;
  80789. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  80790. typedef struct {
  80791. FLAC__int32 value; /**< The constant signal value. */
  80792. } FLAC__Subframe_Constant;
  80793. typedef struct {
  80794. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  80795. } FLAC__Subframe_Verbatim;
  80796. typedef struct {
  80797. FLAC__EntropyCodingMethod entropy_coding_method;
  80798. unsigned order;
  80799. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  80800. const FLAC__int32 *residual;
  80801. } FLAC__Subframe_Fixed;
  80802. typedef struct {
  80803. FLAC__EntropyCodingMethod entropy_coding_method;
  80804. unsigned order;
  80805. unsigned qlp_coeff_precision;
  80806. int quantization_level;
  80807. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  80808. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  80809. const FLAC__int32 *residual;
  80810. } FLAC__Subframe_LPC;
  80811. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  80812. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  80813. typedef struct {
  80814. FLAC__SubframeType type;
  80815. union {
  80816. FLAC__Subframe_Constant constant;
  80817. FLAC__Subframe_Fixed fixed;
  80818. FLAC__Subframe_LPC lpc;
  80819. FLAC__Subframe_Verbatim verbatim;
  80820. } data;
  80821. unsigned wasted_bits;
  80822. } FLAC__Subframe;
  80823. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  80824. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  80825. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  80826. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  80827. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  80828. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  80829. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  80830. typedef enum {
  80831. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  80832. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  80833. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  80834. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  80835. } FLAC__ChannelAssignment;
  80836. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  80837. typedef enum {
  80838. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  80839. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  80840. } FLAC__FrameNumberType;
  80841. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  80842. typedef struct {
  80843. unsigned blocksize;
  80844. unsigned sample_rate;
  80845. unsigned channels;
  80846. FLAC__ChannelAssignment channel_assignment;
  80847. unsigned bits_per_sample;
  80848. FLAC__FrameNumberType number_type;
  80849. union {
  80850. FLAC__uint32 frame_number;
  80851. FLAC__uint64 sample_number;
  80852. } number;
  80853. FLAC__uint8 crc;
  80854. } FLAC__FrameHeader;
  80855. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  80856. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  80857. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  80858. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  80859. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  80860. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  80861. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  80862. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  80863. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  80864. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  80865. typedef struct {
  80866. FLAC__uint16 crc;
  80867. } FLAC__FrameFooter;
  80868. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  80869. typedef struct {
  80870. FLAC__FrameHeader header;
  80871. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  80872. FLAC__FrameFooter footer;
  80873. } FLAC__Frame;
  80874. typedef enum {
  80875. FLAC__METADATA_TYPE_STREAMINFO = 0,
  80876. FLAC__METADATA_TYPE_PADDING = 1,
  80877. FLAC__METADATA_TYPE_APPLICATION = 2,
  80878. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  80879. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  80880. FLAC__METADATA_TYPE_CUESHEET = 5,
  80881. FLAC__METADATA_TYPE_PICTURE = 6,
  80882. FLAC__METADATA_TYPE_UNDEFINED = 7
  80883. } FLAC__MetadataType;
  80884. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  80885. typedef struct {
  80886. unsigned min_blocksize, max_blocksize;
  80887. unsigned min_framesize, max_framesize;
  80888. unsigned sample_rate;
  80889. unsigned channels;
  80890. unsigned bits_per_sample;
  80891. FLAC__uint64 total_samples;
  80892. FLAC__byte md5sum[16];
  80893. } FLAC__StreamMetadata_StreamInfo;
  80894. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80895. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80896. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80897. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80898. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  80899. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  80900. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  80901. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  80902. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  80903. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  80904. typedef struct {
  80905. int dummy;
  80906. } FLAC__StreamMetadata_Padding;
  80907. typedef struct {
  80908. FLAC__byte id[4];
  80909. FLAC__byte *data;
  80910. } FLAC__StreamMetadata_Application;
  80911. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  80912. typedef struct {
  80913. FLAC__uint64 sample_number;
  80914. FLAC__uint64 stream_offset;
  80915. unsigned frame_samples;
  80916. } FLAC__StreamMetadata_SeekPoint;
  80917. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  80918. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  80919. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  80920. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  80921. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  80922. typedef struct {
  80923. unsigned num_points;
  80924. FLAC__StreamMetadata_SeekPoint *points;
  80925. } FLAC__StreamMetadata_SeekTable;
  80926. typedef struct {
  80927. FLAC__uint32 length;
  80928. FLAC__byte *entry;
  80929. } FLAC__StreamMetadata_VorbisComment_Entry;
  80930. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  80931. typedef struct {
  80932. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  80933. FLAC__uint32 num_comments;
  80934. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  80935. } FLAC__StreamMetadata_VorbisComment;
  80936. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  80937. typedef struct {
  80938. FLAC__uint64 offset;
  80939. FLAC__byte number;
  80940. } FLAC__StreamMetadata_CueSheet_Index;
  80941. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  80942. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  80943. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  80944. typedef struct {
  80945. FLAC__uint64 offset;
  80946. FLAC__byte number;
  80947. char isrc[13];
  80948. unsigned type:1;
  80949. unsigned pre_emphasis:1;
  80950. FLAC__byte num_indices;
  80951. FLAC__StreamMetadata_CueSheet_Index *indices;
  80952. } FLAC__StreamMetadata_CueSheet_Track;
  80953. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  80954. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  80955. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  80956. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  80957. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  80958. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  80959. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  80960. typedef struct {
  80961. char media_catalog_number[129];
  80962. FLAC__uint64 lead_in;
  80963. FLAC__bool is_cd;
  80964. unsigned num_tracks;
  80965. FLAC__StreamMetadata_CueSheet_Track *tracks;
  80966. } FLAC__StreamMetadata_CueSheet;
  80967. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  80968. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  80969. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  80970. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  80971. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  80972. typedef enum {
  80973. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  80974. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  80975. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  80976. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  80977. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  80978. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  80979. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  80980. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  80981. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  80982. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  80983. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  80984. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  80985. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  80986. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  80987. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  80988. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  80989. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  80990. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  80991. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  80992. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  80993. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  80994. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  80995. } FLAC__StreamMetadata_Picture_Type;
  80996. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  80997. typedef struct {
  80998. FLAC__StreamMetadata_Picture_Type type;
  80999. char *mime_type;
  81000. FLAC__byte *description;
  81001. FLAC__uint32 width;
  81002. FLAC__uint32 height;
  81003. FLAC__uint32 depth;
  81004. FLAC__uint32 colors;
  81005. FLAC__uint32 data_length;
  81006. FLAC__byte *data;
  81007. } FLAC__StreamMetadata_Picture;
  81008. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  81009. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  81010. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  81011. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  81012. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  81013. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  81014. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  81015. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  81016. typedef struct {
  81017. FLAC__byte *data;
  81018. } FLAC__StreamMetadata_Unknown;
  81019. typedef struct {
  81020. FLAC__MetadataType type;
  81021. FLAC__bool is_last;
  81022. unsigned length;
  81023. union {
  81024. FLAC__StreamMetadata_StreamInfo stream_info;
  81025. FLAC__StreamMetadata_Padding padding;
  81026. FLAC__StreamMetadata_Application application;
  81027. FLAC__StreamMetadata_SeekTable seek_table;
  81028. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  81029. FLAC__StreamMetadata_CueSheet cue_sheet;
  81030. FLAC__StreamMetadata_Picture picture;
  81031. FLAC__StreamMetadata_Unknown unknown;
  81032. } data;
  81033. } FLAC__StreamMetadata;
  81034. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  81035. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  81036. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  81037. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  81038. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  81039. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  81040. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  81041. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  81042. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  81043. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  81044. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  81045. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  81046. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  81047. #ifdef __cplusplus
  81048. }
  81049. #endif
  81050. #endif
  81051. /*** End of inlined file: format.h ***/
  81052. /*** Start of inlined file: metadata.h ***/
  81053. #ifndef FLAC__METADATA_H
  81054. #define FLAC__METADATA_H
  81055. #include <sys/types.h> /* for off_t */
  81056. #ifdef __cplusplus
  81057. extern "C" {
  81058. #endif
  81059. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  81060. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  81061. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  81062. 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);
  81063. struct FLAC__Metadata_SimpleIterator;
  81064. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  81065. typedef enum {
  81066. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  81067. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  81068. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  81069. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  81070. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  81071. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  81072. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  81073. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  81074. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  81075. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  81076. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  81077. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  81078. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  81079. } FLAC__Metadata_SimpleIteratorStatus;
  81080. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  81081. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  81082. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  81083. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  81084. 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);
  81085. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  81086. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  81087. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  81088. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  81089. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  81090. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  81091. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  81092. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  81093. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  81094. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81095. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81096. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  81097. struct FLAC__Metadata_Chain;
  81098. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  81099. struct FLAC__Metadata_Iterator;
  81100. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  81101. typedef enum {
  81102. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  81103. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  81104. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  81105. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  81106. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  81107. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  81108. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  81109. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  81110. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  81111. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  81112. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  81113. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  81114. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  81115. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  81116. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  81117. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  81118. } FLAC__Metadata_ChainStatus;
  81119. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  81120. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  81121. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  81122. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  81123. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  81124. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  81125. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81126. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81127. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  81128. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  81129. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81130. 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);
  81131. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  81132. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  81133. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  81134. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  81135. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  81136. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  81137. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  81138. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  81139. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  81140. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81141. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  81142. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81143. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81144. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  81145. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  81146. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  81147. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  81148. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  81149. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  81150. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81151. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81152. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  81153. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  81154. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  81155. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  81156. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  81157. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  81158. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  81159. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  81160. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81161. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  81162. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81163. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81164. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81165. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  81166. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  81167. 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);
  81168. 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);
  81169. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  81170. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  81171. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  81172. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  81173. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  81174. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  81175. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  81176. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  81177. 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);
  81178. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81179. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81180. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  81181. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81182. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81183. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  81184. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  81185. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  81186. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  81187. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  81188. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  81189. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  81190. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  81191. #ifdef __cplusplus
  81192. }
  81193. #endif
  81194. #endif
  81195. /*** End of inlined file: metadata.h ***/
  81196. /*** Start of inlined file: stream_decoder.h ***/
  81197. #ifndef FLAC__STREAM_DECODER_H
  81198. #define FLAC__STREAM_DECODER_H
  81199. #include <stdio.h> /* for FILE */
  81200. #ifdef __cplusplus
  81201. extern "C" {
  81202. #endif
  81203. typedef enum {
  81204. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  81205. FLAC__STREAM_DECODER_READ_METADATA,
  81206. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  81207. FLAC__STREAM_DECODER_READ_FRAME,
  81208. FLAC__STREAM_DECODER_END_OF_STREAM,
  81209. FLAC__STREAM_DECODER_OGG_ERROR,
  81210. FLAC__STREAM_DECODER_SEEK_ERROR,
  81211. FLAC__STREAM_DECODER_ABORTED,
  81212. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  81213. FLAC__STREAM_DECODER_UNINITIALIZED
  81214. } FLAC__StreamDecoderState;
  81215. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  81216. typedef enum {
  81217. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  81218. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81219. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  81220. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  81221. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  81222. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  81223. } FLAC__StreamDecoderInitStatus;
  81224. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  81225. typedef enum {
  81226. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  81227. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  81228. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  81229. } FLAC__StreamDecoderReadStatus;
  81230. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  81231. typedef enum {
  81232. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  81233. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  81234. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  81235. } FLAC__StreamDecoderSeekStatus;
  81236. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  81237. typedef enum {
  81238. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  81239. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  81240. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  81241. } FLAC__StreamDecoderTellStatus;
  81242. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  81243. typedef enum {
  81244. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  81245. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  81246. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  81247. } FLAC__StreamDecoderLengthStatus;
  81248. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  81249. typedef enum {
  81250. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  81251. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  81252. } FLAC__StreamDecoderWriteStatus;
  81253. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  81254. typedef enum {
  81255. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  81256. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  81257. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  81258. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  81259. } FLAC__StreamDecoderErrorStatus;
  81260. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  81261. struct FLAC__StreamDecoderProtected;
  81262. struct FLAC__StreamDecoderPrivate;
  81263. typedef struct {
  81264. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81265. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81266. } FLAC__StreamDecoder;
  81267. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81268. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81269. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81270. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  81271. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  81272. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  81273. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81274. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  81275. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  81276. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  81277. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  81278. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  81279. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81280. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81281. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  81282. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81283. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81284. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  81285. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  81286. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  81287. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  81288. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  81289. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  81290. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  81291. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  81292. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  81293. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  81294. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81295. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81296. FLAC__StreamDecoder *decoder,
  81297. FLAC__StreamDecoderReadCallback read_callback,
  81298. FLAC__StreamDecoderSeekCallback seek_callback,
  81299. FLAC__StreamDecoderTellCallback tell_callback,
  81300. FLAC__StreamDecoderLengthCallback length_callback,
  81301. FLAC__StreamDecoderEofCallback eof_callback,
  81302. FLAC__StreamDecoderWriteCallback write_callback,
  81303. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81304. FLAC__StreamDecoderErrorCallback error_callback,
  81305. void *client_data
  81306. );
  81307. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81308. FLAC__StreamDecoder *decoder,
  81309. FLAC__StreamDecoderReadCallback read_callback,
  81310. FLAC__StreamDecoderSeekCallback seek_callback,
  81311. FLAC__StreamDecoderTellCallback tell_callback,
  81312. FLAC__StreamDecoderLengthCallback length_callback,
  81313. FLAC__StreamDecoderEofCallback eof_callback,
  81314. FLAC__StreamDecoderWriteCallback write_callback,
  81315. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81316. FLAC__StreamDecoderErrorCallback error_callback,
  81317. void *client_data
  81318. );
  81319. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81320. FLAC__StreamDecoder *decoder,
  81321. FILE *file,
  81322. FLAC__StreamDecoderWriteCallback write_callback,
  81323. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81324. FLAC__StreamDecoderErrorCallback error_callback,
  81325. void *client_data
  81326. );
  81327. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81328. FLAC__StreamDecoder *decoder,
  81329. FILE *file,
  81330. FLAC__StreamDecoderWriteCallback write_callback,
  81331. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81332. FLAC__StreamDecoderErrorCallback error_callback,
  81333. void *client_data
  81334. );
  81335. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81336. FLAC__StreamDecoder *decoder,
  81337. const char *filename,
  81338. FLAC__StreamDecoderWriteCallback write_callback,
  81339. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81340. FLAC__StreamDecoderErrorCallback error_callback,
  81341. void *client_data
  81342. );
  81343. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81344. FLAC__StreamDecoder *decoder,
  81345. const char *filename,
  81346. FLAC__StreamDecoderWriteCallback write_callback,
  81347. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81348. FLAC__StreamDecoderErrorCallback error_callback,
  81349. void *client_data
  81350. );
  81351. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81352. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81353. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81354. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81355. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81356. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81357. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81358. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81359. #ifdef __cplusplus
  81360. }
  81361. #endif
  81362. #endif
  81363. /*** End of inlined file: stream_decoder.h ***/
  81364. /*** Start of inlined file: stream_encoder.h ***/
  81365. #ifndef FLAC__STREAM_ENCODER_H
  81366. #define FLAC__STREAM_ENCODER_H
  81367. #include <stdio.h> /* for FILE */
  81368. #ifdef __cplusplus
  81369. extern "C" {
  81370. #endif
  81371. typedef enum {
  81372. FLAC__STREAM_ENCODER_OK = 0,
  81373. FLAC__STREAM_ENCODER_UNINITIALIZED,
  81374. FLAC__STREAM_ENCODER_OGG_ERROR,
  81375. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  81376. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  81377. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  81378. FLAC__STREAM_ENCODER_IO_ERROR,
  81379. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  81380. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  81381. } FLAC__StreamEncoderState;
  81382. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  81383. typedef enum {
  81384. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  81385. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  81386. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81387. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  81388. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  81389. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  81390. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  81391. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  81392. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  81393. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  81394. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  81395. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  81396. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  81397. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  81398. } FLAC__StreamEncoderInitStatus;
  81399. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  81400. typedef enum {
  81401. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  81402. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  81403. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  81404. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  81405. } FLAC__StreamEncoderReadStatus;
  81406. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81407. typedef enum {
  81408. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81409. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81410. } FLAC__StreamEncoderWriteStatus;
  81411. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81412. typedef enum {
  81413. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81414. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81415. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81416. } FLAC__StreamEncoderSeekStatus;
  81417. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81418. typedef enum {
  81419. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81420. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81421. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81422. } FLAC__StreamEncoderTellStatus;
  81423. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81424. struct FLAC__StreamEncoderProtected;
  81425. struct FLAC__StreamEncoderPrivate;
  81426. typedef struct {
  81427. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81428. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81429. } FLAC__StreamEncoder;
  81430. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81431. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81432. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81433. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81434. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81435. 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);
  81436. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81437. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81438. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81439. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81440. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81441. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81442. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81443. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81444. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81445. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81446. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81447. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81448. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81449. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81450. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81451. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81452. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81453. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81454. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81455. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81456. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81457. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81458. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81459. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81460. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81461. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81462. 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);
  81463. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81464. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81465. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81466. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81467. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81468. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81469. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81470. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81471. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81472. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81473. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81474. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81475. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81476. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81477. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81478. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81479. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81480. 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);
  81481. 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);
  81482. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81483. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81484. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81485. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81486. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81487. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81488. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81489. #ifdef __cplusplus
  81490. }
  81491. #endif
  81492. #endif
  81493. /*** End of inlined file: stream_encoder.h ***/
  81494. #ifdef _MSC_VER
  81495. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81496. {
  81497. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81498. return (x>>16) | (x<<16);
  81499. }
  81500. #endif
  81501. #if defined(_MSC_VER) && defined(_X86_)
  81502. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81503. {
  81504. __asm {
  81505. mov edx, start
  81506. mov ecx, len
  81507. test ecx, ecx
  81508. loop1:
  81509. jz done1
  81510. mov eax, [edx]
  81511. bswap eax
  81512. mov [edx], eax
  81513. add edx, 4
  81514. dec ecx
  81515. jmp short loop1
  81516. done1:
  81517. }
  81518. }
  81519. #endif
  81520. #endif
  81521. /*** End of inlined file: all.h ***/
  81522. /*** Start of inlined file: bitmath.c ***/
  81523. /*** Start of inlined file: juce_FlacHeader.h ***/
  81524. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81525. // tasks..
  81526. #define VERSION "1.2.1"
  81527. #define FLAC__NO_DLL 1
  81528. #if JUCE_MSVC
  81529. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81530. #endif
  81531. #if JUCE_MAC
  81532. #define FLAC__SYS_DARWIN 1
  81533. #endif
  81534. /*** End of inlined file: juce_FlacHeader.h ***/
  81535. #if JUCE_USE_FLAC
  81536. #if HAVE_CONFIG_H
  81537. # include <config.h>
  81538. #endif
  81539. /*** Start of inlined file: bitmath.h ***/
  81540. #ifndef FLAC__PRIVATE__BITMATH_H
  81541. #define FLAC__PRIVATE__BITMATH_H
  81542. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81543. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81544. unsigned FLAC__bitmath_silog2(int v);
  81545. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81546. #endif
  81547. /*** End of inlined file: bitmath.h ***/
  81548. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81549. {
  81550. unsigned l = 0;
  81551. FLAC__ASSERT(v > 0);
  81552. while(v >>= 1)
  81553. l++;
  81554. return l;
  81555. }
  81556. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81557. {
  81558. unsigned l = 0;
  81559. FLAC__ASSERT(v > 0);
  81560. while(v >>= 1)
  81561. l++;
  81562. return l;
  81563. }
  81564. unsigned FLAC__bitmath_silog2(int v)
  81565. {
  81566. while(1) {
  81567. if(v == 0) {
  81568. return 0;
  81569. }
  81570. else if(v > 0) {
  81571. unsigned l = 0;
  81572. while(v) {
  81573. l++;
  81574. v >>= 1;
  81575. }
  81576. return l+1;
  81577. }
  81578. else if(v == -1) {
  81579. return 2;
  81580. }
  81581. else {
  81582. v++;
  81583. v = -v;
  81584. }
  81585. }
  81586. }
  81587. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81588. {
  81589. while(1) {
  81590. if(v == 0) {
  81591. return 0;
  81592. }
  81593. else if(v > 0) {
  81594. unsigned l = 0;
  81595. while(v) {
  81596. l++;
  81597. v >>= 1;
  81598. }
  81599. return l+1;
  81600. }
  81601. else if(v == -1) {
  81602. return 2;
  81603. }
  81604. else {
  81605. v++;
  81606. v = -v;
  81607. }
  81608. }
  81609. }
  81610. #endif
  81611. /*** End of inlined file: bitmath.c ***/
  81612. /*** Start of inlined file: bitreader.c ***/
  81613. /*** Start of inlined file: juce_FlacHeader.h ***/
  81614. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81615. // tasks..
  81616. #define VERSION "1.2.1"
  81617. #define FLAC__NO_DLL 1
  81618. #if JUCE_MSVC
  81619. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81620. #endif
  81621. #if JUCE_MAC
  81622. #define FLAC__SYS_DARWIN 1
  81623. #endif
  81624. /*** End of inlined file: juce_FlacHeader.h ***/
  81625. #if JUCE_USE_FLAC
  81626. #if HAVE_CONFIG_H
  81627. # include <config.h>
  81628. #endif
  81629. #include <stdlib.h> /* for malloc() */
  81630. #include <string.h> /* for memcpy(), memset() */
  81631. #ifdef _MSC_VER
  81632. #include <winsock.h> /* for ntohl() */
  81633. #elif defined FLAC__SYS_DARWIN
  81634. #include <machine/endian.h> /* for ntohl() */
  81635. #elif defined __MINGW32__
  81636. #include <winsock.h> /* for ntohl() */
  81637. #else
  81638. #include <netinet/in.h> /* for ntohl() */
  81639. #endif
  81640. /*** Start of inlined file: bitreader.h ***/
  81641. #ifndef FLAC__PRIVATE__BITREADER_H
  81642. #define FLAC__PRIVATE__BITREADER_H
  81643. #include <stdio.h> /* for FILE */
  81644. /*** Start of inlined file: cpu.h ***/
  81645. #ifndef FLAC__PRIVATE__CPU_H
  81646. #define FLAC__PRIVATE__CPU_H
  81647. #ifdef HAVE_CONFIG_H
  81648. #include <config.h>
  81649. #endif
  81650. typedef enum {
  81651. FLAC__CPUINFO_TYPE_IA32,
  81652. FLAC__CPUINFO_TYPE_PPC,
  81653. FLAC__CPUINFO_TYPE_UNKNOWN
  81654. } FLAC__CPUInfo_Type;
  81655. typedef struct {
  81656. FLAC__bool cpuid;
  81657. FLAC__bool bswap;
  81658. FLAC__bool cmov;
  81659. FLAC__bool mmx;
  81660. FLAC__bool fxsr;
  81661. FLAC__bool sse;
  81662. FLAC__bool sse2;
  81663. FLAC__bool sse3;
  81664. FLAC__bool ssse3;
  81665. FLAC__bool _3dnow;
  81666. FLAC__bool ext3dnow;
  81667. FLAC__bool extmmx;
  81668. } FLAC__CPUInfo_IA32;
  81669. typedef struct {
  81670. FLAC__bool altivec;
  81671. FLAC__bool ppc64;
  81672. } FLAC__CPUInfo_PPC;
  81673. typedef struct {
  81674. FLAC__bool use_asm;
  81675. FLAC__CPUInfo_Type type;
  81676. union {
  81677. FLAC__CPUInfo_IA32 ia32;
  81678. FLAC__CPUInfo_PPC ppc;
  81679. } data;
  81680. } FLAC__CPUInfo;
  81681. void FLAC__cpu_info(FLAC__CPUInfo *info);
  81682. #ifndef FLAC__NO_ASM
  81683. #ifdef FLAC__CPU_IA32
  81684. #ifdef FLAC__HAS_NASM
  81685. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  81686. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  81687. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  81688. #endif
  81689. #endif
  81690. #endif
  81691. #endif
  81692. /*** End of inlined file: cpu.h ***/
  81693. struct FLAC__BitReader;
  81694. typedef struct FLAC__BitReader FLAC__BitReader;
  81695. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  81696. FLAC__BitReader *FLAC__bitreader_new(void);
  81697. void FLAC__bitreader_delete(FLAC__BitReader *br);
  81698. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  81699. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  81700. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  81701. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  81702. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  81703. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  81704. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  81705. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  81706. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  81707. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  81708. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  81709. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  81710. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  81711. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  81712. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  81713. 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! */
  81714. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  81715. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81716. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81717. #ifndef FLAC__NO_ASM
  81718. # ifdef FLAC__CPU_IA32
  81719. # ifdef FLAC__HAS_NASM
  81720. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81721. # endif
  81722. # endif
  81723. #endif
  81724. #if 0 /* UNUSED */
  81725. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81726. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  81727. #endif
  81728. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  81729. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  81730. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  81731. #endif
  81732. /*** End of inlined file: bitreader.h ***/
  81733. /*** Start of inlined file: crc.h ***/
  81734. #ifndef FLAC__PRIVATE__CRC_H
  81735. #define FLAC__PRIVATE__CRC_H
  81736. extern FLAC__byte const FLAC__crc8_table[256];
  81737. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  81738. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  81739. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  81740. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  81741. extern unsigned FLAC__crc16_table[256];
  81742. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  81743. #if 0
  81744. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  81745. #endif
  81746. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  81747. #endif
  81748. /*** End of inlined file: crc.h ***/
  81749. typedef FLAC__uint32 brword;
  81750. #define FLAC__BYTES_PER_WORD 4
  81751. #define FLAC__BITS_PER_WORD 32
  81752. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  81753. #if WORDS_BIGENDIAN
  81754. #define SWAP_BE_WORD_TO_HOST(x) (x)
  81755. #else
  81756. #if defined (_MSC_VER) && defined (_X86_)
  81757. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  81758. #else
  81759. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  81760. #endif
  81761. #endif
  81762. #define COUNT_ZERO_MSBS(word) ( \
  81763. (word) <= 0xffff ? \
  81764. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  81765. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  81766. )
  81767. #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])) )
  81768. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  81769. static const unsigned char byte_to_unary_table[] = {
  81770. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  81771. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  81772. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81773. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81774. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81775. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81776. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81777. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  81786. };
  81787. #ifdef min
  81788. #undef min
  81789. #endif
  81790. #define min(x,y) ((x)<(y)?(x):(y))
  81791. #ifdef max
  81792. #undef max
  81793. #endif
  81794. #define max(x,y) ((x)>(y)?(x):(y))
  81795. #ifdef _MSC_VER
  81796. #define FLAC__U64L(x) x
  81797. #else
  81798. #define FLAC__U64L(x) x##LLU
  81799. #endif
  81800. #ifndef FLaC__INLINE
  81801. #define FLaC__INLINE
  81802. #endif
  81803. struct FLAC__BitReader {
  81804. brword *buffer;
  81805. unsigned capacity; /* in words */
  81806. unsigned words; /* # of completed words in buffer */
  81807. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  81808. unsigned consumed_words; /* #words ... */
  81809. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  81810. unsigned read_crc16; /* the running frame CRC */
  81811. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  81812. FLAC__BitReaderReadCallback read_callback;
  81813. void *client_data;
  81814. FLAC__CPUInfo cpu_info;
  81815. };
  81816. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  81817. {
  81818. register unsigned crc = br->read_crc16;
  81819. #if FLAC__BYTES_PER_WORD == 4
  81820. switch(br->crc16_align) {
  81821. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  81822. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81823. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81824. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81825. }
  81826. #elif FLAC__BYTES_PER_WORD == 8
  81827. switch(br->crc16_align) {
  81828. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  81829. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  81830. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  81831. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  81832. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  81833. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81834. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81835. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81836. }
  81837. #else
  81838. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  81839. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  81840. br->read_crc16 = crc;
  81841. #endif
  81842. br->crc16_align = 0;
  81843. }
  81844. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  81845. {
  81846. unsigned start, end;
  81847. size_t bytes;
  81848. FLAC__byte *target;
  81849. if(br->consumed_words > 0) {
  81850. start = br->consumed_words;
  81851. end = br->words + (br->bytes? 1:0);
  81852. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  81853. br->words -= start;
  81854. br->consumed_words = 0;
  81855. }
  81856. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  81857. if(bytes == 0)
  81858. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  81859. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  81860. #if WORDS_BIGENDIAN
  81861. #else
  81862. if(br->bytes)
  81863. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  81864. #endif
  81865. if(!br->read_callback(target, &bytes, br->client_data))
  81866. return false;
  81867. #if WORDS_BIGENDIAN
  81868. #else
  81869. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  81870. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  81871. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  81872. start = br->words;
  81873. local_swap32_block_(br->buffer + start, end - start);
  81874. }
  81875. else
  81876. # endif
  81877. for(start = br->words; start < end; start++)
  81878. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  81879. #endif
  81880. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  81881. br->words = end / FLAC__BYTES_PER_WORD;
  81882. br->bytes = end % FLAC__BYTES_PER_WORD;
  81883. return true;
  81884. }
  81885. FLAC__BitReader *FLAC__bitreader_new(void)
  81886. {
  81887. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  81888. return br;
  81889. }
  81890. void FLAC__bitreader_delete(FLAC__BitReader *br)
  81891. {
  81892. FLAC__ASSERT(0 != br);
  81893. FLAC__bitreader_free(br);
  81894. free(br);
  81895. }
  81896. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  81897. {
  81898. FLAC__ASSERT(0 != br);
  81899. br->words = br->bytes = 0;
  81900. br->consumed_words = br->consumed_bits = 0;
  81901. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  81902. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  81903. if(br->buffer == 0)
  81904. return false;
  81905. br->read_callback = rcb;
  81906. br->client_data = cd;
  81907. br->cpu_info = cpu;
  81908. return true;
  81909. }
  81910. void FLAC__bitreader_free(FLAC__BitReader *br)
  81911. {
  81912. FLAC__ASSERT(0 != br);
  81913. if(0 != br->buffer)
  81914. free(br->buffer);
  81915. br->buffer = 0;
  81916. br->capacity = 0;
  81917. br->words = br->bytes = 0;
  81918. br->consumed_words = br->consumed_bits = 0;
  81919. br->read_callback = 0;
  81920. br->client_data = 0;
  81921. }
  81922. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  81923. {
  81924. br->words = br->bytes = 0;
  81925. br->consumed_words = br->consumed_bits = 0;
  81926. return true;
  81927. }
  81928. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  81929. {
  81930. unsigned i, j;
  81931. if(br == 0) {
  81932. fprintf(out, "bitreader is NULL\n");
  81933. }
  81934. else {
  81935. 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);
  81936. for(i = 0; i < br->words; i++) {
  81937. fprintf(out, "%08X: ", i);
  81938. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  81939. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81940. fprintf(out, ".");
  81941. else
  81942. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  81943. fprintf(out, "\n");
  81944. }
  81945. if(br->bytes > 0) {
  81946. fprintf(out, "%08X: ", i);
  81947. for(j = 0; j < br->bytes*8; j++)
  81948. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81949. fprintf(out, ".");
  81950. else
  81951. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  81952. fprintf(out, "\n");
  81953. }
  81954. }
  81955. }
  81956. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  81957. {
  81958. FLAC__ASSERT(0 != br);
  81959. FLAC__ASSERT(0 != br->buffer);
  81960. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81961. br->read_crc16 = (unsigned)seed;
  81962. br->crc16_align = br->consumed_bits;
  81963. }
  81964. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  81965. {
  81966. FLAC__ASSERT(0 != br);
  81967. FLAC__ASSERT(0 != br->buffer);
  81968. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81969. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  81970. if(br->consumed_bits) {
  81971. const brword tail = br->buffer[br->consumed_words];
  81972. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  81973. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  81974. }
  81975. return br->read_crc16;
  81976. }
  81977. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  81978. {
  81979. return ((br->consumed_bits & 7) == 0);
  81980. }
  81981. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  81982. {
  81983. return 8 - (br->consumed_bits & 7);
  81984. }
  81985. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  81986. {
  81987. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  81988. }
  81989. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  81990. {
  81991. FLAC__ASSERT(0 != br);
  81992. FLAC__ASSERT(0 != br->buffer);
  81993. FLAC__ASSERT(bits <= 32);
  81994. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  81995. FLAC__ASSERT(br->consumed_words <= br->words);
  81996. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  81997. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  81998. *val = 0;
  81999. return true;
  82000. }
  82001. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  82002. if(!bitreader_read_from_client_(br))
  82003. return false;
  82004. }
  82005. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82006. if(br->consumed_bits) {
  82007. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  82008. const brword word = br->buffer[br->consumed_words];
  82009. if(bits < n) {
  82010. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  82011. br->consumed_bits += bits;
  82012. return true;
  82013. }
  82014. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  82015. bits -= n;
  82016. crc16_update_word_(br, word);
  82017. br->consumed_words++;
  82018. br->consumed_bits = 0;
  82019. 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 */
  82020. *val <<= bits;
  82021. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  82022. br->consumed_bits = bits;
  82023. }
  82024. return true;
  82025. }
  82026. else {
  82027. const brword word = br->buffer[br->consumed_words];
  82028. if(bits < FLAC__BITS_PER_WORD) {
  82029. *val = word >> (FLAC__BITS_PER_WORD-bits);
  82030. br->consumed_bits = bits;
  82031. return true;
  82032. }
  82033. *val = word;
  82034. crc16_update_word_(br, word);
  82035. br->consumed_words++;
  82036. return true;
  82037. }
  82038. }
  82039. else {
  82040. if(br->consumed_bits) {
  82041. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  82042. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  82043. br->consumed_bits += bits;
  82044. return true;
  82045. }
  82046. else {
  82047. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  82048. br->consumed_bits += bits;
  82049. return true;
  82050. }
  82051. }
  82052. }
  82053. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  82054. {
  82055. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  82056. return false;
  82057. *val <<= (32-bits);
  82058. *val >>= (32-bits);
  82059. return true;
  82060. }
  82061. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  82062. {
  82063. FLAC__uint32 hi, lo;
  82064. if(bits > 32) {
  82065. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  82066. return false;
  82067. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  82068. return false;
  82069. *val = hi;
  82070. *val <<= 32;
  82071. *val |= lo;
  82072. }
  82073. else {
  82074. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  82075. return false;
  82076. *val = lo;
  82077. }
  82078. return true;
  82079. }
  82080. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  82081. {
  82082. FLAC__uint32 x8, x32 = 0;
  82083. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  82084. return false;
  82085. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82086. return false;
  82087. x32 |= (x8 << 8);
  82088. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82089. return false;
  82090. x32 |= (x8 << 16);
  82091. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82092. return false;
  82093. x32 |= (x8 << 24);
  82094. *val = x32;
  82095. return true;
  82096. }
  82097. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  82098. {
  82099. FLAC__ASSERT(0 != br);
  82100. FLAC__ASSERT(0 != br->buffer);
  82101. if(bits > 0) {
  82102. const unsigned n = br->consumed_bits & 7;
  82103. unsigned m;
  82104. FLAC__uint32 x;
  82105. if(n != 0) {
  82106. m = min(8-n, bits);
  82107. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  82108. return false;
  82109. bits -= m;
  82110. }
  82111. m = bits / 8;
  82112. if(m > 0) {
  82113. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  82114. return false;
  82115. bits %= 8;
  82116. }
  82117. if(bits > 0) {
  82118. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  82119. return false;
  82120. }
  82121. }
  82122. return true;
  82123. }
  82124. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  82125. {
  82126. FLAC__uint32 x;
  82127. FLAC__ASSERT(0 != br);
  82128. FLAC__ASSERT(0 != br->buffer);
  82129. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82130. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82131. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82132. return false;
  82133. nvals--;
  82134. }
  82135. if(0 == nvals)
  82136. return true;
  82137. while(nvals >= FLAC__BYTES_PER_WORD) {
  82138. if(br->consumed_words < br->words) {
  82139. br->consumed_words++;
  82140. nvals -= FLAC__BYTES_PER_WORD;
  82141. }
  82142. else if(!bitreader_read_from_client_(br))
  82143. return false;
  82144. }
  82145. while(nvals) {
  82146. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82147. return false;
  82148. nvals--;
  82149. }
  82150. return true;
  82151. }
  82152. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  82153. {
  82154. FLAC__uint32 x;
  82155. FLAC__ASSERT(0 != br);
  82156. FLAC__ASSERT(0 != br->buffer);
  82157. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82158. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82159. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82160. return false;
  82161. *val++ = (FLAC__byte)x;
  82162. nvals--;
  82163. }
  82164. if(0 == nvals)
  82165. return true;
  82166. while(nvals >= FLAC__BYTES_PER_WORD) {
  82167. if(br->consumed_words < br->words) {
  82168. const brword word = br->buffer[br->consumed_words++];
  82169. #if FLAC__BYTES_PER_WORD == 4
  82170. val[0] = (FLAC__byte)(word >> 24);
  82171. val[1] = (FLAC__byte)(word >> 16);
  82172. val[2] = (FLAC__byte)(word >> 8);
  82173. val[3] = (FLAC__byte)word;
  82174. #elif FLAC__BYTES_PER_WORD == 8
  82175. val[0] = (FLAC__byte)(word >> 56);
  82176. val[1] = (FLAC__byte)(word >> 48);
  82177. val[2] = (FLAC__byte)(word >> 40);
  82178. val[3] = (FLAC__byte)(word >> 32);
  82179. val[4] = (FLAC__byte)(word >> 24);
  82180. val[5] = (FLAC__byte)(word >> 16);
  82181. val[6] = (FLAC__byte)(word >> 8);
  82182. val[7] = (FLAC__byte)word;
  82183. #else
  82184. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  82185. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  82186. #endif
  82187. val += FLAC__BYTES_PER_WORD;
  82188. nvals -= FLAC__BYTES_PER_WORD;
  82189. }
  82190. else if(!bitreader_read_from_client_(br))
  82191. return false;
  82192. }
  82193. while(nvals) {
  82194. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82195. return false;
  82196. *val++ = (FLAC__byte)x;
  82197. nvals--;
  82198. }
  82199. return true;
  82200. }
  82201. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  82202. #if 0 /* slow but readable version */
  82203. {
  82204. unsigned bit;
  82205. FLAC__ASSERT(0 != br);
  82206. FLAC__ASSERT(0 != br->buffer);
  82207. *val = 0;
  82208. while(1) {
  82209. if(!FLAC__bitreader_read_bit(br, &bit))
  82210. return false;
  82211. if(bit)
  82212. break;
  82213. else
  82214. *val++;
  82215. }
  82216. return true;
  82217. }
  82218. #else
  82219. {
  82220. unsigned i;
  82221. FLAC__ASSERT(0 != br);
  82222. FLAC__ASSERT(0 != br->buffer);
  82223. *val = 0;
  82224. while(1) {
  82225. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82226. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  82227. if(b) {
  82228. i = COUNT_ZERO_MSBS(b);
  82229. *val += i;
  82230. i++;
  82231. br->consumed_bits += i;
  82232. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  82233. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82234. br->consumed_words++;
  82235. br->consumed_bits = 0;
  82236. }
  82237. return true;
  82238. }
  82239. else {
  82240. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  82241. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82242. br->consumed_words++;
  82243. br->consumed_bits = 0;
  82244. }
  82245. }
  82246. if(br->bytes) {
  82247. const unsigned end = br->bytes * 8;
  82248. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  82249. if(b) {
  82250. i = COUNT_ZERO_MSBS(b);
  82251. *val += i;
  82252. i++;
  82253. br->consumed_bits += i;
  82254. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82255. return true;
  82256. }
  82257. else {
  82258. *val += end - br->consumed_bits;
  82259. br->consumed_bits += end;
  82260. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82261. }
  82262. }
  82263. if(!bitreader_read_from_client_(br))
  82264. return false;
  82265. }
  82266. }
  82267. #endif
  82268. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82269. {
  82270. FLAC__uint32 lsbs = 0, msbs = 0;
  82271. unsigned uval;
  82272. FLAC__ASSERT(0 != br);
  82273. FLAC__ASSERT(0 != br->buffer);
  82274. FLAC__ASSERT(parameter <= 31);
  82275. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  82276. return false;
  82277. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  82278. return false;
  82279. uval = (msbs << parameter) | lsbs;
  82280. if(uval & 1)
  82281. *val = -((int)(uval >> 1)) - 1;
  82282. else
  82283. *val = (int)(uval >> 1);
  82284. return true;
  82285. }
  82286. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  82287. #ifdef _MSC_VER
  82288. {
  82289. unsigned i;
  82290. unsigned uval = 0;
  82291. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  82292. register unsigned cwords;
  82293. register unsigned cbits;
  82294. FLAC__ASSERT(0 != br);
  82295. FLAC__ASSERT(0 != br->buffer);
  82296. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82297. FLAC__ASSERT(parameter < 32);
  82298. if(nvals == 0)
  82299. return true;
  82300. cbits = br->consumed_bits;
  82301. cwords = br->consumed_words;
  82302. while(1) {
  82303. while(1) {
  82304. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82305. brword b = br->buffer[cwords] << cbits;
  82306. if(b) {
  82307. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82308. __asm {
  82309. bsr eax, b
  82310. not eax
  82311. and eax, 31
  82312. mov i, eax
  82313. }
  82314. #else
  82315. i = COUNT_ZERO_MSBS(b);
  82316. #endif
  82317. uval += i;
  82318. bits = parameter;
  82319. i++;
  82320. cbits += i;
  82321. if(cbits == FLAC__BITS_PER_WORD) {
  82322. crc16_update_word_(br, br->buffer[cwords]);
  82323. cwords++;
  82324. cbits = 0;
  82325. }
  82326. goto break1;
  82327. }
  82328. else {
  82329. uval += FLAC__BITS_PER_WORD - cbits;
  82330. crc16_update_word_(br, br->buffer[cwords]);
  82331. cwords++;
  82332. cbits = 0;
  82333. }
  82334. }
  82335. if(br->bytes) {
  82336. const unsigned end = br->bytes * 8;
  82337. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82338. if(b) {
  82339. i = COUNT_ZERO_MSBS(b);
  82340. uval += i;
  82341. bits = parameter;
  82342. i++;
  82343. cbits += i;
  82344. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82345. goto break1;
  82346. }
  82347. else {
  82348. uval += end - cbits;
  82349. cbits += end;
  82350. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82351. }
  82352. }
  82353. br->consumed_bits = cbits;
  82354. br->consumed_words = cwords;
  82355. if(!bitreader_read_from_client_(br))
  82356. return false;
  82357. cwords = br->consumed_words;
  82358. }
  82359. break1:
  82360. FLAC__ASSERT(cwords <= br->words);
  82361. if(bits) {
  82362. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  82363. br->consumed_bits = cbits;
  82364. br->consumed_words = cwords;
  82365. if(!bitreader_read_from_client_(br))
  82366. return false;
  82367. cwords = br->consumed_words;
  82368. }
  82369. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82370. if(cbits) {
  82371. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82372. const brword word = br->buffer[cwords];
  82373. if(bits < n) {
  82374. uval <<= bits;
  82375. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  82376. cbits += bits;
  82377. goto break2;
  82378. }
  82379. uval <<= n;
  82380. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82381. bits -= n;
  82382. crc16_update_word_(br, word);
  82383. cwords++;
  82384. cbits = 0;
  82385. 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 */
  82386. uval <<= bits;
  82387. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  82388. cbits = bits;
  82389. }
  82390. goto break2;
  82391. }
  82392. else {
  82393. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  82394. uval <<= bits;
  82395. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82396. cbits = bits;
  82397. goto break2;
  82398. }
  82399. }
  82400. else {
  82401. uval <<= bits;
  82402. if(cbits) {
  82403. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  82404. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  82405. cbits += bits;
  82406. goto break2;
  82407. }
  82408. else {
  82409. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82410. cbits += bits;
  82411. goto break2;
  82412. }
  82413. }
  82414. }
  82415. break2:
  82416. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82417. --nvals;
  82418. if(nvals == 0) {
  82419. br->consumed_bits = cbits;
  82420. br->consumed_words = cwords;
  82421. return true;
  82422. }
  82423. uval = 0;
  82424. ++vals;
  82425. }
  82426. }
  82427. #else
  82428. {
  82429. unsigned i;
  82430. unsigned uval = 0;
  82431. register unsigned cwords;
  82432. register unsigned cbits;
  82433. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82434. FLAC__ASSERT(0 != br);
  82435. FLAC__ASSERT(0 != br->buffer);
  82436. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82437. FLAC__ASSERT(parameter < 32);
  82438. if(nvals == 0)
  82439. return true;
  82440. cbits = br->consumed_bits;
  82441. cwords = br->consumed_words;
  82442. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82443. while(1) {
  82444. while(1) {
  82445. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82446. brword b = br->buffer[cwords] << cbits;
  82447. if(b) {
  82448. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82449. asm volatile (
  82450. "bsrl %1, %0;"
  82451. "notl %0;"
  82452. "andl $31, %0;"
  82453. : "=r"(i)
  82454. : "r"(b)
  82455. );
  82456. #else
  82457. i = COUNT_ZERO_MSBS(b);
  82458. #endif
  82459. uval += i;
  82460. cbits += i;
  82461. cbits++; /* skip over stop bit */
  82462. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82463. crc16_update_word_(br, br->buffer[cwords]);
  82464. cwords++;
  82465. cbits = 0;
  82466. }
  82467. goto break1;
  82468. }
  82469. else {
  82470. uval += FLAC__BITS_PER_WORD - cbits;
  82471. crc16_update_word_(br, br->buffer[cwords]);
  82472. cwords++;
  82473. cbits = 0;
  82474. }
  82475. }
  82476. if(br->bytes) {
  82477. const unsigned end = br->bytes * 8;
  82478. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82479. if(b) {
  82480. i = COUNT_ZERO_MSBS(b);
  82481. uval += i;
  82482. cbits += i;
  82483. cbits++; /* skip over stop bit */
  82484. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82485. goto break1;
  82486. }
  82487. else {
  82488. uval += end - cbits;
  82489. cbits += end;
  82490. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82491. }
  82492. }
  82493. br->consumed_bits = cbits;
  82494. br->consumed_words = cwords;
  82495. if(!bitreader_read_from_client_(br))
  82496. return false;
  82497. cwords = br->consumed_words;
  82498. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82499. }
  82500. break1:
  82501. ucbits -= uval;
  82502. ucbits--; /* account for stop bit */
  82503. FLAC__ASSERT(cwords <= br->words);
  82504. if(parameter) {
  82505. while(ucbits < parameter) {
  82506. br->consumed_bits = cbits;
  82507. br->consumed_words = cwords;
  82508. if(!bitreader_read_from_client_(br))
  82509. return false;
  82510. cwords = br->consumed_words;
  82511. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82512. }
  82513. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82514. if(cbits) {
  82515. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82516. const brword word = br->buffer[cwords];
  82517. if(parameter < n) {
  82518. uval <<= parameter;
  82519. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82520. cbits += parameter;
  82521. }
  82522. else {
  82523. uval <<= n;
  82524. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82525. crc16_update_word_(br, word);
  82526. cwords++;
  82527. cbits = parameter - n;
  82528. 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 */
  82529. uval <<= cbits;
  82530. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82531. }
  82532. }
  82533. }
  82534. else {
  82535. cbits = parameter;
  82536. uval <<= parameter;
  82537. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82538. }
  82539. }
  82540. else {
  82541. uval <<= parameter;
  82542. if(cbits) {
  82543. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82544. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82545. cbits += parameter;
  82546. }
  82547. else {
  82548. cbits = parameter;
  82549. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82550. }
  82551. }
  82552. }
  82553. ucbits -= parameter;
  82554. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82555. --nvals;
  82556. if(nvals == 0) {
  82557. br->consumed_bits = cbits;
  82558. br->consumed_words = cwords;
  82559. return true;
  82560. }
  82561. uval = 0;
  82562. ++vals;
  82563. }
  82564. }
  82565. #endif
  82566. #if 0 /* UNUSED */
  82567. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82568. {
  82569. FLAC__uint32 lsbs = 0, msbs = 0;
  82570. unsigned bit, uval, k;
  82571. FLAC__ASSERT(0 != br);
  82572. FLAC__ASSERT(0 != br->buffer);
  82573. k = FLAC__bitmath_ilog2(parameter);
  82574. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82575. return false;
  82576. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82577. return false;
  82578. if(parameter == 1u<<k) {
  82579. uval = (msbs << k) | lsbs;
  82580. }
  82581. else {
  82582. unsigned d = (1 << (k+1)) - parameter;
  82583. if(lsbs >= d) {
  82584. if(!FLAC__bitreader_read_bit(br, &bit))
  82585. return false;
  82586. lsbs <<= 1;
  82587. lsbs |= bit;
  82588. lsbs -= d;
  82589. }
  82590. uval = msbs * parameter + lsbs;
  82591. }
  82592. if(uval & 1)
  82593. *val = -((int)(uval >> 1)) - 1;
  82594. else
  82595. *val = (int)(uval >> 1);
  82596. return true;
  82597. }
  82598. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82599. {
  82600. FLAC__uint32 lsbs, msbs = 0;
  82601. unsigned bit, k;
  82602. FLAC__ASSERT(0 != br);
  82603. FLAC__ASSERT(0 != br->buffer);
  82604. k = FLAC__bitmath_ilog2(parameter);
  82605. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82606. return false;
  82607. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82608. return false;
  82609. if(parameter == 1u<<k) {
  82610. *val = (msbs << k) | lsbs;
  82611. }
  82612. else {
  82613. unsigned d = (1 << (k+1)) - parameter;
  82614. if(lsbs >= d) {
  82615. if(!FLAC__bitreader_read_bit(br, &bit))
  82616. return false;
  82617. lsbs <<= 1;
  82618. lsbs |= bit;
  82619. lsbs -= d;
  82620. }
  82621. *val = msbs * parameter + lsbs;
  82622. }
  82623. return true;
  82624. }
  82625. #endif /* UNUSED */
  82626. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82627. {
  82628. FLAC__uint32 v = 0;
  82629. FLAC__uint32 x;
  82630. unsigned i;
  82631. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82632. return false;
  82633. if(raw)
  82634. raw[(*rawlen)++] = (FLAC__byte)x;
  82635. if(!(x & 0x80)) { /* 0xxxxxxx */
  82636. v = x;
  82637. i = 0;
  82638. }
  82639. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82640. v = x & 0x1F;
  82641. i = 1;
  82642. }
  82643. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82644. v = x & 0x0F;
  82645. i = 2;
  82646. }
  82647. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82648. v = x & 0x07;
  82649. i = 3;
  82650. }
  82651. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82652. v = x & 0x03;
  82653. i = 4;
  82654. }
  82655. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82656. v = x & 0x01;
  82657. i = 5;
  82658. }
  82659. else {
  82660. *val = 0xffffffff;
  82661. return true;
  82662. }
  82663. for( ; i; i--) {
  82664. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82665. return false;
  82666. if(raw)
  82667. raw[(*rawlen)++] = (FLAC__byte)x;
  82668. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82669. *val = 0xffffffff;
  82670. return true;
  82671. }
  82672. v <<= 6;
  82673. v |= (x & 0x3F);
  82674. }
  82675. *val = v;
  82676. return true;
  82677. }
  82678. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  82679. {
  82680. FLAC__uint64 v = 0;
  82681. FLAC__uint32 x;
  82682. unsigned i;
  82683. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82684. return false;
  82685. if(raw)
  82686. raw[(*rawlen)++] = (FLAC__byte)x;
  82687. if(!(x & 0x80)) { /* 0xxxxxxx */
  82688. v = x;
  82689. i = 0;
  82690. }
  82691. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82692. v = x & 0x1F;
  82693. i = 1;
  82694. }
  82695. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82696. v = x & 0x0F;
  82697. i = 2;
  82698. }
  82699. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82700. v = x & 0x07;
  82701. i = 3;
  82702. }
  82703. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82704. v = x & 0x03;
  82705. i = 4;
  82706. }
  82707. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82708. v = x & 0x01;
  82709. i = 5;
  82710. }
  82711. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  82712. v = 0;
  82713. i = 6;
  82714. }
  82715. else {
  82716. *val = FLAC__U64L(0xffffffffffffffff);
  82717. return true;
  82718. }
  82719. for( ; i; i--) {
  82720. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82721. return false;
  82722. if(raw)
  82723. raw[(*rawlen)++] = (FLAC__byte)x;
  82724. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82725. *val = FLAC__U64L(0xffffffffffffffff);
  82726. return true;
  82727. }
  82728. v <<= 6;
  82729. v |= (x & 0x3F);
  82730. }
  82731. *val = v;
  82732. return true;
  82733. }
  82734. #endif
  82735. /*** End of inlined file: bitreader.c ***/
  82736. /*** Start of inlined file: bitwriter.c ***/
  82737. /*** Start of inlined file: juce_FlacHeader.h ***/
  82738. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82739. // tasks..
  82740. #define VERSION "1.2.1"
  82741. #define FLAC__NO_DLL 1
  82742. #if JUCE_MSVC
  82743. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82744. #endif
  82745. #if JUCE_MAC
  82746. #define FLAC__SYS_DARWIN 1
  82747. #endif
  82748. /*** End of inlined file: juce_FlacHeader.h ***/
  82749. #if JUCE_USE_FLAC
  82750. #if HAVE_CONFIG_H
  82751. # include <config.h>
  82752. #endif
  82753. #include <stdlib.h> /* for malloc() */
  82754. #include <string.h> /* for memcpy(), memset() */
  82755. #ifdef _MSC_VER
  82756. #include <winsock.h> /* for ntohl() */
  82757. #elif defined FLAC__SYS_DARWIN
  82758. #include <machine/endian.h> /* for ntohl() */
  82759. #elif defined __MINGW32__
  82760. #include <winsock.h> /* for ntohl() */
  82761. #else
  82762. #include <netinet/in.h> /* for ntohl() */
  82763. #endif
  82764. #if 0 /* UNUSED */
  82765. #endif
  82766. /*** Start of inlined file: bitwriter.h ***/
  82767. #ifndef FLAC__PRIVATE__BITWRITER_H
  82768. #define FLAC__PRIVATE__BITWRITER_H
  82769. #include <stdio.h> /* for FILE */
  82770. struct FLAC__BitWriter;
  82771. typedef struct FLAC__BitWriter FLAC__BitWriter;
  82772. FLAC__BitWriter *FLAC__bitwriter_new(void);
  82773. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  82774. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  82775. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  82776. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  82777. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  82778. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  82779. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  82780. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  82781. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  82782. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  82783. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  82784. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  82785. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  82786. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  82787. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  82788. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  82789. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  82790. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  82791. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  82792. #if 0 /* UNUSED */
  82793. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  82794. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  82795. #endif
  82796. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  82797. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  82798. #if 0 /* UNUSED */
  82799. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  82800. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  82801. #endif
  82802. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  82803. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  82804. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  82805. #endif
  82806. /*** End of inlined file: bitwriter.h ***/
  82807. /*** Start of inlined file: alloc.h ***/
  82808. #ifndef FLAC__SHARE__ALLOC_H
  82809. #define FLAC__SHARE__ALLOC_H
  82810. #if HAVE_CONFIG_H
  82811. # include <config.h>
  82812. #endif
  82813. #include <limits.h> /* for SIZE_MAX */
  82814. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  82815. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  82816. #endif
  82817. #include <stdlib.h> /* for size_t, malloc(), etc */
  82818. #ifndef SIZE_MAX
  82819. # ifndef SIZE_T_MAX
  82820. # ifdef _MSC_VER
  82821. # define SIZE_T_MAX UINT_MAX
  82822. # else
  82823. # error
  82824. # endif
  82825. # endif
  82826. # define SIZE_MAX SIZE_T_MAX
  82827. #endif
  82828. #ifndef FLaC__INLINE
  82829. #define FLaC__INLINE
  82830. #endif
  82831. static FLaC__INLINE void *safe_malloc_(size_t size)
  82832. {
  82833. if(!size)
  82834. size++;
  82835. return malloc(size);
  82836. }
  82837. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  82838. {
  82839. if(!nmemb || !size)
  82840. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82841. return calloc(nmemb, size);
  82842. }
  82843. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  82844. {
  82845. size2 += size1;
  82846. if(size2 < size1)
  82847. return 0;
  82848. return safe_malloc_(size2);
  82849. }
  82850. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  82851. {
  82852. size2 += size1;
  82853. if(size2 < size1)
  82854. return 0;
  82855. size3 += size2;
  82856. if(size3 < size2)
  82857. return 0;
  82858. return safe_malloc_(size3);
  82859. }
  82860. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  82861. {
  82862. size2 += size1;
  82863. if(size2 < size1)
  82864. return 0;
  82865. size3 += size2;
  82866. if(size3 < size2)
  82867. return 0;
  82868. size4 += size3;
  82869. if(size4 < size3)
  82870. return 0;
  82871. return safe_malloc_(size4);
  82872. }
  82873. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  82874. #if 0
  82875. needs support for cases where sizeof(size_t) != 4
  82876. {
  82877. if(sizeof(size_t) == 4) {
  82878. if ((double)size1 * (double)size2 < 4294967296.0)
  82879. return malloc(size1*size2);
  82880. }
  82881. return 0;
  82882. }
  82883. #else
  82884. {
  82885. if(!size1 || !size2)
  82886. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82887. if(size1 > SIZE_MAX / size2)
  82888. return 0;
  82889. return malloc(size1*size2);
  82890. }
  82891. #endif
  82892. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  82893. {
  82894. if(!size1 || !size2 || !size3)
  82895. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82896. if(size1 > SIZE_MAX / size2)
  82897. return 0;
  82898. size1 *= size2;
  82899. if(size1 > SIZE_MAX / size3)
  82900. return 0;
  82901. return malloc(size1*size3);
  82902. }
  82903. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  82904. {
  82905. if(!size1 || !size2)
  82906. return safe_malloc_(size3);
  82907. if(size1 > SIZE_MAX / size2)
  82908. return 0;
  82909. return safe_malloc_add_2op_(size1*size2, size3);
  82910. }
  82911. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  82912. {
  82913. if(!size1 || (!size2 && !size3))
  82914. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82915. size2 += size3;
  82916. if(size2 < size3)
  82917. return 0;
  82918. return safe_malloc_mul_2op_(size1, size2);
  82919. }
  82920. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  82921. {
  82922. size2 += size1;
  82923. if(size2 < size1)
  82924. return 0;
  82925. return realloc(ptr, size2);
  82926. }
  82927. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  82928. {
  82929. size2 += size1;
  82930. if(size2 < size1)
  82931. return 0;
  82932. size3 += size2;
  82933. if(size3 < size2)
  82934. return 0;
  82935. return realloc(ptr, size3);
  82936. }
  82937. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  82938. {
  82939. size2 += size1;
  82940. if(size2 < size1)
  82941. return 0;
  82942. size3 += size2;
  82943. if(size3 < size2)
  82944. return 0;
  82945. size4 += size3;
  82946. if(size4 < size3)
  82947. return 0;
  82948. return realloc(ptr, size4);
  82949. }
  82950. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  82951. {
  82952. if(!size1 || !size2)
  82953. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82954. if(size1 > SIZE_MAX / size2)
  82955. return 0;
  82956. return realloc(ptr, size1*size2);
  82957. }
  82958. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  82959. {
  82960. if(!size1 || (!size2 && !size3))
  82961. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82962. size2 += size3;
  82963. if(size2 < size3)
  82964. return 0;
  82965. return safe_realloc_mul_2op_(ptr, size1, size2);
  82966. }
  82967. #endif
  82968. /*** End of inlined file: alloc.h ***/
  82969. typedef FLAC__uint32 bwword;
  82970. #define FLAC__BYTES_PER_WORD 4
  82971. #define FLAC__BITS_PER_WORD 32
  82972. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  82973. #if WORDS_BIGENDIAN
  82974. #define SWAP_BE_WORD_TO_HOST(x) (x)
  82975. #else
  82976. #ifdef _MSC_VER
  82977. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82978. #else
  82979. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82980. #endif
  82981. #endif
  82982. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  82983. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  82984. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  82985. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  82986. #ifdef min
  82987. #undef min
  82988. #endif
  82989. #define min(x,y) ((x)<(y)?(x):(y))
  82990. #ifdef _MSC_VER
  82991. #define FLAC__U64L(x) x
  82992. #else
  82993. #define FLAC__U64L(x) x##LLU
  82994. #endif
  82995. #ifndef FLaC__INLINE
  82996. #define FLaC__INLINE
  82997. #endif
  82998. struct FLAC__BitWriter {
  82999. bwword *buffer;
  83000. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  83001. unsigned capacity; /* capacity of buffer in words */
  83002. unsigned words; /* # of complete words in buffer */
  83003. unsigned bits; /* # of used bits in accum */
  83004. };
  83005. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  83006. {
  83007. unsigned new_capacity;
  83008. bwword *new_buffer;
  83009. FLAC__ASSERT(0 != bw);
  83010. FLAC__ASSERT(0 != bw->buffer);
  83011. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  83012. if(bw->capacity >= new_capacity)
  83013. return true;
  83014. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  83015. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83016. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83017. FLAC__ASSERT(new_capacity > bw->capacity);
  83018. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  83019. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  83020. if(new_buffer == 0)
  83021. return false;
  83022. bw->buffer = new_buffer;
  83023. bw->capacity = new_capacity;
  83024. return true;
  83025. }
  83026. FLAC__BitWriter *FLAC__bitwriter_new(void)
  83027. {
  83028. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  83029. return bw;
  83030. }
  83031. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  83032. {
  83033. FLAC__ASSERT(0 != bw);
  83034. FLAC__bitwriter_free(bw);
  83035. free(bw);
  83036. }
  83037. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  83038. {
  83039. FLAC__ASSERT(0 != bw);
  83040. bw->words = bw->bits = 0;
  83041. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  83042. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  83043. if(bw->buffer == 0)
  83044. return false;
  83045. return true;
  83046. }
  83047. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  83048. {
  83049. FLAC__ASSERT(0 != bw);
  83050. if(0 != bw->buffer)
  83051. free(bw->buffer);
  83052. bw->buffer = 0;
  83053. bw->capacity = 0;
  83054. bw->words = bw->bits = 0;
  83055. }
  83056. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  83057. {
  83058. bw->words = bw->bits = 0;
  83059. }
  83060. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  83061. {
  83062. unsigned i, j;
  83063. if(bw == 0) {
  83064. fprintf(out, "bitwriter is NULL\n");
  83065. }
  83066. else {
  83067. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  83068. for(i = 0; i < bw->words; i++) {
  83069. fprintf(out, "%08X: ", i);
  83070. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  83071. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  83072. fprintf(out, "\n");
  83073. }
  83074. if(bw->bits > 0) {
  83075. fprintf(out, "%08X: ", i);
  83076. for(j = 0; j < bw->bits; j++)
  83077. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  83078. fprintf(out, "\n");
  83079. }
  83080. }
  83081. }
  83082. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  83083. {
  83084. const FLAC__byte *buffer;
  83085. size_t bytes;
  83086. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83087. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83088. return false;
  83089. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  83090. FLAC__bitwriter_release_buffer(bw);
  83091. return true;
  83092. }
  83093. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  83094. {
  83095. const FLAC__byte *buffer;
  83096. size_t bytes;
  83097. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83098. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83099. return false;
  83100. *crc = FLAC__crc8(buffer, bytes);
  83101. FLAC__bitwriter_release_buffer(bw);
  83102. return true;
  83103. }
  83104. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  83105. {
  83106. return ((bw->bits & 7) == 0);
  83107. }
  83108. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  83109. {
  83110. return FLAC__TOTAL_BITS(bw);
  83111. }
  83112. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  83113. {
  83114. FLAC__ASSERT((bw->bits & 7) == 0);
  83115. if(bw->bits & 7)
  83116. return false;
  83117. if(bw->bits) {
  83118. FLAC__ASSERT(bw->words <= bw->capacity);
  83119. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  83120. return false;
  83121. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  83122. }
  83123. *buffer = (FLAC__byte*)bw->buffer;
  83124. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  83125. return true;
  83126. }
  83127. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  83128. {
  83129. (void)bw;
  83130. }
  83131. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  83132. {
  83133. unsigned n;
  83134. FLAC__ASSERT(0 != bw);
  83135. FLAC__ASSERT(0 != bw->buffer);
  83136. if(bits == 0)
  83137. return true;
  83138. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83139. return false;
  83140. if(bw->bits) {
  83141. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  83142. bw->accum <<= n;
  83143. bits -= n;
  83144. bw->bits += n;
  83145. if(bw->bits == FLAC__BITS_PER_WORD) {
  83146. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83147. bw->bits = 0;
  83148. }
  83149. else
  83150. return true;
  83151. }
  83152. while(bits >= FLAC__BITS_PER_WORD) {
  83153. bw->buffer[bw->words++] = 0;
  83154. bits -= FLAC__BITS_PER_WORD;
  83155. }
  83156. if(bits > 0) {
  83157. bw->accum = 0;
  83158. bw->bits = bits;
  83159. }
  83160. return true;
  83161. }
  83162. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  83163. {
  83164. register unsigned left;
  83165. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83166. FLAC__ASSERT(0 != bw);
  83167. FLAC__ASSERT(0 != bw->buffer);
  83168. FLAC__ASSERT(bits <= 32);
  83169. if(bits == 0)
  83170. return true;
  83171. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83172. return false;
  83173. left = FLAC__BITS_PER_WORD - bw->bits;
  83174. if(bits < left) {
  83175. bw->accum <<= bits;
  83176. bw->accum |= val;
  83177. bw->bits += bits;
  83178. }
  83179. 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 */
  83180. bw->accum <<= left;
  83181. bw->accum |= val >> (bw->bits = bits - left);
  83182. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83183. bw->accum = val;
  83184. }
  83185. else {
  83186. bw->accum = val;
  83187. bw->bits = 0;
  83188. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  83189. }
  83190. return true;
  83191. }
  83192. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  83193. {
  83194. if(bits < 32)
  83195. val &= (~(0xffffffff << bits));
  83196. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83197. }
  83198. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  83199. {
  83200. if(bits > 32) {
  83201. return
  83202. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  83203. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  83204. }
  83205. else
  83206. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83207. }
  83208. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  83209. {
  83210. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  83211. return false;
  83212. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  83213. return false;
  83214. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  83215. return false;
  83216. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  83217. return false;
  83218. return true;
  83219. }
  83220. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  83221. {
  83222. unsigned i;
  83223. for(i = 0; i < nvals; i++) {
  83224. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  83225. return false;
  83226. }
  83227. return true;
  83228. }
  83229. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  83230. {
  83231. if(val < 32)
  83232. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  83233. else
  83234. return
  83235. FLAC__bitwriter_write_zeroes(bw, val) &&
  83236. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  83237. }
  83238. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  83239. {
  83240. FLAC__uint32 uval;
  83241. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  83242. uval = (val<<1) ^ (val>>31);
  83243. return 1 + parameter + (uval >> parameter);
  83244. }
  83245. #if 0 /* UNUSED */
  83246. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  83247. {
  83248. unsigned bits, msbs, uval;
  83249. unsigned k;
  83250. FLAC__ASSERT(parameter > 0);
  83251. if(val < 0)
  83252. uval = (unsigned)(((-(++val)) << 1) + 1);
  83253. else
  83254. uval = (unsigned)(val << 1);
  83255. k = FLAC__bitmath_ilog2(parameter);
  83256. if(parameter == 1u<<k) {
  83257. FLAC__ASSERT(k <= 30);
  83258. msbs = uval >> k;
  83259. bits = 1 + k + msbs;
  83260. }
  83261. else {
  83262. unsigned q, r, d;
  83263. d = (1 << (k+1)) - parameter;
  83264. q = uval / parameter;
  83265. r = uval - (q * parameter);
  83266. bits = 1 + q + k;
  83267. if(r >= d)
  83268. bits++;
  83269. }
  83270. return bits;
  83271. }
  83272. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  83273. {
  83274. unsigned bits, msbs;
  83275. unsigned k;
  83276. FLAC__ASSERT(parameter > 0);
  83277. k = FLAC__bitmath_ilog2(parameter);
  83278. if(parameter == 1u<<k) {
  83279. FLAC__ASSERT(k <= 30);
  83280. msbs = uval >> k;
  83281. bits = 1 + k + msbs;
  83282. }
  83283. else {
  83284. unsigned q, r, d;
  83285. d = (1 << (k+1)) - parameter;
  83286. q = uval / parameter;
  83287. r = uval - (q * parameter);
  83288. bits = 1 + q + k;
  83289. if(r >= d)
  83290. bits++;
  83291. }
  83292. return bits;
  83293. }
  83294. #endif /* UNUSED */
  83295. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83296. {
  83297. unsigned total_bits, interesting_bits, msbs;
  83298. FLAC__uint32 uval, pattern;
  83299. FLAC__ASSERT(0 != bw);
  83300. FLAC__ASSERT(0 != bw->buffer);
  83301. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83302. uval = (val<<1) ^ (val>>31);
  83303. msbs = uval >> parameter;
  83304. interesting_bits = 1 + parameter;
  83305. total_bits = interesting_bits + msbs;
  83306. pattern = 1 << parameter; /* the unary end bit */
  83307. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83308. if(total_bits <= 32)
  83309. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83310. else
  83311. return
  83312. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83313. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83314. }
  83315. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83316. {
  83317. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83318. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83319. FLAC__uint32 uval;
  83320. unsigned left;
  83321. const unsigned lsbits = 1 + parameter;
  83322. unsigned msbits;
  83323. FLAC__ASSERT(0 != bw);
  83324. FLAC__ASSERT(0 != bw->buffer);
  83325. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83326. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83327. while(nvals) {
  83328. uval = (*vals<<1) ^ (*vals>>31);
  83329. msbits = uval >> parameter;
  83330. #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) */
  83331. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83332. bw->bits = bw->bits + msbits + lsbits;
  83333. uval |= mask1; /* set stop bit */
  83334. uval &= mask2; /* mask off unused top bits */
  83335. bw->accum <<= msbits;
  83336. bw->accum <<= lsbits;
  83337. bw->accum |= uval;
  83338. if(bw->bits == FLAC__BITS_PER_WORD) {
  83339. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83340. bw->bits = 0;
  83341. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83342. FLAC__ASSERT(bw->capacity == bw->words);
  83343. return false;
  83344. }
  83345. }
  83346. }
  83347. else {
  83348. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83349. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83350. bw->bits = bw->bits + msbits + lsbits;
  83351. uval |= mask1; /* set stop bit */
  83352. uval &= mask2; /* mask off unused top bits */
  83353. bw->accum <<= msbits + lsbits;
  83354. bw->accum |= uval;
  83355. }
  83356. else {
  83357. #endif
  83358. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83359. return false;
  83360. if(msbits) {
  83361. if(bw->bits) {
  83362. left = FLAC__BITS_PER_WORD - bw->bits;
  83363. if(msbits < left) {
  83364. bw->accum <<= msbits;
  83365. bw->bits += msbits;
  83366. goto break1;
  83367. }
  83368. else {
  83369. bw->accum <<= left;
  83370. msbits -= left;
  83371. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83372. bw->bits = 0;
  83373. }
  83374. }
  83375. while(msbits >= FLAC__BITS_PER_WORD) {
  83376. bw->buffer[bw->words++] = 0;
  83377. msbits -= FLAC__BITS_PER_WORD;
  83378. }
  83379. if(msbits > 0) {
  83380. bw->accum = 0;
  83381. bw->bits = msbits;
  83382. }
  83383. }
  83384. break1:
  83385. uval |= mask1; /* set stop bit */
  83386. uval &= mask2; /* mask off unused top bits */
  83387. left = FLAC__BITS_PER_WORD - bw->bits;
  83388. if(lsbits < left) {
  83389. bw->accum <<= lsbits;
  83390. bw->accum |= uval;
  83391. bw->bits += lsbits;
  83392. }
  83393. else {
  83394. FLAC__ASSERT(bw->bits);
  83395. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  83396. bw->accum <<= left;
  83397. bw->accum |= uval >> (bw->bits = lsbits - left);
  83398. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83399. bw->accum = uval;
  83400. }
  83401. #if 1
  83402. }
  83403. #endif
  83404. vals++;
  83405. nvals--;
  83406. }
  83407. return true;
  83408. }
  83409. #if 0 /* UNUSED */
  83410. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83411. {
  83412. unsigned total_bits, msbs, uval;
  83413. unsigned k;
  83414. FLAC__ASSERT(0 != bw);
  83415. FLAC__ASSERT(0 != bw->buffer);
  83416. FLAC__ASSERT(parameter > 0);
  83417. if(val < 0)
  83418. uval = (unsigned)(((-(++val)) << 1) + 1);
  83419. else
  83420. uval = (unsigned)(val << 1);
  83421. k = FLAC__bitmath_ilog2(parameter);
  83422. if(parameter == 1u<<k) {
  83423. unsigned pattern;
  83424. FLAC__ASSERT(k <= 30);
  83425. msbs = uval >> k;
  83426. total_bits = 1 + k + msbs;
  83427. pattern = 1 << k; /* the unary end bit */
  83428. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83429. if(total_bits <= 32) {
  83430. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83431. return false;
  83432. }
  83433. else {
  83434. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83435. return false;
  83436. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83437. return false;
  83438. }
  83439. }
  83440. else {
  83441. unsigned q, r, d;
  83442. d = (1 << (k+1)) - parameter;
  83443. q = uval / parameter;
  83444. r = uval - (q * parameter);
  83445. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83446. return false;
  83447. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83448. return false;
  83449. if(r >= d) {
  83450. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83451. return false;
  83452. }
  83453. else {
  83454. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83455. return false;
  83456. }
  83457. }
  83458. return true;
  83459. }
  83460. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83461. {
  83462. unsigned total_bits, msbs;
  83463. unsigned k;
  83464. FLAC__ASSERT(0 != bw);
  83465. FLAC__ASSERT(0 != bw->buffer);
  83466. FLAC__ASSERT(parameter > 0);
  83467. k = FLAC__bitmath_ilog2(parameter);
  83468. if(parameter == 1u<<k) {
  83469. unsigned pattern;
  83470. FLAC__ASSERT(k <= 30);
  83471. msbs = uval >> k;
  83472. total_bits = 1 + k + msbs;
  83473. pattern = 1 << k; /* the unary end bit */
  83474. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83475. if(total_bits <= 32) {
  83476. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83477. return false;
  83478. }
  83479. else {
  83480. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83481. return false;
  83482. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83483. return false;
  83484. }
  83485. }
  83486. else {
  83487. unsigned q, r, d;
  83488. d = (1 << (k+1)) - parameter;
  83489. q = uval / parameter;
  83490. r = uval - (q * parameter);
  83491. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83492. return false;
  83493. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83494. return false;
  83495. if(r >= d) {
  83496. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83497. return false;
  83498. }
  83499. else {
  83500. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83501. return false;
  83502. }
  83503. }
  83504. return true;
  83505. }
  83506. #endif /* UNUSED */
  83507. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83508. {
  83509. FLAC__bool ok = 1;
  83510. FLAC__ASSERT(0 != bw);
  83511. FLAC__ASSERT(0 != bw->buffer);
  83512. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83513. if(val < 0x80) {
  83514. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83515. }
  83516. else if(val < 0x800) {
  83517. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83518. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83519. }
  83520. else if(val < 0x10000) {
  83521. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83522. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83523. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83524. }
  83525. else if(val < 0x200000) {
  83526. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83527. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83528. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83529. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83530. }
  83531. else if(val < 0x4000000) {
  83532. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83533. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83534. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83535. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83536. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83537. }
  83538. else {
  83539. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83540. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83541. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83542. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83543. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83544. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83545. }
  83546. return ok;
  83547. }
  83548. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83549. {
  83550. FLAC__bool ok = 1;
  83551. FLAC__ASSERT(0 != bw);
  83552. FLAC__ASSERT(0 != bw->buffer);
  83553. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83554. if(val < 0x80) {
  83555. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83556. }
  83557. else if(val < 0x800) {
  83558. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83559. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83560. }
  83561. else if(val < 0x10000) {
  83562. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83563. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83564. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83565. }
  83566. else if(val < 0x200000) {
  83567. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83568. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83569. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83570. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83571. }
  83572. else if(val < 0x4000000) {
  83573. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83574. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83575. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83576. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83577. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83578. }
  83579. else if(val < 0x80000000) {
  83580. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83581. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83582. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83583. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83584. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83585. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83586. }
  83587. else {
  83588. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83589. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83590. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83591. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83592. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83593. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83594. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83595. }
  83596. return ok;
  83597. }
  83598. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83599. {
  83600. if(bw->bits & 7u)
  83601. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83602. else
  83603. return true;
  83604. }
  83605. #endif
  83606. /*** End of inlined file: bitwriter.c ***/
  83607. /*** Start of inlined file: cpu.c ***/
  83608. /*** Start of inlined file: juce_FlacHeader.h ***/
  83609. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83610. // tasks..
  83611. #define VERSION "1.2.1"
  83612. #define FLAC__NO_DLL 1
  83613. #if JUCE_MSVC
  83614. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83615. #endif
  83616. #if JUCE_MAC
  83617. #define FLAC__SYS_DARWIN 1
  83618. #endif
  83619. /*** End of inlined file: juce_FlacHeader.h ***/
  83620. #if JUCE_USE_FLAC
  83621. #if HAVE_CONFIG_H
  83622. # include <config.h>
  83623. #endif
  83624. #include <stdlib.h>
  83625. #include <stdio.h>
  83626. #if defined FLAC__CPU_IA32
  83627. # include <signal.h>
  83628. #elif defined FLAC__CPU_PPC
  83629. # if !defined FLAC__NO_ASM
  83630. # if defined FLAC__SYS_DARWIN
  83631. # include <sys/sysctl.h>
  83632. # include <mach/mach.h>
  83633. # include <mach/mach_host.h>
  83634. # include <mach/host_info.h>
  83635. # include <mach/machine.h>
  83636. # ifndef CPU_SUBTYPE_POWERPC_970
  83637. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83638. # endif
  83639. # else /* FLAC__SYS_DARWIN */
  83640. # include <signal.h>
  83641. # include <setjmp.h>
  83642. static sigjmp_buf jmpbuf;
  83643. static volatile sig_atomic_t canjump = 0;
  83644. static void sigill_handler (int sig)
  83645. {
  83646. if (!canjump) {
  83647. signal (sig, SIG_DFL);
  83648. raise (sig);
  83649. }
  83650. canjump = 0;
  83651. siglongjmp (jmpbuf, 1);
  83652. }
  83653. # endif /* FLAC__SYS_DARWIN */
  83654. # endif /* FLAC__NO_ASM */
  83655. #endif /* FLAC__CPU_PPC */
  83656. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83657. #include <sys/param.h>
  83658. #include <sys/sysctl.h>
  83659. #include <machine/cpu.h>
  83660. #endif
  83661. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83662. #include <sys/types.h>
  83663. #include <sys/sysctl.h>
  83664. #endif
  83665. #if defined(__APPLE__)
  83666. #endif
  83667. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83668. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83669. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83670. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  83671. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  83672. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  83673. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  83674. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  83675. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  83676. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  83677. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  83678. # if defined(__linux__)
  83679. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  83680. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83681. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  83682. {
  83683. (void)signal;
  83684. sc.eip += 3 + 3 + 6;
  83685. }
  83686. # else
  83687. # include <sys/ucontext.h>
  83688. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  83689. {
  83690. (void)signal, (void)si;
  83691. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  83692. }
  83693. # endif
  83694. # elif defined(_MSC_VER)
  83695. # include <windows.h>
  83696. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  83697. # ifdef USE_TRY_CATCH_FLAVOR
  83698. # else
  83699. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  83700. {
  83701. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  83702. ep->ContextRecord->Eip += 3 + 3 + 6;
  83703. return EXCEPTION_CONTINUE_EXECUTION;
  83704. }
  83705. return EXCEPTION_CONTINUE_SEARCH;
  83706. }
  83707. # endif
  83708. # endif
  83709. #endif
  83710. void FLAC__cpu_info(FLAC__CPUInfo *info)
  83711. {
  83712. #ifdef FLAC__CPU_IA32
  83713. info->type = FLAC__CPUINFO_TYPE_IA32;
  83714. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  83715. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  83716. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  83717. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  83718. info->data.ia32.cmov = false;
  83719. info->data.ia32.mmx = false;
  83720. info->data.ia32.fxsr = false;
  83721. info->data.ia32.sse = false;
  83722. info->data.ia32.sse2 = false;
  83723. info->data.ia32.sse3 = false;
  83724. info->data.ia32.ssse3 = false;
  83725. info->data.ia32._3dnow = false;
  83726. info->data.ia32.ext3dnow = false;
  83727. info->data.ia32.extmmx = false;
  83728. if(info->data.ia32.cpuid) {
  83729. FLAC__uint32 flags_edx, flags_ecx;
  83730. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  83731. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  83732. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  83733. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  83734. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  83735. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  83736. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  83737. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  83738. #ifdef FLAC__USE_3DNOW
  83739. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  83740. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  83741. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  83742. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  83743. #else
  83744. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  83745. #endif
  83746. #ifdef DEBUG
  83747. fprintf(stderr, "CPU info (IA-32):\n");
  83748. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  83749. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  83750. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  83751. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  83752. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  83753. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83754. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  83755. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  83756. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  83757. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  83758. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  83759. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  83760. #endif
  83761. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  83762. #if defined FLAC__NO_SSE_OS
  83763. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83764. #elif defined FLAC__SSE_OS
  83765. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  83766. int sse = 0;
  83767. size_t len;
  83768. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  83769. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  83770. if(!sse)
  83771. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83772. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  83773. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  83774. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  83775. size_t len = sizeof(val);
  83776. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83777. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83778. else { /* double-check SSE2 */
  83779. mib[1] = CPU_SSE2;
  83780. len = sizeof(val);
  83781. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83782. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83783. }
  83784. # else
  83785. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83786. # endif
  83787. #elif defined(__linux__)
  83788. int sse = 0;
  83789. struct sigaction sigill_save;
  83790. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83791. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  83792. #else
  83793. struct sigaction sigill_sse;
  83794. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  83795. __sigemptyset(&sigill_sse.sa_mask);
  83796. 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 */
  83797. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  83798. #endif
  83799. {
  83800. asm volatile (
  83801. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  83802. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  83803. "incl %0\n\t" /* SIGILL handler will jump over this */
  83804. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  83805. "nop\n\t"
  83806. "nop\n\t"
  83807. "nop\n\t"
  83808. "nop\n\t"
  83809. "nop\n\t"
  83810. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  83811. "nop\n\t"
  83812. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  83813. : "=r"(sse)
  83814. : "r"(sse)
  83815. );
  83816. sigaction(SIGILL, &sigill_save, NULL);
  83817. }
  83818. if(!sse)
  83819. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83820. #elif defined(_MSC_VER)
  83821. # ifdef USE_TRY_CATCH_FLAVOR
  83822. _try {
  83823. __asm {
  83824. # if _MSC_VER <= 1200
  83825. _emit 0x0F
  83826. _emit 0x57
  83827. _emit 0xC0
  83828. # else
  83829. xorps xmm0,xmm0
  83830. # endif
  83831. }
  83832. }
  83833. _except(EXCEPTION_EXECUTE_HANDLER) {
  83834. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  83835. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83836. }
  83837. # else
  83838. int sse = 0;
  83839. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  83840. __asm {
  83841. # if _MSC_VER <= 1200
  83842. _emit 0x0F
  83843. _emit 0x57
  83844. _emit 0xC0
  83845. # else
  83846. xorps xmm0,xmm0
  83847. # endif
  83848. inc sse
  83849. nop
  83850. nop
  83851. nop
  83852. nop
  83853. nop
  83854. nop
  83855. nop
  83856. nop
  83857. nop
  83858. }
  83859. SetUnhandledExceptionFilter(save);
  83860. if(!sse)
  83861. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83862. # endif
  83863. #else
  83864. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83865. #endif
  83866. #ifdef DEBUG
  83867. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83868. #endif
  83869. }
  83870. }
  83871. #else
  83872. info->use_asm = false;
  83873. #endif
  83874. #elif defined FLAC__CPU_PPC
  83875. info->type = FLAC__CPUINFO_TYPE_PPC;
  83876. # if !defined FLAC__NO_ASM
  83877. info->use_asm = true;
  83878. # ifdef FLAC__USE_ALTIVEC
  83879. # if defined FLAC__SYS_DARWIN
  83880. {
  83881. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  83882. size_t len = sizeof(val);
  83883. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  83884. }
  83885. {
  83886. host_basic_info_data_t hostInfo;
  83887. mach_msg_type_number_t infoCount;
  83888. infoCount = HOST_BASIC_INFO_COUNT;
  83889. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  83890. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  83891. }
  83892. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  83893. {
  83894. info->data.ppc.altivec = 0;
  83895. info->data.ppc.ppc64 = 0;
  83896. signal (SIGILL, sigill_handler);
  83897. canjump = 0;
  83898. if (!sigsetjmp (jmpbuf, 1)) {
  83899. canjump = 1;
  83900. asm volatile (
  83901. "mtspr 256, %0\n\t"
  83902. "vand %%v0, %%v0, %%v0"
  83903. :
  83904. : "r" (-1)
  83905. );
  83906. info->data.ppc.altivec = 1;
  83907. }
  83908. canjump = 0;
  83909. if (!sigsetjmp (jmpbuf, 1)) {
  83910. int x = 0;
  83911. canjump = 1;
  83912. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  83913. info->data.ppc.ppc64 = 1;
  83914. }
  83915. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  83916. }
  83917. # endif
  83918. # else /* !FLAC__USE_ALTIVEC */
  83919. info->data.ppc.altivec = 0;
  83920. info->data.ppc.ppc64 = 0;
  83921. # endif
  83922. # else
  83923. info->use_asm = false;
  83924. # endif
  83925. #else
  83926. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  83927. info->use_asm = false;
  83928. #endif
  83929. }
  83930. #endif
  83931. /*** End of inlined file: cpu.c ***/
  83932. /*** Start of inlined file: crc.c ***/
  83933. /*** Start of inlined file: juce_FlacHeader.h ***/
  83934. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83935. // tasks..
  83936. #define VERSION "1.2.1"
  83937. #define FLAC__NO_DLL 1
  83938. #if JUCE_MSVC
  83939. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83940. #endif
  83941. #if JUCE_MAC
  83942. #define FLAC__SYS_DARWIN 1
  83943. #endif
  83944. /*** End of inlined file: juce_FlacHeader.h ***/
  83945. #if JUCE_USE_FLAC
  83946. #if HAVE_CONFIG_H
  83947. # include <config.h>
  83948. #endif
  83949. FLAC__byte const FLAC__crc8_table[256] = {
  83950. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  83951. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  83952. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  83953. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  83954. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  83955. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  83956. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  83957. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  83958. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  83959. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  83960. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  83961. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  83962. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  83963. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  83964. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  83965. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  83966. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  83967. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  83968. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  83969. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  83970. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  83971. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  83972. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  83973. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  83974. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  83975. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  83976. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  83977. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  83978. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  83979. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  83980. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  83981. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  83982. };
  83983. unsigned FLAC__crc16_table[256] = {
  83984. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  83985. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  83986. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  83987. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  83988. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  83989. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  83990. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  83991. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  83992. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  83993. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  83994. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  83995. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  83996. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  83997. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  83998. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  83999. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  84000. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  84001. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  84002. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  84003. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  84004. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  84005. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  84006. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  84007. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  84008. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  84009. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  84010. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  84011. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  84012. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  84013. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  84014. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  84015. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  84016. };
  84017. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  84018. {
  84019. *crc = FLAC__crc8_table[*crc ^ data];
  84020. }
  84021. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  84022. {
  84023. while(len--)
  84024. *crc = FLAC__crc8_table[*crc ^ *data++];
  84025. }
  84026. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  84027. {
  84028. FLAC__uint8 crc = 0;
  84029. while(len--)
  84030. crc = FLAC__crc8_table[crc ^ *data++];
  84031. return crc;
  84032. }
  84033. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  84034. {
  84035. unsigned crc = 0;
  84036. while(len--)
  84037. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  84038. return crc;
  84039. }
  84040. #endif
  84041. /*** End of inlined file: crc.c ***/
  84042. /*** Start of inlined file: fixed.c ***/
  84043. /*** Start of inlined file: juce_FlacHeader.h ***/
  84044. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84045. // tasks..
  84046. #define VERSION "1.2.1"
  84047. #define FLAC__NO_DLL 1
  84048. #if JUCE_MSVC
  84049. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84050. #endif
  84051. #if JUCE_MAC
  84052. #define FLAC__SYS_DARWIN 1
  84053. #endif
  84054. /*** End of inlined file: juce_FlacHeader.h ***/
  84055. #if JUCE_USE_FLAC
  84056. #if HAVE_CONFIG_H
  84057. # include <config.h>
  84058. #endif
  84059. #include <math.h>
  84060. #include <string.h>
  84061. /*** Start of inlined file: fixed.h ***/
  84062. #ifndef FLAC__PRIVATE__FIXED_H
  84063. #define FLAC__PRIVATE__FIXED_H
  84064. #ifdef HAVE_CONFIG_H
  84065. #include <config.h>
  84066. #endif
  84067. /*** Start of inlined file: float.h ***/
  84068. #ifndef FLAC__PRIVATE__FLOAT_H
  84069. #define FLAC__PRIVATE__FLOAT_H
  84070. #ifdef HAVE_CONFIG_H
  84071. #include <config.h>
  84072. #endif
  84073. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84074. typedef double FLAC__double;
  84075. typedef float FLAC__float;
  84076. typedef float FLAC__real;
  84077. #else
  84078. typedef FLAC__int32 FLAC__fixedpoint;
  84079. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  84080. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  84081. extern const FLAC__fixedpoint FLAC__FP_ONE;
  84082. extern const FLAC__fixedpoint FLAC__FP_LN2;
  84083. extern const FLAC__fixedpoint FLAC__FP_E;
  84084. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  84085. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  84086. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  84087. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  84088. #endif
  84089. #endif
  84090. /*** End of inlined file: float.h ***/
  84091. /*** Start of inlined file: format.h ***/
  84092. #ifndef FLAC__PRIVATE__FORMAT_H
  84093. #define FLAC__PRIVATE__FORMAT_H
  84094. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  84095. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  84096. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  84097. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84098. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84099. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  84100. #endif
  84101. /*** End of inlined file: format.h ***/
  84102. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84103. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84104. # ifndef FLAC__NO_ASM
  84105. # ifdef FLAC__CPU_IA32
  84106. # ifdef FLAC__HAS_NASM
  84107. 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]);
  84108. # endif
  84109. # endif
  84110. # endif
  84111. 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]);
  84112. #else
  84113. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84114. 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]);
  84115. #endif
  84116. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  84117. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  84118. #endif
  84119. /*** End of inlined file: fixed.h ***/
  84120. #ifndef M_LN2
  84121. #define M_LN2 0.69314718055994530942
  84122. #endif
  84123. #ifdef min
  84124. #undef min
  84125. #endif
  84126. #define min(x,y) ((x) < (y)? (x) : (y))
  84127. #ifdef local_abs
  84128. #undef local_abs
  84129. #endif
  84130. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  84131. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84132. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  84133. {
  84134. FLAC__uint32 rbps;
  84135. unsigned bits; /* the number of bits required to represent a number */
  84136. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84137. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84138. FLAC__ASSERT(err > 0);
  84139. FLAC__ASSERT(n > 0);
  84140. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84141. if(err <= n)
  84142. return 0;
  84143. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  84144. err <<= fracbits;
  84145. err /= n;
  84146. FLAC__ASSERT(err > 0);
  84147. bits = FLAC__bitmath_ilog2(err)+1;
  84148. if(bits > 16) {
  84149. err >>= (bits-16);
  84150. fracbits -= (bits-16);
  84151. }
  84152. rbps = (FLAC__uint32)err;
  84153. rbps *= FLAC__FP_LN2;
  84154. fracbits += 16;
  84155. FLAC__ASSERT(fracbits >= 0);
  84156. {
  84157. const int f = fracbits & 3;
  84158. if(f) {
  84159. rbps >>= f;
  84160. fracbits -= f;
  84161. }
  84162. }
  84163. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84164. if(rbps == 0)
  84165. return 0;
  84166. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84167. FLAC__ASSERT(fracbits >= -3);
  84168. if(fracbits < 16)
  84169. return rbps << (16-fracbits);
  84170. else if(fracbits > 16)
  84171. return rbps >> (fracbits-16);
  84172. else
  84173. return rbps;
  84174. }
  84175. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  84176. {
  84177. FLAC__uint32 rbps;
  84178. unsigned bits; /* the number of bits required to represent a number */
  84179. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84180. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84181. FLAC__ASSERT(err > 0);
  84182. FLAC__ASSERT(n > 0);
  84183. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84184. if(err <= n)
  84185. return 0;
  84186. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  84187. err <<= fracbits;
  84188. err /= n;
  84189. FLAC__ASSERT(err > 0);
  84190. bits = FLAC__bitmath_ilog2_wide(err)+1;
  84191. if(bits > 16) {
  84192. err >>= (bits-16);
  84193. fracbits -= (bits-16);
  84194. }
  84195. rbps = (FLAC__uint32)err;
  84196. rbps *= FLAC__FP_LN2;
  84197. fracbits += 16;
  84198. FLAC__ASSERT(fracbits >= 0);
  84199. {
  84200. const int f = fracbits & 3;
  84201. if(f) {
  84202. rbps >>= f;
  84203. fracbits -= f;
  84204. }
  84205. }
  84206. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84207. if(rbps == 0)
  84208. return 0;
  84209. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84210. FLAC__ASSERT(fracbits >= -3);
  84211. if(fracbits < 16)
  84212. return rbps << (16-fracbits);
  84213. else if(fracbits > 16)
  84214. return rbps >> (fracbits-16);
  84215. else
  84216. return rbps;
  84217. }
  84218. #endif
  84219. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84220. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84221. #else
  84222. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84223. #endif
  84224. {
  84225. FLAC__int32 last_error_0 = data[-1];
  84226. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84227. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84228. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84229. FLAC__int32 error, save;
  84230. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84231. unsigned i, order;
  84232. for(i = 0; i < data_len; i++) {
  84233. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84234. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84235. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84236. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84237. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84238. }
  84239. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84240. order = 0;
  84241. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84242. order = 1;
  84243. else if(total_error_2 < min(total_error_3, total_error_4))
  84244. order = 2;
  84245. else if(total_error_3 < total_error_4)
  84246. order = 3;
  84247. else
  84248. order = 4;
  84249. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84250. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84251. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84252. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84253. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84254. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84255. 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);
  84256. 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);
  84257. 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);
  84258. 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);
  84259. 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);
  84260. #else
  84261. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  84262. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  84263. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  84264. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  84265. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  84266. #endif
  84267. return order;
  84268. }
  84269. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84270. 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])
  84271. #else
  84272. 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])
  84273. #endif
  84274. {
  84275. FLAC__int32 last_error_0 = data[-1];
  84276. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84277. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84278. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84279. FLAC__int32 error, save;
  84280. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84281. unsigned i, order;
  84282. for(i = 0; i < data_len; i++) {
  84283. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84284. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84285. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84286. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84287. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84288. }
  84289. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84290. order = 0;
  84291. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84292. order = 1;
  84293. else if(total_error_2 < min(total_error_3, total_error_4))
  84294. order = 2;
  84295. else if(total_error_3 < total_error_4)
  84296. order = 3;
  84297. else
  84298. order = 4;
  84299. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84300. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84301. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84302. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84303. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84304. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84305. #if defined _MSC_VER || defined __MINGW32__
  84306. 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);
  84307. 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);
  84308. 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);
  84309. 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);
  84310. 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);
  84311. #else
  84312. 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);
  84313. 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);
  84314. 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);
  84315. 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);
  84316. 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);
  84317. #endif
  84318. #else
  84319. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84320. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84321. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84322. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  84323. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  84324. #endif
  84325. return order;
  84326. }
  84327. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84328. {
  84329. const int idata_len = (int)data_len;
  84330. int i;
  84331. switch(order) {
  84332. case 0:
  84333. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84334. memcpy(residual, data, sizeof(residual[0])*data_len);
  84335. break;
  84336. case 1:
  84337. for(i = 0; i < idata_len; i++)
  84338. residual[i] = data[i] - data[i-1];
  84339. break;
  84340. case 2:
  84341. for(i = 0; i < idata_len; i++)
  84342. #if 1 /* OPT: may be faster with some compilers on some systems */
  84343. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84344. #else
  84345. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84346. #endif
  84347. break;
  84348. case 3:
  84349. for(i = 0; i < idata_len; i++)
  84350. #if 1 /* OPT: may be faster with some compilers on some systems */
  84351. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84352. #else
  84353. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84354. #endif
  84355. break;
  84356. case 4:
  84357. for(i = 0; i < idata_len; i++)
  84358. #if 1 /* OPT: may be faster with some compilers on some systems */
  84359. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84360. #else
  84361. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84362. #endif
  84363. break;
  84364. default:
  84365. FLAC__ASSERT(0);
  84366. }
  84367. }
  84368. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84369. {
  84370. int i, idata_len = (int)data_len;
  84371. switch(order) {
  84372. case 0:
  84373. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84374. memcpy(data, residual, sizeof(residual[0])*data_len);
  84375. break;
  84376. case 1:
  84377. for(i = 0; i < idata_len; i++)
  84378. data[i] = residual[i] + data[i-1];
  84379. break;
  84380. case 2:
  84381. for(i = 0; i < idata_len; i++)
  84382. #if 1 /* OPT: may be faster with some compilers on some systems */
  84383. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  84384. #else
  84385. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  84386. #endif
  84387. break;
  84388. case 3:
  84389. for(i = 0; i < idata_len; i++)
  84390. #if 1 /* OPT: may be faster with some compilers on some systems */
  84391. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  84392. #else
  84393. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  84394. #endif
  84395. break;
  84396. case 4:
  84397. for(i = 0; i < idata_len; i++)
  84398. #if 1 /* OPT: may be faster with some compilers on some systems */
  84399. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  84400. #else
  84401. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  84402. #endif
  84403. break;
  84404. default:
  84405. FLAC__ASSERT(0);
  84406. }
  84407. }
  84408. #endif
  84409. /*** End of inlined file: fixed.c ***/
  84410. /*** Start of inlined file: float.c ***/
  84411. /*** Start of inlined file: juce_FlacHeader.h ***/
  84412. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84413. // tasks..
  84414. #define VERSION "1.2.1"
  84415. #define FLAC__NO_DLL 1
  84416. #if JUCE_MSVC
  84417. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84418. #endif
  84419. #if JUCE_MAC
  84420. #define FLAC__SYS_DARWIN 1
  84421. #endif
  84422. /*** End of inlined file: juce_FlacHeader.h ***/
  84423. #if JUCE_USE_FLAC
  84424. #if HAVE_CONFIG_H
  84425. # include <config.h>
  84426. #endif
  84427. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84428. #ifdef _MSC_VER
  84429. #define FLAC__U64L(x) x
  84430. #else
  84431. #define FLAC__U64L(x) x##LLU
  84432. #endif
  84433. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84434. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84435. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84436. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84437. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84438. #define LOG2_LOOKUP_PRECISION 16
  84439. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84440. {
  84441. 0x00000000,
  84442. 0x00000001,
  84443. 0x00000000,
  84444. 0x00000000,
  84445. 0x00000000,
  84446. 0x00000000,
  84447. 0x00000000,
  84448. 0x00000000,
  84449. 0x00000000,
  84450. 0x00000000,
  84451. 0x00000000,
  84452. 0x00000000,
  84453. 0x00000000,
  84454. 0x00000000,
  84455. 0x00000000,
  84456. 0x00000000
  84457. },
  84458. {
  84459. 0x00000000,
  84460. 0x00000010,
  84461. 0x00000007,
  84462. 0x00000003,
  84463. 0x00000001,
  84464. 0x00000001,
  84465. 0x00000000,
  84466. 0x00000000,
  84467. 0x00000000,
  84468. 0x00000000,
  84469. 0x00000000,
  84470. 0x00000000,
  84471. 0x00000000,
  84472. 0x00000000,
  84473. 0x00000000,
  84474. 0x00000000
  84475. },
  84476. {
  84477. 0x00000000,
  84478. 0x00000100,
  84479. 0x0000006a,
  84480. 0x00000031,
  84481. 0x00000018,
  84482. 0x0000000c,
  84483. 0x00000006,
  84484. 0x00000003,
  84485. 0x00000001,
  84486. 0x00000001,
  84487. 0x00000000,
  84488. 0x00000000,
  84489. 0x00000000,
  84490. 0x00000000,
  84491. 0x00000000,
  84492. 0x00000000
  84493. },
  84494. {
  84495. 0x00000000,
  84496. 0x00001000,
  84497. 0x000006a4,
  84498. 0x00000315,
  84499. 0x0000017d,
  84500. 0x000000bc,
  84501. 0x0000005d,
  84502. 0x0000002e,
  84503. 0x00000017,
  84504. 0x0000000c,
  84505. 0x00000006,
  84506. 0x00000003,
  84507. 0x00000001,
  84508. 0x00000001,
  84509. 0x00000000,
  84510. 0x00000000
  84511. },
  84512. {
  84513. 0x00000000,
  84514. 0x00010000,
  84515. 0x00006a40,
  84516. 0x00003151,
  84517. 0x000017d6,
  84518. 0x00000bba,
  84519. 0x000005d1,
  84520. 0x000002e6,
  84521. 0x00000172,
  84522. 0x000000b9,
  84523. 0x0000005c,
  84524. 0x0000002e,
  84525. 0x00000017,
  84526. 0x0000000c,
  84527. 0x00000006,
  84528. 0x00000003
  84529. },
  84530. {
  84531. 0x00000000,
  84532. 0x00100000,
  84533. 0x0006a3fe,
  84534. 0x00031513,
  84535. 0x00017d60,
  84536. 0x0000bb9d,
  84537. 0x00005d10,
  84538. 0x00002e59,
  84539. 0x00001721,
  84540. 0x00000b8e,
  84541. 0x000005c6,
  84542. 0x000002e3,
  84543. 0x00000171,
  84544. 0x000000b9,
  84545. 0x0000005c,
  84546. 0x0000002e
  84547. },
  84548. {
  84549. 0x00000000,
  84550. 0x01000000,
  84551. 0x006a3fe6,
  84552. 0x00315130,
  84553. 0x0017d605,
  84554. 0x000bb9ca,
  84555. 0x0005d0fc,
  84556. 0x0002e58f,
  84557. 0x0001720e,
  84558. 0x0000b8d8,
  84559. 0x00005c61,
  84560. 0x00002e2d,
  84561. 0x00001716,
  84562. 0x00000b8b,
  84563. 0x000005c5,
  84564. 0x000002e3
  84565. },
  84566. {
  84567. 0x00000000,
  84568. 0x10000000,
  84569. 0x06a3fe5c,
  84570. 0x03151301,
  84571. 0x017d6049,
  84572. 0x00bb9ca6,
  84573. 0x005d0fba,
  84574. 0x002e58f7,
  84575. 0x001720da,
  84576. 0x000b8d87,
  84577. 0x0005c60b,
  84578. 0x0002e2d7,
  84579. 0x00017160,
  84580. 0x0000b8ad,
  84581. 0x00005c56,
  84582. 0x00002e2b
  84583. }
  84584. };
  84585. #if 0
  84586. static const FLAC__uint64 log2_lookup_wide[] = {
  84587. {
  84588. 0x00000000,
  84589. FLAC__U64L(0x100000000),
  84590. FLAC__U64L(0x6a3fe5c6),
  84591. FLAC__U64L(0x31513015),
  84592. FLAC__U64L(0x17d60497),
  84593. FLAC__U64L(0x0bb9ca65),
  84594. FLAC__U64L(0x05d0fba2),
  84595. FLAC__U64L(0x02e58f74),
  84596. FLAC__U64L(0x01720d9c),
  84597. FLAC__U64L(0x00b8d875),
  84598. FLAC__U64L(0x005c60aa),
  84599. FLAC__U64L(0x002e2d72),
  84600. FLAC__U64L(0x00171600),
  84601. FLAC__U64L(0x000b8ad2),
  84602. FLAC__U64L(0x0005c55d),
  84603. FLAC__U64L(0x0002e2ac)
  84604. },
  84605. {
  84606. 0x00000000,
  84607. FLAC__U64L(0x1000000000000),
  84608. FLAC__U64L(0x6a3fe5c60429),
  84609. FLAC__U64L(0x315130157f7a),
  84610. FLAC__U64L(0x17d60496cfbb),
  84611. FLAC__U64L(0xbb9ca64ecac),
  84612. FLAC__U64L(0x5d0fba187cd),
  84613. FLAC__U64L(0x2e58f7441ee),
  84614. FLAC__U64L(0x1720d9c06a8),
  84615. FLAC__U64L(0xb8d8752173),
  84616. FLAC__U64L(0x5c60aa252e),
  84617. FLAC__U64L(0x2e2d71b0d8),
  84618. FLAC__U64L(0x1716001719),
  84619. FLAC__U64L(0xb8ad1de1b),
  84620. FLAC__U64L(0x5c55d640d),
  84621. FLAC__U64L(0x2e2abcf52)
  84622. }
  84623. };
  84624. #endif
  84625. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84626. {
  84627. const FLAC__uint32 ONE = (1u << fracbits);
  84628. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84629. FLAC__ASSERT(fracbits < 32);
  84630. FLAC__ASSERT((fracbits & 0x3) == 0);
  84631. if(x < ONE)
  84632. return 0;
  84633. if(precision > LOG2_LOOKUP_PRECISION)
  84634. precision = LOG2_LOOKUP_PRECISION;
  84635. {
  84636. FLAC__uint32 y = 0;
  84637. FLAC__uint32 z = x >> 1, k = 1;
  84638. while (x > ONE && k < precision) {
  84639. if (x - z >= ONE) {
  84640. x -= z;
  84641. z = x >> k;
  84642. y += table[k];
  84643. }
  84644. else {
  84645. z >>= 1;
  84646. k++;
  84647. }
  84648. }
  84649. return y;
  84650. }
  84651. }
  84652. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84653. #endif
  84654. /*** End of inlined file: float.c ***/
  84655. /*** Start of inlined file: format.c ***/
  84656. /*** Start of inlined file: juce_FlacHeader.h ***/
  84657. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84658. // tasks..
  84659. #define VERSION "1.2.1"
  84660. #define FLAC__NO_DLL 1
  84661. #if JUCE_MSVC
  84662. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84663. #endif
  84664. #if JUCE_MAC
  84665. #define FLAC__SYS_DARWIN 1
  84666. #endif
  84667. /*** End of inlined file: juce_FlacHeader.h ***/
  84668. #if JUCE_USE_FLAC
  84669. #if HAVE_CONFIG_H
  84670. # include <config.h>
  84671. #endif
  84672. #include <stdio.h>
  84673. #include <stdlib.h> /* for qsort() */
  84674. #include <string.h> /* for memset() */
  84675. #ifndef FLaC__INLINE
  84676. #define FLaC__INLINE
  84677. #endif
  84678. #ifdef min
  84679. #undef min
  84680. #endif
  84681. #define min(a,b) ((a)<(b)?(a):(b))
  84682. #ifdef _MSC_VER
  84683. #define FLAC__U64L(x) x
  84684. #else
  84685. #define FLAC__U64L(x) x##LLU
  84686. #endif
  84687. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  84688. ;
  84689. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  84690. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  84691. #else
  84692. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  84693. #endif
  84694. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  84695. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  84696. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  84697. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  84698. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  84699. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  84700. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  84701. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  84702. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  84703. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  84704. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  84705. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  84706. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  84707. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  84708. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  84709. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  84710. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  84711. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  84712. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  84713. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  84714. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  84715. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  84716. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  84717. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  84718. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  84719. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  84720. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  84721. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  84722. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  84723. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  84724. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  84725. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  84726. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  84727. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  84728. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  84729. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  84730. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  84731. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  84732. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  84733. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  84734. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  84735. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  84736. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  84737. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  84738. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  84739. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  84740. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  84741. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  84742. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  84743. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  84744. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  84745. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  84746. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  84747. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  84748. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  84749. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  84750. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  84751. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  84752. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  84753. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  84754. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  84755. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  84756. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  84757. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  84758. "PARTITIONED_RICE",
  84759. "PARTITIONED_RICE2"
  84760. };
  84761. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  84762. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  84763. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  84764. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  84765. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  84766. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  84767. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  84768. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  84769. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  84770. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  84771. "CONSTANT",
  84772. "VERBATIM",
  84773. "FIXED",
  84774. "LPC"
  84775. };
  84776. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  84777. "INDEPENDENT",
  84778. "LEFT_SIDE",
  84779. "RIGHT_SIDE",
  84780. "MID_SIDE"
  84781. };
  84782. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  84783. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  84784. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  84785. };
  84786. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  84787. "STREAMINFO",
  84788. "PADDING",
  84789. "APPLICATION",
  84790. "SEEKTABLE",
  84791. "VORBIS_COMMENT",
  84792. "CUESHEET",
  84793. "PICTURE"
  84794. };
  84795. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  84796. "Other",
  84797. "32x32 pixels 'file icon' (PNG only)",
  84798. "Other file icon",
  84799. "Cover (front)",
  84800. "Cover (back)",
  84801. "Leaflet page",
  84802. "Media (e.g. label side of CD)",
  84803. "Lead artist/lead performer/soloist",
  84804. "Artist/performer",
  84805. "Conductor",
  84806. "Band/Orchestra",
  84807. "Composer",
  84808. "Lyricist/text writer",
  84809. "Recording Location",
  84810. "During recording",
  84811. "During performance",
  84812. "Movie/video screen capture",
  84813. "A bright coloured fish",
  84814. "Illustration",
  84815. "Band/artist logotype",
  84816. "Publisher/Studio logotype"
  84817. };
  84818. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  84819. {
  84820. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  84821. return false;
  84822. }
  84823. else
  84824. return true;
  84825. }
  84826. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  84827. {
  84828. if(
  84829. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  84830. (
  84831. sample_rate >= (1u << 16) &&
  84832. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  84833. )
  84834. ) {
  84835. return false;
  84836. }
  84837. else
  84838. return true;
  84839. }
  84840. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  84841. {
  84842. unsigned i;
  84843. FLAC__uint64 prev_sample_number = 0;
  84844. FLAC__bool got_prev = false;
  84845. FLAC__ASSERT(0 != seek_table);
  84846. for(i = 0; i < seek_table->num_points; i++) {
  84847. if(got_prev) {
  84848. if(
  84849. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  84850. seek_table->points[i].sample_number <= prev_sample_number
  84851. )
  84852. return false;
  84853. }
  84854. prev_sample_number = seek_table->points[i].sample_number;
  84855. got_prev = true;
  84856. }
  84857. return true;
  84858. }
  84859. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  84860. {
  84861. if(l->sample_number == r->sample_number)
  84862. return 0;
  84863. else if(l->sample_number < r->sample_number)
  84864. return -1;
  84865. else
  84866. return 1;
  84867. }
  84868. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  84869. {
  84870. unsigned i, j;
  84871. FLAC__bool first;
  84872. FLAC__ASSERT(0 != seek_table);
  84873. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  84874. first = true;
  84875. for(i = j = 0; i < seek_table->num_points; i++) {
  84876. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  84877. if(!first) {
  84878. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  84879. continue;
  84880. }
  84881. }
  84882. first = false;
  84883. seek_table->points[j++] = seek_table->points[i];
  84884. }
  84885. for(i = j; i < seek_table->num_points; i++) {
  84886. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  84887. seek_table->points[i].stream_offset = 0;
  84888. seek_table->points[i].frame_samples = 0;
  84889. }
  84890. return j;
  84891. }
  84892. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  84893. {
  84894. FLAC__ASSERT(0 != utf8);
  84895. if ((utf8[0] & 0x80) == 0) {
  84896. return 1;
  84897. }
  84898. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  84899. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  84900. return 0;
  84901. return 2;
  84902. }
  84903. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  84904. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  84905. return 0;
  84906. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  84907. return 0;
  84908. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  84909. return 0;
  84910. return 3;
  84911. }
  84912. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  84913. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  84914. return 0;
  84915. return 4;
  84916. }
  84917. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  84918. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  84919. return 0;
  84920. return 5;
  84921. }
  84922. 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) {
  84923. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  84924. return 0;
  84925. return 6;
  84926. }
  84927. else {
  84928. return 0;
  84929. }
  84930. }
  84931. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  84932. {
  84933. char c;
  84934. for(c = *name; c; c = *(++name))
  84935. if(c < 0x20 || c == 0x3d || c > 0x7d)
  84936. return false;
  84937. return true;
  84938. }
  84939. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  84940. {
  84941. if(length == (unsigned)(-1)) {
  84942. while(*value) {
  84943. unsigned n = utf8len_(value);
  84944. if(n == 0)
  84945. return false;
  84946. value += n;
  84947. }
  84948. }
  84949. else {
  84950. const FLAC__byte *end = value + length;
  84951. while(value < end) {
  84952. unsigned n = utf8len_(value);
  84953. if(n == 0)
  84954. return false;
  84955. value += n;
  84956. }
  84957. if(value != end)
  84958. return false;
  84959. }
  84960. return true;
  84961. }
  84962. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  84963. {
  84964. const FLAC__byte *s, *end;
  84965. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  84966. if(*s < 0x20 || *s > 0x7D)
  84967. return false;
  84968. }
  84969. if(s == end)
  84970. return false;
  84971. s++; /* skip '=' */
  84972. while(s < end) {
  84973. unsigned n = utf8len_(s);
  84974. if(n == 0)
  84975. return false;
  84976. s += n;
  84977. }
  84978. if(s != end)
  84979. return false;
  84980. return true;
  84981. }
  84982. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  84983. {
  84984. unsigned i, j;
  84985. if(check_cd_da_subset) {
  84986. if(cue_sheet->lead_in < 2 * 44100) {
  84987. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  84988. return false;
  84989. }
  84990. if(cue_sheet->lead_in % 588 != 0) {
  84991. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  84992. return false;
  84993. }
  84994. }
  84995. if(cue_sheet->num_tracks == 0) {
  84996. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  84997. return false;
  84998. }
  84999. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  85000. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  85001. return false;
  85002. }
  85003. for(i = 0; i < cue_sheet->num_tracks; i++) {
  85004. if(cue_sheet->tracks[i].number == 0) {
  85005. if(violation) *violation = "cue sheet may not have a track number 0";
  85006. return false;
  85007. }
  85008. if(check_cd_da_subset) {
  85009. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  85010. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  85011. return false;
  85012. }
  85013. }
  85014. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  85015. if(violation) {
  85016. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  85017. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  85018. else
  85019. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  85020. }
  85021. return false;
  85022. }
  85023. if(i < cue_sheet->num_tracks - 1) {
  85024. if(cue_sheet->tracks[i].num_indices == 0) {
  85025. if(violation) *violation = "cue sheet track must have at least one index point";
  85026. return false;
  85027. }
  85028. if(cue_sheet->tracks[i].indices[0].number > 1) {
  85029. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  85030. return false;
  85031. }
  85032. }
  85033. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  85034. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  85035. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  85036. return false;
  85037. }
  85038. if(j > 0) {
  85039. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  85040. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  85041. return false;
  85042. }
  85043. }
  85044. }
  85045. }
  85046. return true;
  85047. }
  85048. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  85049. {
  85050. char *p;
  85051. FLAC__byte *b;
  85052. for(p = picture->mime_type; *p; p++) {
  85053. if(*p < 0x20 || *p > 0x7e) {
  85054. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  85055. return false;
  85056. }
  85057. }
  85058. for(b = picture->description; *b; ) {
  85059. unsigned n = utf8len_(b);
  85060. if(n == 0) {
  85061. if(violation) *violation = "description string must be valid UTF-8";
  85062. return false;
  85063. }
  85064. b += n;
  85065. }
  85066. return true;
  85067. }
  85068. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  85069. {
  85070. return
  85071. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  85072. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  85073. blocksize,
  85074. predictor_order
  85075. );
  85076. }
  85077. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  85078. {
  85079. unsigned max_rice_partition_order = 0;
  85080. while(!(blocksize & 1)) {
  85081. max_rice_partition_order++;
  85082. blocksize >>= 1;
  85083. }
  85084. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  85085. }
  85086. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  85087. {
  85088. unsigned max_rice_partition_order = limit;
  85089. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  85090. max_rice_partition_order--;
  85091. FLAC__ASSERT(
  85092. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  85093. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  85094. );
  85095. return max_rice_partition_order;
  85096. }
  85097. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85098. {
  85099. FLAC__ASSERT(0 != object);
  85100. object->parameters = 0;
  85101. object->raw_bits = 0;
  85102. object->capacity_by_order = 0;
  85103. }
  85104. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85105. {
  85106. FLAC__ASSERT(0 != object);
  85107. if(0 != object->parameters)
  85108. free(object->parameters);
  85109. if(0 != object->raw_bits)
  85110. free(object->raw_bits);
  85111. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  85112. }
  85113. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  85114. {
  85115. FLAC__ASSERT(0 != object);
  85116. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  85117. if(object->capacity_by_order < max_partition_order) {
  85118. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  85119. return false;
  85120. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  85121. return false;
  85122. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  85123. object->capacity_by_order = max_partition_order;
  85124. }
  85125. return true;
  85126. }
  85127. #endif
  85128. /*** End of inlined file: format.c ***/
  85129. /*** Start of inlined file: lpc_flac.c ***/
  85130. /*** Start of inlined file: juce_FlacHeader.h ***/
  85131. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  85132. // tasks..
  85133. #define VERSION "1.2.1"
  85134. #define FLAC__NO_DLL 1
  85135. #if JUCE_MSVC
  85136. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  85137. #endif
  85138. #if JUCE_MAC
  85139. #define FLAC__SYS_DARWIN 1
  85140. #endif
  85141. /*** End of inlined file: juce_FlacHeader.h ***/
  85142. #if JUCE_USE_FLAC
  85143. #if HAVE_CONFIG_H
  85144. # include <config.h>
  85145. #endif
  85146. #include <math.h>
  85147. /*** Start of inlined file: lpc.h ***/
  85148. #ifndef FLAC__PRIVATE__LPC_H
  85149. #define FLAC__PRIVATE__LPC_H
  85150. #ifdef HAVE_CONFIG_H
  85151. #include <config.h>
  85152. #endif
  85153. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85154. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  85155. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85156. #ifndef FLAC__NO_ASM
  85157. # ifdef FLAC__CPU_IA32
  85158. # ifdef FLAC__HAS_NASM
  85159. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85160. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85161. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85162. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85163. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85164. # endif
  85165. # endif
  85166. #endif
  85167. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  85168. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  85169. 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[]);
  85170. 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[]);
  85171. #ifndef FLAC__NO_ASM
  85172. # ifdef FLAC__CPU_IA32
  85173. # ifdef FLAC__HAS_NASM
  85174. 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[]);
  85175. 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[]);
  85176. # endif
  85177. # endif
  85178. #endif
  85179. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85180. 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[]);
  85181. 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[]);
  85182. #ifndef FLAC__NO_ASM
  85183. # ifdef FLAC__CPU_IA32
  85184. # ifdef FLAC__HAS_NASM
  85185. 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[]);
  85186. 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[]);
  85187. # endif /* FLAC__HAS_NASM */
  85188. # elif defined FLAC__CPU_PPC
  85189. 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[]);
  85190. 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[]);
  85191. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  85192. #endif /* FLAC__NO_ASM */
  85193. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85194. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  85195. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  85196. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  85197. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85198. #endif
  85199. /*** End of inlined file: lpc.h ***/
  85200. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  85201. #include <stdio.h>
  85202. #endif
  85203. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85204. #ifndef M_LN2
  85205. #define M_LN2 0.69314718055994530942
  85206. #endif
  85207. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  85208. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  85209. {
  85210. unsigned i;
  85211. for(i = 0; i < data_len; i++)
  85212. out[i] = in[i] * window[i];
  85213. }
  85214. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  85215. {
  85216. #if 0
  85217. FLAC__real d;
  85218. unsigned i;
  85219. FLAC__ASSERT(lag > 0);
  85220. FLAC__ASSERT(lag <= data_len);
  85221. while(lag--) {
  85222. for(i = lag, d = 0.0; i < data_len; i++)
  85223. d += data[i] * data[i - lag];
  85224. autoc[lag] = d;
  85225. }
  85226. #endif
  85227. FLAC__real d;
  85228. unsigned sample, coeff;
  85229. const unsigned limit = data_len - lag;
  85230. FLAC__ASSERT(lag > 0);
  85231. FLAC__ASSERT(lag <= data_len);
  85232. for(coeff = 0; coeff < lag; coeff++)
  85233. autoc[coeff] = 0.0;
  85234. for(sample = 0; sample <= limit; sample++) {
  85235. d = data[sample];
  85236. for(coeff = 0; coeff < lag; coeff++)
  85237. autoc[coeff] += d * data[sample+coeff];
  85238. }
  85239. for(; sample < data_len; sample++) {
  85240. d = data[sample];
  85241. for(coeff = 0; coeff < data_len - sample; coeff++)
  85242. autoc[coeff] += d * data[sample+coeff];
  85243. }
  85244. }
  85245. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  85246. {
  85247. unsigned i, j;
  85248. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  85249. FLAC__ASSERT(0 != max_order);
  85250. FLAC__ASSERT(0 < *max_order);
  85251. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  85252. FLAC__ASSERT(autoc[0] != 0.0);
  85253. err = autoc[0];
  85254. for(i = 0; i < *max_order; i++) {
  85255. r = -autoc[i+1];
  85256. for(j = 0; j < i; j++)
  85257. r -= lpc[j] * autoc[i-j];
  85258. ref[i] = (r/=err);
  85259. lpc[i]=r;
  85260. for(j = 0; j < (i>>1); j++) {
  85261. FLAC__double tmp = lpc[j];
  85262. lpc[j] += r * lpc[i-1-j];
  85263. lpc[i-1-j] += r * tmp;
  85264. }
  85265. if(i & 1)
  85266. lpc[j] += lpc[j] * r;
  85267. err *= (1.0 - r * r);
  85268. for(j = 0; j <= i; j++)
  85269. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  85270. error[i] = err;
  85271. if(err == 0.0) {
  85272. *max_order = i+1;
  85273. return;
  85274. }
  85275. }
  85276. }
  85277. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  85278. {
  85279. unsigned i;
  85280. FLAC__double cmax;
  85281. FLAC__int32 qmax, qmin;
  85282. FLAC__ASSERT(precision > 0);
  85283. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  85284. precision--;
  85285. qmax = 1 << precision;
  85286. qmin = -qmax;
  85287. qmax--;
  85288. cmax = 0.0;
  85289. for(i = 0; i < order; i++) {
  85290. const FLAC__double d = fabs(lp_coeff[i]);
  85291. if(d > cmax)
  85292. cmax = d;
  85293. }
  85294. if(cmax <= 0.0) {
  85295. return 2;
  85296. }
  85297. else {
  85298. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85299. const int min_shiftlimit = -max_shiftlimit - 1;
  85300. int log2cmax;
  85301. (void)frexp(cmax, &log2cmax);
  85302. log2cmax--;
  85303. *shift = (int)precision - log2cmax - 1;
  85304. if(*shift > max_shiftlimit)
  85305. *shift = max_shiftlimit;
  85306. else if(*shift < min_shiftlimit)
  85307. return 1;
  85308. }
  85309. if(*shift >= 0) {
  85310. FLAC__double error = 0.0;
  85311. FLAC__int32 q;
  85312. for(i = 0; i < order; i++) {
  85313. error += lp_coeff[i] * (1 << *shift);
  85314. #if 1 /* unfortunately lround() is C99 */
  85315. if(error >= 0.0)
  85316. q = (FLAC__int32)(error + 0.5);
  85317. else
  85318. q = (FLAC__int32)(error - 0.5);
  85319. #else
  85320. q = lround(error);
  85321. #endif
  85322. #ifdef FLAC__OVERFLOW_DETECT
  85323. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85324. 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]);
  85325. else if(q < qmin)
  85326. 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]);
  85327. #endif
  85328. if(q > qmax)
  85329. q = qmax;
  85330. else if(q < qmin)
  85331. q = qmin;
  85332. error -= q;
  85333. qlp_coeff[i] = q;
  85334. }
  85335. }
  85336. else {
  85337. const int nshift = -(*shift);
  85338. FLAC__double error = 0.0;
  85339. FLAC__int32 q;
  85340. #ifdef DEBUG
  85341. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85342. #endif
  85343. for(i = 0; i < order; i++) {
  85344. error += lp_coeff[i] / (1 << nshift);
  85345. #if 1 /* unfortunately lround() is C99 */
  85346. if(error >= 0.0)
  85347. q = (FLAC__int32)(error + 0.5);
  85348. else
  85349. q = (FLAC__int32)(error - 0.5);
  85350. #else
  85351. q = lround(error);
  85352. #endif
  85353. #ifdef FLAC__OVERFLOW_DETECT
  85354. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85355. 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]);
  85356. else if(q < qmin)
  85357. 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]);
  85358. #endif
  85359. if(q > qmax)
  85360. q = qmax;
  85361. else if(q < qmin)
  85362. q = qmin;
  85363. error -= q;
  85364. qlp_coeff[i] = q;
  85365. }
  85366. *shift = 0;
  85367. }
  85368. return 0;
  85369. }
  85370. 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[])
  85371. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85372. {
  85373. FLAC__int64 sumo;
  85374. unsigned i, j;
  85375. FLAC__int32 sum;
  85376. const FLAC__int32 *history;
  85377. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85378. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85379. for(i=0;i<order;i++)
  85380. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85381. fprintf(stderr,"\n");
  85382. #endif
  85383. FLAC__ASSERT(order > 0);
  85384. for(i = 0; i < data_len; i++) {
  85385. sumo = 0;
  85386. sum = 0;
  85387. history = data;
  85388. for(j = 0; j < order; j++) {
  85389. sum += qlp_coeff[j] * (*(--history));
  85390. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85391. #if defined _MSC_VER
  85392. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85393. 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);
  85394. #else
  85395. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85396. 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);
  85397. #endif
  85398. }
  85399. *(residual++) = *(data++) - (sum >> lp_quantization);
  85400. }
  85401. }
  85402. #else /* fully unrolled version for normal use */
  85403. {
  85404. int i;
  85405. FLAC__int32 sum;
  85406. FLAC__ASSERT(order > 0);
  85407. FLAC__ASSERT(order <= 32);
  85408. if(order <= 12) {
  85409. if(order > 8) {
  85410. if(order > 10) {
  85411. if(order == 12) {
  85412. for(i = 0; i < (int)data_len; i++) {
  85413. sum = 0;
  85414. sum += qlp_coeff[11] * data[i-12];
  85415. sum += qlp_coeff[10] * data[i-11];
  85416. sum += qlp_coeff[9] * data[i-10];
  85417. sum += qlp_coeff[8] * data[i-9];
  85418. sum += qlp_coeff[7] * data[i-8];
  85419. sum += qlp_coeff[6] * data[i-7];
  85420. sum += qlp_coeff[5] * data[i-6];
  85421. sum += qlp_coeff[4] * data[i-5];
  85422. sum += qlp_coeff[3] * data[i-4];
  85423. sum += qlp_coeff[2] * data[i-3];
  85424. sum += qlp_coeff[1] * data[i-2];
  85425. sum += qlp_coeff[0] * data[i-1];
  85426. residual[i] = data[i] - (sum >> lp_quantization);
  85427. }
  85428. }
  85429. else { /* order == 11 */
  85430. for(i = 0; i < (int)data_len; i++) {
  85431. sum = 0;
  85432. sum += qlp_coeff[10] * data[i-11];
  85433. sum += qlp_coeff[9] * data[i-10];
  85434. sum += qlp_coeff[8] * data[i-9];
  85435. sum += qlp_coeff[7] * data[i-8];
  85436. sum += qlp_coeff[6] * data[i-7];
  85437. sum += qlp_coeff[5] * data[i-6];
  85438. sum += qlp_coeff[4] * data[i-5];
  85439. sum += qlp_coeff[3] * data[i-4];
  85440. sum += qlp_coeff[2] * data[i-3];
  85441. sum += qlp_coeff[1] * data[i-2];
  85442. sum += qlp_coeff[0] * data[i-1];
  85443. residual[i] = data[i] - (sum >> lp_quantization);
  85444. }
  85445. }
  85446. }
  85447. else {
  85448. if(order == 10) {
  85449. for(i = 0; i < (int)data_len; i++) {
  85450. sum = 0;
  85451. sum += qlp_coeff[9] * data[i-10];
  85452. sum += qlp_coeff[8] * data[i-9];
  85453. sum += qlp_coeff[7] * data[i-8];
  85454. sum += qlp_coeff[6] * data[i-7];
  85455. sum += qlp_coeff[5] * data[i-6];
  85456. sum += qlp_coeff[4] * data[i-5];
  85457. sum += qlp_coeff[3] * data[i-4];
  85458. sum += qlp_coeff[2] * data[i-3];
  85459. sum += qlp_coeff[1] * data[i-2];
  85460. sum += qlp_coeff[0] * data[i-1];
  85461. residual[i] = data[i] - (sum >> lp_quantization);
  85462. }
  85463. }
  85464. else { /* order == 9 */
  85465. for(i = 0; i < (int)data_len; i++) {
  85466. sum = 0;
  85467. sum += qlp_coeff[8] * data[i-9];
  85468. sum += qlp_coeff[7] * data[i-8];
  85469. sum += qlp_coeff[6] * data[i-7];
  85470. sum += qlp_coeff[5] * data[i-6];
  85471. sum += qlp_coeff[4] * data[i-5];
  85472. sum += qlp_coeff[3] * data[i-4];
  85473. sum += qlp_coeff[2] * data[i-3];
  85474. sum += qlp_coeff[1] * data[i-2];
  85475. sum += qlp_coeff[0] * data[i-1];
  85476. residual[i] = data[i] - (sum >> lp_quantization);
  85477. }
  85478. }
  85479. }
  85480. }
  85481. else if(order > 4) {
  85482. if(order > 6) {
  85483. if(order == 8) {
  85484. for(i = 0; i < (int)data_len; i++) {
  85485. sum = 0;
  85486. sum += qlp_coeff[7] * data[i-8];
  85487. sum += qlp_coeff[6] * data[i-7];
  85488. sum += qlp_coeff[5] * data[i-6];
  85489. sum += qlp_coeff[4] * data[i-5];
  85490. sum += qlp_coeff[3] * data[i-4];
  85491. sum += qlp_coeff[2] * data[i-3];
  85492. sum += qlp_coeff[1] * data[i-2];
  85493. sum += qlp_coeff[0] * data[i-1];
  85494. residual[i] = data[i] - (sum >> lp_quantization);
  85495. }
  85496. }
  85497. else { /* order == 7 */
  85498. for(i = 0; i < (int)data_len; i++) {
  85499. sum = 0;
  85500. sum += qlp_coeff[6] * data[i-7];
  85501. sum += qlp_coeff[5] * data[i-6];
  85502. sum += qlp_coeff[4] * data[i-5];
  85503. sum += qlp_coeff[3] * data[i-4];
  85504. sum += qlp_coeff[2] * data[i-3];
  85505. sum += qlp_coeff[1] * data[i-2];
  85506. sum += qlp_coeff[0] * data[i-1];
  85507. residual[i] = data[i] - (sum >> lp_quantization);
  85508. }
  85509. }
  85510. }
  85511. else {
  85512. if(order == 6) {
  85513. for(i = 0; i < (int)data_len; i++) {
  85514. sum = 0;
  85515. sum += qlp_coeff[5] * data[i-6];
  85516. sum += qlp_coeff[4] * data[i-5];
  85517. sum += qlp_coeff[3] * data[i-4];
  85518. sum += qlp_coeff[2] * data[i-3];
  85519. sum += qlp_coeff[1] * data[i-2];
  85520. sum += qlp_coeff[0] * data[i-1];
  85521. residual[i] = data[i] - (sum >> lp_quantization);
  85522. }
  85523. }
  85524. else { /* order == 5 */
  85525. for(i = 0; i < (int)data_len; i++) {
  85526. sum = 0;
  85527. sum += qlp_coeff[4] * data[i-5];
  85528. sum += qlp_coeff[3] * data[i-4];
  85529. sum += qlp_coeff[2] * data[i-3];
  85530. sum += qlp_coeff[1] * data[i-2];
  85531. sum += qlp_coeff[0] * data[i-1];
  85532. residual[i] = data[i] - (sum >> lp_quantization);
  85533. }
  85534. }
  85535. }
  85536. }
  85537. else {
  85538. if(order > 2) {
  85539. if(order == 4) {
  85540. for(i = 0; i < (int)data_len; i++) {
  85541. sum = 0;
  85542. sum += qlp_coeff[3] * data[i-4];
  85543. sum += qlp_coeff[2] * data[i-3];
  85544. sum += qlp_coeff[1] * data[i-2];
  85545. sum += qlp_coeff[0] * data[i-1];
  85546. residual[i] = data[i] - (sum >> lp_quantization);
  85547. }
  85548. }
  85549. else { /* order == 3 */
  85550. for(i = 0; i < (int)data_len; i++) {
  85551. sum = 0;
  85552. sum += qlp_coeff[2] * data[i-3];
  85553. sum += qlp_coeff[1] * data[i-2];
  85554. sum += qlp_coeff[0] * data[i-1];
  85555. residual[i] = data[i] - (sum >> lp_quantization);
  85556. }
  85557. }
  85558. }
  85559. else {
  85560. if(order == 2) {
  85561. for(i = 0; i < (int)data_len; i++) {
  85562. sum = 0;
  85563. sum += qlp_coeff[1] * data[i-2];
  85564. sum += qlp_coeff[0] * data[i-1];
  85565. residual[i] = data[i] - (sum >> lp_quantization);
  85566. }
  85567. }
  85568. else { /* order == 1 */
  85569. for(i = 0; i < (int)data_len; i++)
  85570. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85571. }
  85572. }
  85573. }
  85574. }
  85575. else { /* order > 12 */
  85576. for(i = 0; i < (int)data_len; i++) {
  85577. sum = 0;
  85578. switch(order) {
  85579. case 32: sum += qlp_coeff[31] * data[i-32];
  85580. case 31: sum += qlp_coeff[30] * data[i-31];
  85581. case 30: sum += qlp_coeff[29] * data[i-30];
  85582. case 29: sum += qlp_coeff[28] * data[i-29];
  85583. case 28: sum += qlp_coeff[27] * data[i-28];
  85584. case 27: sum += qlp_coeff[26] * data[i-27];
  85585. case 26: sum += qlp_coeff[25] * data[i-26];
  85586. case 25: sum += qlp_coeff[24] * data[i-25];
  85587. case 24: sum += qlp_coeff[23] * data[i-24];
  85588. case 23: sum += qlp_coeff[22] * data[i-23];
  85589. case 22: sum += qlp_coeff[21] * data[i-22];
  85590. case 21: sum += qlp_coeff[20] * data[i-21];
  85591. case 20: sum += qlp_coeff[19] * data[i-20];
  85592. case 19: sum += qlp_coeff[18] * data[i-19];
  85593. case 18: sum += qlp_coeff[17] * data[i-18];
  85594. case 17: sum += qlp_coeff[16] * data[i-17];
  85595. case 16: sum += qlp_coeff[15] * data[i-16];
  85596. case 15: sum += qlp_coeff[14] * data[i-15];
  85597. case 14: sum += qlp_coeff[13] * data[i-14];
  85598. case 13: sum += qlp_coeff[12] * data[i-13];
  85599. sum += qlp_coeff[11] * data[i-12];
  85600. sum += qlp_coeff[10] * data[i-11];
  85601. sum += qlp_coeff[ 9] * data[i-10];
  85602. sum += qlp_coeff[ 8] * data[i- 9];
  85603. sum += qlp_coeff[ 7] * data[i- 8];
  85604. sum += qlp_coeff[ 6] * data[i- 7];
  85605. sum += qlp_coeff[ 5] * data[i- 6];
  85606. sum += qlp_coeff[ 4] * data[i- 5];
  85607. sum += qlp_coeff[ 3] * data[i- 4];
  85608. sum += qlp_coeff[ 2] * data[i- 3];
  85609. sum += qlp_coeff[ 1] * data[i- 2];
  85610. sum += qlp_coeff[ 0] * data[i- 1];
  85611. }
  85612. residual[i] = data[i] - (sum >> lp_quantization);
  85613. }
  85614. }
  85615. }
  85616. #endif
  85617. 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[])
  85618. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85619. {
  85620. unsigned i, j;
  85621. FLAC__int64 sum;
  85622. const FLAC__int32 *history;
  85623. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85624. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85625. for(i=0;i<order;i++)
  85626. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85627. fprintf(stderr,"\n");
  85628. #endif
  85629. FLAC__ASSERT(order > 0);
  85630. for(i = 0; i < data_len; i++) {
  85631. sum = 0;
  85632. history = data;
  85633. for(j = 0; j < order; j++)
  85634. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85635. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85636. #if defined _MSC_VER
  85637. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85638. #else
  85639. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85640. #endif
  85641. break;
  85642. }
  85643. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85644. #if defined _MSC_VER
  85645. 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));
  85646. #else
  85647. 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)));
  85648. #endif
  85649. break;
  85650. }
  85651. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85652. }
  85653. }
  85654. #else /* fully unrolled version for normal use */
  85655. {
  85656. int i;
  85657. FLAC__int64 sum;
  85658. FLAC__ASSERT(order > 0);
  85659. FLAC__ASSERT(order <= 32);
  85660. if(order <= 12) {
  85661. if(order > 8) {
  85662. if(order > 10) {
  85663. if(order == 12) {
  85664. for(i = 0; i < (int)data_len; i++) {
  85665. sum = 0;
  85666. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85667. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85668. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85669. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85670. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85671. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85672. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85673. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85674. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85675. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85676. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85677. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85678. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85679. }
  85680. }
  85681. else { /* order == 11 */
  85682. for(i = 0; i < (int)data_len; i++) {
  85683. sum = 0;
  85684. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85685. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85686. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85687. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85688. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85689. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85690. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85691. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85692. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85693. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85694. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85695. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85696. }
  85697. }
  85698. }
  85699. else {
  85700. if(order == 10) {
  85701. for(i = 0; i < (int)data_len; i++) {
  85702. sum = 0;
  85703. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85704. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85705. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85706. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85707. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85708. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85709. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85710. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85711. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85712. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85713. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85714. }
  85715. }
  85716. else { /* order == 9 */
  85717. for(i = 0; i < (int)data_len; i++) {
  85718. sum = 0;
  85719. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85720. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85721. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85722. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85723. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85724. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85725. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85726. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85727. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85728. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85729. }
  85730. }
  85731. }
  85732. }
  85733. else if(order > 4) {
  85734. if(order > 6) {
  85735. if(order == 8) {
  85736. for(i = 0; i < (int)data_len; i++) {
  85737. sum = 0;
  85738. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85739. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85740. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85741. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85742. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85743. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85744. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85745. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85746. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85747. }
  85748. }
  85749. else { /* order == 7 */
  85750. for(i = 0; i < (int)data_len; i++) {
  85751. sum = 0;
  85752. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85753. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85754. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85755. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85756. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85757. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85758. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85759. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85760. }
  85761. }
  85762. }
  85763. else {
  85764. if(order == 6) {
  85765. for(i = 0; i < (int)data_len; i++) {
  85766. sum = 0;
  85767. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85768. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85769. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85770. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85771. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85772. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85773. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85774. }
  85775. }
  85776. else { /* order == 5 */
  85777. for(i = 0; i < (int)data_len; i++) {
  85778. sum = 0;
  85779. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85780. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85781. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85782. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85783. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85784. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85785. }
  85786. }
  85787. }
  85788. }
  85789. else {
  85790. if(order > 2) {
  85791. if(order == 4) {
  85792. for(i = 0; i < (int)data_len; i++) {
  85793. sum = 0;
  85794. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85795. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85796. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85797. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85798. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85799. }
  85800. }
  85801. else { /* order == 3 */
  85802. for(i = 0; i < (int)data_len; i++) {
  85803. sum = 0;
  85804. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85805. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85806. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85807. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85808. }
  85809. }
  85810. }
  85811. else {
  85812. if(order == 2) {
  85813. for(i = 0; i < (int)data_len; i++) {
  85814. sum = 0;
  85815. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85816. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85817. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85818. }
  85819. }
  85820. else { /* order == 1 */
  85821. for(i = 0; i < (int)data_len; i++)
  85822. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  85823. }
  85824. }
  85825. }
  85826. }
  85827. else { /* order > 12 */
  85828. for(i = 0; i < (int)data_len; i++) {
  85829. sum = 0;
  85830. switch(order) {
  85831. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  85832. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  85833. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  85834. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  85835. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  85836. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  85837. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  85838. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  85839. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  85840. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  85841. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  85842. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  85843. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  85844. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  85845. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  85846. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  85847. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  85848. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  85849. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  85850. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  85851. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85852. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85853. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  85854. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  85855. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  85856. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  85857. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  85858. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  85859. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  85860. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  85861. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  85862. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  85863. }
  85864. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85865. }
  85866. }
  85867. }
  85868. #endif
  85869. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85870. 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[])
  85871. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85872. {
  85873. FLAC__int64 sumo;
  85874. unsigned i, j;
  85875. FLAC__int32 sum;
  85876. const FLAC__int32 *r = residual, *history;
  85877. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85878. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85879. for(i=0;i<order;i++)
  85880. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85881. fprintf(stderr,"\n");
  85882. #endif
  85883. FLAC__ASSERT(order > 0);
  85884. for(i = 0; i < data_len; i++) {
  85885. sumo = 0;
  85886. sum = 0;
  85887. history = data;
  85888. for(j = 0; j < order; j++) {
  85889. sum += qlp_coeff[j] * (*(--history));
  85890. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85891. #if defined _MSC_VER
  85892. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85893. 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);
  85894. #else
  85895. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85896. 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);
  85897. #endif
  85898. }
  85899. *(data++) = *(r++) + (sum >> lp_quantization);
  85900. }
  85901. }
  85902. #else /* fully unrolled version for normal use */
  85903. {
  85904. int i;
  85905. FLAC__int32 sum;
  85906. FLAC__ASSERT(order > 0);
  85907. FLAC__ASSERT(order <= 32);
  85908. if(order <= 12) {
  85909. if(order > 8) {
  85910. if(order > 10) {
  85911. if(order == 12) {
  85912. for(i = 0; i < (int)data_len; i++) {
  85913. sum = 0;
  85914. sum += qlp_coeff[11] * data[i-12];
  85915. sum += qlp_coeff[10] * data[i-11];
  85916. sum += qlp_coeff[9] * data[i-10];
  85917. sum += qlp_coeff[8] * data[i-9];
  85918. sum += qlp_coeff[7] * data[i-8];
  85919. sum += qlp_coeff[6] * data[i-7];
  85920. sum += qlp_coeff[5] * data[i-6];
  85921. sum += qlp_coeff[4] * data[i-5];
  85922. sum += qlp_coeff[3] * data[i-4];
  85923. sum += qlp_coeff[2] * data[i-3];
  85924. sum += qlp_coeff[1] * data[i-2];
  85925. sum += qlp_coeff[0] * data[i-1];
  85926. data[i] = residual[i] + (sum >> lp_quantization);
  85927. }
  85928. }
  85929. else { /* order == 11 */
  85930. for(i = 0; i < (int)data_len; i++) {
  85931. sum = 0;
  85932. sum += qlp_coeff[10] * data[i-11];
  85933. sum += qlp_coeff[9] * data[i-10];
  85934. sum += qlp_coeff[8] * data[i-9];
  85935. sum += qlp_coeff[7] * data[i-8];
  85936. sum += qlp_coeff[6] * data[i-7];
  85937. sum += qlp_coeff[5] * data[i-6];
  85938. sum += qlp_coeff[4] * data[i-5];
  85939. sum += qlp_coeff[3] * data[i-4];
  85940. sum += qlp_coeff[2] * data[i-3];
  85941. sum += qlp_coeff[1] * data[i-2];
  85942. sum += qlp_coeff[0] * data[i-1];
  85943. data[i] = residual[i] + (sum >> lp_quantization);
  85944. }
  85945. }
  85946. }
  85947. else {
  85948. if(order == 10) {
  85949. for(i = 0; i < (int)data_len; i++) {
  85950. sum = 0;
  85951. sum += qlp_coeff[9] * data[i-10];
  85952. sum += qlp_coeff[8] * data[i-9];
  85953. sum += qlp_coeff[7] * data[i-8];
  85954. sum += qlp_coeff[6] * data[i-7];
  85955. sum += qlp_coeff[5] * data[i-6];
  85956. sum += qlp_coeff[4] * data[i-5];
  85957. sum += qlp_coeff[3] * data[i-4];
  85958. sum += qlp_coeff[2] * data[i-3];
  85959. sum += qlp_coeff[1] * data[i-2];
  85960. sum += qlp_coeff[0] * data[i-1];
  85961. data[i] = residual[i] + (sum >> lp_quantization);
  85962. }
  85963. }
  85964. else { /* order == 9 */
  85965. for(i = 0; i < (int)data_len; i++) {
  85966. sum = 0;
  85967. sum += qlp_coeff[8] * data[i-9];
  85968. sum += qlp_coeff[7] * data[i-8];
  85969. sum += qlp_coeff[6] * data[i-7];
  85970. sum += qlp_coeff[5] * data[i-6];
  85971. sum += qlp_coeff[4] * data[i-5];
  85972. sum += qlp_coeff[3] * data[i-4];
  85973. sum += qlp_coeff[2] * data[i-3];
  85974. sum += qlp_coeff[1] * data[i-2];
  85975. sum += qlp_coeff[0] * data[i-1];
  85976. data[i] = residual[i] + (sum >> lp_quantization);
  85977. }
  85978. }
  85979. }
  85980. }
  85981. else if(order > 4) {
  85982. if(order > 6) {
  85983. if(order == 8) {
  85984. for(i = 0; i < (int)data_len; i++) {
  85985. sum = 0;
  85986. sum += qlp_coeff[7] * data[i-8];
  85987. sum += qlp_coeff[6] * data[i-7];
  85988. sum += qlp_coeff[5] * data[i-6];
  85989. sum += qlp_coeff[4] * data[i-5];
  85990. sum += qlp_coeff[3] * data[i-4];
  85991. sum += qlp_coeff[2] * data[i-3];
  85992. sum += qlp_coeff[1] * data[i-2];
  85993. sum += qlp_coeff[0] * data[i-1];
  85994. data[i] = residual[i] + (sum >> lp_quantization);
  85995. }
  85996. }
  85997. else { /* order == 7 */
  85998. for(i = 0; i < (int)data_len; i++) {
  85999. sum = 0;
  86000. sum += qlp_coeff[6] * data[i-7];
  86001. sum += qlp_coeff[5] * data[i-6];
  86002. sum += qlp_coeff[4] * data[i-5];
  86003. sum += qlp_coeff[3] * data[i-4];
  86004. sum += qlp_coeff[2] * data[i-3];
  86005. sum += qlp_coeff[1] * data[i-2];
  86006. sum += qlp_coeff[0] * data[i-1];
  86007. data[i] = residual[i] + (sum >> lp_quantization);
  86008. }
  86009. }
  86010. }
  86011. else {
  86012. if(order == 6) {
  86013. for(i = 0; i < (int)data_len; i++) {
  86014. sum = 0;
  86015. sum += qlp_coeff[5] * data[i-6];
  86016. sum += qlp_coeff[4] * data[i-5];
  86017. sum += qlp_coeff[3] * data[i-4];
  86018. sum += qlp_coeff[2] * data[i-3];
  86019. sum += qlp_coeff[1] * data[i-2];
  86020. sum += qlp_coeff[0] * data[i-1];
  86021. data[i] = residual[i] + (sum >> lp_quantization);
  86022. }
  86023. }
  86024. else { /* order == 5 */
  86025. for(i = 0; i < (int)data_len; i++) {
  86026. sum = 0;
  86027. sum += qlp_coeff[4] * data[i-5];
  86028. sum += qlp_coeff[3] * data[i-4];
  86029. sum += qlp_coeff[2] * data[i-3];
  86030. sum += qlp_coeff[1] * data[i-2];
  86031. sum += qlp_coeff[0] * data[i-1];
  86032. data[i] = residual[i] + (sum >> lp_quantization);
  86033. }
  86034. }
  86035. }
  86036. }
  86037. else {
  86038. if(order > 2) {
  86039. if(order == 4) {
  86040. for(i = 0; i < (int)data_len; i++) {
  86041. sum = 0;
  86042. sum += qlp_coeff[3] * data[i-4];
  86043. sum += qlp_coeff[2] * data[i-3];
  86044. sum += qlp_coeff[1] * data[i-2];
  86045. sum += qlp_coeff[0] * data[i-1];
  86046. data[i] = residual[i] + (sum >> lp_quantization);
  86047. }
  86048. }
  86049. else { /* order == 3 */
  86050. for(i = 0; i < (int)data_len; i++) {
  86051. sum = 0;
  86052. sum += qlp_coeff[2] * data[i-3];
  86053. sum += qlp_coeff[1] * data[i-2];
  86054. sum += qlp_coeff[0] * data[i-1];
  86055. data[i] = residual[i] + (sum >> lp_quantization);
  86056. }
  86057. }
  86058. }
  86059. else {
  86060. if(order == 2) {
  86061. for(i = 0; i < (int)data_len; i++) {
  86062. sum = 0;
  86063. sum += qlp_coeff[1] * data[i-2];
  86064. sum += qlp_coeff[0] * data[i-1];
  86065. data[i] = residual[i] + (sum >> lp_quantization);
  86066. }
  86067. }
  86068. else { /* order == 1 */
  86069. for(i = 0; i < (int)data_len; i++)
  86070. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  86071. }
  86072. }
  86073. }
  86074. }
  86075. else { /* order > 12 */
  86076. for(i = 0; i < (int)data_len; i++) {
  86077. sum = 0;
  86078. switch(order) {
  86079. case 32: sum += qlp_coeff[31] * data[i-32];
  86080. case 31: sum += qlp_coeff[30] * data[i-31];
  86081. case 30: sum += qlp_coeff[29] * data[i-30];
  86082. case 29: sum += qlp_coeff[28] * data[i-29];
  86083. case 28: sum += qlp_coeff[27] * data[i-28];
  86084. case 27: sum += qlp_coeff[26] * data[i-27];
  86085. case 26: sum += qlp_coeff[25] * data[i-26];
  86086. case 25: sum += qlp_coeff[24] * data[i-25];
  86087. case 24: sum += qlp_coeff[23] * data[i-24];
  86088. case 23: sum += qlp_coeff[22] * data[i-23];
  86089. case 22: sum += qlp_coeff[21] * data[i-22];
  86090. case 21: sum += qlp_coeff[20] * data[i-21];
  86091. case 20: sum += qlp_coeff[19] * data[i-20];
  86092. case 19: sum += qlp_coeff[18] * data[i-19];
  86093. case 18: sum += qlp_coeff[17] * data[i-18];
  86094. case 17: sum += qlp_coeff[16] * data[i-17];
  86095. case 16: sum += qlp_coeff[15] * data[i-16];
  86096. case 15: sum += qlp_coeff[14] * data[i-15];
  86097. case 14: sum += qlp_coeff[13] * data[i-14];
  86098. case 13: sum += qlp_coeff[12] * data[i-13];
  86099. sum += qlp_coeff[11] * data[i-12];
  86100. sum += qlp_coeff[10] * data[i-11];
  86101. sum += qlp_coeff[ 9] * data[i-10];
  86102. sum += qlp_coeff[ 8] * data[i- 9];
  86103. sum += qlp_coeff[ 7] * data[i- 8];
  86104. sum += qlp_coeff[ 6] * data[i- 7];
  86105. sum += qlp_coeff[ 5] * data[i- 6];
  86106. sum += qlp_coeff[ 4] * data[i- 5];
  86107. sum += qlp_coeff[ 3] * data[i- 4];
  86108. sum += qlp_coeff[ 2] * data[i- 3];
  86109. sum += qlp_coeff[ 1] * data[i- 2];
  86110. sum += qlp_coeff[ 0] * data[i- 1];
  86111. }
  86112. data[i] = residual[i] + (sum >> lp_quantization);
  86113. }
  86114. }
  86115. }
  86116. #endif
  86117. 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[])
  86118. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86119. {
  86120. unsigned i, j;
  86121. FLAC__int64 sum;
  86122. const FLAC__int32 *r = residual, *history;
  86123. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86124. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86125. for(i=0;i<order;i++)
  86126. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86127. fprintf(stderr,"\n");
  86128. #endif
  86129. FLAC__ASSERT(order > 0);
  86130. for(i = 0; i < data_len; i++) {
  86131. sum = 0;
  86132. history = data;
  86133. for(j = 0; j < order; j++)
  86134. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  86135. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  86136. #ifdef _MSC_VER
  86137. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  86138. #else
  86139. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  86140. #endif
  86141. break;
  86142. }
  86143. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  86144. #ifdef _MSC_VER
  86145. 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));
  86146. #else
  86147. 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)));
  86148. #endif
  86149. break;
  86150. }
  86151. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  86152. }
  86153. }
  86154. #else /* fully unrolled version for normal use */
  86155. {
  86156. int i;
  86157. FLAC__int64 sum;
  86158. FLAC__ASSERT(order > 0);
  86159. FLAC__ASSERT(order <= 32);
  86160. if(order <= 12) {
  86161. if(order > 8) {
  86162. if(order > 10) {
  86163. if(order == 12) {
  86164. for(i = 0; i < (int)data_len; i++) {
  86165. sum = 0;
  86166. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86167. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86168. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86169. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86170. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86171. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86172. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86173. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86174. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86175. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86176. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86177. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86178. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86179. }
  86180. }
  86181. else { /* order == 11 */
  86182. for(i = 0; i < (int)data_len; i++) {
  86183. sum = 0;
  86184. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86185. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86186. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86187. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86188. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86189. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86190. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86191. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86192. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86193. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86194. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86195. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86196. }
  86197. }
  86198. }
  86199. else {
  86200. if(order == 10) {
  86201. for(i = 0; i < (int)data_len; i++) {
  86202. sum = 0;
  86203. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86204. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86205. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86206. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86207. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86208. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86209. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86210. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86211. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86212. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86213. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86214. }
  86215. }
  86216. else { /* order == 9 */
  86217. for(i = 0; i < (int)data_len; i++) {
  86218. sum = 0;
  86219. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86220. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86221. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86222. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86223. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86224. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86225. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86226. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86227. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86228. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86229. }
  86230. }
  86231. }
  86232. }
  86233. else if(order > 4) {
  86234. if(order > 6) {
  86235. if(order == 8) {
  86236. for(i = 0; i < (int)data_len; i++) {
  86237. sum = 0;
  86238. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86239. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86240. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86241. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86242. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86243. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86244. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86245. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86246. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86247. }
  86248. }
  86249. else { /* order == 7 */
  86250. for(i = 0; i < (int)data_len; i++) {
  86251. sum = 0;
  86252. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86253. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86254. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86255. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86256. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86257. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86258. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86259. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86260. }
  86261. }
  86262. }
  86263. else {
  86264. if(order == 6) {
  86265. for(i = 0; i < (int)data_len; i++) {
  86266. sum = 0;
  86267. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86268. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86269. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86270. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86271. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86272. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86273. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86274. }
  86275. }
  86276. else { /* order == 5 */
  86277. for(i = 0; i < (int)data_len; i++) {
  86278. sum = 0;
  86279. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86280. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86281. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86282. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86283. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86284. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86285. }
  86286. }
  86287. }
  86288. }
  86289. else {
  86290. if(order > 2) {
  86291. if(order == 4) {
  86292. for(i = 0; i < (int)data_len; i++) {
  86293. sum = 0;
  86294. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86295. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86296. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86297. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86298. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86299. }
  86300. }
  86301. else { /* order == 3 */
  86302. for(i = 0; i < (int)data_len; i++) {
  86303. sum = 0;
  86304. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86305. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86306. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86307. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86308. }
  86309. }
  86310. }
  86311. else {
  86312. if(order == 2) {
  86313. for(i = 0; i < (int)data_len; i++) {
  86314. sum = 0;
  86315. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86316. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86317. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86318. }
  86319. }
  86320. else { /* order == 1 */
  86321. for(i = 0; i < (int)data_len; i++)
  86322. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86323. }
  86324. }
  86325. }
  86326. }
  86327. else { /* order > 12 */
  86328. for(i = 0; i < (int)data_len; i++) {
  86329. sum = 0;
  86330. switch(order) {
  86331. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86332. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86333. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86334. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86335. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86336. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86337. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86338. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86339. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86340. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86341. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86342. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86343. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86344. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86345. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86346. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86347. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86348. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86349. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86350. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86351. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86352. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86353. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86354. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86355. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86356. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86357. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86358. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86359. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86360. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86361. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86362. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86363. }
  86364. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86365. }
  86366. }
  86367. }
  86368. #endif
  86369. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86370. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  86371. {
  86372. FLAC__double error_scale;
  86373. FLAC__ASSERT(total_samples > 0);
  86374. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86375. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  86376. }
  86377. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  86378. {
  86379. if(lpc_error > 0.0) {
  86380. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  86381. if(bps >= 0.0)
  86382. return bps;
  86383. else
  86384. return 0.0;
  86385. }
  86386. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  86387. return 1e32;
  86388. }
  86389. else {
  86390. return 0.0;
  86391. }
  86392. }
  86393. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  86394. {
  86395. 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 */
  86396. FLAC__double bits, best_bits, error_scale;
  86397. FLAC__ASSERT(max_order > 0);
  86398. FLAC__ASSERT(total_samples > 0);
  86399. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86400. best_index = 0;
  86401. best_bits = (unsigned)(-1);
  86402. for(index = 0, order = 1; index < max_order; index++, order++) {
  86403. 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);
  86404. if(bits < best_bits) {
  86405. best_index = index;
  86406. best_bits = bits;
  86407. }
  86408. }
  86409. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86410. }
  86411. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86412. #endif
  86413. /*** End of inlined file: lpc_flac.c ***/
  86414. /*** Start of inlined file: md5.c ***/
  86415. /*** Start of inlined file: juce_FlacHeader.h ***/
  86416. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86417. // tasks..
  86418. #define VERSION "1.2.1"
  86419. #define FLAC__NO_DLL 1
  86420. #if JUCE_MSVC
  86421. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86422. #endif
  86423. #if JUCE_MAC
  86424. #define FLAC__SYS_DARWIN 1
  86425. #endif
  86426. /*** End of inlined file: juce_FlacHeader.h ***/
  86427. #if JUCE_USE_FLAC
  86428. #if HAVE_CONFIG_H
  86429. # include <config.h>
  86430. #endif
  86431. #include <stdlib.h> /* for malloc() */
  86432. #include <string.h> /* for memcpy() */
  86433. /*** Start of inlined file: md5.h ***/
  86434. #ifndef FLAC__PRIVATE__MD5_H
  86435. #define FLAC__PRIVATE__MD5_H
  86436. typedef struct {
  86437. FLAC__uint32 in[16];
  86438. FLAC__uint32 buf[4];
  86439. FLAC__uint32 bytes[2];
  86440. FLAC__byte *internal_buf;
  86441. size_t capacity;
  86442. } FLAC__MD5Context;
  86443. void FLAC__MD5Init(FLAC__MD5Context *context);
  86444. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86445. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86446. #endif
  86447. /*** End of inlined file: md5.h ***/
  86448. #ifndef FLaC__INLINE
  86449. #define FLaC__INLINE
  86450. #endif
  86451. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86452. #define F2(x, y, z) F1(z, x, y)
  86453. #define F3(x, y, z) (x ^ y ^ z)
  86454. #define F4(x, y, z) (y ^ (x | ~z))
  86455. #define MD5STEP(f,w,x,y,z,in,s) \
  86456. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86457. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86458. {
  86459. register FLAC__uint32 a, b, c, d;
  86460. a = buf[0];
  86461. b = buf[1];
  86462. c = buf[2];
  86463. d = buf[3];
  86464. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86465. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86466. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86467. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86468. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86469. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86470. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86471. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86472. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86473. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86474. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86475. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86476. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86477. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86478. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86479. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86480. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86481. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86482. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86483. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86484. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86485. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86486. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86487. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86488. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86489. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86490. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86491. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86492. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86493. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86494. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86495. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86496. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86497. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86498. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86499. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86500. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86501. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86502. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86503. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86504. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86505. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86506. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86507. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86508. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86509. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86510. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86511. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86512. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86513. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86514. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86515. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86516. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86517. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86518. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86519. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86520. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86521. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86522. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86523. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86524. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86525. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86526. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86527. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86528. buf[0] += a;
  86529. buf[1] += b;
  86530. buf[2] += c;
  86531. buf[3] += d;
  86532. }
  86533. #if WORDS_BIGENDIAN
  86534. //@@@@@@ OPT: use bswap/intrinsics
  86535. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86536. {
  86537. register FLAC__uint32 x;
  86538. do {
  86539. x = *buf;
  86540. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86541. *buf++ = (x >> 16) | (x << 16);
  86542. } while (--words);
  86543. }
  86544. static void byteSwapX16(FLAC__uint32 *buf)
  86545. {
  86546. register FLAC__uint32 x;
  86547. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86548. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86549. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86550. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86551. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86552. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86553. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86554. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86555. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86556. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86557. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86558. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86559. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86560. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86561. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86562. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16);
  86563. }
  86564. #else
  86565. #define byteSwap(buf, words)
  86566. #define byteSwapX16(buf)
  86567. #endif
  86568. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86569. {
  86570. FLAC__uint32 t;
  86571. t = ctx->bytes[0];
  86572. if ((ctx->bytes[0] = t + len) < t)
  86573. ctx->bytes[1]++; /* Carry from low to high */
  86574. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86575. if (t > len) {
  86576. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86577. return;
  86578. }
  86579. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86580. byteSwapX16(ctx->in);
  86581. FLAC__MD5Transform(ctx->buf, ctx->in);
  86582. buf += t;
  86583. len -= t;
  86584. while (len >= 64) {
  86585. memcpy(ctx->in, buf, 64);
  86586. byteSwapX16(ctx->in);
  86587. FLAC__MD5Transform(ctx->buf, ctx->in);
  86588. buf += 64;
  86589. len -= 64;
  86590. }
  86591. memcpy(ctx->in, buf, len);
  86592. }
  86593. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86594. {
  86595. ctx->buf[0] = 0x67452301;
  86596. ctx->buf[1] = 0xefcdab89;
  86597. ctx->buf[2] = 0x98badcfe;
  86598. ctx->buf[3] = 0x10325476;
  86599. ctx->bytes[0] = 0;
  86600. ctx->bytes[1] = 0;
  86601. ctx->internal_buf = 0;
  86602. ctx->capacity = 0;
  86603. }
  86604. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86605. {
  86606. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86607. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86608. *p++ = 0x80;
  86609. count = 56 - 1 - count;
  86610. if (count < 0) { /* Padding forces an extra block */
  86611. memset(p, 0, count + 8);
  86612. byteSwapX16(ctx->in);
  86613. FLAC__MD5Transform(ctx->buf, ctx->in);
  86614. p = (FLAC__byte *)ctx->in;
  86615. count = 56;
  86616. }
  86617. memset(p, 0, count);
  86618. byteSwap(ctx->in, 14);
  86619. ctx->in[14] = ctx->bytes[0] << 3;
  86620. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86621. FLAC__MD5Transform(ctx->buf, ctx->in);
  86622. byteSwap(ctx->buf, 4);
  86623. memcpy(digest, ctx->buf, 16);
  86624. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86625. if(0 != ctx->internal_buf) {
  86626. free(ctx->internal_buf);
  86627. ctx->internal_buf = 0;
  86628. ctx->capacity = 0;
  86629. }
  86630. }
  86631. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86632. {
  86633. unsigned channel, sample;
  86634. register FLAC__int32 a_word;
  86635. register FLAC__byte *buf_ = buf;
  86636. #if WORDS_BIGENDIAN
  86637. #else
  86638. if(channels == 2 && bytes_per_sample == 2) {
  86639. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86640. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86641. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86642. *buf1_ = (FLAC__int16)signal[1][sample];
  86643. }
  86644. else if(channels == 1 && bytes_per_sample == 2) {
  86645. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86646. for(sample = 0; sample < samples; sample++)
  86647. *buf1_++ = (FLAC__int16)signal[0][sample];
  86648. }
  86649. else
  86650. #endif
  86651. if(bytes_per_sample == 2) {
  86652. if(channels == 2) {
  86653. for(sample = 0; sample < samples; sample++) {
  86654. a_word = signal[0][sample];
  86655. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86656. *buf_++ = (FLAC__byte)a_word;
  86657. a_word = signal[1][sample];
  86658. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86659. *buf_++ = (FLAC__byte)a_word;
  86660. }
  86661. }
  86662. else if(channels == 1) {
  86663. for(sample = 0; sample < samples; sample++) {
  86664. a_word = signal[0][sample];
  86665. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86666. *buf_++ = (FLAC__byte)a_word;
  86667. }
  86668. }
  86669. else {
  86670. for(sample = 0; sample < samples; sample++) {
  86671. for(channel = 0; channel < channels; channel++) {
  86672. a_word = signal[channel][sample];
  86673. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86674. *buf_++ = (FLAC__byte)a_word;
  86675. }
  86676. }
  86677. }
  86678. }
  86679. else if(bytes_per_sample == 3) {
  86680. if(channels == 2) {
  86681. for(sample = 0; sample < samples; sample++) {
  86682. a_word = signal[0][sample];
  86683. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86684. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86685. *buf_++ = (FLAC__byte)a_word;
  86686. a_word = signal[1][sample];
  86687. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86688. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86689. *buf_++ = (FLAC__byte)a_word;
  86690. }
  86691. }
  86692. else if(channels == 1) {
  86693. for(sample = 0; sample < samples; sample++) {
  86694. a_word = signal[0][sample];
  86695. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86696. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86697. *buf_++ = (FLAC__byte)a_word;
  86698. }
  86699. }
  86700. else {
  86701. for(sample = 0; sample < samples; sample++) {
  86702. for(channel = 0; channel < channels; channel++) {
  86703. a_word = signal[channel][sample];
  86704. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86705. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86706. *buf_++ = (FLAC__byte)a_word;
  86707. }
  86708. }
  86709. }
  86710. }
  86711. else if(bytes_per_sample == 1) {
  86712. if(channels == 2) {
  86713. for(sample = 0; sample < samples; sample++) {
  86714. a_word = signal[0][sample];
  86715. *buf_++ = (FLAC__byte)a_word;
  86716. a_word = signal[1][sample];
  86717. *buf_++ = (FLAC__byte)a_word;
  86718. }
  86719. }
  86720. else if(channels == 1) {
  86721. for(sample = 0; sample < samples; sample++) {
  86722. a_word = signal[0][sample];
  86723. *buf_++ = (FLAC__byte)a_word;
  86724. }
  86725. }
  86726. else {
  86727. for(sample = 0; sample < samples; sample++) {
  86728. for(channel = 0; channel < channels; channel++) {
  86729. a_word = signal[channel][sample];
  86730. *buf_++ = (FLAC__byte)a_word;
  86731. }
  86732. }
  86733. }
  86734. }
  86735. else { /* bytes_per_sample == 4, maybe optimize more later */
  86736. for(sample = 0; sample < samples; sample++) {
  86737. for(channel = 0; channel < channels; channel++) {
  86738. a_word = signal[channel][sample];
  86739. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86740. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86741. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86742. *buf_++ = (FLAC__byte)a_word;
  86743. }
  86744. }
  86745. }
  86746. }
  86747. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86748. {
  86749. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  86750. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  86751. return false;
  86752. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  86753. return false;
  86754. if(ctx->capacity < bytes_needed) {
  86755. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  86756. if(0 == tmp) {
  86757. free(ctx->internal_buf);
  86758. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  86759. return false;
  86760. }
  86761. ctx->internal_buf = tmp;
  86762. ctx->capacity = bytes_needed;
  86763. }
  86764. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  86765. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  86766. return true;
  86767. }
  86768. #endif
  86769. /*** End of inlined file: md5.c ***/
  86770. /*** Start of inlined file: memory.c ***/
  86771. /*** Start of inlined file: juce_FlacHeader.h ***/
  86772. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86773. // tasks..
  86774. #define VERSION "1.2.1"
  86775. #define FLAC__NO_DLL 1
  86776. #if JUCE_MSVC
  86777. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86778. #endif
  86779. #if JUCE_MAC
  86780. #define FLAC__SYS_DARWIN 1
  86781. #endif
  86782. /*** End of inlined file: juce_FlacHeader.h ***/
  86783. #if JUCE_USE_FLAC
  86784. #if HAVE_CONFIG_H
  86785. # include <config.h>
  86786. #endif
  86787. /*** Start of inlined file: memory.h ***/
  86788. #ifndef FLAC__PRIVATE__MEMORY_H
  86789. #define FLAC__PRIVATE__MEMORY_H
  86790. #ifdef HAVE_CONFIG_H
  86791. #include <config.h>
  86792. #endif
  86793. #include <stdlib.h> /* for size_t */
  86794. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  86795. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  86796. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  86797. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  86798. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  86799. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86800. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  86801. #endif
  86802. #endif
  86803. /*** End of inlined file: memory.h ***/
  86804. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  86805. {
  86806. void *x;
  86807. FLAC__ASSERT(0 != aligned_address);
  86808. #ifdef FLAC__ALIGN_MALLOC_DATA
  86809. x = safe_malloc_add_2op_(bytes, /*+*/31);
  86810. #ifdef SIZEOF_VOIDP
  86811. #if SIZEOF_VOIDP == 4
  86812. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86813. #elif SIZEOF_VOIDP == 8
  86814. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86815. #else
  86816. # error Unsupported sizeof(void*)
  86817. #endif
  86818. #else
  86819. if(sizeof(void*) == sizeof(unsigned))
  86820. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86821. else if(sizeof(void*) == sizeof(FLAC__uint64))
  86822. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86823. else
  86824. return 0;
  86825. #endif
  86826. #else
  86827. x = safe_malloc_(bytes);
  86828. *aligned_address = x;
  86829. #endif
  86830. return x;
  86831. }
  86832. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  86833. {
  86834. FLAC__int32 *pu; /* unaligned pointer */
  86835. union { /* union needed to comply with C99 pointer aliasing rules */
  86836. FLAC__int32 *pa; /* aligned pointer */
  86837. void *pv; /* aligned pointer alias */
  86838. } u;
  86839. FLAC__ASSERT(elements > 0);
  86840. FLAC__ASSERT(0 != unaligned_pointer);
  86841. FLAC__ASSERT(0 != aligned_pointer);
  86842. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86843. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  86844. if(0 == pu) {
  86845. return false;
  86846. }
  86847. else {
  86848. if(*unaligned_pointer != 0)
  86849. free(*unaligned_pointer);
  86850. *unaligned_pointer = pu;
  86851. *aligned_pointer = u.pa;
  86852. return true;
  86853. }
  86854. }
  86855. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  86856. {
  86857. FLAC__uint32 *pu; /* unaligned pointer */
  86858. union { /* union needed to comply with C99 pointer aliasing rules */
  86859. FLAC__uint32 *pa; /* aligned pointer */
  86860. void *pv; /* aligned pointer alias */
  86861. } u;
  86862. FLAC__ASSERT(elements > 0);
  86863. FLAC__ASSERT(0 != unaligned_pointer);
  86864. FLAC__ASSERT(0 != aligned_pointer);
  86865. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86866. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86867. if(0 == pu) {
  86868. return false;
  86869. }
  86870. else {
  86871. if(*unaligned_pointer != 0)
  86872. free(*unaligned_pointer);
  86873. *unaligned_pointer = pu;
  86874. *aligned_pointer = u.pa;
  86875. return true;
  86876. }
  86877. }
  86878. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  86879. {
  86880. FLAC__uint64 *pu; /* unaligned pointer */
  86881. union { /* union needed to comply with C99 pointer aliasing rules */
  86882. FLAC__uint64 *pa; /* aligned pointer */
  86883. void *pv; /* aligned pointer alias */
  86884. } u;
  86885. FLAC__ASSERT(elements > 0);
  86886. FLAC__ASSERT(0 != unaligned_pointer);
  86887. FLAC__ASSERT(0 != aligned_pointer);
  86888. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86889. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86890. if(0 == pu) {
  86891. return false;
  86892. }
  86893. else {
  86894. if(*unaligned_pointer != 0)
  86895. free(*unaligned_pointer);
  86896. *unaligned_pointer = pu;
  86897. *aligned_pointer = u.pa;
  86898. return true;
  86899. }
  86900. }
  86901. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  86902. {
  86903. unsigned *pu; /* unaligned pointer */
  86904. union { /* union needed to comply with C99 pointer aliasing rules */
  86905. unsigned *pa; /* aligned pointer */
  86906. void *pv; /* aligned pointer alias */
  86907. } u;
  86908. FLAC__ASSERT(elements > 0);
  86909. FLAC__ASSERT(0 != unaligned_pointer);
  86910. FLAC__ASSERT(0 != aligned_pointer);
  86911. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86912. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86913. if(0 == pu) {
  86914. return false;
  86915. }
  86916. else {
  86917. if(*unaligned_pointer != 0)
  86918. free(*unaligned_pointer);
  86919. *unaligned_pointer = pu;
  86920. *aligned_pointer = u.pa;
  86921. return true;
  86922. }
  86923. }
  86924. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86925. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  86926. {
  86927. FLAC__real *pu; /* unaligned pointer */
  86928. union { /* union needed to comply with C99 pointer aliasing rules */
  86929. FLAC__real *pa; /* aligned pointer */
  86930. void *pv; /* aligned pointer alias */
  86931. } u;
  86932. FLAC__ASSERT(elements > 0);
  86933. FLAC__ASSERT(0 != unaligned_pointer);
  86934. FLAC__ASSERT(0 != aligned_pointer);
  86935. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86936. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86937. if(0 == pu) {
  86938. return false;
  86939. }
  86940. else {
  86941. if(*unaligned_pointer != 0)
  86942. free(*unaligned_pointer);
  86943. *unaligned_pointer = pu;
  86944. *aligned_pointer = u.pa;
  86945. return true;
  86946. }
  86947. }
  86948. #endif
  86949. #endif
  86950. /*** End of inlined file: memory.c ***/
  86951. /*** Start of inlined file: stream_decoder.c ***/
  86952. /*** Start of inlined file: juce_FlacHeader.h ***/
  86953. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86954. // tasks..
  86955. #define VERSION "1.2.1"
  86956. #define FLAC__NO_DLL 1
  86957. #if JUCE_MSVC
  86958. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86959. #endif
  86960. #if JUCE_MAC
  86961. #define FLAC__SYS_DARWIN 1
  86962. #endif
  86963. /*** End of inlined file: juce_FlacHeader.h ***/
  86964. #if JUCE_USE_FLAC
  86965. #if HAVE_CONFIG_H
  86966. # include <config.h>
  86967. #endif
  86968. #if defined _MSC_VER || defined __MINGW32__
  86969. #include <io.h> /* for _setmode() */
  86970. #include <fcntl.h> /* for _O_BINARY */
  86971. #endif
  86972. #if defined __CYGWIN__ || defined __EMX__
  86973. #include <io.h> /* for setmode(), O_BINARY */
  86974. #include <fcntl.h> /* for _O_BINARY */
  86975. #endif
  86976. #include <stdio.h>
  86977. #include <stdlib.h> /* for malloc() */
  86978. #include <string.h> /* for memset/memcpy() */
  86979. #include <sys/stat.h> /* for stat() */
  86980. #include <sys/types.h> /* for off_t */
  86981. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  86982. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  86983. #define fseeko fseek
  86984. #define ftello ftell
  86985. #endif
  86986. #endif
  86987. /*** Start of inlined file: stream_decoder.h ***/
  86988. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  86989. #define FLAC__PROTECTED__STREAM_DECODER_H
  86990. #if FLAC__HAS_OGG
  86991. #include "include/private/ogg_decoder_aspect.h"
  86992. #endif
  86993. typedef struct FLAC__StreamDecoderProtected {
  86994. FLAC__StreamDecoderState state;
  86995. unsigned channels;
  86996. FLAC__ChannelAssignment channel_assignment;
  86997. unsigned bits_per_sample;
  86998. unsigned sample_rate; /* in Hz */
  86999. unsigned blocksize; /* in samples (per channel) */
  87000. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  87001. #if FLAC__HAS_OGG
  87002. FLAC__OggDecoderAspect ogg_decoder_aspect;
  87003. #endif
  87004. } FLAC__StreamDecoderProtected;
  87005. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  87006. #endif
  87007. /*** End of inlined file: stream_decoder.h ***/
  87008. #ifdef max
  87009. #undef max
  87010. #endif
  87011. #define max(a,b) ((a)>(b)?(a):(b))
  87012. #ifdef _MSC_VER
  87013. #define FLAC__U64L(x) x
  87014. #else
  87015. #define FLAC__U64L(x) x##LLU
  87016. #endif
  87017. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  87018. #if FLAC__HAS_OGG
  87019. 1
  87020. #else
  87021. 0
  87022. #endif
  87023. ;
  87024. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  87025. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  87026. static FILE *get_binary_stdin_(void);
  87027. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  87028. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  87029. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  87030. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  87031. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87032. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87033. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  87034. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  87035. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  87036. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  87037. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  87038. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  87039. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  87040. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87041. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87042. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87043. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87044. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87045. 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);
  87046. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  87047. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  87048. #if FLAC__HAS_OGG
  87049. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  87050. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87051. #endif
  87052. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  87053. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  87054. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87055. #if FLAC__HAS_OGG
  87056. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87057. #endif
  87058. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87059. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  87060. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  87061. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  87062. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  87063. typedef struct FLAC__StreamDecoderPrivate {
  87064. #if FLAC__HAS_OGG
  87065. FLAC__bool is_ogg;
  87066. #endif
  87067. FLAC__StreamDecoderReadCallback read_callback;
  87068. FLAC__StreamDecoderSeekCallback seek_callback;
  87069. FLAC__StreamDecoderTellCallback tell_callback;
  87070. FLAC__StreamDecoderLengthCallback length_callback;
  87071. FLAC__StreamDecoderEofCallback eof_callback;
  87072. FLAC__StreamDecoderWriteCallback write_callback;
  87073. FLAC__StreamDecoderMetadataCallback metadata_callback;
  87074. FLAC__StreamDecoderErrorCallback error_callback;
  87075. 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[]);
  87076. 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[]);
  87077. 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[]);
  87078. 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[]);
  87079. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  87080. void *client_data;
  87081. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  87082. FLAC__BitReader *input;
  87083. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  87084. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  87085. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  87086. unsigned output_capacity, output_channels;
  87087. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  87088. FLAC__uint64 samples_decoded;
  87089. FLAC__bool has_stream_info, has_seek_table;
  87090. FLAC__StreamMetadata stream_info;
  87091. FLAC__StreamMetadata seek_table;
  87092. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  87093. FLAC__byte *metadata_filter_ids;
  87094. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  87095. FLAC__Frame frame;
  87096. FLAC__bool cached; /* true if there is a byte in lookahead */
  87097. FLAC__CPUInfo cpuinfo;
  87098. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  87099. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  87100. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  87101. 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 */
  87102. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  87103. FLAC__bool is_seeking;
  87104. FLAC__MD5Context md5context;
  87105. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  87106. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  87107. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  87108. FLAC__uint64 target_sample;
  87109. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  87110. #if FLAC__HAS_OGG
  87111. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  87112. #endif
  87113. } FLAC__StreamDecoderPrivate;
  87114. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  87115. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  87116. "FLAC__STREAM_DECODER_READ_METADATA",
  87117. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  87118. "FLAC__STREAM_DECODER_READ_FRAME",
  87119. "FLAC__STREAM_DECODER_END_OF_STREAM",
  87120. "FLAC__STREAM_DECODER_OGG_ERROR",
  87121. "FLAC__STREAM_DECODER_SEEK_ERROR",
  87122. "FLAC__STREAM_DECODER_ABORTED",
  87123. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  87124. "FLAC__STREAM_DECODER_UNINITIALIZED"
  87125. };
  87126. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  87127. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  87128. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  87129. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  87130. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  87131. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  87132. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  87133. };
  87134. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  87135. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  87136. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  87137. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  87138. };
  87139. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  87140. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  87141. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  87142. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  87143. };
  87144. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  87145. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  87146. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  87147. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  87148. };
  87149. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  87150. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  87151. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  87152. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  87153. };
  87154. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  87155. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  87156. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  87157. };
  87158. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  87159. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  87160. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  87161. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  87162. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  87163. };
  87164. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  87165. {
  87166. FLAC__StreamDecoder *decoder;
  87167. unsigned i;
  87168. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  87169. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  87170. if(decoder == 0) {
  87171. return 0;
  87172. }
  87173. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  87174. if(decoder->protected_ == 0) {
  87175. free(decoder);
  87176. return 0;
  87177. }
  87178. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  87179. if(decoder->private_ == 0) {
  87180. free(decoder->protected_);
  87181. free(decoder);
  87182. return 0;
  87183. }
  87184. decoder->private_->input = FLAC__bitreader_new();
  87185. if(decoder->private_->input == 0) {
  87186. free(decoder->private_);
  87187. free(decoder->protected_);
  87188. free(decoder);
  87189. return 0;
  87190. }
  87191. decoder->private_->metadata_filter_ids_capacity = 16;
  87192. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  87193. FLAC__bitreader_delete(decoder->private_->input);
  87194. free(decoder->private_);
  87195. free(decoder->protected_);
  87196. free(decoder);
  87197. return 0;
  87198. }
  87199. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87200. decoder->private_->output[i] = 0;
  87201. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87202. }
  87203. decoder->private_->output_capacity = 0;
  87204. decoder->private_->output_channels = 0;
  87205. decoder->private_->has_seek_table = false;
  87206. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87207. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  87208. decoder->private_->file = 0;
  87209. set_defaults_dec(decoder);
  87210. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87211. return decoder;
  87212. }
  87213. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  87214. {
  87215. unsigned i;
  87216. FLAC__ASSERT(0 != decoder);
  87217. FLAC__ASSERT(0 != decoder->protected_);
  87218. FLAC__ASSERT(0 != decoder->private_);
  87219. FLAC__ASSERT(0 != decoder->private_->input);
  87220. (void)FLAC__stream_decoder_finish(decoder);
  87221. if(0 != decoder->private_->metadata_filter_ids)
  87222. free(decoder->private_->metadata_filter_ids);
  87223. FLAC__bitreader_delete(decoder->private_->input);
  87224. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87225. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  87226. free(decoder->private_);
  87227. free(decoder->protected_);
  87228. free(decoder);
  87229. }
  87230. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  87231. FLAC__StreamDecoder *decoder,
  87232. FLAC__StreamDecoderReadCallback read_callback,
  87233. FLAC__StreamDecoderSeekCallback seek_callback,
  87234. FLAC__StreamDecoderTellCallback tell_callback,
  87235. FLAC__StreamDecoderLengthCallback length_callback,
  87236. FLAC__StreamDecoderEofCallback eof_callback,
  87237. FLAC__StreamDecoderWriteCallback write_callback,
  87238. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87239. FLAC__StreamDecoderErrorCallback error_callback,
  87240. void *client_data,
  87241. FLAC__bool is_ogg
  87242. )
  87243. {
  87244. FLAC__ASSERT(0 != decoder);
  87245. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87246. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  87247. #if !FLAC__HAS_OGG
  87248. if(is_ogg)
  87249. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  87250. #endif
  87251. if(
  87252. 0 == read_callback ||
  87253. 0 == write_callback ||
  87254. 0 == error_callback ||
  87255. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  87256. )
  87257. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  87258. #if FLAC__HAS_OGG
  87259. decoder->private_->is_ogg = is_ogg;
  87260. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  87261. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  87262. #endif
  87263. FLAC__cpu_info(&decoder->private_->cpuinfo);
  87264. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  87265. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  87266. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  87267. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  87268. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  87269. #ifndef FLAC__NO_ASM
  87270. if(decoder->private_->cpuinfo.use_asm) {
  87271. #ifdef FLAC__CPU_IA32
  87272. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  87273. #ifdef FLAC__HAS_NASM
  87274. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  87275. if(decoder->private_->cpuinfo.data.ia32.bswap)
  87276. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  87277. #endif
  87278. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  87279. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87280. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87281. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87282. }
  87283. else {
  87284. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87285. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  87286. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  87287. }
  87288. #endif
  87289. #elif defined FLAC__CPU_PPC
  87290. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  87291. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  87292. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  87293. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  87294. }
  87295. #endif
  87296. }
  87297. #endif
  87298. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87299. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87300. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87301. }
  87302. decoder->private_->read_callback = read_callback;
  87303. decoder->private_->seek_callback = seek_callback;
  87304. decoder->private_->tell_callback = tell_callback;
  87305. decoder->private_->length_callback = length_callback;
  87306. decoder->private_->eof_callback = eof_callback;
  87307. decoder->private_->write_callback = write_callback;
  87308. decoder->private_->metadata_callback = metadata_callback;
  87309. decoder->private_->error_callback = error_callback;
  87310. decoder->private_->client_data = client_data;
  87311. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87312. decoder->private_->samples_decoded = 0;
  87313. decoder->private_->has_stream_info = false;
  87314. decoder->private_->cached = false;
  87315. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87316. decoder->private_->is_seeking = false;
  87317. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87318. if(!FLAC__stream_decoder_reset(decoder)) {
  87319. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87320. }
  87321. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87322. }
  87323. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  87324. FLAC__StreamDecoder *decoder,
  87325. FLAC__StreamDecoderReadCallback read_callback,
  87326. FLAC__StreamDecoderSeekCallback seek_callback,
  87327. FLAC__StreamDecoderTellCallback tell_callback,
  87328. FLAC__StreamDecoderLengthCallback length_callback,
  87329. FLAC__StreamDecoderEofCallback eof_callback,
  87330. FLAC__StreamDecoderWriteCallback write_callback,
  87331. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87332. FLAC__StreamDecoderErrorCallback error_callback,
  87333. void *client_data
  87334. )
  87335. {
  87336. return init_stream_internal_dec(
  87337. decoder,
  87338. read_callback,
  87339. seek_callback,
  87340. tell_callback,
  87341. length_callback,
  87342. eof_callback,
  87343. write_callback,
  87344. metadata_callback,
  87345. error_callback,
  87346. client_data,
  87347. false
  87348. );
  87349. }
  87350. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87351. FLAC__StreamDecoder *decoder,
  87352. FLAC__StreamDecoderReadCallback read_callback,
  87353. FLAC__StreamDecoderSeekCallback seek_callback,
  87354. FLAC__StreamDecoderTellCallback tell_callback,
  87355. FLAC__StreamDecoderLengthCallback length_callback,
  87356. FLAC__StreamDecoderEofCallback eof_callback,
  87357. FLAC__StreamDecoderWriteCallback write_callback,
  87358. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87359. FLAC__StreamDecoderErrorCallback error_callback,
  87360. void *client_data
  87361. )
  87362. {
  87363. return init_stream_internal_dec(
  87364. decoder,
  87365. read_callback,
  87366. seek_callback,
  87367. tell_callback,
  87368. length_callback,
  87369. eof_callback,
  87370. write_callback,
  87371. metadata_callback,
  87372. error_callback,
  87373. client_data,
  87374. true
  87375. );
  87376. }
  87377. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  87378. FLAC__StreamDecoder *decoder,
  87379. FILE *file,
  87380. FLAC__StreamDecoderWriteCallback write_callback,
  87381. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87382. FLAC__StreamDecoderErrorCallback error_callback,
  87383. void *client_data,
  87384. FLAC__bool is_ogg
  87385. )
  87386. {
  87387. FLAC__ASSERT(0 != decoder);
  87388. FLAC__ASSERT(0 != file);
  87389. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87390. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87391. if(0 == write_callback || 0 == error_callback)
  87392. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87393. if(file == stdin)
  87394. file = get_binary_stdin_(); /* just to be safe */
  87395. decoder->private_->file = file;
  87396. return init_stream_internal_dec(
  87397. decoder,
  87398. file_read_callback_dec,
  87399. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  87400. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  87401. decoder->private_->file == stdin? 0: file_length_callback_,
  87402. file_eof_callback_,
  87403. write_callback,
  87404. metadata_callback,
  87405. error_callback,
  87406. client_data,
  87407. is_ogg
  87408. );
  87409. }
  87410. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87411. FLAC__StreamDecoder *decoder,
  87412. FILE *file,
  87413. FLAC__StreamDecoderWriteCallback write_callback,
  87414. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87415. FLAC__StreamDecoderErrorCallback error_callback,
  87416. void *client_data
  87417. )
  87418. {
  87419. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87420. }
  87421. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  87422. FLAC__StreamDecoder *decoder,
  87423. FILE *file,
  87424. FLAC__StreamDecoderWriteCallback write_callback,
  87425. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87426. FLAC__StreamDecoderErrorCallback error_callback,
  87427. void *client_data
  87428. )
  87429. {
  87430. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87431. }
  87432. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87433. FLAC__StreamDecoder *decoder,
  87434. const char *filename,
  87435. FLAC__StreamDecoderWriteCallback write_callback,
  87436. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87437. FLAC__StreamDecoderErrorCallback error_callback,
  87438. void *client_data,
  87439. FLAC__bool is_ogg
  87440. )
  87441. {
  87442. FILE *file;
  87443. FLAC__ASSERT(0 != decoder);
  87444. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87445. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87446. if(0 == write_callback || 0 == error_callback)
  87447. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87448. file = filename? fopen(filename, "rb") : stdin;
  87449. if(0 == file)
  87450. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87451. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87452. }
  87453. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87454. FLAC__StreamDecoder *decoder,
  87455. const char *filename,
  87456. FLAC__StreamDecoderWriteCallback write_callback,
  87457. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87458. FLAC__StreamDecoderErrorCallback error_callback,
  87459. void *client_data
  87460. )
  87461. {
  87462. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87463. }
  87464. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  87465. FLAC__StreamDecoder *decoder,
  87466. const char *filename,
  87467. FLAC__StreamDecoderWriteCallback write_callback,
  87468. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87469. FLAC__StreamDecoderErrorCallback error_callback,
  87470. void *client_data
  87471. )
  87472. {
  87473. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87474. }
  87475. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87476. {
  87477. FLAC__bool md5_failed = false;
  87478. unsigned i;
  87479. FLAC__ASSERT(0 != decoder);
  87480. FLAC__ASSERT(0 != decoder->private_);
  87481. FLAC__ASSERT(0 != decoder->protected_);
  87482. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87483. return true;
  87484. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87485. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87486. free(decoder->private_->seek_table.data.seek_table.points);
  87487. decoder->private_->seek_table.data.seek_table.points = 0;
  87488. decoder->private_->has_seek_table = false;
  87489. }
  87490. FLAC__bitreader_free(decoder->private_->input);
  87491. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87492. if(0 != decoder->private_->output[i]) {
  87493. free(decoder->private_->output[i]-4);
  87494. decoder->private_->output[i] = 0;
  87495. }
  87496. if(0 != decoder->private_->residual_unaligned[i]) {
  87497. free(decoder->private_->residual_unaligned[i]);
  87498. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87499. }
  87500. }
  87501. decoder->private_->output_capacity = 0;
  87502. decoder->private_->output_channels = 0;
  87503. #if FLAC__HAS_OGG
  87504. if(decoder->private_->is_ogg)
  87505. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87506. #endif
  87507. if(0 != decoder->private_->file) {
  87508. if(decoder->private_->file != stdin)
  87509. fclose(decoder->private_->file);
  87510. decoder->private_->file = 0;
  87511. }
  87512. if(decoder->private_->do_md5_checking) {
  87513. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87514. md5_failed = true;
  87515. }
  87516. decoder->private_->is_seeking = false;
  87517. set_defaults_dec(decoder);
  87518. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87519. return !md5_failed;
  87520. }
  87521. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87522. {
  87523. FLAC__ASSERT(0 != decoder);
  87524. FLAC__ASSERT(0 != decoder->private_);
  87525. FLAC__ASSERT(0 != decoder->protected_);
  87526. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87527. return false;
  87528. #if FLAC__HAS_OGG
  87529. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87530. return true;
  87531. #else
  87532. (void)value;
  87533. return false;
  87534. #endif
  87535. }
  87536. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87537. {
  87538. FLAC__ASSERT(0 != decoder);
  87539. FLAC__ASSERT(0 != decoder->protected_);
  87540. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87541. return false;
  87542. decoder->protected_->md5_checking = value;
  87543. return true;
  87544. }
  87545. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87546. {
  87547. FLAC__ASSERT(0 != decoder);
  87548. FLAC__ASSERT(0 != decoder->private_);
  87549. FLAC__ASSERT(0 != decoder->protected_);
  87550. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87551. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87552. return false;
  87553. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87554. return false;
  87555. decoder->private_->metadata_filter[type] = true;
  87556. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87557. decoder->private_->metadata_filter_ids_count = 0;
  87558. return true;
  87559. }
  87560. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87561. {
  87562. FLAC__ASSERT(0 != decoder);
  87563. FLAC__ASSERT(0 != decoder->private_);
  87564. FLAC__ASSERT(0 != decoder->protected_);
  87565. FLAC__ASSERT(0 != id);
  87566. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87567. return false;
  87568. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87569. return true;
  87570. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87571. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87572. 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))) {
  87573. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87574. return false;
  87575. }
  87576. decoder->private_->metadata_filter_ids_capacity *= 2;
  87577. }
  87578. 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));
  87579. decoder->private_->metadata_filter_ids_count++;
  87580. return true;
  87581. }
  87582. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87583. {
  87584. unsigned i;
  87585. FLAC__ASSERT(0 != decoder);
  87586. FLAC__ASSERT(0 != decoder->private_);
  87587. FLAC__ASSERT(0 != decoder->protected_);
  87588. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87589. return false;
  87590. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87591. decoder->private_->metadata_filter[i] = true;
  87592. decoder->private_->metadata_filter_ids_count = 0;
  87593. return true;
  87594. }
  87595. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87596. {
  87597. FLAC__ASSERT(0 != decoder);
  87598. FLAC__ASSERT(0 != decoder->private_);
  87599. FLAC__ASSERT(0 != decoder->protected_);
  87600. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87601. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87602. return false;
  87603. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87604. return false;
  87605. decoder->private_->metadata_filter[type] = false;
  87606. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87607. decoder->private_->metadata_filter_ids_count = 0;
  87608. return true;
  87609. }
  87610. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87611. {
  87612. FLAC__ASSERT(0 != decoder);
  87613. FLAC__ASSERT(0 != decoder->private_);
  87614. FLAC__ASSERT(0 != decoder->protected_);
  87615. FLAC__ASSERT(0 != id);
  87616. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87617. return false;
  87618. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87619. return true;
  87620. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87621. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87622. 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))) {
  87623. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87624. return false;
  87625. }
  87626. decoder->private_->metadata_filter_ids_capacity *= 2;
  87627. }
  87628. 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));
  87629. decoder->private_->metadata_filter_ids_count++;
  87630. return true;
  87631. }
  87632. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87633. {
  87634. FLAC__ASSERT(0 != decoder);
  87635. FLAC__ASSERT(0 != decoder->private_);
  87636. FLAC__ASSERT(0 != decoder->protected_);
  87637. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87638. return false;
  87639. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87640. decoder->private_->metadata_filter_ids_count = 0;
  87641. return true;
  87642. }
  87643. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87644. {
  87645. FLAC__ASSERT(0 != decoder);
  87646. FLAC__ASSERT(0 != decoder->protected_);
  87647. return decoder->protected_->state;
  87648. }
  87649. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87650. {
  87651. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87652. }
  87653. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87654. {
  87655. FLAC__ASSERT(0 != decoder);
  87656. FLAC__ASSERT(0 != decoder->protected_);
  87657. return decoder->protected_->md5_checking;
  87658. }
  87659. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87660. {
  87661. FLAC__ASSERT(0 != decoder);
  87662. FLAC__ASSERT(0 != decoder->protected_);
  87663. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87664. }
  87665. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87666. {
  87667. FLAC__ASSERT(0 != decoder);
  87668. FLAC__ASSERT(0 != decoder->protected_);
  87669. return decoder->protected_->channels;
  87670. }
  87671. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  87672. {
  87673. FLAC__ASSERT(0 != decoder);
  87674. FLAC__ASSERT(0 != decoder->protected_);
  87675. return decoder->protected_->channel_assignment;
  87676. }
  87677. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  87678. {
  87679. FLAC__ASSERT(0 != decoder);
  87680. FLAC__ASSERT(0 != decoder->protected_);
  87681. return decoder->protected_->bits_per_sample;
  87682. }
  87683. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  87684. {
  87685. FLAC__ASSERT(0 != decoder);
  87686. FLAC__ASSERT(0 != decoder->protected_);
  87687. return decoder->protected_->sample_rate;
  87688. }
  87689. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  87690. {
  87691. FLAC__ASSERT(0 != decoder);
  87692. FLAC__ASSERT(0 != decoder->protected_);
  87693. return decoder->protected_->blocksize;
  87694. }
  87695. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  87696. {
  87697. FLAC__ASSERT(0 != decoder);
  87698. FLAC__ASSERT(0 != decoder->private_);
  87699. FLAC__ASSERT(0 != position);
  87700. #if FLAC__HAS_OGG
  87701. if(decoder->private_->is_ogg)
  87702. return false;
  87703. #endif
  87704. if(0 == decoder->private_->tell_callback)
  87705. return false;
  87706. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  87707. return false;
  87708. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  87709. return false;
  87710. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  87711. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  87712. return true;
  87713. }
  87714. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  87715. {
  87716. FLAC__ASSERT(0 != decoder);
  87717. FLAC__ASSERT(0 != decoder->private_);
  87718. FLAC__ASSERT(0 != decoder->protected_);
  87719. decoder->private_->samples_decoded = 0;
  87720. decoder->private_->do_md5_checking = false;
  87721. #if FLAC__HAS_OGG
  87722. if(decoder->private_->is_ogg)
  87723. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  87724. #endif
  87725. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  87726. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87727. return false;
  87728. }
  87729. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87730. return true;
  87731. }
  87732. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  87733. {
  87734. FLAC__ASSERT(0 != decoder);
  87735. FLAC__ASSERT(0 != decoder->private_);
  87736. FLAC__ASSERT(0 != decoder->protected_);
  87737. if(!FLAC__stream_decoder_flush(decoder)) {
  87738. return false;
  87739. }
  87740. #if FLAC__HAS_OGG
  87741. if(decoder->private_->is_ogg)
  87742. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  87743. #endif
  87744. if(!decoder->private_->internal_reset_hack) {
  87745. if(decoder->private_->file == stdin)
  87746. return false; /* can't rewind stdin, reset fails */
  87747. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  87748. return false; /* seekable and seek fails, reset fails */
  87749. }
  87750. else
  87751. decoder->private_->internal_reset_hack = false;
  87752. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  87753. decoder->private_->has_stream_info = false;
  87754. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87755. free(decoder->private_->seek_table.data.seek_table.points);
  87756. decoder->private_->seek_table.data.seek_table.points = 0;
  87757. decoder->private_->has_seek_table = false;
  87758. }
  87759. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87760. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87761. FLAC__MD5Init(&decoder->private_->md5context);
  87762. decoder->private_->first_frame_offset = 0;
  87763. decoder->private_->unparseable_frame_count = 0;
  87764. return true;
  87765. }
  87766. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  87767. {
  87768. FLAC__bool got_a_frame;
  87769. FLAC__ASSERT(0 != decoder);
  87770. FLAC__ASSERT(0 != decoder->protected_);
  87771. while(1) {
  87772. switch(decoder->protected_->state) {
  87773. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87774. if(!find_metadata_(decoder))
  87775. return false; /* above function sets the status for us */
  87776. break;
  87777. case FLAC__STREAM_DECODER_READ_METADATA:
  87778. if(!read_metadata_(decoder))
  87779. return false; /* above function sets the status for us */
  87780. else
  87781. return true;
  87782. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87783. if(!frame_sync_(decoder))
  87784. return true; /* above function sets the status for us */
  87785. break;
  87786. case FLAC__STREAM_DECODER_READ_FRAME:
  87787. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  87788. return false; /* above function sets the status for us */
  87789. if(got_a_frame)
  87790. return true; /* above function sets the status for us */
  87791. break;
  87792. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87793. case FLAC__STREAM_DECODER_ABORTED:
  87794. return true;
  87795. default:
  87796. FLAC__ASSERT(0);
  87797. return false;
  87798. }
  87799. }
  87800. }
  87801. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  87802. {
  87803. FLAC__ASSERT(0 != decoder);
  87804. FLAC__ASSERT(0 != decoder->protected_);
  87805. while(1) {
  87806. switch(decoder->protected_->state) {
  87807. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87808. if(!find_metadata_(decoder))
  87809. return false; /* above function sets the status for us */
  87810. break;
  87811. case FLAC__STREAM_DECODER_READ_METADATA:
  87812. if(!read_metadata_(decoder))
  87813. return false; /* above function sets the status for us */
  87814. break;
  87815. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87816. case FLAC__STREAM_DECODER_READ_FRAME:
  87817. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87818. case FLAC__STREAM_DECODER_ABORTED:
  87819. return true;
  87820. default:
  87821. FLAC__ASSERT(0);
  87822. return false;
  87823. }
  87824. }
  87825. }
  87826. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  87827. {
  87828. FLAC__bool dummy;
  87829. FLAC__ASSERT(0 != decoder);
  87830. FLAC__ASSERT(0 != decoder->protected_);
  87831. while(1) {
  87832. switch(decoder->protected_->state) {
  87833. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87834. if(!find_metadata_(decoder))
  87835. return false; /* above function sets the status for us */
  87836. break;
  87837. case FLAC__STREAM_DECODER_READ_METADATA:
  87838. if(!read_metadata_(decoder))
  87839. return false; /* above function sets the status for us */
  87840. break;
  87841. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87842. if(!frame_sync_(decoder))
  87843. return true; /* above function sets the status for us */
  87844. break;
  87845. case FLAC__STREAM_DECODER_READ_FRAME:
  87846. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  87847. return false; /* above function sets the status for us */
  87848. break;
  87849. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87850. case FLAC__STREAM_DECODER_ABORTED:
  87851. return true;
  87852. default:
  87853. FLAC__ASSERT(0);
  87854. return false;
  87855. }
  87856. }
  87857. }
  87858. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  87859. {
  87860. FLAC__bool got_a_frame;
  87861. FLAC__ASSERT(0 != decoder);
  87862. FLAC__ASSERT(0 != decoder->protected_);
  87863. while(1) {
  87864. switch(decoder->protected_->state) {
  87865. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87866. case FLAC__STREAM_DECODER_READ_METADATA:
  87867. return false; /* above function sets the status for us */
  87868. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87869. if(!frame_sync_(decoder))
  87870. return true; /* above function sets the status for us */
  87871. break;
  87872. case FLAC__STREAM_DECODER_READ_FRAME:
  87873. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  87874. return false; /* above function sets the status for us */
  87875. if(got_a_frame)
  87876. return true; /* above function sets the status for us */
  87877. break;
  87878. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87879. case FLAC__STREAM_DECODER_ABORTED:
  87880. return true;
  87881. default:
  87882. FLAC__ASSERT(0);
  87883. return false;
  87884. }
  87885. }
  87886. }
  87887. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  87888. {
  87889. FLAC__uint64 length;
  87890. FLAC__ASSERT(0 != decoder);
  87891. if(
  87892. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  87893. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  87894. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  87895. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  87896. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  87897. )
  87898. return false;
  87899. if(0 == decoder->private_->seek_callback)
  87900. return false;
  87901. FLAC__ASSERT(decoder->private_->seek_callback);
  87902. FLAC__ASSERT(decoder->private_->tell_callback);
  87903. FLAC__ASSERT(decoder->private_->length_callback);
  87904. FLAC__ASSERT(decoder->private_->eof_callback);
  87905. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  87906. return false;
  87907. decoder->private_->is_seeking = true;
  87908. decoder->private_->do_md5_checking = false;
  87909. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  87910. decoder->private_->is_seeking = false;
  87911. return false;
  87912. }
  87913. if(
  87914. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  87915. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  87916. ) {
  87917. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  87918. decoder->private_->is_seeking = false;
  87919. return false;
  87920. }
  87921. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  87922. decoder->private_->is_seeking = false;
  87923. return false;
  87924. }
  87925. }
  87926. {
  87927. const FLAC__bool ok =
  87928. #if FLAC__HAS_OGG
  87929. decoder->private_->is_ogg?
  87930. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  87931. #endif
  87932. seek_to_absolute_sample_(decoder, length, sample)
  87933. ;
  87934. decoder->private_->is_seeking = false;
  87935. return ok;
  87936. }
  87937. }
  87938. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  87939. {
  87940. FLAC__ASSERT(0 != decoder);
  87941. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87942. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  87943. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  87944. }
  87945. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  87946. {
  87947. #if FLAC__HAS_OGG
  87948. decoder->private_->is_ogg = false;
  87949. #endif
  87950. decoder->private_->read_callback = 0;
  87951. decoder->private_->seek_callback = 0;
  87952. decoder->private_->tell_callback = 0;
  87953. decoder->private_->length_callback = 0;
  87954. decoder->private_->eof_callback = 0;
  87955. decoder->private_->write_callback = 0;
  87956. decoder->private_->metadata_callback = 0;
  87957. decoder->private_->error_callback = 0;
  87958. decoder->private_->client_data = 0;
  87959. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87960. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  87961. decoder->private_->metadata_filter_ids_count = 0;
  87962. decoder->protected_->md5_checking = false;
  87963. #if FLAC__HAS_OGG
  87964. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  87965. #endif
  87966. }
  87967. FILE *get_binary_stdin_(void)
  87968. {
  87969. #if defined _MSC_VER || defined __MINGW32__
  87970. _setmode(_fileno(stdin), _O_BINARY);
  87971. #elif defined __CYGWIN__
  87972. setmode(_fileno(stdin), _O_BINARY);
  87973. #elif defined __EMX__
  87974. setmode(fileno(stdin), O_BINARY);
  87975. #endif
  87976. return stdin;
  87977. }
  87978. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  87979. {
  87980. unsigned i;
  87981. FLAC__int32 *tmp;
  87982. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  87983. return true;
  87984. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87985. if(0 != decoder->private_->output[i]) {
  87986. free(decoder->private_->output[i]-4);
  87987. decoder->private_->output[i] = 0;
  87988. }
  87989. if(0 != decoder->private_->residual_unaligned[i]) {
  87990. free(decoder->private_->residual_unaligned[i]);
  87991. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87992. }
  87993. }
  87994. for(i = 0; i < channels; i++) {
  87995. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  87996. if(tmp == 0) {
  87997. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87998. return false;
  87999. }
  88000. memset(tmp, 0, sizeof(FLAC__int32)*4);
  88001. decoder->private_->output[i] = tmp + 4;
  88002. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  88003. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88004. return false;
  88005. }
  88006. }
  88007. decoder->private_->output_capacity = size;
  88008. decoder->private_->output_channels = channels;
  88009. return true;
  88010. }
  88011. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  88012. {
  88013. size_t i;
  88014. FLAC__ASSERT(0 != decoder);
  88015. FLAC__ASSERT(0 != decoder->private_);
  88016. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  88017. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  88018. return true;
  88019. return false;
  88020. }
  88021. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  88022. {
  88023. FLAC__uint32 x;
  88024. unsigned i, id_;
  88025. FLAC__bool first = true;
  88026. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88027. for(i = id_ = 0; i < 4; ) {
  88028. if(decoder->private_->cached) {
  88029. x = (FLAC__uint32)decoder->private_->lookahead;
  88030. decoder->private_->cached = false;
  88031. }
  88032. else {
  88033. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88034. return false; /* read_callback_ sets the state for us */
  88035. }
  88036. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  88037. first = true;
  88038. i++;
  88039. id_ = 0;
  88040. continue;
  88041. }
  88042. if(x == ID3V2_TAG_[id_]) {
  88043. id_++;
  88044. i = 0;
  88045. if(id_ == 3) {
  88046. if(!skip_id3v2_tag_(decoder))
  88047. return false; /* skip_id3v2_tag_ sets the state for us */
  88048. }
  88049. continue;
  88050. }
  88051. id_ = 0;
  88052. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88053. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88054. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88055. return false; /* read_callback_ sets the state for us */
  88056. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88057. decoder->private_->lookahead = (FLAC__byte)x;
  88058. decoder->private_->cached = true;
  88059. }
  88060. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88061. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88062. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88063. return true;
  88064. }
  88065. }
  88066. i = 0;
  88067. if(first) {
  88068. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88069. first = false;
  88070. }
  88071. }
  88072. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  88073. return true;
  88074. }
  88075. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  88076. {
  88077. FLAC__bool is_last;
  88078. FLAC__uint32 i, x, type, length;
  88079. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88080. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  88081. return false; /* read_callback_ sets the state for us */
  88082. is_last = x? true : false;
  88083. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  88084. return false; /* read_callback_ sets the state for us */
  88085. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  88086. return false; /* read_callback_ sets the state for us */
  88087. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  88088. if(!read_metadata_streaminfo_(decoder, is_last, length))
  88089. return false;
  88090. decoder->private_->has_stream_info = true;
  88091. 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))
  88092. decoder->private_->do_md5_checking = false;
  88093. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  88094. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  88095. }
  88096. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  88097. if(!read_metadata_seektable_(decoder, is_last, length))
  88098. return false;
  88099. decoder->private_->has_seek_table = true;
  88100. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  88101. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  88102. }
  88103. else {
  88104. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  88105. unsigned real_length = length;
  88106. FLAC__StreamMetadata block;
  88107. block.is_last = is_last;
  88108. block.type = (FLAC__MetadataType)type;
  88109. block.length = length;
  88110. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  88111. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  88112. return false; /* read_callback_ sets the state for us */
  88113. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  88114. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  88115. return false;
  88116. }
  88117. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  88118. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  88119. skip_it = !skip_it;
  88120. }
  88121. if(skip_it) {
  88122. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88123. return false; /* read_callback_ sets the state for us */
  88124. }
  88125. else {
  88126. switch(type) {
  88127. case FLAC__METADATA_TYPE_PADDING:
  88128. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88129. return false; /* read_callback_ sets the state for us */
  88130. break;
  88131. case FLAC__METADATA_TYPE_APPLICATION:
  88132. if(real_length > 0) {
  88133. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  88134. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88135. return false;
  88136. }
  88137. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  88138. return false; /* read_callback_ sets the state for us */
  88139. }
  88140. else
  88141. block.data.application.data = 0;
  88142. break;
  88143. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88144. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  88145. return false;
  88146. break;
  88147. case FLAC__METADATA_TYPE_CUESHEET:
  88148. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  88149. return false;
  88150. break;
  88151. case FLAC__METADATA_TYPE_PICTURE:
  88152. if(!read_metadata_picture_(decoder, &block.data.picture))
  88153. return false;
  88154. break;
  88155. case FLAC__METADATA_TYPE_STREAMINFO:
  88156. case FLAC__METADATA_TYPE_SEEKTABLE:
  88157. FLAC__ASSERT(0);
  88158. break;
  88159. default:
  88160. if(real_length > 0) {
  88161. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  88162. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88163. return false;
  88164. }
  88165. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  88166. return false; /* read_callback_ sets the state for us */
  88167. }
  88168. else
  88169. block.data.unknown.data = 0;
  88170. break;
  88171. }
  88172. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  88173. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  88174. switch(type) {
  88175. case FLAC__METADATA_TYPE_PADDING:
  88176. break;
  88177. case FLAC__METADATA_TYPE_APPLICATION:
  88178. if(0 != block.data.application.data)
  88179. free(block.data.application.data);
  88180. break;
  88181. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88182. if(0 != block.data.vorbis_comment.vendor_string.entry)
  88183. free(block.data.vorbis_comment.vendor_string.entry);
  88184. if(block.data.vorbis_comment.num_comments > 0)
  88185. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  88186. if(0 != block.data.vorbis_comment.comments[i].entry)
  88187. free(block.data.vorbis_comment.comments[i].entry);
  88188. if(0 != block.data.vorbis_comment.comments)
  88189. free(block.data.vorbis_comment.comments);
  88190. break;
  88191. case FLAC__METADATA_TYPE_CUESHEET:
  88192. if(block.data.cue_sheet.num_tracks > 0)
  88193. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  88194. if(0 != block.data.cue_sheet.tracks[i].indices)
  88195. free(block.data.cue_sheet.tracks[i].indices);
  88196. if(0 != block.data.cue_sheet.tracks)
  88197. free(block.data.cue_sheet.tracks);
  88198. break;
  88199. case FLAC__METADATA_TYPE_PICTURE:
  88200. if(0 != block.data.picture.mime_type)
  88201. free(block.data.picture.mime_type);
  88202. if(0 != block.data.picture.description)
  88203. free(block.data.picture.description);
  88204. if(0 != block.data.picture.data)
  88205. free(block.data.picture.data);
  88206. break;
  88207. case FLAC__METADATA_TYPE_STREAMINFO:
  88208. case FLAC__METADATA_TYPE_SEEKTABLE:
  88209. FLAC__ASSERT(0);
  88210. default:
  88211. if(0 != block.data.unknown.data)
  88212. free(block.data.unknown.data);
  88213. break;
  88214. }
  88215. }
  88216. }
  88217. if(is_last) {
  88218. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  88219. decoder->private_->first_frame_offset = 0;
  88220. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88221. }
  88222. return true;
  88223. }
  88224. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88225. {
  88226. FLAC__uint32 x;
  88227. unsigned bits, used_bits = 0;
  88228. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88229. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  88230. decoder->private_->stream_info.is_last = is_last;
  88231. decoder->private_->stream_info.length = length;
  88232. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  88233. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  88234. return false; /* read_callback_ sets the state for us */
  88235. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  88236. used_bits += bits;
  88237. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  88238. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  88239. return false; /* read_callback_ sets the state for us */
  88240. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  88241. used_bits += bits;
  88242. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  88243. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  88244. return false; /* read_callback_ sets the state for us */
  88245. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  88246. used_bits += bits;
  88247. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  88248. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  88249. return false; /* read_callback_ sets the state for us */
  88250. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  88251. used_bits += bits;
  88252. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  88253. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  88254. return false; /* read_callback_ sets the state for us */
  88255. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  88256. used_bits += bits;
  88257. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  88258. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  88259. return false; /* read_callback_ sets the state for us */
  88260. decoder->private_->stream_info.data.stream_info.channels = x+1;
  88261. used_bits += bits;
  88262. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  88263. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  88264. return false; /* read_callback_ sets the state for us */
  88265. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  88266. used_bits += bits;
  88267. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  88268. 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))
  88269. return false; /* read_callback_ sets the state for us */
  88270. used_bits += bits;
  88271. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  88272. return false; /* read_callback_ sets the state for us */
  88273. used_bits += 16*8;
  88274. FLAC__ASSERT(used_bits % 8 == 0);
  88275. length -= (used_bits / 8);
  88276. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88277. return false; /* read_callback_ sets the state for us */
  88278. return true;
  88279. }
  88280. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88281. {
  88282. FLAC__uint32 i, x;
  88283. FLAC__uint64 xx;
  88284. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88285. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  88286. decoder->private_->seek_table.is_last = is_last;
  88287. decoder->private_->seek_table.length = length;
  88288. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  88289. 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)))) {
  88290. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88291. return false;
  88292. }
  88293. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  88294. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88295. return false; /* read_callback_ sets the state for us */
  88296. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88297. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88298. return false; /* read_callback_ sets the state for us */
  88299. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88300. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88301. return false; /* read_callback_ sets the state for us */
  88302. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88303. }
  88304. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88305. if(length > 0) {
  88306. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88307. return false; /* read_callback_ sets the state for us */
  88308. }
  88309. return true;
  88310. }
  88311. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88312. {
  88313. FLAC__uint32 i;
  88314. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88315. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88316. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88317. return false; /* read_callback_ sets the state for us */
  88318. if(obj->vendor_string.length > 0) {
  88319. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88320. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88321. return false;
  88322. }
  88323. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  88324. return false; /* read_callback_ sets the state for us */
  88325. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88326. }
  88327. else
  88328. obj->vendor_string.entry = 0;
  88329. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88330. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88331. return false; /* read_callback_ sets the state for us */
  88332. if(obj->num_comments > 0) {
  88333. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88334. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88335. return false;
  88336. }
  88337. for(i = 0; i < obj->num_comments; i++) {
  88338. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88339. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88340. return false; /* read_callback_ sets the state for us */
  88341. if(obj->comments[i].length > 0) {
  88342. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88343. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88344. return false;
  88345. }
  88346. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88347. return false; /* read_callback_ sets the state for us */
  88348. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88349. }
  88350. else
  88351. obj->comments[i].entry = 0;
  88352. }
  88353. }
  88354. else {
  88355. obj->comments = 0;
  88356. }
  88357. return true;
  88358. }
  88359. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88360. {
  88361. FLAC__uint32 i, j, x;
  88362. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88363. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88364. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88365. 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))
  88366. return false; /* read_callback_ sets the state for us */
  88367. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  88368. return false; /* read_callback_ sets the state for us */
  88369. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  88370. return false; /* read_callback_ sets the state for us */
  88371. obj->is_cd = x? true : false;
  88372. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  88373. return false; /* read_callback_ sets the state for us */
  88374. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  88375. return false; /* read_callback_ sets the state for us */
  88376. obj->num_tracks = x;
  88377. if(obj->num_tracks > 0) {
  88378. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  88379. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88380. return false;
  88381. }
  88382. for(i = 0; i < obj->num_tracks; i++) {
  88383. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  88384. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  88385. return false; /* read_callback_ sets the state for us */
  88386. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  88387. return false; /* read_callback_ sets the state for us */
  88388. track->number = (FLAC__byte)x;
  88389. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  88390. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  88391. return false; /* read_callback_ sets the state for us */
  88392. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  88393. return false; /* read_callback_ sets the state for us */
  88394. track->type = x;
  88395. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  88396. return false; /* read_callback_ sets the state for us */
  88397. track->pre_emphasis = x;
  88398. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  88399. return false; /* read_callback_ sets the state for us */
  88400. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  88401. return false; /* read_callback_ sets the state for us */
  88402. track->num_indices = (FLAC__byte)x;
  88403. if(track->num_indices > 0) {
  88404. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  88405. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88406. return false;
  88407. }
  88408. for(j = 0; j < track->num_indices; j++) {
  88409. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88410. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88411. return false; /* read_callback_ sets the state for us */
  88412. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88413. return false; /* read_callback_ sets the state for us */
  88414. index->number = (FLAC__byte)x;
  88415. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88416. return false; /* read_callback_ sets the state for us */
  88417. }
  88418. }
  88419. }
  88420. }
  88421. return true;
  88422. }
  88423. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88424. {
  88425. FLAC__uint32 x;
  88426. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88427. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88428. return false; /* read_callback_ sets the state for us */
  88429. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88430. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88431. return false; /* read_callback_ sets the state for us */
  88432. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88433. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88434. return false;
  88435. }
  88436. if(x > 0) {
  88437. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88438. return false; /* read_callback_ sets the state for us */
  88439. }
  88440. obj->mime_type[x] = '\0';
  88441. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88442. return false; /* read_callback_ sets the state for us */
  88443. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  88444. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88445. return false;
  88446. }
  88447. if(x > 0) {
  88448. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  88449. return false; /* read_callback_ sets the state for us */
  88450. }
  88451. obj->description[x] = '\0';
  88452. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88453. return false; /* read_callback_ sets the state for us */
  88454. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88455. return false; /* read_callback_ sets the state for us */
  88456. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88457. return false; /* read_callback_ sets the state for us */
  88458. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88459. return false; /* read_callback_ sets the state for us */
  88460. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88461. return false; /* read_callback_ sets the state for us */
  88462. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88463. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88464. return false;
  88465. }
  88466. if(obj->data_length > 0) {
  88467. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88468. return false; /* read_callback_ sets the state for us */
  88469. }
  88470. return true;
  88471. }
  88472. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88473. {
  88474. FLAC__uint32 x;
  88475. unsigned i, skip;
  88476. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88477. return false; /* read_callback_ sets the state for us */
  88478. skip = 0;
  88479. for(i = 0; i < 4; i++) {
  88480. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88481. return false; /* read_callback_ sets the state for us */
  88482. skip <<= 7;
  88483. skip |= (x & 0x7f);
  88484. }
  88485. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88486. return false; /* read_callback_ sets the state for us */
  88487. return true;
  88488. }
  88489. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88490. {
  88491. FLAC__uint32 x;
  88492. FLAC__bool first = true;
  88493. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88494. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88495. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88496. return true;
  88497. }
  88498. }
  88499. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88500. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88501. return false; /* read_callback_ sets the state for us */
  88502. }
  88503. while(1) {
  88504. if(decoder->private_->cached) {
  88505. x = (FLAC__uint32)decoder->private_->lookahead;
  88506. decoder->private_->cached = false;
  88507. }
  88508. else {
  88509. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88510. return false; /* read_callback_ sets the state for us */
  88511. }
  88512. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88513. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88514. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88515. return false; /* read_callback_ sets the state for us */
  88516. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88517. decoder->private_->lookahead = (FLAC__byte)x;
  88518. decoder->private_->cached = true;
  88519. }
  88520. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88521. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88522. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88523. return true;
  88524. }
  88525. }
  88526. if(first) {
  88527. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88528. first = false;
  88529. }
  88530. }
  88531. return true;
  88532. }
  88533. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88534. {
  88535. unsigned channel;
  88536. unsigned i;
  88537. FLAC__int32 mid, side;
  88538. unsigned frame_crc; /* the one we calculate from the input stream */
  88539. FLAC__uint32 x;
  88540. *got_a_frame = false;
  88541. frame_crc = 0;
  88542. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88543. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88544. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88545. if(!read_frame_header_(decoder))
  88546. return false;
  88547. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88548. return true;
  88549. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88550. return false;
  88551. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88552. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88553. switch(decoder->private_->frame.header.channel_assignment) {
  88554. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88555. break;
  88556. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88557. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88558. if(channel == 1)
  88559. bps++;
  88560. break;
  88561. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88562. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88563. if(channel == 0)
  88564. bps++;
  88565. break;
  88566. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88567. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88568. if(channel == 1)
  88569. bps++;
  88570. break;
  88571. default:
  88572. FLAC__ASSERT(0);
  88573. }
  88574. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88575. return false;
  88576. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88577. return true;
  88578. }
  88579. if(!read_zero_padding_(decoder))
  88580. return false;
  88581. 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) */
  88582. return true;
  88583. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88584. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88585. return false; /* read_callback_ sets the state for us */
  88586. if(frame_crc == x) {
  88587. if(do_full_decode) {
  88588. switch(decoder->private_->frame.header.channel_assignment) {
  88589. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88590. break;
  88591. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88592. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88593. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88594. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88595. break;
  88596. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88597. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88598. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88599. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88600. break;
  88601. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88602. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88603. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88604. #if 1
  88605. mid = decoder->private_->output[0][i];
  88606. side = decoder->private_->output[1][i];
  88607. mid <<= 1;
  88608. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88609. decoder->private_->output[0][i] = (mid + side) >> 1;
  88610. decoder->private_->output[1][i] = (mid - side) >> 1;
  88611. #else
  88612. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88613. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88614. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88615. #endif
  88616. }
  88617. break;
  88618. default:
  88619. FLAC__ASSERT(0);
  88620. break;
  88621. }
  88622. }
  88623. }
  88624. else {
  88625. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88626. if(do_full_decode) {
  88627. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88628. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88629. }
  88630. }
  88631. }
  88632. *got_a_frame = true;
  88633. if(decoder->private_->next_fixed_block_size)
  88634. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88635. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88636. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88637. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88638. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88639. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88640. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88641. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88642. if(do_full_decode) {
  88643. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88644. return false;
  88645. }
  88646. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88647. return true;
  88648. }
  88649. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88650. {
  88651. FLAC__uint32 x;
  88652. FLAC__uint64 xx;
  88653. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88654. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88655. unsigned raw_header_len;
  88656. FLAC__bool is_unparseable = false;
  88657. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88658. raw_header[0] = decoder->private_->header_warmup[0];
  88659. raw_header[1] = decoder->private_->header_warmup[1];
  88660. raw_header_len = 2;
  88661. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88662. is_unparseable = true;
  88663. for(i = 0; i < 2; i++) {
  88664. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88665. return false; /* read_callback_ sets the state for us */
  88666. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88667. decoder->private_->lookahead = (FLAC__byte)x;
  88668. decoder->private_->cached = true;
  88669. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88670. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88671. return true;
  88672. }
  88673. raw_header[raw_header_len++] = (FLAC__byte)x;
  88674. }
  88675. switch(x = raw_header[2] >> 4) {
  88676. case 0:
  88677. is_unparseable = true;
  88678. break;
  88679. case 1:
  88680. decoder->private_->frame.header.blocksize = 192;
  88681. break;
  88682. case 2:
  88683. case 3:
  88684. case 4:
  88685. case 5:
  88686. decoder->private_->frame.header.blocksize = 576 << (x-2);
  88687. break;
  88688. case 6:
  88689. case 7:
  88690. blocksize_hint = x;
  88691. break;
  88692. case 8:
  88693. case 9:
  88694. case 10:
  88695. case 11:
  88696. case 12:
  88697. case 13:
  88698. case 14:
  88699. case 15:
  88700. decoder->private_->frame.header.blocksize = 256 << (x-8);
  88701. break;
  88702. default:
  88703. FLAC__ASSERT(0);
  88704. break;
  88705. }
  88706. switch(x = raw_header[2] & 0x0f) {
  88707. case 0:
  88708. if(decoder->private_->has_stream_info)
  88709. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  88710. else
  88711. is_unparseable = true;
  88712. break;
  88713. case 1:
  88714. decoder->private_->frame.header.sample_rate = 88200;
  88715. break;
  88716. case 2:
  88717. decoder->private_->frame.header.sample_rate = 176400;
  88718. break;
  88719. case 3:
  88720. decoder->private_->frame.header.sample_rate = 192000;
  88721. break;
  88722. case 4:
  88723. decoder->private_->frame.header.sample_rate = 8000;
  88724. break;
  88725. case 5:
  88726. decoder->private_->frame.header.sample_rate = 16000;
  88727. break;
  88728. case 6:
  88729. decoder->private_->frame.header.sample_rate = 22050;
  88730. break;
  88731. case 7:
  88732. decoder->private_->frame.header.sample_rate = 24000;
  88733. break;
  88734. case 8:
  88735. decoder->private_->frame.header.sample_rate = 32000;
  88736. break;
  88737. case 9:
  88738. decoder->private_->frame.header.sample_rate = 44100;
  88739. break;
  88740. case 10:
  88741. decoder->private_->frame.header.sample_rate = 48000;
  88742. break;
  88743. case 11:
  88744. decoder->private_->frame.header.sample_rate = 96000;
  88745. break;
  88746. case 12:
  88747. case 13:
  88748. case 14:
  88749. sample_rate_hint = x;
  88750. break;
  88751. case 15:
  88752. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88753. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88754. return true;
  88755. default:
  88756. FLAC__ASSERT(0);
  88757. }
  88758. x = (unsigned)(raw_header[3] >> 4);
  88759. if(x & 8) {
  88760. decoder->private_->frame.header.channels = 2;
  88761. switch(x & 7) {
  88762. case 0:
  88763. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  88764. break;
  88765. case 1:
  88766. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  88767. break;
  88768. case 2:
  88769. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  88770. break;
  88771. default:
  88772. is_unparseable = true;
  88773. break;
  88774. }
  88775. }
  88776. else {
  88777. decoder->private_->frame.header.channels = (unsigned)x + 1;
  88778. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  88779. }
  88780. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  88781. case 0:
  88782. if(decoder->private_->has_stream_info)
  88783. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  88784. else
  88785. is_unparseable = true;
  88786. break;
  88787. case 1:
  88788. decoder->private_->frame.header.bits_per_sample = 8;
  88789. break;
  88790. case 2:
  88791. decoder->private_->frame.header.bits_per_sample = 12;
  88792. break;
  88793. case 4:
  88794. decoder->private_->frame.header.bits_per_sample = 16;
  88795. break;
  88796. case 5:
  88797. decoder->private_->frame.header.bits_per_sample = 20;
  88798. break;
  88799. case 6:
  88800. decoder->private_->frame.header.bits_per_sample = 24;
  88801. break;
  88802. case 3:
  88803. case 7:
  88804. is_unparseable = true;
  88805. break;
  88806. default:
  88807. FLAC__ASSERT(0);
  88808. break;
  88809. }
  88810. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  88811. is_unparseable = true;
  88812. if(
  88813. raw_header[1] & 0x01 ||
  88814. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  88815. ) { /* variable blocksize */
  88816. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  88817. return false; /* read_callback_ sets the state for us */
  88818. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  88819. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88820. decoder->private_->cached = true;
  88821. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88822. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88823. return true;
  88824. }
  88825. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88826. decoder->private_->frame.header.number.sample_number = xx;
  88827. }
  88828. else { /* fixed blocksize */
  88829. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  88830. return false; /* read_callback_ sets the state for us */
  88831. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  88832. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88833. decoder->private_->cached = true;
  88834. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88835. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88836. return true;
  88837. }
  88838. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  88839. decoder->private_->frame.header.number.frame_number = x;
  88840. }
  88841. if(blocksize_hint) {
  88842. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88843. return false; /* read_callback_ sets the state for us */
  88844. raw_header[raw_header_len++] = (FLAC__byte)x;
  88845. if(blocksize_hint == 7) {
  88846. FLAC__uint32 _x;
  88847. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88848. return false; /* read_callback_ sets the state for us */
  88849. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88850. x = (x << 8) | _x;
  88851. }
  88852. decoder->private_->frame.header.blocksize = x+1;
  88853. }
  88854. if(sample_rate_hint) {
  88855. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88856. return false; /* read_callback_ sets the state for us */
  88857. raw_header[raw_header_len++] = (FLAC__byte)x;
  88858. if(sample_rate_hint != 12) {
  88859. FLAC__uint32 _x;
  88860. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88861. return false; /* read_callback_ sets the state for us */
  88862. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88863. x = (x << 8) | _x;
  88864. }
  88865. if(sample_rate_hint == 12)
  88866. decoder->private_->frame.header.sample_rate = x*1000;
  88867. else if(sample_rate_hint == 13)
  88868. decoder->private_->frame.header.sample_rate = x;
  88869. else
  88870. decoder->private_->frame.header.sample_rate = x*10;
  88871. }
  88872. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88873. return false; /* read_callback_ sets the state for us */
  88874. crc8 = (FLAC__byte)x;
  88875. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  88876. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88877. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88878. return true;
  88879. }
  88880. decoder->private_->next_fixed_block_size = 0;
  88881. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  88882. x = decoder->private_->frame.header.number.frame_number;
  88883. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88884. if(decoder->private_->fixed_block_size)
  88885. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  88886. else if(decoder->private_->has_stream_info) {
  88887. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  88888. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  88889. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  88890. }
  88891. else
  88892. is_unparseable = true;
  88893. }
  88894. else if(x == 0) {
  88895. decoder->private_->frame.header.number.sample_number = 0;
  88896. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  88897. }
  88898. else {
  88899. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  88900. }
  88901. }
  88902. if(is_unparseable) {
  88903. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88904. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88905. return true;
  88906. }
  88907. return true;
  88908. }
  88909. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88910. {
  88911. FLAC__uint32 x;
  88912. FLAC__bool wasted_bits;
  88913. unsigned i;
  88914. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  88915. return false; /* read_callback_ sets the state for us */
  88916. wasted_bits = (x & 1);
  88917. x &= 0xfe;
  88918. if(wasted_bits) {
  88919. unsigned u;
  88920. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  88921. return false; /* read_callback_ sets the state for us */
  88922. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  88923. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  88924. }
  88925. else
  88926. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  88927. if(x & 0x80) {
  88928. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88929. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88930. return true;
  88931. }
  88932. else if(x == 0) {
  88933. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  88934. return false;
  88935. }
  88936. else if(x == 2) {
  88937. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  88938. return false;
  88939. }
  88940. else if(x < 16) {
  88941. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88942. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88943. return true;
  88944. }
  88945. else if(x <= 24) {
  88946. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  88947. return false;
  88948. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88949. return true;
  88950. }
  88951. else if(x < 64) {
  88952. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88953. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88954. return true;
  88955. }
  88956. else {
  88957. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  88958. return false;
  88959. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88960. return true;
  88961. }
  88962. if(wasted_bits && do_full_decode) {
  88963. x = decoder->private_->frame.subframes[channel].wasted_bits;
  88964. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88965. decoder->private_->output[channel][i] <<= x;
  88966. }
  88967. return true;
  88968. }
  88969. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88970. {
  88971. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  88972. FLAC__int32 x;
  88973. unsigned i;
  88974. FLAC__int32 *output = decoder->private_->output[channel];
  88975. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  88976. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88977. return false; /* read_callback_ sets the state for us */
  88978. subframe->value = x;
  88979. if(do_full_decode) {
  88980. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88981. output[i] = x;
  88982. }
  88983. return true;
  88984. }
  88985. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88986. {
  88987. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  88988. FLAC__int32 i32;
  88989. FLAC__uint32 u32;
  88990. unsigned u;
  88991. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  88992. subframe->residual = decoder->private_->residual[channel];
  88993. subframe->order = order;
  88994. for(u = 0; u < order; u++) {
  88995. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88996. return false; /* read_callback_ sets the state for us */
  88997. subframe->warmup[u] = i32;
  88998. }
  88999. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89000. return false; /* read_callback_ sets the state for us */
  89001. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89002. switch(subframe->entropy_coding_method.type) {
  89003. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89004. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89005. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89006. return false; /* read_callback_ sets the state for us */
  89007. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89008. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89009. break;
  89010. default:
  89011. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89012. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89013. return true;
  89014. }
  89015. switch(subframe->entropy_coding_method.type) {
  89016. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89017. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89018. 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))
  89019. return false;
  89020. break;
  89021. default:
  89022. FLAC__ASSERT(0);
  89023. }
  89024. if(do_full_decode) {
  89025. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89026. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  89027. }
  89028. return true;
  89029. }
  89030. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89031. {
  89032. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  89033. FLAC__int32 i32;
  89034. FLAC__uint32 u32;
  89035. unsigned u;
  89036. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  89037. subframe->residual = decoder->private_->residual[channel];
  89038. subframe->order = order;
  89039. for(u = 0; u < order; u++) {
  89040. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89041. return false; /* read_callback_ sets the state for us */
  89042. subframe->warmup[u] = i32;
  89043. }
  89044. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  89045. return false; /* read_callback_ sets the state for us */
  89046. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  89047. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89048. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89049. return true;
  89050. }
  89051. subframe->qlp_coeff_precision = u32+1;
  89052. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  89053. return false; /* read_callback_ sets the state for us */
  89054. subframe->quantization_level = i32;
  89055. for(u = 0; u < order; u++) {
  89056. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  89057. return false; /* read_callback_ sets the state for us */
  89058. subframe->qlp_coeff[u] = i32;
  89059. }
  89060. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89061. return false; /* read_callback_ sets the state for us */
  89062. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89063. switch(subframe->entropy_coding_method.type) {
  89064. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89065. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89066. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89067. return false; /* read_callback_ sets the state for us */
  89068. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89069. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89070. break;
  89071. default:
  89072. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89073. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89074. return true;
  89075. }
  89076. switch(subframe->entropy_coding_method.type) {
  89077. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89078. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89079. 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))
  89080. return false;
  89081. break;
  89082. default:
  89083. FLAC__ASSERT(0);
  89084. }
  89085. if(do_full_decode) {
  89086. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89087. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  89088. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  89089. if(order <= 8)
  89090. 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);
  89091. else
  89092. 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);
  89093. }
  89094. else
  89095. 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);
  89096. else
  89097. 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);
  89098. }
  89099. return true;
  89100. }
  89101. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89102. {
  89103. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  89104. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  89105. unsigned i;
  89106. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  89107. subframe->data = residual;
  89108. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  89109. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89110. return false; /* read_callback_ sets the state for us */
  89111. residual[i] = x;
  89112. }
  89113. if(do_full_decode)
  89114. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  89115. return true;
  89116. }
  89117. 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)
  89118. {
  89119. FLAC__uint32 rice_parameter;
  89120. int i;
  89121. unsigned partition, sample, u;
  89122. const unsigned partitions = 1u << partition_order;
  89123. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  89124. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  89125. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  89126. if(partition_order == 0) {
  89127. if(decoder->private_->frame.header.blocksize < predictor_order) {
  89128. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89129. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89130. return true;
  89131. }
  89132. }
  89133. else {
  89134. if(partition_samples < predictor_order) {
  89135. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89136. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89137. return true;
  89138. }
  89139. }
  89140. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  89141. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89142. return false;
  89143. }
  89144. sample = 0;
  89145. for(partition = 0; partition < partitions; partition++) {
  89146. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  89147. return false; /* read_callback_ sets the state for us */
  89148. partitioned_rice_contents->parameters[partition] = rice_parameter;
  89149. if(rice_parameter < pesc) {
  89150. partitioned_rice_contents->raw_bits[partition] = 0;
  89151. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  89152. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  89153. return false; /* read_callback_ sets the state for us */
  89154. sample += u;
  89155. }
  89156. else {
  89157. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  89158. return false; /* read_callback_ sets the state for us */
  89159. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  89160. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  89161. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  89162. return false; /* read_callback_ sets the state for us */
  89163. residual[sample] = i;
  89164. }
  89165. }
  89166. }
  89167. return true;
  89168. }
  89169. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  89170. {
  89171. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  89172. FLAC__uint32 zero = 0;
  89173. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  89174. return false; /* read_callback_ sets the state for us */
  89175. if(zero != 0) {
  89176. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89177. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89178. }
  89179. }
  89180. return true;
  89181. }
  89182. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  89183. {
  89184. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  89185. if(
  89186. #if FLAC__HAS_OGG
  89187. !decoder->private_->is_ogg &&
  89188. #endif
  89189. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89190. ) {
  89191. *bytes = 0;
  89192. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89193. return false;
  89194. }
  89195. else if(*bytes > 0) {
  89196. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  89197. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89198. return false;
  89199. }
  89200. else {
  89201. const FLAC__StreamDecoderReadStatus status =
  89202. #if FLAC__HAS_OGG
  89203. decoder->private_->is_ogg?
  89204. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  89205. #endif
  89206. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  89207. ;
  89208. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  89209. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89210. return false;
  89211. }
  89212. else if(*bytes == 0) {
  89213. if(
  89214. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  89215. (
  89216. #if FLAC__HAS_OGG
  89217. !decoder->private_->is_ogg &&
  89218. #endif
  89219. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89220. )
  89221. ) {
  89222. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89223. return false;
  89224. }
  89225. else
  89226. return true;
  89227. }
  89228. else
  89229. return true;
  89230. }
  89231. }
  89232. else {
  89233. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89234. return false;
  89235. }
  89236. }
  89237. #if FLAC__HAS_OGG
  89238. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  89239. {
  89240. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  89241. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  89242. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89243. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  89244. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89245. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  89246. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89247. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  89248. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  89249. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  89250. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  89251. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  89252. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89253. default:
  89254. FLAC__ASSERT(0);
  89255. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89256. }
  89257. }
  89258. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89259. {
  89260. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  89261. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  89262. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  89263. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  89264. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  89265. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  89266. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  89267. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89268. default:
  89269. FLAC__ASSERT(0);
  89270. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89271. }
  89272. }
  89273. #endif
  89274. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  89275. {
  89276. if(decoder->private_->is_seeking) {
  89277. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  89278. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  89279. FLAC__uint64 target_sample = decoder->private_->target_sample;
  89280. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89281. #if FLAC__HAS_OGG
  89282. decoder->private_->got_a_frame = true;
  89283. #endif
  89284. decoder->private_->last_frame = *frame; /* save the frame */
  89285. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  89286. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  89287. decoder->private_->is_seeking = false;
  89288. if(delta > 0) {
  89289. unsigned channel;
  89290. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  89291. for(channel = 0; channel < frame->header.channels; channel++)
  89292. newbuffer[channel] = buffer[channel] + delta;
  89293. decoder->private_->last_frame.header.blocksize -= delta;
  89294. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89295. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89296. }
  89297. else {
  89298. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89299. }
  89300. }
  89301. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89302. }
  89303. if(!decoder->private_->has_stream_info)
  89304. decoder->private_->do_md5_checking = false;
  89305. if(decoder->private_->do_md5_checking) {
  89306. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89307. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89308. }
  89309. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89310. }
  89311. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89312. {
  89313. if(!decoder->private_->is_seeking)
  89314. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89315. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89316. decoder->private_->unparseable_frame_count++;
  89317. }
  89318. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89319. {
  89320. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89321. FLAC__int64 pos = -1;
  89322. int i;
  89323. unsigned approx_bytes_per_frame;
  89324. FLAC__bool first_seek = true;
  89325. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89326. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89327. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89328. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89329. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89330. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89331. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89332. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89333. if(channels == 0)
  89334. channels = decoder->private_->stream_info.data.stream_info.channels;
  89335. if(bps == 0)
  89336. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89337. if(max_framesize > 0)
  89338. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89339. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89340. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89341. }
  89342. else
  89343. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89344. lower_bound = first_frame_offset;
  89345. lower_bound_sample = 0;
  89346. upper_bound = stream_length;
  89347. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89348. if(seek_table) {
  89349. FLAC__uint64 new_lower_bound = lower_bound;
  89350. FLAC__uint64 new_upper_bound = upper_bound;
  89351. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89352. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89353. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89354. if(
  89355. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89356. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89357. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89358. seek_table->points[i].sample_number <= target_sample
  89359. )
  89360. break;
  89361. }
  89362. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89363. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89364. new_lower_bound_sample = seek_table->points[i].sample_number;
  89365. }
  89366. for(i = 0; i < (int)seek_table->num_points; i++) {
  89367. if(
  89368. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89369. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89370. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89371. seek_table->points[i].sample_number > target_sample
  89372. )
  89373. break;
  89374. }
  89375. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  89376. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89377. new_upper_bound_sample = seek_table->points[i].sample_number;
  89378. }
  89379. if(new_upper_bound >= new_lower_bound) {
  89380. lower_bound = new_lower_bound;
  89381. upper_bound = new_upper_bound;
  89382. lower_bound_sample = new_lower_bound_sample;
  89383. upper_bound_sample = new_upper_bound_sample;
  89384. }
  89385. }
  89386. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  89387. if(upper_bound_sample == lower_bound_sample)
  89388. upper_bound_sample++;
  89389. decoder->private_->target_sample = target_sample;
  89390. while(1) {
  89391. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  89392. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89393. return false;
  89394. }
  89395. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89396. #if defined _MSC_VER || defined __MINGW32__
  89397. 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;
  89398. #else
  89399. 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;
  89400. #endif
  89401. #else
  89402. if(upper_bound - lower_bound < 0xffffffff)
  89403. 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;
  89404. else /* @@@ WATCHOUT, ~2TB limit */
  89405. 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;
  89406. #endif
  89407. if(pos >= (FLAC__int64)upper_bound)
  89408. pos = (FLAC__int64)upper_bound - 1;
  89409. if(pos < (FLAC__int64)lower_bound)
  89410. pos = (FLAC__int64)lower_bound;
  89411. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89412. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89413. return false;
  89414. }
  89415. if(!FLAC__stream_decoder_flush(decoder)) {
  89416. return false;
  89417. }
  89418. decoder->private_->unparseable_frame_count = 0;
  89419. if(!FLAC__stream_decoder_process_single(decoder)) {
  89420. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89421. return false;
  89422. }
  89423. #if 0
  89424. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89425. break;
  89426. #endif
  89427. if(!decoder->private_->is_seeking)
  89428. break;
  89429. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89430. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89431. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89432. if (pos == (FLAC__int64)lower_bound) {
  89433. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89434. return false;
  89435. }
  89436. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89437. continue;
  89438. }
  89439. first_seek = false;
  89440. if (this_frame_sample < lower_bound_sample) {
  89441. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89442. return false;
  89443. }
  89444. if(target_sample < this_frame_sample) {
  89445. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89446. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89447. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89448. return false;
  89449. }
  89450. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89451. }
  89452. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89453. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89454. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89455. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89456. return false;
  89457. }
  89458. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89459. }
  89460. }
  89461. return true;
  89462. }
  89463. #if FLAC__HAS_OGG
  89464. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89465. {
  89466. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89467. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89468. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89469. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89470. FLAC__bool did_a_seek;
  89471. unsigned iteration = 0;
  89472. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89473. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89474. if(right_sample == 0) {
  89475. right_sample = (FLAC__uint64)(-1);
  89476. BINARY_SEARCH_AFTER_ITERATION = 0;
  89477. }
  89478. decoder->private_->target_sample = target_sample;
  89479. for( ; ; iteration++) {
  89480. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89481. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89482. pos = (right_pos + left_pos) / 2;
  89483. }
  89484. else {
  89485. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89486. #if defined _MSC_VER || defined __MINGW32__
  89487. 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));
  89488. #else
  89489. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89490. #endif
  89491. #else
  89492. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89493. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89494. else /* @@@ WATCHOUT, ~2TB limit */
  89495. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89496. #endif
  89497. }
  89498. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89499. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89500. return false;
  89501. }
  89502. if(!FLAC__stream_decoder_flush(decoder)) {
  89503. return false;
  89504. }
  89505. did_a_seek = true;
  89506. }
  89507. else
  89508. did_a_seek = false;
  89509. decoder->private_->got_a_frame = false;
  89510. if(!FLAC__stream_decoder_process_single(decoder)) {
  89511. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89512. return false;
  89513. }
  89514. if(!decoder->private_->got_a_frame) {
  89515. if(did_a_seek) {
  89516. right_pos = pos;
  89517. BINARY_SEARCH_AFTER_ITERATION = 0;
  89518. }
  89519. else {
  89520. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89521. return false;
  89522. }
  89523. }
  89524. else if(!decoder->private_->is_seeking) {
  89525. break;
  89526. }
  89527. else {
  89528. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89529. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89530. if (did_a_seek) {
  89531. if (this_frame_sample <= target_sample) {
  89532. FLAC__ASSERT(this_frame_sample != target_sample);
  89533. left_sample = this_frame_sample;
  89534. if (left_pos == pos) {
  89535. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89536. return false;
  89537. }
  89538. left_pos = pos;
  89539. }
  89540. else if(this_frame_sample > target_sample) {
  89541. right_sample = this_frame_sample;
  89542. if (right_pos == pos) {
  89543. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89544. return false;
  89545. }
  89546. right_pos = pos;
  89547. }
  89548. }
  89549. }
  89550. }
  89551. return true;
  89552. }
  89553. #endif
  89554. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89555. {
  89556. (void)client_data;
  89557. if(*bytes > 0) {
  89558. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89559. if(ferror(decoder->private_->file))
  89560. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89561. else if(*bytes == 0)
  89562. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89563. else
  89564. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89565. }
  89566. else
  89567. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89568. }
  89569. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89570. {
  89571. (void)client_data;
  89572. if(decoder->private_->file == stdin)
  89573. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89574. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89575. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89576. else
  89577. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89578. }
  89579. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89580. {
  89581. off_t pos;
  89582. (void)client_data;
  89583. if(decoder->private_->file == stdin)
  89584. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89585. else if((pos = ftello(decoder->private_->file)) < 0)
  89586. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89587. else {
  89588. *absolute_byte_offset = (FLAC__uint64)pos;
  89589. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89590. }
  89591. }
  89592. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89593. {
  89594. struct stat filestats;
  89595. (void)client_data;
  89596. if(decoder->private_->file == stdin)
  89597. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89598. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89599. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89600. else {
  89601. *stream_length = (FLAC__uint64)filestats.st_size;
  89602. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89603. }
  89604. }
  89605. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89606. {
  89607. (void)client_data;
  89608. return feof(decoder->private_->file)? true : false;
  89609. }
  89610. #endif
  89611. /*** End of inlined file: stream_decoder.c ***/
  89612. /*** Start of inlined file: stream_encoder.c ***/
  89613. /*** Start of inlined file: juce_FlacHeader.h ***/
  89614. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89615. // tasks..
  89616. #define VERSION "1.2.1"
  89617. #define FLAC__NO_DLL 1
  89618. #if JUCE_MSVC
  89619. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89620. #endif
  89621. #if JUCE_MAC
  89622. #define FLAC__SYS_DARWIN 1
  89623. #endif
  89624. /*** End of inlined file: juce_FlacHeader.h ***/
  89625. #if JUCE_USE_FLAC
  89626. #if HAVE_CONFIG_H
  89627. # include <config.h>
  89628. #endif
  89629. #if defined _MSC_VER || defined __MINGW32__
  89630. #include <io.h> /* for _setmode() */
  89631. #include <fcntl.h> /* for _O_BINARY */
  89632. #endif
  89633. #if defined __CYGWIN__ || defined __EMX__
  89634. #include <io.h> /* for setmode(), O_BINARY */
  89635. #include <fcntl.h> /* for _O_BINARY */
  89636. #endif
  89637. #include <limits.h>
  89638. #include <stdio.h>
  89639. #include <stdlib.h> /* for malloc() */
  89640. #include <string.h> /* for memcpy() */
  89641. #include <sys/types.h> /* for off_t */
  89642. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89643. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89644. #define fseeko fseek
  89645. #define ftello ftell
  89646. #endif
  89647. #endif
  89648. /*** Start of inlined file: stream_encoder.h ***/
  89649. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89650. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89651. #if FLAC__HAS_OGG
  89652. #include "private/ogg_encoder_aspect.h"
  89653. #endif
  89654. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89655. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89656. typedef enum {
  89657. FLAC__APODIZATION_BARTLETT,
  89658. FLAC__APODIZATION_BARTLETT_HANN,
  89659. FLAC__APODIZATION_BLACKMAN,
  89660. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89661. FLAC__APODIZATION_CONNES,
  89662. FLAC__APODIZATION_FLATTOP,
  89663. FLAC__APODIZATION_GAUSS,
  89664. FLAC__APODIZATION_HAMMING,
  89665. FLAC__APODIZATION_HANN,
  89666. FLAC__APODIZATION_KAISER_BESSEL,
  89667. FLAC__APODIZATION_NUTTALL,
  89668. FLAC__APODIZATION_RECTANGLE,
  89669. FLAC__APODIZATION_TRIANGLE,
  89670. FLAC__APODIZATION_TUKEY,
  89671. FLAC__APODIZATION_WELCH
  89672. } FLAC__ApodizationFunction;
  89673. typedef struct {
  89674. FLAC__ApodizationFunction type;
  89675. union {
  89676. struct {
  89677. FLAC__real stddev;
  89678. } gauss;
  89679. struct {
  89680. FLAC__real p;
  89681. } tukey;
  89682. } parameters;
  89683. } FLAC__ApodizationSpecification;
  89684. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89685. typedef struct FLAC__StreamEncoderProtected {
  89686. FLAC__StreamEncoderState state;
  89687. FLAC__bool verify;
  89688. FLAC__bool streamable_subset;
  89689. FLAC__bool do_md5;
  89690. FLAC__bool do_mid_side_stereo;
  89691. FLAC__bool loose_mid_side_stereo;
  89692. unsigned channels;
  89693. unsigned bits_per_sample;
  89694. unsigned sample_rate;
  89695. unsigned blocksize;
  89696. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89697. unsigned num_apodizations;
  89698. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  89699. #endif
  89700. unsigned max_lpc_order;
  89701. unsigned qlp_coeff_precision;
  89702. FLAC__bool do_qlp_coeff_prec_search;
  89703. FLAC__bool do_exhaustive_model_search;
  89704. FLAC__bool do_escape_coding;
  89705. unsigned min_residual_partition_order;
  89706. unsigned max_residual_partition_order;
  89707. unsigned rice_parameter_search_dist;
  89708. FLAC__uint64 total_samples_estimate;
  89709. FLAC__StreamMetadata **metadata;
  89710. unsigned num_metadata_blocks;
  89711. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  89712. #if FLAC__HAS_OGG
  89713. FLAC__OggEncoderAspect ogg_encoder_aspect;
  89714. #endif
  89715. } FLAC__StreamEncoderProtected;
  89716. #endif
  89717. /*** End of inlined file: stream_encoder.h ***/
  89718. #if FLAC__HAS_OGG
  89719. #include "include/private/ogg_helper.h"
  89720. #include "include/private/ogg_mapping.h"
  89721. #endif
  89722. /*** Start of inlined file: stream_encoder_framing.h ***/
  89723. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89724. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89725. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  89726. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  89727. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89728. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89729. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89730. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89731. #endif
  89732. /*** End of inlined file: stream_encoder_framing.h ***/
  89733. /*** Start of inlined file: window.h ***/
  89734. #ifndef FLAC__PRIVATE__WINDOW_H
  89735. #define FLAC__PRIVATE__WINDOW_H
  89736. #ifdef HAVE_CONFIG_H
  89737. #include <config.h>
  89738. #endif
  89739. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89740. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  89741. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  89742. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  89743. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  89744. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  89745. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  89746. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  89747. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  89748. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  89749. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  89750. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  89751. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  89752. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  89753. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  89754. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  89755. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  89756. #endif
  89757. /*** End of inlined file: window.h ***/
  89758. #ifndef FLaC__INLINE
  89759. #define FLaC__INLINE
  89760. #endif
  89761. #ifdef min
  89762. #undef min
  89763. #endif
  89764. #define min(x,y) ((x)<(y)?(x):(y))
  89765. #ifdef max
  89766. #undef max
  89767. #endif
  89768. #define max(x,y) ((x)>(y)?(x):(y))
  89769. #undef EXACT_RICE_BITS_CALCULATION
  89770. #undef ENABLE_RICE_PARAMETER_SEARCH
  89771. typedef struct {
  89772. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  89773. unsigned size; /* of each data[] in samples */
  89774. unsigned tail;
  89775. } verify_input_fifo;
  89776. typedef struct {
  89777. const FLAC__byte *data;
  89778. unsigned capacity;
  89779. unsigned bytes;
  89780. } verify_output;
  89781. typedef enum {
  89782. ENCODER_IN_MAGIC = 0,
  89783. ENCODER_IN_METADATA = 1,
  89784. ENCODER_IN_AUDIO = 2
  89785. } EncoderStateHint;
  89786. static struct CompressionLevels {
  89787. FLAC__bool do_mid_side_stereo;
  89788. FLAC__bool loose_mid_side_stereo;
  89789. unsigned max_lpc_order;
  89790. unsigned qlp_coeff_precision;
  89791. FLAC__bool do_qlp_coeff_prec_search;
  89792. FLAC__bool do_escape_coding;
  89793. FLAC__bool do_exhaustive_model_search;
  89794. unsigned min_residual_partition_order;
  89795. unsigned max_residual_partition_order;
  89796. unsigned rice_parameter_search_dist;
  89797. } compression_levels_[] = {
  89798. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  89799. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  89800. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  89801. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  89802. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  89803. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  89804. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  89805. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  89806. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  89807. };
  89808. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  89809. static void free_(FLAC__StreamEncoder *encoder);
  89810. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  89811. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  89812. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  89813. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  89814. #if FLAC__HAS_OGG
  89815. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  89816. #endif
  89817. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  89818. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  89819. static FLAC__bool process_subframe_(
  89820. FLAC__StreamEncoder *encoder,
  89821. unsigned min_partition_order,
  89822. unsigned max_partition_order,
  89823. const FLAC__FrameHeader *frame_header,
  89824. unsigned subframe_bps,
  89825. const FLAC__int32 integer_signal[],
  89826. FLAC__Subframe *subframe[2],
  89827. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  89828. FLAC__int32 *residual[2],
  89829. unsigned *best_subframe,
  89830. unsigned *best_bits
  89831. );
  89832. static FLAC__bool add_subframe_(
  89833. FLAC__StreamEncoder *encoder,
  89834. unsigned blocksize,
  89835. unsigned subframe_bps,
  89836. const FLAC__Subframe *subframe,
  89837. FLAC__BitWriter *frame
  89838. );
  89839. static unsigned evaluate_constant_subframe_(
  89840. FLAC__StreamEncoder *encoder,
  89841. const FLAC__int32 signal,
  89842. unsigned blocksize,
  89843. unsigned subframe_bps,
  89844. FLAC__Subframe *subframe
  89845. );
  89846. static unsigned evaluate_fixed_subframe_(
  89847. FLAC__StreamEncoder *encoder,
  89848. const FLAC__int32 signal[],
  89849. FLAC__int32 residual[],
  89850. FLAC__uint64 abs_residual_partition_sums[],
  89851. unsigned raw_bits_per_partition[],
  89852. unsigned blocksize,
  89853. unsigned subframe_bps,
  89854. unsigned order,
  89855. unsigned rice_parameter,
  89856. unsigned rice_parameter_limit,
  89857. unsigned min_partition_order,
  89858. unsigned max_partition_order,
  89859. FLAC__bool do_escape_coding,
  89860. unsigned rice_parameter_search_dist,
  89861. FLAC__Subframe *subframe,
  89862. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89863. );
  89864. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89865. static unsigned evaluate_lpc_subframe_(
  89866. FLAC__StreamEncoder *encoder,
  89867. const FLAC__int32 signal[],
  89868. FLAC__int32 residual[],
  89869. FLAC__uint64 abs_residual_partition_sums[],
  89870. unsigned raw_bits_per_partition[],
  89871. const FLAC__real lp_coeff[],
  89872. unsigned blocksize,
  89873. unsigned subframe_bps,
  89874. unsigned order,
  89875. unsigned qlp_coeff_precision,
  89876. unsigned rice_parameter,
  89877. unsigned rice_parameter_limit,
  89878. unsigned min_partition_order,
  89879. unsigned max_partition_order,
  89880. FLAC__bool do_escape_coding,
  89881. unsigned rice_parameter_search_dist,
  89882. FLAC__Subframe *subframe,
  89883. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89884. );
  89885. #endif
  89886. static unsigned evaluate_verbatim_subframe_(
  89887. FLAC__StreamEncoder *encoder,
  89888. const FLAC__int32 signal[],
  89889. unsigned blocksize,
  89890. unsigned subframe_bps,
  89891. FLAC__Subframe *subframe
  89892. );
  89893. static unsigned find_best_partition_order_(
  89894. struct FLAC__StreamEncoderPrivate *private_,
  89895. const FLAC__int32 residual[],
  89896. FLAC__uint64 abs_residual_partition_sums[],
  89897. unsigned raw_bits_per_partition[],
  89898. unsigned residual_samples,
  89899. unsigned predictor_order,
  89900. unsigned rice_parameter,
  89901. unsigned rice_parameter_limit,
  89902. unsigned min_partition_order,
  89903. unsigned max_partition_order,
  89904. unsigned bps,
  89905. FLAC__bool do_escape_coding,
  89906. unsigned rice_parameter_search_dist,
  89907. FLAC__EntropyCodingMethod *best_ecm
  89908. );
  89909. static void precompute_partition_info_sums_(
  89910. const FLAC__int32 residual[],
  89911. FLAC__uint64 abs_residual_partition_sums[],
  89912. unsigned residual_samples,
  89913. unsigned predictor_order,
  89914. unsigned min_partition_order,
  89915. unsigned max_partition_order,
  89916. unsigned bps
  89917. );
  89918. static void precompute_partition_info_escapes_(
  89919. const FLAC__int32 residual[],
  89920. unsigned raw_bits_per_partition[],
  89921. unsigned residual_samples,
  89922. unsigned predictor_order,
  89923. unsigned min_partition_order,
  89924. unsigned max_partition_order
  89925. );
  89926. static FLAC__bool set_partitioned_rice_(
  89927. #ifdef EXACT_RICE_BITS_CALCULATION
  89928. const FLAC__int32 residual[],
  89929. #endif
  89930. const FLAC__uint64 abs_residual_partition_sums[],
  89931. const unsigned raw_bits_per_partition[],
  89932. const unsigned residual_samples,
  89933. const unsigned predictor_order,
  89934. const unsigned suggested_rice_parameter,
  89935. const unsigned rice_parameter_limit,
  89936. const unsigned rice_parameter_search_dist,
  89937. const unsigned partition_order,
  89938. const FLAC__bool search_for_escapes,
  89939. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  89940. unsigned *bits
  89941. );
  89942. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  89943. static void append_to_verify_fifo_(
  89944. verify_input_fifo *fifo,
  89945. const FLAC__int32 * const input[],
  89946. unsigned input_offset,
  89947. unsigned channels,
  89948. unsigned wide_samples
  89949. );
  89950. static void append_to_verify_fifo_interleaved_(
  89951. verify_input_fifo *fifo,
  89952. const FLAC__int32 input[],
  89953. unsigned input_offset,
  89954. unsigned channels,
  89955. unsigned wide_samples
  89956. );
  89957. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89958. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  89959. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  89960. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  89961. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89962. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  89963. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  89964. 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);
  89965. static FILE *get_binary_stdout_(void);
  89966. typedef struct FLAC__StreamEncoderPrivate {
  89967. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  89968. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  89969. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  89970. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89971. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  89972. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  89973. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  89974. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  89975. #endif
  89976. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  89977. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  89978. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  89979. FLAC__int32 *residual_workspace_mid_side[2][2];
  89980. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  89981. FLAC__Subframe subframe_workspace_mid_side[2][2];
  89982. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89983. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  89984. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  89985. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  89986. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89987. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  89988. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  89989. unsigned best_subframe_mid_side[2];
  89990. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  89991. unsigned best_subframe_bits_mid_side[2];
  89992. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  89993. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  89994. FLAC__BitWriter *frame; /* the current frame being worked on */
  89995. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  89996. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  89997. FLAC__ChannelAssignment last_channel_assignment;
  89998. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  89999. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  90000. unsigned current_sample_number;
  90001. unsigned current_frame_number;
  90002. FLAC__MD5Context md5context;
  90003. FLAC__CPUInfo cpuinfo;
  90004. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90005. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90006. #else
  90007. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90008. #endif
  90009. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90010. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  90011. 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[]);
  90012. 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[]);
  90013. 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[]);
  90014. #endif
  90015. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  90016. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  90017. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  90018. FLAC__bool disable_constant_subframes;
  90019. FLAC__bool disable_fixed_subframes;
  90020. FLAC__bool disable_verbatim_subframes;
  90021. #if FLAC__HAS_OGG
  90022. FLAC__bool is_ogg;
  90023. #endif
  90024. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  90025. FLAC__StreamEncoderSeekCallback seek_callback;
  90026. FLAC__StreamEncoderTellCallback tell_callback;
  90027. FLAC__StreamEncoderWriteCallback write_callback;
  90028. FLAC__StreamEncoderMetadataCallback metadata_callback;
  90029. FLAC__StreamEncoderProgressCallback progress_callback;
  90030. void *client_data;
  90031. unsigned first_seekpoint_to_check;
  90032. FILE *file; /* only used when encoding to a file */
  90033. FLAC__uint64 bytes_written;
  90034. FLAC__uint64 samples_written;
  90035. unsigned frames_written;
  90036. unsigned total_frames_estimate;
  90037. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  90038. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  90039. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90040. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  90041. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  90042. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  90043. FLAC__real *windowed_signal_unaligned;
  90044. #endif
  90045. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  90046. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  90047. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  90048. unsigned *raw_bits_per_partition_unaligned;
  90049. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90050. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  90051. #endif
  90052. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  90053. struct {
  90054. FLAC__StreamDecoder *decoder;
  90055. EncoderStateHint state_hint;
  90056. FLAC__bool needs_magic_hack;
  90057. verify_input_fifo input_fifo;
  90058. verify_output output;
  90059. struct {
  90060. FLAC__uint64 absolute_sample;
  90061. unsigned frame_number;
  90062. unsigned channel;
  90063. unsigned sample;
  90064. FLAC__int32 expected;
  90065. FLAC__int32 got;
  90066. } error_stats;
  90067. } verify;
  90068. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  90069. } FLAC__StreamEncoderPrivate;
  90070. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  90071. "FLAC__STREAM_ENCODER_OK",
  90072. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  90073. "FLAC__STREAM_ENCODER_OGG_ERROR",
  90074. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  90075. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  90076. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  90077. "FLAC__STREAM_ENCODER_IO_ERROR",
  90078. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  90079. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  90080. };
  90081. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  90082. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  90083. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  90084. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  90085. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  90086. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  90087. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  90088. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  90089. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  90090. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  90091. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  90092. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  90093. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  90094. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  90095. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  90096. };
  90097. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  90098. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  90099. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  90100. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  90101. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  90102. };
  90103. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  90104. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  90105. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  90106. };
  90107. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  90108. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  90109. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  90110. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  90111. };
  90112. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  90113. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  90114. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  90115. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  90116. };
  90117. static const unsigned OVERREAD_ = 1;
  90118. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  90119. {
  90120. FLAC__StreamEncoder *encoder;
  90121. unsigned i;
  90122. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  90123. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  90124. if(encoder == 0) {
  90125. return 0;
  90126. }
  90127. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  90128. if(encoder->protected_ == 0) {
  90129. free(encoder);
  90130. return 0;
  90131. }
  90132. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  90133. if(encoder->private_ == 0) {
  90134. free(encoder->protected_);
  90135. free(encoder);
  90136. return 0;
  90137. }
  90138. encoder->private_->frame = FLAC__bitwriter_new();
  90139. if(encoder->private_->frame == 0) {
  90140. free(encoder->private_);
  90141. free(encoder->protected_);
  90142. free(encoder);
  90143. return 0;
  90144. }
  90145. encoder->private_->file = 0;
  90146. set_defaults_enc(encoder);
  90147. encoder->private_->is_being_deleted = false;
  90148. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90149. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  90150. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  90151. }
  90152. for(i = 0; i < 2; i++) {
  90153. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  90154. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  90155. }
  90156. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90157. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  90158. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  90159. }
  90160. for(i = 0; i < 2; i++) {
  90161. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  90162. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  90163. }
  90164. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90165. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90166. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90167. }
  90168. for(i = 0; i < 2; i++) {
  90169. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90170. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90171. }
  90172. for(i = 0; i < 2; i++)
  90173. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  90174. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90175. return encoder;
  90176. }
  90177. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  90178. {
  90179. unsigned i;
  90180. FLAC__ASSERT(0 != encoder);
  90181. FLAC__ASSERT(0 != encoder->protected_);
  90182. FLAC__ASSERT(0 != encoder->private_);
  90183. FLAC__ASSERT(0 != encoder->private_->frame);
  90184. encoder->private_->is_being_deleted = true;
  90185. (void)FLAC__stream_encoder_finish(encoder);
  90186. if(0 != encoder->private_->verify.decoder)
  90187. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  90188. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90189. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90190. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90191. }
  90192. for(i = 0; i < 2; i++) {
  90193. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90194. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90195. }
  90196. for(i = 0; i < 2; i++)
  90197. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  90198. FLAC__bitwriter_delete(encoder->private_->frame);
  90199. free(encoder->private_);
  90200. free(encoder->protected_);
  90201. free(encoder);
  90202. }
  90203. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  90204. FLAC__StreamEncoder *encoder,
  90205. FLAC__StreamEncoderReadCallback read_callback,
  90206. FLAC__StreamEncoderWriteCallback write_callback,
  90207. FLAC__StreamEncoderSeekCallback seek_callback,
  90208. FLAC__StreamEncoderTellCallback tell_callback,
  90209. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90210. void *client_data,
  90211. FLAC__bool is_ogg
  90212. )
  90213. {
  90214. unsigned i;
  90215. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  90216. FLAC__ASSERT(0 != encoder);
  90217. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90218. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90219. #if !FLAC__HAS_OGG
  90220. if(is_ogg)
  90221. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  90222. #endif
  90223. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  90224. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  90225. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  90226. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  90227. if(encoder->protected_->channels != 2) {
  90228. encoder->protected_->do_mid_side_stereo = false;
  90229. encoder->protected_->loose_mid_side_stereo = false;
  90230. }
  90231. else if(!encoder->protected_->do_mid_side_stereo)
  90232. encoder->protected_->loose_mid_side_stereo = false;
  90233. if(encoder->protected_->bits_per_sample >= 32)
  90234. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  90235. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  90236. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  90237. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  90238. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  90239. if(encoder->protected_->blocksize == 0) {
  90240. if(encoder->protected_->max_lpc_order == 0)
  90241. encoder->protected_->blocksize = 1152;
  90242. else
  90243. encoder->protected_->blocksize = 4096;
  90244. }
  90245. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  90246. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  90247. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  90248. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  90249. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  90250. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  90251. if(encoder->protected_->qlp_coeff_precision == 0) {
  90252. if(encoder->protected_->bits_per_sample < 16) {
  90253. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  90254. }
  90255. else if(encoder->protected_->bits_per_sample == 16) {
  90256. if(encoder->protected_->blocksize <= 192)
  90257. encoder->protected_->qlp_coeff_precision = 7;
  90258. else if(encoder->protected_->blocksize <= 384)
  90259. encoder->protected_->qlp_coeff_precision = 8;
  90260. else if(encoder->protected_->blocksize <= 576)
  90261. encoder->protected_->qlp_coeff_precision = 9;
  90262. else if(encoder->protected_->blocksize <= 1152)
  90263. encoder->protected_->qlp_coeff_precision = 10;
  90264. else if(encoder->protected_->blocksize <= 2304)
  90265. encoder->protected_->qlp_coeff_precision = 11;
  90266. else if(encoder->protected_->blocksize <= 4608)
  90267. encoder->protected_->qlp_coeff_precision = 12;
  90268. else
  90269. encoder->protected_->qlp_coeff_precision = 13;
  90270. }
  90271. else {
  90272. if(encoder->protected_->blocksize <= 384)
  90273. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  90274. else if(encoder->protected_->blocksize <= 1152)
  90275. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  90276. else
  90277. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  90278. }
  90279. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  90280. }
  90281. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  90282. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  90283. if(encoder->protected_->streamable_subset) {
  90284. if(
  90285. encoder->protected_->blocksize != 192 &&
  90286. encoder->protected_->blocksize != 576 &&
  90287. encoder->protected_->blocksize != 1152 &&
  90288. encoder->protected_->blocksize != 2304 &&
  90289. encoder->protected_->blocksize != 4608 &&
  90290. encoder->protected_->blocksize != 256 &&
  90291. encoder->protected_->blocksize != 512 &&
  90292. encoder->protected_->blocksize != 1024 &&
  90293. encoder->protected_->blocksize != 2048 &&
  90294. encoder->protected_->blocksize != 4096 &&
  90295. encoder->protected_->blocksize != 8192 &&
  90296. encoder->protected_->blocksize != 16384
  90297. )
  90298. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90299. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90300. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90301. if(
  90302. encoder->protected_->bits_per_sample != 8 &&
  90303. encoder->protected_->bits_per_sample != 12 &&
  90304. encoder->protected_->bits_per_sample != 16 &&
  90305. encoder->protected_->bits_per_sample != 20 &&
  90306. encoder->protected_->bits_per_sample != 24
  90307. )
  90308. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90309. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90310. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90311. if(
  90312. encoder->protected_->sample_rate <= 48000 &&
  90313. (
  90314. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90315. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90316. )
  90317. ) {
  90318. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90319. }
  90320. }
  90321. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90322. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  90323. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  90324. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  90325. #if FLAC__HAS_OGG
  90326. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90327. unsigned i;
  90328. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90329. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90330. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90331. for( ; i > 0; i--)
  90332. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90333. encoder->protected_->metadata[0] = vc;
  90334. break;
  90335. }
  90336. }
  90337. }
  90338. #endif
  90339. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90340. unsigned i;
  90341. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90342. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90343. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90344. break; /* take only the first one */
  90345. }
  90346. }
  90347. }
  90348. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90349. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90350. metadata_has_seektable = false;
  90351. metadata_has_vorbis_comment = false;
  90352. metadata_picture_has_type1 = false;
  90353. metadata_picture_has_type2 = false;
  90354. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90355. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90356. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90357. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90358. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90359. if(metadata_has_seektable) /* only one is allowed */
  90360. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90361. metadata_has_seektable = true;
  90362. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90363. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90364. }
  90365. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90366. if(metadata_has_vorbis_comment) /* only one is allowed */
  90367. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90368. metadata_has_vorbis_comment = true;
  90369. }
  90370. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  90371. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  90372. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90373. }
  90374. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  90375. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  90376. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90377. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  90378. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  90379. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90380. metadata_picture_has_type1 = true;
  90381. if(
  90382. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  90383. (
  90384. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  90385. m->data.picture.width != 32 ||
  90386. m->data.picture.height != 32
  90387. )
  90388. )
  90389. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90390. }
  90391. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  90392. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  90393. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90394. metadata_picture_has_type2 = true;
  90395. }
  90396. }
  90397. }
  90398. encoder->private_->input_capacity = 0;
  90399. for(i = 0; i < encoder->protected_->channels; i++) {
  90400. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  90401. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90402. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  90403. #endif
  90404. }
  90405. for(i = 0; i < 2; i++) {
  90406. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90407. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90408. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90409. #endif
  90410. }
  90411. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90412. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90413. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90414. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90415. #endif
  90416. for(i = 0; i < encoder->protected_->channels; i++) {
  90417. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90418. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90419. encoder->private_->best_subframe[i] = 0;
  90420. }
  90421. for(i = 0; i < 2; i++) {
  90422. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90423. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90424. encoder->private_->best_subframe_mid_side[i] = 0;
  90425. }
  90426. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90427. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90428. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90429. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90430. #else
  90431. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90432. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90433. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90434. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90435. 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);
  90436. #endif
  90437. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90438. encoder->private_->loose_mid_side_stereo_frames = 1;
  90439. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90440. encoder->private_->current_sample_number = 0;
  90441. encoder->private_->current_frame_number = 0;
  90442. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90443. 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? */
  90444. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90445. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90446. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90447. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90448. #endif
  90449. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90450. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90451. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90452. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90453. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90454. #endif
  90455. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90456. # ifndef FLAC__NO_ASM
  90457. if(encoder->private_->cpuinfo.use_asm) {
  90458. # ifdef FLAC__CPU_IA32
  90459. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90460. # ifdef FLAC__HAS_NASM
  90461. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90462. if(encoder->protected_->max_lpc_order < 4)
  90463. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90464. else if(encoder->protected_->max_lpc_order < 8)
  90465. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90466. else if(encoder->protected_->max_lpc_order < 12)
  90467. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90468. else
  90469. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90470. }
  90471. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90472. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90473. else
  90474. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90475. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90476. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90477. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90478. }
  90479. else {
  90480. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90481. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90482. }
  90483. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90484. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90485. # endif /* FLAC__HAS_NASM */
  90486. # endif /* FLAC__CPU_IA32 */
  90487. }
  90488. # endif /* !FLAC__NO_ASM */
  90489. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90490. if(encoder->private_->use_wide_by_block) {
  90491. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90492. }
  90493. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90494. #if FLAC__HAS_OGG
  90495. encoder->private_->is_ogg = is_ogg;
  90496. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90497. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90498. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90499. }
  90500. #endif
  90501. encoder->private_->read_callback = read_callback;
  90502. encoder->private_->write_callback = write_callback;
  90503. encoder->private_->seek_callback = seek_callback;
  90504. encoder->private_->tell_callback = tell_callback;
  90505. encoder->private_->metadata_callback = metadata_callback;
  90506. encoder->private_->client_data = client_data;
  90507. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90508. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90509. }
  90510. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90511. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90512. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90513. }
  90514. if(encoder->protected_->verify) {
  90515. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90516. for(i = 0; i < encoder->protected_->channels; i++) {
  90517. 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))) {
  90518. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90519. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90520. }
  90521. }
  90522. encoder->private_->verify.input_fifo.tail = 0;
  90523. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90524. if(0 == encoder->private_->verify.decoder) {
  90525. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90526. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90527. }
  90528. 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) {
  90529. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90530. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90531. }
  90532. }
  90533. encoder->private_->verify.error_stats.absolute_sample = 0;
  90534. encoder->private_->verify.error_stats.frame_number = 0;
  90535. encoder->private_->verify.error_stats.channel = 0;
  90536. encoder->private_->verify.error_stats.sample = 0;
  90537. encoder->private_->verify.error_stats.expected = 0;
  90538. encoder->private_->verify.error_stats.got = 0;
  90539. encoder->private_->first_seekpoint_to_check = 0;
  90540. encoder->private_->samples_written = 0;
  90541. encoder->protected_->streaminfo_offset = 0;
  90542. encoder->protected_->seektable_offset = 0;
  90543. encoder->protected_->audio_offset = 0;
  90544. if(encoder->protected_->verify)
  90545. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90546. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90547. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90548. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90549. }
  90550. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90551. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90552. }
  90553. if(encoder->protected_->verify)
  90554. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90555. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90556. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90557. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90558. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90559. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90560. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90561. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90562. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90563. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90564. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90565. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90566. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90567. if(encoder->protected_->do_md5)
  90568. FLAC__MD5Init(&encoder->private_->md5context);
  90569. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90570. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90571. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90572. }
  90573. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90574. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90575. }
  90576. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90577. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90578. if(!metadata_has_vorbis_comment) {
  90579. FLAC__StreamMetadata vorbis_comment;
  90580. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90581. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90582. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90583. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90584. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90585. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90586. vorbis_comment.data.vorbis_comment.comments = 0;
  90587. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90588. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90589. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90590. }
  90591. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90592. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90593. }
  90594. }
  90595. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90596. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90597. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  90598. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90599. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90600. }
  90601. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90602. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90603. }
  90604. }
  90605. 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 */
  90606. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90607. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90608. }
  90609. if(encoder->protected_->verify)
  90610. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90611. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90612. }
  90613. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90614. FLAC__StreamEncoder *encoder,
  90615. FLAC__StreamEncoderWriteCallback write_callback,
  90616. FLAC__StreamEncoderSeekCallback seek_callback,
  90617. FLAC__StreamEncoderTellCallback tell_callback,
  90618. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90619. void *client_data
  90620. )
  90621. {
  90622. return init_stream_internal_enc(
  90623. encoder,
  90624. 0,
  90625. write_callback,
  90626. seek_callback,
  90627. tell_callback,
  90628. metadata_callback,
  90629. client_data,
  90630. false
  90631. );
  90632. }
  90633. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90634. FLAC__StreamEncoder *encoder,
  90635. FLAC__StreamEncoderReadCallback read_callback,
  90636. FLAC__StreamEncoderWriteCallback write_callback,
  90637. FLAC__StreamEncoderSeekCallback seek_callback,
  90638. FLAC__StreamEncoderTellCallback tell_callback,
  90639. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90640. void *client_data
  90641. )
  90642. {
  90643. return init_stream_internal_enc(
  90644. encoder,
  90645. read_callback,
  90646. write_callback,
  90647. seek_callback,
  90648. tell_callback,
  90649. metadata_callback,
  90650. client_data,
  90651. true
  90652. );
  90653. }
  90654. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90655. FLAC__StreamEncoder *encoder,
  90656. FILE *file,
  90657. FLAC__StreamEncoderProgressCallback progress_callback,
  90658. void *client_data,
  90659. FLAC__bool is_ogg
  90660. )
  90661. {
  90662. FLAC__StreamEncoderInitStatus init_status;
  90663. FLAC__ASSERT(0 != encoder);
  90664. FLAC__ASSERT(0 != file);
  90665. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90666. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90667. if(file == 0) {
  90668. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90669. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90670. }
  90671. if(file == stdout)
  90672. file = get_binary_stdout_(); /* just to be safe */
  90673. encoder->private_->file = file;
  90674. encoder->private_->progress_callback = progress_callback;
  90675. encoder->private_->bytes_written = 0;
  90676. encoder->private_->samples_written = 0;
  90677. encoder->private_->frames_written = 0;
  90678. init_status = init_stream_internal_enc(
  90679. encoder,
  90680. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  90681. file_write_callback_,
  90682. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  90683. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  90684. 0,
  90685. client_data,
  90686. is_ogg
  90687. );
  90688. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  90689. return init_status;
  90690. }
  90691. {
  90692. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  90693. FLAC__ASSERT(blocksize != 0);
  90694. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  90695. }
  90696. return init_status;
  90697. }
  90698. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  90699. FLAC__StreamEncoder *encoder,
  90700. FILE *file,
  90701. FLAC__StreamEncoderProgressCallback progress_callback,
  90702. void *client_data
  90703. )
  90704. {
  90705. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  90706. }
  90707. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  90708. FLAC__StreamEncoder *encoder,
  90709. FILE *file,
  90710. FLAC__StreamEncoderProgressCallback progress_callback,
  90711. void *client_data
  90712. )
  90713. {
  90714. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  90715. }
  90716. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  90717. FLAC__StreamEncoder *encoder,
  90718. const char *filename,
  90719. FLAC__StreamEncoderProgressCallback progress_callback,
  90720. void *client_data,
  90721. FLAC__bool is_ogg
  90722. )
  90723. {
  90724. FILE *file;
  90725. FLAC__ASSERT(0 != encoder);
  90726. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90727. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90728. file = filename? fopen(filename, "w+b") : stdout;
  90729. if(file == 0) {
  90730. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90731. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90732. }
  90733. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  90734. }
  90735. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  90736. FLAC__StreamEncoder *encoder,
  90737. const char *filename,
  90738. FLAC__StreamEncoderProgressCallback progress_callback,
  90739. void *client_data
  90740. )
  90741. {
  90742. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  90743. }
  90744. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  90745. FLAC__StreamEncoder *encoder,
  90746. const char *filename,
  90747. FLAC__StreamEncoderProgressCallback progress_callback,
  90748. void *client_data
  90749. )
  90750. {
  90751. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  90752. }
  90753. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  90754. {
  90755. FLAC__bool error = false;
  90756. FLAC__ASSERT(0 != encoder);
  90757. FLAC__ASSERT(0 != encoder->private_);
  90758. FLAC__ASSERT(0 != encoder->protected_);
  90759. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  90760. return true;
  90761. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  90762. if(encoder->private_->current_sample_number != 0) {
  90763. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  90764. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  90765. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  90766. error = true;
  90767. }
  90768. }
  90769. if(encoder->protected_->do_md5)
  90770. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  90771. if(!encoder->private_->is_being_deleted) {
  90772. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  90773. if(encoder->private_->seek_callback) {
  90774. #if FLAC__HAS_OGG
  90775. if(encoder->private_->is_ogg)
  90776. update_ogg_metadata_(encoder);
  90777. else
  90778. #endif
  90779. update_metadata_(encoder);
  90780. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  90781. error = true;
  90782. }
  90783. if(encoder->private_->metadata_callback)
  90784. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  90785. }
  90786. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  90787. if(!error)
  90788. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  90789. error = true;
  90790. }
  90791. }
  90792. if(0 != encoder->private_->file) {
  90793. if(encoder->private_->file != stdout)
  90794. fclose(encoder->private_->file);
  90795. encoder->private_->file = 0;
  90796. }
  90797. #if FLAC__HAS_OGG
  90798. if(encoder->private_->is_ogg)
  90799. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  90800. #endif
  90801. free_(encoder);
  90802. set_defaults_enc(encoder);
  90803. if(!error)
  90804. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90805. return !error;
  90806. }
  90807. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  90808. {
  90809. FLAC__ASSERT(0 != encoder);
  90810. FLAC__ASSERT(0 != encoder->private_);
  90811. FLAC__ASSERT(0 != encoder->protected_);
  90812. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90813. return false;
  90814. #if FLAC__HAS_OGG
  90815. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  90816. return true;
  90817. #else
  90818. (void)value;
  90819. return false;
  90820. #endif
  90821. }
  90822. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90823. {
  90824. FLAC__ASSERT(0 != encoder);
  90825. FLAC__ASSERT(0 != encoder->private_);
  90826. FLAC__ASSERT(0 != encoder->protected_);
  90827. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90828. return false;
  90829. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  90830. encoder->protected_->verify = value;
  90831. #endif
  90832. return true;
  90833. }
  90834. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90835. {
  90836. FLAC__ASSERT(0 != encoder);
  90837. FLAC__ASSERT(0 != encoder->private_);
  90838. FLAC__ASSERT(0 != encoder->protected_);
  90839. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90840. return false;
  90841. encoder->protected_->streamable_subset = value;
  90842. return true;
  90843. }
  90844. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90845. {
  90846. FLAC__ASSERT(0 != encoder);
  90847. FLAC__ASSERT(0 != encoder->private_);
  90848. FLAC__ASSERT(0 != encoder->protected_);
  90849. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90850. return false;
  90851. encoder->protected_->do_md5 = value;
  90852. return true;
  90853. }
  90854. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  90855. {
  90856. FLAC__ASSERT(0 != encoder);
  90857. FLAC__ASSERT(0 != encoder->private_);
  90858. FLAC__ASSERT(0 != encoder->protected_);
  90859. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90860. return false;
  90861. encoder->protected_->channels = value;
  90862. return true;
  90863. }
  90864. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  90865. {
  90866. FLAC__ASSERT(0 != encoder);
  90867. FLAC__ASSERT(0 != encoder->private_);
  90868. FLAC__ASSERT(0 != encoder->protected_);
  90869. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90870. return false;
  90871. encoder->protected_->bits_per_sample = value;
  90872. return true;
  90873. }
  90874. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  90875. {
  90876. FLAC__ASSERT(0 != encoder);
  90877. FLAC__ASSERT(0 != encoder->private_);
  90878. FLAC__ASSERT(0 != encoder->protected_);
  90879. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90880. return false;
  90881. encoder->protected_->sample_rate = value;
  90882. return true;
  90883. }
  90884. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  90885. {
  90886. FLAC__bool ok = true;
  90887. FLAC__ASSERT(0 != encoder);
  90888. FLAC__ASSERT(0 != encoder->private_);
  90889. FLAC__ASSERT(0 != encoder->protected_);
  90890. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90891. return false;
  90892. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  90893. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  90894. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  90895. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  90896. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90897. #if 0
  90898. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  90899. #else
  90900. encoder->protected_->num_apodizations = 1;
  90901. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90902. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90903. #endif
  90904. #endif
  90905. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  90906. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  90907. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  90908. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  90909. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  90910. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  90911. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  90912. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  90913. return ok;
  90914. }
  90915. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  90916. {
  90917. FLAC__ASSERT(0 != encoder);
  90918. FLAC__ASSERT(0 != encoder->private_);
  90919. FLAC__ASSERT(0 != encoder->protected_);
  90920. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90921. return false;
  90922. encoder->protected_->blocksize = value;
  90923. return true;
  90924. }
  90925. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90926. {
  90927. FLAC__ASSERT(0 != encoder);
  90928. FLAC__ASSERT(0 != encoder->private_);
  90929. FLAC__ASSERT(0 != encoder->protected_);
  90930. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90931. return false;
  90932. encoder->protected_->do_mid_side_stereo = value;
  90933. return true;
  90934. }
  90935. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90936. {
  90937. FLAC__ASSERT(0 != encoder);
  90938. FLAC__ASSERT(0 != encoder->private_);
  90939. FLAC__ASSERT(0 != encoder->protected_);
  90940. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90941. return false;
  90942. encoder->protected_->loose_mid_side_stereo = value;
  90943. return true;
  90944. }
  90945. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  90946. {
  90947. FLAC__ASSERT(0 != encoder);
  90948. FLAC__ASSERT(0 != encoder->private_);
  90949. FLAC__ASSERT(0 != encoder->protected_);
  90950. FLAC__ASSERT(0 != specification);
  90951. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90952. return false;
  90953. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  90954. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  90955. #else
  90956. encoder->protected_->num_apodizations = 0;
  90957. while(1) {
  90958. const char *s = strchr(specification, ';');
  90959. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  90960. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  90961. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  90962. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  90963. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  90964. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  90965. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  90966. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  90967. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  90968. else if(n==6 && 0 == strncmp("connes" , specification, n))
  90969. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  90970. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  90971. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  90972. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  90973. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  90974. if (stddev > 0.0 && stddev <= 0.5) {
  90975. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  90976. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  90977. }
  90978. }
  90979. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  90980. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  90981. else if(n==4 && 0 == strncmp("hann" , specification, n))
  90982. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  90983. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  90984. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  90985. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  90986. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  90987. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  90988. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  90989. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  90990. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  90991. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  90992. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  90993. if (p >= 0.0 && p <= 1.0) {
  90994. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  90995. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  90996. }
  90997. }
  90998. else if(n==5 && 0 == strncmp("welch" , specification, n))
  90999. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  91000. if (encoder->protected_->num_apodizations == 32)
  91001. break;
  91002. if (s)
  91003. specification = s+1;
  91004. else
  91005. break;
  91006. }
  91007. if(encoder->protected_->num_apodizations == 0) {
  91008. encoder->protected_->num_apodizations = 1;
  91009. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91010. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91011. }
  91012. #endif
  91013. return true;
  91014. }
  91015. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  91016. {
  91017. FLAC__ASSERT(0 != encoder);
  91018. FLAC__ASSERT(0 != encoder->private_);
  91019. FLAC__ASSERT(0 != encoder->protected_);
  91020. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91021. return false;
  91022. encoder->protected_->max_lpc_order = value;
  91023. return true;
  91024. }
  91025. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  91026. {
  91027. FLAC__ASSERT(0 != encoder);
  91028. FLAC__ASSERT(0 != encoder->private_);
  91029. FLAC__ASSERT(0 != encoder->protected_);
  91030. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91031. return false;
  91032. encoder->protected_->qlp_coeff_precision = value;
  91033. return true;
  91034. }
  91035. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91036. {
  91037. FLAC__ASSERT(0 != encoder);
  91038. FLAC__ASSERT(0 != encoder->private_);
  91039. FLAC__ASSERT(0 != encoder->protected_);
  91040. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91041. return false;
  91042. encoder->protected_->do_qlp_coeff_prec_search = value;
  91043. return true;
  91044. }
  91045. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91046. {
  91047. FLAC__ASSERT(0 != encoder);
  91048. FLAC__ASSERT(0 != encoder->private_);
  91049. FLAC__ASSERT(0 != encoder->protected_);
  91050. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91051. return false;
  91052. #if 0
  91053. encoder->protected_->do_escape_coding = value;
  91054. #else
  91055. (void)value;
  91056. #endif
  91057. return true;
  91058. }
  91059. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91060. {
  91061. FLAC__ASSERT(0 != encoder);
  91062. FLAC__ASSERT(0 != encoder->private_);
  91063. FLAC__ASSERT(0 != encoder->protected_);
  91064. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91065. return false;
  91066. encoder->protected_->do_exhaustive_model_search = value;
  91067. return true;
  91068. }
  91069. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91070. {
  91071. FLAC__ASSERT(0 != encoder);
  91072. FLAC__ASSERT(0 != encoder->private_);
  91073. FLAC__ASSERT(0 != encoder->protected_);
  91074. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91075. return false;
  91076. encoder->protected_->min_residual_partition_order = value;
  91077. return true;
  91078. }
  91079. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91080. {
  91081. FLAC__ASSERT(0 != encoder);
  91082. FLAC__ASSERT(0 != encoder->private_);
  91083. FLAC__ASSERT(0 != encoder->protected_);
  91084. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91085. return false;
  91086. encoder->protected_->max_residual_partition_order = value;
  91087. return true;
  91088. }
  91089. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  91090. {
  91091. FLAC__ASSERT(0 != encoder);
  91092. FLAC__ASSERT(0 != encoder->private_);
  91093. FLAC__ASSERT(0 != encoder->protected_);
  91094. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91095. return false;
  91096. #if 0
  91097. encoder->protected_->rice_parameter_search_dist = value;
  91098. #else
  91099. (void)value;
  91100. #endif
  91101. return true;
  91102. }
  91103. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  91104. {
  91105. FLAC__ASSERT(0 != encoder);
  91106. FLAC__ASSERT(0 != encoder->private_);
  91107. FLAC__ASSERT(0 != encoder->protected_);
  91108. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91109. return false;
  91110. encoder->protected_->total_samples_estimate = value;
  91111. return true;
  91112. }
  91113. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  91114. {
  91115. FLAC__ASSERT(0 != encoder);
  91116. FLAC__ASSERT(0 != encoder->private_);
  91117. FLAC__ASSERT(0 != encoder->protected_);
  91118. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91119. return false;
  91120. if(0 == metadata)
  91121. num_blocks = 0;
  91122. if(0 == num_blocks)
  91123. metadata = 0;
  91124. if(encoder->protected_->metadata) {
  91125. free(encoder->protected_->metadata);
  91126. encoder->protected_->metadata = 0;
  91127. encoder->protected_->num_metadata_blocks = 0;
  91128. }
  91129. if(num_blocks) {
  91130. FLAC__StreamMetadata **m;
  91131. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  91132. return false;
  91133. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  91134. encoder->protected_->metadata = m;
  91135. encoder->protected_->num_metadata_blocks = num_blocks;
  91136. }
  91137. #if FLAC__HAS_OGG
  91138. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  91139. return false;
  91140. #endif
  91141. return true;
  91142. }
  91143. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91144. {
  91145. FLAC__ASSERT(0 != encoder);
  91146. FLAC__ASSERT(0 != encoder->private_);
  91147. FLAC__ASSERT(0 != encoder->protected_);
  91148. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91149. return false;
  91150. encoder->private_->disable_constant_subframes = value;
  91151. return true;
  91152. }
  91153. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91154. {
  91155. FLAC__ASSERT(0 != encoder);
  91156. FLAC__ASSERT(0 != encoder->private_);
  91157. FLAC__ASSERT(0 != encoder->protected_);
  91158. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91159. return false;
  91160. encoder->private_->disable_fixed_subframes = value;
  91161. return true;
  91162. }
  91163. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91164. {
  91165. FLAC__ASSERT(0 != encoder);
  91166. FLAC__ASSERT(0 != encoder->private_);
  91167. FLAC__ASSERT(0 != encoder->protected_);
  91168. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91169. return false;
  91170. encoder->private_->disable_verbatim_subframes = value;
  91171. return true;
  91172. }
  91173. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  91174. {
  91175. FLAC__ASSERT(0 != encoder);
  91176. FLAC__ASSERT(0 != encoder->private_);
  91177. FLAC__ASSERT(0 != encoder->protected_);
  91178. return encoder->protected_->state;
  91179. }
  91180. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  91181. {
  91182. FLAC__ASSERT(0 != encoder);
  91183. FLAC__ASSERT(0 != encoder->private_);
  91184. FLAC__ASSERT(0 != encoder->protected_);
  91185. if(encoder->protected_->verify)
  91186. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  91187. else
  91188. return FLAC__STREAM_DECODER_UNINITIALIZED;
  91189. }
  91190. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  91191. {
  91192. FLAC__ASSERT(0 != encoder);
  91193. FLAC__ASSERT(0 != encoder->private_);
  91194. FLAC__ASSERT(0 != encoder->protected_);
  91195. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  91196. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  91197. else
  91198. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  91199. }
  91200. 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)
  91201. {
  91202. FLAC__ASSERT(0 != encoder);
  91203. FLAC__ASSERT(0 != encoder->private_);
  91204. FLAC__ASSERT(0 != encoder->protected_);
  91205. if(0 != absolute_sample)
  91206. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  91207. if(0 != frame_number)
  91208. *frame_number = encoder->private_->verify.error_stats.frame_number;
  91209. if(0 != channel)
  91210. *channel = encoder->private_->verify.error_stats.channel;
  91211. if(0 != sample)
  91212. *sample = encoder->private_->verify.error_stats.sample;
  91213. if(0 != expected)
  91214. *expected = encoder->private_->verify.error_stats.expected;
  91215. if(0 != got)
  91216. *got = encoder->private_->verify.error_stats.got;
  91217. }
  91218. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  91219. {
  91220. FLAC__ASSERT(0 != encoder);
  91221. FLAC__ASSERT(0 != encoder->private_);
  91222. FLAC__ASSERT(0 != encoder->protected_);
  91223. return encoder->protected_->verify;
  91224. }
  91225. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  91226. {
  91227. FLAC__ASSERT(0 != encoder);
  91228. FLAC__ASSERT(0 != encoder->private_);
  91229. FLAC__ASSERT(0 != encoder->protected_);
  91230. return encoder->protected_->streamable_subset;
  91231. }
  91232. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  91233. {
  91234. FLAC__ASSERT(0 != encoder);
  91235. FLAC__ASSERT(0 != encoder->private_);
  91236. FLAC__ASSERT(0 != encoder->protected_);
  91237. return encoder->protected_->do_md5;
  91238. }
  91239. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  91240. {
  91241. FLAC__ASSERT(0 != encoder);
  91242. FLAC__ASSERT(0 != encoder->private_);
  91243. FLAC__ASSERT(0 != encoder->protected_);
  91244. return encoder->protected_->channels;
  91245. }
  91246. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  91247. {
  91248. FLAC__ASSERT(0 != encoder);
  91249. FLAC__ASSERT(0 != encoder->private_);
  91250. FLAC__ASSERT(0 != encoder->protected_);
  91251. return encoder->protected_->bits_per_sample;
  91252. }
  91253. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  91254. {
  91255. FLAC__ASSERT(0 != encoder);
  91256. FLAC__ASSERT(0 != encoder->private_);
  91257. FLAC__ASSERT(0 != encoder->protected_);
  91258. return encoder->protected_->sample_rate;
  91259. }
  91260. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  91261. {
  91262. FLAC__ASSERT(0 != encoder);
  91263. FLAC__ASSERT(0 != encoder->private_);
  91264. FLAC__ASSERT(0 != encoder->protected_);
  91265. return encoder->protected_->blocksize;
  91266. }
  91267. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91268. {
  91269. FLAC__ASSERT(0 != encoder);
  91270. FLAC__ASSERT(0 != encoder->private_);
  91271. FLAC__ASSERT(0 != encoder->protected_);
  91272. return encoder->protected_->do_mid_side_stereo;
  91273. }
  91274. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91275. {
  91276. FLAC__ASSERT(0 != encoder);
  91277. FLAC__ASSERT(0 != encoder->private_);
  91278. FLAC__ASSERT(0 != encoder->protected_);
  91279. return encoder->protected_->loose_mid_side_stereo;
  91280. }
  91281. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  91282. {
  91283. FLAC__ASSERT(0 != encoder);
  91284. FLAC__ASSERT(0 != encoder->private_);
  91285. FLAC__ASSERT(0 != encoder->protected_);
  91286. return encoder->protected_->max_lpc_order;
  91287. }
  91288. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  91289. {
  91290. FLAC__ASSERT(0 != encoder);
  91291. FLAC__ASSERT(0 != encoder->private_);
  91292. FLAC__ASSERT(0 != encoder->protected_);
  91293. return encoder->protected_->qlp_coeff_precision;
  91294. }
  91295. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  91296. {
  91297. FLAC__ASSERT(0 != encoder);
  91298. FLAC__ASSERT(0 != encoder->private_);
  91299. FLAC__ASSERT(0 != encoder->protected_);
  91300. return encoder->protected_->do_qlp_coeff_prec_search;
  91301. }
  91302. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  91303. {
  91304. FLAC__ASSERT(0 != encoder);
  91305. FLAC__ASSERT(0 != encoder->private_);
  91306. FLAC__ASSERT(0 != encoder->protected_);
  91307. return encoder->protected_->do_escape_coding;
  91308. }
  91309. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  91310. {
  91311. FLAC__ASSERT(0 != encoder);
  91312. FLAC__ASSERT(0 != encoder->private_);
  91313. FLAC__ASSERT(0 != encoder->protected_);
  91314. return encoder->protected_->do_exhaustive_model_search;
  91315. }
  91316. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91317. {
  91318. FLAC__ASSERT(0 != encoder);
  91319. FLAC__ASSERT(0 != encoder->private_);
  91320. FLAC__ASSERT(0 != encoder->protected_);
  91321. return encoder->protected_->min_residual_partition_order;
  91322. }
  91323. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91324. {
  91325. FLAC__ASSERT(0 != encoder);
  91326. FLAC__ASSERT(0 != encoder->private_);
  91327. FLAC__ASSERT(0 != encoder->protected_);
  91328. return encoder->protected_->max_residual_partition_order;
  91329. }
  91330. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  91331. {
  91332. FLAC__ASSERT(0 != encoder);
  91333. FLAC__ASSERT(0 != encoder->private_);
  91334. FLAC__ASSERT(0 != encoder->protected_);
  91335. return encoder->protected_->rice_parameter_search_dist;
  91336. }
  91337. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  91338. {
  91339. FLAC__ASSERT(0 != encoder);
  91340. FLAC__ASSERT(0 != encoder->private_);
  91341. FLAC__ASSERT(0 != encoder->protected_);
  91342. return encoder->protected_->total_samples_estimate;
  91343. }
  91344. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91345. {
  91346. unsigned i, j = 0, channel;
  91347. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91348. FLAC__ASSERT(0 != encoder);
  91349. FLAC__ASSERT(0 != encoder->private_);
  91350. FLAC__ASSERT(0 != encoder->protected_);
  91351. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91352. do {
  91353. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91354. if(encoder->protected_->verify)
  91355. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91356. for(channel = 0; channel < channels; channel++)
  91357. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91358. if(encoder->protected_->do_mid_side_stereo) {
  91359. FLAC__ASSERT(channels == 2);
  91360. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91361. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91362. 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' ! */
  91363. }
  91364. }
  91365. else
  91366. j += n;
  91367. encoder->private_->current_sample_number += n;
  91368. if(encoder->private_->current_sample_number > blocksize) {
  91369. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  91370. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91371. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91372. return false;
  91373. for(channel = 0; channel < channels; channel++)
  91374. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91375. if(encoder->protected_->do_mid_side_stereo) {
  91376. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91377. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91378. }
  91379. encoder->private_->current_sample_number = 1;
  91380. }
  91381. } while(j < samples);
  91382. return true;
  91383. }
  91384. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  91385. {
  91386. unsigned i, j, k, channel;
  91387. FLAC__int32 x, mid, side;
  91388. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91389. FLAC__ASSERT(0 != encoder);
  91390. FLAC__ASSERT(0 != encoder->private_);
  91391. FLAC__ASSERT(0 != encoder->protected_);
  91392. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91393. j = k = 0;
  91394. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  91395. do {
  91396. if(encoder->protected_->verify)
  91397. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91398. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91399. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  91400. x = buffer[k++];
  91401. encoder->private_->integer_signal[1][i] = x;
  91402. mid += x;
  91403. side -= x;
  91404. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  91405. encoder->private_->integer_signal_mid_side[1][i] = side;
  91406. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91407. }
  91408. encoder->private_->current_sample_number = i;
  91409. if(i > blocksize) {
  91410. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91411. return false;
  91412. /* move unprocessed overread samples to beginnings of arrays */
  91413. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91414. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91415. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91416. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91417. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91418. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91419. encoder->private_->current_sample_number = 1;
  91420. }
  91421. } while(j < samples);
  91422. }
  91423. else {
  91424. do {
  91425. if(encoder->protected_->verify)
  91426. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91427. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91428. for(channel = 0; channel < channels; channel++)
  91429. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91430. }
  91431. encoder->private_->current_sample_number = i;
  91432. if(i > blocksize) {
  91433. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91434. return false;
  91435. /* move unprocessed overread samples to beginnings of arrays */
  91436. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91437. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91438. for(channel = 0; channel < channels; channel++)
  91439. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91440. encoder->private_->current_sample_number = 1;
  91441. }
  91442. } while(j < samples);
  91443. }
  91444. return true;
  91445. }
  91446. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91447. {
  91448. FLAC__ASSERT(0 != encoder);
  91449. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91450. encoder->protected_->verify = true;
  91451. #else
  91452. encoder->protected_->verify = false;
  91453. #endif
  91454. encoder->protected_->streamable_subset = true;
  91455. encoder->protected_->do_md5 = true;
  91456. encoder->protected_->do_mid_side_stereo = false;
  91457. encoder->protected_->loose_mid_side_stereo = false;
  91458. encoder->protected_->channels = 2;
  91459. encoder->protected_->bits_per_sample = 16;
  91460. encoder->protected_->sample_rate = 44100;
  91461. encoder->protected_->blocksize = 0;
  91462. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91463. encoder->protected_->num_apodizations = 1;
  91464. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91465. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91466. #endif
  91467. encoder->protected_->max_lpc_order = 0;
  91468. encoder->protected_->qlp_coeff_precision = 0;
  91469. encoder->protected_->do_qlp_coeff_prec_search = false;
  91470. encoder->protected_->do_exhaustive_model_search = false;
  91471. encoder->protected_->do_escape_coding = false;
  91472. encoder->protected_->min_residual_partition_order = 0;
  91473. encoder->protected_->max_residual_partition_order = 0;
  91474. encoder->protected_->rice_parameter_search_dist = 0;
  91475. encoder->protected_->total_samples_estimate = 0;
  91476. encoder->protected_->metadata = 0;
  91477. encoder->protected_->num_metadata_blocks = 0;
  91478. encoder->private_->seek_table = 0;
  91479. encoder->private_->disable_constant_subframes = false;
  91480. encoder->private_->disable_fixed_subframes = false;
  91481. encoder->private_->disable_verbatim_subframes = false;
  91482. #if FLAC__HAS_OGG
  91483. encoder->private_->is_ogg = false;
  91484. #endif
  91485. encoder->private_->read_callback = 0;
  91486. encoder->private_->write_callback = 0;
  91487. encoder->private_->seek_callback = 0;
  91488. encoder->private_->tell_callback = 0;
  91489. encoder->private_->metadata_callback = 0;
  91490. encoder->private_->progress_callback = 0;
  91491. encoder->private_->client_data = 0;
  91492. #if FLAC__HAS_OGG
  91493. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91494. #endif
  91495. }
  91496. void free_(FLAC__StreamEncoder *encoder)
  91497. {
  91498. unsigned i, channel;
  91499. FLAC__ASSERT(0 != encoder);
  91500. if(encoder->protected_->metadata) {
  91501. free(encoder->protected_->metadata);
  91502. encoder->protected_->metadata = 0;
  91503. encoder->protected_->num_metadata_blocks = 0;
  91504. }
  91505. for(i = 0; i < encoder->protected_->channels; i++) {
  91506. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91507. free(encoder->private_->integer_signal_unaligned[i]);
  91508. encoder->private_->integer_signal_unaligned[i] = 0;
  91509. }
  91510. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91511. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91512. free(encoder->private_->real_signal_unaligned[i]);
  91513. encoder->private_->real_signal_unaligned[i] = 0;
  91514. }
  91515. #endif
  91516. }
  91517. for(i = 0; i < 2; i++) {
  91518. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91519. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91520. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91521. }
  91522. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91523. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91524. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91525. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91526. }
  91527. #endif
  91528. }
  91529. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91530. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91531. if(0 != encoder->private_->window_unaligned[i]) {
  91532. free(encoder->private_->window_unaligned[i]);
  91533. encoder->private_->window_unaligned[i] = 0;
  91534. }
  91535. }
  91536. if(0 != encoder->private_->windowed_signal_unaligned) {
  91537. free(encoder->private_->windowed_signal_unaligned);
  91538. encoder->private_->windowed_signal_unaligned = 0;
  91539. }
  91540. #endif
  91541. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91542. for(i = 0; i < 2; i++) {
  91543. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91544. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91545. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91546. }
  91547. }
  91548. }
  91549. for(channel = 0; channel < 2; channel++) {
  91550. for(i = 0; i < 2; i++) {
  91551. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91552. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91553. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91554. }
  91555. }
  91556. }
  91557. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91558. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91559. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91560. }
  91561. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91562. free(encoder->private_->raw_bits_per_partition_unaligned);
  91563. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91564. }
  91565. if(encoder->protected_->verify) {
  91566. for(i = 0; i < encoder->protected_->channels; i++) {
  91567. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91568. free(encoder->private_->verify.input_fifo.data[i]);
  91569. encoder->private_->verify.input_fifo.data[i] = 0;
  91570. }
  91571. }
  91572. }
  91573. FLAC__bitwriter_free(encoder->private_->frame);
  91574. }
  91575. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91576. {
  91577. FLAC__bool ok;
  91578. unsigned i, channel;
  91579. FLAC__ASSERT(new_blocksize > 0);
  91580. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91581. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91582. if(new_blocksize <= encoder->private_->input_capacity)
  91583. return true;
  91584. ok = true;
  91585. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91586. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91587. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91588. encoder->private_->integer_signal[i] += 4;
  91589. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91590. #if 0 /* @@@ currently unused */
  91591. if(encoder->protected_->max_lpc_order > 0)
  91592. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91593. #endif
  91594. #endif
  91595. }
  91596. for(i = 0; ok && i < 2; i++) {
  91597. 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]);
  91598. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91599. encoder->private_->integer_signal_mid_side[i] += 4;
  91600. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91601. #if 0 /* @@@ currently unused */
  91602. if(encoder->protected_->max_lpc_order > 0)
  91603. 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]);
  91604. #endif
  91605. #endif
  91606. }
  91607. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91608. if(ok && encoder->protected_->max_lpc_order > 0) {
  91609. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91610. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91611. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91612. }
  91613. #endif
  91614. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91615. for(i = 0; ok && i < 2; i++) {
  91616. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91617. }
  91618. }
  91619. for(channel = 0; ok && channel < 2; channel++) {
  91620. for(i = 0; ok && i < 2; i++) {
  91621. 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]);
  91622. }
  91623. }
  91624. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91625. if(encoder->protected_->do_escape_coding)
  91626. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91627. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91628. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91629. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91630. switch(encoder->protected_->apodizations[i].type) {
  91631. case FLAC__APODIZATION_BARTLETT:
  91632. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91633. break;
  91634. case FLAC__APODIZATION_BARTLETT_HANN:
  91635. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91636. break;
  91637. case FLAC__APODIZATION_BLACKMAN:
  91638. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91639. break;
  91640. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91641. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91642. break;
  91643. case FLAC__APODIZATION_CONNES:
  91644. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91645. break;
  91646. case FLAC__APODIZATION_FLATTOP:
  91647. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91648. break;
  91649. case FLAC__APODIZATION_GAUSS:
  91650. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91651. break;
  91652. case FLAC__APODIZATION_HAMMING:
  91653. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91654. break;
  91655. case FLAC__APODIZATION_HANN:
  91656. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91657. break;
  91658. case FLAC__APODIZATION_KAISER_BESSEL:
  91659. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91660. break;
  91661. case FLAC__APODIZATION_NUTTALL:
  91662. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91663. break;
  91664. case FLAC__APODIZATION_RECTANGLE:
  91665. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91666. break;
  91667. case FLAC__APODIZATION_TRIANGLE:
  91668. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91669. break;
  91670. case FLAC__APODIZATION_TUKEY:
  91671. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  91672. break;
  91673. case FLAC__APODIZATION_WELCH:
  91674. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  91675. break;
  91676. default:
  91677. FLAC__ASSERT(0);
  91678. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91679. break;
  91680. }
  91681. }
  91682. }
  91683. #endif
  91684. if(ok)
  91685. encoder->private_->input_capacity = new_blocksize;
  91686. else
  91687. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91688. return ok;
  91689. }
  91690. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  91691. {
  91692. const FLAC__byte *buffer;
  91693. size_t bytes;
  91694. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91695. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  91696. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91697. return false;
  91698. }
  91699. if(encoder->protected_->verify) {
  91700. encoder->private_->verify.output.data = buffer;
  91701. encoder->private_->verify.output.bytes = bytes;
  91702. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  91703. encoder->private_->verify.needs_magic_hack = true;
  91704. }
  91705. else {
  91706. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  91707. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91708. FLAC__bitwriter_clear(encoder->private_->frame);
  91709. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  91710. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91711. return false;
  91712. }
  91713. }
  91714. }
  91715. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91716. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91717. FLAC__bitwriter_clear(encoder->private_->frame);
  91718. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91719. return false;
  91720. }
  91721. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91722. FLAC__bitwriter_clear(encoder->private_->frame);
  91723. if(samples > 0) {
  91724. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  91725. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  91726. }
  91727. return true;
  91728. }
  91729. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  91730. {
  91731. FLAC__StreamEncoderWriteStatus status;
  91732. FLAC__uint64 output_position = 0;
  91733. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  91734. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91735. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  91736. }
  91737. if(samples == 0) {
  91738. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  91739. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  91740. encoder->protected_->streaminfo_offset = output_position;
  91741. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  91742. encoder->protected_->seektable_offset = output_position;
  91743. }
  91744. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  91745. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91746. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  91747. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  91748. FLAC__uint64 test_sample;
  91749. unsigned i;
  91750. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  91751. test_sample = encoder->private_->seek_table->points[i].sample_number;
  91752. if(test_sample > frame_last_sample) {
  91753. break;
  91754. }
  91755. else if(test_sample >= frame_first_sample) {
  91756. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  91757. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  91758. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  91759. encoder->private_->first_seekpoint_to_check++;
  91760. }
  91761. else {
  91762. encoder->private_->first_seekpoint_to_check++;
  91763. }
  91764. }
  91765. }
  91766. #if FLAC__HAS_OGG
  91767. if(encoder->private_->is_ogg) {
  91768. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  91769. &encoder->protected_->ogg_encoder_aspect,
  91770. buffer,
  91771. bytes,
  91772. samples,
  91773. encoder->private_->current_frame_number,
  91774. is_last_block,
  91775. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  91776. encoder,
  91777. encoder->private_->client_data
  91778. );
  91779. }
  91780. else
  91781. #endif
  91782. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  91783. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91784. encoder->private_->bytes_written += bytes;
  91785. encoder->private_->samples_written += samples;
  91786. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  91787. }
  91788. else
  91789. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91790. return status;
  91791. }
  91792. void update_metadata_(const FLAC__StreamEncoder *encoder)
  91793. {
  91794. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91795. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91796. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91797. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91798. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91799. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  91800. FLAC__StreamEncoderSeekStatus seek_status;
  91801. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91802. {
  91803. const unsigned md5_offset =
  91804. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91805. (
  91806. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91807. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91808. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91809. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91810. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91811. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91812. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91813. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91814. ) / 8;
  91815. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  91816. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91817. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91818. return;
  91819. }
  91820. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91821. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91822. return;
  91823. }
  91824. }
  91825. {
  91826. const unsigned total_samples_byte_offset =
  91827. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91828. (
  91829. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91830. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91831. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91832. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91833. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91834. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91835. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91836. - 4
  91837. ) / 8;
  91838. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  91839. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91840. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91841. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91842. b[4] = (FLAC__byte)(samples & 0xFF);
  91843. 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) {
  91844. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91845. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91846. return;
  91847. }
  91848. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91849. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91850. return;
  91851. }
  91852. }
  91853. {
  91854. const unsigned min_framesize_offset =
  91855. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91856. (
  91857. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91858. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91859. ) / 8;
  91860. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91861. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91862. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91863. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91864. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91865. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91866. 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) {
  91867. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91868. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91869. return;
  91870. }
  91871. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91872. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91873. return;
  91874. }
  91875. }
  91876. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91877. unsigned i;
  91878. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91879. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91880. 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) {
  91881. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91882. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91883. return;
  91884. }
  91885. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  91886. FLAC__uint64 xx;
  91887. unsigned x;
  91888. xx = encoder->private_->seek_table->points[i].sample_number;
  91889. b[7] = (FLAC__byte)xx; xx >>= 8;
  91890. b[6] = (FLAC__byte)xx; xx >>= 8;
  91891. b[5] = (FLAC__byte)xx; xx >>= 8;
  91892. b[4] = (FLAC__byte)xx; xx >>= 8;
  91893. b[3] = (FLAC__byte)xx; xx >>= 8;
  91894. b[2] = (FLAC__byte)xx; xx >>= 8;
  91895. b[1] = (FLAC__byte)xx; xx >>= 8;
  91896. b[0] = (FLAC__byte)xx; xx >>= 8;
  91897. xx = encoder->private_->seek_table->points[i].stream_offset;
  91898. b[15] = (FLAC__byte)xx; xx >>= 8;
  91899. b[14] = (FLAC__byte)xx; xx >>= 8;
  91900. b[13] = (FLAC__byte)xx; xx >>= 8;
  91901. b[12] = (FLAC__byte)xx; xx >>= 8;
  91902. b[11] = (FLAC__byte)xx; xx >>= 8;
  91903. b[10] = (FLAC__byte)xx; xx >>= 8;
  91904. b[9] = (FLAC__byte)xx; xx >>= 8;
  91905. b[8] = (FLAC__byte)xx; xx >>= 8;
  91906. x = encoder->private_->seek_table->points[i].frame_samples;
  91907. b[17] = (FLAC__byte)x; x >>= 8;
  91908. b[16] = (FLAC__byte)x; x >>= 8;
  91909. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91910. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91911. return;
  91912. }
  91913. }
  91914. }
  91915. }
  91916. #if FLAC__HAS_OGG
  91917. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  91918. {
  91919. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  91920. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  91921. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  91922. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  91923. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  91924. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  91925. FLAC__STREAM_SYNC_LENGTH
  91926. ;
  91927. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91928. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91929. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91930. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91931. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91932. ogg_page page;
  91933. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91934. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  91935. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  91936. return;
  91937. simple_ogg_page__init(&page);
  91938. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91939. simple_ogg_page__clear(&page);
  91940. return; /* state already set */
  91941. }
  91942. {
  91943. const unsigned md5_offset =
  91944. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91945. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91946. (
  91947. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91948. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91949. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91950. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91951. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91952. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91953. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91954. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91955. ) / 8;
  91956. if(md5_offset + 16 > (unsigned)page.body_len) {
  91957. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91958. simple_ogg_page__clear(&page);
  91959. return;
  91960. }
  91961. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  91962. }
  91963. {
  91964. const unsigned total_samples_byte_offset =
  91965. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91966. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91967. (
  91968. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91969. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91970. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91971. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91972. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91973. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91974. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91975. - 4
  91976. ) / 8;
  91977. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  91978. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91979. simple_ogg_page__clear(&page);
  91980. return;
  91981. }
  91982. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  91983. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  91984. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91985. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91986. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91987. b[4] = (FLAC__byte)(samples & 0xFF);
  91988. memcpy(page.body + total_samples_byte_offset, b, 5);
  91989. }
  91990. {
  91991. const unsigned min_framesize_offset =
  91992. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91993. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91994. (
  91995. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91996. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91997. ) / 8;
  91998. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  91999. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92000. simple_ogg_page__clear(&page);
  92001. return;
  92002. }
  92003. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92004. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92005. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92006. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92007. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92008. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92009. memcpy(page.body + min_framesize_offset, b, 6);
  92010. }
  92011. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92012. simple_ogg_page__clear(&page);
  92013. return; /* state already set */
  92014. }
  92015. simple_ogg_page__clear(&page);
  92016. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92017. unsigned i;
  92018. FLAC__byte *p;
  92019. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92020. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92021. simple_ogg_page__init(&page);
  92022. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92023. simple_ogg_page__clear(&page);
  92024. return; /* state already set */
  92025. }
  92026. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  92027. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92028. simple_ogg_page__clear(&page);
  92029. return;
  92030. }
  92031. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  92032. FLAC__uint64 xx;
  92033. unsigned x;
  92034. xx = encoder->private_->seek_table->points[i].sample_number;
  92035. b[7] = (FLAC__byte)xx; xx >>= 8;
  92036. b[6] = (FLAC__byte)xx; xx >>= 8;
  92037. b[5] = (FLAC__byte)xx; xx >>= 8;
  92038. b[4] = (FLAC__byte)xx; xx >>= 8;
  92039. b[3] = (FLAC__byte)xx; xx >>= 8;
  92040. b[2] = (FLAC__byte)xx; xx >>= 8;
  92041. b[1] = (FLAC__byte)xx; xx >>= 8;
  92042. b[0] = (FLAC__byte)xx; xx >>= 8;
  92043. xx = encoder->private_->seek_table->points[i].stream_offset;
  92044. b[15] = (FLAC__byte)xx; xx >>= 8;
  92045. b[14] = (FLAC__byte)xx; xx >>= 8;
  92046. b[13] = (FLAC__byte)xx; xx >>= 8;
  92047. b[12] = (FLAC__byte)xx; xx >>= 8;
  92048. b[11] = (FLAC__byte)xx; xx >>= 8;
  92049. b[10] = (FLAC__byte)xx; xx >>= 8;
  92050. b[9] = (FLAC__byte)xx; xx >>= 8;
  92051. b[8] = (FLAC__byte)xx; xx >>= 8;
  92052. x = encoder->private_->seek_table->points[i].frame_samples;
  92053. b[17] = (FLAC__byte)x; x >>= 8;
  92054. b[16] = (FLAC__byte)x; x >>= 8;
  92055. memcpy(p, b, 18);
  92056. }
  92057. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92058. simple_ogg_page__clear(&page);
  92059. return; /* state already set */
  92060. }
  92061. simple_ogg_page__clear(&page);
  92062. }
  92063. }
  92064. #endif
  92065. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  92066. {
  92067. FLAC__uint16 crc;
  92068. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  92069. 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)) {
  92070. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92071. return false;
  92072. }
  92073. if(!process_subframes_(encoder, is_fractional_block)) {
  92074. return false;
  92075. }
  92076. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  92077. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92078. return false;
  92079. }
  92080. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  92081. if(
  92082. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  92083. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  92084. ) {
  92085. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92086. return false;
  92087. }
  92088. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  92089. return false;
  92090. }
  92091. encoder->private_->current_sample_number = 0;
  92092. encoder->private_->current_frame_number++;
  92093. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  92094. return true;
  92095. }
  92096. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  92097. {
  92098. FLAC__FrameHeader frame_header;
  92099. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  92100. FLAC__bool do_independent, do_mid_side;
  92101. if(is_fractional_block) {
  92102. max_partition_order = 0;
  92103. }
  92104. else {
  92105. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  92106. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  92107. }
  92108. min_partition_order = min(min_partition_order, max_partition_order);
  92109. frame_header.blocksize = encoder->protected_->blocksize;
  92110. frame_header.sample_rate = encoder->protected_->sample_rate;
  92111. frame_header.channels = encoder->protected_->channels;
  92112. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  92113. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  92114. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  92115. frame_header.number.frame_number = encoder->private_->current_frame_number;
  92116. if(encoder->protected_->do_mid_side_stereo) {
  92117. if(encoder->protected_->loose_mid_side_stereo) {
  92118. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  92119. do_independent = true;
  92120. do_mid_side = true;
  92121. }
  92122. else {
  92123. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  92124. do_mid_side = !do_independent;
  92125. }
  92126. }
  92127. else {
  92128. do_independent = true;
  92129. do_mid_side = true;
  92130. }
  92131. }
  92132. else {
  92133. do_independent = true;
  92134. do_mid_side = false;
  92135. }
  92136. FLAC__ASSERT(do_independent || do_mid_side);
  92137. if(do_independent) {
  92138. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92139. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  92140. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  92141. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  92142. }
  92143. }
  92144. if(do_mid_side) {
  92145. FLAC__ASSERT(encoder->protected_->channels == 2);
  92146. for(channel = 0; channel < 2; channel++) {
  92147. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  92148. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  92149. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  92150. }
  92151. }
  92152. if(do_independent) {
  92153. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92154. if(!
  92155. process_subframe_(
  92156. encoder,
  92157. min_partition_order,
  92158. max_partition_order,
  92159. &frame_header,
  92160. encoder->private_->subframe_bps[channel],
  92161. encoder->private_->integer_signal[channel],
  92162. encoder->private_->subframe_workspace_ptr[channel],
  92163. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  92164. encoder->private_->residual_workspace[channel],
  92165. encoder->private_->best_subframe+channel,
  92166. encoder->private_->best_subframe_bits+channel
  92167. )
  92168. )
  92169. return false;
  92170. }
  92171. }
  92172. if(do_mid_side) {
  92173. FLAC__ASSERT(encoder->protected_->channels == 2);
  92174. for(channel = 0; channel < 2; channel++) {
  92175. if(!
  92176. process_subframe_(
  92177. encoder,
  92178. min_partition_order,
  92179. max_partition_order,
  92180. &frame_header,
  92181. encoder->private_->subframe_bps_mid_side[channel],
  92182. encoder->private_->integer_signal_mid_side[channel],
  92183. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  92184. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  92185. encoder->private_->residual_workspace_mid_side[channel],
  92186. encoder->private_->best_subframe_mid_side+channel,
  92187. encoder->private_->best_subframe_bits_mid_side+channel
  92188. )
  92189. )
  92190. return false;
  92191. }
  92192. }
  92193. if(do_mid_side) {
  92194. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  92195. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  92196. FLAC__ChannelAssignment channel_assignment;
  92197. FLAC__ASSERT(encoder->protected_->channels == 2);
  92198. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  92199. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  92200. }
  92201. else {
  92202. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  92203. unsigned min_bits;
  92204. int ca;
  92205. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  92206. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  92207. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  92208. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  92209. FLAC__ASSERT(do_independent && do_mid_side);
  92210. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  92211. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  92212. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  92213. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  92214. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  92215. min_bits = bits[channel_assignment];
  92216. for(ca = 1; ca <= 3; ca++) {
  92217. if(bits[ca] < min_bits) {
  92218. min_bits = bits[ca];
  92219. channel_assignment = (FLAC__ChannelAssignment)ca;
  92220. }
  92221. }
  92222. }
  92223. frame_header.channel_assignment = channel_assignment;
  92224. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92225. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92226. return false;
  92227. }
  92228. switch(channel_assignment) {
  92229. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92230. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92231. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92232. break;
  92233. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92234. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92235. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92236. break;
  92237. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92238. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92239. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92240. break;
  92241. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92242. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  92243. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92244. break;
  92245. default:
  92246. FLAC__ASSERT(0);
  92247. }
  92248. switch(channel_assignment) {
  92249. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92250. left_bps = encoder->private_->subframe_bps [0];
  92251. right_bps = encoder->private_->subframe_bps [1];
  92252. break;
  92253. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92254. left_bps = encoder->private_->subframe_bps [0];
  92255. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92256. break;
  92257. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92258. left_bps = encoder->private_->subframe_bps_mid_side[1];
  92259. right_bps = encoder->private_->subframe_bps [1];
  92260. break;
  92261. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92262. left_bps = encoder->private_->subframe_bps_mid_side[0];
  92263. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92264. break;
  92265. default:
  92266. FLAC__ASSERT(0);
  92267. }
  92268. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  92269. return false;
  92270. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  92271. return false;
  92272. }
  92273. else {
  92274. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92275. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92276. return false;
  92277. }
  92278. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92279. 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)) {
  92280. return false;
  92281. }
  92282. }
  92283. }
  92284. if(encoder->protected_->loose_mid_side_stereo) {
  92285. encoder->private_->loose_mid_side_stereo_frame_count++;
  92286. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  92287. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  92288. }
  92289. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  92290. return true;
  92291. }
  92292. FLAC__bool process_subframe_(
  92293. FLAC__StreamEncoder *encoder,
  92294. unsigned min_partition_order,
  92295. unsigned max_partition_order,
  92296. const FLAC__FrameHeader *frame_header,
  92297. unsigned subframe_bps,
  92298. const FLAC__int32 integer_signal[],
  92299. FLAC__Subframe *subframe[2],
  92300. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92301. FLAC__int32 *residual[2],
  92302. unsigned *best_subframe,
  92303. unsigned *best_bits
  92304. )
  92305. {
  92306. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92307. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92308. #else
  92309. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92310. #endif
  92311. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92312. FLAC__double lpc_residual_bits_per_sample;
  92313. 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 */
  92314. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92315. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92316. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92317. #endif
  92318. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92319. unsigned rice_parameter;
  92320. unsigned _candidate_bits, _best_bits;
  92321. unsigned _best_subframe;
  92322. 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;
  92323. FLAC__ASSERT(frame_header->blocksize > 0);
  92324. _best_subframe = 0;
  92325. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92326. _best_bits = UINT_MAX;
  92327. else
  92328. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92329. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92330. unsigned signal_is_constant = false;
  92331. 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);
  92332. if(
  92333. !encoder->private_->disable_constant_subframes &&
  92334. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92335. fixed_residual_bits_per_sample[1] == 0.0
  92336. #else
  92337. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92338. #endif
  92339. ) {
  92340. unsigned i;
  92341. signal_is_constant = true;
  92342. for(i = 1; i < frame_header->blocksize; i++) {
  92343. if(integer_signal[0] != integer_signal[i]) {
  92344. signal_is_constant = false;
  92345. break;
  92346. }
  92347. }
  92348. }
  92349. if(signal_is_constant) {
  92350. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92351. if(_candidate_bits < _best_bits) {
  92352. _best_subframe = !_best_subframe;
  92353. _best_bits = _candidate_bits;
  92354. }
  92355. }
  92356. else {
  92357. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92358. if(encoder->protected_->do_exhaustive_model_search) {
  92359. min_fixed_order = 0;
  92360. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92361. }
  92362. else {
  92363. min_fixed_order = max_fixed_order = guess_fixed_order;
  92364. }
  92365. if(max_fixed_order >= frame_header->blocksize)
  92366. max_fixed_order = frame_header->blocksize - 1;
  92367. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92368. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92369. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  92370. continue; /* don't even try */
  92371. 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 */
  92372. #else
  92373. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  92374. continue; /* don't even try */
  92375. 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 */
  92376. #endif
  92377. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92378. if(rice_parameter >= rice_parameter_limit) {
  92379. #ifdef DEBUG_VERBOSE
  92380. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  92381. #endif
  92382. rice_parameter = rice_parameter_limit - 1;
  92383. }
  92384. _candidate_bits =
  92385. evaluate_fixed_subframe_(
  92386. encoder,
  92387. integer_signal,
  92388. residual[!_best_subframe],
  92389. encoder->private_->abs_residual_partition_sums,
  92390. encoder->private_->raw_bits_per_partition,
  92391. frame_header->blocksize,
  92392. subframe_bps,
  92393. fixed_order,
  92394. rice_parameter,
  92395. rice_parameter_limit,
  92396. min_partition_order,
  92397. max_partition_order,
  92398. encoder->protected_->do_escape_coding,
  92399. encoder->protected_->rice_parameter_search_dist,
  92400. subframe[!_best_subframe],
  92401. partitioned_rice_contents[!_best_subframe]
  92402. );
  92403. if(_candidate_bits < _best_bits) {
  92404. _best_subframe = !_best_subframe;
  92405. _best_bits = _candidate_bits;
  92406. }
  92407. }
  92408. }
  92409. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92410. if(encoder->protected_->max_lpc_order > 0) {
  92411. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92412. max_lpc_order = frame_header->blocksize-1;
  92413. else
  92414. max_lpc_order = encoder->protected_->max_lpc_order;
  92415. if(max_lpc_order > 0) {
  92416. unsigned a;
  92417. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92418. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92419. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92420. if(autoc[0] != 0.0) {
  92421. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92422. if(encoder->protected_->do_exhaustive_model_search) {
  92423. min_lpc_order = 1;
  92424. }
  92425. else {
  92426. const unsigned guess_lpc_order =
  92427. FLAC__lpc_compute_best_order(
  92428. lpc_error,
  92429. max_lpc_order,
  92430. frame_header->blocksize,
  92431. subframe_bps + (
  92432. encoder->protected_->do_qlp_coeff_prec_search?
  92433. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92434. encoder->protected_->qlp_coeff_precision
  92435. )
  92436. );
  92437. min_lpc_order = max_lpc_order = guess_lpc_order;
  92438. }
  92439. if(max_lpc_order >= frame_header->blocksize)
  92440. max_lpc_order = frame_header->blocksize - 1;
  92441. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92442. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92443. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92444. continue; /* don't even try */
  92445. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  92446. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92447. if(rice_parameter >= rice_parameter_limit) {
  92448. #ifdef DEBUG_VERBOSE
  92449. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  92450. #endif
  92451. rice_parameter = rice_parameter_limit - 1;
  92452. }
  92453. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92454. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92455. if(subframe_bps <= 17) {
  92456. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92457. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92458. }
  92459. else
  92460. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92461. }
  92462. else {
  92463. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92464. }
  92465. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92466. _candidate_bits =
  92467. evaluate_lpc_subframe_(
  92468. encoder,
  92469. integer_signal,
  92470. residual[!_best_subframe],
  92471. encoder->private_->abs_residual_partition_sums,
  92472. encoder->private_->raw_bits_per_partition,
  92473. encoder->private_->lp_coeff[lpc_order-1],
  92474. frame_header->blocksize,
  92475. subframe_bps,
  92476. lpc_order,
  92477. qlp_coeff_precision,
  92478. rice_parameter,
  92479. rice_parameter_limit,
  92480. min_partition_order,
  92481. max_partition_order,
  92482. encoder->protected_->do_escape_coding,
  92483. encoder->protected_->rice_parameter_search_dist,
  92484. subframe[!_best_subframe],
  92485. partitioned_rice_contents[!_best_subframe]
  92486. );
  92487. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92488. if(_candidate_bits < _best_bits) {
  92489. _best_subframe = !_best_subframe;
  92490. _best_bits = _candidate_bits;
  92491. }
  92492. }
  92493. }
  92494. }
  92495. }
  92496. }
  92497. }
  92498. }
  92499. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92500. }
  92501. }
  92502. if(_best_bits == UINT_MAX) {
  92503. FLAC__ASSERT(_best_subframe == 0);
  92504. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92505. }
  92506. *best_subframe = _best_subframe;
  92507. *best_bits = _best_bits;
  92508. return true;
  92509. }
  92510. FLAC__bool add_subframe_(
  92511. FLAC__StreamEncoder *encoder,
  92512. unsigned blocksize,
  92513. unsigned subframe_bps,
  92514. const FLAC__Subframe *subframe,
  92515. FLAC__BitWriter *frame
  92516. )
  92517. {
  92518. switch(subframe->type) {
  92519. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92520. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92521. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92522. return false;
  92523. }
  92524. break;
  92525. case FLAC__SUBFRAME_TYPE_FIXED:
  92526. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92527. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92528. return false;
  92529. }
  92530. break;
  92531. case FLAC__SUBFRAME_TYPE_LPC:
  92532. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92533. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92534. return false;
  92535. }
  92536. break;
  92537. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92538. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92539. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92540. return false;
  92541. }
  92542. break;
  92543. default:
  92544. FLAC__ASSERT(0);
  92545. }
  92546. return true;
  92547. }
  92548. #define SPOTCHECK_ESTIMATE 0
  92549. #if SPOTCHECK_ESTIMATE
  92550. static void spotcheck_subframe_estimate_(
  92551. FLAC__StreamEncoder *encoder,
  92552. unsigned blocksize,
  92553. unsigned subframe_bps,
  92554. const FLAC__Subframe *subframe,
  92555. unsigned estimate
  92556. )
  92557. {
  92558. FLAC__bool ret;
  92559. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92560. if(frame == 0) {
  92561. fprintf(stderr, "EST: can't allocate frame\n");
  92562. return;
  92563. }
  92564. if(!FLAC__bitwriter_init(frame)) {
  92565. fprintf(stderr, "EST: can't init frame\n");
  92566. return;
  92567. }
  92568. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92569. FLAC__ASSERT(ret);
  92570. {
  92571. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92572. if(estimate != actual)
  92573. 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);
  92574. }
  92575. FLAC__bitwriter_delete(frame);
  92576. }
  92577. #endif
  92578. unsigned evaluate_constant_subframe_(
  92579. FLAC__StreamEncoder *encoder,
  92580. const FLAC__int32 signal,
  92581. unsigned blocksize,
  92582. unsigned subframe_bps,
  92583. FLAC__Subframe *subframe
  92584. )
  92585. {
  92586. unsigned estimate;
  92587. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92588. subframe->data.constant.value = signal;
  92589. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92590. #if SPOTCHECK_ESTIMATE
  92591. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92592. #else
  92593. (void)encoder, (void)blocksize;
  92594. #endif
  92595. return estimate;
  92596. }
  92597. unsigned evaluate_fixed_subframe_(
  92598. FLAC__StreamEncoder *encoder,
  92599. const FLAC__int32 signal[],
  92600. FLAC__int32 residual[],
  92601. FLAC__uint64 abs_residual_partition_sums[],
  92602. unsigned raw_bits_per_partition[],
  92603. unsigned blocksize,
  92604. unsigned subframe_bps,
  92605. unsigned order,
  92606. unsigned rice_parameter,
  92607. unsigned rice_parameter_limit,
  92608. unsigned min_partition_order,
  92609. unsigned max_partition_order,
  92610. FLAC__bool do_escape_coding,
  92611. unsigned rice_parameter_search_dist,
  92612. FLAC__Subframe *subframe,
  92613. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92614. )
  92615. {
  92616. unsigned i, residual_bits, estimate;
  92617. const unsigned residual_samples = blocksize - order;
  92618. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92619. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92620. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92621. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92622. subframe->data.fixed.residual = residual;
  92623. residual_bits =
  92624. find_best_partition_order_(
  92625. encoder->private_,
  92626. residual,
  92627. abs_residual_partition_sums,
  92628. raw_bits_per_partition,
  92629. residual_samples,
  92630. order,
  92631. rice_parameter,
  92632. rice_parameter_limit,
  92633. min_partition_order,
  92634. max_partition_order,
  92635. subframe_bps,
  92636. do_escape_coding,
  92637. rice_parameter_search_dist,
  92638. &subframe->data.fixed.entropy_coding_method
  92639. );
  92640. subframe->data.fixed.order = order;
  92641. for(i = 0; i < order; i++)
  92642. subframe->data.fixed.warmup[i] = signal[i];
  92643. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92644. #if SPOTCHECK_ESTIMATE
  92645. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92646. #endif
  92647. return estimate;
  92648. }
  92649. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92650. unsigned evaluate_lpc_subframe_(
  92651. FLAC__StreamEncoder *encoder,
  92652. const FLAC__int32 signal[],
  92653. FLAC__int32 residual[],
  92654. FLAC__uint64 abs_residual_partition_sums[],
  92655. unsigned raw_bits_per_partition[],
  92656. const FLAC__real lp_coeff[],
  92657. unsigned blocksize,
  92658. unsigned subframe_bps,
  92659. unsigned order,
  92660. unsigned qlp_coeff_precision,
  92661. unsigned rice_parameter,
  92662. unsigned rice_parameter_limit,
  92663. unsigned min_partition_order,
  92664. unsigned max_partition_order,
  92665. FLAC__bool do_escape_coding,
  92666. unsigned rice_parameter_search_dist,
  92667. FLAC__Subframe *subframe,
  92668. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92669. )
  92670. {
  92671. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  92672. unsigned i, residual_bits, estimate;
  92673. int quantization, ret;
  92674. const unsigned residual_samples = blocksize - order;
  92675. if(subframe_bps <= 16) {
  92676. FLAC__ASSERT(order > 0);
  92677. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  92678. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  92679. }
  92680. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  92681. if(ret != 0)
  92682. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  92683. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  92684. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  92685. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92686. else
  92687. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92688. else
  92689. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92690. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  92691. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92692. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92693. subframe->data.lpc.residual = residual;
  92694. residual_bits =
  92695. find_best_partition_order_(
  92696. encoder->private_,
  92697. residual,
  92698. abs_residual_partition_sums,
  92699. raw_bits_per_partition,
  92700. residual_samples,
  92701. order,
  92702. rice_parameter,
  92703. rice_parameter_limit,
  92704. min_partition_order,
  92705. max_partition_order,
  92706. subframe_bps,
  92707. do_escape_coding,
  92708. rice_parameter_search_dist,
  92709. &subframe->data.lpc.entropy_coding_method
  92710. );
  92711. subframe->data.lpc.order = order;
  92712. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  92713. subframe->data.lpc.quantization_level = quantization;
  92714. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  92715. for(i = 0; i < order; i++)
  92716. subframe->data.lpc.warmup[i] = signal[i];
  92717. 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;
  92718. #if SPOTCHECK_ESTIMATE
  92719. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92720. #endif
  92721. return estimate;
  92722. }
  92723. #endif
  92724. unsigned evaluate_verbatim_subframe_(
  92725. FLAC__StreamEncoder *encoder,
  92726. const FLAC__int32 signal[],
  92727. unsigned blocksize,
  92728. unsigned subframe_bps,
  92729. FLAC__Subframe *subframe
  92730. )
  92731. {
  92732. unsigned estimate;
  92733. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  92734. subframe->data.verbatim.data = signal;
  92735. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  92736. #if SPOTCHECK_ESTIMATE
  92737. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92738. #else
  92739. (void)encoder;
  92740. #endif
  92741. return estimate;
  92742. }
  92743. unsigned find_best_partition_order_(
  92744. FLAC__StreamEncoderPrivate *private_,
  92745. const FLAC__int32 residual[],
  92746. FLAC__uint64 abs_residual_partition_sums[],
  92747. unsigned raw_bits_per_partition[],
  92748. unsigned residual_samples,
  92749. unsigned predictor_order,
  92750. unsigned rice_parameter,
  92751. unsigned rice_parameter_limit,
  92752. unsigned min_partition_order,
  92753. unsigned max_partition_order,
  92754. unsigned bps,
  92755. FLAC__bool do_escape_coding,
  92756. unsigned rice_parameter_search_dist,
  92757. FLAC__EntropyCodingMethod *best_ecm
  92758. )
  92759. {
  92760. unsigned residual_bits, best_residual_bits = 0;
  92761. unsigned best_parameters_index = 0;
  92762. unsigned best_partition_order = 0;
  92763. const unsigned blocksize = residual_samples + predictor_order;
  92764. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  92765. min_partition_order = min(min_partition_order, max_partition_order);
  92766. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  92767. if(do_escape_coding)
  92768. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  92769. {
  92770. int partition_order;
  92771. unsigned sum;
  92772. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  92773. if(!
  92774. set_partitioned_rice_(
  92775. #ifdef EXACT_RICE_BITS_CALCULATION
  92776. residual,
  92777. #endif
  92778. abs_residual_partition_sums+sum,
  92779. raw_bits_per_partition+sum,
  92780. residual_samples,
  92781. predictor_order,
  92782. rice_parameter,
  92783. rice_parameter_limit,
  92784. rice_parameter_search_dist,
  92785. (unsigned)partition_order,
  92786. do_escape_coding,
  92787. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  92788. &residual_bits
  92789. )
  92790. )
  92791. {
  92792. FLAC__ASSERT(best_residual_bits != 0);
  92793. break;
  92794. }
  92795. sum += 1u << partition_order;
  92796. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  92797. best_residual_bits = residual_bits;
  92798. best_parameters_index = !best_parameters_index;
  92799. best_partition_order = partition_order;
  92800. }
  92801. }
  92802. }
  92803. best_ecm->data.partitioned_rice.order = best_partition_order;
  92804. {
  92805. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  92806. unsigned partition;
  92807. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  92808. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  92809. if(do_escape_coding)
  92810. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  92811. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  92812. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  92813. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  92814. break;
  92815. }
  92816. }
  92817. }
  92818. return best_residual_bits;
  92819. }
  92820. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92821. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  92822. const FLAC__int32 residual[],
  92823. FLAC__uint64 abs_residual_partition_sums[],
  92824. unsigned blocksize,
  92825. unsigned predictor_order,
  92826. unsigned min_partition_order,
  92827. unsigned max_partition_order
  92828. );
  92829. #endif
  92830. void precompute_partition_info_sums_(
  92831. const FLAC__int32 residual[],
  92832. FLAC__uint64 abs_residual_partition_sums[],
  92833. unsigned residual_samples,
  92834. unsigned predictor_order,
  92835. unsigned min_partition_order,
  92836. unsigned max_partition_order,
  92837. unsigned bps
  92838. )
  92839. {
  92840. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  92841. unsigned partitions = 1u << max_partition_order;
  92842. FLAC__ASSERT(default_partition_samples > predictor_order);
  92843. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92844. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92845. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  92846. return;
  92847. }
  92848. #endif
  92849. {
  92850. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  92851. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92852. FLAC__uint32 abs_residual_partition_sum;
  92853. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92854. end += default_partition_samples;
  92855. abs_residual_partition_sum = 0;
  92856. for( ; residual_sample < end; residual_sample++)
  92857. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92858. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92859. }
  92860. }
  92861. else { /* have to pessimistically use 64 bits for accumulator */
  92862. FLAC__uint64 abs_residual_partition_sum;
  92863. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92864. end += default_partition_samples;
  92865. abs_residual_partition_sum = 0;
  92866. for( ; residual_sample < end; residual_sample++)
  92867. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92868. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92869. }
  92870. }
  92871. }
  92872. {
  92873. unsigned from_partition = 0, to_partition = partitions;
  92874. int partition_order;
  92875. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  92876. unsigned i;
  92877. partitions >>= 1;
  92878. for(i = 0; i < partitions; i++) {
  92879. abs_residual_partition_sums[to_partition++] =
  92880. abs_residual_partition_sums[from_partition ] +
  92881. abs_residual_partition_sums[from_partition+1];
  92882. from_partition += 2;
  92883. }
  92884. }
  92885. }
  92886. }
  92887. void precompute_partition_info_escapes_(
  92888. const FLAC__int32 residual[],
  92889. unsigned raw_bits_per_partition[],
  92890. unsigned residual_samples,
  92891. unsigned predictor_order,
  92892. unsigned min_partition_order,
  92893. unsigned max_partition_order
  92894. )
  92895. {
  92896. int partition_order;
  92897. unsigned from_partition, to_partition = 0;
  92898. const unsigned blocksize = residual_samples + predictor_order;
  92899. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  92900. FLAC__int32 r;
  92901. FLAC__uint32 rmax;
  92902. unsigned partition, partition_sample, partition_samples, residual_sample;
  92903. const unsigned partitions = 1u << partition_order;
  92904. const unsigned default_partition_samples = blocksize >> partition_order;
  92905. FLAC__ASSERT(default_partition_samples > predictor_order);
  92906. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92907. partition_samples = default_partition_samples;
  92908. if(partition == 0)
  92909. partition_samples -= predictor_order;
  92910. rmax = 0;
  92911. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  92912. r = residual[residual_sample++];
  92913. if(r < 0)
  92914. rmax |= ~r;
  92915. else
  92916. rmax |= r;
  92917. }
  92918. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  92919. }
  92920. to_partition = partitions;
  92921. break; /*@@@ yuck, should remove the 'for' loop instead */
  92922. }
  92923. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  92924. unsigned m;
  92925. unsigned i;
  92926. const unsigned partitions = 1u << partition_order;
  92927. for(i = 0; i < partitions; i++) {
  92928. m = raw_bits_per_partition[from_partition];
  92929. from_partition++;
  92930. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  92931. from_partition++;
  92932. to_partition++;
  92933. }
  92934. }
  92935. }
  92936. #ifdef EXACT_RICE_BITS_CALCULATION
  92937. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92938. const unsigned rice_parameter,
  92939. const unsigned partition_samples,
  92940. const FLAC__int32 *residual
  92941. )
  92942. {
  92943. unsigned i, partition_bits =
  92944. 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 */
  92945. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  92946. ;
  92947. for(i = 0; i < partition_samples; i++)
  92948. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  92949. return partition_bits;
  92950. }
  92951. #else
  92952. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92953. const unsigned rice_parameter,
  92954. const unsigned partition_samples,
  92955. const FLAC__uint64 abs_residual_partition_sum
  92956. )
  92957. {
  92958. return
  92959. 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 */
  92960. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  92961. (
  92962. rice_parameter?
  92963. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  92964. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  92965. )
  92966. - (partition_samples >> 1)
  92967. ;
  92968. }
  92969. #endif
  92970. FLAC__bool set_partitioned_rice_(
  92971. #ifdef EXACT_RICE_BITS_CALCULATION
  92972. const FLAC__int32 residual[],
  92973. #endif
  92974. const FLAC__uint64 abs_residual_partition_sums[],
  92975. const unsigned raw_bits_per_partition[],
  92976. const unsigned residual_samples,
  92977. const unsigned predictor_order,
  92978. const unsigned suggested_rice_parameter,
  92979. const unsigned rice_parameter_limit,
  92980. const unsigned rice_parameter_search_dist,
  92981. const unsigned partition_order,
  92982. const FLAC__bool search_for_escapes,
  92983. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  92984. unsigned *bits
  92985. )
  92986. {
  92987. unsigned rice_parameter, partition_bits;
  92988. unsigned best_partition_bits, best_rice_parameter = 0;
  92989. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  92990. unsigned *parameters, *raw_bits;
  92991. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92992. unsigned min_rice_parameter, max_rice_parameter;
  92993. #else
  92994. (void)rice_parameter_search_dist;
  92995. #endif
  92996. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92997. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92998. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  92999. parameters = partitioned_rice_contents->parameters;
  93000. raw_bits = partitioned_rice_contents->raw_bits;
  93001. if(partition_order == 0) {
  93002. best_partition_bits = (unsigned)(-1);
  93003. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93004. if(rice_parameter_search_dist) {
  93005. if(suggested_rice_parameter < rice_parameter_search_dist)
  93006. min_rice_parameter = 0;
  93007. else
  93008. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  93009. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  93010. if(max_rice_parameter >= rice_parameter_limit) {
  93011. #ifdef DEBUG_VERBOSE
  93012. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  93013. #endif
  93014. max_rice_parameter = rice_parameter_limit - 1;
  93015. }
  93016. }
  93017. else
  93018. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  93019. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93020. #else
  93021. rice_parameter = suggested_rice_parameter;
  93022. #endif
  93023. #ifdef EXACT_RICE_BITS_CALCULATION
  93024. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  93025. #else
  93026. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  93027. #endif
  93028. if(partition_bits < best_partition_bits) {
  93029. best_rice_parameter = rice_parameter;
  93030. best_partition_bits = partition_bits;
  93031. }
  93032. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93033. }
  93034. #endif
  93035. if(search_for_escapes) {
  93036. 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;
  93037. if(partition_bits <= best_partition_bits) {
  93038. raw_bits[0] = raw_bits_per_partition[0];
  93039. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93040. best_partition_bits = partition_bits;
  93041. }
  93042. else
  93043. raw_bits[0] = 0;
  93044. }
  93045. parameters[0] = best_rice_parameter;
  93046. bits_ += best_partition_bits;
  93047. }
  93048. else {
  93049. unsigned partition, residual_sample;
  93050. unsigned partition_samples;
  93051. FLAC__uint64 mean, k;
  93052. const unsigned partitions = 1u << partition_order;
  93053. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93054. partition_samples = (residual_samples+predictor_order) >> partition_order;
  93055. if(partition == 0) {
  93056. if(partition_samples <= predictor_order)
  93057. return false;
  93058. else
  93059. partition_samples -= predictor_order;
  93060. }
  93061. mean = abs_residual_partition_sums[partition];
  93062. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  93063. ;
  93064. if(rice_parameter >= rice_parameter_limit) {
  93065. #ifdef DEBUG_VERBOSE
  93066. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  93067. #endif
  93068. rice_parameter = rice_parameter_limit - 1;
  93069. }
  93070. best_partition_bits = (unsigned)(-1);
  93071. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93072. if(rice_parameter_search_dist) {
  93073. if(rice_parameter < rice_parameter_search_dist)
  93074. min_rice_parameter = 0;
  93075. else
  93076. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  93077. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  93078. if(max_rice_parameter >= rice_parameter_limit) {
  93079. #ifdef DEBUG_VERBOSE
  93080. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  93081. #endif
  93082. max_rice_parameter = rice_parameter_limit - 1;
  93083. }
  93084. }
  93085. else
  93086. min_rice_parameter = max_rice_parameter = rice_parameter;
  93087. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93088. #endif
  93089. #ifdef EXACT_RICE_BITS_CALCULATION
  93090. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  93091. #else
  93092. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  93093. #endif
  93094. if(partition_bits < best_partition_bits) {
  93095. best_rice_parameter = rice_parameter;
  93096. best_partition_bits = partition_bits;
  93097. }
  93098. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93099. }
  93100. #endif
  93101. if(search_for_escapes) {
  93102. 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;
  93103. if(partition_bits <= best_partition_bits) {
  93104. raw_bits[partition] = raw_bits_per_partition[partition];
  93105. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93106. best_partition_bits = partition_bits;
  93107. }
  93108. else
  93109. raw_bits[partition] = 0;
  93110. }
  93111. parameters[partition] = best_rice_parameter;
  93112. bits_ += best_partition_bits;
  93113. residual_sample += partition_samples;
  93114. }
  93115. }
  93116. *bits = bits_;
  93117. return true;
  93118. }
  93119. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  93120. {
  93121. unsigned i, shift;
  93122. FLAC__int32 x = 0;
  93123. for(i = 0; i < samples && !(x&1); i++)
  93124. x |= signal[i];
  93125. if(x == 0) {
  93126. shift = 0;
  93127. }
  93128. else {
  93129. for(shift = 0; !(x&1); shift++)
  93130. x >>= 1;
  93131. }
  93132. if(shift > 0) {
  93133. for(i = 0; i < samples; i++)
  93134. signal[i] >>= shift;
  93135. }
  93136. return shift;
  93137. }
  93138. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93139. {
  93140. unsigned channel;
  93141. for(channel = 0; channel < channels; channel++)
  93142. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  93143. fifo->tail += wide_samples;
  93144. FLAC__ASSERT(fifo->tail <= fifo->size);
  93145. }
  93146. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93147. {
  93148. unsigned channel;
  93149. unsigned sample, wide_sample;
  93150. unsigned tail = fifo->tail;
  93151. sample = input_offset * channels;
  93152. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  93153. for(channel = 0; channel < channels; channel++)
  93154. fifo->data[channel][tail] = input[sample++];
  93155. tail++;
  93156. }
  93157. fifo->tail = tail;
  93158. FLAC__ASSERT(fifo->tail <= fifo->size);
  93159. }
  93160. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93161. {
  93162. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93163. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  93164. (void)decoder;
  93165. if(encoder->private_->verify.needs_magic_hack) {
  93166. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  93167. *bytes = FLAC__STREAM_SYNC_LENGTH;
  93168. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  93169. encoder->private_->verify.needs_magic_hack = false;
  93170. }
  93171. else {
  93172. if(encoded_bytes == 0) {
  93173. FLAC__ASSERT(0);
  93174. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  93175. }
  93176. else if(encoded_bytes < *bytes)
  93177. *bytes = encoded_bytes;
  93178. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  93179. encoder->private_->verify.output.data += *bytes;
  93180. encoder->private_->verify.output.bytes -= *bytes;
  93181. }
  93182. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93183. }
  93184. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  93185. {
  93186. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  93187. unsigned channel;
  93188. const unsigned channels = frame->header.channels;
  93189. const unsigned blocksize = frame->header.blocksize;
  93190. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  93191. (void)decoder;
  93192. for(channel = 0; channel < channels; channel++) {
  93193. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  93194. unsigned i, sample = 0;
  93195. FLAC__int32 expect = 0, got = 0;
  93196. for(i = 0; i < blocksize; i++) {
  93197. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  93198. sample = i;
  93199. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  93200. got = (FLAC__int32)buffer[channel][i];
  93201. break;
  93202. }
  93203. }
  93204. FLAC__ASSERT(i < blocksize);
  93205. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  93206. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  93207. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  93208. encoder->private_->verify.error_stats.channel = channel;
  93209. encoder->private_->verify.error_stats.sample = sample;
  93210. encoder->private_->verify.error_stats.expected = expect;
  93211. encoder->private_->verify.error_stats.got = got;
  93212. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  93213. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  93214. }
  93215. }
  93216. encoder->private_->verify.input_fifo.tail -= blocksize;
  93217. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  93218. for(channel = 0; channel < channels; channel++)
  93219. 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]));
  93220. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93221. }
  93222. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  93223. {
  93224. (void)decoder, (void)metadata, (void)client_data;
  93225. }
  93226. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  93227. {
  93228. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93229. (void)decoder, (void)status;
  93230. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  93231. }
  93232. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93233. {
  93234. (void)client_data;
  93235. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  93236. if (*bytes == 0) {
  93237. if (feof(encoder->private_->file))
  93238. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  93239. else if (ferror(encoder->private_->file))
  93240. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  93241. }
  93242. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  93243. }
  93244. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  93245. {
  93246. (void)client_data;
  93247. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  93248. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  93249. else
  93250. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  93251. }
  93252. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  93253. {
  93254. off_t offset;
  93255. (void)client_data;
  93256. offset = ftello(encoder->private_->file);
  93257. if(offset < 0) {
  93258. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  93259. }
  93260. else {
  93261. *absolute_byte_offset = (FLAC__uint64)offset;
  93262. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93263. }
  93264. }
  93265. #ifdef FLAC__VALGRIND_TESTING
  93266. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  93267. {
  93268. size_t ret = fwrite(ptr, size, nmemb, stream);
  93269. if(!ferror(stream))
  93270. fflush(stream);
  93271. return ret;
  93272. }
  93273. #else
  93274. #define local__fwrite fwrite
  93275. #endif
  93276. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  93277. {
  93278. (void)client_data, (void)current_frame;
  93279. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  93280. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  93281. #if FLAC__HAS_OGG
  93282. encoder->private_->is_ogg? true :
  93283. #endif
  93284. samples > 0
  93285. );
  93286. if(call_it) {
  93287. 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);
  93288. }
  93289. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  93290. }
  93291. else
  93292. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93293. }
  93294. FILE *get_binary_stdout_(void)
  93295. {
  93296. #if defined _MSC_VER || defined __MINGW32__
  93297. _setmode(_fileno(stdout), _O_BINARY);
  93298. #elif defined __CYGWIN__
  93299. setmode(_fileno(stdout), _O_BINARY);
  93300. #elif defined __EMX__
  93301. setmode(fileno(stdout), O_BINARY);
  93302. #endif
  93303. return stdout;
  93304. }
  93305. #endif
  93306. /*** End of inlined file: stream_encoder.c ***/
  93307. /*** Start of inlined file: stream_encoder_framing.c ***/
  93308. /*** Start of inlined file: juce_FlacHeader.h ***/
  93309. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93310. // tasks..
  93311. #define VERSION "1.2.1"
  93312. #define FLAC__NO_DLL 1
  93313. #if JUCE_MSVC
  93314. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93315. #endif
  93316. #if JUCE_MAC
  93317. #define FLAC__SYS_DARWIN 1
  93318. #endif
  93319. /*** End of inlined file: juce_FlacHeader.h ***/
  93320. #if JUCE_USE_FLAC
  93321. #if HAVE_CONFIG_H
  93322. # include <config.h>
  93323. #endif
  93324. #include <stdio.h>
  93325. #include <string.h> /* for strlen() */
  93326. #ifdef max
  93327. #undef max
  93328. #endif
  93329. #define max(x,y) ((x)>(y)?(x):(y))
  93330. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93331. 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);
  93332. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93333. {
  93334. unsigned i, j;
  93335. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93336. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93337. return false;
  93338. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93339. return false;
  93340. i = metadata->length;
  93341. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93342. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93343. i -= metadata->data.vorbis_comment.vendor_string.length;
  93344. i += vendor_string_length;
  93345. }
  93346. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93347. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93348. return false;
  93349. switch(metadata->type) {
  93350. case FLAC__METADATA_TYPE_STREAMINFO:
  93351. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93352. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93353. return false;
  93354. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93355. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93356. return false;
  93357. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93358. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93359. return false;
  93360. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93361. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93362. return false;
  93363. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93364. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93365. return false;
  93366. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93367. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93368. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93369. return false;
  93370. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  93371. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93372. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  93373. return false;
  93374. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  93375. return false;
  93376. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  93377. return false;
  93378. break;
  93379. case FLAC__METADATA_TYPE_PADDING:
  93380. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  93381. return false;
  93382. break;
  93383. case FLAC__METADATA_TYPE_APPLICATION:
  93384. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  93385. return false;
  93386. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  93387. return false;
  93388. break;
  93389. case FLAC__METADATA_TYPE_SEEKTABLE:
  93390. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  93391. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  93392. return false;
  93393. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  93394. return false;
  93395. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  93396. return false;
  93397. }
  93398. break;
  93399. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  93400. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  93401. return false;
  93402. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  93403. return false;
  93404. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  93405. return false;
  93406. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93407. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93408. return false;
  93409. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93410. return false;
  93411. }
  93412. break;
  93413. case FLAC__METADATA_TYPE_CUESHEET:
  93414. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93415. 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))
  93416. return false;
  93417. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93418. return false;
  93419. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93420. return false;
  93421. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93422. return false;
  93423. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93424. return false;
  93425. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93426. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93427. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93428. return false;
  93429. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93430. return false;
  93431. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93432. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93433. return false;
  93434. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93435. return false;
  93436. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93437. return false;
  93438. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93439. return false;
  93440. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93441. return false;
  93442. for(j = 0; j < track->num_indices; j++) {
  93443. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93444. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93445. return false;
  93446. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93447. return false;
  93448. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93449. return false;
  93450. }
  93451. }
  93452. break;
  93453. case FLAC__METADATA_TYPE_PICTURE:
  93454. {
  93455. size_t len;
  93456. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93457. return false;
  93458. len = strlen(metadata->data.picture.mime_type);
  93459. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93460. return false;
  93461. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93462. return false;
  93463. len = strlen((const char *)metadata->data.picture.description);
  93464. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93465. return false;
  93466. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93467. return false;
  93468. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93469. return false;
  93470. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93471. return false;
  93472. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93473. return false;
  93474. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93475. return false;
  93476. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93477. return false;
  93478. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93479. return false;
  93480. }
  93481. break;
  93482. default:
  93483. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93484. return false;
  93485. break;
  93486. }
  93487. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93488. return true;
  93489. }
  93490. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93491. {
  93492. unsigned u, blocksize_hint, sample_rate_hint;
  93493. FLAC__byte crc;
  93494. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93495. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93496. return false;
  93497. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93498. return false;
  93499. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93500. return false;
  93501. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93502. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93503. blocksize_hint = 0;
  93504. switch(header->blocksize) {
  93505. case 192: u = 1; break;
  93506. case 576: u = 2; break;
  93507. case 1152: u = 3; break;
  93508. case 2304: u = 4; break;
  93509. case 4608: u = 5; break;
  93510. case 256: u = 8; break;
  93511. case 512: u = 9; break;
  93512. case 1024: u = 10; break;
  93513. case 2048: u = 11; break;
  93514. case 4096: u = 12; break;
  93515. case 8192: u = 13; break;
  93516. case 16384: u = 14; break;
  93517. case 32768: u = 15; break;
  93518. default:
  93519. if(header->blocksize <= 0x100)
  93520. blocksize_hint = u = 6;
  93521. else
  93522. blocksize_hint = u = 7;
  93523. break;
  93524. }
  93525. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93526. return false;
  93527. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93528. sample_rate_hint = 0;
  93529. switch(header->sample_rate) {
  93530. case 88200: u = 1; break;
  93531. case 176400: u = 2; break;
  93532. case 192000: u = 3; break;
  93533. case 8000: u = 4; break;
  93534. case 16000: u = 5; break;
  93535. case 22050: u = 6; break;
  93536. case 24000: u = 7; break;
  93537. case 32000: u = 8; break;
  93538. case 44100: u = 9; break;
  93539. case 48000: u = 10; break;
  93540. case 96000: u = 11; break;
  93541. default:
  93542. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93543. sample_rate_hint = u = 12;
  93544. else if(header->sample_rate % 10 == 0)
  93545. sample_rate_hint = u = 14;
  93546. else if(header->sample_rate <= 0xffff)
  93547. sample_rate_hint = u = 13;
  93548. else
  93549. u = 0;
  93550. break;
  93551. }
  93552. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93553. return false;
  93554. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93555. switch(header->channel_assignment) {
  93556. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93557. u = header->channels - 1;
  93558. break;
  93559. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93560. FLAC__ASSERT(header->channels == 2);
  93561. u = 8;
  93562. break;
  93563. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93564. FLAC__ASSERT(header->channels == 2);
  93565. u = 9;
  93566. break;
  93567. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93568. FLAC__ASSERT(header->channels == 2);
  93569. u = 10;
  93570. break;
  93571. default:
  93572. FLAC__ASSERT(0);
  93573. }
  93574. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93575. return false;
  93576. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93577. switch(header->bits_per_sample) {
  93578. case 8 : u = 1; break;
  93579. case 12: u = 2; break;
  93580. case 16: u = 4; break;
  93581. case 20: u = 5; break;
  93582. case 24: u = 6; break;
  93583. default: u = 0; break;
  93584. }
  93585. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93586. return false;
  93587. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93588. return false;
  93589. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93590. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93591. return false;
  93592. }
  93593. else {
  93594. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93595. return false;
  93596. }
  93597. if(blocksize_hint)
  93598. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93599. return false;
  93600. switch(sample_rate_hint) {
  93601. case 12:
  93602. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93603. return false;
  93604. break;
  93605. case 13:
  93606. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93607. return false;
  93608. break;
  93609. case 14:
  93610. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93611. return false;
  93612. break;
  93613. }
  93614. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93615. return false;
  93616. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93617. return false;
  93618. return true;
  93619. }
  93620. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93621. {
  93622. FLAC__bool ok;
  93623. ok =
  93624. 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) &&
  93625. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93626. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93627. ;
  93628. return ok;
  93629. }
  93630. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93631. {
  93632. unsigned i;
  93633. 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))
  93634. return false;
  93635. if(wasted_bits)
  93636. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93637. return false;
  93638. for(i = 0; i < subframe->order; i++)
  93639. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93640. return false;
  93641. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93642. return false;
  93643. switch(subframe->entropy_coding_method.type) {
  93644. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93645. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93646. if(!add_residual_partitioned_rice_(
  93647. bw,
  93648. subframe->residual,
  93649. residual_samples,
  93650. subframe->order,
  93651. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93652. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93653. subframe->entropy_coding_method.data.partitioned_rice.order,
  93654. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93655. ))
  93656. return false;
  93657. break;
  93658. default:
  93659. FLAC__ASSERT(0);
  93660. }
  93661. return true;
  93662. }
  93663. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93664. {
  93665. unsigned i;
  93666. 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))
  93667. return false;
  93668. if(wasted_bits)
  93669. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93670. return false;
  93671. for(i = 0; i < subframe->order; i++)
  93672. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93673. return false;
  93674. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  93675. return false;
  93676. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  93677. return false;
  93678. for(i = 0; i < subframe->order; i++)
  93679. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  93680. return false;
  93681. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93682. return false;
  93683. switch(subframe->entropy_coding_method.type) {
  93684. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93685. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93686. if(!add_residual_partitioned_rice_(
  93687. bw,
  93688. subframe->residual,
  93689. residual_samples,
  93690. subframe->order,
  93691. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93692. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93693. subframe->entropy_coding_method.data.partitioned_rice.order,
  93694. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93695. ))
  93696. return false;
  93697. break;
  93698. default:
  93699. FLAC__ASSERT(0);
  93700. }
  93701. return true;
  93702. }
  93703. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93704. {
  93705. unsigned i;
  93706. const FLAC__int32 *signal = subframe->data;
  93707. 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))
  93708. return false;
  93709. if(wasted_bits)
  93710. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93711. return false;
  93712. for(i = 0; i < samples; i++)
  93713. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  93714. return false;
  93715. return true;
  93716. }
  93717. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  93718. {
  93719. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  93720. return false;
  93721. switch(method->type) {
  93722. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93723. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93724. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  93725. return false;
  93726. break;
  93727. default:
  93728. FLAC__ASSERT(0);
  93729. }
  93730. return true;
  93731. }
  93732. 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)
  93733. {
  93734. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  93735. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  93736. if(partition_order == 0) {
  93737. unsigned i;
  93738. if(raw_bits[0] == 0) {
  93739. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  93740. return false;
  93741. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  93742. return false;
  93743. }
  93744. else {
  93745. FLAC__ASSERT(rice_parameters[0] == 0);
  93746. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93747. return false;
  93748. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93749. return false;
  93750. for(i = 0; i < residual_samples; i++) {
  93751. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  93752. return false;
  93753. }
  93754. }
  93755. return true;
  93756. }
  93757. else {
  93758. unsigned i, j, k = 0, k_last = 0;
  93759. unsigned partition_samples;
  93760. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  93761. for(i = 0; i < (1u<<partition_order); i++) {
  93762. partition_samples = default_partition_samples;
  93763. if(i == 0)
  93764. partition_samples -= predictor_order;
  93765. k += partition_samples;
  93766. if(raw_bits[i] == 0) {
  93767. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  93768. return false;
  93769. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  93770. return false;
  93771. }
  93772. else {
  93773. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93774. return false;
  93775. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93776. return false;
  93777. for(j = k_last; j < k; j++) {
  93778. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  93779. return false;
  93780. }
  93781. }
  93782. k_last = k;
  93783. }
  93784. return true;
  93785. }
  93786. }
  93787. #endif
  93788. /*** End of inlined file: stream_encoder_framing.c ***/
  93789. /*** Start of inlined file: window_flac.c ***/
  93790. /*** Start of inlined file: juce_FlacHeader.h ***/
  93791. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93792. // tasks..
  93793. #define VERSION "1.2.1"
  93794. #define FLAC__NO_DLL 1
  93795. #if JUCE_MSVC
  93796. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93797. #endif
  93798. #if JUCE_MAC
  93799. #define FLAC__SYS_DARWIN 1
  93800. #endif
  93801. /*** End of inlined file: juce_FlacHeader.h ***/
  93802. #if JUCE_USE_FLAC
  93803. #if HAVE_CONFIG_H
  93804. # include <config.h>
  93805. #endif
  93806. #include <math.h>
  93807. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  93808. #ifndef M_PI
  93809. #define M_PI 3.14159265358979323846
  93810. #endif
  93811. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  93812. {
  93813. const FLAC__int32 N = L - 1;
  93814. FLAC__int32 n;
  93815. if (L & 1) {
  93816. for (n = 0; n <= N/2; n++)
  93817. window[n] = 2.0f * n / (float)N;
  93818. for (; n <= N; n++)
  93819. window[n] = 2.0f - 2.0f * n / (float)N;
  93820. }
  93821. else {
  93822. for (n = 0; n <= L/2-1; n++)
  93823. window[n] = 2.0f * n / (float)N;
  93824. for (; n <= N; n++)
  93825. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  93826. }
  93827. }
  93828. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  93829. {
  93830. const FLAC__int32 N = L - 1;
  93831. FLAC__int32 n;
  93832. for (n = 0; n < L; n++)
  93833. 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)));
  93834. }
  93835. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  93836. {
  93837. const FLAC__int32 N = L - 1;
  93838. FLAC__int32 n;
  93839. for (n = 0; n < L; n++)
  93840. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  93841. }
  93842. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  93843. {
  93844. const FLAC__int32 N = L - 1;
  93845. FLAC__int32 n;
  93846. for (n = 0; n <= N; n++)
  93847. 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));
  93848. }
  93849. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  93850. {
  93851. const FLAC__int32 N = L - 1;
  93852. const double N2 = (double)N / 2.;
  93853. FLAC__int32 n;
  93854. for (n = 0; n <= N; n++) {
  93855. double k = ((double)n - N2) / N2;
  93856. k = 1.0f - k * k;
  93857. window[n] = (FLAC__real)(k * k);
  93858. }
  93859. }
  93860. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  93861. {
  93862. const FLAC__int32 N = L - 1;
  93863. FLAC__int32 n;
  93864. for (n = 0; n < L; n++)
  93865. 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));
  93866. }
  93867. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  93868. {
  93869. const FLAC__int32 N = L - 1;
  93870. const double N2 = (double)N / 2.;
  93871. FLAC__int32 n;
  93872. for (n = 0; n <= N; n++) {
  93873. const double k = ((double)n - N2) / (stddev * N2);
  93874. window[n] = (FLAC__real)exp(-0.5f * k * k);
  93875. }
  93876. }
  93877. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  93878. {
  93879. const FLAC__int32 N = L - 1;
  93880. FLAC__int32 n;
  93881. for (n = 0; n < L; n++)
  93882. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  93883. }
  93884. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  93885. {
  93886. const FLAC__int32 N = L - 1;
  93887. FLAC__int32 n;
  93888. for (n = 0; n < L; n++)
  93889. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  93890. }
  93891. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  93892. {
  93893. const FLAC__int32 N = L - 1;
  93894. FLAC__int32 n;
  93895. for (n = 0; n < L; n++)
  93896. 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));
  93897. }
  93898. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  93899. {
  93900. const FLAC__int32 N = L - 1;
  93901. FLAC__int32 n;
  93902. for (n = 0; n < L; n++)
  93903. 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));
  93904. }
  93905. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  93906. {
  93907. FLAC__int32 n;
  93908. for (n = 0; n < L; n++)
  93909. window[n] = 1.0f;
  93910. }
  93911. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  93912. {
  93913. FLAC__int32 n;
  93914. if (L & 1) {
  93915. for (n = 1; n <= L+1/2; n++)
  93916. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  93917. for (; n <= L; n++)
  93918. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  93919. }
  93920. else {
  93921. for (n = 1; n <= L/2; n++)
  93922. window[n-1] = 2.0f * n / (float)L;
  93923. for (; n <= L; n++)
  93924. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  93925. }
  93926. }
  93927. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  93928. {
  93929. if (p <= 0.0)
  93930. FLAC__window_rectangle(window, L);
  93931. else if (p >= 1.0)
  93932. FLAC__window_hann(window, L);
  93933. else {
  93934. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  93935. FLAC__int32 n;
  93936. FLAC__window_rectangle(window, L);
  93937. if (Np > 0) {
  93938. for (n = 0; n <= Np; n++) {
  93939. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  93940. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  93941. }
  93942. }
  93943. }
  93944. }
  93945. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  93946. {
  93947. const FLAC__int32 N = L - 1;
  93948. const double N2 = (double)N / 2.;
  93949. FLAC__int32 n;
  93950. for (n = 0; n <= N; n++) {
  93951. const double k = ((double)n - N2) / N2;
  93952. window[n] = (FLAC__real)(1.0f - k * k);
  93953. }
  93954. }
  93955. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  93956. #endif
  93957. /*** End of inlined file: window_flac.c ***/
  93958. #else
  93959. #include <FLAC/all.h>
  93960. #endif
  93961. }
  93962. #ifdef _MSC_VER
  93963. #pragma warning (pop)
  93964. #endif
  93965. BEGIN_JUCE_NAMESPACE
  93966. using namespace FlacNamespace;
  93967. static const char* const flacFormatName = "FLAC file";
  93968. static const tchar* const flacExtensions[] = { T(".flac"), 0 };
  93969. class FlacReader : public AudioFormatReader
  93970. {
  93971. FLAC__StreamDecoder* decoder;
  93972. AudioSampleBuffer reservoir;
  93973. int reservoirStart, samplesInReservoir;
  93974. bool ok, scanningForLength;
  93975. public:
  93976. FlacReader (InputStream* const in)
  93977. : AudioFormatReader (in, TRANS (flacFormatName)),
  93978. reservoir (2, 0),
  93979. reservoirStart (0),
  93980. samplesInReservoir (0),
  93981. scanningForLength (false)
  93982. {
  93983. using namespace FlacNamespace;
  93984. lengthInSamples = 0;
  93985. decoder = FLAC__stream_decoder_new();
  93986. ok = FLAC__stream_decoder_init_stream (decoder,
  93987. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  93988. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  93989. (void*) this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  93990. if (ok)
  93991. {
  93992. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93993. if (lengthInSamples == 0 && sampleRate > 0)
  93994. {
  93995. // the length hasn't been stored in the metadata, so we'll need to
  93996. // work it out the length the hard way, by scanning the whole file..
  93997. scanningForLength = true;
  93998. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  93999. scanningForLength = false;
  94000. const int64 tempLength = lengthInSamples;
  94001. FLAC__stream_decoder_reset (decoder);
  94002. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94003. lengthInSamples = tempLength;
  94004. }
  94005. }
  94006. }
  94007. ~FlacReader()
  94008. {
  94009. FLAC__stream_decoder_delete (decoder);
  94010. }
  94011. void useMetadata (const FLAC__StreamMetadata_StreamInfo& info)
  94012. {
  94013. sampleRate = info.sample_rate;
  94014. bitsPerSample = info.bits_per_sample;
  94015. lengthInSamples = (unsigned int) info.total_samples;
  94016. numChannels = info.channels;
  94017. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  94018. }
  94019. // returns the number of samples read
  94020. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  94021. int64 startSampleInFile, int numSamples)
  94022. {
  94023. using namespace FlacNamespace;
  94024. if (! ok)
  94025. return false;
  94026. while (numSamples > 0)
  94027. {
  94028. if (startSampleInFile >= reservoirStart
  94029. && startSampleInFile < reservoirStart + samplesInReservoir)
  94030. {
  94031. const int num = (int) jmin ((int64) numSamples,
  94032. reservoirStart + samplesInReservoir - startSampleInFile);
  94033. jassert (num > 0);
  94034. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  94035. if (destSamples[i] != 0)
  94036. memcpy (destSamples[i] + startOffsetInDestBuffer,
  94037. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  94038. sizeof (int) * num);
  94039. startOffsetInDestBuffer += num;
  94040. startSampleInFile += num;
  94041. numSamples -= num;
  94042. }
  94043. else
  94044. {
  94045. if (startSampleInFile >= (int) lengthInSamples)
  94046. {
  94047. samplesInReservoir = 0;
  94048. }
  94049. else if (startSampleInFile < reservoirStart
  94050. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  94051. {
  94052. // had some problems with flac crashing if the read pos is aligned more
  94053. // accurately than this. Probably fixed in newer versions of the library, though.
  94054. reservoirStart = (int) (startSampleInFile & ~511);
  94055. samplesInReservoir = 0;
  94056. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  94057. }
  94058. else
  94059. {
  94060. reservoirStart += samplesInReservoir;
  94061. samplesInReservoir = 0;
  94062. FLAC__stream_decoder_process_single (decoder);
  94063. }
  94064. if (samplesInReservoir == 0)
  94065. break;
  94066. }
  94067. }
  94068. if (numSamples > 0)
  94069. {
  94070. for (int i = numDestChannels; --i >= 0;)
  94071. if (destSamples[i] != 0)
  94072. zeromem (destSamples[i] + startOffsetInDestBuffer,
  94073. sizeof (int) * numSamples);
  94074. }
  94075. return true;
  94076. }
  94077. void useSamples (const FLAC__int32* const buffer[], int numSamples)
  94078. {
  94079. if (scanningForLength)
  94080. {
  94081. lengthInSamples += numSamples;
  94082. }
  94083. else
  94084. {
  94085. if (numSamples > reservoir.getNumSamples())
  94086. reservoir.setSize (numChannels, numSamples, false, false, true);
  94087. const int bitsToShift = 32 - bitsPerSample;
  94088. for (int i = 0; i < (int) numChannels; ++i)
  94089. {
  94090. const FLAC__int32* src = buffer[i];
  94091. int n = i;
  94092. while (src == 0 && n > 0)
  94093. src = buffer [--n];
  94094. if (src != 0)
  94095. {
  94096. int* dest = (int*) reservoir.getSampleData(i);
  94097. for (int j = 0; j < numSamples; ++j)
  94098. dest[j] = src[j] << bitsToShift;
  94099. }
  94100. }
  94101. samplesInReservoir = numSamples;
  94102. }
  94103. }
  94104. static FLAC__StreamDecoderReadStatus readCallback_ (const FLAC__StreamDecoder*, FLAC__byte buffer[], size_t* bytes, void* client_data)
  94105. {
  94106. *bytes = (unsigned int) ((const FlacReader*) client_data)->input->read (buffer, (int) *bytes);
  94107. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  94108. }
  94109. static FLAC__StreamDecoderSeekStatus seekCallback_ (const FLAC__StreamDecoder*, FLAC__uint64 absolute_byte_offset, void* client_data)
  94110. {
  94111. ((const FlacReader*) client_data)->input->setPosition ((int) absolute_byte_offset);
  94112. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  94113. }
  94114. static FLAC__StreamDecoderTellStatus tellCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94115. {
  94116. *absolute_byte_offset = ((const FlacReader*) client_data)->input->getPosition();
  94117. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  94118. }
  94119. static FLAC__StreamDecoderLengthStatus lengthCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* stream_length, void* client_data)
  94120. {
  94121. *stream_length = ((const FlacReader*) client_data)->input->getTotalLength();
  94122. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  94123. }
  94124. static FLAC__bool eofCallback_ (const FLAC__StreamDecoder*, void* client_data)
  94125. {
  94126. return ((const FlacReader*) client_data)->input->isExhausted();
  94127. }
  94128. static FLAC__StreamDecoderWriteStatus writeCallback_ (const FLAC__StreamDecoder*,
  94129. const FLAC__Frame* frame,
  94130. const FLAC__int32* const buffer[],
  94131. void* client_data)
  94132. {
  94133. ((FlacReader*) client_data)->useSamples (buffer, frame->header.blocksize);
  94134. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  94135. }
  94136. static void metadataCallback_ (const FLAC__StreamDecoder*,
  94137. const FLAC__StreamMetadata* metadata,
  94138. void* client_data)
  94139. {
  94140. ((FlacReader*) client_data)->useMetadata (metadata->data.stream_info);
  94141. }
  94142. static void errorCallback_ (const FLAC__StreamDecoder*, FLAC__StreamDecoderErrorStatus, void*)
  94143. {
  94144. }
  94145. juce_UseDebuggingNewOperator
  94146. };
  94147. class FlacWriter : public AudioFormatWriter
  94148. {
  94149. FLAC__StreamEncoder* encoder;
  94150. MemoryBlock temp;
  94151. public:
  94152. bool ok;
  94153. FlacWriter (OutputStream* const out,
  94154. const double sampleRate_,
  94155. const int numChannels_,
  94156. const int bitsPerSample_)
  94157. : AudioFormatWriter (out, TRANS (flacFormatName),
  94158. sampleRate_,
  94159. numChannels_,
  94160. bitsPerSample_)
  94161. {
  94162. using namespace FlacNamespace;
  94163. encoder = FLAC__stream_encoder_new();
  94164. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  94165. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  94166. FLAC__stream_encoder_set_channels (encoder, numChannels);
  94167. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  94168. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  94169. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  94170. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  94171. ok = FLAC__stream_encoder_init_stream (encoder,
  94172. encodeWriteCallback, encodeSeekCallback,
  94173. encodeTellCallback, encodeMetadataCallback,
  94174. (void*) this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  94175. }
  94176. ~FlacWriter()
  94177. {
  94178. if (ok)
  94179. {
  94180. FLAC__stream_encoder_finish (encoder);
  94181. output->flush();
  94182. }
  94183. else
  94184. {
  94185. output = 0; // to stop the base class deleting this, as it needs to be returned
  94186. // to the caller of createWriter()
  94187. }
  94188. FLAC__stream_encoder_delete (encoder);
  94189. }
  94190. bool write (const int** samplesToWrite, int numSamples)
  94191. {
  94192. if (! ok)
  94193. return false;
  94194. int* buf[3];
  94195. const int bitsToShift = 32 - bitsPerSample;
  94196. if (bitsToShift > 0)
  94197. {
  94198. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  94199. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  94200. buf[0] = (int*) temp.getData();
  94201. buf[1] = buf[0] + numSamples;
  94202. buf[2] = 0;
  94203. for (int i = numChannelsToWrite; --i >= 0;)
  94204. {
  94205. if (samplesToWrite[i] != 0)
  94206. {
  94207. for (int j = 0; j < numSamples; ++j)
  94208. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  94209. }
  94210. }
  94211. samplesToWrite = (const int**) buf;
  94212. }
  94213. return FLAC__stream_encoder_process (encoder,
  94214. (const FLAC__int32**) samplesToWrite,
  94215. numSamples) != 0;
  94216. }
  94217. bool writeData (const void* const data, const int size) const
  94218. {
  94219. return output->write (data, size);
  94220. }
  94221. static void packUint32 (FLAC__uint32 val, FLAC__byte* b, const int bytes)
  94222. {
  94223. b += bytes;
  94224. for (int i = 0; i < bytes; ++i)
  94225. {
  94226. *(--b) = (FLAC__byte) (val & 0xff);
  94227. val >>= 8;
  94228. }
  94229. }
  94230. void writeMetaData (const FLAC__StreamMetadata* metadata)
  94231. {
  94232. using namespace FlacNamespace;
  94233. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  94234. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  94235. const unsigned int channelsMinus1 = info.channels - 1;
  94236. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  94237. packUint32 (info.min_blocksize, buffer, 2);
  94238. packUint32 (info.max_blocksize, buffer + 2, 2);
  94239. packUint32 (info.min_framesize, buffer + 4, 3);
  94240. packUint32 (info.max_framesize, buffer + 7, 3);
  94241. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  94242. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  94243. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  94244. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  94245. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  94246. memcpy (buffer + 18, info.md5sum, 16);
  94247. const bool seekOk = output->setPosition (4);
  94248. (void) seekOk;
  94249. // if this fails, you've given it an output stream that can't seek! It needs
  94250. // to be able to seek back to write the header
  94251. jassert (seekOk);
  94252. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94253. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94254. }
  94255. static FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FLAC__StreamEncoder*,
  94256. const FLAC__byte buffer[],
  94257. size_t bytes,
  94258. unsigned int /*samples*/,
  94259. unsigned int /*current_frame*/,
  94260. void* client_data)
  94261. {
  94262. using namespace FlacNamespace;
  94263. return ((FlacWriter*) client_data)->writeData (buffer, (int) bytes)
  94264. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  94265. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  94266. }
  94267. static FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FLAC__StreamEncoder*, FLAC__uint64, void*)
  94268. {
  94269. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  94270. }
  94271. static FLAC__StreamEncoderTellStatus encodeTellCallback (const FLAC__StreamEncoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94272. {
  94273. if (client_data == 0)
  94274. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  94275. *absolute_byte_offset = (FLAC__uint64) ((FlacWriter*) client_data)->output->getPosition();
  94276. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  94277. }
  94278. static void encodeMetadataCallback (const FLAC__StreamEncoder*,
  94279. const FLAC__StreamMetadata* metadata,
  94280. void* client_data)
  94281. {
  94282. ((FlacWriter*) client_data)->writeMetaData (metadata);
  94283. }
  94284. juce_UseDebuggingNewOperator
  94285. };
  94286. FlacAudioFormat::FlacAudioFormat()
  94287. : AudioFormat (TRANS (flacFormatName), (const tchar**) flacExtensions)
  94288. {
  94289. }
  94290. FlacAudioFormat::~FlacAudioFormat()
  94291. {
  94292. }
  94293. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94294. {
  94295. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94296. return Array <int> (rates);
  94297. }
  94298. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94299. {
  94300. const int depths[] = { 16, 24, 0 };
  94301. return Array <int> (depths);
  94302. }
  94303. bool FlacAudioFormat::canDoStereo()
  94304. {
  94305. return true;
  94306. }
  94307. bool FlacAudioFormat::canDoMono()
  94308. {
  94309. return true;
  94310. }
  94311. bool FlacAudioFormat::isCompressed()
  94312. {
  94313. return true;
  94314. }
  94315. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94316. const bool deleteStreamIfOpeningFails)
  94317. {
  94318. ScopedPointer <FlacReader> r (new FlacReader (in));
  94319. if (r->sampleRate != 0)
  94320. return r.release();
  94321. if (! deleteStreamIfOpeningFails)
  94322. r->input = 0;
  94323. return 0;
  94324. }
  94325. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94326. double sampleRate,
  94327. unsigned int numberOfChannels,
  94328. int bitsPerSample,
  94329. const StringPairArray& /*metadataValues*/,
  94330. int /*qualityOptionIndex*/)
  94331. {
  94332. if (getPossibleBitDepths().contains (bitsPerSample))
  94333. {
  94334. ScopedPointer <FlacWriter> w (new FlacWriter (out,
  94335. sampleRate,
  94336. numberOfChannels,
  94337. bitsPerSample));
  94338. if (w->ok)
  94339. return w.release();
  94340. }
  94341. return 0;
  94342. }
  94343. END_JUCE_NAMESPACE
  94344. #endif
  94345. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  94346. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  94347. #if JUCE_USE_OGGVORBIS
  94348. #if JUCE_MAC
  94349. #define __MACOSX__ 1
  94350. #endif
  94351. namespace OggVorbisNamespace
  94352. {
  94353. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94354. /*** Start of inlined file: vorbisenc.h ***/
  94355. #ifndef _OV_ENC_H_
  94356. #define _OV_ENC_H_
  94357. #ifdef __cplusplus
  94358. extern "C"
  94359. {
  94360. #endif /* __cplusplus */
  94361. /*** Start of inlined file: codec.h ***/
  94362. #ifndef _vorbis_codec_h_
  94363. #define _vorbis_codec_h_
  94364. #ifdef __cplusplus
  94365. extern "C"
  94366. {
  94367. #endif /* __cplusplus */
  94368. /*** Start of inlined file: ogg.h ***/
  94369. #ifndef _OGG_H
  94370. #define _OGG_H
  94371. #ifdef __cplusplus
  94372. extern "C" {
  94373. #endif
  94374. /*** Start of inlined file: os_types.h ***/
  94375. #ifndef _OS_TYPES_H
  94376. #define _OS_TYPES_H
  94377. #define _ogg_malloc malloc
  94378. #define _ogg_calloc calloc
  94379. #define _ogg_realloc realloc
  94380. #define _ogg_free free
  94381. #if defined(_WIN32)
  94382. # if defined(__CYGWIN__)
  94383. # include <_G_config.h>
  94384. typedef _G_int64_t ogg_int64_t;
  94385. typedef _G_int32_t ogg_int32_t;
  94386. typedef _G_uint32_t ogg_uint32_t;
  94387. typedef _G_int16_t ogg_int16_t;
  94388. typedef _G_uint16_t ogg_uint16_t;
  94389. # elif defined(__MINGW32__)
  94390. typedef short ogg_int16_t;
  94391. typedef unsigned short ogg_uint16_t;
  94392. typedef int ogg_int32_t;
  94393. typedef unsigned int ogg_uint32_t;
  94394. typedef long long ogg_int64_t;
  94395. typedef unsigned long long ogg_uint64_t;
  94396. # elif defined(__MWERKS__)
  94397. typedef long long ogg_int64_t;
  94398. typedef int ogg_int32_t;
  94399. typedef unsigned int ogg_uint32_t;
  94400. typedef short ogg_int16_t;
  94401. typedef unsigned short ogg_uint16_t;
  94402. # else
  94403. typedef __int64 ogg_int64_t;
  94404. typedef __int32 ogg_int32_t;
  94405. typedef unsigned __int32 ogg_uint32_t;
  94406. typedef __int16 ogg_int16_t;
  94407. typedef unsigned __int16 ogg_uint16_t;
  94408. # endif
  94409. #elif defined(__MACOS__)
  94410. # include <sys/types.h>
  94411. typedef SInt16 ogg_int16_t;
  94412. typedef UInt16 ogg_uint16_t;
  94413. typedef SInt32 ogg_int32_t;
  94414. typedef UInt32 ogg_uint32_t;
  94415. typedef SInt64 ogg_int64_t;
  94416. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94417. # include <sys/types.h>
  94418. typedef int16_t ogg_int16_t;
  94419. typedef u_int16_t ogg_uint16_t;
  94420. typedef int32_t ogg_int32_t;
  94421. typedef u_int32_t ogg_uint32_t;
  94422. typedef int64_t ogg_int64_t;
  94423. #elif defined(__BEOS__)
  94424. # include <inttypes.h>
  94425. typedef int16_t ogg_int16_t;
  94426. typedef u_int16_t ogg_uint16_t;
  94427. typedef int32_t ogg_int32_t;
  94428. typedef u_int32_t ogg_uint32_t;
  94429. typedef int64_t ogg_int64_t;
  94430. #elif defined (__EMX__)
  94431. typedef short ogg_int16_t;
  94432. typedef unsigned short ogg_uint16_t;
  94433. typedef int ogg_int32_t;
  94434. typedef unsigned int ogg_uint32_t;
  94435. typedef long long ogg_int64_t;
  94436. #elif defined (DJGPP)
  94437. typedef short ogg_int16_t;
  94438. typedef int ogg_int32_t;
  94439. typedef unsigned int ogg_uint32_t;
  94440. typedef long long ogg_int64_t;
  94441. #elif defined(R5900)
  94442. typedef long ogg_int64_t;
  94443. typedef int ogg_int32_t;
  94444. typedef unsigned ogg_uint32_t;
  94445. typedef short ogg_int16_t;
  94446. #elif defined(__SYMBIAN32__)
  94447. typedef signed short ogg_int16_t;
  94448. typedef unsigned short ogg_uint16_t;
  94449. typedef signed int ogg_int32_t;
  94450. typedef unsigned int ogg_uint32_t;
  94451. typedef long long int ogg_int64_t;
  94452. #else
  94453. # include <sys/types.h>
  94454. /*** Start of inlined file: config_types.h ***/
  94455. #ifndef __CONFIG_TYPES_H__
  94456. #define __CONFIG_TYPES_H__
  94457. typedef int16_t ogg_int16_t;
  94458. typedef unsigned short ogg_uint16_t;
  94459. typedef int32_t ogg_int32_t;
  94460. typedef unsigned int ogg_uint32_t;
  94461. typedef int64_t ogg_int64_t;
  94462. #endif
  94463. /*** End of inlined file: config_types.h ***/
  94464. #endif
  94465. #endif /* _OS_TYPES_H */
  94466. /*** End of inlined file: os_types.h ***/
  94467. typedef struct {
  94468. long endbyte;
  94469. int endbit;
  94470. unsigned char *buffer;
  94471. unsigned char *ptr;
  94472. long storage;
  94473. } oggpack_buffer;
  94474. typedef struct {
  94475. unsigned char *header;
  94476. long header_len;
  94477. unsigned char *body;
  94478. long body_len;
  94479. } ogg_page;
  94480. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94481. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94482. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94483. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94484. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94485. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94486. }
  94487. typedef struct {
  94488. unsigned char *body_data; /* bytes from packet bodies */
  94489. long body_storage; /* storage elements allocated */
  94490. long body_fill; /* elements stored; fill mark */
  94491. long body_returned; /* elements of fill returned */
  94492. int *lacing_vals; /* The values that will go to the segment table */
  94493. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94494. this way, but it is simple coupled to the
  94495. lacing fifo */
  94496. long lacing_storage;
  94497. long lacing_fill;
  94498. long lacing_packet;
  94499. long lacing_returned;
  94500. unsigned char header[282]; /* working space for header encode */
  94501. int header_fill;
  94502. int e_o_s; /* set when we have buffered the last packet in the
  94503. logical bitstream */
  94504. int b_o_s; /* set after we've written the initial page
  94505. of a logical bitstream */
  94506. long serialno;
  94507. long pageno;
  94508. ogg_int64_t packetno; /* sequence number for decode; the framing
  94509. knows where there's a hole in the data,
  94510. but we need coupling so that the codec
  94511. (which is in a seperate abstraction
  94512. layer) also knows about the gap */
  94513. ogg_int64_t granulepos;
  94514. } ogg_stream_state;
  94515. typedef struct {
  94516. unsigned char *packet;
  94517. long bytes;
  94518. long b_o_s;
  94519. long e_o_s;
  94520. ogg_int64_t granulepos;
  94521. ogg_int64_t packetno; /* sequence number for decode; the framing
  94522. knows where there's a hole in the data,
  94523. but we need coupling so that the codec
  94524. (which is in a seperate abstraction
  94525. layer) also knows about the gap */
  94526. } ogg_packet;
  94527. typedef struct {
  94528. unsigned char *data;
  94529. int storage;
  94530. int fill;
  94531. int returned;
  94532. int unsynced;
  94533. int headerbytes;
  94534. int bodybytes;
  94535. } ogg_sync_state;
  94536. extern void oggpack_writeinit(oggpack_buffer *b);
  94537. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94538. extern void oggpack_writealign(oggpack_buffer *b);
  94539. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94540. extern void oggpack_reset(oggpack_buffer *b);
  94541. extern void oggpack_writeclear(oggpack_buffer *b);
  94542. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94543. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94544. extern long oggpack_look(oggpack_buffer *b,int bits);
  94545. extern long oggpack_look1(oggpack_buffer *b);
  94546. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94547. extern void oggpack_adv1(oggpack_buffer *b);
  94548. extern long oggpack_read(oggpack_buffer *b,int bits);
  94549. extern long oggpack_read1(oggpack_buffer *b);
  94550. extern long oggpack_bytes(oggpack_buffer *b);
  94551. extern long oggpack_bits(oggpack_buffer *b);
  94552. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94553. extern void oggpackB_writeinit(oggpack_buffer *b);
  94554. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94555. extern void oggpackB_writealign(oggpack_buffer *b);
  94556. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94557. extern void oggpackB_reset(oggpack_buffer *b);
  94558. extern void oggpackB_writeclear(oggpack_buffer *b);
  94559. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94560. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94561. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94562. extern long oggpackB_look1(oggpack_buffer *b);
  94563. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94564. extern void oggpackB_adv1(oggpack_buffer *b);
  94565. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94566. extern long oggpackB_read1(oggpack_buffer *b);
  94567. extern long oggpackB_bytes(oggpack_buffer *b);
  94568. extern long oggpackB_bits(oggpack_buffer *b);
  94569. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94570. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94571. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94572. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94573. extern int ogg_sync_init(ogg_sync_state *oy);
  94574. extern int ogg_sync_clear(ogg_sync_state *oy);
  94575. extern int ogg_sync_reset(ogg_sync_state *oy);
  94576. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94577. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94578. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94579. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94580. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94581. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94582. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94583. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94584. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94585. extern int ogg_stream_clear(ogg_stream_state *os);
  94586. extern int ogg_stream_reset(ogg_stream_state *os);
  94587. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94588. extern int ogg_stream_destroy(ogg_stream_state *os);
  94589. extern int ogg_stream_eos(ogg_stream_state *os);
  94590. extern void ogg_page_checksum_set(ogg_page *og);
  94591. extern int ogg_page_version(ogg_page *og);
  94592. extern int ogg_page_continued(ogg_page *og);
  94593. extern int ogg_page_bos(ogg_page *og);
  94594. extern int ogg_page_eos(ogg_page *og);
  94595. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94596. extern int ogg_page_serialno(ogg_page *og);
  94597. extern long ogg_page_pageno(ogg_page *og);
  94598. extern int ogg_page_packets(ogg_page *og);
  94599. extern void ogg_packet_clear(ogg_packet *op);
  94600. #ifdef __cplusplus
  94601. }
  94602. #endif
  94603. #endif /* _OGG_H */
  94604. /*** End of inlined file: ogg.h ***/
  94605. typedef struct vorbis_info{
  94606. int version;
  94607. int channels;
  94608. long rate;
  94609. long bitrate_upper;
  94610. long bitrate_nominal;
  94611. long bitrate_lower;
  94612. long bitrate_window;
  94613. void *codec_setup;
  94614. } vorbis_info;
  94615. typedef struct vorbis_dsp_state{
  94616. int analysisp;
  94617. vorbis_info *vi;
  94618. float **pcm;
  94619. float **pcmret;
  94620. int pcm_storage;
  94621. int pcm_current;
  94622. int pcm_returned;
  94623. int preextrapolate;
  94624. int eofflag;
  94625. long lW;
  94626. long W;
  94627. long nW;
  94628. long centerW;
  94629. ogg_int64_t granulepos;
  94630. ogg_int64_t sequence;
  94631. ogg_int64_t glue_bits;
  94632. ogg_int64_t time_bits;
  94633. ogg_int64_t floor_bits;
  94634. ogg_int64_t res_bits;
  94635. void *backend_state;
  94636. } vorbis_dsp_state;
  94637. typedef struct vorbis_block{
  94638. float **pcm; /* this is a pointer into local storage */
  94639. oggpack_buffer opb;
  94640. long lW;
  94641. long W;
  94642. long nW;
  94643. int pcmend;
  94644. int mode;
  94645. int eofflag;
  94646. ogg_int64_t granulepos;
  94647. ogg_int64_t sequence;
  94648. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94649. void *localstore;
  94650. long localtop;
  94651. long localalloc;
  94652. long totaluse;
  94653. struct alloc_chain *reap;
  94654. long glue_bits;
  94655. long time_bits;
  94656. long floor_bits;
  94657. long res_bits;
  94658. void *internal;
  94659. } vorbis_block;
  94660. struct alloc_chain{
  94661. void *ptr;
  94662. struct alloc_chain *next;
  94663. };
  94664. typedef struct vorbis_comment{
  94665. char **user_comments;
  94666. int *comment_lengths;
  94667. int comments;
  94668. char *vendor;
  94669. } vorbis_comment;
  94670. extern void vorbis_info_init(vorbis_info *vi);
  94671. extern void vorbis_info_clear(vorbis_info *vi);
  94672. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  94673. extern void vorbis_comment_init(vorbis_comment *vc);
  94674. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  94675. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  94676. const char *tag, char *contents);
  94677. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  94678. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  94679. extern void vorbis_comment_clear(vorbis_comment *vc);
  94680. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  94681. extern int vorbis_block_clear(vorbis_block *vb);
  94682. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  94683. extern double vorbis_granule_time(vorbis_dsp_state *v,
  94684. ogg_int64_t granulepos);
  94685. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94686. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  94687. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  94688. vorbis_comment *vc,
  94689. ogg_packet *op,
  94690. ogg_packet *op_comm,
  94691. ogg_packet *op_code);
  94692. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  94693. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  94694. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  94695. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  94696. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  94697. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  94698. ogg_packet *op);
  94699. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  94700. ogg_packet *op);
  94701. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94702. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  94703. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  94704. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  94705. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  94706. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  94707. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  94708. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  94709. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  94710. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  94711. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  94712. #define OV_FALSE -1
  94713. #define OV_EOF -2
  94714. #define OV_HOLE -3
  94715. #define OV_EREAD -128
  94716. #define OV_EFAULT -129
  94717. #define OV_EIMPL -130
  94718. #define OV_EINVAL -131
  94719. #define OV_ENOTVORBIS -132
  94720. #define OV_EBADHEADER -133
  94721. #define OV_EVERSION -134
  94722. #define OV_ENOTAUDIO -135
  94723. #define OV_EBADPACKET -136
  94724. #define OV_EBADLINK -137
  94725. #define OV_ENOSEEK -138
  94726. #ifdef __cplusplus
  94727. }
  94728. #endif /* __cplusplus */
  94729. #endif
  94730. /*** End of inlined file: codec.h ***/
  94731. extern int vorbis_encode_init(vorbis_info *vi,
  94732. long channels,
  94733. long rate,
  94734. long max_bitrate,
  94735. long nominal_bitrate,
  94736. long min_bitrate);
  94737. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  94738. long channels,
  94739. long rate,
  94740. long max_bitrate,
  94741. long nominal_bitrate,
  94742. long min_bitrate);
  94743. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  94744. long channels,
  94745. long rate,
  94746. float quality /* quality level from 0. (lo) to 1. (hi) */
  94747. );
  94748. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  94749. long channels,
  94750. long rate,
  94751. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  94752. );
  94753. extern int vorbis_encode_setup_init(vorbis_info *vi);
  94754. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  94755. #define OV_ECTL_RATEMANAGE_GET 0x10
  94756. #define OV_ECTL_RATEMANAGE_SET 0x11
  94757. #define OV_ECTL_RATEMANAGE_AVG 0x12
  94758. #define OV_ECTL_RATEMANAGE_HARD 0x13
  94759. struct ovectl_ratemanage_arg {
  94760. int management_active;
  94761. long bitrate_hard_min;
  94762. long bitrate_hard_max;
  94763. double bitrate_hard_window;
  94764. long bitrate_av_lo;
  94765. long bitrate_av_hi;
  94766. double bitrate_av_window;
  94767. double bitrate_av_window_center;
  94768. };
  94769. #define OV_ECTL_RATEMANAGE2_GET 0x14
  94770. #define OV_ECTL_RATEMANAGE2_SET 0x15
  94771. struct ovectl_ratemanage2_arg {
  94772. int management_active;
  94773. long bitrate_limit_min_kbps;
  94774. long bitrate_limit_max_kbps;
  94775. long bitrate_limit_reservoir_bits;
  94776. double bitrate_limit_reservoir_bias;
  94777. long bitrate_average_kbps;
  94778. double bitrate_average_damping;
  94779. };
  94780. #define OV_ECTL_LOWPASS_GET 0x20
  94781. #define OV_ECTL_LOWPASS_SET 0x21
  94782. #define OV_ECTL_IBLOCK_GET 0x30
  94783. #define OV_ECTL_IBLOCK_SET 0x31
  94784. #ifdef __cplusplus
  94785. }
  94786. #endif /* __cplusplus */
  94787. #endif
  94788. /*** End of inlined file: vorbisenc.h ***/
  94789. /*** Start of inlined file: vorbisfile.h ***/
  94790. #ifndef _OV_FILE_H_
  94791. #define _OV_FILE_H_
  94792. #ifdef __cplusplus
  94793. extern "C"
  94794. {
  94795. #endif /* __cplusplus */
  94796. #include <stdio.h>
  94797. typedef struct {
  94798. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  94799. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  94800. int (*close_func) (void *datasource);
  94801. long (*tell_func) (void *datasource);
  94802. } ov_callbacks;
  94803. #define NOTOPEN 0
  94804. #define PARTOPEN 1
  94805. #define OPENED 2
  94806. #define STREAMSET 3
  94807. #define INITSET 4
  94808. typedef struct OggVorbis_File {
  94809. void *datasource; /* Pointer to a FILE *, etc. */
  94810. int seekable;
  94811. ogg_int64_t offset;
  94812. ogg_int64_t end;
  94813. ogg_sync_state oy;
  94814. int links;
  94815. ogg_int64_t *offsets;
  94816. ogg_int64_t *dataoffsets;
  94817. long *serialnos;
  94818. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  94819. compatability; x2 size, stores both
  94820. beginning and end values */
  94821. vorbis_info *vi;
  94822. vorbis_comment *vc;
  94823. ogg_int64_t pcm_offset;
  94824. int ready_state;
  94825. long current_serialno;
  94826. int current_link;
  94827. double bittrack;
  94828. double samptrack;
  94829. ogg_stream_state os; /* take physical pages, weld into a logical
  94830. stream of packets */
  94831. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  94832. vorbis_block vb; /* local working space for packet->PCM decode */
  94833. ov_callbacks callbacks;
  94834. } OggVorbis_File;
  94835. extern int ov_clear(OggVorbis_File *vf);
  94836. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94837. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  94838. char *initial, long ibytes, ov_callbacks callbacks);
  94839. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94840. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  94841. char *initial, long ibytes, ov_callbacks callbacks);
  94842. extern int ov_test_open(OggVorbis_File *vf);
  94843. extern long ov_bitrate(OggVorbis_File *vf,int i);
  94844. extern long ov_bitrate_instant(OggVorbis_File *vf);
  94845. extern long ov_streams(OggVorbis_File *vf);
  94846. extern long ov_seekable(OggVorbis_File *vf);
  94847. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  94848. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  94849. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  94850. extern double ov_time_total(OggVorbis_File *vf,int i);
  94851. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94852. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94853. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  94854. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  94855. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  94856. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94857. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94858. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94859. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  94860. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  94861. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  94862. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  94863. extern double ov_time_tell(OggVorbis_File *vf);
  94864. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  94865. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  94866. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  94867. int *bitstream);
  94868. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  94869. int bigendianp,int word,int sgned,int *bitstream);
  94870. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  94871. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  94872. extern int ov_halfrate_p(OggVorbis_File *vf);
  94873. #ifdef __cplusplus
  94874. }
  94875. #endif /* __cplusplus */
  94876. #endif
  94877. /*** End of inlined file: vorbisfile.h ***/
  94878. /*** Start of inlined file: bitwise.c ***/
  94879. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  94880. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  94881. // tasks..
  94882. #if JUCE_MSVC
  94883. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  94884. #endif
  94885. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  94886. #if JUCE_USE_OGGVORBIS
  94887. #include <string.h>
  94888. #include <stdlib.h>
  94889. #define BUFFER_INCREMENT 256
  94890. static const unsigned long mask[]=
  94891. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  94892. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  94893. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  94894. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  94895. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  94896. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  94897. 0x3fffffff,0x7fffffff,0xffffffff };
  94898. static const unsigned int mask8B[]=
  94899. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  94900. void oggpack_writeinit(oggpack_buffer *b){
  94901. memset(b,0,sizeof(*b));
  94902. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  94903. b->buffer[0]='\0';
  94904. b->storage=BUFFER_INCREMENT;
  94905. }
  94906. void oggpackB_writeinit(oggpack_buffer *b){
  94907. oggpack_writeinit(b);
  94908. }
  94909. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  94910. long bytes=bits>>3;
  94911. bits-=bytes*8;
  94912. b->ptr=b->buffer+bytes;
  94913. b->endbit=bits;
  94914. b->endbyte=bytes;
  94915. *b->ptr&=mask[bits];
  94916. }
  94917. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  94918. long bytes=bits>>3;
  94919. bits-=bytes*8;
  94920. b->ptr=b->buffer+bytes;
  94921. b->endbit=bits;
  94922. b->endbyte=bytes;
  94923. *b->ptr&=mask8B[bits];
  94924. }
  94925. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  94926. if(b->endbyte+4>=b->storage){
  94927. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94928. b->storage+=BUFFER_INCREMENT;
  94929. b->ptr=b->buffer+b->endbyte;
  94930. }
  94931. value&=mask[bits];
  94932. bits+=b->endbit;
  94933. b->ptr[0]|=value<<b->endbit;
  94934. if(bits>=8){
  94935. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  94936. if(bits>=16){
  94937. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  94938. if(bits>=24){
  94939. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  94940. if(bits>=32){
  94941. if(b->endbit)
  94942. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  94943. else
  94944. b->ptr[4]=0;
  94945. }
  94946. }
  94947. }
  94948. }
  94949. b->endbyte+=bits/8;
  94950. b->ptr+=bits/8;
  94951. b->endbit=bits&7;
  94952. }
  94953. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  94954. if(b->endbyte+4>=b->storage){
  94955. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94956. b->storage+=BUFFER_INCREMENT;
  94957. b->ptr=b->buffer+b->endbyte;
  94958. }
  94959. value=(value&mask[bits])<<(32-bits);
  94960. bits+=b->endbit;
  94961. b->ptr[0]|=value>>(24+b->endbit);
  94962. if(bits>=8){
  94963. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  94964. if(bits>=16){
  94965. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  94966. if(bits>=24){
  94967. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  94968. if(bits>=32){
  94969. if(b->endbit)
  94970. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  94971. else
  94972. b->ptr[4]=0;
  94973. }
  94974. }
  94975. }
  94976. }
  94977. b->endbyte+=bits/8;
  94978. b->ptr+=bits/8;
  94979. b->endbit=bits&7;
  94980. }
  94981. void oggpack_writealign(oggpack_buffer *b){
  94982. int bits=8-b->endbit;
  94983. if(bits<8)
  94984. oggpack_write(b,0,bits);
  94985. }
  94986. void oggpackB_writealign(oggpack_buffer *b){
  94987. int bits=8-b->endbit;
  94988. if(bits<8)
  94989. oggpackB_write(b,0,bits);
  94990. }
  94991. static void oggpack_writecopy_helper(oggpack_buffer *b,
  94992. void *source,
  94993. long bits,
  94994. void (*w)(oggpack_buffer *,
  94995. unsigned long,
  94996. int),
  94997. int msb){
  94998. unsigned char *ptr=(unsigned char *)source;
  94999. long bytes=bits/8;
  95000. bits-=bytes*8;
  95001. if(b->endbit){
  95002. int i;
  95003. for(i=0;i<bytes;i++)
  95004. w(b,(unsigned long)(ptr[i]),8);
  95005. }else{
  95006. if(b->endbyte+bytes+1>=b->storage){
  95007. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  95008. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  95009. b->ptr=b->buffer+b->endbyte;
  95010. }
  95011. memmove(b->ptr,source,bytes);
  95012. b->ptr+=bytes;
  95013. b->endbyte+=bytes;
  95014. *b->ptr=0;
  95015. }
  95016. if(bits){
  95017. if(msb)
  95018. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  95019. else
  95020. w(b,(unsigned long)(ptr[bytes]),bits);
  95021. }
  95022. }
  95023. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  95024. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  95025. }
  95026. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  95027. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  95028. }
  95029. void oggpack_reset(oggpack_buffer *b){
  95030. b->ptr=b->buffer;
  95031. b->buffer[0]=0;
  95032. b->endbit=b->endbyte=0;
  95033. }
  95034. void oggpackB_reset(oggpack_buffer *b){
  95035. oggpack_reset(b);
  95036. }
  95037. void oggpack_writeclear(oggpack_buffer *b){
  95038. _ogg_free(b->buffer);
  95039. memset(b,0,sizeof(*b));
  95040. }
  95041. void oggpackB_writeclear(oggpack_buffer *b){
  95042. oggpack_writeclear(b);
  95043. }
  95044. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95045. memset(b,0,sizeof(*b));
  95046. b->buffer=b->ptr=buf;
  95047. b->storage=bytes;
  95048. }
  95049. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95050. oggpack_readinit(b,buf,bytes);
  95051. }
  95052. long oggpack_look(oggpack_buffer *b,int bits){
  95053. unsigned long ret;
  95054. unsigned long m=mask[bits];
  95055. bits+=b->endbit;
  95056. if(b->endbyte+4>=b->storage){
  95057. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95058. }
  95059. ret=b->ptr[0]>>b->endbit;
  95060. if(bits>8){
  95061. ret|=b->ptr[1]<<(8-b->endbit);
  95062. if(bits>16){
  95063. ret|=b->ptr[2]<<(16-b->endbit);
  95064. if(bits>24){
  95065. ret|=b->ptr[3]<<(24-b->endbit);
  95066. if(bits>32 && b->endbit)
  95067. ret|=b->ptr[4]<<(32-b->endbit);
  95068. }
  95069. }
  95070. }
  95071. return(m&ret);
  95072. }
  95073. long oggpackB_look(oggpack_buffer *b,int bits){
  95074. unsigned long ret;
  95075. int m=32-bits;
  95076. bits+=b->endbit;
  95077. if(b->endbyte+4>=b->storage){
  95078. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95079. }
  95080. ret=b->ptr[0]<<(24+b->endbit);
  95081. if(bits>8){
  95082. ret|=b->ptr[1]<<(16+b->endbit);
  95083. if(bits>16){
  95084. ret|=b->ptr[2]<<(8+b->endbit);
  95085. if(bits>24){
  95086. ret|=b->ptr[3]<<(b->endbit);
  95087. if(bits>32 && b->endbit)
  95088. ret|=b->ptr[4]>>(8-b->endbit);
  95089. }
  95090. }
  95091. }
  95092. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  95093. }
  95094. long oggpack_look1(oggpack_buffer *b){
  95095. if(b->endbyte>=b->storage)return(-1);
  95096. return((b->ptr[0]>>b->endbit)&1);
  95097. }
  95098. long oggpackB_look1(oggpack_buffer *b){
  95099. if(b->endbyte>=b->storage)return(-1);
  95100. return((b->ptr[0]>>(7-b->endbit))&1);
  95101. }
  95102. void oggpack_adv(oggpack_buffer *b,int bits){
  95103. bits+=b->endbit;
  95104. b->ptr+=bits/8;
  95105. b->endbyte+=bits/8;
  95106. b->endbit=bits&7;
  95107. }
  95108. void oggpackB_adv(oggpack_buffer *b,int bits){
  95109. oggpack_adv(b,bits);
  95110. }
  95111. void oggpack_adv1(oggpack_buffer *b){
  95112. if(++(b->endbit)>7){
  95113. b->endbit=0;
  95114. b->ptr++;
  95115. b->endbyte++;
  95116. }
  95117. }
  95118. void oggpackB_adv1(oggpack_buffer *b){
  95119. oggpack_adv1(b);
  95120. }
  95121. long oggpack_read(oggpack_buffer *b,int bits){
  95122. long ret;
  95123. unsigned long m=mask[bits];
  95124. bits+=b->endbit;
  95125. if(b->endbyte+4>=b->storage){
  95126. ret=-1L;
  95127. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95128. }
  95129. ret=b->ptr[0]>>b->endbit;
  95130. if(bits>8){
  95131. ret|=b->ptr[1]<<(8-b->endbit);
  95132. if(bits>16){
  95133. ret|=b->ptr[2]<<(16-b->endbit);
  95134. if(bits>24){
  95135. ret|=b->ptr[3]<<(24-b->endbit);
  95136. if(bits>32 && b->endbit){
  95137. ret|=b->ptr[4]<<(32-b->endbit);
  95138. }
  95139. }
  95140. }
  95141. }
  95142. ret&=m;
  95143. overflow:
  95144. b->ptr+=bits/8;
  95145. b->endbyte+=bits/8;
  95146. b->endbit=bits&7;
  95147. return(ret);
  95148. }
  95149. long oggpackB_read(oggpack_buffer *b,int bits){
  95150. long ret;
  95151. long m=32-bits;
  95152. bits+=b->endbit;
  95153. if(b->endbyte+4>=b->storage){
  95154. ret=-1L;
  95155. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95156. }
  95157. ret=b->ptr[0]<<(24+b->endbit);
  95158. if(bits>8){
  95159. ret|=b->ptr[1]<<(16+b->endbit);
  95160. if(bits>16){
  95161. ret|=b->ptr[2]<<(8+b->endbit);
  95162. if(bits>24){
  95163. ret|=b->ptr[3]<<(b->endbit);
  95164. if(bits>32 && b->endbit)
  95165. ret|=b->ptr[4]>>(8-b->endbit);
  95166. }
  95167. }
  95168. }
  95169. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  95170. overflow:
  95171. b->ptr+=bits/8;
  95172. b->endbyte+=bits/8;
  95173. b->endbit=bits&7;
  95174. return(ret);
  95175. }
  95176. long oggpack_read1(oggpack_buffer *b){
  95177. long ret;
  95178. if(b->endbyte>=b->storage){
  95179. ret=-1L;
  95180. goto overflow;
  95181. }
  95182. ret=(b->ptr[0]>>b->endbit)&1;
  95183. overflow:
  95184. b->endbit++;
  95185. if(b->endbit>7){
  95186. b->endbit=0;
  95187. b->ptr++;
  95188. b->endbyte++;
  95189. }
  95190. return(ret);
  95191. }
  95192. long oggpackB_read1(oggpack_buffer *b){
  95193. long ret;
  95194. if(b->endbyte>=b->storage){
  95195. ret=-1L;
  95196. goto overflow;
  95197. }
  95198. ret=(b->ptr[0]>>(7-b->endbit))&1;
  95199. overflow:
  95200. b->endbit++;
  95201. if(b->endbit>7){
  95202. b->endbit=0;
  95203. b->ptr++;
  95204. b->endbyte++;
  95205. }
  95206. return(ret);
  95207. }
  95208. long oggpack_bytes(oggpack_buffer *b){
  95209. return(b->endbyte+(b->endbit+7)/8);
  95210. }
  95211. long oggpack_bits(oggpack_buffer *b){
  95212. return(b->endbyte*8+b->endbit);
  95213. }
  95214. long oggpackB_bytes(oggpack_buffer *b){
  95215. return oggpack_bytes(b);
  95216. }
  95217. long oggpackB_bits(oggpack_buffer *b){
  95218. return oggpack_bits(b);
  95219. }
  95220. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  95221. return(b->buffer);
  95222. }
  95223. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  95224. return oggpack_get_buffer(b);
  95225. }
  95226. #ifdef _V_SELFTEST
  95227. #include <stdio.h>
  95228. static int ilog(unsigned int v){
  95229. int ret=0;
  95230. while(v){
  95231. ret++;
  95232. v>>=1;
  95233. }
  95234. return(ret);
  95235. }
  95236. oggpack_buffer o;
  95237. oggpack_buffer r;
  95238. void report(char *in){
  95239. fprintf(stderr,"%s",in);
  95240. exit(1);
  95241. }
  95242. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95243. long bytes,i;
  95244. unsigned char *buffer;
  95245. oggpack_reset(&o);
  95246. for(i=0;i<vals;i++)
  95247. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  95248. buffer=oggpack_get_buffer(&o);
  95249. bytes=oggpack_bytes(&o);
  95250. if(bytes!=compsize)report("wrong number of bytes!\n");
  95251. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95252. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95253. report("wrote incorrect value!\n");
  95254. }
  95255. oggpack_readinit(&r,buffer,bytes);
  95256. for(i=0;i<vals;i++){
  95257. int tbit=bits?bits:ilog(b[i]);
  95258. if(oggpack_look(&r,tbit)==-1)
  95259. report("out of data!\n");
  95260. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  95261. report("looked at incorrect value!\n");
  95262. if(tbit==1)
  95263. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  95264. report("looked at single bit incorrect value!\n");
  95265. if(tbit==1){
  95266. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  95267. report("read incorrect single bit value!\n");
  95268. }else{
  95269. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  95270. report("read incorrect value!\n");
  95271. }
  95272. }
  95273. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95274. }
  95275. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95276. long bytes,i;
  95277. unsigned char *buffer;
  95278. oggpackB_reset(&o);
  95279. for(i=0;i<vals;i++)
  95280. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  95281. buffer=oggpackB_get_buffer(&o);
  95282. bytes=oggpackB_bytes(&o);
  95283. if(bytes!=compsize)report("wrong number of bytes!\n");
  95284. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95285. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95286. report("wrote incorrect value!\n");
  95287. }
  95288. oggpackB_readinit(&r,buffer,bytes);
  95289. for(i=0;i<vals;i++){
  95290. int tbit=bits?bits:ilog(b[i]);
  95291. if(oggpackB_look(&r,tbit)==-1)
  95292. report("out of data!\n");
  95293. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95294. report("looked at incorrect value!\n");
  95295. if(tbit==1)
  95296. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95297. report("looked at single bit incorrect value!\n");
  95298. if(tbit==1){
  95299. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95300. report("read incorrect single bit value!\n");
  95301. }else{
  95302. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95303. report("read incorrect value!\n");
  95304. }
  95305. }
  95306. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95307. }
  95308. int main(void){
  95309. unsigned char *buffer;
  95310. long bytes,i;
  95311. static unsigned long testbuffer1[]=
  95312. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95313. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95314. int test1size=43;
  95315. static unsigned long testbuffer2[]=
  95316. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95317. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95318. 85525151,0,12321,1,349528352};
  95319. int test2size=21;
  95320. static unsigned long testbuffer3[]=
  95321. {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,
  95322. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95323. int test3size=56;
  95324. static unsigned long large[]=
  95325. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95326. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95327. 85525151,0,12321,1,2146528352};
  95328. int onesize=33;
  95329. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95330. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95331. 223,4};
  95332. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95333. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95334. 245,251,128};
  95335. int twosize=6;
  95336. static int two[6]={61,255,255,251,231,29};
  95337. static int twoB[6]={247,63,255,253,249,120};
  95338. int threesize=54;
  95339. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95340. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95341. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95342. 100,52,4,14,18,86,77,1};
  95343. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95344. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95345. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95346. 200,20,254,4,58,106,176,144,0};
  95347. int foursize=38;
  95348. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95349. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95350. 28,2,133,0,1};
  95351. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95352. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95353. 129,10,4,32};
  95354. int fivesize=45;
  95355. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95356. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95357. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95358. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95359. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95360. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95361. int sixsize=7;
  95362. static int six[7]={17,177,170,242,169,19,148};
  95363. static int sixB[7]={136,141,85,79,149,200,41};
  95364. oggpack_writeinit(&o);
  95365. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95366. cliptest(testbuffer1,test1size,0,one,onesize);
  95367. fprintf(stderr,"ok.");
  95368. fprintf(stderr,"\nNull bit call (LSb): ");
  95369. cliptest(testbuffer3,test3size,0,two,twosize);
  95370. fprintf(stderr,"ok.");
  95371. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  95372. cliptest(testbuffer2,test2size,0,three,threesize);
  95373. fprintf(stderr,"ok.");
  95374. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  95375. oggpack_reset(&o);
  95376. for(i=0;i<test2size;i++)
  95377. oggpack_write(&o,large[i],32);
  95378. buffer=oggpack_get_buffer(&o);
  95379. bytes=oggpack_bytes(&o);
  95380. oggpack_readinit(&r,buffer,bytes);
  95381. for(i=0;i<test2size;i++){
  95382. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  95383. if(oggpack_look(&r,32)!=large[i]){
  95384. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  95385. oggpack_look(&r,32),large[i]);
  95386. report("read incorrect value!\n");
  95387. }
  95388. oggpack_adv(&r,32);
  95389. }
  95390. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95391. fprintf(stderr,"ok.");
  95392. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  95393. cliptest(testbuffer1,test1size,7,four,foursize);
  95394. fprintf(stderr,"ok.");
  95395. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95396. cliptest(testbuffer2,test2size,17,five,fivesize);
  95397. fprintf(stderr,"ok.");
  95398. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95399. cliptest(testbuffer3,test3size,1,six,sixsize);
  95400. fprintf(stderr,"ok.");
  95401. fprintf(stderr,"\nTesting read past end (LSb): ");
  95402. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95403. for(i=0;i<64;i++){
  95404. if(oggpack_read(&r,1)!=0){
  95405. fprintf(stderr,"failed; got -1 prematurely.\n");
  95406. exit(1);
  95407. }
  95408. }
  95409. if(oggpack_look(&r,1)!=-1 ||
  95410. oggpack_read(&r,1)!=-1){
  95411. fprintf(stderr,"failed; read past end without -1.\n");
  95412. exit(1);
  95413. }
  95414. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95415. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95416. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95417. exit(1);
  95418. }
  95419. if(oggpack_look(&r,18)!=0 ||
  95420. oggpack_look(&r,18)!=0){
  95421. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95422. exit(1);
  95423. }
  95424. if(oggpack_look(&r,19)!=-1 ||
  95425. oggpack_look(&r,19)!=-1){
  95426. fprintf(stderr,"failed; read past end without -1.\n");
  95427. exit(1);
  95428. }
  95429. if(oggpack_look(&r,32)!=-1 ||
  95430. oggpack_look(&r,32)!=-1){
  95431. fprintf(stderr,"failed; read past end without -1.\n");
  95432. exit(1);
  95433. }
  95434. oggpack_writeclear(&o);
  95435. fprintf(stderr,"ok.\n");
  95436. oggpackB_writeinit(&o);
  95437. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95438. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95439. fprintf(stderr,"ok.");
  95440. fprintf(stderr,"\nNull bit call (MSb): ");
  95441. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95442. fprintf(stderr,"ok.");
  95443. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95444. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95445. fprintf(stderr,"ok.");
  95446. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95447. oggpackB_reset(&o);
  95448. for(i=0;i<test2size;i++)
  95449. oggpackB_write(&o,large[i],32);
  95450. buffer=oggpackB_get_buffer(&o);
  95451. bytes=oggpackB_bytes(&o);
  95452. oggpackB_readinit(&r,buffer,bytes);
  95453. for(i=0;i<test2size;i++){
  95454. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95455. if(oggpackB_look(&r,32)!=large[i]){
  95456. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95457. oggpackB_look(&r,32),large[i]);
  95458. report("read incorrect value!\n");
  95459. }
  95460. oggpackB_adv(&r,32);
  95461. }
  95462. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95463. fprintf(stderr,"ok.");
  95464. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95465. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95466. fprintf(stderr,"ok.");
  95467. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95468. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95469. fprintf(stderr,"ok.");
  95470. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95471. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95472. fprintf(stderr,"ok.");
  95473. fprintf(stderr,"\nTesting read past end (MSb): ");
  95474. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95475. for(i=0;i<64;i++){
  95476. if(oggpackB_read(&r,1)!=0){
  95477. fprintf(stderr,"failed; got -1 prematurely.\n");
  95478. exit(1);
  95479. }
  95480. }
  95481. if(oggpackB_look(&r,1)!=-1 ||
  95482. oggpackB_read(&r,1)!=-1){
  95483. fprintf(stderr,"failed; read past end without -1.\n");
  95484. exit(1);
  95485. }
  95486. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95487. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95488. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95489. exit(1);
  95490. }
  95491. if(oggpackB_look(&r,18)!=0 ||
  95492. oggpackB_look(&r,18)!=0){
  95493. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95494. exit(1);
  95495. }
  95496. if(oggpackB_look(&r,19)!=-1 ||
  95497. oggpackB_look(&r,19)!=-1){
  95498. fprintf(stderr,"failed; read past end without -1.\n");
  95499. exit(1);
  95500. }
  95501. if(oggpackB_look(&r,32)!=-1 ||
  95502. oggpackB_look(&r,32)!=-1){
  95503. fprintf(stderr,"failed; read past end without -1.\n");
  95504. exit(1);
  95505. }
  95506. oggpackB_writeclear(&o);
  95507. fprintf(stderr,"ok.\n\n");
  95508. return(0);
  95509. }
  95510. #endif /* _V_SELFTEST */
  95511. #undef BUFFER_INCREMENT
  95512. #endif
  95513. /*** End of inlined file: bitwise.c ***/
  95514. /*** Start of inlined file: framing.c ***/
  95515. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95516. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95517. // tasks..
  95518. #if JUCE_MSVC
  95519. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95520. #endif
  95521. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95522. #if JUCE_USE_OGGVORBIS
  95523. #include <stdlib.h>
  95524. #include <string.h>
  95525. int ogg_page_version(ogg_page *og){
  95526. return((int)(og->header[4]));
  95527. }
  95528. int ogg_page_continued(ogg_page *og){
  95529. return((int)(og->header[5]&0x01));
  95530. }
  95531. int ogg_page_bos(ogg_page *og){
  95532. return((int)(og->header[5]&0x02));
  95533. }
  95534. int ogg_page_eos(ogg_page *og){
  95535. return((int)(og->header[5]&0x04));
  95536. }
  95537. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95538. unsigned char *page=og->header;
  95539. ogg_int64_t granulepos=page[13]&(0xff);
  95540. granulepos= (granulepos<<8)|(page[12]&0xff);
  95541. granulepos= (granulepos<<8)|(page[11]&0xff);
  95542. granulepos= (granulepos<<8)|(page[10]&0xff);
  95543. granulepos= (granulepos<<8)|(page[9]&0xff);
  95544. granulepos= (granulepos<<8)|(page[8]&0xff);
  95545. granulepos= (granulepos<<8)|(page[7]&0xff);
  95546. granulepos= (granulepos<<8)|(page[6]&0xff);
  95547. return(granulepos);
  95548. }
  95549. int ogg_page_serialno(ogg_page *og){
  95550. return(og->header[14] |
  95551. (og->header[15]<<8) |
  95552. (og->header[16]<<16) |
  95553. (og->header[17]<<24));
  95554. }
  95555. long ogg_page_pageno(ogg_page *og){
  95556. return(og->header[18] |
  95557. (og->header[19]<<8) |
  95558. (og->header[20]<<16) |
  95559. (og->header[21]<<24));
  95560. }
  95561. int ogg_page_packets(ogg_page *og){
  95562. int i,n=og->header[26],count=0;
  95563. for(i=0;i<n;i++)
  95564. if(og->header[27+i]<255)count++;
  95565. return(count);
  95566. }
  95567. #if 0
  95568. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95569. int i;
  95570. unsigned long r;
  95571. r = index << 24;
  95572. for (i=0; i<8; i++)
  95573. if (r & 0x80000000UL)
  95574. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95575. polynomial, although we use an
  95576. unreflected alg and an init/final
  95577. of 0, not 0xffffffff */
  95578. else
  95579. r<<=1;
  95580. return (r & 0xffffffffUL);
  95581. }
  95582. #endif
  95583. static const ogg_uint32_t crc_lookup[256]={
  95584. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95585. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95586. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95587. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95588. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95589. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95590. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95591. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95592. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95593. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95594. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95595. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95596. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95597. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95598. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95599. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95600. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95601. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95602. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95603. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95604. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95605. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95606. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95607. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95608. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95609. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95610. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95611. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95612. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95613. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95614. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95615. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95616. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95617. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95618. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95619. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95620. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95621. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95622. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95623. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95624. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95625. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95626. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95627. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95628. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95629. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95630. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95631. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95632. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95633. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95634. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95635. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95636. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95637. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95638. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95639. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95640. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95641. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95642. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95643. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95644. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95645. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95646. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95647. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95648. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95649. if(os){
  95650. memset(os,0,sizeof(*os));
  95651. os->body_storage=16*1024;
  95652. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95653. os->lacing_storage=1024;
  95654. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95655. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95656. os->serialno=serialno;
  95657. return(0);
  95658. }
  95659. return(-1);
  95660. }
  95661. int ogg_stream_clear(ogg_stream_state *os){
  95662. if(os){
  95663. if(os->body_data)_ogg_free(os->body_data);
  95664. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95665. if(os->granule_vals)_ogg_free(os->granule_vals);
  95666. memset(os,0,sizeof(*os));
  95667. }
  95668. return(0);
  95669. }
  95670. int ogg_stream_destroy(ogg_stream_state *os){
  95671. if(os){
  95672. ogg_stream_clear(os);
  95673. _ogg_free(os);
  95674. }
  95675. return(0);
  95676. }
  95677. static void _os_body_expand(ogg_stream_state *os,int needed){
  95678. if(os->body_storage<=os->body_fill+needed){
  95679. os->body_storage+=(needed+1024);
  95680. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  95681. }
  95682. }
  95683. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  95684. if(os->lacing_storage<=os->lacing_fill+needed){
  95685. os->lacing_storage+=(needed+32);
  95686. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  95687. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  95688. }
  95689. }
  95690. void ogg_page_checksum_set(ogg_page *og){
  95691. if(og){
  95692. ogg_uint32_t crc_reg=0;
  95693. int i;
  95694. og->header[22]=0;
  95695. og->header[23]=0;
  95696. og->header[24]=0;
  95697. og->header[25]=0;
  95698. for(i=0;i<og->header_len;i++)
  95699. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  95700. for(i=0;i<og->body_len;i++)
  95701. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  95702. og->header[22]=(unsigned char)(crc_reg&0xff);
  95703. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  95704. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  95705. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  95706. }
  95707. }
  95708. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  95709. int lacing_vals=op->bytes/255+1,i;
  95710. if(os->body_returned){
  95711. os->body_fill-=os->body_returned;
  95712. if(os->body_fill)
  95713. memmove(os->body_data,os->body_data+os->body_returned,
  95714. os->body_fill);
  95715. os->body_returned=0;
  95716. }
  95717. _os_body_expand(os,op->bytes);
  95718. _os_lacing_expand(os,lacing_vals);
  95719. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  95720. os->body_fill+=op->bytes;
  95721. for(i=0;i<lacing_vals-1;i++){
  95722. os->lacing_vals[os->lacing_fill+i]=255;
  95723. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  95724. }
  95725. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  95726. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  95727. os->lacing_vals[os->lacing_fill]|= 0x100;
  95728. os->lacing_fill+=lacing_vals;
  95729. os->packetno++;
  95730. if(op->e_o_s)os->e_o_s=1;
  95731. return(0);
  95732. }
  95733. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  95734. int i;
  95735. int vals=0;
  95736. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  95737. int bytes=0;
  95738. long acc=0;
  95739. ogg_int64_t granule_pos=-1;
  95740. if(maxvals==0)return(0);
  95741. if(os->b_o_s==0){ /* 'initial header page' case */
  95742. granule_pos=0;
  95743. for(vals=0;vals<maxvals;vals++){
  95744. if((os->lacing_vals[vals]&0x0ff)<255){
  95745. vals++;
  95746. break;
  95747. }
  95748. }
  95749. }else{
  95750. for(vals=0;vals<maxvals;vals++){
  95751. if(acc>4096)break;
  95752. acc+=os->lacing_vals[vals]&0x0ff;
  95753. if((os->lacing_vals[vals]&0xff)<255)
  95754. granule_pos=os->granule_vals[vals];
  95755. }
  95756. }
  95757. memcpy(os->header,"OggS",4);
  95758. os->header[4]=0x00;
  95759. os->header[5]=0x00;
  95760. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  95761. if(os->b_o_s==0)os->header[5]|=0x02;
  95762. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  95763. os->b_o_s=1;
  95764. for(i=6;i<14;i++){
  95765. os->header[i]=(unsigned char)(granule_pos&0xff);
  95766. granule_pos>>=8;
  95767. }
  95768. {
  95769. long serialno=os->serialno;
  95770. for(i=14;i<18;i++){
  95771. os->header[i]=(unsigned char)(serialno&0xff);
  95772. serialno>>=8;
  95773. }
  95774. }
  95775. if(os->pageno==-1)os->pageno=0; /* because someone called
  95776. stream_reset; this would be a
  95777. strange thing to do in an
  95778. encode stream, but it has
  95779. plausible uses */
  95780. {
  95781. long pageno=os->pageno++;
  95782. for(i=18;i<22;i++){
  95783. os->header[i]=(unsigned char)(pageno&0xff);
  95784. pageno>>=8;
  95785. }
  95786. }
  95787. os->header[22]=0;
  95788. os->header[23]=0;
  95789. os->header[24]=0;
  95790. os->header[25]=0;
  95791. os->header[26]=(unsigned char)(vals&0xff);
  95792. for(i=0;i<vals;i++)
  95793. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  95794. og->header=os->header;
  95795. og->header_len=os->header_fill=vals+27;
  95796. og->body=os->body_data+os->body_returned;
  95797. og->body_len=bytes;
  95798. os->lacing_fill-=vals;
  95799. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  95800. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  95801. os->body_returned+=bytes;
  95802. ogg_page_checksum_set(og);
  95803. return(1);
  95804. }
  95805. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  95806. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  95807. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  95808. os->lacing_fill>=255 || /* 'segment table full' case */
  95809. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  95810. return(ogg_stream_flush(os,og));
  95811. }
  95812. return(0);
  95813. }
  95814. int ogg_stream_eos(ogg_stream_state *os){
  95815. return os->e_o_s;
  95816. }
  95817. int ogg_sync_init(ogg_sync_state *oy){
  95818. if(oy){
  95819. memset(oy,0,sizeof(*oy));
  95820. }
  95821. return(0);
  95822. }
  95823. int ogg_sync_clear(ogg_sync_state *oy){
  95824. if(oy){
  95825. if(oy->data)_ogg_free(oy->data);
  95826. ogg_sync_init(oy);
  95827. }
  95828. return(0);
  95829. }
  95830. int ogg_sync_destroy(ogg_sync_state *oy){
  95831. if(oy){
  95832. ogg_sync_clear(oy);
  95833. _ogg_free(oy);
  95834. }
  95835. return(0);
  95836. }
  95837. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  95838. if(oy->returned){
  95839. oy->fill-=oy->returned;
  95840. if(oy->fill>0)
  95841. memmove(oy->data,oy->data+oy->returned,oy->fill);
  95842. oy->returned=0;
  95843. }
  95844. if(size>oy->storage-oy->fill){
  95845. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  95846. if(oy->data)
  95847. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  95848. else
  95849. oy->data=(unsigned char*) _ogg_malloc(newsize);
  95850. oy->storage=newsize;
  95851. }
  95852. return((char *)oy->data+oy->fill);
  95853. }
  95854. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  95855. if(oy->fill+bytes>oy->storage)return(-1);
  95856. oy->fill+=bytes;
  95857. return(0);
  95858. }
  95859. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  95860. unsigned char *page=oy->data+oy->returned;
  95861. unsigned char *next;
  95862. long bytes=oy->fill-oy->returned;
  95863. if(oy->headerbytes==0){
  95864. int headerbytes,i;
  95865. if(bytes<27)return(0); /* not enough for a header */
  95866. if(memcmp(page,"OggS",4))goto sync_fail;
  95867. headerbytes=page[26]+27;
  95868. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  95869. for(i=0;i<page[26];i++)
  95870. oy->bodybytes+=page[27+i];
  95871. oy->headerbytes=headerbytes;
  95872. }
  95873. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  95874. {
  95875. char chksum[4];
  95876. ogg_page log;
  95877. memcpy(chksum,page+22,4);
  95878. memset(page+22,0,4);
  95879. log.header=page;
  95880. log.header_len=oy->headerbytes;
  95881. log.body=page+oy->headerbytes;
  95882. log.body_len=oy->bodybytes;
  95883. ogg_page_checksum_set(&log);
  95884. if(memcmp(chksum,page+22,4)){
  95885. memcpy(page+22,chksum,4);
  95886. goto sync_fail;
  95887. }
  95888. }
  95889. {
  95890. unsigned char *page=oy->data+oy->returned;
  95891. long bytes;
  95892. if(og){
  95893. og->header=page;
  95894. og->header_len=oy->headerbytes;
  95895. og->body=page+oy->headerbytes;
  95896. og->body_len=oy->bodybytes;
  95897. }
  95898. oy->unsynced=0;
  95899. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  95900. oy->headerbytes=0;
  95901. oy->bodybytes=0;
  95902. return(bytes);
  95903. }
  95904. sync_fail:
  95905. oy->headerbytes=0;
  95906. oy->bodybytes=0;
  95907. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  95908. if(!next)
  95909. next=oy->data+oy->fill;
  95910. oy->returned=next-oy->data;
  95911. return(-(next-page));
  95912. }
  95913. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  95914. for(;;){
  95915. long ret=ogg_sync_pageseek(oy,og);
  95916. if(ret>0){
  95917. return(1);
  95918. }
  95919. if(ret==0){
  95920. return(0);
  95921. }
  95922. if(!oy->unsynced){
  95923. oy->unsynced=1;
  95924. return(-1);
  95925. }
  95926. }
  95927. }
  95928. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  95929. unsigned char *header=og->header;
  95930. unsigned char *body=og->body;
  95931. long bodysize=og->body_len;
  95932. int segptr=0;
  95933. int version=ogg_page_version(og);
  95934. int continued=ogg_page_continued(og);
  95935. int bos=ogg_page_bos(og);
  95936. int eos=ogg_page_eos(og);
  95937. ogg_int64_t granulepos=ogg_page_granulepos(og);
  95938. int serialno=ogg_page_serialno(og);
  95939. long pageno=ogg_page_pageno(og);
  95940. int segments=header[26];
  95941. {
  95942. long lr=os->lacing_returned;
  95943. long br=os->body_returned;
  95944. if(br){
  95945. os->body_fill-=br;
  95946. if(os->body_fill)
  95947. memmove(os->body_data,os->body_data+br,os->body_fill);
  95948. os->body_returned=0;
  95949. }
  95950. if(lr){
  95951. if(os->lacing_fill-lr){
  95952. memmove(os->lacing_vals,os->lacing_vals+lr,
  95953. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  95954. memmove(os->granule_vals,os->granule_vals+lr,
  95955. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  95956. }
  95957. os->lacing_fill-=lr;
  95958. os->lacing_packet-=lr;
  95959. os->lacing_returned=0;
  95960. }
  95961. }
  95962. if(serialno!=os->serialno)return(-1);
  95963. if(version>0)return(-1);
  95964. _os_lacing_expand(os,segments+1);
  95965. if(pageno!=os->pageno){
  95966. int i;
  95967. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  95968. os->body_fill-=os->lacing_vals[i]&0xff;
  95969. os->lacing_fill=os->lacing_packet;
  95970. if(os->pageno!=-1){
  95971. os->lacing_vals[os->lacing_fill++]=0x400;
  95972. os->lacing_packet++;
  95973. }
  95974. }
  95975. if(continued){
  95976. if(os->lacing_fill<1 ||
  95977. os->lacing_vals[os->lacing_fill-1]==0x400){
  95978. bos=0;
  95979. for(;segptr<segments;segptr++){
  95980. int val=header[27+segptr];
  95981. body+=val;
  95982. bodysize-=val;
  95983. if(val<255){
  95984. segptr++;
  95985. break;
  95986. }
  95987. }
  95988. }
  95989. }
  95990. if(bodysize){
  95991. _os_body_expand(os,bodysize);
  95992. memcpy(os->body_data+os->body_fill,body,bodysize);
  95993. os->body_fill+=bodysize;
  95994. }
  95995. {
  95996. int saved=-1;
  95997. while(segptr<segments){
  95998. int val=header[27+segptr];
  95999. os->lacing_vals[os->lacing_fill]=val;
  96000. os->granule_vals[os->lacing_fill]=-1;
  96001. if(bos){
  96002. os->lacing_vals[os->lacing_fill]|=0x100;
  96003. bos=0;
  96004. }
  96005. if(val<255)saved=os->lacing_fill;
  96006. os->lacing_fill++;
  96007. segptr++;
  96008. if(val<255)os->lacing_packet=os->lacing_fill;
  96009. }
  96010. if(saved!=-1){
  96011. os->granule_vals[saved]=granulepos;
  96012. }
  96013. }
  96014. if(eos){
  96015. os->e_o_s=1;
  96016. if(os->lacing_fill>0)
  96017. os->lacing_vals[os->lacing_fill-1]|=0x200;
  96018. }
  96019. os->pageno=pageno+1;
  96020. return(0);
  96021. }
  96022. int ogg_sync_reset(ogg_sync_state *oy){
  96023. oy->fill=0;
  96024. oy->returned=0;
  96025. oy->unsynced=0;
  96026. oy->headerbytes=0;
  96027. oy->bodybytes=0;
  96028. return(0);
  96029. }
  96030. int ogg_stream_reset(ogg_stream_state *os){
  96031. os->body_fill=0;
  96032. os->body_returned=0;
  96033. os->lacing_fill=0;
  96034. os->lacing_packet=0;
  96035. os->lacing_returned=0;
  96036. os->header_fill=0;
  96037. os->e_o_s=0;
  96038. os->b_o_s=0;
  96039. os->pageno=-1;
  96040. os->packetno=0;
  96041. os->granulepos=0;
  96042. return(0);
  96043. }
  96044. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  96045. ogg_stream_reset(os);
  96046. os->serialno=serialno;
  96047. return(0);
  96048. }
  96049. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  96050. int ptr=os->lacing_returned;
  96051. if(os->lacing_packet<=ptr)return(0);
  96052. if(os->lacing_vals[ptr]&0x400){
  96053. os->lacing_returned++;
  96054. os->packetno++;
  96055. return(-1);
  96056. }
  96057. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  96058. to ask if there's a whole packet
  96059. waiting */
  96060. {
  96061. int size=os->lacing_vals[ptr]&0xff;
  96062. int bytes=size;
  96063. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  96064. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  96065. while(size==255){
  96066. int val=os->lacing_vals[++ptr];
  96067. size=val&0xff;
  96068. if(val&0x200)eos=0x200;
  96069. bytes+=size;
  96070. }
  96071. if(op){
  96072. op->e_o_s=eos;
  96073. op->b_o_s=bos;
  96074. op->packet=os->body_data+os->body_returned;
  96075. op->packetno=os->packetno;
  96076. op->granulepos=os->granule_vals[ptr];
  96077. op->bytes=bytes;
  96078. }
  96079. if(adv){
  96080. os->body_returned+=bytes;
  96081. os->lacing_returned=ptr+1;
  96082. os->packetno++;
  96083. }
  96084. }
  96085. return(1);
  96086. }
  96087. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  96088. return _packetout(os,op,1);
  96089. }
  96090. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  96091. return _packetout(os,op,0);
  96092. }
  96093. void ogg_packet_clear(ogg_packet *op) {
  96094. _ogg_free(op->packet);
  96095. memset(op, 0, sizeof(*op));
  96096. }
  96097. #ifdef _V_SELFTEST
  96098. #include <stdio.h>
  96099. ogg_stream_state os_en, os_de;
  96100. ogg_sync_state oy;
  96101. void checkpacket(ogg_packet *op,int len, int no, int pos){
  96102. long j;
  96103. static int sequence=0;
  96104. static int lastno=0;
  96105. if(op->bytes!=len){
  96106. fprintf(stderr,"incorrect packet length!\n");
  96107. exit(1);
  96108. }
  96109. if(op->granulepos!=pos){
  96110. fprintf(stderr,"incorrect packet position!\n");
  96111. exit(1);
  96112. }
  96113. if(no==0){
  96114. sequence=0;
  96115. }else{
  96116. sequence++;
  96117. if(no>lastno+1)
  96118. sequence++;
  96119. }
  96120. lastno=no;
  96121. if(op->packetno!=sequence){
  96122. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  96123. (long)(op->packetno),sequence);
  96124. exit(1);
  96125. }
  96126. for(j=0;j<op->bytes;j++)
  96127. if(op->packet[j]!=((j+no)&0xff)){
  96128. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  96129. j,op->packet[j],(j+no)&0xff);
  96130. exit(1);
  96131. }
  96132. }
  96133. void check_page(unsigned char *data,const int *header,ogg_page *og){
  96134. long j;
  96135. for(j=0;j<og->body_len;j++)
  96136. if(og->body[j]!=data[j]){
  96137. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  96138. j,data[j],og->body[j]);
  96139. exit(1);
  96140. }
  96141. for(j=0;j<og->header_len;j++){
  96142. if(og->header[j]!=header[j]){
  96143. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  96144. for(j=0;j<header[26]+27;j++)
  96145. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  96146. fprintf(stderr,"\n");
  96147. exit(1);
  96148. }
  96149. }
  96150. if(og->header_len!=header[26]+27){
  96151. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  96152. og->header_len,header[26]+27);
  96153. exit(1);
  96154. }
  96155. }
  96156. void print_header(ogg_page *og){
  96157. int j;
  96158. fprintf(stderr,"\nHEADER:\n");
  96159. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  96160. og->header[0],og->header[1],og->header[2],og->header[3],
  96161. (int)og->header[4],(int)og->header[5]);
  96162. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  96163. (og->header[9]<<24)|(og->header[8]<<16)|
  96164. (og->header[7]<<8)|og->header[6],
  96165. (og->header[17]<<24)|(og->header[16]<<16)|
  96166. (og->header[15]<<8)|og->header[14],
  96167. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  96168. (og->header[19]<<8)|og->header[18]);
  96169. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  96170. (int)og->header[22],(int)og->header[23],
  96171. (int)og->header[24],(int)og->header[25],
  96172. (int)og->header[26]);
  96173. for(j=27;j<og->header_len;j++)
  96174. fprintf(stderr,"%d ",(int)og->header[j]);
  96175. fprintf(stderr,")\n\n");
  96176. }
  96177. void copy_page(ogg_page *og){
  96178. unsigned char *temp=_ogg_malloc(og->header_len);
  96179. memcpy(temp,og->header,og->header_len);
  96180. og->header=temp;
  96181. temp=_ogg_malloc(og->body_len);
  96182. memcpy(temp,og->body,og->body_len);
  96183. og->body=temp;
  96184. }
  96185. void free_page(ogg_page *og){
  96186. _ogg_free (og->header);
  96187. _ogg_free (og->body);
  96188. }
  96189. void error(void){
  96190. fprintf(stderr,"error!\n");
  96191. exit(1);
  96192. }
  96193. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  96194. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96195. 0x01,0x02,0x03,0x04,0,0,0,0,
  96196. 0x15,0xed,0xec,0x91,
  96197. 1,
  96198. 17};
  96199. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96200. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96201. 0x01,0x02,0x03,0x04,0,0,0,0,
  96202. 0x59,0x10,0x6c,0x2c,
  96203. 1,
  96204. 17};
  96205. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96206. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  96207. 0x01,0x02,0x03,0x04,1,0,0,0,
  96208. 0x89,0x33,0x85,0xce,
  96209. 13,
  96210. 254,255,0,255,1,255,245,255,255,0,
  96211. 255,255,90};
  96212. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96213. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96214. 0x01,0x02,0x03,0x04,0,0,0,0,
  96215. 0xff,0x7b,0x23,0x17,
  96216. 1,
  96217. 0};
  96218. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96219. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  96220. 0x01,0x02,0x03,0x04,1,0,0,0,
  96221. 0x5c,0x3f,0x66,0xcb,
  96222. 17,
  96223. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  96224. 255,255,90,0};
  96225. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96226. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96227. 0x01,0x02,0x03,0x04,0,0,0,0,
  96228. 0x01,0x27,0x31,0xaa,
  96229. 18,
  96230. 255,255,255,255,255,255,255,255,
  96231. 255,255,255,255,255,255,255,255,255,10};
  96232. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96233. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96234. 0x01,0x02,0x03,0x04,1,0,0,0,
  96235. 0x7f,0x4e,0x8a,0xd2,
  96236. 4,
  96237. 255,4,255,0};
  96238. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96239. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96240. 0x01,0x02,0x03,0x04,0,0,0,0,
  96241. 0xff,0x7b,0x23,0x17,
  96242. 1,
  96243. 0};
  96244. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96245. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96246. 0x01,0x02,0x03,0x04,1,0,0,0,
  96247. 0x54,0x05,0x51,0xc8,
  96248. 17,
  96249. 255,255,255,255,255,255,255,255,
  96250. 255,255,255,255,255,255,255,255,255};
  96251. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96252. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  96253. 0x01,0x02,0x03,0x04,2,0,0,0,
  96254. 0xc8,0xc3,0xcb,0xed,
  96255. 5,
  96256. 10,255,4,255,0};
  96257. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96258. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96259. 0x01,0x02,0x03,0x04,0,0,0,0,
  96260. 0xff,0x7b,0x23,0x17,
  96261. 1,
  96262. 0};
  96263. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96264. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  96265. 0x01,0x02,0x03,0x04,1,0,0,0,
  96266. 0xed,0x2a,0x2e,0xa7,
  96267. 255,
  96268. 10,10,10,10,10,10,10,10,
  96269. 10,10,10,10,10,10,10,10,
  96270. 10,10,10,10,10,10,10,10,
  96271. 10,10,10,10,10,10,10,10,
  96272. 10,10,10,10,10,10,10,10,
  96273. 10,10,10,10,10,10,10,10,
  96274. 10,10,10,10,10,10,10,10,
  96275. 10,10,10,10,10,10,10,10,
  96276. 10,10,10,10,10,10,10,10,
  96277. 10,10,10,10,10,10,10,10,
  96278. 10,10,10,10,10,10,10,10,
  96279. 10,10,10,10,10,10,10,10,
  96280. 10,10,10,10,10,10,10,10,
  96281. 10,10,10,10,10,10,10,10,
  96282. 10,10,10,10,10,10,10,10,
  96283. 10,10,10,10,10,10,10,10,
  96284. 10,10,10,10,10,10,10,10,
  96285. 10,10,10,10,10,10,10,10,
  96286. 10,10,10,10,10,10,10,10,
  96287. 10,10,10,10,10,10,10,10,
  96288. 10,10,10,10,10,10,10,10,
  96289. 10,10,10,10,10,10,10,10,
  96290. 10,10,10,10,10,10,10,10,
  96291. 10,10,10,10,10,10,10,10,
  96292. 10,10,10,10,10,10,10,10,
  96293. 10,10,10,10,10,10,10,10,
  96294. 10,10,10,10,10,10,10,10,
  96295. 10,10,10,10,10,10,10,10,
  96296. 10,10,10,10,10,10,10,10,
  96297. 10,10,10,10,10,10,10,10,
  96298. 10,10,10,10,10,10,10,10,
  96299. 10,10,10,10,10,10,10};
  96300. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96301. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96302. 0x01,0x02,0x03,0x04,2,0,0,0,
  96303. 0x6c,0x3b,0x82,0x3d,
  96304. 1,
  96305. 50};
  96306. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96307. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96308. 0x01,0x02,0x03,0x04,0,0,0,0,
  96309. 0xff,0x7b,0x23,0x17,
  96310. 1,
  96311. 0};
  96312. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96313. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96314. 0x01,0x02,0x03,0x04,1,0,0,0,
  96315. 0x3c,0xd9,0x4d,0x3f,
  96316. 17,
  96317. 100,255,255,255,255,255,255,255,255,
  96318. 255,255,255,255,255,255,255,255};
  96319. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96320. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96321. 0x01,0x02,0x03,0x04,2,0,0,0,
  96322. 0x01,0xd2,0xe5,0xe5,
  96323. 17,
  96324. 255,255,255,255,255,255,255,255,
  96325. 255,255,255,255,255,255,255,255,255};
  96326. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96327. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96328. 0x01,0x02,0x03,0x04,3,0,0,0,
  96329. 0xef,0xdd,0x88,0xde,
  96330. 7,
  96331. 255,255,75,255,4,255,0};
  96332. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96333. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96334. 0x01,0x02,0x03,0x04,0,0,0,0,
  96335. 0xff,0x7b,0x23,0x17,
  96336. 1,
  96337. 0};
  96338. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96339. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96340. 0x01,0x02,0x03,0x04,1,0,0,0,
  96341. 0x3c,0xd9,0x4d,0x3f,
  96342. 17,
  96343. 100,255,255,255,255,255,255,255,255,
  96344. 255,255,255,255,255,255,255,255};
  96345. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96346. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96347. 0x01,0x02,0x03,0x04,2,0,0,0,
  96348. 0xd4,0xe0,0x60,0xe5,
  96349. 1,0};
  96350. void test_pack(const int *pl, const int **headers, int byteskip,
  96351. int pageskip, int packetskip){
  96352. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96353. long inptr=0;
  96354. long outptr=0;
  96355. long deptr=0;
  96356. long depacket=0;
  96357. long granule_pos=7,pageno=0;
  96358. int i,j,packets,pageout=pageskip;
  96359. int eosflag=0;
  96360. int bosflag=0;
  96361. int byteskipcount=0;
  96362. ogg_stream_reset(&os_en);
  96363. ogg_stream_reset(&os_de);
  96364. ogg_sync_reset(&oy);
  96365. for(packets=0;packets<packetskip;packets++)
  96366. depacket+=pl[packets];
  96367. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96368. for(i=0;i<packets;i++){
  96369. ogg_packet op;
  96370. int len=pl[i];
  96371. op.packet=data+inptr;
  96372. op.bytes=len;
  96373. op.e_o_s=(pl[i+1]<0?1:0);
  96374. op.granulepos=granule_pos;
  96375. granule_pos+=1024;
  96376. for(j=0;j<len;j++)data[inptr++]=i+j;
  96377. ogg_stream_packetin(&os_en,&op);
  96378. {
  96379. ogg_page og;
  96380. while(ogg_stream_pageout(&os_en,&og)){
  96381. fprintf(stderr,"%ld, ",pageno);
  96382. if(headers[pageno]==NULL){
  96383. fprintf(stderr,"coded too many pages!\n");
  96384. exit(1);
  96385. }
  96386. check_page(data+outptr,headers[pageno],&og);
  96387. outptr+=og.body_len;
  96388. pageno++;
  96389. if(pageskip){
  96390. bosflag=1;
  96391. pageskip--;
  96392. deptr+=og.body_len;
  96393. }
  96394. {
  96395. ogg_page og_de;
  96396. ogg_packet op_de,op_de2;
  96397. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96398. char *next=buf;
  96399. byteskipcount+=og.header_len;
  96400. if(byteskipcount>byteskip){
  96401. memcpy(next,og.header,byteskipcount-byteskip);
  96402. next+=byteskipcount-byteskip;
  96403. byteskipcount=byteskip;
  96404. }
  96405. byteskipcount+=og.body_len;
  96406. if(byteskipcount>byteskip){
  96407. memcpy(next,og.body,byteskipcount-byteskip);
  96408. next+=byteskipcount-byteskip;
  96409. byteskipcount=byteskip;
  96410. }
  96411. ogg_sync_wrote(&oy,next-buf);
  96412. while(1){
  96413. int ret=ogg_sync_pageout(&oy,&og_de);
  96414. if(ret==0)break;
  96415. if(ret<0)continue;
  96416. fprintf(stderr,"(%ld), ",pageout);
  96417. check_page(data+deptr,headers[pageout],&og_de);
  96418. deptr+=og_de.body_len;
  96419. pageout++;
  96420. ogg_stream_pagein(&os_de,&og_de);
  96421. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96422. ogg_stream_packetpeek(&os_de,NULL);
  96423. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96424. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96425. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96426. depacket);
  96427. exit(1);
  96428. }
  96429. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96430. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96431. depacket);
  96432. exit(1);
  96433. }
  96434. if(bosflag==0 && op_de.b_o_s==0){
  96435. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96436. exit(1);
  96437. }
  96438. if(bosflag && op_de.b_o_s){
  96439. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96440. exit(1);
  96441. }
  96442. bosflag=1;
  96443. depacket+=op_de.bytes;
  96444. if(eosflag){
  96445. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96446. exit(1);
  96447. }
  96448. if(op_de.e_o_s)eosflag=1;
  96449. if(op_de.granulepos!=-1){
  96450. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96451. }
  96452. }
  96453. }
  96454. }
  96455. }
  96456. }
  96457. }
  96458. _ogg_free(data);
  96459. if(headers[pageno]!=NULL){
  96460. fprintf(stderr,"did not write last page!\n");
  96461. exit(1);
  96462. }
  96463. if(headers[pageout]!=NULL){
  96464. fprintf(stderr,"did not decode last page!\n");
  96465. exit(1);
  96466. }
  96467. if(inptr!=outptr){
  96468. fprintf(stderr,"encoded page data incomplete!\n");
  96469. exit(1);
  96470. }
  96471. if(inptr!=deptr){
  96472. fprintf(stderr,"decoded page data incomplete!\n");
  96473. exit(1);
  96474. }
  96475. if(inptr!=depacket){
  96476. fprintf(stderr,"decoded packet data incomplete!\n");
  96477. exit(1);
  96478. }
  96479. if(!eosflag){
  96480. fprintf(stderr,"Never got a packet with EOS set!\n");
  96481. exit(1);
  96482. }
  96483. fprintf(stderr,"ok.\n");
  96484. }
  96485. int main(void){
  96486. ogg_stream_init(&os_en,0x04030201);
  96487. ogg_stream_init(&os_de,0x04030201);
  96488. ogg_sync_init(&oy);
  96489. {
  96490. const int packets[]={17, -1};
  96491. const int *headret[]={head1_0,NULL};
  96492. fprintf(stderr,"testing single page encoding... ");
  96493. test_pack(packets,headret,0,0,0);
  96494. }
  96495. {
  96496. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96497. const int *headret[]={head1_1,head2_1,NULL};
  96498. fprintf(stderr,"testing basic page encoding... ");
  96499. test_pack(packets,headret,0,0,0);
  96500. }
  96501. {
  96502. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96503. const int *headret[]={head1_2,head2_2,NULL};
  96504. fprintf(stderr,"testing basic nil packets... ");
  96505. test_pack(packets,headret,0,0,0);
  96506. }
  96507. {
  96508. const int packets[]={4345,259,255,-1};
  96509. const int *headret[]={head1_3,head2_3,NULL};
  96510. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96511. test_pack(packets,headret,0,0,0);
  96512. }
  96513. {
  96514. const int packets[]={0,4345,259,255,-1};
  96515. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96516. fprintf(stderr,"testing single packet page span... ");
  96517. test_pack(packets,headret,0,0,0);
  96518. }
  96519. {
  96520. const int packets[]={0,10,10,10,10,10,10,10,10,
  96521. 10,10,10,10,10,10,10,10,
  96522. 10,10,10,10,10,10,10,10,
  96523. 10,10,10,10,10,10,10,10,
  96524. 10,10,10,10,10,10,10,10,
  96525. 10,10,10,10,10,10,10,10,
  96526. 10,10,10,10,10,10,10,10,
  96527. 10,10,10,10,10,10,10,10,
  96528. 10,10,10,10,10,10,10,10,
  96529. 10,10,10,10,10,10,10,10,
  96530. 10,10,10,10,10,10,10,10,
  96531. 10,10,10,10,10,10,10,10,
  96532. 10,10,10,10,10,10,10,10,
  96533. 10,10,10,10,10,10,10,10,
  96534. 10,10,10,10,10,10,10,10,
  96535. 10,10,10,10,10,10,10,10,
  96536. 10,10,10,10,10,10,10,10,
  96537. 10,10,10,10,10,10,10,10,
  96538. 10,10,10,10,10,10,10,10,
  96539. 10,10,10,10,10,10,10,10,
  96540. 10,10,10,10,10,10,10,10,
  96541. 10,10,10,10,10,10,10,10,
  96542. 10,10,10,10,10,10,10,10,
  96543. 10,10,10,10,10,10,10,10,
  96544. 10,10,10,10,10,10,10,10,
  96545. 10,10,10,10,10,10,10,10,
  96546. 10,10,10,10,10,10,10,10,
  96547. 10,10,10,10,10,10,10,10,
  96548. 10,10,10,10,10,10,10,10,
  96549. 10,10,10,10,10,10,10,10,
  96550. 10,10,10,10,10,10,10,10,
  96551. 10,10,10,10,10,10,10,50,-1};
  96552. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96553. fprintf(stderr,"testing max packet segments... ");
  96554. test_pack(packets,headret,0,0,0);
  96555. }
  96556. {
  96557. const int packets[]={0,100,9000,259,255,-1};
  96558. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96559. fprintf(stderr,"testing very large packets... ");
  96560. test_pack(packets,headret,0,0,0);
  96561. }
  96562. {
  96563. const int packets[]={0,100,9000,259,255,-1};
  96564. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96565. fprintf(stderr,"testing continuation resync in very large packets... ");
  96566. test_pack(packets,headret,100,2,3);
  96567. }
  96568. {
  96569. const int packets[]={0,100,4080,-1};
  96570. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96571. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96572. test_pack(packets,headret,0,0,0);
  96573. }
  96574. {
  96575. unsigned char *data=_ogg_malloc(1024*1024);
  96576. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96577. int inptr=0,i,j;
  96578. ogg_page og[5];
  96579. ogg_stream_reset(&os_en);
  96580. for(i=0;pl[i]!=-1;i++){
  96581. ogg_packet op;
  96582. int len=pl[i];
  96583. op.packet=data+inptr;
  96584. op.bytes=len;
  96585. op.e_o_s=(pl[i+1]<0?1:0);
  96586. op.granulepos=(i+1)*1000;
  96587. for(j=0;j<len;j++)data[inptr++]=i+j;
  96588. ogg_stream_packetin(&os_en,&op);
  96589. }
  96590. _ogg_free(data);
  96591. for(i=0;i<5;i++){
  96592. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96593. fprintf(stderr,"Too few pages output building sync tests!\n");
  96594. exit(1);
  96595. }
  96596. copy_page(&og[i]);
  96597. }
  96598. {
  96599. ogg_page temp;
  96600. ogg_packet test;
  96601. fprintf(stderr,"Testing loss of pages... ");
  96602. ogg_sync_reset(&oy);
  96603. ogg_stream_reset(&os_de);
  96604. for(i=0;i<5;i++){
  96605. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96606. og[i].header_len);
  96607. ogg_sync_wrote(&oy,og[i].header_len);
  96608. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96609. ogg_sync_wrote(&oy,og[i].body_len);
  96610. }
  96611. ogg_sync_pageout(&oy,&temp);
  96612. ogg_stream_pagein(&os_de,&temp);
  96613. ogg_sync_pageout(&oy,&temp);
  96614. ogg_stream_pagein(&os_de,&temp);
  96615. ogg_sync_pageout(&oy,&temp);
  96616. ogg_sync_pageout(&oy,&temp);
  96617. ogg_stream_pagein(&os_de,&temp);
  96618. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96619. checkpacket(&test,0,0,0);
  96620. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96621. checkpacket(&test,100,1,-1);
  96622. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96623. checkpacket(&test,4079,2,3000);
  96624. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96625. fprintf(stderr,"Error: loss of page did not return error\n");
  96626. exit(1);
  96627. }
  96628. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96629. checkpacket(&test,76,5,-1);
  96630. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96631. checkpacket(&test,34,6,-1);
  96632. fprintf(stderr,"ok.\n");
  96633. }
  96634. {
  96635. ogg_page temp;
  96636. ogg_packet test;
  96637. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96638. ogg_sync_reset(&oy);
  96639. ogg_stream_reset(&os_de);
  96640. for(i=0;i<5;i++){
  96641. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96642. og[i].header_len);
  96643. ogg_sync_wrote(&oy,og[i].header_len);
  96644. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96645. ogg_sync_wrote(&oy,og[i].body_len);
  96646. }
  96647. ogg_sync_pageout(&oy,&temp);
  96648. ogg_stream_pagein(&os_de,&temp);
  96649. ogg_sync_pageout(&oy,&temp);
  96650. ogg_stream_pagein(&os_de,&temp);
  96651. ogg_sync_pageout(&oy,&temp);
  96652. ogg_stream_pagein(&os_de,&temp);
  96653. ogg_sync_pageout(&oy,&temp);
  96654. ogg_sync_pageout(&oy,&temp);
  96655. ogg_stream_pagein(&os_de,&temp);
  96656. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96657. checkpacket(&test,0,0,0);
  96658. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96659. checkpacket(&test,100,1,-1);
  96660. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96661. checkpacket(&test,4079,2,3000);
  96662. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96663. checkpacket(&test,2956,3,4000);
  96664. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96665. fprintf(stderr,"Error: loss of page did not return error\n");
  96666. exit(1);
  96667. }
  96668. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96669. checkpacket(&test,300,13,14000);
  96670. fprintf(stderr,"ok.\n");
  96671. }
  96672. {
  96673. ogg_page og_de;
  96674. fprintf(stderr,"Testing sync on partial inputs... ");
  96675. ogg_sync_reset(&oy);
  96676. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96677. 3);
  96678. ogg_sync_wrote(&oy,3);
  96679. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96680. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  96681. 20);
  96682. ogg_sync_wrote(&oy,20);
  96683. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96684. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  96685. 5);
  96686. ogg_sync_wrote(&oy,5);
  96687. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96688. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  96689. og[1].header_len-28);
  96690. ogg_sync_wrote(&oy,og[1].header_len-28);
  96691. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96692. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  96693. ogg_sync_wrote(&oy,1000);
  96694. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96695. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  96696. og[1].body_len-1000);
  96697. ogg_sync_wrote(&oy,og[1].body_len-1000);
  96698. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96699. fprintf(stderr,"ok.\n");
  96700. }
  96701. {
  96702. ogg_page og_de;
  96703. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  96704. ogg_sync_reset(&oy);
  96705. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96706. og[1].header_len);
  96707. ogg_sync_wrote(&oy,og[1].header_len);
  96708. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96709. og[1].body_len);
  96710. ogg_sync_wrote(&oy,og[1].body_len);
  96711. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96712. 20);
  96713. ogg_sync_wrote(&oy,20);
  96714. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96715. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96716. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  96717. og[1].header_len-20);
  96718. ogg_sync_wrote(&oy,og[1].header_len-20);
  96719. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96720. og[1].body_len);
  96721. ogg_sync_wrote(&oy,og[1].body_len);
  96722. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96723. fprintf(stderr,"ok.\n");
  96724. }
  96725. {
  96726. ogg_page og_de;
  96727. fprintf(stderr,"Testing search for capture... ");
  96728. ogg_sync_reset(&oy);
  96729. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96730. og[1].body_len);
  96731. ogg_sync_wrote(&oy,og[1].body_len);
  96732. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96733. og[1].header_len);
  96734. ogg_sync_wrote(&oy,og[1].header_len);
  96735. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96736. og[1].body_len);
  96737. ogg_sync_wrote(&oy,og[1].body_len);
  96738. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96739. 20);
  96740. ogg_sync_wrote(&oy,20);
  96741. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96742. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96743. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96744. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  96745. og[2].header_len-20);
  96746. ogg_sync_wrote(&oy,og[2].header_len-20);
  96747. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96748. og[2].body_len);
  96749. ogg_sync_wrote(&oy,og[2].body_len);
  96750. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96751. fprintf(stderr,"ok.\n");
  96752. }
  96753. {
  96754. ogg_page og_de;
  96755. fprintf(stderr,"Testing recapture... ");
  96756. ogg_sync_reset(&oy);
  96757. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96758. og[1].header_len);
  96759. ogg_sync_wrote(&oy,og[1].header_len);
  96760. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96761. og[1].body_len);
  96762. ogg_sync_wrote(&oy,og[1].body_len);
  96763. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96764. og[2].header_len);
  96765. ogg_sync_wrote(&oy,og[2].header_len);
  96766. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96767. og[2].header_len);
  96768. ogg_sync_wrote(&oy,og[2].header_len);
  96769. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96770. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96771. og[2].body_len-5);
  96772. ogg_sync_wrote(&oy,og[2].body_len-5);
  96773. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  96774. og[3].header_len);
  96775. ogg_sync_wrote(&oy,og[3].header_len);
  96776. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  96777. og[3].body_len);
  96778. ogg_sync_wrote(&oy,og[3].body_len);
  96779. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96780. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96781. fprintf(stderr,"ok.\n");
  96782. }
  96783. {
  96784. for(i=0;i<5;i++){
  96785. free_page(&og[i]);
  96786. }
  96787. }
  96788. }
  96789. return(0);
  96790. }
  96791. #endif
  96792. #endif
  96793. /*** End of inlined file: framing.c ***/
  96794. /*** Start of inlined file: analysis.c ***/
  96795. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  96796. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  96797. // tasks..
  96798. #if JUCE_MSVC
  96799. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  96800. #endif
  96801. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  96802. #if JUCE_USE_OGGVORBIS
  96803. #include <stdio.h>
  96804. #include <string.h>
  96805. #include <math.h>
  96806. /*** Start of inlined file: codec_internal.h ***/
  96807. #ifndef _V_CODECI_H_
  96808. #define _V_CODECI_H_
  96809. /*** Start of inlined file: envelope.h ***/
  96810. #ifndef _V_ENVELOPE_
  96811. #define _V_ENVELOPE_
  96812. /*** Start of inlined file: mdct.h ***/
  96813. #ifndef _OGG_mdct_H_
  96814. #define _OGG_mdct_H_
  96815. #ifdef MDCT_INTEGERIZED
  96816. #define DATA_TYPE int
  96817. #define REG_TYPE register int
  96818. #define TRIGBITS 14
  96819. #define cPI3_8 6270
  96820. #define cPI2_8 11585
  96821. #define cPI1_8 15137
  96822. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  96823. #define MULT_NORM(x) ((x)>>TRIGBITS)
  96824. #define HALVE(x) ((x)>>1)
  96825. #else
  96826. #define DATA_TYPE float
  96827. #define REG_TYPE float
  96828. #define cPI3_8 .38268343236508977175F
  96829. #define cPI2_8 .70710678118654752441F
  96830. #define cPI1_8 .92387953251128675613F
  96831. #define FLOAT_CONV(x) (x)
  96832. #define MULT_NORM(x) (x)
  96833. #define HALVE(x) ((x)*.5f)
  96834. #endif
  96835. typedef struct {
  96836. int n;
  96837. int log2n;
  96838. DATA_TYPE *trig;
  96839. int *bitrev;
  96840. DATA_TYPE scale;
  96841. } mdct_lookup;
  96842. extern void mdct_init(mdct_lookup *lookup,int n);
  96843. extern void mdct_clear(mdct_lookup *l);
  96844. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96845. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96846. #endif
  96847. /*** End of inlined file: mdct.h ***/
  96848. #define VE_PRE 16
  96849. #define VE_WIN 4
  96850. #define VE_POST 2
  96851. #define VE_AMP (VE_PRE+VE_POST-1)
  96852. #define VE_BANDS 7
  96853. #define VE_NEARDC 15
  96854. #define VE_MINSTRETCH 2 /* a bit less than short block */
  96855. #define VE_MAXSTRETCH 12 /* one-third full block */
  96856. typedef struct {
  96857. float ampbuf[VE_AMP];
  96858. int ampptr;
  96859. float nearDC[VE_NEARDC];
  96860. float nearDC_acc;
  96861. float nearDC_partialacc;
  96862. int nearptr;
  96863. } envelope_filter_state;
  96864. typedef struct {
  96865. int begin;
  96866. int end;
  96867. float *window;
  96868. float total;
  96869. } envelope_band;
  96870. typedef struct {
  96871. int ch;
  96872. int winlength;
  96873. int searchstep;
  96874. float minenergy;
  96875. mdct_lookup mdct;
  96876. float *mdct_win;
  96877. envelope_band band[VE_BANDS];
  96878. envelope_filter_state *filter;
  96879. int stretch;
  96880. int *mark;
  96881. long storage;
  96882. long current;
  96883. long curmark;
  96884. long cursor;
  96885. } envelope_lookup;
  96886. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  96887. extern void _ve_envelope_clear(envelope_lookup *e);
  96888. extern long _ve_envelope_search(vorbis_dsp_state *v);
  96889. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  96890. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  96891. #endif
  96892. /*** End of inlined file: envelope.h ***/
  96893. /*** Start of inlined file: codebook.h ***/
  96894. #ifndef _V_CODEBOOK_H_
  96895. #define _V_CODEBOOK_H_
  96896. typedef struct static_codebook{
  96897. long dim; /* codebook dimensions (elements per vector) */
  96898. long entries; /* codebook entries */
  96899. long *lengthlist; /* codeword lengths in bits */
  96900. int maptype; /* 0=none
  96901. 1=implicitly populated values from map column
  96902. 2=listed arbitrary values */
  96903. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  96904. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  96905. int q_quant; /* bits: 0 < quant <= 16 */
  96906. int q_sequencep; /* bitflag */
  96907. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  96908. map == 2: list of dim*entries quantized entry vals
  96909. */
  96910. struct encode_aux_nearestmatch *nearest_tree;
  96911. struct encode_aux_threshmatch *thresh_tree;
  96912. struct encode_aux_pigeonhole *pigeon_tree;
  96913. int allocedp;
  96914. } static_codebook;
  96915. typedef struct encode_aux_nearestmatch{
  96916. long *ptr0;
  96917. long *ptr1;
  96918. long *p; /* decision points (each is an entry) */
  96919. long *q; /* decision points (each is an entry) */
  96920. long aux; /* number of tree entries */
  96921. long alloc;
  96922. } encode_aux_nearestmatch;
  96923. typedef struct encode_aux_threshmatch{
  96924. float *quantthresh;
  96925. long *quantmap;
  96926. int quantvals;
  96927. int threshvals;
  96928. } encode_aux_threshmatch;
  96929. typedef struct encode_aux_pigeonhole{
  96930. float min;
  96931. float del;
  96932. int mapentries;
  96933. int quantvals;
  96934. long *pigeonmap;
  96935. long fittotal;
  96936. long *fitlist;
  96937. long *fitmap;
  96938. long *fitlength;
  96939. } encode_aux_pigeonhole;
  96940. typedef struct codebook{
  96941. long dim; /* codebook dimensions (elements per vector) */
  96942. long entries; /* codebook entries */
  96943. long used_entries; /* populated codebook entries */
  96944. const static_codebook *c;
  96945. float *valuelist; /* list of dim*entries actual entry values */
  96946. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  96947. int *dec_index; /* only used if sparseness collapsed */
  96948. char *dec_codelengths;
  96949. ogg_uint32_t *dec_firsttable;
  96950. int dec_firsttablen;
  96951. int dec_maxlength;
  96952. } codebook;
  96953. extern void vorbis_staticbook_clear(static_codebook *b);
  96954. extern void vorbis_staticbook_destroy(static_codebook *b);
  96955. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  96956. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  96957. extern void vorbis_book_clear(codebook *b);
  96958. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  96959. extern float *_book_logdist(const static_codebook *b,float *vals);
  96960. extern float _float32_unpack(long val);
  96961. extern long _float32_pack(float val);
  96962. extern int _best(codebook *book, float *a, int step);
  96963. extern int _ilog(unsigned int v);
  96964. extern long _book_maptype1_quantvals(const static_codebook *b);
  96965. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  96966. extern long vorbis_book_codeword(codebook *book,int entry);
  96967. extern long vorbis_book_codelen(codebook *book,int entry);
  96968. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  96969. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  96970. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  96971. extern int vorbis_book_errorv(codebook *book, float *a);
  96972. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  96973. oggpack_buffer *b);
  96974. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  96975. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  96976. oggpack_buffer *b,int n);
  96977. extern long vorbis_book_decodev_set(codebook *book, float *a,
  96978. oggpack_buffer *b,int n);
  96979. extern long vorbis_book_decodev_add(codebook *book, float *a,
  96980. oggpack_buffer *b,int n);
  96981. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  96982. long off,int ch,
  96983. oggpack_buffer *b,int n);
  96984. #endif
  96985. /*** End of inlined file: codebook.h ***/
  96986. #define BLOCKTYPE_IMPULSE 0
  96987. #define BLOCKTYPE_PADDING 1
  96988. #define BLOCKTYPE_TRANSITION 0
  96989. #define BLOCKTYPE_LONG 1
  96990. #define PACKETBLOBS 15
  96991. typedef struct vorbis_block_internal{
  96992. float **pcmdelay; /* this is a pointer into local storage */
  96993. float ampmax;
  96994. int blocktype;
  96995. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  96996. blob [PACKETBLOBS/2] points to
  96997. the oggpack_buffer in the
  96998. main vorbis_block */
  96999. } vorbis_block_internal;
  97000. typedef void vorbis_look_floor;
  97001. typedef void vorbis_look_residue;
  97002. typedef void vorbis_look_transform;
  97003. typedef struct {
  97004. int blockflag;
  97005. int windowtype;
  97006. int transformtype;
  97007. int mapping;
  97008. } vorbis_info_mode;
  97009. typedef void vorbis_info_floor;
  97010. typedef void vorbis_info_residue;
  97011. typedef void vorbis_info_mapping;
  97012. /*** Start of inlined file: psy.h ***/
  97013. #ifndef _V_PSY_H_
  97014. #define _V_PSY_H_
  97015. /*** Start of inlined file: smallft.h ***/
  97016. #ifndef _V_SMFT_H_
  97017. #define _V_SMFT_H_
  97018. typedef struct {
  97019. int n;
  97020. float *trigcache;
  97021. int *splitcache;
  97022. } drft_lookup;
  97023. extern void drft_forward(drft_lookup *l,float *data);
  97024. extern void drft_backward(drft_lookup *l,float *data);
  97025. extern void drft_init(drft_lookup *l,int n);
  97026. extern void drft_clear(drft_lookup *l);
  97027. #endif
  97028. /*** End of inlined file: smallft.h ***/
  97029. /*** Start of inlined file: backends.h ***/
  97030. #ifndef _vorbis_backend_h_
  97031. #define _vorbis_backend_h_
  97032. typedef struct{
  97033. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  97034. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  97035. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  97036. void (*free_info) (vorbis_info_floor *);
  97037. void (*free_look) (vorbis_look_floor *);
  97038. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  97039. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  97040. void *buffer,float *);
  97041. } vorbis_func_floor;
  97042. typedef struct{
  97043. int order;
  97044. long rate;
  97045. long barkmap;
  97046. int ampbits;
  97047. int ampdB;
  97048. int numbooks; /* <= 16 */
  97049. int books[16];
  97050. float lessthan; /* encode-only config setting hacks for libvorbis */
  97051. float greaterthan; /* encode-only config setting hacks for libvorbis */
  97052. } vorbis_info_floor0;
  97053. #define VIF_POSIT 63
  97054. #define VIF_CLASS 16
  97055. #define VIF_PARTS 31
  97056. typedef struct{
  97057. int partitions; /* 0 to 31 */
  97058. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  97059. int class_dim[VIF_CLASS]; /* 1 to 8 */
  97060. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  97061. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  97062. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  97063. int mult; /* 1 2 3 or 4 */
  97064. int postlist[VIF_POSIT+2]; /* first two implicit */
  97065. float maxover;
  97066. float maxunder;
  97067. float maxerr;
  97068. float twofitweight;
  97069. float twofitatten;
  97070. int n;
  97071. } vorbis_info_floor1;
  97072. typedef struct{
  97073. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  97074. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  97075. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  97076. vorbis_info_residue *);
  97077. void (*free_info) (vorbis_info_residue *);
  97078. void (*free_look) (vorbis_look_residue *);
  97079. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  97080. float **,int *,int);
  97081. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  97082. vorbis_look_residue *,
  97083. float **,float **,int *,int,long **);
  97084. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  97085. float **,int *,int);
  97086. } vorbis_func_residue;
  97087. typedef struct vorbis_info_residue0{
  97088. long begin;
  97089. long end;
  97090. int grouping; /* group n vectors per partition */
  97091. int partitions; /* possible codebooks for a partition */
  97092. int groupbook; /* huffbook for partitioning */
  97093. int secondstages[64]; /* expanded out to pointers in lookup */
  97094. int booklist[256]; /* list of second stage books */
  97095. float classmetric1[64];
  97096. float classmetric2[64];
  97097. } vorbis_info_residue0;
  97098. typedef struct{
  97099. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  97100. oggpack_buffer *);
  97101. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  97102. void (*free_info) (vorbis_info_mapping *);
  97103. int (*forward) (struct vorbis_block *vb);
  97104. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  97105. } vorbis_func_mapping;
  97106. typedef struct vorbis_info_mapping0{
  97107. int submaps; /* <= 16 */
  97108. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  97109. int floorsubmap[16]; /* [mux] submap to floors */
  97110. int residuesubmap[16]; /* [mux] submap to residue */
  97111. int coupling_steps;
  97112. int coupling_mag[256];
  97113. int coupling_ang[256];
  97114. } vorbis_info_mapping0;
  97115. #endif
  97116. /*** End of inlined file: backends.h ***/
  97117. #ifndef EHMER_MAX
  97118. #define EHMER_MAX 56
  97119. #endif
  97120. #define P_BANDS 17 /* 62Hz to 16kHz */
  97121. #define P_LEVELS 8 /* 30dB to 100dB */
  97122. #define P_LEVEL_0 30. /* 30 dB */
  97123. #define P_NOISECURVES 3
  97124. #define NOISE_COMPAND_LEVELS 40
  97125. typedef struct vorbis_info_psy{
  97126. int blockflag;
  97127. float ath_adjatt;
  97128. float ath_maxatt;
  97129. float tone_masteratt[P_NOISECURVES];
  97130. float tone_centerboost;
  97131. float tone_decay;
  97132. float tone_abs_limit;
  97133. float toneatt[P_BANDS];
  97134. int noisemaskp;
  97135. float noisemaxsupp;
  97136. float noisewindowlo;
  97137. float noisewindowhi;
  97138. int noisewindowlomin;
  97139. int noisewindowhimin;
  97140. int noisewindowfixed;
  97141. float noiseoff[P_NOISECURVES][P_BANDS];
  97142. float noisecompand[NOISE_COMPAND_LEVELS];
  97143. float max_curve_dB;
  97144. int normal_channel_p;
  97145. int normal_point_p;
  97146. int normal_start;
  97147. int normal_partition;
  97148. double normal_thresh;
  97149. } vorbis_info_psy;
  97150. typedef struct{
  97151. int eighth_octave_lines;
  97152. float preecho_thresh[VE_BANDS];
  97153. float postecho_thresh[VE_BANDS];
  97154. float stretch_penalty;
  97155. float preecho_minenergy;
  97156. float ampmax_att_per_sec;
  97157. int coupling_pkHz[PACKETBLOBS];
  97158. int coupling_pointlimit[2][PACKETBLOBS];
  97159. int coupling_prepointamp[PACKETBLOBS];
  97160. int coupling_postpointamp[PACKETBLOBS];
  97161. int sliding_lowpass[2][PACKETBLOBS];
  97162. } vorbis_info_psy_global;
  97163. typedef struct {
  97164. float ampmax;
  97165. int channels;
  97166. vorbis_info_psy_global *gi;
  97167. int coupling_pointlimit[2][P_NOISECURVES];
  97168. } vorbis_look_psy_global;
  97169. typedef struct {
  97170. int n;
  97171. struct vorbis_info_psy *vi;
  97172. float ***tonecurves;
  97173. float **noiseoffset;
  97174. float *ath;
  97175. long *octave; /* in n.ocshift format */
  97176. long *bark;
  97177. long firstoc;
  97178. long shiftoc;
  97179. int eighth_octave_lines; /* power of two, please */
  97180. int total_octave_lines;
  97181. long rate; /* cache it */
  97182. float m_val; /* Masking compensation value */
  97183. } vorbis_look_psy;
  97184. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  97185. vorbis_info_psy_global *gi,int n,long rate);
  97186. extern void _vp_psy_clear(vorbis_look_psy *p);
  97187. extern void *_vi_psy_dup(void *source);
  97188. extern void _vi_psy_free(vorbis_info_psy *i);
  97189. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  97190. extern void _vp_remove_floor(vorbis_look_psy *p,
  97191. float *mdct,
  97192. int *icodedflr,
  97193. float *residue,
  97194. int sliding_lowpass);
  97195. extern void _vp_noisemask(vorbis_look_psy *p,
  97196. float *logmdct,
  97197. float *logmask);
  97198. extern void _vp_tonemask(vorbis_look_psy *p,
  97199. float *logfft,
  97200. float *logmask,
  97201. float global_specmax,
  97202. float local_specmax);
  97203. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  97204. float *noise,
  97205. float *tone,
  97206. int offset_select,
  97207. float *logmask,
  97208. float *mdct,
  97209. float *logmdct);
  97210. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  97211. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  97212. vorbis_info_psy_global *g,
  97213. vorbis_look_psy *p,
  97214. vorbis_info_mapping0 *vi,
  97215. float **mdct);
  97216. extern void _vp_couple(int blobno,
  97217. vorbis_info_psy_global *g,
  97218. vorbis_look_psy *p,
  97219. vorbis_info_mapping0 *vi,
  97220. float **res,
  97221. float **mag_memo,
  97222. int **mag_sort,
  97223. int **ifloor,
  97224. int *nonzero,
  97225. int sliding_lowpass);
  97226. extern void _vp_noise_normalize(vorbis_look_psy *p,
  97227. float *in,float *out,int *sortedindex);
  97228. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  97229. float *magnitudes,int *sortedindex);
  97230. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  97231. vorbis_look_psy *p,
  97232. vorbis_info_mapping0 *vi,
  97233. float **mags);
  97234. extern void hf_reduction(vorbis_info_psy_global *g,
  97235. vorbis_look_psy *p,
  97236. vorbis_info_mapping0 *vi,
  97237. float **mdct);
  97238. #endif
  97239. /*** End of inlined file: psy.h ***/
  97240. /*** Start of inlined file: bitrate.h ***/
  97241. #ifndef _V_BITRATE_H_
  97242. #define _V_BITRATE_H_
  97243. /*** Start of inlined file: os.h ***/
  97244. #ifndef _OS_H
  97245. #define _OS_H
  97246. #ifdef HAVE_CONFIG_H
  97247. #include "config.h"
  97248. #endif
  97249. #include <math.h>
  97250. /*** Start of inlined file: misc.h ***/
  97251. #ifndef _V_RANDOM_H_
  97252. #define _V_RANDOM_H_
  97253. extern int analysis_noisy;
  97254. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  97255. extern void _vorbis_block_ripcord(vorbis_block *vb);
  97256. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97257. ogg_int64_t off);
  97258. #ifdef DEBUG_MALLOC
  97259. #define _VDBG_GRAPHFILE "malloc.m"
  97260. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  97261. extern void _VDBG_free(void *ptr,char *file,long line);
  97262. #ifndef MISC_C
  97263. #undef _ogg_malloc
  97264. #undef _ogg_calloc
  97265. #undef _ogg_realloc
  97266. #undef _ogg_free
  97267. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  97268. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  97269. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  97270. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  97271. #endif
  97272. #endif
  97273. #endif
  97274. /*** End of inlined file: misc.h ***/
  97275. #ifndef _V_IFDEFJAIL_H_
  97276. # define _V_IFDEFJAIL_H_
  97277. # ifdef __GNUC__
  97278. # define STIN static __inline__
  97279. # elif _WIN32
  97280. # define STIN static __inline
  97281. # else
  97282. # define STIN static
  97283. # endif
  97284. #ifdef DJGPP
  97285. # define rint(x) (floor((x)+0.5f))
  97286. #endif
  97287. #ifndef M_PI
  97288. # define M_PI (3.1415926536f)
  97289. #endif
  97290. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97291. # include <malloc.h>
  97292. # define rint(x) (floor((x)+0.5f))
  97293. # define NO_FLOAT_MATH_LIB
  97294. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97295. #endif
  97296. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97297. void *_alloca(size_t size);
  97298. # define alloca _alloca
  97299. #endif
  97300. #ifndef FAST_HYPOT
  97301. # define FAST_HYPOT hypot
  97302. #endif
  97303. #endif
  97304. #ifdef HAVE_ALLOCA_H
  97305. # include <alloca.h>
  97306. #endif
  97307. #ifdef USE_MEMORY_H
  97308. # include <memory.h>
  97309. #endif
  97310. #ifndef min
  97311. # define min(x,y) ((x)>(y)?(y):(x))
  97312. #endif
  97313. #ifndef max
  97314. # define max(x,y) ((x)<(y)?(y):(x))
  97315. #endif
  97316. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97317. # define VORBIS_FPU_CONTROL
  97318. typedef ogg_int16_t vorbis_fpu_control;
  97319. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97320. ogg_int16_t ret;
  97321. ogg_int16_t temp;
  97322. __asm__ __volatile__("fnstcw %0\n\t"
  97323. "movw %0,%%dx\n\t"
  97324. "orw $62463,%%dx\n\t"
  97325. "movw %%dx,%1\n\t"
  97326. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97327. *fpu=ret;
  97328. }
  97329. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97330. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97331. }
  97332. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97333. we get extra fst/fld to
  97334. truncate precision */
  97335. int i;
  97336. __asm__("fistl %0": "=m"(i) : "t"(f));
  97337. return(i);
  97338. }
  97339. #endif
  97340. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97341. # define VORBIS_FPU_CONTROL
  97342. typedef ogg_int16_t vorbis_fpu_control;
  97343. static __inline int vorbis_ftoi(double f){
  97344. int i;
  97345. __asm{
  97346. fld f
  97347. fistp i
  97348. }
  97349. return i;
  97350. }
  97351. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97352. }
  97353. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97354. }
  97355. #endif
  97356. #ifndef VORBIS_FPU_CONTROL
  97357. typedef int vorbis_fpu_control;
  97358. static int vorbis_ftoi(double f){
  97359. return (int)(f+.5);
  97360. }
  97361. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97362. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97363. #endif
  97364. #endif /* _OS_H */
  97365. /*** End of inlined file: os.h ***/
  97366. typedef struct bitrate_manager_state {
  97367. int managed;
  97368. long avg_reservoir;
  97369. long minmax_reservoir;
  97370. long avg_bitsper;
  97371. long min_bitsper;
  97372. long max_bitsper;
  97373. long short_per_long;
  97374. double avgfloat;
  97375. vorbis_block *vb;
  97376. int choice;
  97377. } bitrate_manager_state;
  97378. typedef struct bitrate_manager_info{
  97379. long avg_rate;
  97380. long min_rate;
  97381. long max_rate;
  97382. long reservoir_bits;
  97383. double reservoir_bias;
  97384. double slew_damp;
  97385. } bitrate_manager_info;
  97386. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  97387. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  97388. extern int vorbis_bitrate_managed(vorbis_block *vb);
  97389. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  97390. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  97391. #endif
  97392. /*** End of inlined file: bitrate.h ***/
  97393. static int ilog(unsigned int v){
  97394. int ret=0;
  97395. while(v){
  97396. ret++;
  97397. v>>=1;
  97398. }
  97399. return(ret);
  97400. }
  97401. static int ilog2(unsigned int v){
  97402. int ret=0;
  97403. if(v)--v;
  97404. while(v){
  97405. ret++;
  97406. v>>=1;
  97407. }
  97408. return(ret);
  97409. }
  97410. typedef struct private_state {
  97411. envelope_lookup *ve; /* envelope lookup */
  97412. int window[2];
  97413. vorbis_look_transform **transform[2]; /* block, type */
  97414. drft_lookup fft_look[2];
  97415. int modebits;
  97416. vorbis_look_floor **flr;
  97417. vorbis_look_residue **residue;
  97418. vorbis_look_psy *psy;
  97419. vorbis_look_psy_global *psy_g_look;
  97420. unsigned char *header;
  97421. unsigned char *header1;
  97422. unsigned char *header2;
  97423. bitrate_manager_state bms;
  97424. ogg_int64_t sample_count;
  97425. } private_state;
  97426. /*** Start of inlined file: highlevel.h ***/
  97427. typedef struct highlevel_byblocktype {
  97428. double tone_mask_setting;
  97429. double tone_peaklimit_setting;
  97430. double noise_bias_setting;
  97431. double noise_compand_setting;
  97432. } highlevel_byblocktype;
  97433. typedef struct highlevel_encode_setup {
  97434. void *setup;
  97435. int set_in_stone;
  97436. double base_setting;
  97437. double long_setting;
  97438. double short_setting;
  97439. double impulse_noisetune;
  97440. int managed;
  97441. long bitrate_min;
  97442. long bitrate_av;
  97443. double bitrate_av_damp;
  97444. long bitrate_max;
  97445. long bitrate_reservoir;
  97446. double bitrate_reservoir_bias;
  97447. int impulse_block_p;
  97448. int noise_normalize_p;
  97449. double stereo_point_setting;
  97450. double lowpass_kHz;
  97451. double ath_floating_dB;
  97452. double ath_absolute_dB;
  97453. double amplitude_track_dBpersec;
  97454. double trigger_setting;
  97455. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97456. } highlevel_encode_setup;
  97457. /*** End of inlined file: highlevel.h ***/
  97458. typedef struct codec_setup_info {
  97459. long blocksizes[2];
  97460. int modes;
  97461. int maps;
  97462. int floors;
  97463. int residues;
  97464. int books;
  97465. int psys; /* encode only */
  97466. vorbis_info_mode *mode_param[64];
  97467. int map_type[64];
  97468. vorbis_info_mapping *map_param[64];
  97469. int floor_type[64];
  97470. vorbis_info_floor *floor_param[64];
  97471. int residue_type[64];
  97472. vorbis_info_residue *residue_param[64];
  97473. static_codebook *book_param[256];
  97474. codebook *fullbooks;
  97475. vorbis_info_psy *psy_param[4]; /* encode only */
  97476. vorbis_info_psy_global psy_g_param;
  97477. bitrate_manager_info bi;
  97478. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97479. highly redundant structure, but
  97480. improves clarity of program flow. */
  97481. int halfrate_flag; /* painless downsample for decode */
  97482. } codec_setup_info;
  97483. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97484. extern void _vp_global_free(vorbis_look_psy_global *look);
  97485. #endif
  97486. /*** End of inlined file: codec_internal.h ***/
  97487. /*** Start of inlined file: registry.h ***/
  97488. #ifndef _V_REG_H_
  97489. #define _V_REG_H_
  97490. #define VI_TRANSFORMB 1
  97491. #define VI_WINDOWB 1
  97492. #define VI_TIMEB 1
  97493. #define VI_FLOORB 2
  97494. #define VI_RESB 3
  97495. #define VI_MAPB 1
  97496. extern vorbis_func_floor *_floor_P[];
  97497. extern vorbis_func_residue *_residue_P[];
  97498. extern vorbis_func_mapping *_mapping_P[];
  97499. #endif
  97500. /*** End of inlined file: registry.h ***/
  97501. /*** Start of inlined file: scales.h ***/
  97502. #ifndef _V_SCALES_H_
  97503. #define _V_SCALES_H_
  97504. #include <math.h>
  97505. #define VORBIS_IEEE_FLOAT32 1
  97506. #ifdef VORBIS_IEEE_FLOAT32
  97507. static float unitnorm(float x){
  97508. union {
  97509. ogg_uint32_t i;
  97510. float f;
  97511. } ix;
  97512. ix.f = x;
  97513. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97514. return ix.f;
  97515. }
  97516. static float todB(const float *x){
  97517. union {
  97518. ogg_uint32_t i;
  97519. float f;
  97520. } ix;
  97521. ix.f = *x;
  97522. ix.i = ix.i&0x7fffffff;
  97523. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97524. }
  97525. #define todB_nn(x) todB(x)
  97526. #else
  97527. static float unitnorm(float x){
  97528. if(x<0)return(-1.f);
  97529. return(1.f);
  97530. }
  97531. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97532. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97533. #endif
  97534. #define fromdB(x) (exp((x)*.11512925f))
  97535. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97536. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97537. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97538. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97539. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97540. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97541. #endif
  97542. /*** End of inlined file: scales.h ***/
  97543. int analysis_noisy=1;
  97544. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97545. int ret,i;
  97546. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97547. vb->glue_bits=0;
  97548. vb->time_bits=0;
  97549. vb->floor_bits=0;
  97550. vb->res_bits=0;
  97551. for(i=0;i<PACKETBLOBS;i++)
  97552. oggpack_reset(vbi->packetblob[i]);
  97553. if((ret=_mapping_P[0]->forward(vb)))
  97554. return(ret);
  97555. if(op){
  97556. if(vorbis_bitrate_managed(vb))
  97557. return(OV_EINVAL);
  97558. op->packet=oggpack_get_buffer(&vb->opb);
  97559. op->bytes=oggpack_bytes(&vb->opb);
  97560. op->b_o_s=0;
  97561. op->e_o_s=vb->eofflag;
  97562. op->granulepos=vb->granulepos;
  97563. op->packetno=vb->sequence; /* for sake of completeness */
  97564. }
  97565. return(0);
  97566. }
  97567. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97568. int j;
  97569. FILE *of;
  97570. char buffer[80];
  97571. sprintf(buffer,"%s_%d.m",base,i);
  97572. of=fopen(buffer,"w");
  97573. if(!of)perror("failed to open data dump file");
  97574. for(j=0;j<n;j++){
  97575. if(bark){
  97576. float b=toBARK((4000.f*j/n)+.25);
  97577. fprintf(of,"%f ",b);
  97578. }else
  97579. if(off!=0)
  97580. fprintf(of,"%f ",(double)(j+off)/8000.);
  97581. else
  97582. fprintf(of,"%f ",(double)j);
  97583. if(dB){
  97584. float val;
  97585. if(v[j]==0.)
  97586. val=-140.;
  97587. else
  97588. val=todB(v+j);
  97589. fprintf(of,"%f\n",val);
  97590. }else{
  97591. fprintf(of,"%f\n",v[j]);
  97592. }
  97593. }
  97594. fclose(of);
  97595. }
  97596. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97597. ogg_int64_t off){
  97598. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97599. }
  97600. #endif
  97601. /*** End of inlined file: analysis.c ***/
  97602. /*** Start of inlined file: bitrate.c ***/
  97603. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97604. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97605. // tasks..
  97606. #if JUCE_MSVC
  97607. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97608. #endif
  97609. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97610. #if JUCE_USE_OGGVORBIS
  97611. #include <stdlib.h>
  97612. #include <string.h>
  97613. #include <math.h>
  97614. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97615. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97616. bitrate_manager_info *bi=&ci->bi;
  97617. memset(bm,0,sizeof(*bm));
  97618. if(bi && (bi->reservoir_bits>0)){
  97619. long ratesamples=vi->rate;
  97620. int halfsamples=ci->blocksizes[0]>>1;
  97621. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97622. bm->managed=1;
  97623. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97624. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97625. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97626. bm->avgfloat=PACKETBLOBS/2;
  97627. {
  97628. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97629. bm->minmax_reservoir=desired_fill;
  97630. bm->avg_reservoir=desired_fill;
  97631. }
  97632. }
  97633. }
  97634. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97635. memset(bm,0,sizeof(*bm));
  97636. return;
  97637. }
  97638. int vorbis_bitrate_managed(vorbis_block *vb){
  97639. vorbis_dsp_state *vd=vb->vd;
  97640. private_state *b=(private_state*)vd->backend_state;
  97641. bitrate_manager_state *bm=&b->bms;
  97642. if(bm && bm->managed)return(1);
  97643. return(0);
  97644. }
  97645. int vorbis_bitrate_addblock(vorbis_block *vb){
  97646. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97647. vorbis_dsp_state *vd=vb->vd;
  97648. private_state *b=(private_state*)vd->backend_state;
  97649. bitrate_manager_state *bm=&b->bms;
  97650. vorbis_info *vi=vd->vi;
  97651. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97652. bitrate_manager_info *bi=&ci->bi;
  97653. int choice=rint(bm->avgfloat);
  97654. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97655. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97656. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97657. int samples=ci->blocksizes[vb->W]>>1;
  97658. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97659. if(!bm->managed){
  97660. if(bm->vb)return(-1); /* one has been submitted without
  97661. being claimed */
  97662. bm->vb=vb;
  97663. return(0);
  97664. }
  97665. bm->vb=vb;
  97666. if(bm->avg_bitsper>0){
  97667. double slew=0.;
  97668. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97669. double slewlimit= 15./bi->slew_damp;
  97670. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97671. while(choice>0 && this_bits>avg_target_bits &&
  97672. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97673. choice--;
  97674. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97675. }
  97676. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97677. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  97678. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97679. choice++;
  97680. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97681. }
  97682. }
  97683. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  97684. if(slew<-slewlimit)slew=-slewlimit;
  97685. if(slew>slewlimit)slew=slewlimit;
  97686. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  97687. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97688. }
  97689. if(bm->min_bitsper>0){
  97690. if(this_bits<min_target_bits){
  97691. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  97692. choice++;
  97693. if(choice>=PACKETBLOBS)break;
  97694. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97695. }
  97696. }
  97697. }
  97698. if(bm->max_bitsper>0){
  97699. if(this_bits>max_target_bits){
  97700. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  97701. choice--;
  97702. if(choice<0)break;
  97703. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97704. }
  97705. }
  97706. }
  97707. if(choice<0){
  97708. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  97709. bm->choice=choice=0;
  97710. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  97711. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  97712. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97713. }
  97714. }else{
  97715. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  97716. if(choice>=PACKETBLOBS)
  97717. choice=PACKETBLOBS-1;
  97718. bm->choice=choice;
  97719. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  97720. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  97721. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97722. }
  97723. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  97724. if(max_target_bits>0 && this_bits>max_target_bits){
  97725. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97726. }else if(min_target_bits>0 && this_bits<min_target_bits){
  97727. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97728. }else{
  97729. if(bm->minmax_reservoir>desired_fill){
  97730. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  97731. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97732. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  97733. }else{
  97734. bm->minmax_reservoir=desired_fill;
  97735. }
  97736. }else{
  97737. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  97738. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97739. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  97740. }else{
  97741. bm->minmax_reservoir=desired_fill;
  97742. }
  97743. }
  97744. }
  97745. }
  97746. if(bm->avg_bitsper>0){
  97747. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97748. bm->avg_reservoir+=this_bits-avg_target_bits;
  97749. }
  97750. return(0);
  97751. }
  97752. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  97753. private_state *b=(private_state*)vd->backend_state;
  97754. bitrate_manager_state *bm=&b->bms;
  97755. vorbis_block *vb=bm->vb;
  97756. int choice=PACKETBLOBS/2;
  97757. if(!vb)return 0;
  97758. if(op){
  97759. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97760. if(vorbis_bitrate_managed(vb))
  97761. choice=bm->choice;
  97762. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  97763. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  97764. op->b_o_s=0;
  97765. op->e_o_s=vb->eofflag;
  97766. op->granulepos=vb->granulepos;
  97767. op->packetno=vb->sequence; /* for sake of completeness */
  97768. }
  97769. bm->vb=0;
  97770. return(1);
  97771. }
  97772. #endif
  97773. /*** End of inlined file: bitrate.c ***/
  97774. /*** Start of inlined file: block.c ***/
  97775. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97776. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97777. // tasks..
  97778. #if JUCE_MSVC
  97779. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97780. #endif
  97781. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97782. #if JUCE_USE_OGGVORBIS
  97783. #include <stdio.h>
  97784. #include <stdlib.h>
  97785. #include <string.h>
  97786. /*** Start of inlined file: window.h ***/
  97787. #ifndef _V_WINDOW_
  97788. #define _V_WINDOW_
  97789. extern float *_vorbis_window_get(int n);
  97790. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  97791. int lW,int W,int nW);
  97792. #endif
  97793. /*** End of inlined file: window.h ***/
  97794. /*** Start of inlined file: lpc.h ***/
  97795. #ifndef _V_LPC_H_
  97796. #define _V_LPC_H_
  97797. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  97798. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  97799. float *data,long n);
  97800. #endif
  97801. /*** End of inlined file: lpc.h ***/
  97802. #ifndef WORD_ALIGN
  97803. #define WORD_ALIGN 8
  97804. #endif
  97805. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  97806. int i;
  97807. memset(vb,0,sizeof(*vb));
  97808. vb->vd=v;
  97809. vb->localalloc=0;
  97810. vb->localstore=NULL;
  97811. if(v->analysisp){
  97812. vorbis_block_internal *vbi=(vorbis_block_internal*)
  97813. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  97814. vbi->ampmax=-9999;
  97815. for(i=0;i<PACKETBLOBS;i++){
  97816. if(i==PACKETBLOBS/2){
  97817. vbi->packetblob[i]=&vb->opb;
  97818. }else{
  97819. vbi->packetblob[i]=
  97820. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  97821. }
  97822. oggpack_writeinit(vbi->packetblob[i]);
  97823. }
  97824. }
  97825. return(0);
  97826. }
  97827. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  97828. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  97829. if(bytes+vb->localtop>vb->localalloc){
  97830. if(vb->localstore){
  97831. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  97832. vb->totaluse+=vb->localtop;
  97833. link->next=vb->reap;
  97834. link->ptr=vb->localstore;
  97835. vb->reap=link;
  97836. }
  97837. vb->localalloc=bytes;
  97838. vb->localstore=_ogg_malloc(vb->localalloc);
  97839. vb->localtop=0;
  97840. }
  97841. {
  97842. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  97843. vb->localtop+=bytes;
  97844. return ret;
  97845. }
  97846. }
  97847. void _vorbis_block_ripcord(vorbis_block *vb){
  97848. struct alloc_chain *reap=vb->reap;
  97849. while(reap){
  97850. struct alloc_chain *next=reap->next;
  97851. _ogg_free(reap->ptr);
  97852. memset(reap,0,sizeof(*reap));
  97853. _ogg_free(reap);
  97854. reap=next;
  97855. }
  97856. if(vb->totaluse){
  97857. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  97858. vb->localalloc+=vb->totaluse;
  97859. vb->totaluse=0;
  97860. }
  97861. vb->localtop=0;
  97862. vb->reap=NULL;
  97863. }
  97864. int vorbis_block_clear(vorbis_block *vb){
  97865. int i;
  97866. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97867. _vorbis_block_ripcord(vb);
  97868. if(vb->localstore)_ogg_free(vb->localstore);
  97869. if(vbi){
  97870. for(i=0;i<PACKETBLOBS;i++){
  97871. oggpack_writeclear(vbi->packetblob[i]);
  97872. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  97873. }
  97874. _ogg_free(vbi);
  97875. }
  97876. memset(vb,0,sizeof(*vb));
  97877. return(0);
  97878. }
  97879. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  97880. int i;
  97881. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97882. private_state *b=NULL;
  97883. int hs;
  97884. if(ci==NULL) return 1;
  97885. hs=ci->halfrate_flag;
  97886. memset(v,0,sizeof(*v));
  97887. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  97888. v->vi=vi;
  97889. b->modebits=ilog2(ci->modes);
  97890. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  97891. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  97892. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97893. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97894. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  97895. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  97896. b->window[0]=ilog2(ci->blocksizes[0])-6;
  97897. b->window[1]=ilog2(ci->blocksizes[1])-6;
  97898. if(encp){ /* encode/decode differ here */
  97899. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  97900. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  97901. if(!ci->fullbooks){
  97902. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97903. for(i=0;i<ci->books;i++)
  97904. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  97905. }
  97906. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  97907. for(i=0;i<ci->psys;i++){
  97908. _vp_psy_init(b->psy+i,
  97909. ci->psy_param[i],
  97910. &ci->psy_g_param,
  97911. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  97912. vi->rate);
  97913. }
  97914. v->analysisp=1;
  97915. }else{
  97916. if(!ci->fullbooks){
  97917. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97918. for(i=0;i<ci->books;i++){
  97919. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  97920. vorbis_staticbook_destroy(ci->book_param[i]);
  97921. ci->book_param[i]=NULL;
  97922. }
  97923. }
  97924. }
  97925. v->pcm_storage=ci->blocksizes[1];
  97926. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  97927. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  97928. {
  97929. int i;
  97930. for(i=0;i<vi->channels;i++)
  97931. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  97932. }
  97933. v->lW=0; /* previous window size */
  97934. v->W=0; /* current window size */
  97935. v->centerW=ci->blocksizes[1]/2;
  97936. v->pcm_current=v->centerW;
  97937. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  97938. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  97939. for(i=0;i<ci->floors;i++)
  97940. b->flr[i]=_floor_P[ci->floor_type[i]]->
  97941. look(v,ci->floor_param[i]);
  97942. for(i=0;i<ci->residues;i++)
  97943. b->residue[i]=_residue_P[ci->residue_type[i]]->
  97944. look(v,ci->residue_param[i]);
  97945. return 0;
  97946. }
  97947. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  97948. private_state *b=NULL;
  97949. if(_vds_shared_init(v,vi,1))return 1;
  97950. b=(private_state*)v->backend_state;
  97951. b->psy_g_look=_vp_global_look(vi);
  97952. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  97953. _ve_envelope_init(b->ve,vi);
  97954. vorbis_bitrate_init(vi,&b->bms);
  97955. v->sequence=3;
  97956. return(0);
  97957. }
  97958. void vorbis_dsp_clear(vorbis_dsp_state *v){
  97959. int i;
  97960. if(v){
  97961. vorbis_info *vi=v->vi;
  97962. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  97963. private_state *b=(private_state*)v->backend_state;
  97964. if(b){
  97965. if(b->ve){
  97966. _ve_envelope_clear(b->ve);
  97967. _ogg_free(b->ve);
  97968. }
  97969. if(b->transform[0]){
  97970. mdct_clear((mdct_lookup*) b->transform[0][0]);
  97971. _ogg_free(b->transform[0][0]);
  97972. _ogg_free(b->transform[0]);
  97973. }
  97974. if(b->transform[1]){
  97975. mdct_clear((mdct_lookup*) b->transform[1][0]);
  97976. _ogg_free(b->transform[1][0]);
  97977. _ogg_free(b->transform[1]);
  97978. }
  97979. if(b->flr){
  97980. for(i=0;i<ci->floors;i++)
  97981. _floor_P[ci->floor_type[i]]->
  97982. free_look(b->flr[i]);
  97983. _ogg_free(b->flr);
  97984. }
  97985. if(b->residue){
  97986. for(i=0;i<ci->residues;i++)
  97987. _residue_P[ci->residue_type[i]]->
  97988. free_look(b->residue[i]);
  97989. _ogg_free(b->residue);
  97990. }
  97991. if(b->psy){
  97992. for(i=0;i<ci->psys;i++)
  97993. _vp_psy_clear(b->psy+i);
  97994. _ogg_free(b->psy);
  97995. }
  97996. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  97997. vorbis_bitrate_clear(&b->bms);
  97998. drft_clear(&b->fft_look[0]);
  97999. drft_clear(&b->fft_look[1]);
  98000. }
  98001. if(v->pcm){
  98002. for(i=0;i<vi->channels;i++)
  98003. if(v->pcm[i])_ogg_free(v->pcm[i]);
  98004. _ogg_free(v->pcm);
  98005. if(v->pcmret)_ogg_free(v->pcmret);
  98006. }
  98007. if(b){
  98008. if(b->header)_ogg_free(b->header);
  98009. if(b->header1)_ogg_free(b->header1);
  98010. if(b->header2)_ogg_free(b->header2);
  98011. _ogg_free(b);
  98012. }
  98013. memset(v,0,sizeof(*v));
  98014. }
  98015. }
  98016. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  98017. int i;
  98018. vorbis_info *vi=v->vi;
  98019. private_state *b=(private_state*)v->backend_state;
  98020. if(b->header)_ogg_free(b->header);b->header=NULL;
  98021. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  98022. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  98023. if(v->pcm_current+vals>=v->pcm_storage){
  98024. v->pcm_storage=v->pcm_current+vals*2;
  98025. for(i=0;i<vi->channels;i++){
  98026. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  98027. }
  98028. }
  98029. for(i=0;i<vi->channels;i++)
  98030. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  98031. return(v->pcmret);
  98032. }
  98033. static void _preextrapolate_helper(vorbis_dsp_state *v){
  98034. int i;
  98035. int order=32;
  98036. float *lpc=(float*)alloca(order*sizeof(*lpc));
  98037. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  98038. long j;
  98039. v->preextrapolate=1;
  98040. if(v->pcm_current-v->centerW>order*2){ /* safety */
  98041. for(i=0;i<v->vi->channels;i++){
  98042. for(j=0;j<v->pcm_current;j++)
  98043. work[j]=v->pcm[i][v->pcm_current-j-1];
  98044. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  98045. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  98046. order,
  98047. work+v->pcm_current-v->centerW,
  98048. v->centerW);
  98049. for(j=0;j<v->pcm_current;j++)
  98050. v->pcm[i][v->pcm_current-j-1]=work[j];
  98051. }
  98052. }
  98053. }
  98054. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  98055. vorbis_info *vi=v->vi;
  98056. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98057. if(vals<=0){
  98058. int order=32;
  98059. int i;
  98060. float *lpc=(float*) alloca(order*sizeof(*lpc));
  98061. if(!v->preextrapolate)
  98062. _preextrapolate_helper(v);
  98063. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  98064. v->eofflag=v->pcm_current;
  98065. v->pcm_current+=ci->blocksizes[1]*3;
  98066. for(i=0;i<vi->channels;i++){
  98067. if(v->eofflag>order*2){
  98068. long n;
  98069. n=v->eofflag;
  98070. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  98071. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  98072. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  98073. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  98074. }else{
  98075. memset(v->pcm[i]+v->eofflag,0,
  98076. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  98077. }
  98078. }
  98079. }else{
  98080. if(v->pcm_current+vals>v->pcm_storage)
  98081. return(OV_EINVAL);
  98082. v->pcm_current+=vals;
  98083. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  98084. _preextrapolate_helper(v);
  98085. }
  98086. return(0);
  98087. }
  98088. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  98089. int i;
  98090. vorbis_info *vi=v->vi;
  98091. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98092. private_state *b=(private_state*)v->backend_state;
  98093. vorbis_look_psy_global *g=b->psy_g_look;
  98094. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  98095. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  98096. if(!v->preextrapolate)return(0);
  98097. if(v->eofflag==-1)return(0);
  98098. {
  98099. long bp=_ve_envelope_search(v);
  98100. if(bp==-1){
  98101. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  98102. full long block */
  98103. v->nW=0;
  98104. }else{
  98105. if(ci->blocksizes[0]==ci->blocksizes[1])
  98106. v->nW=0;
  98107. else
  98108. v->nW=bp;
  98109. }
  98110. }
  98111. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  98112. {
  98113. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  98114. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  98115. although this check is
  98116. less strict that the
  98117. _ve_envelope_search,
  98118. the search is not run
  98119. if we only use one
  98120. block size */
  98121. }
  98122. _vorbis_block_ripcord(vb);
  98123. vb->lW=v->lW;
  98124. vb->W=v->W;
  98125. vb->nW=v->nW;
  98126. if(v->W){
  98127. if(!v->lW || !v->nW){
  98128. vbi->blocktype=BLOCKTYPE_TRANSITION;
  98129. }else{
  98130. vbi->blocktype=BLOCKTYPE_LONG;
  98131. }
  98132. }else{
  98133. if(_ve_envelope_mark(v)){
  98134. vbi->blocktype=BLOCKTYPE_IMPULSE;
  98135. }else{
  98136. vbi->blocktype=BLOCKTYPE_PADDING;
  98137. }
  98138. }
  98139. vb->vd=v;
  98140. vb->sequence=v->sequence++;
  98141. vb->granulepos=v->granulepos;
  98142. vb->pcmend=ci->blocksizes[v->W];
  98143. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  98144. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  98145. vbi->ampmax=g->ampmax;
  98146. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  98147. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  98148. for(i=0;i<vi->channels;i++){
  98149. vbi->pcmdelay[i]=
  98150. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98151. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98152. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  98153. }
  98154. if(v->eofflag){
  98155. if(v->centerW>=v->eofflag){
  98156. v->eofflag=-1;
  98157. vb->eofflag=1;
  98158. return(1);
  98159. }
  98160. }
  98161. {
  98162. int new_centerNext=ci->blocksizes[1]/2;
  98163. int movementW=centerNext-new_centerNext;
  98164. if(movementW>0){
  98165. _ve_envelope_shift(b->ve,movementW);
  98166. v->pcm_current-=movementW;
  98167. for(i=0;i<vi->channels;i++)
  98168. memmove(v->pcm[i],v->pcm[i]+movementW,
  98169. v->pcm_current*sizeof(*v->pcm[i]));
  98170. v->lW=v->W;
  98171. v->W=v->nW;
  98172. v->centerW=new_centerNext;
  98173. if(v->eofflag){
  98174. v->eofflag-=movementW;
  98175. if(v->eofflag<=0)v->eofflag=-1;
  98176. if(v->centerW>=v->eofflag){
  98177. v->granulepos+=movementW-(v->centerW-v->eofflag);
  98178. }else{
  98179. v->granulepos+=movementW;
  98180. }
  98181. }else{
  98182. v->granulepos+=movementW;
  98183. }
  98184. }
  98185. }
  98186. return(1);
  98187. }
  98188. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  98189. vorbis_info *vi=v->vi;
  98190. codec_setup_info *ci;
  98191. int hs;
  98192. if(!v->backend_state)return -1;
  98193. if(!vi)return -1;
  98194. ci=(codec_setup_info*) vi->codec_setup;
  98195. if(!ci)return -1;
  98196. hs=ci->halfrate_flag;
  98197. v->centerW=ci->blocksizes[1]>>(hs+1);
  98198. v->pcm_current=v->centerW>>hs;
  98199. v->pcm_returned=-1;
  98200. v->granulepos=-1;
  98201. v->sequence=-1;
  98202. v->eofflag=0;
  98203. ((private_state *)(v->backend_state))->sample_count=-1;
  98204. return(0);
  98205. }
  98206. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98207. if(_vds_shared_init(v,vi,0)) return 1;
  98208. vorbis_synthesis_restart(v);
  98209. return 0;
  98210. }
  98211. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  98212. vorbis_info *vi=v->vi;
  98213. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98214. private_state *b=(private_state*)v->backend_state;
  98215. int hs=ci->halfrate_flag;
  98216. int i,j;
  98217. if(!vb)return(OV_EINVAL);
  98218. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  98219. v->lW=v->W;
  98220. v->W=vb->W;
  98221. v->nW=-1;
  98222. if((v->sequence==-1)||
  98223. (v->sequence+1 != vb->sequence)){
  98224. v->granulepos=-1; /* out of sequence; lose count */
  98225. b->sample_count=-1;
  98226. }
  98227. v->sequence=vb->sequence;
  98228. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  98229. was called on block */
  98230. int n=ci->blocksizes[v->W]>>(hs+1);
  98231. int n0=ci->blocksizes[0]>>(hs+1);
  98232. int n1=ci->blocksizes[1]>>(hs+1);
  98233. int thisCenter;
  98234. int prevCenter;
  98235. v->glue_bits+=vb->glue_bits;
  98236. v->time_bits+=vb->time_bits;
  98237. v->floor_bits+=vb->floor_bits;
  98238. v->res_bits+=vb->res_bits;
  98239. if(v->centerW){
  98240. thisCenter=n1;
  98241. prevCenter=0;
  98242. }else{
  98243. thisCenter=0;
  98244. prevCenter=n1;
  98245. }
  98246. for(j=0;j<vi->channels;j++){
  98247. if(v->lW){
  98248. if(v->W){
  98249. float *w=_vorbis_window_get(b->window[1]-hs);
  98250. float *pcm=v->pcm[j]+prevCenter;
  98251. float *p=vb->pcm[j];
  98252. for(i=0;i<n1;i++)
  98253. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  98254. }else{
  98255. float *w=_vorbis_window_get(b->window[0]-hs);
  98256. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  98257. float *p=vb->pcm[j];
  98258. for(i=0;i<n0;i++)
  98259. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98260. }
  98261. }else{
  98262. if(v->W){
  98263. float *w=_vorbis_window_get(b->window[0]-hs);
  98264. float *pcm=v->pcm[j]+prevCenter;
  98265. float *p=vb->pcm[j]+n1/2-n0/2;
  98266. for(i=0;i<n0;i++)
  98267. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98268. for(;i<n1/2+n0/2;i++)
  98269. pcm[i]=p[i];
  98270. }else{
  98271. float *w=_vorbis_window_get(b->window[0]-hs);
  98272. float *pcm=v->pcm[j]+prevCenter;
  98273. float *p=vb->pcm[j];
  98274. for(i=0;i<n0;i++)
  98275. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98276. }
  98277. }
  98278. {
  98279. float *pcm=v->pcm[j]+thisCenter;
  98280. float *p=vb->pcm[j]+n;
  98281. for(i=0;i<n;i++)
  98282. pcm[i]=p[i];
  98283. }
  98284. }
  98285. if(v->centerW)
  98286. v->centerW=0;
  98287. else
  98288. v->centerW=n1;
  98289. if(v->pcm_returned==-1){
  98290. v->pcm_returned=thisCenter;
  98291. v->pcm_current=thisCenter;
  98292. }else{
  98293. v->pcm_returned=prevCenter;
  98294. v->pcm_current=prevCenter+
  98295. ((ci->blocksizes[v->lW]/4+
  98296. ci->blocksizes[v->W]/4)>>hs);
  98297. }
  98298. }
  98299. if(b->sample_count==-1){
  98300. b->sample_count=0;
  98301. }else{
  98302. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98303. }
  98304. if(v->granulepos==-1){
  98305. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98306. v->granulepos=vb->granulepos;
  98307. if(b->sample_count>v->granulepos){
  98308. if(vb->eofflag){
  98309. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98310. }else{
  98311. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98312. if(v->pcm_returned>v->pcm_current)
  98313. v->pcm_returned=v->pcm_current;
  98314. }
  98315. }
  98316. }
  98317. }else{
  98318. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98319. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98320. if(v->granulepos>vb->granulepos){
  98321. long extra=v->granulepos-vb->granulepos;
  98322. if(extra)
  98323. if(vb->eofflag){
  98324. v->pcm_current-=extra>>hs;
  98325. } /* else {Shouldn't happen *unless* the bitstream is out of
  98326. spec. Either way, believe the bitstream } */
  98327. } /* else {Shouldn't happen *unless* the bitstream is out of
  98328. spec. Either way, believe the bitstream } */
  98329. v->granulepos=vb->granulepos;
  98330. }
  98331. }
  98332. if(vb->eofflag)v->eofflag=1;
  98333. return(0);
  98334. }
  98335. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98336. vorbis_info *vi=v->vi;
  98337. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98338. if(pcm){
  98339. int i;
  98340. for(i=0;i<vi->channels;i++)
  98341. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98342. *pcm=v->pcmret;
  98343. }
  98344. return(v->pcm_current-v->pcm_returned);
  98345. }
  98346. return(0);
  98347. }
  98348. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98349. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98350. v->pcm_returned+=n;
  98351. return(0);
  98352. }
  98353. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98354. vorbis_info *vi=v->vi;
  98355. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98356. int hs=ci->halfrate_flag;
  98357. int n=ci->blocksizes[v->W]>>(hs+1);
  98358. int n0=ci->blocksizes[0]>>(hs+1);
  98359. int n1=ci->blocksizes[1]>>(hs+1);
  98360. int i,j;
  98361. if(v->pcm_returned<0)return 0;
  98362. if(v->centerW==n1){
  98363. for(j=0;j<vi->channels;j++){
  98364. float *p=v->pcm[j];
  98365. for(i=0;i<n1;i++){
  98366. float temp=p[i];
  98367. p[i]=p[i+n1];
  98368. p[i+n1]=temp;
  98369. }
  98370. }
  98371. v->pcm_current-=n1;
  98372. v->pcm_returned-=n1;
  98373. v->centerW=0;
  98374. }
  98375. if((v->lW^v->W)==1){
  98376. for(j=0;j<vi->channels;j++){
  98377. float *s=v->pcm[j];
  98378. float *d=v->pcm[j]+(n1-n0)/2;
  98379. for(i=(n1+n0)/2-1;i>=0;--i)
  98380. d[i]=s[i];
  98381. }
  98382. v->pcm_returned+=(n1-n0)/2;
  98383. v->pcm_current+=(n1-n0)/2;
  98384. }else{
  98385. if(v->lW==0){
  98386. for(j=0;j<vi->channels;j++){
  98387. float *s=v->pcm[j];
  98388. float *d=v->pcm[j]+n1-n0;
  98389. for(i=n0-1;i>=0;--i)
  98390. d[i]=s[i];
  98391. }
  98392. v->pcm_returned+=n1-n0;
  98393. v->pcm_current+=n1-n0;
  98394. }
  98395. }
  98396. if(pcm){
  98397. int i;
  98398. for(i=0;i<vi->channels;i++)
  98399. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98400. *pcm=v->pcmret;
  98401. }
  98402. return(n1+n-v->pcm_returned);
  98403. }
  98404. float *vorbis_window(vorbis_dsp_state *v,int W){
  98405. vorbis_info *vi=v->vi;
  98406. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98407. int hs=ci->halfrate_flag;
  98408. private_state *b=(private_state*)v->backend_state;
  98409. if(b->window[W]-1<0)return NULL;
  98410. return _vorbis_window_get(b->window[W]-hs);
  98411. }
  98412. #endif
  98413. /*** End of inlined file: block.c ***/
  98414. /*** Start of inlined file: codebook.c ***/
  98415. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98416. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98417. // tasks..
  98418. #if JUCE_MSVC
  98419. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98420. #endif
  98421. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98422. #if JUCE_USE_OGGVORBIS
  98423. #include <stdlib.h>
  98424. #include <string.h>
  98425. #include <math.h>
  98426. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98427. long i,j;
  98428. int ordered=0;
  98429. oggpack_write(opb,0x564342,24);
  98430. oggpack_write(opb,c->dim,16);
  98431. oggpack_write(opb,c->entries,24);
  98432. for(i=1;i<c->entries;i++)
  98433. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98434. if(i==c->entries)ordered=1;
  98435. if(ordered){
  98436. long count=0;
  98437. oggpack_write(opb,1,1); /* ordered */
  98438. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98439. for(i=1;i<c->entries;i++){
  98440. long thisx=c->lengthlist[i];
  98441. long last=c->lengthlist[i-1];
  98442. if(thisx>last){
  98443. for(j=last;j<thisx;j++){
  98444. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98445. count=i;
  98446. }
  98447. }
  98448. }
  98449. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98450. }else{
  98451. oggpack_write(opb,0,1); /* unordered */
  98452. for(i=0;i<c->entries;i++)
  98453. if(c->lengthlist[i]==0)break;
  98454. if(i==c->entries){
  98455. oggpack_write(opb,0,1); /* no unused entries */
  98456. for(i=0;i<c->entries;i++)
  98457. oggpack_write(opb,c->lengthlist[i]-1,5);
  98458. }else{
  98459. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98460. for(i=0;i<c->entries;i++){
  98461. if(c->lengthlist[i]==0){
  98462. oggpack_write(opb,0,1);
  98463. }else{
  98464. oggpack_write(opb,1,1);
  98465. oggpack_write(opb,c->lengthlist[i]-1,5);
  98466. }
  98467. }
  98468. }
  98469. }
  98470. oggpack_write(opb,c->maptype,4);
  98471. switch(c->maptype){
  98472. case 0:
  98473. break;
  98474. case 1:case 2:
  98475. if(!c->quantlist){
  98476. return(-1);
  98477. }
  98478. oggpack_write(opb,c->q_min,32);
  98479. oggpack_write(opb,c->q_delta,32);
  98480. oggpack_write(opb,c->q_quant-1,4);
  98481. oggpack_write(opb,c->q_sequencep,1);
  98482. {
  98483. int quantvals;
  98484. switch(c->maptype){
  98485. case 1:
  98486. quantvals=_book_maptype1_quantvals(c);
  98487. break;
  98488. case 2:
  98489. quantvals=c->entries*c->dim;
  98490. break;
  98491. default: /* NOT_REACHABLE */
  98492. quantvals=-1;
  98493. }
  98494. for(i=0;i<quantvals;i++)
  98495. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98496. }
  98497. break;
  98498. default:
  98499. return(-1);
  98500. }
  98501. return(0);
  98502. }
  98503. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98504. long i,j;
  98505. memset(s,0,sizeof(*s));
  98506. s->allocedp=1;
  98507. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98508. s->dim=oggpack_read(opb,16);
  98509. s->entries=oggpack_read(opb,24);
  98510. if(s->entries==-1)goto _eofout;
  98511. switch((int)oggpack_read(opb,1)){
  98512. case 0:
  98513. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98514. if(oggpack_read(opb,1)){
  98515. for(i=0;i<s->entries;i++){
  98516. if(oggpack_read(opb,1)){
  98517. long num=oggpack_read(opb,5);
  98518. if(num==-1)goto _eofout;
  98519. s->lengthlist[i]=num+1;
  98520. }else
  98521. s->lengthlist[i]=0;
  98522. }
  98523. }else{
  98524. for(i=0;i<s->entries;i++){
  98525. long num=oggpack_read(opb,5);
  98526. if(num==-1)goto _eofout;
  98527. s->lengthlist[i]=num+1;
  98528. }
  98529. }
  98530. break;
  98531. case 1:
  98532. {
  98533. long length=oggpack_read(opb,5)+1;
  98534. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98535. for(i=0;i<s->entries;){
  98536. long num=oggpack_read(opb,_ilog(s->entries-i));
  98537. if(num==-1)goto _eofout;
  98538. for(j=0;j<num && i<s->entries;j++,i++)
  98539. s->lengthlist[i]=length;
  98540. length++;
  98541. }
  98542. }
  98543. break;
  98544. default:
  98545. return(-1);
  98546. }
  98547. switch((s->maptype=oggpack_read(opb,4))){
  98548. case 0:
  98549. break;
  98550. case 1: case 2:
  98551. s->q_min=oggpack_read(opb,32);
  98552. s->q_delta=oggpack_read(opb,32);
  98553. s->q_quant=oggpack_read(opb,4)+1;
  98554. s->q_sequencep=oggpack_read(opb,1);
  98555. {
  98556. int quantvals=0;
  98557. switch(s->maptype){
  98558. case 1:
  98559. quantvals=_book_maptype1_quantvals(s);
  98560. break;
  98561. case 2:
  98562. quantvals=s->entries*s->dim;
  98563. break;
  98564. }
  98565. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98566. for(i=0;i<quantvals;i++)
  98567. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98568. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98569. }
  98570. break;
  98571. default:
  98572. goto _errout;
  98573. }
  98574. return(0);
  98575. _errout:
  98576. _eofout:
  98577. vorbis_staticbook_clear(s);
  98578. return(-1);
  98579. }
  98580. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98581. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98582. return(book->c->lengthlist[a]);
  98583. }
  98584. int vorbis_book_errorv(codebook *book,float *a){
  98585. int dim=book->dim,k;
  98586. int best=_best(book,a,1);
  98587. for(k=0;k<dim;k++)
  98588. a[k]=(book->valuelist+best*dim)[k];
  98589. return(best);
  98590. }
  98591. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98592. int k,dim=book->dim;
  98593. for(k=0;k<dim;k++)
  98594. a[k]=(book->valuelist+best*dim)[k];
  98595. return(vorbis_book_encode(book,best,b));
  98596. }
  98597. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98598. int read=book->dec_maxlength;
  98599. long lo,hi;
  98600. long lok = oggpack_look(b,book->dec_firsttablen);
  98601. if (lok >= 0) {
  98602. long entry = book->dec_firsttable[lok];
  98603. if(entry&0x80000000UL){
  98604. lo=(entry>>15)&0x7fff;
  98605. hi=book->used_entries-(entry&0x7fff);
  98606. }else{
  98607. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98608. return(entry-1);
  98609. }
  98610. }else{
  98611. lo=0;
  98612. hi=book->used_entries;
  98613. }
  98614. lok = oggpack_look(b, read);
  98615. while(lok<0 && read>1)
  98616. lok = oggpack_look(b, --read);
  98617. if(lok<0)return -1;
  98618. {
  98619. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98620. while(hi-lo>1){
  98621. long p=(hi-lo)>>1;
  98622. long test=book->codelist[lo+p]>testword;
  98623. lo+=p&(test-1);
  98624. hi-=p&(-test);
  98625. }
  98626. if(book->dec_codelengths[lo]<=read){
  98627. oggpack_adv(b, book->dec_codelengths[lo]);
  98628. return(lo);
  98629. }
  98630. }
  98631. oggpack_adv(b, read);
  98632. return(-1);
  98633. }
  98634. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98635. long packed_entry=decode_packed_entry_number(book,b);
  98636. if(packed_entry>=0)
  98637. return(book->dec_index[packed_entry]);
  98638. return(packed_entry);
  98639. }
  98640. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98641. int step=n/book->dim;
  98642. long *entry = (long*)alloca(sizeof(*entry)*step);
  98643. float **t = (float**)alloca(sizeof(*t)*step);
  98644. int i,j,o;
  98645. for (i = 0; i < step; i++) {
  98646. entry[i]=decode_packed_entry_number(book,b);
  98647. if(entry[i]==-1)return(-1);
  98648. t[i] = book->valuelist+entry[i]*book->dim;
  98649. }
  98650. for(i=0,o=0;i<book->dim;i++,o+=step)
  98651. for (j=0;j<step;j++)
  98652. a[o+j]+=t[j][i];
  98653. return(0);
  98654. }
  98655. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98656. int i,j,entry;
  98657. float *t;
  98658. if(book->dim>8){
  98659. for(i=0;i<n;){
  98660. entry = decode_packed_entry_number(book,b);
  98661. if(entry==-1)return(-1);
  98662. t = book->valuelist+entry*book->dim;
  98663. for (j=0;j<book->dim;)
  98664. a[i++]+=t[j++];
  98665. }
  98666. }else{
  98667. for(i=0;i<n;){
  98668. entry = decode_packed_entry_number(book,b);
  98669. if(entry==-1)return(-1);
  98670. t = book->valuelist+entry*book->dim;
  98671. j=0;
  98672. switch((int)book->dim){
  98673. case 8:
  98674. a[i++]+=t[j++];
  98675. case 7:
  98676. a[i++]+=t[j++];
  98677. case 6:
  98678. a[i++]+=t[j++];
  98679. case 5:
  98680. a[i++]+=t[j++];
  98681. case 4:
  98682. a[i++]+=t[j++];
  98683. case 3:
  98684. a[i++]+=t[j++];
  98685. case 2:
  98686. a[i++]+=t[j++];
  98687. case 1:
  98688. a[i++]+=t[j++];
  98689. case 0:
  98690. break;
  98691. }
  98692. }
  98693. }
  98694. return(0);
  98695. }
  98696. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  98697. int i,j,entry;
  98698. float *t;
  98699. for(i=0;i<n;){
  98700. entry = decode_packed_entry_number(book,b);
  98701. if(entry==-1)return(-1);
  98702. t = book->valuelist+entry*book->dim;
  98703. for (j=0;j<book->dim;)
  98704. a[i++]=t[j++];
  98705. }
  98706. return(0);
  98707. }
  98708. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  98709. oggpack_buffer *b,int n){
  98710. long i,j,entry;
  98711. int chptr=0;
  98712. for(i=offset/ch;i<(offset+n)/ch;){
  98713. entry = decode_packed_entry_number(book,b);
  98714. if(entry==-1)return(-1);
  98715. {
  98716. const float *t = book->valuelist+entry*book->dim;
  98717. for (j=0;j<book->dim;j++){
  98718. a[chptr++][i]+=t[j];
  98719. if(chptr==ch){
  98720. chptr=0;
  98721. i++;
  98722. }
  98723. }
  98724. }
  98725. }
  98726. return(0);
  98727. }
  98728. #ifdef _V_SELFTEST
  98729. #include <stdio.h>
  98730. #include "vorbis/book/lsp20_0.vqh"
  98731. #include "vorbis/book/res0a_13.vqh"
  98732. #define TESTSIZE 40
  98733. float test1[TESTSIZE]={
  98734. 0.105939f,
  98735. 0.215373f,
  98736. 0.429117f,
  98737. 0.587974f,
  98738. 0.181173f,
  98739. 0.296583f,
  98740. 0.515707f,
  98741. 0.715261f,
  98742. 0.162327f,
  98743. 0.263834f,
  98744. 0.342876f,
  98745. 0.406025f,
  98746. 0.103571f,
  98747. 0.223561f,
  98748. 0.368513f,
  98749. 0.540313f,
  98750. 0.136672f,
  98751. 0.395882f,
  98752. 0.587183f,
  98753. 0.652476f,
  98754. 0.114338f,
  98755. 0.417300f,
  98756. 0.525486f,
  98757. 0.698679f,
  98758. 0.147492f,
  98759. 0.324481f,
  98760. 0.643089f,
  98761. 0.757582f,
  98762. 0.139556f,
  98763. 0.215795f,
  98764. 0.324559f,
  98765. 0.399387f,
  98766. 0.120236f,
  98767. 0.267420f,
  98768. 0.446940f,
  98769. 0.608760f,
  98770. 0.115587f,
  98771. 0.287234f,
  98772. 0.571081f,
  98773. 0.708603f,
  98774. };
  98775. float test3[TESTSIZE]={
  98776. 0,1,-2,3,4,-5,6,7,8,9,
  98777. 8,-2,7,-1,4,6,8,3,1,-9,
  98778. 10,11,12,13,14,15,26,17,18,19,
  98779. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  98780. static_codebook *testlist[]={&_vq_book_lsp20_0,
  98781. &_vq_book_res0a_13,NULL};
  98782. float *testvec[]={test1,test3};
  98783. int main(){
  98784. oggpack_buffer write;
  98785. oggpack_buffer read;
  98786. long ptr=0,i;
  98787. oggpack_writeinit(&write);
  98788. fprintf(stderr,"Testing codebook abstraction...:\n");
  98789. while(testlist[ptr]){
  98790. codebook c;
  98791. static_codebook s;
  98792. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  98793. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  98794. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  98795. memset(iv,0,sizeof(*iv)*TESTSIZE);
  98796. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  98797. oggpack_reset(&write);
  98798. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  98799. we can write */
  98800. vorbis_staticbook_pack(testlist[ptr],&write);
  98801. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  98802. for(i=0;i<TESTSIZE;i+=c.dim){
  98803. int best=_best(&c,qv+i,1);
  98804. vorbis_book_encodev(&c,best,qv+i,&write);
  98805. }
  98806. vorbis_book_clear(&c);
  98807. fprintf(stderr,"OK.\n");
  98808. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  98809. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  98810. if(vorbis_staticbook_unpack(&read,&s)){
  98811. fprintf(stderr,"Error unpacking codebook.\n");
  98812. exit(1);
  98813. }
  98814. if(vorbis_book_init_decode(&c,&s)){
  98815. fprintf(stderr,"Error initializing codebook.\n");
  98816. exit(1);
  98817. }
  98818. for(i=0;i<TESTSIZE;i+=c.dim)
  98819. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  98820. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  98821. exit(1);
  98822. }
  98823. for(i=0;i<TESTSIZE;i++)
  98824. if(fabs(qv[i]-iv[i])>.000001){
  98825. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  98826. iv[i],qv[i],i);
  98827. exit(1);
  98828. }
  98829. fprintf(stderr,"OK\n");
  98830. ptr++;
  98831. }
  98832. exit(0);
  98833. }
  98834. #endif
  98835. #endif
  98836. /*** End of inlined file: codebook.c ***/
  98837. /*** Start of inlined file: envelope.c ***/
  98838. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98839. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98840. // tasks..
  98841. #if JUCE_MSVC
  98842. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98843. #endif
  98844. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98845. #if JUCE_USE_OGGVORBIS
  98846. #include <stdlib.h>
  98847. #include <string.h>
  98848. #include <stdio.h>
  98849. #include <math.h>
  98850. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  98851. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98852. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98853. int ch=vi->channels;
  98854. int i,j;
  98855. int n=e->winlength=128;
  98856. e->searchstep=64; /* not random */
  98857. e->minenergy=gi->preecho_minenergy;
  98858. e->ch=ch;
  98859. e->storage=128;
  98860. e->cursor=ci->blocksizes[1]/2;
  98861. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  98862. mdct_init(&e->mdct,n);
  98863. for(i=0;i<n;i++){
  98864. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  98865. e->mdct_win[i]*=e->mdct_win[i];
  98866. }
  98867. e->band[0].begin=2; e->band[0].end=4;
  98868. e->band[1].begin=4; e->band[1].end=5;
  98869. e->band[2].begin=6; e->band[2].end=6;
  98870. e->band[3].begin=9; e->band[3].end=8;
  98871. e->band[4].begin=13; e->band[4].end=8;
  98872. e->band[5].begin=17; e->band[5].end=8;
  98873. e->band[6].begin=22; e->band[6].end=8;
  98874. for(j=0;j<VE_BANDS;j++){
  98875. n=e->band[j].end;
  98876. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  98877. for(i=0;i<n;i++){
  98878. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  98879. e->band[j].total+=e->band[j].window[i];
  98880. }
  98881. e->band[j].total=1./e->band[j].total;
  98882. }
  98883. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  98884. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  98885. }
  98886. void _ve_envelope_clear(envelope_lookup *e){
  98887. int i;
  98888. mdct_clear(&e->mdct);
  98889. for(i=0;i<VE_BANDS;i++)
  98890. _ogg_free(e->band[i].window);
  98891. _ogg_free(e->mdct_win);
  98892. _ogg_free(e->filter);
  98893. _ogg_free(e->mark);
  98894. memset(e,0,sizeof(*e));
  98895. }
  98896. static int _ve_amp(envelope_lookup *ve,
  98897. vorbis_info_psy_global *gi,
  98898. float *data,
  98899. envelope_band *bands,
  98900. envelope_filter_state *filters,
  98901. long pos){
  98902. long n=ve->winlength;
  98903. int ret=0;
  98904. long i,j;
  98905. float decay;
  98906. float minV=ve->minenergy;
  98907. float *vec=(float*) alloca(n*sizeof(*vec));
  98908. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  98909. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  98910. if(penalty<0.f)penalty=0.f;
  98911. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  98912. for(i=0;i<n;i++)
  98913. vec[i]=data[i]*ve->mdct_win[i];
  98914. mdct_forward(&ve->mdct,vec,vec);
  98915. {
  98916. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  98917. int ptr=filters->nearptr;
  98918. if(ptr==0){
  98919. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  98920. filters->nearDC_partialacc=temp;
  98921. }else{
  98922. decay=filters->nearDC_acc+=temp;
  98923. filters->nearDC_partialacc+=temp;
  98924. }
  98925. filters->nearDC_acc-=filters->nearDC[ptr];
  98926. filters->nearDC[ptr]=temp;
  98927. decay*=(1./(VE_NEARDC+1));
  98928. filters->nearptr++;
  98929. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  98930. decay=todB(&decay)*.5-15.f;
  98931. }
  98932. for(i=0;i<n/2;i+=2){
  98933. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  98934. val=todB(&val)*.5f;
  98935. if(val<decay)val=decay;
  98936. if(val<minV)val=minV;
  98937. vec[i>>1]=val;
  98938. decay-=8.;
  98939. }
  98940. for(j=0;j<VE_BANDS;j++){
  98941. float acc=0.;
  98942. float valmax,valmin;
  98943. for(i=0;i<bands[j].end;i++)
  98944. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  98945. acc*=bands[j].total;
  98946. {
  98947. int p,thisx=filters[j].ampptr;
  98948. float postmax,postmin,premax=-99999.f,premin=99999.f;
  98949. p=thisx;
  98950. p--;
  98951. if(p<0)p+=VE_AMP;
  98952. postmax=max(acc,filters[j].ampbuf[p]);
  98953. postmin=min(acc,filters[j].ampbuf[p]);
  98954. for(i=0;i<stretch;i++){
  98955. p--;
  98956. if(p<0)p+=VE_AMP;
  98957. premax=max(premax,filters[j].ampbuf[p]);
  98958. premin=min(premin,filters[j].ampbuf[p]);
  98959. }
  98960. valmin=postmin-premin;
  98961. valmax=postmax-premax;
  98962. filters[j].ampbuf[thisx]=acc;
  98963. filters[j].ampptr++;
  98964. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  98965. }
  98966. if(valmax>gi->preecho_thresh[j]+penalty){
  98967. ret|=1;
  98968. ret|=4;
  98969. }
  98970. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  98971. }
  98972. return(ret);
  98973. }
  98974. #if 0
  98975. static int seq=0;
  98976. static ogg_int64_t totalshift=-1024;
  98977. #endif
  98978. long _ve_envelope_search(vorbis_dsp_state *v){
  98979. vorbis_info *vi=v->vi;
  98980. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98981. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98982. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98983. long i,j;
  98984. int first=ve->current/ve->searchstep;
  98985. int last=v->pcm_current/ve->searchstep-VE_WIN;
  98986. if(first<0)first=0;
  98987. if(last+VE_WIN+VE_POST>ve->storage){
  98988. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  98989. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  98990. }
  98991. for(j=first;j<last;j++){
  98992. int ret=0;
  98993. ve->stretch++;
  98994. if(ve->stretch>VE_MAXSTRETCH*2)
  98995. ve->stretch=VE_MAXSTRETCH*2;
  98996. for(i=0;i<ve->ch;i++){
  98997. float *pcm=v->pcm[i]+ve->searchstep*(j);
  98998. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  98999. }
  99000. ve->mark[j+VE_POST]=0;
  99001. if(ret&1){
  99002. ve->mark[j]=1;
  99003. ve->mark[j+1]=1;
  99004. }
  99005. if(ret&2){
  99006. ve->mark[j]=1;
  99007. if(j>0)ve->mark[j-1]=1;
  99008. }
  99009. if(ret&4)ve->stretch=-1;
  99010. }
  99011. ve->current=last*ve->searchstep;
  99012. {
  99013. long centerW=v->centerW;
  99014. long testW=
  99015. centerW+
  99016. ci->blocksizes[v->W]/4+
  99017. ci->blocksizes[1]/2+
  99018. ci->blocksizes[0]/4;
  99019. j=ve->cursor;
  99020. while(j<ve->current-(ve->searchstep)){/* account for postecho
  99021. working back one window */
  99022. if(j>=testW)return(1);
  99023. ve->cursor=j;
  99024. if(ve->mark[j/ve->searchstep]){
  99025. if(j>centerW){
  99026. #if 0
  99027. if(j>ve->curmark){
  99028. float *marker=alloca(v->pcm_current*sizeof(*marker));
  99029. int l,m;
  99030. memset(marker,0,sizeof(*marker)*v->pcm_current);
  99031. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  99032. seq,
  99033. (totalshift+ve->cursor)/44100.,
  99034. (totalshift+j)/44100.);
  99035. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  99036. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  99037. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  99038. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  99039. for(m=0;m<VE_BANDS;m++){
  99040. char buf[80];
  99041. sprintf(buf,"delL%d",m);
  99042. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  99043. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99044. }
  99045. for(m=0;m<VE_BANDS;m++){
  99046. char buf[80];
  99047. sprintf(buf,"delR%d",m);
  99048. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  99049. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99050. }
  99051. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  99052. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  99053. seq++;
  99054. }
  99055. #endif
  99056. ve->curmark=j;
  99057. if(j>=testW)return(1);
  99058. return(0);
  99059. }
  99060. }
  99061. j+=ve->searchstep;
  99062. }
  99063. }
  99064. return(-1);
  99065. }
  99066. int _ve_envelope_mark(vorbis_dsp_state *v){
  99067. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99068. vorbis_info *vi=v->vi;
  99069. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99070. long centerW=v->centerW;
  99071. long beginW=centerW-ci->blocksizes[v->W]/4;
  99072. long endW=centerW+ci->blocksizes[v->W]/4;
  99073. if(v->W){
  99074. beginW-=ci->blocksizes[v->lW]/4;
  99075. endW+=ci->blocksizes[v->nW]/4;
  99076. }else{
  99077. beginW-=ci->blocksizes[0]/4;
  99078. endW+=ci->blocksizes[0]/4;
  99079. }
  99080. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  99081. {
  99082. long first=beginW/ve->searchstep;
  99083. long last=endW/ve->searchstep;
  99084. long i;
  99085. for(i=first;i<last;i++)
  99086. if(ve->mark[i])return(1);
  99087. }
  99088. return(0);
  99089. }
  99090. void _ve_envelope_shift(envelope_lookup *e,long shift){
  99091. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  99092. ahead of ve->current */
  99093. int smallshift=shift/e->searchstep;
  99094. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  99095. #if 0
  99096. for(i=0;i<VE_BANDS*e->ch;i++)
  99097. memmove(e->filter[i].markers,
  99098. e->filter[i].markers+smallshift,
  99099. (1024-smallshift)*sizeof(*(*e->filter).markers));
  99100. totalshift+=shift;
  99101. #endif
  99102. e->current-=shift;
  99103. if(e->curmark>=0)
  99104. e->curmark-=shift;
  99105. e->cursor-=shift;
  99106. }
  99107. #endif
  99108. /*** End of inlined file: envelope.c ***/
  99109. /*** Start of inlined file: floor0.c ***/
  99110. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99111. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99112. // tasks..
  99113. #if JUCE_MSVC
  99114. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99115. #endif
  99116. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99117. #if JUCE_USE_OGGVORBIS
  99118. #include <stdlib.h>
  99119. #include <string.h>
  99120. #include <math.h>
  99121. /*** Start of inlined file: lsp.h ***/
  99122. #ifndef _V_LSP_H_
  99123. #define _V_LSP_H_
  99124. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  99125. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  99126. float *lsp,int m,
  99127. float amp,float ampoffset);
  99128. #endif
  99129. /*** End of inlined file: lsp.h ***/
  99130. #include <stdio.h>
  99131. typedef struct {
  99132. int ln;
  99133. int m;
  99134. int **linearmap;
  99135. int n[2];
  99136. vorbis_info_floor0 *vi;
  99137. long bits;
  99138. long frames;
  99139. } vorbis_look_floor0;
  99140. static void floor0_free_info(vorbis_info_floor *i){
  99141. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  99142. if(info){
  99143. memset(info,0,sizeof(*info));
  99144. _ogg_free(info);
  99145. }
  99146. }
  99147. static void floor0_free_look(vorbis_look_floor *i){
  99148. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99149. if(look){
  99150. if(look->linearmap){
  99151. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  99152. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  99153. _ogg_free(look->linearmap);
  99154. }
  99155. memset(look,0,sizeof(*look));
  99156. _ogg_free(look);
  99157. }
  99158. }
  99159. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99160. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99161. int j;
  99162. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  99163. info->order=oggpack_read(opb,8);
  99164. info->rate=oggpack_read(opb,16);
  99165. info->barkmap=oggpack_read(opb,16);
  99166. info->ampbits=oggpack_read(opb,6);
  99167. info->ampdB=oggpack_read(opb,8);
  99168. info->numbooks=oggpack_read(opb,4)+1;
  99169. if(info->order<1)goto err_out;
  99170. if(info->rate<1)goto err_out;
  99171. if(info->barkmap<1)goto err_out;
  99172. if(info->numbooks<1)goto err_out;
  99173. for(j=0;j<info->numbooks;j++){
  99174. info->books[j]=oggpack_read(opb,8);
  99175. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  99176. }
  99177. return(info);
  99178. err_out:
  99179. floor0_free_info(info);
  99180. return(NULL);
  99181. }
  99182. static void floor0_map_lazy_init(vorbis_block *vb,
  99183. vorbis_info_floor *infoX,
  99184. vorbis_look_floor0 *look){
  99185. if(!look->linearmap[vb->W]){
  99186. vorbis_dsp_state *vd=vb->vd;
  99187. vorbis_info *vi=vd->vi;
  99188. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99189. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  99190. int W=vb->W;
  99191. int n=ci->blocksizes[W]/2,j;
  99192. float scale=look->ln/toBARK(info->rate/2.f);
  99193. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  99194. for(j=0;j<n;j++){
  99195. int val=floor( toBARK((info->rate/2.f)/n*j)
  99196. *scale); /* bark numbers represent band edges */
  99197. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  99198. look->linearmap[W][j]=val;
  99199. }
  99200. look->linearmap[W][j]=-1;
  99201. look->n[W]=n;
  99202. }
  99203. }
  99204. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  99205. vorbis_info_floor *i){
  99206. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  99207. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  99208. look->m=info->order;
  99209. look->ln=info->barkmap;
  99210. look->vi=info;
  99211. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  99212. return look;
  99213. }
  99214. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  99215. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99216. vorbis_info_floor0 *info=look->vi;
  99217. int j,k;
  99218. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  99219. if(ampraw>0){ /* also handles the -1 out of data case */
  99220. long maxval=(1<<info->ampbits)-1;
  99221. float amp=(float)ampraw/maxval*info->ampdB;
  99222. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  99223. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  99224. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  99225. codebook *b=ci->fullbooks+info->books[booknum];
  99226. float last=0.f;
  99227. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  99228. for(j=0;j<look->m;j+=b->dim)
  99229. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  99230. for(j=0;j<look->m;){
  99231. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  99232. last=lsp[j-1];
  99233. }
  99234. lsp[look->m]=amp;
  99235. return(lsp);
  99236. }
  99237. }
  99238. eop:
  99239. return(NULL);
  99240. }
  99241. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  99242. void *memo,float *out){
  99243. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99244. vorbis_info_floor0 *info=look->vi;
  99245. floor0_map_lazy_init(vb,info,look);
  99246. if(memo){
  99247. float *lsp=(float *)memo;
  99248. float amp=lsp[look->m];
  99249. vorbis_lsp_to_curve(out,
  99250. look->linearmap[vb->W],
  99251. look->n[vb->W],
  99252. look->ln,
  99253. lsp,look->m,amp,(float)info->ampdB);
  99254. return(1);
  99255. }
  99256. memset(out,0,sizeof(*out)*look->n[vb->W]);
  99257. return(0);
  99258. }
  99259. vorbis_func_floor floor0_exportbundle={
  99260. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  99261. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  99262. };
  99263. #endif
  99264. /*** End of inlined file: floor0.c ***/
  99265. /*** Start of inlined file: floor1.c ***/
  99266. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99267. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99268. // tasks..
  99269. #if JUCE_MSVC
  99270. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99271. #endif
  99272. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99273. #if JUCE_USE_OGGVORBIS
  99274. #include <stdlib.h>
  99275. #include <string.h>
  99276. #include <math.h>
  99277. #include <stdio.h>
  99278. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  99279. typedef struct {
  99280. int sorted_index[VIF_POSIT+2];
  99281. int forward_index[VIF_POSIT+2];
  99282. int reverse_index[VIF_POSIT+2];
  99283. int hineighbor[VIF_POSIT];
  99284. int loneighbor[VIF_POSIT];
  99285. int posts;
  99286. int n;
  99287. int quant_q;
  99288. vorbis_info_floor1 *vi;
  99289. long phrasebits;
  99290. long postbits;
  99291. long frames;
  99292. } vorbis_look_floor1;
  99293. typedef struct lsfit_acc{
  99294. long x0;
  99295. long x1;
  99296. long xa;
  99297. long ya;
  99298. long x2a;
  99299. long y2a;
  99300. long xya;
  99301. long an;
  99302. } lsfit_acc;
  99303. static void floor1_free_info(vorbis_info_floor *i){
  99304. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99305. if(info){
  99306. memset(info,0,sizeof(*info));
  99307. _ogg_free(info);
  99308. }
  99309. }
  99310. static void floor1_free_look(vorbis_look_floor *i){
  99311. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99312. if(look){
  99313. memset(look,0,sizeof(*look));
  99314. _ogg_free(look);
  99315. }
  99316. }
  99317. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99318. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99319. int j,k;
  99320. int count=0;
  99321. int rangebits;
  99322. int maxposit=info->postlist[1];
  99323. int maxclass=-1;
  99324. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99325. for(j=0;j<info->partitions;j++){
  99326. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99327. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99328. }
  99329. for(j=0;j<maxclass+1;j++){
  99330. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99331. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99332. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99333. for(k=0;k<(1<<info->class_subs[j]);k++)
  99334. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99335. }
  99336. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99337. oggpack_write(opb,ilog2(maxposit),4);
  99338. rangebits=ilog2(maxposit);
  99339. for(j=0,k=0;j<info->partitions;j++){
  99340. count+=info->class_dim[info->partitionclass[j]];
  99341. for(;k<count;k++)
  99342. oggpack_write(opb,info->postlist[k+2],rangebits);
  99343. }
  99344. }
  99345. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99346. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99347. int j,k,count=0,maxclass=-1,rangebits;
  99348. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99349. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99350. for(j=0;j<info->partitions;j++){
  99351. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  99352. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99353. }
  99354. for(j=0;j<maxclass+1;j++){
  99355. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99356. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99357. if(info->class_subs[j]<0)
  99358. goto err_out;
  99359. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99360. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99361. goto err_out;
  99362. for(k=0;k<(1<<info->class_subs[j]);k++){
  99363. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99364. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99365. goto err_out;
  99366. }
  99367. }
  99368. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99369. rangebits=oggpack_read(opb,4);
  99370. for(j=0,k=0;j<info->partitions;j++){
  99371. count+=info->class_dim[info->partitionclass[j]];
  99372. for(;k<count;k++){
  99373. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  99374. if(t<0 || t>=(1<<rangebits))
  99375. goto err_out;
  99376. }
  99377. }
  99378. info->postlist[0]=0;
  99379. info->postlist[1]=1<<rangebits;
  99380. return(info);
  99381. err_out:
  99382. floor1_free_info(info);
  99383. return(NULL);
  99384. }
  99385. static int icomp(const void *a,const void *b){
  99386. return(**(int **)a-**(int **)b);
  99387. }
  99388. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  99389. vorbis_info_floor *in){
  99390. int *sortpointer[VIF_POSIT+2];
  99391. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  99392. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  99393. int i,j,n=0;
  99394. look->vi=info;
  99395. look->n=info->postlist[1];
  99396. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99397. n+=2;
  99398. look->posts=n;
  99399. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99400. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99401. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99402. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99403. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99404. switch(info->mult){
  99405. case 1: /* 1024 -> 256 */
  99406. look->quant_q=256;
  99407. break;
  99408. case 2: /* 1024 -> 128 */
  99409. look->quant_q=128;
  99410. break;
  99411. case 3: /* 1024 -> 86 */
  99412. look->quant_q=86;
  99413. break;
  99414. case 4: /* 1024 -> 64 */
  99415. look->quant_q=64;
  99416. break;
  99417. }
  99418. for(i=0;i<n-2;i++){
  99419. int lo=0;
  99420. int hi=1;
  99421. int lx=0;
  99422. int hx=look->n;
  99423. int currentx=info->postlist[i+2];
  99424. for(j=0;j<i+2;j++){
  99425. int x=info->postlist[j];
  99426. if(x>lx && x<currentx){
  99427. lo=j;
  99428. lx=x;
  99429. }
  99430. if(x<hx && x>currentx){
  99431. hi=j;
  99432. hx=x;
  99433. }
  99434. }
  99435. look->loneighbor[i]=lo;
  99436. look->hineighbor[i]=hi;
  99437. }
  99438. return(look);
  99439. }
  99440. static int render_point(int x0,int x1,int y0,int y1,int x){
  99441. y0&=0x7fff; /* mask off flag */
  99442. y1&=0x7fff;
  99443. {
  99444. int dy=y1-y0;
  99445. int adx=x1-x0;
  99446. int ady=abs(dy);
  99447. int err=ady*(x-x0);
  99448. int off=err/adx;
  99449. if(dy<0)return(y0-off);
  99450. return(y0+off);
  99451. }
  99452. }
  99453. static int vorbis_dBquant(const float *x){
  99454. int i= *x*7.3142857f+1023.5f;
  99455. if(i>1023)return(1023);
  99456. if(i<0)return(0);
  99457. return i;
  99458. }
  99459. static float FLOOR1_fromdB_LOOKUP[256]={
  99460. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99461. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99462. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99463. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99464. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99465. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99466. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99467. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99468. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99469. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99470. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99471. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99472. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99473. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99474. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99475. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99476. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99477. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99478. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99479. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99480. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99481. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99482. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99483. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99484. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99485. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99486. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99487. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99488. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99489. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99490. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99491. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99492. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99493. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99494. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99495. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99496. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99497. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99498. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99499. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99500. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99501. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99502. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99503. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99504. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99505. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99506. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99507. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99508. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99509. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99510. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99511. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99512. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99513. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99514. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99515. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99516. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99517. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99518. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99519. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99520. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99521. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99522. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99523. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99524. };
  99525. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99526. int dy=y1-y0;
  99527. int adx=x1-x0;
  99528. int ady=abs(dy);
  99529. int base=dy/adx;
  99530. int sy=(dy<0?base-1:base+1);
  99531. int x=x0;
  99532. int y=y0;
  99533. int err=0;
  99534. ady-=abs(base*adx);
  99535. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99536. while(++x<x1){
  99537. err=err+ady;
  99538. if(err>=adx){
  99539. err-=adx;
  99540. y+=sy;
  99541. }else{
  99542. y+=base;
  99543. }
  99544. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99545. }
  99546. }
  99547. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99548. int dy=y1-y0;
  99549. int adx=x1-x0;
  99550. int ady=abs(dy);
  99551. int base=dy/adx;
  99552. int sy=(dy<0?base-1:base+1);
  99553. int x=x0;
  99554. int y=y0;
  99555. int err=0;
  99556. ady-=abs(base*adx);
  99557. d[x]=y;
  99558. while(++x<x1){
  99559. err=err+ady;
  99560. if(err>=adx){
  99561. err-=adx;
  99562. y+=sy;
  99563. }else{
  99564. y+=base;
  99565. }
  99566. d[x]=y;
  99567. }
  99568. }
  99569. static int accumulate_fit(const float *flr,const float *mdct,
  99570. int x0, int x1,lsfit_acc *a,
  99571. int n,vorbis_info_floor1 *info){
  99572. long i;
  99573. 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;
  99574. memset(a,0,sizeof(*a));
  99575. a->x0=x0;
  99576. a->x1=x1;
  99577. if(x1>=n)x1=n-1;
  99578. for(i=x0;i<=x1;i++){
  99579. int quantized=vorbis_dBquant(flr+i);
  99580. if(quantized){
  99581. if(mdct[i]+info->twofitatten>=flr[i]){
  99582. xa += i;
  99583. ya += quantized;
  99584. x2a += i*i;
  99585. y2a += quantized*quantized;
  99586. xya += i*quantized;
  99587. na++;
  99588. }else{
  99589. xb += i;
  99590. yb += quantized;
  99591. x2b += i*i;
  99592. y2b += quantized*quantized;
  99593. xyb += i*quantized;
  99594. nb++;
  99595. }
  99596. }
  99597. }
  99598. xb+=xa;
  99599. yb+=ya;
  99600. x2b+=x2a;
  99601. y2b+=y2a;
  99602. xyb+=xya;
  99603. nb+=na;
  99604. {
  99605. int weight=nb*info->twofitweight/(na+1);
  99606. a->xa=xa*weight+xb;
  99607. a->ya=ya*weight+yb;
  99608. a->x2a=x2a*weight+x2b;
  99609. a->y2a=y2a*weight+y2b;
  99610. a->xya=xya*weight+xyb;
  99611. a->an=na*weight+nb;
  99612. }
  99613. return(na);
  99614. }
  99615. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99616. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99617. long x0=a[0].x0;
  99618. long x1=a[fits-1].x1;
  99619. for(i=0;i<fits;i++){
  99620. x+=a[i].xa;
  99621. y+=a[i].ya;
  99622. x2+=a[i].x2a;
  99623. y2+=a[i].y2a;
  99624. xy+=a[i].xya;
  99625. an+=a[i].an;
  99626. }
  99627. if(*y0>=0){
  99628. x+= x0;
  99629. y+= *y0;
  99630. x2+= x0 * x0;
  99631. y2+= *y0 * *y0;
  99632. xy+= *y0 * x0;
  99633. an++;
  99634. }
  99635. if(*y1>=0){
  99636. x+= x1;
  99637. y+= *y1;
  99638. x2+= x1 * x1;
  99639. y2+= *y1 * *y1;
  99640. xy+= *y1 * x1;
  99641. an++;
  99642. }
  99643. if(an){
  99644. double fx=x;
  99645. double fy=y;
  99646. double fx2=x2;
  99647. double fxy=xy;
  99648. double denom=1./(an*fx2-fx*fx);
  99649. double a=(fy*fx2-fxy*fx)*denom;
  99650. double b=(an*fxy-fx*fy)*denom;
  99651. *y0=rint(a+b*x0);
  99652. *y1=rint(a+b*x1);
  99653. if(*y0>1023)*y0=1023;
  99654. if(*y1>1023)*y1=1023;
  99655. if(*y0<0)*y0=0;
  99656. if(*y1<0)*y1=0;
  99657. }else{
  99658. *y0=0;
  99659. *y1=0;
  99660. }
  99661. }
  99662. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99663. const float *mdct,
  99664. vorbis_info_floor1 *info){
  99665. int dy=y1-y0;
  99666. int adx=x1-x0;
  99667. int ady=abs(dy);
  99668. int base=dy/adx;
  99669. int sy=(dy<0?base-1:base+1);
  99670. int x=x0;
  99671. int y=y0;
  99672. int err=0;
  99673. int val=vorbis_dBquant(mask+x);
  99674. int mse=0;
  99675. int n=0;
  99676. ady-=abs(base*adx);
  99677. mse=(y-val);
  99678. mse*=mse;
  99679. n++;
  99680. if(mdct[x]+info->twofitatten>=mask[x]){
  99681. if(y+info->maxover<val)return(1);
  99682. if(y-info->maxunder>val)return(1);
  99683. }
  99684. while(++x<x1){
  99685. err=err+ady;
  99686. if(err>=adx){
  99687. err-=adx;
  99688. y+=sy;
  99689. }else{
  99690. y+=base;
  99691. }
  99692. val=vorbis_dBquant(mask+x);
  99693. mse+=((y-val)*(y-val));
  99694. n++;
  99695. if(mdct[x]+info->twofitatten>=mask[x]){
  99696. if(val){
  99697. if(y+info->maxover<val)return(1);
  99698. if(y-info->maxunder>val)return(1);
  99699. }
  99700. }
  99701. }
  99702. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  99703. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  99704. if(mse/n>info->maxerr)return(1);
  99705. return(0);
  99706. }
  99707. static int post_Y(int *A,int *B,int pos){
  99708. if(A[pos]<0)
  99709. return B[pos];
  99710. if(B[pos]<0)
  99711. return A[pos];
  99712. return (A[pos]+B[pos])>>1;
  99713. }
  99714. int *floor1_fit(vorbis_block *vb,void *look_,
  99715. const float *logmdct, /* in */
  99716. const float *logmask){
  99717. long i,j;
  99718. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  99719. vorbis_info_floor1 *info=look->vi;
  99720. long n=look->n;
  99721. long posts=look->posts;
  99722. long nonzero=0;
  99723. lsfit_acc fits[VIF_POSIT+1];
  99724. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  99725. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  99726. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  99727. int hineighbor[VIF_POSIT+2];
  99728. int *output=NULL;
  99729. int memo[VIF_POSIT+2];
  99730. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  99731. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  99732. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  99733. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  99734. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  99735. if(posts==0){
  99736. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  99737. }else{
  99738. for(i=0;i<posts-1;i++)
  99739. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  99740. look->sorted_index[i+1],fits+i,
  99741. n,info);
  99742. }
  99743. if(nonzero){
  99744. int y0=-200;
  99745. int y1=-200;
  99746. fit_line(fits,posts-1,&y0,&y1);
  99747. fit_valueA[0]=y0;
  99748. fit_valueB[0]=y0;
  99749. fit_valueB[1]=y1;
  99750. fit_valueA[1]=y1;
  99751. for(i=2;i<posts;i++){
  99752. int sortpos=look->reverse_index[i];
  99753. int ln=loneighbor[sortpos];
  99754. int hn=hineighbor[sortpos];
  99755. if(memo[ln]!=hn){
  99756. int lsortpos=look->reverse_index[ln];
  99757. int hsortpos=look->reverse_index[hn];
  99758. memo[ln]=hn;
  99759. {
  99760. int lx=info->postlist[ln];
  99761. int hx=info->postlist[hn];
  99762. int ly=post_Y(fit_valueA,fit_valueB,ln);
  99763. int hy=post_Y(fit_valueA,fit_valueB,hn);
  99764. if(ly==-1 || hy==-1){
  99765. exit(1);
  99766. }
  99767. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  99768. int ly0=-200;
  99769. int ly1=-200;
  99770. int hy0=-200;
  99771. int hy1=-200;
  99772. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  99773. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  99774. fit_valueB[ln]=ly0;
  99775. if(ln==0)fit_valueA[ln]=ly0;
  99776. fit_valueA[i]=ly1;
  99777. fit_valueB[i]=hy0;
  99778. fit_valueA[hn]=hy1;
  99779. if(hn==1)fit_valueB[hn]=hy1;
  99780. if(ly1>=0 || hy0>=0){
  99781. for(j=sortpos-1;j>=0;j--)
  99782. if(hineighbor[j]==hn)
  99783. hineighbor[j]=i;
  99784. else
  99785. break;
  99786. for(j=sortpos+1;j<posts;j++)
  99787. if(loneighbor[j]==ln)
  99788. loneighbor[j]=i;
  99789. else
  99790. break;
  99791. }
  99792. }else{
  99793. fit_valueA[i]=-200;
  99794. fit_valueB[i]=-200;
  99795. }
  99796. }
  99797. }
  99798. }
  99799. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99800. output[0]=post_Y(fit_valueA,fit_valueB,0);
  99801. output[1]=post_Y(fit_valueA,fit_valueB,1);
  99802. for(i=2;i<posts;i++){
  99803. int ln=look->loneighbor[i-2];
  99804. int hn=look->hineighbor[i-2];
  99805. int x0=info->postlist[ln];
  99806. int x1=info->postlist[hn];
  99807. int y0=output[ln];
  99808. int y1=output[hn];
  99809. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99810. int vx=post_Y(fit_valueA,fit_valueB,i);
  99811. if(vx>=0 && predicted!=vx){
  99812. output[i]=vx;
  99813. }else{
  99814. output[i]= predicted|0x8000;
  99815. }
  99816. }
  99817. }
  99818. return(output);
  99819. }
  99820. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  99821. int *A,int *B,
  99822. int del){
  99823. long i;
  99824. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  99825. long posts=look->posts;
  99826. int *output=NULL;
  99827. if(A && B){
  99828. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99829. for(i=0;i<posts;i++){
  99830. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  99831. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  99832. }
  99833. }
  99834. return(output);
  99835. }
  99836. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  99837. void*look_,
  99838. int *post,int *ilogmask){
  99839. long i,j;
  99840. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  99841. vorbis_info_floor1 *info=look->vi;
  99842. long posts=look->posts;
  99843. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99844. int out[VIF_POSIT+2];
  99845. static_codebook **sbooks=ci->book_param;
  99846. codebook *books=ci->fullbooks;
  99847. static long seq=0;
  99848. if(post){
  99849. for(i=0;i<posts;i++){
  99850. int val=post[i]&0x7fff;
  99851. switch(info->mult){
  99852. case 1: /* 1024 -> 256 */
  99853. val>>=2;
  99854. break;
  99855. case 2: /* 1024 -> 128 */
  99856. val>>=3;
  99857. break;
  99858. case 3: /* 1024 -> 86 */
  99859. val/=12;
  99860. break;
  99861. case 4: /* 1024 -> 64 */
  99862. val>>=4;
  99863. break;
  99864. }
  99865. post[i]=val | (post[i]&0x8000);
  99866. }
  99867. out[0]=post[0];
  99868. out[1]=post[1];
  99869. for(i=2;i<posts;i++){
  99870. int ln=look->loneighbor[i-2];
  99871. int hn=look->hineighbor[i-2];
  99872. int x0=info->postlist[ln];
  99873. int x1=info->postlist[hn];
  99874. int y0=post[ln];
  99875. int y1=post[hn];
  99876. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99877. if((post[i]&0x8000) || (predicted==post[i])){
  99878. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  99879. in interpolation */
  99880. out[i]=0;
  99881. }else{
  99882. int headroom=(look->quant_q-predicted<predicted?
  99883. look->quant_q-predicted:predicted);
  99884. int val=post[i]-predicted;
  99885. if(val<0)
  99886. if(val<-headroom)
  99887. val=headroom-val-1;
  99888. else
  99889. val=-1-(val<<1);
  99890. else
  99891. if(val>=headroom)
  99892. val= val+headroom;
  99893. else
  99894. val<<=1;
  99895. out[i]=val;
  99896. post[ln]&=0x7fff;
  99897. post[hn]&=0x7fff;
  99898. }
  99899. }
  99900. oggpack_write(opb,1,1);
  99901. look->frames++;
  99902. look->postbits+=ilog(look->quant_q-1)*2;
  99903. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  99904. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  99905. for(i=0,j=2;i<info->partitions;i++){
  99906. int classx=info->partitionclass[i];
  99907. int cdim=info->class_dim[classx];
  99908. int csubbits=info->class_subs[classx];
  99909. int csub=1<<csubbits;
  99910. int bookas[8]={0,0,0,0,0,0,0,0};
  99911. int cval=0;
  99912. int cshift=0;
  99913. int k,l;
  99914. if(csubbits){
  99915. int maxval[8];
  99916. for(k=0;k<csub;k++){
  99917. int booknum=info->class_subbook[classx][k];
  99918. if(booknum<0){
  99919. maxval[k]=1;
  99920. }else{
  99921. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  99922. }
  99923. }
  99924. for(k=0;k<cdim;k++){
  99925. for(l=0;l<csub;l++){
  99926. int val=out[j+k];
  99927. if(val<maxval[l]){
  99928. bookas[k]=l;
  99929. break;
  99930. }
  99931. }
  99932. cval|= bookas[k]<<cshift;
  99933. cshift+=csubbits;
  99934. }
  99935. look->phrasebits+=
  99936. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  99937. #ifdef TRAIN_FLOOR1
  99938. {
  99939. FILE *of;
  99940. char buffer[80];
  99941. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  99942. vb->pcmend/2,posts-2,class);
  99943. of=fopen(buffer,"a");
  99944. fprintf(of,"%d\n",cval);
  99945. fclose(of);
  99946. }
  99947. #endif
  99948. }
  99949. for(k=0;k<cdim;k++){
  99950. int book=info->class_subbook[classx][bookas[k]];
  99951. if(book>=0){
  99952. if(out[j+k]<(books+book)->entries)
  99953. look->postbits+=vorbis_book_encode(books+book,
  99954. out[j+k],opb);
  99955. #ifdef TRAIN_FLOOR1
  99956. {
  99957. FILE *of;
  99958. char buffer[80];
  99959. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  99960. vb->pcmend/2,posts-2,class,bookas[k]);
  99961. of=fopen(buffer,"a");
  99962. fprintf(of,"%d\n",out[j+k]);
  99963. fclose(of);
  99964. }
  99965. #endif
  99966. }
  99967. }
  99968. j+=cdim;
  99969. }
  99970. {
  99971. int hx=0;
  99972. int lx=0;
  99973. int ly=post[0]*info->mult;
  99974. for(j=1;j<look->posts;j++){
  99975. int current=look->forward_index[j];
  99976. int hy=post[current]&0x7fff;
  99977. if(hy==post[current]){
  99978. hy*=info->mult;
  99979. hx=info->postlist[current];
  99980. render_line0(lx,hx,ly,hy,ilogmask);
  99981. lx=hx;
  99982. ly=hy;
  99983. }
  99984. }
  99985. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  99986. seq++;
  99987. return(1);
  99988. }
  99989. }else{
  99990. oggpack_write(opb,0,1);
  99991. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  99992. seq++;
  99993. return(0);
  99994. }
  99995. }
  99996. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  99997. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99998. vorbis_info_floor1 *info=look->vi;
  99999. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100000. int i,j,k;
  100001. codebook *books=ci->fullbooks;
  100002. if(oggpack_read(&vb->opb,1)==1){
  100003. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  100004. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100005. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100006. for(i=0,j=2;i<info->partitions;i++){
  100007. int classx=info->partitionclass[i];
  100008. int cdim=info->class_dim[classx];
  100009. int csubbits=info->class_subs[classx];
  100010. int csub=1<<csubbits;
  100011. int cval=0;
  100012. if(csubbits){
  100013. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  100014. if(cval==-1)goto eop;
  100015. }
  100016. for(k=0;k<cdim;k++){
  100017. int book=info->class_subbook[classx][cval&(csub-1)];
  100018. cval>>=csubbits;
  100019. if(book>=0){
  100020. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  100021. goto eop;
  100022. }else{
  100023. fit_value[j+k]=0;
  100024. }
  100025. }
  100026. j+=cdim;
  100027. }
  100028. for(i=2;i<look->posts;i++){
  100029. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  100030. info->postlist[look->hineighbor[i-2]],
  100031. fit_value[look->loneighbor[i-2]],
  100032. fit_value[look->hineighbor[i-2]],
  100033. info->postlist[i]);
  100034. int hiroom=look->quant_q-predicted;
  100035. int loroom=predicted;
  100036. int room=(hiroom<loroom?hiroom:loroom)<<1;
  100037. int val=fit_value[i];
  100038. if(val){
  100039. if(val>=room){
  100040. if(hiroom>loroom){
  100041. val = val-loroom;
  100042. }else{
  100043. val = -1-(val-hiroom);
  100044. }
  100045. }else{
  100046. if(val&1){
  100047. val= -((val+1)>>1);
  100048. }else{
  100049. val>>=1;
  100050. }
  100051. }
  100052. fit_value[i]=val+predicted;
  100053. fit_value[look->loneighbor[i-2]]&=0x7fff;
  100054. fit_value[look->hineighbor[i-2]]&=0x7fff;
  100055. }else{
  100056. fit_value[i]=predicted|0x8000;
  100057. }
  100058. }
  100059. return(fit_value);
  100060. }
  100061. eop:
  100062. return(NULL);
  100063. }
  100064. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  100065. float *out){
  100066. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100067. vorbis_info_floor1 *info=look->vi;
  100068. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100069. int n=ci->blocksizes[vb->W]/2;
  100070. int j;
  100071. if(memo){
  100072. int *fit_value=(int *)memo;
  100073. int hx=0;
  100074. int lx=0;
  100075. int ly=fit_value[0]*info->mult;
  100076. for(j=1;j<look->posts;j++){
  100077. int current=look->forward_index[j];
  100078. int hy=fit_value[current]&0x7fff;
  100079. if(hy==fit_value[current]){
  100080. hy*=info->mult;
  100081. hx=info->postlist[current];
  100082. render_line(lx,hx,ly,hy,out);
  100083. lx=hx;
  100084. ly=hy;
  100085. }
  100086. }
  100087. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  100088. return(1);
  100089. }
  100090. memset(out,0,sizeof(*out)*n);
  100091. return(0);
  100092. }
  100093. vorbis_func_floor floor1_exportbundle={
  100094. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  100095. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  100096. };
  100097. #endif
  100098. /*** End of inlined file: floor1.c ***/
  100099. /*** Start of inlined file: info.c ***/
  100100. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100101. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100102. // tasks..
  100103. #if JUCE_MSVC
  100104. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100105. #endif
  100106. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100107. #if JUCE_USE_OGGVORBIS
  100108. #include <stdlib.h>
  100109. #include <string.h>
  100110. #include <ctype.h>
  100111. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  100112. while(bytes--){
  100113. oggpack_write(o,*s++,8);
  100114. }
  100115. }
  100116. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  100117. while(bytes--){
  100118. *buf++=oggpack_read(o,8);
  100119. }
  100120. }
  100121. void vorbis_comment_init(vorbis_comment *vc){
  100122. memset(vc,0,sizeof(*vc));
  100123. }
  100124. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  100125. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  100126. (vc->comments+2)*sizeof(*vc->user_comments));
  100127. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  100128. (vc->comments+2)*sizeof(*vc->comment_lengths));
  100129. vc->comment_lengths[vc->comments]=strlen(comment);
  100130. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  100131. strcpy(vc->user_comments[vc->comments], comment);
  100132. vc->comments++;
  100133. vc->user_comments[vc->comments]=NULL;
  100134. }
  100135. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  100136. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  100137. strcpy(comment, tag);
  100138. strcat(comment, "=");
  100139. strcat(comment, contents);
  100140. vorbis_comment_add(vc, comment);
  100141. }
  100142. static int tagcompare(const char *s1, const char *s2, int n){
  100143. int c=0;
  100144. while(c < n){
  100145. if(toupper(s1[c]) != toupper(s2[c]))
  100146. return !0;
  100147. c++;
  100148. }
  100149. return 0;
  100150. }
  100151. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  100152. long i;
  100153. int found = 0;
  100154. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100155. char *fulltag = (char*)alloca(taglen+ 1);
  100156. strcpy(fulltag, tag);
  100157. strcat(fulltag, "=");
  100158. for(i=0;i<vc->comments;i++){
  100159. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  100160. if(count == found)
  100161. return vc->user_comments[i] + taglen;
  100162. else
  100163. found++;
  100164. }
  100165. }
  100166. return NULL; /* didn't find anything */
  100167. }
  100168. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  100169. int i,count=0;
  100170. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100171. char *fulltag = (char*)alloca(taglen+1);
  100172. strcpy(fulltag,tag);
  100173. strcat(fulltag, "=");
  100174. for(i=0;i<vc->comments;i++){
  100175. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  100176. count++;
  100177. }
  100178. return count;
  100179. }
  100180. void vorbis_comment_clear(vorbis_comment *vc){
  100181. if(vc){
  100182. long i;
  100183. for(i=0;i<vc->comments;i++)
  100184. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  100185. if(vc->user_comments)_ogg_free(vc->user_comments);
  100186. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  100187. if(vc->vendor)_ogg_free(vc->vendor);
  100188. }
  100189. memset(vc,0,sizeof(*vc));
  100190. }
  100191. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  100192. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  100193. return ci ? ci->blocksizes[zo] : -1;
  100194. }
  100195. void vorbis_info_init(vorbis_info *vi){
  100196. memset(vi,0,sizeof(*vi));
  100197. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  100198. }
  100199. void vorbis_info_clear(vorbis_info *vi){
  100200. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100201. int i;
  100202. if(ci){
  100203. for(i=0;i<ci->modes;i++)
  100204. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  100205. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  100206. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  100207. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  100208. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  100209. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  100210. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  100211. for(i=0;i<ci->books;i++){
  100212. if(ci->book_param[i]){
  100213. vorbis_staticbook_destroy(ci->book_param[i]);
  100214. }
  100215. if(ci->fullbooks)
  100216. vorbis_book_clear(ci->fullbooks+i);
  100217. }
  100218. if(ci->fullbooks)
  100219. _ogg_free(ci->fullbooks);
  100220. for(i=0;i<ci->psys;i++)
  100221. _vi_psy_free(ci->psy_param[i]);
  100222. _ogg_free(ci);
  100223. }
  100224. memset(vi,0,sizeof(*vi));
  100225. }
  100226. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  100227. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100228. if(!ci)return(OV_EFAULT);
  100229. vi->version=oggpack_read(opb,32);
  100230. if(vi->version!=0)return(OV_EVERSION);
  100231. vi->channels=oggpack_read(opb,8);
  100232. vi->rate=oggpack_read(opb,32);
  100233. vi->bitrate_upper=oggpack_read(opb,32);
  100234. vi->bitrate_nominal=oggpack_read(opb,32);
  100235. vi->bitrate_lower=oggpack_read(opb,32);
  100236. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  100237. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  100238. if(vi->rate<1)goto err_out;
  100239. if(vi->channels<1)goto err_out;
  100240. if(ci->blocksizes[0]<8)goto err_out;
  100241. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  100242. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100243. return(0);
  100244. err_out:
  100245. vorbis_info_clear(vi);
  100246. return(OV_EBADHEADER);
  100247. }
  100248. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  100249. int i;
  100250. int vendorlen=oggpack_read(opb,32);
  100251. if(vendorlen<0)goto err_out;
  100252. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  100253. _v_readstring(opb,vc->vendor,vendorlen);
  100254. vc->comments=oggpack_read(opb,32);
  100255. if(vc->comments<0)goto err_out;
  100256. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  100257. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  100258. for(i=0;i<vc->comments;i++){
  100259. int len=oggpack_read(opb,32);
  100260. if(len<0)goto err_out;
  100261. vc->comment_lengths[i]=len;
  100262. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  100263. _v_readstring(opb,vc->user_comments[i],len);
  100264. }
  100265. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100266. return(0);
  100267. err_out:
  100268. vorbis_comment_clear(vc);
  100269. return(OV_EBADHEADER);
  100270. }
  100271. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  100272. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100273. int i;
  100274. if(!ci)return(OV_EFAULT);
  100275. ci->books=oggpack_read(opb,8)+1;
  100276. for(i=0;i<ci->books;i++){
  100277. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  100278. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  100279. }
  100280. {
  100281. int times=oggpack_read(opb,6)+1;
  100282. for(i=0;i<times;i++){
  100283. int test=oggpack_read(opb,16);
  100284. if(test<0 || test>=VI_TIMEB)goto err_out;
  100285. }
  100286. }
  100287. ci->floors=oggpack_read(opb,6)+1;
  100288. for(i=0;i<ci->floors;i++){
  100289. ci->floor_type[i]=oggpack_read(opb,16);
  100290. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100291. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100292. if(!ci->floor_param[i])goto err_out;
  100293. }
  100294. ci->residues=oggpack_read(opb,6)+1;
  100295. for(i=0;i<ci->residues;i++){
  100296. ci->residue_type[i]=oggpack_read(opb,16);
  100297. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100298. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100299. if(!ci->residue_param[i])goto err_out;
  100300. }
  100301. ci->maps=oggpack_read(opb,6)+1;
  100302. for(i=0;i<ci->maps;i++){
  100303. ci->map_type[i]=oggpack_read(opb,16);
  100304. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100305. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100306. if(!ci->map_param[i])goto err_out;
  100307. }
  100308. ci->modes=oggpack_read(opb,6)+1;
  100309. for(i=0;i<ci->modes;i++){
  100310. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100311. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100312. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100313. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100314. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100315. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100316. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100317. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100318. }
  100319. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100320. return(0);
  100321. err_out:
  100322. vorbis_info_clear(vi);
  100323. return(OV_EBADHEADER);
  100324. }
  100325. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100326. oggpack_buffer opb;
  100327. if(op){
  100328. oggpack_readinit(&opb,op->packet,op->bytes);
  100329. {
  100330. char buffer[6];
  100331. int packtype=oggpack_read(&opb,8);
  100332. memset(buffer,0,6);
  100333. _v_readstring(&opb,buffer,6);
  100334. if(memcmp(buffer,"vorbis",6)){
  100335. return(OV_ENOTVORBIS);
  100336. }
  100337. switch(packtype){
  100338. case 0x01: /* least significant *bit* is read first */
  100339. if(!op->b_o_s){
  100340. return(OV_EBADHEADER);
  100341. }
  100342. if(vi->rate!=0){
  100343. return(OV_EBADHEADER);
  100344. }
  100345. return(_vorbis_unpack_info(vi,&opb));
  100346. case 0x03: /* least significant *bit* is read first */
  100347. if(vi->rate==0){
  100348. return(OV_EBADHEADER);
  100349. }
  100350. return(_vorbis_unpack_comment(vc,&opb));
  100351. case 0x05: /* least significant *bit* is read first */
  100352. if(vi->rate==0 || vc->vendor==NULL){
  100353. return(OV_EBADHEADER);
  100354. }
  100355. return(_vorbis_unpack_books(vi,&opb));
  100356. default:
  100357. return(OV_EBADHEADER);
  100358. break;
  100359. }
  100360. }
  100361. }
  100362. return(OV_EBADHEADER);
  100363. }
  100364. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100365. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100366. if(!ci)return(OV_EFAULT);
  100367. oggpack_write(opb,0x01,8);
  100368. _v_writestring(opb,"vorbis", 6);
  100369. oggpack_write(opb,0x00,32);
  100370. oggpack_write(opb,vi->channels,8);
  100371. oggpack_write(opb,vi->rate,32);
  100372. oggpack_write(opb,vi->bitrate_upper,32);
  100373. oggpack_write(opb,vi->bitrate_nominal,32);
  100374. oggpack_write(opb,vi->bitrate_lower,32);
  100375. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  100376. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  100377. oggpack_write(opb,1,1);
  100378. return(0);
  100379. }
  100380. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  100381. char temp[]="Xiph.Org libVorbis I 20050304";
  100382. int bytes = strlen(temp);
  100383. oggpack_write(opb,0x03,8);
  100384. _v_writestring(opb,"vorbis", 6);
  100385. oggpack_write(opb,bytes,32);
  100386. _v_writestring(opb,temp, bytes);
  100387. oggpack_write(opb,vc->comments,32);
  100388. if(vc->comments){
  100389. int i;
  100390. for(i=0;i<vc->comments;i++){
  100391. if(vc->user_comments[i]){
  100392. oggpack_write(opb,vc->comment_lengths[i],32);
  100393. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  100394. }else{
  100395. oggpack_write(opb,0,32);
  100396. }
  100397. }
  100398. }
  100399. oggpack_write(opb,1,1);
  100400. return(0);
  100401. }
  100402. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100403. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100404. int i;
  100405. if(!ci)return(OV_EFAULT);
  100406. oggpack_write(opb,0x05,8);
  100407. _v_writestring(opb,"vorbis", 6);
  100408. oggpack_write(opb,ci->books-1,8);
  100409. for(i=0;i<ci->books;i++)
  100410. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100411. oggpack_write(opb,0,6);
  100412. oggpack_write(opb,0,16);
  100413. oggpack_write(opb,ci->floors-1,6);
  100414. for(i=0;i<ci->floors;i++){
  100415. oggpack_write(opb,ci->floor_type[i],16);
  100416. if(_floor_P[ci->floor_type[i]]->pack)
  100417. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100418. else
  100419. goto err_out;
  100420. }
  100421. oggpack_write(opb,ci->residues-1,6);
  100422. for(i=0;i<ci->residues;i++){
  100423. oggpack_write(opb,ci->residue_type[i],16);
  100424. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100425. }
  100426. oggpack_write(opb,ci->maps-1,6);
  100427. for(i=0;i<ci->maps;i++){
  100428. oggpack_write(opb,ci->map_type[i],16);
  100429. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100430. }
  100431. oggpack_write(opb,ci->modes-1,6);
  100432. for(i=0;i<ci->modes;i++){
  100433. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100434. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100435. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100436. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100437. }
  100438. oggpack_write(opb,1,1);
  100439. return(0);
  100440. err_out:
  100441. return(-1);
  100442. }
  100443. int vorbis_commentheader_out(vorbis_comment *vc,
  100444. ogg_packet *op){
  100445. oggpack_buffer opb;
  100446. oggpack_writeinit(&opb);
  100447. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100448. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100449. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100450. op->bytes=oggpack_bytes(&opb);
  100451. op->b_o_s=0;
  100452. op->e_o_s=0;
  100453. op->granulepos=0;
  100454. op->packetno=1;
  100455. return 0;
  100456. }
  100457. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100458. vorbis_comment *vc,
  100459. ogg_packet *op,
  100460. ogg_packet *op_comm,
  100461. ogg_packet *op_code){
  100462. int ret=OV_EIMPL;
  100463. vorbis_info *vi=v->vi;
  100464. oggpack_buffer opb;
  100465. private_state *b=(private_state*)v->backend_state;
  100466. if(!b){
  100467. ret=OV_EFAULT;
  100468. goto err_out;
  100469. }
  100470. oggpack_writeinit(&opb);
  100471. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100472. if(b->header)_ogg_free(b->header);
  100473. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100474. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100475. op->packet=b->header;
  100476. op->bytes=oggpack_bytes(&opb);
  100477. op->b_o_s=1;
  100478. op->e_o_s=0;
  100479. op->granulepos=0;
  100480. op->packetno=0;
  100481. oggpack_reset(&opb);
  100482. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100483. if(b->header1)_ogg_free(b->header1);
  100484. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100485. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100486. op_comm->packet=b->header1;
  100487. op_comm->bytes=oggpack_bytes(&opb);
  100488. op_comm->b_o_s=0;
  100489. op_comm->e_o_s=0;
  100490. op_comm->granulepos=0;
  100491. op_comm->packetno=1;
  100492. oggpack_reset(&opb);
  100493. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100494. if(b->header2)_ogg_free(b->header2);
  100495. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100496. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100497. op_code->packet=b->header2;
  100498. op_code->bytes=oggpack_bytes(&opb);
  100499. op_code->b_o_s=0;
  100500. op_code->e_o_s=0;
  100501. op_code->granulepos=0;
  100502. op_code->packetno=2;
  100503. oggpack_writeclear(&opb);
  100504. return(0);
  100505. err_out:
  100506. oggpack_writeclear(&opb);
  100507. memset(op,0,sizeof(*op));
  100508. memset(op_comm,0,sizeof(*op_comm));
  100509. memset(op_code,0,sizeof(*op_code));
  100510. if(b->header)_ogg_free(b->header);
  100511. if(b->header1)_ogg_free(b->header1);
  100512. if(b->header2)_ogg_free(b->header2);
  100513. b->header=NULL;
  100514. b->header1=NULL;
  100515. b->header2=NULL;
  100516. return(ret);
  100517. }
  100518. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100519. if(granulepos>=0)
  100520. return((double)granulepos/v->vi->rate);
  100521. return(-1);
  100522. }
  100523. #endif
  100524. /*** End of inlined file: info.c ***/
  100525. /*** Start of inlined file: lpc.c ***/
  100526. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100527. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100528. // tasks..
  100529. #if JUCE_MSVC
  100530. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100531. #endif
  100532. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100533. #if JUCE_USE_OGGVORBIS
  100534. #include <stdlib.h>
  100535. #include <string.h>
  100536. #include <math.h>
  100537. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100538. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100539. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100540. double error;
  100541. int i,j;
  100542. j=m+1;
  100543. while(j--){
  100544. double d=0; /* double needed for accumulator depth */
  100545. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100546. aut[j]=d;
  100547. }
  100548. error=aut[0];
  100549. for(i=0;i<m;i++){
  100550. double r= -aut[i+1];
  100551. if(error==0){
  100552. memset(lpci,0,m*sizeof(*lpci));
  100553. return 0;
  100554. }
  100555. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100556. r/=error;
  100557. lpc[i]=r;
  100558. for(j=0;j<i/2;j++){
  100559. double tmp=lpc[j];
  100560. lpc[j]+=r*lpc[i-1-j];
  100561. lpc[i-1-j]+=r*tmp;
  100562. }
  100563. if(i%2)lpc[j]+=lpc[j]*r;
  100564. error*=1.f-r*r;
  100565. }
  100566. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100567. return error;
  100568. }
  100569. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100570. float *data,long n){
  100571. long i,j,o,p;
  100572. float y;
  100573. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100574. if(!prime)
  100575. for(i=0;i<m;i++)
  100576. work[i]=0.f;
  100577. else
  100578. for(i=0;i<m;i++)
  100579. work[i]=prime[i];
  100580. for(i=0;i<n;i++){
  100581. y=0;
  100582. o=i;
  100583. p=m;
  100584. for(j=0;j<m;j++)
  100585. y-=work[o++]*coeff[--p];
  100586. data[i]=work[o]=y;
  100587. }
  100588. }
  100589. #endif
  100590. /*** End of inlined file: lpc.c ***/
  100591. /*** Start of inlined file: lsp.c ***/
  100592. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100593. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100594. // tasks..
  100595. #if JUCE_MSVC
  100596. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100597. #endif
  100598. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100599. #if JUCE_USE_OGGVORBIS
  100600. #include <math.h>
  100601. #include <string.h>
  100602. #include <stdlib.h>
  100603. /*** Start of inlined file: lookup.h ***/
  100604. #ifndef _V_LOOKUP_H_
  100605. #ifdef FLOAT_LOOKUP
  100606. extern float vorbis_coslook(float a);
  100607. extern float vorbis_invsqlook(float a);
  100608. extern float vorbis_invsq2explook(int a);
  100609. extern float vorbis_fromdBlook(float a);
  100610. #endif
  100611. #ifdef INT_LOOKUP
  100612. extern long vorbis_invsqlook_i(long a,long e);
  100613. extern long vorbis_coslook_i(long a);
  100614. extern float vorbis_fromdBlook_i(long a);
  100615. #endif
  100616. #endif
  100617. /*** End of inlined file: lookup.h ***/
  100618. #define FLOAT_LOOKUP
  100619. #undef INT_LOOKUP
  100620. #ifdef FLOAT_LOOKUP
  100621. /*** Start of inlined file: lookup.c ***/
  100622. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100623. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100624. // tasks..
  100625. #if JUCE_MSVC
  100626. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100627. #endif
  100628. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100629. #if JUCE_USE_OGGVORBIS
  100630. #include <math.h>
  100631. /*** Start of inlined file: lookup.h ***/
  100632. #ifndef _V_LOOKUP_H_
  100633. #ifdef FLOAT_LOOKUP
  100634. extern float vorbis_coslook(float a);
  100635. extern float vorbis_invsqlook(float a);
  100636. extern float vorbis_invsq2explook(int a);
  100637. extern float vorbis_fromdBlook(float a);
  100638. #endif
  100639. #ifdef INT_LOOKUP
  100640. extern long vorbis_invsqlook_i(long a,long e);
  100641. extern long vorbis_coslook_i(long a);
  100642. extern float vorbis_fromdBlook_i(long a);
  100643. #endif
  100644. #endif
  100645. /*** End of inlined file: lookup.h ***/
  100646. /*** Start of inlined file: lookup_data.h ***/
  100647. #ifndef _V_LOOKUP_DATA_H_
  100648. #ifdef FLOAT_LOOKUP
  100649. #define COS_LOOKUP_SZ 128
  100650. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100651. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100652. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100653. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100654. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100655. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100656. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100657. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100658. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100659. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100660. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100661. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100662. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100663. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100664. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100665. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100666. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100667. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100668. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100669. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100670. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100671. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100672. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100673. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100674. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100675. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100676. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100677. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100678. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100679. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100680. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100681. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100682. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100683. -1.0000000000000f,
  100684. };
  100685. #define INVSQ_LOOKUP_SZ 32
  100686. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100687. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100688. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100689. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100690. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100691. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100692. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100693. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100694. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100695. 1.000000000000f,
  100696. };
  100697. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100698. #define INVSQ2EXP_LOOKUP_MAX 32
  100699. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100700. INVSQ2EXP_LOOKUP_MIN+1]={
  100701. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100702. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100703. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100704. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100705. 256.f, 181.019336f, 128.f, 90.50966799f,
  100706. 64.f, 45.254834f, 32.f, 22.627417f,
  100707. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100708. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100709. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100710. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100711. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100712. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100713. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100714. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100715. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100716. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100717. 1.525878906e-05f,
  100718. };
  100719. #endif
  100720. #define FROMdB_LOOKUP_SZ 35
  100721. #define FROMdB2_LOOKUP_SZ 32
  100722. #define FROMdB_SHIFT 5
  100723. #define FROMdB2_SHIFT 3
  100724. #define FROMdB2_MASK 31
  100725. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100726. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100727. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100728. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100729. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100730. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100731. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100732. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100733. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100734. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100735. };
  100736. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100737. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100738. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100739. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100740. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100741. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100742. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100743. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100744. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100745. };
  100746. #ifdef INT_LOOKUP
  100747. #define INVSQ_LOOKUP_I_SHIFT 10
  100748. #define INVSQ_LOOKUP_I_MASK 1023
  100749. static long INVSQ_LOOKUP_I[64+1]={
  100750. 92682l, 91966l, 91267l, 90583l,
  100751. 89915l, 89261l, 88621l, 87995l,
  100752. 87381l, 86781l, 86192l, 85616l,
  100753. 85051l, 84497l, 83953l, 83420l,
  100754. 82897l, 82384l, 81880l, 81385l,
  100755. 80899l, 80422l, 79953l, 79492l,
  100756. 79039l, 78594l, 78156l, 77726l,
  100757. 77302l, 76885l, 76475l, 76072l,
  100758. 75674l, 75283l, 74898l, 74519l,
  100759. 74146l, 73778l, 73415l, 73058l,
  100760. 72706l, 72359l, 72016l, 71679l,
  100761. 71347l, 71019l, 70695l, 70376l,
  100762. 70061l, 69750l, 69444l, 69141l,
  100763. 68842l, 68548l, 68256l, 67969l,
  100764. 67685l, 67405l, 67128l, 66855l,
  100765. 66585l, 66318l, 66054l, 65794l,
  100766. 65536l,
  100767. };
  100768. #define COS_LOOKUP_I_SHIFT 9
  100769. #define COS_LOOKUP_I_MASK 511
  100770. #define COS_LOOKUP_I_SZ 128
  100771. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100772. 16384l, 16379l, 16364l, 16340l,
  100773. 16305l, 16261l, 16207l, 16143l,
  100774. 16069l, 15986l, 15893l, 15791l,
  100775. 15679l, 15557l, 15426l, 15286l,
  100776. 15137l, 14978l, 14811l, 14635l,
  100777. 14449l, 14256l, 14053l, 13842l,
  100778. 13623l, 13395l, 13160l, 12916l,
  100779. 12665l, 12406l, 12140l, 11866l,
  100780. 11585l, 11297l, 11003l, 10702l,
  100781. 10394l, 10080l, 9760l, 9434l,
  100782. 9102l, 8765l, 8423l, 8076l,
  100783. 7723l, 7366l, 7005l, 6639l,
  100784. 6270l, 5897l, 5520l, 5139l,
  100785. 4756l, 4370l, 3981l, 3590l,
  100786. 3196l, 2801l, 2404l, 2006l,
  100787. 1606l, 1205l, 804l, 402l,
  100788. 0l, -401l, -803l, -1204l,
  100789. -1605l, -2005l, -2403l, -2800l,
  100790. -3195l, -3589l, -3980l, -4369l,
  100791. -4755l, -5138l, -5519l, -5896l,
  100792. -6269l, -6638l, -7004l, -7365l,
  100793. -7722l, -8075l, -8422l, -8764l,
  100794. -9101l, -9433l, -9759l, -10079l,
  100795. -10393l, -10701l, -11002l, -11296l,
  100796. -11584l, -11865l, -12139l, -12405l,
  100797. -12664l, -12915l, -13159l, -13394l,
  100798. -13622l, -13841l, -14052l, -14255l,
  100799. -14448l, -14634l, -14810l, -14977l,
  100800. -15136l, -15285l, -15425l, -15556l,
  100801. -15678l, -15790l, -15892l, -15985l,
  100802. -16068l, -16142l, -16206l, -16260l,
  100803. -16304l, -16339l, -16363l, -16378l,
  100804. -16383l,
  100805. };
  100806. #endif
  100807. #endif
  100808. /*** End of inlined file: lookup_data.h ***/
  100809. #ifdef FLOAT_LOOKUP
  100810. float vorbis_coslook(float a){
  100811. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100812. int i=vorbis_ftoi(d-.5);
  100813. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100814. }
  100815. float vorbis_invsqlook(float a){
  100816. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100817. int i=vorbis_ftoi(d-.5f);
  100818. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100819. }
  100820. float vorbis_invsq2explook(int a){
  100821. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100822. }
  100823. #include <stdio.h>
  100824. float vorbis_fromdBlook(float a){
  100825. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100826. return (i<0)?1.f:
  100827. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100828. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100829. }
  100830. #endif
  100831. #ifdef INT_LOOKUP
  100832. long vorbis_invsqlook_i(long a,long e){
  100833. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100834. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100835. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100836. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100837. d)>>16); /* result 1.16 */
  100838. e+=32;
  100839. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100840. e=(e>>1)-8;
  100841. return(val>>e);
  100842. }
  100843. float vorbis_fromdBlook_i(long a){
  100844. int i=(-a)>>(12-FROMdB2_SHIFT);
  100845. return (i<0)?1.f:
  100846. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100847. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100848. }
  100849. long vorbis_coslook_i(long a){
  100850. int i=a>>COS_LOOKUP_I_SHIFT;
  100851. int d=a&COS_LOOKUP_I_MASK;
  100852. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100853. COS_LOOKUP_I_SHIFT);
  100854. }
  100855. #endif
  100856. #endif
  100857. /*** End of inlined file: lookup.c ***/
  100858. /* catch this in the build system; we #include for
  100859. compilers (like gcc) that can't inline across
  100860. modules */
  100861. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100862. float amp,float ampoffset){
  100863. int i;
  100864. float wdel=M_PI/ln;
  100865. vorbis_fpu_control fpu;
  100866. (void) fpu; // to avoid an unused variable warning
  100867. vorbis_fpu_setround(&fpu);
  100868. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  100869. i=0;
  100870. while(i<n){
  100871. int k=map[i];
  100872. int qexp;
  100873. float p=.7071067812f;
  100874. float q=.7071067812f;
  100875. float w=vorbis_coslook(wdel*k);
  100876. float *ftmp=lsp;
  100877. int c=m>>1;
  100878. do{
  100879. q*=ftmp[0]-w;
  100880. p*=ftmp[1]-w;
  100881. ftmp+=2;
  100882. }while(--c);
  100883. if(m&1){
  100884. q*=ftmp[0]-w;
  100885. q*=q;
  100886. p*=p*(1.f-w*w);
  100887. }else{
  100888. q*=q*(1.f+w);
  100889. p*=p*(1.f-w);
  100890. }
  100891. q=frexp(p+q,&qexp);
  100892. q=vorbis_fromdBlook(amp*
  100893. vorbis_invsqlook(q)*
  100894. vorbis_invsq2explook(qexp+m)-
  100895. ampoffset);
  100896. do{
  100897. curve[i++]*=q;
  100898. }while(map[i]==k);
  100899. }
  100900. vorbis_fpu_restore(fpu);
  100901. }
  100902. #else
  100903. #ifdef INT_LOOKUP
  100904. /*** Start of inlined file: lookup.c ***/
  100905. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100906. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100907. // tasks..
  100908. #if JUCE_MSVC
  100909. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100910. #endif
  100911. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100912. #if JUCE_USE_OGGVORBIS
  100913. #include <math.h>
  100914. /*** Start of inlined file: lookup.h ***/
  100915. #ifndef _V_LOOKUP_H_
  100916. #ifdef FLOAT_LOOKUP
  100917. extern float vorbis_coslook(float a);
  100918. extern float vorbis_invsqlook(float a);
  100919. extern float vorbis_invsq2explook(int a);
  100920. extern float vorbis_fromdBlook(float a);
  100921. #endif
  100922. #ifdef INT_LOOKUP
  100923. extern long vorbis_invsqlook_i(long a,long e);
  100924. extern long vorbis_coslook_i(long a);
  100925. extern float vorbis_fromdBlook_i(long a);
  100926. #endif
  100927. #endif
  100928. /*** End of inlined file: lookup.h ***/
  100929. /*** Start of inlined file: lookup_data.h ***/
  100930. #ifndef _V_LOOKUP_DATA_H_
  100931. #ifdef FLOAT_LOOKUP
  100932. #define COS_LOOKUP_SZ 128
  100933. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100934. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100935. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100936. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100937. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100938. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100939. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100940. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100941. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100942. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100943. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100944. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100945. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100946. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100947. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100948. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100949. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100950. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100951. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100952. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100953. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100954. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100955. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100956. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100957. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100958. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100959. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100960. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100961. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100962. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100963. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100964. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100965. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100966. -1.0000000000000f,
  100967. };
  100968. #define INVSQ_LOOKUP_SZ 32
  100969. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100970. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100971. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100972. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100973. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100974. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100975. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100976. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100977. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100978. 1.000000000000f,
  100979. };
  100980. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100981. #define INVSQ2EXP_LOOKUP_MAX 32
  100982. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100983. INVSQ2EXP_LOOKUP_MIN+1]={
  100984. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100985. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100986. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100987. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100988. 256.f, 181.019336f, 128.f, 90.50966799f,
  100989. 64.f, 45.254834f, 32.f, 22.627417f,
  100990. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100991. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100992. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100993. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100994. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100995. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100996. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100997. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100998. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100999. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  101000. 1.525878906e-05f,
  101001. };
  101002. #endif
  101003. #define FROMdB_LOOKUP_SZ 35
  101004. #define FROMdB2_LOOKUP_SZ 32
  101005. #define FROMdB_SHIFT 5
  101006. #define FROMdB2_SHIFT 3
  101007. #define FROMdB2_MASK 31
  101008. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  101009. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  101010. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  101011. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  101012. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  101013. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  101014. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  101015. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  101016. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  101017. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  101018. };
  101019. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  101020. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  101021. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  101022. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  101023. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  101024. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  101025. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  101026. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  101027. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  101028. };
  101029. #ifdef INT_LOOKUP
  101030. #define INVSQ_LOOKUP_I_SHIFT 10
  101031. #define INVSQ_LOOKUP_I_MASK 1023
  101032. static long INVSQ_LOOKUP_I[64+1]={
  101033. 92682l, 91966l, 91267l, 90583l,
  101034. 89915l, 89261l, 88621l, 87995l,
  101035. 87381l, 86781l, 86192l, 85616l,
  101036. 85051l, 84497l, 83953l, 83420l,
  101037. 82897l, 82384l, 81880l, 81385l,
  101038. 80899l, 80422l, 79953l, 79492l,
  101039. 79039l, 78594l, 78156l, 77726l,
  101040. 77302l, 76885l, 76475l, 76072l,
  101041. 75674l, 75283l, 74898l, 74519l,
  101042. 74146l, 73778l, 73415l, 73058l,
  101043. 72706l, 72359l, 72016l, 71679l,
  101044. 71347l, 71019l, 70695l, 70376l,
  101045. 70061l, 69750l, 69444l, 69141l,
  101046. 68842l, 68548l, 68256l, 67969l,
  101047. 67685l, 67405l, 67128l, 66855l,
  101048. 66585l, 66318l, 66054l, 65794l,
  101049. 65536l,
  101050. };
  101051. #define COS_LOOKUP_I_SHIFT 9
  101052. #define COS_LOOKUP_I_MASK 511
  101053. #define COS_LOOKUP_I_SZ 128
  101054. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  101055. 16384l, 16379l, 16364l, 16340l,
  101056. 16305l, 16261l, 16207l, 16143l,
  101057. 16069l, 15986l, 15893l, 15791l,
  101058. 15679l, 15557l, 15426l, 15286l,
  101059. 15137l, 14978l, 14811l, 14635l,
  101060. 14449l, 14256l, 14053l, 13842l,
  101061. 13623l, 13395l, 13160l, 12916l,
  101062. 12665l, 12406l, 12140l, 11866l,
  101063. 11585l, 11297l, 11003l, 10702l,
  101064. 10394l, 10080l, 9760l, 9434l,
  101065. 9102l, 8765l, 8423l, 8076l,
  101066. 7723l, 7366l, 7005l, 6639l,
  101067. 6270l, 5897l, 5520l, 5139l,
  101068. 4756l, 4370l, 3981l, 3590l,
  101069. 3196l, 2801l, 2404l, 2006l,
  101070. 1606l, 1205l, 804l, 402l,
  101071. 0l, -401l, -803l, -1204l,
  101072. -1605l, -2005l, -2403l, -2800l,
  101073. -3195l, -3589l, -3980l, -4369l,
  101074. -4755l, -5138l, -5519l, -5896l,
  101075. -6269l, -6638l, -7004l, -7365l,
  101076. -7722l, -8075l, -8422l, -8764l,
  101077. -9101l, -9433l, -9759l, -10079l,
  101078. -10393l, -10701l, -11002l, -11296l,
  101079. -11584l, -11865l, -12139l, -12405l,
  101080. -12664l, -12915l, -13159l, -13394l,
  101081. -13622l, -13841l, -14052l, -14255l,
  101082. -14448l, -14634l, -14810l, -14977l,
  101083. -15136l, -15285l, -15425l, -15556l,
  101084. -15678l, -15790l, -15892l, -15985l,
  101085. -16068l, -16142l, -16206l, -16260l,
  101086. -16304l, -16339l, -16363l, -16378l,
  101087. -16383l,
  101088. };
  101089. #endif
  101090. #endif
  101091. /*** End of inlined file: lookup_data.h ***/
  101092. #ifdef FLOAT_LOOKUP
  101093. float vorbis_coslook(float a){
  101094. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101095. int i=vorbis_ftoi(d-.5);
  101096. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101097. }
  101098. float vorbis_invsqlook(float a){
  101099. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101100. int i=vorbis_ftoi(d-.5f);
  101101. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101102. }
  101103. float vorbis_invsq2explook(int a){
  101104. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101105. }
  101106. #include <stdio.h>
  101107. float vorbis_fromdBlook(float a){
  101108. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101109. return (i<0)?1.f:
  101110. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101111. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101112. }
  101113. #endif
  101114. #ifdef INT_LOOKUP
  101115. long vorbis_invsqlook_i(long a,long e){
  101116. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101117. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101118. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101119. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101120. d)>>16); /* result 1.16 */
  101121. e+=32;
  101122. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101123. e=(e>>1)-8;
  101124. return(val>>e);
  101125. }
  101126. float vorbis_fromdBlook_i(long a){
  101127. int i=(-a)>>(12-FROMdB2_SHIFT);
  101128. return (i<0)?1.f:
  101129. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101130. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101131. }
  101132. long vorbis_coslook_i(long a){
  101133. int i=a>>COS_LOOKUP_I_SHIFT;
  101134. int d=a&COS_LOOKUP_I_MASK;
  101135. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101136. COS_LOOKUP_I_SHIFT);
  101137. }
  101138. #endif
  101139. #endif
  101140. /*** End of inlined file: lookup.c ***/
  101141. /* catch this in the build system; we #include for
  101142. compilers (like gcc) that can't inline across
  101143. modules */
  101144. static int MLOOP_1[64]={
  101145. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  101146. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  101147. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101148. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101149. };
  101150. static int MLOOP_2[64]={
  101151. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  101152. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  101153. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101154. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101155. };
  101156. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  101157. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101158. float amp,float ampoffset){
  101159. int i;
  101160. int ampoffseti=rint(ampoffset*4096.f);
  101161. int ampi=rint(amp*16.f);
  101162. long *ilsp=alloca(m*sizeof(*ilsp));
  101163. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  101164. i=0;
  101165. while(i<n){
  101166. int j,k=map[i];
  101167. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  101168. unsigned long qi=46341;
  101169. int qexp=0,shift;
  101170. long wi=vorbis_coslook_i(k*65536/ln);
  101171. qi*=labs(ilsp[0]-wi);
  101172. pi*=labs(ilsp[1]-wi);
  101173. for(j=3;j<m;j+=2){
  101174. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101175. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101176. shift=MLOOP_3[(pi|qi)>>16];
  101177. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101178. pi=(pi>>shift)*labs(ilsp[j]-wi);
  101179. qexp+=shift;
  101180. }
  101181. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101182. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101183. shift=MLOOP_3[(pi|qi)>>16];
  101184. if(m&1){
  101185. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101186. pi=(pi>>shift)<<14;
  101187. qexp+=shift;
  101188. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101189. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101190. shift=MLOOP_3[(pi|qi)>>16];
  101191. pi>>=shift;
  101192. qi>>=shift;
  101193. qexp+=shift-14*((m+1)>>1);
  101194. pi=((pi*pi)>>16);
  101195. qi=((qi*qi)>>16);
  101196. qexp=qexp*2+m;
  101197. pi*=(1<<14)-((wi*wi)>>14);
  101198. qi+=pi>>14;
  101199. }else{
  101200. pi>>=shift;
  101201. qi>>=shift;
  101202. qexp+=shift-7*m;
  101203. pi=((pi*pi)>>16);
  101204. qi=((qi*qi)>>16);
  101205. qexp=qexp*2+m;
  101206. pi*=(1<<14)-wi;
  101207. qi*=(1<<14)+wi;
  101208. qi=(qi+pi)>>14;
  101209. }
  101210. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  101211. qi>>=1; qexp++;
  101212. }else
  101213. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  101214. qi<<=1; qexp--;
  101215. }
  101216. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  101217. vorbis_invsqlook_i(qi,qexp)-
  101218. ampoffseti); /* 8.12[0] */
  101219. curve[i]*=amp;
  101220. while(map[++i]==k)curve[i]*=amp;
  101221. }
  101222. }
  101223. #else
  101224. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101225. float amp,float ampoffset){
  101226. int i;
  101227. float wdel=M_PI/ln;
  101228. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  101229. i=0;
  101230. while(i<n){
  101231. int j,k=map[i];
  101232. float p=.5f;
  101233. float q=.5f;
  101234. float w=2.f*cos(wdel*k);
  101235. for(j=1;j<m;j+=2){
  101236. q *= w-lsp[j-1];
  101237. p *= w-lsp[j];
  101238. }
  101239. if(j==m){
  101240. q*=w-lsp[j-1];
  101241. p*=p*(4.f-w*w);
  101242. q*=q;
  101243. }else{
  101244. p*=p*(2.f-w);
  101245. q*=q*(2.f+w);
  101246. }
  101247. q=fromdB(amp/sqrt(p+q)-ampoffset);
  101248. curve[i]*=q;
  101249. while(map[++i]==k)curve[i]*=q;
  101250. }
  101251. }
  101252. #endif
  101253. #endif
  101254. static void cheby(float *g, int ord) {
  101255. int i, j;
  101256. g[0] *= .5f;
  101257. for(i=2; i<= ord; i++) {
  101258. for(j=ord; j >= i; j--) {
  101259. g[j-2] -= g[j];
  101260. g[j] += g[j];
  101261. }
  101262. }
  101263. }
  101264. static int comp(const void *a,const void *b){
  101265. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  101266. }
  101267. #define EPSILON 10e-7
  101268. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  101269. int i,m;
  101270. double lastdelta=0.f;
  101271. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  101272. for(i=0;i<=ord;i++)defl[i]=a[i];
  101273. for(m=ord;m>0;m--){
  101274. double newx=0.f,delta;
  101275. while(1){
  101276. double p=defl[m],pp=0.f,ppp=0.f,denom;
  101277. for(i=m;i>0;i--){
  101278. ppp = newx*ppp + pp;
  101279. pp = newx*pp + p;
  101280. p = newx*p + defl[i-1];
  101281. }
  101282. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  101283. if(denom<0)
  101284. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101285. if(pp>0){
  101286. denom = pp + sqrt(denom);
  101287. if(denom<EPSILON)denom=EPSILON;
  101288. }else{
  101289. denom = pp - sqrt(denom);
  101290. if(denom>-(EPSILON))denom=-(EPSILON);
  101291. }
  101292. delta = m*p/denom;
  101293. newx -= delta;
  101294. if(delta<0.f)delta*=-1;
  101295. if(fabs(delta/newx)<10e-12)break;
  101296. lastdelta=delta;
  101297. }
  101298. r[m-1]=newx;
  101299. for(i=m;i>0;i--)
  101300. defl[i-1]+=newx*defl[i];
  101301. defl++;
  101302. }
  101303. return(0);
  101304. }
  101305. static int Newton_Raphson(float *a,int ord,float *r){
  101306. int i, k, count=0;
  101307. double error=1.f;
  101308. double *root=(double*)alloca(ord*sizeof(*root));
  101309. for(i=0; i<ord;i++) root[i] = r[i];
  101310. while(error>1e-20){
  101311. error=0;
  101312. for(i=0; i<ord; i++) { /* Update each point. */
  101313. double pp=0.,delta;
  101314. double rooti=root[i];
  101315. double p=a[ord];
  101316. for(k=ord-1; k>= 0; k--) {
  101317. pp= pp* rooti + p;
  101318. p = p * rooti + a[k];
  101319. }
  101320. delta = p/pp;
  101321. root[i] -= delta;
  101322. error+= delta*delta;
  101323. }
  101324. if(count>40)return(-1);
  101325. count++;
  101326. }
  101327. for(i=0; i<ord;i++) r[i] = root[i];
  101328. return(0);
  101329. }
  101330. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101331. int order2=(m+1)>>1;
  101332. int g1_order,g2_order;
  101333. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101334. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101335. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101336. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101337. int i;
  101338. g1_order=(m+1)>>1;
  101339. g2_order=(m) >>1;
  101340. g1[g1_order] = 1.f;
  101341. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101342. g2[g2_order] = 1.f;
  101343. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101344. if(g1_order>g2_order){
  101345. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101346. }else{
  101347. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101348. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101349. }
  101350. cheby(g1,g1_order);
  101351. cheby(g2,g2_order);
  101352. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101353. Laguerre_With_Deflation(g2,g2_order,g2r))
  101354. return(-1);
  101355. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101356. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101357. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101358. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101359. for(i=0;i<g1_order;i++)
  101360. lsp[i*2] = acos(g1r[i]);
  101361. for(i=0;i<g2_order;i++)
  101362. lsp[i*2+1] = acos(g2r[i]);
  101363. return(0);
  101364. }
  101365. #endif
  101366. /*** End of inlined file: lsp.c ***/
  101367. /*** Start of inlined file: mapping0.c ***/
  101368. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101369. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101370. // tasks..
  101371. #if JUCE_MSVC
  101372. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101373. #endif
  101374. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101375. #if JUCE_USE_OGGVORBIS
  101376. #include <stdlib.h>
  101377. #include <stdio.h>
  101378. #include <string.h>
  101379. #include <math.h>
  101380. static void mapping0_free_info(vorbis_info_mapping *i){
  101381. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  101382. if(info){
  101383. memset(info,0,sizeof(*info));
  101384. _ogg_free(info);
  101385. }
  101386. }
  101387. static int ilog3(unsigned int v){
  101388. int ret=0;
  101389. if(v)--v;
  101390. while(v){
  101391. ret++;
  101392. v>>=1;
  101393. }
  101394. return(ret);
  101395. }
  101396. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101397. oggpack_buffer *opb){
  101398. int i;
  101399. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101400. if(info->submaps>1){
  101401. oggpack_write(opb,1,1);
  101402. oggpack_write(opb,info->submaps-1,4);
  101403. }else
  101404. oggpack_write(opb,0,1);
  101405. if(info->coupling_steps>0){
  101406. oggpack_write(opb,1,1);
  101407. oggpack_write(opb,info->coupling_steps-1,8);
  101408. for(i=0;i<info->coupling_steps;i++){
  101409. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101410. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101411. }
  101412. }else
  101413. oggpack_write(opb,0,1);
  101414. oggpack_write(opb,0,2); /* 2,3:reserved */
  101415. if(info->submaps>1){
  101416. for(i=0;i<vi->channels;i++)
  101417. oggpack_write(opb,info->chmuxlist[i],4);
  101418. }
  101419. for(i=0;i<info->submaps;i++){
  101420. oggpack_write(opb,0,8); /* time submap unused */
  101421. oggpack_write(opb,info->floorsubmap[i],8);
  101422. oggpack_write(opb,info->residuesubmap[i],8);
  101423. }
  101424. }
  101425. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101426. int i;
  101427. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101428. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101429. memset(info,0,sizeof(*info));
  101430. if(oggpack_read(opb,1))
  101431. info->submaps=oggpack_read(opb,4)+1;
  101432. else
  101433. info->submaps=1;
  101434. if(oggpack_read(opb,1)){
  101435. info->coupling_steps=oggpack_read(opb,8)+1;
  101436. for(i=0;i<info->coupling_steps;i++){
  101437. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101438. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101439. if(testM<0 ||
  101440. testA<0 ||
  101441. testM==testA ||
  101442. testM>=vi->channels ||
  101443. testA>=vi->channels) goto err_out;
  101444. }
  101445. }
  101446. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101447. if(info->submaps>1){
  101448. for(i=0;i<vi->channels;i++){
  101449. info->chmuxlist[i]=oggpack_read(opb,4);
  101450. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101451. }
  101452. }
  101453. for(i=0;i<info->submaps;i++){
  101454. oggpack_read(opb,8); /* time submap unused */
  101455. info->floorsubmap[i]=oggpack_read(opb,8);
  101456. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101457. info->residuesubmap[i]=oggpack_read(opb,8);
  101458. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101459. }
  101460. return info;
  101461. err_out:
  101462. mapping0_free_info(info);
  101463. return(NULL);
  101464. }
  101465. #if 0
  101466. static long seq=0;
  101467. static ogg_int64_t total=0;
  101468. static float FLOOR1_fromdB_LOOKUP[256]={
  101469. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101470. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101471. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101472. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101473. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101474. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101475. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101476. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101477. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101478. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101479. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101480. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101481. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101482. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101483. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101484. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101485. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101486. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101487. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101488. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101489. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101490. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101491. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101492. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101493. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101494. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101495. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101496. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101497. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101498. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101499. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101500. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101501. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101502. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101503. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101504. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101505. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101506. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101507. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101508. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101509. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101510. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101511. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101512. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101513. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101514. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101515. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101516. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101517. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101518. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101519. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101520. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101521. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101522. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101523. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101524. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101525. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101526. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101527. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101528. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101529. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101530. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101531. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101532. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101533. };
  101534. #endif
  101535. extern int *floor1_fit(vorbis_block *vb,void *look,
  101536. const float *logmdct, /* in */
  101537. const float *logmask);
  101538. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101539. int *A,int *B,
  101540. int del);
  101541. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101542. void*look,
  101543. int *post,int *ilogmask);
  101544. static int mapping0_forward(vorbis_block *vb){
  101545. vorbis_dsp_state *vd=vb->vd;
  101546. vorbis_info *vi=vd->vi;
  101547. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101548. private_state *b=(private_state*)vb->vd->backend_state;
  101549. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101550. int n=vb->pcmend;
  101551. int i,j,k;
  101552. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101553. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101554. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101555. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101556. float global_ampmax=vbi->ampmax;
  101557. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101558. int blocktype=vbi->blocktype;
  101559. int modenumber=vb->W;
  101560. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101561. vorbis_look_psy *psy_look=
  101562. b->psy+blocktype+(vb->W?2:0);
  101563. vb->mode=modenumber;
  101564. for(i=0;i<vi->channels;i++){
  101565. float scale=4.f/n;
  101566. float scale_dB;
  101567. float *pcm =vb->pcm[i];
  101568. float *logfft =pcm;
  101569. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101570. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101571. todB estimation used on IEEE 754
  101572. compliant machines had a bug that
  101573. returned dB values about a third
  101574. of a decibel too high. The bug
  101575. was harmless because tunings
  101576. implicitly took that into
  101577. account. However, fixing the bug
  101578. in the estimator requires
  101579. changing all the tunings as well.
  101580. For now, it's easier to sync
  101581. things back up here, and
  101582. recalibrate the tunings in the
  101583. next major model upgrade. */
  101584. #if 0
  101585. if(vi->channels==2)
  101586. if(i==0)
  101587. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101588. else
  101589. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101590. #endif
  101591. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101592. #if 0
  101593. if(vi->channels==2)
  101594. if(i==0)
  101595. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101596. else
  101597. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101598. #endif
  101599. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101600. drft_forward(&b->fft_look[vb->W],pcm);
  101601. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101602. original todB estimation used on
  101603. IEEE 754 compliant machines had a
  101604. bug that returned dB values about
  101605. a third of a decibel too high.
  101606. The bug was harmless because
  101607. tunings implicitly took that into
  101608. account. However, fixing the bug
  101609. in the estimator requires
  101610. changing all the tunings as well.
  101611. For now, it's easier to sync
  101612. things back up here, and
  101613. recalibrate the tunings in the
  101614. next major model upgrade. */
  101615. local_ampmax[i]=logfft[0];
  101616. for(j=1;j<n-1;j+=2){
  101617. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101618. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101619. .345 is a hack; the original todB
  101620. estimation used on IEEE 754
  101621. compliant machines had a bug that
  101622. returned dB values about a third
  101623. of a decibel too high. The bug
  101624. was harmless because tunings
  101625. implicitly took that into
  101626. account. However, fixing the bug
  101627. in the estimator requires
  101628. changing all the tunings as well.
  101629. For now, it's easier to sync
  101630. things back up here, and
  101631. recalibrate the tunings in the
  101632. next major model upgrade. */
  101633. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101634. }
  101635. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101636. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101637. #if 0
  101638. if(vi->channels==2){
  101639. if(i==0){
  101640. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101641. }else{
  101642. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101643. }
  101644. }
  101645. #endif
  101646. }
  101647. {
  101648. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101649. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101650. for(i=0;i<vi->channels;i++){
  101651. int submap=info->chmuxlist[i];
  101652. float *mdct =gmdct[i];
  101653. float *logfft =vb->pcm[i];
  101654. float *logmdct =logfft+n/2;
  101655. float *logmask =logfft;
  101656. vb->mode=modenumber;
  101657. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101658. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101659. for(j=0;j<n/2;j++)
  101660. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101661. todB estimation used on IEEE 754
  101662. compliant machines had a bug that
  101663. returned dB values about a third
  101664. of a decibel too high. The bug
  101665. was harmless because tunings
  101666. implicitly took that into
  101667. account. However, fixing the bug
  101668. in the estimator requires
  101669. changing all the tunings as well.
  101670. For now, it's easier to sync
  101671. things back up here, and
  101672. recalibrate the tunings in the
  101673. next major model upgrade. */
  101674. #if 0
  101675. if(vi->channels==2){
  101676. if(i==0)
  101677. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  101678. else
  101679. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  101680. }else{
  101681. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  101682. }
  101683. #endif
  101684. _vp_noisemask(psy_look,
  101685. logmdct,
  101686. noise); /* noise does not have by-frequency offset
  101687. bias applied yet */
  101688. #if 0
  101689. if(vi->channels==2){
  101690. if(i==0)
  101691. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  101692. else
  101693. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  101694. }
  101695. #endif
  101696. _vp_tonemask(psy_look,
  101697. logfft,
  101698. tone,
  101699. global_ampmax,
  101700. local_ampmax[i]);
  101701. #if 0
  101702. if(vi->channels==2){
  101703. if(i==0)
  101704. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  101705. else
  101706. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  101707. }
  101708. #endif
  101709. #if 0
  101710. {
  101711. float aotuv[psy_look->n];
  101712. #endif
  101713. _vp_offset_and_mix(psy_look,
  101714. noise,
  101715. tone,
  101716. 1,
  101717. logmask,
  101718. mdct,
  101719. logmdct);
  101720. #if 0
  101721. if(vi->channels==2){
  101722. if(i==0)
  101723. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  101724. else
  101725. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  101726. }
  101727. }
  101728. #endif
  101729. #if 0
  101730. if(vi->channels==2){
  101731. if(i==0)
  101732. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  101733. else
  101734. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  101735. }
  101736. #endif
  101737. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  101738. floor_posts[i][PACKETBLOBS/2]=
  101739. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101740. logmdct,
  101741. logmask);
  101742. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  101743. _vp_offset_and_mix(psy_look,
  101744. noise,
  101745. tone,
  101746. 2,
  101747. logmask,
  101748. mdct,
  101749. logmdct);
  101750. #if 0
  101751. if(vi->channels==2){
  101752. if(i==0)
  101753. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  101754. else
  101755. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  101756. }
  101757. #endif
  101758. floor_posts[i][PACKETBLOBS-1]=
  101759. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101760. logmdct,
  101761. logmask);
  101762. _vp_offset_and_mix(psy_look,
  101763. noise,
  101764. tone,
  101765. 0,
  101766. logmask,
  101767. mdct,
  101768. logmdct);
  101769. #if 0
  101770. if(vi->channels==2)
  101771. if(i==0)
  101772. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  101773. else
  101774. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  101775. #endif
  101776. floor_posts[i][0]=
  101777. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101778. logmdct,
  101779. logmask);
  101780. for(k=1;k<PACKETBLOBS/2;k++)
  101781. floor_posts[i][k]=
  101782. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101783. floor_posts[i][0],
  101784. floor_posts[i][PACKETBLOBS/2],
  101785. k*65536/(PACKETBLOBS/2));
  101786. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  101787. floor_posts[i][k]=
  101788. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101789. floor_posts[i][PACKETBLOBS/2],
  101790. floor_posts[i][PACKETBLOBS-1],
  101791. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  101792. }
  101793. }
  101794. }
  101795. vbi->ampmax=global_ampmax;
  101796. {
  101797. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  101798. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  101799. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101800. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  101801. float **mag_memo;
  101802. int **mag_sort;
  101803. if(info->coupling_steps){
  101804. mag_memo=_vp_quantize_couple_memo(vb,
  101805. &ci->psy_g_param,
  101806. psy_look,
  101807. info,
  101808. gmdct);
  101809. mag_sort=_vp_quantize_couple_sort(vb,
  101810. psy_look,
  101811. info,
  101812. mag_memo);
  101813. hf_reduction(&ci->psy_g_param,
  101814. psy_look,
  101815. info,
  101816. mag_memo);
  101817. }
  101818. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  101819. if(psy_look->vi->normal_channel_p){
  101820. for(i=0;i<vi->channels;i++){
  101821. float *mdct =gmdct[i];
  101822. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  101823. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  101824. }
  101825. }
  101826. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  101827. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  101828. k++){
  101829. oggpack_buffer *opb=vbi->packetblob[k];
  101830. oggpack_write(opb,0,1);
  101831. oggpack_write(opb,modenumber,b->modebits);
  101832. if(vb->W){
  101833. oggpack_write(opb,vb->lW,1);
  101834. oggpack_write(opb,vb->nW,1);
  101835. }
  101836. for(i=0;i<vi->channels;i++){
  101837. int submap=info->chmuxlist[i];
  101838. float *mdct =gmdct[i];
  101839. float *res =vb->pcm[i];
  101840. int *ilogmask=ilogmaskch[i]=
  101841. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101842. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  101843. floor_posts[i][k],
  101844. ilogmask);
  101845. #if 0
  101846. {
  101847. char buf[80];
  101848. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  101849. float work[n/2];
  101850. for(j=0;j<n/2;j++)
  101851. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  101852. _analysis_output(buf,seq,work,n/2,1,1,0);
  101853. }
  101854. #endif
  101855. _vp_remove_floor(psy_look,
  101856. mdct,
  101857. ilogmask,
  101858. res,
  101859. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101860. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  101861. #if 0
  101862. {
  101863. char buf[80];
  101864. float work[n/2];
  101865. for(j=0;j<n/2;j++)
  101866. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  101867. sprintf(buf,"resI%c%d",i?'R':'L',k);
  101868. _analysis_output(buf,seq,work,n/2,1,1,0);
  101869. }
  101870. #endif
  101871. }
  101872. if(info->coupling_steps){
  101873. _vp_couple(k,
  101874. &ci->psy_g_param,
  101875. psy_look,
  101876. info,
  101877. vb->pcm,
  101878. mag_memo,
  101879. mag_sort,
  101880. ilogmaskch,
  101881. nonzero,
  101882. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101883. }
  101884. for(i=0;i<info->submaps;i++){
  101885. int ch_in_bundle=0;
  101886. long **classifications;
  101887. int resnum=info->residuesubmap[i];
  101888. for(j=0;j<vi->channels;j++){
  101889. if(info->chmuxlist[j]==i){
  101890. zerobundle[ch_in_bundle]=0;
  101891. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  101892. res_bundle[ch_in_bundle]=vb->pcm[j];
  101893. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  101894. }
  101895. }
  101896. classifications=_residue_P[ci->residue_type[resnum]]->
  101897. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  101898. _residue_P[ci->residue_type[resnum]]->
  101899. forward(opb,vb,b->residue[resnum],
  101900. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  101901. }
  101902. }
  101903. }
  101904. #if 0
  101905. seq++;
  101906. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  101907. #endif
  101908. return(0);
  101909. }
  101910. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  101911. vorbis_dsp_state *vd=vb->vd;
  101912. vorbis_info *vi=vd->vi;
  101913. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  101914. private_state *b=(private_state*)vd->backend_state;
  101915. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  101916. int i,j;
  101917. long n=vb->pcmend=ci->blocksizes[vb->W];
  101918. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  101919. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101920. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  101921. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  101922. for(i=0;i<vi->channels;i++){
  101923. int submap=info->chmuxlist[i];
  101924. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101925. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  101926. if(floormemo[i])
  101927. nonzero[i]=1;
  101928. else
  101929. nonzero[i]=0;
  101930. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  101931. }
  101932. for(i=0;i<info->coupling_steps;i++){
  101933. if(nonzero[info->coupling_mag[i]] ||
  101934. nonzero[info->coupling_ang[i]]){
  101935. nonzero[info->coupling_mag[i]]=1;
  101936. nonzero[info->coupling_ang[i]]=1;
  101937. }
  101938. }
  101939. for(i=0;i<info->submaps;i++){
  101940. int ch_in_bundle=0;
  101941. for(j=0;j<vi->channels;j++){
  101942. if(info->chmuxlist[j]==i){
  101943. if(nonzero[j])
  101944. zerobundle[ch_in_bundle]=1;
  101945. else
  101946. zerobundle[ch_in_bundle]=0;
  101947. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  101948. }
  101949. }
  101950. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  101951. inverse(vb,b->residue[info->residuesubmap[i]],
  101952. pcmbundle,zerobundle,ch_in_bundle);
  101953. }
  101954. for(i=info->coupling_steps-1;i>=0;i--){
  101955. float *pcmM=vb->pcm[info->coupling_mag[i]];
  101956. float *pcmA=vb->pcm[info->coupling_ang[i]];
  101957. for(j=0;j<n/2;j++){
  101958. float mag=pcmM[j];
  101959. float ang=pcmA[j];
  101960. if(mag>0)
  101961. if(ang>0){
  101962. pcmM[j]=mag;
  101963. pcmA[j]=mag-ang;
  101964. }else{
  101965. pcmA[j]=mag;
  101966. pcmM[j]=mag+ang;
  101967. }
  101968. else
  101969. if(ang>0){
  101970. pcmM[j]=mag;
  101971. pcmA[j]=mag+ang;
  101972. }else{
  101973. pcmA[j]=mag;
  101974. pcmM[j]=mag-ang;
  101975. }
  101976. }
  101977. }
  101978. for(i=0;i<vi->channels;i++){
  101979. float *pcm=vb->pcm[i];
  101980. int submap=info->chmuxlist[i];
  101981. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101982. inverse2(vb,b->flr[info->floorsubmap[submap]],
  101983. floormemo[i],pcm);
  101984. }
  101985. for(i=0;i<vi->channels;i++){
  101986. float *pcm=vb->pcm[i];
  101987. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  101988. }
  101989. return(0);
  101990. }
  101991. vorbis_func_mapping mapping0_exportbundle={
  101992. &mapping0_pack,
  101993. &mapping0_unpack,
  101994. &mapping0_free_info,
  101995. &mapping0_forward,
  101996. &mapping0_inverse
  101997. };
  101998. #endif
  101999. /*** End of inlined file: mapping0.c ***/
  102000. /*** Start of inlined file: mdct.c ***/
  102001. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102002. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102003. // tasks..
  102004. #if JUCE_MSVC
  102005. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102006. #endif
  102007. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102008. #if JUCE_USE_OGGVORBIS
  102009. #include <stdio.h>
  102010. #include <stdlib.h>
  102011. #include <string.h>
  102012. #include <math.h>
  102013. void mdct_init(mdct_lookup *lookup,int n){
  102014. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  102015. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  102016. int i;
  102017. int n2=n>>1;
  102018. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  102019. lookup->n=n;
  102020. lookup->trig=T;
  102021. lookup->bitrev=bitrev;
  102022. for(i=0;i<n/4;i++){
  102023. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  102024. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  102025. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  102026. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  102027. }
  102028. for(i=0;i<n/8;i++){
  102029. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  102030. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  102031. }
  102032. {
  102033. int mask=(1<<(log2n-1))-1,i,j;
  102034. int msb=1<<(log2n-2);
  102035. for(i=0;i<n/8;i++){
  102036. int acc=0;
  102037. for(j=0;msb>>j;j++)
  102038. if((msb>>j)&i)acc|=1<<j;
  102039. bitrev[i*2]=((~acc)&mask)-1;
  102040. bitrev[i*2+1]=acc;
  102041. }
  102042. }
  102043. lookup->scale=FLOAT_CONV(4.f/n);
  102044. }
  102045. STIN void mdct_butterfly_8(DATA_TYPE *x){
  102046. REG_TYPE r0 = x[6] + x[2];
  102047. REG_TYPE r1 = x[6] - x[2];
  102048. REG_TYPE r2 = x[4] + x[0];
  102049. REG_TYPE r3 = x[4] - x[0];
  102050. x[6] = r0 + r2;
  102051. x[4] = r0 - r2;
  102052. r0 = x[5] - x[1];
  102053. r2 = x[7] - x[3];
  102054. x[0] = r1 + r0;
  102055. x[2] = r1 - r0;
  102056. r0 = x[5] + x[1];
  102057. r1 = x[7] + x[3];
  102058. x[3] = r2 + r3;
  102059. x[1] = r2 - r3;
  102060. x[7] = r1 + r0;
  102061. x[5] = r1 - r0;
  102062. }
  102063. STIN void mdct_butterfly_16(DATA_TYPE *x){
  102064. REG_TYPE r0 = x[1] - x[9];
  102065. REG_TYPE r1 = x[0] - x[8];
  102066. x[8] += x[0];
  102067. x[9] += x[1];
  102068. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  102069. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  102070. r0 = x[3] - x[11];
  102071. r1 = x[10] - x[2];
  102072. x[10] += x[2];
  102073. x[11] += x[3];
  102074. x[2] = r0;
  102075. x[3] = r1;
  102076. r0 = x[12] - x[4];
  102077. r1 = x[13] - x[5];
  102078. x[12] += x[4];
  102079. x[13] += x[5];
  102080. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  102081. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  102082. r0 = x[14] - x[6];
  102083. r1 = x[15] - x[7];
  102084. x[14] += x[6];
  102085. x[15] += x[7];
  102086. x[6] = r0;
  102087. x[7] = r1;
  102088. mdct_butterfly_8(x);
  102089. mdct_butterfly_8(x+8);
  102090. }
  102091. STIN void mdct_butterfly_32(DATA_TYPE *x){
  102092. REG_TYPE r0 = x[30] - x[14];
  102093. REG_TYPE r1 = x[31] - x[15];
  102094. x[30] += x[14];
  102095. x[31] += x[15];
  102096. x[14] = r0;
  102097. x[15] = r1;
  102098. r0 = x[28] - x[12];
  102099. r1 = x[29] - x[13];
  102100. x[28] += x[12];
  102101. x[29] += x[13];
  102102. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  102103. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  102104. r0 = x[26] - x[10];
  102105. r1 = x[27] - x[11];
  102106. x[26] += x[10];
  102107. x[27] += x[11];
  102108. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  102109. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  102110. r0 = x[24] - x[8];
  102111. r1 = x[25] - x[9];
  102112. x[24] += x[8];
  102113. x[25] += x[9];
  102114. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  102115. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102116. r0 = x[22] - x[6];
  102117. r1 = x[7] - x[23];
  102118. x[22] += x[6];
  102119. x[23] += x[7];
  102120. x[6] = r1;
  102121. x[7] = r0;
  102122. r0 = x[4] - x[20];
  102123. r1 = x[5] - x[21];
  102124. x[20] += x[4];
  102125. x[21] += x[5];
  102126. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  102127. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  102128. r0 = x[2] - x[18];
  102129. r1 = x[3] - x[19];
  102130. x[18] += x[2];
  102131. x[19] += x[3];
  102132. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  102133. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  102134. r0 = x[0] - x[16];
  102135. r1 = x[1] - x[17];
  102136. x[16] += x[0];
  102137. x[17] += x[1];
  102138. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102139. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  102140. mdct_butterfly_16(x);
  102141. mdct_butterfly_16(x+16);
  102142. }
  102143. STIN void mdct_butterfly_first(DATA_TYPE *T,
  102144. DATA_TYPE *x,
  102145. int points){
  102146. DATA_TYPE *x1 = x + points - 8;
  102147. DATA_TYPE *x2 = x + (points>>1) - 8;
  102148. REG_TYPE r0;
  102149. REG_TYPE r1;
  102150. do{
  102151. r0 = x1[6] - x2[6];
  102152. r1 = x1[7] - x2[7];
  102153. x1[6] += x2[6];
  102154. x1[7] += x2[7];
  102155. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102156. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102157. r0 = x1[4] - x2[4];
  102158. r1 = x1[5] - x2[5];
  102159. x1[4] += x2[4];
  102160. x1[5] += x2[5];
  102161. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  102162. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  102163. r0 = x1[2] - x2[2];
  102164. r1 = x1[3] - x2[3];
  102165. x1[2] += x2[2];
  102166. x1[3] += x2[3];
  102167. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  102168. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  102169. r0 = x1[0] - x2[0];
  102170. r1 = x1[1] - x2[1];
  102171. x1[0] += x2[0];
  102172. x1[1] += x2[1];
  102173. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  102174. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  102175. x1-=8;
  102176. x2-=8;
  102177. T+=16;
  102178. }while(x2>=x);
  102179. }
  102180. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  102181. DATA_TYPE *x,
  102182. int points,
  102183. int trigint){
  102184. DATA_TYPE *x1 = x + points - 8;
  102185. DATA_TYPE *x2 = x + (points>>1) - 8;
  102186. REG_TYPE r0;
  102187. REG_TYPE r1;
  102188. do{
  102189. r0 = x1[6] - x2[6];
  102190. r1 = x1[7] - x2[7];
  102191. x1[6] += x2[6];
  102192. x1[7] += x2[7];
  102193. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102194. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102195. T+=trigint;
  102196. r0 = x1[4] - x2[4];
  102197. r1 = x1[5] - x2[5];
  102198. x1[4] += x2[4];
  102199. x1[5] += x2[5];
  102200. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102201. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102202. T+=trigint;
  102203. r0 = x1[2] - x2[2];
  102204. r1 = x1[3] - x2[3];
  102205. x1[2] += x2[2];
  102206. x1[3] += x2[3];
  102207. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102208. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102209. T+=trigint;
  102210. r0 = x1[0] - x2[0];
  102211. r1 = x1[1] - x2[1];
  102212. x1[0] += x2[0];
  102213. x1[1] += x2[1];
  102214. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102215. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102216. T+=trigint;
  102217. x1-=8;
  102218. x2-=8;
  102219. }while(x2>=x);
  102220. }
  102221. STIN void mdct_butterflies(mdct_lookup *init,
  102222. DATA_TYPE *x,
  102223. int points){
  102224. DATA_TYPE *T=init->trig;
  102225. int stages=init->log2n-5;
  102226. int i,j;
  102227. if(--stages>0){
  102228. mdct_butterfly_first(T,x,points);
  102229. }
  102230. for(i=1;--stages>0;i++){
  102231. for(j=0;j<(1<<i);j++)
  102232. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  102233. }
  102234. for(j=0;j<points;j+=32)
  102235. mdct_butterfly_32(x+j);
  102236. }
  102237. void mdct_clear(mdct_lookup *l){
  102238. if(l){
  102239. if(l->trig)_ogg_free(l->trig);
  102240. if(l->bitrev)_ogg_free(l->bitrev);
  102241. memset(l,0,sizeof(*l));
  102242. }
  102243. }
  102244. STIN void mdct_bitreverse(mdct_lookup *init,
  102245. DATA_TYPE *x){
  102246. int n = init->n;
  102247. int *bit = init->bitrev;
  102248. DATA_TYPE *w0 = x;
  102249. DATA_TYPE *w1 = x = w0+(n>>1);
  102250. DATA_TYPE *T = init->trig+n;
  102251. do{
  102252. DATA_TYPE *x0 = x+bit[0];
  102253. DATA_TYPE *x1 = x+bit[1];
  102254. REG_TYPE r0 = x0[1] - x1[1];
  102255. REG_TYPE r1 = x0[0] + x1[0];
  102256. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  102257. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  102258. w1 -= 4;
  102259. r0 = HALVE(x0[1] + x1[1]);
  102260. r1 = HALVE(x0[0] - x1[0]);
  102261. w0[0] = r0 + r2;
  102262. w1[2] = r0 - r2;
  102263. w0[1] = r1 + r3;
  102264. w1[3] = r3 - r1;
  102265. x0 = x+bit[2];
  102266. x1 = x+bit[3];
  102267. r0 = x0[1] - x1[1];
  102268. r1 = x0[0] + x1[0];
  102269. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  102270. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  102271. r0 = HALVE(x0[1] + x1[1]);
  102272. r1 = HALVE(x0[0] - x1[0]);
  102273. w0[2] = r0 + r2;
  102274. w1[0] = r0 - r2;
  102275. w0[3] = r1 + r3;
  102276. w1[1] = r3 - r1;
  102277. T += 4;
  102278. bit += 4;
  102279. w0 += 4;
  102280. }while(w0<w1);
  102281. }
  102282. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102283. int n=init->n;
  102284. int n2=n>>1;
  102285. int n4=n>>2;
  102286. DATA_TYPE *iX = in+n2-7;
  102287. DATA_TYPE *oX = out+n2+n4;
  102288. DATA_TYPE *T = init->trig+n4;
  102289. do{
  102290. oX -= 4;
  102291. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102292. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102293. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102294. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102295. iX -= 8;
  102296. T += 4;
  102297. }while(iX>=in);
  102298. iX = in+n2-8;
  102299. oX = out+n2+n4;
  102300. T = init->trig+n4;
  102301. do{
  102302. T -= 4;
  102303. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102304. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102305. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102306. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102307. iX -= 8;
  102308. oX += 4;
  102309. }while(iX>=in);
  102310. mdct_butterflies(init,out+n2,n2);
  102311. mdct_bitreverse(init,out);
  102312. {
  102313. DATA_TYPE *oX1=out+n2+n4;
  102314. DATA_TYPE *oX2=out+n2+n4;
  102315. DATA_TYPE *iX =out;
  102316. T =init->trig+n2;
  102317. do{
  102318. oX1-=4;
  102319. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102320. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102321. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102322. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102323. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102324. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102325. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102326. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102327. oX2+=4;
  102328. iX += 8;
  102329. T += 8;
  102330. }while(iX<oX1);
  102331. iX=out+n2+n4;
  102332. oX1=out+n4;
  102333. oX2=oX1;
  102334. do{
  102335. oX1-=4;
  102336. iX-=4;
  102337. oX2[0] = -(oX1[3] = iX[3]);
  102338. oX2[1] = -(oX1[2] = iX[2]);
  102339. oX2[2] = -(oX1[1] = iX[1]);
  102340. oX2[3] = -(oX1[0] = iX[0]);
  102341. oX2+=4;
  102342. }while(oX2<iX);
  102343. iX=out+n2+n4;
  102344. oX1=out+n2+n4;
  102345. oX2=out+n2;
  102346. do{
  102347. oX1-=4;
  102348. oX1[0]= iX[3];
  102349. oX1[1]= iX[2];
  102350. oX1[2]= iX[1];
  102351. oX1[3]= iX[0];
  102352. iX+=4;
  102353. }while(oX1>oX2);
  102354. }
  102355. }
  102356. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102357. int n=init->n;
  102358. int n2=n>>1;
  102359. int n4=n>>2;
  102360. int n8=n>>3;
  102361. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102362. DATA_TYPE *w2=w+n2;
  102363. REG_TYPE r0;
  102364. REG_TYPE r1;
  102365. DATA_TYPE *x0=in+n2+n4;
  102366. DATA_TYPE *x1=x0+1;
  102367. DATA_TYPE *T=init->trig+n2;
  102368. int i=0;
  102369. for(i=0;i<n8;i+=2){
  102370. x0 -=4;
  102371. T-=2;
  102372. r0= x0[2] + x1[0];
  102373. r1= x0[0] + x1[2];
  102374. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102375. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102376. x1 +=4;
  102377. }
  102378. x1=in+1;
  102379. for(;i<n2-n8;i+=2){
  102380. T-=2;
  102381. x0 -=4;
  102382. r0= x0[2] - x1[0];
  102383. r1= x0[0] - x1[2];
  102384. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102385. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102386. x1 +=4;
  102387. }
  102388. x0=in+n;
  102389. for(;i<n2;i+=2){
  102390. T-=2;
  102391. x0 -=4;
  102392. r0= -x0[2] - x1[0];
  102393. r1= -x0[0] - x1[2];
  102394. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102395. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102396. x1 +=4;
  102397. }
  102398. mdct_butterflies(init,w+n2,n2);
  102399. mdct_bitreverse(init,w);
  102400. T=init->trig+n2;
  102401. x0=out+n2;
  102402. for(i=0;i<n4;i++){
  102403. x0--;
  102404. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102405. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102406. w+=2;
  102407. T+=2;
  102408. }
  102409. }
  102410. #endif
  102411. /*** End of inlined file: mdct.c ***/
  102412. /*** Start of inlined file: psy.c ***/
  102413. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102414. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102415. // tasks..
  102416. #if JUCE_MSVC
  102417. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102418. #endif
  102419. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102420. #if JUCE_USE_OGGVORBIS
  102421. #include <stdlib.h>
  102422. #include <math.h>
  102423. #include <string.h>
  102424. /*** Start of inlined file: masking.h ***/
  102425. #ifndef _V_MASKING_H_
  102426. #define _V_MASKING_H_
  102427. #define MAX_ATH 88
  102428. static float ATH[]={
  102429. -51, -52, -53, -54, -55, -56, -57, -58,
  102430. -59, -60, -61, -62, -63, -64, -65, -66,
  102431. -67, -68, -69, -70, -71, -72, -73, -74,
  102432. -75, -76, -77, -78, -80, -81, -82, -83,
  102433. -84, -85, -86, -87, -88, -88, -89, -89,
  102434. -90, -91, -91, -92, -93, -94, -95, -96,
  102435. -96, -97, -98, -98, -99, -99,-100,-100,
  102436. -101,-102,-103,-104,-106,-107,-107,-107,
  102437. -107,-105,-103,-102,-101, -99, -98, -96,
  102438. -95, -95, -96, -97, -96, -95, -93, -90,
  102439. -80, -70, -50, -40, -30, -30, -30, -30
  102440. };
  102441. #define EHMER_OFFSET 16
  102442. #define EHMER_MAX 56
  102443. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102444. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102445. -60, -60, -60, -60, -62, -62, -65, -73,
  102446. -69, -68, -68, -67, -70, -70, -72, -74,
  102447. -75, -79, -79, -80, -83, -88, -93, -100,
  102448. -110, -999, -999, -999, -999, -999, -999, -999,
  102449. -999, -999, -999, -999, -999, -999, -999, -999,
  102450. -999, -999, -999, -999, -999, -999, -999, -999},
  102451. { -48, -48, -48, -48, -48, -48, -48, -48,
  102452. -48, -48, -48, -48, -48, -53, -61, -66,
  102453. -66, -68, -67, -70, -76, -76, -72, -73,
  102454. -75, -76, -78, -79, -83, -88, -93, -100,
  102455. -110, -999, -999, -999, -999, -999, -999, -999,
  102456. -999, -999, -999, -999, -999, -999, -999, -999,
  102457. -999, -999, -999, -999, -999, -999, -999, -999},
  102458. { -37, -37, -37, -37, -37, -37, -37, -37,
  102459. -38, -40, -42, -46, -48, -53, -55, -62,
  102460. -65, -58, -56, -56, -61, -60, -65, -67,
  102461. -69, -71, -77, -77, -78, -80, -82, -84,
  102462. -88, -93, -98, -106, -112, -999, -999, -999,
  102463. -999, -999, -999, -999, -999, -999, -999, -999,
  102464. -999, -999, -999, -999, -999, -999, -999, -999},
  102465. { -25, -25, -25, -25, -25, -25, -25, -25,
  102466. -25, -26, -27, -29, -32, -38, -48, -52,
  102467. -52, -50, -48, -48, -51, -52, -54, -60,
  102468. -67, -67, -66, -68, -69, -73, -73, -76,
  102469. -80, -81, -81, -85, -85, -86, -88, -93,
  102470. -100, -110, -999, -999, -999, -999, -999, -999,
  102471. -999, -999, -999, -999, -999, -999, -999, -999},
  102472. { -16, -16, -16, -16, -16, -16, -16, -16,
  102473. -17, -19, -20, -22, -26, -28, -31, -40,
  102474. -47, -39, -39, -40, -42, -43, -47, -51,
  102475. -57, -52, -55, -55, -60, -58, -62, -63,
  102476. -70, -67, -69, -72, -73, -77, -80, -82,
  102477. -83, -87, -90, -94, -98, -104, -115, -999,
  102478. -999, -999, -999, -999, -999, -999, -999, -999},
  102479. { -8, -8, -8, -8, -8, -8, -8, -8,
  102480. -8, -8, -10, -11, -15, -19, -25, -30,
  102481. -34, -31, -30, -31, -29, -32, -35, -42,
  102482. -48, -42, -44, -46, -50, -50, -51, -52,
  102483. -59, -54, -55, -55, -58, -62, -63, -66,
  102484. -72, -73, -76, -75, -78, -80, -80, -81,
  102485. -84, -88, -90, -94, -98, -101, -106, -110}},
  102486. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102487. -66, -66, -66, -66, -66, -67, -67, -67,
  102488. -76, -72, -71, -74, -76, -76, -75, -78,
  102489. -79, -79, -81, -83, -86, -89, -93, -97,
  102490. -100, -105, -110, -999, -999, -999, -999, -999,
  102491. -999, -999, -999, -999, -999, -999, -999, -999,
  102492. -999, -999, -999, -999, -999, -999, -999, -999},
  102493. { -47, -47, -47, -47, -47, -47, -47, -47,
  102494. -47, -47, -47, -48, -51, -55, -59, -66,
  102495. -66, -66, -67, -66, -68, -69, -70, -74,
  102496. -79, -77, -77, -78, -80, -81, -82, -84,
  102497. -86, -88, -91, -95, -100, -108, -116, -999,
  102498. -999, -999, -999, -999, -999, -999, -999, -999,
  102499. -999, -999, -999, -999, -999, -999, -999, -999},
  102500. { -36, -36, -36, -36, -36, -36, -36, -36,
  102501. -36, -37, -37, -41, -44, -48, -51, -58,
  102502. -62, -60, -57, -59, -59, -60, -63, -65,
  102503. -72, -71, -70, -72, -74, -77, -76, -78,
  102504. -81, -81, -80, -83, -86, -91, -96, -100,
  102505. -105, -110, -999, -999, -999, -999, -999, -999,
  102506. -999, -999, -999, -999, -999, -999, -999, -999},
  102507. { -28, -28, -28, -28, -28, -28, -28, -28,
  102508. -28, -30, -32, -32, -33, -35, -41, -49,
  102509. -50, -49, -47, -48, -48, -52, -51, -57,
  102510. -65, -61, -59, -61, -64, -69, -70, -74,
  102511. -77, -77, -78, -81, -84, -85, -87, -90,
  102512. -92, -96, -100, -107, -112, -999, -999, -999,
  102513. -999, -999, -999, -999, -999, -999, -999, -999},
  102514. { -19, -19, -19, -19, -19, -19, -19, -19,
  102515. -20, -21, -23, -27, -30, -35, -36, -41,
  102516. -46, -44, -42, -40, -41, -41, -43, -48,
  102517. -55, -53, -52, -53, -56, -59, -58, -60,
  102518. -67, -66, -69, -71, -72, -75, -79, -81,
  102519. -84, -87, -90, -93, -97, -101, -107, -114,
  102520. -999, -999, -999, -999, -999, -999, -999, -999},
  102521. { -9, -9, -9, -9, -9, -9, -9, -9,
  102522. -11, -12, -12, -15, -16, -20, -23, -30,
  102523. -37, -34, -33, -34, -31, -32, -32, -38,
  102524. -47, -44, -41, -40, -47, -49, -46, -46,
  102525. -58, -50, -50, -54, -58, -62, -64, -67,
  102526. -67, -70, -72, -76, -79, -83, -87, -91,
  102527. -96, -100, -104, -110, -999, -999, -999, -999}},
  102528. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102529. -62, -62, -63, -64, -66, -67, -66, -68,
  102530. -75, -72, -76, -75, -76, -78, -79, -82,
  102531. -84, -85, -90, -94, -101, -110, -999, -999,
  102532. -999, -999, -999, -999, -999, -999, -999, -999,
  102533. -999, -999, -999, -999, -999, -999, -999, -999,
  102534. -999, -999, -999, -999, -999, -999, -999, -999},
  102535. { -59, -59, -59, -59, -59, -59, -59, -59,
  102536. -59, -59, -59, -60, -60, -61, -63, -66,
  102537. -71, -68, -70, -70, -71, -72, -72, -75,
  102538. -81, -78, -79, -82, -83, -86, -90, -97,
  102539. -103, -113, -999, -999, -999, -999, -999, -999,
  102540. -999, -999, -999, -999, -999, -999, -999, -999,
  102541. -999, -999, -999, -999, -999, -999, -999, -999},
  102542. { -53, -53, -53, -53, -53, -53, -53, -53,
  102543. -53, -54, -55, -57, -56, -57, -55, -61,
  102544. -65, -60, -60, -62, -63, -63, -66, -68,
  102545. -74, -73, -75, -75, -78, -80, -80, -82,
  102546. -85, -90, -96, -101, -108, -999, -999, -999,
  102547. -999, -999, -999, -999, -999, -999, -999, -999,
  102548. -999, -999, -999, -999, -999, -999, -999, -999},
  102549. { -46, -46, -46, -46, -46, -46, -46, -46,
  102550. -46, -46, -47, -47, -47, -47, -48, -51,
  102551. -57, -51, -49, -50, -51, -53, -54, -59,
  102552. -66, -60, -62, -67, -67, -70, -72, -75,
  102553. -76, -78, -81, -85, -88, -94, -97, -104,
  102554. -112, -999, -999, -999, -999, -999, -999, -999,
  102555. -999, -999, -999, -999, -999, -999, -999, -999},
  102556. { -36, -36, -36, -36, -36, -36, -36, -36,
  102557. -39, -41, -42, -42, -39, -38, -41, -43,
  102558. -52, -44, -40, -39, -37, -37, -40, -47,
  102559. -54, -50, -48, -50, -55, -61, -59, -62,
  102560. -66, -66, -66, -69, -69, -73, -74, -74,
  102561. -75, -77, -79, -82, -87, -91, -95, -100,
  102562. -108, -115, -999, -999, -999, -999, -999, -999},
  102563. { -28, -26, -24, -22, -20, -20, -23, -29,
  102564. -30, -31, -28, -27, -28, -28, -28, -35,
  102565. -40, -33, -32, -29, -30, -30, -30, -37,
  102566. -45, -41, -37, -38, -45, -47, -47, -48,
  102567. -53, -49, -48, -50, -49, -49, -51, -52,
  102568. -58, -56, -57, -56, -60, -61, -62, -70,
  102569. -72, -74, -78, -83, -88, -93, -100, -106}},
  102570. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102571. -999, -110, -105, -100, -95, -91, -87, -83,
  102572. -80, -78, -76, -78, -78, -81, -83, -85,
  102573. -86, -85, -86, -87, -90, -97, -107, -999,
  102574. -999, -999, -999, -999, -999, -999, -999, -999,
  102575. -999, -999, -999, -999, -999, -999, -999, -999,
  102576. -999, -999, -999, -999, -999, -999, -999, -999},
  102577. {-999, -999, -999, -110, -105, -100, -95, -90,
  102578. -85, -81, -77, -73, -70, -67, -67, -68,
  102579. -75, -73, -70, -69, -70, -72, -75, -79,
  102580. -84, -83, -84, -86, -88, -89, -89, -93,
  102581. -98, -105, -112, -999, -999, -999, -999, -999,
  102582. -999, -999, -999, -999, -999, -999, -999, -999,
  102583. -999, -999, -999, -999, -999, -999, -999, -999},
  102584. {-105, -100, -95, -90, -85, -80, -76, -71,
  102585. -68, -68, -65, -63, -63, -62, -62, -64,
  102586. -65, -64, -61, -62, -63, -64, -66, -68,
  102587. -73, -73, -74, -75, -76, -81, -83, -85,
  102588. -88, -89, -92, -95, -100, -108, -999, -999,
  102589. -999, -999, -999, -999, -999, -999, -999, -999,
  102590. -999, -999, -999, -999, -999, -999, -999, -999},
  102591. { -80, -75, -71, -68, -65, -63, -62, -61,
  102592. -61, -61, -61, -59, -56, -57, -53, -50,
  102593. -58, -52, -50, -50, -52, -53, -54, -58,
  102594. -67, -63, -67, -68, -72, -75, -78, -80,
  102595. -81, -81, -82, -85, -89, -90, -93, -97,
  102596. -101, -107, -114, -999, -999, -999, -999, -999,
  102597. -999, -999, -999, -999, -999, -999, -999, -999},
  102598. { -65, -61, -59, -57, -56, -55, -55, -56,
  102599. -56, -57, -55, -53, -52, -47, -44, -44,
  102600. -50, -44, -41, -39, -39, -42, -40, -46,
  102601. -51, -49, -50, -53, -54, -63, -60, -61,
  102602. -62, -66, -66, -66, -70, -73, -74, -75,
  102603. -76, -75, -79, -85, -89, -91, -96, -102,
  102604. -110, -999, -999, -999, -999, -999, -999, -999},
  102605. { -52, -50, -49, -49, -48, -48, -48, -49,
  102606. -50, -50, -49, -46, -43, -39, -35, -33,
  102607. -38, -36, -32, -29, -32, -32, -32, -35,
  102608. -44, -39, -38, -38, -46, -50, -45, -46,
  102609. -53, -50, -50, -50, -54, -54, -53, -53,
  102610. -56, -57, -59, -66, -70, -72, -74, -79,
  102611. -83, -85, -90, -97, -114, -999, -999, -999}},
  102612. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102613. -100, -95, -90, -86, -80, -75, -75, -79,
  102614. -80, -79, -80, -81, -82, -88, -95, -103,
  102615. -110, -999, -999, -999, -999, -999, -999, -999,
  102616. -999, -999, -999, -999, -999, -999, -999, -999,
  102617. -999, -999, -999, -999, -999, -999, -999, -999,
  102618. -999, -999, -999, -999, -999, -999, -999, -999},
  102619. {-999, -999, -999, -999, -108, -103, -98, -93,
  102620. -88, -83, -79, -78, -75, -71, -67, -68,
  102621. -73, -73, -72, -73, -75, -77, -80, -82,
  102622. -88, -93, -100, -107, -114, -999, -999, -999,
  102623. -999, -999, -999, -999, -999, -999, -999, -999,
  102624. -999, -999, -999, -999, -999, -999, -999, -999,
  102625. -999, -999, -999, -999, -999, -999, -999, -999},
  102626. {-999, -999, -999, -110, -105, -101, -96, -90,
  102627. -86, -81, -77, -73, -69, -66, -61, -62,
  102628. -66, -64, -62, -65, -66, -70, -72, -76,
  102629. -81, -80, -84, -90, -95, -102, -110, -999,
  102630. -999, -999, -999, -999, -999, -999, -999, -999,
  102631. -999, -999, -999, -999, -999, -999, -999, -999,
  102632. -999, -999, -999, -999, -999, -999, -999, -999},
  102633. {-999, -999, -999, -107, -103, -97, -92, -88,
  102634. -83, -79, -74, -70, -66, -59, -53, -58,
  102635. -62, -55, -54, -54, -54, -58, -61, -62,
  102636. -72, -70, -72, -75, -78, -80, -81, -80,
  102637. -83, -83, -88, -93, -100, -107, -115, -999,
  102638. -999, -999, -999, -999, -999, -999, -999, -999,
  102639. -999, -999, -999, -999, -999, -999, -999, -999},
  102640. {-999, -999, -999, -105, -100, -95, -90, -85,
  102641. -80, -75, -70, -66, -62, -56, -48, -44,
  102642. -48, -46, -46, -43, -46, -48, -48, -51,
  102643. -58, -58, -59, -60, -62, -62, -61, -61,
  102644. -65, -64, -65, -68, -70, -74, -75, -78,
  102645. -81, -86, -95, -110, -999, -999, -999, -999,
  102646. -999, -999, -999, -999, -999, -999, -999, -999},
  102647. {-999, -999, -105, -100, -95, -90, -85, -80,
  102648. -75, -70, -65, -61, -55, -49, -39, -33,
  102649. -40, -35, -32, -38, -40, -33, -35, -37,
  102650. -46, -41, -45, -44, -46, -42, -45, -46,
  102651. -52, -50, -50, -50, -54, -54, -55, -57,
  102652. -62, -64, -66, -68, -70, -76, -81, -90,
  102653. -100, -110, -999, -999, -999, -999, -999, -999}},
  102654. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102655. -105, -98, -90, -85, -82, -83, -80, -78,
  102656. -84, -79, -80, -83, -87, -89, -91, -93,
  102657. -99, -106, -117, -999, -999, -999, -999, -999,
  102658. -999, -999, -999, -999, -999, -999, -999, -999,
  102659. -999, -999, -999, -999, -999, -999, -999, -999,
  102660. -999, -999, -999, -999, -999, -999, -999, -999},
  102661. {-999, -999, -999, -999, -999, -999, -999, -999,
  102662. -105, -98, -90, -85, -80, -75, -70, -68,
  102663. -74, -72, -74, -77, -80, -82, -85, -87,
  102664. -92, -89, -91, -95, -100, -106, -112, -999,
  102665. -999, -999, -999, -999, -999, -999, -999, -999,
  102666. -999, -999, -999, -999, -999, -999, -999, -999,
  102667. -999, -999, -999, -999, -999, -999, -999, -999},
  102668. {-999, -999, -999, -999, -999, -999, -999, -999,
  102669. -105, -98, -90, -83, -75, -71, -63, -64,
  102670. -67, -62, -64, -67, -70, -73, -77, -81,
  102671. -84, -83, -85, -89, -90, -93, -98, -104,
  102672. -109, -114, -999, -999, -999, -999, -999, -999,
  102673. -999, -999, -999, -999, -999, -999, -999, -999,
  102674. -999, -999, -999, -999, -999, -999, -999, -999},
  102675. {-999, -999, -999, -999, -999, -999, -999, -999,
  102676. -103, -96, -88, -81, -75, -68, -58, -54,
  102677. -56, -54, -56, -56, -58, -60, -63, -66,
  102678. -74, -69, -72, -72, -75, -74, -77, -81,
  102679. -81, -82, -84, -87, -93, -96, -99, -104,
  102680. -110, -999, -999, -999, -999, -999, -999, -999,
  102681. -999, -999, -999, -999, -999, -999, -999, -999},
  102682. {-999, -999, -999, -999, -999, -108, -102, -96,
  102683. -91, -85, -80, -74, -68, -60, -51, -46,
  102684. -48, -46, -43, -45, -47, -47, -49, -48,
  102685. -56, -53, -55, -58, -57, -63, -58, -60,
  102686. -66, -64, -67, -70, -70, -74, -77, -84,
  102687. -86, -89, -91, -93, -94, -101, -109, -118,
  102688. -999, -999, -999, -999, -999, -999, -999, -999},
  102689. {-999, -999, -999, -108, -103, -98, -93, -88,
  102690. -83, -78, -73, -68, -60, -53, -44, -35,
  102691. -38, -38, -34, -34, -36, -40, -41, -44,
  102692. -51, -45, -46, -47, -46, -54, -50, -49,
  102693. -50, -50, -50, -51, -54, -57, -58, -60,
  102694. -66, -66, -66, -64, -65, -68, -77, -82,
  102695. -87, -95, -110, -999, -999, -999, -999, -999}},
  102696. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102697. -107, -102, -97, -92, -87, -83, -78, -75,
  102698. -82, -79, -83, -85, -89, -92, -95, -98,
  102699. -101, -105, -109, -113, -999, -999, -999, -999,
  102700. -999, -999, -999, -999, -999, -999, -999, -999,
  102701. -999, -999, -999, -999, -999, -999, -999, -999,
  102702. -999, -999, -999, -999, -999, -999, -999, -999},
  102703. {-999, -999, -999, -999, -999, -999, -999, -106,
  102704. -100, -95, -90, -86, -81, -78, -74, -69,
  102705. -74, -74, -76, -79, -83, -84, -86, -89,
  102706. -92, -97, -93, -100, -103, -107, -110, -999,
  102707. -999, -999, -999, -999, -999, -999, -999, -999,
  102708. -999, -999, -999, -999, -999, -999, -999, -999,
  102709. -999, -999, -999, -999, -999, -999, -999, -999},
  102710. {-999, -999, -999, -999, -999, -999, -106, -100,
  102711. -95, -90, -87, -83, -80, -75, -69, -60,
  102712. -66, -66, -68, -70, -74, -78, -79, -81,
  102713. -81, -83, -84, -87, -93, -96, -99, -103,
  102714. -107, -110, -999, -999, -999, -999, -999, -999,
  102715. -999, -999, -999, -999, -999, -999, -999, -999,
  102716. -999, -999, -999, -999, -999, -999, -999, -999},
  102717. {-999, -999, -999, -999, -999, -108, -103, -98,
  102718. -93, -89, -85, -82, -78, -71, -62, -55,
  102719. -58, -58, -54, -54, -55, -59, -61, -62,
  102720. -70, -66, -66, -67, -70, -72, -75, -78,
  102721. -84, -84, -84, -88, -91, -90, -95, -98,
  102722. -102, -103, -106, -110, -999, -999, -999, -999,
  102723. -999, -999, -999, -999, -999, -999, -999, -999},
  102724. {-999, -999, -999, -999, -108, -103, -98, -94,
  102725. -90, -87, -82, -79, -73, -67, -58, -47,
  102726. -50, -45, -41, -45, -48, -44, -44, -49,
  102727. -54, -51, -48, -47, -49, -50, -51, -57,
  102728. -58, -60, -63, -69, -70, -69, -71, -74,
  102729. -78, -82, -90, -95, -101, -105, -110, -999,
  102730. -999, -999, -999, -999, -999, -999, -999, -999},
  102731. {-999, -999, -999, -105, -101, -97, -93, -90,
  102732. -85, -80, -77, -72, -65, -56, -48, -37,
  102733. -40, -36, -34, -40, -50, -47, -38, -41,
  102734. -47, -38, -35, -39, -38, -43, -40, -45,
  102735. -50, -45, -44, -47, -50, -55, -48, -48,
  102736. -52, -66, -70, -76, -82, -90, -97, -105,
  102737. -110, -999, -999, -999, -999, -999, -999, -999}},
  102738. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102739. -999, -108, -103, -98, -93, -86, -79, -76,
  102740. -83, -81, -85, -87, -89, -93, -98, -102,
  102741. -107, -112, -999, -999, -999, -999, -999, -999,
  102742. -999, -999, -999, -999, -999, -999, -999, -999,
  102743. -999, -999, -999, -999, -999, -999, -999, -999,
  102744. -999, -999, -999, -999, -999, -999, -999, -999},
  102745. {-999, -999, -999, -999, -999, -999, -999, -999,
  102746. -999, -108, -103, -98, -93, -86, -79, -71,
  102747. -77, -74, -77, -79, -81, -84, -85, -90,
  102748. -92, -93, -92, -98, -101, -108, -112, -999,
  102749. -999, -999, -999, -999, -999, -999, -999, -999,
  102750. -999, -999, -999, -999, -999, -999, -999, -999,
  102751. -999, -999, -999, -999, -999, -999, -999, -999},
  102752. {-999, -999, -999, -999, -999, -999, -999, -999,
  102753. -108, -103, -98, -93, -87, -78, -68, -65,
  102754. -66, -62, -65, -67, -70, -73, -75, -78,
  102755. -82, -82, -83, -84, -91, -93, -98, -102,
  102756. -106, -110, -999, -999, -999, -999, -999, -999,
  102757. -999, -999, -999, -999, -999, -999, -999, -999,
  102758. -999, -999, -999, -999, -999, -999, -999, -999},
  102759. {-999, -999, -999, -999, -999, -999, -999, -999,
  102760. -105, -100, -95, -90, -82, -74, -62, -57,
  102761. -58, -56, -51, -52, -52, -54, -54, -58,
  102762. -66, -59, -60, -63, -66, -69, -73, -79,
  102763. -83, -84, -80, -81, -81, -82, -88, -92,
  102764. -98, -105, -113, -999, -999, -999, -999, -999,
  102765. -999, -999, -999, -999, -999, -999, -999, -999},
  102766. {-999, -999, -999, -999, -999, -999, -999, -107,
  102767. -102, -97, -92, -84, -79, -69, -57, -47,
  102768. -52, -47, -44, -45, -50, -52, -42, -42,
  102769. -53, -43, -43, -48, -51, -56, -55, -52,
  102770. -57, -59, -61, -62, -67, -71, -78, -83,
  102771. -86, -94, -98, -103, -110, -999, -999, -999,
  102772. -999, -999, -999, -999, -999, -999, -999, -999},
  102773. {-999, -999, -999, -999, -999, -999, -105, -100,
  102774. -95, -90, -84, -78, -70, -61, -51, -41,
  102775. -40, -38, -40, -46, -52, -51, -41, -40,
  102776. -46, -40, -38, -38, -41, -46, -41, -46,
  102777. -47, -43, -43, -45, -41, -45, -56, -67,
  102778. -68, -83, -87, -90, -95, -102, -107, -113,
  102779. -999, -999, -999, -999, -999, -999, -999, -999}},
  102780. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102781. -999, -109, -105, -101, -96, -91, -84, -77,
  102782. -82, -82, -85, -89, -94, -100, -106, -110,
  102783. -999, -999, -999, -999, -999, -999, -999, -999,
  102784. -999, -999, -999, -999, -999, -999, -999, -999,
  102785. -999, -999, -999, -999, -999, -999, -999, -999,
  102786. -999, -999, -999, -999, -999, -999, -999, -999},
  102787. {-999, -999, -999, -999, -999, -999, -999, -999,
  102788. -999, -106, -103, -98, -92, -85, -80, -71,
  102789. -75, -72, -76, -80, -84, -86, -89, -93,
  102790. -100, -107, -113, -999, -999, -999, -999, -999,
  102791. -999, -999, -999, -999, -999, -999, -999, -999,
  102792. -999, -999, -999, -999, -999, -999, -999, -999,
  102793. -999, -999, -999, -999, -999, -999, -999, -999},
  102794. {-999, -999, -999, -999, -999, -999, -999, -107,
  102795. -104, -101, -97, -92, -88, -84, -80, -64,
  102796. -66, -63, -64, -66, -69, -73, -77, -83,
  102797. -83, -86, -91, -98, -104, -111, -999, -999,
  102798. -999, -999, -999, -999, -999, -999, -999, -999,
  102799. -999, -999, -999, -999, -999, -999, -999, -999,
  102800. -999, -999, -999, -999, -999, -999, -999, -999},
  102801. {-999, -999, -999, -999, -999, -999, -999, -107,
  102802. -104, -101, -97, -92, -90, -84, -74, -57,
  102803. -58, -52, -55, -54, -50, -52, -50, -52,
  102804. -63, -62, -69, -76, -77, -78, -78, -79,
  102805. -82, -88, -94, -100, -106, -111, -999, -999,
  102806. -999, -999, -999, -999, -999, -999, -999, -999,
  102807. -999, -999, -999, -999, -999, -999, -999, -999},
  102808. {-999, -999, -999, -999, -999, -999, -106, -102,
  102809. -98, -95, -90, -85, -83, -78, -70, -50,
  102810. -50, -41, -44, -49, -47, -50, -50, -44,
  102811. -55, -46, -47, -48, -48, -54, -49, -49,
  102812. -58, -62, -71, -81, -87, -92, -97, -102,
  102813. -108, -114, -999, -999, -999, -999, -999, -999,
  102814. -999, -999, -999, -999, -999, -999, -999, -999},
  102815. {-999, -999, -999, -999, -999, -999, -106, -102,
  102816. -98, -95, -90, -85, -83, -78, -70, -45,
  102817. -43, -41, -47, -50, -51, -50, -49, -45,
  102818. -47, -41, -44, -41, -39, -43, -38, -37,
  102819. -40, -41, -44, -50, -58, -65, -73, -79,
  102820. -85, -92, -97, -101, -105, -109, -113, -999,
  102821. -999, -999, -999, -999, -999, -999, -999, -999}},
  102822. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102823. -999, -999, -999, -107, -100, -95, -87, -81,
  102824. -85, -83, -88, -93, -100, -107, -114, -999,
  102825. -999, -999, -999, -999, -999, -999, -999, -999,
  102826. -999, -999, -999, -999, -999, -999, -999, -999,
  102827. -999, -999, -999, -999, -999, -999, -999, -999,
  102828. -999, -999, -999, -999, -999, -999, -999, -999},
  102829. {-999, -999, -999, -999, -999, -999, -999, -999,
  102830. -999, -999, -107, -101, -95, -88, -83, -76,
  102831. -73, -72, -79, -84, -90, -95, -100, -105,
  102832. -110, -115, -999, -999, -999, -999, -999, -999,
  102833. -999, -999, -999, -999, -999, -999, -999, -999,
  102834. -999, -999, -999, -999, -999, -999, -999, -999,
  102835. -999, -999, -999, -999, -999, -999, -999, -999},
  102836. {-999, -999, -999, -999, -999, -999, -999, -999,
  102837. -999, -999, -104, -98, -92, -87, -81, -70,
  102838. -65, -62, -67, -71, -74, -80, -85, -91,
  102839. -95, -99, -103, -108, -111, -114, -999, -999,
  102840. -999, -999, -999, -999, -999, -999, -999, -999,
  102841. -999, -999, -999, -999, -999, -999, -999, -999,
  102842. -999, -999, -999, -999, -999, -999, -999, -999},
  102843. {-999, -999, -999, -999, -999, -999, -999, -999,
  102844. -999, -999, -103, -97, -90, -85, -76, -60,
  102845. -56, -54, -60, -62, -61, -56, -63, -65,
  102846. -73, -74, -77, -75, -78, -81, -86, -87,
  102847. -88, -91, -94, -98, -103, -110, -999, -999,
  102848. -999, -999, -999, -999, -999, -999, -999, -999,
  102849. -999, -999, -999, -999, -999, -999, -999, -999},
  102850. {-999, -999, -999, -999, -999, -999, -999, -105,
  102851. -100, -97, -92, -86, -81, -79, -70, -57,
  102852. -51, -47, -51, -58, -60, -56, -53, -50,
  102853. -58, -52, -50, -50, -53, -55, -64, -69,
  102854. -71, -85, -82, -78, -81, -85, -95, -102,
  102855. -112, -999, -999, -999, -999, -999, -999, -999,
  102856. -999, -999, -999, -999, -999, -999, -999, -999},
  102857. {-999, -999, -999, -999, -999, -999, -999, -105,
  102858. -100, -97, -92, -85, -83, -79, -72, -49,
  102859. -40, -43, -43, -54, -56, -51, -50, -40,
  102860. -43, -38, -36, -35, -37, -38, -37, -44,
  102861. -54, -60, -57, -60, -70, -75, -84, -92,
  102862. -103, -112, -999, -999, -999, -999, -999, -999,
  102863. -999, -999, -999, -999, -999, -999, -999, -999}},
  102864. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102865. -999, -999, -999, -110, -102, -95, -89, -82,
  102866. -83, -84, -90, -92, -99, -107, -113, -999,
  102867. -999, -999, -999, -999, -999, -999, -999, -999,
  102868. -999, -999, -999, -999, -999, -999, -999, -999,
  102869. -999, -999, -999, -999, -999, -999, -999, -999,
  102870. -999, -999, -999, -999, -999, -999, -999, -999},
  102871. {-999, -999, -999, -999, -999, -999, -999, -999,
  102872. -999, -999, -107, -101, -95, -89, -83, -72,
  102873. -74, -78, -85, -88, -88, -90, -92, -98,
  102874. -105, -111, -999, -999, -999, -999, -999, -999,
  102875. -999, -999, -999, -999, -999, -999, -999, -999,
  102876. -999, -999, -999, -999, -999, -999, -999, -999,
  102877. -999, -999, -999, -999, -999, -999, -999, -999},
  102878. {-999, -999, -999, -999, -999, -999, -999, -999,
  102879. -999, -109, -103, -97, -93, -87, -81, -70,
  102880. -70, -67, -75, -73, -76, -79, -81, -83,
  102881. -88, -89, -97, -103, -110, -999, -999, -999,
  102882. -999, -999, -999, -999, -999, -999, -999, -999,
  102883. -999, -999, -999, -999, -999, -999, -999, -999,
  102884. -999, -999, -999, -999, -999, -999, -999, -999},
  102885. {-999, -999, -999, -999, -999, -999, -999, -999,
  102886. -999, -107, -100, -94, -88, -83, -75, -63,
  102887. -59, -59, -63, -66, -60, -62, -67, -67,
  102888. -77, -76, -81, -88, -86, -92, -96, -102,
  102889. -109, -116, -999, -999, -999, -999, -999, -999,
  102890. -999, -999, -999, -999, -999, -999, -999, -999,
  102891. -999, -999, -999, -999, -999, -999, -999, -999},
  102892. {-999, -999, -999, -999, -999, -999, -999, -999,
  102893. -999, -105, -98, -92, -86, -81, -73, -56,
  102894. -52, -47, -55, -60, -58, -52, -51, -45,
  102895. -49, -50, -53, -54, -61, -71, -70, -69,
  102896. -78, -79, -87, -90, -96, -104, -112, -999,
  102897. -999, -999, -999, -999, -999, -999, -999, -999,
  102898. -999, -999, -999, -999, -999, -999, -999, -999},
  102899. {-999, -999, -999, -999, -999, -999, -999, -999,
  102900. -999, -103, -96, -90, -86, -78, -70, -51,
  102901. -42, -47, -48, -55, -54, -54, -53, -42,
  102902. -35, -28, -33, -38, -37, -44, -47, -49,
  102903. -54, -63, -68, -78, -82, -89, -94, -99,
  102904. -104, -109, -114, -999, -999, -999, -999, -999,
  102905. -999, -999, -999, -999, -999, -999, -999, -999}},
  102906. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102907. -999, -999, -999, -999, -110, -100, -90, -79,
  102908. -85, -81, -82, -82, -89, -94, -99, -103,
  102909. -109, -115, -999, -999, -999, -999, -999, -999,
  102910. -999, -999, -999, -999, -999, -999, -999, -999,
  102911. -999, -999, -999, -999, -999, -999, -999, -999,
  102912. -999, -999, -999, -999, -999, -999, -999, -999},
  102913. {-999, -999, -999, -999, -999, -999, -999, -999,
  102914. -999, -999, -999, -999, -105, -97, -85, -72,
  102915. -74, -70, -70, -70, -76, -85, -91, -93,
  102916. -97, -103, -109, -115, -999, -999, -999, -999,
  102917. -999, -999, -999, -999, -999, -999, -999, -999,
  102918. -999, -999, -999, -999, -999, -999, -999, -999,
  102919. -999, -999, -999, -999, -999, -999, -999, -999},
  102920. {-999, -999, -999, -999, -999, -999, -999, -999,
  102921. -999, -999, -999, -999, -112, -93, -81, -68,
  102922. -62, -60, -60, -57, -63, -70, -77, -82,
  102923. -90, -93, -98, -104, -109, -113, -999, -999,
  102924. -999, -999, -999, -999, -999, -999, -999, -999,
  102925. -999, -999, -999, -999, -999, -999, -999, -999,
  102926. -999, -999, -999, -999, -999, -999, -999, -999},
  102927. {-999, -999, -999, -999, -999, -999, -999, -999,
  102928. -999, -999, -999, -113, -100, -93, -84, -63,
  102929. -58, -48, -53, -54, -52, -52, -57, -64,
  102930. -66, -76, -83, -81, -85, -85, -90, -95,
  102931. -98, -101, -103, -106, -108, -111, -999, -999,
  102932. -999, -999, -999, -999, -999, -999, -999, -999,
  102933. -999, -999, -999, -999, -999, -999, -999, -999},
  102934. {-999, -999, -999, -999, -999, -999, -999, -999,
  102935. -999, -999, -999, -105, -95, -86, -74, -53,
  102936. -50, -38, -43, -49, -43, -42, -39, -39,
  102937. -46, -52, -57, -56, -72, -69, -74, -81,
  102938. -87, -92, -94, -97, -99, -102, -105, -108,
  102939. -999, -999, -999, -999, -999, -999, -999, -999,
  102940. -999, -999, -999, -999, -999, -999, -999, -999},
  102941. {-999, -999, -999, -999, -999, -999, -999, -999,
  102942. -999, -999, -108, -99, -90, -76, -66, -45,
  102943. -43, -41, -44, -47, -43, -47, -40, -30,
  102944. -31, -31, -39, -33, -40, -41, -43, -53,
  102945. -59, -70, -73, -77, -79, -82, -84, -87,
  102946. -999, -999, -999, -999, -999, -999, -999, -999,
  102947. -999, -999, -999, -999, -999, -999, -999, -999}},
  102948. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102949. -999, -999, -999, -999, -999, -110, -91, -76,
  102950. -75, -85, -93, -98, -104, -110, -999, -999,
  102951. -999, -999, -999, -999, -999, -999, -999, -999,
  102952. -999, -999, -999, -999, -999, -999, -999, -999,
  102953. -999, -999, -999, -999, -999, -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, -110, -91, -70,
  102957. -70, -75, -86, -89, -94, -98, -101, -106,
  102958. -110, -999, -999, -999, -999, -999, -999, -999,
  102959. -999, -999, -999, -999, -999, -999, -999, -999,
  102960. -999, -999, -999, -999, -999, -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, -110, -95, -80, -60,
  102964. -65, -64, -74, -83, -88, -91, -95, -99,
  102965. -103, -107, -110, -999, -999, -999, -999, -999,
  102966. -999, -999, -999, -999, -999, -999, -999, -999,
  102967. -999, -999, -999, -999, -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, -110, -95, -80, -58,
  102971. -55, -49, -66, -68, -71, -78, -78, -80,
  102972. -88, -85, -89, -97, -100, -105, -110, -999,
  102973. -999, -999, -999, -999, -999, -999, -999, -999,
  102974. -999, -999, -999, -999, -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, -110, -95, -80, -53,
  102978. -52, -41, -59, -59, -49, -58, -56, -63,
  102979. -86, -79, -90, -93, -98, -103, -107, -112,
  102980. -999, -999, -999, -999, -999, -999, -999, -999,
  102981. -999, -999, -999, -999, -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, -110, -97, -91, -73, -45,
  102985. -40, -33, -53, -61, -49, -54, -50, -50,
  102986. -60, -52, -67, -74, -81, -92, -96, -100,
  102987. -105, -110, -999, -999, -999, -999, -999, -999,
  102988. -999, -999, -999, -999, -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, -113, -106, -99, -92, -77,
  102992. -80, -88, -97, -106, -115, -999, -999, -999,
  102993. -999, -999, -999, -999, -999, -999, -999, -999,
  102994. -999, -999, -999, -999, -999, -999, -999, -999,
  102995. -999, -999, -999, -999, -999, -999, -999, -999,
  102996. -999, -999, -999, -999, -999, -999, -999, -999},
  102997. {-999, -999, -999, -999, -999, -999, -999, -999,
  102998. -999, -999, -116, -109, -102, -95, -89, -74,
  102999. -72, -88, -87, -95, -102, -109, -116, -999,
  103000. -999, -999, -999, -999, -999, -999, -999, -999,
  103001. -999, -999, -999, -999, -999, -999, -999, -999,
  103002. -999, -999, -999, -999, -999, -999, -999, -999,
  103003. -999, -999, -999, -999, -999, -999, -999, -999},
  103004. {-999, -999, -999, -999, -999, -999, -999, -999,
  103005. -999, -999, -116, -109, -102, -95, -89, -75,
  103006. -66, -74, -77, -78, -86, -87, -90, -96,
  103007. -105, -115, -999, -999, -999, -999, -999, -999,
  103008. -999, -999, -999, -999, -999, -999, -999, -999,
  103009. -999, -999, -999, -999, -999, -999, -999, -999,
  103010. -999, -999, -999, -999, -999, -999, -999, -999},
  103011. {-999, -999, -999, -999, -999, -999, -999, -999,
  103012. -999, -999, -115, -108, -101, -94, -88, -66,
  103013. -56, -61, -70, -65, -78, -72, -83, -84,
  103014. -93, -98, -105, -110, -999, -999, -999, -999,
  103015. -999, -999, -999, -999, -999, -999, -999, -999,
  103016. -999, -999, -999, -999, -999, -999, -999, -999,
  103017. -999, -999, -999, -999, -999, -999, -999, -999},
  103018. {-999, -999, -999, -999, -999, -999, -999, -999,
  103019. -999, -999, -110, -105, -95, -89, -82, -57,
  103020. -52, -52, -59, -56, -59, -58, -69, -67,
  103021. -88, -82, -82, -89, -94, -100, -108, -999,
  103022. -999, -999, -999, -999, -999, -999, -999, -999,
  103023. -999, -999, -999, -999, -999, -999, -999, -999,
  103024. -999, -999, -999, -999, -999, -999, -999, -999},
  103025. {-999, -999, -999, -999, -999, -999, -999, -999,
  103026. -999, -110, -101, -96, -90, -83, -77, -54,
  103027. -43, -38, -50, -48, -52, -48, -42, -42,
  103028. -51, -52, -53, -59, -65, -71, -78, -85,
  103029. -95, -999, -999, -999, -999, -999, -999, -999,
  103030. -999, -999, -999, -999, -999, -999, -999, -999,
  103031. -999, -999, -999, -999, -999, -999, -999, -999}},
  103032. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103033. -999, -999, -999, -999, -120, -105, -86, -68,
  103034. -78, -79, -90, -100, -110, -999, -999, -999,
  103035. -999, -999, -999, -999, -999, -999, -999, -999,
  103036. -999, -999, -999, -999, -999, -999, -999, -999,
  103037. -999, -999, -999, -999, -999, -999, -999, -999,
  103038. -999, -999, -999, -999, -999, -999, -999, -999},
  103039. {-999, -999, -999, -999, -999, -999, -999, -999,
  103040. -999, -999, -999, -999, -120, -105, -86, -66,
  103041. -73, -77, -88, -96, -105, -115, -999, -999,
  103042. -999, -999, -999, -999, -999, -999, -999, -999,
  103043. -999, -999, -999, -999, -999, -999, -999, -999,
  103044. -999, -999, -999, -999, -999, -999, -999, -999,
  103045. -999, -999, -999, -999, -999, -999, -999, -999},
  103046. {-999, -999, -999, -999, -999, -999, -999, -999,
  103047. -999, -999, -999, -120, -105, -92, -80, -61,
  103048. -64, -68, -80, -87, -92, -100, -110, -999,
  103049. -999, -999, -999, -999, -999, -999, -999, -999,
  103050. -999, -999, -999, -999, -999, -999, -999, -999,
  103051. -999, -999, -999, -999, -999, -999, -999, -999,
  103052. -999, -999, -999, -999, -999, -999, -999, -999},
  103053. {-999, -999, -999, -999, -999, -999, -999, -999,
  103054. -999, -999, -999, -120, -104, -91, -79, -52,
  103055. -60, -54, -64, -69, -77, -80, -82, -84,
  103056. -85, -87, -88, -90, -999, -999, -999, -999,
  103057. -999, -999, -999, -999, -999, -999, -999, -999,
  103058. -999, -999, -999, -999, -999, -999, -999, -999,
  103059. -999, -999, -999, -999, -999, -999, -999, -999},
  103060. {-999, -999, -999, -999, -999, -999, -999, -999,
  103061. -999, -999, -999, -118, -100, -87, -77, -49,
  103062. -50, -44, -58, -61, -61, -67, -65, -62,
  103063. -62, -62, -65, -68, -999, -999, -999, -999,
  103064. -999, -999, -999, -999, -999, -999, -999, -999,
  103065. -999, -999, -999, -999, -999, -999, -999, -999,
  103066. -999, -999, -999, -999, -999, -999, -999, -999},
  103067. {-999, -999, -999, -999, -999, -999, -999, -999,
  103068. -999, -999, -999, -115, -98, -84, -62, -49,
  103069. -44, -38, -46, -49, -49, -46, -39, -37,
  103070. -39, -40, -42, -43, -999, -999, -999, -999,
  103071. -999, -999, -999, -999, -999, -999, -999, -999,
  103072. -999, -999, -999, -999, -999, -999, -999, -999,
  103073. -999, -999, -999, -999, -999, -999, -999, -999}},
  103074. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103075. -999, -999, -999, -999, -999, -110, -88, -74,
  103076. -77, -82, -82, -85, -90, -94, -99, -104,
  103077. -999, -999, -999, -999, -999, -999, -999, -999,
  103078. -999, -999, -999, -999, -999, -999, -999, -999,
  103079. -999, -999, -999, -999, -999, -999, -999, -999,
  103080. -999, -999, -999, -999, -999, -999, -999, -999},
  103081. {-999, -999, -999, -999, -999, -999, -999, -999,
  103082. -999, -999, -999, -999, -999, -110, -88, -66,
  103083. -70, -81, -80, -81, -84, -88, -91, -93,
  103084. -999, -999, -999, -999, -999, -999, -999, -999,
  103085. -999, -999, -999, -999, -999, -999, -999, -999,
  103086. -999, -999, -999, -999, -999, -999, -999, -999,
  103087. -999, -999, -999, -999, -999, -999, -999, -999},
  103088. {-999, -999, -999, -999, -999, -999, -999, -999,
  103089. -999, -999, -999, -999, -999, -110, -88, -61,
  103090. -63, -70, -71, -74, -77, -80, -83, -85,
  103091. -999, -999, -999, -999, -999, -999, -999, -999,
  103092. -999, -999, -999, -999, -999, -999, -999, -999,
  103093. -999, -999, -999, -999, -999, -999, -999, -999,
  103094. -999, -999, -999, -999, -999, -999, -999, -999},
  103095. {-999, -999, -999, -999, -999, -999, -999, -999,
  103096. -999, -999, -999, -999, -999, -110, -86, -62,
  103097. -63, -62, -62, -58, -52, -50, -50, -52,
  103098. -54, -999, -999, -999, -999, -999, -999, -999,
  103099. -999, -999, -999, -999, -999, -999, -999, -999,
  103100. -999, -999, -999, -999, -999, -999, -999, -999,
  103101. -999, -999, -999, -999, -999, -999, -999, -999},
  103102. {-999, -999, -999, -999, -999, -999, -999, -999,
  103103. -999, -999, -999, -999, -118, -108, -84, -53,
  103104. -50, -50, -50, -55, -47, -45, -40, -40,
  103105. -40, -999, -999, -999, -999, -999, -999, -999,
  103106. -999, -999, -999, -999, -999, -999, -999, -999,
  103107. -999, -999, -999, -999, -999, -999, -999, -999,
  103108. -999, -999, -999, -999, -999, -999, -999, -999},
  103109. {-999, -999, -999, -999, -999, -999, -999, -999,
  103110. -999, -999, -999, -999, -118, -100, -73, -43,
  103111. -37, -42, -43, -53, -38, -37, -35, -35,
  103112. -38, -999, -999, -999, -999, -999, -999, -999,
  103113. -999, -999, -999, -999, -999, -999, -999, -999,
  103114. -999, -999, -999, -999, -999, -999, -999, -999,
  103115. -999, -999, -999, -999, -999, -999, -999, -999}},
  103116. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103117. -999, -999, -999, -110, -100, -91, -84, -74,
  103118. -80, -80, -80, -80, -80, -999, -999, -999,
  103119. -999, -999, -999, -999, -999, -999, -999, -999,
  103120. -999, -999, -999, -999, -999, -999, -999, -999,
  103121. -999, -999, -999, -999, -999, -999, -999, -999,
  103122. -999, -999, -999, -999, -999, -999, -999, -999},
  103123. {-999, -999, -999, -999, -999, -999, -999, -999,
  103124. -999, -999, -999, -110, -100, -91, -84, -74,
  103125. -68, -68, -68, -68, -68, -999, -999, -999,
  103126. -999, -999, -999, -999, -999, -999, -999, -999,
  103127. -999, -999, -999, -999, -999, -999, -999, -999,
  103128. -999, -999, -999, -999, -999, -999, -999, -999,
  103129. -999, -999, -999, -999, -999, -999, -999, -999},
  103130. {-999, -999, -999, -999, -999, -999, -999, -999,
  103131. -999, -999, -999, -110, -100, -86, -78, -70,
  103132. -60, -45, -30, -21, -999, -999, -999, -999,
  103133. -999, -999, -999, -999, -999, -999, -999, -999,
  103134. -999, -999, -999, -999, -999, -999, -999, -999,
  103135. -999, -999, -999, -999, -999, -999, -999, -999,
  103136. -999, -999, -999, -999, -999, -999, -999, -999},
  103137. {-999, -999, -999, -999, -999, -999, -999, -999,
  103138. -999, -999, -999, -110, -100, -87, -78, -67,
  103139. -48, -38, -29, -21, -999, -999, -999, -999,
  103140. -999, -999, -999, -999, -999, -999, -999, -999,
  103141. -999, -999, -999, -999, -999, -999, -999, -999,
  103142. -999, -999, -999, -999, -999, -999, -999, -999,
  103143. -999, -999, -999, -999, -999, -999, -999, -999},
  103144. {-999, -999, -999, -999, -999, -999, -999, -999,
  103145. -999, -999, -999, -110, -100, -86, -69, -56,
  103146. -45, -35, -33, -29, -999, -999, -999, -999,
  103147. -999, -999, -999, -999, -999, -999, -999, -999,
  103148. -999, -999, -999, -999, -999, -999, -999, -999,
  103149. -999, -999, -999, -999, -999, -999, -999, -999,
  103150. -999, -999, -999, -999, -999, -999, -999, -999},
  103151. {-999, -999, -999, -999, -999, -999, -999, -999,
  103152. -999, -999, -999, -110, -100, -83, -71, -48,
  103153. -27, -38, -37, -34, -999, -999, -999, -999,
  103154. -999, -999, -999, -999, -999, -999, -999, -999,
  103155. -999, -999, -999, -999, -999, -999, -999, -999,
  103156. -999, -999, -999, -999, -999, -999, -999, -999,
  103157. -999, -999, -999, -999, -999, -999, -999, -999}}
  103158. };
  103159. #endif
  103160. /*** End of inlined file: masking.h ***/
  103161. #define NEGINF -9999.f
  103162. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  103163. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  103164. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  103165. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103166. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103167. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  103168. look->channels=vi->channels;
  103169. look->ampmax=-9999.;
  103170. look->gi=gi;
  103171. return(look);
  103172. }
  103173. void _vp_global_free(vorbis_look_psy_global *look){
  103174. if(look){
  103175. memset(look,0,sizeof(*look));
  103176. _ogg_free(look);
  103177. }
  103178. }
  103179. void _vi_gpsy_free(vorbis_info_psy_global *i){
  103180. if(i){
  103181. memset(i,0,sizeof(*i));
  103182. _ogg_free(i);
  103183. }
  103184. }
  103185. void _vi_psy_free(vorbis_info_psy *i){
  103186. if(i){
  103187. memset(i,0,sizeof(*i));
  103188. _ogg_free(i);
  103189. }
  103190. }
  103191. static void min_curve(float *c,
  103192. float *c2){
  103193. int i;
  103194. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  103195. }
  103196. static void max_curve(float *c,
  103197. float *c2){
  103198. int i;
  103199. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  103200. }
  103201. static void attenuate_curve(float *c,float att){
  103202. int i;
  103203. for(i=0;i<EHMER_MAX;i++)
  103204. c[i]+=att;
  103205. }
  103206. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  103207. float center_boost, float center_decay_rate){
  103208. int i,j,k,m;
  103209. float ath[EHMER_MAX];
  103210. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  103211. float athc[P_LEVELS][EHMER_MAX];
  103212. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  103213. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  103214. memset(workc,0,sizeof(workc));
  103215. for(i=0;i<P_BANDS;i++){
  103216. int ath_offset=i*4;
  103217. for(j=0;j<EHMER_MAX;j++){
  103218. float min=999.;
  103219. for(k=0;k<4;k++)
  103220. if(j+k+ath_offset<MAX_ATH){
  103221. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  103222. }else{
  103223. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  103224. }
  103225. ath[j]=min;
  103226. }
  103227. for(j=0;j<6;j++)
  103228. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  103229. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103230. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103231. for(j=0;j<P_LEVELS;j++){
  103232. for(k=0;k<EHMER_MAX;k++){
  103233. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  103234. if(adj<0. && center_boost>0)adj=0.;
  103235. if(adj>0. && center_boost<0)adj=0.;
  103236. workc[i][j][k]+=adj;
  103237. }
  103238. }
  103239. for(j=0;j<P_LEVELS;j++){
  103240. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  103241. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  103242. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  103243. max_curve(athc[j],workc[i][j]);
  103244. }
  103245. for(j=1;j<P_LEVELS;j++){
  103246. min_curve(athc[j],athc[j-1]);
  103247. min_curve(workc[i][j],athc[j]);
  103248. }
  103249. }
  103250. for(i=0;i<P_BANDS;i++){
  103251. int hi_curve,lo_curve,bin;
  103252. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  103253. bin=floor(fromOC(i*.5)/binHz);
  103254. lo_curve= ceil(toOC(bin*binHz+1)*2);
  103255. hi_curve= floor(toOC((bin+1)*binHz)*2);
  103256. if(lo_curve>i)lo_curve=i;
  103257. if(lo_curve<0)lo_curve=0;
  103258. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  103259. for(m=0;m<P_LEVELS;m++){
  103260. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  103261. for(j=0;j<n;j++)brute_buffer[j]=999.;
  103262. for(k=lo_curve;k<=hi_curve;k++){
  103263. int l=0;
  103264. for(j=0;j<EHMER_MAX;j++){
  103265. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  103266. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  103267. if(lo_bin<0)lo_bin=0;
  103268. if(lo_bin>n)lo_bin=n;
  103269. if(lo_bin<l)l=lo_bin;
  103270. if(hi_bin<0)hi_bin=0;
  103271. if(hi_bin>n)hi_bin=n;
  103272. for(;l<hi_bin && l<n;l++)
  103273. if(brute_buffer[l]>workc[k][m][j])
  103274. brute_buffer[l]=workc[k][m][j];
  103275. }
  103276. for(;l<n;l++)
  103277. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103278. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103279. }
  103280. if(i+1<P_BANDS){
  103281. int l=0;
  103282. k=i+1;
  103283. for(j=0;j<EHMER_MAX;j++){
  103284. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103285. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103286. if(lo_bin<0)lo_bin=0;
  103287. if(lo_bin>n)lo_bin=n;
  103288. if(lo_bin<l)l=lo_bin;
  103289. if(hi_bin<0)hi_bin=0;
  103290. if(hi_bin>n)hi_bin=n;
  103291. for(;l<hi_bin && l<n;l++)
  103292. if(brute_buffer[l]>workc[k][m][j])
  103293. brute_buffer[l]=workc[k][m][j];
  103294. }
  103295. for(;l<n;l++)
  103296. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103297. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103298. }
  103299. for(j=0;j<EHMER_MAX;j++){
  103300. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103301. if(bin<0){
  103302. ret[i][m][j+2]=-999.;
  103303. }else{
  103304. if(bin>=n){
  103305. ret[i][m][j+2]=-999.;
  103306. }else{
  103307. ret[i][m][j+2]=brute_buffer[bin];
  103308. }
  103309. }
  103310. }
  103311. for(j=0;j<EHMER_OFFSET;j++)
  103312. if(ret[i][m][j+2]>-200.f)break;
  103313. ret[i][m][0]=j;
  103314. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103315. if(ret[i][m][j+2]>-200.f)
  103316. break;
  103317. ret[i][m][1]=j;
  103318. }
  103319. }
  103320. return(ret);
  103321. }
  103322. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103323. vorbis_info_psy_global *gi,int n,long rate){
  103324. long i,j,lo=-99,hi=1;
  103325. long maxoc;
  103326. memset(p,0,sizeof(*p));
  103327. p->eighth_octave_lines=gi->eighth_octave_lines;
  103328. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103329. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103330. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103331. p->total_octave_lines=maxoc-p->firstoc+1;
  103332. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103333. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103334. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103335. p->vi=vi;
  103336. p->n=n;
  103337. p->rate=rate;
  103338. p->m_val = 1.;
  103339. if(rate < 26000) p->m_val = 0;
  103340. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103341. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103342. for(i=0,j=0;i<MAX_ATH-1;i++){
  103343. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103344. float base=ATH[i];
  103345. if(j<endpos){
  103346. float delta=(ATH[i+1]-base)/(endpos-j);
  103347. for(;j<endpos && j<n;j++){
  103348. p->ath[j]=base+100.;
  103349. base+=delta;
  103350. }
  103351. }
  103352. }
  103353. for(i=0;i<n;i++){
  103354. float bark=toBARK(rate/(2*n)*i);
  103355. for(;lo+vi->noisewindowlomin<i &&
  103356. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103357. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103358. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103359. p->bark[i]=((lo-1)<<16)+(hi-1);
  103360. }
  103361. for(i=0;i<n;i++)
  103362. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103363. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103364. vi->tone_centerboost,vi->tone_decay);
  103365. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103366. for(i=0;i<P_NOISECURVES;i++)
  103367. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103368. for(i=0;i<n;i++){
  103369. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103370. int inthalfoc;
  103371. float del;
  103372. if(halfoc<0)halfoc=0;
  103373. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103374. inthalfoc=(int)halfoc;
  103375. del=halfoc-inthalfoc;
  103376. for(j=0;j<P_NOISECURVES;j++)
  103377. p->noiseoffset[j][i]=
  103378. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  103379. p->vi->noiseoff[j][inthalfoc+1]*del;
  103380. }
  103381. #if 0
  103382. {
  103383. static int ls=0;
  103384. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  103385. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  103386. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  103387. }
  103388. #endif
  103389. }
  103390. void _vp_psy_clear(vorbis_look_psy *p){
  103391. int i,j;
  103392. if(p){
  103393. if(p->ath)_ogg_free(p->ath);
  103394. if(p->octave)_ogg_free(p->octave);
  103395. if(p->bark)_ogg_free(p->bark);
  103396. if(p->tonecurves){
  103397. for(i=0;i<P_BANDS;i++){
  103398. for(j=0;j<P_LEVELS;j++){
  103399. _ogg_free(p->tonecurves[i][j]);
  103400. }
  103401. _ogg_free(p->tonecurves[i]);
  103402. }
  103403. _ogg_free(p->tonecurves);
  103404. }
  103405. if(p->noiseoffset){
  103406. for(i=0;i<P_NOISECURVES;i++){
  103407. _ogg_free(p->noiseoffset[i]);
  103408. }
  103409. _ogg_free(p->noiseoffset);
  103410. }
  103411. memset(p,0,sizeof(*p));
  103412. }
  103413. }
  103414. static void seed_curve(float *seed,
  103415. const float **curves,
  103416. float amp,
  103417. int oc, int n,
  103418. int linesper,float dBoffset){
  103419. int i,post1;
  103420. int seedptr;
  103421. const float *posts,*curve;
  103422. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103423. choice=max(choice,0);
  103424. choice=min(choice,P_LEVELS-1);
  103425. posts=curves[choice];
  103426. curve=posts+2;
  103427. post1=(int)posts[1];
  103428. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103429. for(i=posts[0];i<post1;i++){
  103430. if(seedptr>0){
  103431. float lin=amp+curve[i];
  103432. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103433. }
  103434. seedptr+=linesper;
  103435. if(seedptr>=n)break;
  103436. }
  103437. }
  103438. static void seed_loop(vorbis_look_psy *p,
  103439. const float ***curves,
  103440. const float *f,
  103441. const float *flr,
  103442. float *seed,
  103443. float specmax){
  103444. vorbis_info_psy *vi=p->vi;
  103445. long n=p->n,i;
  103446. float dBoffset=vi->max_curve_dB-specmax;
  103447. for(i=0;i<n;i++){
  103448. float max=f[i];
  103449. long oc=p->octave[i];
  103450. while(i+1<n && p->octave[i+1]==oc){
  103451. i++;
  103452. if(f[i]>max)max=f[i];
  103453. }
  103454. if(max+6.f>flr[i]){
  103455. oc=oc>>p->shiftoc;
  103456. if(oc>=P_BANDS)oc=P_BANDS-1;
  103457. if(oc<0)oc=0;
  103458. seed_curve(seed,
  103459. curves[oc],
  103460. max,
  103461. p->octave[i]-p->firstoc,
  103462. p->total_octave_lines,
  103463. p->eighth_octave_lines,
  103464. dBoffset);
  103465. }
  103466. }
  103467. }
  103468. static void seed_chase(float *seeds, int linesper, long n){
  103469. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103470. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103471. long stack=0;
  103472. long pos=0;
  103473. long i;
  103474. for(i=0;i<n;i++){
  103475. if(stack<2){
  103476. posstack[stack]=i;
  103477. ampstack[stack++]=seeds[i];
  103478. }else{
  103479. while(1){
  103480. if(seeds[i]<ampstack[stack-1]){
  103481. posstack[stack]=i;
  103482. ampstack[stack++]=seeds[i];
  103483. break;
  103484. }else{
  103485. if(i<posstack[stack-1]+linesper){
  103486. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103487. i<posstack[stack-2]+linesper){
  103488. stack--;
  103489. continue;
  103490. }
  103491. }
  103492. posstack[stack]=i;
  103493. ampstack[stack++]=seeds[i];
  103494. break;
  103495. }
  103496. }
  103497. }
  103498. }
  103499. for(i=0;i<stack;i++){
  103500. long endpos;
  103501. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103502. endpos=posstack[i+1];
  103503. }else{
  103504. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103505. discarded in short frames */
  103506. }
  103507. if(endpos>n)endpos=n;
  103508. for(;pos<endpos;pos++)
  103509. seeds[pos]=ampstack[i];
  103510. }
  103511. }
  103512. #include<stdio.h>
  103513. static void max_seeds(vorbis_look_psy *p,
  103514. float *seed,
  103515. float *flr){
  103516. long n=p->total_octave_lines;
  103517. int linesper=p->eighth_octave_lines;
  103518. long linpos=0;
  103519. long pos;
  103520. seed_chase(seed,linesper,n); /* for masking */
  103521. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103522. while(linpos+1<p->n){
  103523. float minV=seed[pos];
  103524. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103525. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103526. while(pos+1<=end){
  103527. pos++;
  103528. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103529. minV=seed[pos];
  103530. }
  103531. end=pos+p->firstoc;
  103532. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103533. if(flr[linpos]<minV)flr[linpos]=minV;
  103534. }
  103535. {
  103536. float minV=seed[p->total_octave_lines-1];
  103537. for(;linpos<p->n;linpos++)
  103538. if(flr[linpos]<minV)flr[linpos]=minV;
  103539. }
  103540. }
  103541. static void bark_noise_hybridmp(int n,const long *b,
  103542. const float *f,
  103543. float *noise,
  103544. const float offset,
  103545. const int fixed){
  103546. float *N=(float*) alloca(n*sizeof(*N));
  103547. float *X=(float*) alloca(n*sizeof(*N));
  103548. float *XX=(float*) alloca(n*sizeof(*N));
  103549. float *Y=(float*) alloca(n*sizeof(*N));
  103550. float *XY=(float*) alloca(n*sizeof(*N));
  103551. float tN, tX, tXX, tY, tXY;
  103552. int i;
  103553. int lo, hi;
  103554. float R, A, B, D;
  103555. float w, x, y;
  103556. tN = tX = tXX = tY = tXY = 0.f;
  103557. y = f[0] + offset;
  103558. if (y < 1.f) y = 1.f;
  103559. w = y * y * .5;
  103560. tN += w;
  103561. tX += w;
  103562. tY += w * y;
  103563. N[0] = tN;
  103564. X[0] = tX;
  103565. XX[0] = tXX;
  103566. Y[0] = tY;
  103567. XY[0] = tXY;
  103568. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103569. y = f[i] + offset;
  103570. if (y < 1.f) y = 1.f;
  103571. w = y * y;
  103572. tN += w;
  103573. tX += w * x;
  103574. tXX += w * x * x;
  103575. tY += w * y;
  103576. tXY += w * x * y;
  103577. N[i] = tN;
  103578. X[i] = tX;
  103579. XX[i] = tXX;
  103580. Y[i] = tY;
  103581. XY[i] = tXY;
  103582. }
  103583. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103584. lo = b[i] >> 16;
  103585. if( lo>=0 ) break;
  103586. hi = b[i] & 0xffff;
  103587. tN = N[hi] + N[-lo];
  103588. tX = X[hi] - X[-lo];
  103589. tXX = XX[hi] + XX[-lo];
  103590. tY = Y[hi] + Y[-lo];
  103591. tXY = XY[hi] - XY[-lo];
  103592. A = tY * tXX - tX * tXY;
  103593. B = tN * tXY - tX * tY;
  103594. D = tN * tXX - tX * tX;
  103595. R = (A + x * B) / D;
  103596. if (R < 0.f)
  103597. R = 0.f;
  103598. noise[i] = R - offset;
  103599. }
  103600. for ( ;; i++, x += 1.f) {
  103601. lo = b[i] >> 16;
  103602. hi = b[i] & 0xffff;
  103603. if(hi>=n)break;
  103604. tN = N[hi] - N[lo];
  103605. tX = X[hi] - X[lo];
  103606. tXX = XX[hi] - XX[lo];
  103607. tY = Y[hi] - Y[lo];
  103608. tXY = XY[hi] - XY[lo];
  103609. A = tY * tXX - tX * tXY;
  103610. B = tN * tXY - tX * tY;
  103611. D = tN * tXX - tX * tX;
  103612. R = (A + x * B) / D;
  103613. if (R < 0.f) R = 0.f;
  103614. noise[i] = R - offset;
  103615. }
  103616. for ( ; i < n; i++, x += 1.f) {
  103617. R = (A + x * B) / D;
  103618. if (R < 0.f) R = 0.f;
  103619. noise[i] = R - offset;
  103620. }
  103621. if (fixed <= 0) return;
  103622. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103623. hi = i + fixed / 2;
  103624. lo = hi - fixed;
  103625. if(lo>=0)break;
  103626. tN = N[hi] + N[-lo];
  103627. tX = X[hi] - X[-lo];
  103628. tXX = XX[hi] + XX[-lo];
  103629. tY = Y[hi] + Y[-lo];
  103630. tXY = XY[hi] - XY[-lo];
  103631. A = tY * tXX - tX * tXY;
  103632. B = tN * tXY - tX * tY;
  103633. D = tN * tXX - tX * tX;
  103634. R = (A + x * B) / D;
  103635. if (R - offset < noise[i]) noise[i] = R - offset;
  103636. }
  103637. for ( ;; i++, x += 1.f) {
  103638. hi = i + fixed / 2;
  103639. lo = hi - fixed;
  103640. if(hi>=n)break;
  103641. tN = N[hi] - N[lo];
  103642. tX = X[hi] - X[lo];
  103643. tXX = XX[hi] - XX[lo];
  103644. tY = Y[hi] - Y[lo];
  103645. tXY = XY[hi] - XY[lo];
  103646. A = tY * tXX - tX * tXY;
  103647. B = tN * tXY - tX * tY;
  103648. D = tN * tXX - tX * tX;
  103649. R = (A + x * B) / D;
  103650. if (R - offset < noise[i]) noise[i] = R - offset;
  103651. }
  103652. for ( ; i < n; i++, x += 1.f) {
  103653. R = (A + x * B) / D;
  103654. if (R - offset < noise[i]) noise[i] = R - offset;
  103655. }
  103656. }
  103657. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103658. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103659. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103660. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103661. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103662. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103663. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103664. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103665. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103666. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103667. 973377.F, 913981.F, 858210.F, 805842.F,
  103668. 756669.F, 710497.F, 667142.F, 626433.F,
  103669. 588208.F, 552316.F, 518613.F, 486967.F,
  103670. 457252.F, 429351.F, 403152.F, 378551.F,
  103671. 355452.F, 333762.F, 313396.F, 294273.F,
  103672. 276316.F, 259455.F, 243623.F, 228757.F,
  103673. 214798.F, 201691.F, 189384.F, 177828.F,
  103674. 166977.F, 156788.F, 147221.F, 138237.F,
  103675. 129802.F, 121881.F, 114444.F, 107461.F,
  103676. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  103677. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  103678. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  103679. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  103680. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  103681. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  103682. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  103683. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  103684. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  103685. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  103686. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  103687. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  103688. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  103689. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  103690. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  103691. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  103692. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  103693. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  103694. 1084.32F, 1018.15F, 956.024F, 897.687F,
  103695. 842.910F, 791.475F, 743.179F, 697.830F,
  103696. 655.249F, 615.265F, 577.722F, 542.469F,
  103697. 509.367F, 478.286F, 449.101F, 421.696F,
  103698. 395.964F, 371.803F, 349.115F, 327.812F,
  103699. 307.809F, 289.026F, 271.390F, 254.830F,
  103700. 239.280F, 224.679F, 210.969F, 198.096F,
  103701. 186.008F, 174.658F, 164.000F, 153.993F,
  103702. 144.596F, 135.773F, 127.488F, 119.708F,
  103703. 112.404F, 105.545F, 99.1046F, 93.0572F,
  103704. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  103705. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  103706. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  103707. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  103708. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  103709. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  103710. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  103711. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  103712. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  103713. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  103714. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  103715. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  103716. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  103717. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  103718. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  103719. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  103720. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  103721. 1.20790F, 1.13419F, 1.06499F, 1.F
  103722. };
  103723. void _vp_remove_floor(vorbis_look_psy *p,
  103724. float *mdct,
  103725. int *codedflr,
  103726. float *residue,
  103727. int sliding_lowpass){
  103728. int i,n=p->n;
  103729. if(sliding_lowpass>n)sliding_lowpass=n;
  103730. for(i=0;i<sliding_lowpass;i++){
  103731. residue[i]=
  103732. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  103733. }
  103734. for(;i<n;i++)
  103735. residue[i]=0.;
  103736. }
  103737. void _vp_noisemask(vorbis_look_psy *p,
  103738. float *logmdct,
  103739. float *logmask){
  103740. int i,n=p->n;
  103741. float *work=(float*) alloca(n*sizeof(*work));
  103742. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  103743. 140.,-1);
  103744. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  103745. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  103746. p->vi->noisewindowfixed);
  103747. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  103748. #if 0
  103749. {
  103750. static int seq=0;
  103751. float work2[n];
  103752. for(i=0;i<n;i++){
  103753. work2[i]=logmask[i]+work[i];
  103754. }
  103755. if(seq&1)
  103756. _analysis_output("median2R",seq/2,work,n,1,0,0);
  103757. else
  103758. _analysis_output("median2L",seq/2,work,n,1,0,0);
  103759. if(seq&1)
  103760. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  103761. else
  103762. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  103763. seq++;
  103764. }
  103765. #endif
  103766. for(i=0;i<n;i++){
  103767. int dB=logmask[i]+.5;
  103768. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  103769. if(dB<0)dB=0;
  103770. logmask[i]= work[i]+p->vi->noisecompand[dB];
  103771. }
  103772. }
  103773. void _vp_tonemask(vorbis_look_psy *p,
  103774. float *logfft,
  103775. float *logmask,
  103776. float global_specmax,
  103777. float local_specmax){
  103778. int i,n=p->n;
  103779. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  103780. float att=local_specmax+p->vi->ath_adjatt;
  103781. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  103782. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  103783. for(i=0;i<n;i++)
  103784. logmask[i]=p->ath[i]+att;
  103785. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  103786. max_seeds(p,seed,logmask);
  103787. }
  103788. void _vp_offset_and_mix(vorbis_look_psy *p,
  103789. float *noise,
  103790. float *tone,
  103791. int offset_select,
  103792. float *logmask,
  103793. float *mdct,
  103794. float *logmdct){
  103795. int i,n=p->n;
  103796. float de, coeffi, cx;/* AoTuV */
  103797. float toneatt=p->vi->tone_masteratt[offset_select];
  103798. cx = p->m_val;
  103799. for(i=0;i<n;i++){
  103800. float val= noise[i]+p->noiseoffset[offset_select][i];
  103801. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  103802. logmask[i]=max(val,tone[i]+toneatt);
  103803. if(offset_select == 1) {
  103804. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  103805. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  103806. if(val > coeffi){
  103807. de = 1.0-((val-coeffi)*0.005*cx);
  103808. if(de < 0) de = 0.0001;
  103809. }else
  103810. de = 1.0-((val-coeffi)*0.0003*cx);
  103811. mdct[i] *= de;
  103812. }
  103813. }
  103814. }
  103815. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  103816. vorbis_info *vi=vd->vi;
  103817. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103818. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103819. int n=ci->blocksizes[vd->W]/2;
  103820. float secs=(float)n/vi->rate;
  103821. amp+=secs*gi->ampmax_att_per_sec;
  103822. if(amp<-9999)amp=-9999;
  103823. return(amp);
  103824. }
  103825. static void couple_lossless(float A, float B,
  103826. float *qA, float *qB){
  103827. int test1=fabs(*qA)>fabs(*qB);
  103828. test1-= fabs(*qA)<fabs(*qB);
  103829. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  103830. if(test1==1){
  103831. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  103832. }else{
  103833. float temp=*qB;
  103834. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  103835. *qA=temp;
  103836. }
  103837. if(*qB>fabs(*qA)*1.9999f){
  103838. *qB= -fabs(*qA)*2.f;
  103839. *qA= -*qA;
  103840. }
  103841. }
  103842. static float hypot_lookup[32]={
  103843. -0.009935, -0.011245, -0.012726, -0.014397,
  103844. -0.016282, -0.018407, -0.020800, -0.023494,
  103845. -0.026522, -0.029923, -0.033737, -0.038010,
  103846. -0.042787, -0.048121, -0.054064, -0.060671,
  103847. -0.068000, -0.076109, -0.085054, -0.094892,
  103848. -0.105675, -0.117451, -0.130260, -0.144134,
  103849. -0.159093, -0.175146, -0.192286, -0.210490,
  103850. -0.229718, -0.249913, -0.271001, -0.292893};
  103851. static void precomputed_couple_point(float premag,
  103852. int floorA,int floorB,
  103853. float *mag, float *ang){
  103854. int test=(floorA>floorB)-1;
  103855. int offset=31-abs(floorA-floorB);
  103856. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  103857. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  103858. *mag=premag*floormag;
  103859. *ang=0.f;
  103860. }
  103861. static float dipole_hypot(float a, float b){
  103862. if(a>0.){
  103863. if(b>0.)return sqrt(a*a+b*b);
  103864. if(a>-b)return sqrt(a*a-b*b);
  103865. return -sqrt(b*b-a*a);
  103866. }
  103867. if(b<0.)return -sqrt(a*a+b*b);
  103868. if(-a>b)return -sqrt(a*a-b*b);
  103869. return sqrt(b*b-a*a);
  103870. }
  103871. static float round_hypot(float a, float b){
  103872. if(a>0.){
  103873. if(b>0.)return sqrt(a*a+b*b);
  103874. if(a>-b)return sqrt(a*a+b*b);
  103875. return -sqrt(b*b+a*a);
  103876. }
  103877. if(b<0.)return -sqrt(a*a+b*b);
  103878. if(-a>b)return -sqrt(a*a+b*b);
  103879. return sqrt(b*b+a*a);
  103880. }
  103881. float **_vp_quantize_couple_memo(vorbis_block *vb,
  103882. vorbis_info_psy_global *g,
  103883. vorbis_look_psy *p,
  103884. vorbis_info_mapping0 *vi,
  103885. float **mdct){
  103886. int i,j,n=p->n;
  103887. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103888. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103889. for(i=0;i<vi->coupling_steps;i++){
  103890. float *mdctM=mdct[vi->coupling_mag[i]];
  103891. float *mdctA=mdct[vi->coupling_ang[i]];
  103892. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103893. for(j=0;j<limit;j++)
  103894. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  103895. for(;j<n;j++)
  103896. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  103897. }
  103898. return(ret);
  103899. }
  103900. static int apsort(const void *a, const void *b){
  103901. float f1=fabs(**(float**)a);
  103902. float f2=fabs(**(float**)b);
  103903. return (f1<f2)-(f1>f2);
  103904. }
  103905. int **_vp_quantize_couple_sort(vorbis_block *vb,
  103906. vorbis_look_psy *p,
  103907. vorbis_info_mapping0 *vi,
  103908. float **mags){
  103909. if(p->vi->normal_point_p){
  103910. int i,j,k,n=p->n;
  103911. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103912. int partition=p->vi->normal_partition;
  103913. float **work=(float**) alloca(sizeof(*work)*partition);
  103914. for(i=0;i<vi->coupling_steps;i++){
  103915. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103916. for(j=0;j<n;j+=partition){
  103917. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  103918. qsort(work,partition,sizeof(*work),apsort);
  103919. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  103920. }
  103921. }
  103922. return(ret);
  103923. }
  103924. return(NULL);
  103925. }
  103926. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  103927. float *magnitudes,int *sortedindex){
  103928. int i,j,n=p->n;
  103929. vorbis_info_psy *vi=p->vi;
  103930. int partition=vi->normal_partition;
  103931. float **work=(float**) alloca(sizeof(*work)*partition);
  103932. int start=vi->normal_start;
  103933. for(j=start;j<n;j+=partition){
  103934. if(j+partition>n)partition=n-j;
  103935. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  103936. qsort(work,partition,sizeof(*work),apsort);
  103937. for(i=0;i<partition;i++){
  103938. sortedindex[i+j-start]=work[i]-magnitudes;
  103939. }
  103940. }
  103941. }
  103942. void _vp_noise_normalize(vorbis_look_psy *p,
  103943. float *in,float *out,int *sortedindex){
  103944. int flag=0,i,j=0,n=p->n;
  103945. vorbis_info_psy *vi=p->vi;
  103946. int partition=vi->normal_partition;
  103947. int start=vi->normal_start;
  103948. if(start>n)start=n;
  103949. if(vi->normal_channel_p){
  103950. for(;j<start;j++)
  103951. out[j]=rint(in[j]);
  103952. for(;j+partition<=n;j+=partition){
  103953. float acc=0.;
  103954. int k;
  103955. for(i=j;i<j+partition;i++)
  103956. acc+=in[i]*in[i];
  103957. for(i=0;i<partition;i++){
  103958. k=sortedindex[i+j-start];
  103959. if(in[k]*in[k]>=.25f){
  103960. out[k]=rint(in[k]);
  103961. acc-=in[k]*in[k];
  103962. flag=1;
  103963. }else{
  103964. if(acc<vi->normal_thresh)break;
  103965. out[k]=unitnorm(in[k]);
  103966. acc-=1.;
  103967. }
  103968. }
  103969. for(;i<partition;i++){
  103970. k=sortedindex[i+j-start];
  103971. out[k]=0.;
  103972. }
  103973. }
  103974. }
  103975. for(;j<n;j++)
  103976. out[j]=rint(in[j]);
  103977. }
  103978. void _vp_couple(int blobno,
  103979. vorbis_info_psy_global *g,
  103980. vorbis_look_psy *p,
  103981. vorbis_info_mapping0 *vi,
  103982. float **res,
  103983. float **mag_memo,
  103984. int **mag_sort,
  103985. int **ifloor,
  103986. int *nonzero,
  103987. int sliding_lowpass){
  103988. int i,j,k,n=p->n;
  103989. for(i=0;i<vi->coupling_steps;i++){
  103990. if(nonzero[vi->coupling_mag[i]] ||
  103991. nonzero[vi->coupling_ang[i]]){
  103992. float *rM=res[vi->coupling_mag[i]];
  103993. float *rA=res[vi->coupling_ang[i]];
  103994. float *qM=rM+n;
  103995. float *qA=rA+n;
  103996. int *floorM=ifloor[vi->coupling_mag[i]];
  103997. int *floorA=ifloor[vi->coupling_ang[i]];
  103998. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  103999. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  104000. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  104001. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  104002. int pointlimit=limit;
  104003. nonzero[vi->coupling_mag[i]]=1;
  104004. nonzero[vi->coupling_ang[i]]=1;
  104005. if(n > 1000)
  104006. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  104007. for(j=0;j<p->n;j+=partition){
  104008. float acc=0.f;
  104009. for(k=0;k<partition;k++){
  104010. int l=k+j;
  104011. if(l<sliding_lowpass){
  104012. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  104013. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  104014. precomputed_couple_point(mag_memo[i][l],
  104015. floorM[l],floorA[l],
  104016. qM+l,qA+l);
  104017. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  104018. }else{
  104019. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  104020. }
  104021. }else{
  104022. qM[l]=0.;
  104023. qA[l]=0.;
  104024. }
  104025. }
  104026. if(p->vi->normal_point_p){
  104027. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  104028. int l=mag_sort[i][j+k];
  104029. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  104030. qM[l]=unitnorm(qM[l]);
  104031. acc-=1.f;
  104032. }
  104033. }
  104034. }
  104035. }
  104036. }
  104037. }
  104038. }
  104039. void hf_reduction(vorbis_info_psy_global *g,
  104040. vorbis_look_psy *p,
  104041. vorbis_info_mapping0 *vi,
  104042. float **mdct){
  104043. int i,j,n=p->n, de=0.3*p->m_val;
  104044. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104045. for(i=0; i<vi->coupling_steps; i++){
  104046. for(j=limit; j<n; j++)
  104047. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  104048. }
  104049. }
  104050. #endif
  104051. /*** End of inlined file: psy.c ***/
  104052. /*** Start of inlined file: registry.c ***/
  104053. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104054. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104055. // tasks..
  104056. #if JUCE_MSVC
  104057. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104058. #endif
  104059. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104060. #if JUCE_USE_OGGVORBIS
  104061. extern vorbis_func_floor floor0_exportbundle;
  104062. extern vorbis_func_floor floor1_exportbundle;
  104063. extern vorbis_func_residue residue0_exportbundle;
  104064. extern vorbis_func_residue residue1_exportbundle;
  104065. extern vorbis_func_residue residue2_exportbundle;
  104066. extern vorbis_func_mapping mapping0_exportbundle;
  104067. vorbis_func_floor *_floor_P[]={
  104068. &floor0_exportbundle,
  104069. &floor1_exportbundle,
  104070. };
  104071. vorbis_func_residue *_residue_P[]={
  104072. &residue0_exportbundle,
  104073. &residue1_exportbundle,
  104074. &residue2_exportbundle,
  104075. };
  104076. vorbis_func_mapping *_mapping_P[]={
  104077. &mapping0_exportbundle,
  104078. };
  104079. #endif
  104080. /*** End of inlined file: registry.c ***/
  104081. /*** Start of inlined file: res0.c ***/
  104082. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104083. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104084. // tasks..
  104085. #if JUCE_MSVC
  104086. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104087. #endif
  104088. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104089. #if JUCE_USE_OGGVORBIS
  104090. #include <stdlib.h>
  104091. #include <string.h>
  104092. #include <math.h>
  104093. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104094. #include <stdio.h>
  104095. #endif
  104096. typedef struct {
  104097. vorbis_info_residue0 *info;
  104098. int parts;
  104099. int stages;
  104100. codebook *fullbooks;
  104101. codebook *phrasebook;
  104102. codebook ***partbooks;
  104103. int partvals;
  104104. int **decodemap;
  104105. long postbits;
  104106. long phrasebits;
  104107. long frames;
  104108. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  104109. int train_seq;
  104110. long *training_data[8][64];
  104111. float training_max[8][64];
  104112. float training_min[8][64];
  104113. float tmin;
  104114. float tmax;
  104115. #endif
  104116. } vorbis_look_residue0;
  104117. void res0_free_info(vorbis_info_residue *i){
  104118. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  104119. if(info){
  104120. memset(info,0,sizeof(*info));
  104121. _ogg_free(info);
  104122. }
  104123. }
  104124. void res0_free_look(vorbis_look_residue *i){
  104125. int j;
  104126. if(i){
  104127. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  104128. #ifdef TRAIN_RES
  104129. {
  104130. int j,k,l;
  104131. for(j=0;j<look->parts;j++){
  104132. for(k=0;k<8;k++)
  104133. if(look->training_data[k][j]){
  104134. char buffer[80];
  104135. FILE *of;
  104136. codebook *statebook=look->partbooks[j][k];
  104137. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  104138. of=fopen(buffer,"a");
  104139. for(l=0;l<statebook->entries;l++)
  104140. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  104141. fclose(of);
  104142. _ogg_free(look->training_data[k][j]);
  104143. look->training_data[k][j]=NULL;
  104144. }
  104145. }
  104146. }
  104147. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  104148. #endif
  104149. for(j=0;j<look->parts;j++)
  104150. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  104151. _ogg_free(look->partbooks);
  104152. for(j=0;j<look->partvals;j++)
  104153. _ogg_free(look->decodemap[j]);
  104154. _ogg_free(look->decodemap);
  104155. memset(look,0,sizeof(*look));
  104156. _ogg_free(look);
  104157. }
  104158. }
  104159. static int icount(unsigned int v){
  104160. int ret=0;
  104161. while(v){
  104162. ret+=v&1;
  104163. v>>=1;
  104164. }
  104165. return(ret);
  104166. }
  104167. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  104168. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104169. int j,acc=0;
  104170. oggpack_write(opb,info->begin,24);
  104171. oggpack_write(opb,info->end,24);
  104172. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  104173. code with a partitioned book */
  104174. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  104175. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  104176. for(j=0;j<info->partitions;j++){
  104177. if(ilog(info->secondstages[j])>3){
  104178. oggpack_write(opb,info->secondstages[j],3);
  104179. oggpack_write(opb,1,1);
  104180. oggpack_write(opb,info->secondstages[j]>>3,5);
  104181. }else
  104182. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  104183. acc+=icount(info->secondstages[j]);
  104184. }
  104185. for(j=0;j<acc;j++)
  104186. oggpack_write(opb,info->booklist[j],8);
  104187. }
  104188. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  104189. int j,acc=0;
  104190. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  104191. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  104192. info->begin=oggpack_read(opb,24);
  104193. info->end=oggpack_read(opb,24);
  104194. info->grouping=oggpack_read(opb,24)+1;
  104195. info->partitions=oggpack_read(opb,6)+1;
  104196. info->groupbook=oggpack_read(opb,8);
  104197. for(j=0;j<info->partitions;j++){
  104198. int cascade=oggpack_read(opb,3);
  104199. if(oggpack_read(opb,1))
  104200. cascade|=(oggpack_read(opb,5)<<3);
  104201. info->secondstages[j]=cascade;
  104202. acc+=icount(cascade);
  104203. }
  104204. for(j=0;j<acc;j++)
  104205. info->booklist[j]=oggpack_read(opb,8);
  104206. if(info->groupbook>=ci->books)goto errout;
  104207. for(j=0;j<acc;j++)
  104208. if(info->booklist[j]>=ci->books)goto errout;
  104209. return(info);
  104210. errout:
  104211. res0_free_info(info);
  104212. return(NULL);
  104213. }
  104214. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  104215. vorbis_info_residue *vr){
  104216. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104217. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  104218. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  104219. int j,k,acc=0;
  104220. int dim;
  104221. int maxstage=0;
  104222. look->info=info;
  104223. look->parts=info->partitions;
  104224. look->fullbooks=ci->fullbooks;
  104225. look->phrasebook=ci->fullbooks+info->groupbook;
  104226. dim=look->phrasebook->dim;
  104227. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  104228. for(j=0;j<look->parts;j++){
  104229. int stages=ilog(info->secondstages[j]);
  104230. if(stages){
  104231. if(stages>maxstage)maxstage=stages;
  104232. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  104233. for(k=0;k<stages;k++)
  104234. if(info->secondstages[j]&(1<<k)){
  104235. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  104236. #ifdef TRAIN_RES
  104237. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  104238. sizeof(***look->training_data));
  104239. #endif
  104240. }
  104241. }
  104242. }
  104243. look->partvals=rint(pow((float)look->parts,(float)dim));
  104244. look->stages=maxstage;
  104245. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  104246. for(j=0;j<look->partvals;j++){
  104247. long val=j;
  104248. long mult=look->partvals/look->parts;
  104249. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  104250. for(k=0;k<dim;k++){
  104251. long deco=val/mult;
  104252. val-=deco*mult;
  104253. mult/=look->parts;
  104254. look->decodemap[j][k]=deco;
  104255. }
  104256. }
  104257. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104258. {
  104259. static int train_seq=0;
  104260. look->train_seq=train_seq++;
  104261. }
  104262. #endif
  104263. return(look);
  104264. }
  104265. static int local_book_besterror(codebook *book,float *a){
  104266. int dim=book->dim,i,k,o;
  104267. int best=0;
  104268. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104269. for(k=0,o=dim;k<dim;++k){
  104270. float val=a[--o];
  104271. i=tt->threshvals>>1;
  104272. if(val<tt->quantthresh[i]){
  104273. if(val<tt->quantthresh[i-1]){
  104274. for(--i;i>0;--i)
  104275. if(val>=tt->quantthresh[i-1])
  104276. break;
  104277. }
  104278. }else{
  104279. for(++i;i<tt->threshvals-1;++i)
  104280. if(val<tt->quantthresh[i])break;
  104281. }
  104282. best=(best*tt->quantvals)+tt->quantmap[i];
  104283. }
  104284. if(book->c->lengthlist[best]<=0){
  104285. const static_codebook *c=book->c;
  104286. int i,j;
  104287. float bestf=0.f;
  104288. float *e=book->valuelist;
  104289. best=-1;
  104290. for(i=0;i<book->entries;i++){
  104291. if(c->lengthlist[i]>0){
  104292. float thisx=0.f;
  104293. for(j=0;j<dim;j++){
  104294. float val=(e[j]-a[j]);
  104295. thisx+=val*val;
  104296. }
  104297. if(best==-1 || thisx<bestf){
  104298. bestf=thisx;
  104299. best=i;
  104300. }
  104301. }
  104302. e+=dim;
  104303. }
  104304. }
  104305. {
  104306. float *ptr=book->valuelist+best*dim;
  104307. for(i=0;i<dim;i++)
  104308. *a++ -= *ptr++;
  104309. }
  104310. return(best);
  104311. }
  104312. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104313. codebook *book,long *acc){
  104314. int i,bits=0;
  104315. int dim=book->dim;
  104316. int step=n/dim;
  104317. for(i=0;i<step;i++){
  104318. int entry=local_book_besterror(book,vec+i*dim);
  104319. #ifdef TRAIN_RES
  104320. acc[entry]++;
  104321. #endif
  104322. bits+=vorbis_book_encode(book,entry,opb);
  104323. }
  104324. return(bits);
  104325. }
  104326. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104327. float **in,int ch){
  104328. long i,j,k;
  104329. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104330. vorbis_info_residue0 *info=look->info;
  104331. int samples_per_partition=info->grouping;
  104332. int possible_partitions=info->partitions;
  104333. int n=info->end-info->begin;
  104334. int partvals=n/samples_per_partition;
  104335. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104336. float scale=100./samples_per_partition;
  104337. for(i=0;i<ch;i++){
  104338. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104339. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104340. }
  104341. for(i=0;i<partvals;i++){
  104342. int offset=i*samples_per_partition+info->begin;
  104343. for(j=0;j<ch;j++){
  104344. float max=0.;
  104345. float ent=0.;
  104346. for(k=0;k<samples_per_partition;k++){
  104347. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104348. ent+=fabs(rint(in[j][offset+k]));
  104349. }
  104350. ent*=scale;
  104351. for(k=0;k<possible_partitions-1;k++)
  104352. if(max<=info->classmetric1[k] &&
  104353. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104354. break;
  104355. partword[j][i]=k;
  104356. }
  104357. }
  104358. #ifdef TRAIN_RESAUX
  104359. {
  104360. FILE *of;
  104361. char buffer[80];
  104362. for(i=0;i<ch;i++){
  104363. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104364. of=fopen(buffer,"a");
  104365. for(j=0;j<partvals;j++)
  104366. fprintf(of,"%ld, ",partword[i][j]);
  104367. fprintf(of,"\n");
  104368. fclose(of);
  104369. }
  104370. }
  104371. #endif
  104372. look->frames++;
  104373. return(partword);
  104374. }
  104375. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  104376. int ch){
  104377. long i,j,k,l;
  104378. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104379. vorbis_info_residue0 *info=look->info;
  104380. int samples_per_partition=info->grouping;
  104381. int possible_partitions=info->partitions;
  104382. int n=info->end-info->begin;
  104383. int partvals=n/samples_per_partition;
  104384. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  104385. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104386. FILE *of;
  104387. char buffer[80];
  104388. #endif
  104389. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  104390. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  104391. for(i=0,l=info->begin/ch;i<partvals;i++){
  104392. float magmax=0.f;
  104393. float angmax=0.f;
  104394. for(j=0;j<samples_per_partition;j+=ch){
  104395. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104396. for(k=1;k<ch;k++)
  104397. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104398. l++;
  104399. }
  104400. for(j=0;j<possible_partitions-1;j++)
  104401. if(magmax<=info->classmetric1[j] &&
  104402. angmax<=info->classmetric2[j])
  104403. break;
  104404. partword[0][i]=j;
  104405. }
  104406. #ifdef TRAIN_RESAUX
  104407. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104408. of=fopen(buffer,"a");
  104409. for(i=0;i<partvals;i++)
  104410. fprintf(of,"%ld, ",partword[0][i]);
  104411. fprintf(of,"\n");
  104412. fclose(of);
  104413. #endif
  104414. look->frames++;
  104415. return(partword);
  104416. }
  104417. static int _01forward(oggpack_buffer *opb,
  104418. vorbis_block *vb,vorbis_look_residue *vl,
  104419. float **in,int ch,
  104420. long **partword,
  104421. int (*encode)(oggpack_buffer *,float *,int,
  104422. codebook *,long *)){
  104423. long i,j,k,s;
  104424. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104425. vorbis_info_residue0 *info=look->info;
  104426. int samples_per_partition=info->grouping;
  104427. int possible_partitions=info->partitions;
  104428. int partitions_per_word=look->phrasebook->dim;
  104429. int n=info->end-info->begin;
  104430. int partvals=n/samples_per_partition;
  104431. long resbits[128];
  104432. long resvals[128];
  104433. #ifdef TRAIN_RES
  104434. for(i=0;i<ch;i++)
  104435. for(j=info->begin;j<info->end;j++){
  104436. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104437. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104438. }
  104439. #endif
  104440. memset(resbits,0,sizeof(resbits));
  104441. memset(resvals,0,sizeof(resvals));
  104442. for(s=0;s<look->stages;s++){
  104443. for(i=0;i<partvals;){
  104444. if(s==0){
  104445. for(j=0;j<ch;j++){
  104446. long val=partword[j][i];
  104447. for(k=1;k<partitions_per_word;k++){
  104448. val*=possible_partitions;
  104449. if(i+k<partvals)
  104450. val+=partword[j][i+k];
  104451. }
  104452. if(val<look->phrasebook->entries)
  104453. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104454. #if 0 /*def TRAIN_RES*/
  104455. else
  104456. fprintf(stderr,"!");
  104457. #endif
  104458. }
  104459. }
  104460. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104461. long offset=i*samples_per_partition+info->begin;
  104462. for(j=0;j<ch;j++){
  104463. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104464. if(info->secondstages[partword[j][i]]&(1<<s)){
  104465. codebook *statebook=look->partbooks[partword[j][i]][s];
  104466. if(statebook){
  104467. int ret;
  104468. long *accumulator=NULL;
  104469. #ifdef TRAIN_RES
  104470. accumulator=look->training_data[s][partword[j][i]];
  104471. {
  104472. int l;
  104473. float *samples=in[j]+offset;
  104474. for(l=0;l<samples_per_partition;l++){
  104475. if(samples[l]<look->training_min[s][partword[j][i]])
  104476. look->training_min[s][partword[j][i]]=samples[l];
  104477. if(samples[l]>look->training_max[s][partword[j][i]])
  104478. look->training_max[s][partword[j][i]]=samples[l];
  104479. }
  104480. }
  104481. #endif
  104482. ret=encode(opb,in[j]+offset,samples_per_partition,
  104483. statebook,accumulator);
  104484. look->postbits+=ret;
  104485. resbits[partword[j][i]]+=ret;
  104486. }
  104487. }
  104488. }
  104489. }
  104490. }
  104491. }
  104492. return(0);
  104493. }
  104494. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104495. float **in,int ch,
  104496. long (*decodepart)(codebook *, float *,
  104497. oggpack_buffer *,int)){
  104498. long i,j,k,l,s;
  104499. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104500. vorbis_info_residue0 *info=look->info;
  104501. int samples_per_partition=info->grouping;
  104502. int partitions_per_word=look->phrasebook->dim;
  104503. int n=info->end-info->begin;
  104504. int partvals=n/samples_per_partition;
  104505. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104506. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104507. for(j=0;j<ch;j++)
  104508. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104509. for(s=0;s<look->stages;s++){
  104510. for(i=0,l=0;i<partvals;l++){
  104511. if(s==0){
  104512. for(j=0;j<ch;j++){
  104513. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104514. if(temp==-1)goto eopbreak;
  104515. partword[j][l]=look->decodemap[temp];
  104516. if(partword[j][l]==NULL)goto errout;
  104517. }
  104518. }
  104519. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104520. for(j=0;j<ch;j++){
  104521. long offset=info->begin+i*samples_per_partition;
  104522. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104523. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104524. if(stagebook){
  104525. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104526. samples_per_partition)==-1)goto eopbreak;
  104527. }
  104528. }
  104529. }
  104530. }
  104531. }
  104532. errout:
  104533. eopbreak:
  104534. return(0);
  104535. }
  104536. #if 0
  104537. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104538. float **in,int *nonzero,int ch){
  104539. int i,used=0;
  104540. for(i=0;i<ch;i++)
  104541. if(nonzero[i])
  104542. in[used++]=in[i];
  104543. if(used)
  104544. return(_01class(vb,vl,in,used));
  104545. else
  104546. return(0);
  104547. }
  104548. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104549. float **in,float **out,int *nonzero,int ch,
  104550. long **partword){
  104551. int i,j,used=0,n=vb->pcmend/2;
  104552. for(i=0;i<ch;i++)
  104553. if(nonzero[i]){
  104554. if(out)
  104555. for(j=0;j<n;j++)
  104556. out[i][j]+=in[i][j];
  104557. in[used++]=in[i];
  104558. }
  104559. if(used){
  104560. int ret=_01forward(vb,vl,in,used,partword,
  104561. _interleaved_encodepart);
  104562. if(out){
  104563. used=0;
  104564. for(i=0;i<ch;i++)
  104565. if(nonzero[i]){
  104566. for(j=0;j<n;j++)
  104567. out[i][j]-=in[used][j];
  104568. used++;
  104569. }
  104570. }
  104571. return(ret);
  104572. }else{
  104573. return(0);
  104574. }
  104575. }
  104576. #endif
  104577. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104578. float **in,int *nonzero,int ch){
  104579. int i,used=0;
  104580. for(i=0;i<ch;i++)
  104581. if(nonzero[i])
  104582. in[used++]=in[i];
  104583. if(used)
  104584. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104585. else
  104586. return(0);
  104587. }
  104588. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104589. float **in,float **out,int *nonzero,int ch,
  104590. long **partword){
  104591. int i,j,used=0,n=vb->pcmend/2;
  104592. for(i=0;i<ch;i++)
  104593. if(nonzero[i]){
  104594. if(out)
  104595. for(j=0;j<n;j++)
  104596. out[i][j]+=in[i][j];
  104597. in[used++]=in[i];
  104598. }
  104599. if(used){
  104600. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104601. if(out){
  104602. used=0;
  104603. for(i=0;i<ch;i++)
  104604. if(nonzero[i]){
  104605. for(j=0;j<n;j++)
  104606. out[i][j]-=in[used][j];
  104607. used++;
  104608. }
  104609. }
  104610. return(ret);
  104611. }else{
  104612. return(0);
  104613. }
  104614. }
  104615. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104616. float **in,int *nonzero,int ch){
  104617. int i,used=0;
  104618. for(i=0;i<ch;i++)
  104619. if(nonzero[i])
  104620. in[used++]=in[i];
  104621. if(used)
  104622. return(_01class(vb,vl,in,used));
  104623. else
  104624. return(0);
  104625. }
  104626. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104627. float **in,int *nonzero,int ch){
  104628. int i,used=0;
  104629. for(i=0;i<ch;i++)
  104630. if(nonzero[i])
  104631. in[used++]=in[i];
  104632. if(used)
  104633. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104634. else
  104635. return(0);
  104636. }
  104637. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  104638. float **in,int *nonzero,int ch){
  104639. int i,used=0;
  104640. for(i=0;i<ch;i++)
  104641. if(nonzero[i])used++;
  104642. if(used)
  104643. return(_2class(vb,vl,in,ch));
  104644. else
  104645. return(0);
  104646. }
  104647. int res2_forward(oggpack_buffer *opb,
  104648. vorbis_block *vb,vorbis_look_residue *vl,
  104649. float **in,float **out,int *nonzero,int ch,
  104650. long **partword){
  104651. long i,j,k,n=vb->pcmend/2,used=0;
  104652. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104653. for(i=0;i<ch;i++){
  104654. float *pcm=in[i];
  104655. if(nonzero[i])used++;
  104656. for(j=0,k=i;j<n;j++,k+=ch)
  104657. work[k]=pcm[j];
  104658. }
  104659. if(used){
  104660. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104661. if(out){
  104662. for(i=0;i<ch;i++){
  104663. float *pcm=in[i];
  104664. float *sofar=out[i];
  104665. for(j=0,k=i;j<n;j++,k+=ch)
  104666. sofar[j]+=pcm[j]-work[k];
  104667. }
  104668. }
  104669. return(ret);
  104670. }else{
  104671. return(0);
  104672. }
  104673. }
  104674. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104675. float **in,int *nonzero,int ch){
  104676. long i,k,l,s;
  104677. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104678. vorbis_info_residue0 *info=look->info;
  104679. int samples_per_partition=info->grouping;
  104680. int partitions_per_word=look->phrasebook->dim;
  104681. int n=info->end-info->begin;
  104682. int partvals=n/samples_per_partition;
  104683. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104684. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  104685. for(i=0;i<ch;i++)if(nonzero[i])break;
  104686. if(i==ch)return(0); /* no nonzero vectors */
  104687. for(s=0;s<look->stages;s++){
  104688. for(i=0,l=0;i<partvals;l++){
  104689. if(s==0){
  104690. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104691. if(temp==-1)goto eopbreak;
  104692. partword[l]=look->decodemap[temp];
  104693. if(partword[l]==NULL)goto errout;
  104694. }
  104695. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104696. if(info->secondstages[partword[l][k]]&(1<<s)){
  104697. codebook *stagebook=look->partbooks[partword[l][k]][s];
  104698. if(stagebook){
  104699. if(vorbis_book_decodevv_add(stagebook,in,
  104700. i*samples_per_partition+info->begin,ch,
  104701. &vb->opb,samples_per_partition)==-1)
  104702. goto eopbreak;
  104703. }
  104704. }
  104705. }
  104706. }
  104707. errout:
  104708. eopbreak:
  104709. return(0);
  104710. }
  104711. vorbis_func_residue residue0_exportbundle={
  104712. NULL,
  104713. &res0_unpack,
  104714. &res0_look,
  104715. &res0_free_info,
  104716. &res0_free_look,
  104717. NULL,
  104718. NULL,
  104719. &res0_inverse
  104720. };
  104721. vorbis_func_residue residue1_exportbundle={
  104722. &res0_pack,
  104723. &res0_unpack,
  104724. &res0_look,
  104725. &res0_free_info,
  104726. &res0_free_look,
  104727. &res1_class,
  104728. &res1_forward,
  104729. &res1_inverse
  104730. };
  104731. vorbis_func_residue residue2_exportbundle={
  104732. &res0_pack,
  104733. &res0_unpack,
  104734. &res0_look,
  104735. &res0_free_info,
  104736. &res0_free_look,
  104737. &res2_class,
  104738. &res2_forward,
  104739. &res2_inverse
  104740. };
  104741. #endif
  104742. /*** End of inlined file: res0.c ***/
  104743. /*** Start of inlined file: sharedbook.c ***/
  104744. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104745. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104746. // tasks..
  104747. #if JUCE_MSVC
  104748. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104749. #endif
  104750. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104751. #if JUCE_USE_OGGVORBIS
  104752. #include <stdlib.h>
  104753. #include <math.h>
  104754. #include <string.h>
  104755. int _ilog(unsigned int v){
  104756. int ret=0;
  104757. while(v){
  104758. ret++;
  104759. v>>=1;
  104760. }
  104761. return(ret);
  104762. }
  104763. #define VQ_FEXP 10
  104764. #define VQ_FMAN 21
  104765. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  104766. long _float32_pack(float val){
  104767. int sign=0;
  104768. long exp;
  104769. long mant;
  104770. if(val<0){
  104771. sign=0x80000000;
  104772. val= -val;
  104773. }
  104774. exp= floor(log(val)/log(2.f));
  104775. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  104776. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  104777. return(sign|exp|mant);
  104778. }
  104779. float _float32_unpack(long val){
  104780. double mant=val&0x1fffff;
  104781. int sign=val&0x80000000;
  104782. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  104783. if(sign)mant= -mant;
  104784. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  104785. }
  104786. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  104787. long i,j,count=0;
  104788. ogg_uint32_t marker[33];
  104789. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  104790. memset(marker,0,sizeof(marker));
  104791. for(i=0;i<n;i++){
  104792. long length=l[i];
  104793. if(length>0){
  104794. ogg_uint32_t entry=marker[length];
  104795. if(length<32 && (entry>>length)){
  104796. _ogg_free(r);
  104797. return(NULL);
  104798. }
  104799. r[count++]=entry;
  104800. {
  104801. for(j=length;j>0;j--){
  104802. if(marker[j]&1){
  104803. if(j==1)
  104804. marker[1]++;
  104805. else
  104806. marker[j]=marker[j-1]<<1;
  104807. break; /* invariant says next upper marker would already
  104808. have been moved if it was on the same path */
  104809. }
  104810. marker[j]++;
  104811. }
  104812. }
  104813. for(j=length+1;j<33;j++)
  104814. if((marker[j]>>1) == entry){
  104815. entry=marker[j];
  104816. marker[j]=marker[j-1]<<1;
  104817. }else
  104818. break;
  104819. }else
  104820. if(sparsecount==0)count++;
  104821. }
  104822. for(i=0,count=0;i<n;i++){
  104823. ogg_uint32_t temp=0;
  104824. for(j=0;j<l[i];j++){
  104825. temp<<=1;
  104826. temp|=(r[count]>>j)&1;
  104827. }
  104828. if(sparsecount){
  104829. if(l[i])
  104830. r[count++]=temp;
  104831. }else
  104832. r[count++]=temp;
  104833. }
  104834. return(r);
  104835. }
  104836. long _book_maptype1_quantvals(const static_codebook *b){
  104837. long vals=floor(pow((float)b->entries,1.f/b->dim));
  104838. while(1){
  104839. long acc=1;
  104840. long acc1=1;
  104841. int i;
  104842. for(i=0;i<b->dim;i++){
  104843. acc*=vals;
  104844. acc1*=vals+1;
  104845. }
  104846. if(acc<=b->entries && acc1>b->entries){
  104847. return(vals);
  104848. }else{
  104849. if(acc>b->entries){
  104850. vals--;
  104851. }else{
  104852. vals++;
  104853. }
  104854. }
  104855. }
  104856. }
  104857. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  104858. long j,k,count=0;
  104859. if(b->maptype==1 || b->maptype==2){
  104860. int quantvals;
  104861. float mindel=_float32_unpack(b->q_min);
  104862. float delta=_float32_unpack(b->q_delta);
  104863. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  104864. switch(b->maptype){
  104865. case 1:
  104866. quantvals=_book_maptype1_quantvals(b);
  104867. for(j=0;j<b->entries;j++){
  104868. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104869. float last=0.f;
  104870. int indexdiv=1;
  104871. for(k=0;k<b->dim;k++){
  104872. int index= (j/indexdiv)%quantvals;
  104873. float val=b->quantlist[index];
  104874. val=fabs(val)*delta+mindel+last;
  104875. if(b->q_sequencep)last=val;
  104876. if(sparsemap)
  104877. r[sparsemap[count]*b->dim+k]=val;
  104878. else
  104879. r[count*b->dim+k]=val;
  104880. indexdiv*=quantvals;
  104881. }
  104882. count++;
  104883. }
  104884. }
  104885. break;
  104886. case 2:
  104887. for(j=0;j<b->entries;j++){
  104888. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104889. float last=0.f;
  104890. for(k=0;k<b->dim;k++){
  104891. float val=b->quantlist[j*b->dim+k];
  104892. val=fabs(val)*delta+mindel+last;
  104893. if(b->q_sequencep)last=val;
  104894. if(sparsemap)
  104895. r[sparsemap[count]*b->dim+k]=val;
  104896. else
  104897. r[count*b->dim+k]=val;
  104898. }
  104899. count++;
  104900. }
  104901. }
  104902. break;
  104903. }
  104904. return(r);
  104905. }
  104906. return(NULL);
  104907. }
  104908. void vorbis_staticbook_clear(static_codebook *b){
  104909. if(b->allocedp){
  104910. if(b->quantlist)_ogg_free(b->quantlist);
  104911. if(b->lengthlist)_ogg_free(b->lengthlist);
  104912. if(b->nearest_tree){
  104913. _ogg_free(b->nearest_tree->ptr0);
  104914. _ogg_free(b->nearest_tree->ptr1);
  104915. _ogg_free(b->nearest_tree->p);
  104916. _ogg_free(b->nearest_tree->q);
  104917. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  104918. _ogg_free(b->nearest_tree);
  104919. }
  104920. if(b->thresh_tree){
  104921. _ogg_free(b->thresh_tree->quantthresh);
  104922. _ogg_free(b->thresh_tree->quantmap);
  104923. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  104924. _ogg_free(b->thresh_tree);
  104925. }
  104926. memset(b,0,sizeof(*b));
  104927. }
  104928. }
  104929. void vorbis_staticbook_destroy(static_codebook *b){
  104930. if(b->allocedp){
  104931. vorbis_staticbook_clear(b);
  104932. _ogg_free(b);
  104933. }
  104934. }
  104935. void vorbis_book_clear(codebook *b){
  104936. if(b->valuelist)_ogg_free(b->valuelist);
  104937. if(b->codelist)_ogg_free(b->codelist);
  104938. if(b->dec_index)_ogg_free(b->dec_index);
  104939. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  104940. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  104941. memset(b,0,sizeof(*b));
  104942. }
  104943. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  104944. memset(c,0,sizeof(*c));
  104945. c->c=s;
  104946. c->entries=s->entries;
  104947. c->used_entries=s->entries;
  104948. c->dim=s->dim;
  104949. c->codelist=_make_words(s->lengthlist,s->entries,0);
  104950. c->valuelist=_book_unquantize(s,s->entries,NULL);
  104951. return(0);
  104952. }
  104953. static int sort32a(const void *a,const void *b){
  104954. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  104955. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  104956. }
  104957. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  104958. int i,j,n=0,tabn;
  104959. int *sortindex;
  104960. memset(c,0,sizeof(*c));
  104961. for(i=0;i<s->entries;i++)
  104962. if(s->lengthlist[i]>0)
  104963. n++;
  104964. c->entries=s->entries;
  104965. c->used_entries=n;
  104966. c->dim=s->dim;
  104967. {
  104968. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  104969. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  104970. if(codes==NULL)goto err_out;
  104971. for(i=0;i<n;i++){
  104972. codes[i]=ogg_bitreverse(codes[i]);
  104973. codep[i]=codes+i;
  104974. }
  104975. qsort(codep,n,sizeof(*codep),sort32a);
  104976. sortindex=(int*)alloca(n*sizeof(*sortindex));
  104977. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  104978. for(i=0;i<n;i++){
  104979. int position=codep[i]-codes;
  104980. sortindex[position]=i;
  104981. }
  104982. for(i=0;i<n;i++)
  104983. c->codelist[sortindex[i]]=codes[i];
  104984. _ogg_free(codes);
  104985. }
  104986. c->valuelist=_book_unquantize(s,n,sortindex);
  104987. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  104988. for(n=0,i=0;i<s->entries;i++)
  104989. if(s->lengthlist[i]>0)
  104990. c->dec_index[sortindex[n++]]=i;
  104991. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  104992. for(n=0,i=0;i<s->entries;i++)
  104993. if(s->lengthlist[i]>0)
  104994. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  104995. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  104996. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  104997. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  104998. tabn=1<<c->dec_firsttablen;
  104999. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  105000. c->dec_maxlength=0;
  105001. for(i=0;i<n;i++){
  105002. if(c->dec_maxlength<c->dec_codelengths[i])
  105003. c->dec_maxlength=c->dec_codelengths[i];
  105004. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  105005. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  105006. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  105007. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  105008. }
  105009. }
  105010. {
  105011. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  105012. long lo=0,hi=0;
  105013. for(i=0;i<tabn;i++){
  105014. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  105015. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  105016. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  105017. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  105018. {
  105019. unsigned long loval=lo;
  105020. unsigned long hival=n-hi;
  105021. if(loval>0x7fff)loval=0x7fff;
  105022. if(hival>0x7fff)hival=0x7fff;
  105023. c->dec_firsttable[ogg_bitreverse(word)]=
  105024. 0x80000000UL | (loval<<15) | hival;
  105025. }
  105026. }
  105027. }
  105028. }
  105029. return(0);
  105030. err_out:
  105031. vorbis_book_clear(c);
  105032. return(-1);
  105033. }
  105034. static float _dist(int el,float *ref, float *b,int step){
  105035. int i;
  105036. float acc=0.f;
  105037. for(i=0;i<el;i++){
  105038. float val=(ref[i]-b[i*step]);
  105039. acc+=val*val;
  105040. }
  105041. return(acc);
  105042. }
  105043. int _best(codebook *book, float *a, int step){
  105044. encode_aux_threshmatch *tt=book->c->thresh_tree;
  105045. #if 0
  105046. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  105047. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  105048. #endif
  105049. int dim=book->dim;
  105050. int k,o;
  105051. if(tt){
  105052. int index=0,i;
  105053. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105054. i=tt->threshvals>>1;
  105055. if(a[o]<tt->quantthresh[i]){
  105056. for(;i>0;i--)
  105057. if(a[o]>=tt->quantthresh[i-1])
  105058. break;
  105059. }else{
  105060. for(i++;i<tt->threshvals-1;i++)
  105061. if(a[o]<tt->quantthresh[i])break;
  105062. }
  105063. index=(index*tt->quantvals)+tt->quantmap[i];
  105064. }
  105065. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  105066. use a decision tree after all
  105067. and fall through*/
  105068. return(index);
  105069. }
  105070. #if 0
  105071. if(pt){
  105072. const static_codebook *c=book->c;
  105073. int i,besti=-1;
  105074. float best=0.f;
  105075. int entry=0;
  105076. if(c->q_sequencep){
  105077. int pv;
  105078. long mul=1;
  105079. float qlast=0;
  105080. for(k=0,o=0;k<dim;k++,o+=step){
  105081. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  105082. if(pv<0 || pv>=pt->mapentries)break;
  105083. entry+=pt->pigeonmap[pv]*mul;
  105084. mul*=pt->quantvals;
  105085. qlast+=pv*pt->del+pt->min;
  105086. }
  105087. }else{
  105088. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105089. int pv=(int)((a[o]-pt->min)/pt->del);
  105090. if(pv<0 || pv>=pt->mapentries)break;
  105091. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  105092. }
  105093. }
  105094. if(k==dim && pt->fitlength[entry]){
  105095. long *list=pt->fitlist+pt->fitmap[entry];
  105096. for(i=0;i<pt->fitlength[entry];i++){
  105097. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  105098. if(besti==-1 || this<best){
  105099. best=this;
  105100. besti=list[i];
  105101. }
  105102. }
  105103. return(besti);
  105104. }
  105105. }
  105106. if(nt){
  105107. while(1){
  105108. float c=0.f;
  105109. float *p=book->valuelist+nt->p[ptr];
  105110. float *q=book->valuelist+nt->q[ptr];
  105111. for(k=0,o=0;k<dim;k++,o+=step)
  105112. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  105113. if(c>0.f) /* in A */
  105114. ptr= -nt->ptr0[ptr];
  105115. else /* in B */
  105116. ptr= -nt->ptr1[ptr];
  105117. if(ptr<=0)break;
  105118. }
  105119. return(-ptr);
  105120. }
  105121. #endif
  105122. {
  105123. const static_codebook *c=book->c;
  105124. int i,besti=-1;
  105125. float best=0.f;
  105126. float *e=book->valuelist;
  105127. for(i=0;i<book->entries;i++){
  105128. if(c->lengthlist[i]>0){
  105129. float thisx=_dist(dim,e,a,step);
  105130. if(besti==-1 || thisx<best){
  105131. best=thisx;
  105132. besti=i;
  105133. }
  105134. }
  105135. e+=dim;
  105136. }
  105137. return(besti);
  105138. }
  105139. }
  105140. long vorbis_book_codeword(codebook *book,int entry){
  105141. if(book->c) /* only use with encode; decode optimizations are
  105142. allowed to break this */
  105143. return book->codelist[entry];
  105144. return -1;
  105145. }
  105146. long vorbis_book_codelen(codebook *book,int entry){
  105147. if(book->c) /* only use with encode; decode optimizations are
  105148. allowed to break this */
  105149. return book->c->lengthlist[entry];
  105150. return -1;
  105151. }
  105152. #ifdef _V_SELFTEST
  105153. #include <stdio.h>
  105154. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  105155. static long partial_quantlist1[]={0,7,2};
  105156. static_codebook test1={
  105157. 4,16,
  105158. NULL,
  105159. 0,
  105160. 0,0,0,0,
  105161. NULL,
  105162. NULL,NULL
  105163. };
  105164. static float *test1_result=NULL;
  105165. static_codebook test2={
  105166. 4,3,
  105167. NULL,
  105168. 2,
  105169. -533200896,1611661312,4,0,
  105170. full_quantlist1,
  105171. NULL,NULL
  105172. };
  105173. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  105174. static_codebook test3={
  105175. 4,3,
  105176. NULL,
  105177. 2,
  105178. -533200896,1611661312,4,1,
  105179. full_quantlist1,
  105180. NULL,NULL
  105181. };
  105182. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  105183. static_codebook test4={
  105184. 3,27,
  105185. NULL,
  105186. 1,
  105187. -533200896,1611661312,4,0,
  105188. partial_quantlist1,
  105189. NULL,NULL
  105190. };
  105191. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  105192. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  105193. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  105194. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  105195. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  105196. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  105197. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  105198. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  105199. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  105200. static_codebook test5={
  105201. 3,27,
  105202. NULL,
  105203. 1,
  105204. -533200896,1611661312,4,1,
  105205. partial_quantlist1,
  105206. NULL,NULL
  105207. };
  105208. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  105209. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  105210. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  105211. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  105212. -3, 1, 5, 4, 8,12, -1, 3, 7,
  105213. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  105214. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  105215. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  105216. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  105217. void run_test(static_codebook *b,float *comp){
  105218. float *out=_book_unquantize(b,b->entries,NULL);
  105219. int i;
  105220. if(comp){
  105221. if(!out){
  105222. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  105223. exit(1);
  105224. }
  105225. for(i=0;i<b->entries*b->dim;i++)
  105226. if(fabs(out[i]-comp[i])>.0001){
  105227. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  105228. "position %d, %g != %g\n",i,out[i],comp[i]);
  105229. exit(1);
  105230. }
  105231. }else{
  105232. if(out){
  105233. fprintf(stderr,"_book_unquantize returned a value array: \n"
  105234. " correct result should have been NULL\n");
  105235. exit(1);
  105236. }
  105237. }
  105238. }
  105239. int main(){
  105240. fprintf(stderr,"Dequant test 1... ");
  105241. run_test(&test1,test1_result);
  105242. fprintf(stderr,"OK\nDequant test 2... ");
  105243. run_test(&test2,test2_result);
  105244. fprintf(stderr,"OK\nDequant test 3... ");
  105245. run_test(&test3,test3_result);
  105246. fprintf(stderr,"OK\nDequant test 4... ");
  105247. run_test(&test4,test4_result);
  105248. fprintf(stderr,"OK\nDequant test 5... ");
  105249. run_test(&test5,test5_result);
  105250. fprintf(stderr,"OK\n\n");
  105251. return(0);
  105252. }
  105253. #endif
  105254. #endif
  105255. /*** End of inlined file: sharedbook.c ***/
  105256. /*** Start of inlined file: smallft.c ***/
  105257. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105258. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105259. // tasks..
  105260. #if JUCE_MSVC
  105261. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105262. #endif
  105263. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105264. #if JUCE_USE_OGGVORBIS
  105265. #include <stdlib.h>
  105266. #include <string.h>
  105267. #include <math.h>
  105268. static void drfti1(int n, float *wa, int *ifac){
  105269. static int ntryh[4] = { 4,2,3,5 };
  105270. static float tpi = 6.28318530717958648f;
  105271. float arg,argh,argld,fi;
  105272. int ntry=0,i,j=-1;
  105273. int k1, l1, l2, ib;
  105274. int ld, ii, ip, is, nq, nr;
  105275. int ido, ipm, nfm1;
  105276. int nl=n;
  105277. int nf=0;
  105278. L101:
  105279. j++;
  105280. if (j < 4)
  105281. ntry=ntryh[j];
  105282. else
  105283. ntry+=2;
  105284. L104:
  105285. nq=nl/ntry;
  105286. nr=nl-ntry*nq;
  105287. if (nr!=0) goto L101;
  105288. nf++;
  105289. ifac[nf+1]=ntry;
  105290. nl=nq;
  105291. if(ntry!=2)goto L107;
  105292. if(nf==1)goto L107;
  105293. for (i=1;i<nf;i++){
  105294. ib=nf-i+1;
  105295. ifac[ib+1]=ifac[ib];
  105296. }
  105297. ifac[2] = 2;
  105298. L107:
  105299. if(nl!=1)goto L104;
  105300. ifac[0]=n;
  105301. ifac[1]=nf;
  105302. argh=tpi/n;
  105303. is=0;
  105304. nfm1=nf-1;
  105305. l1=1;
  105306. if(nfm1==0)return;
  105307. for (k1=0;k1<nfm1;k1++){
  105308. ip=ifac[k1+2];
  105309. ld=0;
  105310. l2=l1*ip;
  105311. ido=n/l2;
  105312. ipm=ip-1;
  105313. for (j=0;j<ipm;j++){
  105314. ld+=l1;
  105315. i=is;
  105316. argld=(float)ld*argh;
  105317. fi=0.f;
  105318. for (ii=2;ii<ido;ii+=2){
  105319. fi+=1.f;
  105320. arg=fi*argld;
  105321. wa[i++]=cos(arg);
  105322. wa[i++]=sin(arg);
  105323. }
  105324. is+=ido;
  105325. }
  105326. l1=l2;
  105327. }
  105328. }
  105329. static void fdrffti(int n, float *wsave, int *ifac){
  105330. if (n == 1) return;
  105331. drfti1(n, wsave+n, ifac);
  105332. }
  105333. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105334. int i,k;
  105335. float ti2,tr2;
  105336. int t0,t1,t2,t3,t4,t5,t6;
  105337. t1=0;
  105338. t0=(t2=l1*ido);
  105339. t3=ido<<1;
  105340. for(k=0;k<l1;k++){
  105341. ch[t1<<1]=cc[t1]+cc[t2];
  105342. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105343. t1+=ido;
  105344. t2+=ido;
  105345. }
  105346. if(ido<2)return;
  105347. if(ido==2)goto L105;
  105348. t1=0;
  105349. t2=t0;
  105350. for(k=0;k<l1;k++){
  105351. t3=t2;
  105352. t4=(t1<<1)+(ido<<1);
  105353. t5=t1;
  105354. t6=t1+t1;
  105355. for(i=2;i<ido;i+=2){
  105356. t3+=2;
  105357. t4-=2;
  105358. t5+=2;
  105359. t6+=2;
  105360. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105361. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105362. ch[t6]=cc[t5]+ti2;
  105363. ch[t4]=ti2-cc[t5];
  105364. ch[t6-1]=cc[t5-1]+tr2;
  105365. ch[t4-1]=cc[t5-1]-tr2;
  105366. }
  105367. t1+=ido;
  105368. t2+=ido;
  105369. }
  105370. if(ido%2==1)return;
  105371. L105:
  105372. t3=(t2=(t1=ido)-1);
  105373. t2+=t0;
  105374. for(k=0;k<l1;k++){
  105375. ch[t1]=-cc[t2];
  105376. ch[t1-1]=cc[t3];
  105377. t1+=ido<<1;
  105378. t2+=ido;
  105379. t3+=ido;
  105380. }
  105381. }
  105382. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  105383. float *wa2,float *wa3){
  105384. static float hsqt2 = .70710678118654752f;
  105385. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105386. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105387. t0=l1*ido;
  105388. t1=t0;
  105389. t4=t1<<1;
  105390. t2=t1+(t1<<1);
  105391. t3=0;
  105392. for(k=0;k<l1;k++){
  105393. tr1=cc[t1]+cc[t2];
  105394. tr2=cc[t3]+cc[t4];
  105395. ch[t5=t3<<2]=tr1+tr2;
  105396. ch[(ido<<2)+t5-1]=tr2-tr1;
  105397. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105398. ch[t5]=cc[t2]-cc[t1];
  105399. t1+=ido;
  105400. t2+=ido;
  105401. t3+=ido;
  105402. t4+=ido;
  105403. }
  105404. if(ido<2)return;
  105405. if(ido==2)goto L105;
  105406. t1=0;
  105407. for(k=0;k<l1;k++){
  105408. t2=t1;
  105409. t4=t1<<2;
  105410. t5=(t6=ido<<1)+t4;
  105411. for(i=2;i<ido;i+=2){
  105412. t3=(t2+=2);
  105413. t4+=2;
  105414. t5-=2;
  105415. t3+=t0;
  105416. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105417. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105418. t3+=t0;
  105419. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105420. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105421. t3+=t0;
  105422. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105423. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105424. tr1=cr2+cr4;
  105425. tr4=cr4-cr2;
  105426. ti1=ci2+ci4;
  105427. ti4=ci2-ci4;
  105428. ti2=cc[t2]+ci3;
  105429. ti3=cc[t2]-ci3;
  105430. tr2=cc[t2-1]+cr3;
  105431. tr3=cc[t2-1]-cr3;
  105432. ch[t4-1]=tr1+tr2;
  105433. ch[t4]=ti1+ti2;
  105434. ch[t5-1]=tr3-ti4;
  105435. ch[t5]=tr4-ti3;
  105436. ch[t4+t6-1]=ti4+tr3;
  105437. ch[t4+t6]=tr4+ti3;
  105438. ch[t5+t6-1]=tr2-tr1;
  105439. ch[t5+t6]=ti1-ti2;
  105440. }
  105441. t1+=ido;
  105442. }
  105443. if(ido&1)return;
  105444. L105:
  105445. t2=(t1=t0+ido-1)+(t0<<1);
  105446. t3=ido<<2;
  105447. t4=ido;
  105448. t5=ido<<1;
  105449. t6=ido;
  105450. for(k=0;k<l1;k++){
  105451. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105452. tr1=hsqt2*(cc[t1]-cc[t2]);
  105453. ch[t4-1]=tr1+cc[t6-1];
  105454. ch[t4+t5-1]=cc[t6-1]-tr1;
  105455. ch[t4]=ti1-cc[t1+t0];
  105456. ch[t4+t5]=ti1+cc[t1+t0];
  105457. t1+=ido;
  105458. t2+=ido;
  105459. t4+=t3;
  105460. t6+=ido;
  105461. }
  105462. }
  105463. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105464. float *c2,float *ch,float *ch2,float *wa){
  105465. static float tpi=6.283185307179586f;
  105466. int idij,ipph,i,j,k,l,ic,ik,is;
  105467. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105468. float dc2,ai1,ai2,ar1,ar2,ds2;
  105469. int nbd;
  105470. float dcp,arg,dsp,ar1h,ar2h;
  105471. int idp2,ipp2;
  105472. arg=tpi/(float)ip;
  105473. dcp=cos(arg);
  105474. dsp=sin(arg);
  105475. ipph=(ip+1)>>1;
  105476. ipp2=ip;
  105477. idp2=ido;
  105478. nbd=(ido-1)>>1;
  105479. t0=l1*ido;
  105480. t10=ip*ido;
  105481. if(ido==1)goto L119;
  105482. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105483. t1=0;
  105484. for(j=1;j<ip;j++){
  105485. t1+=t0;
  105486. t2=t1;
  105487. for(k=0;k<l1;k++){
  105488. ch[t2]=c1[t2];
  105489. t2+=ido;
  105490. }
  105491. }
  105492. is=-ido;
  105493. t1=0;
  105494. if(nbd>l1){
  105495. for(j=1;j<ip;j++){
  105496. t1+=t0;
  105497. is+=ido;
  105498. t2= -ido+t1;
  105499. for(k=0;k<l1;k++){
  105500. idij=is-1;
  105501. t2+=ido;
  105502. t3=t2;
  105503. for(i=2;i<ido;i+=2){
  105504. idij+=2;
  105505. t3+=2;
  105506. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105507. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105508. }
  105509. }
  105510. }
  105511. }else{
  105512. for(j=1;j<ip;j++){
  105513. is+=ido;
  105514. idij=is-1;
  105515. t1+=t0;
  105516. t2=t1;
  105517. for(i=2;i<ido;i+=2){
  105518. idij+=2;
  105519. t2+=2;
  105520. t3=t2;
  105521. for(k=0;k<l1;k++){
  105522. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105523. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105524. t3+=ido;
  105525. }
  105526. }
  105527. }
  105528. }
  105529. t1=0;
  105530. t2=ipp2*t0;
  105531. if(nbd<l1){
  105532. for(j=1;j<ipph;j++){
  105533. t1+=t0;
  105534. t2-=t0;
  105535. t3=t1;
  105536. t4=t2;
  105537. for(i=2;i<ido;i+=2){
  105538. t3+=2;
  105539. t4+=2;
  105540. t5=t3-ido;
  105541. t6=t4-ido;
  105542. for(k=0;k<l1;k++){
  105543. t5+=ido;
  105544. t6+=ido;
  105545. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105546. c1[t6-1]=ch[t5]-ch[t6];
  105547. c1[t5]=ch[t5]+ch[t6];
  105548. c1[t6]=ch[t6-1]-ch[t5-1];
  105549. }
  105550. }
  105551. }
  105552. }else{
  105553. for(j=1;j<ipph;j++){
  105554. t1+=t0;
  105555. t2-=t0;
  105556. t3=t1;
  105557. t4=t2;
  105558. for(k=0;k<l1;k++){
  105559. t5=t3;
  105560. t6=t4;
  105561. for(i=2;i<ido;i+=2){
  105562. t5+=2;
  105563. t6+=2;
  105564. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105565. c1[t6-1]=ch[t5]-ch[t6];
  105566. c1[t5]=ch[t5]+ch[t6];
  105567. c1[t6]=ch[t6-1]-ch[t5-1];
  105568. }
  105569. t3+=ido;
  105570. t4+=ido;
  105571. }
  105572. }
  105573. }
  105574. L119:
  105575. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105576. t1=0;
  105577. t2=ipp2*idl1;
  105578. for(j=1;j<ipph;j++){
  105579. t1+=t0;
  105580. t2-=t0;
  105581. t3=t1-ido;
  105582. t4=t2-ido;
  105583. for(k=0;k<l1;k++){
  105584. t3+=ido;
  105585. t4+=ido;
  105586. c1[t3]=ch[t3]+ch[t4];
  105587. c1[t4]=ch[t4]-ch[t3];
  105588. }
  105589. }
  105590. ar1=1.f;
  105591. ai1=0.f;
  105592. t1=0;
  105593. t2=ipp2*idl1;
  105594. t3=(ip-1)*idl1;
  105595. for(l=1;l<ipph;l++){
  105596. t1+=idl1;
  105597. t2-=idl1;
  105598. ar1h=dcp*ar1-dsp*ai1;
  105599. ai1=dcp*ai1+dsp*ar1;
  105600. ar1=ar1h;
  105601. t4=t1;
  105602. t5=t2;
  105603. t6=t3;
  105604. t7=idl1;
  105605. for(ik=0;ik<idl1;ik++){
  105606. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105607. ch2[t5++]=ai1*c2[t6++];
  105608. }
  105609. dc2=ar1;
  105610. ds2=ai1;
  105611. ar2=ar1;
  105612. ai2=ai1;
  105613. t4=idl1;
  105614. t5=(ipp2-1)*idl1;
  105615. for(j=2;j<ipph;j++){
  105616. t4+=idl1;
  105617. t5-=idl1;
  105618. ar2h=dc2*ar2-ds2*ai2;
  105619. ai2=dc2*ai2+ds2*ar2;
  105620. ar2=ar2h;
  105621. t6=t1;
  105622. t7=t2;
  105623. t8=t4;
  105624. t9=t5;
  105625. for(ik=0;ik<idl1;ik++){
  105626. ch2[t6++]+=ar2*c2[t8++];
  105627. ch2[t7++]+=ai2*c2[t9++];
  105628. }
  105629. }
  105630. }
  105631. t1=0;
  105632. for(j=1;j<ipph;j++){
  105633. t1+=idl1;
  105634. t2=t1;
  105635. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105636. }
  105637. if(ido<l1)goto L132;
  105638. t1=0;
  105639. t2=0;
  105640. for(k=0;k<l1;k++){
  105641. t3=t1;
  105642. t4=t2;
  105643. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105644. t1+=ido;
  105645. t2+=t10;
  105646. }
  105647. goto L135;
  105648. L132:
  105649. for(i=0;i<ido;i++){
  105650. t1=i;
  105651. t2=i;
  105652. for(k=0;k<l1;k++){
  105653. cc[t2]=ch[t1];
  105654. t1+=ido;
  105655. t2+=t10;
  105656. }
  105657. }
  105658. L135:
  105659. t1=0;
  105660. t2=ido<<1;
  105661. t3=0;
  105662. t4=ipp2*t0;
  105663. for(j=1;j<ipph;j++){
  105664. t1+=t2;
  105665. t3+=t0;
  105666. t4-=t0;
  105667. t5=t1;
  105668. t6=t3;
  105669. t7=t4;
  105670. for(k=0;k<l1;k++){
  105671. cc[t5-1]=ch[t6];
  105672. cc[t5]=ch[t7];
  105673. t5+=t10;
  105674. t6+=ido;
  105675. t7+=ido;
  105676. }
  105677. }
  105678. if(ido==1)return;
  105679. if(nbd<l1)goto L141;
  105680. t1=-ido;
  105681. t3=0;
  105682. t4=0;
  105683. t5=ipp2*t0;
  105684. for(j=1;j<ipph;j++){
  105685. t1+=t2;
  105686. t3+=t2;
  105687. t4+=t0;
  105688. t5-=t0;
  105689. t6=t1;
  105690. t7=t3;
  105691. t8=t4;
  105692. t9=t5;
  105693. for(k=0;k<l1;k++){
  105694. for(i=2;i<ido;i+=2){
  105695. ic=idp2-i;
  105696. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  105697. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  105698. cc[i+t7]=ch[i+t8]+ch[i+t9];
  105699. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  105700. }
  105701. t6+=t10;
  105702. t7+=t10;
  105703. t8+=ido;
  105704. t9+=ido;
  105705. }
  105706. }
  105707. return;
  105708. L141:
  105709. t1=-ido;
  105710. t3=0;
  105711. t4=0;
  105712. t5=ipp2*t0;
  105713. for(j=1;j<ipph;j++){
  105714. t1+=t2;
  105715. t3+=t2;
  105716. t4+=t0;
  105717. t5-=t0;
  105718. for(i=2;i<ido;i+=2){
  105719. t6=idp2+t1-i;
  105720. t7=i+t3;
  105721. t8=i+t4;
  105722. t9=i+t5;
  105723. for(k=0;k<l1;k++){
  105724. cc[t7-1]=ch[t8-1]+ch[t9-1];
  105725. cc[t6-1]=ch[t8-1]-ch[t9-1];
  105726. cc[t7]=ch[t8]+ch[t9];
  105727. cc[t6]=ch[t9]-ch[t8];
  105728. t6+=t10;
  105729. t7+=t10;
  105730. t8+=ido;
  105731. t9+=ido;
  105732. }
  105733. }
  105734. }
  105735. }
  105736. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  105737. int i,k1,l1,l2;
  105738. int na,kh,nf;
  105739. int ip,iw,ido,idl1,ix2,ix3;
  105740. nf=ifac[1];
  105741. na=1;
  105742. l2=n;
  105743. iw=n;
  105744. for(k1=0;k1<nf;k1++){
  105745. kh=nf-k1;
  105746. ip=ifac[kh+1];
  105747. l1=l2/ip;
  105748. ido=n/l2;
  105749. idl1=ido*l1;
  105750. iw-=(ip-1)*ido;
  105751. na=1-na;
  105752. if(ip!=4)goto L102;
  105753. ix2=iw+ido;
  105754. ix3=ix2+ido;
  105755. if(na!=0)
  105756. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105757. else
  105758. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105759. goto L110;
  105760. L102:
  105761. if(ip!=2)goto L104;
  105762. if(na!=0)goto L103;
  105763. dradf2(ido,l1,c,ch,wa+iw-1);
  105764. goto L110;
  105765. L103:
  105766. dradf2(ido,l1,ch,c,wa+iw-1);
  105767. goto L110;
  105768. L104:
  105769. if(ido==1)na=1-na;
  105770. if(na!=0)goto L109;
  105771. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  105772. na=1;
  105773. goto L110;
  105774. L109:
  105775. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  105776. na=0;
  105777. L110:
  105778. l2=l1;
  105779. }
  105780. if(na==1)return;
  105781. for(i=0;i<n;i++)c[i]=ch[i];
  105782. }
  105783. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  105784. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105785. float ti2,tr2;
  105786. t0=l1*ido;
  105787. t1=0;
  105788. t2=0;
  105789. t3=(ido<<1)-1;
  105790. for(k=0;k<l1;k++){
  105791. ch[t1]=cc[t2]+cc[t3+t2];
  105792. ch[t1+t0]=cc[t2]-cc[t3+t2];
  105793. t2=(t1+=ido)<<1;
  105794. }
  105795. if(ido<2)return;
  105796. if(ido==2)goto L105;
  105797. t1=0;
  105798. t2=0;
  105799. for(k=0;k<l1;k++){
  105800. t3=t1;
  105801. t5=(t4=t2)+(ido<<1);
  105802. t6=t0+t1;
  105803. for(i=2;i<ido;i+=2){
  105804. t3+=2;
  105805. t4+=2;
  105806. t5-=2;
  105807. t6+=2;
  105808. ch[t3-1]=cc[t4-1]+cc[t5-1];
  105809. tr2=cc[t4-1]-cc[t5-1];
  105810. ch[t3]=cc[t4]-cc[t5];
  105811. ti2=cc[t4]+cc[t5];
  105812. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  105813. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  105814. }
  105815. t2=(t1+=ido)<<1;
  105816. }
  105817. if(ido%2==1)return;
  105818. L105:
  105819. t1=ido-1;
  105820. t2=ido-1;
  105821. for(k=0;k<l1;k++){
  105822. ch[t1]=cc[t2]+cc[t2];
  105823. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  105824. t1+=ido;
  105825. t2+=ido<<1;
  105826. }
  105827. }
  105828. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  105829. float *wa2){
  105830. static float taur = -.5f;
  105831. static float taui = .8660254037844386f;
  105832. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105833. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  105834. t0=l1*ido;
  105835. t1=0;
  105836. t2=t0<<1;
  105837. t3=ido<<1;
  105838. t4=ido+(ido<<1);
  105839. t5=0;
  105840. for(k=0;k<l1;k++){
  105841. tr2=cc[t3-1]+cc[t3-1];
  105842. cr2=cc[t5]+(taur*tr2);
  105843. ch[t1]=cc[t5]+tr2;
  105844. ci3=taui*(cc[t3]+cc[t3]);
  105845. ch[t1+t0]=cr2-ci3;
  105846. ch[t1+t2]=cr2+ci3;
  105847. t1+=ido;
  105848. t3+=t4;
  105849. t5+=t4;
  105850. }
  105851. if(ido==1)return;
  105852. t1=0;
  105853. t3=ido<<1;
  105854. for(k=0;k<l1;k++){
  105855. t7=t1+(t1<<1);
  105856. t6=(t5=t7+t3);
  105857. t8=t1;
  105858. t10=(t9=t1+t0)+t0;
  105859. for(i=2;i<ido;i+=2){
  105860. t5+=2;
  105861. t6-=2;
  105862. t7+=2;
  105863. t8+=2;
  105864. t9+=2;
  105865. t10+=2;
  105866. tr2=cc[t5-1]+cc[t6-1];
  105867. cr2=cc[t7-1]+(taur*tr2);
  105868. ch[t8-1]=cc[t7-1]+tr2;
  105869. ti2=cc[t5]-cc[t6];
  105870. ci2=cc[t7]+(taur*ti2);
  105871. ch[t8]=cc[t7]+ti2;
  105872. cr3=taui*(cc[t5-1]-cc[t6-1]);
  105873. ci3=taui*(cc[t5]+cc[t6]);
  105874. dr2=cr2-ci3;
  105875. dr3=cr2+ci3;
  105876. di2=ci2+cr3;
  105877. di3=ci2-cr3;
  105878. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  105879. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  105880. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  105881. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  105882. }
  105883. t1+=ido;
  105884. }
  105885. }
  105886. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  105887. float *wa2,float *wa3){
  105888. static float sqrt2=1.414213562373095f;
  105889. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  105890. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105891. t0=l1*ido;
  105892. t1=0;
  105893. t2=ido<<2;
  105894. t3=0;
  105895. t6=ido<<1;
  105896. for(k=0;k<l1;k++){
  105897. t4=t3+t6;
  105898. t5=t1;
  105899. tr3=cc[t4-1]+cc[t4-1];
  105900. tr4=cc[t4]+cc[t4];
  105901. tr1=cc[t3]-cc[(t4+=t6)-1];
  105902. tr2=cc[t3]+cc[t4-1];
  105903. ch[t5]=tr2+tr3;
  105904. ch[t5+=t0]=tr1-tr4;
  105905. ch[t5+=t0]=tr2-tr3;
  105906. ch[t5+=t0]=tr1+tr4;
  105907. t1+=ido;
  105908. t3+=t2;
  105909. }
  105910. if(ido<2)return;
  105911. if(ido==2)goto L105;
  105912. t1=0;
  105913. for(k=0;k<l1;k++){
  105914. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  105915. t7=t1;
  105916. for(i=2;i<ido;i+=2){
  105917. t2+=2;
  105918. t3+=2;
  105919. t4-=2;
  105920. t5-=2;
  105921. t7+=2;
  105922. ti1=cc[t2]+cc[t5];
  105923. ti2=cc[t2]-cc[t5];
  105924. ti3=cc[t3]-cc[t4];
  105925. tr4=cc[t3]+cc[t4];
  105926. tr1=cc[t2-1]-cc[t5-1];
  105927. tr2=cc[t2-1]+cc[t5-1];
  105928. ti4=cc[t3-1]-cc[t4-1];
  105929. tr3=cc[t3-1]+cc[t4-1];
  105930. ch[t7-1]=tr2+tr3;
  105931. cr3=tr2-tr3;
  105932. ch[t7]=ti2+ti3;
  105933. ci3=ti2-ti3;
  105934. cr2=tr1-tr4;
  105935. cr4=tr1+tr4;
  105936. ci2=ti1+ti4;
  105937. ci4=ti1-ti4;
  105938. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  105939. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  105940. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  105941. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  105942. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  105943. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  105944. }
  105945. t1+=ido;
  105946. }
  105947. if(ido%2 == 1)return;
  105948. L105:
  105949. t1=ido;
  105950. t2=ido<<2;
  105951. t3=ido-1;
  105952. t4=ido+(ido<<1);
  105953. for(k=0;k<l1;k++){
  105954. t5=t3;
  105955. ti1=cc[t1]+cc[t4];
  105956. ti2=cc[t4]-cc[t1];
  105957. tr1=cc[t1-1]-cc[t4-1];
  105958. tr2=cc[t1-1]+cc[t4-1];
  105959. ch[t5]=tr2+tr2;
  105960. ch[t5+=t0]=sqrt2*(tr1-ti1);
  105961. ch[t5+=t0]=ti2+ti2;
  105962. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  105963. t3+=ido;
  105964. t1+=t2;
  105965. t4+=t2;
  105966. }
  105967. }
  105968. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105969. float *c2,float *ch,float *ch2,float *wa){
  105970. static float tpi=6.283185307179586f;
  105971. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  105972. t11,t12;
  105973. float dc2,ai1,ai2,ar1,ar2,ds2;
  105974. int nbd;
  105975. float dcp,arg,dsp,ar1h,ar2h;
  105976. int ipp2;
  105977. t10=ip*ido;
  105978. t0=l1*ido;
  105979. arg=tpi/(float)ip;
  105980. dcp=cos(arg);
  105981. dsp=sin(arg);
  105982. nbd=(ido-1)>>1;
  105983. ipp2=ip;
  105984. ipph=(ip+1)>>1;
  105985. if(ido<l1)goto L103;
  105986. t1=0;
  105987. t2=0;
  105988. for(k=0;k<l1;k++){
  105989. t3=t1;
  105990. t4=t2;
  105991. for(i=0;i<ido;i++){
  105992. ch[t3]=cc[t4];
  105993. t3++;
  105994. t4++;
  105995. }
  105996. t1+=ido;
  105997. t2+=t10;
  105998. }
  105999. goto L106;
  106000. L103:
  106001. t1=0;
  106002. for(i=0;i<ido;i++){
  106003. t2=t1;
  106004. t3=t1;
  106005. for(k=0;k<l1;k++){
  106006. ch[t2]=cc[t3];
  106007. t2+=ido;
  106008. t3+=t10;
  106009. }
  106010. t1++;
  106011. }
  106012. L106:
  106013. t1=0;
  106014. t2=ipp2*t0;
  106015. t7=(t5=ido<<1);
  106016. for(j=1;j<ipph;j++){
  106017. t1+=t0;
  106018. t2-=t0;
  106019. t3=t1;
  106020. t4=t2;
  106021. t6=t5;
  106022. for(k=0;k<l1;k++){
  106023. ch[t3]=cc[t6-1]+cc[t6-1];
  106024. ch[t4]=cc[t6]+cc[t6];
  106025. t3+=ido;
  106026. t4+=ido;
  106027. t6+=t10;
  106028. }
  106029. t5+=t7;
  106030. }
  106031. if (ido == 1)goto L116;
  106032. if(nbd<l1)goto L112;
  106033. t1=0;
  106034. t2=ipp2*t0;
  106035. t7=0;
  106036. for(j=1;j<ipph;j++){
  106037. t1+=t0;
  106038. t2-=t0;
  106039. t3=t1;
  106040. t4=t2;
  106041. t7+=(ido<<1);
  106042. t8=t7;
  106043. for(k=0;k<l1;k++){
  106044. t5=t3;
  106045. t6=t4;
  106046. t9=t8;
  106047. t11=t8;
  106048. for(i=2;i<ido;i+=2){
  106049. t5+=2;
  106050. t6+=2;
  106051. t9+=2;
  106052. t11-=2;
  106053. ch[t5-1]=cc[t9-1]+cc[t11-1];
  106054. ch[t6-1]=cc[t9-1]-cc[t11-1];
  106055. ch[t5]=cc[t9]-cc[t11];
  106056. ch[t6]=cc[t9]+cc[t11];
  106057. }
  106058. t3+=ido;
  106059. t4+=ido;
  106060. t8+=t10;
  106061. }
  106062. }
  106063. goto L116;
  106064. L112:
  106065. t1=0;
  106066. t2=ipp2*t0;
  106067. t7=0;
  106068. for(j=1;j<ipph;j++){
  106069. t1+=t0;
  106070. t2-=t0;
  106071. t3=t1;
  106072. t4=t2;
  106073. t7+=(ido<<1);
  106074. t8=t7;
  106075. t9=t7;
  106076. for(i=2;i<ido;i+=2){
  106077. t3+=2;
  106078. t4+=2;
  106079. t8+=2;
  106080. t9-=2;
  106081. t5=t3;
  106082. t6=t4;
  106083. t11=t8;
  106084. t12=t9;
  106085. for(k=0;k<l1;k++){
  106086. ch[t5-1]=cc[t11-1]+cc[t12-1];
  106087. ch[t6-1]=cc[t11-1]-cc[t12-1];
  106088. ch[t5]=cc[t11]-cc[t12];
  106089. ch[t6]=cc[t11]+cc[t12];
  106090. t5+=ido;
  106091. t6+=ido;
  106092. t11+=t10;
  106093. t12+=t10;
  106094. }
  106095. }
  106096. }
  106097. L116:
  106098. ar1=1.f;
  106099. ai1=0.f;
  106100. t1=0;
  106101. t9=(t2=ipp2*idl1);
  106102. t3=(ip-1)*idl1;
  106103. for(l=1;l<ipph;l++){
  106104. t1+=idl1;
  106105. t2-=idl1;
  106106. ar1h=dcp*ar1-dsp*ai1;
  106107. ai1=dcp*ai1+dsp*ar1;
  106108. ar1=ar1h;
  106109. t4=t1;
  106110. t5=t2;
  106111. t6=0;
  106112. t7=idl1;
  106113. t8=t3;
  106114. for(ik=0;ik<idl1;ik++){
  106115. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  106116. c2[t5++]=ai1*ch2[t8++];
  106117. }
  106118. dc2=ar1;
  106119. ds2=ai1;
  106120. ar2=ar1;
  106121. ai2=ai1;
  106122. t6=idl1;
  106123. t7=t9-idl1;
  106124. for(j=2;j<ipph;j++){
  106125. t6+=idl1;
  106126. t7-=idl1;
  106127. ar2h=dc2*ar2-ds2*ai2;
  106128. ai2=dc2*ai2+ds2*ar2;
  106129. ar2=ar2h;
  106130. t4=t1;
  106131. t5=t2;
  106132. t11=t6;
  106133. t12=t7;
  106134. for(ik=0;ik<idl1;ik++){
  106135. c2[t4++]+=ar2*ch2[t11++];
  106136. c2[t5++]+=ai2*ch2[t12++];
  106137. }
  106138. }
  106139. }
  106140. t1=0;
  106141. for(j=1;j<ipph;j++){
  106142. t1+=idl1;
  106143. t2=t1;
  106144. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  106145. }
  106146. t1=0;
  106147. t2=ipp2*t0;
  106148. for(j=1;j<ipph;j++){
  106149. t1+=t0;
  106150. t2-=t0;
  106151. t3=t1;
  106152. t4=t2;
  106153. for(k=0;k<l1;k++){
  106154. ch[t3]=c1[t3]-c1[t4];
  106155. ch[t4]=c1[t3]+c1[t4];
  106156. t3+=ido;
  106157. t4+=ido;
  106158. }
  106159. }
  106160. if(ido==1)goto L132;
  106161. if(nbd<l1)goto L128;
  106162. t1=0;
  106163. t2=ipp2*t0;
  106164. for(j=1;j<ipph;j++){
  106165. t1+=t0;
  106166. t2-=t0;
  106167. t3=t1;
  106168. t4=t2;
  106169. for(k=0;k<l1;k++){
  106170. t5=t3;
  106171. t6=t4;
  106172. for(i=2;i<ido;i+=2){
  106173. t5+=2;
  106174. t6+=2;
  106175. ch[t5-1]=c1[t5-1]-c1[t6];
  106176. ch[t6-1]=c1[t5-1]+c1[t6];
  106177. ch[t5]=c1[t5]+c1[t6-1];
  106178. ch[t6]=c1[t5]-c1[t6-1];
  106179. }
  106180. t3+=ido;
  106181. t4+=ido;
  106182. }
  106183. }
  106184. goto L132;
  106185. L128:
  106186. t1=0;
  106187. t2=ipp2*t0;
  106188. for(j=1;j<ipph;j++){
  106189. t1+=t0;
  106190. t2-=t0;
  106191. t3=t1;
  106192. t4=t2;
  106193. for(i=2;i<ido;i+=2){
  106194. t3+=2;
  106195. t4+=2;
  106196. t5=t3;
  106197. t6=t4;
  106198. for(k=0;k<l1;k++){
  106199. ch[t5-1]=c1[t5-1]-c1[t6];
  106200. ch[t6-1]=c1[t5-1]+c1[t6];
  106201. ch[t5]=c1[t5]+c1[t6-1];
  106202. ch[t6]=c1[t5]-c1[t6-1];
  106203. t5+=ido;
  106204. t6+=ido;
  106205. }
  106206. }
  106207. }
  106208. L132:
  106209. if(ido==1)return;
  106210. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106211. t1=0;
  106212. for(j=1;j<ip;j++){
  106213. t2=(t1+=t0);
  106214. for(k=0;k<l1;k++){
  106215. c1[t2]=ch[t2];
  106216. t2+=ido;
  106217. }
  106218. }
  106219. if(nbd>l1)goto L139;
  106220. is= -ido-1;
  106221. t1=0;
  106222. for(j=1;j<ip;j++){
  106223. is+=ido;
  106224. t1+=t0;
  106225. idij=is;
  106226. t2=t1;
  106227. for(i=2;i<ido;i+=2){
  106228. t2+=2;
  106229. idij+=2;
  106230. t3=t2;
  106231. for(k=0;k<l1;k++){
  106232. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106233. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106234. t3+=ido;
  106235. }
  106236. }
  106237. }
  106238. return;
  106239. L139:
  106240. is= -ido-1;
  106241. t1=0;
  106242. for(j=1;j<ip;j++){
  106243. is+=ido;
  106244. t1+=t0;
  106245. t2=t1;
  106246. for(k=0;k<l1;k++){
  106247. idij=is;
  106248. t3=t2;
  106249. for(i=2;i<ido;i+=2){
  106250. idij+=2;
  106251. t3+=2;
  106252. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106253. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106254. }
  106255. t2+=ido;
  106256. }
  106257. }
  106258. }
  106259. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  106260. int i,k1,l1,l2;
  106261. int na;
  106262. int nf,ip,iw,ix2,ix3,ido,idl1;
  106263. nf=ifac[1];
  106264. na=0;
  106265. l1=1;
  106266. iw=1;
  106267. for(k1=0;k1<nf;k1++){
  106268. ip=ifac[k1 + 2];
  106269. l2=ip*l1;
  106270. ido=n/l2;
  106271. idl1=ido*l1;
  106272. if(ip!=4)goto L103;
  106273. ix2=iw+ido;
  106274. ix3=ix2+ido;
  106275. if(na!=0)
  106276. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106277. else
  106278. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106279. na=1-na;
  106280. goto L115;
  106281. L103:
  106282. if(ip!=2)goto L106;
  106283. if(na!=0)
  106284. dradb2(ido,l1,ch,c,wa+iw-1);
  106285. else
  106286. dradb2(ido,l1,c,ch,wa+iw-1);
  106287. na=1-na;
  106288. goto L115;
  106289. L106:
  106290. if(ip!=3)goto L109;
  106291. ix2=iw+ido;
  106292. if(na!=0)
  106293. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106294. else
  106295. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106296. na=1-na;
  106297. goto L115;
  106298. L109:
  106299. if(na!=0)
  106300. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106301. else
  106302. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106303. if(ido==1)na=1-na;
  106304. L115:
  106305. l1=l2;
  106306. iw+=(ip-1)*ido;
  106307. }
  106308. if(na==0)return;
  106309. for(i=0;i<n;i++)c[i]=ch[i];
  106310. }
  106311. void drft_forward(drft_lookup *l,float *data){
  106312. if(l->n==1)return;
  106313. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106314. }
  106315. void drft_backward(drft_lookup *l,float *data){
  106316. if (l->n==1)return;
  106317. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106318. }
  106319. void drft_init(drft_lookup *l,int n){
  106320. l->n=n;
  106321. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106322. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106323. fdrffti(n, l->trigcache, l->splitcache);
  106324. }
  106325. void drft_clear(drft_lookup *l){
  106326. if(l){
  106327. if(l->trigcache)_ogg_free(l->trigcache);
  106328. if(l->splitcache)_ogg_free(l->splitcache);
  106329. memset(l,0,sizeof(*l));
  106330. }
  106331. }
  106332. #endif
  106333. /*** End of inlined file: smallft.c ***/
  106334. /*** Start of inlined file: synthesis.c ***/
  106335. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106336. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106337. // tasks..
  106338. #if JUCE_MSVC
  106339. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106340. #endif
  106341. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106342. #if JUCE_USE_OGGVORBIS
  106343. #include <stdio.h>
  106344. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106345. vorbis_dsp_state *vd=vb->vd;
  106346. private_state *b=(private_state*)vd->backend_state;
  106347. vorbis_info *vi=vd->vi;
  106348. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106349. oggpack_buffer *opb=&vb->opb;
  106350. int type,mode,i;
  106351. _vorbis_block_ripcord(vb);
  106352. oggpack_readinit(opb,op->packet,op->bytes);
  106353. if(oggpack_read(opb,1)!=0){
  106354. return(OV_ENOTAUDIO);
  106355. }
  106356. mode=oggpack_read(opb,b->modebits);
  106357. if(mode==-1)return(OV_EBADPACKET);
  106358. vb->mode=mode;
  106359. vb->W=ci->mode_param[mode]->blockflag;
  106360. if(vb->W){
  106361. vb->lW=oggpack_read(opb,1);
  106362. vb->nW=oggpack_read(opb,1);
  106363. if(vb->nW==-1) return(OV_EBADPACKET);
  106364. }else{
  106365. vb->lW=0;
  106366. vb->nW=0;
  106367. }
  106368. vb->granulepos=op->granulepos;
  106369. vb->sequence=op->packetno;
  106370. vb->eofflag=op->e_o_s;
  106371. vb->pcmend=ci->blocksizes[vb->W];
  106372. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106373. for(i=0;i<vi->channels;i++)
  106374. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106375. type=ci->map_type[ci->mode_param[mode]->mapping];
  106376. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  106377. mapping]));
  106378. }
  106379. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  106380. vorbis_dsp_state *vd=vb->vd;
  106381. private_state *b=(private_state*)vd->backend_state;
  106382. vorbis_info *vi=vd->vi;
  106383. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106384. oggpack_buffer *opb=&vb->opb;
  106385. int mode;
  106386. _vorbis_block_ripcord(vb);
  106387. oggpack_readinit(opb,op->packet,op->bytes);
  106388. if(oggpack_read(opb,1)!=0){
  106389. return(OV_ENOTAUDIO);
  106390. }
  106391. mode=oggpack_read(opb,b->modebits);
  106392. if(mode==-1)return(OV_EBADPACKET);
  106393. vb->mode=mode;
  106394. vb->W=ci->mode_param[mode]->blockflag;
  106395. if(vb->W){
  106396. vb->lW=oggpack_read(opb,1);
  106397. vb->nW=oggpack_read(opb,1);
  106398. if(vb->nW==-1) return(OV_EBADPACKET);
  106399. }else{
  106400. vb->lW=0;
  106401. vb->nW=0;
  106402. }
  106403. vb->granulepos=op->granulepos;
  106404. vb->sequence=op->packetno;
  106405. vb->eofflag=op->e_o_s;
  106406. vb->pcmend=0;
  106407. vb->pcm=NULL;
  106408. return(0);
  106409. }
  106410. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106411. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106412. oggpack_buffer opb;
  106413. int mode;
  106414. oggpack_readinit(&opb,op->packet,op->bytes);
  106415. if(oggpack_read(&opb,1)!=0){
  106416. return(OV_ENOTAUDIO);
  106417. }
  106418. {
  106419. int modebits=0;
  106420. int v=ci->modes;
  106421. while(v>1){
  106422. modebits++;
  106423. v>>=1;
  106424. }
  106425. mode=oggpack_read(&opb,modebits);
  106426. }
  106427. if(mode==-1)return(OV_EBADPACKET);
  106428. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106429. }
  106430. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106431. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106432. if(ci->blocksizes[0]<=64 && flag)return -1;
  106433. ci->halfrate_flag=(flag?1:0);
  106434. return 0;
  106435. }
  106436. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106437. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106438. return ci->halfrate_flag;
  106439. }
  106440. #endif
  106441. /*** End of inlined file: synthesis.c ***/
  106442. /*** Start of inlined file: vorbisenc.c ***/
  106443. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106444. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106445. // tasks..
  106446. #if JUCE_MSVC
  106447. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106448. #endif
  106449. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106450. #if JUCE_USE_OGGVORBIS
  106451. #include <stdlib.h>
  106452. #include <string.h>
  106453. #include <math.h>
  106454. typedef struct {
  106455. static_codebook *books[12][3];
  106456. } static_bookblock;
  106457. typedef struct {
  106458. int res_type;
  106459. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106460. vorbis_info_residue0 *res;
  106461. static_codebook *book_aux;
  106462. static_codebook *book_aux_managed;
  106463. static_bookblock *books_base;
  106464. static_bookblock *books_base_managed;
  106465. } vorbis_residue_template;
  106466. typedef struct {
  106467. vorbis_info_mapping0 *map;
  106468. vorbis_residue_template *res;
  106469. } vorbis_mapping_template;
  106470. typedef struct vp_adjblock{
  106471. int block[P_BANDS];
  106472. } vp_adjblock;
  106473. typedef struct {
  106474. int data[NOISE_COMPAND_LEVELS];
  106475. } compandblock;
  106476. typedef struct {
  106477. int att[P_NOISECURVES];
  106478. float boost;
  106479. float decay;
  106480. } att3;
  106481. typedef struct { int data[P_NOISECURVES]; } adj3;
  106482. typedef struct {
  106483. int pre[PACKETBLOBS];
  106484. int post[PACKETBLOBS];
  106485. float kHz[PACKETBLOBS];
  106486. float lowpasskHz[PACKETBLOBS];
  106487. } adj_stereo;
  106488. typedef struct {
  106489. int lo;
  106490. int hi;
  106491. int fixed;
  106492. } noiseguard;
  106493. typedef struct {
  106494. int data[P_NOISECURVES][17];
  106495. } noise3;
  106496. typedef struct {
  106497. int mappings;
  106498. double *rate_mapping;
  106499. double *quality_mapping;
  106500. int coupling_restriction;
  106501. long samplerate_min_restriction;
  106502. long samplerate_max_restriction;
  106503. int *blocksize_short;
  106504. int *blocksize_long;
  106505. att3 *psy_tone_masteratt;
  106506. int *psy_tone_0dB;
  106507. int *psy_tone_dBsuppress;
  106508. vp_adjblock *psy_tone_adj_impulse;
  106509. vp_adjblock *psy_tone_adj_long;
  106510. vp_adjblock *psy_tone_adj_other;
  106511. noiseguard *psy_noiseguards;
  106512. noise3 *psy_noise_bias_impulse;
  106513. noise3 *psy_noise_bias_padding;
  106514. noise3 *psy_noise_bias_trans;
  106515. noise3 *psy_noise_bias_long;
  106516. int *psy_noise_dBsuppress;
  106517. compandblock *psy_noise_compand;
  106518. double *psy_noise_compand_short_mapping;
  106519. double *psy_noise_compand_long_mapping;
  106520. int *psy_noise_normal_start[2];
  106521. int *psy_noise_normal_partition[2];
  106522. double *psy_noise_normal_thresh;
  106523. int *psy_ath_float;
  106524. int *psy_ath_abs;
  106525. double *psy_lowpass;
  106526. vorbis_info_psy_global *global_params;
  106527. double *global_mapping;
  106528. adj_stereo *stereo_modes;
  106529. static_codebook ***floor_books;
  106530. vorbis_info_floor1 *floor_params;
  106531. int *floor_short_mapping;
  106532. int *floor_long_mapping;
  106533. vorbis_mapping_template *maps;
  106534. } ve_setup_data_template;
  106535. static vorbis_info_mode _mode_template[2]={
  106536. {0,0,0,0},
  106537. {1,0,0,1}
  106538. };
  106539. static vorbis_info_mapping0 _map_nominal[2]={
  106540. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106541. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106542. };
  106543. /*** Start of inlined file: setup_44.h ***/
  106544. /*** Start of inlined file: floor_all.h ***/
  106545. /*** Start of inlined file: floor_books.h ***/
  106546. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106547. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106548. };
  106549. static static_codebook _huff_book_line_256x7_0sub1 = {
  106550. 1, 9,
  106551. _huff_lengthlist_line_256x7_0sub1,
  106552. 0, 0, 0, 0, 0,
  106553. NULL,
  106554. NULL,
  106555. NULL,
  106556. NULL,
  106557. 0
  106558. };
  106559. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106561. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106562. };
  106563. static static_codebook _huff_book_line_256x7_0sub2 = {
  106564. 1, 25,
  106565. _huff_lengthlist_line_256x7_0sub2,
  106566. 0, 0, 0, 0, 0,
  106567. NULL,
  106568. NULL,
  106569. NULL,
  106570. NULL,
  106571. 0
  106572. };
  106573. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106576. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106577. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106578. };
  106579. static static_codebook _huff_book_line_256x7_0sub3 = {
  106580. 1, 64,
  106581. _huff_lengthlist_line_256x7_0sub3,
  106582. 0, 0, 0, 0, 0,
  106583. NULL,
  106584. NULL,
  106585. NULL,
  106586. NULL,
  106587. 0
  106588. };
  106589. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106590. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106591. };
  106592. static static_codebook _huff_book_line_256x7_1sub1 = {
  106593. 1, 9,
  106594. _huff_lengthlist_line_256x7_1sub1,
  106595. 0, 0, 0, 0, 0,
  106596. NULL,
  106597. NULL,
  106598. NULL,
  106599. NULL,
  106600. 0
  106601. };
  106602. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106604. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106605. };
  106606. static static_codebook _huff_book_line_256x7_1sub2 = {
  106607. 1, 25,
  106608. _huff_lengthlist_line_256x7_1sub2,
  106609. 0, 0, 0, 0, 0,
  106610. NULL,
  106611. NULL,
  106612. NULL,
  106613. NULL,
  106614. 0
  106615. };
  106616. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106619. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106620. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106621. };
  106622. static static_codebook _huff_book_line_256x7_1sub3 = {
  106623. 1, 64,
  106624. _huff_lengthlist_line_256x7_1sub3,
  106625. 0, 0, 0, 0, 0,
  106626. NULL,
  106627. NULL,
  106628. NULL,
  106629. NULL,
  106630. 0
  106631. };
  106632. static long _huff_lengthlist_line_256x7_class0[] = {
  106633. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106634. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106635. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106636. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106637. };
  106638. static static_codebook _huff_book_line_256x7_class0 = {
  106639. 1, 64,
  106640. _huff_lengthlist_line_256x7_class0,
  106641. 0, 0, 0, 0, 0,
  106642. NULL,
  106643. NULL,
  106644. NULL,
  106645. NULL,
  106646. 0
  106647. };
  106648. static long _huff_lengthlist_line_256x7_class1[] = {
  106649. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106650. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106651. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106652. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106653. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106654. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106655. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106656. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106657. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106658. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106659. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106660. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106661. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106662. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106663. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106664. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106665. };
  106666. static static_codebook _huff_book_line_256x7_class1 = {
  106667. 1, 256,
  106668. _huff_lengthlist_line_256x7_class1,
  106669. 0, 0, 0, 0, 0,
  106670. NULL,
  106671. NULL,
  106672. NULL,
  106673. NULL,
  106674. 0
  106675. };
  106676. static long _huff_lengthlist_line_512x17_0sub0[] = {
  106677. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  106678. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  106679. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  106680. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  106681. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  106682. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  106683. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  106684. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  106685. };
  106686. static static_codebook _huff_book_line_512x17_0sub0 = {
  106687. 1, 128,
  106688. _huff_lengthlist_line_512x17_0sub0,
  106689. 0, 0, 0, 0, 0,
  106690. NULL,
  106691. NULL,
  106692. NULL,
  106693. NULL,
  106694. 0
  106695. };
  106696. static long _huff_lengthlist_line_512x17_1sub0[] = {
  106697. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  106698. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  106699. };
  106700. static static_codebook _huff_book_line_512x17_1sub0 = {
  106701. 1, 32,
  106702. _huff_lengthlist_line_512x17_1sub0,
  106703. 0, 0, 0, 0, 0,
  106704. NULL,
  106705. NULL,
  106706. NULL,
  106707. NULL,
  106708. 0
  106709. };
  106710. static long _huff_lengthlist_line_512x17_1sub1[] = {
  106711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106713. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  106714. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  106715. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  106716. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  106717. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  106718. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106719. };
  106720. static static_codebook _huff_book_line_512x17_1sub1 = {
  106721. 1, 128,
  106722. _huff_lengthlist_line_512x17_1sub1,
  106723. 0, 0, 0, 0, 0,
  106724. NULL,
  106725. NULL,
  106726. NULL,
  106727. NULL,
  106728. 0
  106729. };
  106730. static long _huff_lengthlist_line_512x17_2sub1[] = {
  106731. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  106732. 5, 3,
  106733. };
  106734. static static_codebook _huff_book_line_512x17_2sub1 = {
  106735. 1, 18,
  106736. _huff_lengthlist_line_512x17_2sub1,
  106737. 0, 0, 0, 0, 0,
  106738. NULL,
  106739. NULL,
  106740. NULL,
  106741. NULL,
  106742. 0
  106743. };
  106744. static long _huff_lengthlist_line_512x17_2sub2[] = {
  106745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106746. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  106747. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  106748. 9, 8,
  106749. };
  106750. static static_codebook _huff_book_line_512x17_2sub2 = {
  106751. 1, 50,
  106752. _huff_lengthlist_line_512x17_2sub2,
  106753. 0, 0, 0, 0, 0,
  106754. NULL,
  106755. NULL,
  106756. NULL,
  106757. NULL,
  106758. 0
  106759. };
  106760. static long _huff_lengthlist_line_512x17_2sub3[] = {
  106761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106764. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  106765. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  106766. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106767. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106768. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106769. };
  106770. static static_codebook _huff_book_line_512x17_2sub3 = {
  106771. 1, 128,
  106772. _huff_lengthlist_line_512x17_2sub3,
  106773. 0, 0, 0, 0, 0,
  106774. NULL,
  106775. NULL,
  106776. NULL,
  106777. NULL,
  106778. 0
  106779. };
  106780. static long _huff_lengthlist_line_512x17_3sub1[] = {
  106781. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  106782. 5, 5,
  106783. };
  106784. static static_codebook _huff_book_line_512x17_3sub1 = {
  106785. 1, 18,
  106786. _huff_lengthlist_line_512x17_3sub1,
  106787. 0, 0, 0, 0, 0,
  106788. NULL,
  106789. NULL,
  106790. NULL,
  106791. NULL,
  106792. 0
  106793. };
  106794. static long _huff_lengthlist_line_512x17_3sub2[] = {
  106795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106796. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  106797. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  106798. 11,14,
  106799. };
  106800. static static_codebook _huff_book_line_512x17_3sub2 = {
  106801. 1, 50,
  106802. _huff_lengthlist_line_512x17_3sub2,
  106803. 0, 0, 0, 0, 0,
  106804. NULL,
  106805. NULL,
  106806. NULL,
  106807. NULL,
  106808. 0
  106809. };
  106810. static long _huff_lengthlist_line_512x17_3sub3[] = {
  106811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106814. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  106815. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106816. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106817. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106818. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106819. };
  106820. static static_codebook _huff_book_line_512x17_3sub3 = {
  106821. 1, 128,
  106822. _huff_lengthlist_line_512x17_3sub3,
  106823. 0, 0, 0, 0, 0,
  106824. NULL,
  106825. NULL,
  106826. NULL,
  106827. NULL,
  106828. 0
  106829. };
  106830. static long _huff_lengthlist_line_512x17_class1[] = {
  106831. 1, 2, 3, 6, 5, 4, 7, 7,
  106832. };
  106833. static static_codebook _huff_book_line_512x17_class1 = {
  106834. 1, 8,
  106835. _huff_lengthlist_line_512x17_class1,
  106836. 0, 0, 0, 0, 0,
  106837. NULL,
  106838. NULL,
  106839. NULL,
  106840. NULL,
  106841. 0
  106842. };
  106843. static long _huff_lengthlist_line_512x17_class2[] = {
  106844. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  106845. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  106846. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  106847. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  106848. };
  106849. static static_codebook _huff_book_line_512x17_class2 = {
  106850. 1, 64,
  106851. _huff_lengthlist_line_512x17_class2,
  106852. 0, 0, 0, 0, 0,
  106853. NULL,
  106854. NULL,
  106855. NULL,
  106856. NULL,
  106857. 0
  106858. };
  106859. static long _huff_lengthlist_line_512x17_class3[] = {
  106860. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  106861. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  106862. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  106863. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  106864. };
  106865. static static_codebook _huff_book_line_512x17_class3 = {
  106866. 1, 64,
  106867. _huff_lengthlist_line_512x17_class3,
  106868. 0, 0, 0, 0, 0,
  106869. NULL,
  106870. NULL,
  106871. NULL,
  106872. NULL,
  106873. 0
  106874. };
  106875. static long _huff_lengthlist_line_128x4_class0[] = {
  106876. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  106877. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  106878. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  106879. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  106880. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  106881. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  106882. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  106883. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  106884. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  106885. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  106886. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  106887. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  106888. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  106889. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  106890. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  106891. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  106892. };
  106893. static static_codebook _huff_book_line_128x4_class0 = {
  106894. 1, 256,
  106895. _huff_lengthlist_line_128x4_class0,
  106896. 0, 0, 0, 0, 0,
  106897. NULL,
  106898. NULL,
  106899. NULL,
  106900. NULL,
  106901. 0
  106902. };
  106903. static long _huff_lengthlist_line_128x4_0sub0[] = {
  106904. 2, 2, 2, 2,
  106905. };
  106906. static static_codebook _huff_book_line_128x4_0sub0 = {
  106907. 1, 4,
  106908. _huff_lengthlist_line_128x4_0sub0,
  106909. 0, 0, 0, 0, 0,
  106910. NULL,
  106911. NULL,
  106912. NULL,
  106913. NULL,
  106914. 0
  106915. };
  106916. static long _huff_lengthlist_line_128x4_0sub1[] = {
  106917. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  106918. };
  106919. static static_codebook _huff_book_line_128x4_0sub1 = {
  106920. 1, 10,
  106921. _huff_lengthlist_line_128x4_0sub1,
  106922. 0, 0, 0, 0, 0,
  106923. NULL,
  106924. NULL,
  106925. NULL,
  106926. NULL,
  106927. 0
  106928. };
  106929. static long _huff_lengthlist_line_128x4_0sub2[] = {
  106930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  106931. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  106932. };
  106933. static static_codebook _huff_book_line_128x4_0sub2 = {
  106934. 1, 25,
  106935. _huff_lengthlist_line_128x4_0sub2,
  106936. 0, 0, 0, 0, 0,
  106937. NULL,
  106938. NULL,
  106939. NULL,
  106940. NULL,
  106941. 0
  106942. };
  106943. static long _huff_lengthlist_line_128x4_0sub3[] = {
  106944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106946. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  106947. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  106948. };
  106949. static static_codebook _huff_book_line_128x4_0sub3 = {
  106950. 1, 64,
  106951. _huff_lengthlist_line_128x4_0sub3,
  106952. 0, 0, 0, 0, 0,
  106953. NULL,
  106954. NULL,
  106955. NULL,
  106956. NULL,
  106957. 0
  106958. };
  106959. static long _huff_lengthlist_line_256x4_class0[] = {
  106960. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  106961. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  106962. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  106963. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  106964. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  106965. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  106966. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  106967. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  106968. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  106969. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  106970. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  106971. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  106972. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  106973. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  106974. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  106975. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  106976. };
  106977. static static_codebook _huff_book_line_256x4_class0 = {
  106978. 1, 256,
  106979. _huff_lengthlist_line_256x4_class0,
  106980. 0, 0, 0, 0, 0,
  106981. NULL,
  106982. NULL,
  106983. NULL,
  106984. NULL,
  106985. 0
  106986. };
  106987. static long _huff_lengthlist_line_256x4_0sub0[] = {
  106988. 2, 2, 2, 2,
  106989. };
  106990. static static_codebook _huff_book_line_256x4_0sub0 = {
  106991. 1, 4,
  106992. _huff_lengthlist_line_256x4_0sub0,
  106993. 0, 0, 0, 0, 0,
  106994. NULL,
  106995. NULL,
  106996. NULL,
  106997. NULL,
  106998. 0
  106999. };
  107000. static long _huff_lengthlist_line_256x4_0sub1[] = {
  107001. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  107002. };
  107003. static static_codebook _huff_book_line_256x4_0sub1 = {
  107004. 1, 10,
  107005. _huff_lengthlist_line_256x4_0sub1,
  107006. 0, 0, 0, 0, 0,
  107007. NULL,
  107008. NULL,
  107009. NULL,
  107010. NULL,
  107011. 0
  107012. };
  107013. static long _huff_lengthlist_line_256x4_0sub2[] = {
  107014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  107015. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  107016. };
  107017. static static_codebook _huff_book_line_256x4_0sub2 = {
  107018. 1, 25,
  107019. _huff_lengthlist_line_256x4_0sub2,
  107020. 0, 0, 0, 0, 0,
  107021. NULL,
  107022. NULL,
  107023. NULL,
  107024. NULL,
  107025. 0
  107026. };
  107027. static long _huff_lengthlist_line_256x4_0sub3[] = {
  107028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  107030. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  107031. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  107032. };
  107033. static static_codebook _huff_book_line_256x4_0sub3 = {
  107034. 1, 64,
  107035. _huff_lengthlist_line_256x4_0sub3,
  107036. 0, 0, 0, 0, 0,
  107037. NULL,
  107038. NULL,
  107039. NULL,
  107040. NULL,
  107041. 0
  107042. };
  107043. static long _huff_lengthlist_line_128x7_class0[] = {
  107044. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  107045. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  107046. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  107047. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  107048. };
  107049. static static_codebook _huff_book_line_128x7_class0 = {
  107050. 1, 64,
  107051. _huff_lengthlist_line_128x7_class0,
  107052. 0, 0, 0, 0, 0,
  107053. NULL,
  107054. NULL,
  107055. NULL,
  107056. NULL,
  107057. 0
  107058. };
  107059. static long _huff_lengthlist_line_128x7_class1[] = {
  107060. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  107061. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  107062. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  107063. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107064. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  107065. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  107066. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  107067. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  107068. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  107069. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  107070. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  107071. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  107072. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  107073. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  107074. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  107075. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  107076. };
  107077. static static_codebook _huff_book_line_128x7_class1 = {
  107078. 1, 256,
  107079. _huff_lengthlist_line_128x7_class1,
  107080. 0, 0, 0, 0, 0,
  107081. NULL,
  107082. NULL,
  107083. NULL,
  107084. NULL,
  107085. 0
  107086. };
  107087. static long _huff_lengthlist_line_128x7_0sub1[] = {
  107088. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  107089. };
  107090. static static_codebook _huff_book_line_128x7_0sub1 = {
  107091. 1, 9,
  107092. _huff_lengthlist_line_128x7_0sub1,
  107093. 0, 0, 0, 0, 0,
  107094. NULL,
  107095. NULL,
  107096. NULL,
  107097. NULL,
  107098. 0
  107099. };
  107100. static long _huff_lengthlist_line_128x7_0sub2[] = {
  107101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  107102. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  107103. };
  107104. static static_codebook _huff_book_line_128x7_0sub2 = {
  107105. 1, 25,
  107106. _huff_lengthlist_line_128x7_0sub2,
  107107. 0, 0, 0, 0, 0,
  107108. NULL,
  107109. NULL,
  107110. NULL,
  107111. NULL,
  107112. 0
  107113. };
  107114. static long _huff_lengthlist_line_128x7_0sub3[] = {
  107115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  107117. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107118. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  107119. };
  107120. static static_codebook _huff_book_line_128x7_0sub3 = {
  107121. 1, 64,
  107122. _huff_lengthlist_line_128x7_0sub3,
  107123. 0, 0, 0, 0, 0,
  107124. NULL,
  107125. NULL,
  107126. NULL,
  107127. NULL,
  107128. 0
  107129. };
  107130. static long _huff_lengthlist_line_128x7_1sub1[] = {
  107131. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  107132. };
  107133. static static_codebook _huff_book_line_128x7_1sub1 = {
  107134. 1, 9,
  107135. _huff_lengthlist_line_128x7_1sub1,
  107136. 0, 0, 0, 0, 0,
  107137. NULL,
  107138. NULL,
  107139. NULL,
  107140. NULL,
  107141. 0
  107142. };
  107143. static long _huff_lengthlist_line_128x7_1sub2[] = {
  107144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  107145. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  107146. };
  107147. static static_codebook _huff_book_line_128x7_1sub2 = {
  107148. 1, 25,
  107149. _huff_lengthlist_line_128x7_1sub2,
  107150. 0, 0, 0, 0, 0,
  107151. NULL,
  107152. NULL,
  107153. NULL,
  107154. NULL,
  107155. 0
  107156. };
  107157. static long _huff_lengthlist_line_128x7_1sub3[] = {
  107158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  107160. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  107161. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  107162. };
  107163. static static_codebook _huff_book_line_128x7_1sub3 = {
  107164. 1, 64,
  107165. _huff_lengthlist_line_128x7_1sub3,
  107166. 0, 0, 0, 0, 0,
  107167. NULL,
  107168. NULL,
  107169. NULL,
  107170. NULL,
  107171. 0
  107172. };
  107173. static long _huff_lengthlist_line_128x11_class1[] = {
  107174. 1, 6, 3, 7, 2, 4, 5, 7,
  107175. };
  107176. static static_codebook _huff_book_line_128x11_class1 = {
  107177. 1, 8,
  107178. _huff_lengthlist_line_128x11_class1,
  107179. 0, 0, 0, 0, 0,
  107180. NULL,
  107181. NULL,
  107182. NULL,
  107183. NULL,
  107184. 0
  107185. };
  107186. static long _huff_lengthlist_line_128x11_class2[] = {
  107187. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  107188. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  107189. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  107190. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  107191. };
  107192. static static_codebook _huff_book_line_128x11_class2 = {
  107193. 1, 64,
  107194. _huff_lengthlist_line_128x11_class2,
  107195. 0, 0, 0, 0, 0,
  107196. NULL,
  107197. NULL,
  107198. NULL,
  107199. NULL,
  107200. 0
  107201. };
  107202. static long _huff_lengthlist_line_128x11_class3[] = {
  107203. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  107204. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  107205. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  107206. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  107207. };
  107208. static static_codebook _huff_book_line_128x11_class3 = {
  107209. 1, 64,
  107210. _huff_lengthlist_line_128x11_class3,
  107211. 0, 0, 0, 0, 0,
  107212. NULL,
  107213. NULL,
  107214. NULL,
  107215. NULL,
  107216. 0
  107217. };
  107218. static long _huff_lengthlist_line_128x11_0sub0[] = {
  107219. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107220. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  107221. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  107222. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  107223. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  107224. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  107225. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  107226. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107227. };
  107228. static static_codebook _huff_book_line_128x11_0sub0 = {
  107229. 1, 128,
  107230. _huff_lengthlist_line_128x11_0sub0,
  107231. 0, 0, 0, 0, 0,
  107232. NULL,
  107233. NULL,
  107234. NULL,
  107235. NULL,
  107236. 0
  107237. };
  107238. static long _huff_lengthlist_line_128x11_1sub0[] = {
  107239. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107240. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  107241. };
  107242. static static_codebook _huff_book_line_128x11_1sub0 = {
  107243. 1, 32,
  107244. _huff_lengthlist_line_128x11_1sub0,
  107245. 0, 0, 0, 0, 0,
  107246. NULL,
  107247. NULL,
  107248. NULL,
  107249. NULL,
  107250. 0
  107251. };
  107252. static long _huff_lengthlist_line_128x11_1sub1[] = {
  107253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107255. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107256. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  107257. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  107258. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  107259. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  107260. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  107261. };
  107262. static static_codebook _huff_book_line_128x11_1sub1 = {
  107263. 1, 128,
  107264. _huff_lengthlist_line_128x11_1sub1,
  107265. 0, 0, 0, 0, 0,
  107266. NULL,
  107267. NULL,
  107268. NULL,
  107269. NULL,
  107270. 0
  107271. };
  107272. static long _huff_lengthlist_line_128x11_2sub1[] = {
  107273. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  107274. 5, 5,
  107275. };
  107276. static static_codebook _huff_book_line_128x11_2sub1 = {
  107277. 1, 18,
  107278. _huff_lengthlist_line_128x11_2sub1,
  107279. 0, 0, 0, 0, 0,
  107280. NULL,
  107281. NULL,
  107282. NULL,
  107283. NULL,
  107284. 0
  107285. };
  107286. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107288. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107289. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107290. 8,11,
  107291. };
  107292. static static_codebook _huff_book_line_128x11_2sub2 = {
  107293. 1, 50,
  107294. _huff_lengthlist_line_128x11_2sub2,
  107295. 0, 0, 0, 0, 0,
  107296. NULL,
  107297. NULL,
  107298. NULL,
  107299. NULL,
  107300. 0
  107301. };
  107302. static long _huff_lengthlist_line_128x11_2sub3[] = {
  107303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107306. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107307. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107308. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107309. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107310. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107311. };
  107312. static static_codebook _huff_book_line_128x11_2sub3 = {
  107313. 1, 128,
  107314. _huff_lengthlist_line_128x11_2sub3,
  107315. 0, 0, 0, 0, 0,
  107316. NULL,
  107317. NULL,
  107318. NULL,
  107319. NULL,
  107320. 0
  107321. };
  107322. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107323. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107324. 5, 4,
  107325. };
  107326. static static_codebook _huff_book_line_128x11_3sub1 = {
  107327. 1, 18,
  107328. _huff_lengthlist_line_128x11_3sub1,
  107329. 0, 0, 0, 0, 0,
  107330. NULL,
  107331. NULL,
  107332. NULL,
  107333. NULL,
  107334. 0
  107335. };
  107336. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107338. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107339. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107340. 12, 6,
  107341. };
  107342. static static_codebook _huff_book_line_128x11_3sub2 = {
  107343. 1, 50,
  107344. _huff_lengthlist_line_128x11_3sub2,
  107345. 0, 0, 0, 0, 0,
  107346. NULL,
  107347. NULL,
  107348. NULL,
  107349. NULL,
  107350. 0
  107351. };
  107352. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107356. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107357. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107358. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107359. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107360. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107361. };
  107362. static static_codebook _huff_book_line_128x11_3sub3 = {
  107363. 1, 128,
  107364. _huff_lengthlist_line_128x11_3sub3,
  107365. 0, 0, 0, 0, 0,
  107366. NULL,
  107367. NULL,
  107368. NULL,
  107369. NULL,
  107370. 0
  107371. };
  107372. static long _huff_lengthlist_line_128x17_class1[] = {
  107373. 1, 3, 4, 7, 2, 5, 6, 7,
  107374. };
  107375. static static_codebook _huff_book_line_128x17_class1 = {
  107376. 1, 8,
  107377. _huff_lengthlist_line_128x17_class1,
  107378. 0, 0, 0, 0, 0,
  107379. NULL,
  107380. NULL,
  107381. NULL,
  107382. NULL,
  107383. 0
  107384. };
  107385. static long _huff_lengthlist_line_128x17_class2[] = {
  107386. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  107387. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  107388. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  107389. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107390. };
  107391. static static_codebook _huff_book_line_128x17_class2 = {
  107392. 1, 64,
  107393. _huff_lengthlist_line_128x17_class2,
  107394. 0, 0, 0, 0, 0,
  107395. NULL,
  107396. NULL,
  107397. NULL,
  107398. NULL,
  107399. 0
  107400. };
  107401. static long _huff_lengthlist_line_128x17_class3[] = {
  107402. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107403. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107404. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107405. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107406. };
  107407. static static_codebook _huff_book_line_128x17_class3 = {
  107408. 1, 64,
  107409. _huff_lengthlist_line_128x17_class3,
  107410. 0, 0, 0, 0, 0,
  107411. NULL,
  107412. NULL,
  107413. NULL,
  107414. NULL,
  107415. 0
  107416. };
  107417. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107418. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107419. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107420. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107421. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107422. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107423. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107424. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107425. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107426. };
  107427. static static_codebook _huff_book_line_128x17_0sub0 = {
  107428. 1, 128,
  107429. _huff_lengthlist_line_128x17_0sub0,
  107430. 0, 0, 0, 0, 0,
  107431. NULL,
  107432. NULL,
  107433. NULL,
  107434. NULL,
  107435. 0
  107436. };
  107437. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107438. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107439. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107440. };
  107441. static static_codebook _huff_book_line_128x17_1sub0 = {
  107442. 1, 32,
  107443. _huff_lengthlist_line_128x17_1sub0,
  107444. 0, 0, 0, 0, 0,
  107445. NULL,
  107446. NULL,
  107447. NULL,
  107448. NULL,
  107449. 0
  107450. };
  107451. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107454. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107455. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107456. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107457. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107458. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107459. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107460. };
  107461. static static_codebook _huff_book_line_128x17_1sub1 = {
  107462. 1, 128,
  107463. _huff_lengthlist_line_128x17_1sub1,
  107464. 0, 0, 0, 0, 0,
  107465. NULL,
  107466. NULL,
  107467. NULL,
  107468. NULL,
  107469. 0
  107470. };
  107471. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107472. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107473. 9, 4,
  107474. };
  107475. static static_codebook _huff_book_line_128x17_2sub1 = {
  107476. 1, 18,
  107477. _huff_lengthlist_line_128x17_2sub1,
  107478. 0, 0, 0, 0, 0,
  107479. NULL,
  107480. NULL,
  107481. NULL,
  107482. NULL,
  107483. 0
  107484. };
  107485. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107487. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107488. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107489. 13,13,
  107490. };
  107491. static static_codebook _huff_book_line_128x17_2sub2 = {
  107492. 1, 50,
  107493. _huff_lengthlist_line_128x17_2sub2,
  107494. 0, 0, 0, 0, 0,
  107495. NULL,
  107496. NULL,
  107497. NULL,
  107498. NULL,
  107499. 0
  107500. };
  107501. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107505. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107506. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107507. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107508. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107509. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107510. };
  107511. static static_codebook _huff_book_line_128x17_2sub3 = {
  107512. 1, 128,
  107513. _huff_lengthlist_line_128x17_2sub3,
  107514. 0, 0, 0, 0, 0,
  107515. NULL,
  107516. NULL,
  107517. NULL,
  107518. NULL,
  107519. 0
  107520. };
  107521. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107522. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107523. 6, 4,
  107524. };
  107525. static static_codebook _huff_book_line_128x17_3sub1 = {
  107526. 1, 18,
  107527. _huff_lengthlist_line_128x17_3sub1,
  107528. 0, 0, 0, 0, 0,
  107529. NULL,
  107530. NULL,
  107531. NULL,
  107532. NULL,
  107533. 0
  107534. };
  107535. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107537. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107538. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107539. 10, 8,
  107540. };
  107541. static static_codebook _huff_book_line_128x17_3sub2 = {
  107542. 1, 50,
  107543. _huff_lengthlist_line_128x17_3sub2,
  107544. 0, 0, 0, 0, 0,
  107545. NULL,
  107546. NULL,
  107547. NULL,
  107548. NULL,
  107549. 0
  107550. };
  107551. static long _huff_lengthlist_line_128x17_3sub3[] = {
  107552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107555. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107556. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107557. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107558. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107559. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107560. };
  107561. static static_codebook _huff_book_line_128x17_3sub3 = {
  107562. 1, 128,
  107563. _huff_lengthlist_line_128x17_3sub3,
  107564. 0, 0, 0, 0, 0,
  107565. NULL,
  107566. NULL,
  107567. NULL,
  107568. NULL,
  107569. 0
  107570. };
  107571. static long _huff_lengthlist_line_1024x27_class1[] = {
  107572. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107573. };
  107574. static static_codebook _huff_book_line_1024x27_class1 = {
  107575. 1, 16,
  107576. _huff_lengthlist_line_1024x27_class1,
  107577. 0, 0, 0, 0, 0,
  107578. NULL,
  107579. NULL,
  107580. NULL,
  107581. NULL,
  107582. 0
  107583. };
  107584. static long _huff_lengthlist_line_1024x27_class2[] = {
  107585. 1, 4, 2, 6, 3, 7, 5, 7,
  107586. };
  107587. static static_codebook _huff_book_line_1024x27_class2 = {
  107588. 1, 8,
  107589. _huff_lengthlist_line_1024x27_class2,
  107590. 0, 0, 0, 0, 0,
  107591. NULL,
  107592. NULL,
  107593. NULL,
  107594. NULL,
  107595. 0
  107596. };
  107597. static long _huff_lengthlist_line_1024x27_class3[] = {
  107598. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107599. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107600. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107601. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107602. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107603. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107604. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107605. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107606. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107607. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107608. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107609. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107610. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107611. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107612. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107613. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107614. };
  107615. static static_codebook _huff_book_line_1024x27_class3 = {
  107616. 1, 256,
  107617. _huff_lengthlist_line_1024x27_class3,
  107618. 0, 0, 0, 0, 0,
  107619. NULL,
  107620. NULL,
  107621. NULL,
  107622. NULL,
  107623. 0
  107624. };
  107625. static long _huff_lengthlist_line_1024x27_class4[] = {
  107626. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107627. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107628. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107629. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107630. };
  107631. static static_codebook _huff_book_line_1024x27_class4 = {
  107632. 1, 64,
  107633. _huff_lengthlist_line_1024x27_class4,
  107634. 0, 0, 0, 0, 0,
  107635. NULL,
  107636. NULL,
  107637. NULL,
  107638. NULL,
  107639. 0
  107640. };
  107641. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107642. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107643. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107644. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107645. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107646. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107647. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107648. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107649. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107650. };
  107651. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107652. 1, 128,
  107653. _huff_lengthlist_line_1024x27_0sub0,
  107654. 0, 0, 0, 0, 0,
  107655. NULL,
  107656. NULL,
  107657. NULL,
  107658. NULL,
  107659. 0
  107660. };
  107661. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107662. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107663. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107664. };
  107665. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107666. 1, 32,
  107667. _huff_lengthlist_line_1024x27_1sub0,
  107668. 0, 0, 0, 0, 0,
  107669. NULL,
  107670. NULL,
  107671. NULL,
  107672. NULL,
  107673. 0
  107674. };
  107675. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  107676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107678. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  107679. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  107680. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  107681. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  107682. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  107683. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  107684. };
  107685. static static_codebook _huff_book_line_1024x27_1sub1 = {
  107686. 1, 128,
  107687. _huff_lengthlist_line_1024x27_1sub1,
  107688. 0, 0, 0, 0, 0,
  107689. NULL,
  107690. NULL,
  107691. NULL,
  107692. NULL,
  107693. 0
  107694. };
  107695. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  107696. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107697. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  107698. };
  107699. static static_codebook _huff_book_line_1024x27_2sub0 = {
  107700. 1, 32,
  107701. _huff_lengthlist_line_1024x27_2sub0,
  107702. 0, 0, 0, 0, 0,
  107703. NULL,
  107704. NULL,
  107705. NULL,
  107706. NULL,
  107707. 0
  107708. };
  107709. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  107710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107712. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  107713. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  107714. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  107715. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  107716. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  107717. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  107718. };
  107719. static static_codebook _huff_book_line_1024x27_2sub1 = {
  107720. 1, 128,
  107721. _huff_lengthlist_line_1024x27_2sub1,
  107722. 0, 0, 0, 0, 0,
  107723. NULL,
  107724. NULL,
  107725. NULL,
  107726. NULL,
  107727. 0
  107728. };
  107729. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  107730. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  107731. 5, 5,
  107732. };
  107733. static static_codebook _huff_book_line_1024x27_3sub1 = {
  107734. 1, 18,
  107735. _huff_lengthlist_line_1024x27_3sub1,
  107736. 0, 0, 0, 0, 0,
  107737. NULL,
  107738. NULL,
  107739. NULL,
  107740. NULL,
  107741. 0
  107742. };
  107743. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  107744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107745. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  107746. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  107747. 9,11,
  107748. };
  107749. static static_codebook _huff_book_line_1024x27_3sub2 = {
  107750. 1, 50,
  107751. _huff_lengthlist_line_1024x27_3sub2,
  107752. 0, 0, 0, 0, 0,
  107753. NULL,
  107754. NULL,
  107755. NULL,
  107756. NULL,
  107757. 0
  107758. };
  107759. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  107760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107763. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  107764. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  107765. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107766. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107767. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107768. };
  107769. static static_codebook _huff_book_line_1024x27_3sub3 = {
  107770. 1, 128,
  107771. _huff_lengthlist_line_1024x27_3sub3,
  107772. 0, 0, 0, 0, 0,
  107773. NULL,
  107774. NULL,
  107775. NULL,
  107776. NULL,
  107777. 0
  107778. };
  107779. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  107780. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  107781. 5, 4,
  107782. };
  107783. static static_codebook _huff_book_line_1024x27_4sub1 = {
  107784. 1, 18,
  107785. _huff_lengthlist_line_1024x27_4sub1,
  107786. 0, 0, 0, 0, 0,
  107787. NULL,
  107788. NULL,
  107789. NULL,
  107790. NULL,
  107791. 0
  107792. };
  107793. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  107794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107795. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  107796. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  107797. 9,12,
  107798. };
  107799. static static_codebook _huff_book_line_1024x27_4sub2 = {
  107800. 1, 50,
  107801. _huff_lengthlist_line_1024x27_4sub2,
  107802. 0, 0, 0, 0, 0,
  107803. NULL,
  107804. NULL,
  107805. NULL,
  107806. NULL,
  107807. 0
  107808. };
  107809. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  107810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107813. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  107814. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  107815. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107816. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107817. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  107818. };
  107819. static static_codebook _huff_book_line_1024x27_4sub3 = {
  107820. 1, 128,
  107821. _huff_lengthlist_line_1024x27_4sub3,
  107822. 0, 0, 0, 0, 0,
  107823. NULL,
  107824. NULL,
  107825. NULL,
  107826. NULL,
  107827. 0
  107828. };
  107829. static long _huff_lengthlist_line_2048x27_class1[] = {
  107830. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  107831. };
  107832. static static_codebook _huff_book_line_2048x27_class1 = {
  107833. 1, 16,
  107834. _huff_lengthlist_line_2048x27_class1,
  107835. 0, 0, 0, 0, 0,
  107836. NULL,
  107837. NULL,
  107838. NULL,
  107839. NULL,
  107840. 0
  107841. };
  107842. static long _huff_lengthlist_line_2048x27_class2[] = {
  107843. 1, 2, 3, 6, 4, 7, 5, 7,
  107844. };
  107845. static static_codebook _huff_book_line_2048x27_class2 = {
  107846. 1, 8,
  107847. _huff_lengthlist_line_2048x27_class2,
  107848. 0, 0, 0, 0, 0,
  107849. NULL,
  107850. NULL,
  107851. NULL,
  107852. NULL,
  107853. 0
  107854. };
  107855. static long _huff_lengthlist_line_2048x27_class3[] = {
  107856. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  107857. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  107858. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  107859. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  107860. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  107861. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  107862. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  107863. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  107864. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  107865. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  107866. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  107867. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107868. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  107869. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  107870. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107871. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107872. };
  107873. static static_codebook _huff_book_line_2048x27_class3 = {
  107874. 1, 256,
  107875. _huff_lengthlist_line_2048x27_class3,
  107876. 0, 0, 0, 0, 0,
  107877. NULL,
  107878. NULL,
  107879. NULL,
  107880. NULL,
  107881. 0
  107882. };
  107883. static long _huff_lengthlist_line_2048x27_class4[] = {
  107884. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  107885. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  107886. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  107887. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  107888. };
  107889. static static_codebook _huff_book_line_2048x27_class4 = {
  107890. 1, 64,
  107891. _huff_lengthlist_line_2048x27_class4,
  107892. 0, 0, 0, 0, 0,
  107893. NULL,
  107894. NULL,
  107895. NULL,
  107896. NULL,
  107897. 0
  107898. };
  107899. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  107900. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107901. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  107902. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  107903. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  107904. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  107905. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  107906. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  107907. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  107908. };
  107909. static static_codebook _huff_book_line_2048x27_0sub0 = {
  107910. 1, 128,
  107911. _huff_lengthlist_line_2048x27_0sub0,
  107912. 0, 0, 0, 0, 0,
  107913. NULL,
  107914. NULL,
  107915. NULL,
  107916. NULL,
  107917. 0
  107918. };
  107919. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  107920. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107921. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  107922. };
  107923. static static_codebook _huff_book_line_2048x27_1sub0 = {
  107924. 1, 32,
  107925. _huff_lengthlist_line_2048x27_1sub0,
  107926. 0, 0, 0, 0, 0,
  107927. NULL,
  107928. NULL,
  107929. NULL,
  107930. NULL,
  107931. 0
  107932. };
  107933. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  107934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107936. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  107937. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  107938. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  107939. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  107940. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  107941. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  107942. };
  107943. static static_codebook _huff_book_line_2048x27_1sub1 = {
  107944. 1, 128,
  107945. _huff_lengthlist_line_2048x27_1sub1,
  107946. 0, 0, 0, 0, 0,
  107947. NULL,
  107948. NULL,
  107949. NULL,
  107950. NULL,
  107951. 0
  107952. };
  107953. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  107954. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107955. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  107956. };
  107957. static static_codebook _huff_book_line_2048x27_2sub0 = {
  107958. 1, 32,
  107959. _huff_lengthlist_line_2048x27_2sub0,
  107960. 0, 0, 0, 0, 0,
  107961. NULL,
  107962. NULL,
  107963. NULL,
  107964. NULL,
  107965. 0
  107966. };
  107967. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  107968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107970. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  107971. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  107972. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  107973. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  107974. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  107975. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107976. };
  107977. static static_codebook _huff_book_line_2048x27_2sub1 = {
  107978. 1, 128,
  107979. _huff_lengthlist_line_2048x27_2sub1,
  107980. 0, 0, 0, 0, 0,
  107981. NULL,
  107982. NULL,
  107983. NULL,
  107984. NULL,
  107985. 0
  107986. };
  107987. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  107988. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  107989. 5, 5,
  107990. };
  107991. static static_codebook _huff_book_line_2048x27_3sub1 = {
  107992. 1, 18,
  107993. _huff_lengthlist_line_2048x27_3sub1,
  107994. 0, 0, 0, 0, 0,
  107995. NULL,
  107996. NULL,
  107997. NULL,
  107998. NULL,
  107999. 0
  108000. };
  108001. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  108002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108003. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  108004. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  108005. 10,12,
  108006. };
  108007. static static_codebook _huff_book_line_2048x27_3sub2 = {
  108008. 1, 50,
  108009. _huff_lengthlist_line_2048x27_3sub2,
  108010. 0, 0, 0, 0, 0,
  108011. NULL,
  108012. NULL,
  108013. NULL,
  108014. NULL,
  108015. 0
  108016. };
  108017. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  108018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108021. 0, 0, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  108022. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108023. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108024. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108025. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108026. };
  108027. static static_codebook _huff_book_line_2048x27_3sub3 = {
  108028. 1, 128,
  108029. _huff_lengthlist_line_2048x27_3sub3,
  108030. 0, 0, 0, 0, 0,
  108031. NULL,
  108032. NULL,
  108033. NULL,
  108034. NULL,
  108035. 0
  108036. };
  108037. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  108038. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  108039. 4, 5,
  108040. };
  108041. static static_codebook _huff_book_line_2048x27_4sub1 = {
  108042. 1, 18,
  108043. _huff_lengthlist_line_2048x27_4sub1,
  108044. 0, 0, 0, 0, 0,
  108045. NULL,
  108046. NULL,
  108047. NULL,
  108048. NULL,
  108049. 0
  108050. };
  108051. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  108052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108053. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  108054. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  108055. 10,10,
  108056. };
  108057. static static_codebook _huff_book_line_2048x27_4sub2 = {
  108058. 1, 50,
  108059. _huff_lengthlist_line_2048x27_4sub2,
  108060. 0, 0, 0, 0, 0,
  108061. NULL,
  108062. NULL,
  108063. NULL,
  108064. NULL,
  108065. 0
  108066. };
  108067. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  108068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108071. 0, 0, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  108072. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  108073. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108074. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108075. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  108076. };
  108077. static static_codebook _huff_book_line_2048x27_4sub3 = {
  108078. 1, 128,
  108079. _huff_lengthlist_line_2048x27_4sub3,
  108080. 0, 0, 0, 0, 0,
  108081. NULL,
  108082. NULL,
  108083. NULL,
  108084. NULL,
  108085. 0
  108086. };
  108087. static long _huff_lengthlist_line_256x4low_class0[] = {
  108088. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  108089. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  108090. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  108091. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  108092. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  108093. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  108094. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  108095. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  108096. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  108097. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  108098. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  108099. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  108100. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  108101. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  108102. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  108103. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  108104. };
  108105. static static_codebook _huff_book_line_256x4low_class0 = {
  108106. 1, 256,
  108107. _huff_lengthlist_line_256x4low_class0,
  108108. 0, 0, 0, 0, 0,
  108109. NULL,
  108110. NULL,
  108111. NULL,
  108112. NULL,
  108113. 0
  108114. };
  108115. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  108116. 1, 3, 2, 3,
  108117. };
  108118. static static_codebook _huff_book_line_256x4low_0sub0 = {
  108119. 1, 4,
  108120. _huff_lengthlist_line_256x4low_0sub0,
  108121. 0, 0, 0, 0, 0,
  108122. NULL,
  108123. NULL,
  108124. NULL,
  108125. NULL,
  108126. 0
  108127. };
  108128. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  108129. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  108130. };
  108131. static static_codebook _huff_book_line_256x4low_0sub1 = {
  108132. 1, 10,
  108133. _huff_lengthlist_line_256x4low_0sub1,
  108134. 0, 0, 0, 0, 0,
  108135. NULL,
  108136. NULL,
  108137. NULL,
  108138. NULL,
  108139. 0
  108140. };
  108141. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  108142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  108143. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  108144. };
  108145. static static_codebook _huff_book_line_256x4low_0sub2 = {
  108146. 1, 25,
  108147. _huff_lengthlist_line_256x4low_0sub2,
  108148. 0, 0, 0, 0, 0,
  108149. NULL,
  108150. NULL,
  108151. NULL,
  108152. NULL,
  108153. 0
  108154. };
  108155. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  108156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 2, 4, 3, 5, 4,
  108158. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  108159. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  108160. };
  108161. static static_codebook _huff_book_line_256x4low_0sub3 = {
  108162. 1, 64,
  108163. _huff_lengthlist_line_256x4low_0sub3,
  108164. 0, 0, 0, 0, 0,
  108165. NULL,
  108166. NULL,
  108167. NULL,
  108168. NULL,
  108169. 0
  108170. };
  108171. /*** End of inlined file: floor_books.h ***/
  108172. static static_codebook *_floor_128x4_books[]={
  108173. &_huff_book_line_128x4_class0,
  108174. &_huff_book_line_128x4_0sub0,
  108175. &_huff_book_line_128x4_0sub1,
  108176. &_huff_book_line_128x4_0sub2,
  108177. &_huff_book_line_128x4_0sub3,
  108178. };
  108179. static static_codebook *_floor_256x4_books[]={
  108180. &_huff_book_line_256x4_class0,
  108181. &_huff_book_line_256x4_0sub0,
  108182. &_huff_book_line_256x4_0sub1,
  108183. &_huff_book_line_256x4_0sub2,
  108184. &_huff_book_line_256x4_0sub3,
  108185. };
  108186. static static_codebook *_floor_128x7_books[]={
  108187. &_huff_book_line_128x7_class0,
  108188. &_huff_book_line_128x7_class1,
  108189. &_huff_book_line_128x7_0sub1,
  108190. &_huff_book_line_128x7_0sub2,
  108191. &_huff_book_line_128x7_0sub3,
  108192. &_huff_book_line_128x7_1sub1,
  108193. &_huff_book_line_128x7_1sub2,
  108194. &_huff_book_line_128x7_1sub3,
  108195. };
  108196. static static_codebook *_floor_256x7_books[]={
  108197. &_huff_book_line_256x7_class0,
  108198. &_huff_book_line_256x7_class1,
  108199. &_huff_book_line_256x7_0sub1,
  108200. &_huff_book_line_256x7_0sub2,
  108201. &_huff_book_line_256x7_0sub3,
  108202. &_huff_book_line_256x7_1sub1,
  108203. &_huff_book_line_256x7_1sub2,
  108204. &_huff_book_line_256x7_1sub3,
  108205. };
  108206. static static_codebook *_floor_128x11_books[]={
  108207. &_huff_book_line_128x11_class1,
  108208. &_huff_book_line_128x11_class2,
  108209. &_huff_book_line_128x11_class3,
  108210. &_huff_book_line_128x11_0sub0,
  108211. &_huff_book_line_128x11_1sub0,
  108212. &_huff_book_line_128x11_1sub1,
  108213. &_huff_book_line_128x11_2sub1,
  108214. &_huff_book_line_128x11_2sub2,
  108215. &_huff_book_line_128x11_2sub3,
  108216. &_huff_book_line_128x11_3sub1,
  108217. &_huff_book_line_128x11_3sub2,
  108218. &_huff_book_line_128x11_3sub3,
  108219. };
  108220. static static_codebook *_floor_128x17_books[]={
  108221. &_huff_book_line_128x17_class1,
  108222. &_huff_book_line_128x17_class2,
  108223. &_huff_book_line_128x17_class3,
  108224. &_huff_book_line_128x17_0sub0,
  108225. &_huff_book_line_128x17_1sub0,
  108226. &_huff_book_line_128x17_1sub1,
  108227. &_huff_book_line_128x17_2sub1,
  108228. &_huff_book_line_128x17_2sub2,
  108229. &_huff_book_line_128x17_2sub3,
  108230. &_huff_book_line_128x17_3sub1,
  108231. &_huff_book_line_128x17_3sub2,
  108232. &_huff_book_line_128x17_3sub3,
  108233. };
  108234. static static_codebook *_floor_256x4low_books[]={
  108235. &_huff_book_line_256x4low_class0,
  108236. &_huff_book_line_256x4low_0sub0,
  108237. &_huff_book_line_256x4low_0sub1,
  108238. &_huff_book_line_256x4low_0sub2,
  108239. &_huff_book_line_256x4low_0sub3,
  108240. };
  108241. static static_codebook *_floor_1024x27_books[]={
  108242. &_huff_book_line_1024x27_class1,
  108243. &_huff_book_line_1024x27_class2,
  108244. &_huff_book_line_1024x27_class3,
  108245. &_huff_book_line_1024x27_class4,
  108246. &_huff_book_line_1024x27_0sub0,
  108247. &_huff_book_line_1024x27_1sub0,
  108248. &_huff_book_line_1024x27_1sub1,
  108249. &_huff_book_line_1024x27_2sub0,
  108250. &_huff_book_line_1024x27_2sub1,
  108251. &_huff_book_line_1024x27_3sub1,
  108252. &_huff_book_line_1024x27_3sub2,
  108253. &_huff_book_line_1024x27_3sub3,
  108254. &_huff_book_line_1024x27_4sub1,
  108255. &_huff_book_line_1024x27_4sub2,
  108256. &_huff_book_line_1024x27_4sub3,
  108257. };
  108258. static static_codebook *_floor_2048x27_books[]={
  108259. &_huff_book_line_2048x27_class1,
  108260. &_huff_book_line_2048x27_class2,
  108261. &_huff_book_line_2048x27_class3,
  108262. &_huff_book_line_2048x27_class4,
  108263. &_huff_book_line_2048x27_0sub0,
  108264. &_huff_book_line_2048x27_1sub0,
  108265. &_huff_book_line_2048x27_1sub1,
  108266. &_huff_book_line_2048x27_2sub0,
  108267. &_huff_book_line_2048x27_2sub1,
  108268. &_huff_book_line_2048x27_3sub1,
  108269. &_huff_book_line_2048x27_3sub2,
  108270. &_huff_book_line_2048x27_3sub3,
  108271. &_huff_book_line_2048x27_4sub1,
  108272. &_huff_book_line_2048x27_4sub2,
  108273. &_huff_book_line_2048x27_4sub3,
  108274. };
  108275. static static_codebook *_floor_512x17_books[]={
  108276. &_huff_book_line_512x17_class1,
  108277. &_huff_book_line_512x17_class2,
  108278. &_huff_book_line_512x17_class3,
  108279. &_huff_book_line_512x17_0sub0,
  108280. &_huff_book_line_512x17_1sub0,
  108281. &_huff_book_line_512x17_1sub1,
  108282. &_huff_book_line_512x17_2sub1,
  108283. &_huff_book_line_512x17_2sub2,
  108284. &_huff_book_line_512x17_2sub3,
  108285. &_huff_book_line_512x17_3sub1,
  108286. &_huff_book_line_512x17_3sub2,
  108287. &_huff_book_line_512x17_3sub3,
  108288. };
  108289. static static_codebook **_floor_books[10]={
  108290. _floor_128x4_books,
  108291. _floor_256x4_books,
  108292. _floor_128x7_books,
  108293. _floor_256x7_books,
  108294. _floor_128x11_books,
  108295. _floor_128x17_books,
  108296. _floor_256x4low_books,
  108297. _floor_1024x27_books,
  108298. _floor_2048x27_books,
  108299. _floor_512x17_books,
  108300. };
  108301. static vorbis_info_floor1 _floor[10]={
  108302. {
  108303. 1,{0},{4},{2},{0},
  108304. {{1,2,3,4}},
  108305. 4,{0,128, 33,8,16,70},
  108306. 60,30,500, 1.,18., -1
  108307. },
  108308. {
  108309. 1,{0},{4},{2},{0},
  108310. {{1,2,3,4}},
  108311. 4,{0,256, 66,16,32,140},
  108312. 60,30,500, 1.,18., -1
  108313. },
  108314. {
  108315. 2,{0,1},{3,4},{2,2},{0,1},
  108316. {{-1,2,3,4},{-1,5,6,7}},
  108317. 4,{0,128, 14,4,58, 2,8,28,90},
  108318. 60,30,500, 1.,18., -1
  108319. },
  108320. {
  108321. 2,{0,1},{3,4},{2,2},{0,1},
  108322. {{-1,2,3,4},{-1,5,6,7}},
  108323. 4,{0,256, 28,8,116, 4,16,56,180},
  108324. 60,30,500, 1.,18., -1
  108325. },
  108326. {
  108327. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108328. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108329. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108330. 60,30,500, 1,18., -1
  108331. },
  108332. {
  108333. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108334. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108335. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108336. 60,30,500, 1,18., -1
  108337. },
  108338. {
  108339. 1,{0},{4},{2},{0},
  108340. {{1,2,3,4}},
  108341. 4,{0,256, 66,16,32,140},
  108342. 60,30,500, 1.,18., -1
  108343. },
  108344. {
  108345. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108346. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108347. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108348. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108349. 60,30,500, 3,18., -1 /* lowpass */
  108350. },
  108351. {
  108352. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108353. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108354. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108355. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108356. 60,30,500, 3,18., -1 /* lowpass */
  108357. },
  108358. {
  108359. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108360. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108361. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108362. 7,23,39, 55,79,110, 156,232,360},
  108363. 60,30,500, 1,18., -1 /* lowpass! */
  108364. },
  108365. };
  108366. /*** End of inlined file: floor_all.h ***/
  108367. /*** Start of inlined file: residue_44.h ***/
  108368. /*** Start of inlined file: res_books_stereo.h ***/
  108369. static long _vq_quantlist__16c0_s_p1_0[] = {
  108370. 1,
  108371. 0,
  108372. 2,
  108373. };
  108374. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108375. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  108376. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  108381. 0, 0, 0, 7, 9,10, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  108386. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 8, 0, 0, 0, 0,
  108421. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0,
  108426. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 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, 7,10,10, 0, 0,
  108431. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108467. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108472. 0, 0, 0, 0, 0, 9,10,12, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108477. 0, 0, 0, 0, 0, 0, 9,12, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108785. 0,
  108786. };
  108787. static float _vq_quantthresh__16c0_s_p1_0[] = {
  108788. -0.5, 0.5,
  108789. };
  108790. static long _vq_quantmap__16c0_s_p1_0[] = {
  108791. 1, 0, 2,
  108792. };
  108793. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  108794. _vq_quantthresh__16c0_s_p1_0,
  108795. _vq_quantmap__16c0_s_p1_0,
  108796. 3,
  108797. 3
  108798. };
  108799. static static_codebook _16c0_s_p1_0 = {
  108800. 8, 6561,
  108801. _vq_lengthlist__16c0_s_p1_0,
  108802. 1, -535822336, 1611661312, 2, 0,
  108803. _vq_quantlist__16c0_s_p1_0,
  108804. NULL,
  108805. &_vq_auxt__16c0_s_p1_0,
  108806. NULL,
  108807. 0
  108808. };
  108809. static long _vq_quantlist__16c0_s_p2_0[] = {
  108810. 2,
  108811. 1,
  108812. 3,
  108813. 0,
  108814. 4,
  108815. };
  108816. static long _vq_lengthlist__16c0_s_p2_0[] = {
  108817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108856. 0,
  108857. };
  108858. static float _vq_quantthresh__16c0_s_p2_0[] = {
  108859. -1.5, -0.5, 0.5, 1.5,
  108860. };
  108861. static long _vq_quantmap__16c0_s_p2_0[] = {
  108862. 3, 1, 0, 2, 4,
  108863. };
  108864. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  108865. _vq_quantthresh__16c0_s_p2_0,
  108866. _vq_quantmap__16c0_s_p2_0,
  108867. 5,
  108868. 5
  108869. };
  108870. static static_codebook _16c0_s_p2_0 = {
  108871. 4, 625,
  108872. _vq_lengthlist__16c0_s_p2_0,
  108873. 1, -533725184, 1611661312, 3, 0,
  108874. _vq_quantlist__16c0_s_p2_0,
  108875. NULL,
  108876. &_vq_auxt__16c0_s_p2_0,
  108877. NULL,
  108878. 0
  108879. };
  108880. static long _vq_quantlist__16c0_s_p3_0[] = {
  108881. 2,
  108882. 1,
  108883. 3,
  108884. 0,
  108885. 4,
  108886. };
  108887. static long _vq_lengthlist__16c0_s_p3_0[] = {
  108888. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  108890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108891. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  108893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108894. 0, 0, 0, 0, 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  108895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108927. 0,
  108928. };
  108929. static float _vq_quantthresh__16c0_s_p3_0[] = {
  108930. -1.5, -0.5, 0.5, 1.5,
  108931. };
  108932. static long _vq_quantmap__16c0_s_p3_0[] = {
  108933. 3, 1, 0, 2, 4,
  108934. };
  108935. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  108936. _vq_quantthresh__16c0_s_p3_0,
  108937. _vq_quantmap__16c0_s_p3_0,
  108938. 5,
  108939. 5
  108940. };
  108941. static static_codebook _16c0_s_p3_0 = {
  108942. 4, 625,
  108943. _vq_lengthlist__16c0_s_p3_0,
  108944. 1, -533725184, 1611661312, 3, 0,
  108945. _vq_quantlist__16c0_s_p3_0,
  108946. NULL,
  108947. &_vq_auxt__16c0_s_p3_0,
  108948. NULL,
  108949. 0
  108950. };
  108951. static long _vq_quantlist__16c0_s_p4_0[] = {
  108952. 4,
  108953. 3,
  108954. 5,
  108955. 2,
  108956. 6,
  108957. 1,
  108958. 7,
  108959. 0,
  108960. 8,
  108961. };
  108962. static long _vq_lengthlist__16c0_s_p4_0[] = {
  108963. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  108964. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  108965. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  108966. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  108967. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108968. 0,
  108969. };
  108970. static float _vq_quantthresh__16c0_s_p4_0[] = {
  108971. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108972. };
  108973. static long _vq_quantmap__16c0_s_p4_0[] = {
  108974. 7, 5, 3, 1, 0, 2, 4, 6,
  108975. 8,
  108976. };
  108977. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  108978. _vq_quantthresh__16c0_s_p4_0,
  108979. _vq_quantmap__16c0_s_p4_0,
  108980. 9,
  108981. 9
  108982. };
  108983. static static_codebook _16c0_s_p4_0 = {
  108984. 2, 81,
  108985. _vq_lengthlist__16c0_s_p4_0,
  108986. 1, -531628032, 1611661312, 4, 0,
  108987. _vq_quantlist__16c0_s_p4_0,
  108988. NULL,
  108989. &_vq_auxt__16c0_s_p4_0,
  108990. NULL,
  108991. 0
  108992. };
  108993. static long _vq_quantlist__16c0_s_p5_0[] = {
  108994. 4,
  108995. 3,
  108996. 5,
  108997. 2,
  108998. 6,
  108999. 1,
  109000. 7,
  109001. 0,
  109002. 8,
  109003. };
  109004. static long _vq_lengthlist__16c0_s_p5_0[] = {
  109005. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109006. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  109007. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  109008. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  109009. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109010. 10,
  109011. };
  109012. static float _vq_quantthresh__16c0_s_p5_0[] = {
  109013. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109014. };
  109015. static long _vq_quantmap__16c0_s_p5_0[] = {
  109016. 7, 5, 3, 1, 0, 2, 4, 6,
  109017. 8,
  109018. };
  109019. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  109020. _vq_quantthresh__16c0_s_p5_0,
  109021. _vq_quantmap__16c0_s_p5_0,
  109022. 9,
  109023. 9
  109024. };
  109025. static static_codebook _16c0_s_p5_0 = {
  109026. 2, 81,
  109027. _vq_lengthlist__16c0_s_p5_0,
  109028. 1, -531628032, 1611661312, 4, 0,
  109029. _vq_quantlist__16c0_s_p5_0,
  109030. NULL,
  109031. &_vq_auxt__16c0_s_p5_0,
  109032. NULL,
  109033. 0
  109034. };
  109035. static long _vq_quantlist__16c0_s_p6_0[] = {
  109036. 8,
  109037. 7,
  109038. 9,
  109039. 6,
  109040. 10,
  109041. 5,
  109042. 11,
  109043. 4,
  109044. 12,
  109045. 3,
  109046. 13,
  109047. 2,
  109048. 14,
  109049. 1,
  109050. 15,
  109051. 0,
  109052. 16,
  109053. };
  109054. static long _vq_lengthlist__16c0_s_p6_0[] = {
  109055. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  109056. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  109057. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  109058. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  109059. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  109060. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  109061. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  109062. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  109063. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  109064. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  109065. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  109066. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  109067. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  109068. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  109069. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  109070. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  109071. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  109072. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  109073. 14,
  109074. };
  109075. static float _vq_quantthresh__16c0_s_p6_0[] = {
  109076. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  109077. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  109078. };
  109079. static long _vq_quantmap__16c0_s_p6_0[] = {
  109080. 15, 13, 11, 9, 7, 5, 3, 1,
  109081. 0, 2, 4, 6, 8, 10, 12, 14,
  109082. 16,
  109083. };
  109084. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  109085. _vq_quantthresh__16c0_s_p6_0,
  109086. _vq_quantmap__16c0_s_p6_0,
  109087. 17,
  109088. 17
  109089. };
  109090. static static_codebook _16c0_s_p6_0 = {
  109091. 2, 289,
  109092. _vq_lengthlist__16c0_s_p6_0,
  109093. 1, -529530880, 1611661312, 5, 0,
  109094. _vq_quantlist__16c0_s_p6_0,
  109095. NULL,
  109096. &_vq_auxt__16c0_s_p6_0,
  109097. NULL,
  109098. 0
  109099. };
  109100. static long _vq_quantlist__16c0_s_p7_0[] = {
  109101. 1,
  109102. 0,
  109103. 2,
  109104. };
  109105. static long _vq_lengthlist__16c0_s_p7_0[] = {
  109106. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  109107. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  109108. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  109109. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  109110. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  109111. 13,
  109112. };
  109113. static float _vq_quantthresh__16c0_s_p7_0[] = {
  109114. -5.5, 5.5,
  109115. };
  109116. static long _vq_quantmap__16c0_s_p7_0[] = {
  109117. 1, 0, 2,
  109118. };
  109119. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  109120. _vq_quantthresh__16c0_s_p7_0,
  109121. _vq_quantmap__16c0_s_p7_0,
  109122. 3,
  109123. 3
  109124. };
  109125. static static_codebook _16c0_s_p7_0 = {
  109126. 4, 81,
  109127. _vq_lengthlist__16c0_s_p7_0,
  109128. 1, -529137664, 1618345984, 2, 0,
  109129. _vq_quantlist__16c0_s_p7_0,
  109130. NULL,
  109131. &_vq_auxt__16c0_s_p7_0,
  109132. NULL,
  109133. 0
  109134. };
  109135. static long _vq_quantlist__16c0_s_p7_1[] = {
  109136. 5,
  109137. 4,
  109138. 6,
  109139. 3,
  109140. 7,
  109141. 2,
  109142. 8,
  109143. 1,
  109144. 9,
  109145. 0,
  109146. 10,
  109147. };
  109148. static long _vq_lengthlist__16c0_s_p7_1[] = {
  109149. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  109150. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  109151. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  109152. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  109153. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  109154. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  109155. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  109156. 11,11,11, 9, 9, 9, 9,10,10,
  109157. };
  109158. static float _vq_quantthresh__16c0_s_p7_1[] = {
  109159. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  109160. 3.5, 4.5,
  109161. };
  109162. static long _vq_quantmap__16c0_s_p7_1[] = {
  109163. 9, 7, 5, 3, 1, 0, 2, 4,
  109164. 6, 8, 10,
  109165. };
  109166. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  109167. _vq_quantthresh__16c0_s_p7_1,
  109168. _vq_quantmap__16c0_s_p7_1,
  109169. 11,
  109170. 11
  109171. };
  109172. static static_codebook _16c0_s_p7_1 = {
  109173. 2, 121,
  109174. _vq_lengthlist__16c0_s_p7_1,
  109175. 1, -531365888, 1611661312, 4, 0,
  109176. _vq_quantlist__16c0_s_p7_1,
  109177. NULL,
  109178. &_vq_auxt__16c0_s_p7_1,
  109179. NULL,
  109180. 0
  109181. };
  109182. static long _vq_quantlist__16c0_s_p8_0[] = {
  109183. 6,
  109184. 5,
  109185. 7,
  109186. 4,
  109187. 8,
  109188. 3,
  109189. 9,
  109190. 2,
  109191. 10,
  109192. 1,
  109193. 11,
  109194. 0,
  109195. 12,
  109196. };
  109197. static long _vq_lengthlist__16c0_s_p8_0[] = {
  109198. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  109199. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  109200. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  109201. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  109202. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  109203. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  109204. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  109205. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  109206. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  109207. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  109208. 0,12,13,13,12,13,14,14,14,
  109209. };
  109210. static float _vq_quantthresh__16c0_s_p8_0[] = {
  109211. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  109212. 12.5, 17.5, 22.5, 27.5,
  109213. };
  109214. static long _vq_quantmap__16c0_s_p8_0[] = {
  109215. 11, 9, 7, 5, 3, 1, 0, 2,
  109216. 4, 6, 8, 10, 12,
  109217. };
  109218. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  109219. _vq_quantthresh__16c0_s_p8_0,
  109220. _vq_quantmap__16c0_s_p8_0,
  109221. 13,
  109222. 13
  109223. };
  109224. static static_codebook _16c0_s_p8_0 = {
  109225. 2, 169,
  109226. _vq_lengthlist__16c0_s_p8_0,
  109227. 1, -526516224, 1616117760, 4, 0,
  109228. _vq_quantlist__16c0_s_p8_0,
  109229. NULL,
  109230. &_vq_auxt__16c0_s_p8_0,
  109231. NULL,
  109232. 0
  109233. };
  109234. static long _vq_quantlist__16c0_s_p8_1[] = {
  109235. 2,
  109236. 1,
  109237. 3,
  109238. 0,
  109239. 4,
  109240. };
  109241. static long _vq_lengthlist__16c0_s_p8_1[] = {
  109242. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  109243. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  109244. };
  109245. static float _vq_quantthresh__16c0_s_p8_1[] = {
  109246. -1.5, -0.5, 0.5, 1.5,
  109247. };
  109248. static long _vq_quantmap__16c0_s_p8_1[] = {
  109249. 3, 1, 0, 2, 4,
  109250. };
  109251. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  109252. _vq_quantthresh__16c0_s_p8_1,
  109253. _vq_quantmap__16c0_s_p8_1,
  109254. 5,
  109255. 5
  109256. };
  109257. static static_codebook _16c0_s_p8_1 = {
  109258. 2, 25,
  109259. _vq_lengthlist__16c0_s_p8_1,
  109260. 1, -533725184, 1611661312, 3, 0,
  109261. _vq_quantlist__16c0_s_p8_1,
  109262. NULL,
  109263. &_vq_auxt__16c0_s_p8_1,
  109264. NULL,
  109265. 0
  109266. };
  109267. static long _vq_quantlist__16c0_s_p9_0[] = {
  109268. 1,
  109269. 0,
  109270. 2,
  109271. };
  109272. static long _vq_lengthlist__16c0_s_p9_0[] = {
  109273. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109274. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109275. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109276. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109277. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109278. 7,
  109279. };
  109280. static float _vq_quantthresh__16c0_s_p9_0[] = {
  109281. -157.5, 157.5,
  109282. };
  109283. static long _vq_quantmap__16c0_s_p9_0[] = {
  109284. 1, 0, 2,
  109285. };
  109286. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109287. _vq_quantthresh__16c0_s_p9_0,
  109288. _vq_quantmap__16c0_s_p9_0,
  109289. 3,
  109290. 3
  109291. };
  109292. static static_codebook _16c0_s_p9_0 = {
  109293. 4, 81,
  109294. _vq_lengthlist__16c0_s_p9_0,
  109295. 1, -518803456, 1628680192, 2, 0,
  109296. _vq_quantlist__16c0_s_p9_0,
  109297. NULL,
  109298. &_vq_auxt__16c0_s_p9_0,
  109299. NULL,
  109300. 0
  109301. };
  109302. static long _vq_quantlist__16c0_s_p9_1[] = {
  109303. 7,
  109304. 6,
  109305. 8,
  109306. 5,
  109307. 9,
  109308. 4,
  109309. 10,
  109310. 3,
  109311. 11,
  109312. 2,
  109313. 12,
  109314. 1,
  109315. 13,
  109316. 0,
  109317. 14,
  109318. };
  109319. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109320. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109321. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109322. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109323. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109324. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109325. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109326. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109327. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109328. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109329. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109330. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109331. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109332. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109333. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109334. 10,
  109335. };
  109336. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109337. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109338. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109339. };
  109340. static long _vq_quantmap__16c0_s_p9_1[] = {
  109341. 13, 11, 9, 7, 5, 3, 1, 0,
  109342. 2, 4, 6, 8, 10, 12, 14,
  109343. };
  109344. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109345. _vq_quantthresh__16c0_s_p9_1,
  109346. _vq_quantmap__16c0_s_p9_1,
  109347. 15,
  109348. 15
  109349. };
  109350. static static_codebook _16c0_s_p9_1 = {
  109351. 2, 225,
  109352. _vq_lengthlist__16c0_s_p9_1,
  109353. 1, -520986624, 1620377600, 4, 0,
  109354. _vq_quantlist__16c0_s_p9_1,
  109355. NULL,
  109356. &_vq_auxt__16c0_s_p9_1,
  109357. NULL,
  109358. 0
  109359. };
  109360. static long _vq_quantlist__16c0_s_p9_2[] = {
  109361. 10,
  109362. 9,
  109363. 11,
  109364. 8,
  109365. 12,
  109366. 7,
  109367. 13,
  109368. 6,
  109369. 14,
  109370. 5,
  109371. 15,
  109372. 4,
  109373. 16,
  109374. 3,
  109375. 17,
  109376. 2,
  109377. 18,
  109378. 1,
  109379. 19,
  109380. 0,
  109381. 20,
  109382. };
  109383. static long _vq_lengthlist__16c0_s_p9_2[] = {
  109384. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  109385. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  109386. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  109387. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  109388. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  109389. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  109390. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  109391. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  109392. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  109393. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  109394. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109395. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109396. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109397. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109398. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109399. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109400. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109401. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109402. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109403. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109404. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109405. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109406. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109407. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109408. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109409. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109410. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109411. 10,11,10,10,11, 9,10,10,10,
  109412. };
  109413. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109414. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109415. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109416. 6.5, 7.5, 8.5, 9.5,
  109417. };
  109418. static long _vq_quantmap__16c0_s_p9_2[] = {
  109419. 19, 17, 15, 13, 11, 9, 7, 5,
  109420. 3, 1, 0, 2, 4, 6, 8, 10,
  109421. 12, 14, 16, 18, 20,
  109422. };
  109423. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109424. _vq_quantthresh__16c0_s_p9_2,
  109425. _vq_quantmap__16c0_s_p9_2,
  109426. 21,
  109427. 21
  109428. };
  109429. static static_codebook _16c0_s_p9_2 = {
  109430. 2, 441,
  109431. _vq_lengthlist__16c0_s_p9_2,
  109432. 1, -529268736, 1611661312, 5, 0,
  109433. _vq_quantlist__16c0_s_p9_2,
  109434. NULL,
  109435. &_vq_auxt__16c0_s_p9_2,
  109436. NULL,
  109437. 0
  109438. };
  109439. static long _huff_lengthlist__16c0_s_single[] = {
  109440. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109441. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109442. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109443. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109444. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109445. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109446. 16,16,18,18,
  109447. };
  109448. static static_codebook _huff_book__16c0_s_single = {
  109449. 2, 100,
  109450. _huff_lengthlist__16c0_s_single,
  109451. 0, 0, 0, 0, 0,
  109452. NULL,
  109453. NULL,
  109454. NULL,
  109455. NULL,
  109456. 0
  109457. };
  109458. static long _huff_lengthlist__16c1_s_long[] = {
  109459. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109460. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109461. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109462. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109463. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109464. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109465. 12,11,11,13,
  109466. };
  109467. static static_codebook _huff_book__16c1_s_long = {
  109468. 2, 100,
  109469. _huff_lengthlist__16c1_s_long,
  109470. 0, 0, 0, 0, 0,
  109471. NULL,
  109472. NULL,
  109473. NULL,
  109474. NULL,
  109475. 0
  109476. };
  109477. static long _vq_quantlist__16c1_s_p1_0[] = {
  109478. 1,
  109479. 0,
  109480. 2,
  109481. };
  109482. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109483. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109484. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109489. 0, 0, 0, 7, 8, 9, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109494. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 7, 0, 0, 0, 0,
  109529. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  109534. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  109539. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109575. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109580. 0, 0, 0, 0, 0, 8, 9,11, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109585. 0, 0, 0, 0, 0, 0, 9,11, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109893. 0,
  109894. };
  109895. static float _vq_quantthresh__16c1_s_p1_0[] = {
  109896. -0.5, 0.5,
  109897. };
  109898. static long _vq_quantmap__16c1_s_p1_0[] = {
  109899. 1, 0, 2,
  109900. };
  109901. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  109902. _vq_quantthresh__16c1_s_p1_0,
  109903. _vq_quantmap__16c1_s_p1_0,
  109904. 3,
  109905. 3
  109906. };
  109907. static static_codebook _16c1_s_p1_0 = {
  109908. 8, 6561,
  109909. _vq_lengthlist__16c1_s_p1_0,
  109910. 1, -535822336, 1611661312, 2, 0,
  109911. _vq_quantlist__16c1_s_p1_0,
  109912. NULL,
  109913. &_vq_auxt__16c1_s_p1_0,
  109914. NULL,
  109915. 0
  109916. };
  109917. static long _vq_quantlist__16c1_s_p2_0[] = {
  109918. 2,
  109919. 1,
  109920. 3,
  109921. 0,
  109922. 4,
  109923. };
  109924. static long _vq_lengthlist__16c1_s_p2_0[] = {
  109925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109964. 0,
  109965. };
  109966. static float _vq_quantthresh__16c1_s_p2_0[] = {
  109967. -1.5, -0.5, 0.5, 1.5,
  109968. };
  109969. static long _vq_quantmap__16c1_s_p2_0[] = {
  109970. 3, 1, 0, 2, 4,
  109971. };
  109972. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  109973. _vq_quantthresh__16c1_s_p2_0,
  109974. _vq_quantmap__16c1_s_p2_0,
  109975. 5,
  109976. 5
  109977. };
  109978. static static_codebook _16c1_s_p2_0 = {
  109979. 4, 625,
  109980. _vq_lengthlist__16c1_s_p2_0,
  109981. 1, -533725184, 1611661312, 3, 0,
  109982. _vq_quantlist__16c1_s_p2_0,
  109983. NULL,
  109984. &_vq_auxt__16c1_s_p2_0,
  109985. NULL,
  109986. 0
  109987. };
  109988. static long _vq_quantlist__16c1_s_p3_0[] = {
  109989. 2,
  109990. 1,
  109991. 3,
  109992. 0,
  109993. 4,
  109994. };
  109995. static long _vq_lengthlist__16c1_s_p3_0[] = {
  109996. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  109998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109999. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  110001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110002. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  110003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110035. 0,
  110036. };
  110037. static float _vq_quantthresh__16c1_s_p3_0[] = {
  110038. -1.5, -0.5, 0.5, 1.5,
  110039. };
  110040. static long _vq_quantmap__16c1_s_p3_0[] = {
  110041. 3, 1, 0, 2, 4,
  110042. };
  110043. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  110044. _vq_quantthresh__16c1_s_p3_0,
  110045. _vq_quantmap__16c1_s_p3_0,
  110046. 5,
  110047. 5
  110048. };
  110049. static static_codebook _16c1_s_p3_0 = {
  110050. 4, 625,
  110051. _vq_lengthlist__16c1_s_p3_0,
  110052. 1, -533725184, 1611661312, 3, 0,
  110053. _vq_quantlist__16c1_s_p3_0,
  110054. NULL,
  110055. &_vq_auxt__16c1_s_p3_0,
  110056. NULL,
  110057. 0
  110058. };
  110059. static long _vq_quantlist__16c1_s_p4_0[] = {
  110060. 4,
  110061. 3,
  110062. 5,
  110063. 2,
  110064. 6,
  110065. 1,
  110066. 7,
  110067. 0,
  110068. 8,
  110069. };
  110070. static long _vq_lengthlist__16c1_s_p4_0[] = {
  110071. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  110072. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  110073. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  110074. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  110075. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110076. 0,
  110077. };
  110078. static float _vq_quantthresh__16c1_s_p4_0[] = {
  110079. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110080. };
  110081. static long _vq_quantmap__16c1_s_p4_0[] = {
  110082. 7, 5, 3, 1, 0, 2, 4, 6,
  110083. 8,
  110084. };
  110085. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  110086. _vq_quantthresh__16c1_s_p4_0,
  110087. _vq_quantmap__16c1_s_p4_0,
  110088. 9,
  110089. 9
  110090. };
  110091. static static_codebook _16c1_s_p4_0 = {
  110092. 2, 81,
  110093. _vq_lengthlist__16c1_s_p4_0,
  110094. 1, -531628032, 1611661312, 4, 0,
  110095. _vq_quantlist__16c1_s_p4_0,
  110096. NULL,
  110097. &_vq_auxt__16c1_s_p4_0,
  110098. NULL,
  110099. 0
  110100. };
  110101. static long _vq_quantlist__16c1_s_p5_0[] = {
  110102. 4,
  110103. 3,
  110104. 5,
  110105. 2,
  110106. 6,
  110107. 1,
  110108. 7,
  110109. 0,
  110110. 8,
  110111. };
  110112. static long _vq_lengthlist__16c1_s_p5_0[] = {
  110113. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  110114. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  110115. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  110116. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  110117. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  110118. 10,
  110119. };
  110120. static float _vq_quantthresh__16c1_s_p5_0[] = {
  110121. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110122. };
  110123. static long _vq_quantmap__16c1_s_p5_0[] = {
  110124. 7, 5, 3, 1, 0, 2, 4, 6,
  110125. 8,
  110126. };
  110127. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  110128. _vq_quantthresh__16c1_s_p5_0,
  110129. _vq_quantmap__16c1_s_p5_0,
  110130. 9,
  110131. 9
  110132. };
  110133. static static_codebook _16c1_s_p5_0 = {
  110134. 2, 81,
  110135. _vq_lengthlist__16c1_s_p5_0,
  110136. 1, -531628032, 1611661312, 4, 0,
  110137. _vq_quantlist__16c1_s_p5_0,
  110138. NULL,
  110139. &_vq_auxt__16c1_s_p5_0,
  110140. NULL,
  110141. 0
  110142. };
  110143. static long _vq_quantlist__16c1_s_p6_0[] = {
  110144. 8,
  110145. 7,
  110146. 9,
  110147. 6,
  110148. 10,
  110149. 5,
  110150. 11,
  110151. 4,
  110152. 12,
  110153. 3,
  110154. 13,
  110155. 2,
  110156. 14,
  110157. 1,
  110158. 15,
  110159. 0,
  110160. 16,
  110161. };
  110162. static long _vq_lengthlist__16c1_s_p6_0[] = {
  110163. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  110164. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  110165. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  110166. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  110167. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  110168. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  110169. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  110170. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  110171. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  110172. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  110173. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  110174. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  110175. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  110176. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  110177. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  110178. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  110179. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  110180. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  110181. 14,
  110182. };
  110183. static float _vq_quantthresh__16c1_s_p6_0[] = {
  110184. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110185. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110186. };
  110187. static long _vq_quantmap__16c1_s_p6_0[] = {
  110188. 15, 13, 11, 9, 7, 5, 3, 1,
  110189. 0, 2, 4, 6, 8, 10, 12, 14,
  110190. 16,
  110191. };
  110192. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  110193. _vq_quantthresh__16c1_s_p6_0,
  110194. _vq_quantmap__16c1_s_p6_0,
  110195. 17,
  110196. 17
  110197. };
  110198. static static_codebook _16c1_s_p6_0 = {
  110199. 2, 289,
  110200. _vq_lengthlist__16c1_s_p6_0,
  110201. 1, -529530880, 1611661312, 5, 0,
  110202. _vq_quantlist__16c1_s_p6_0,
  110203. NULL,
  110204. &_vq_auxt__16c1_s_p6_0,
  110205. NULL,
  110206. 0
  110207. };
  110208. static long _vq_quantlist__16c1_s_p7_0[] = {
  110209. 1,
  110210. 0,
  110211. 2,
  110212. };
  110213. static long _vq_lengthlist__16c1_s_p7_0[] = {
  110214. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  110215. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  110216. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  110217. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  110218. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  110219. 11,
  110220. };
  110221. static float _vq_quantthresh__16c1_s_p7_0[] = {
  110222. -5.5, 5.5,
  110223. };
  110224. static long _vq_quantmap__16c1_s_p7_0[] = {
  110225. 1, 0, 2,
  110226. };
  110227. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  110228. _vq_quantthresh__16c1_s_p7_0,
  110229. _vq_quantmap__16c1_s_p7_0,
  110230. 3,
  110231. 3
  110232. };
  110233. static static_codebook _16c1_s_p7_0 = {
  110234. 4, 81,
  110235. _vq_lengthlist__16c1_s_p7_0,
  110236. 1, -529137664, 1618345984, 2, 0,
  110237. _vq_quantlist__16c1_s_p7_0,
  110238. NULL,
  110239. &_vq_auxt__16c1_s_p7_0,
  110240. NULL,
  110241. 0
  110242. };
  110243. static long _vq_quantlist__16c1_s_p7_1[] = {
  110244. 5,
  110245. 4,
  110246. 6,
  110247. 3,
  110248. 7,
  110249. 2,
  110250. 8,
  110251. 1,
  110252. 9,
  110253. 0,
  110254. 10,
  110255. };
  110256. static long _vq_lengthlist__16c1_s_p7_1[] = {
  110257. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  110258. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  110259. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  110260. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  110261. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  110262. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  110263. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  110264. 10,10,10, 8, 8, 8, 8, 9, 9,
  110265. };
  110266. static float _vq_quantthresh__16c1_s_p7_1[] = {
  110267. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110268. 3.5, 4.5,
  110269. };
  110270. static long _vq_quantmap__16c1_s_p7_1[] = {
  110271. 9, 7, 5, 3, 1, 0, 2, 4,
  110272. 6, 8, 10,
  110273. };
  110274. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  110275. _vq_quantthresh__16c1_s_p7_1,
  110276. _vq_quantmap__16c1_s_p7_1,
  110277. 11,
  110278. 11
  110279. };
  110280. static static_codebook _16c1_s_p7_1 = {
  110281. 2, 121,
  110282. _vq_lengthlist__16c1_s_p7_1,
  110283. 1, -531365888, 1611661312, 4, 0,
  110284. _vq_quantlist__16c1_s_p7_1,
  110285. NULL,
  110286. &_vq_auxt__16c1_s_p7_1,
  110287. NULL,
  110288. 0
  110289. };
  110290. static long _vq_quantlist__16c1_s_p8_0[] = {
  110291. 6,
  110292. 5,
  110293. 7,
  110294. 4,
  110295. 8,
  110296. 3,
  110297. 9,
  110298. 2,
  110299. 10,
  110300. 1,
  110301. 11,
  110302. 0,
  110303. 12,
  110304. };
  110305. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110306. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110307. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110308. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110309. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110310. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110311. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110312. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110313. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110314. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110315. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110316. 0,12,12,12,12,13,13,14,15,
  110317. };
  110318. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110319. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110320. 12.5, 17.5, 22.5, 27.5,
  110321. };
  110322. static long _vq_quantmap__16c1_s_p8_0[] = {
  110323. 11, 9, 7, 5, 3, 1, 0, 2,
  110324. 4, 6, 8, 10, 12,
  110325. };
  110326. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110327. _vq_quantthresh__16c1_s_p8_0,
  110328. _vq_quantmap__16c1_s_p8_0,
  110329. 13,
  110330. 13
  110331. };
  110332. static static_codebook _16c1_s_p8_0 = {
  110333. 2, 169,
  110334. _vq_lengthlist__16c1_s_p8_0,
  110335. 1, -526516224, 1616117760, 4, 0,
  110336. _vq_quantlist__16c1_s_p8_0,
  110337. NULL,
  110338. &_vq_auxt__16c1_s_p8_0,
  110339. NULL,
  110340. 0
  110341. };
  110342. static long _vq_quantlist__16c1_s_p8_1[] = {
  110343. 2,
  110344. 1,
  110345. 3,
  110346. 0,
  110347. 4,
  110348. };
  110349. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110350. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110351. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110352. };
  110353. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110354. -1.5, -0.5, 0.5, 1.5,
  110355. };
  110356. static long _vq_quantmap__16c1_s_p8_1[] = {
  110357. 3, 1, 0, 2, 4,
  110358. };
  110359. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110360. _vq_quantthresh__16c1_s_p8_1,
  110361. _vq_quantmap__16c1_s_p8_1,
  110362. 5,
  110363. 5
  110364. };
  110365. static static_codebook _16c1_s_p8_1 = {
  110366. 2, 25,
  110367. _vq_lengthlist__16c1_s_p8_1,
  110368. 1, -533725184, 1611661312, 3, 0,
  110369. _vq_quantlist__16c1_s_p8_1,
  110370. NULL,
  110371. &_vq_auxt__16c1_s_p8_1,
  110372. NULL,
  110373. 0
  110374. };
  110375. static long _vq_quantlist__16c1_s_p9_0[] = {
  110376. 6,
  110377. 5,
  110378. 7,
  110379. 4,
  110380. 8,
  110381. 3,
  110382. 9,
  110383. 2,
  110384. 10,
  110385. 1,
  110386. 11,
  110387. 0,
  110388. 12,
  110389. };
  110390. static long _vq_lengthlist__16c1_s_p9_0[] = {
  110391. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110392. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110393. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110394. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110395. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110396. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110397. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110398. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110399. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110400. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110401. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110402. };
  110403. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110404. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110405. 787.5, 1102.5, 1417.5, 1732.5,
  110406. };
  110407. static long _vq_quantmap__16c1_s_p9_0[] = {
  110408. 11, 9, 7, 5, 3, 1, 0, 2,
  110409. 4, 6, 8, 10, 12,
  110410. };
  110411. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110412. _vq_quantthresh__16c1_s_p9_0,
  110413. _vq_quantmap__16c1_s_p9_0,
  110414. 13,
  110415. 13
  110416. };
  110417. static static_codebook _16c1_s_p9_0 = {
  110418. 2, 169,
  110419. _vq_lengthlist__16c1_s_p9_0,
  110420. 1, -513964032, 1628680192, 4, 0,
  110421. _vq_quantlist__16c1_s_p9_0,
  110422. NULL,
  110423. &_vq_auxt__16c1_s_p9_0,
  110424. NULL,
  110425. 0
  110426. };
  110427. static long _vq_quantlist__16c1_s_p9_1[] = {
  110428. 7,
  110429. 6,
  110430. 8,
  110431. 5,
  110432. 9,
  110433. 4,
  110434. 10,
  110435. 3,
  110436. 11,
  110437. 2,
  110438. 12,
  110439. 1,
  110440. 13,
  110441. 0,
  110442. 14,
  110443. };
  110444. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110445. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110446. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110447. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110448. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110449. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110450. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110451. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110452. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110453. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110454. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110455. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110456. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110457. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110458. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110459. 13,
  110460. };
  110461. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110462. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110463. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110464. };
  110465. static long _vq_quantmap__16c1_s_p9_1[] = {
  110466. 13, 11, 9, 7, 5, 3, 1, 0,
  110467. 2, 4, 6, 8, 10, 12, 14,
  110468. };
  110469. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110470. _vq_quantthresh__16c1_s_p9_1,
  110471. _vq_quantmap__16c1_s_p9_1,
  110472. 15,
  110473. 15
  110474. };
  110475. static static_codebook _16c1_s_p9_1 = {
  110476. 2, 225,
  110477. _vq_lengthlist__16c1_s_p9_1,
  110478. 1, -520986624, 1620377600, 4, 0,
  110479. _vq_quantlist__16c1_s_p9_1,
  110480. NULL,
  110481. &_vq_auxt__16c1_s_p9_1,
  110482. NULL,
  110483. 0
  110484. };
  110485. static long _vq_quantlist__16c1_s_p9_2[] = {
  110486. 10,
  110487. 9,
  110488. 11,
  110489. 8,
  110490. 12,
  110491. 7,
  110492. 13,
  110493. 6,
  110494. 14,
  110495. 5,
  110496. 15,
  110497. 4,
  110498. 16,
  110499. 3,
  110500. 17,
  110501. 2,
  110502. 18,
  110503. 1,
  110504. 19,
  110505. 0,
  110506. 20,
  110507. };
  110508. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110509. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110510. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110511. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110512. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110513. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110514. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110515. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110516. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110517. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110518. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110519. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110520. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110521. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110522. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110523. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110524. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110525. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110526. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110527. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110528. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110529. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110530. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110531. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110532. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110533. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110534. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110535. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110536. 11,11,11,11,12,11,11,12,11,
  110537. };
  110538. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110539. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110540. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110541. 6.5, 7.5, 8.5, 9.5,
  110542. };
  110543. static long _vq_quantmap__16c1_s_p9_2[] = {
  110544. 19, 17, 15, 13, 11, 9, 7, 5,
  110545. 3, 1, 0, 2, 4, 6, 8, 10,
  110546. 12, 14, 16, 18, 20,
  110547. };
  110548. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110549. _vq_quantthresh__16c1_s_p9_2,
  110550. _vq_quantmap__16c1_s_p9_2,
  110551. 21,
  110552. 21
  110553. };
  110554. static static_codebook _16c1_s_p9_2 = {
  110555. 2, 441,
  110556. _vq_lengthlist__16c1_s_p9_2,
  110557. 1, -529268736, 1611661312, 5, 0,
  110558. _vq_quantlist__16c1_s_p9_2,
  110559. NULL,
  110560. &_vq_auxt__16c1_s_p9_2,
  110561. NULL,
  110562. 0
  110563. };
  110564. static long _huff_lengthlist__16c1_s_short[] = {
  110565. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110566. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110567. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110568. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110569. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110570. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110571. 9, 9,10,13,
  110572. };
  110573. static static_codebook _huff_book__16c1_s_short = {
  110574. 2, 100,
  110575. _huff_lengthlist__16c1_s_short,
  110576. 0, 0, 0, 0, 0,
  110577. NULL,
  110578. NULL,
  110579. NULL,
  110580. NULL,
  110581. 0
  110582. };
  110583. static long _huff_lengthlist__16c2_s_long[] = {
  110584. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110585. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110586. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110587. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110588. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110589. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110590. 14,14,16,18,
  110591. };
  110592. static static_codebook _huff_book__16c2_s_long = {
  110593. 2, 100,
  110594. _huff_lengthlist__16c2_s_long,
  110595. 0, 0, 0, 0, 0,
  110596. NULL,
  110597. NULL,
  110598. NULL,
  110599. NULL,
  110600. 0
  110601. };
  110602. static long _vq_quantlist__16c2_s_p1_0[] = {
  110603. 1,
  110604. 0,
  110605. 2,
  110606. };
  110607. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110608. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110609. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110613. 0,
  110614. };
  110615. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110616. -0.5, 0.5,
  110617. };
  110618. static long _vq_quantmap__16c2_s_p1_0[] = {
  110619. 1, 0, 2,
  110620. };
  110621. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110622. _vq_quantthresh__16c2_s_p1_0,
  110623. _vq_quantmap__16c2_s_p1_0,
  110624. 3,
  110625. 3
  110626. };
  110627. static static_codebook _16c2_s_p1_0 = {
  110628. 4, 81,
  110629. _vq_lengthlist__16c2_s_p1_0,
  110630. 1, -535822336, 1611661312, 2, 0,
  110631. _vq_quantlist__16c2_s_p1_0,
  110632. NULL,
  110633. &_vq_auxt__16c2_s_p1_0,
  110634. NULL,
  110635. 0
  110636. };
  110637. static long _vq_quantlist__16c2_s_p2_0[] = {
  110638. 2,
  110639. 1,
  110640. 3,
  110641. 0,
  110642. 4,
  110643. };
  110644. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110645. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110646. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110647. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110648. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110649. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110650. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110651. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110652. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  110653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110657. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  110658. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110659. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110660. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110665. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110666. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110667. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110668. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110673. 0, 0, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  110674. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  110675. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  110676. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  110681. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  110682. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  110683. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  110684. 13,
  110685. };
  110686. static float _vq_quantthresh__16c2_s_p2_0[] = {
  110687. -1.5, -0.5, 0.5, 1.5,
  110688. };
  110689. static long _vq_quantmap__16c2_s_p2_0[] = {
  110690. 3, 1, 0, 2, 4,
  110691. };
  110692. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  110693. _vq_quantthresh__16c2_s_p2_0,
  110694. _vq_quantmap__16c2_s_p2_0,
  110695. 5,
  110696. 5
  110697. };
  110698. static static_codebook _16c2_s_p2_0 = {
  110699. 4, 625,
  110700. _vq_lengthlist__16c2_s_p2_0,
  110701. 1, -533725184, 1611661312, 3, 0,
  110702. _vq_quantlist__16c2_s_p2_0,
  110703. NULL,
  110704. &_vq_auxt__16c2_s_p2_0,
  110705. NULL,
  110706. 0
  110707. };
  110708. static long _vq_quantlist__16c2_s_p3_0[] = {
  110709. 4,
  110710. 3,
  110711. 5,
  110712. 2,
  110713. 6,
  110714. 1,
  110715. 7,
  110716. 0,
  110717. 8,
  110718. };
  110719. static long _vq_lengthlist__16c2_s_p3_0[] = {
  110720. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  110721. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  110722. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  110723. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  110724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110725. 0,
  110726. };
  110727. static float _vq_quantthresh__16c2_s_p3_0[] = {
  110728. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110729. };
  110730. static long _vq_quantmap__16c2_s_p3_0[] = {
  110731. 7, 5, 3, 1, 0, 2, 4, 6,
  110732. 8,
  110733. };
  110734. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  110735. _vq_quantthresh__16c2_s_p3_0,
  110736. _vq_quantmap__16c2_s_p3_0,
  110737. 9,
  110738. 9
  110739. };
  110740. static static_codebook _16c2_s_p3_0 = {
  110741. 2, 81,
  110742. _vq_lengthlist__16c2_s_p3_0,
  110743. 1, -531628032, 1611661312, 4, 0,
  110744. _vq_quantlist__16c2_s_p3_0,
  110745. NULL,
  110746. &_vq_auxt__16c2_s_p3_0,
  110747. NULL,
  110748. 0
  110749. };
  110750. static long _vq_quantlist__16c2_s_p4_0[] = {
  110751. 8,
  110752. 7,
  110753. 9,
  110754. 6,
  110755. 10,
  110756. 5,
  110757. 11,
  110758. 4,
  110759. 12,
  110760. 3,
  110761. 13,
  110762. 2,
  110763. 14,
  110764. 1,
  110765. 15,
  110766. 0,
  110767. 16,
  110768. };
  110769. static long _vq_lengthlist__16c2_s_p4_0[] = {
  110770. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  110771. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  110772. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  110773. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  110774. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  110775. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  110776. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  110777. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  110778. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  110779. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  110780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110788. 0,
  110789. };
  110790. static float _vq_quantthresh__16c2_s_p4_0[] = {
  110791. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110792. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110793. };
  110794. static long _vq_quantmap__16c2_s_p4_0[] = {
  110795. 15, 13, 11, 9, 7, 5, 3, 1,
  110796. 0, 2, 4, 6, 8, 10, 12, 14,
  110797. 16,
  110798. };
  110799. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  110800. _vq_quantthresh__16c2_s_p4_0,
  110801. _vq_quantmap__16c2_s_p4_0,
  110802. 17,
  110803. 17
  110804. };
  110805. static static_codebook _16c2_s_p4_0 = {
  110806. 2, 289,
  110807. _vq_lengthlist__16c2_s_p4_0,
  110808. 1, -529530880, 1611661312, 5, 0,
  110809. _vq_quantlist__16c2_s_p4_0,
  110810. NULL,
  110811. &_vq_auxt__16c2_s_p4_0,
  110812. NULL,
  110813. 0
  110814. };
  110815. static long _vq_quantlist__16c2_s_p5_0[] = {
  110816. 1,
  110817. 0,
  110818. 2,
  110819. };
  110820. static long _vq_lengthlist__16c2_s_p5_0[] = {
  110821. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  110822. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  110823. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  110824. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  110825. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  110826. 12,
  110827. };
  110828. static float _vq_quantthresh__16c2_s_p5_0[] = {
  110829. -5.5, 5.5,
  110830. };
  110831. static long _vq_quantmap__16c2_s_p5_0[] = {
  110832. 1, 0, 2,
  110833. };
  110834. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  110835. _vq_quantthresh__16c2_s_p5_0,
  110836. _vq_quantmap__16c2_s_p5_0,
  110837. 3,
  110838. 3
  110839. };
  110840. static static_codebook _16c2_s_p5_0 = {
  110841. 4, 81,
  110842. _vq_lengthlist__16c2_s_p5_0,
  110843. 1, -529137664, 1618345984, 2, 0,
  110844. _vq_quantlist__16c2_s_p5_0,
  110845. NULL,
  110846. &_vq_auxt__16c2_s_p5_0,
  110847. NULL,
  110848. 0
  110849. };
  110850. static long _vq_quantlist__16c2_s_p5_1[] = {
  110851. 5,
  110852. 4,
  110853. 6,
  110854. 3,
  110855. 7,
  110856. 2,
  110857. 8,
  110858. 1,
  110859. 9,
  110860. 0,
  110861. 10,
  110862. };
  110863. static long _vq_lengthlist__16c2_s_p5_1[] = {
  110864. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  110865. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  110866. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  110867. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  110868. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  110869. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  110870. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  110871. 11,11,11, 7, 7, 8, 8, 8, 8,
  110872. };
  110873. static float _vq_quantthresh__16c2_s_p5_1[] = {
  110874. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110875. 3.5, 4.5,
  110876. };
  110877. static long _vq_quantmap__16c2_s_p5_1[] = {
  110878. 9, 7, 5, 3, 1, 0, 2, 4,
  110879. 6, 8, 10,
  110880. };
  110881. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  110882. _vq_quantthresh__16c2_s_p5_1,
  110883. _vq_quantmap__16c2_s_p5_1,
  110884. 11,
  110885. 11
  110886. };
  110887. static static_codebook _16c2_s_p5_1 = {
  110888. 2, 121,
  110889. _vq_lengthlist__16c2_s_p5_1,
  110890. 1, -531365888, 1611661312, 4, 0,
  110891. _vq_quantlist__16c2_s_p5_1,
  110892. NULL,
  110893. &_vq_auxt__16c2_s_p5_1,
  110894. NULL,
  110895. 0
  110896. };
  110897. static long _vq_quantlist__16c2_s_p6_0[] = {
  110898. 6,
  110899. 5,
  110900. 7,
  110901. 4,
  110902. 8,
  110903. 3,
  110904. 9,
  110905. 2,
  110906. 10,
  110907. 1,
  110908. 11,
  110909. 0,
  110910. 12,
  110911. };
  110912. static long _vq_lengthlist__16c2_s_p6_0[] = {
  110913. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110914. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  110915. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  110916. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  110917. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  110918. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  110919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110923. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110924. };
  110925. static float _vq_quantthresh__16c2_s_p6_0[] = {
  110926. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110927. 12.5, 17.5, 22.5, 27.5,
  110928. };
  110929. static long _vq_quantmap__16c2_s_p6_0[] = {
  110930. 11, 9, 7, 5, 3, 1, 0, 2,
  110931. 4, 6, 8, 10, 12,
  110932. };
  110933. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  110934. _vq_quantthresh__16c2_s_p6_0,
  110935. _vq_quantmap__16c2_s_p6_0,
  110936. 13,
  110937. 13
  110938. };
  110939. static static_codebook _16c2_s_p6_0 = {
  110940. 2, 169,
  110941. _vq_lengthlist__16c2_s_p6_0,
  110942. 1, -526516224, 1616117760, 4, 0,
  110943. _vq_quantlist__16c2_s_p6_0,
  110944. NULL,
  110945. &_vq_auxt__16c2_s_p6_0,
  110946. NULL,
  110947. 0
  110948. };
  110949. static long _vq_quantlist__16c2_s_p6_1[] = {
  110950. 2,
  110951. 1,
  110952. 3,
  110953. 0,
  110954. 4,
  110955. };
  110956. static long _vq_lengthlist__16c2_s_p6_1[] = {
  110957. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110958. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110959. };
  110960. static float _vq_quantthresh__16c2_s_p6_1[] = {
  110961. -1.5, -0.5, 0.5, 1.5,
  110962. };
  110963. static long _vq_quantmap__16c2_s_p6_1[] = {
  110964. 3, 1, 0, 2, 4,
  110965. };
  110966. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  110967. _vq_quantthresh__16c2_s_p6_1,
  110968. _vq_quantmap__16c2_s_p6_1,
  110969. 5,
  110970. 5
  110971. };
  110972. static static_codebook _16c2_s_p6_1 = {
  110973. 2, 25,
  110974. _vq_lengthlist__16c2_s_p6_1,
  110975. 1, -533725184, 1611661312, 3, 0,
  110976. _vq_quantlist__16c2_s_p6_1,
  110977. NULL,
  110978. &_vq_auxt__16c2_s_p6_1,
  110979. NULL,
  110980. 0
  110981. };
  110982. static long _vq_quantlist__16c2_s_p7_0[] = {
  110983. 6,
  110984. 5,
  110985. 7,
  110986. 4,
  110987. 8,
  110988. 3,
  110989. 9,
  110990. 2,
  110991. 10,
  110992. 1,
  110993. 11,
  110994. 0,
  110995. 12,
  110996. };
  110997. static long _vq_lengthlist__16c2_s_p7_0[] = {
  110998. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110999. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  111000. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  111001. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  111002. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  111003. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  111004. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  111005. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  111006. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  111007. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  111008. 18,13,14,13,13,14,13,15,14,
  111009. };
  111010. static float _vq_quantthresh__16c2_s_p7_0[] = {
  111011. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  111012. 27.5, 38.5, 49.5, 60.5,
  111013. };
  111014. static long _vq_quantmap__16c2_s_p7_0[] = {
  111015. 11, 9, 7, 5, 3, 1, 0, 2,
  111016. 4, 6, 8, 10, 12,
  111017. };
  111018. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  111019. _vq_quantthresh__16c2_s_p7_0,
  111020. _vq_quantmap__16c2_s_p7_0,
  111021. 13,
  111022. 13
  111023. };
  111024. static static_codebook _16c2_s_p7_0 = {
  111025. 2, 169,
  111026. _vq_lengthlist__16c2_s_p7_0,
  111027. 1, -523206656, 1618345984, 4, 0,
  111028. _vq_quantlist__16c2_s_p7_0,
  111029. NULL,
  111030. &_vq_auxt__16c2_s_p7_0,
  111031. NULL,
  111032. 0
  111033. };
  111034. static long _vq_quantlist__16c2_s_p7_1[] = {
  111035. 5,
  111036. 4,
  111037. 6,
  111038. 3,
  111039. 7,
  111040. 2,
  111041. 8,
  111042. 1,
  111043. 9,
  111044. 0,
  111045. 10,
  111046. };
  111047. static long _vq_lengthlist__16c2_s_p7_1[] = {
  111048. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  111049. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  111050. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  111051. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111052. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  111053. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  111054. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  111055. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111056. };
  111057. static float _vq_quantthresh__16c2_s_p7_1[] = {
  111058. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111059. 3.5, 4.5,
  111060. };
  111061. static long _vq_quantmap__16c2_s_p7_1[] = {
  111062. 9, 7, 5, 3, 1, 0, 2, 4,
  111063. 6, 8, 10,
  111064. };
  111065. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  111066. _vq_quantthresh__16c2_s_p7_1,
  111067. _vq_quantmap__16c2_s_p7_1,
  111068. 11,
  111069. 11
  111070. };
  111071. static static_codebook _16c2_s_p7_1 = {
  111072. 2, 121,
  111073. _vq_lengthlist__16c2_s_p7_1,
  111074. 1, -531365888, 1611661312, 4, 0,
  111075. _vq_quantlist__16c2_s_p7_1,
  111076. NULL,
  111077. &_vq_auxt__16c2_s_p7_1,
  111078. NULL,
  111079. 0
  111080. };
  111081. static long _vq_quantlist__16c2_s_p8_0[] = {
  111082. 7,
  111083. 6,
  111084. 8,
  111085. 5,
  111086. 9,
  111087. 4,
  111088. 10,
  111089. 3,
  111090. 11,
  111091. 2,
  111092. 12,
  111093. 1,
  111094. 13,
  111095. 0,
  111096. 14,
  111097. };
  111098. static long _vq_lengthlist__16c2_s_p8_0[] = {
  111099. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  111100. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  111101. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  111102. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  111103. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  111104. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  111105. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  111106. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  111107. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  111108. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  111109. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  111110. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  111111. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  111112. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  111113. 13,
  111114. };
  111115. static float _vq_quantthresh__16c2_s_p8_0[] = {
  111116. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  111117. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  111118. };
  111119. static long _vq_quantmap__16c2_s_p8_0[] = {
  111120. 13, 11, 9, 7, 5, 3, 1, 0,
  111121. 2, 4, 6, 8, 10, 12, 14,
  111122. };
  111123. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  111124. _vq_quantthresh__16c2_s_p8_0,
  111125. _vq_quantmap__16c2_s_p8_0,
  111126. 15,
  111127. 15
  111128. };
  111129. static static_codebook _16c2_s_p8_0 = {
  111130. 2, 225,
  111131. _vq_lengthlist__16c2_s_p8_0,
  111132. 1, -520986624, 1620377600, 4, 0,
  111133. _vq_quantlist__16c2_s_p8_0,
  111134. NULL,
  111135. &_vq_auxt__16c2_s_p8_0,
  111136. NULL,
  111137. 0
  111138. };
  111139. static long _vq_quantlist__16c2_s_p8_1[] = {
  111140. 10,
  111141. 9,
  111142. 11,
  111143. 8,
  111144. 12,
  111145. 7,
  111146. 13,
  111147. 6,
  111148. 14,
  111149. 5,
  111150. 15,
  111151. 4,
  111152. 16,
  111153. 3,
  111154. 17,
  111155. 2,
  111156. 18,
  111157. 1,
  111158. 19,
  111159. 0,
  111160. 20,
  111161. };
  111162. static long _vq_lengthlist__16c2_s_p8_1[] = {
  111163. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  111164. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  111165. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  111166. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  111167. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  111168. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  111169. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  111170. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  111171. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  111172. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  111173. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  111174. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  111175. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  111176. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  111177. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  111178. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  111179. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  111180. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  111181. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  111182. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  111183. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  111184. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  111185. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  111186. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  111187. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  111188. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  111189. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  111190. 10,11,10,10,10,10,10,10,10,
  111191. };
  111192. static float _vq_quantthresh__16c2_s_p8_1[] = {
  111193. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  111194. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  111195. 6.5, 7.5, 8.5, 9.5,
  111196. };
  111197. static long _vq_quantmap__16c2_s_p8_1[] = {
  111198. 19, 17, 15, 13, 11, 9, 7, 5,
  111199. 3, 1, 0, 2, 4, 6, 8, 10,
  111200. 12, 14, 16, 18, 20,
  111201. };
  111202. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  111203. _vq_quantthresh__16c2_s_p8_1,
  111204. _vq_quantmap__16c2_s_p8_1,
  111205. 21,
  111206. 21
  111207. };
  111208. static static_codebook _16c2_s_p8_1 = {
  111209. 2, 441,
  111210. _vq_lengthlist__16c2_s_p8_1,
  111211. 1, -529268736, 1611661312, 5, 0,
  111212. _vq_quantlist__16c2_s_p8_1,
  111213. NULL,
  111214. &_vq_auxt__16c2_s_p8_1,
  111215. NULL,
  111216. 0
  111217. };
  111218. static long _vq_quantlist__16c2_s_p9_0[] = {
  111219. 6,
  111220. 5,
  111221. 7,
  111222. 4,
  111223. 8,
  111224. 3,
  111225. 9,
  111226. 2,
  111227. 10,
  111228. 1,
  111229. 11,
  111230. 0,
  111231. 12,
  111232. };
  111233. static long _vq_lengthlist__16c2_s_p9_0[] = {
  111234. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111235. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111236. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111237. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111238. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111239. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111240. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111241. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111242. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111243. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111244. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111245. };
  111246. static float _vq_quantthresh__16c2_s_p9_0[] = {
  111247. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  111248. 2327.5, 3258.5, 4189.5, 5120.5,
  111249. };
  111250. static long _vq_quantmap__16c2_s_p9_0[] = {
  111251. 11, 9, 7, 5, 3, 1, 0, 2,
  111252. 4, 6, 8, 10, 12,
  111253. };
  111254. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  111255. _vq_quantthresh__16c2_s_p9_0,
  111256. _vq_quantmap__16c2_s_p9_0,
  111257. 13,
  111258. 13
  111259. };
  111260. static static_codebook _16c2_s_p9_0 = {
  111261. 2, 169,
  111262. _vq_lengthlist__16c2_s_p9_0,
  111263. 1, -510275072, 1631393792, 4, 0,
  111264. _vq_quantlist__16c2_s_p9_0,
  111265. NULL,
  111266. &_vq_auxt__16c2_s_p9_0,
  111267. NULL,
  111268. 0
  111269. };
  111270. static long _vq_quantlist__16c2_s_p9_1[] = {
  111271. 8,
  111272. 7,
  111273. 9,
  111274. 6,
  111275. 10,
  111276. 5,
  111277. 11,
  111278. 4,
  111279. 12,
  111280. 3,
  111281. 13,
  111282. 2,
  111283. 14,
  111284. 1,
  111285. 15,
  111286. 0,
  111287. 16,
  111288. };
  111289. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111290. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111291. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111292. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111293. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111294. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111295. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111296. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111297. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111298. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111299. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111300. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111301. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111302. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111303. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111304. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111305. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111306. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111307. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111308. 10,
  111309. };
  111310. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111311. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111312. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111313. };
  111314. static long _vq_quantmap__16c2_s_p9_1[] = {
  111315. 15, 13, 11, 9, 7, 5, 3, 1,
  111316. 0, 2, 4, 6, 8, 10, 12, 14,
  111317. 16,
  111318. };
  111319. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111320. _vq_quantthresh__16c2_s_p9_1,
  111321. _vq_quantmap__16c2_s_p9_1,
  111322. 17,
  111323. 17
  111324. };
  111325. static static_codebook _16c2_s_p9_1 = {
  111326. 2, 289,
  111327. _vq_lengthlist__16c2_s_p9_1,
  111328. 1, -518488064, 1622704128, 5, 0,
  111329. _vq_quantlist__16c2_s_p9_1,
  111330. NULL,
  111331. &_vq_auxt__16c2_s_p9_1,
  111332. NULL,
  111333. 0
  111334. };
  111335. static long _vq_quantlist__16c2_s_p9_2[] = {
  111336. 13,
  111337. 12,
  111338. 14,
  111339. 11,
  111340. 15,
  111341. 10,
  111342. 16,
  111343. 9,
  111344. 17,
  111345. 8,
  111346. 18,
  111347. 7,
  111348. 19,
  111349. 6,
  111350. 20,
  111351. 5,
  111352. 21,
  111353. 4,
  111354. 22,
  111355. 3,
  111356. 23,
  111357. 2,
  111358. 24,
  111359. 1,
  111360. 25,
  111361. 0,
  111362. 26,
  111363. };
  111364. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111365. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111366. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111367. };
  111368. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111369. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111370. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111371. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111372. 11.5, 12.5,
  111373. };
  111374. static long _vq_quantmap__16c2_s_p9_2[] = {
  111375. 25, 23, 21, 19, 17, 15, 13, 11,
  111376. 9, 7, 5, 3, 1, 0, 2, 4,
  111377. 6, 8, 10, 12, 14, 16, 18, 20,
  111378. 22, 24, 26,
  111379. };
  111380. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  111381. _vq_quantthresh__16c2_s_p9_2,
  111382. _vq_quantmap__16c2_s_p9_2,
  111383. 27,
  111384. 27
  111385. };
  111386. static static_codebook _16c2_s_p9_2 = {
  111387. 1, 27,
  111388. _vq_lengthlist__16c2_s_p9_2,
  111389. 1, -528875520, 1611661312, 5, 0,
  111390. _vq_quantlist__16c2_s_p9_2,
  111391. NULL,
  111392. &_vq_auxt__16c2_s_p9_2,
  111393. NULL,
  111394. 0
  111395. };
  111396. static long _huff_lengthlist__16c2_s_short[] = {
  111397. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111398. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111399. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111400. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111401. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111402. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111403. 15,12,14,14,
  111404. };
  111405. static static_codebook _huff_book__16c2_s_short = {
  111406. 2, 100,
  111407. _huff_lengthlist__16c2_s_short,
  111408. 0, 0, 0, 0, 0,
  111409. NULL,
  111410. NULL,
  111411. NULL,
  111412. NULL,
  111413. 0
  111414. };
  111415. static long _vq_quantlist__8c0_s_p1_0[] = {
  111416. 1,
  111417. 0,
  111418. 2,
  111419. };
  111420. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111421. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111422. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111427. 0, 0, 0, 7, 8, 9, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111432. 0, 0, 0, 0, 7, 9, 8, 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, 5, 8, 8, 0, 0, 0, 0,
  111467. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  111472. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 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, 7, 9,10, 0, 0,
  111477. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111513. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111518. 0, 0, 0, 0, 0, 9,10,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111523. 0, 0, 0, 0, 0, 0, 8,11, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111831. 0,
  111832. };
  111833. static float _vq_quantthresh__8c0_s_p1_0[] = {
  111834. -0.5, 0.5,
  111835. };
  111836. static long _vq_quantmap__8c0_s_p1_0[] = {
  111837. 1, 0, 2,
  111838. };
  111839. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  111840. _vq_quantthresh__8c0_s_p1_0,
  111841. _vq_quantmap__8c0_s_p1_0,
  111842. 3,
  111843. 3
  111844. };
  111845. static static_codebook _8c0_s_p1_0 = {
  111846. 8, 6561,
  111847. _vq_lengthlist__8c0_s_p1_0,
  111848. 1, -535822336, 1611661312, 2, 0,
  111849. _vq_quantlist__8c0_s_p1_0,
  111850. NULL,
  111851. &_vq_auxt__8c0_s_p1_0,
  111852. NULL,
  111853. 0
  111854. };
  111855. static long _vq_quantlist__8c0_s_p2_0[] = {
  111856. 2,
  111857. 1,
  111858. 3,
  111859. 0,
  111860. 4,
  111861. };
  111862. static long _vq_lengthlist__8c0_s_p2_0[] = {
  111863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111902. 0,
  111903. };
  111904. static float _vq_quantthresh__8c0_s_p2_0[] = {
  111905. -1.5, -0.5, 0.5, 1.5,
  111906. };
  111907. static long _vq_quantmap__8c0_s_p2_0[] = {
  111908. 3, 1, 0, 2, 4,
  111909. };
  111910. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  111911. _vq_quantthresh__8c0_s_p2_0,
  111912. _vq_quantmap__8c0_s_p2_0,
  111913. 5,
  111914. 5
  111915. };
  111916. static static_codebook _8c0_s_p2_0 = {
  111917. 4, 625,
  111918. _vq_lengthlist__8c0_s_p2_0,
  111919. 1, -533725184, 1611661312, 3, 0,
  111920. _vq_quantlist__8c0_s_p2_0,
  111921. NULL,
  111922. &_vq_auxt__8c0_s_p2_0,
  111923. NULL,
  111924. 0
  111925. };
  111926. static long _vq_quantlist__8c0_s_p3_0[] = {
  111927. 2,
  111928. 1,
  111929. 3,
  111930. 0,
  111931. 4,
  111932. };
  111933. static long _vq_lengthlist__8c0_s_p3_0[] = {
  111934. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  111936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111937. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  111939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111940. 0, 0, 0, 0, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  111941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111973. 0,
  111974. };
  111975. static float _vq_quantthresh__8c0_s_p3_0[] = {
  111976. -1.5, -0.5, 0.5, 1.5,
  111977. };
  111978. static long _vq_quantmap__8c0_s_p3_0[] = {
  111979. 3, 1, 0, 2, 4,
  111980. };
  111981. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  111982. _vq_quantthresh__8c0_s_p3_0,
  111983. _vq_quantmap__8c0_s_p3_0,
  111984. 5,
  111985. 5
  111986. };
  111987. static static_codebook _8c0_s_p3_0 = {
  111988. 4, 625,
  111989. _vq_lengthlist__8c0_s_p3_0,
  111990. 1, -533725184, 1611661312, 3, 0,
  111991. _vq_quantlist__8c0_s_p3_0,
  111992. NULL,
  111993. &_vq_auxt__8c0_s_p3_0,
  111994. NULL,
  111995. 0
  111996. };
  111997. static long _vq_quantlist__8c0_s_p4_0[] = {
  111998. 4,
  111999. 3,
  112000. 5,
  112001. 2,
  112002. 6,
  112003. 1,
  112004. 7,
  112005. 0,
  112006. 8,
  112007. };
  112008. static long _vq_lengthlist__8c0_s_p4_0[] = {
  112009. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112010. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112011. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112012. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112013. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112014. 0,
  112015. };
  112016. static float _vq_quantthresh__8c0_s_p4_0[] = {
  112017. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112018. };
  112019. static long _vq_quantmap__8c0_s_p4_0[] = {
  112020. 7, 5, 3, 1, 0, 2, 4, 6,
  112021. 8,
  112022. };
  112023. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  112024. _vq_quantthresh__8c0_s_p4_0,
  112025. _vq_quantmap__8c0_s_p4_0,
  112026. 9,
  112027. 9
  112028. };
  112029. static static_codebook _8c0_s_p4_0 = {
  112030. 2, 81,
  112031. _vq_lengthlist__8c0_s_p4_0,
  112032. 1, -531628032, 1611661312, 4, 0,
  112033. _vq_quantlist__8c0_s_p4_0,
  112034. NULL,
  112035. &_vq_auxt__8c0_s_p4_0,
  112036. NULL,
  112037. 0
  112038. };
  112039. static long _vq_quantlist__8c0_s_p5_0[] = {
  112040. 4,
  112041. 3,
  112042. 5,
  112043. 2,
  112044. 6,
  112045. 1,
  112046. 7,
  112047. 0,
  112048. 8,
  112049. };
  112050. static long _vq_lengthlist__8c0_s_p5_0[] = {
  112051. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  112052. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  112053. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  112054. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  112055. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  112056. 10,
  112057. };
  112058. static float _vq_quantthresh__8c0_s_p5_0[] = {
  112059. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112060. };
  112061. static long _vq_quantmap__8c0_s_p5_0[] = {
  112062. 7, 5, 3, 1, 0, 2, 4, 6,
  112063. 8,
  112064. };
  112065. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  112066. _vq_quantthresh__8c0_s_p5_0,
  112067. _vq_quantmap__8c0_s_p5_0,
  112068. 9,
  112069. 9
  112070. };
  112071. static static_codebook _8c0_s_p5_0 = {
  112072. 2, 81,
  112073. _vq_lengthlist__8c0_s_p5_0,
  112074. 1, -531628032, 1611661312, 4, 0,
  112075. _vq_quantlist__8c0_s_p5_0,
  112076. NULL,
  112077. &_vq_auxt__8c0_s_p5_0,
  112078. NULL,
  112079. 0
  112080. };
  112081. static long _vq_quantlist__8c0_s_p6_0[] = {
  112082. 8,
  112083. 7,
  112084. 9,
  112085. 6,
  112086. 10,
  112087. 5,
  112088. 11,
  112089. 4,
  112090. 12,
  112091. 3,
  112092. 13,
  112093. 2,
  112094. 14,
  112095. 1,
  112096. 15,
  112097. 0,
  112098. 16,
  112099. };
  112100. static long _vq_lengthlist__8c0_s_p6_0[] = {
  112101. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  112102. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  112103. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  112104. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  112105. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  112106. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  112107. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  112108. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  112109. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  112110. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  112111. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  112112. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  112113. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  112114. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  112115. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  112116. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  112117. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  112118. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  112119. 14,
  112120. };
  112121. static float _vq_quantthresh__8c0_s_p6_0[] = {
  112122. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  112123. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  112124. };
  112125. static long _vq_quantmap__8c0_s_p6_0[] = {
  112126. 15, 13, 11, 9, 7, 5, 3, 1,
  112127. 0, 2, 4, 6, 8, 10, 12, 14,
  112128. 16,
  112129. };
  112130. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  112131. _vq_quantthresh__8c0_s_p6_0,
  112132. _vq_quantmap__8c0_s_p6_0,
  112133. 17,
  112134. 17
  112135. };
  112136. static static_codebook _8c0_s_p6_0 = {
  112137. 2, 289,
  112138. _vq_lengthlist__8c0_s_p6_0,
  112139. 1, -529530880, 1611661312, 5, 0,
  112140. _vq_quantlist__8c0_s_p6_0,
  112141. NULL,
  112142. &_vq_auxt__8c0_s_p6_0,
  112143. NULL,
  112144. 0
  112145. };
  112146. static long _vq_quantlist__8c0_s_p7_0[] = {
  112147. 1,
  112148. 0,
  112149. 2,
  112150. };
  112151. static long _vq_lengthlist__8c0_s_p7_0[] = {
  112152. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  112153. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  112154. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  112155. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  112156. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  112157. 10,
  112158. };
  112159. static float _vq_quantthresh__8c0_s_p7_0[] = {
  112160. -5.5, 5.5,
  112161. };
  112162. static long _vq_quantmap__8c0_s_p7_0[] = {
  112163. 1, 0, 2,
  112164. };
  112165. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  112166. _vq_quantthresh__8c0_s_p7_0,
  112167. _vq_quantmap__8c0_s_p7_0,
  112168. 3,
  112169. 3
  112170. };
  112171. static static_codebook _8c0_s_p7_0 = {
  112172. 4, 81,
  112173. _vq_lengthlist__8c0_s_p7_0,
  112174. 1, -529137664, 1618345984, 2, 0,
  112175. _vq_quantlist__8c0_s_p7_0,
  112176. NULL,
  112177. &_vq_auxt__8c0_s_p7_0,
  112178. NULL,
  112179. 0
  112180. };
  112181. static long _vq_quantlist__8c0_s_p7_1[] = {
  112182. 5,
  112183. 4,
  112184. 6,
  112185. 3,
  112186. 7,
  112187. 2,
  112188. 8,
  112189. 1,
  112190. 9,
  112191. 0,
  112192. 10,
  112193. };
  112194. static long _vq_lengthlist__8c0_s_p7_1[] = {
  112195. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  112196. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  112197. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  112198. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  112199. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  112200. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  112201. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  112202. 10,10,10, 9, 9, 9,10,10,10,
  112203. };
  112204. static float _vq_quantthresh__8c0_s_p7_1[] = {
  112205. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112206. 3.5, 4.5,
  112207. };
  112208. static long _vq_quantmap__8c0_s_p7_1[] = {
  112209. 9, 7, 5, 3, 1, 0, 2, 4,
  112210. 6, 8, 10,
  112211. };
  112212. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  112213. _vq_quantthresh__8c0_s_p7_1,
  112214. _vq_quantmap__8c0_s_p7_1,
  112215. 11,
  112216. 11
  112217. };
  112218. static static_codebook _8c0_s_p7_1 = {
  112219. 2, 121,
  112220. _vq_lengthlist__8c0_s_p7_1,
  112221. 1, -531365888, 1611661312, 4, 0,
  112222. _vq_quantlist__8c0_s_p7_1,
  112223. NULL,
  112224. &_vq_auxt__8c0_s_p7_1,
  112225. NULL,
  112226. 0
  112227. };
  112228. static long _vq_quantlist__8c0_s_p8_0[] = {
  112229. 6,
  112230. 5,
  112231. 7,
  112232. 4,
  112233. 8,
  112234. 3,
  112235. 9,
  112236. 2,
  112237. 10,
  112238. 1,
  112239. 11,
  112240. 0,
  112241. 12,
  112242. };
  112243. static long _vq_lengthlist__8c0_s_p8_0[] = {
  112244. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  112245. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  112246. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  112247. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  112248. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  112249. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  112250. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  112251. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  112252. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  112253. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  112254. 0, 0,13,13,11,13,13,11,12,
  112255. };
  112256. static float _vq_quantthresh__8c0_s_p8_0[] = {
  112257. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  112258. 12.5, 17.5, 22.5, 27.5,
  112259. };
  112260. static long _vq_quantmap__8c0_s_p8_0[] = {
  112261. 11, 9, 7, 5, 3, 1, 0, 2,
  112262. 4, 6, 8, 10, 12,
  112263. };
  112264. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  112265. _vq_quantthresh__8c0_s_p8_0,
  112266. _vq_quantmap__8c0_s_p8_0,
  112267. 13,
  112268. 13
  112269. };
  112270. static static_codebook _8c0_s_p8_0 = {
  112271. 2, 169,
  112272. _vq_lengthlist__8c0_s_p8_0,
  112273. 1, -526516224, 1616117760, 4, 0,
  112274. _vq_quantlist__8c0_s_p8_0,
  112275. NULL,
  112276. &_vq_auxt__8c0_s_p8_0,
  112277. NULL,
  112278. 0
  112279. };
  112280. static long _vq_quantlist__8c0_s_p8_1[] = {
  112281. 2,
  112282. 1,
  112283. 3,
  112284. 0,
  112285. 4,
  112286. };
  112287. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112288. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112289. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112290. };
  112291. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112292. -1.5, -0.5, 0.5, 1.5,
  112293. };
  112294. static long _vq_quantmap__8c0_s_p8_1[] = {
  112295. 3, 1, 0, 2, 4,
  112296. };
  112297. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112298. _vq_quantthresh__8c0_s_p8_1,
  112299. _vq_quantmap__8c0_s_p8_1,
  112300. 5,
  112301. 5
  112302. };
  112303. static static_codebook _8c0_s_p8_1 = {
  112304. 2, 25,
  112305. _vq_lengthlist__8c0_s_p8_1,
  112306. 1, -533725184, 1611661312, 3, 0,
  112307. _vq_quantlist__8c0_s_p8_1,
  112308. NULL,
  112309. &_vq_auxt__8c0_s_p8_1,
  112310. NULL,
  112311. 0
  112312. };
  112313. static long _vq_quantlist__8c0_s_p9_0[] = {
  112314. 1,
  112315. 0,
  112316. 2,
  112317. };
  112318. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112319. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112320. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112321. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112322. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112323. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112324. 7,
  112325. };
  112326. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112327. -157.5, 157.5,
  112328. };
  112329. static long _vq_quantmap__8c0_s_p9_0[] = {
  112330. 1, 0, 2,
  112331. };
  112332. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112333. _vq_quantthresh__8c0_s_p9_0,
  112334. _vq_quantmap__8c0_s_p9_0,
  112335. 3,
  112336. 3
  112337. };
  112338. static static_codebook _8c0_s_p9_0 = {
  112339. 4, 81,
  112340. _vq_lengthlist__8c0_s_p9_0,
  112341. 1, -518803456, 1628680192, 2, 0,
  112342. _vq_quantlist__8c0_s_p9_0,
  112343. NULL,
  112344. &_vq_auxt__8c0_s_p9_0,
  112345. NULL,
  112346. 0
  112347. };
  112348. static long _vq_quantlist__8c0_s_p9_1[] = {
  112349. 7,
  112350. 6,
  112351. 8,
  112352. 5,
  112353. 9,
  112354. 4,
  112355. 10,
  112356. 3,
  112357. 11,
  112358. 2,
  112359. 12,
  112360. 1,
  112361. 13,
  112362. 0,
  112363. 14,
  112364. };
  112365. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112366. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112367. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112368. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112369. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112370. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112371. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112372. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112373. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112374. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112375. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112376. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112377. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112378. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112379. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112380. 11,
  112381. };
  112382. static float _vq_quantthresh__8c0_s_p9_1[] = {
  112383. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  112384. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  112385. };
  112386. static long _vq_quantmap__8c0_s_p9_1[] = {
  112387. 13, 11, 9, 7, 5, 3, 1, 0,
  112388. 2, 4, 6, 8, 10, 12, 14,
  112389. };
  112390. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  112391. _vq_quantthresh__8c0_s_p9_1,
  112392. _vq_quantmap__8c0_s_p9_1,
  112393. 15,
  112394. 15
  112395. };
  112396. static static_codebook _8c0_s_p9_1 = {
  112397. 2, 225,
  112398. _vq_lengthlist__8c0_s_p9_1,
  112399. 1, -520986624, 1620377600, 4, 0,
  112400. _vq_quantlist__8c0_s_p9_1,
  112401. NULL,
  112402. &_vq_auxt__8c0_s_p9_1,
  112403. NULL,
  112404. 0
  112405. };
  112406. static long _vq_quantlist__8c0_s_p9_2[] = {
  112407. 10,
  112408. 9,
  112409. 11,
  112410. 8,
  112411. 12,
  112412. 7,
  112413. 13,
  112414. 6,
  112415. 14,
  112416. 5,
  112417. 15,
  112418. 4,
  112419. 16,
  112420. 3,
  112421. 17,
  112422. 2,
  112423. 18,
  112424. 1,
  112425. 19,
  112426. 0,
  112427. 20,
  112428. };
  112429. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112430. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112431. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112432. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112433. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112434. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112435. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112436. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112437. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112438. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112439. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112440. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112441. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112442. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112443. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112444. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112445. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112446. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112447. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112448. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112449. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112450. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112451. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112452. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112453. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112454. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112455. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112456. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112457. 10,11, 9,11,10, 9,10, 9,10,
  112458. };
  112459. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112460. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112461. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112462. 6.5, 7.5, 8.5, 9.5,
  112463. };
  112464. static long _vq_quantmap__8c0_s_p9_2[] = {
  112465. 19, 17, 15, 13, 11, 9, 7, 5,
  112466. 3, 1, 0, 2, 4, 6, 8, 10,
  112467. 12, 14, 16, 18, 20,
  112468. };
  112469. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112470. _vq_quantthresh__8c0_s_p9_2,
  112471. _vq_quantmap__8c0_s_p9_2,
  112472. 21,
  112473. 21
  112474. };
  112475. static static_codebook _8c0_s_p9_2 = {
  112476. 2, 441,
  112477. _vq_lengthlist__8c0_s_p9_2,
  112478. 1, -529268736, 1611661312, 5, 0,
  112479. _vq_quantlist__8c0_s_p9_2,
  112480. NULL,
  112481. &_vq_auxt__8c0_s_p9_2,
  112482. NULL,
  112483. 0
  112484. };
  112485. static long _huff_lengthlist__8c0_s_single[] = {
  112486. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112487. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112488. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112489. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112490. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112491. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112492. 17,16,17,17,
  112493. };
  112494. static static_codebook _huff_book__8c0_s_single = {
  112495. 2, 100,
  112496. _huff_lengthlist__8c0_s_single,
  112497. 0, 0, 0, 0, 0,
  112498. NULL,
  112499. NULL,
  112500. NULL,
  112501. NULL,
  112502. 0
  112503. };
  112504. static long _vq_quantlist__8c1_s_p1_0[] = {
  112505. 1,
  112506. 0,
  112507. 2,
  112508. };
  112509. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112510. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112511. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112516. 0, 0, 0, 7, 8, 9, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112521. 0, 0, 0, 0, 7, 9, 8, 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, 5, 8, 8, 0, 0, 0, 0,
  112556. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  112561. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  112566. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112602. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112607. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112612. 0, 0, 0, 0, 0, 0, 8,10, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112920. 0,
  112921. };
  112922. static float _vq_quantthresh__8c1_s_p1_0[] = {
  112923. -0.5, 0.5,
  112924. };
  112925. static long _vq_quantmap__8c1_s_p1_0[] = {
  112926. 1, 0, 2,
  112927. };
  112928. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  112929. _vq_quantthresh__8c1_s_p1_0,
  112930. _vq_quantmap__8c1_s_p1_0,
  112931. 3,
  112932. 3
  112933. };
  112934. static static_codebook _8c1_s_p1_0 = {
  112935. 8, 6561,
  112936. _vq_lengthlist__8c1_s_p1_0,
  112937. 1, -535822336, 1611661312, 2, 0,
  112938. _vq_quantlist__8c1_s_p1_0,
  112939. NULL,
  112940. &_vq_auxt__8c1_s_p1_0,
  112941. NULL,
  112942. 0
  112943. };
  112944. static long _vq_quantlist__8c1_s_p2_0[] = {
  112945. 2,
  112946. 1,
  112947. 3,
  112948. 0,
  112949. 4,
  112950. };
  112951. static long _vq_lengthlist__8c1_s_p2_0[] = {
  112952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112991. 0,
  112992. };
  112993. static float _vq_quantthresh__8c1_s_p2_0[] = {
  112994. -1.5, -0.5, 0.5, 1.5,
  112995. };
  112996. static long _vq_quantmap__8c1_s_p2_0[] = {
  112997. 3, 1, 0, 2, 4,
  112998. };
  112999. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  113000. _vq_quantthresh__8c1_s_p2_0,
  113001. _vq_quantmap__8c1_s_p2_0,
  113002. 5,
  113003. 5
  113004. };
  113005. static static_codebook _8c1_s_p2_0 = {
  113006. 4, 625,
  113007. _vq_lengthlist__8c1_s_p2_0,
  113008. 1, -533725184, 1611661312, 3, 0,
  113009. _vq_quantlist__8c1_s_p2_0,
  113010. NULL,
  113011. &_vq_auxt__8c1_s_p2_0,
  113012. NULL,
  113013. 0
  113014. };
  113015. static long _vq_quantlist__8c1_s_p3_0[] = {
  113016. 2,
  113017. 1,
  113018. 3,
  113019. 0,
  113020. 4,
  113021. };
  113022. static long _vq_lengthlist__8c1_s_p3_0[] = {
  113023. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  113025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113026. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  113028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113029. 0, 0, 0, 0, 6, 6, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113062. 0,
  113063. };
  113064. static float _vq_quantthresh__8c1_s_p3_0[] = {
  113065. -1.5, -0.5, 0.5, 1.5,
  113066. };
  113067. static long _vq_quantmap__8c1_s_p3_0[] = {
  113068. 3, 1, 0, 2, 4,
  113069. };
  113070. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  113071. _vq_quantthresh__8c1_s_p3_0,
  113072. _vq_quantmap__8c1_s_p3_0,
  113073. 5,
  113074. 5
  113075. };
  113076. static static_codebook _8c1_s_p3_0 = {
  113077. 4, 625,
  113078. _vq_lengthlist__8c1_s_p3_0,
  113079. 1, -533725184, 1611661312, 3, 0,
  113080. _vq_quantlist__8c1_s_p3_0,
  113081. NULL,
  113082. &_vq_auxt__8c1_s_p3_0,
  113083. NULL,
  113084. 0
  113085. };
  113086. static long _vq_quantlist__8c1_s_p4_0[] = {
  113087. 4,
  113088. 3,
  113089. 5,
  113090. 2,
  113091. 6,
  113092. 1,
  113093. 7,
  113094. 0,
  113095. 8,
  113096. };
  113097. static long _vq_lengthlist__8c1_s_p4_0[] = {
  113098. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  113099. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  113100. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113101. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  113102. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113103. 0,
  113104. };
  113105. static float _vq_quantthresh__8c1_s_p4_0[] = {
  113106. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113107. };
  113108. static long _vq_quantmap__8c1_s_p4_0[] = {
  113109. 7, 5, 3, 1, 0, 2, 4, 6,
  113110. 8,
  113111. };
  113112. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  113113. _vq_quantthresh__8c1_s_p4_0,
  113114. _vq_quantmap__8c1_s_p4_0,
  113115. 9,
  113116. 9
  113117. };
  113118. static static_codebook _8c1_s_p4_0 = {
  113119. 2, 81,
  113120. _vq_lengthlist__8c1_s_p4_0,
  113121. 1, -531628032, 1611661312, 4, 0,
  113122. _vq_quantlist__8c1_s_p4_0,
  113123. NULL,
  113124. &_vq_auxt__8c1_s_p4_0,
  113125. NULL,
  113126. 0
  113127. };
  113128. static long _vq_quantlist__8c1_s_p5_0[] = {
  113129. 4,
  113130. 3,
  113131. 5,
  113132. 2,
  113133. 6,
  113134. 1,
  113135. 7,
  113136. 0,
  113137. 8,
  113138. };
  113139. static long _vq_lengthlist__8c1_s_p5_0[] = {
  113140. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  113141. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  113142. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  113143. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  113144. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  113145. 10,
  113146. };
  113147. static float _vq_quantthresh__8c1_s_p5_0[] = {
  113148. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113149. };
  113150. static long _vq_quantmap__8c1_s_p5_0[] = {
  113151. 7, 5, 3, 1, 0, 2, 4, 6,
  113152. 8,
  113153. };
  113154. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  113155. _vq_quantthresh__8c1_s_p5_0,
  113156. _vq_quantmap__8c1_s_p5_0,
  113157. 9,
  113158. 9
  113159. };
  113160. static static_codebook _8c1_s_p5_0 = {
  113161. 2, 81,
  113162. _vq_lengthlist__8c1_s_p5_0,
  113163. 1, -531628032, 1611661312, 4, 0,
  113164. _vq_quantlist__8c1_s_p5_0,
  113165. NULL,
  113166. &_vq_auxt__8c1_s_p5_0,
  113167. NULL,
  113168. 0
  113169. };
  113170. static long _vq_quantlist__8c1_s_p6_0[] = {
  113171. 8,
  113172. 7,
  113173. 9,
  113174. 6,
  113175. 10,
  113176. 5,
  113177. 11,
  113178. 4,
  113179. 12,
  113180. 3,
  113181. 13,
  113182. 2,
  113183. 14,
  113184. 1,
  113185. 15,
  113186. 0,
  113187. 16,
  113188. };
  113189. static long _vq_lengthlist__8c1_s_p6_0[] = {
  113190. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  113191. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  113192. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113193. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  113194. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  113195. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  113196. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  113197. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  113198. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  113199. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  113200. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  113201. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  113202. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  113203. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  113204. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  113205. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  113206. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  113207. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  113208. 14,
  113209. };
  113210. static float _vq_quantthresh__8c1_s_p6_0[] = {
  113211. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  113212. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  113213. };
  113214. static long _vq_quantmap__8c1_s_p6_0[] = {
  113215. 15, 13, 11, 9, 7, 5, 3, 1,
  113216. 0, 2, 4, 6, 8, 10, 12, 14,
  113217. 16,
  113218. };
  113219. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  113220. _vq_quantthresh__8c1_s_p6_0,
  113221. _vq_quantmap__8c1_s_p6_0,
  113222. 17,
  113223. 17
  113224. };
  113225. static static_codebook _8c1_s_p6_0 = {
  113226. 2, 289,
  113227. _vq_lengthlist__8c1_s_p6_0,
  113228. 1, -529530880, 1611661312, 5, 0,
  113229. _vq_quantlist__8c1_s_p6_0,
  113230. NULL,
  113231. &_vq_auxt__8c1_s_p6_0,
  113232. NULL,
  113233. 0
  113234. };
  113235. static long _vq_quantlist__8c1_s_p7_0[] = {
  113236. 1,
  113237. 0,
  113238. 2,
  113239. };
  113240. static long _vq_lengthlist__8c1_s_p7_0[] = {
  113241. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  113242. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  113243. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  113244. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  113245. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  113246. 9,
  113247. };
  113248. static float _vq_quantthresh__8c1_s_p7_0[] = {
  113249. -5.5, 5.5,
  113250. };
  113251. static long _vq_quantmap__8c1_s_p7_0[] = {
  113252. 1, 0, 2,
  113253. };
  113254. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  113255. _vq_quantthresh__8c1_s_p7_0,
  113256. _vq_quantmap__8c1_s_p7_0,
  113257. 3,
  113258. 3
  113259. };
  113260. static static_codebook _8c1_s_p7_0 = {
  113261. 4, 81,
  113262. _vq_lengthlist__8c1_s_p7_0,
  113263. 1, -529137664, 1618345984, 2, 0,
  113264. _vq_quantlist__8c1_s_p7_0,
  113265. NULL,
  113266. &_vq_auxt__8c1_s_p7_0,
  113267. NULL,
  113268. 0
  113269. };
  113270. static long _vq_quantlist__8c1_s_p7_1[] = {
  113271. 5,
  113272. 4,
  113273. 6,
  113274. 3,
  113275. 7,
  113276. 2,
  113277. 8,
  113278. 1,
  113279. 9,
  113280. 0,
  113281. 10,
  113282. };
  113283. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113284. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113285. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113286. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113287. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113288. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113289. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113290. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113291. 10,10,10, 8, 8, 8, 8, 8, 8,
  113292. };
  113293. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113294. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113295. 3.5, 4.5,
  113296. };
  113297. static long _vq_quantmap__8c1_s_p7_1[] = {
  113298. 9, 7, 5, 3, 1, 0, 2, 4,
  113299. 6, 8, 10,
  113300. };
  113301. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113302. _vq_quantthresh__8c1_s_p7_1,
  113303. _vq_quantmap__8c1_s_p7_1,
  113304. 11,
  113305. 11
  113306. };
  113307. static static_codebook _8c1_s_p7_1 = {
  113308. 2, 121,
  113309. _vq_lengthlist__8c1_s_p7_1,
  113310. 1, -531365888, 1611661312, 4, 0,
  113311. _vq_quantlist__8c1_s_p7_1,
  113312. NULL,
  113313. &_vq_auxt__8c1_s_p7_1,
  113314. NULL,
  113315. 0
  113316. };
  113317. static long _vq_quantlist__8c1_s_p8_0[] = {
  113318. 6,
  113319. 5,
  113320. 7,
  113321. 4,
  113322. 8,
  113323. 3,
  113324. 9,
  113325. 2,
  113326. 10,
  113327. 1,
  113328. 11,
  113329. 0,
  113330. 12,
  113331. };
  113332. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113333. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113334. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113335. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113336. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113337. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113338. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113339. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113340. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113341. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113342. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113343. 0,12,12,11,10,12,11,13,12,
  113344. };
  113345. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113346. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113347. 12.5, 17.5, 22.5, 27.5,
  113348. };
  113349. static long _vq_quantmap__8c1_s_p8_0[] = {
  113350. 11, 9, 7, 5, 3, 1, 0, 2,
  113351. 4, 6, 8, 10, 12,
  113352. };
  113353. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113354. _vq_quantthresh__8c1_s_p8_0,
  113355. _vq_quantmap__8c1_s_p8_0,
  113356. 13,
  113357. 13
  113358. };
  113359. static static_codebook _8c1_s_p8_0 = {
  113360. 2, 169,
  113361. _vq_lengthlist__8c1_s_p8_0,
  113362. 1, -526516224, 1616117760, 4, 0,
  113363. _vq_quantlist__8c1_s_p8_0,
  113364. NULL,
  113365. &_vq_auxt__8c1_s_p8_0,
  113366. NULL,
  113367. 0
  113368. };
  113369. static long _vq_quantlist__8c1_s_p8_1[] = {
  113370. 2,
  113371. 1,
  113372. 3,
  113373. 0,
  113374. 4,
  113375. };
  113376. static long _vq_lengthlist__8c1_s_p8_1[] = {
  113377. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  113378. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  113379. };
  113380. static float _vq_quantthresh__8c1_s_p8_1[] = {
  113381. -1.5, -0.5, 0.5, 1.5,
  113382. };
  113383. static long _vq_quantmap__8c1_s_p8_1[] = {
  113384. 3, 1, 0, 2, 4,
  113385. };
  113386. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  113387. _vq_quantthresh__8c1_s_p8_1,
  113388. _vq_quantmap__8c1_s_p8_1,
  113389. 5,
  113390. 5
  113391. };
  113392. static static_codebook _8c1_s_p8_1 = {
  113393. 2, 25,
  113394. _vq_lengthlist__8c1_s_p8_1,
  113395. 1, -533725184, 1611661312, 3, 0,
  113396. _vq_quantlist__8c1_s_p8_1,
  113397. NULL,
  113398. &_vq_auxt__8c1_s_p8_1,
  113399. NULL,
  113400. 0
  113401. };
  113402. static long _vq_quantlist__8c1_s_p9_0[] = {
  113403. 6,
  113404. 5,
  113405. 7,
  113406. 4,
  113407. 8,
  113408. 3,
  113409. 9,
  113410. 2,
  113411. 10,
  113412. 1,
  113413. 11,
  113414. 0,
  113415. 12,
  113416. };
  113417. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113418. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113419. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113420. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113421. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113422. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113423. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113424. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113425. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113426. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113427. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113428. 10,10,10,10,10, 9, 9, 9, 9,
  113429. };
  113430. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113431. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113432. 787.5, 1102.5, 1417.5, 1732.5,
  113433. };
  113434. static long _vq_quantmap__8c1_s_p9_0[] = {
  113435. 11, 9, 7, 5, 3, 1, 0, 2,
  113436. 4, 6, 8, 10, 12,
  113437. };
  113438. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113439. _vq_quantthresh__8c1_s_p9_0,
  113440. _vq_quantmap__8c1_s_p9_0,
  113441. 13,
  113442. 13
  113443. };
  113444. static static_codebook _8c1_s_p9_0 = {
  113445. 2, 169,
  113446. _vq_lengthlist__8c1_s_p9_0,
  113447. 1, -513964032, 1628680192, 4, 0,
  113448. _vq_quantlist__8c1_s_p9_0,
  113449. NULL,
  113450. &_vq_auxt__8c1_s_p9_0,
  113451. NULL,
  113452. 0
  113453. };
  113454. static long _vq_quantlist__8c1_s_p9_1[] = {
  113455. 7,
  113456. 6,
  113457. 8,
  113458. 5,
  113459. 9,
  113460. 4,
  113461. 10,
  113462. 3,
  113463. 11,
  113464. 2,
  113465. 12,
  113466. 1,
  113467. 13,
  113468. 0,
  113469. 14,
  113470. };
  113471. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113472. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113473. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113474. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113475. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113476. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113477. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113478. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113479. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113480. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113481. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113482. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113483. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113484. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113485. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113486. 15,
  113487. };
  113488. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113489. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113490. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113491. };
  113492. static long _vq_quantmap__8c1_s_p9_1[] = {
  113493. 13, 11, 9, 7, 5, 3, 1, 0,
  113494. 2, 4, 6, 8, 10, 12, 14,
  113495. };
  113496. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113497. _vq_quantthresh__8c1_s_p9_1,
  113498. _vq_quantmap__8c1_s_p9_1,
  113499. 15,
  113500. 15
  113501. };
  113502. static static_codebook _8c1_s_p9_1 = {
  113503. 2, 225,
  113504. _vq_lengthlist__8c1_s_p9_1,
  113505. 1, -520986624, 1620377600, 4, 0,
  113506. _vq_quantlist__8c1_s_p9_1,
  113507. NULL,
  113508. &_vq_auxt__8c1_s_p9_1,
  113509. NULL,
  113510. 0
  113511. };
  113512. static long _vq_quantlist__8c1_s_p9_2[] = {
  113513. 10,
  113514. 9,
  113515. 11,
  113516. 8,
  113517. 12,
  113518. 7,
  113519. 13,
  113520. 6,
  113521. 14,
  113522. 5,
  113523. 15,
  113524. 4,
  113525. 16,
  113526. 3,
  113527. 17,
  113528. 2,
  113529. 18,
  113530. 1,
  113531. 19,
  113532. 0,
  113533. 20,
  113534. };
  113535. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113536. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113537. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113538. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113539. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113540. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113541. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113542. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113543. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113544. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113545. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113546. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113547. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113548. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113549. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113550. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113551. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113552. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113553. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113554. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113555. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113556. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113557. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113558. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113559. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113560. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113561. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113562. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113563. 10,10,10,10,10,10,10,10,10,
  113564. };
  113565. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113566. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113567. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113568. 6.5, 7.5, 8.5, 9.5,
  113569. };
  113570. static long _vq_quantmap__8c1_s_p9_2[] = {
  113571. 19, 17, 15, 13, 11, 9, 7, 5,
  113572. 3, 1, 0, 2, 4, 6, 8, 10,
  113573. 12, 14, 16, 18, 20,
  113574. };
  113575. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113576. _vq_quantthresh__8c1_s_p9_2,
  113577. _vq_quantmap__8c1_s_p9_2,
  113578. 21,
  113579. 21
  113580. };
  113581. static static_codebook _8c1_s_p9_2 = {
  113582. 2, 441,
  113583. _vq_lengthlist__8c1_s_p9_2,
  113584. 1, -529268736, 1611661312, 5, 0,
  113585. _vq_quantlist__8c1_s_p9_2,
  113586. NULL,
  113587. &_vq_auxt__8c1_s_p9_2,
  113588. NULL,
  113589. 0
  113590. };
  113591. static long _huff_lengthlist__8c1_s_single[] = {
  113592. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113593. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113594. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113595. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113596. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113597. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113598. 9, 7, 7, 8,
  113599. };
  113600. static static_codebook _huff_book__8c1_s_single = {
  113601. 2, 100,
  113602. _huff_lengthlist__8c1_s_single,
  113603. 0, 0, 0, 0, 0,
  113604. NULL,
  113605. NULL,
  113606. NULL,
  113607. NULL,
  113608. 0
  113609. };
  113610. static long _huff_lengthlist__44c2_s_long[] = {
  113611. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113612. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113613. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113614. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113615. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113616. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113617. 10, 8, 8, 9,
  113618. };
  113619. static static_codebook _huff_book__44c2_s_long = {
  113620. 2, 100,
  113621. _huff_lengthlist__44c2_s_long,
  113622. 0, 0, 0, 0, 0,
  113623. NULL,
  113624. NULL,
  113625. NULL,
  113626. NULL,
  113627. 0
  113628. };
  113629. static long _vq_quantlist__44c2_s_p1_0[] = {
  113630. 1,
  113631. 0,
  113632. 2,
  113633. };
  113634. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113635. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113636. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113641. 0, 0, 0, 6, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113646. 0, 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0,
  113681. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  113686. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  113691. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113727. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113732. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113737. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113916. 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113924. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114045. 0,
  114046. };
  114047. static float _vq_quantthresh__44c2_s_p1_0[] = {
  114048. -0.5, 0.5,
  114049. };
  114050. static long _vq_quantmap__44c2_s_p1_0[] = {
  114051. 1, 0, 2,
  114052. };
  114053. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  114054. _vq_quantthresh__44c2_s_p1_0,
  114055. _vq_quantmap__44c2_s_p1_0,
  114056. 3,
  114057. 3
  114058. };
  114059. static static_codebook _44c2_s_p1_0 = {
  114060. 8, 6561,
  114061. _vq_lengthlist__44c2_s_p1_0,
  114062. 1, -535822336, 1611661312, 2, 0,
  114063. _vq_quantlist__44c2_s_p1_0,
  114064. NULL,
  114065. &_vq_auxt__44c2_s_p1_0,
  114066. NULL,
  114067. 0
  114068. };
  114069. static long _vq_quantlist__44c2_s_p2_0[] = {
  114070. 2,
  114071. 1,
  114072. 3,
  114073. 0,
  114074. 4,
  114075. };
  114076. static long _vq_lengthlist__44c2_s_p2_0[] = {
  114077. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  114078. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  114079. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  114080. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  114081. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114086. 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  114087. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  114088. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  114089. 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114094. 0, 0, 0, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  114095. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  114096. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0,
  114097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114102. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  114103. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  114104. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 0, 0, 0, 0, 0,
  114105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114116. 0,
  114117. };
  114118. static float _vq_quantthresh__44c2_s_p2_0[] = {
  114119. -1.5, -0.5, 0.5, 1.5,
  114120. };
  114121. static long _vq_quantmap__44c2_s_p2_0[] = {
  114122. 3, 1, 0, 2, 4,
  114123. };
  114124. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  114125. _vq_quantthresh__44c2_s_p2_0,
  114126. _vq_quantmap__44c2_s_p2_0,
  114127. 5,
  114128. 5
  114129. };
  114130. static static_codebook _44c2_s_p2_0 = {
  114131. 4, 625,
  114132. _vq_lengthlist__44c2_s_p2_0,
  114133. 1, -533725184, 1611661312, 3, 0,
  114134. _vq_quantlist__44c2_s_p2_0,
  114135. NULL,
  114136. &_vq_auxt__44c2_s_p2_0,
  114137. NULL,
  114138. 0
  114139. };
  114140. static long _vq_quantlist__44c2_s_p3_0[] = {
  114141. 2,
  114142. 1,
  114143. 3,
  114144. 0,
  114145. 4,
  114146. };
  114147. static long _vq_lengthlist__44c2_s_p3_0[] = {
  114148. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  114150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114151. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  114153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114154. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  114155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114187. 0,
  114188. };
  114189. static float _vq_quantthresh__44c2_s_p3_0[] = {
  114190. -1.5, -0.5, 0.5, 1.5,
  114191. };
  114192. static long _vq_quantmap__44c2_s_p3_0[] = {
  114193. 3, 1, 0, 2, 4,
  114194. };
  114195. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  114196. _vq_quantthresh__44c2_s_p3_0,
  114197. _vq_quantmap__44c2_s_p3_0,
  114198. 5,
  114199. 5
  114200. };
  114201. static static_codebook _44c2_s_p3_0 = {
  114202. 4, 625,
  114203. _vq_lengthlist__44c2_s_p3_0,
  114204. 1, -533725184, 1611661312, 3, 0,
  114205. _vq_quantlist__44c2_s_p3_0,
  114206. NULL,
  114207. &_vq_auxt__44c2_s_p3_0,
  114208. NULL,
  114209. 0
  114210. };
  114211. static long _vq_quantlist__44c2_s_p4_0[] = {
  114212. 4,
  114213. 3,
  114214. 5,
  114215. 2,
  114216. 6,
  114217. 1,
  114218. 7,
  114219. 0,
  114220. 8,
  114221. };
  114222. static long _vq_lengthlist__44c2_s_p4_0[] = {
  114223. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  114224. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  114225. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  114226. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  114227. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114228. 0,
  114229. };
  114230. static float _vq_quantthresh__44c2_s_p4_0[] = {
  114231. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114232. };
  114233. static long _vq_quantmap__44c2_s_p4_0[] = {
  114234. 7, 5, 3, 1, 0, 2, 4, 6,
  114235. 8,
  114236. };
  114237. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  114238. _vq_quantthresh__44c2_s_p4_0,
  114239. _vq_quantmap__44c2_s_p4_0,
  114240. 9,
  114241. 9
  114242. };
  114243. static static_codebook _44c2_s_p4_0 = {
  114244. 2, 81,
  114245. _vq_lengthlist__44c2_s_p4_0,
  114246. 1, -531628032, 1611661312, 4, 0,
  114247. _vq_quantlist__44c2_s_p4_0,
  114248. NULL,
  114249. &_vq_auxt__44c2_s_p4_0,
  114250. NULL,
  114251. 0
  114252. };
  114253. static long _vq_quantlist__44c2_s_p5_0[] = {
  114254. 4,
  114255. 3,
  114256. 5,
  114257. 2,
  114258. 6,
  114259. 1,
  114260. 7,
  114261. 0,
  114262. 8,
  114263. };
  114264. static long _vq_lengthlist__44c2_s_p5_0[] = {
  114265. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  114266. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  114267. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  114268. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  114269. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  114270. 11,
  114271. };
  114272. static float _vq_quantthresh__44c2_s_p5_0[] = {
  114273. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114274. };
  114275. static long _vq_quantmap__44c2_s_p5_0[] = {
  114276. 7, 5, 3, 1, 0, 2, 4, 6,
  114277. 8,
  114278. };
  114279. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  114280. _vq_quantthresh__44c2_s_p5_0,
  114281. _vq_quantmap__44c2_s_p5_0,
  114282. 9,
  114283. 9
  114284. };
  114285. static static_codebook _44c2_s_p5_0 = {
  114286. 2, 81,
  114287. _vq_lengthlist__44c2_s_p5_0,
  114288. 1, -531628032, 1611661312, 4, 0,
  114289. _vq_quantlist__44c2_s_p5_0,
  114290. NULL,
  114291. &_vq_auxt__44c2_s_p5_0,
  114292. NULL,
  114293. 0
  114294. };
  114295. static long _vq_quantlist__44c2_s_p6_0[] = {
  114296. 8,
  114297. 7,
  114298. 9,
  114299. 6,
  114300. 10,
  114301. 5,
  114302. 11,
  114303. 4,
  114304. 12,
  114305. 3,
  114306. 13,
  114307. 2,
  114308. 14,
  114309. 1,
  114310. 15,
  114311. 0,
  114312. 16,
  114313. };
  114314. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114315. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114316. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114317. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114318. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114319. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114320. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114321. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114322. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114323. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114324. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114325. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114326. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114327. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114328. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114329. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114330. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114331. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114332. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114333. 14,
  114334. };
  114335. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114336. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114337. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114338. };
  114339. static long _vq_quantmap__44c2_s_p6_0[] = {
  114340. 15, 13, 11, 9, 7, 5, 3, 1,
  114341. 0, 2, 4, 6, 8, 10, 12, 14,
  114342. 16,
  114343. };
  114344. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114345. _vq_quantthresh__44c2_s_p6_0,
  114346. _vq_quantmap__44c2_s_p6_0,
  114347. 17,
  114348. 17
  114349. };
  114350. static static_codebook _44c2_s_p6_0 = {
  114351. 2, 289,
  114352. _vq_lengthlist__44c2_s_p6_0,
  114353. 1, -529530880, 1611661312, 5, 0,
  114354. _vq_quantlist__44c2_s_p6_0,
  114355. NULL,
  114356. &_vq_auxt__44c2_s_p6_0,
  114357. NULL,
  114358. 0
  114359. };
  114360. static long _vq_quantlist__44c2_s_p7_0[] = {
  114361. 1,
  114362. 0,
  114363. 2,
  114364. };
  114365. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114366. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114367. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114368. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114369. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114370. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114371. 11,
  114372. };
  114373. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114374. -5.5, 5.5,
  114375. };
  114376. static long _vq_quantmap__44c2_s_p7_0[] = {
  114377. 1, 0, 2,
  114378. };
  114379. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  114380. _vq_quantthresh__44c2_s_p7_0,
  114381. _vq_quantmap__44c2_s_p7_0,
  114382. 3,
  114383. 3
  114384. };
  114385. static static_codebook _44c2_s_p7_0 = {
  114386. 4, 81,
  114387. _vq_lengthlist__44c2_s_p7_0,
  114388. 1, -529137664, 1618345984, 2, 0,
  114389. _vq_quantlist__44c2_s_p7_0,
  114390. NULL,
  114391. &_vq_auxt__44c2_s_p7_0,
  114392. NULL,
  114393. 0
  114394. };
  114395. static long _vq_quantlist__44c2_s_p7_1[] = {
  114396. 5,
  114397. 4,
  114398. 6,
  114399. 3,
  114400. 7,
  114401. 2,
  114402. 8,
  114403. 1,
  114404. 9,
  114405. 0,
  114406. 10,
  114407. };
  114408. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114409. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114410. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114411. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114412. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114413. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114414. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114415. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114416. 10,10,10, 8, 8, 8, 8, 8, 8,
  114417. };
  114418. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114419. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114420. 3.5, 4.5,
  114421. };
  114422. static long _vq_quantmap__44c2_s_p7_1[] = {
  114423. 9, 7, 5, 3, 1, 0, 2, 4,
  114424. 6, 8, 10,
  114425. };
  114426. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114427. _vq_quantthresh__44c2_s_p7_1,
  114428. _vq_quantmap__44c2_s_p7_1,
  114429. 11,
  114430. 11
  114431. };
  114432. static static_codebook _44c2_s_p7_1 = {
  114433. 2, 121,
  114434. _vq_lengthlist__44c2_s_p7_1,
  114435. 1, -531365888, 1611661312, 4, 0,
  114436. _vq_quantlist__44c2_s_p7_1,
  114437. NULL,
  114438. &_vq_auxt__44c2_s_p7_1,
  114439. NULL,
  114440. 0
  114441. };
  114442. static long _vq_quantlist__44c2_s_p8_0[] = {
  114443. 6,
  114444. 5,
  114445. 7,
  114446. 4,
  114447. 8,
  114448. 3,
  114449. 9,
  114450. 2,
  114451. 10,
  114452. 1,
  114453. 11,
  114454. 0,
  114455. 12,
  114456. };
  114457. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114458. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114459. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114460. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114461. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114462. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114463. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114464. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114465. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114466. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114467. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114468. 0,12,12,12,12,13,12,14,14,
  114469. };
  114470. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114471. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114472. 12.5, 17.5, 22.5, 27.5,
  114473. };
  114474. static long _vq_quantmap__44c2_s_p8_0[] = {
  114475. 11, 9, 7, 5, 3, 1, 0, 2,
  114476. 4, 6, 8, 10, 12,
  114477. };
  114478. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114479. _vq_quantthresh__44c2_s_p8_0,
  114480. _vq_quantmap__44c2_s_p8_0,
  114481. 13,
  114482. 13
  114483. };
  114484. static static_codebook _44c2_s_p8_0 = {
  114485. 2, 169,
  114486. _vq_lengthlist__44c2_s_p8_0,
  114487. 1, -526516224, 1616117760, 4, 0,
  114488. _vq_quantlist__44c2_s_p8_0,
  114489. NULL,
  114490. &_vq_auxt__44c2_s_p8_0,
  114491. NULL,
  114492. 0
  114493. };
  114494. static long _vq_quantlist__44c2_s_p8_1[] = {
  114495. 2,
  114496. 1,
  114497. 3,
  114498. 0,
  114499. 4,
  114500. };
  114501. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114502. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114503. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114504. };
  114505. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114506. -1.5, -0.5, 0.5, 1.5,
  114507. };
  114508. static long _vq_quantmap__44c2_s_p8_1[] = {
  114509. 3, 1, 0, 2, 4,
  114510. };
  114511. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114512. _vq_quantthresh__44c2_s_p8_1,
  114513. _vq_quantmap__44c2_s_p8_1,
  114514. 5,
  114515. 5
  114516. };
  114517. static static_codebook _44c2_s_p8_1 = {
  114518. 2, 25,
  114519. _vq_lengthlist__44c2_s_p8_1,
  114520. 1, -533725184, 1611661312, 3, 0,
  114521. _vq_quantlist__44c2_s_p8_1,
  114522. NULL,
  114523. &_vq_auxt__44c2_s_p8_1,
  114524. NULL,
  114525. 0
  114526. };
  114527. static long _vq_quantlist__44c2_s_p9_0[] = {
  114528. 6,
  114529. 5,
  114530. 7,
  114531. 4,
  114532. 8,
  114533. 3,
  114534. 9,
  114535. 2,
  114536. 10,
  114537. 1,
  114538. 11,
  114539. 0,
  114540. 12,
  114541. };
  114542. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114543. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114544. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114545. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114546. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114547. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114548. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114549. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114550. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114551. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114552. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114553. 11,11,11,11,11,11,11,11,11,
  114554. };
  114555. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114556. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114557. 552.5, 773.5, 994.5, 1215.5,
  114558. };
  114559. static long _vq_quantmap__44c2_s_p9_0[] = {
  114560. 11, 9, 7, 5, 3, 1, 0, 2,
  114561. 4, 6, 8, 10, 12,
  114562. };
  114563. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114564. _vq_quantthresh__44c2_s_p9_0,
  114565. _vq_quantmap__44c2_s_p9_0,
  114566. 13,
  114567. 13
  114568. };
  114569. static static_codebook _44c2_s_p9_0 = {
  114570. 2, 169,
  114571. _vq_lengthlist__44c2_s_p9_0,
  114572. 1, -514541568, 1627103232, 4, 0,
  114573. _vq_quantlist__44c2_s_p9_0,
  114574. NULL,
  114575. &_vq_auxt__44c2_s_p9_0,
  114576. NULL,
  114577. 0
  114578. };
  114579. static long _vq_quantlist__44c2_s_p9_1[] = {
  114580. 6,
  114581. 5,
  114582. 7,
  114583. 4,
  114584. 8,
  114585. 3,
  114586. 9,
  114587. 2,
  114588. 10,
  114589. 1,
  114590. 11,
  114591. 0,
  114592. 12,
  114593. };
  114594. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114595. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114596. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114597. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114598. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114599. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114600. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114601. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114602. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114603. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114604. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114605. 17,13,12,12,10,13,11,14,14,
  114606. };
  114607. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114608. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114609. 42.5, 59.5, 76.5, 93.5,
  114610. };
  114611. static long _vq_quantmap__44c2_s_p9_1[] = {
  114612. 11, 9, 7, 5, 3, 1, 0, 2,
  114613. 4, 6, 8, 10, 12,
  114614. };
  114615. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114616. _vq_quantthresh__44c2_s_p9_1,
  114617. _vq_quantmap__44c2_s_p9_1,
  114618. 13,
  114619. 13
  114620. };
  114621. static static_codebook _44c2_s_p9_1 = {
  114622. 2, 169,
  114623. _vq_lengthlist__44c2_s_p9_1,
  114624. 1, -522616832, 1620115456, 4, 0,
  114625. _vq_quantlist__44c2_s_p9_1,
  114626. NULL,
  114627. &_vq_auxt__44c2_s_p9_1,
  114628. NULL,
  114629. 0
  114630. };
  114631. static long _vq_quantlist__44c2_s_p9_2[] = {
  114632. 8,
  114633. 7,
  114634. 9,
  114635. 6,
  114636. 10,
  114637. 5,
  114638. 11,
  114639. 4,
  114640. 12,
  114641. 3,
  114642. 13,
  114643. 2,
  114644. 14,
  114645. 1,
  114646. 15,
  114647. 0,
  114648. 16,
  114649. };
  114650. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114651. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114652. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114653. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114654. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114655. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114656. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114657. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114658. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114659. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114660. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114661. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114662. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114663. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114664. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114665. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114666. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114667. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114668. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114669. 10,
  114670. };
  114671. static float _vq_quantthresh__44c2_s_p9_2[] = {
  114672. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114673. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114674. };
  114675. static long _vq_quantmap__44c2_s_p9_2[] = {
  114676. 15, 13, 11, 9, 7, 5, 3, 1,
  114677. 0, 2, 4, 6, 8, 10, 12, 14,
  114678. 16,
  114679. };
  114680. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  114681. _vq_quantthresh__44c2_s_p9_2,
  114682. _vq_quantmap__44c2_s_p9_2,
  114683. 17,
  114684. 17
  114685. };
  114686. static static_codebook _44c2_s_p9_2 = {
  114687. 2, 289,
  114688. _vq_lengthlist__44c2_s_p9_2,
  114689. 1, -529530880, 1611661312, 5, 0,
  114690. _vq_quantlist__44c2_s_p9_2,
  114691. NULL,
  114692. &_vq_auxt__44c2_s_p9_2,
  114693. NULL,
  114694. 0
  114695. };
  114696. static long _huff_lengthlist__44c2_s_short[] = {
  114697. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  114698. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  114699. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  114700. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  114701. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  114702. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  114703. 6, 8, 9,12,
  114704. };
  114705. static static_codebook _huff_book__44c2_s_short = {
  114706. 2, 100,
  114707. _huff_lengthlist__44c2_s_short,
  114708. 0, 0, 0, 0, 0,
  114709. NULL,
  114710. NULL,
  114711. NULL,
  114712. NULL,
  114713. 0
  114714. };
  114715. static long _huff_lengthlist__44c3_s_long[] = {
  114716. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  114717. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  114718. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  114719. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  114720. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  114721. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  114722. 9, 8, 8, 8,
  114723. };
  114724. static static_codebook _huff_book__44c3_s_long = {
  114725. 2, 100,
  114726. _huff_lengthlist__44c3_s_long,
  114727. 0, 0, 0, 0, 0,
  114728. NULL,
  114729. NULL,
  114730. NULL,
  114731. NULL,
  114732. 0
  114733. };
  114734. static long _vq_quantlist__44c3_s_p1_0[] = {
  114735. 1,
  114736. 0,
  114737. 2,
  114738. };
  114739. static long _vq_lengthlist__44c3_s_p1_0[] = {
  114740. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  114741. 0, 0, 5, 6, 6, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114746. 0, 0, 0, 6, 7, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  114751. 0, 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0,
  114786. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  114791. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  114796. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114832. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114837. 0, 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114842. 0, 0, 0, 0, 0, 0, 8, 9, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115021. 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115029. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115150. 0,
  115151. };
  115152. static float _vq_quantthresh__44c3_s_p1_0[] = {
  115153. -0.5, 0.5,
  115154. };
  115155. static long _vq_quantmap__44c3_s_p1_0[] = {
  115156. 1, 0, 2,
  115157. };
  115158. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  115159. _vq_quantthresh__44c3_s_p1_0,
  115160. _vq_quantmap__44c3_s_p1_0,
  115161. 3,
  115162. 3
  115163. };
  115164. static static_codebook _44c3_s_p1_0 = {
  115165. 8, 6561,
  115166. _vq_lengthlist__44c3_s_p1_0,
  115167. 1, -535822336, 1611661312, 2, 0,
  115168. _vq_quantlist__44c3_s_p1_0,
  115169. NULL,
  115170. &_vq_auxt__44c3_s_p1_0,
  115171. NULL,
  115172. 0
  115173. };
  115174. static long _vq_quantlist__44c3_s_p2_0[] = {
  115175. 2,
  115176. 1,
  115177. 3,
  115178. 0,
  115179. 4,
  115180. };
  115181. static long _vq_lengthlist__44c3_s_p2_0[] = {
  115182. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  115183. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  115184. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115185. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  115186. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115191. 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  115192. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  115193. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  115194. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115199. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115200. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115201. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  115202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115207. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  115208. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  115209. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115221. 0,
  115222. };
  115223. static float _vq_quantthresh__44c3_s_p2_0[] = {
  115224. -1.5, -0.5, 0.5, 1.5,
  115225. };
  115226. static long _vq_quantmap__44c3_s_p2_0[] = {
  115227. 3, 1, 0, 2, 4,
  115228. };
  115229. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  115230. _vq_quantthresh__44c3_s_p2_0,
  115231. _vq_quantmap__44c3_s_p2_0,
  115232. 5,
  115233. 5
  115234. };
  115235. static static_codebook _44c3_s_p2_0 = {
  115236. 4, 625,
  115237. _vq_lengthlist__44c3_s_p2_0,
  115238. 1, -533725184, 1611661312, 3, 0,
  115239. _vq_quantlist__44c3_s_p2_0,
  115240. NULL,
  115241. &_vq_auxt__44c3_s_p2_0,
  115242. NULL,
  115243. 0
  115244. };
  115245. static long _vq_quantlist__44c3_s_p3_0[] = {
  115246. 2,
  115247. 1,
  115248. 3,
  115249. 0,
  115250. 4,
  115251. };
  115252. static long _vq_lengthlist__44c3_s_p3_0[] = {
  115253. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  115255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115256. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  115258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115259. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115292. 0,
  115293. };
  115294. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115295. -1.5, -0.5, 0.5, 1.5,
  115296. };
  115297. static long _vq_quantmap__44c3_s_p3_0[] = {
  115298. 3, 1, 0, 2, 4,
  115299. };
  115300. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115301. _vq_quantthresh__44c3_s_p3_0,
  115302. _vq_quantmap__44c3_s_p3_0,
  115303. 5,
  115304. 5
  115305. };
  115306. static static_codebook _44c3_s_p3_0 = {
  115307. 4, 625,
  115308. _vq_lengthlist__44c3_s_p3_0,
  115309. 1, -533725184, 1611661312, 3, 0,
  115310. _vq_quantlist__44c3_s_p3_0,
  115311. NULL,
  115312. &_vq_auxt__44c3_s_p3_0,
  115313. NULL,
  115314. 0
  115315. };
  115316. static long _vq_quantlist__44c3_s_p4_0[] = {
  115317. 4,
  115318. 3,
  115319. 5,
  115320. 2,
  115321. 6,
  115322. 1,
  115323. 7,
  115324. 0,
  115325. 8,
  115326. };
  115327. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115328. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115329. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115330. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115331. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115332. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115333. 0,
  115334. };
  115335. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115336. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115337. };
  115338. static long _vq_quantmap__44c3_s_p4_0[] = {
  115339. 7, 5, 3, 1, 0, 2, 4, 6,
  115340. 8,
  115341. };
  115342. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115343. _vq_quantthresh__44c3_s_p4_0,
  115344. _vq_quantmap__44c3_s_p4_0,
  115345. 9,
  115346. 9
  115347. };
  115348. static static_codebook _44c3_s_p4_0 = {
  115349. 2, 81,
  115350. _vq_lengthlist__44c3_s_p4_0,
  115351. 1, -531628032, 1611661312, 4, 0,
  115352. _vq_quantlist__44c3_s_p4_0,
  115353. NULL,
  115354. &_vq_auxt__44c3_s_p4_0,
  115355. NULL,
  115356. 0
  115357. };
  115358. static long _vq_quantlist__44c3_s_p5_0[] = {
  115359. 4,
  115360. 3,
  115361. 5,
  115362. 2,
  115363. 6,
  115364. 1,
  115365. 7,
  115366. 0,
  115367. 8,
  115368. };
  115369. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115370. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115371. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115372. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115373. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115374. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115375. 11,
  115376. };
  115377. static float _vq_quantthresh__44c3_s_p5_0[] = {
  115378. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115379. };
  115380. static long _vq_quantmap__44c3_s_p5_0[] = {
  115381. 7, 5, 3, 1, 0, 2, 4, 6,
  115382. 8,
  115383. };
  115384. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  115385. _vq_quantthresh__44c3_s_p5_0,
  115386. _vq_quantmap__44c3_s_p5_0,
  115387. 9,
  115388. 9
  115389. };
  115390. static static_codebook _44c3_s_p5_0 = {
  115391. 2, 81,
  115392. _vq_lengthlist__44c3_s_p5_0,
  115393. 1, -531628032, 1611661312, 4, 0,
  115394. _vq_quantlist__44c3_s_p5_0,
  115395. NULL,
  115396. &_vq_auxt__44c3_s_p5_0,
  115397. NULL,
  115398. 0
  115399. };
  115400. static long _vq_quantlist__44c3_s_p6_0[] = {
  115401. 8,
  115402. 7,
  115403. 9,
  115404. 6,
  115405. 10,
  115406. 5,
  115407. 11,
  115408. 4,
  115409. 12,
  115410. 3,
  115411. 13,
  115412. 2,
  115413. 14,
  115414. 1,
  115415. 15,
  115416. 0,
  115417. 16,
  115418. };
  115419. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115420. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115421. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115422. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115423. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115424. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115425. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115426. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115427. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115428. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115429. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115430. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115431. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115432. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115433. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115434. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115435. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115436. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115437. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115438. 13,
  115439. };
  115440. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115441. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115442. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115443. };
  115444. static long _vq_quantmap__44c3_s_p6_0[] = {
  115445. 15, 13, 11, 9, 7, 5, 3, 1,
  115446. 0, 2, 4, 6, 8, 10, 12, 14,
  115447. 16,
  115448. };
  115449. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115450. _vq_quantthresh__44c3_s_p6_0,
  115451. _vq_quantmap__44c3_s_p6_0,
  115452. 17,
  115453. 17
  115454. };
  115455. static static_codebook _44c3_s_p6_0 = {
  115456. 2, 289,
  115457. _vq_lengthlist__44c3_s_p6_0,
  115458. 1, -529530880, 1611661312, 5, 0,
  115459. _vq_quantlist__44c3_s_p6_0,
  115460. NULL,
  115461. &_vq_auxt__44c3_s_p6_0,
  115462. NULL,
  115463. 0
  115464. };
  115465. static long _vq_quantlist__44c3_s_p7_0[] = {
  115466. 1,
  115467. 0,
  115468. 2,
  115469. };
  115470. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115471. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115472. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115473. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115474. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115475. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115476. 10,
  115477. };
  115478. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115479. -5.5, 5.5,
  115480. };
  115481. static long _vq_quantmap__44c3_s_p7_0[] = {
  115482. 1, 0, 2,
  115483. };
  115484. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115485. _vq_quantthresh__44c3_s_p7_0,
  115486. _vq_quantmap__44c3_s_p7_0,
  115487. 3,
  115488. 3
  115489. };
  115490. static static_codebook _44c3_s_p7_0 = {
  115491. 4, 81,
  115492. _vq_lengthlist__44c3_s_p7_0,
  115493. 1, -529137664, 1618345984, 2, 0,
  115494. _vq_quantlist__44c3_s_p7_0,
  115495. NULL,
  115496. &_vq_auxt__44c3_s_p7_0,
  115497. NULL,
  115498. 0
  115499. };
  115500. static long _vq_quantlist__44c3_s_p7_1[] = {
  115501. 5,
  115502. 4,
  115503. 6,
  115504. 3,
  115505. 7,
  115506. 2,
  115507. 8,
  115508. 1,
  115509. 9,
  115510. 0,
  115511. 10,
  115512. };
  115513. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115514. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115515. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115516. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115517. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115518. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115519. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115520. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115521. 10,10,10, 8, 8, 8, 8, 8, 8,
  115522. };
  115523. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115524. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115525. 3.5, 4.5,
  115526. };
  115527. static long _vq_quantmap__44c3_s_p7_1[] = {
  115528. 9, 7, 5, 3, 1, 0, 2, 4,
  115529. 6, 8, 10,
  115530. };
  115531. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115532. _vq_quantthresh__44c3_s_p7_1,
  115533. _vq_quantmap__44c3_s_p7_1,
  115534. 11,
  115535. 11
  115536. };
  115537. static static_codebook _44c3_s_p7_1 = {
  115538. 2, 121,
  115539. _vq_lengthlist__44c3_s_p7_1,
  115540. 1, -531365888, 1611661312, 4, 0,
  115541. _vq_quantlist__44c3_s_p7_1,
  115542. NULL,
  115543. &_vq_auxt__44c3_s_p7_1,
  115544. NULL,
  115545. 0
  115546. };
  115547. static long _vq_quantlist__44c3_s_p8_0[] = {
  115548. 6,
  115549. 5,
  115550. 7,
  115551. 4,
  115552. 8,
  115553. 3,
  115554. 9,
  115555. 2,
  115556. 10,
  115557. 1,
  115558. 11,
  115559. 0,
  115560. 12,
  115561. };
  115562. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115563. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115564. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115565. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115566. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115567. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115568. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115569. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115570. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115571. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115572. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115573. 0,13,13,12,12,13,12,14,13,
  115574. };
  115575. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115576. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115577. 12.5, 17.5, 22.5, 27.5,
  115578. };
  115579. static long _vq_quantmap__44c3_s_p8_0[] = {
  115580. 11, 9, 7, 5, 3, 1, 0, 2,
  115581. 4, 6, 8, 10, 12,
  115582. };
  115583. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115584. _vq_quantthresh__44c3_s_p8_0,
  115585. _vq_quantmap__44c3_s_p8_0,
  115586. 13,
  115587. 13
  115588. };
  115589. static static_codebook _44c3_s_p8_0 = {
  115590. 2, 169,
  115591. _vq_lengthlist__44c3_s_p8_0,
  115592. 1, -526516224, 1616117760, 4, 0,
  115593. _vq_quantlist__44c3_s_p8_0,
  115594. NULL,
  115595. &_vq_auxt__44c3_s_p8_0,
  115596. NULL,
  115597. 0
  115598. };
  115599. static long _vq_quantlist__44c3_s_p8_1[] = {
  115600. 2,
  115601. 1,
  115602. 3,
  115603. 0,
  115604. 4,
  115605. };
  115606. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115607. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115608. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115609. };
  115610. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115611. -1.5, -0.5, 0.5, 1.5,
  115612. };
  115613. static long _vq_quantmap__44c3_s_p8_1[] = {
  115614. 3, 1, 0, 2, 4,
  115615. };
  115616. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115617. _vq_quantthresh__44c3_s_p8_1,
  115618. _vq_quantmap__44c3_s_p8_1,
  115619. 5,
  115620. 5
  115621. };
  115622. static static_codebook _44c3_s_p8_1 = {
  115623. 2, 25,
  115624. _vq_lengthlist__44c3_s_p8_1,
  115625. 1, -533725184, 1611661312, 3, 0,
  115626. _vq_quantlist__44c3_s_p8_1,
  115627. NULL,
  115628. &_vq_auxt__44c3_s_p8_1,
  115629. NULL,
  115630. 0
  115631. };
  115632. static long _vq_quantlist__44c3_s_p9_0[] = {
  115633. 6,
  115634. 5,
  115635. 7,
  115636. 4,
  115637. 8,
  115638. 3,
  115639. 9,
  115640. 2,
  115641. 10,
  115642. 1,
  115643. 11,
  115644. 0,
  115645. 12,
  115646. };
  115647. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115648. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115649. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115650. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115651. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115652. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115653. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115654. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115655. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115656. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115657. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115658. 11,11,11,11,11,11,11,11,11,
  115659. };
  115660. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115661. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115662. 637.5, 892.5, 1147.5, 1402.5,
  115663. };
  115664. static long _vq_quantmap__44c3_s_p9_0[] = {
  115665. 11, 9, 7, 5, 3, 1, 0, 2,
  115666. 4, 6, 8, 10, 12,
  115667. };
  115668. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115669. _vq_quantthresh__44c3_s_p9_0,
  115670. _vq_quantmap__44c3_s_p9_0,
  115671. 13,
  115672. 13
  115673. };
  115674. static static_codebook _44c3_s_p9_0 = {
  115675. 2, 169,
  115676. _vq_lengthlist__44c3_s_p9_0,
  115677. 1, -514332672, 1627381760, 4, 0,
  115678. _vq_quantlist__44c3_s_p9_0,
  115679. NULL,
  115680. &_vq_auxt__44c3_s_p9_0,
  115681. NULL,
  115682. 0
  115683. };
  115684. static long _vq_quantlist__44c3_s_p9_1[] = {
  115685. 7,
  115686. 6,
  115687. 8,
  115688. 5,
  115689. 9,
  115690. 4,
  115691. 10,
  115692. 3,
  115693. 11,
  115694. 2,
  115695. 12,
  115696. 1,
  115697. 13,
  115698. 0,
  115699. 14,
  115700. };
  115701. static long _vq_lengthlist__44c3_s_p9_1[] = {
  115702. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  115703. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  115704. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  115705. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  115706. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  115707. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  115708. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  115709. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  115710. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  115711. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  115712. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  115713. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  115714. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  115715. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  115716. 15,
  115717. };
  115718. static float _vq_quantthresh__44c3_s_p9_1[] = {
  115719. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  115720. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  115721. };
  115722. static long _vq_quantmap__44c3_s_p9_1[] = {
  115723. 13, 11, 9, 7, 5, 3, 1, 0,
  115724. 2, 4, 6, 8, 10, 12, 14,
  115725. };
  115726. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  115727. _vq_quantthresh__44c3_s_p9_1,
  115728. _vq_quantmap__44c3_s_p9_1,
  115729. 15,
  115730. 15
  115731. };
  115732. static static_codebook _44c3_s_p9_1 = {
  115733. 2, 225,
  115734. _vq_lengthlist__44c3_s_p9_1,
  115735. 1, -522338304, 1620115456, 4, 0,
  115736. _vq_quantlist__44c3_s_p9_1,
  115737. NULL,
  115738. &_vq_auxt__44c3_s_p9_1,
  115739. NULL,
  115740. 0
  115741. };
  115742. static long _vq_quantlist__44c3_s_p9_2[] = {
  115743. 8,
  115744. 7,
  115745. 9,
  115746. 6,
  115747. 10,
  115748. 5,
  115749. 11,
  115750. 4,
  115751. 12,
  115752. 3,
  115753. 13,
  115754. 2,
  115755. 14,
  115756. 1,
  115757. 15,
  115758. 0,
  115759. 16,
  115760. };
  115761. static long _vq_lengthlist__44c3_s_p9_2[] = {
  115762. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  115763. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  115764. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  115765. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  115766. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  115767. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  115768. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  115769. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  115770. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  115771. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  115772. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  115773. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  115774. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  115775. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  115776. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  115777. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  115778. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  115779. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  115780. 10,
  115781. };
  115782. static float _vq_quantthresh__44c3_s_p9_2[] = {
  115783. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115784. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115785. };
  115786. static long _vq_quantmap__44c3_s_p9_2[] = {
  115787. 15, 13, 11, 9, 7, 5, 3, 1,
  115788. 0, 2, 4, 6, 8, 10, 12, 14,
  115789. 16,
  115790. };
  115791. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  115792. _vq_quantthresh__44c3_s_p9_2,
  115793. _vq_quantmap__44c3_s_p9_2,
  115794. 17,
  115795. 17
  115796. };
  115797. static static_codebook _44c3_s_p9_2 = {
  115798. 2, 289,
  115799. _vq_lengthlist__44c3_s_p9_2,
  115800. 1, -529530880, 1611661312, 5, 0,
  115801. _vq_quantlist__44c3_s_p9_2,
  115802. NULL,
  115803. &_vq_auxt__44c3_s_p9_2,
  115804. NULL,
  115805. 0
  115806. };
  115807. static long _huff_lengthlist__44c3_s_short[] = {
  115808. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  115809. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  115810. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  115811. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  115812. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  115813. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  115814. 6, 8, 9,11,
  115815. };
  115816. static static_codebook _huff_book__44c3_s_short = {
  115817. 2, 100,
  115818. _huff_lengthlist__44c3_s_short,
  115819. 0, 0, 0, 0, 0,
  115820. NULL,
  115821. NULL,
  115822. NULL,
  115823. NULL,
  115824. 0
  115825. };
  115826. static long _huff_lengthlist__44c4_s_long[] = {
  115827. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  115828. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  115829. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  115830. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  115831. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  115832. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  115833. 9, 8, 7, 7,
  115834. };
  115835. static static_codebook _huff_book__44c4_s_long = {
  115836. 2, 100,
  115837. _huff_lengthlist__44c4_s_long,
  115838. 0, 0, 0, 0, 0,
  115839. NULL,
  115840. NULL,
  115841. NULL,
  115842. NULL,
  115843. 0
  115844. };
  115845. static long _vq_quantlist__44c4_s_p1_0[] = {
  115846. 1,
  115847. 0,
  115848. 2,
  115849. };
  115850. static long _vq_lengthlist__44c4_s_p1_0[] = {
  115851. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  115852. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115857. 0, 0, 0, 6, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  115862. 0, 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0,
  115897. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  115902. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  115907. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115943. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115948. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115953. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116132. 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116140. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116261. 0,
  116262. };
  116263. static float _vq_quantthresh__44c4_s_p1_0[] = {
  116264. -0.5, 0.5,
  116265. };
  116266. static long _vq_quantmap__44c4_s_p1_0[] = {
  116267. 1, 0, 2,
  116268. };
  116269. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  116270. _vq_quantthresh__44c4_s_p1_0,
  116271. _vq_quantmap__44c4_s_p1_0,
  116272. 3,
  116273. 3
  116274. };
  116275. static static_codebook _44c4_s_p1_0 = {
  116276. 8, 6561,
  116277. _vq_lengthlist__44c4_s_p1_0,
  116278. 1, -535822336, 1611661312, 2, 0,
  116279. _vq_quantlist__44c4_s_p1_0,
  116280. NULL,
  116281. &_vq_auxt__44c4_s_p1_0,
  116282. NULL,
  116283. 0
  116284. };
  116285. static long _vq_quantlist__44c4_s_p2_0[] = {
  116286. 2,
  116287. 1,
  116288. 3,
  116289. 0,
  116290. 4,
  116291. };
  116292. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116293. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116294. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116295. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116296. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116297. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116302. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116303. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116304. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116305. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116310. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116311. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116312. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  116313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116318. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116319. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116320. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116332. 0,
  116333. };
  116334. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116335. -1.5, -0.5, 0.5, 1.5,
  116336. };
  116337. static long _vq_quantmap__44c4_s_p2_0[] = {
  116338. 3, 1, 0, 2, 4,
  116339. };
  116340. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116341. _vq_quantthresh__44c4_s_p2_0,
  116342. _vq_quantmap__44c4_s_p2_0,
  116343. 5,
  116344. 5
  116345. };
  116346. static static_codebook _44c4_s_p2_0 = {
  116347. 4, 625,
  116348. _vq_lengthlist__44c4_s_p2_0,
  116349. 1, -533725184, 1611661312, 3, 0,
  116350. _vq_quantlist__44c4_s_p2_0,
  116351. NULL,
  116352. &_vq_auxt__44c4_s_p2_0,
  116353. NULL,
  116354. 0
  116355. };
  116356. static long _vq_quantlist__44c4_s_p3_0[] = {
  116357. 2,
  116358. 1,
  116359. 3,
  116360. 0,
  116361. 4,
  116362. };
  116363. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116364. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116367. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116370. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116403. 0,
  116404. };
  116405. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116406. -1.5, -0.5, 0.5, 1.5,
  116407. };
  116408. static long _vq_quantmap__44c4_s_p3_0[] = {
  116409. 3, 1, 0, 2, 4,
  116410. };
  116411. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116412. _vq_quantthresh__44c4_s_p3_0,
  116413. _vq_quantmap__44c4_s_p3_0,
  116414. 5,
  116415. 5
  116416. };
  116417. static static_codebook _44c4_s_p3_0 = {
  116418. 4, 625,
  116419. _vq_lengthlist__44c4_s_p3_0,
  116420. 1, -533725184, 1611661312, 3, 0,
  116421. _vq_quantlist__44c4_s_p3_0,
  116422. NULL,
  116423. &_vq_auxt__44c4_s_p3_0,
  116424. NULL,
  116425. 0
  116426. };
  116427. static long _vq_quantlist__44c4_s_p4_0[] = {
  116428. 4,
  116429. 3,
  116430. 5,
  116431. 2,
  116432. 6,
  116433. 1,
  116434. 7,
  116435. 0,
  116436. 8,
  116437. };
  116438. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116439. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116440. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116441. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116442. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116443. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116444. 0,
  116445. };
  116446. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116447. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116448. };
  116449. static long _vq_quantmap__44c4_s_p4_0[] = {
  116450. 7, 5, 3, 1, 0, 2, 4, 6,
  116451. 8,
  116452. };
  116453. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116454. _vq_quantthresh__44c4_s_p4_0,
  116455. _vq_quantmap__44c4_s_p4_0,
  116456. 9,
  116457. 9
  116458. };
  116459. static static_codebook _44c4_s_p4_0 = {
  116460. 2, 81,
  116461. _vq_lengthlist__44c4_s_p4_0,
  116462. 1, -531628032, 1611661312, 4, 0,
  116463. _vq_quantlist__44c4_s_p4_0,
  116464. NULL,
  116465. &_vq_auxt__44c4_s_p4_0,
  116466. NULL,
  116467. 0
  116468. };
  116469. static long _vq_quantlist__44c4_s_p5_0[] = {
  116470. 4,
  116471. 3,
  116472. 5,
  116473. 2,
  116474. 6,
  116475. 1,
  116476. 7,
  116477. 0,
  116478. 8,
  116479. };
  116480. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116481. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116482. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116483. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116484. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116485. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116486. 10,
  116487. };
  116488. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116489. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116490. };
  116491. static long _vq_quantmap__44c4_s_p5_0[] = {
  116492. 7, 5, 3, 1, 0, 2, 4, 6,
  116493. 8,
  116494. };
  116495. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116496. _vq_quantthresh__44c4_s_p5_0,
  116497. _vq_quantmap__44c4_s_p5_0,
  116498. 9,
  116499. 9
  116500. };
  116501. static static_codebook _44c4_s_p5_0 = {
  116502. 2, 81,
  116503. _vq_lengthlist__44c4_s_p5_0,
  116504. 1, -531628032, 1611661312, 4, 0,
  116505. _vq_quantlist__44c4_s_p5_0,
  116506. NULL,
  116507. &_vq_auxt__44c4_s_p5_0,
  116508. NULL,
  116509. 0
  116510. };
  116511. static long _vq_quantlist__44c4_s_p6_0[] = {
  116512. 8,
  116513. 7,
  116514. 9,
  116515. 6,
  116516. 10,
  116517. 5,
  116518. 11,
  116519. 4,
  116520. 12,
  116521. 3,
  116522. 13,
  116523. 2,
  116524. 14,
  116525. 1,
  116526. 15,
  116527. 0,
  116528. 16,
  116529. };
  116530. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116531. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116532. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116533. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116534. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116535. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116536. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116537. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116538. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116539. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116540. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116541. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116542. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116543. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116544. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116545. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116546. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116547. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116548. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116549. 13,
  116550. };
  116551. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116552. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116553. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116554. };
  116555. static long _vq_quantmap__44c4_s_p6_0[] = {
  116556. 15, 13, 11, 9, 7, 5, 3, 1,
  116557. 0, 2, 4, 6, 8, 10, 12, 14,
  116558. 16,
  116559. };
  116560. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116561. _vq_quantthresh__44c4_s_p6_0,
  116562. _vq_quantmap__44c4_s_p6_0,
  116563. 17,
  116564. 17
  116565. };
  116566. static static_codebook _44c4_s_p6_0 = {
  116567. 2, 289,
  116568. _vq_lengthlist__44c4_s_p6_0,
  116569. 1, -529530880, 1611661312, 5, 0,
  116570. _vq_quantlist__44c4_s_p6_0,
  116571. NULL,
  116572. &_vq_auxt__44c4_s_p6_0,
  116573. NULL,
  116574. 0
  116575. };
  116576. static long _vq_quantlist__44c4_s_p7_0[] = {
  116577. 1,
  116578. 0,
  116579. 2,
  116580. };
  116581. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116582. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116583. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116584. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116585. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116586. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116587. 10,
  116588. };
  116589. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116590. -5.5, 5.5,
  116591. };
  116592. static long _vq_quantmap__44c4_s_p7_0[] = {
  116593. 1, 0, 2,
  116594. };
  116595. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116596. _vq_quantthresh__44c4_s_p7_0,
  116597. _vq_quantmap__44c4_s_p7_0,
  116598. 3,
  116599. 3
  116600. };
  116601. static static_codebook _44c4_s_p7_0 = {
  116602. 4, 81,
  116603. _vq_lengthlist__44c4_s_p7_0,
  116604. 1, -529137664, 1618345984, 2, 0,
  116605. _vq_quantlist__44c4_s_p7_0,
  116606. NULL,
  116607. &_vq_auxt__44c4_s_p7_0,
  116608. NULL,
  116609. 0
  116610. };
  116611. static long _vq_quantlist__44c4_s_p7_1[] = {
  116612. 5,
  116613. 4,
  116614. 6,
  116615. 3,
  116616. 7,
  116617. 2,
  116618. 8,
  116619. 1,
  116620. 9,
  116621. 0,
  116622. 10,
  116623. };
  116624. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116625. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116626. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116627. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116628. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116629. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116630. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116631. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116632. 10,10,10, 8, 8, 8, 8, 9, 9,
  116633. };
  116634. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116635. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116636. 3.5, 4.5,
  116637. };
  116638. static long _vq_quantmap__44c4_s_p7_1[] = {
  116639. 9, 7, 5, 3, 1, 0, 2, 4,
  116640. 6, 8, 10,
  116641. };
  116642. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116643. _vq_quantthresh__44c4_s_p7_1,
  116644. _vq_quantmap__44c4_s_p7_1,
  116645. 11,
  116646. 11
  116647. };
  116648. static static_codebook _44c4_s_p7_1 = {
  116649. 2, 121,
  116650. _vq_lengthlist__44c4_s_p7_1,
  116651. 1, -531365888, 1611661312, 4, 0,
  116652. _vq_quantlist__44c4_s_p7_1,
  116653. NULL,
  116654. &_vq_auxt__44c4_s_p7_1,
  116655. NULL,
  116656. 0
  116657. };
  116658. static long _vq_quantlist__44c4_s_p8_0[] = {
  116659. 6,
  116660. 5,
  116661. 7,
  116662. 4,
  116663. 8,
  116664. 3,
  116665. 9,
  116666. 2,
  116667. 10,
  116668. 1,
  116669. 11,
  116670. 0,
  116671. 12,
  116672. };
  116673. static long _vq_lengthlist__44c4_s_p8_0[] = {
  116674. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116675. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  116676. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116677. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  116678. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  116679. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  116680. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  116681. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  116682. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  116683. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  116684. 0,13,12,12,12,12,12,13,13,
  116685. };
  116686. static float _vq_quantthresh__44c4_s_p8_0[] = {
  116687. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  116688. 12.5, 17.5, 22.5, 27.5,
  116689. };
  116690. static long _vq_quantmap__44c4_s_p8_0[] = {
  116691. 11, 9, 7, 5, 3, 1, 0, 2,
  116692. 4, 6, 8, 10, 12,
  116693. };
  116694. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  116695. _vq_quantthresh__44c4_s_p8_0,
  116696. _vq_quantmap__44c4_s_p8_0,
  116697. 13,
  116698. 13
  116699. };
  116700. static static_codebook _44c4_s_p8_0 = {
  116701. 2, 169,
  116702. _vq_lengthlist__44c4_s_p8_0,
  116703. 1, -526516224, 1616117760, 4, 0,
  116704. _vq_quantlist__44c4_s_p8_0,
  116705. NULL,
  116706. &_vq_auxt__44c4_s_p8_0,
  116707. NULL,
  116708. 0
  116709. };
  116710. static long _vq_quantlist__44c4_s_p8_1[] = {
  116711. 2,
  116712. 1,
  116713. 3,
  116714. 0,
  116715. 4,
  116716. };
  116717. static long _vq_lengthlist__44c4_s_p8_1[] = {
  116718. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  116719. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  116720. };
  116721. static float _vq_quantthresh__44c4_s_p8_1[] = {
  116722. -1.5, -0.5, 0.5, 1.5,
  116723. };
  116724. static long _vq_quantmap__44c4_s_p8_1[] = {
  116725. 3, 1, 0, 2, 4,
  116726. };
  116727. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  116728. _vq_quantthresh__44c4_s_p8_1,
  116729. _vq_quantmap__44c4_s_p8_1,
  116730. 5,
  116731. 5
  116732. };
  116733. static static_codebook _44c4_s_p8_1 = {
  116734. 2, 25,
  116735. _vq_lengthlist__44c4_s_p8_1,
  116736. 1, -533725184, 1611661312, 3, 0,
  116737. _vq_quantlist__44c4_s_p8_1,
  116738. NULL,
  116739. &_vq_auxt__44c4_s_p8_1,
  116740. NULL,
  116741. 0
  116742. };
  116743. static long _vq_quantlist__44c4_s_p9_0[] = {
  116744. 6,
  116745. 5,
  116746. 7,
  116747. 4,
  116748. 8,
  116749. 3,
  116750. 9,
  116751. 2,
  116752. 10,
  116753. 1,
  116754. 11,
  116755. 0,
  116756. 12,
  116757. };
  116758. static long _vq_lengthlist__44c4_s_p9_0[] = {
  116759. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  116760. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  116761. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116762. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116763. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116764. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116765. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116766. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116767. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116768. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116769. 12,12,12,12,12,12,12,12,12,
  116770. };
  116771. static float _vq_quantthresh__44c4_s_p9_0[] = {
  116772. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  116773. 787.5, 1102.5, 1417.5, 1732.5,
  116774. };
  116775. static long _vq_quantmap__44c4_s_p9_0[] = {
  116776. 11, 9, 7, 5, 3, 1, 0, 2,
  116777. 4, 6, 8, 10, 12,
  116778. };
  116779. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  116780. _vq_quantthresh__44c4_s_p9_0,
  116781. _vq_quantmap__44c4_s_p9_0,
  116782. 13,
  116783. 13
  116784. };
  116785. static static_codebook _44c4_s_p9_0 = {
  116786. 2, 169,
  116787. _vq_lengthlist__44c4_s_p9_0,
  116788. 1, -513964032, 1628680192, 4, 0,
  116789. _vq_quantlist__44c4_s_p9_0,
  116790. NULL,
  116791. &_vq_auxt__44c4_s_p9_0,
  116792. NULL,
  116793. 0
  116794. };
  116795. static long _vq_quantlist__44c4_s_p9_1[] = {
  116796. 7,
  116797. 6,
  116798. 8,
  116799. 5,
  116800. 9,
  116801. 4,
  116802. 10,
  116803. 3,
  116804. 11,
  116805. 2,
  116806. 12,
  116807. 1,
  116808. 13,
  116809. 0,
  116810. 14,
  116811. };
  116812. static long _vq_lengthlist__44c4_s_p9_1[] = {
  116813. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  116814. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  116815. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  116816. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  116817. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  116818. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  116819. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  116820. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  116821. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  116822. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  116823. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  116824. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  116825. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  116826. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  116827. 15,
  116828. };
  116829. static float _vq_quantthresh__44c4_s_p9_1[] = {
  116830. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  116831. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  116832. };
  116833. static long _vq_quantmap__44c4_s_p9_1[] = {
  116834. 13, 11, 9, 7, 5, 3, 1, 0,
  116835. 2, 4, 6, 8, 10, 12, 14,
  116836. };
  116837. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  116838. _vq_quantthresh__44c4_s_p9_1,
  116839. _vq_quantmap__44c4_s_p9_1,
  116840. 15,
  116841. 15
  116842. };
  116843. static static_codebook _44c4_s_p9_1 = {
  116844. 2, 225,
  116845. _vq_lengthlist__44c4_s_p9_1,
  116846. 1, -520986624, 1620377600, 4, 0,
  116847. _vq_quantlist__44c4_s_p9_1,
  116848. NULL,
  116849. &_vq_auxt__44c4_s_p9_1,
  116850. NULL,
  116851. 0
  116852. };
  116853. static long _vq_quantlist__44c4_s_p9_2[] = {
  116854. 10,
  116855. 9,
  116856. 11,
  116857. 8,
  116858. 12,
  116859. 7,
  116860. 13,
  116861. 6,
  116862. 14,
  116863. 5,
  116864. 15,
  116865. 4,
  116866. 16,
  116867. 3,
  116868. 17,
  116869. 2,
  116870. 18,
  116871. 1,
  116872. 19,
  116873. 0,
  116874. 20,
  116875. };
  116876. static long _vq_lengthlist__44c4_s_p9_2[] = {
  116877. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  116878. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  116879. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  116880. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  116881. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  116882. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  116883. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  116884. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  116885. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  116886. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  116887. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  116888. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  116889. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  116890. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  116891. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  116892. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  116893. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  116894. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  116895. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  116896. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  116897. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  116898. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  116899. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  116900. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  116901. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  116902. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  116903. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  116904. 10,10,10,10,10,10,10,10,10,
  116905. };
  116906. static float _vq_quantthresh__44c4_s_p9_2[] = {
  116907. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  116908. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  116909. 6.5, 7.5, 8.5, 9.5,
  116910. };
  116911. static long _vq_quantmap__44c4_s_p9_2[] = {
  116912. 19, 17, 15, 13, 11, 9, 7, 5,
  116913. 3, 1, 0, 2, 4, 6, 8, 10,
  116914. 12, 14, 16, 18, 20,
  116915. };
  116916. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  116917. _vq_quantthresh__44c4_s_p9_2,
  116918. _vq_quantmap__44c4_s_p9_2,
  116919. 21,
  116920. 21
  116921. };
  116922. static static_codebook _44c4_s_p9_2 = {
  116923. 2, 441,
  116924. _vq_lengthlist__44c4_s_p9_2,
  116925. 1, -529268736, 1611661312, 5, 0,
  116926. _vq_quantlist__44c4_s_p9_2,
  116927. NULL,
  116928. &_vq_auxt__44c4_s_p9_2,
  116929. NULL,
  116930. 0
  116931. };
  116932. static long _huff_lengthlist__44c4_s_short[] = {
  116933. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  116934. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  116935. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  116936. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  116937. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  116938. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  116939. 7, 9,12,17,
  116940. };
  116941. static static_codebook _huff_book__44c4_s_short = {
  116942. 2, 100,
  116943. _huff_lengthlist__44c4_s_short,
  116944. 0, 0, 0, 0, 0,
  116945. NULL,
  116946. NULL,
  116947. NULL,
  116948. NULL,
  116949. 0
  116950. };
  116951. static long _huff_lengthlist__44c5_s_long[] = {
  116952. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  116953. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  116954. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  116955. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  116956. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  116957. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  116958. 9, 8, 7, 7,
  116959. };
  116960. static static_codebook _huff_book__44c5_s_long = {
  116961. 2, 100,
  116962. _huff_lengthlist__44c5_s_long,
  116963. 0, 0, 0, 0, 0,
  116964. NULL,
  116965. NULL,
  116966. NULL,
  116967. NULL,
  116968. 0
  116969. };
  116970. static long _vq_quantlist__44c5_s_p1_0[] = {
  116971. 1,
  116972. 0,
  116973. 2,
  116974. };
  116975. static long _vq_lengthlist__44c5_s_p1_0[] = {
  116976. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116977. 0, 0, 4, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  116982. 0, 0, 0, 7, 8, 9, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  116987. 0, 0, 0, 0, 7, 9, 9, 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, 4, 7, 7, 0, 0, 0, 0,
  117022. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  117027. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  117032. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117068. 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  117073. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  117078. 0, 0, 0, 0, 0, 0, 9,11,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117257. 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117265. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117386. 0,
  117387. };
  117388. static float _vq_quantthresh__44c5_s_p1_0[] = {
  117389. -0.5, 0.5,
  117390. };
  117391. static long _vq_quantmap__44c5_s_p1_0[] = {
  117392. 1, 0, 2,
  117393. };
  117394. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117395. _vq_quantthresh__44c5_s_p1_0,
  117396. _vq_quantmap__44c5_s_p1_0,
  117397. 3,
  117398. 3
  117399. };
  117400. static static_codebook _44c5_s_p1_0 = {
  117401. 8, 6561,
  117402. _vq_lengthlist__44c5_s_p1_0,
  117403. 1, -535822336, 1611661312, 2, 0,
  117404. _vq_quantlist__44c5_s_p1_0,
  117405. NULL,
  117406. &_vq_auxt__44c5_s_p1_0,
  117407. NULL,
  117408. 0
  117409. };
  117410. static long _vq_quantlist__44c5_s_p2_0[] = {
  117411. 2,
  117412. 1,
  117413. 3,
  117414. 0,
  117415. 4,
  117416. };
  117417. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117418. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117419. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117420. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117421. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117422. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117427. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117428. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117429. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117430. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117435. 0, 0, 0, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117436. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117437. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 0, 0,
  117438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117443. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117444. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117445. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 0, 0, 0, 0, 0,
  117446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117457. 0,
  117458. };
  117459. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117460. -1.5, -0.5, 0.5, 1.5,
  117461. };
  117462. static long _vq_quantmap__44c5_s_p2_0[] = {
  117463. 3, 1, 0, 2, 4,
  117464. };
  117465. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117466. _vq_quantthresh__44c5_s_p2_0,
  117467. _vq_quantmap__44c5_s_p2_0,
  117468. 5,
  117469. 5
  117470. };
  117471. static static_codebook _44c5_s_p2_0 = {
  117472. 4, 625,
  117473. _vq_lengthlist__44c5_s_p2_0,
  117474. 1, -533725184, 1611661312, 3, 0,
  117475. _vq_quantlist__44c5_s_p2_0,
  117476. NULL,
  117477. &_vq_auxt__44c5_s_p2_0,
  117478. NULL,
  117479. 0
  117480. };
  117481. static long _vq_quantlist__44c5_s_p3_0[] = {
  117482. 2,
  117483. 1,
  117484. 3,
  117485. 0,
  117486. 4,
  117487. };
  117488. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117489. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117492. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117495. 0, 0, 0, 0, 5, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  117496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117528. 0,
  117529. };
  117530. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117531. -1.5, -0.5, 0.5, 1.5,
  117532. };
  117533. static long _vq_quantmap__44c5_s_p3_0[] = {
  117534. 3, 1, 0, 2, 4,
  117535. };
  117536. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117537. _vq_quantthresh__44c5_s_p3_0,
  117538. _vq_quantmap__44c5_s_p3_0,
  117539. 5,
  117540. 5
  117541. };
  117542. static static_codebook _44c5_s_p3_0 = {
  117543. 4, 625,
  117544. _vq_lengthlist__44c5_s_p3_0,
  117545. 1, -533725184, 1611661312, 3, 0,
  117546. _vq_quantlist__44c5_s_p3_0,
  117547. NULL,
  117548. &_vq_auxt__44c5_s_p3_0,
  117549. NULL,
  117550. 0
  117551. };
  117552. static long _vq_quantlist__44c5_s_p4_0[] = {
  117553. 4,
  117554. 3,
  117555. 5,
  117556. 2,
  117557. 6,
  117558. 1,
  117559. 7,
  117560. 0,
  117561. 8,
  117562. };
  117563. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117564. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117565. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117566. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117567. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117568. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117569. 0,
  117570. };
  117571. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117572. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117573. };
  117574. static long _vq_quantmap__44c5_s_p4_0[] = {
  117575. 7, 5, 3, 1, 0, 2, 4, 6,
  117576. 8,
  117577. };
  117578. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117579. _vq_quantthresh__44c5_s_p4_0,
  117580. _vq_quantmap__44c5_s_p4_0,
  117581. 9,
  117582. 9
  117583. };
  117584. static static_codebook _44c5_s_p4_0 = {
  117585. 2, 81,
  117586. _vq_lengthlist__44c5_s_p4_0,
  117587. 1, -531628032, 1611661312, 4, 0,
  117588. _vq_quantlist__44c5_s_p4_0,
  117589. NULL,
  117590. &_vq_auxt__44c5_s_p4_0,
  117591. NULL,
  117592. 0
  117593. };
  117594. static long _vq_quantlist__44c5_s_p5_0[] = {
  117595. 4,
  117596. 3,
  117597. 5,
  117598. 2,
  117599. 6,
  117600. 1,
  117601. 7,
  117602. 0,
  117603. 8,
  117604. };
  117605. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117606. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117607. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117608. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117609. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117610. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117611. 10,
  117612. };
  117613. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117614. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117615. };
  117616. static long _vq_quantmap__44c5_s_p5_0[] = {
  117617. 7, 5, 3, 1, 0, 2, 4, 6,
  117618. 8,
  117619. };
  117620. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117621. _vq_quantthresh__44c5_s_p5_0,
  117622. _vq_quantmap__44c5_s_p5_0,
  117623. 9,
  117624. 9
  117625. };
  117626. static static_codebook _44c5_s_p5_0 = {
  117627. 2, 81,
  117628. _vq_lengthlist__44c5_s_p5_0,
  117629. 1, -531628032, 1611661312, 4, 0,
  117630. _vq_quantlist__44c5_s_p5_0,
  117631. NULL,
  117632. &_vq_auxt__44c5_s_p5_0,
  117633. NULL,
  117634. 0
  117635. };
  117636. static long _vq_quantlist__44c5_s_p6_0[] = {
  117637. 8,
  117638. 7,
  117639. 9,
  117640. 6,
  117641. 10,
  117642. 5,
  117643. 11,
  117644. 4,
  117645. 12,
  117646. 3,
  117647. 13,
  117648. 2,
  117649. 14,
  117650. 1,
  117651. 15,
  117652. 0,
  117653. 16,
  117654. };
  117655. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117656. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117657. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117658. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117659. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117660. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117661. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117662. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117663. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117664. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117665. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117666. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117667. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117668. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117669. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117670. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  117671. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117672. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  117673. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  117674. 13,
  117675. };
  117676. static float _vq_quantthresh__44c5_s_p6_0[] = {
  117677. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117678. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117679. };
  117680. static long _vq_quantmap__44c5_s_p6_0[] = {
  117681. 15, 13, 11, 9, 7, 5, 3, 1,
  117682. 0, 2, 4, 6, 8, 10, 12, 14,
  117683. 16,
  117684. };
  117685. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  117686. _vq_quantthresh__44c5_s_p6_0,
  117687. _vq_quantmap__44c5_s_p6_0,
  117688. 17,
  117689. 17
  117690. };
  117691. static static_codebook _44c5_s_p6_0 = {
  117692. 2, 289,
  117693. _vq_lengthlist__44c5_s_p6_0,
  117694. 1, -529530880, 1611661312, 5, 0,
  117695. _vq_quantlist__44c5_s_p6_0,
  117696. NULL,
  117697. &_vq_auxt__44c5_s_p6_0,
  117698. NULL,
  117699. 0
  117700. };
  117701. static long _vq_quantlist__44c5_s_p7_0[] = {
  117702. 1,
  117703. 0,
  117704. 2,
  117705. };
  117706. static long _vq_lengthlist__44c5_s_p7_0[] = {
  117707. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  117708. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  117709. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  117710. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  117711. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  117712. 10,
  117713. };
  117714. static float _vq_quantthresh__44c5_s_p7_0[] = {
  117715. -5.5, 5.5,
  117716. };
  117717. static long _vq_quantmap__44c5_s_p7_0[] = {
  117718. 1, 0, 2,
  117719. };
  117720. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  117721. _vq_quantthresh__44c5_s_p7_0,
  117722. _vq_quantmap__44c5_s_p7_0,
  117723. 3,
  117724. 3
  117725. };
  117726. static static_codebook _44c5_s_p7_0 = {
  117727. 4, 81,
  117728. _vq_lengthlist__44c5_s_p7_0,
  117729. 1, -529137664, 1618345984, 2, 0,
  117730. _vq_quantlist__44c5_s_p7_0,
  117731. NULL,
  117732. &_vq_auxt__44c5_s_p7_0,
  117733. NULL,
  117734. 0
  117735. };
  117736. static long _vq_quantlist__44c5_s_p7_1[] = {
  117737. 5,
  117738. 4,
  117739. 6,
  117740. 3,
  117741. 7,
  117742. 2,
  117743. 8,
  117744. 1,
  117745. 9,
  117746. 0,
  117747. 10,
  117748. };
  117749. static long _vq_lengthlist__44c5_s_p7_1[] = {
  117750. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  117751. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  117752. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  117753. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  117754. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  117755. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  117756. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  117757. 10,10,10, 8, 8, 8, 8, 8, 8,
  117758. };
  117759. static float _vq_quantthresh__44c5_s_p7_1[] = {
  117760. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  117761. 3.5, 4.5,
  117762. };
  117763. static long _vq_quantmap__44c5_s_p7_1[] = {
  117764. 9, 7, 5, 3, 1, 0, 2, 4,
  117765. 6, 8, 10,
  117766. };
  117767. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  117768. _vq_quantthresh__44c5_s_p7_1,
  117769. _vq_quantmap__44c5_s_p7_1,
  117770. 11,
  117771. 11
  117772. };
  117773. static static_codebook _44c5_s_p7_1 = {
  117774. 2, 121,
  117775. _vq_lengthlist__44c5_s_p7_1,
  117776. 1, -531365888, 1611661312, 4, 0,
  117777. _vq_quantlist__44c5_s_p7_1,
  117778. NULL,
  117779. &_vq_auxt__44c5_s_p7_1,
  117780. NULL,
  117781. 0
  117782. };
  117783. static long _vq_quantlist__44c5_s_p8_0[] = {
  117784. 6,
  117785. 5,
  117786. 7,
  117787. 4,
  117788. 8,
  117789. 3,
  117790. 9,
  117791. 2,
  117792. 10,
  117793. 1,
  117794. 11,
  117795. 0,
  117796. 12,
  117797. };
  117798. static long _vq_lengthlist__44c5_s_p8_0[] = {
  117799. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  117800. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  117801. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117802. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  117803. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  117804. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  117805. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  117806. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  117807. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  117808. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  117809. 0,12,12,12,12,12,12,13,13,
  117810. };
  117811. static float _vq_quantthresh__44c5_s_p8_0[] = {
  117812. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  117813. 12.5, 17.5, 22.5, 27.5,
  117814. };
  117815. static long _vq_quantmap__44c5_s_p8_0[] = {
  117816. 11, 9, 7, 5, 3, 1, 0, 2,
  117817. 4, 6, 8, 10, 12,
  117818. };
  117819. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  117820. _vq_quantthresh__44c5_s_p8_0,
  117821. _vq_quantmap__44c5_s_p8_0,
  117822. 13,
  117823. 13
  117824. };
  117825. static static_codebook _44c5_s_p8_0 = {
  117826. 2, 169,
  117827. _vq_lengthlist__44c5_s_p8_0,
  117828. 1, -526516224, 1616117760, 4, 0,
  117829. _vq_quantlist__44c5_s_p8_0,
  117830. NULL,
  117831. &_vq_auxt__44c5_s_p8_0,
  117832. NULL,
  117833. 0
  117834. };
  117835. static long _vq_quantlist__44c5_s_p8_1[] = {
  117836. 2,
  117837. 1,
  117838. 3,
  117839. 0,
  117840. 4,
  117841. };
  117842. static long _vq_lengthlist__44c5_s_p8_1[] = {
  117843. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  117844. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  117845. };
  117846. static float _vq_quantthresh__44c5_s_p8_1[] = {
  117847. -1.5, -0.5, 0.5, 1.5,
  117848. };
  117849. static long _vq_quantmap__44c5_s_p8_1[] = {
  117850. 3, 1, 0, 2, 4,
  117851. };
  117852. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  117853. _vq_quantthresh__44c5_s_p8_1,
  117854. _vq_quantmap__44c5_s_p8_1,
  117855. 5,
  117856. 5
  117857. };
  117858. static static_codebook _44c5_s_p8_1 = {
  117859. 2, 25,
  117860. _vq_lengthlist__44c5_s_p8_1,
  117861. 1, -533725184, 1611661312, 3, 0,
  117862. _vq_quantlist__44c5_s_p8_1,
  117863. NULL,
  117864. &_vq_auxt__44c5_s_p8_1,
  117865. NULL,
  117866. 0
  117867. };
  117868. static long _vq_quantlist__44c5_s_p9_0[] = {
  117869. 7,
  117870. 6,
  117871. 8,
  117872. 5,
  117873. 9,
  117874. 4,
  117875. 10,
  117876. 3,
  117877. 11,
  117878. 2,
  117879. 12,
  117880. 1,
  117881. 13,
  117882. 0,
  117883. 14,
  117884. };
  117885. static long _vq_lengthlist__44c5_s_p9_0[] = {
  117886. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  117887. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  117888. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117889. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117890. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117891. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117892. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117893. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117894. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117895. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117896. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117897. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117898. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117899. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  117900. 12,
  117901. };
  117902. static float _vq_quantthresh__44c5_s_p9_0[] = {
  117903. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  117904. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  117905. };
  117906. static long _vq_quantmap__44c5_s_p9_0[] = {
  117907. 13, 11, 9, 7, 5, 3, 1, 0,
  117908. 2, 4, 6, 8, 10, 12, 14,
  117909. };
  117910. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  117911. _vq_quantthresh__44c5_s_p9_0,
  117912. _vq_quantmap__44c5_s_p9_0,
  117913. 15,
  117914. 15
  117915. };
  117916. static static_codebook _44c5_s_p9_0 = {
  117917. 2, 225,
  117918. _vq_lengthlist__44c5_s_p9_0,
  117919. 1, -512522752, 1628852224, 4, 0,
  117920. _vq_quantlist__44c5_s_p9_0,
  117921. NULL,
  117922. &_vq_auxt__44c5_s_p9_0,
  117923. NULL,
  117924. 0
  117925. };
  117926. static long _vq_quantlist__44c5_s_p9_1[] = {
  117927. 8,
  117928. 7,
  117929. 9,
  117930. 6,
  117931. 10,
  117932. 5,
  117933. 11,
  117934. 4,
  117935. 12,
  117936. 3,
  117937. 13,
  117938. 2,
  117939. 14,
  117940. 1,
  117941. 15,
  117942. 0,
  117943. 16,
  117944. };
  117945. static long _vq_lengthlist__44c5_s_p9_1[] = {
  117946. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  117947. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  117948. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  117949. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  117950. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  117951. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  117952. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  117953. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  117954. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  117955. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  117956. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  117957. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  117958. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  117959. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  117960. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  117961. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  117962. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  117963. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  117964. 15,
  117965. };
  117966. static float _vq_quantthresh__44c5_s_p9_1[] = {
  117967. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  117968. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  117969. };
  117970. static long _vq_quantmap__44c5_s_p9_1[] = {
  117971. 15, 13, 11, 9, 7, 5, 3, 1,
  117972. 0, 2, 4, 6, 8, 10, 12, 14,
  117973. 16,
  117974. };
  117975. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  117976. _vq_quantthresh__44c5_s_p9_1,
  117977. _vq_quantmap__44c5_s_p9_1,
  117978. 17,
  117979. 17
  117980. };
  117981. static static_codebook _44c5_s_p9_1 = {
  117982. 2, 289,
  117983. _vq_lengthlist__44c5_s_p9_1,
  117984. 1, -520814592, 1620377600, 5, 0,
  117985. _vq_quantlist__44c5_s_p9_1,
  117986. NULL,
  117987. &_vq_auxt__44c5_s_p9_1,
  117988. NULL,
  117989. 0
  117990. };
  117991. static long _vq_quantlist__44c5_s_p9_2[] = {
  117992. 10,
  117993. 9,
  117994. 11,
  117995. 8,
  117996. 12,
  117997. 7,
  117998. 13,
  117999. 6,
  118000. 14,
  118001. 5,
  118002. 15,
  118003. 4,
  118004. 16,
  118005. 3,
  118006. 17,
  118007. 2,
  118008. 18,
  118009. 1,
  118010. 19,
  118011. 0,
  118012. 20,
  118013. };
  118014. static long _vq_lengthlist__44c5_s_p9_2[] = {
  118015. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  118016. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  118017. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  118018. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  118019. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  118020. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  118021. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  118022. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  118023. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  118024. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118025. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  118026. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  118027. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  118028. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  118029. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  118030. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  118031. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  118032. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118033. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  118034. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  118035. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118036. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118037. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118038. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118039. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  118040. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118041. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  118042. 10,10,10,10,10,10,10,10,10,
  118043. };
  118044. static float _vq_quantthresh__44c5_s_p9_2[] = {
  118045. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118046. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118047. 6.5, 7.5, 8.5, 9.5,
  118048. };
  118049. static long _vq_quantmap__44c5_s_p9_2[] = {
  118050. 19, 17, 15, 13, 11, 9, 7, 5,
  118051. 3, 1, 0, 2, 4, 6, 8, 10,
  118052. 12, 14, 16, 18, 20,
  118053. };
  118054. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  118055. _vq_quantthresh__44c5_s_p9_2,
  118056. _vq_quantmap__44c5_s_p9_2,
  118057. 21,
  118058. 21
  118059. };
  118060. static static_codebook _44c5_s_p9_2 = {
  118061. 2, 441,
  118062. _vq_lengthlist__44c5_s_p9_2,
  118063. 1, -529268736, 1611661312, 5, 0,
  118064. _vq_quantlist__44c5_s_p9_2,
  118065. NULL,
  118066. &_vq_auxt__44c5_s_p9_2,
  118067. NULL,
  118068. 0
  118069. };
  118070. static long _huff_lengthlist__44c5_s_short[] = {
  118071. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  118072. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  118073. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  118074. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  118075. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  118076. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  118077. 6, 8,11,16,
  118078. };
  118079. static static_codebook _huff_book__44c5_s_short = {
  118080. 2, 100,
  118081. _huff_lengthlist__44c5_s_short,
  118082. 0, 0, 0, 0, 0,
  118083. NULL,
  118084. NULL,
  118085. NULL,
  118086. NULL,
  118087. 0
  118088. };
  118089. static long _huff_lengthlist__44c6_s_long[] = {
  118090. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  118091. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  118092. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  118093. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  118094. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  118095. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  118096. 11,10,10,12,
  118097. };
  118098. static static_codebook _huff_book__44c6_s_long = {
  118099. 2, 100,
  118100. _huff_lengthlist__44c6_s_long,
  118101. 0, 0, 0, 0, 0,
  118102. NULL,
  118103. NULL,
  118104. NULL,
  118105. NULL,
  118106. 0
  118107. };
  118108. static long _vq_quantlist__44c6_s_p1_0[] = {
  118109. 1,
  118110. 0,
  118111. 2,
  118112. };
  118113. static long _vq_lengthlist__44c6_s_p1_0[] = {
  118114. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118115. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118116. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118117. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118118. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  118119. 8,
  118120. };
  118121. static float _vq_quantthresh__44c6_s_p1_0[] = {
  118122. -0.5, 0.5,
  118123. };
  118124. static long _vq_quantmap__44c6_s_p1_0[] = {
  118125. 1, 0, 2,
  118126. };
  118127. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  118128. _vq_quantthresh__44c6_s_p1_0,
  118129. _vq_quantmap__44c6_s_p1_0,
  118130. 3,
  118131. 3
  118132. };
  118133. static static_codebook _44c6_s_p1_0 = {
  118134. 4, 81,
  118135. _vq_lengthlist__44c6_s_p1_0,
  118136. 1, -535822336, 1611661312, 2, 0,
  118137. _vq_quantlist__44c6_s_p1_0,
  118138. NULL,
  118139. &_vq_auxt__44c6_s_p1_0,
  118140. NULL,
  118141. 0
  118142. };
  118143. static long _vq_quantlist__44c6_s_p2_0[] = {
  118144. 2,
  118145. 1,
  118146. 3,
  118147. 0,
  118148. 4,
  118149. };
  118150. static long _vq_lengthlist__44c6_s_p2_0[] = {
  118151. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118152. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118153. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118154. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118155. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  118156. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118157. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  118158. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118160. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118161. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118162. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118163. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118164. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118165. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  118166. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118168. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118169. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  118170. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  118171. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  118172. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  118173. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118174. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118176. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  118177. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118178. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118179. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  118180. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118181. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  118182. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118187. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  118188. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  118189. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118190. 13,
  118191. };
  118192. static float _vq_quantthresh__44c6_s_p2_0[] = {
  118193. -1.5, -0.5, 0.5, 1.5,
  118194. };
  118195. static long _vq_quantmap__44c6_s_p2_0[] = {
  118196. 3, 1, 0, 2, 4,
  118197. };
  118198. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  118199. _vq_quantthresh__44c6_s_p2_0,
  118200. _vq_quantmap__44c6_s_p2_0,
  118201. 5,
  118202. 5
  118203. };
  118204. static static_codebook _44c6_s_p2_0 = {
  118205. 4, 625,
  118206. _vq_lengthlist__44c6_s_p2_0,
  118207. 1, -533725184, 1611661312, 3, 0,
  118208. _vq_quantlist__44c6_s_p2_0,
  118209. NULL,
  118210. &_vq_auxt__44c6_s_p2_0,
  118211. NULL,
  118212. 0
  118213. };
  118214. static long _vq_quantlist__44c6_s_p3_0[] = {
  118215. 4,
  118216. 3,
  118217. 5,
  118218. 2,
  118219. 6,
  118220. 1,
  118221. 7,
  118222. 0,
  118223. 8,
  118224. };
  118225. static long _vq_lengthlist__44c6_s_p3_0[] = {
  118226. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118227. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  118228. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  118229. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  118230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118231. 0,
  118232. };
  118233. static float _vq_quantthresh__44c6_s_p3_0[] = {
  118234. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118235. };
  118236. static long _vq_quantmap__44c6_s_p3_0[] = {
  118237. 7, 5, 3, 1, 0, 2, 4, 6,
  118238. 8,
  118239. };
  118240. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  118241. _vq_quantthresh__44c6_s_p3_0,
  118242. _vq_quantmap__44c6_s_p3_0,
  118243. 9,
  118244. 9
  118245. };
  118246. static static_codebook _44c6_s_p3_0 = {
  118247. 2, 81,
  118248. _vq_lengthlist__44c6_s_p3_0,
  118249. 1, -531628032, 1611661312, 4, 0,
  118250. _vq_quantlist__44c6_s_p3_0,
  118251. NULL,
  118252. &_vq_auxt__44c6_s_p3_0,
  118253. NULL,
  118254. 0
  118255. };
  118256. static long _vq_quantlist__44c6_s_p4_0[] = {
  118257. 8,
  118258. 7,
  118259. 9,
  118260. 6,
  118261. 10,
  118262. 5,
  118263. 11,
  118264. 4,
  118265. 12,
  118266. 3,
  118267. 13,
  118268. 2,
  118269. 14,
  118270. 1,
  118271. 15,
  118272. 0,
  118273. 16,
  118274. };
  118275. static long _vq_lengthlist__44c6_s_p4_0[] = {
  118276. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  118277. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  118278. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  118279. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118280. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118281. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118282. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  118283. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118284. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118285. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118294. 0,
  118295. };
  118296. static float _vq_quantthresh__44c6_s_p4_0[] = {
  118297. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118298. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118299. };
  118300. static long _vq_quantmap__44c6_s_p4_0[] = {
  118301. 15, 13, 11, 9, 7, 5, 3, 1,
  118302. 0, 2, 4, 6, 8, 10, 12, 14,
  118303. 16,
  118304. };
  118305. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118306. _vq_quantthresh__44c6_s_p4_0,
  118307. _vq_quantmap__44c6_s_p4_0,
  118308. 17,
  118309. 17
  118310. };
  118311. static static_codebook _44c6_s_p4_0 = {
  118312. 2, 289,
  118313. _vq_lengthlist__44c6_s_p4_0,
  118314. 1, -529530880, 1611661312, 5, 0,
  118315. _vq_quantlist__44c6_s_p4_0,
  118316. NULL,
  118317. &_vq_auxt__44c6_s_p4_0,
  118318. NULL,
  118319. 0
  118320. };
  118321. static long _vq_quantlist__44c6_s_p5_0[] = {
  118322. 1,
  118323. 0,
  118324. 2,
  118325. };
  118326. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118327. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118328. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118329. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118330. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118331. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118332. 12,
  118333. };
  118334. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118335. -5.5, 5.5,
  118336. };
  118337. static long _vq_quantmap__44c6_s_p5_0[] = {
  118338. 1, 0, 2,
  118339. };
  118340. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118341. _vq_quantthresh__44c6_s_p5_0,
  118342. _vq_quantmap__44c6_s_p5_0,
  118343. 3,
  118344. 3
  118345. };
  118346. static static_codebook _44c6_s_p5_0 = {
  118347. 4, 81,
  118348. _vq_lengthlist__44c6_s_p5_0,
  118349. 1, -529137664, 1618345984, 2, 0,
  118350. _vq_quantlist__44c6_s_p5_0,
  118351. NULL,
  118352. &_vq_auxt__44c6_s_p5_0,
  118353. NULL,
  118354. 0
  118355. };
  118356. static long _vq_quantlist__44c6_s_p5_1[] = {
  118357. 5,
  118358. 4,
  118359. 6,
  118360. 3,
  118361. 7,
  118362. 2,
  118363. 8,
  118364. 1,
  118365. 9,
  118366. 0,
  118367. 10,
  118368. };
  118369. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118370. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118371. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118372. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118373. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118374. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118375. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  118376. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  118377. 11,10,10, 7, 7, 8, 8, 8, 8,
  118378. };
  118379. static float _vq_quantthresh__44c6_s_p5_1[] = {
  118380. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118381. 3.5, 4.5,
  118382. };
  118383. static long _vq_quantmap__44c6_s_p5_1[] = {
  118384. 9, 7, 5, 3, 1, 0, 2, 4,
  118385. 6, 8, 10,
  118386. };
  118387. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  118388. _vq_quantthresh__44c6_s_p5_1,
  118389. _vq_quantmap__44c6_s_p5_1,
  118390. 11,
  118391. 11
  118392. };
  118393. static static_codebook _44c6_s_p5_1 = {
  118394. 2, 121,
  118395. _vq_lengthlist__44c6_s_p5_1,
  118396. 1, -531365888, 1611661312, 4, 0,
  118397. _vq_quantlist__44c6_s_p5_1,
  118398. NULL,
  118399. &_vq_auxt__44c6_s_p5_1,
  118400. NULL,
  118401. 0
  118402. };
  118403. static long _vq_quantlist__44c6_s_p6_0[] = {
  118404. 6,
  118405. 5,
  118406. 7,
  118407. 4,
  118408. 8,
  118409. 3,
  118410. 9,
  118411. 2,
  118412. 10,
  118413. 1,
  118414. 11,
  118415. 0,
  118416. 12,
  118417. };
  118418. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118419. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118420. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118421. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118422. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118423. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118424. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118429. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118430. };
  118431. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118432. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118433. 12.5, 17.5, 22.5, 27.5,
  118434. };
  118435. static long _vq_quantmap__44c6_s_p6_0[] = {
  118436. 11, 9, 7, 5, 3, 1, 0, 2,
  118437. 4, 6, 8, 10, 12,
  118438. };
  118439. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118440. _vq_quantthresh__44c6_s_p6_0,
  118441. _vq_quantmap__44c6_s_p6_0,
  118442. 13,
  118443. 13
  118444. };
  118445. static static_codebook _44c6_s_p6_0 = {
  118446. 2, 169,
  118447. _vq_lengthlist__44c6_s_p6_0,
  118448. 1, -526516224, 1616117760, 4, 0,
  118449. _vq_quantlist__44c6_s_p6_0,
  118450. NULL,
  118451. &_vq_auxt__44c6_s_p6_0,
  118452. NULL,
  118453. 0
  118454. };
  118455. static long _vq_quantlist__44c6_s_p6_1[] = {
  118456. 2,
  118457. 1,
  118458. 3,
  118459. 0,
  118460. 4,
  118461. };
  118462. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118463. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118464. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118465. };
  118466. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118467. -1.5, -0.5, 0.5, 1.5,
  118468. };
  118469. static long _vq_quantmap__44c6_s_p6_1[] = {
  118470. 3, 1, 0, 2, 4,
  118471. };
  118472. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118473. _vq_quantthresh__44c6_s_p6_1,
  118474. _vq_quantmap__44c6_s_p6_1,
  118475. 5,
  118476. 5
  118477. };
  118478. static static_codebook _44c6_s_p6_1 = {
  118479. 2, 25,
  118480. _vq_lengthlist__44c6_s_p6_1,
  118481. 1, -533725184, 1611661312, 3, 0,
  118482. _vq_quantlist__44c6_s_p6_1,
  118483. NULL,
  118484. &_vq_auxt__44c6_s_p6_1,
  118485. NULL,
  118486. 0
  118487. };
  118488. static long _vq_quantlist__44c6_s_p7_0[] = {
  118489. 6,
  118490. 5,
  118491. 7,
  118492. 4,
  118493. 8,
  118494. 3,
  118495. 9,
  118496. 2,
  118497. 10,
  118498. 1,
  118499. 11,
  118500. 0,
  118501. 12,
  118502. };
  118503. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118504. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118505. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118506. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118507. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118508. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118509. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118510. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118511. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118512. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118513. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118514. 20,13,13,13,13,13,13,14,14,
  118515. };
  118516. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118517. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118518. 27.5, 38.5, 49.5, 60.5,
  118519. };
  118520. static long _vq_quantmap__44c6_s_p7_0[] = {
  118521. 11, 9, 7, 5, 3, 1, 0, 2,
  118522. 4, 6, 8, 10, 12,
  118523. };
  118524. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118525. _vq_quantthresh__44c6_s_p7_0,
  118526. _vq_quantmap__44c6_s_p7_0,
  118527. 13,
  118528. 13
  118529. };
  118530. static static_codebook _44c6_s_p7_0 = {
  118531. 2, 169,
  118532. _vq_lengthlist__44c6_s_p7_0,
  118533. 1, -523206656, 1618345984, 4, 0,
  118534. _vq_quantlist__44c6_s_p7_0,
  118535. NULL,
  118536. &_vq_auxt__44c6_s_p7_0,
  118537. NULL,
  118538. 0
  118539. };
  118540. static long _vq_quantlist__44c6_s_p7_1[] = {
  118541. 5,
  118542. 4,
  118543. 6,
  118544. 3,
  118545. 7,
  118546. 2,
  118547. 8,
  118548. 1,
  118549. 9,
  118550. 0,
  118551. 10,
  118552. };
  118553. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118554. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118555. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118556. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118557. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118558. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118559. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118560. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118561. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118562. };
  118563. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118564. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118565. 3.5, 4.5,
  118566. };
  118567. static long _vq_quantmap__44c6_s_p7_1[] = {
  118568. 9, 7, 5, 3, 1, 0, 2, 4,
  118569. 6, 8, 10,
  118570. };
  118571. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118572. _vq_quantthresh__44c6_s_p7_1,
  118573. _vq_quantmap__44c6_s_p7_1,
  118574. 11,
  118575. 11
  118576. };
  118577. static static_codebook _44c6_s_p7_1 = {
  118578. 2, 121,
  118579. _vq_lengthlist__44c6_s_p7_1,
  118580. 1, -531365888, 1611661312, 4, 0,
  118581. _vq_quantlist__44c6_s_p7_1,
  118582. NULL,
  118583. &_vq_auxt__44c6_s_p7_1,
  118584. NULL,
  118585. 0
  118586. };
  118587. static long _vq_quantlist__44c6_s_p8_0[] = {
  118588. 7,
  118589. 6,
  118590. 8,
  118591. 5,
  118592. 9,
  118593. 4,
  118594. 10,
  118595. 3,
  118596. 11,
  118597. 2,
  118598. 12,
  118599. 1,
  118600. 13,
  118601. 0,
  118602. 14,
  118603. };
  118604. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118605. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118606. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118607. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118608. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118609. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118610. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118611. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118612. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118613. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118614. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118615. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118616. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118617. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118618. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118619. 14,
  118620. };
  118621. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118622. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118623. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118624. };
  118625. static long _vq_quantmap__44c6_s_p8_0[] = {
  118626. 13, 11, 9, 7, 5, 3, 1, 0,
  118627. 2, 4, 6, 8, 10, 12, 14,
  118628. };
  118629. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118630. _vq_quantthresh__44c6_s_p8_0,
  118631. _vq_quantmap__44c6_s_p8_0,
  118632. 15,
  118633. 15
  118634. };
  118635. static static_codebook _44c6_s_p8_0 = {
  118636. 2, 225,
  118637. _vq_lengthlist__44c6_s_p8_0,
  118638. 1, -520986624, 1620377600, 4, 0,
  118639. _vq_quantlist__44c6_s_p8_0,
  118640. NULL,
  118641. &_vq_auxt__44c6_s_p8_0,
  118642. NULL,
  118643. 0
  118644. };
  118645. static long _vq_quantlist__44c6_s_p8_1[] = {
  118646. 10,
  118647. 9,
  118648. 11,
  118649. 8,
  118650. 12,
  118651. 7,
  118652. 13,
  118653. 6,
  118654. 14,
  118655. 5,
  118656. 15,
  118657. 4,
  118658. 16,
  118659. 3,
  118660. 17,
  118661. 2,
  118662. 18,
  118663. 1,
  118664. 19,
  118665. 0,
  118666. 20,
  118667. };
  118668. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118669. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118670. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  118671. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  118672. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  118673. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118674. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  118675. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  118676. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  118677. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118678. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118679. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  118680. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  118681. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  118682. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  118683. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  118684. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  118685. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  118686. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  118687. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  118688. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  118689. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  118690. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118691. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118692. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118693. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  118694. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  118695. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  118696. 10,10,10,10,10,10,10,10,10,
  118697. };
  118698. static float _vq_quantthresh__44c6_s_p8_1[] = {
  118699. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118700. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118701. 6.5, 7.5, 8.5, 9.5,
  118702. };
  118703. static long _vq_quantmap__44c6_s_p8_1[] = {
  118704. 19, 17, 15, 13, 11, 9, 7, 5,
  118705. 3, 1, 0, 2, 4, 6, 8, 10,
  118706. 12, 14, 16, 18, 20,
  118707. };
  118708. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  118709. _vq_quantthresh__44c6_s_p8_1,
  118710. _vq_quantmap__44c6_s_p8_1,
  118711. 21,
  118712. 21
  118713. };
  118714. static static_codebook _44c6_s_p8_1 = {
  118715. 2, 441,
  118716. _vq_lengthlist__44c6_s_p8_1,
  118717. 1, -529268736, 1611661312, 5, 0,
  118718. _vq_quantlist__44c6_s_p8_1,
  118719. NULL,
  118720. &_vq_auxt__44c6_s_p8_1,
  118721. NULL,
  118722. 0
  118723. };
  118724. static long _vq_quantlist__44c6_s_p9_0[] = {
  118725. 6,
  118726. 5,
  118727. 7,
  118728. 4,
  118729. 8,
  118730. 3,
  118731. 9,
  118732. 2,
  118733. 10,
  118734. 1,
  118735. 11,
  118736. 0,
  118737. 12,
  118738. };
  118739. static long _vq_lengthlist__44c6_s_p9_0[] = {
  118740. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  118741. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  118742. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  118743. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  118744. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118745. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118746. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118747. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118748. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118749. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118750. 10,10,10,10,10,10,10,10,10,
  118751. };
  118752. static float _vq_quantthresh__44c6_s_p9_0[] = {
  118753. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  118754. 1592.5, 2229.5, 2866.5, 3503.5,
  118755. };
  118756. static long _vq_quantmap__44c6_s_p9_0[] = {
  118757. 11, 9, 7, 5, 3, 1, 0, 2,
  118758. 4, 6, 8, 10, 12,
  118759. };
  118760. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  118761. _vq_quantthresh__44c6_s_p9_0,
  118762. _vq_quantmap__44c6_s_p9_0,
  118763. 13,
  118764. 13
  118765. };
  118766. static static_codebook _44c6_s_p9_0 = {
  118767. 2, 169,
  118768. _vq_lengthlist__44c6_s_p9_0,
  118769. 1, -511845376, 1630791680, 4, 0,
  118770. _vq_quantlist__44c6_s_p9_0,
  118771. NULL,
  118772. &_vq_auxt__44c6_s_p9_0,
  118773. NULL,
  118774. 0
  118775. };
  118776. static long _vq_quantlist__44c6_s_p9_1[] = {
  118777. 6,
  118778. 5,
  118779. 7,
  118780. 4,
  118781. 8,
  118782. 3,
  118783. 9,
  118784. 2,
  118785. 10,
  118786. 1,
  118787. 11,
  118788. 0,
  118789. 12,
  118790. };
  118791. static long _vq_lengthlist__44c6_s_p9_1[] = {
  118792. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  118793. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  118794. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  118795. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  118796. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  118797. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  118798. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  118799. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  118800. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  118801. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  118802. 15,12,10,11,11,13,11,12,13,
  118803. };
  118804. static float _vq_quantthresh__44c6_s_p9_1[] = {
  118805. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  118806. 122.5, 171.5, 220.5, 269.5,
  118807. };
  118808. static long _vq_quantmap__44c6_s_p9_1[] = {
  118809. 11, 9, 7, 5, 3, 1, 0, 2,
  118810. 4, 6, 8, 10, 12,
  118811. };
  118812. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  118813. _vq_quantthresh__44c6_s_p9_1,
  118814. _vq_quantmap__44c6_s_p9_1,
  118815. 13,
  118816. 13
  118817. };
  118818. static static_codebook _44c6_s_p9_1 = {
  118819. 2, 169,
  118820. _vq_lengthlist__44c6_s_p9_1,
  118821. 1, -518889472, 1622704128, 4, 0,
  118822. _vq_quantlist__44c6_s_p9_1,
  118823. NULL,
  118824. &_vq_auxt__44c6_s_p9_1,
  118825. NULL,
  118826. 0
  118827. };
  118828. static long _vq_quantlist__44c6_s_p9_2[] = {
  118829. 24,
  118830. 23,
  118831. 25,
  118832. 22,
  118833. 26,
  118834. 21,
  118835. 27,
  118836. 20,
  118837. 28,
  118838. 19,
  118839. 29,
  118840. 18,
  118841. 30,
  118842. 17,
  118843. 31,
  118844. 16,
  118845. 32,
  118846. 15,
  118847. 33,
  118848. 14,
  118849. 34,
  118850. 13,
  118851. 35,
  118852. 12,
  118853. 36,
  118854. 11,
  118855. 37,
  118856. 10,
  118857. 38,
  118858. 9,
  118859. 39,
  118860. 8,
  118861. 40,
  118862. 7,
  118863. 41,
  118864. 6,
  118865. 42,
  118866. 5,
  118867. 43,
  118868. 4,
  118869. 44,
  118870. 3,
  118871. 45,
  118872. 2,
  118873. 46,
  118874. 1,
  118875. 47,
  118876. 0,
  118877. 48,
  118878. };
  118879. static long _vq_lengthlist__44c6_s_p9_2[] = {
  118880. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  118881. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118882. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118883. 7,
  118884. };
  118885. static float _vq_quantthresh__44c6_s_p9_2[] = {
  118886. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  118887. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  118888. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118889. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118890. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  118891. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  118892. };
  118893. static long _vq_quantmap__44c6_s_p9_2[] = {
  118894. 47, 45, 43, 41, 39, 37, 35, 33,
  118895. 31, 29, 27, 25, 23, 21, 19, 17,
  118896. 15, 13, 11, 9, 7, 5, 3, 1,
  118897. 0, 2, 4, 6, 8, 10, 12, 14,
  118898. 16, 18, 20, 22, 24, 26, 28, 30,
  118899. 32, 34, 36, 38, 40, 42, 44, 46,
  118900. 48,
  118901. };
  118902. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  118903. _vq_quantthresh__44c6_s_p9_2,
  118904. _vq_quantmap__44c6_s_p9_2,
  118905. 49,
  118906. 49
  118907. };
  118908. static static_codebook _44c6_s_p9_2 = {
  118909. 1, 49,
  118910. _vq_lengthlist__44c6_s_p9_2,
  118911. 1, -526909440, 1611661312, 6, 0,
  118912. _vq_quantlist__44c6_s_p9_2,
  118913. NULL,
  118914. &_vq_auxt__44c6_s_p9_2,
  118915. NULL,
  118916. 0
  118917. };
  118918. static long _huff_lengthlist__44c6_s_short[] = {
  118919. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  118920. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  118921. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  118922. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  118923. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  118924. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  118925. 9,10,17,18,
  118926. };
  118927. static static_codebook _huff_book__44c6_s_short = {
  118928. 2, 100,
  118929. _huff_lengthlist__44c6_s_short,
  118930. 0, 0, 0, 0, 0,
  118931. NULL,
  118932. NULL,
  118933. NULL,
  118934. NULL,
  118935. 0
  118936. };
  118937. static long _huff_lengthlist__44c7_s_long[] = {
  118938. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  118939. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  118940. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  118941. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  118942. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  118943. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  118944. 11,10,10,12,
  118945. };
  118946. static static_codebook _huff_book__44c7_s_long = {
  118947. 2, 100,
  118948. _huff_lengthlist__44c7_s_long,
  118949. 0, 0, 0, 0, 0,
  118950. NULL,
  118951. NULL,
  118952. NULL,
  118953. NULL,
  118954. 0
  118955. };
  118956. static long _vq_quantlist__44c7_s_p1_0[] = {
  118957. 1,
  118958. 0,
  118959. 2,
  118960. };
  118961. static long _vq_lengthlist__44c7_s_p1_0[] = {
  118962. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118963. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118964. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118965. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118966. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  118967. 8,
  118968. };
  118969. static float _vq_quantthresh__44c7_s_p1_0[] = {
  118970. -0.5, 0.5,
  118971. };
  118972. static long _vq_quantmap__44c7_s_p1_0[] = {
  118973. 1, 0, 2,
  118974. };
  118975. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  118976. _vq_quantthresh__44c7_s_p1_0,
  118977. _vq_quantmap__44c7_s_p1_0,
  118978. 3,
  118979. 3
  118980. };
  118981. static static_codebook _44c7_s_p1_0 = {
  118982. 4, 81,
  118983. _vq_lengthlist__44c7_s_p1_0,
  118984. 1, -535822336, 1611661312, 2, 0,
  118985. _vq_quantlist__44c7_s_p1_0,
  118986. NULL,
  118987. &_vq_auxt__44c7_s_p1_0,
  118988. NULL,
  118989. 0
  118990. };
  118991. static long _vq_quantlist__44c7_s_p2_0[] = {
  118992. 2,
  118993. 1,
  118994. 3,
  118995. 0,
  118996. 4,
  118997. };
  118998. static long _vq_lengthlist__44c7_s_p2_0[] = {
  118999. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119000. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119001. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119002. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  119003. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119004. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  119005. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  119006. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119008. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119009. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  119010. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119011. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  119012. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  119013. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  119014. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  119015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119016. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  119017. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  119018. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  119019. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  119020. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  119021. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  119022. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119024. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119025. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  119026. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119027. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  119028. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  119029. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  119030. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119035. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  119036. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119037. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  119038. 13,
  119039. };
  119040. static float _vq_quantthresh__44c7_s_p2_0[] = {
  119041. -1.5, -0.5, 0.5, 1.5,
  119042. };
  119043. static long _vq_quantmap__44c7_s_p2_0[] = {
  119044. 3, 1, 0, 2, 4,
  119045. };
  119046. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  119047. _vq_quantthresh__44c7_s_p2_0,
  119048. _vq_quantmap__44c7_s_p2_0,
  119049. 5,
  119050. 5
  119051. };
  119052. static static_codebook _44c7_s_p2_0 = {
  119053. 4, 625,
  119054. _vq_lengthlist__44c7_s_p2_0,
  119055. 1, -533725184, 1611661312, 3, 0,
  119056. _vq_quantlist__44c7_s_p2_0,
  119057. NULL,
  119058. &_vq_auxt__44c7_s_p2_0,
  119059. NULL,
  119060. 0
  119061. };
  119062. static long _vq_quantlist__44c7_s_p3_0[] = {
  119063. 4,
  119064. 3,
  119065. 5,
  119066. 2,
  119067. 6,
  119068. 1,
  119069. 7,
  119070. 0,
  119071. 8,
  119072. };
  119073. static long _vq_lengthlist__44c7_s_p3_0[] = {
  119074. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119075. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119076. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119077. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119079. 0,
  119080. };
  119081. static float _vq_quantthresh__44c7_s_p3_0[] = {
  119082. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119083. };
  119084. static long _vq_quantmap__44c7_s_p3_0[] = {
  119085. 7, 5, 3, 1, 0, 2, 4, 6,
  119086. 8,
  119087. };
  119088. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  119089. _vq_quantthresh__44c7_s_p3_0,
  119090. _vq_quantmap__44c7_s_p3_0,
  119091. 9,
  119092. 9
  119093. };
  119094. static static_codebook _44c7_s_p3_0 = {
  119095. 2, 81,
  119096. _vq_lengthlist__44c7_s_p3_0,
  119097. 1, -531628032, 1611661312, 4, 0,
  119098. _vq_quantlist__44c7_s_p3_0,
  119099. NULL,
  119100. &_vq_auxt__44c7_s_p3_0,
  119101. NULL,
  119102. 0
  119103. };
  119104. static long _vq_quantlist__44c7_s_p4_0[] = {
  119105. 8,
  119106. 7,
  119107. 9,
  119108. 6,
  119109. 10,
  119110. 5,
  119111. 11,
  119112. 4,
  119113. 12,
  119114. 3,
  119115. 13,
  119116. 2,
  119117. 14,
  119118. 1,
  119119. 15,
  119120. 0,
  119121. 16,
  119122. };
  119123. static long _vq_lengthlist__44c7_s_p4_0[] = {
  119124. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119125. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  119126. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119127. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  119128. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  119129. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119130. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119131. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119132. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119133. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119142. 0,
  119143. };
  119144. static float _vq_quantthresh__44c7_s_p4_0[] = {
  119145. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119146. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119147. };
  119148. static long _vq_quantmap__44c7_s_p4_0[] = {
  119149. 15, 13, 11, 9, 7, 5, 3, 1,
  119150. 0, 2, 4, 6, 8, 10, 12, 14,
  119151. 16,
  119152. };
  119153. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  119154. _vq_quantthresh__44c7_s_p4_0,
  119155. _vq_quantmap__44c7_s_p4_0,
  119156. 17,
  119157. 17
  119158. };
  119159. static static_codebook _44c7_s_p4_0 = {
  119160. 2, 289,
  119161. _vq_lengthlist__44c7_s_p4_0,
  119162. 1, -529530880, 1611661312, 5, 0,
  119163. _vq_quantlist__44c7_s_p4_0,
  119164. NULL,
  119165. &_vq_auxt__44c7_s_p4_0,
  119166. NULL,
  119167. 0
  119168. };
  119169. static long _vq_quantlist__44c7_s_p5_0[] = {
  119170. 1,
  119171. 0,
  119172. 2,
  119173. };
  119174. static long _vq_lengthlist__44c7_s_p5_0[] = {
  119175. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  119176. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119177. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119178. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  119179. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  119180. 12,
  119181. };
  119182. static float _vq_quantthresh__44c7_s_p5_0[] = {
  119183. -5.5, 5.5,
  119184. };
  119185. static long _vq_quantmap__44c7_s_p5_0[] = {
  119186. 1, 0, 2,
  119187. };
  119188. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  119189. _vq_quantthresh__44c7_s_p5_0,
  119190. _vq_quantmap__44c7_s_p5_0,
  119191. 3,
  119192. 3
  119193. };
  119194. static static_codebook _44c7_s_p5_0 = {
  119195. 4, 81,
  119196. _vq_lengthlist__44c7_s_p5_0,
  119197. 1, -529137664, 1618345984, 2, 0,
  119198. _vq_quantlist__44c7_s_p5_0,
  119199. NULL,
  119200. &_vq_auxt__44c7_s_p5_0,
  119201. NULL,
  119202. 0
  119203. };
  119204. static long _vq_quantlist__44c7_s_p5_1[] = {
  119205. 5,
  119206. 4,
  119207. 6,
  119208. 3,
  119209. 7,
  119210. 2,
  119211. 8,
  119212. 1,
  119213. 9,
  119214. 0,
  119215. 10,
  119216. };
  119217. static long _vq_lengthlist__44c7_s_p5_1[] = {
  119218. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  119219. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  119220. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  119221. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  119222. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  119223. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  119224. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  119225. 11,11,11, 7, 7, 8, 8, 8, 8,
  119226. };
  119227. static float _vq_quantthresh__44c7_s_p5_1[] = {
  119228. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119229. 3.5, 4.5,
  119230. };
  119231. static long _vq_quantmap__44c7_s_p5_1[] = {
  119232. 9, 7, 5, 3, 1, 0, 2, 4,
  119233. 6, 8, 10,
  119234. };
  119235. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  119236. _vq_quantthresh__44c7_s_p5_1,
  119237. _vq_quantmap__44c7_s_p5_1,
  119238. 11,
  119239. 11
  119240. };
  119241. static static_codebook _44c7_s_p5_1 = {
  119242. 2, 121,
  119243. _vq_lengthlist__44c7_s_p5_1,
  119244. 1, -531365888, 1611661312, 4, 0,
  119245. _vq_quantlist__44c7_s_p5_1,
  119246. NULL,
  119247. &_vq_auxt__44c7_s_p5_1,
  119248. NULL,
  119249. 0
  119250. };
  119251. static long _vq_quantlist__44c7_s_p6_0[] = {
  119252. 6,
  119253. 5,
  119254. 7,
  119255. 4,
  119256. 8,
  119257. 3,
  119258. 9,
  119259. 2,
  119260. 10,
  119261. 1,
  119262. 11,
  119263. 0,
  119264. 12,
  119265. };
  119266. static long _vq_lengthlist__44c7_s_p6_0[] = {
  119267. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  119268. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  119269. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  119270. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  119271. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  119272. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  119273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119277. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119278. };
  119279. static float _vq_quantthresh__44c7_s_p6_0[] = {
  119280. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119281. 12.5, 17.5, 22.5, 27.5,
  119282. };
  119283. static long _vq_quantmap__44c7_s_p6_0[] = {
  119284. 11, 9, 7, 5, 3, 1, 0, 2,
  119285. 4, 6, 8, 10, 12,
  119286. };
  119287. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119288. _vq_quantthresh__44c7_s_p6_0,
  119289. _vq_quantmap__44c7_s_p6_0,
  119290. 13,
  119291. 13
  119292. };
  119293. static static_codebook _44c7_s_p6_0 = {
  119294. 2, 169,
  119295. _vq_lengthlist__44c7_s_p6_0,
  119296. 1, -526516224, 1616117760, 4, 0,
  119297. _vq_quantlist__44c7_s_p6_0,
  119298. NULL,
  119299. &_vq_auxt__44c7_s_p6_0,
  119300. NULL,
  119301. 0
  119302. };
  119303. static long _vq_quantlist__44c7_s_p6_1[] = {
  119304. 2,
  119305. 1,
  119306. 3,
  119307. 0,
  119308. 4,
  119309. };
  119310. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119311. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119312. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119313. };
  119314. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119315. -1.5, -0.5, 0.5, 1.5,
  119316. };
  119317. static long _vq_quantmap__44c7_s_p6_1[] = {
  119318. 3, 1, 0, 2, 4,
  119319. };
  119320. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119321. _vq_quantthresh__44c7_s_p6_1,
  119322. _vq_quantmap__44c7_s_p6_1,
  119323. 5,
  119324. 5
  119325. };
  119326. static static_codebook _44c7_s_p6_1 = {
  119327. 2, 25,
  119328. _vq_lengthlist__44c7_s_p6_1,
  119329. 1, -533725184, 1611661312, 3, 0,
  119330. _vq_quantlist__44c7_s_p6_1,
  119331. NULL,
  119332. &_vq_auxt__44c7_s_p6_1,
  119333. NULL,
  119334. 0
  119335. };
  119336. static long _vq_quantlist__44c7_s_p7_0[] = {
  119337. 6,
  119338. 5,
  119339. 7,
  119340. 4,
  119341. 8,
  119342. 3,
  119343. 9,
  119344. 2,
  119345. 10,
  119346. 1,
  119347. 11,
  119348. 0,
  119349. 12,
  119350. };
  119351. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119352. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119353. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119354. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119355. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119356. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119357. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119358. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119359. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119360. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119361. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119362. 19,13,13,13,13,14,14,15,15,
  119363. };
  119364. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119365. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119366. 27.5, 38.5, 49.5, 60.5,
  119367. };
  119368. static long _vq_quantmap__44c7_s_p7_0[] = {
  119369. 11, 9, 7, 5, 3, 1, 0, 2,
  119370. 4, 6, 8, 10, 12,
  119371. };
  119372. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119373. _vq_quantthresh__44c7_s_p7_0,
  119374. _vq_quantmap__44c7_s_p7_0,
  119375. 13,
  119376. 13
  119377. };
  119378. static static_codebook _44c7_s_p7_0 = {
  119379. 2, 169,
  119380. _vq_lengthlist__44c7_s_p7_0,
  119381. 1, -523206656, 1618345984, 4, 0,
  119382. _vq_quantlist__44c7_s_p7_0,
  119383. NULL,
  119384. &_vq_auxt__44c7_s_p7_0,
  119385. NULL,
  119386. 0
  119387. };
  119388. static long _vq_quantlist__44c7_s_p7_1[] = {
  119389. 5,
  119390. 4,
  119391. 6,
  119392. 3,
  119393. 7,
  119394. 2,
  119395. 8,
  119396. 1,
  119397. 9,
  119398. 0,
  119399. 10,
  119400. };
  119401. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119402. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119403. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119404. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119405. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119406. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119407. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119408. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119409. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119410. };
  119411. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119412. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119413. 3.5, 4.5,
  119414. };
  119415. static long _vq_quantmap__44c7_s_p7_1[] = {
  119416. 9, 7, 5, 3, 1, 0, 2, 4,
  119417. 6, 8, 10,
  119418. };
  119419. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119420. _vq_quantthresh__44c7_s_p7_1,
  119421. _vq_quantmap__44c7_s_p7_1,
  119422. 11,
  119423. 11
  119424. };
  119425. static static_codebook _44c7_s_p7_1 = {
  119426. 2, 121,
  119427. _vq_lengthlist__44c7_s_p7_1,
  119428. 1, -531365888, 1611661312, 4, 0,
  119429. _vq_quantlist__44c7_s_p7_1,
  119430. NULL,
  119431. &_vq_auxt__44c7_s_p7_1,
  119432. NULL,
  119433. 0
  119434. };
  119435. static long _vq_quantlist__44c7_s_p8_0[] = {
  119436. 7,
  119437. 6,
  119438. 8,
  119439. 5,
  119440. 9,
  119441. 4,
  119442. 10,
  119443. 3,
  119444. 11,
  119445. 2,
  119446. 12,
  119447. 1,
  119448. 13,
  119449. 0,
  119450. 14,
  119451. };
  119452. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119453. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119454. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119455. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119456. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119457. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119458. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119459. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119460. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119461. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119462. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119463. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119464. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119465. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119466. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119467. 14,
  119468. };
  119469. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119470. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119471. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119472. };
  119473. static long _vq_quantmap__44c7_s_p8_0[] = {
  119474. 13, 11, 9, 7, 5, 3, 1, 0,
  119475. 2, 4, 6, 8, 10, 12, 14,
  119476. };
  119477. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119478. _vq_quantthresh__44c7_s_p8_0,
  119479. _vq_quantmap__44c7_s_p8_0,
  119480. 15,
  119481. 15
  119482. };
  119483. static static_codebook _44c7_s_p8_0 = {
  119484. 2, 225,
  119485. _vq_lengthlist__44c7_s_p8_0,
  119486. 1, -520986624, 1620377600, 4, 0,
  119487. _vq_quantlist__44c7_s_p8_0,
  119488. NULL,
  119489. &_vq_auxt__44c7_s_p8_0,
  119490. NULL,
  119491. 0
  119492. };
  119493. static long _vq_quantlist__44c7_s_p8_1[] = {
  119494. 10,
  119495. 9,
  119496. 11,
  119497. 8,
  119498. 12,
  119499. 7,
  119500. 13,
  119501. 6,
  119502. 14,
  119503. 5,
  119504. 15,
  119505. 4,
  119506. 16,
  119507. 3,
  119508. 17,
  119509. 2,
  119510. 18,
  119511. 1,
  119512. 19,
  119513. 0,
  119514. 20,
  119515. };
  119516. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119517. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119518. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119519. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119520. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119521. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119522. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119523. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119524. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119525. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119526. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119527. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119528. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119529. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119530. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119531. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119532. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119533. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119534. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119535. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119536. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119537. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119538. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119539. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119540. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119541. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119542. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119543. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119544. 10,10,10,10,10,10,10,10,10,
  119545. };
  119546. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119547. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119548. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119549. 6.5, 7.5, 8.5, 9.5,
  119550. };
  119551. static long _vq_quantmap__44c7_s_p8_1[] = {
  119552. 19, 17, 15, 13, 11, 9, 7, 5,
  119553. 3, 1, 0, 2, 4, 6, 8, 10,
  119554. 12, 14, 16, 18, 20,
  119555. };
  119556. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119557. _vq_quantthresh__44c7_s_p8_1,
  119558. _vq_quantmap__44c7_s_p8_1,
  119559. 21,
  119560. 21
  119561. };
  119562. static static_codebook _44c7_s_p8_1 = {
  119563. 2, 441,
  119564. _vq_lengthlist__44c7_s_p8_1,
  119565. 1, -529268736, 1611661312, 5, 0,
  119566. _vq_quantlist__44c7_s_p8_1,
  119567. NULL,
  119568. &_vq_auxt__44c7_s_p8_1,
  119569. NULL,
  119570. 0
  119571. };
  119572. static long _vq_quantlist__44c7_s_p9_0[] = {
  119573. 6,
  119574. 5,
  119575. 7,
  119576. 4,
  119577. 8,
  119578. 3,
  119579. 9,
  119580. 2,
  119581. 10,
  119582. 1,
  119583. 11,
  119584. 0,
  119585. 12,
  119586. };
  119587. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119588. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119589. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119590. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119591. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119592. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119593. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119594. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119595. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119596. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119597. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119598. 11,11,11,11,11,11,11,11,11,
  119599. };
  119600. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119601. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119602. 1592.5, 2229.5, 2866.5, 3503.5,
  119603. };
  119604. static long _vq_quantmap__44c7_s_p9_0[] = {
  119605. 11, 9, 7, 5, 3, 1, 0, 2,
  119606. 4, 6, 8, 10, 12,
  119607. };
  119608. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119609. _vq_quantthresh__44c7_s_p9_0,
  119610. _vq_quantmap__44c7_s_p9_0,
  119611. 13,
  119612. 13
  119613. };
  119614. static static_codebook _44c7_s_p9_0 = {
  119615. 2, 169,
  119616. _vq_lengthlist__44c7_s_p9_0,
  119617. 1, -511845376, 1630791680, 4, 0,
  119618. _vq_quantlist__44c7_s_p9_0,
  119619. NULL,
  119620. &_vq_auxt__44c7_s_p9_0,
  119621. NULL,
  119622. 0
  119623. };
  119624. static long _vq_quantlist__44c7_s_p9_1[] = {
  119625. 6,
  119626. 5,
  119627. 7,
  119628. 4,
  119629. 8,
  119630. 3,
  119631. 9,
  119632. 2,
  119633. 10,
  119634. 1,
  119635. 11,
  119636. 0,
  119637. 12,
  119638. };
  119639. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119640. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119641. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119642. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119643. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119644. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119645. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119646. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119647. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119648. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119649. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119650. 15,11,11,10,10,12,12,12,12,
  119651. };
  119652. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119653. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119654. 122.5, 171.5, 220.5, 269.5,
  119655. };
  119656. static long _vq_quantmap__44c7_s_p9_1[] = {
  119657. 11, 9, 7, 5, 3, 1, 0, 2,
  119658. 4, 6, 8, 10, 12,
  119659. };
  119660. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119661. _vq_quantthresh__44c7_s_p9_1,
  119662. _vq_quantmap__44c7_s_p9_1,
  119663. 13,
  119664. 13
  119665. };
  119666. static static_codebook _44c7_s_p9_1 = {
  119667. 2, 169,
  119668. _vq_lengthlist__44c7_s_p9_1,
  119669. 1, -518889472, 1622704128, 4, 0,
  119670. _vq_quantlist__44c7_s_p9_1,
  119671. NULL,
  119672. &_vq_auxt__44c7_s_p9_1,
  119673. NULL,
  119674. 0
  119675. };
  119676. static long _vq_quantlist__44c7_s_p9_2[] = {
  119677. 24,
  119678. 23,
  119679. 25,
  119680. 22,
  119681. 26,
  119682. 21,
  119683. 27,
  119684. 20,
  119685. 28,
  119686. 19,
  119687. 29,
  119688. 18,
  119689. 30,
  119690. 17,
  119691. 31,
  119692. 16,
  119693. 32,
  119694. 15,
  119695. 33,
  119696. 14,
  119697. 34,
  119698. 13,
  119699. 35,
  119700. 12,
  119701. 36,
  119702. 11,
  119703. 37,
  119704. 10,
  119705. 38,
  119706. 9,
  119707. 39,
  119708. 8,
  119709. 40,
  119710. 7,
  119711. 41,
  119712. 6,
  119713. 42,
  119714. 5,
  119715. 43,
  119716. 4,
  119717. 44,
  119718. 3,
  119719. 45,
  119720. 2,
  119721. 46,
  119722. 1,
  119723. 47,
  119724. 0,
  119725. 48,
  119726. };
  119727. static long _vq_lengthlist__44c7_s_p9_2[] = {
  119728. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119729. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119730. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119731. 7,
  119732. };
  119733. static float _vq_quantthresh__44c7_s_p9_2[] = {
  119734. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119735. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119736. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119737. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119738. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119739. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119740. };
  119741. static long _vq_quantmap__44c7_s_p9_2[] = {
  119742. 47, 45, 43, 41, 39, 37, 35, 33,
  119743. 31, 29, 27, 25, 23, 21, 19, 17,
  119744. 15, 13, 11, 9, 7, 5, 3, 1,
  119745. 0, 2, 4, 6, 8, 10, 12, 14,
  119746. 16, 18, 20, 22, 24, 26, 28, 30,
  119747. 32, 34, 36, 38, 40, 42, 44, 46,
  119748. 48,
  119749. };
  119750. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  119751. _vq_quantthresh__44c7_s_p9_2,
  119752. _vq_quantmap__44c7_s_p9_2,
  119753. 49,
  119754. 49
  119755. };
  119756. static static_codebook _44c7_s_p9_2 = {
  119757. 1, 49,
  119758. _vq_lengthlist__44c7_s_p9_2,
  119759. 1, -526909440, 1611661312, 6, 0,
  119760. _vq_quantlist__44c7_s_p9_2,
  119761. NULL,
  119762. &_vq_auxt__44c7_s_p9_2,
  119763. NULL,
  119764. 0
  119765. };
  119766. static long _huff_lengthlist__44c7_s_short[] = {
  119767. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  119768. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  119769. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  119770. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  119771. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  119772. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  119773. 10, 9,11,14,
  119774. };
  119775. static static_codebook _huff_book__44c7_s_short = {
  119776. 2, 100,
  119777. _huff_lengthlist__44c7_s_short,
  119778. 0, 0, 0, 0, 0,
  119779. NULL,
  119780. NULL,
  119781. NULL,
  119782. NULL,
  119783. 0
  119784. };
  119785. static long _huff_lengthlist__44c8_s_long[] = {
  119786. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  119787. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  119788. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  119789. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  119790. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  119791. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  119792. 11, 9, 9,10,
  119793. };
  119794. static static_codebook _huff_book__44c8_s_long = {
  119795. 2, 100,
  119796. _huff_lengthlist__44c8_s_long,
  119797. 0, 0, 0, 0, 0,
  119798. NULL,
  119799. NULL,
  119800. NULL,
  119801. NULL,
  119802. 0
  119803. };
  119804. static long _vq_quantlist__44c8_s_p1_0[] = {
  119805. 1,
  119806. 0,
  119807. 2,
  119808. };
  119809. static long _vq_lengthlist__44c8_s_p1_0[] = {
  119810. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  119811. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119812. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119813. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119814. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119815. 8,
  119816. };
  119817. static float _vq_quantthresh__44c8_s_p1_0[] = {
  119818. -0.5, 0.5,
  119819. };
  119820. static long _vq_quantmap__44c8_s_p1_0[] = {
  119821. 1, 0, 2,
  119822. };
  119823. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  119824. _vq_quantthresh__44c8_s_p1_0,
  119825. _vq_quantmap__44c8_s_p1_0,
  119826. 3,
  119827. 3
  119828. };
  119829. static static_codebook _44c8_s_p1_0 = {
  119830. 4, 81,
  119831. _vq_lengthlist__44c8_s_p1_0,
  119832. 1, -535822336, 1611661312, 2, 0,
  119833. _vq_quantlist__44c8_s_p1_0,
  119834. NULL,
  119835. &_vq_auxt__44c8_s_p1_0,
  119836. NULL,
  119837. 0
  119838. };
  119839. static long _vq_quantlist__44c8_s_p2_0[] = {
  119840. 2,
  119841. 1,
  119842. 3,
  119843. 0,
  119844. 4,
  119845. };
  119846. static long _vq_lengthlist__44c8_s_p2_0[] = {
  119847. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119848. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119849. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119850. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  119851. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119852. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  119853. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  119854. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119856. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119857. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  119858. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119859. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  119860. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  119861. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  119862. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  119863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119864. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  119865. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  119866. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  119867. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  119868. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  119869. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  119870. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119872. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119873. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  119874. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119875. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  119876. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  119877. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  119878. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119883. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  119884. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119885. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  119886. 13,
  119887. };
  119888. static float _vq_quantthresh__44c8_s_p2_0[] = {
  119889. -1.5, -0.5, 0.5, 1.5,
  119890. };
  119891. static long _vq_quantmap__44c8_s_p2_0[] = {
  119892. 3, 1, 0, 2, 4,
  119893. };
  119894. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  119895. _vq_quantthresh__44c8_s_p2_0,
  119896. _vq_quantmap__44c8_s_p2_0,
  119897. 5,
  119898. 5
  119899. };
  119900. static static_codebook _44c8_s_p2_0 = {
  119901. 4, 625,
  119902. _vq_lengthlist__44c8_s_p2_0,
  119903. 1, -533725184, 1611661312, 3, 0,
  119904. _vq_quantlist__44c8_s_p2_0,
  119905. NULL,
  119906. &_vq_auxt__44c8_s_p2_0,
  119907. NULL,
  119908. 0
  119909. };
  119910. static long _vq_quantlist__44c8_s_p3_0[] = {
  119911. 4,
  119912. 3,
  119913. 5,
  119914. 2,
  119915. 6,
  119916. 1,
  119917. 7,
  119918. 0,
  119919. 8,
  119920. };
  119921. static long _vq_lengthlist__44c8_s_p3_0[] = {
  119922. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119923. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119924. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119925. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119927. 0,
  119928. };
  119929. static float _vq_quantthresh__44c8_s_p3_0[] = {
  119930. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119931. };
  119932. static long _vq_quantmap__44c8_s_p3_0[] = {
  119933. 7, 5, 3, 1, 0, 2, 4, 6,
  119934. 8,
  119935. };
  119936. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  119937. _vq_quantthresh__44c8_s_p3_0,
  119938. _vq_quantmap__44c8_s_p3_0,
  119939. 9,
  119940. 9
  119941. };
  119942. static static_codebook _44c8_s_p3_0 = {
  119943. 2, 81,
  119944. _vq_lengthlist__44c8_s_p3_0,
  119945. 1, -531628032, 1611661312, 4, 0,
  119946. _vq_quantlist__44c8_s_p3_0,
  119947. NULL,
  119948. &_vq_auxt__44c8_s_p3_0,
  119949. NULL,
  119950. 0
  119951. };
  119952. static long _vq_quantlist__44c8_s_p4_0[] = {
  119953. 8,
  119954. 7,
  119955. 9,
  119956. 6,
  119957. 10,
  119958. 5,
  119959. 11,
  119960. 4,
  119961. 12,
  119962. 3,
  119963. 13,
  119964. 2,
  119965. 14,
  119966. 1,
  119967. 15,
  119968. 0,
  119969. 16,
  119970. };
  119971. static long _vq_lengthlist__44c8_s_p4_0[] = {
  119972. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119973. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  119974. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119975. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  119976. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  119977. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119978. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119979. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119980. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119981. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119990. 0,
  119991. };
  119992. static float _vq_quantthresh__44c8_s_p4_0[] = {
  119993. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119994. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119995. };
  119996. static long _vq_quantmap__44c8_s_p4_0[] = {
  119997. 15, 13, 11, 9, 7, 5, 3, 1,
  119998. 0, 2, 4, 6, 8, 10, 12, 14,
  119999. 16,
  120000. };
  120001. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  120002. _vq_quantthresh__44c8_s_p4_0,
  120003. _vq_quantmap__44c8_s_p4_0,
  120004. 17,
  120005. 17
  120006. };
  120007. static static_codebook _44c8_s_p4_0 = {
  120008. 2, 289,
  120009. _vq_lengthlist__44c8_s_p4_0,
  120010. 1, -529530880, 1611661312, 5, 0,
  120011. _vq_quantlist__44c8_s_p4_0,
  120012. NULL,
  120013. &_vq_auxt__44c8_s_p4_0,
  120014. NULL,
  120015. 0
  120016. };
  120017. static long _vq_quantlist__44c8_s_p5_0[] = {
  120018. 1,
  120019. 0,
  120020. 2,
  120021. };
  120022. static long _vq_lengthlist__44c8_s_p5_0[] = {
  120023. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  120024. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  120025. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  120026. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  120027. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  120028. 12,
  120029. };
  120030. static float _vq_quantthresh__44c8_s_p5_0[] = {
  120031. -5.5, 5.5,
  120032. };
  120033. static long _vq_quantmap__44c8_s_p5_0[] = {
  120034. 1, 0, 2,
  120035. };
  120036. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  120037. _vq_quantthresh__44c8_s_p5_0,
  120038. _vq_quantmap__44c8_s_p5_0,
  120039. 3,
  120040. 3
  120041. };
  120042. static static_codebook _44c8_s_p5_0 = {
  120043. 4, 81,
  120044. _vq_lengthlist__44c8_s_p5_0,
  120045. 1, -529137664, 1618345984, 2, 0,
  120046. _vq_quantlist__44c8_s_p5_0,
  120047. NULL,
  120048. &_vq_auxt__44c8_s_p5_0,
  120049. NULL,
  120050. 0
  120051. };
  120052. static long _vq_quantlist__44c8_s_p5_1[] = {
  120053. 5,
  120054. 4,
  120055. 6,
  120056. 3,
  120057. 7,
  120058. 2,
  120059. 8,
  120060. 1,
  120061. 9,
  120062. 0,
  120063. 10,
  120064. };
  120065. static long _vq_lengthlist__44c8_s_p5_1[] = {
  120066. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  120067. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  120068. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  120069. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  120070. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  120071. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  120072. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  120073. 11,11,11, 7, 7, 7, 7, 8, 8,
  120074. };
  120075. static float _vq_quantthresh__44c8_s_p5_1[] = {
  120076. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120077. 3.5, 4.5,
  120078. };
  120079. static long _vq_quantmap__44c8_s_p5_1[] = {
  120080. 9, 7, 5, 3, 1, 0, 2, 4,
  120081. 6, 8, 10,
  120082. };
  120083. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  120084. _vq_quantthresh__44c8_s_p5_1,
  120085. _vq_quantmap__44c8_s_p5_1,
  120086. 11,
  120087. 11
  120088. };
  120089. static static_codebook _44c8_s_p5_1 = {
  120090. 2, 121,
  120091. _vq_lengthlist__44c8_s_p5_1,
  120092. 1, -531365888, 1611661312, 4, 0,
  120093. _vq_quantlist__44c8_s_p5_1,
  120094. NULL,
  120095. &_vq_auxt__44c8_s_p5_1,
  120096. NULL,
  120097. 0
  120098. };
  120099. static long _vq_quantlist__44c8_s_p6_0[] = {
  120100. 6,
  120101. 5,
  120102. 7,
  120103. 4,
  120104. 8,
  120105. 3,
  120106. 9,
  120107. 2,
  120108. 10,
  120109. 1,
  120110. 11,
  120111. 0,
  120112. 12,
  120113. };
  120114. static long _vq_lengthlist__44c8_s_p6_0[] = {
  120115. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  120116. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  120117. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  120118. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  120119. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  120120. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  120121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120125. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120126. };
  120127. static float _vq_quantthresh__44c8_s_p6_0[] = {
  120128. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120129. 12.5, 17.5, 22.5, 27.5,
  120130. };
  120131. static long _vq_quantmap__44c8_s_p6_0[] = {
  120132. 11, 9, 7, 5, 3, 1, 0, 2,
  120133. 4, 6, 8, 10, 12,
  120134. };
  120135. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  120136. _vq_quantthresh__44c8_s_p6_0,
  120137. _vq_quantmap__44c8_s_p6_0,
  120138. 13,
  120139. 13
  120140. };
  120141. static static_codebook _44c8_s_p6_0 = {
  120142. 2, 169,
  120143. _vq_lengthlist__44c8_s_p6_0,
  120144. 1, -526516224, 1616117760, 4, 0,
  120145. _vq_quantlist__44c8_s_p6_0,
  120146. NULL,
  120147. &_vq_auxt__44c8_s_p6_0,
  120148. NULL,
  120149. 0
  120150. };
  120151. static long _vq_quantlist__44c8_s_p6_1[] = {
  120152. 2,
  120153. 1,
  120154. 3,
  120155. 0,
  120156. 4,
  120157. };
  120158. static long _vq_lengthlist__44c8_s_p6_1[] = {
  120159. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  120160. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  120161. };
  120162. static float _vq_quantthresh__44c8_s_p6_1[] = {
  120163. -1.5, -0.5, 0.5, 1.5,
  120164. };
  120165. static long _vq_quantmap__44c8_s_p6_1[] = {
  120166. 3, 1, 0, 2, 4,
  120167. };
  120168. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  120169. _vq_quantthresh__44c8_s_p6_1,
  120170. _vq_quantmap__44c8_s_p6_1,
  120171. 5,
  120172. 5
  120173. };
  120174. static static_codebook _44c8_s_p6_1 = {
  120175. 2, 25,
  120176. _vq_lengthlist__44c8_s_p6_1,
  120177. 1, -533725184, 1611661312, 3, 0,
  120178. _vq_quantlist__44c8_s_p6_1,
  120179. NULL,
  120180. &_vq_auxt__44c8_s_p6_1,
  120181. NULL,
  120182. 0
  120183. };
  120184. static long _vq_quantlist__44c8_s_p7_0[] = {
  120185. 6,
  120186. 5,
  120187. 7,
  120188. 4,
  120189. 8,
  120190. 3,
  120191. 9,
  120192. 2,
  120193. 10,
  120194. 1,
  120195. 11,
  120196. 0,
  120197. 12,
  120198. };
  120199. static long _vq_lengthlist__44c8_s_p7_0[] = {
  120200. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  120201. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  120202. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  120203. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  120204. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  120205. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  120206. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  120207. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  120208. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  120209. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  120210. 20,13,13,13,13,14,13,15,15,
  120211. };
  120212. static float _vq_quantthresh__44c8_s_p7_0[] = {
  120213. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120214. 27.5, 38.5, 49.5, 60.5,
  120215. };
  120216. static long _vq_quantmap__44c8_s_p7_0[] = {
  120217. 11, 9, 7, 5, 3, 1, 0, 2,
  120218. 4, 6, 8, 10, 12,
  120219. };
  120220. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  120221. _vq_quantthresh__44c8_s_p7_0,
  120222. _vq_quantmap__44c8_s_p7_0,
  120223. 13,
  120224. 13
  120225. };
  120226. static static_codebook _44c8_s_p7_0 = {
  120227. 2, 169,
  120228. _vq_lengthlist__44c8_s_p7_0,
  120229. 1, -523206656, 1618345984, 4, 0,
  120230. _vq_quantlist__44c8_s_p7_0,
  120231. NULL,
  120232. &_vq_auxt__44c8_s_p7_0,
  120233. NULL,
  120234. 0
  120235. };
  120236. static long _vq_quantlist__44c8_s_p7_1[] = {
  120237. 5,
  120238. 4,
  120239. 6,
  120240. 3,
  120241. 7,
  120242. 2,
  120243. 8,
  120244. 1,
  120245. 9,
  120246. 0,
  120247. 10,
  120248. };
  120249. static long _vq_lengthlist__44c8_s_p7_1[] = {
  120250. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  120251. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120252. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120253. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120254. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120255. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120256. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120257. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120258. };
  120259. static float _vq_quantthresh__44c8_s_p7_1[] = {
  120260. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120261. 3.5, 4.5,
  120262. };
  120263. static long _vq_quantmap__44c8_s_p7_1[] = {
  120264. 9, 7, 5, 3, 1, 0, 2, 4,
  120265. 6, 8, 10,
  120266. };
  120267. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  120268. _vq_quantthresh__44c8_s_p7_1,
  120269. _vq_quantmap__44c8_s_p7_1,
  120270. 11,
  120271. 11
  120272. };
  120273. static static_codebook _44c8_s_p7_1 = {
  120274. 2, 121,
  120275. _vq_lengthlist__44c8_s_p7_1,
  120276. 1, -531365888, 1611661312, 4, 0,
  120277. _vq_quantlist__44c8_s_p7_1,
  120278. NULL,
  120279. &_vq_auxt__44c8_s_p7_1,
  120280. NULL,
  120281. 0
  120282. };
  120283. static long _vq_quantlist__44c8_s_p8_0[] = {
  120284. 7,
  120285. 6,
  120286. 8,
  120287. 5,
  120288. 9,
  120289. 4,
  120290. 10,
  120291. 3,
  120292. 11,
  120293. 2,
  120294. 12,
  120295. 1,
  120296. 13,
  120297. 0,
  120298. 14,
  120299. };
  120300. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120301. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120302. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120303. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120304. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120305. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120306. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120307. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120308. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120309. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120310. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120311. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120312. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120313. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120314. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120315. 15,
  120316. };
  120317. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120318. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120319. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120320. };
  120321. static long _vq_quantmap__44c8_s_p8_0[] = {
  120322. 13, 11, 9, 7, 5, 3, 1, 0,
  120323. 2, 4, 6, 8, 10, 12, 14,
  120324. };
  120325. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120326. _vq_quantthresh__44c8_s_p8_0,
  120327. _vq_quantmap__44c8_s_p8_0,
  120328. 15,
  120329. 15
  120330. };
  120331. static static_codebook _44c8_s_p8_0 = {
  120332. 2, 225,
  120333. _vq_lengthlist__44c8_s_p8_0,
  120334. 1, -520986624, 1620377600, 4, 0,
  120335. _vq_quantlist__44c8_s_p8_0,
  120336. NULL,
  120337. &_vq_auxt__44c8_s_p8_0,
  120338. NULL,
  120339. 0
  120340. };
  120341. static long _vq_quantlist__44c8_s_p8_1[] = {
  120342. 10,
  120343. 9,
  120344. 11,
  120345. 8,
  120346. 12,
  120347. 7,
  120348. 13,
  120349. 6,
  120350. 14,
  120351. 5,
  120352. 15,
  120353. 4,
  120354. 16,
  120355. 3,
  120356. 17,
  120357. 2,
  120358. 18,
  120359. 1,
  120360. 19,
  120361. 0,
  120362. 20,
  120363. };
  120364. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120365. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120366. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120367. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120368. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120369. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120370. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120371. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120372. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120373. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120374. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120375. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120376. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120377. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  120378. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120379. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120380. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  120381. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  120382. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  120383. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  120384. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  120385. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  120386. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  120387. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120388. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  120389. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  120390. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  120391. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120392. 10, 9, 9,10,10, 9,10, 9, 9,
  120393. };
  120394. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120395. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120396. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120397. 6.5, 7.5, 8.5, 9.5,
  120398. };
  120399. static long _vq_quantmap__44c8_s_p8_1[] = {
  120400. 19, 17, 15, 13, 11, 9, 7, 5,
  120401. 3, 1, 0, 2, 4, 6, 8, 10,
  120402. 12, 14, 16, 18, 20,
  120403. };
  120404. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120405. _vq_quantthresh__44c8_s_p8_1,
  120406. _vq_quantmap__44c8_s_p8_1,
  120407. 21,
  120408. 21
  120409. };
  120410. static static_codebook _44c8_s_p8_1 = {
  120411. 2, 441,
  120412. _vq_lengthlist__44c8_s_p8_1,
  120413. 1, -529268736, 1611661312, 5, 0,
  120414. _vq_quantlist__44c8_s_p8_1,
  120415. NULL,
  120416. &_vq_auxt__44c8_s_p8_1,
  120417. NULL,
  120418. 0
  120419. };
  120420. static long _vq_quantlist__44c8_s_p9_0[] = {
  120421. 8,
  120422. 7,
  120423. 9,
  120424. 6,
  120425. 10,
  120426. 5,
  120427. 11,
  120428. 4,
  120429. 12,
  120430. 3,
  120431. 13,
  120432. 2,
  120433. 14,
  120434. 1,
  120435. 15,
  120436. 0,
  120437. 16,
  120438. };
  120439. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120440. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120441. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120442. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120443. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120444. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120445. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120446. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120447. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120448. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120449. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120450. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120451. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120452. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120453. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120454. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120455. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120456. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120457. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120458. 10,
  120459. };
  120460. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120461. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120462. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120463. };
  120464. static long _vq_quantmap__44c8_s_p9_0[] = {
  120465. 15, 13, 11, 9, 7, 5, 3, 1,
  120466. 0, 2, 4, 6, 8, 10, 12, 14,
  120467. 16,
  120468. };
  120469. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120470. _vq_quantthresh__44c8_s_p9_0,
  120471. _vq_quantmap__44c8_s_p9_0,
  120472. 17,
  120473. 17
  120474. };
  120475. static static_codebook _44c8_s_p9_0 = {
  120476. 2, 289,
  120477. _vq_lengthlist__44c8_s_p9_0,
  120478. 1, -509798400, 1631393792, 5, 0,
  120479. _vq_quantlist__44c8_s_p9_0,
  120480. NULL,
  120481. &_vq_auxt__44c8_s_p9_0,
  120482. NULL,
  120483. 0
  120484. };
  120485. static long _vq_quantlist__44c8_s_p9_1[] = {
  120486. 9,
  120487. 8,
  120488. 10,
  120489. 7,
  120490. 11,
  120491. 6,
  120492. 12,
  120493. 5,
  120494. 13,
  120495. 4,
  120496. 14,
  120497. 3,
  120498. 15,
  120499. 2,
  120500. 16,
  120501. 1,
  120502. 17,
  120503. 0,
  120504. 18,
  120505. };
  120506. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120507. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120508. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120509. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120510. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120511. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120512. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120513. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120514. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120515. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120516. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120517. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120518. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120519. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120520. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120521. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120522. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120523. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120524. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120525. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120526. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120527. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120528. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120529. 14,13,13,14,14,15,14,15,14,
  120530. };
  120531. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120532. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120533. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120534. 367.5, 416.5,
  120535. };
  120536. static long _vq_quantmap__44c8_s_p9_1[] = {
  120537. 17, 15, 13, 11, 9, 7, 5, 3,
  120538. 1, 0, 2, 4, 6, 8, 10, 12,
  120539. 14, 16, 18,
  120540. };
  120541. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120542. _vq_quantthresh__44c8_s_p9_1,
  120543. _vq_quantmap__44c8_s_p9_1,
  120544. 19,
  120545. 19
  120546. };
  120547. static static_codebook _44c8_s_p9_1 = {
  120548. 2, 361,
  120549. _vq_lengthlist__44c8_s_p9_1,
  120550. 1, -518287360, 1622704128, 5, 0,
  120551. _vq_quantlist__44c8_s_p9_1,
  120552. NULL,
  120553. &_vq_auxt__44c8_s_p9_1,
  120554. NULL,
  120555. 0
  120556. };
  120557. static long _vq_quantlist__44c8_s_p9_2[] = {
  120558. 24,
  120559. 23,
  120560. 25,
  120561. 22,
  120562. 26,
  120563. 21,
  120564. 27,
  120565. 20,
  120566. 28,
  120567. 19,
  120568. 29,
  120569. 18,
  120570. 30,
  120571. 17,
  120572. 31,
  120573. 16,
  120574. 32,
  120575. 15,
  120576. 33,
  120577. 14,
  120578. 34,
  120579. 13,
  120580. 35,
  120581. 12,
  120582. 36,
  120583. 11,
  120584. 37,
  120585. 10,
  120586. 38,
  120587. 9,
  120588. 39,
  120589. 8,
  120590. 40,
  120591. 7,
  120592. 41,
  120593. 6,
  120594. 42,
  120595. 5,
  120596. 43,
  120597. 4,
  120598. 44,
  120599. 3,
  120600. 45,
  120601. 2,
  120602. 46,
  120603. 1,
  120604. 47,
  120605. 0,
  120606. 48,
  120607. };
  120608. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120609. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120610. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120611. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120612. 7,
  120613. };
  120614. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120615. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120616. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120617. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120618. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120619. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120620. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120621. };
  120622. static long _vq_quantmap__44c8_s_p9_2[] = {
  120623. 47, 45, 43, 41, 39, 37, 35, 33,
  120624. 31, 29, 27, 25, 23, 21, 19, 17,
  120625. 15, 13, 11, 9, 7, 5, 3, 1,
  120626. 0, 2, 4, 6, 8, 10, 12, 14,
  120627. 16, 18, 20, 22, 24, 26, 28, 30,
  120628. 32, 34, 36, 38, 40, 42, 44, 46,
  120629. 48,
  120630. };
  120631. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120632. _vq_quantthresh__44c8_s_p9_2,
  120633. _vq_quantmap__44c8_s_p9_2,
  120634. 49,
  120635. 49
  120636. };
  120637. static static_codebook _44c8_s_p9_2 = {
  120638. 1, 49,
  120639. _vq_lengthlist__44c8_s_p9_2,
  120640. 1, -526909440, 1611661312, 6, 0,
  120641. _vq_quantlist__44c8_s_p9_2,
  120642. NULL,
  120643. &_vq_auxt__44c8_s_p9_2,
  120644. NULL,
  120645. 0
  120646. };
  120647. static long _huff_lengthlist__44c8_s_short[] = {
  120648. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120649. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120650. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120651. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120652. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120653. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120654. 10, 9,11,14,
  120655. };
  120656. static static_codebook _huff_book__44c8_s_short = {
  120657. 2, 100,
  120658. _huff_lengthlist__44c8_s_short,
  120659. 0, 0, 0, 0, 0,
  120660. NULL,
  120661. NULL,
  120662. NULL,
  120663. NULL,
  120664. 0
  120665. };
  120666. static long _huff_lengthlist__44c9_s_long[] = {
  120667. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120668. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120669. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120670. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  120671. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  120672. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  120673. 10, 9, 8, 9,
  120674. };
  120675. static static_codebook _huff_book__44c9_s_long = {
  120676. 2, 100,
  120677. _huff_lengthlist__44c9_s_long,
  120678. 0, 0, 0, 0, 0,
  120679. NULL,
  120680. NULL,
  120681. NULL,
  120682. NULL,
  120683. 0
  120684. };
  120685. static long _vq_quantlist__44c9_s_p1_0[] = {
  120686. 1,
  120687. 0,
  120688. 2,
  120689. };
  120690. static long _vq_lengthlist__44c9_s_p1_0[] = {
  120691. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  120692. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120693. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  120694. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120695. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  120696. 7,
  120697. };
  120698. static float _vq_quantthresh__44c9_s_p1_0[] = {
  120699. -0.5, 0.5,
  120700. };
  120701. static long _vq_quantmap__44c9_s_p1_0[] = {
  120702. 1, 0, 2,
  120703. };
  120704. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  120705. _vq_quantthresh__44c9_s_p1_0,
  120706. _vq_quantmap__44c9_s_p1_0,
  120707. 3,
  120708. 3
  120709. };
  120710. static static_codebook _44c9_s_p1_0 = {
  120711. 4, 81,
  120712. _vq_lengthlist__44c9_s_p1_0,
  120713. 1, -535822336, 1611661312, 2, 0,
  120714. _vq_quantlist__44c9_s_p1_0,
  120715. NULL,
  120716. &_vq_auxt__44c9_s_p1_0,
  120717. NULL,
  120718. 0
  120719. };
  120720. static long _vq_quantlist__44c9_s_p2_0[] = {
  120721. 2,
  120722. 1,
  120723. 3,
  120724. 0,
  120725. 4,
  120726. };
  120727. static long _vq_lengthlist__44c9_s_p2_0[] = {
  120728. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120729. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  120730. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  120731. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  120732. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  120733. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  120734. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  120735. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  120736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120737. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  120738. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  120739. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  120740. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  120741. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  120742. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  120743. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  120744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120745. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  120746. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  120747. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  120748. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  120749. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  120750. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  120751. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120753. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  120754. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  120755. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  120756. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  120757. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  120758. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  120759. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120764. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  120765. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  120766. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  120767. 12,
  120768. };
  120769. static float _vq_quantthresh__44c9_s_p2_0[] = {
  120770. -1.5, -0.5, 0.5, 1.5,
  120771. };
  120772. static long _vq_quantmap__44c9_s_p2_0[] = {
  120773. 3, 1, 0, 2, 4,
  120774. };
  120775. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  120776. _vq_quantthresh__44c9_s_p2_0,
  120777. _vq_quantmap__44c9_s_p2_0,
  120778. 5,
  120779. 5
  120780. };
  120781. static static_codebook _44c9_s_p2_0 = {
  120782. 4, 625,
  120783. _vq_lengthlist__44c9_s_p2_0,
  120784. 1, -533725184, 1611661312, 3, 0,
  120785. _vq_quantlist__44c9_s_p2_0,
  120786. NULL,
  120787. &_vq_auxt__44c9_s_p2_0,
  120788. NULL,
  120789. 0
  120790. };
  120791. static long _vq_quantlist__44c9_s_p3_0[] = {
  120792. 4,
  120793. 3,
  120794. 5,
  120795. 2,
  120796. 6,
  120797. 1,
  120798. 7,
  120799. 0,
  120800. 8,
  120801. };
  120802. static long _vq_lengthlist__44c9_s_p3_0[] = {
  120803. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  120804. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  120805. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  120806. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  120807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120808. 0,
  120809. };
  120810. static float _vq_quantthresh__44c9_s_p3_0[] = {
  120811. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120812. };
  120813. static long _vq_quantmap__44c9_s_p3_0[] = {
  120814. 7, 5, 3, 1, 0, 2, 4, 6,
  120815. 8,
  120816. };
  120817. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  120818. _vq_quantthresh__44c9_s_p3_0,
  120819. _vq_quantmap__44c9_s_p3_0,
  120820. 9,
  120821. 9
  120822. };
  120823. static static_codebook _44c9_s_p3_0 = {
  120824. 2, 81,
  120825. _vq_lengthlist__44c9_s_p3_0,
  120826. 1, -531628032, 1611661312, 4, 0,
  120827. _vq_quantlist__44c9_s_p3_0,
  120828. NULL,
  120829. &_vq_auxt__44c9_s_p3_0,
  120830. NULL,
  120831. 0
  120832. };
  120833. static long _vq_quantlist__44c9_s_p4_0[] = {
  120834. 8,
  120835. 7,
  120836. 9,
  120837. 6,
  120838. 10,
  120839. 5,
  120840. 11,
  120841. 4,
  120842. 12,
  120843. 3,
  120844. 13,
  120845. 2,
  120846. 14,
  120847. 1,
  120848. 15,
  120849. 0,
  120850. 16,
  120851. };
  120852. static long _vq_lengthlist__44c9_s_p4_0[] = {
  120853. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  120854. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  120855. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  120856. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  120857. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  120858. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  120859. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  120860. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120861. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120862. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  120863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120871. 0,
  120872. };
  120873. static float _vq_quantthresh__44c9_s_p4_0[] = {
  120874. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120875. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120876. };
  120877. static long _vq_quantmap__44c9_s_p4_0[] = {
  120878. 15, 13, 11, 9, 7, 5, 3, 1,
  120879. 0, 2, 4, 6, 8, 10, 12, 14,
  120880. 16,
  120881. };
  120882. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  120883. _vq_quantthresh__44c9_s_p4_0,
  120884. _vq_quantmap__44c9_s_p4_0,
  120885. 17,
  120886. 17
  120887. };
  120888. static static_codebook _44c9_s_p4_0 = {
  120889. 2, 289,
  120890. _vq_lengthlist__44c9_s_p4_0,
  120891. 1, -529530880, 1611661312, 5, 0,
  120892. _vq_quantlist__44c9_s_p4_0,
  120893. NULL,
  120894. &_vq_auxt__44c9_s_p4_0,
  120895. NULL,
  120896. 0
  120897. };
  120898. static long _vq_quantlist__44c9_s_p5_0[] = {
  120899. 1,
  120900. 0,
  120901. 2,
  120902. };
  120903. static long _vq_lengthlist__44c9_s_p5_0[] = {
  120904. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  120905. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  120906. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  120907. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  120908. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  120909. 12,
  120910. };
  120911. static float _vq_quantthresh__44c9_s_p5_0[] = {
  120912. -5.5, 5.5,
  120913. };
  120914. static long _vq_quantmap__44c9_s_p5_0[] = {
  120915. 1, 0, 2,
  120916. };
  120917. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  120918. _vq_quantthresh__44c9_s_p5_0,
  120919. _vq_quantmap__44c9_s_p5_0,
  120920. 3,
  120921. 3
  120922. };
  120923. static static_codebook _44c9_s_p5_0 = {
  120924. 4, 81,
  120925. _vq_lengthlist__44c9_s_p5_0,
  120926. 1, -529137664, 1618345984, 2, 0,
  120927. _vq_quantlist__44c9_s_p5_0,
  120928. NULL,
  120929. &_vq_auxt__44c9_s_p5_0,
  120930. NULL,
  120931. 0
  120932. };
  120933. static long _vq_quantlist__44c9_s_p5_1[] = {
  120934. 5,
  120935. 4,
  120936. 6,
  120937. 3,
  120938. 7,
  120939. 2,
  120940. 8,
  120941. 1,
  120942. 9,
  120943. 0,
  120944. 10,
  120945. };
  120946. static long _vq_lengthlist__44c9_s_p5_1[] = {
  120947. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  120948. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  120949. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  120950. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  120951. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  120952. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  120953. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  120954. 11,11,11, 7, 7, 7, 7, 7, 7,
  120955. };
  120956. static float _vq_quantthresh__44c9_s_p5_1[] = {
  120957. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120958. 3.5, 4.5,
  120959. };
  120960. static long _vq_quantmap__44c9_s_p5_1[] = {
  120961. 9, 7, 5, 3, 1, 0, 2, 4,
  120962. 6, 8, 10,
  120963. };
  120964. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  120965. _vq_quantthresh__44c9_s_p5_1,
  120966. _vq_quantmap__44c9_s_p5_1,
  120967. 11,
  120968. 11
  120969. };
  120970. static static_codebook _44c9_s_p5_1 = {
  120971. 2, 121,
  120972. _vq_lengthlist__44c9_s_p5_1,
  120973. 1, -531365888, 1611661312, 4, 0,
  120974. _vq_quantlist__44c9_s_p5_1,
  120975. NULL,
  120976. &_vq_auxt__44c9_s_p5_1,
  120977. NULL,
  120978. 0
  120979. };
  120980. static long _vq_quantlist__44c9_s_p6_0[] = {
  120981. 6,
  120982. 5,
  120983. 7,
  120984. 4,
  120985. 8,
  120986. 3,
  120987. 9,
  120988. 2,
  120989. 10,
  120990. 1,
  120991. 11,
  120992. 0,
  120993. 12,
  120994. };
  120995. static long _vq_lengthlist__44c9_s_p6_0[] = {
  120996. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  120997. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  120998. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  120999. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  121000. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  121001. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  121002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121006. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121007. };
  121008. static float _vq_quantthresh__44c9_s_p6_0[] = {
  121009. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  121010. 12.5, 17.5, 22.5, 27.5,
  121011. };
  121012. static long _vq_quantmap__44c9_s_p6_0[] = {
  121013. 11, 9, 7, 5, 3, 1, 0, 2,
  121014. 4, 6, 8, 10, 12,
  121015. };
  121016. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  121017. _vq_quantthresh__44c9_s_p6_0,
  121018. _vq_quantmap__44c9_s_p6_0,
  121019. 13,
  121020. 13
  121021. };
  121022. static static_codebook _44c9_s_p6_0 = {
  121023. 2, 169,
  121024. _vq_lengthlist__44c9_s_p6_0,
  121025. 1, -526516224, 1616117760, 4, 0,
  121026. _vq_quantlist__44c9_s_p6_0,
  121027. NULL,
  121028. &_vq_auxt__44c9_s_p6_0,
  121029. NULL,
  121030. 0
  121031. };
  121032. static long _vq_quantlist__44c9_s_p6_1[] = {
  121033. 2,
  121034. 1,
  121035. 3,
  121036. 0,
  121037. 4,
  121038. };
  121039. static long _vq_lengthlist__44c9_s_p6_1[] = {
  121040. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  121041. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  121042. };
  121043. static float _vq_quantthresh__44c9_s_p6_1[] = {
  121044. -1.5, -0.5, 0.5, 1.5,
  121045. };
  121046. static long _vq_quantmap__44c9_s_p6_1[] = {
  121047. 3, 1, 0, 2, 4,
  121048. };
  121049. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  121050. _vq_quantthresh__44c9_s_p6_1,
  121051. _vq_quantmap__44c9_s_p6_1,
  121052. 5,
  121053. 5
  121054. };
  121055. static static_codebook _44c9_s_p6_1 = {
  121056. 2, 25,
  121057. _vq_lengthlist__44c9_s_p6_1,
  121058. 1, -533725184, 1611661312, 3, 0,
  121059. _vq_quantlist__44c9_s_p6_1,
  121060. NULL,
  121061. &_vq_auxt__44c9_s_p6_1,
  121062. NULL,
  121063. 0
  121064. };
  121065. static long _vq_quantlist__44c9_s_p7_0[] = {
  121066. 6,
  121067. 5,
  121068. 7,
  121069. 4,
  121070. 8,
  121071. 3,
  121072. 9,
  121073. 2,
  121074. 10,
  121075. 1,
  121076. 11,
  121077. 0,
  121078. 12,
  121079. };
  121080. static long _vq_lengthlist__44c9_s_p7_0[] = {
  121081. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  121082. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  121083. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  121084. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  121085. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  121086. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  121087. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  121088. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  121089. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  121090. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  121091. 19,12,12,12,12,13,13,14,14,
  121092. };
  121093. static float _vq_quantthresh__44c9_s_p7_0[] = {
  121094. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  121095. 27.5, 38.5, 49.5, 60.5,
  121096. };
  121097. static long _vq_quantmap__44c9_s_p7_0[] = {
  121098. 11, 9, 7, 5, 3, 1, 0, 2,
  121099. 4, 6, 8, 10, 12,
  121100. };
  121101. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  121102. _vq_quantthresh__44c9_s_p7_0,
  121103. _vq_quantmap__44c9_s_p7_0,
  121104. 13,
  121105. 13
  121106. };
  121107. static static_codebook _44c9_s_p7_0 = {
  121108. 2, 169,
  121109. _vq_lengthlist__44c9_s_p7_0,
  121110. 1, -523206656, 1618345984, 4, 0,
  121111. _vq_quantlist__44c9_s_p7_0,
  121112. NULL,
  121113. &_vq_auxt__44c9_s_p7_0,
  121114. NULL,
  121115. 0
  121116. };
  121117. static long _vq_quantlist__44c9_s_p7_1[] = {
  121118. 5,
  121119. 4,
  121120. 6,
  121121. 3,
  121122. 7,
  121123. 2,
  121124. 8,
  121125. 1,
  121126. 9,
  121127. 0,
  121128. 10,
  121129. };
  121130. static long _vq_lengthlist__44c9_s_p7_1[] = {
  121131. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  121132. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121133. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  121134. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121135. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  121136. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  121137. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  121138. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121139. };
  121140. static float _vq_quantthresh__44c9_s_p7_1[] = {
  121141. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121142. 3.5, 4.5,
  121143. };
  121144. static long _vq_quantmap__44c9_s_p7_1[] = {
  121145. 9, 7, 5, 3, 1, 0, 2, 4,
  121146. 6, 8, 10,
  121147. };
  121148. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  121149. _vq_quantthresh__44c9_s_p7_1,
  121150. _vq_quantmap__44c9_s_p7_1,
  121151. 11,
  121152. 11
  121153. };
  121154. static static_codebook _44c9_s_p7_1 = {
  121155. 2, 121,
  121156. _vq_lengthlist__44c9_s_p7_1,
  121157. 1, -531365888, 1611661312, 4, 0,
  121158. _vq_quantlist__44c9_s_p7_1,
  121159. NULL,
  121160. &_vq_auxt__44c9_s_p7_1,
  121161. NULL,
  121162. 0
  121163. };
  121164. static long _vq_quantlist__44c9_s_p8_0[] = {
  121165. 7,
  121166. 6,
  121167. 8,
  121168. 5,
  121169. 9,
  121170. 4,
  121171. 10,
  121172. 3,
  121173. 11,
  121174. 2,
  121175. 12,
  121176. 1,
  121177. 13,
  121178. 0,
  121179. 14,
  121180. };
  121181. static long _vq_lengthlist__44c9_s_p8_0[] = {
  121182. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  121183. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  121184. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  121185. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  121186. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  121187. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  121188. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  121189. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  121190. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  121191. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  121192. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  121193. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  121194. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  121195. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  121196. 14,
  121197. };
  121198. static float _vq_quantthresh__44c9_s_p8_0[] = {
  121199. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  121200. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  121201. };
  121202. static long _vq_quantmap__44c9_s_p8_0[] = {
  121203. 13, 11, 9, 7, 5, 3, 1, 0,
  121204. 2, 4, 6, 8, 10, 12, 14,
  121205. };
  121206. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  121207. _vq_quantthresh__44c9_s_p8_0,
  121208. _vq_quantmap__44c9_s_p8_0,
  121209. 15,
  121210. 15
  121211. };
  121212. static static_codebook _44c9_s_p8_0 = {
  121213. 2, 225,
  121214. _vq_lengthlist__44c9_s_p8_0,
  121215. 1, -520986624, 1620377600, 4, 0,
  121216. _vq_quantlist__44c9_s_p8_0,
  121217. NULL,
  121218. &_vq_auxt__44c9_s_p8_0,
  121219. NULL,
  121220. 0
  121221. };
  121222. static long _vq_quantlist__44c9_s_p8_1[] = {
  121223. 10,
  121224. 9,
  121225. 11,
  121226. 8,
  121227. 12,
  121228. 7,
  121229. 13,
  121230. 6,
  121231. 14,
  121232. 5,
  121233. 15,
  121234. 4,
  121235. 16,
  121236. 3,
  121237. 17,
  121238. 2,
  121239. 18,
  121240. 1,
  121241. 19,
  121242. 0,
  121243. 20,
  121244. };
  121245. static long _vq_lengthlist__44c9_s_p8_1[] = {
  121246. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  121247. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  121248. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  121249. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  121250. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121251. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  121252. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  121253. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  121254. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121255. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121256. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121257. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121258. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121259. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121260. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121261. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  121262. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  121263. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  121264. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  121265. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121266. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  121267. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  121268. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  121269. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121270. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  121271. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  121272. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  121273. 9, 9, 9,10, 9, 9, 9, 9, 9,
  121274. };
  121275. static float _vq_quantthresh__44c9_s_p8_1[] = {
  121276. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121277. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121278. 6.5, 7.5, 8.5, 9.5,
  121279. };
  121280. static long _vq_quantmap__44c9_s_p8_1[] = {
  121281. 19, 17, 15, 13, 11, 9, 7, 5,
  121282. 3, 1, 0, 2, 4, 6, 8, 10,
  121283. 12, 14, 16, 18, 20,
  121284. };
  121285. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121286. _vq_quantthresh__44c9_s_p8_1,
  121287. _vq_quantmap__44c9_s_p8_1,
  121288. 21,
  121289. 21
  121290. };
  121291. static static_codebook _44c9_s_p8_1 = {
  121292. 2, 441,
  121293. _vq_lengthlist__44c9_s_p8_1,
  121294. 1, -529268736, 1611661312, 5, 0,
  121295. _vq_quantlist__44c9_s_p8_1,
  121296. NULL,
  121297. &_vq_auxt__44c9_s_p8_1,
  121298. NULL,
  121299. 0
  121300. };
  121301. static long _vq_quantlist__44c9_s_p9_0[] = {
  121302. 9,
  121303. 8,
  121304. 10,
  121305. 7,
  121306. 11,
  121307. 6,
  121308. 12,
  121309. 5,
  121310. 13,
  121311. 4,
  121312. 14,
  121313. 3,
  121314. 15,
  121315. 2,
  121316. 16,
  121317. 1,
  121318. 17,
  121319. 0,
  121320. 18,
  121321. };
  121322. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121323. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121324. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121325. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121326. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121327. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121328. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121329. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121330. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121331. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121332. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121333. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121334. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121335. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121336. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121337. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121338. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121339. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  121340. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121341. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121342. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121343. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121344. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121345. 11,11,11,11,11,11,11,11,11,
  121346. };
  121347. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121348. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121349. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121350. 6982.5, 7913.5,
  121351. };
  121352. static long _vq_quantmap__44c9_s_p9_0[] = {
  121353. 17, 15, 13, 11, 9, 7, 5, 3,
  121354. 1, 0, 2, 4, 6, 8, 10, 12,
  121355. 14, 16, 18,
  121356. };
  121357. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121358. _vq_quantthresh__44c9_s_p9_0,
  121359. _vq_quantmap__44c9_s_p9_0,
  121360. 19,
  121361. 19
  121362. };
  121363. static static_codebook _44c9_s_p9_0 = {
  121364. 2, 361,
  121365. _vq_lengthlist__44c9_s_p9_0,
  121366. 1, -508535424, 1631393792, 5, 0,
  121367. _vq_quantlist__44c9_s_p9_0,
  121368. NULL,
  121369. &_vq_auxt__44c9_s_p9_0,
  121370. NULL,
  121371. 0
  121372. };
  121373. static long _vq_quantlist__44c9_s_p9_1[] = {
  121374. 9,
  121375. 8,
  121376. 10,
  121377. 7,
  121378. 11,
  121379. 6,
  121380. 12,
  121381. 5,
  121382. 13,
  121383. 4,
  121384. 14,
  121385. 3,
  121386. 15,
  121387. 2,
  121388. 16,
  121389. 1,
  121390. 17,
  121391. 0,
  121392. 18,
  121393. };
  121394. static long _vq_lengthlist__44c9_s_p9_1[] = {
  121395. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121396. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121397. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121398. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121399. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121400. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121401. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121402. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121403. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121404. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121405. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121406. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121407. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121408. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121409. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121410. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121411. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121412. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121413. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121414. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121415. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121416. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121417. 13,13,13,14,13,14,15,15,15,
  121418. };
  121419. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121420. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121421. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121422. 367.5, 416.5,
  121423. };
  121424. static long _vq_quantmap__44c9_s_p9_1[] = {
  121425. 17, 15, 13, 11, 9, 7, 5, 3,
  121426. 1, 0, 2, 4, 6, 8, 10, 12,
  121427. 14, 16, 18,
  121428. };
  121429. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  121430. _vq_quantthresh__44c9_s_p9_1,
  121431. _vq_quantmap__44c9_s_p9_1,
  121432. 19,
  121433. 19
  121434. };
  121435. static static_codebook _44c9_s_p9_1 = {
  121436. 2, 361,
  121437. _vq_lengthlist__44c9_s_p9_1,
  121438. 1, -518287360, 1622704128, 5, 0,
  121439. _vq_quantlist__44c9_s_p9_1,
  121440. NULL,
  121441. &_vq_auxt__44c9_s_p9_1,
  121442. NULL,
  121443. 0
  121444. };
  121445. static long _vq_quantlist__44c9_s_p9_2[] = {
  121446. 24,
  121447. 23,
  121448. 25,
  121449. 22,
  121450. 26,
  121451. 21,
  121452. 27,
  121453. 20,
  121454. 28,
  121455. 19,
  121456. 29,
  121457. 18,
  121458. 30,
  121459. 17,
  121460. 31,
  121461. 16,
  121462. 32,
  121463. 15,
  121464. 33,
  121465. 14,
  121466. 34,
  121467. 13,
  121468. 35,
  121469. 12,
  121470. 36,
  121471. 11,
  121472. 37,
  121473. 10,
  121474. 38,
  121475. 9,
  121476. 39,
  121477. 8,
  121478. 40,
  121479. 7,
  121480. 41,
  121481. 6,
  121482. 42,
  121483. 5,
  121484. 43,
  121485. 4,
  121486. 44,
  121487. 3,
  121488. 45,
  121489. 2,
  121490. 46,
  121491. 1,
  121492. 47,
  121493. 0,
  121494. 48,
  121495. };
  121496. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121497. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121498. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121499. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121500. 7,
  121501. };
  121502. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121503. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121504. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121505. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121506. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121507. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121508. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121509. };
  121510. static long _vq_quantmap__44c9_s_p9_2[] = {
  121511. 47, 45, 43, 41, 39, 37, 35, 33,
  121512. 31, 29, 27, 25, 23, 21, 19, 17,
  121513. 15, 13, 11, 9, 7, 5, 3, 1,
  121514. 0, 2, 4, 6, 8, 10, 12, 14,
  121515. 16, 18, 20, 22, 24, 26, 28, 30,
  121516. 32, 34, 36, 38, 40, 42, 44, 46,
  121517. 48,
  121518. };
  121519. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121520. _vq_quantthresh__44c9_s_p9_2,
  121521. _vq_quantmap__44c9_s_p9_2,
  121522. 49,
  121523. 49
  121524. };
  121525. static static_codebook _44c9_s_p9_2 = {
  121526. 1, 49,
  121527. _vq_lengthlist__44c9_s_p9_2,
  121528. 1, -526909440, 1611661312, 6, 0,
  121529. _vq_quantlist__44c9_s_p9_2,
  121530. NULL,
  121531. &_vq_auxt__44c9_s_p9_2,
  121532. NULL,
  121533. 0
  121534. };
  121535. static long _huff_lengthlist__44c9_s_short[] = {
  121536. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121537. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121538. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121539. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121540. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121541. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121542. 9, 8,10,13,
  121543. };
  121544. static static_codebook _huff_book__44c9_s_short = {
  121545. 2, 100,
  121546. _huff_lengthlist__44c9_s_short,
  121547. 0, 0, 0, 0, 0,
  121548. NULL,
  121549. NULL,
  121550. NULL,
  121551. NULL,
  121552. 0
  121553. };
  121554. static long _huff_lengthlist__44c0_s_long[] = {
  121555. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121556. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121557. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121558. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121559. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121560. 12,
  121561. };
  121562. static static_codebook _huff_book__44c0_s_long = {
  121563. 2, 81,
  121564. _huff_lengthlist__44c0_s_long,
  121565. 0, 0, 0, 0, 0,
  121566. NULL,
  121567. NULL,
  121568. NULL,
  121569. NULL,
  121570. 0
  121571. };
  121572. static long _vq_quantlist__44c0_s_p1_0[] = {
  121573. 1,
  121574. 0,
  121575. 2,
  121576. };
  121577. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121578. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121579. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121584. 0, 0, 0, 7, 9, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121589. 0, 0, 0, 0, 7, 9, 9, 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, 5, 7, 7, 0, 0, 0, 0,
  121624. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  121629. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  121634. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121670. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121675. 0, 0, 0, 0, 0, 9, 9,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  121680. 0, 0, 0, 0, 0, 0, 9,11,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121988. 0,
  121989. };
  121990. static float _vq_quantthresh__44c0_s_p1_0[] = {
  121991. -0.5, 0.5,
  121992. };
  121993. static long _vq_quantmap__44c0_s_p1_0[] = {
  121994. 1, 0, 2,
  121995. };
  121996. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  121997. _vq_quantthresh__44c0_s_p1_0,
  121998. _vq_quantmap__44c0_s_p1_0,
  121999. 3,
  122000. 3
  122001. };
  122002. static static_codebook _44c0_s_p1_0 = {
  122003. 8, 6561,
  122004. _vq_lengthlist__44c0_s_p1_0,
  122005. 1, -535822336, 1611661312, 2, 0,
  122006. _vq_quantlist__44c0_s_p1_0,
  122007. NULL,
  122008. &_vq_auxt__44c0_s_p1_0,
  122009. NULL,
  122010. 0
  122011. };
  122012. static long _vq_quantlist__44c0_s_p2_0[] = {
  122013. 2,
  122014. 1,
  122015. 3,
  122016. 0,
  122017. 4,
  122018. };
  122019. static long _vq_lengthlist__44c0_s_p2_0[] = {
  122020. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  122022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122023. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122026. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  122027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122059. 0,
  122060. };
  122061. static float _vq_quantthresh__44c0_s_p2_0[] = {
  122062. -1.5, -0.5, 0.5, 1.5,
  122063. };
  122064. static long _vq_quantmap__44c0_s_p2_0[] = {
  122065. 3, 1, 0, 2, 4,
  122066. };
  122067. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  122068. _vq_quantthresh__44c0_s_p2_0,
  122069. _vq_quantmap__44c0_s_p2_0,
  122070. 5,
  122071. 5
  122072. };
  122073. static static_codebook _44c0_s_p2_0 = {
  122074. 4, 625,
  122075. _vq_lengthlist__44c0_s_p2_0,
  122076. 1, -533725184, 1611661312, 3, 0,
  122077. _vq_quantlist__44c0_s_p2_0,
  122078. NULL,
  122079. &_vq_auxt__44c0_s_p2_0,
  122080. NULL,
  122081. 0
  122082. };
  122083. static long _vq_quantlist__44c0_s_p3_0[] = {
  122084. 4,
  122085. 3,
  122086. 5,
  122087. 2,
  122088. 6,
  122089. 1,
  122090. 7,
  122091. 0,
  122092. 8,
  122093. };
  122094. static long _vq_lengthlist__44c0_s_p3_0[] = {
  122095. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  122096. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  122097. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  122098. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  122099. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122100. 0,
  122101. };
  122102. static float _vq_quantthresh__44c0_s_p3_0[] = {
  122103. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122104. };
  122105. static long _vq_quantmap__44c0_s_p3_0[] = {
  122106. 7, 5, 3, 1, 0, 2, 4, 6,
  122107. 8,
  122108. };
  122109. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  122110. _vq_quantthresh__44c0_s_p3_0,
  122111. _vq_quantmap__44c0_s_p3_0,
  122112. 9,
  122113. 9
  122114. };
  122115. static static_codebook _44c0_s_p3_0 = {
  122116. 2, 81,
  122117. _vq_lengthlist__44c0_s_p3_0,
  122118. 1, -531628032, 1611661312, 4, 0,
  122119. _vq_quantlist__44c0_s_p3_0,
  122120. NULL,
  122121. &_vq_auxt__44c0_s_p3_0,
  122122. NULL,
  122123. 0
  122124. };
  122125. static long _vq_quantlist__44c0_s_p4_0[] = {
  122126. 4,
  122127. 3,
  122128. 5,
  122129. 2,
  122130. 6,
  122131. 1,
  122132. 7,
  122133. 0,
  122134. 8,
  122135. };
  122136. static long _vq_lengthlist__44c0_s_p4_0[] = {
  122137. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  122138. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  122139. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  122140. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  122141. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  122142. 10,
  122143. };
  122144. static float _vq_quantthresh__44c0_s_p4_0[] = {
  122145. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122146. };
  122147. static long _vq_quantmap__44c0_s_p4_0[] = {
  122148. 7, 5, 3, 1, 0, 2, 4, 6,
  122149. 8,
  122150. };
  122151. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  122152. _vq_quantthresh__44c0_s_p4_0,
  122153. _vq_quantmap__44c0_s_p4_0,
  122154. 9,
  122155. 9
  122156. };
  122157. static static_codebook _44c0_s_p4_0 = {
  122158. 2, 81,
  122159. _vq_lengthlist__44c0_s_p4_0,
  122160. 1, -531628032, 1611661312, 4, 0,
  122161. _vq_quantlist__44c0_s_p4_0,
  122162. NULL,
  122163. &_vq_auxt__44c0_s_p4_0,
  122164. NULL,
  122165. 0
  122166. };
  122167. static long _vq_quantlist__44c0_s_p5_0[] = {
  122168. 8,
  122169. 7,
  122170. 9,
  122171. 6,
  122172. 10,
  122173. 5,
  122174. 11,
  122175. 4,
  122176. 12,
  122177. 3,
  122178. 13,
  122179. 2,
  122180. 14,
  122181. 1,
  122182. 15,
  122183. 0,
  122184. 16,
  122185. };
  122186. static long _vq_lengthlist__44c0_s_p5_0[] = {
  122187. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  122188. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  122189. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122190. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  122191. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  122192. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  122193. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  122194. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122195. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  122196. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  122197. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122198. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122199. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  122200. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  122201. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  122202. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  122203. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  122204. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122205. 14,
  122206. };
  122207. static float _vq_quantthresh__44c0_s_p5_0[] = {
  122208. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122209. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122210. };
  122211. static long _vq_quantmap__44c0_s_p5_0[] = {
  122212. 15, 13, 11, 9, 7, 5, 3, 1,
  122213. 0, 2, 4, 6, 8, 10, 12, 14,
  122214. 16,
  122215. };
  122216. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  122217. _vq_quantthresh__44c0_s_p5_0,
  122218. _vq_quantmap__44c0_s_p5_0,
  122219. 17,
  122220. 17
  122221. };
  122222. static static_codebook _44c0_s_p5_0 = {
  122223. 2, 289,
  122224. _vq_lengthlist__44c0_s_p5_0,
  122225. 1, -529530880, 1611661312, 5, 0,
  122226. _vq_quantlist__44c0_s_p5_0,
  122227. NULL,
  122228. &_vq_auxt__44c0_s_p5_0,
  122229. NULL,
  122230. 0
  122231. };
  122232. static long _vq_quantlist__44c0_s_p6_0[] = {
  122233. 1,
  122234. 0,
  122235. 2,
  122236. };
  122237. static long _vq_lengthlist__44c0_s_p6_0[] = {
  122238. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  122239. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  122240. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  122241. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  122242. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122243. 10,
  122244. };
  122245. static float _vq_quantthresh__44c0_s_p6_0[] = {
  122246. -5.5, 5.5,
  122247. };
  122248. static long _vq_quantmap__44c0_s_p6_0[] = {
  122249. 1, 0, 2,
  122250. };
  122251. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  122252. _vq_quantthresh__44c0_s_p6_0,
  122253. _vq_quantmap__44c0_s_p6_0,
  122254. 3,
  122255. 3
  122256. };
  122257. static static_codebook _44c0_s_p6_0 = {
  122258. 4, 81,
  122259. _vq_lengthlist__44c0_s_p6_0,
  122260. 1, -529137664, 1618345984, 2, 0,
  122261. _vq_quantlist__44c0_s_p6_0,
  122262. NULL,
  122263. &_vq_auxt__44c0_s_p6_0,
  122264. NULL,
  122265. 0
  122266. };
  122267. static long _vq_quantlist__44c0_s_p6_1[] = {
  122268. 5,
  122269. 4,
  122270. 6,
  122271. 3,
  122272. 7,
  122273. 2,
  122274. 8,
  122275. 1,
  122276. 9,
  122277. 0,
  122278. 10,
  122279. };
  122280. static long _vq_lengthlist__44c0_s_p6_1[] = {
  122281. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  122282. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  122283. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122284. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122285. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122286. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122287. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122288. 10,10,10, 8, 8, 8, 8, 8, 8,
  122289. };
  122290. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122291. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122292. 3.5, 4.5,
  122293. };
  122294. static long _vq_quantmap__44c0_s_p6_1[] = {
  122295. 9, 7, 5, 3, 1, 0, 2, 4,
  122296. 6, 8, 10,
  122297. };
  122298. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122299. _vq_quantthresh__44c0_s_p6_1,
  122300. _vq_quantmap__44c0_s_p6_1,
  122301. 11,
  122302. 11
  122303. };
  122304. static static_codebook _44c0_s_p6_1 = {
  122305. 2, 121,
  122306. _vq_lengthlist__44c0_s_p6_1,
  122307. 1, -531365888, 1611661312, 4, 0,
  122308. _vq_quantlist__44c0_s_p6_1,
  122309. NULL,
  122310. &_vq_auxt__44c0_s_p6_1,
  122311. NULL,
  122312. 0
  122313. };
  122314. static long _vq_quantlist__44c0_s_p7_0[] = {
  122315. 6,
  122316. 5,
  122317. 7,
  122318. 4,
  122319. 8,
  122320. 3,
  122321. 9,
  122322. 2,
  122323. 10,
  122324. 1,
  122325. 11,
  122326. 0,
  122327. 12,
  122328. };
  122329. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122330. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122331. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122332. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122333. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122334. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122335. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122336. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122337. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122338. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122339. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122340. 0,12,12,11,11,12,12,13,13,
  122341. };
  122342. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122343. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122344. 12.5, 17.5, 22.5, 27.5,
  122345. };
  122346. static long _vq_quantmap__44c0_s_p7_0[] = {
  122347. 11, 9, 7, 5, 3, 1, 0, 2,
  122348. 4, 6, 8, 10, 12,
  122349. };
  122350. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122351. _vq_quantthresh__44c0_s_p7_0,
  122352. _vq_quantmap__44c0_s_p7_0,
  122353. 13,
  122354. 13
  122355. };
  122356. static static_codebook _44c0_s_p7_0 = {
  122357. 2, 169,
  122358. _vq_lengthlist__44c0_s_p7_0,
  122359. 1, -526516224, 1616117760, 4, 0,
  122360. _vq_quantlist__44c0_s_p7_0,
  122361. NULL,
  122362. &_vq_auxt__44c0_s_p7_0,
  122363. NULL,
  122364. 0
  122365. };
  122366. static long _vq_quantlist__44c0_s_p7_1[] = {
  122367. 2,
  122368. 1,
  122369. 3,
  122370. 0,
  122371. 4,
  122372. };
  122373. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122374. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122375. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  122376. };
  122377. static float _vq_quantthresh__44c0_s_p7_1[] = {
  122378. -1.5, -0.5, 0.5, 1.5,
  122379. };
  122380. static long _vq_quantmap__44c0_s_p7_1[] = {
  122381. 3, 1, 0, 2, 4,
  122382. };
  122383. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  122384. _vq_quantthresh__44c0_s_p7_1,
  122385. _vq_quantmap__44c0_s_p7_1,
  122386. 5,
  122387. 5
  122388. };
  122389. static static_codebook _44c0_s_p7_1 = {
  122390. 2, 25,
  122391. _vq_lengthlist__44c0_s_p7_1,
  122392. 1, -533725184, 1611661312, 3, 0,
  122393. _vq_quantlist__44c0_s_p7_1,
  122394. NULL,
  122395. &_vq_auxt__44c0_s_p7_1,
  122396. NULL,
  122397. 0
  122398. };
  122399. static long _vq_quantlist__44c0_s_p8_0[] = {
  122400. 2,
  122401. 1,
  122402. 3,
  122403. 0,
  122404. 4,
  122405. };
  122406. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122407. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122408. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122409. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122410. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122411. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122412. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122413. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122414. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122415. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122416. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122417. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122418. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122419. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  122420. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122421. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122422. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122423. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122424. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122425. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122426. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122427. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122428. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122429. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122430. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122431. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122432. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122433. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122434. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122435. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122436. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122437. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122438. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122439. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122440. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122441. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122442. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122443. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122444. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122445. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122446. 11,
  122447. };
  122448. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122449. -331.5, -110.5, 110.5, 331.5,
  122450. };
  122451. static long _vq_quantmap__44c0_s_p8_0[] = {
  122452. 3, 1, 0, 2, 4,
  122453. };
  122454. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122455. _vq_quantthresh__44c0_s_p8_0,
  122456. _vq_quantmap__44c0_s_p8_0,
  122457. 5,
  122458. 5
  122459. };
  122460. static static_codebook _44c0_s_p8_0 = {
  122461. 4, 625,
  122462. _vq_lengthlist__44c0_s_p8_0,
  122463. 1, -518283264, 1627103232, 3, 0,
  122464. _vq_quantlist__44c0_s_p8_0,
  122465. NULL,
  122466. &_vq_auxt__44c0_s_p8_0,
  122467. NULL,
  122468. 0
  122469. };
  122470. static long _vq_quantlist__44c0_s_p8_1[] = {
  122471. 6,
  122472. 5,
  122473. 7,
  122474. 4,
  122475. 8,
  122476. 3,
  122477. 9,
  122478. 2,
  122479. 10,
  122480. 1,
  122481. 11,
  122482. 0,
  122483. 12,
  122484. };
  122485. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122486. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122487. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122488. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122489. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122490. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122491. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122492. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122493. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122494. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122495. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122496. 16,13,13,12,12,14,14,15,13,
  122497. };
  122498. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122499. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122500. 42.5, 59.5, 76.5, 93.5,
  122501. };
  122502. static long _vq_quantmap__44c0_s_p8_1[] = {
  122503. 11, 9, 7, 5, 3, 1, 0, 2,
  122504. 4, 6, 8, 10, 12,
  122505. };
  122506. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122507. _vq_quantthresh__44c0_s_p8_1,
  122508. _vq_quantmap__44c0_s_p8_1,
  122509. 13,
  122510. 13
  122511. };
  122512. static static_codebook _44c0_s_p8_1 = {
  122513. 2, 169,
  122514. _vq_lengthlist__44c0_s_p8_1,
  122515. 1, -522616832, 1620115456, 4, 0,
  122516. _vq_quantlist__44c0_s_p8_1,
  122517. NULL,
  122518. &_vq_auxt__44c0_s_p8_1,
  122519. NULL,
  122520. 0
  122521. };
  122522. static long _vq_quantlist__44c0_s_p8_2[] = {
  122523. 8,
  122524. 7,
  122525. 9,
  122526. 6,
  122527. 10,
  122528. 5,
  122529. 11,
  122530. 4,
  122531. 12,
  122532. 3,
  122533. 13,
  122534. 2,
  122535. 14,
  122536. 1,
  122537. 15,
  122538. 0,
  122539. 16,
  122540. };
  122541. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122542. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122543. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122544. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122545. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122546. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122547. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122548. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122549. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122550. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122551. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122552. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122553. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122554. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122555. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122556. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122557. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122558. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122559. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122560. 10,
  122561. };
  122562. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122563. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122564. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122565. };
  122566. static long _vq_quantmap__44c0_s_p8_2[] = {
  122567. 15, 13, 11, 9, 7, 5, 3, 1,
  122568. 0, 2, 4, 6, 8, 10, 12, 14,
  122569. 16,
  122570. };
  122571. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122572. _vq_quantthresh__44c0_s_p8_2,
  122573. _vq_quantmap__44c0_s_p8_2,
  122574. 17,
  122575. 17
  122576. };
  122577. static static_codebook _44c0_s_p8_2 = {
  122578. 2, 289,
  122579. _vq_lengthlist__44c0_s_p8_2,
  122580. 1, -529530880, 1611661312, 5, 0,
  122581. _vq_quantlist__44c0_s_p8_2,
  122582. NULL,
  122583. &_vq_auxt__44c0_s_p8_2,
  122584. NULL,
  122585. 0
  122586. };
  122587. static long _huff_lengthlist__44c0_s_short[] = {
  122588. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122589. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122590. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122591. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122592. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122593. 12,
  122594. };
  122595. static static_codebook _huff_book__44c0_s_short = {
  122596. 2, 81,
  122597. _huff_lengthlist__44c0_s_short,
  122598. 0, 0, 0, 0, 0,
  122599. NULL,
  122600. NULL,
  122601. NULL,
  122602. NULL,
  122603. 0
  122604. };
  122605. static long _huff_lengthlist__44c0_sm_long[] = {
  122606. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122607. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122608. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122609. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122610. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122611. 13,
  122612. };
  122613. static static_codebook _huff_book__44c0_sm_long = {
  122614. 2, 81,
  122615. _huff_lengthlist__44c0_sm_long,
  122616. 0, 0, 0, 0, 0,
  122617. NULL,
  122618. NULL,
  122619. NULL,
  122620. NULL,
  122621. 0
  122622. };
  122623. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122624. 1,
  122625. 0,
  122626. 2,
  122627. };
  122628. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122629. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122630. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122635. 0, 0, 0, 7, 8, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122640. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 7, 0, 0, 0, 0,
  122675. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  122680. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  122685. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122721. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122726. 0, 0, 0, 0, 0, 9, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122731. 0, 0, 0, 0, 0, 0, 9,10,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123039. 0,
  123040. };
  123041. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  123042. -0.5, 0.5,
  123043. };
  123044. static long _vq_quantmap__44c0_sm_p1_0[] = {
  123045. 1, 0, 2,
  123046. };
  123047. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  123048. _vq_quantthresh__44c0_sm_p1_0,
  123049. _vq_quantmap__44c0_sm_p1_0,
  123050. 3,
  123051. 3
  123052. };
  123053. static static_codebook _44c0_sm_p1_0 = {
  123054. 8, 6561,
  123055. _vq_lengthlist__44c0_sm_p1_0,
  123056. 1, -535822336, 1611661312, 2, 0,
  123057. _vq_quantlist__44c0_sm_p1_0,
  123058. NULL,
  123059. &_vq_auxt__44c0_sm_p1_0,
  123060. NULL,
  123061. 0
  123062. };
  123063. static long _vq_quantlist__44c0_sm_p2_0[] = {
  123064. 2,
  123065. 1,
  123066. 3,
  123067. 0,
  123068. 4,
  123069. };
  123070. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  123071. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  123073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123074. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  123076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123077. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  123078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123110. 0,
  123111. };
  123112. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  123113. -1.5, -0.5, 0.5, 1.5,
  123114. };
  123115. static long _vq_quantmap__44c0_sm_p2_0[] = {
  123116. 3, 1, 0, 2, 4,
  123117. };
  123118. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  123119. _vq_quantthresh__44c0_sm_p2_0,
  123120. _vq_quantmap__44c0_sm_p2_0,
  123121. 5,
  123122. 5
  123123. };
  123124. static static_codebook _44c0_sm_p2_0 = {
  123125. 4, 625,
  123126. _vq_lengthlist__44c0_sm_p2_0,
  123127. 1, -533725184, 1611661312, 3, 0,
  123128. _vq_quantlist__44c0_sm_p2_0,
  123129. NULL,
  123130. &_vq_auxt__44c0_sm_p2_0,
  123131. NULL,
  123132. 0
  123133. };
  123134. static long _vq_quantlist__44c0_sm_p3_0[] = {
  123135. 4,
  123136. 3,
  123137. 5,
  123138. 2,
  123139. 6,
  123140. 1,
  123141. 7,
  123142. 0,
  123143. 8,
  123144. };
  123145. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  123146. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  123147. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  123148. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123149. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  123150. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123151. 0,
  123152. };
  123153. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  123154. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123155. };
  123156. static long _vq_quantmap__44c0_sm_p3_0[] = {
  123157. 7, 5, 3, 1, 0, 2, 4, 6,
  123158. 8,
  123159. };
  123160. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  123161. _vq_quantthresh__44c0_sm_p3_0,
  123162. _vq_quantmap__44c0_sm_p3_0,
  123163. 9,
  123164. 9
  123165. };
  123166. static static_codebook _44c0_sm_p3_0 = {
  123167. 2, 81,
  123168. _vq_lengthlist__44c0_sm_p3_0,
  123169. 1, -531628032, 1611661312, 4, 0,
  123170. _vq_quantlist__44c0_sm_p3_0,
  123171. NULL,
  123172. &_vq_auxt__44c0_sm_p3_0,
  123173. NULL,
  123174. 0
  123175. };
  123176. static long _vq_quantlist__44c0_sm_p4_0[] = {
  123177. 4,
  123178. 3,
  123179. 5,
  123180. 2,
  123181. 6,
  123182. 1,
  123183. 7,
  123184. 0,
  123185. 8,
  123186. };
  123187. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  123188. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  123189. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  123190. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  123191. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  123192. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123193. 11,
  123194. };
  123195. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  123196. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123197. };
  123198. static long _vq_quantmap__44c0_sm_p4_0[] = {
  123199. 7, 5, 3, 1, 0, 2, 4, 6,
  123200. 8,
  123201. };
  123202. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  123203. _vq_quantthresh__44c0_sm_p4_0,
  123204. _vq_quantmap__44c0_sm_p4_0,
  123205. 9,
  123206. 9
  123207. };
  123208. static static_codebook _44c0_sm_p4_0 = {
  123209. 2, 81,
  123210. _vq_lengthlist__44c0_sm_p4_0,
  123211. 1, -531628032, 1611661312, 4, 0,
  123212. _vq_quantlist__44c0_sm_p4_0,
  123213. NULL,
  123214. &_vq_auxt__44c0_sm_p4_0,
  123215. NULL,
  123216. 0
  123217. };
  123218. static long _vq_quantlist__44c0_sm_p5_0[] = {
  123219. 8,
  123220. 7,
  123221. 9,
  123222. 6,
  123223. 10,
  123224. 5,
  123225. 11,
  123226. 4,
  123227. 12,
  123228. 3,
  123229. 13,
  123230. 2,
  123231. 14,
  123232. 1,
  123233. 15,
  123234. 0,
  123235. 16,
  123236. };
  123237. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  123238. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  123239. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  123240. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123241. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  123242. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  123243. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  123244. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  123245. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123246. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  123247. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  123248. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123249. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123250. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  123251. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  123252. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  123253. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  123254. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  123255. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123256. 14,
  123257. };
  123258. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  123259. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123260. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123261. };
  123262. static long _vq_quantmap__44c0_sm_p5_0[] = {
  123263. 15, 13, 11, 9, 7, 5, 3, 1,
  123264. 0, 2, 4, 6, 8, 10, 12, 14,
  123265. 16,
  123266. };
  123267. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  123268. _vq_quantthresh__44c0_sm_p5_0,
  123269. _vq_quantmap__44c0_sm_p5_0,
  123270. 17,
  123271. 17
  123272. };
  123273. static static_codebook _44c0_sm_p5_0 = {
  123274. 2, 289,
  123275. _vq_lengthlist__44c0_sm_p5_0,
  123276. 1, -529530880, 1611661312, 5, 0,
  123277. _vq_quantlist__44c0_sm_p5_0,
  123278. NULL,
  123279. &_vq_auxt__44c0_sm_p5_0,
  123280. NULL,
  123281. 0
  123282. };
  123283. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123284. 1,
  123285. 0,
  123286. 2,
  123287. };
  123288. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123289. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123290. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123291. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123292. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123293. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123294. 11,
  123295. };
  123296. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123297. -5.5, 5.5,
  123298. };
  123299. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123300. 1, 0, 2,
  123301. };
  123302. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123303. _vq_quantthresh__44c0_sm_p6_0,
  123304. _vq_quantmap__44c0_sm_p6_0,
  123305. 3,
  123306. 3
  123307. };
  123308. static static_codebook _44c0_sm_p6_0 = {
  123309. 4, 81,
  123310. _vq_lengthlist__44c0_sm_p6_0,
  123311. 1, -529137664, 1618345984, 2, 0,
  123312. _vq_quantlist__44c0_sm_p6_0,
  123313. NULL,
  123314. &_vq_auxt__44c0_sm_p6_0,
  123315. NULL,
  123316. 0
  123317. };
  123318. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123319. 5,
  123320. 4,
  123321. 6,
  123322. 3,
  123323. 7,
  123324. 2,
  123325. 8,
  123326. 1,
  123327. 9,
  123328. 0,
  123329. 10,
  123330. };
  123331. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123332. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123333. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123334. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123335. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123336. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123337. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123338. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123339. 10,10,10, 8, 8, 8, 8, 8, 8,
  123340. };
  123341. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123342. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123343. 3.5, 4.5,
  123344. };
  123345. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123346. 9, 7, 5, 3, 1, 0, 2, 4,
  123347. 6, 8, 10,
  123348. };
  123349. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123350. _vq_quantthresh__44c0_sm_p6_1,
  123351. _vq_quantmap__44c0_sm_p6_1,
  123352. 11,
  123353. 11
  123354. };
  123355. static static_codebook _44c0_sm_p6_1 = {
  123356. 2, 121,
  123357. _vq_lengthlist__44c0_sm_p6_1,
  123358. 1, -531365888, 1611661312, 4, 0,
  123359. _vq_quantlist__44c0_sm_p6_1,
  123360. NULL,
  123361. &_vq_auxt__44c0_sm_p6_1,
  123362. NULL,
  123363. 0
  123364. };
  123365. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123366. 6,
  123367. 5,
  123368. 7,
  123369. 4,
  123370. 8,
  123371. 3,
  123372. 9,
  123373. 2,
  123374. 10,
  123375. 1,
  123376. 11,
  123377. 0,
  123378. 12,
  123379. };
  123380. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  123381. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123382. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  123383. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123384. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123385. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123386. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  123387. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123388. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123389. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123390. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  123391. 0,12,12,11,11,13,12,14,14,
  123392. };
  123393. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  123394. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123395. 12.5, 17.5, 22.5, 27.5,
  123396. };
  123397. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123398. 11, 9, 7, 5, 3, 1, 0, 2,
  123399. 4, 6, 8, 10, 12,
  123400. };
  123401. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123402. _vq_quantthresh__44c0_sm_p7_0,
  123403. _vq_quantmap__44c0_sm_p7_0,
  123404. 13,
  123405. 13
  123406. };
  123407. static static_codebook _44c0_sm_p7_0 = {
  123408. 2, 169,
  123409. _vq_lengthlist__44c0_sm_p7_0,
  123410. 1, -526516224, 1616117760, 4, 0,
  123411. _vq_quantlist__44c0_sm_p7_0,
  123412. NULL,
  123413. &_vq_auxt__44c0_sm_p7_0,
  123414. NULL,
  123415. 0
  123416. };
  123417. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123418. 2,
  123419. 1,
  123420. 3,
  123421. 0,
  123422. 4,
  123423. };
  123424. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123425. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123426. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123427. };
  123428. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123429. -1.5, -0.5, 0.5, 1.5,
  123430. };
  123431. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123432. 3, 1, 0, 2, 4,
  123433. };
  123434. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123435. _vq_quantthresh__44c0_sm_p7_1,
  123436. _vq_quantmap__44c0_sm_p7_1,
  123437. 5,
  123438. 5
  123439. };
  123440. static static_codebook _44c0_sm_p7_1 = {
  123441. 2, 25,
  123442. _vq_lengthlist__44c0_sm_p7_1,
  123443. 1, -533725184, 1611661312, 3, 0,
  123444. _vq_quantlist__44c0_sm_p7_1,
  123445. NULL,
  123446. &_vq_auxt__44c0_sm_p7_1,
  123447. NULL,
  123448. 0
  123449. };
  123450. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123451. 4,
  123452. 3,
  123453. 5,
  123454. 2,
  123455. 6,
  123456. 1,
  123457. 7,
  123458. 0,
  123459. 8,
  123460. };
  123461. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123462. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123463. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123464. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123465. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123466. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123467. 12,
  123468. };
  123469. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123470. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123471. };
  123472. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123473. 7, 5, 3, 1, 0, 2, 4, 6,
  123474. 8,
  123475. };
  123476. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123477. _vq_quantthresh__44c0_sm_p8_0,
  123478. _vq_quantmap__44c0_sm_p8_0,
  123479. 9,
  123480. 9
  123481. };
  123482. static static_codebook _44c0_sm_p8_0 = {
  123483. 2, 81,
  123484. _vq_lengthlist__44c0_sm_p8_0,
  123485. 1, -516186112, 1627103232, 4, 0,
  123486. _vq_quantlist__44c0_sm_p8_0,
  123487. NULL,
  123488. &_vq_auxt__44c0_sm_p8_0,
  123489. NULL,
  123490. 0
  123491. };
  123492. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123493. 6,
  123494. 5,
  123495. 7,
  123496. 4,
  123497. 8,
  123498. 3,
  123499. 9,
  123500. 2,
  123501. 10,
  123502. 1,
  123503. 11,
  123504. 0,
  123505. 12,
  123506. };
  123507. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123508. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123509. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123510. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123511. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123512. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123513. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123514. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123515. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123516. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123517. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123518. 20,13,13,12,12,16,13,15,13,
  123519. };
  123520. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123521. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123522. 42.5, 59.5, 76.5, 93.5,
  123523. };
  123524. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123525. 11, 9, 7, 5, 3, 1, 0, 2,
  123526. 4, 6, 8, 10, 12,
  123527. };
  123528. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123529. _vq_quantthresh__44c0_sm_p8_1,
  123530. _vq_quantmap__44c0_sm_p8_1,
  123531. 13,
  123532. 13
  123533. };
  123534. static static_codebook _44c0_sm_p8_1 = {
  123535. 2, 169,
  123536. _vq_lengthlist__44c0_sm_p8_1,
  123537. 1, -522616832, 1620115456, 4, 0,
  123538. _vq_quantlist__44c0_sm_p8_1,
  123539. NULL,
  123540. &_vq_auxt__44c0_sm_p8_1,
  123541. NULL,
  123542. 0
  123543. };
  123544. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123545. 8,
  123546. 7,
  123547. 9,
  123548. 6,
  123549. 10,
  123550. 5,
  123551. 11,
  123552. 4,
  123553. 12,
  123554. 3,
  123555. 13,
  123556. 2,
  123557. 14,
  123558. 1,
  123559. 15,
  123560. 0,
  123561. 16,
  123562. };
  123563. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123564. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123565. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123566. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123567. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123568. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123569. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123570. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123571. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123572. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123573. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123574. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123575. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123576. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123577. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123578. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123579. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123580. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123581. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123582. 9,
  123583. };
  123584. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123585. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123586. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123587. };
  123588. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123589. 15, 13, 11, 9, 7, 5, 3, 1,
  123590. 0, 2, 4, 6, 8, 10, 12, 14,
  123591. 16,
  123592. };
  123593. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123594. _vq_quantthresh__44c0_sm_p8_2,
  123595. _vq_quantmap__44c0_sm_p8_2,
  123596. 17,
  123597. 17
  123598. };
  123599. static static_codebook _44c0_sm_p8_2 = {
  123600. 2, 289,
  123601. _vq_lengthlist__44c0_sm_p8_2,
  123602. 1, -529530880, 1611661312, 5, 0,
  123603. _vq_quantlist__44c0_sm_p8_2,
  123604. NULL,
  123605. &_vq_auxt__44c0_sm_p8_2,
  123606. NULL,
  123607. 0
  123608. };
  123609. static long _huff_lengthlist__44c0_sm_short[] = {
  123610. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123611. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123612. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123613. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123614. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123615. 12,
  123616. };
  123617. static static_codebook _huff_book__44c0_sm_short = {
  123618. 2, 81,
  123619. _huff_lengthlist__44c0_sm_short,
  123620. 0, 0, 0, 0, 0,
  123621. NULL,
  123622. NULL,
  123623. NULL,
  123624. NULL,
  123625. 0
  123626. };
  123627. static long _huff_lengthlist__44c1_s_long[] = {
  123628. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123629. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123630. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123631. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123632. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123633. 11,
  123634. };
  123635. static static_codebook _huff_book__44c1_s_long = {
  123636. 2, 81,
  123637. _huff_lengthlist__44c1_s_long,
  123638. 0, 0, 0, 0, 0,
  123639. NULL,
  123640. NULL,
  123641. NULL,
  123642. NULL,
  123643. 0
  123644. };
  123645. static long _vq_quantlist__44c1_s_p1_0[] = {
  123646. 1,
  123647. 0,
  123648. 2,
  123649. };
  123650. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123651. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123652. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123657. 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123662. 0, 0, 0, 0, 7, 8, 8, 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, 4, 7, 7, 0, 0, 0, 0,
  123697. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  123702. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  123707. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123743. 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  123748. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123753. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124061. 0,
  124062. };
  124063. static float _vq_quantthresh__44c1_s_p1_0[] = {
  124064. -0.5, 0.5,
  124065. };
  124066. static long _vq_quantmap__44c1_s_p1_0[] = {
  124067. 1, 0, 2,
  124068. };
  124069. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  124070. _vq_quantthresh__44c1_s_p1_0,
  124071. _vq_quantmap__44c1_s_p1_0,
  124072. 3,
  124073. 3
  124074. };
  124075. static static_codebook _44c1_s_p1_0 = {
  124076. 8, 6561,
  124077. _vq_lengthlist__44c1_s_p1_0,
  124078. 1, -535822336, 1611661312, 2, 0,
  124079. _vq_quantlist__44c1_s_p1_0,
  124080. NULL,
  124081. &_vq_auxt__44c1_s_p1_0,
  124082. NULL,
  124083. 0
  124084. };
  124085. static long _vq_quantlist__44c1_s_p2_0[] = {
  124086. 2,
  124087. 1,
  124088. 3,
  124089. 0,
  124090. 4,
  124091. };
  124092. static long _vq_lengthlist__44c1_s_p2_0[] = {
  124093. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124096. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  124098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124099. 0, 0, 0, 0, 6, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  124100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124132. 0,
  124133. };
  124134. static float _vq_quantthresh__44c1_s_p2_0[] = {
  124135. -1.5, -0.5, 0.5, 1.5,
  124136. };
  124137. static long _vq_quantmap__44c1_s_p2_0[] = {
  124138. 3, 1, 0, 2, 4,
  124139. };
  124140. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  124141. _vq_quantthresh__44c1_s_p2_0,
  124142. _vq_quantmap__44c1_s_p2_0,
  124143. 5,
  124144. 5
  124145. };
  124146. static static_codebook _44c1_s_p2_0 = {
  124147. 4, 625,
  124148. _vq_lengthlist__44c1_s_p2_0,
  124149. 1, -533725184, 1611661312, 3, 0,
  124150. _vq_quantlist__44c1_s_p2_0,
  124151. NULL,
  124152. &_vq_auxt__44c1_s_p2_0,
  124153. NULL,
  124154. 0
  124155. };
  124156. static long _vq_quantlist__44c1_s_p3_0[] = {
  124157. 4,
  124158. 3,
  124159. 5,
  124160. 2,
  124161. 6,
  124162. 1,
  124163. 7,
  124164. 0,
  124165. 8,
  124166. };
  124167. static long _vq_lengthlist__44c1_s_p3_0[] = {
  124168. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  124169. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  124170. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124171. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124172. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124173. 0,
  124174. };
  124175. static float _vq_quantthresh__44c1_s_p3_0[] = {
  124176. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124177. };
  124178. static long _vq_quantmap__44c1_s_p3_0[] = {
  124179. 7, 5, 3, 1, 0, 2, 4, 6,
  124180. 8,
  124181. };
  124182. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  124183. _vq_quantthresh__44c1_s_p3_0,
  124184. _vq_quantmap__44c1_s_p3_0,
  124185. 9,
  124186. 9
  124187. };
  124188. static static_codebook _44c1_s_p3_0 = {
  124189. 2, 81,
  124190. _vq_lengthlist__44c1_s_p3_0,
  124191. 1, -531628032, 1611661312, 4, 0,
  124192. _vq_quantlist__44c1_s_p3_0,
  124193. NULL,
  124194. &_vq_auxt__44c1_s_p3_0,
  124195. NULL,
  124196. 0
  124197. };
  124198. static long _vq_quantlist__44c1_s_p4_0[] = {
  124199. 4,
  124200. 3,
  124201. 5,
  124202. 2,
  124203. 6,
  124204. 1,
  124205. 7,
  124206. 0,
  124207. 8,
  124208. };
  124209. static long _vq_lengthlist__44c1_s_p4_0[] = {
  124210. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  124211. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  124212. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  124213. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  124214. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124215. 11,
  124216. };
  124217. static float _vq_quantthresh__44c1_s_p4_0[] = {
  124218. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124219. };
  124220. static long _vq_quantmap__44c1_s_p4_0[] = {
  124221. 7, 5, 3, 1, 0, 2, 4, 6,
  124222. 8,
  124223. };
  124224. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  124225. _vq_quantthresh__44c1_s_p4_0,
  124226. _vq_quantmap__44c1_s_p4_0,
  124227. 9,
  124228. 9
  124229. };
  124230. static static_codebook _44c1_s_p4_0 = {
  124231. 2, 81,
  124232. _vq_lengthlist__44c1_s_p4_0,
  124233. 1, -531628032, 1611661312, 4, 0,
  124234. _vq_quantlist__44c1_s_p4_0,
  124235. NULL,
  124236. &_vq_auxt__44c1_s_p4_0,
  124237. NULL,
  124238. 0
  124239. };
  124240. static long _vq_quantlist__44c1_s_p5_0[] = {
  124241. 8,
  124242. 7,
  124243. 9,
  124244. 6,
  124245. 10,
  124246. 5,
  124247. 11,
  124248. 4,
  124249. 12,
  124250. 3,
  124251. 13,
  124252. 2,
  124253. 14,
  124254. 1,
  124255. 15,
  124256. 0,
  124257. 16,
  124258. };
  124259. static long _vq_lengthlist__44c1_s_p5_0[] = {
  124260. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124261. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124262. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  124263. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124264. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124265. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  124266. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  124267. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124268. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124269. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  124270. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124271. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124272. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124273. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124274. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  124275. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124276. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  124277. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124278. 14,
  124279. };
  124280. static float _vq_quantthresh__44c1_s_p5_0[] = {
  124281. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124282. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124283. };
  124284. static long _vq_quantmap__44c1_s_p5_0[] = {
  124285. 15, 13, 11, 9, 7, 5, 3, 1,
  124286. 0, 2, 4, 6, 8, 10, 12, 14,
  124287. 16,
  124288. };
  124289. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124290. _vq_quantthresh__44c1_s_p5_0,
  124291. _vq_quantmap__44c1_s_p5_0,
  124292. 17,
  124293. 17
  124294. };
  124295. static static_codebook _44c1_s_p5_0 = {
  124296. 2, 289,
  124297. _vq_lengthlist__44c1_s_p5_0,
  124298. 1, -529530880, 1611661312, 5, 0,
  124299. _vq_quantlist__44c1_s_p5_0,
  124300. NULL,
  124301. &_vq_auxt__44c1_s_p5_0,
  124302. NULL,
  124303. 0
  124304. };
  124305. static long _vq_quantlist__44c1_s_p6_0[] = {
  124306. 1,
  124307. 0,
  124308. 2,
  124309. };
  124310. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124311. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124312. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124313. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124314. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124315. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124316. 11,
  124317. };
  124318. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124319. -5.5, 5.5,
  124320. };
  124321. static long _vq_quantmap__44c1_s_p6_0[] = {
  124322. 1, 0, 2,
  124323. };
  124324. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124325. _vq_quantthresh__44c1_s_p6_0,
  124326. _vq_quantmap__44c1_s_p6_0,
  124327. 3,
  124328. 3
  124329. };
  124330. static static_codebook _44c1_s_p6_0 = {
  124331. 4, 81,
  124332. _vq_lengthlist__44c1_s_p6_0,
  124333. 1, -529137664, 1618345984, 2, 0,
  124334. _vq_quantlist__44c1_s_p6_0,
  124335. NULL,
  124336. &_vq_auxt__44c1_s_p6_0,
  124337. NULL,
  124338. 0
  124339. };
  124340. static long _vq_quantlist__44c1_s_p6_1[] = {
  124341. 5,
  124342. 4,
  124343. 6,
  124344. 3,
  124345. 7,
  124346. 2,
  124347. 8,
  124348. 1,
  124349. 9,
  124350. 0,
  124351. 10,
  124352. };
  124353. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124354. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124355. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124356. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124357. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124358. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124359. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124360. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124361. 10,10,10, 8, 8, 8, 8, 8, 8,
  124362. };
  124363. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124364. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124365. 3.5, 4.5,
  124366. };
  124367. static long _vq_quantmap__44c1_s_p6_1[] = {
  124368. 9, 7, 5, 3, 1, 0, 2, 4,
  124369. 6, 8, 10,
  124370. };
  124371. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124372. _vq_quantthresh__44c1_s_p6_1,
  124373. _vq_quantmap__44c1_s_p6_1,
  124374. 11,
  124375. 11
  124376. };
  124377. static static_codebook _44c1_s_p6_1 = {
  124378. 2, 121,
  124379. _vq_lengthlist__44c1_s_p6_1,
  124380. 1, -531365888, 1611661312, 4, 0,
  124381. _vq_quantlist__44c1_s_p6_1,
  124382. NULL,
  124383. &_vq_auxt__44c1_s_p6_1,
  124384. NULL,
  124385. 0
  124386. };
  124387. static long _vq_quantlist__44c1_s_p7_0[] = {
  124388. 6,
  124389. 5,
  124390. 7,
  124391. 4,
  124392. 8,
  124393. 3,
  124394. 9,
  124395. 2,
  124396. 10,
  124397. 1,
  124398. 11,
  124399. 0,
  124400. 12,
  124401. };
  124402. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124403. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124404. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124405. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124406. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124407. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124408. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124409. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124410. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124411. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124412. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124413. 0,12,11,11,11,13,10,14,13,
  124414. };
  124415. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124416. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124417. 12.5, 17.5, 22.5, 27.5,
  124418. };
  124419. static long _vq_quantmap__44c1_s_p7_0[] = {
  124420. 11, 9, 7, 5, 3, 1, 0, 2,
  124421. 4, 6, 8, 10, 12,
  124422. };
  124423. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124424. _vq_quantthresh__44c1_s_p7_0,
  124425. _vq_quantmap__44c1_s_p7_0,
  124426. 13,
  124427. 13
  124428. };
  124429. static static_codebook _44c1_s_p7_0 = {
  124430. 2, 169,
  124431. _vq_lengthlist__44c1_s_p7_0,
  124432. 1, -526516224, 1616117760, 4, 0,
  124433. _vq_quantlist__44c1_s_p7_0,
  124434. NULL,
  124435. &_vq_auxt__44c1_s_p7_0,
  124436. NULL,
  124437. 0
  124438. };
  124439. static long _vq_quantlist__44c1_s_p7_1[] = {
  124440. 2,
  124441. 1,
  124442. 3,
  124443. 0,
  124444. 4,
  124445. };
  124446. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124447. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124448. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124449. };
  124450. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124451. -1.5, -0.5, 0.5, 1.5,
  124452. };
  124453. static long _vq_quantmap__44c1_s_p7_1[] = {
  124454. 3, 1, 0, 2, 4,
  124455. };
  124456. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124457. _vq_quantthresh__44c1_s_p7_1,
  124458. _vq_quantmap__44c1_s_p7_1,
  124459. 5,
  124460. 5
  124461. };
  124462. static static_codebook _44c1_s_p7_1 = {
  124463. 2, 25,
  124464. _vq_lengthlist__44c1_s_p7_1,
  124465. 1, -533725184, 1611661312, 3, 0,
  124466. _vq_quantlist__44c1_s_p7_1,
  124467. NULL,
  124468. &_vq_auxt__44c1_s_p7_1,
  124469. NULL,
  124470. 0
  124471. };
  124472. static long _vq_quantlist__44c1_s_p8_0[] = {
  124473. 6,
  124474. 5,
  124475. 7,
  124476. 4,
  124477. 8,
  124478. 3,
  124479. 9,
  124480. 2,
  124481. 10,
  124482. 1,
  124483. 11,
  124484. 0,
  124485. 12,
  124486. };
  124487. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124488. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124489. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124490. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124491. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124492. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124493. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124494. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124495. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124496. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124497. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124498. 10,10,10,10,10,10,10,10,10,
  124499. };
  124500. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124501. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124502. 552.5, 773.5, 994.5, 1215.5,
  124503. };
  124504. static long _vq_quantmap__44c1_s_p8_0[] = {
  124505. 11, 9, 7, 5, 3, 1, 0, 2,
  124506. 4, 6, 8, 10, 12,
  124507. };
  124508. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124509. _vq_quantthresh__44c1_s_p8_0,
  124510. _vq_quantmap__44c1_s_p8_0,
  124511. 13,
  124512. 13
  124513. };
  124514. static static_codebook _44c1_s_p8_0 = {
  124515. 2, 169,
  124516. _vq_lengthlist__44c1_s_p8_0,
  124517. 1, -514541568, 1627103232, 4, 0,
  124518. _vq_quantlist__44c1_s_p8_0,
  124519. NULL,
  124520. &_vq_auxt__44c1_s_p8_0,
  124521. NULL,
  124522. 0
  124523. };
  124524. static long _vq_quantlist__44c1_s_p8_1[] = {
  124525. 6,
  124526. 5,
  124527. 7,
  124528. 4,
  124529. 8,
  124530. 3,
  124531. 9,
  124532. 2,
  124533. 10,
  124534. 1,
  124535. 11,
  124536. 0,
  124537. 12,
  124538. };
  124539. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124540. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124541. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124542. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124543. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124544. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124545. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124546. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124547. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124548. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124549. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124550. 16,13,12,12,11,14,12,15,13,
  124551. };
  124552. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124553. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124554. 42.5, 59.5, 76.5, 93.5,
  124555. };
  124556. static long _vq_quantmap__44c1_s_p8_1[] = {
  124557. 11, 9, 7, 5, 3, 1, 0, 2,
  124558. 4, 6, 8, 10, 12,
  124559. };
  124560. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124561. _vq_quantthresh__44c1_s_p8_1,
  124562. _vq_quantmap__44c1_s_p8_1,
  124563. 13,
  124564. 13
  124565. };
  124566. static static_codebook _44c1_s_p8_1 = {
  124567. 2, 169,
  124568. _vq_lengthlist__44c1_s_p8_1,
  124569. 1, -522616832, 1620115456, 4, 0,
  124570. _vq_quantlist__44c1_s_p8_1,
  124571. NULL,
  124572. &_vq_auxt__44c1_s_p8_1,
  124573. NULL,
  124574. 0
  124575. };
  124576. static long _vq_quantlist__44c1_s_p8_2[] = {
  124577. 8,
  124578. 7,
  124579. 9,
  124580. 6,
  124581. 10,
  124582. 5,
  124583. 11,
  124584. 4,
  124585. 12,
  124586. 3,
  124587. 13,
  124588. 2,
  124589. 14,
  124590. 1,
  124591. 15,
  124592. 0,
  124593. 16,
  124594. };
  124595. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124596. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124597. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124598. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124599. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124600. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124601. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124602. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124603. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124604. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124605. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124606. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124607. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124608. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124609. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124610. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124611. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124612. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124613. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124614. 9,
  124615. };
  124616. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124617. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124618. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124619. };
  124620. static long _vq_quantmap__44c1_s_p8_2[] = {
  124621. 15, 13, 11, 9, 7, 5, 3, 1,
  124622. 0, 2, 4, 6, 8, 10, 12, 14,
  124623. 16,
  124624. };
  124625. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124626. _vq_quantthresh__44c1_s_p8_2,
  124627. _vq_quantmap__44c1_s_p8_2,
  124628. 17,
  124629. 17
  124630. };
  124631. static static_codebook _44c1_s_p8_2 = {
  124632. 2, 289,
  124633. _vq_lengthlist__44c1_s_p8_2,
  124634. 1, -529530880, 1611661312, 5, 0,
  124635. _vq_quantlist__44c1_s_p8_2,
  124636. NULL,
  124637. &_vq_auxt__44c1_s_p8_2,
  124638. NULL,
  124639. 0
  124640. };
  124641. static long _huff_lengthlist__44c1_s_short[] = {
  124642. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124643. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124644. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124645. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124646. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124647. 11,
  124648. };
  124649. static static_codebook _huff_book__44c1_s_short = {
  124650. 2, 81,
  124651. _huff_lengthlist__44c1_s_short,
  124652. 0, 0, 0, 0, 0,
  124653. NULL,
  124654. NULL,
  124655. NULL,
  124656. NULL,
  124657. 0
  124658. };
  124659. static long _huff_lengthlist__44c1_sm_long[] = {
  124660. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124661. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124662. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124663. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124664. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124665. 11,
  124666. };
  124667. static static_codebook _huff_book__44c1_sm_long = {
  124668. 2, 81,
  124669. _huff_lengthlist__44c1_sm_long,
  124670. 0, 0, 0, 0, 0,
  124671. NULL,
  124672. NULL,
  124673. NULL,
  124674. NULL,
  124675. 0
  124676. };
  124677. static long _vq_quantlist__44c1_sm_p1_0[] = {
  124678. 1,
  124679. 0,
  124680. 2,
  124681. };
  124682. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  124683. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  124684. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124689. 0, 0, 0, 7, 8, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  124694. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 7, 0, 0, 0, 0,
  124729. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  124734. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  124739. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124775. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124780. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124785. 0, 0, 0, 0, 0, 0, 9,10, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125093. 0,
  125094. };
  125095. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  125096. -0.5, 0.5,
  125097. };
  125098. static long _vq_quantmap__44c1_sm_p1_0[] = {
  125099. 1, 0, 2,
  125100. };
  125101. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  125102. _vq_quantthresh__44c1_sm_p1_0,
  125103. _vq_quantmap__44c1_sm_p1_0,
  125104. 3,
  125105. 3
  125106. };
  125107. static static_codebook _44c1_sm_p1_0 = {
  125108. 8, 6561,
  125109. _vq_lengthlist__44c1_sm_p1_0,
  125110. 1, -535822336, 1611661312, 2, 0,
  125111. _vq_quantlist__44c1_sm_p1_0,
  125112. NULL,
  125113. &_vq_auxt__44c1_sm_p1_0,
  125114. NULL,
  125115. 0
  125116. };
  125117. static long _vq_quantlist__44c1_sm_p2_0[] = {
  125118. 2,
  125119. 1,
  125120. 3,
  125121. 0,
  125122. 4,
  125123. };
  125124. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  125125. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  125127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125128. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  125130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125131. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  125132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125164. 0,
  125165. };
  125166. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  125167. -1.5, -0.5, 0.5, 1.5,
  125168. };
  125169. static long _vq_quantmap__44c1_sm_p2_0[] = {
  125170. 3, 1, 0, 2, 4,
  125171. };
  125172. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  125173. _vq_quantthresh__44c1_sm_p2_0,
  125174. _vq_quantmap__44c1_sm_p2_0,
  125175. 5,
  125176. 5
  125177. };
  125178. static static_codebook _44c1_sm_p2_0 = {
  125179. 4, 625,
  125180. _vq_lengthlist__44c1_sm_p2_0,
  125181. 1, -533725184, 1611661312, 3, 0,
  125182. _vq_quantlist__44c1_sm_p2_0,
  125183. NULL,
  125184. &_vq_auxt__44c1_sm_p2_0,
  125185. NULL,
  125186. 0
  125187. };
  125188. static long _vq_quantlist__44c1_sm_p3_0[] = {
  125189. 4,
  125190. 3,
  125191. 5,
  125192. 2,
  125193. 6,
  125194. 1,
  125195. 7,
  125196. 0,
  125197. 8,
  125198. };
  125199. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  125200. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  125201. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  125202. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125203. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125204. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125205. 0,
  125206. };
  125207. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  125208. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125209. };
  125210. static long _vq_quantmap__44c1_sm_p3_0[] = {
  125211. 7, 5, 3, 1, 0, 2, 4, 6,
  125212. 8,
  125213. };
  125214. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  125215. _vq_quantthresh__44c1_sm_p3_0,
  125216. _vq_quantmap__44c1_sm_p3_0,
  125217. 9,
  125218. 9
  125219. };
  125220. static static_codebook _44c1_sm_p3_0 = {
  125221. 2, 81,
  125222. _vq_lengthlist__44c1_sm_p3_0,
  125223. 1, -531628032, 1611661312, 4, 0,
  125224. _vq_quantlist__44c1_sm_p3_0,
  125225. NULL,
  125226. &_vq_auxt__44c1_sm_p3_0,
  125227. NULL,
  125228. 0
  125229. };
  125230. static long _vq_quantlist__44c1_sm_p4_0[] = {
  125231. 4,
  125232. 3,
  125233. 5,
  125234. 2,
  125235. 6,
  125236. 1,
  125237. 7,
  125238. 0,
  125239. 8,
  125240. };
  125241. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  125242. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  125243. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  125244. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  125245. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  125246. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  125247. 11,
  125248. };
  125249. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  125250. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125251. };
  125252. static long _vq_quantmap__44c1_sm_p4_0[] = {
  125253. 7, 5, 3, 1, 0, 2, 4, 6,
  125254. 8,
  125255. };
  125256. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  125257. _vq_quantthresh__44c1_sm_p4_0,
  125258. _vq_quantmap__44c1_sm_p4_0,
  125259. 9,
  125260. 9
  125261. };
  125262. static static_codebook _44c1_sm_p4_0 = {
  125263. 2, 81,
  125264. _vq_lengthlist__44c1_sm_p4_0,
  125265. 1, -531628032, 1611661312, 4, 0,
  125266. _vq_quantlist__44c1_sm_p4_0,
  125267. NULL,
  125268. &_vq_auxt__44c1_sm_p4_0,
  125269. NULL,
  125270. 0
  125271. };
  125272. static long _vq_quantlist__44c1_sm_p5_0[] = {
  125273. 8,
  125274. 7,
  125275. 9,
  125276. 6,
  125277. 10,
  125278. 5,
  125279. 11,
  125280. 4,
  125281. 12,
  125282. 3,
  125283. 13,
  125284. 2,
  125285. 14,
  125286. 1,
  125287. 15,
  125288. 0,
  125289. 16,
  125290. };
  125291. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125292. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125293. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125294. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125295. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125296. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125297. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125298. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125299. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125300. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125301. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125302. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125303. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125304. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125305. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125306. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125307. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125308. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125309. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125310. 14,
  125311. };
  125312. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125313. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125314. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125315. };
  125316. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125317. 15, 13, 11, 9, 7, 5, 3, 1,
  125318. 0, 2, 4, 6, 8, 10, 12, 14,
  125319. 16,
  125320. };
  125321. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125322. _vq_quantthresh__44c1_sm_p5_0,
  125323. _vq_quantmap__44c1_sm_p5_0,
  125324. 17,
  125325. 17
  125326. };
  125327. static static_codebook _44c1_sm_p5_0 = {
  125328. 2, 289,
  125329. _vq_lengthlist__44c1_sm_p5_0,
  125330. 1, -529530880, 1611661312, 5, 0,
  125331. _vq_quantlist__44c1_sm_p5_0,
  125332. NULL,
  125333. &_vq_auxt__44c1_sm_p5_0,
  125334. NULL,
  125335. 0
  125336. };
  125337. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125338. 1,
  125339. 0,
  125340. 2,
  125341. };
  125342. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125343. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125344. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125345. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125346. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125347. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125348. 11,
  125349. };
  125350. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125351. -5.5, 5.5,
  125352. };
  125353. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125354. 1, 0, 2,
  125355. };
  125356. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125357. _vq_quantthresh__44c1_sm_p6_0,
  125358. _vq_quantmap__44c1_sm_p6_0,
  125359. 3,
  125360. 3
  125361. };
  125362. static static_codebook _44c1_sm_p6_0 = {
  125363. 4, 81,
  125364. _vq_lengthlist__44c1_sm_p6_0,
  125365. 1, -529137664, 1618345984, 2, 0,
  125366. _vq_quantlist__44c1_sm_p6_0,
  125367. NULL,
  125368. &_vq_auxt__44c1_sm_p6_0,
  125369. NULL,
  125370. 0
  125371. };
  125372. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125373. 5,
  125374. 4,
  125375. 6,
  125376. 3,
  125377. 7,
  125378. 2,
  125379. 8,
  125380. 1,
  125381. 9,
  125382. 0,
  125383. 10,
  125384. };
  125385. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  125386. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  125387. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  125388. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  125389. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125390. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125391. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  125392. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125393. 10,10,10, 8, 8, 8, 8, 8, 8,
  125394. };
  125395. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125396. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125397. 3.5, 4.5,
  125398. };
  125399. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125400. 9, 7, 5, 3, 1, 0, 2, 4,
  125401. 6, 8, 10,
  125402. };
  125403. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125404. _vq_quantthresh__44c1_sm_p6_1,
  125405. _vq_quantmap__44c1_sm_p6_1,
  125406. 11,
  125407. 11
  125408. };
  125409. static static_codebook _44c1_sm_p6_1 = {
  125410. 2, 121,
  125411. _vq_lengthlist__44c1_sm_p6_1,
  125412. 1, -531365888, 1611661312, 4, 0,
  125413. _vq_quantlist__44c1_sm_p6_1,
  125414. NULL,
  125415. &_vq_auxt__44c1_sm_p6_1,
  125416. NULL,
  125417. 0
  125418. };
  125419. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125420. 6,
  125421. 5,
  125422. 7,
  125423. 4,
  125424. 8,
  125425. 3,
  125426. 9,
  125427. 2,
  125428. 10,
  125429. 1,
  125430. 11,
  125431. 0,
  125432. 12,
  125433. };
  125434. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125435. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125436. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125437. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125438. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125439. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125440. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125441. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125442. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125443. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125444. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125445. 0,12,12,11,11,13,12,14,13,
  125446. };
  125447. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125448. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125449. 12.5, 17.5, 22.5, 27.5,
  125450. };
  125451. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125452. 11, 9, 7, 5, 3, 1, 0, 2,
  125453. 4, 6, 8, 10, 12,
  125454. };
  125455. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125456. _vq_quantthresh__44c1_sm_p7_0,
  125457. _vq_quantmap__44c1_sm_p7_0,
  125458. 13,
  125459. 13
  125460. };
  125461. static static_codebook _44c1_sm_p7_0 = {
  125462. 2, 169,
  125463. _vq_lengthlist__44c1_sm_p7_0,
  125464. 1, -526516224, 1616117760, 4, 0,
  125465. _vq_quantlist__44c1_sm_p7_0,
  125466. NULL,
  125467. &_vq_auxt__44c1_sm_p7_0,
  125468. NULL,
  125469. 0
  125470. };
  125471. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125472. 2,
  125473. 1,
  125474. 3,
  125475. 0,
  125476. 4,
  125477. };
  125478. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125479. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125480. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125481. };
  125482. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125483. -1.5, -0.5, 0.5, 1.5,
  125484. };
  125485. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125486. 3, 1, 0, 2, 4,
  125487. };
  125488. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125489. _vq_quantthresh__44c1_sm_p7_1,
  125490. _vq_quantmap__44c1_sm_p7_1,
  125491. 5,
  125492. 5
  125493. };
  125494. static static_codebook _44c1_sm_p7_1 = {
  125495. 2, 25,
  125496. _vq_lengthlist__44c1_sm_p7_1,
  125497. 1, -533725184, 1611661312, 3, 0,
  125498. _vq_quantlist__44c1_sm_p7_1,
  125499. NULL,
  125500. &_vq_auxt__44c1_sm_p7_1,
  125501. NULL,
  125502. 0
  125503. };
  125504. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125505. 6,
  125506. 5,
  125507. 7,
  125508. 4,
  125509. 8,
  125510. 3,
  125511. 9,
  125512. 2,
  125513. 10,
  125514. 1,
  125515. 11,
  125516. 0,
  125517. 12,
  125518. };
  125519. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125520. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125521. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125522. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125523. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125524. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125525. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125526. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125527. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125528. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125529. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125530. 13,13,13,13,13,13,13,13,13,
  125531. };
  125532. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125533. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125534. 552.5, 773.5, 994.5, 1215.5,
  125535. };
  125536. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125537. 11, 9, 7, 5, 3, 1, 0, 2,
  125538. 4, 6, 8, 10, 12,
  125539. };
  125540. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125541. _vq_quantthresh__44c1_sm_p8_0,
  125542. _vq_quantmap__44c1_sm_p8_0,
  125543. 13,
  125544. 13
  125545. };
  125546. static static_codebook _44c1_sm_p8_0 = {
  125547. 2, 169,
  125548. _vq_lengthlist__44c1_sm_p8_0,
  125549. 1, -514541568, 1627103232, 4, 0,
  125550. _vq_quantlist__44c1_sm_p8_0,
  125551. NULL,
  125552. &_vq_auxt__44c1_sm_p8_0,
  125553. NULL,
  125554. 0
  125555. };
  125556. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125557. 6,
  125558. 5,
  125559. 7,
  125560. 4,
  125561. 8,
  125562. 3,
  125563. 9,
  125564. 2,
  125565. 10,
  125566. 1,
  125567. 11,
  125568. 0,
  125569. 12,
  125570. };
  125571. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125572. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125573. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125574. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125575. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125576. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125577. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125578. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125579. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125580. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125581. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125582. 20,13,12,12,12,14,12,14,13,
  125583. };
  125584. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125585. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125586. 42.5, 59.5, 76.5, 93.5,
  125587. };
  125588. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125589. 11, 9, 7, 5, 3, 1, 0, 2,
  125590. 4, 6, 8, 10, 12,
  125591. };
  125592. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125593. _vq_quantthresh__44c1_sm_p8_1,
  125594. _vq_quantmap__44c1_sm_p8_1,
  125595. 13,
  125596. 13
  125597. };
  125598. static static_codebook _44c1_sm_p8_1 = {
  125599. 2, 169,
  125600. _vq_lengthlist__44c1_sm_p8_1,
  125601. 1, -522616832, 1620115456, 4, 0,
  125602. _vq_quantlist__44c1_sm_p8_1,
  125603. NULL,
  125604. &_vq_auxt__44c1_sm_p8_1,
  125605. NULL,
  125606. 0
  125607. };
  125608. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125609. 8,
  125610. 7,
  125611. 9,
  125612. 6,
  125613. 10,
  125614. 5,
  125615. 11,
  125616. 4,
  125617. 12,
  125618. 3,
  125619. 13,
  125620. 2,
  125621. 14,
  125622. 1,
  125623. 15,
  125624. 0,
  125625. 16,
  125626. };
  125627. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125628. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125629. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125630. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125631. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125632. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125633. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125634. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125635. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125636. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125637. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125638. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125639. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125640. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125641. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125642. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125643. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125644. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125645. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125646. 9,
  125647. };
  125648. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125649. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125650. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125651. };
  125652. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125653. 15, 13, 11, 9, 7, 5, 3, 1,
  125654. 0, 2, 4, 6, 8, 10, 12, 14,
  125655. 16,
  125656. };
  125657. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125658. _vq_quantthresh__44c1_sm_p8_2,
  125659. _vq_quantmap__44c1_sm_p8_2,
  125660. 17,
  125661. 17
  125662. };
  125663. static static_codebook _44c1_sm_p8_2 = {
  125664. 2, 289,
  125665. _vq_lengthlist__44c1_sm_p8_2,
  125666. 1, -529530880, 1611661312, 5, 0,
  125667. _vq_quantlist__44c1_sm_p8_2,
  125668. NULL,
  125669. &_vq_auxt__44c1_sm_p8_2,
  125670. NULL,
  125671. 0
  125672. };
  125673. static long _huff_lengthlist__44c1_sm_short[] = {
  125674. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  125675. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  125676. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  125677. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  125678. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  125679. 11,
  125680. };
  125681. static static_codebook _huff_book__44c1_sm_short = {
  125682. 2, 81,
  125683. _huff_lengthlist__44c1_sm_short,
  125684. 0, 0, 0, 0, 0,
  125685. NULL,
  125686. NULL,
  125687. NULL,
  125688. NULL,
  125689. 0
  125690. };
  125691. static long _huff_lengthlist__44cn1_s_long[] = {
  125692. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  125693. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  125694. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  125695. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  125696. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  125697. 20,
  125698. };
  125699. static static_codebook _huff_book__44cn1_s_long = {
  125700. 2, 81,
  125701. _huff_lengthlist__44cn1_s_long,
  125702. 0, 0, 0, 0, 0,
  125703. NULL,
  125704. NULL,
  125705. NULL,
  125706. NULL,
  125707. 0
  125708. };
  125709. static long _vq_quantlist__44cn1_s_p1_0[] = {
  125710. 1,
  125711. 0,
  125712. 2,
  125713. };
  125714. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  125715. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125716. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  125721. 0, 0, 0, 7, 9,10, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  125726. 0, 0, 0, 0, 8,10, 9, 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, 5, 8, 8, 0, 0, 0, 0,
  125761. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 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, 7,10,10, 0, 0, 0,
  125766. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 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, 7,10,10, 0, 0,
  125771. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  125807. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125812. 0, 0, 0, 0, 0, 9, 9,11, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  125817. 0, 0, 0, 0, 0, 0, 9,11, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126125. 0,
  126126. };
  126127. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  126128. -0.5, 0.5,
  126129. };
  126130. static long _vq_quantmap__44cn1_s_p1_0[] = {
  126131. 1, 0, 2,
  126132. };
  126133. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  126134. _vq_quantthresh__44cn1_s_p1_0,
  126135. _vq_quantmap__44cn1_s_p1_0,
  126136. 3,
  126137. 3
  126138. };
  126139. static static_codebook _44cn1_s_p1_0 = {
  126140. 8, 6561,
  126141. _vq_lengthlist__44cn1_s_p1_0,
  126142. 1, -535822336, 1611661312, 2, 0,
  126143. _vq_quantlist__44cn1_s_p1_0,
  126144. NULL,
  126145. &_vq_auxt__44cn1_s_p1_0,
  126146. NULL,
  126147. 0
  126148. };
  126149. static long _vq_quantlist__44cn1_s_p2_0[] = {
  126150. 2,
  126151. 1,
  126152. 3,
  126153. 0,
  126154. 4,
  126155. };
  126156. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  126157. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  126159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126160. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  126162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126163. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  126164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126196. 0,
  126197. };
  126198. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  126199. -1.5, -0.5, 0.5, 1.5,
  126200. };
  126201. static long _vq_quantmap__44cn1_s_p2_0[] = {
  126202. 3, 1, 0, 2, 4,
  126203. };
  126204. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  126205. _vq_quantthresh__44cn1_s_p2_0,
  126206. _vq_quantmap__44cn1_s_p2_0,
  126207. 5,
  126208. 5
  126209. };
  126210. static static_codebook _44cn1_s_p2_0 = {
  126211. 4, 625,
  126212. _vq_lengthlist__44cn1_s_p2_0,
  126213. 1, -533725184, 1611661312, 3, 0,
  126214. _vq_quantlist__44cn1_s_p2_0,
  126215. NULL,
  126216. &_vq_auxt__44cn1_s_p2_0,
  126217. NULL,
  126218. 0
  126219. };
  126220. static long _vq_quantlist__44cn1_s_p3_0[] = {
  126221. 4,
  126222. 3,
  126223. 5,
  126224. 2,
  126225. 6,
  126226. 1,
  126227. 7,
  126228. 0,
  126229. 8,
  126230. };
  126231. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  126232. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  126233. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  126234. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  126235. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  126236. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126237. 0,
  126238. };
  126239. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  126240. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126241. };
  126242. static long _vq_quantmap__44cn1_s_p3_0[] = {
  126243. 7, 5, 3, 1, 0, 2, 4, 6,
  126244. 8,
  126245. };
  126246. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  126247. _vq_quantthresh__44cn1_s_p3_0,
  126248. _vq_quantmap__44cn1_s_p3_0,
  126249. 9,
  126250. 9
  126251. };
  126252. static static_codebook _44cn1_s_p3_0 = {
  126253. 2, 81,
  126254. _vq_lengthlist__44cn1_s_p3_0,
  126255. 1, -531628032, 1611661312, 4, 0,
  126256. _vq_quantlist__44cn1_s_p3_0,
  126257. NULL,
  126258. &_vq_auxt__44cn1_s_p3_0,
  126259. NULL,
  126260. 0
  126261. };
  126262. static long _vq_quantlist__44cn1_s_p4_0[] = {
  126263. 4,
  126264. 3,
  126265. 5,
  126266. 2,
  126267. 6,
  126268. 1,
  126269. 7,
  126270. 0,
  126271. 8,
  126272. };
  126273. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  126274. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  126275. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  126276. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  126277. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126278. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126279. 11,
  126280. };
  126281. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  126282. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126283. };
  126284. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126285. 7, 5, 3, 1, 0, 2, 4, 6,
  126286. 8,
  126287. };
  126288. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126289. _vq_quantthresh__44cn1_s_p4_0,
  126290. _vq_quantmap__44cn1_s_p4_0,
  126291. 9,
  126292. 9
  126293. };
  126294. static static_codebook _44cn1_s_p4_0 = {
  126295. 2, 81,
  126296. _vq_lengthlist__44cn1_s_p4_0,
  126297. 1, -531628032, 1611661312, 4, 0,
  126298. _vq_quantlist__44cn1_s_p4_0,
  126299. NULL,
  126300. &_vq_auxt__44cn1_s_p4_0,
  126301. NULL,
  126302. 0
  126303. };
  126304. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126305. 8,
  126306. 7,
  126307. 9,
  126308. 6,
  126309. 10,
  126310. 5,
  126311. 11,
  126312. 4,
  126313. 12,
  126314. 3,
  126315. 13,
  126316. 2,
  126317. 14,
  126318. 1,
  126319. 15,
  126320. 0,
  126321. 16,
  126322. };
  126323. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126324. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126325. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126326. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126327. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126328. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126329. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126330. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126331. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126332. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126333. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126334. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126335. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126336. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126337. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126338. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126339. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126340. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126341. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126342. 14,
  126343. };
  126344. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126345. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126346. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126347. };
  126348. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126349. 15, 13, 11, 9, 7, 5, 3, 1,
  126350. 0, 2, 4, 6, 8, 10, 12, 14,
  126351. 16,
  126352. };
  126353. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126354. _vq_quantthresh__44cn1_s_p5_0,
  126355. _vq_quantmap__44cn1_s_p5_0,
  126356. 17,
  126357. 17
  126358. };
  126359. static static_codebook _44cn1_s_p5_0 = {
  126360. 2, 289,
  126361. _vq_lengthlist__44cn1_s_p5_0,
  126362. 1, -529530880, 1611661312, 5, 0,
  126363. _vq_quantlist__44cn1_s_p5_0,
  126364. NULL,
  126365. &_vq_auxt__44cn1_s_p5_0,
  126366. NULL,
  126367. 0
  126368. };
  126369. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126370. 1,
  126371. 0,
  126372. 2,
  126373. };
  126374. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126375. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  126376. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  126377. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  126378. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  126379. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  126380. 10,
  126381. };
  126382. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  126383. -5.5, 5.5,
  126384. };
  126385. static long _vq_quantmap__44cn1_s_p6_0[] = {
  126386. 1, 0, 2,
  126387. };
  126388. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  126389. _vq_quantthresh__44cn1_s_p6_0,
  126390. _vq_quantmap__44cn1_s_p6_0,
  126391. 3,
  126392. 3
  126393. };
  126394. static static_codebook _44cn1_s_p6_0 = {
  126395. 4, 81,
  126396. _vq_lengthlist__44cn1_s_p6_0,
  126397. 1, -529137664, 1618345984, 2, 0,
  126398. _vq_quantlist__44cn1_s_p6_0,
  126399. NULL,
  126400. &_vq_auxt__44cn1_s_p6_0,
  126401. NULL,
  126402. 0
  126403. };
  126404. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126405. 5,
  126406. 4,
  126407. 6,
  126408. 3,
  126409. 7,
  126410. 2,
  126411. 8,
  126412. 1,
  126413. 9,
  126414. 0,
  126415. 10,
  126416. };
  126417. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126418. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126419. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126420. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126421. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126422. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126423. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126424. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126425. 10,10,10, 9, 9, 9, 9, 9, 9,
  126426. };
  126427. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126428. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126429. 3.5, 4.5,
  126430. };
  126431. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126432. 9, 7, 5, 3, 1, 0, 2, 4,
  126433. 6, 8, 10,
  126434. };
  126435. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126436. _vq_quantthresh__44cn1_s_p6_1,
  126437. _vq_quantmap__44cn1_s_p6_1,
  126438. 11,
  126439. 11
  126440. };
  126441. static static_codebook _44cn1_s_p6_1 = {
  126442. 2, 121,
  126443. _vq_lengthlist__44cn1_s_p6_1,
  126444. 1, -531365888, 1611661312, 4, 0,
  126445. _vq_quantlist__44cn1_s_p6_1,
  126446. NULL,
  126447. &_vq_auxt__44cn1_s_p6_1,
  126448. NULL,
  126449. 0
  126450. };
  126451. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126452. 6,
  126453. 5,
  126454. 7,
  126455. 4,
  126456. 8,
  126457. 3,
  126458. 9,
  126459. 2,
  126460. 10,
  126461. 1,
  126462. 11,
  126463. 0,
  126464. 12,
  126465. };
  126466. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126467. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126468. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126469. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126470. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126471. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126472. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126473. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126474. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126475. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126476. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126477. 0,13,13,12,12,13,13,13,14,
  126478. };
  126479. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126480. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126481. 12.5, 17.5, 22.5, 27.5,
  126482. };
  126483. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126484. 11, 9, 7, 5, 3, 1, 0, 2,
  126485. 4, 6, 8, 10, 12,
  126486. };
  126487. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126488. _vq_quantthresh__44cn1_s_p7_0,
  126489. _vq_quantmap__44cn1_s_p7_0,
  126490. 13,
  126491. 13
  126492. };
  126493. static static_codebook _44cn1_s_p7_0 = {
  126494. 2, 169,
  126495. _vq_lengthlist__44cn1_s_p7_0,
  126496. 1, -526516224, 1616117760, 4, 0,
  126497. _vq_quantlist__44cn1_s_p7_0,
  126498. NULL,
  126499. &_vq_auxt__44cn1_s_p7_0,
  126500. NULL,
  126501. 0
  126502. };
  126503. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126504. 2,
  126505. 1,
  126506. 3,
  126507. 0,
  126508. 4,
  126509. };
  126510. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126511. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126512. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126513. };
  126514. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126515. -1.5, -0.5, 0.5, 1.5,
  126516. };
  126517. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126518. 3, 1, 0, 2, 4,
  126519. };
  126520. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126521. _vq_quantthresh__44cn1_s_p7_1,
  126522. _vq_quantmap__44cn1_s_p7_1,
  126523. 5,
  126524. 5
  126525. };
  126526. static static_codebook _44cn1_s_p7_1 = {
  126527. 2, 25,
  126528. _vq_lengthlist__44cn1_s_p7_1,
  126529. 1, -533725184, 1611661312, 3, 0,
  126530. _vq_quantlist__44cn1_s_p7_1,
  126531. NULL,
  126532. &_vq_auxt__44cn1_s_p7_1,
  126533. NULL,
  126534. 0
  126535. };
  126536. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126537. 2,
  126538. 1,
  126539. 3,
  126540. 0,
  126541. 4,
  126542. };
  126543. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126544. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126545. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  126546. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126547. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126548. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126549. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126550. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126551. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126552. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126553. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126554. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126555. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126556. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126557. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126558. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126559. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  126560. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126561. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126562. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126563. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126564. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126565. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126566. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126567. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126568. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126569. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126570. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126571. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126572. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126573. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126574. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126575. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126576. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126577. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  126578. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126579. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126580. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126581. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126582. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126583. 12,
  126584. };
  126585. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126586. -331.5, -110.5, 110.5, 331.5,
  126587. };
  126588. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126589. 3, 1, 0, 2, 4,
  126590. };
  126591. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126592. _vq_quantthresh__44cn1_s_p8_0,
  126593. _vq_quantmap__44cn1_s_p8_0,
  126594. 5,
  126595. 5
  126596. };
  126597. static static_codebook _44cn1_s_p8_0 = {
  126598. 4, 625,
  126599. _vq_lengthlist__44cn1_s_p8_0,
  126600. 1, -518283264, 1627103232, 3, 0,
  126601. _vq_quantlist__44cn1_s_p8_0,
  126602. NULL,
  126603. &_vq_auxt__44cn1_s_p8_0,
  126604. NULL,
  126605. 0
  126606. };
  126607. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126608. 6,
  126609. 5,
  126610. 7,
  126611. 4,
  126612. 8,
  126613. 3,
  126614. 9,
  126615. 2,
  126616. 10,
  126617. 1,
  126618. 11,
  126619. 0,
  126620. 12,
  126621. };
  126622. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126623. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126624. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126625. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126626. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126627. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126628. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126629. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126630. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126631. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126632. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126633. 15,12,12,11,11,14,12,13,14,
  126634. };
  126635. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126636. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126637. 42.5, 59.5, 76.5, 93.5,
  126638. };
  126639. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126640. 11, 9, 7, 5, 3, 1, 0, 2,
  126641. 4, 6, 8, 10, 12,
  126642. };
  126643. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126644. _vq_quantthresh__44cn1_s_p8_1,
  126645. _vq_quantmap__44cn1_s_p8_1,
  126646. 13,
  126647. 13
  126648. };
  126649. static static_codebook _44cn1_s_p8_1 = {
  126650. 2, 169,
  126651. _vq_lengthlist__44cn1_s_p8_1,
  126652. 1, -522616832, 1620115456, 4, 0,
  126653. _vq_quantlist__44cn1_s_p8_1,
  126654. NULL,
  126655. &_vq_auxt__44cn1_s_p8_1,
  126656. NULL,
  126657. 0
  126658. };
  126659. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126660. 8,
  126661. 7,
  126662. 9,
  126663. 6,
  126664. 10,
  126665. 5,
  126666. 11,
  126667. 4,
  126668. 12,
  126669. 3,
  126670. 13,
  126671. 2,
  126672. 14,
  126673. 1,
  126674. 15,
  126675. 0,
  126676. 16,
  126677. };
  126678. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  126679. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  126680. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  126681. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  126682. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  126683. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  126684. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  126685. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  126686. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  126687. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  126688. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  126689. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  126690. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  126691. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  126692. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  126693. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  126694. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  126695. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  126696. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  126697. 9,
  126698. };
  126699. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  126700. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126701. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126702. };
  126703. static long _vq_quantmap__44cn1_s_p8_2[] = {
  126704. 15, 13, 11, 9, 7, 5, 3, 1,
  126705. 0, 2, 4, 6, 8, 10, 12, 14,
  126706. 16,
  126707. };
  126708. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  126709. _vq_quantthresh__44cn1_s_p8_2,
  126710. _vq_quantmap__44cn1_s_p8_2,
  126711. 17,
  126712. 17
  126713. };
  126714. static static_codebook _44cn1_s_p8_2 = {
  126715. 2, 289,
  126716. _vq_lengthlist__44cn1_s_p8_2,
  126717. 1, -529530880, 1611661312, 5, 0,
  126718. _vq_quantlist__44cn1_s_p8_2,
  126719. NULL,
  126720. &_vq_auxt__44cn1_s_p8_2,
  126721. NULL,
  126722. 0
  126723. };
  126724. static long _huff_lengthlist__44cn1_s_short[] = {
  126725. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  126726. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  126727. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  126728. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  126729. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  126730. 10,
  126731. };
  126732. static static_codebook _huff_book__44cn1_s_short = {
  126733. 2, 81,
  126734. _huff_lengthlist__44cn1_s_short,
  126735. 0, 0, 0, 0, 0,
  126736. NULL,
  126737. NULL,
  126738. NULL,
  126739. NULL,
  126740. 0
  126741. };
  126742. static long _huff_lengthlist__44cn1_sm_long[] = {
  126743. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  126744. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  126745. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  126746. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  126747. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  126748. 17,
  126749. };
  126750. static static_codebook _huff_book__44cn1_sm_long = {
  126751. 2, 81,
  126752. _huff_lengthlist__44cn1_sm_long,
  126753. 0, 0, 0, 0, 0,
  126754. NULL,
  126755. NULL,
  126756. NULL,
  126757. NULL,
  126758. 0
  126759. };
  126760. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  126761. 1,
  126762. 0,
  126763. 2,
  126764. };
  126765. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  126766. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126767. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126772. 0, 0, 0, 7, 8, 9, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  126777. 0, 0, 0, 0, 8, 9, 9, 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, 5, 8, 8, 0, 0, 0, 0,
  126812. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  126817. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  126822. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  126858. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  126863. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  126868. 0, 0, 0, 0, 0, 0, 9,10, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127176. 0,
  127177. };
  127178. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  127179. -0.5, 0.5,
  127180. };
  127181. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  127182. 1, 0, 2,
  127183. };
  127184. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  127185. _vq_quantthresh__44cn1_sm_p1_0,
  127186. _vq_quantmap__44cn1_sm_p1_0,
  127187. 3,
  127188. 3
  127189. };
  127190. static static_codebook _44cn1_sm_p1_0 = {
  127191. 8, 6561,
  127192. _vq_lengthlist__44cn1_sm_p1_0,
  127193. 1, -535822336, 1611661312, 2, 0,
  127194. _vq_quantlist__44cn1_sm_p1_0,
  127195. NULL,
  127196. &_vq_auxt__44cn1_sm_p1_0,
  127197. NULL,
  127198. 0
  127199. };
  127200. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  127201. 2,
  127202. 1,
  127203. 3,
  127204. 0,
  127205. 4,
  127206. };
  127207. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  127208. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  127210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127211. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  127213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127214. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  127215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127247. 0,
  127248. };
  127249. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  127250. -1.5, -0.5, 0.5, 1.5,
  127251. };
  127252. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  127253. 3, 1, 0, 2, 4,
  127254. };
  127255. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  127256. _vq_quantthresh__44cn1_sm_p2_0,
  127257. _vq_quantmap__44cn1_sm_p2_0,
  127258. 5,
  127259. 5
  127260. };
  127261. static static_codebook _44cn1_sm_p2_0 = {
  127262. 4, 625,
  127263. _vq_lengthlist__44cn1_sm_p2_0,
  127264. 1, -533725184, 1611661312, 3, 0,
  127265. _vq_quantlist__44cn1_sm_p2_0,
  127266. NULL,
  127267. &_vq_auxt__44cn1_sm_p2_0,
  127268. NULL,
  127269. 0
  127270. };
  127271. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  127272. 4,
  127273. 3,
  127274. 5,
  127275. 2,
  127276. 6,
  127277. 1,
  127278. 7,
  127279. 0,
  127280. 8,
  127281. };
  127282. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  127283. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127284. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127285. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127286. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127287. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127288. 0,
  127289. };
  127290. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127291. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127292. };
  127293. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127294. 7, 5, 3, 1, 0, 2, 4, 6,
  127295. 8,
  127296. };
  127297. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127298. _vq_quantthresh__44cn1_sm_p3_0,
  127299. _vq_quantmap__44cn1_sm_p3_0,
  127300. 9,
  127301. 9
  127302. };
  127303. static static_codebook _44cn1_sm_p3_0 = {
  127304. 2, 81,
  127305. _vq_lengthlist__44cn1_sm_p3_0,
  127306. 1, -531628032, 1611661312, 4, 0,
  127307. _vq_quantlist__44cn1_sm_p3_0,
  127308. NULL,
  127309. &_vq_auxt__44cn1_sm_p3_0,
  127310. NULL,
  127311. 0
  127312. };
  127313. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127314. 4,
  127315. 3,
  127316. 5,
  127317. 2,
  127318. 6,
  127319. 1,
  127320. 7,
  127321. 0,
  127322. 8,
  127323. };
  127324. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127325. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127326. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127327. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127328. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127329. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127330. 11,
  127331. };
  127332. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127333. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127334. };
  127335. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127336. 7, 5, 3, 1, 0, 2, 4, 6,
  127337. 8,
  127338. };
  127339. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127340. _vq_quantthresh__44cn1_sm_p4_0,
  127341. _vq_quantmap__44cn1_sm_p4_0,
  127342. 9,
  127343. 9
  127344. };
  127345. static static_codebook _44cn1_sm_p4_0 = {
  127346. 2, 81,
  127347. _vq_lengthlist__44cn1_sm_p4_0,
  127348. 1, -531628032, 1611661312, 4, 0,
  127349. _vq_quantlist__44cn1_sm_p4_0,
  127350. NULL,
  127351. &_vq_auxt__44cn1_sm_p4_0,
  127352. NULL,
  127353. 0
  127354. };
  127355. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127356. 8,
  127357. 7,
  127358. 9,
  127359. 6,
  127360. 10,
  127361. 5,
  127362. 11,
  127363. 4,
  127364. 12,
  127365. 3,
  127366. 13,
  127367. 2,
  127368. 14,
  127369. 1,
  127370. 15,
  127371. 0,
  127372. 16,
  127373. };
  127374. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127375. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  127376. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  127377. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  127378. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  127379. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  127380. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  127381. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  127382. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  127383. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  127384. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  127385. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  127386. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  127387. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  127388. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  127389. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  127390. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  127391. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  127392. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  127393. 14,
  127394. };
  127395. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127396. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127397. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127398. };
  127399. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127400. 15, 13, 11, 9, 7, 5, 3, 1,
  127401. 0, 2, 4, 6, 8, 10, 12, 14,
  127402. 16,
  127403. };
  127404. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127405. _vq_quantthresh__44cn1_sm_p5_0,
  127406. _vq_quantmap__44cn1_sm_p5_0,
  127407. 17,
  127408. 17
  127409. };
  127410. static static_codebook _44cn1_sm_p5_0 = {
  127411. 2, 289,
  127412. _vq_lengthlist__44cn1_sm_p5_0,
  127413. 1, -529530880, 1611661312, 5, 0,
  127414. _vq_quantlist__44cn1_sm_p5_0,
  127415. NULL,
  127416. &_vq_auxt__44cn1_sm_p5_0,
  127417. NULL,
  127418. 0
  127419. };
  127420. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127421. 1,
  127422. 0,
  127423. 2,
  127424. };
  127425. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127426. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127427. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127428. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127429. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127430. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127431. 10,
  127432. };
  127433. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127434. -5.5, 5.5,
  127435. };
  127436. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127437. 1, 0, 2,
  127438. };
  127439. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127440. _vq_quantthresh__44cn1_sm_p6_0,
  127441. _vq_quantmap__44cn1_sm_p6_0,
  127442. 3,
  127443. 3
  127444. };
  127445. static static_codebook _44cn1_sm_p6_0 = {
  127446. 4, 81,
  127447. _vq_lengthlist__44cn1_sm_p6_0,
  127448. 1, -529137664, 1618345984, 2, 0,
  127449. _vq_quantlist__44cn1_sm_p6_0,
  127450. NULL,
  127451. &_vq_auxt__44cn1_sm_p6_0,
  127452. NULL,
  127453. 0
  127454. };
  127455. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127456. 5,
  127457. 4,
  127458. 6,
  127459. 3,
  127460. 7,
  127461. 2,
  127462. 8,
  127463. 1,
  127464. 9,
  127465. 0,
  127466. 10,
  127467. };
  127468. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127469. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127470. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127471. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127472. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127473. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127474. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127475. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127476. 10,10,10, 8, 9, 8, 8, 9, 8,
  127477. };
  127478. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127479. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127480. 3.5, 4.5,
  127481. };
  127482. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127483. 9, 7, 5, 3, 1, 0, 2, 4,
  127484. 6, 8, 10,
  127485. };
  127486. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127487. _vq_quantthresh__44cn1_sm_p6_1,
  127488. _vq_quantmap__44cn1_sm_p6_1,
  127489. 11,
  127490. 11
  127491. };
  127492. static static_codebook _44cn1_sm_p6_1 = {
  127493. 2, 121,
  127494. _vq_lengthlist__44cn1_sm_p6_1,
  127495. 1, -531365888, 1611661312, 4, 0,
  127496. _vq_quantlist__44cn1_sm_p6_1,
  127497. NULL,
  127498. &_vq_auxt__44cn1_sm_p6_1,
  127499. NULL,
  127500. 0
  127501. };
  127502. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127503. 6,
  127504. 5,
  127505. 7,
  127506. 4,
  127507. 8,
  127508. 3,
  127509. 9,
  127510. 2,
  127511. 10,
  127512. 1,
  127513. 11,
  127514. 0,
  127515. 12,
  127516. };
  127517. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127518. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127519. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127520. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127521. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127522. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127523. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127524. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127525. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127526. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127527. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127528. 0,13,12,12,12,13,13,13,14,
  127529. };
  127530. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127531. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127532. 12.5, 17.5, 22.5, 27.5,
  127533. };
  127534. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127535. 11, 9, 7, 5, 3, 1, 0, 2,
  127536. 4, 6, 8, 10, 12,
  127537. };
  127538. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127539. _vq_quantthresh__44cn1_sm_p7_0,
  127540. _vq_quantmap__44cn1_sm_p7_0,
  127541. 13,
  127542. 13
  127543. };
  127544. static static_codebook _44cn1_sm_p7_0 = {
  127545. 2, 169,
  127546. _vq_lengthlist__44cn1_sm_p7_0,
  127547. 1, -526516224, 1616117760, 4, 0,
  127548. _vq_quantlist__44cn1_sm_p7_0,
  127549. NULL,
  127550. &_vq_auxt__44cn1_sm_p7_0,
  127551. NULL,
  127552. 0
  127553. };
  127554. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127555. 2,
  127556. 1,
  127557. 3,
  127558. 0,
  127559. 4,
  127560. };
  127561. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127562. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127563. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127564. };
  127565. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127566. -1.5, -0.5, 0.5, 1.5,
  127567. };
  127568. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127569. 3, 1, 0, 2, 4,
  127570. };
  127571. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127572. _vq_quantthresh__44cn1_sm_p7_1,
  127573. _vq_quantmap__44cn1_sm_p7_1,
  127574. 5,
  127575. 5
  127576. };
  127577. static static_codebook _44cn1_sm_p7_1 = {
  127578. 2, 25,
  127579. _vq_lengthlist__44cn1_sm_p7_1,
  127580. 1, -533725184, 1611661312, 3, 0,
  127581. _vq_quantlist__44cn1_sm_p7_1,
  127582. NULL,
  127583. &_vq_auxt__44cn1_sm_p7_1,
  127584. NULL,
  127585. 0
  127586. };
  127587. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127588. 4,
  127589. 3,
  127590. 5,
  127591. 2,
  127592. 6,
  127593. 1,
  127594. 7,
  127595. 0,
  127596. 8,
  127597. };
  127598. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127599. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127600. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127601. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127602. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127603. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127604. 14,
  127605. };
  127606. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127607. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127608. };
  127609. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127610. 7, 5, 3, 1, 0, 2, 4, 6,
  127611. 8,
  127612. };
  127613. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127614. _vq_quantthresh__44cn1_sm_p8_0,
  127615. _vq_quantmap__44cn1_sm_p8_0,
  127616. 9,
  127617. 9
  127618. };
  127619. static static_codebook _44cn1_sm_p8_0 = {
  127620. 2, 81,
  127621. _vq_lengthlist__44cn1_sm_p8_0,
  127622. 1, -516186112, 1627103232, 4, 0,
  127623. _vq_quantlist__44cn1_sm_p8_0,
  127624. NULL,
  127625. &_vq_auxt__44cn1_sm_p8_0,
  127626. NULL,
  127627. 0
  127628. };
  127629. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127630. 6,
  127631. 5,
  127632. 7,
  127633. 4,
  127634. 8,
  127635. 3,
  127636. 9,
  127637. 2,
  127638. 10,
  127639. 1,
  127640. 11,
  127641. 0,
  127642. 12,
  127643. };
  127644. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127645. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127646. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127647. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127648. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127649. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127650. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127651. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127652. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127653. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127654. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127655. 17,12,12,11,10,13,11,13,13,
  127656. };
  127657. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127658. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127659. 42.5, 59.5, 76.5, 93.5,
  127660. };
  127661. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127662. 11, 9, 7, 5, 3, 1, 0, 2,
  127663. 4, 6, 8, 10, 12,
  127664. };
  127665. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127666. _vq_quantthresh__44cn1_sm_p8_1,
  127667. _vq_quantmap__44cn1_sm_p8_1,
  127668. 13,
  127669. 13
  127670. };
  127671. static static_codebook _44cn1_sm_p8_1 = {
  127672. 2, 169,
  127673. _vq_lengthlist__44cn1_sm_p8_1,
  127674. 1, -522616832, 1620115456, 4, 0,
  127675. _vq_quantlist__44cn1_sm_p8_1,
  127676. NULL,
  127677. &_vq_auxt__44cn1_sm_p8_1,
  127678. NULL,
  127679. 0
  127680. };
  127681. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  127682. 8,
  127683. 7,
  127684. 9,
  127685. 6,
  127686. 10,
  127687. 5,
  127688. 11,
  127689. 4,
  127690. 12,
  127691. 3,
  127692. 13,
  127693. 2,
  127694. 14,
  127695. 1,
  127696. 15,
  127697. 0,
  127698. 16,
  127699. };
  127700. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  127701. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  127702. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  127703. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  127704. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  127705. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  127706. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  127707. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  127708. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  127709. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  127710. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  127711. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  127712. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  127713. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  127714. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  127715. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  127716. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127717. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127718. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  127719. 9,
  127720. };
  127721. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  127722. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127723. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127724. };
  127725. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  127726. 15, 13, 11, 9, 7, 5, 3, 1,
  127727. 0, 2, 4, 6, 8, 10, 12, 14,
  127728. 16,
  127729. };
  127730. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  127731. _vq_quantthresh__44cn1_sm_p8_2,
  127732. _vq_quantmap__44cn1_sm_p8_2,
  127733. 17,
  127734. 17
  127735. };
  127736. static static_codebook _44cn1_sm_p8_2 = {
  127737. 2, 289,
  127738. _vq_lengthlist__44cn1_sm_p8_2,
  127739. 1, -529530880, 1611661312, 5, 0,
  127740. _vq_quantlist__44cn1_sm_p8_2,
  127741. NULL,
  127742. &_vq_auxt__44cn1_sm_p8_2,
  127743. NULL,
  127744. 0
  127745. };
  127746. static long _huff_lengthlist__44cn1_sm_short[] = {
  127747. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  127748. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  127749. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  127750. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  127751. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  127752. 9,
  127753. };
  127754. static static_codebook _huff_book__44cn1_sm_short = {
  127755. 2, 81,
  127756. _huff_lengthlist__44cn1_sm_short,
  127757. 0, 0, 0, 0, 0,
  127758. NULL,
  127759. NULL,
  127760. NULL,
  127761. NULL,
  127762. 0
  127763. };
  127764. /*** End of inlined file: res_books_stereo.h ***/
  127765. static vorbis_info_residue0 _residue_44_low={
  127766. 0,-1, -1, 9,-1,
  127767. {0},
  127768. {-1},
  127769. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127770. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  127771. };
  127772. static vorbis_info_residue0 _residue_44_mid={
  127773. 0,-1, -1, 10,-1,
  127774. {0},
  127775. {-1},
  127776. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127777. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  127778. };
  127779. static vorbis_info_residue0 _residue_44_high={
  127780. 0,-1, -1, 10,-1,
  127781. {0},
  127782. {-1},
  127783. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  127784. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  127785. };
  127786. static static_bookblock _resbook_44s_n1={
  127787. {
  127788. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  127789. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  127790. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  127791. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  127792. }
  127793. };
  127794. static static_bookblock _resbook_44sm_n1={
  127795. {
  127796. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  127797. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  127798. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  127799. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  127800. }
  127801. };
  127802. static static_bookblock _resbook_44s_0={
  127803. {
  127804. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  127805. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  127806. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  127807. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  127808. }
  127809. };
  127810. static static_bookblock _resbook_44sm_0={
  127811. {
  127812. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  127813. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  127814. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  127815. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  127816. }
  127817. };
  127818. static static_bookblock _resbook_44s_1={
  127819. {
  127820. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  127821. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  127822. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  127823. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  127824. }
  127825. };
  127826. static static_bookblock _resbook_44sm_1={
  127827. {
  127828. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  127829. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  127830. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  127831. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  127832. }
  127833. };
  127834. static static_bookblock _resbook_44s_2={
  127835. {
  127836. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  127837. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  127838. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  127839. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  127840. }
  127841. };
  127842. static static_bookblock _resbook_44s_3={
  127843. {
  127844. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  127845. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  127846. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  127847. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  127848. }
  127849. };
  127850. static static_bookblock _resbook_44s_4={
  127851. {
  127852. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  127853. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  127854. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  127855. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  127856. }
  127857. };
  127858. static static_bookblock _resbook_44s_5={
  127859. {
  127860. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  127861. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  127862. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  127863. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  127864. }
  127865. };
  127866. static static_bookblock _resbook_44s_6={
  127867. {
  127868. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  127869. {0,0,&_44c6_s_p4_0},
  127870. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  127871. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  127872. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  127873. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  127874. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  127875. }
  127876. };
  127877. static static_bookblock _resbook_44s_7={
  127878. {
  127879. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  127880. {0,0,&_44c7_s_p4_0},
  127881. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  127882. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  127883. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  127884. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  127885. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  127886. }
  127887. };
  127888. static static_bookblock _resbook_44s_8={
  127889. {
  127890. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  127891. {0,0,&_44c8_s_p4_0},
  127892. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  127893. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  127894. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  127895. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  127896. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  127897. }
  127898. };
  127899. static static_bookblock _resbook_44s_9={
  127900. {
  127901. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  127902. {0,0,&_44c9_s_p4_0},
  127903. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  127904. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  127905. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  127906. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  127907. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  127908. }
  127909. };
  127910. static vorbis_residue_template _res_44s_n1[]={
  127911. {2,0, &_residue_44_low,
  127912. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  127913. &_resbook_44s_n1,&_resbook_44sm_n1},
  127914. {2,0, &_residue_44_low,
  127915. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  127916. &_resbook_44s_n1,&_resbook_44sm_n1}
  127917. };
  127918. static vorbis_residue_template _res_44s_0[]={
  127919. {2,0, &_residue_44_low,
  127920. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  127921. &_resbook_44s_0,&_resbook_44sm_0},
  127922. {2,0, &_residue_44_low,
  127923. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  127924. &_resbook_44s_0,&_resbook_44sm_0}
  127925. };
  127926. static vorbis_residue_template _res_44s_1[]={
  127927. {2,0, &_residue_44_low,
  127928. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  127929. &_resbook_44s_1,&_resbook_44sm_1},
  127930. {2,0, &_residue_44_low,
  127931. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  127932. &_resbook_44s_1,&_resbook_44sm_1}
  127933. };
  127934. static vorbis_residue_template _res_44s_2[]={
  127935. {2,0, &_residue_44_mid,
  127936. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  127937. &_resbook_44s_2,&_resbook_44s_2},
  127938. {2,0, &_residue_44_mid,
  127939. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  127940. &_resbook_44s_2,&_resbook_44s_2}
  127941. };
  127942. static vorbis_residue_template _res_44s_3[]={
  127943. {2,0, &_residue_44_mid,
  127944. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  127945. &_resbook_44s_3,&_resbook_44s_3},
  127946. {2,0, &_residue_44_mid,
  127947. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  127948. &_resbook_44s_3,&_resbook_44s_3}
  127949. };
  127950. static vorbis_residue_template _res_44s_4[]={
  127951. {2,0, &_residue_44_mid,
  127952. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  127953. &_resbook_44s_4,&_resbook_44s_4},
  127954. {2,0, &_residue_44_mid,
  127955. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  127956. &_resbook_44s_4,&_resbook_44s_4}
  127957. };
  127958. static vorbis_residue_template _res_44s_5[]={
  127959. {2,0, &_residue_44_mid,
  127960. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  127961. &_resbook_44s_5,&_resbook_44s_5},
  127962. {2,0, &_residue_44_mid,
  127963. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  127964. &_resbook_44s_5,&_resbook_44s_5}
  127965. };
  127966. static vorbis_residue_template _res_44s_6[]={
  127967. {2,0, &_residue_44_high,
  127968. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  127969. &_resbook_44s_6,&_resbook_44s_6},
  127970. {2,0, &_residue_44_high,
  127971. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  127972. &_resbook_44s_6,&_resbook_44s_6}
  127973. };
  127974. static vorbis_residue_template _res_44s_7[]={
  127975. {2,0, &_residue_44_high,
  127976. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  127977. &_resbook_44s_7,&_resbook_44s_7},
  127978. {2,0, &_residue_44_high,
  127979. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  127980. &_resbook_44s_7,&_resbook_44s_7}
  127981. };
  127982. static vorbis_residue_template _res_44s_8[]={
  127983. {2,0, &_residue_44_high,
  127984. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  127985. &_resbook_44s_8,&_resbook_44s_8},
  127986. {2,0, &_residue_44_high,
  127987. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  127988. &_resbook_44s_8,&_resbook_44s_8}
  127989. };
  127990. static vorbis_residue_template _res_44s_9[]={
  127991. {2,0, &_residue_44_high,
  127992. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  127993. &_resbook_44s_9,&_resbook_44s_9},
  127994. {2,0, &_residue_44_high,
  127995. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  127996. &_resbook_44s_9,&_resbook_44s_9}
  127997. };
  127998. static vorbis_mapping_template _mapres_template_44_stereo[]={
  127999. { _map_nominal, _res_44s_n1 }, /* -1 */
  128000. { _map_nominal, _res_44s_0 }, /* 0 */
  128001. { _map_nominal, _res_44s_1 }, /* 1 */
  128002. { _map_nominal, _res_44s_2 }, /* 2 */
  128003. { _map_nominal, _res_44s_3 }, /* 3 */
  128004. { _map_nominal, _res_44s_4 }, /* 4 */
  128005. { _map_nominal, _res_44s_5 }, /* 5 */
  128006. { _map_nominal, _res_44s_6 }, /* 6 */
  128007. { _map_nominal, _res_44s_7 }, /* 7 */
  128008. { _map_nominal, _res_44s_8 }, /* 8 */
  128009. { _map_nominal, _res_44s_9 }, /* 9 */
  128010. };
  128011. /*** End of inlined file: residue_44.h ***/
  128012. /*** Start of inlined file: psych_44.h ***/
  128013. static vorbis_info_psy_global _psy_global_44[5]={
  128014. {8, /* lines per eighth octave */
  128015. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  128016. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  128017. -6.f,
  128018. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128019. },
  128020. {8, /* lines per eighth octave */
  128021. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128022. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  128023. -6.f,
  128024. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128025. },
  128026. {8, /* lines per eighth octave */
  128027. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128028. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  128029. -6.f,
  128030. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128031. },
  128032. {8, /* lines per eighth octave */
  128033. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  128034. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  128035. -6.f,
  128036. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128037. },
  128038. {8, /* lines per eighth octave */
  128039. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  128040. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  128041. -6.f,
  128042. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128043. },
  128044. };
  128045. static compandblock _psy_compand_44[6]={
  128046. {{
  128047. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128048. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128049. 16,17,18,19,20,21,22, 23, /* 23dB */
  128050. 24,25,26,27,28,29,30, 31, /* 31dB */
  128051. 32,33,34,35,36,37,38, 39, /* 39dB */
  128052. }},
  128053. {{
  128054. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  128055. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  128056. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  128057. 15,16,17,17,17,18,18, 19, /* 31dB */
  128058. 19,19,20,21,22,23,24, 25, /* 39dB */
  128059. }},
  128060. {{
  128061. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  128062. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  128063. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128064. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128065. 11,12,13,14,15,16,17, 18, /* 39dB */
  128066. }},
  128067. {{
  128068. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128069. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128070. 16,17,18,19,20,21,22, 23, /* 23dB */
  128071. 24,25,26,27,28,29,30, 31, /* 31dB */
  128072. 32,33,34,35,36,37,38, 39, /* 39dB */
  128073. }},
  128074. {{
  128075. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128076. 8, 9,10,11,12,12,13, 13, /* 15dB */
  128077. 13,14,14,14,15,15,15, 15, /* 23dB */
  128078. 16,16,17,17,17,18,18, 19, /* 31dB */
  128079. 19,19,20,21,22,23,24, 25, /* 39dB */
  128080. }},
  128081. {{
  128082. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128083. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  128084. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128085. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128086. 11,12,13,14,15,16,17, 18, /* 39dB */
  128087. }}
  128088. };
  128089. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  128090. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  128091. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  128092. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  128093. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  128094. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  128095. /* 4 */
  128096. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128097. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128098. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128099. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128100. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128101. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128102. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128103. };
  128104. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  128105. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  128106. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  128107. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  128108. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  128109. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  128110. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128111. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128112. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128113. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128114. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128115. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128116. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128117. };
  128118. static noise3 _psy_noisebias_trans[12]={
  128119. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128120. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128121. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128122. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128123. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  128124. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128125. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128126. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128127. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128128. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128129. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128130. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  128131. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128132. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128133. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128134. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128135. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128136. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128137. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128138. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128139. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  128140. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128141. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128142. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128143. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128144. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  128145. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128146. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  128147. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  128148. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128149. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128150. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  128151. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  128152. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  128153. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  128154. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128155. };
  128156. static noise3 _psy_noisebias_long[12]={
  128157. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  128158. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  128159. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128160. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  128161. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  128162. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128163. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128164. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128165. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128166. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128167. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128168. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128169. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128170. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128171. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  128172. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128173. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128174. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  128175. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128176. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128177. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  128178. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128179. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128180. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  128181. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128182. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  128183. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128184. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  128185. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  128186. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128187. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128188. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  128189. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128190. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  128191. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  128192. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128193. };
  128194. static noise3 _psy_noisebias_impulse[12]={
  128195. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128196. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128197. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128198. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  128199. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  128200. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128201. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128202. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  128203. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  128204. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128205. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128206. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128207. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128208. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128209. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128210. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128211. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128212. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128213. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128214. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  128215. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  128216. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128217. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  128218. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  128219. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  128220. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  128221. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128222. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  128223. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  128224. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128225. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128226. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  128227. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128228. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  128229. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  128230. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128231. };
  128232. static noise3 _psy_noisebias_padding[12]={
  128233. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128234. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128235. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128236. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128237. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  128238. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  128239. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128240. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  128241. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  128242. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128243. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128244. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128245. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128246. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128247. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128248. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128249. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  128250. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128251. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128252. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  128253. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  128254. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128255. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  128256. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  128257. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128258. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  128259. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  128260. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  128261. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  128262. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  128263. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  128264. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  128265. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  128266. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  128267. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  128268. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128269. };
  128270. static noiseguard _psy_noiseguards_44[4]={
  128271. {3,3,15},
  128272. {3,3,15},
  128273. {10,10,100},
  128274. {10,10,100},
  128275. };
  128276. static int _psy_tone_suppress[12]={
  128277. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  128278. };
  128279. static int _psy_tone_0dB[12]={
  128280. 90,90,95,95,95,95,105,105,105,105,105,105,
  128281. };
  128282. static int _psy_noise_suppress[12]={
  128283. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128284. };
  128285. static vorbis_info_psy _psy_info_template={
  128286. -1,
  128287. -140.,-140.,
  128288. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128289. 1, -0.f, .5f, .5f, 0,0,0,
  128290. {{-1},{-1},{-1}},{-1},105.f,
  128291. 0,0,-1,-1,0.,
  128292. };
  128293. static int _psy_ath_floater[12]={
  128294. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128295. };
  128296. static int _psy_ath_abs[12]={
  128297. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128298. };
  128299. static adj_stereo _psy_stereo_modes_44[12]={
  128300. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128301. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128302. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128303. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128304. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128305. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128306. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128307. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128308. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128309. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128310. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128311. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128312. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128313. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128314. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128315. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128316. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128317. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128318. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128319. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128320. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128321. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128322. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128323. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128324. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128325. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128326. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128327. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128328. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128329. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128330. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128331. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128332. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128333. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128334. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128335. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128336. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128337. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128338. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128339. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128340. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128341. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128342. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128343. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128344. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128345. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128346. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128347. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128348. };
  128349. static att3 _psy_tone_masteratt_44[12]={
  128350. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128351. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128352. /* 1 */
  128353. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128354. /* 2 */
  128355. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128356. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128357. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128358. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128359. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128360. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128361. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128362. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128363. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128364. };
  128365. static double _psy_lowpass_44[12]={
  128366. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128367. };
  128368. static int _noise_start_short_44[11]={
  128369. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128370. };
  128371. static int _noise_start_long_44[11]={
  128372. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128373. };
  128374. static int _noise_part_short_44[11]={
  128375. 8,8,8,8,8,8,8,8,8,8,8
  128376. };
  128377. static int _noise_part_long_44[11]={
  128378. 32,32,32,32,32,32,32,32,32,32,32
  128379. };
  128380. static double _noise_thresh_44[11]={
  128381. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  128382. };
  128383. static double _noise_thresh_5only[2]={
  128384. .5,.5,
  128385. };
  128386. /*** End of inlined file: psych_44.h ***/
  128387. static double rate_mapping_44_stereo[12]={
  128388. 22500.,32000.,40000.,48000.,56000.,64000.,
  128389. 80000.,96000.,112000.,128000.,160000.,250001.
  128390. };
  128391. static double quality_mapping_44[12]={
  128392. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  128393. };
  128394. static int blocksize_short_44[11]={
  128395. 512,256,256,256,256,256,256,256,256,256,256
  128396. };
  128397. static int blocksize_long_44[11]={
  128398. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128399. };
  128400. static double _psy_compand_short_mapping[12]={
  128401. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128402. };
  128403. static double _psy_compand_long_mapping[12]={
  128404. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128405. };
  128406. static double _global_mapping_44[12]={
  128407. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128408. };
  128409. static int _floor_short_mapping_44[11]={
  128410. 1,0,0,2,2,4,5,5,5,5,5
  128411. };
  128412. static int _floor_long_mapping_44[11]={
  128413. 8,7,7,7,7,7,7,7,7,7,7
  128414. };
  128415. ve_setup_data_template ve_setup_44_stereo={
  128416. 11,
  128417. rate_mapping_44_stereo,
  128418. quality_mapping_44,
  128419. 2,
  128420. 40000,
  128421. 50000,
  128422. blocksize_short_44,
  128423. blocksize_long_44,
  128424. _psy_tone_masteratt_44,
  128425. _psy_tone_0dB,
  128426. _psy_tone_suppress,
  128427. _vp_tonemask_adj_otherblock,
  128428. _vp_tonemask_adj_longblock,
  128429. _vp_tonemask_adj_otherblock,
  128430. _psy_noiseguards_44,
  128431. _psy_noisebias_impulse,
  128432. _psy_noisebias_padding,
  128433. _psy_noisebias_trans,
  128434. _psy_noisebias_long,
  128435. _psy_noise_suppress,
  128436. _psy_compand_44,
  128437. _psy_compand_short_mapping,
  128438. _psy_compand_long_mapping,
  128439. {_noise_start_short_44,_noise_start_long_44},
  128440. {_noise_part_short_44,_noise_part_long_44},
  128441. _noise_thresh_44,
  128442. _psy_ath_floater,
  128443. _psy_ath_abs,
  128444. _psy_lowpass_44,
  128445. _psy_global_44,
  128446. _global_mapping_44,
  128447. _psy_stereo_modes_44,
  128448. _floor_books,
  128449. _floor,
  128450. _floor_short_mapping_44,
  128451. _floor_long_mapping_44,
  128452. _mapres_template_44_stereo
  128453. };
  128454. /*** End of inlined file: setup_44.h ***/
  128455. /*** Start of inlined file: setup_44u.h ***/
  128456. /*** Start of inlined file: residue_44u.h ***/
  128457. /*** Start of inlined file: res_books_uncoupled.h ***/
  128458. static long _vq_quantlist__16u0__p1_0[] = {
  128459. 1,
  128460. 0,
  128461. 2,
  128462. };
  128463. static long _vq_lengthlist__16u0__p1_0[] = {
  128464. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128465. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128466. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128467. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128468. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128469. 12,
  128470. };
  128471. static float _vq_quantthresh__16u0__p1_0[] = {
  128472. -0.5, 0.5,
  128473. };
  128474. static long _vq_quantmap__16u0__p1_0[] = {
  128475. 1, 0, 2,
  128476. };
  128477. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128478. _vq_quantthresh__16u0__p1_0,
  128479. _vq_quantmap__16u0__p1_0,
  128480. 3,
  128481. 3
  128482. };
  128483. static static_codebook _16u0__p1_0 = {
  128484. 4, 81,
  128485. _vq_lengthlist__16u0__p1_0,
  128486. 1, -535822336, 1611661312, 2, 0,
  128487. _vq_quantlist__16u0__p1_0,
  128488. NULL,
  128489. &_vq_auxt__16u0__p1_0,
  128490. NULL,
  128491. 0
  128492. };
  128493. static long _vq_quantlist__16u0__p2_0[] = {
  128494. 1,
  128495. 0,
  128496. 2,
  128497. };
  128498. static long _vq_lengthlist__16u0__p2_0[] = {
  128499. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128500. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128501. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128502. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128503. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128504. 8,
  128505. };
  128506. static float _vq_quantthresh__16u0__p2_0[] = {
  128507. -0.5, 0.5,
  128508. };
  128509. static long _vq_quantmap__16u0__p2_0[] = {
  128510. 1, 0, 2,
  128511. };
  128512. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128513. _vq_quantthresh__16u0__p2_0,
  128514. _vq_quantmap__16u0__p2_0,
  128515. 3,
  128516. 3
  128517. };
  128518. static static_codebook _16u0__p2_0 = {
  128519. 4, 81,
  128520. _vq_lengthlist__16u0__p2_0,
  128521. 1, -535822336, 1611661312, 2, 0,
  128522. _vq_quantlist__16u0__p2_0,
  128523. NULL,
  128524. &_vq_auxt__16u0__p2_0,
  128525. NULL,
  128526. 0
  128527. };
  128528. static long _vq_quantlist__16u0__p3_0[] = {
  128529. 2,
  128530. 1,
  128531. 3,
  128532. 0,
  128533. 4,
  128534. };
  128535. static long _vq_lengthlist__16u0__p3_0[] = {
  128536. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128537. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128538. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128539. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128540. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128541. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128542. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128543. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128544. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128545. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128546. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128547. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128548. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128549. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128550. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128551. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128552. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128553. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128554. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128555. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128556. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128557. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128558. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128559. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128560. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128561. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128562. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128563. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128564. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128565. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128566. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128567. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128568. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128569. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128570. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128571. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128572. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128573. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128574. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128575. 18,
  128576. };
  128577. static float _vq_quantthresh__16u0__p3_0[] = {
  128578. -1.5, -0.5, 0.5, 1.5,
  128579. };
  128580. static long _vq_quantmap__16u0__p3_0[] = {
  128581. 3, 1, 0, 2, 4,
  128582. };
  128583. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128584. _vq_quantthresh__16u0__p3_0,
  128585. _vq_quantmap__16u0__p3_0,
  128586. 5,
  128587. 5
  128588. };
  128589. static static_codebook _16u0__p3_0 = {
  128590. 4, 625,
  128591. _vq_lengthlist__16u0__p3_0,
  128592. 1, -533725184, 1611661312, 3, 0,
  128593. _vq_quantlist__16u0__p3_0,
  128594. NULL,
  128595. &_vq_auxt__16u0__p3_0,
  128596. NULL,
  128597. 0
  128598. };
  128599. static long _vq_quantlist__16u0__p4_0[] = {
  128600. 2,
  128601. 1,
  128602. 3,
  128603. 0,
  128604. 4,
  128605. };
  128606. static long _vq_lengthlist__16u0__p4_0[] = {
  128607. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128608. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128609. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128610. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128611. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128612. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128613. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128614. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128615. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128616. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128617. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128618. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128619. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128620. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128621. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128622. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128623. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128624. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128625. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128626. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128627. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128628. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128629. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128630. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128631. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128632. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128633. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128634. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128635. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128636. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128637. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128638. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128639. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128640. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128641. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128642. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128643. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128644. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128645. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128646. 11,
  128647. };
  128648. static float _vq_quantthresh__16u0__p4_0[] = {
  128649. -1.5, -0.5, 0.5, 1.5,
  128650. };
  128651. static long _vq_quantmap__16u0__p4_0[] = {
  128652. 3, 1, 0, 2, 4,
  128653. };
  128654. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128655. _vq_quantthresh__16u0__p4_0,
  128656. _vq_quantmap__16u0__p4_0,
  128657. 5,
  128658. 5
  128659. };
  128660. static static_codebook _16u0__p4_0 = {
  128661. 4, 625,
  128662. _vq_lengthlist__16u0__p4_0,
  128663. 1, -533725184, 1611661312, 3, 0,
  128664. _vq_quantlist__16u0__p4_0,
  128665. NULL,
  128666. &_vq_auxt__16u0__p4_0,
  128667. NULL,
  128668. 0
  128669. };
  128670. static long _vq_quantlist__16u0__p5_0[] = {
  128671. 4,
  128672. 3,
  128673. 5,
  128674. 2,
  128675. 6,
  128676. 1,
  128677. 7,
  128678. 0,
  128679. 8,
  128680. };
  128681. static long _vq_lengthlist__16u0__p5_0[] = {
  128682. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128683. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  128684. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  128685. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  128686. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  128687. 12,
  128688. };
  128689. static float _vq_quantthresh__16u0__p5_0[] = {
  128690. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128691. };
  128692. static long _vq_quantmap__16u0__p5_0[] = {
  128693. 7, 5, 3, 1, 0, 2, 4, 6,
  128694. 8,
  128695. };
  128696. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  128697. _vq_quantthresh__16u0__p5_0,
  128698. _vq_quantmap__16u0__p5_0,
  128699. 9,
  128700. 9
  128701. };
  128702. static static_codebook _16u0__p5_0 = {
  128703. 2, 81,
  128704. _vq_lengthlist__16u0__p5_0,
  128705. 1, -531628032, 1611661312, 4, 0,
  128706. _vq_quantlist__16u0__p5_0,
  128707. NULL,
  128708. &_vq_auxt__16u0__p5_0,
  128709. NULL,
  128710. 0
  128711. };
  128712. static long _vq_quantlist__16u0__p6_0[] = {
  128713. 6,
  128714. 5,
  128715. 7,
  128716. 4,
  128717. 8,
  128718. 3,
  128719. 9,
  128720. 2,
  128721. 10,
  128722. 1,
  128723. 11,
  128724. 0,
  128725. 12,
  128726. };
  128727. static long _vq_lengthlist__16u0__p6_0[] = {
  128728. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  128729. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  128730. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  128731. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  128732. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  128733. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  128734. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  128735. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  128736. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  128737. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  128738. 18, 0,19, 0, 0, 0, 0, 0, 0,
  128739. };
  128740. static float _vq_quantthresh__16u0__p6_0[] = {
  128741. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  128742. 12.5, 17.5, 22.5, 27.5,
  128743. };
  128744. static long _vq_quantmap__16u0__p6_0[] = {
  128745. 11, 9, 7, 5, 3, 1, 0, 2,
  128746. 4, 6, 8, 10, 12,
  128747. };
  128748. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  128749. _vq_quantthresh__16u0__p6_0,
  128750. _vq_quantmap__16u0__p6_0,
  128751. 13,
  128752. 13
  128753. };
  128754. static static_codebook _16u0__p6_0 = {
  128755. 2, 169,
  128756. _vq_lengthlist__16u0__p6_0,
  128757. 1, -526516224, 1616117760, 4, 0,
  128758. _vq_quantlist__16u0__p6_0,
  128759. NULL,
  128760. &_vq_auxt__16u0__p6_0,
  128761. NULL,
  128762. 0
  128763. };
  128764. static long _vq_quantlist__16u0__p6_1[] = {
  128765. 2,
  128766. 1,
  128767. 3,
  128768. 0,
  128769. 4,
  128770. };
  128771. static long _vq_lengthlist__16u0__p6_1[] = {
  128772. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  128773. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  128774. };
  128775. static float _vq_quantthresh__16u0__p6_1[] = {
  128776. -1.5, -0.5, 0.5, 1.5,
  128777. };
  128778. static long _vq_quantmap__16u0__p6_1[] = {
  128779. 3, 1, 0, 2, 4,
  128780. };
  128781. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  128782. _vq_quantthresh__16u0__p6_1,
  128783. _vq_quantmap__16u0__p6_1,
  128784. 5,
  128785. 5
  128786. };
  128787. static static_codebook _16u0__p6_1 = {
  128788. 2, 25,
  128789. _vq_lengthlist__16u0__p6_1,
  128790. 1, -533725184, 1611661312, 3, 0,
  128791. _vq_quantlist__16u0__p6_1,
  128792. NULL,
  128793. &_vq_auxt__16u0__p6_1,
  128794. NULL,
  128795. 0
  128796. };
  128797. static long _vq_quantlist__16u0__p7_0[] = {
  128798. 1,
  128799. 0,
  128800. 2,
  128801. };
  128802. static long _vq_lengthlist__16u0__p7_0[] = {
  128803. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128804. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128805. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128806. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128807. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128808. 7,
  128809. };
  128810. static float _vq_quantthresh__16u0__p7_0[] = {
  128811. -157.5, 157.5,
  128812. };
  128813. static long _vq_quantmap__16u0__p7_0[] = {
  128814. 1, 0, 2,
  128815. };
  128816. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  128817. _vq_quantthresh__16u0__p7_0,
  128818. _vq_quantmap__16u0__p7_0,
  128819. 3,
  128820. 3
  128821. };
  128822. static static_codebook _16u0__p7_0 = {
  128823. 4, 81,
  128824. _vq_lengthlist__16u0__p7_0,
  128825. 1, -518803456, 1628680192, 2, 0,
  128826. _vq_quantlist__16u0__p7_0,
  128827. NULL,
  128828. &_vq_auxt__16u0__p7_0,
  128829. NULL,
  128830. 0
  128831. };
  128832. static long _vq_quantlist__16u0__p7_1[] = {
  128833. 7,
  128834. 6,
  128835. 8,
  128836. 5,
  128837. 9,
  128838. 4,
  128839. 10,
  128840. 3,
  128841. 11,
  128842. 2,
  128843. 12,
  128844. 1,
  128845. 13,
  128846. 0,
  128847. 14,
  128848. };
  128849. static long _vq_lengthlist__16u0__p7_1[] = {
  128850. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  128851. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  128852. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  128853. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  128854. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  128855. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  128856. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128857. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128858. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128859. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128860. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128861. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128862. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128863. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128864. 10,
  128865. };
  128866. static float _vq_quantthresh__16u0__p7_1[] = {
  128867. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  128868. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  128869. };
  128870. static long _vq_quantmap__16u0__p7_1[] = {
  128871. 13, 11, 9, 7, 5, 3, 1, 0,
  128872. 2, 4, 6, 8, 10, 12, 14,
  128873. };
  128874. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  128875. _vq_quantthresh__16u0__p7_1,
  128876. _vq_quantmap__16u0__p7_1,
  128877. 15,
  128878. 15
  128879. };
  128880. static static_codebook _16u0__p7_1 = {
  128881. 2, 225,
  128882. _vq_lengthlist__16u0__p7_1,
  128883. 1, -520986624, 1620377600, 4, 0,
  128884. _vq_quantlist__16u0__p7_1,
  128885. NULL,
  128886. &_vq_auxt__16u0__p7_1,
  128887. NULL,
  128888. 0
  128889. };
  128890. static long _vq_quantlist__16u0__p7_2[] = {
  128891. 10,
  128892. 9,
  128893. 11,
  128894. 8,
  128895. 12,
  128896. 7,
  128897. 13,
  128898. 6,
  128899. 14,
  128900. 5,
  128901. 15,
  128902. 4,
  128903. 16,
  128904. 3,
  128905. 17,
  128906. 2,
  128907. 18,
  128908. 1,
  128909. 19,
  128910. 0,
  128911. 20,
  128912. };
  128913. static long _vq_lengthlist__16u0__p7_2[] = {
  128914. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  128915. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  128916. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  128917. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  128918. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  128919. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  128920. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  128921. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  128922. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  128923. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  128924. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  128925. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  128926. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  128927. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  128928. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  128929. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  128930. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  128931. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  128932. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  128933. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  128934. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  128935. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  128936. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  128937. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  128938. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  128939. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  128940. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  128941. 10,10,12,11,10,11,11,11,10,
  128942. };
  128943. static float _vq_quantthresh__16u0__p7_2[] = {
  128944. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  128945. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  128946. 6.5, 7.5, 8.5, 9.5,
  128947. };
  128948. static long _vq_quantmap__16u0__p7_2[] = {
  128949. 19, 17, 15, 13, 11, 9, 7, 5,
  128950. 3, 1, 0, 2, 4, 6, 8, 10,
  128951. 12, 14, 16, 18, 20,
  128952. };
  128953. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  128954. _vq_quantthresh__16u0__p7_2,
  128955. _vq_quantmap__16u0__p7_2,
  128956. 21,
  128957. 21
  128958. };
  128959. static static_codebook _16u0__p7_2 = {
  128960. 2, 441,
  128961. _vq_lengthlist__16u0__p7_2,
  128962. 1, -529268736, 1611661312, 5, 0,
  128963. _vq_quantlist__16u0__p7_2,
  128964. NULL,
  128965. &_vq_auxt__16u0__p7_2,
  128966. NULL,
  128967. 0
  128968. };
  128969. static long _huff_lengthlist__16u0__single[] = {
  128970. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  128971. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  128972. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  128973. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  128974. };
  128975. static static_codebook _huff_book__16u0__single = {
  128976. 2, 64,
  128977. _huff_lengthlist__16u0__single,
  128978. 0, 0, 0, 0, 0,
  128979. NULL,
  128980. NULL,
  128981. NULL,
  128982. NULL,
  128983. 0
  128984. };
  128985. static long _huff_lengthlist__16u1__long[] = {
  128986. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  128987. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  128988. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  128989. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  128990. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  128991. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  128992. 16,13,16,18,
  128993. };
  128994. static static_codebook _huff_book__16u1__long = {
  128995. 2, 100,
  128996. _huff_lengthlist__16u1__long,
  128997. 0, 0, 0, 0, 0,
  128998. NULL,
  128999. NULL,
  129000. NULL,
  129001. NULL,
  129002. 0
  129003. };
  129004. static long _vq_quantlist__16u1__p1_0[] = {
  129005. 1,
  129006. 0,
  129007. 2,
  129008. };
  129009. static long _vq_lengthlist__16u1__p1_0[] = {
  129010. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  129011. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  129012. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  129013. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  129014. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  129015. 11,
  129016. };
  129017. static float _vq_quantthresh__16u1__p1_0[] = {
  129018. -0.5, 0.5,
  129019. };
  129020. static long _vq_quantmap__16u1__p1_0[] = {
  129021. 1, 0, 2,
  129022. };
  129023. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  129024. _vq_quantthresh__16u1__p1_0,
  129025. _vq_quantmap__16u1__p1_0,
  129026. 3,
  129027. 3
  129028. };
  129029. static static_codebook _16u1__p1_0 = {
  129030. 4, 81,
  129031. _vq_lengthlist__16u1__p1_0,
  129032. 1, -535822336, 1611661312, 2, 0,
  129033. _vq_quantlist__16u1__p1_0,
  129034. NULL,
  129035. &_vq_auxt__16u1__p1_0,
  129036. NULL,
  129037. 0
  129038. };
  129039. static long _vq_quantlist__16u1__p2_0[] = {
  129040. 1,
  129041. 0,
  129042. 2,
  129043. };
  129044. static long _vq_lengthlist__16u1__p2_0[] = {
  129045. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  129046. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  129047. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  129048. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  129049. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  129050. 8,
  129051. };
  129052. static float _vq_quantthresh__16u1__p2_0[] = {
  129053. -0.5, 0.5,
  129054. };
  129055. static long _vq_quantmap__16u1__p2_0[] = {
  129056. 1, 0, 2,
  129057. };
  129058. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  129059. _vq_quantthresh__16u1__p2_0,
  129060. _vq_quantmap__16u1__p2_0,
  129061. 3,
  129062. 3
  129063. };
  129064. static static_codebook _16u1__p2_0 = {
  129065. 4, 81,
  129066. _vq_lengthlist__16u1__p2_0,
  129067. 1, -535822336, 1611661312, 2, 0,
  129068. _vq_quantlist__16u1__p2_0,
  129069. NULL,
  129070. &_vq_auxt__16u1__p2_0,
  129071. NULL,
  129072. 0
  129073. };
  129074. static long _vq_quantlist__16u1__p3_0[] = {
  129075. 2,
  129076. 1,
  129077. 3,
  129078. 0,
  129079. 4,
  129080. };
  129081. static long _vq_lengthlist__16u1__p3_0[] = {
  129082. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129083. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  129084. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  129085. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  129086. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  129087. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  129088. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  129089. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  129090. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  129091. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  129092. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  129093. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  129094. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  129095. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  129096. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  129097. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  129098. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  129099. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  129100. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  129101. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  129102. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  129103. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  129104. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  129105. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  129106. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  129107. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  129108. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  129109. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  129110. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  129111. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  129112. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  129113. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  129114. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  129115. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  129116. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  129117. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  129118. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  129119. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  129120. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  129121. 16,
  129122. };
  129123. static float _vq_quantthresh__16u1__p3_0[] = {
  129124. -1.5, -0.5, 0.5, 1.5,
  129125. };
  129126. static long _vq_quantmap__16u1__p3_0[] = {
  129127. 3, 1, 0, 2, 4,
  129128. };
  129129. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  129130. _vq_quantthresh__16u1__p3_0,
  129131. _vq_quantmap__16u1__p3_0,
  129132. 5,
  129133. 5
  129134. };
  129135. static static_codebook _16u1__p3_0 = {
  129136. 4, 625,
  129137. _vq_lengthlist__16u1__p3_0,
  129138. 1, -533725184, 1611661312, 3, 0,
  129139. _vq_quantlist__16u1__p3_0,
  129140. NULL,
  129141. &_vq_auxt__16u1__p3_0,
  129142. NULL,
  129143. 0
  129144. };
  129145. static long _vq_quantlist__16u1__p4_0[] = {
  129146. 2,
  129147. 1,
  129148. 3,
  129149. 0,
  129150. 4,
  129151. };
  129152. static long _vq_lengthlist__16u1__p4_0[] = {
  129153. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  129154. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  129155. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  129156. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  129157. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  129158. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  129159. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  129160. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  129161. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  129162. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  129163. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  129164. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  129165. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  129166. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  129167. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  129168. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  129169. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  129170. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  129171. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  129172. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  129173. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  129174. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  129175. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  129176. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  129177. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  129178. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  129179. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  129180. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  129181. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  129182. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  129183. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  129184. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  129185. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  129186. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  129187. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  129188. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  129189. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  129190. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  129191. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  129192. 11,
  129193. };
  129194. static float _vq_quantthresh__16u1__p4_0[] = {
  129195. -1.5, -0.5, 0.5, 1.5,
  129196. };
  129197. static long _vq_quantmap__16u1__p4_0[] = {
  129198. 3, 1, 0, 2, 4,
  129199. };
  129200. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  129201. _vq_quantthresh__16u1__p4_0,
  129202. _vq_quantmap__16u1__p4_0,
  129203. 5,
  129204. 5
  129205. };
  129206. static static_codebook _16u1__p4_0 = {
  129207. 4, 625,
  129208. _vq_lengthlist__16u1__p4_0,
  129209. 1, -533725184, 1611661312, 3, 0,
  129210. _vq_quantlist__16u1__p4_0,
  129211. NULL,
  129212. &_vq_auxt__16u1__p4_0,
  129213. NULL,
  129214. 0
  129215. };
  129216. static long _vq_quantlist__16u1__p5_0[] = {
  129217. 4,
  129218. 3,
  129219. 5,
  129220. 2,
  129221. 6,
  129222. 1,
  129223. 7,
  129224. 0,
  129225. 8,
  129226. };
  129227. static long _vq_lengthlist__16u1__p5_0[] = {
  129228. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129229. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  129230. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  129231. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  129232. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  129233. 13,
  129234. };
  129235. static float _vq_quantthresh__16u1__p5_0[] = {
  129236. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129237. };
  129238. static long _vq_quantmap__16u1__p5_0[] = {
  129239. 7, 5, 3, 1, 0, 2, 4, 6,
  129240. 8,
  129241. };
  129242. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  129243. _vq_quantthresh__16u1__p5_0,
  129244. _vq_quantmap__16u1__p5_0,
  129245. 9,
  129246. 9
  129247. };
  129248. static static_codebook _16u1__p5_0 = {
  129249. 2, 81,
  129250. _vq_lengthlist__16u1__p5_0,
  129251. 1, -531628032, 1611661312, 4, 0,
  129252. _vq_quantlist__16u1__p5_0,
  129253. NULL,
  129254. &_vq_auxt__16u1__p5_0,
  129255. NULL,
  129256. 0
  129257. };
  129258. static long _vq_quantlist__16u1__p6_0[] = {
  129259. 4,
  129260. 3,
  129261. 5,
  129262. 2,
  129263. 6,
  129264. 1,
  129265. 7,
  129266. 0,
  129267. 8,
  129268. };
  129269. static long _vq_lengthlist__16u1__p6_0[] = {
  129270. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  129271. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  129272. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129273. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129274. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129275. 11,
  129276. };
  129277. static float _vq_quantthresh__16u1__p6_0[] = {
  129278. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129279. };
  129280. static long _vq_quantmap__16u1__p6_0[] = {
  129281. 7, 5, 3, 1, 0, 2, 4, 6,
  129282. 8,
  129283. };
  129284. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129285. _vq_quantthresh__16u1__p6_0,
  129286. _vq_quantmap__16u1__p6_0,
  129287. 9,
  129288. 9
  129289. };
  129290. static static_codebook _16u1__p6_0 = {
  129291. 2, 81,
  129292. _vq_lengthlist__16u1__p6_0,
  129293. 1, -531628032, 1611661312, 4, 0,
  129294. _vq_quantlist__16u1__p6_0,
  129295. NULL,
  129296. &_vq_auxt__16u1__p6_0,
  129297. NULL,
  129298. 0
  129299. };
  129300. static long _vq_quantlist__16u1__p7_0[] = {
  129301. 1,
  129302. 0,
  129303. 2,
  129304. };
  129305. static long _vq_lengthlist__16u1__p7_0[] = {
  129306. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129307. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129308. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129309. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129310. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129311. 13,
  129312. };
  129313. static float _vq_quantthresh__16u1__p7_0[] = {
  129314. -5.5, 5.5,
  129315. };
  129316. static long _vq_quantmap__16u1__p7_0[] = {
  129317. 1, 0, 2,
  129318. };
  129319. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129320. _vq_quantthresh__16u1__p7_0,
  129321. _vq_quantmap__16u1__p7_0,
  129322. 3,
  129323. 3
  129324. };
  129325. static static_codebook _16u1__p7_0 = {
  129326. 4, 81,
  129327. _vq_lengthlist__16u1__p7_0,
  129328. 1, -529137664, 1618345984, 2, 0,
  129329. _vq_quantlist__16u1__p7_0,
  129330. NULL,
  129331. &_vq_auxt__16u1__p7_0,
  129332. NULL,
  129333. 0
  129334. };
  129335. static long _vq_quantlist__16u1__p7_1[] = {
  129336. 5,
  129337. 4,
  129338. 6,
  129339. 3,
  129340. 7,
  129341. 2,
  129342. 8,
  129343. 1,
  129344. 9,
  129345. 0,
  129346. 10,
  129347. };
  129348. static long _vq_lengthlist__16u1__p7_1[] = {
  129349. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129350. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129351. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129352. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129353. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129354. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129355. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129356. 8, 9, 9,10,10,10,10,10,10,
  129357. };
  129358. static float _vq_quantthresh__16u1__p7_1[] = {
  129359. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129360. 3.5, 4.5,
  129361. };
  129362. static long _vq_quantmap__16u1__p7_1[] = {
  129363. 9, 7, 5, 3, 1, 0, 2, 4,
  129364. 6, 8, 10,
  129365. };
  129366. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129367. _vq_quantthresh__16u1__p7_1,
  129368. _vq_quantmap__16u1__p7_1,
  129369. 11,
  129370. 11
  129371. };
  129372. static static_codebook _16u1__p7_1 = {
  129373. 2, 121,
  129374. _vq_lengthlist__16u1__p7_1,
  129375. 1, -531365888, 1611661312, 4, 0,
  129376. _vq_quantlist__16u1__p7_1,
  129377. NULL,
  129378. &_vq_auxt__16u1__p7_1,
  129379. NULL,
  129380. 0
  129381. };
  129382. static long _vq_quantlist__16u1__p8_0[] = {
  129383. 5,
  129384. 4,
  129385. 6,
  129386. 3,
  129387. 7,
  129388. 2,
  129389. 8,
  129390. 1,
  129391. 9,
  129392. 0,
  129393. 10,
  129394. };
  129395. static long _vq_lengthlist__16u1__p8_0[] = {
  129396. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129397. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129398. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129399. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129400. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129401. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129402. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129403. 13,14,14,15,15,16,16,15,16,
  129404. };
  129405. static float _vq_quantthresh__16u1__p8_0[] = {
  129406. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129407. 38.5, 49.5,
  129408. };
  129409. static long _vq_quantmap__16u1__p8_0[] = {
  129410. 9, 7, 5, 3, 1, 0, 2, 4,
  129411. 6, 8, 10,
  129412. };
  129413. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129414. _vq_quantthresh__16u1__p8_0,
  129415. _vq_quantmap__16u1__p8_0,
  129416. 11,
  129417. 11
  129418. };
  129419. static static_codebook _16u1__p8_0 = {
  129420. 2, 121,
  129421. _vq_lengthlist__16u1__p8_0,
  129422. 1, -524582912, 1618345984, 4, 0,
  129423. _vq_quantlist__16u1__p8_0,
  129424. NULL,
  129425. &_vq_auxt__16u1__p8_0,
  129426. NULL,
  129427. 0
  129428. };
  129429. static long _vq_quantlist__16u1__p8_1[] = {
  129430. 5,
  129431. 4,
  129432. 6,
  129433. 3,
  129434. 7,
  129435. 2,
  129436. 8,
  129437. 1,
  129438. 9,
  129439. 0,
  129440. 10,
  129441. };
  129442. static long _vq_lengthlist__16u1__p8_1[] = {
  129443. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129444. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129445. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129446. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129447. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129448. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129449. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129450. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129451. };
  129452. static float _vq_quantthresh__16u1__p8_1[] = {
  129453. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129454. 3.5, 4.5,
  129455. };
  129456. static long _vq_quantmap__16u1__p8_1[] = {
  129457. 9, 7, 5, 3, 1, 0, 2, 4,
  129458. 6, 8, 10,
  129459. };
  129460. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129461. _vq_quantthresh__16u1__p8_1,
  129462. _vq_quantmap__16u1__p8_1,
  129463. 11,
  129464. 11
  129465. };
  129466. static static_codebook _16u1__p8_1 = {
  129467. 2, 121,
  129468. _vq_lengthlist__16u1__p8_1,
  129469. 1, -531365888, 1611661312, 4, 0,
  129470. _vq_quantlist__16u1__p8_1,
  129471. NULL,
  129472. &_vq_auxt__16u1__p8_1,
  129473. NULL,
  129474. 0
  129475. };
  129476. static long _vq_quantlist__16u1__p9_0[] = {
  129477. 7,
  129478. 6,
  129479. 8,
  129480. 5,
  129481. 9,
  129482. 4,
  129483. 10,
  129484. 3,
  129485. 11,
  129486. 2,
  129487. 12,
  129488. 1,
  129489. 13,
  129490. 0,
  129491. 14,
  129492. };
  129493. static long _vq_lengthlist__16u1__p9_0[] = {
  129494. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129495. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129496. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129497. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129498. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129499. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129500. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129501. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129502. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129503. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129504. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129505. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129506. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129507. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129508. 8,
  129509. };
  129510. static float _vq_quantthresh__16u1__p9_0[] = {
  129511. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129512. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129513. };
  129514. static long _vq_quantmap__16u1__p9_0[] = {
  129515. 13, 11, 9, 7, 5, 3, 1, 0,
  129516. 2, 4, 6, 8, 10, 12, 14,
  129517. };
  129518. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129519. _vq_quantthresh__16u1__p9_0,
  129520. _vq_quantmap__16u1__p9_0,
  129521. 15,
  129522. 15
  129523. };
  129524. static static_codebook _16u1__p9_0 = {
  129525. 2, 225,
  129526. _vq_lengthlist__16u1__p9_0,
  129527. 1, -514071552, 1627381760, 4, 0,
  129528. _vq_quantlist__16u1__p9_0,
  129529. NULL,
  129530. &_vq_auxt__16u1__p9_0,
  129531. NULL,
  129532. 0
  129533. };
  129534. static long _vq_quantlist__16u1__p9_1[] = {
  129535. 7,
  129536. 6,
  129537. 8,
  129538. 5,
  129539. 9,
  129540. 4,
  129541. 10,
  129542. 3,
  129543. 11,
  129544. 2,
  129545. 12,
  129546. 1,
  129547. 13,
  129548. 0,
  129549. 14,
  129550. };
  129551. static long _vq_lengthlist__16u1__p9_1[] = {
  129552. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129553. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129554. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129555. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129556. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129557. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129558. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129559. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129560. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129561. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129562. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  129563. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129564. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129565. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129566. 9,
  129567. };
  129568. static float _vq_quantthresh__16u1__p9_1[] = {
  129569. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129570. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129571. };
  129572. static long _vq_quantmap__16u1__p9_1[] = {
  129573. 13, 11, 9, 7, 5, 3, 1, 0,
  129574. 2, 4, 6, 8, 10, 12, 14,
  129575. };
  129576. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129577. _vq_quantthresh__16u1__p9_1,
  129578. _vq_quantmap__16u1__p9_1,
  129579. 15,
  129580. 15
  129581. };
  129582. static static_codebook _16u1__p9_1 = {
  129583. 2, 225,
  129584. _vq_lengthlist__16u1__p9_1,
  129585. 1, -522338304, 1620115456, 4, 0,
  129586. _vq_quantlist__16u1__p9_1,
  129587. NULL,
  129588. &_vq_auxt__16u1__p9_1,
  129589. NULL,
  129590. 0
  129591. };
  129592. static long _vq_quantlist__16u1__p9_2[] = {
  129593. 8,
  129594. 7,
  129595. 9,
  129596. 6,
  129597. 10,
  129598. 5,
  129599. 11,
  129600. 4,
  129601. 12,
  129602. 3,
  129603. 13,
  129604. 2,
  129605. 14,
  129606. 1,
  129607. 15,
  129608. 0,
  129609. 16,
  129610. };
  129611. static long _vq_lengthlist__16u1__p9_2[] = {
  129612. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129613. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129614. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129615. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129616. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129617. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129618. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129619. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129620. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129621. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129622. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129623. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129624. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129625. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129626. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129627. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129628. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129629. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129630. 10,
  129631. };
  129632. static float _vq_quantthresh__16u1__p9_2[] = {
  129633. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129634. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129635. };
  129636. static long _vq_quantmap__16u1__p9_2[] = {
  129637. 15, 13, 11, 9, 7, 5, 3, 1,
  129638. 0, 2, 4, 6, 8, 10, 12, 14,
  129639. 16,
  129640. };
  129641. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129642. _vq_quantthresh__16u1__p9_2,
  129643. _vq_quantmap__16u1__p9_2,
  129644. 17,
  129645. 17
  129646. };
  129647. static static_codebook _16u1__p9_2 = {
  129648. 2, 289,
  129649. _vq_lengthlist__16u1__p9_2,
  129650. 1, -529530880, 1611661312, 5, 0,
  129651. _vq_quantlist__16u1__p9_2,
  129652. NULL,
  129653. &_vq_auxt__16u1__p9_2,
  129654. NULL,
  129655. 0
  129656. };
  129657. static long _huff_lengthlist__16u1__short[] = {
  129658. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129659. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129660. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129661. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129662. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129663. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129664. 16,16,16,16,
  129665. };
  129666. static static_codebook _huff_book__16u1__short = {
  129667. 2, 100,
  129668. _huff_lengthlist__16u1__short,
  129669. 0, 0, 0, 0, 0,
  129670. NULL,
  129671. NULL,
  129672. NULL,
  129673. NULL,
  129674. 0
  129675. };
  129676. static long _huff_lengthlist__16u2__long[] = {
  129677. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  129678. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  129679. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  129680. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  129681. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  129682. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  129683. 13,14,18,18,
  129684. };
  129685. static static_codebook _huff_book__16u2__long = {
  129686. 2, 100,
  129687. _huff_lengthlist__16u2__long,
  129688. 0, 0, 0, 0, 0,
  129689. NULL,
  129690. NULL,
  129691. NULL,
  129692. NULL,
  129693. 0
  129694. };
  129695. static long _huff_lengthlist__16u2__short[] = {
  129696. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  129697. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  129698. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  129699. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  129700. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  129701. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  129702. 16,16,16,16,
  129703. };
  129704. static static_codebook _huff_book__16u2__short = {
  129705. 2, 100,
  129706. _huff_lengthlist__16u2__short,
  129707. 0, 0, 0, 0, 0,
  129708. NULL,
  129709. NULL,
  129710. NULL,
  129711. NULL,
  129712. 0
  129713. };
  129714. static long _vq_quantlist__16u2_p1_0[] = {
  129715. 1,
  129716. 0,
  129717. 2,
  129718. };
  129719. static long _vq_lengthlist__16u2_p1_0[] = {
  129720. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  129721. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  129722. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  129723. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  129724. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  129725. 10,
  129726. };
  129727. static float _vq_quantthresh__16u2_p1_0[] = {
  129728. -0.5, 0.5,
  129729. };
  129730. static long _vq_quantmap__16u2_p1_0[] = {
  129731. 1, 0, 2,
  129732. };
  129733. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  129734. _vq_quantthresh__16u2_p1_0,
  129735. _vq_quantmap__16u2_p1_0,
  129736. 3,
  129737. 3
  129738. };
  129739. static static_codebook _16u2_p1_0 = {
  129740. 4, 81,
  129741. _vq_lengthlist__16u2_p1_0,
  129742. 1, -535822336, 1611661312, 2, 0,
  129743. _vq_quantlist__16u2_p1_0,
  129744. NULL,
  129745. &_vq_auxt__16u2_p1_0,
  129746. NULL,
  129747. 0
  129748. };
  129749. static long _vq_quantlist__16u2_p2_0[] = {
  129750. 2,
  129751. 1,
  129752. 3,
  129753. 0,
  129754. 4,
  129755. };
  129756. static long _vq_lengthlist__16u2_p2_0[] = {
  129757. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129758. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  129759. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  129760. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  129761. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  129762. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  129763. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  129764. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  129765. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  129766. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  129767. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  129768. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  129769. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  129770. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  129771. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  129772. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  129773. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  129774. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  129775. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  129776. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  129777. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  129778. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  129779. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  129780. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  129781. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  129782. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  129783. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  129784. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  129785. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  129786. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  129787. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  129788. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  129789. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  129790. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  129791. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  129792. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  129793. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  129794. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  129795. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  129796. 13,
  129797. };
  129798. static float _vq_quantthresh__16u2_p2_0[] = {
  129799. -1.5, -0.5, 0.5, 1.5,
  129800. };
  129801. static long _vq_quantmap__16u2_p2_0[] = {
  129802. 3, 1, 0, 2, 4,
  129803. };
  129804. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  129805. _vq_quantthresh__16u2_p2_0,
  129806. _vq_quantmap__16u2_p2_0,
  129807. 5,
  129808. 5
  129809. };
  129810. static static_codebook _16u2_p2_0 = {
  129811. 4, 625,
  129812. _vq_lengthlist__16u2_p2_0,
  129813. 1, -533725184, 1611661312, 3, 0,
  129814. _vq_quantlist__16u2_p2_0,
  129815. NULL,
  129816. &_vq_auxt__16u2_p2_0,
  129817. NULL,
  129818. 0
  129819. };
  129820. static long _vq_quantlist__16u2_p3_0[] = {
  129821. 4,
  129822. 3,
  129823. 5,
  129824. 2,
  129825. 6,
  129826. 1,
  129827. 7,
  129828. 0,
  129829. 8,
  129830. };
  129831. static long _vq_lengthlist__16u2_p3_0[] = {
  129832. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  129833. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  129834. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129835. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129836. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129837. 11,
  129838. };
  129839. static float _vq_quantthresh__16u2_p3_0[] = {
  129840. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129841. };
  129842. static long _vq_quantmap__16u2_p3_0[] = {
  129843. 7, 5, 3, 1, 0, 2, 4, 6,
  129844. 8,
  129845. };
  129846. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  129847. _vq_quantthresh__16u2_p3_0,
  129848. _vq_quantmap__16u2_p3_0,
  129849. 9,
  129850. 9
  129851. };
  129852. static static_codebook _16u2_p3_0 = {
  129853. 2, 81,
  129854. _vq_lengthlist__16u2_p3_0,
  129855. 1, -531628032, 1611661312, 4, 0,
  129856. _vq_quantlist__16u2_p3_0,
  129857. NULL,
  129858. &_vq_auxt__16u2_p3_0,
  129859. NULL,
  129860. 0
  129861. };
  129862. static long _vq_quantlist__16u2_p4_0[] = {
  129863. 8,
  129864. 7,
  129865. 9,
  129866. 6,
  129867. 10,
  129868. 5,
  129869. 11,
  129870. 4,
  129871. 12,
  129872. 3,
  129873. 13,
  129874. 2,
  129875. 14,
  129876. 1,
  129877. 15,
  129878. 0,
  129879. 16,
  129880. };
  129881. static long _vq_lengthlist__16u2_p4_0[] = {
  129882. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  129883. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  129884. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  129885. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  129886. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  129887. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  129888. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  129889. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  129890. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  129891. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  129892. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  129893. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  129894. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  129895. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  129896. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  129897. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  129898. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  129899. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  129900. 14,
  129901. };
  129902. static float _vq_quantthresh__16u2_p4_0[] = {
  129903. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129904. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129905. };
  129906. static long _vq_quantmap__16u2_p4_0[] = {
  129907. 15, 13, 11, 9, 7, 5, 3, 1,
  129908. 0, 2, 4, 6, 8, 10, 12, 14,
  129909. 16,
  129910. };
  129911. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  129912. _vq_quantthresh__16u2_p4_0,
  129913. _vq_quantmap__16u2_p4_0,
  129914. 17,
  129915. 17
  129916. };
  129917. static static_codebook _16u2_p4_0 = {
  129918. 2, 289,
  129919. _vq_lengthlist__16u2_p4_0,
  129920. 1, -529530880, 1611661312, 5, 0,
  129921. _vq_quantlist__16u2_p4_0,
  129922. NULL,
  129923. &_vq_auxt__16u2_p4_0,
  129924. NULL,
  129925. 0
  129926. };
  129927. static long _vq_quantlist__16u2_p5_0[] = {
  129928. 1,
  129929. 0,
  129930. 2,
  129931. };
  129932. static long _vq_lengthlist__16u2_p5_0[] = {
  129933. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  129934. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  129935. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  129936. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  129937. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  129938. 10,
  129939. };
  129940. static float _vq_quantthresh__16u2_p5_0[] = {
  129941. -5.5, 5.5,
  129942. };
  129943. static long _vq_quantmap__16u2_p5_0[] = {
  129944. 1, 0, 2,
  129945. };
  129946. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  129947. _vq_quantthresh__16u2_p5_0,
  129948. _vq_quantmap__16u2_p5_0,
  129949. 3,
  129950. 3
  129951. };
  129952. static static_codebook _16u2_p5_0 = {
  129953. 4, 81,
  129954. _vq_lengthlist__16u2_p5_0,
  129955. 1, -529137664, 1618345984, 2, 0,
  129956. _vq_quantlist__16u2_p5_0,
  129957. NULL,
  129958. &_vq_auxt__16u2_p5_0,
  129959. NULL,
  129960. 0
  129961. };
  129962. static long _vq_quantlist__16u2_p5_1[] = {
  129963. 5,
  129964. 4,
  129965. 6,
  129966. 3,
  129967. 7,
  129968. 2,
  129969. 8,
  129970. 1,
  129971. 9,
  129972. 0,
  129973. 10,
  129974. };
  129975. static long _vq_lengthlist__16u2_p5_1[] = {
  129976. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  129977. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  129978. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  129979. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129980. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129981. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129982. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129983. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  129984. };
  129985. static float _vq_quantthresh__16u2_p5_1[] = {
  129986. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129987. 3.5, 4.5,
  129988. };
  129989. static long _vq_quantmap__16u2_p5_1[] = {
  129990. 9, 7, 5, 3, 1, 0, 2, 4,
  129991. 6, 8, 10,
  129992. };
  129993. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  129994. _vq_quantthresh__16u2_p5_1,
  129995. _vq_quantmap__16u2_p5_1,
  129996. 11,
  129997. 11
  129998. };
  129999. static static_codebook _16u2_p5_1 = {
  130000. 2, 121,
  130001. _vq_lengthlist__16u2_p5_1,
  130002. 1, -531365888, 1611661312, 4, 0,
  130003. _vq_quantlist__16u2_p5_1,
  130004. NULL,
  130005. &_vq_auxt__16u2_p5_1,
  130006. NULL,
  130007. 0
  130008. };
  130009. static long _vq_quantlist__16u2_p6_0[] = {
  130010. 6,
  130011. 5,
  130012. 7,
  130013. 4,
  130014. 8,
  130015. 3,
  130016. 9,
  130017. 2,
  130018. 10,
  130019. 1,
  130020. 11,
  130021. 0,
  130022. 12,
  130023. };
  130024. static long _vq_lengthlist__16u2_p6_0[] = {
  130025. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  130026. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  130027. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  130028. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  130029. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  130030. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  130031. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  130032. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  130033. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  130034. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  130035. 12,13,13,14,14,14,14,15,15,
  130036. };
  130037. static float _vq_quantthresh__16u2_p6_0[] = {
  130038. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130039. 12.5, 17.5, 22.5, 27.5,
  130040. };
  130041. static long _vq_quantmap__16u2_p6_0[] = {
  130042. 11, 9, 7, 5, 3, 1, 0, 2,
  130043. 4, 6, 8, 10, 12,
  130044. };
  130045. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  130046. _vq_quantthresh__16u2_p6_0,
  130047. _vq_quantmap__16u2_p6_0,
  130048. 13,
  130049. 13
  130050. };
  130051. static static_codebook _16u2_p6_0 = {
  130052. 2, 169,
  130053. _vq_lengthlist__16u2_p6_0,
  130054. 1, -526516224, 1616117760, 4, 0,
  130055. _vq_quantlist__16u2_p6_0,
  130056. NULL,
  130057. &_vq_auxt__16u2_p6_0,
  130058. NULL,
  130059. 0
  130060. };
  130061. static long _vq_quantlist__16u2_p6_1[] = {
  130062. 2,
  130063. 1,
  130064. 3,
  130065. 0,
  130066. 4,
  130067. };
  130068. static long _vq_lengthlist__16u2_p6_1[] = {
  130069. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  130070. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  130071. };
  130072. static float _vq_quantthresh__16u2_p6_1[] = {
  130073. -1.5, -0.5, 0.5, 1.5,
  130074. };
  130075. static long _vq_quantmap__16u2_p6_1[] = {
  130076. 3, 1, 0, 2, 4,
  130077. };
  130078. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  130079. _vq_quantthresh__16u2_p6_1,
  130080. _vq_quantmap__16u2_p6_1,
  130081. 5,
  130082. 5
  130083. };
  130084. static static_codebook _16u2_p6_1 = {
  130085. 2, 25,
  130086. _vq_lengthlist__16u2_p6_1,
  130087. 1, -533725184, 1611661312, 3, 0,
  130088. _vq_quantlist__16u2_p6_1,
  130089. NULL,
  130090. &_vq_auxt__16u2_p6_1,
  130091. NULL,
  130092. 0
  130093. };
  130094. static long _vq_quantlist__16u2_p7_0[] = {
  130095. 6,
  130096. 5,
  130097. 7,
  130098. 4,
  130099. 8,
  130100. 3,
  130101. 9,
  130102. 2,
  130103. 10,
  130104. 1,
  130105. 11,
  130106. 0,
  130107. 12,
  130108. };
  130109. static long _vq_lengthlist__16u2_p7_0[] = {
  130110. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  130111. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  130112. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  130113. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  130114. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  130115. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  130116. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  130117. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  130118. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  130119. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  130120. 12,13,13,13,14,14,14,15,14,
  130121. };
  130122. static float _vq_quantthresh__16u2_p7_0[] = {
  130123. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  130124. 27.5, 38.5, 49.5, 60.5,
  130125. };
  130126. static long _vq_quantmap__16u2_p7_0[] = {
  130127. 11, 9, 7, 5, 3, 1, 0, 2,
  130128. 4, 6, 8, 10, 12,
  130129. };
  130130. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  130131. _vq_quantthresh__16u2_p7_0,
  130132. _vq_quantmap__16u2_p7_0,
  130133. 13,
  130134. 13
  130135. };
  130136. static static_codebook _16u2_p7_0 = {
  130137. 2, 169,
  130138. _vq_lengthlist__16u2_p7_0,
  130139. 1, -523206656, 1618345984, 4, 0,
  130140. _vq_quantlist__16u2_p7_0,
  130141. NULL,
  130142. &_vq_auxt__16u2_p7_0,
  130143. NULL,
  130144. 0
  130145. };
  130146. static long _vq_quantlist__16u2_p7_1[] = {
  130147. 5,
  130148. 4,
  130149. 6,
  130150. 3,
  130151. 7,
  130152. 2,
  130153. 8,
  130154. 1,
  130155. 9,
  130156. 0,
  130157. 10,
  130158. };
  130159. static long _vq_lengthlist__16u2_p7_1[] = {
  130160. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  130161. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  130162. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  130163. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  130164. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  130165. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  130166. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  130167. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130168. };
  130169. static float _vq_quantthresh__16u2_p7_1[] = {
  130170. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130171. 3.5, 4.5,
  130172. };
  130173. static long _vq_quantmap__16u2_p7_1[] = {
  130174. 9, 7, 5, 3, 1, 0, 2, 4,
  130175. 6, 8, 10,
  130176. };
  130177. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  130178. _vq_quantthresh__16u2_p7_1,
  130179. _vq_quantmap__16u2_p7_1,
  130180. 11,
  130181. 11
  130182. };
  130183. static static_codebook _16u2_p7_1 = {
  130184. 2, 121,
  130185. _vq_lengthlist__16u2_p7_1,
  130186. 1, -531365888, 1611661312, 4, 0,
  130187. _vq_quantlist__16u2_p7_1,
  130188. NULL,
  130189. &_vq_auxt__16u2_p7_1,
  130190. NULL,
  130191. 0
  130192. };
  130193. static long _vq_quantlist__16u2_p8_0[] = {
  130194. 7,
  130195. 6,
  130196. 8,
  130197. 5,
  130198. 9,
  130199. 4,
  130200. 10,
  130201. 3,
  130202. 11,
  130203. 2,
  130204. 12,
  130205. 1,
  130206. 13,
  130207. 0,
  130208. 14,
  130209. };
  130210. static long _vq_lengthlist__16u2_p8_0[] = {
  130211. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  130212. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  130213. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  130214. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  130215. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  130216. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  130217. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  130218. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  130219. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  130220. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  130221. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  130222. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  130223. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  130224. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  130225. 14,
  130226. };
  130227. static float _vq_quantthresh__16u2_p8_0[] = {
  130228. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130229. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130230. };
  130231. static long _vq_quantmap__16u2_p8_0[] = {
  130232. 13, 11, 9, 7, 5, 3, 1, 0,
  130233. 2, 4, 6, 8, 10, 12, 14,
  130234. };
  130235. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  130236. _vq_quantthresh__16u2_p8_0,
  130237. _vq_quantmap__16u2_p8_0,
  130238. 15,
  130239. 15
  130240. };
  130241. static static_codebook _16u2_p8_0 = {
  130242. 2, 225,
  130243. _vq_lengthlist__16u2_p8_0,
  130244. 1, -520986624, 1620377600, 4, 0,
  130245. _vq_quantlist__16u2_p8_0,
  130246. NULL,
  130247. &_vq_auxt__16u2_p8_0,
  130248. NULL,
  130249. 0
  130250. };
  130251. static long _vq_quantlist__16u2_p8_1[] = {
  130252. 10,
  130253. 9,
  130254. 11,
  130255. 8,
  130256. 12,
  130257. 7,
  130258. 13,
  130259. 6,
  130260. 14,
  130261. 5,
  130262. 15,
  130263. 4,
  130264. 16,
  130265. 3,
  130266. 17,
  130267. 2,
  130268. 18,
  130269. 1,
  130270. 19,
  130271. 0,
  130272. 20,
  130273. };
  130274. static long _vq_lengthlist__16u2_p8_1[] = {
  130275. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  130276. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  130277. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  130278. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  130279. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  130280. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  130281. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  130282. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  130283. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130284. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130285. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130286. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130287. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130288. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130289. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130290. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130291. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130292. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130293. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130294. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130295. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130296. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130297. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130298. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130299. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130300. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130301. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130302. 11,11,10,11,11,11,10,11,11,
  130303. };
  130304. static float _vq_quantthresh__16u2_p8_1[] = {
  130305. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130306. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130307. 6.5, 7.5, 8.5, 9.5,
  130308. };
  130309. static long _vq_quantmap__16u2_p8_1[] = {
  130310. 19, 17, 15, 13, 11, 9, 7, 5,
  130311. 3, 1, 0, 2, 4, 6, 8, 10,
  130312. 12, 14, 16, 18, 20,
  130313. };
  130314. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130315. _vq_quantthresh__16u2_p8_1,
  130316. _vq_quantmap__16u2_p8_1,
  130317. 21,
  130318. 21
  130319. };
  130320. static static_codebook _16u2_p8_1 = {
  130321. 2, 441,
  130322. _vq_lengthlist__16u2_p8_1,
  130323. 1, -529268736, 1611661312, 5, 0,
  130324. _vq_quantlist__16u2_p8_1,
  130325. NULL,
  130326. &_vq_auxt__16u2_p8_1,
  130327. NULL,
  130328. 0
  130329. };
  130330. static long _vq_quantlist__16u2_p9_0[] = {
  130331. 5586,
  130332. 4655,
  130333. 6517,
  130334. 3724,
  130335. 7448,
  130336. 2793,
  130337. 8379,
  130338. 1862,
  130339. 9310,
  130340. 931,
  130341. 10241,
  130342. 0,
  130343. 11172,
  130344. 5521,
  130345. 5651,
  130346. };
  130347. static long _vq_lengthlist__16u2_p9_0[] = {
  130348. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130349. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130350. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130351. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130352. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130353. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130354. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130355. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130356. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130357. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130358. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130359. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130360. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130361. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130362. 5,
  130363. };
  130364. static float _vq_quantthresh__16u2_p9_0[] = {
  130365. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130366. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130367. };
  130368. static long _vq_quantmap__16u2_p9_0[] = {
  130369. 11, 9, 7, 5, 3, 1, 13, 0,
  130370. 14, 2, 4, 6, 8, 10, 12,
  130371. };
  130372. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130373. _vq_quantthresh__16u2_p9_0,
  130374. _vq_quantmap__16u2_p9_0,
  130375. 15,
  130376. 15
  130377. };
  130378. static static_codebook _16u2_p9_0 = {
  130379. 2, 225,
  130380. _vq_lengthlist__16u2_p9_0,
  130381. 1, -510275072, 1611661312, 14, 0,
  130382. _vq_quantlist__16u2_p9_0,
  130383. NULL,
  130384. &_vq_auxt__16u2_p9_0,
  130385. NULL,
  130386. 0
  130387. };
  130388. static long _vq_quantlist__16u2_p9_1[] = {
  130389. 392,
  130390. 343,
  130391. 441,
  130392. 294,
  130393. 490,
  130394. 245,
  130395. 539,
  130396. 196,
  130397. 588,
  130398. 147,
  130399. 637,
  130400. 98,
  130401. 686,
  130402. 49,
  130403. 735,
  130404. 0,
  130405. 784,
  130406. 388,
  130407. 396,
  130408. };
  130409. static long _vq_lengthlist__16u2_p9_1[] = {
  130410. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130411. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130412. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130413. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130414. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130415. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130416. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130417. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130418. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130419. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130420. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130421. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130422. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130423. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130424. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130425. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130426. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130427. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130428. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130429. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130430. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130431. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130432. 11,11,11,11,11,11,11, 5, 4,
  130433. };
  130434. static float _vq_quantthresh__16u2_p9_1[] = {
  130435. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130436. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130437. 318.5, 367.5,
  130438. };
  130439. static long _vq_quantmap__16u2_p9_1[] = {
  130440. 15, 13, 11, 9, 7, 5, 3, 1,
  130441. 17, 0, 18, 2, 4, 6, 8, 10,
  130442. 12, 14, 16,
  130443. };
  130444. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130445. _vq_quantthresh__16u2_p9_1,
  130446. _vq_quantmap__16u2_p9_1,
  130447. 19,
  130448. 19
  130449. };
  130450. static static_codebook _16u2_p9_1 = {
  130451. 2, 361,
  130452. _vq_lengthlist__16u2_p9_1,
  130453. 1, -518488064, 1611661312, 10, 0,
  130454. _vq_quantlist__16u2_p9_1,
  130455. NULL,
  130456. &_vq_auxt__16u2_p9_1,
  130457. NULL,
  130458. 0
  130459. };
  130460. static long _vq_quantlist__16u2_p9_2[] = {
  130461. 24,
  130462. 23,
  130463. 25,
  130464. 22,
  130465. 26,
  130466. 21,
  130467. 27,
  130468. 20,
  130469. 28,
  130470. 19,
  130471. 29,
  130472. 18,
  130473. 30,
  130474. 17,
  130475. 31,
  130476. 16,
  130477. 32,
  130478. 15,
  130479. 33,
  130480. 14,
  130481. 34,
  130482. 13,
  130483. 35,
  130484. 12,
  130485. 36,
  130486. 11,
  130487. 37,
  130488. 10,
  130489. 38,
  130490. 9,
  130491. 39,
  130492. 8,
  130493. 40,
  130494. 7,
  130495. 41,
  130496. 6,
  130497. 42,
  130498. 5,
  130499. 43,
  130500. 4,
  130501. 44,
  130502. 3,
  130503. 45,
  130504. 2,
  130505. 46,
  130506. 1,
  130507. 47,
  130508. 0,
  130509. 48,
  130510. };
  130511. static long _vq_lengthlist__16u2_p9_2[] = {
  130512. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130513. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130514. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130515. 11,
  130516. };
  130517. static float _vq_quantthresh__16u2_p9_2[] = {
  130518. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130519. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130520. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130521. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130522. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130523. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130524. };
  130525. static long _vq_quantmap__16u2_p9_2[] = {
  130526. 47, 45, 43, 41, 39, 37, 35, 33,
  130527. 31, 29, 27, 25, 23, 21, 19, 17,
  130528. 15, 13, 11, 9, 7, 5, 3, 1,
  130529. 0, 2, 4, 6, 8, 10, 12, 14,
  130530. 16, 18, 20, 22, 24, 26, 28, 30,
  130531. 32, 34, 36, 38, 40, 42, 44, 46,
  130532. 48,
  130533. };
  130534. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130535. _vq_quantthresh__16u2_p9_2,
  130536. _vq_quantmap__16u2_p9_2,
  130537. 49,
  130538. 49
  130539. };
  130540. static static_codebook _16u2_p9_2 = {
  130541. 1, 49,
  130542. _vq_lengthlist__16u2_p9_2,
  130543. 1, -526909440, 1611661312, 6, 0,
  130544. _vq_quantlist__16u2_p9_2,
  130545. NULL,
  130546. &_vq_auxt__16u2_p9_2,
  130547. NULL,
  130548. 0
  130549. };
  130550. static long _vq_quantlist__8u0__p1_0[] = {
  130551. 1,
  130552. 0,
  130553. 2,
  130554. };
  130555. static long _vq_lengthlist__8u0__p1_0[] = {
  130556. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130557. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130558. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130559. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130560. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130561. 11,
  130562. };
  130563. static float _vq_quantthresh__8u0__p1_0[] = {
  130564. -0.5, 0.5,
  130565. };
  130566. static long _vq_quantmap__8u0__p1_0[] = {
  130567. 1, 0, 2,
  130568. };
  130569. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130570. _vq_quantthresh__8u0__p1_0,
  130571. _vq_quantmap__8u0__p1_0,
  130572. 3,
  130573. 3
  130574. };
  130575. static static_codebook _8u0__p1_0 = {
  130576. 4, 81,
  130577. _vq_lengthlist__8u0__p1_0,
  130578. 1, -535822336, 1611661312, 2, 0,
  130579. _vq_quantlist__8u0__p1_0,
  130580. NULL,
  130581. &_vq_auxt__8u0__p1_0,
  130582. NULL,
  130583. 0
  130584. };
  130585. static long _vq_quantlist__8u0__p2_0[] = {
  130586. 1,
  130587. 0,
  130588. 2,
  130589. };
  130590. static long _vq_lengthlist__8u0__p2_0[] = {
  130591. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130592. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130593. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130594. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130595. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130596. 8,
  130597. };
  130598. static float _vq_quantthresh__8u0__p2_0[] = {
  130599. -0.5, 0.5,
  130600. };
  130601. static long _vq_quantmap__8u0__p2_0[] = {
  130602. 1, 0, 2,
  130603. };
  130604. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130605. _vq_quantthresh__8u0__p2_0,
  130606. _vq_quantmap__8u0__p2_0,
  130607. 3,
  130608. 3
  130609. };
  130610. static static_codebook _8u0__p2_0 = {
  130611. 4, 81,
  130612. _vq_lengthlist__8u0__p2_0,
  130613. 1, -535822336, 1611661312, 2, 0,
  130614. _vq_quantlist__8u0__p2_0,
  130615. NULL,
  130616. &_vq_auxt__8u0__p2_0,
  130617. NULL,
  130618. 0
  130619. };
  130620. static long _vq_quantlist__8u0__p3_0[] = {
  130621. 2,
  130622. 1,
  130623. 3,
  130624. 0,
  130625. 4,
  130626. };
  130627. static long _vq_lengthlist__8u0__p3_0[] = {
  130628. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130629. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130630. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130631. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130632. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130633. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130634. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130635. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130636. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130637. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130638. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130639. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130640. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130641. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130642. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130643. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130644. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130645. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130646. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130647. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130648. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130649. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130650. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130651. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130652. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130653. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130654. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130655. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130656. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130657. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130658. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130659. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130660. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130661. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130662. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130663. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130664. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130665. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130666. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130667. 16,
  130668. };
  130669. static float _vq_quantthresh__8u0__p3_0[] = {
  130670. -1.5, -0.5, 0.5, 1.5,
  130671. };
  130672. static long _vq_quantmap__8u0__p3_0[] = {
  130673. 3, 1, 0, 2, 4,
  130674. };
  130675. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  130676. _vq_quantthresh__8u0__p3_0,
  130677. _vq_quantmap__8u0__p3_0,
  130678. 5,
  130679. 5
  130680. };
  130681. static static_codebook _8u0__p3_0 = {
  130682. 4, 625,
  130683. _vq_lengthlist__8u0__p3_0,
  130684. 1, -533725184, 1611661312, 3, 0,
  130685. _vq_quantlist__8u0__p3_0,
  130686. NULL,
  130687. &_vq_auxt__8u0__p3_0,
  130688. NULL,
  130689. 0
  130690. };
  130691. static long _vq_quantlist__8u0__p4_0[] = {
  130692. 2,
  130693. 1,
  130694. 3,
  130695. 0,
  130696. 4,
  130697. };
  130698. static long _vq_lengthlist__8u0__p4_0[] = {
  130699. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  130700. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  130701. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  130702. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  130703. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  130704. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  130705. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  130706. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  130707. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  130708. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  130709. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  130710. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  130711. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  130712. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  130713. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  130714. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  130715. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  130716. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  130717. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  130718. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  130719. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  130720. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  130721. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  130722. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  130723. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  130724. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  130725. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  130726. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  130727. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  130728. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  130729. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  130730. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  130731. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  130732. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  130733. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  130734. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  130735. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  130736. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  130737. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  130738. 12,
  130739. };
  130740. static float _vq_quantthresh__8u0__p4_0[] = {
  130741. -1.5, -0.5, 0.5, 1.5,
  130742. };
  130743. static long _vq_quantmap__8u0__p4_0[] = {
  130744. 3, 1, 0, 2, 4,
  130745. };
  130746. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  130747. _vq_quantthresh__8u0__p4_0,
  130748. _vq_quantmap__8u0__p4_0,
  130749. 5,
  130750. 5
  130751. };
  130752. static static_codebook _8u0__p4_0 = {
  130753. 4, 625,
  130754. _vq_lengthlist__8u0__p4_0,
  130755. 1, -533725184, 1611661312, 3, 0,
  130756. _vq_quantlist__8u0__p4_0,
  130757. NULL,
  130758. &_vq_auxt__8u0__p4_0,
  130759. NULL,
  130760. 0
  130761. };
  130762. static long _vq_quantlist__8u0__p5_0[] = {
  130763. 4,
  130764. 3,
  130765. 5,
  130766. 2,
  130767. 6,
  130768. 1,
  130769. 7,
  130770. 0,
  130771. 8,
  130772. };
  130773. static long _vq_lengthlist__8u0__p5_0[] = {
  130774. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  130775. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  130776. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  130777. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  130778. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  130779. 12,
  130780. };
  130781. static float _vq_quantthresh__8u0__p5_0[] = {
  130782. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130783. };
  130784. static long _vq_quantmap__8u0__p5_0[] = {
  130785. 7, 5, 3, 1, 0, 2, 4, 6,
  130786. 8,
  130787. };
  130788. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  130789. _vq_quantthresh__8u0__p5_0,
  130790. _vq_quantmap__8u0__p5_0,
  130791. 9,
  130792. 9
  130793. };
  130794. static static_codebook _8u0__p5_0 = {
  130795. 2, 81,
  130796. _vq_lengthlist__8u0__p5_0,
  130797. 1, -531628032, 1611661312, 4, 0,
  130798. _vq_quantlist__8u0__p5_0,
  130799. NULL,
  130800. &_vq_auxt__8u0__p5_0,
  130801. NULL,
  130802. 0
  130803. };
  130804. static long _vq_quantlist__8u0__p6_0[] = {
  130805. 6,
  130806. 5,
  130807. 7,
  130808. 4,
  130809. 8,
  130810. 3,
  130811. 9,
  130812. 2,
  130813. 10,
  130814. 1,
  130815. 11,
  130816. 0,
  130817. 12,
  130818. };
  130819. static long _vq_lengthlist__8u0__p6_0[] = {
  130820. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  130821. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  130822. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  130823. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  130824. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  130825. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  130826. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  130827. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  130828. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  130829. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  130830. 16, 0,15, 0,17, 0, 0, 0, 0,
  130831. };
  130832. static float _vq_quantthresh__8u0__p6_0[] = {
  130833. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130834. 12.5, 17.5, 22.5, 27.5,
  130835. };
  130836. static long _vq_quantmap__8u0__p6_0[] = {
  130837. 11, 9, 7, 5, 3, 1, 0, 2,
  130838. 4, 6, 8, 10, 12,
  130839. };
  130840. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  130841. _vq_quantthresh__8u0__p6_0,
  130842. _vq_quantmap__8u0__p6_0,
  130843. 13,
  130844. 13
  130845. };
  130846. static static_codebook _8u0__p6_0 = {
  130847. 2, 169,
  130848. _vq_lengthlist__8u0__p6_0,
  130849. 1, -526516224, 1616117760, 4, 0,
  130850. _vq_quantlist__8u0__p6_0,
  130851. NULL,
  130852. &_vq_auxt__8u0__p6_0,
  130853. NULL,
  130854. 0
  130855. };
  130856. static long _vq_quantlist__8u0__p6_1[] = {
  130857. 2,
  130858. 1,
  130859. 3,
  130860. 0,
  130861. 4,
  130862. };
  130863. static long _vq_lengthlist__8u0__p6_1[] = {
  130864. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  130865. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  130866. };
  130867. static float _vq_quantthresh__8u0__p6_1[] = {
  130868. -1.5, -0.5, 0.5, 1.5,
  130869. };
  130870. static long _vq_quantmap__8u0__p6_1[] = {
  130871. 3, 1, 0, 2, 4,
  130872. };
  130873. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  130874. _vq_quantthresh__8u0__p6_1,
  130875. _vq_quantmap__8u0__p6_1,
  130876. 5,
  130877. 5
  130878. };
  130879. static static_codebook _8u0__p6_1 = {
  130880. 2, 25,
  130881. _vq_lengthlist__8u0__p6_1,
  130882. 1, -533725184, 1611661312, 3, 0,
  130883. _vq_quantlist__8u0__p6_1,
  130884. NULL,
  130885. &_vq_auxt__8u0__p6_1,
  130886. NULL,
  130887. 0
  130888. };
  130889. static long _vq_quantlist__8u0__p7_0[] = {
  130890. 1,
  130891. 0,
  130892. 2,
  130893. };
  130894. static long _vq_lengthlist__8u0__p7_0[] = {
  130895. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130896. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130897. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130898. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130899. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130900. 7,
  130901. };
  130902. static float _vq_quantthresh__8u0__p7_0[] = {
  130903. -157.5, 157.5,
  130904. };
  130905. static long _vq_quantmap__8u0__p7_0[] = {
  130906. 1, 0, 2,
  130907. };
  130908. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  130909. _vq_quantthresh__8u0__p7_0,
  130910. _vq_quantmap__8u0__p7_0,
  130911. 3,
  130912. 3
  130913. };
  130914. static static_codebook _8u0__p7_0 = {
  130915. 4, 81,
  130916. _vq_lengthlist__8u0__p7_0,
  130917. 1, -518803456, 1628680192, 2, 0,
  130918. _vq_quantlist__8u0__p7_0,
  130919. NULL,
  130920. &_vq_auxt__8u0__p7_0,
  130921. NULL,
  130922. 0
  130923. };
  130924. static long _vq_quantlist__8u0__p7_1[] = {
  130925. 7,
  130926. 6,
  130927. 8,
  130928. 5,
  130929. 9,
  130930. 4,
  130931. 10,
  130932. 3,
  130933. 11,
  130934. 2,
  130935. 12,
  130936. 1,
  130937. 13,
  130938. 0,
  130939. 14,
  130940. };
  130941. static long _vq_lengthlist__8u0__p7_1[] = {
  130942. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  130943. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  130944. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  130945. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  130946. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  130947. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  130948. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130949. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130950. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130951. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130952. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130953. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130954. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  130955. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130956. 10,
  130957. };
  130958. static float _vq_quantthresh__8u0__p7_1[] = {
  130959. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130960. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130961. };
  130962. static long _vq_quantmap__8u0__p7_1[] = {
  130963. 13, 11, 9, 7, 5, 3, 1, 0,
  130964. 2, 4, 6, 8, 10, 12, 14,
  130965. };
  130966. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  130967. _vq_quantthresh__8u0__p7_1,
  130968. _vq_quantmap__8u0__p7_1,
  130969. 15,
  130970. 15
  130971. };
  130972. static static_codebook _8u0__p7_1 = {
  130973. 2, 225,
  130974. _vq_lengthlist__8u0__p7_1,
  130975. 1, -520986624, 1620377600, 4, 0,
  130976. _vq_quantlist__8u0__p7_1,
  130977. NULL,
  130978. &_vq_auxt__8u0__p7_1,
  130979. NULL,
  130980. 0
  130981. };
  130982. static long _vq_quantlist__8u0__p7_2[] = {
  130983. 10,
  130984. 9,
  130985. 11,
  130986. 8,
  130987. 12,
  130988. 7,
  130989. 13,
  130990. 6,
  130991. 14,
  130992. 5,
  130993. 15,
  130994. 4,
  130995. 16,
  130996. 3,
  130997. 17,
  130998. 2,
  130999. 18,
  131000. 1,
  131001. 19,
  131002. 0,
  131003. 20,
  131004. };
  131005. static long _vq_lengthlist__8u0__p7_2[] = {
  131006. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  131007. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  131008. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  131009. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  131010. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  131011. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  131012. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  131013. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  131014. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  131015. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  131016. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  131017. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  131018. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  131019. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  131020. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  131021. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  131022. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  131023. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  131024. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  131025. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  131026. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  131027. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  131028. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  131029. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  131030. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  131031. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  131032. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  131033. 11,12,11,11,11,10,10,11,11,
  131034. };
  131035. static float _vq_quantthresh__8u0__p7_2[] = {
  131036. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  131037. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  131038. 6.5, 7.5, 8.5, 9.5,
  131039. };
  131040. static long _vq_quantmap__8u0__p7_2[] = {
  131041. 19, 17, 15, 13, 11, 9, 7, 5,
  131042. 3, 1, 0, 2, 4, 6, 8, 10,
  131043. 12, 14, 16, 18, 20,
  131044. };
  131045. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  131046. _vq_quantthresh__8u0__p7_2,
  131047. _vq_quantmap__8u0__p7_2,
  131048. 21,
  131049. 21
  131050. };
  131051. static static_codebook _8u0__p7_2 = {
  131052. 2, 441,
  131053. _vq_lengthlist__8u0__p7_2,
  131054. 1, -529268736, 1611661312, 5, 0,
  131055. _vq_quantlist__8u0__p7_2,
  131056. NULL,
  131057. &_vq_auxt__8u0__p7_2,
  131058. NULL,
  131059. 0
  131060. };
  131061. static long _huff_lengthlist__8u0__single[] = {
  131062. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  131063. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  131064. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  131065. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  131066. };
  131067. static static_codebook _huff_book__8u0__single = {
  131068. 2, 64,
  131069. _huff_lengthlist__8u0__single,
  131070. 0, 0, 0, 0, 0,
  131071. NULL,
  131072. NULL,
  131073. NULL,
  131074. NULL,
  131075. 0
  131076. };
  131077. static long _vq_quantlist__8u1__p1_0[] = {
  131078. 1,
  131079. 0,
  131080. 2,
  131081. };
  131082. static long _vq_lengthlist__8u1__p1_0[] = {
  131083. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  131084. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  131085. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  131086. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  131087. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  131088. 10,
  131089. };
  131090. static float _vq_quantthresh__8u1__p1_0[] = {
  131091. -0.5, 0.5,
  131092. };
  131093. static long _vq_quantmap__8u1__p1_0[] = {
  131094. 1, 0, 2,
  131095. };
  131096. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  131097. _vq_quantthresh__8u1__p1_0,
  131098. _vq_quantmap__8u1__p1_0,
  131099. 3,
  131100. 3
  131101. };
  131102. static static_codebook _8u1__p1_0 = {
  131103. 4, 81,
  131104. _vq_lengthlist__8u1__p1_0,
  131105. 1, -535822336, 1611661312, 2, 0,
  131106. _vq_quantlist__8u1__p1_0,
  131107. NULL,
  131108. &_vq_auxt__8u1__p1_0,
  131109. NULL,
  131110. 0
  131111. };
  131112. static long _vq_quantlist__8u1__p2_0[] = {
  131113. 1,
  131114. 0,
  131115. 2,
  131116. };
  131117. static long _vq_lengthlist__8u1__p2_0[] = {
  131118. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  131119. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  131120. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  131121. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  131122. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  131123. 7,
  131124. };
  131125. static float _vq_quantthresh__8u1__p2_0[] = {
  131126. -0.5, 0.5,
  131127. };
  131128. static long _vq_quantmap__8u1__p2_0[] = {
  131129. 1, 0, 2,
  131130. };
  131131. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  131132. _vq_quantthresh__8u1__p2_0,
  131133. _vq_quantmap__8u1__p2_0,
  131134. 3,
  131135. 3
  131136. };
  131137. static static_codebook _8u1__p2_0 = {
  131138. 4, 81,
  131139. _vq_lengthlist__8u1__p2_0,
  131140. 1, -535822336, 1611661312, 2, 0,
  131141. _vq_quantlist__8u1__p2_0,
  131142. NULL,
  131143. &_vq_auxt__8u1__p2_0,
  131144. NULL,
  131145. 0
  131146. };
  131147. static long _vq_quantlist__8u1__p3_0[] = {
  131148. 2,
  131149. 1,
  131150. 3,
  131151. 0,
  131152. 4,
  131153. };
  131154. static long _vq_lengthlist__8u1__p3_0[] = {
  131155. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  131156. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  131157. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  131158. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  131159. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  131160. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  131161. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  131162. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  131163. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  131164. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  131165. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  131166. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  131167. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  131168. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  131169. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  131170. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  131171. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  131172. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  131173. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  131174. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  131175. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  131176. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  131177. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  131178. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  131179. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  131180. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  131181. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  131182. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  131183. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  131184. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  131185. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  131186. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  131187. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  131188. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  131189. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  131190. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  131191. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  131192. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  131193. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  131194. 16,
  131195. };
  131196. static float _vq_quantthresh__8u1__p3_0[] = {
  131197. -1.5, -0.5, 0.5, 1.5,
  131198. };
  131199. static long _vq_quantmap__8u1__p3_0[] = {
  131200. 3, 1, 0, 2, 4,
  131201. };
  131202. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  131203. _vq_quantthresh__8u1__p3_0,
  131204. _vq_quantmap__8u1__p3_0,
  131205. 5,
  131206. 5
  131207. };
  131208. static static_codebook _8u1__p3_0 = {
  131209. 4, 625,
  131210. _vq_lengthlist__8u1__p3_0,
  131211. 1, -533725184, 1611661312, 3, 0,
  131212. _vq_quantlist__8u1__p3_0,
  131213. NULL,
  131214. &_vq_auxt__8u1__p3_0,
  131215. NULL,
  131216. 0
  131217. };
  131218. static long _vq_quantlist__8u1__p4_0[] = {
  131219. 2,
  131220. 1,
  131221. 3,
  131222. 0,
  131223. 4,
  131224. };
  131225. static long _vq_lengthlist__8u1__p4_0[] = {
  131226. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  131227. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  131228. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  131229. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  131230. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  131231. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  131232. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  131233. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  131234. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  131235. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  131236. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  131237. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  131238. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  131239. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  131240. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  131241. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  131242. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  131243. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  131244. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  131245. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  131246. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  131247. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  131248. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  131249. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  131250. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  131251. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  131252. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  131253. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  131254. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  131255. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  131256. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  131257. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  131258. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  131259. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  131260. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  131261. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  131262. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  131263. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  131264. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  131265. 10,
  131266. };
  131267. static float _vq_quantthresh__8u1__p4_0[] = {
  131268. -1.5, -0.5, 0.5, 1.5,
  131269. };
  131270. static long _vq_quantmap__8u1__p4_0[] = {
  131271. 3, 1, 0, 2, 4,
  131272. };
  131273. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  131274. _vq_quantthresh__8u1__p4_0,
  131275. _vq_quantmap__8u1__p4_0,
  131276. 5,
  131277. 5
  131278. };
  131279. static static_codebook _8u1__p4_0 = {
  131280. 4, 625,
  131281. _vq_lengthlist__8u1__p4_0,
  131282. 1, -533725184, 1611661312, 3, 0,
  131283. _vq_quantlist__8u1__p4_0,
  131284. NULL,
  131285. &_vq_auxt__8u1__p4_0,
  131286. NULL,
  131287. 0
  131288. };
  131289. static long _vq_quantlist__8u1__p5_0[] = {
  131290. 4,
  131291. 3,
  131292. 5,
  131293. 2,
  131294. 6,
  131295. 1,
  131296. 7,
  131297. 0,
  131298. 8,
  131299. };
  131300. static long _vq_lengthlist__8u1__p5_0[] = {
  131301. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131302. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131303. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131304. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131305. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131306. 13,
  131307. };
  131308. static float _vq_quantthresh__8u1__p5_0[] = {
  131309. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131310. };
  131311. static long _vq_quantmap__8u1__p5_0[] = {
  131312. 7, 5, 3, 1, 0, 2, 4, 6,
  131313. 8,
  131314. };
  131315. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131316. _vq_quantthresh__8u1__p5_0,
  131317. _vq_quantmap__8u1__p5_0,
  131318. 9,
  131319. 9
  131320. };
  131321. static static_codebook _8u1__p5_0 = {
  131322. 2, 81,
  131323. _vq_lengthlist__8u1__p5_0,
  131324. 1, -531628032, 1611661312, 4, 0,
  131325. _vq_quantlist__8u1__p5_0,
  131326. NULL,
  131327. &_vq_auxt__8u1__p5_0,
  131328. NULL,
  131329. 0
  131330. };
  131331. static long _vq_quantlist__8u1__p6_0[] = {
  131332. 4,
  131333. 3,
  131334. 5,
  131335. 2,
  131336. 6,
  131337. 1,
  131338. 7,
  131339. 0,
  131340. 8,
  131341. };
  131342. static long _vq_lengthlist__8u1__p6_0[] = {
  131343. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131344. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131345. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131346. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131347. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131348. 10,
  131349. };
  131350. static float _vq_quantthresh__8u1__p6_0[] = {
  131351. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131352. };
  131353. static long _vq_quantmap__8u1__p6_0[] = {
  131354. 7, 5, 3, 1, 0, 2, 4, 6,
  131355. 8,
  131356. };
  131357. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131358. _vq_quantthresh__8u1__p6_0,
  131359. _vq_quantmap__8u1__p6_0,
  131360. 9,
  131361. 9
  131362. };
  131363. static static_codebook _8u1__p6_0 = {
  131364. 2, 81,
  131365. _vq_lengthlist__8u1__p6_0,
  131366. 1, -531628032, 1611661312, 4, 0,
  131367. _vq_quantlist__8u1__p6_0,
  131368. NULL,
  131369. &_vq_auxt__8u1__p6_0,
  131370. NULL,
  131371. 0
  131372. };
  131373. static long _vq_quantlist__8u1__p7_0[] = {
  131374. 1,
  131375. 0,
  131376. 2,
  131377. };
  131378. static long _vq_lengthlist__8u1__p7_0[] = {
  131379. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  131380. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  131381. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  131382. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  131383. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  131384. 11,
  131385. };
  131386. static float _vq_quantthresh__8u1__p7_0[] = {
  131387. -5.5, 5.5,
  131388. };
  131389. static long _vq_quantmap__8u1__p7_0[] = {
  131390. 1, 0, 2,
  131391. };
  131392. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  131393. _vq_quantthresh__8u1__p7_0,
  131394. _vq_quantmap__8u1__p7_0,
  131395. 3,
  131396. 3
  131397. };
  131398. static static_codebook _8u1__p7_0 = {
  131399. 4, 81,
  131400. _vq_lengthlist__8u1__p7_0,
  131401. 1, -529137664, 1618345984, 2, 0,
  131402. _vq_quantlist__8u1__p7_0,
  131403. NULL,
  131404. &_vq_auxt__8u1__p7_0,
  131405. NULL,
  131406. 0
  131407. };
  131408. static long _vq_quantlist__8u1__p7_1[] = {
  131409. 5,
  131410. 4,
  131411. 6,
  131412. 3,
  131413. 7,
  131414. 2,
  131415. 8,
  131416. 1,
  131417. 9,
  131418. 0,
  131419. 10,
  131420. };
  131421. static long _vq_lengthlist__8u1__p7_1[] = {
  131422. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131423. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131424. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131425. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131426. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131427. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131428. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131429. 9, 9, 9, 9, 9,10,10,10,10,
  131430. };
  131431. static float _vq_quantthresh__8u1__p7_1[] = {
  131432. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131433. 3.5, 4.5,
  131434. };
  131435. static long _vq_quantmap__8u1__p7_1[] = {
  131436. 9, 7, 5, 3, 1, 0, 2, 4,
  131437. 6, 8, 10,
  131438. };
  131439. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131440. _vq_quantthresh__8u1__p7_1,
  131441. _vq_quantmap__8u1__p7_1,
  131442. 11,
  131443. 11
  131444. };
  131445. static static_codebook _8u1__p7_1 = {
  131446. 2, 121,
  131447. _vq_lengthlist__8u1__p7_1,
  131448. 1, -531365888, 1611661312, 4, 0,
  131449. _vq_quantlist__8u1__p7_1,
  131450. NULL,
  131451. &_vq_auxt__8u1__p7_1,
  131452. NULL,
  131453. 0
  131454. };
  131455. static long _vq_quantlist__8u1__p8_0[] = {
  131456. 5,
  131457. 4,
  131458. 6,
  131459. 3,
  131460. 7,
  131461. 2,
  131462. 8,
  131463. 1,
  131464. 9,
  131465. 0,
  131466. 10,
  131467. };
  131468. static long _vq_lengthlist__8u1__p8_0[] = {
  131469. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131470. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131471. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131472. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131473. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131474. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131475. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131476. 12,13,13,14,14,15,15,15,15,
  131477. };
  131478. static float _vq_quantthresh__8u1__p8_0[] = {
  131479. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131480. 38.5, 49.5,
  131481. };
  131482. static long _vq_quantmap__8u1__p8_0[] = {
  131483. 9, 7, 5, 3, 1, 0, 2, 4,
  131484. 6, 8, 10,
  131485. };
  131486. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131487. _vq_quantthresh__8u1__p8_0,
  131488. _vq_quantmap__8u1__p8_0,
  131489. 11,
  131490. 11
  131491. };
  131492. static static_codebook _8u1__p8_0 = {
  131493. 2, 121,
  131494. _vq_lengthlist__8u1__p8_0,
  131495. 1, -524582912, 1618345984, 4, 0,
  131496. _vq_quantlist__8u1__p8_0,
  131497. NULL,
  131498. &_vq_auxt__8u1__p8_0,
  131499. NULL,
  131500. 0
  131501. };
  131502. static long _vq_quantlist__8u1__p8_1[] = {
  131503. 5,
  131504. 4,
  131505. 6,
  131506. 3,
  131507. 7,
  131508. 2,
  131509. 8,
  131510. 1,
  131511. 9,
  131512. 0,
  131513. 10,
  131514. };
  131515. static long _vq_lengthlist__8u1__p8_1[] = {
  131516. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131517. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131518. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131519. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131520. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131521. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131522. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131523. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131524. };
  131525. static float _vq_quantthresh__8u1__p8_1[] = {
  131526. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131527. 3.5, 4.5,
  131528. };
  131529. static long _vq_quantmap__8u1__p8_1[] = {
  131530. 9, 7, 5, 3, 1, 0, 2, 4,
  131531. 6, 8, 10,
  131532. };
  131533. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131534. _vq_quantthresh__8u1__p8_1,
  131535. _vq_quantmap__8u1__p8_1,
  131536. 11,
  131537. 11
  131538. };
  131539. static static_codebook _8u1__p8_1 = {
  131540. 2, 121,
  131541. _vq_lengthlist__8u1__p8_1,
  131542. 1, -531365888, 1611661312, 4, 0,
  131543. _vq_quantlist__8u1__p8_1,
  131544. NULL,
  131545. &_vq_auxt__8u1__p8_1,
  131546. NULL,
  131547. 0
  131548. };
  131549. static long _vq_quantlist__8u1__p9_0[] = {
  131550. 7,
  131551. 6,
  131552. 8,
  131553. 5,
  131554. 9,
  131555. 4,
  131556. 10,
  131557. 3,
  131558. 11,
  131559. 2,
  131560. 12,
  131561. 1,
  131562. 13,
  131563. 0,
  131564. 14,
  131565. };
  131566. static long _vq_lengthlist__8u1__p9_0[] = {
  131567. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131568. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131569. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131570. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131571. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131572. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131573. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131574. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131575. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131576. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131577. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131578. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131579. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131580. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131581. 10,
  131582. };
  131583. static float _vq_quantthresh__8u1__p9_0[] = {
  131584. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131585. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131586. };
  131587. static long _vq_quantmap__8u1__p9_0[] = {
  131588. 13, 11, 9, 7, 5, 3, 1, 0,
  131589. 2, 4, 6, 8, 10, 12, 14,
  131590. };
  131591. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131592. _vq_quantthresh__8u1__p9_0,
  131593. _vq_quantmap__8u1__p9_0,
  131594. 15,
  131595. 15
  131596. };
  131597. static static_codebook _8u1__p9_0 = {
  131598. 2, 225,
  131599. _vq_lengthlist__8u1__p9_0,
  131600. 1, -514071552, 1627381760, 4, 0,
  131601. _vq_quantlist__8u1__p9_0,
  131602. NULL,
  131603. &_vq_auxt__8u1__p9_0,
  131604. NULL,
  131605. 0
  131606. };
  131607. static long _vq_quantlist__8u1__p9_1[] = {
  131608. 7,
  131609. 6,
  131610. 8,
  131611. 5,
  131612. 9,
  131613. 4,
  131614. 10,
  131615. 3,
  131616. 11,
  131617. 2,
  131618. 12,
  131619. 1,
  131620. 13,
  131621. 0,
  131622. 14,
  131623. };
  131624. static long _vq_lengthlist__8u1__p9_1[] = {
  131625. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131626. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131627. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131628. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131629. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131630. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131631. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131632. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131633. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131634. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131635. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131636. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131637. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131638. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131639. 13,
  131640. };
  131641. static float _vq_quantthresh__8u1__p9_1[] = {
  131642. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131643. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131644. };
  131645. static long _vq_quantmap__8u1__p9_1[] = {
  131646. 13, 11, 9, 7, 5, 3, 1, 0,
  131647. 2, 4, 6, 8, 10, 12, 14,
  131648. };
  131649. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131650. _vq_quantthresh__8u1__p9_1,
  131651. _vq_quantmap__8u1__p9_1,
  131652. 15,
  131653. 15
  131654. };
  131655. static static_codebook _8u1__p9_1 = {
  131656. 2, 225,
  131657. _vq_lengthlist__8u1__p9_1,
  131658. 1, -522338304, 1620115456, 4, 0,
  131659. _vq_quantlist__8u1__p9_1,
  131660. NULL,
  131661. &_vq_auxt__8u1__p9_1,
  131662. NULL,
  131663. 0
  131664. };
  131665. static long _vq_quantlist__8u1__p9_2[] = {
  131666. 8,
  131667. 7,
  131668. 9,
  131669. 6,
  131670. 10,
  131671. 5,
  131672. 11,
  131673. 4,
  131674. 12,
  131675. 3,
  131676. 13,
  131677. 2,
  131678. 14,
  131679. 1,
  131680. 15,
  131681. 0,
  131682. 16,
  131683. };
  131684. static long _vq_lengthlist__8u1__p9_2[] = {
  131685. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131686. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  131687. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131688. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  131689. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131690. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  131691. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131692. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  131693. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131694. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  131695. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  131696. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  131697. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  131698. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  131699. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  131700. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  131701. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131702. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131703. 10,
  131704. };
  131705. static float _vq_quantthresh__8u1__p9_2[] = {
  131706. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  131707. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  131708. };
  131709. static long _vq_quantmap__8u1__p9_2[] = {
  131710. 15, 13, 11, 9, 7, 5, 3, 1,
  131711. 0, 2, 4, 6, 8, 10, 12, 14,
  131712. 16,
  131713. };
  131714. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  131715. _vq_quantthresh__8u1__p9_2,
  131716. _vq_quantmap__8u1__p9_2,
  131717. 17,
  131718. 17
  131719. };
  131720. static static_codebook _8u1__p9_2 = {
  131721. 2, 289,
  131722. _vq_lengthlist__8u1__p9_2,
  131723. 1, -529530880, 1611661312, 5, 0,
  131724. _vq_quantlist__8u1__p9_2,
  131725. NULL,
  131726. &_vq_auxt__8u1__p9_2,
  131727. NULL,
  131728. 0
  131729. };
  131730. static long _huff_lengthlist__8u1__single[] = {
  131731. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  131732. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  131733. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  131734. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  131735. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  131736. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  131737. 13, 8, 8,15,
  131738. };
  131739. static static_codebook _huff_book__8u1__single = {
  131740. 2, 100,
  131741. _huff_lengthlist__8u1__single,
  131742. 0, 0, 0, 0, 0,
  131743. NULL,
  131744. NULL,
  131745. NULL,
  131746. NULL,
  131747. 0
  131748. };
  131749. static long _huff_lengthlist__44u0__long[] = {
  131750. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  131751. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  131752. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  131753. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  131754. };
  131755. static static_codebook _huff_book__44u0__long = {
  131756. 2, 64,
  131757. _huff_lengthlist__44u0__long,
  131758. 0, 0, 0, 0, 0,
  131759. NULL,
  131760. NULL,
  131761. NULL,
  131762. NULL,
  131763. 0
  131764. };
  131765. static long _vq_quantlist__44u0__p1_0[] = {
  131766. 1,
  131767. 0,
  131768. 2,
  131769. };
  131770. static long _vq_lengthlist__44u0__p1_0[] = {
  131771. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  131772. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  131773. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  131774. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  131775. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  131776. 13,
  131777. };
  131778. static float _vq_quantthresh__44u0__p1_0[] = {
  131779. -0.5, 0.5,
  131780. };
  131781. static long _vq_quantmap__44u0__p1_0[] = {
  131782. 1, 0, 2,
  131783. };
  131784. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  131785. _vq_quantthresh__44u0__p1_0,
  131786. _vq_quantmap__44u0__p1_0,
  131787. 3,
  131788. 3
  131789. };
  131790. static static_codebook _44u0__p1_0 = {
  131791. 4, 81,
  131792. _vq_lengthlist__44u0__p1_0,
  131793. 1, -535822336, 1611661312, 2, 0,
  131794. _vq_quantlist__44u0__p1_0,
  131795. NULL,
  131796. &_vq_auxt__44u0__p1_0,
  131797. NULL,
  131798. 0
  131799. };
  131800. static long _vq_quantlist__44u0__p2_0[] = {
  131801. 1,
  131802. 0,
  131803. 2,
  131804. };
  131805. static long _vq_lengthlist__44u0__p2_0[] = {
  131806. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  131807. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  131808. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  131809. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  131810. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  131811. 9,
  131812. };
  131813. static float _vq_quantthresh__44u0__p2_0[] = {
  131814. -0.5, 0.5,
  131815. };
  131816. static long _vq_quantmap__44u0__p2_0[] = {
  131817. 1, 0, 2,
  131818. };
  131819. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  131820. _vq_quantthresh__44u0__p2_0,
  131821. _vq_quantmap__44u0__p2_0,
  131822. 3,
  131823. 3
  131824. };
  131825. static static_codebook _44u0__p2_0 = {
  131826. 4, 81,
  131827. _vq_lengthlist__44u0__p2_0,
  131828. 1, -535822336, 1611661312, 2, 0,
  131829. _vq_quantlist__44u0__p2_0,
  131830. NULL,
  131831. &_vq_auxt__44u0__p2_0,
  131832. NULL,
  131833. 0
  131834. };
  131835. static long _vq_quantlist__44u0__p3_0[] = {
  131836. 2,
  131837. 1,
  131838. 3,
  131839. 0,
  131840. 4,
  131841. };
  131842. static long _vq_lengthlist__44u0__p3_0[] = {
  131843. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  131844. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  131845. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  131846. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  131847. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  131848. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  131849. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  131850. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  131851. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  131852. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  131853. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  131854. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  131855. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  131856. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  131857. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  131858. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  131859. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  131860. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  131861. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  131862. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  131863. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  131864. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  131865. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  131866. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  131867. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  131868. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  131869. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  131870. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  131871. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  131872. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  131873. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  131874. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  131875. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  131876. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  131877. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  131878. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  131879. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  131880. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  131881. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  131882. 19,
  131883. };
  131884. static float _vq_quantthresh__44u0__p3_0[] = {
  131885. -1.5, -0.5, 0.5, 1.5,
  131886. };
  131887. static long _vq_quantmap__44u0__p3_0[] = {
  131888. 3, 1, 0, 2, 4,
  131889. };
  131890. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  131891. _vq_quantthresh__44u0__p3_0,
  131892. _vq_quantmap__44u0__p3_0,
  131893. 5,
  131894. 5
  131895. };
  131896. static static_codebook _44u0__p3_0 = {
  131897. 4, 625,
  131898. _vq_lengthlist__44u0__p3_0,
  131899. 1, -533725184, 1611661312, 3, 0,
  131900. _vq_quantlist__44u0__p3_0,
  131901. NULL,
  131902. &_vq_auxt__44u0__p3_0,
  131903. NULL,
  131904. 0
  131905. };
  131906. static long _vq_quantlist__44u0__p4_0[] = {
  131907. 2,
  131908. 1,
  131909. 3,
  131910. 0,
  131911. 4,
  131912. };
  131913. static long _vq_lengthlist__44u0__p4_0[] = {
  131914. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  131915. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  131916. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  131917. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  131918. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  131919. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  131920. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  131921. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  131922. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  131923. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  131924. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  131925. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  131926. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  131927. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  131928. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  131929. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  131930. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  131931. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  131932. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  131933. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  131934. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  131935. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  131936. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  131937. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  131938. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  131939. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  131940. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  131941. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  131942. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  131943. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  131944. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  131945. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  131946. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  131947. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  131948. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  131949. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  131950. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  131951. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  131952. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  131953. 12,
  131954. };
  131955. static float _vq_quantthresh__44u0__p4_0[] = {
  131956. -1.5, -0.5, 0.5, 1.5,
  131957. };
  131958. static long _vq_quantmap__44u0__p4_0[] = {
  131959. 3, 1, 0, 2, 4,
  131960. };
  131961. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  131962. _vq_quantthresh__44u0__p4_0,
  131963. _vq_quantmap__44u0__p4_0,
  131964. 5,
  131965. 5
  131966. };
  131967. static static_codebook _44u0__p4_0 = {
  131968. 4, 625,
  131969. _vq_lengthlist__44u0__p4_0,
  131970. 1, -533725184, 1611661312, 3, 0,
  131971. _vq_quantlist__44u0__p4_0,
  131972. NULL,
  131973. &_vq_auxt__44u0__p4_0,
  131974. NULL,
  131975. 0
  131976. };
  131977. static long _vq_quantlist__44u0__p5_0[] = {
  131978. 4,
  131979. 3,
  131980. 5,
  131981. 2,
  131982. 6,
  131983. 1,
  131984. 7,
  131985. 0,
  131986. 8,
  131987. };
  131988. static long _vq_lengthlist__44u0__p5_0[] = {
  131989. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  131990. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  131991. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  131992. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131993. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  131994. 12,
  131995. };
  131996. static float _vq_quantthresh__44u0__p5_0[] = {
  131997. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131998. };
  131999. static long _vq_quantmap__44u0__p5_0[] = {
  132000. 7, 5, 3, 1, 0, 2, 4, 6,
  132001. 8,
  132002. };
  132003. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  132004. _vq_quantthresh__44u0__p5_0,
  132005. _vq_quantmap__44u0__p5_0,
  132006. 9,
  132007. 9
  132008. };
  132009. static static_codebook _44u0__p5_0 = {
  132010. 2, 81,
  132011. _vq_lengthlist__44u0__p5_0,
  132012. 1, -531628032, 1611661312, 4, 0,
  132013. _vq_quantlist__44u0__p5_0,
  132014. NULL,
  132015. &_vq_auxt__44u0__p5_0,
  132016. NULL,
  132017. 0
  132018. };
  132019. static long _vq_quantlist__44u0__p6_0[] = {
  132020. 6,
  132021. 5,
  132022. 7,
  132023. 4,
  132024. 8,
  132025. 3,
  132026. 9,
  132027. 2,
  132028. 10,
  132029. 1,
  132030. 11,
  132031. 0,
  132032. 12,
  132033. };
  132034. static long _vq_lengthlist__44u0__p6_0[] = {
  132035. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132036. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132037. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132038. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132039. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132040. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132041. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132042. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132043. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132044. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132045. 15,17,16,17,18,17,17,18, 0,
  132046. };
  132047. static float _vq_quantthresh__44u0__p6_0[] = {
  132048. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132049. 12.5, 17.5, 22.5, 27.5,
  132050. };
  132051. static long _vq_quantmap__44u0__p6_0[] = {
  132052. 11, 9, 7, 5, 3, 1, 0, 2,
  132053. 4, 6, 8, 10, 12,
  132054. };
  132055. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  132056. _vq_quantthresh__44u0__p6_0,
  132057. _vq_quantmap__44u0__p6_0,
  132058. 13,
  132059. 13
  132060. };
  132061. static static_codebook _44u0__p6_0 = {
  132062. 2, 169,
  132063. _vq_lengthlist__44u0__p6_0,
  132064. 1, -526516224, 1616117760, 4, 0,
  132065. _vq_quantlist__44u0__p6_0,
  132066. NULL,
  132067. &_vq_auxt__44u0__p6_0,
  132068. NULL,
  132069. 0
  132070. };
  132071. static long _vq_quantlist__44u0__p6_1[] = {
  132072. 2,
  132073. 1,
  132074. 3,
  132075. 0,
  132076. 4,
  132077. };
  132078. static long _vq_lengthlist__44u0__p6_1[] = {
  132079. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132080. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132081. };
  132082. static float _vq_quantthresh__44u0__p6_1[] = {
  132083. -1.5, -0.5, 0.5, 1.5,
  132084. };
  132085. static long _vq_quantmap__44u0__p6_1[] = {
  132086. 3, 1, 0, 2, 4,
  132087. };
  132088. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  132089. _vq_quantthresh__44u0__p6_1,
  132090. _vq_quantmap__44u0__p6_1,
  132091. 5,
  132092. 5
  132093. };
  132094. static static_codebook _44u0__p6_1 = {
  132095. 2, 25,
  132096. _vq_lengthlist__44u0__p6_1,
  132097. 1, -533725184, 1611661312, 3, 0,
  132098. _vq_quantlist__44u0__p6_1,
  132099. NULL,
  132100. &_vq_auxt__44u0__p6_1,
  132101. NULL,
  132102. 0
  132103. };
  132104. static long _vq_quantlist__44u0__p7_0[] = {
  132105. 2,
  132106. 1,
  132107. 3,
  132108. 0,
  132109. 4,
  132110. };
  132111. static long _vq_lengthlist__44u0__p7_0[] = {
  132112. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  132113. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132114. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132115. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132116. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132117. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132118. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132119. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  132120. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132121. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132122. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132123. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132124. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132125. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132126. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132127. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132128. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132129. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132130. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132131. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132132. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132133. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132134. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132135. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132136. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132137. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132138. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132139. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132140. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132141. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132142. 11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,
  132143. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132144. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132145. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132146. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132147. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132148. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132149. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132150. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132151. 10,
  132152. };
  132153. static float _vq_quantthresh__44u0__p7_0[] = {
  132154. -253.5, -84.5, 84.5, 253.5,
  132155. };
  132156. static long _vq_quantmap__44u0__p7_0[] = {
  132157. 3, 1, 0, 2, 4,
  132158. };
  132159. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  132160. _vq_quantthresh__44u0__p7_0,
  132161. _vq_quantmap__44u0__p7_0,
  132162. 5,
  132163. 5
  132164. };
  132165. static static_codebook _44u0__p7_0 = {
  132166. 4, 625,
  132167. _vq_lengthlist__44u0__p7_0,
  132168. 1, -518709248, 1626677248, 3, 0,
  132169. _vq_quantlist__44u0__p7_0,
  132170. NULL,
  132171. &_vq_auxt__44u0__p7_0,
  132172. NULL,
  132173. 0
  132174. };
  132175. static long _vq_quantlist__44u0__p7_1[] = {
  132176. 6,
  132177. 5,
  132178. 7,
  132179. 4,
  132180. 8,
  132181. 3,
  132182. 9,
  132183. 2,
  132184. 10,
  132185. 1,
  132186. 11,
  132187. 0,
  132188. 12,
  132189. };
  132190. static long _vq_lengthlist__44u0__p7_1[] = {
  132191. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132192. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132193. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132194. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132195. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132196. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132197. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132198. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132199. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132200. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132201. 15,15,15,15,15,15,15,15,15,
  132202. };
  132203. static float _vq_quantthresh__44u0__p7_1[] = {
  132204. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132205. 32.5, 45.5, 58.5, 71.5,
  132206. };
  132207. static long _vq_quantmap__44u0__p7_1[] = {
  132208. 11, 9, 7, 5, 3, 1, 0, 2,
  132209. 4, 6, 8, 10, 12,
  132210. };
  132211. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  132212. _vq_quantthresh__44u0__p7_1,
  132213. _vq_quantmap__44u0__p7_1,
  132214. 13,
  132215. 13
  132216. };
  132217. static static_codebook _44u0__p7_1 = {
  132218. 2, 169,
  132219. _vq_lengthlist__44u0__p7_1,
  132220. 1, -523010048, 1618608128, 4, 0,
  132221. _vq_quantlist__44u0__p7_1,
  132222. NULL,
  132223. &_vq_auxt__44u0__p7_1,
  132224. NULL,
  132225. 0
  132226. };
  132227. static long _vq_quantlist__44u0__p7_2[] = {
  132228. 6,
  132229. 5,
  132230. 7,
  132231. 4,
  132232. 8,
  132233. 3,
  132234. 9,
  132235. 2,
  132236. 10,
  132237. 1,
  132238. 11,
  132239. 0,
  132240. 12,
  132241. };
  132242. static long _vq_lengthlist__44u0__p7_2[] = {
  132243. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132244. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132245. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132246. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132247. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132248. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132249. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132250. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132251. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132252. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132253. 9, 9, 9,10, 9, 9,10,10, 9,
  132254. };
  132255. static float _vq_quantthresh__44u0__p7_2[] = {
  132256. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132257. 2.5, 3.5, 4.5, 5.5,
  132258. };
  132259. static long _vq_quantmap__44u0__p7_2[] = {
  132260. 11, 9, 7, 5, 3, 1, 0, 2,
  132261. 4, 6, 8, 10, 12,
  132262. };
  132263. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  132264. _vq_quantthresh__44u0__p7_2,
  132265. _vq_quantmap__44u0__p7_2,
  132266. 13,
  132267. 13
  132268. };
  132269. static static_codebook _44u0__p7_2 = {
  132270. 2, 169,
  132271. _vq_lengthlist__44u0__p7_2,
  132272. 1, -531103744, 1611661312, 4, 0,
  132273. _vq_quantlist__44u0__p7_2,
  132274. NULL,
  132275. &_vq_auxt__44u0__p7_2,
  132276. NULL,
  132277. 0
  132278. };
  132279. static long _huff_lengthlist__44u0__short[] = {
  132280. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132281. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132282. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132283. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132284. };
  132285. static static_codebook _huff_book__44u0__short = {
  132286. 2, 64,
  132287. _huff_lengthlist__44u0__short,
  132288. 0, 0, 0, 0, 0,
  132289. NULL,
  132290. NULL,
  132291. NULL,
  132292. NULL,
  132293. 0
  132294. };
  132295. static long _huff_lengthlist__44u1__long[] = {
  132296. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132297. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132298. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132299. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132300. };
  132301. static static_codebook _huff_book__44u1__long = {
  132302. 2, 64,
  132303. _huff_lengthlist__44u1__long,
  132304. 0, 0, 0, 0, 0,
  132305. NULL,
  132306. NULL,
  132307. NULL,
  132308. NULL,
  132309. 0
  132310. };
  132311. static long _vq_quantlist__44u1__p1_0[] = {
  132312. 1,
  132313. 0,
  132314. 2,
  132315. };
  132316. static long _vq_lengthlist__44u1__p1_0[] = {
  132317. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132318. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132319. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132320. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132321. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132322. 13,
  132323. };
  132324. static float _vq_quantthresh__44u1__p1_0[] = {
  132325. -0.5, 0.5,
  132326. };
  132327. static long _vq_quantmap__44u1__p1_0[] = {
  132328. 1, 0, 2,
  132329. };
  132330. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132331. _vq_quantthresh__44u1__p1_0,
  132332. _vq_quantmap__44u1__p1_0,
  132333. 3,
  132334. 3
  132335. };
  132336. static static_codebook _44u1__p1_0 = {
  132337. 4, 81,
  132338. _vq_lengthlist__44u1__p1_0,
  132339. 1, -535822336, 1611661312, 2, 0,
  132340. _vq_quantlist__44u1__p1_0,
  132341. NULL,
  132342. &_vq_auxt__44u1__p1_0,
  132343. NULL,
  132344. 0
  132345. };
  132346. static long _vq_quantlist__44u1__p2_0[] = {
  132347. 1,
  132348. 0,
  132349. 2,
  132350. };
  132351. static long _vq_lengthlist__44u1__p2_0[] = {
  132352. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132353. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132354. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132355. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132356. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132357. 9,
  132358. };
  132359. static float _vq_quantthresh__44u1__p2_0[] = {
  132360. -0.5, 0.5,
  132361. };
  132362. static long _vq_quantmap__44u1__p2_0[] = {
  132363. 1, 0, 2,
  132364. };
  132365. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132366. _vq_quantthresh__44u1__p2_0,
  132367. _vq_quantmap__44u1__p2_0,
  132368. 3,
  132369. 3
  132370. };
  132371. static static_codebook _44u1__p2_0 = {
  132372. 4, 81,
  132373. _vq_lengthlist__44u1__p2_0,
  132374. 1, -535822336, 1611661312, 2, 0,
  132375. _vq_quantlist__44u1__p2_0,
  132376. NULL,
  132377. &_vq_auxt__44u1__p2_0,
  132378. NULL,
  132379. 0
  132380. };
  132381. static long _vq_quantlist__44u1__p3_0[] = {
  132382. 2,
  132383. 1,
  132384. 3,
  132385. 0,
  132386. 4,
  132387. };
  132388. static long _vq_lengthlist__44u1__p3_0[] = {
  132389. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132390. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132391. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132392. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132393. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132394. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132395. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132396. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132397. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132398. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132399. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132400. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132401. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132402. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132403. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132404. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132405. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132406. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132407. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132408. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132409. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132410. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132411. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132412. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132413. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132414. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132415. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132416. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132417. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132418. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132419. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132420. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132421. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132422. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132423. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132424. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132425. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132426. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132427. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132428. 19,
  132429. };
  132430. static float _vq_quantthresh__44u1__p3_0[] = {
  132431. -1.5, -0.5, 0.5, 1.5,
  132432. };
  132433. static long _vq_quantmap__44u1__p3_0[] = {
  132434. 3, 1, 0, 2, 4,
  132435. };
  132436. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132437. _vq_quantthresh__44u1__p3_0,
  132438. _vq_quantmap__44u1__p3_0,
  132439. 5,
  132440. 5
  132441. };
  132442. static static_codebook _44u1__p3_0 = {
  132443. 4, 625,
  132444. _vq_lengthlist__44u1__p3_0,
  132445. 1, -533725184, 1611661312, 3, 0,
  132446. _vq_quantlist__44u1__p3_0,
  132447. NULL,
  132448. &_vq_auxt__44u1__p3_0,
  132449. NULL,
  132450. 0
  132451. };
  132452. static long _vq_quantlist__44u1__p4_0[] = {
  132453. 2,
  132454. 1,
  132455. 3,
  132456. 0,
  132457. 4,
  132458. };
  132459. static long _vq_lengthlist__44u1__p4_0[] = {
  132460. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132461. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132462. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132463. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132464. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132465. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132466. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132467. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132468. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132469. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132470. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132471. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132472. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132473. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132474. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132475. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132476. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132477. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132478. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132479. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132480. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132481. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132482. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132483. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132484. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132485. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132486. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132487. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132488. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132489. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132490. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132491. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132492. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132493. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132494. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132495. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132496. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132497. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132498. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132499. 12,
  132500. };
  132501. static float _vq_quantthresh__44u1__p4_0[] = {
  132502. -1.5, -0.5, 0.5, 1.5,
  132503. };
  132504. static long _vq_quantmap__44u1__p4_0[] = {
  132505. 3, 1, 0, 2, 4,
  132506. };
  132507. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132508. _vq_quantthresh__44u1__p4_0,
  132509. _vq_quantmap__44u1__p4_0,
  132510. 5,
  132511. 5
  132512. };
  132513. static static_codebook _44u1__p4_0 = {
  132514. 4, 625,
  132515. _vq_lengthlist__44u1__p4_0,
  132516. 1, -533725184, 1611661312, 3, 0,
  132517. _vq_quantlist__44u1__p4_0,
  132518. NULL,
  132519. &_vq_auxt__44u1__p4_0,
  132520. NULL,
  132521. 0
  132522. };
  132523. static long _vq_quantlist__44u1__p5_0[] = {
  132524. 4,
  132525. 3,
  132526. 5,
  132527. 2,
  132528. 6,
  132529. 1,
  132530. 7,
  132531. 0,
  132532. 8,
  132533. };
  132534. static long _vq_lengthlist__44u1__p5_0[] = {
  132535. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132536. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132537. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132538. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132539. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132540. 12,
  132541. };
  132542. static float _vq_quantthresh__44u1__p5_0[] = {
  132543. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132544. };
  132545. static long _vq_quantmap__44u1__p5_0[] = {
  132546. 7, 5, 3, 1, 0, 2, 4, 6,
  132547. 8,
  132548. };
  132549. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132550. _vq_quantthresh__44u1__p5_0,
  132551. _vq_quantmap__44u1__p5_0,
  132552. 9,
  132553. 9
  132554. };
  132555. static static_codebook _44u1__p5_0 = {
  132556. 2, 81,
  132557. _vq_lengthlist__44u1__p5_0,
  132558. 1, -531628032, 1611661312, 4, 0,
  132559. _vq_quantlist__44u1__p5_0,
  132560. NULL,
  132561. &_vq_auxt__44u1__p5_0,
  132562. NULL,
  132563. 0
  132564. };
  132565. static long _vq_quantlist__44u1__p6_0[] = {
  132566. 6,
  132567. 5,
  132568. 7,
  132569. 4,
  132570. 8,
  132571. 3,
  132572. 9,
  132573. 2,
  132574. 10,
  132575. 1,
  132576. 11,
  132577. 0,
  132578. 12,
  132579. };
  132580. static long _vq_lengthlist__44u1__p6_0[] = {
  132581. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132582. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132583. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132584. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132585. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132586. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132587. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132588. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132589. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132590. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132591. 15,17,16,17,18,17,17,18, 0,
  132592. };
  132593. static float _vq_quantthresh__44u1__p6_0[] = {
  132594. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132595. 12.5, 17.5, 22.5, 27.5,
  132596. };
  132597. static long _vq_quantmap__44u1__p6_0[] = {
  132598. 11, 9, 7, 5, 3, 1, 0, 2,
  132599. 4, 6, 8, 10, 12,
  132600. };
  132601. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132602. _vq_quantthresh__44u1__p6_0,
  132603. _vq_quantmap__44u1__p6_0,
  132604. 13,
  132605. 13
  132606. };
  132607. static static_codebook _44u1__p6_0 = {
  132608. 2, 169,
  132609. _vq_lengthlist__44u1__p6_0,
  132610. 1, -526516224, 1616117760, 4, 0,
  132611. _vq_quantlist__44u1__p6_0,
  132612. NULL,
  132613. &_vq_auxt__44u1__p6_0,
  132614. NULL,
  132615. 0
  132616. };
  132617. static long _vq_quantlist__44u1__p6_1[] = {
  132618. 2,
  132619. 1,
  132620. 3,
  132621. 0,
  132622. 4,
  132623. };
  132624. static long _vq_lengthlist__44u1__p6_1[] = {
  132625. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132626. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132627. };
  132628. static float _vq_quantthresh__44u1__p6_1[] = {
  132629. -1.5, -0.5, 0.5, 1.5,
  132630. };
  132631. static long _vq_quantmap__44u1__p6_1[] = {
  132632. 3, 1, 0, 2, 4,
  132633. };
  132634. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132635. _vq_quantthresh__44u1__p6_1,
  132636. _vq_quantmap__44u1__p6_1,
  132637. 5,
  132638. 5
  132639. };
  132640. static static_codebook _44u1__p6_1 = {
  132641. 2, 25,
  132642. _vq_lengthlist__44u1__p6_1,
  132643. 1, -533725184, 1611661312, 3, 0,
  132644. _vq_quantlist__44u1__p6_1,
  132645. NULL,
  132646. &_vq_auxt__44u1__p6_1,
  132647. NULL,
  132648. 0
  132649. };
  132650. static long _vq_quantlist__44u1__p7_0[] = {
  132651. 3,
  132652. 2,
  132653. 4,
  132654. 1,
  132655. 5,
  132656. 0,
  132657. 6,
  132658. };
  132659. static long _vq_lengthlist__44u1__p7_0[] = {
  132660. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132661. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132662. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132663. 8,
  132664. };
  132665. static float _vq_quantthresh__44u1__p7_0[] = {
  132666. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132667. };
  132668. static long _vq_quantmap__44u1__p7_0[] = {
  132669. 5, 3, 1, 0, 2, 4, 6,
  132670. };
  132671. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  132672. _vq_quantthresh__44u1__p7_0,
  132673. _vq_quantmap__44u1__p7_0,
  132674. 7,
  132675. 7
  132676. };
  132677. static static_codebook _44u1__p7_0 = {
  132678. 2, 49,
  132679. _vq_lengthlist__44u1__p7_0,
  132680. 1, -518017024, 1626677248, 3, 0,
  132681. _vq_quantlist__44u1__p7_0,
  132682. NULL,
  132683. &_vq_auxt__44u1__p7_0,
  132684. NULL,
  132685. 0
  132686. };
  132687. static long _vq_quantlist__44u1__p7_1[] = {
  132688. 6,
  132689. 5,
  132690. 7,
  132691. 4,
  132692. 8,
  132693. 3,
  132694. 9,
  132695. 2,
  132696. 10,
  132697. 1,
  132698. 11,
  132699. 0,
  132700. 12,
  132701. };
  132702. static long _vq_lengthlist__44u1__p7_1[] = {
  132703. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132704. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132705. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132706. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132707. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132708. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132709. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132710. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132711. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132712. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132713. 15,15,15,15,15,15,15,15,15,
  132714. };
  132715. static float _vq_quantthresh__44u1__p7_1[] = {
  132716. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132717. 32.5, 45.5, 58.5, 71.5,
  132718. };
  132719. static long _vq_quantmap__44u1__p7_1[] = {
  132720. 11, 9, 7, 5, 3, 1, 0, 2,
  132721. 4, 6, 8, 10, 12,
  132722. };
  132723. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  132724. _vq_quantthresh__44u1__p7_1,
  132725. _vq_quantmap__44u1__p7_1,
  132726. 13,
  132727. 13
  132728. };
  132729. static static_codebook _44u1__p7_1 = {
  132730. 2, 169,
  132731. _vq_lengthlist__44u1__p7_1,
  132732. 1, -523010048, 1618608128, 4, 0,
  132733. _vq_quantlist__44u1__p7_1,
  132734. NULL,
  132735. &_vq_auxt__44u1__p7_1,
  132736. NULL,
  132737. 0
  132738. };
  132739. static long _vq_quantlist__44u1__p7_2[] = {
  132740. 6,
  132741. 5,
  132742. 7,
  132743. 4,
  132744. 8,
  132745. 3,
  132746. 9,
  132747. 2,
  132748. 10,
  132749. 1,
  132750. 11,
  132751. 0,
  132752. 12,
  132753. };
  132754. static long _vq_lengthlist__44u1__p7_2[] = {
  132755. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132756. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132757. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132758. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132759. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132760. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132761. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132762. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132763. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132764. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132765. 9, 9, 9,10, 9, 9,10,10, 9,
  132766. };
  132767. static float _vq_quantthresh__44u1__p7_2[] = {
  132768. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132769. 2.5, 3.5, 4.5, 5.5,
  132770. };
  132771. static long _vq_quantmap__44u1__p7_2[] = {
  132772. 11, 9, 7, 5, 3, 1, 0, 2,
  132773. 4, 6, 8, 10, 12,
  132774. };
  132775. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  132776. _vq_quantthresh__44u1__p7_2,
  132777. _vq_quantmap__44u1__p7_2,
  132778. 13,
  132779. 13
  132780. };
  132781. static static_codebook _44u1__p7_2 = {
  132782. 2, 169,
  132783. _vq_lengthlist__44u1__p7_2,
  132784. 1, -531103744, 1611661312, 4, 0,
  132785. _vq_quantlist__44u1__p7_2,
  132786. NULL,
  132787. &_vq_auxt__44u1__p7_2,
  132788. NULL,
  132789. 0
  132790. };
  132791. static long _huff_lengthlist__44u1__short[] = {
  132792. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132793. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132794. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132795. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132796. };
  132797. static static_codebook _huff_book__44u1__short = {
  132798. 2, 64,
  132799. _huff_lengthlist__44u1__short,
  132800. 0, 0, 0, 0, 0,
  132801. NULL,
  132802. NULL,
  132803. NULL,
  132804. NULL,
  132805. 0
  132806. };
  132807. static long _huff_lengthlist__44u2__long[] = {
  132808. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  132809. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  132810. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  132811. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  132812. };
  132813. static static_codebook _huff_book__44u2__long = {
  132814. 2, 64,
  132815. _huff_lengthlist__44u2__long,
  132816. 0, 0, 0, 0, 0,
  132817. NULL,
  132818. NULL,
  132819. NULL,
  132820. NULL,
  132821. 0
  132822. };
  132823. static long _vq_quantlist__44u2__p1_0[] = {
  132824. 1,
  132825. 0,
  132826. 2,
  132827. };
  132828. static long _vq_lengthlist__44u2__p1_0[] = {
  132829. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132830. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132831. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  132832. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  132833. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  132834. 13,
  132835. };
  132836. static float _vq_quantthresh__44u2__p1_0[] = {
  132837. -0.5, 0.5,
  132838. };
  132839. static long _vq_quantmap__44u2__p1_0[] = {
  132840. 1, 0, 2,
  132841. };
  132842. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  132843. _vq_quantthresh__44u2__p1_0,
  132844. _vq_quantmap__44u2__p1_0,
  132845. 3,
  132846. 3
  132847. };
  132848. static static_codebook _44u2__p1_0 = {
  132849. 4, 81,
  132850. _vq_lengthlist__44u2__p1_0,
  132851. 1, -535822336, 1611661312, 2, 0,
  132852. _vq_quantlist__44u2__p1_0,
  132853. NULL,
  132854. &_vq_auxt__44u2__p1_0,
  132855. NULL,
  132856. 0
  132857. };
  132858. static long _vq_quantlist__44u2__p2_0[] = {
  132859. 1,
  132860. 0,
  132861. 2,
  132862. };
  132863. static long _vq_lengthlist__44u2__p2_0[] = {
  132864. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  132865. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  132866. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132867. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  132868. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132869. 9,
  132870. };
  132871. static float _vq_quantthresh__44u2__p2_0[] = {
  132872. -0.5, 0.5,
  132873. };
  132874. static long _vq_quantmap__44u2__p2_0[] = {
  132875. 1, 0, 2,
  132876. };
  132877. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  132878. _vq_quantthresh__44u2__p2_0,
  132879. _vq_quantmap__44u2__p2_0,
  132880. 3,
  132881. 3
  132882. };
  132883. static static_codebook _44u2__p2_0 = {
  132884. 4, 81,
  132885. _vq_lengthlist__44u2__p2_0,
  132886. 1, -535822336, 1611661312, 2, 0,
  132887. _vq_quantlist__44u2__p2_0,
  132888. NULL,
  132889. &_vq_auxt__44u2__p2_0,
  132890. NULL,
  132891. 0
  132892. };
  132893. static long _vq_quantlist__44u2__p3_0[] = {
  132894. 2,
  132895. 1,
  132896. 3,
  132897. 0,
  132898. 4,
  132899. };
  132900. static long _vq_lengthlist__44u2__p3_0[] = {
  132901. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  132902. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  132903. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  132904. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  132905. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  132906. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  132907. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  132908. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  132909. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  132910. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  132911. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  132912. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  132913. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  132914. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  132915. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  132916. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  132917. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  132918. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  132919. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  132920. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  132921. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  132922. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  132923. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  132924. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  132925. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  132926. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  132927. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  132928. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  132929. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  132930. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  132931. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  132932. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  132933. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  132934. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  132935. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  132936. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  132937. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  132938. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  132939. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  132940. 0,
  132941. };
  132942. static float _vq_quantthresh__44u2__p3_0[] = {
  132943. -1.5, -0.5, 0.5, 1.5,
  132944. };
  132945. static long _vq_quantmap__44u2__p3_0[] = {
  132946. 3, 1, 0, 2, 4,
  132947. };
  132948. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  132949. _vq_quantthresh__44u2__p3_0,
  132950. _vq_quantmap__44u2__p3_0,
  132951. 5,
  132952. 5
  132953. };
  132954. static static_codebook _44u2__p3_0 = {
  132955. 4, 625,
  132956. _vq_lengthlist__44u2__p3_0,
  132957. 1, -533725184, 1611661312, 3, 0,
  132958. _vq_quantlist__44u2__p3_0,
  132959. NULL,
  132960. &_vq_auxt__44u2__p3_0,
  132961. NULL,
  132962. 0
  132963. };
  132964. static long _vq_quantlist__44u2__p4_0[] = {
  132965. 2,
  132966. 1,
  132967. 3,
  132968. 0,
  132969. 4,
  132970. };
  132971. static long _vq_lengthlist__44u2__p4_0[] = {
  132972. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  132973. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  132974. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  132975. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  132976. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  132977. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  132978. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  132979. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  132980. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  132981. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  132982. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  132983. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132984. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  132985. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  132986. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  132987. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  132988. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  132989. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  132990. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  132991. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  132992. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  132993. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  132994. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  132995. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  132996. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  132997. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  132998. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  132999. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  133000. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133001. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  133002. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  133003. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  133004. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  133005. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133006. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133007. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  133008. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133009. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  133010. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  133011. 13,
  133012. };
  133013. static float _vq_quantthresh__44u2__p4_0[] = {
  133014. -1.5, -0.5, 0.5, 1.5,
  133015. };
  133016. static long _vq_quantmap__44u2__p4_0[] = {
  133017. 3, 1, 0, 2, 4,
  133018. };
  133019. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  133020. _vq_quantthresh__44u2__p4_0,
  133021. _vq_quantmap__44u2__p4_0,
  133022. 5,
  133023. 5
  133024. };
  133025. static static_codebook _44u2__p4_0 = {
  133026. 4, 625,
  133027. _vq_lengthlist__44u2__p4_0,
  133028. 1, -533725184, 1611661312, 3, 0,
  133029. _vq_quantlist__44u2__p4_0,
  133030. NULL,
  133031. &_vq_auxt__44u2__p4_0,
  133032. NULL,
  133033. 0
  133034. };
  133035. static long _vq_quantlist__44u2__p5_0[] = {
  133036. 4,
  133037. 3,
  133038. 5,
  133039. 2,
  133040. 6,
  133041. 1,
  133042. 7,
  133043. 0,
  133044. 8,
  133045. };
  133046. static long _vq_lengthlist__44u2__p5_0[] = {
  133047. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  133048. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  133049. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  133050. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  133051. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  133052. 13,
  133053. };
  133054. static float _vq_quantthresh__44u2__p5_0[] = {
  133055. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133056. };
  133057. static long _vq_quantmap__44u2__p5_0[] = {
  133058. 7, 5, 3, 1, 0, 2, 4, 6,
  133059. 8,
  133060. };
  133061. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  133062. _vq_quantthresh__44u2__p5_0,
  133063. _vq_quantmap__44u2__p5_0,
  133064. 9,
  133065. 9
  133066. };
  133067. static static_codebook _44u2__p5_0 = {
  133068. 2, 81,
  133069. _vq_lengthlist__44u2__p5_0,
  133070. 1, -531628032, 1611661312, 4, 0,
  133071. _vq_quantlist__44u2__p5_0,
  133072. NULL,
  133073. &_vq_auxt__44u2__p5_0,
  133074. NULL,
  133075. 0
  133076. };
  133077. static long _vq_quantlist__44u2__p6_0[] = {
  133078. 6,
  133079. 5,
  133080. 7,
  133081. 4,
  133082. 8,
  133083. 3,
  133084. 9,
  133085. 2,
  133086. 10,
  133087. 1,
  133088. 11,
  133089. 0,
  133090. 12,
  133091. };
  133092. static long _vq_lengthlist__44u2__p6_0[] = {
  133093. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  133094. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  133095. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  133096. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  133097. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  133098. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  133099. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  133100. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  133101. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  133102. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  133103. 15,17,17,16,18,17,18, 0, 0,
  133104. };
  133105. static float _vq_quantthresh__44u2__p6_0[] = {
  133106. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133107. 12.5, 17.5, 22.5, 27.5,
  133108. };
  133109. static long _vq_quantmap__44u2__p6_0[] = {
  133110. 11, 9, 7, 5, 3, 1, 0, 2,
  133111. 4, 6, 8, 10, 12,
  133112. };
  133113. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  133114. _vq_quantthresh__44u2__p6_0,
  133115. _vq_quantmap__44u2__p6_0,
  133116. 13,
  133117. 13
  133118. };
  133119. static static_codebook _44u2__p6_0 = {
  133120. 2, 169,
  133121. _vq_lengthlist__44u2__p6_0,
  133122. 1, -526516224, 1616117760, 4, 0,
  133123. _vq_quantlist__44u2__p6_0,
  133124. NULL,
  133125. &_vq_auxt__44u2__p6_0,
  133126. NULL,
  133127. 0
  133128. };
  133129. static long _vq_quantlist__44u2__p6_1[] = {
  133130. 2,
  133131. 1,
  133132. 3,
  133133. 0,
  133134. 4,
  133135. };
  133136. static long _vq_lengthlist__44u2__p6_1[] = {
  133137. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133138. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133139. };
  133140. static float _vq_quantthresh__44u2__p6_1[] = {
  133141. -1.5, -0.5, 0.5, 1.5,
  133142. };
  133143. static long _vq_quantmap__44u2__p6_1[] = {
  133144. 3, 1, 0, 2, 4,
  133145. };
  133146. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  133147. _vq_quantthresh__44u2__p6_1,
  133148. _vq_quantmap__44u2__p6_1,
  133149. 5,
  133150. 5
  133151. };
  133152. static static_codebook _44u2__p6_1 = {
  133153. 2, 25,
  133154. _vq_lengthlist__44u2__p6_1,
  133155. 1, -533725184, 1611661312, 3, 0,
  133156. _vq_quantlist__44u2__p6_1,
  133157. NULL,
  133158. &_vq_auxt__44u2__p6_1,
  133159. NULL,
  133160. 0
  133161. };
  133162. static long _vq_quantlist__44u2__p7_0[] = {
  133163. 4,
  133164. 3,
  133165. 5,
  133166. 2,
  133167. 6,
  133168. 1,
  133169. 7,
  133170. 0,
  133171. 8,
  133172. };
  133173. static long _vq_lengthlist__44u2__p7_0[] = {
  133174. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  133175. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  133176. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133177. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133178. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133179. 11,
  133180. };
  133181. static float _vq_quantthresh__44u2__p7_0[] = {
  133182. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  133183. };
  133184. static long _vq_quantmap__44u2__p7_0[] = {
  133185. 7, 5, 3, 1, 0, 2, 4, 6,
  133186. 8,
  133187. };
  133188. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  133189. _vq_quantthresh__44u2__p7_0,
  133190. _vq_quantmap__44u2__p7_0,
  133191. 9,
  133192. 9
  133193. };
  133194. static static_codebook _44u2__p7_0 = {
  133195. 2, 81,
  133196. _vq_lengthlist__44u2__p7_0,
  133197. 1, -516612096, 1626677248, 4, 0,
  133198. _vq_quantlist__44u2__p7_0,
  133199. NULL,
  133200. &_vq_auxt__44u2__p7_0,
  133201. NULL,
  133202. 0
  133203. };
  133204. static long _vq_quantlist__44u2__p7_1[] = {
  133205. 6,
  133206. 5,
  133207. 7,
  133208. 4,
  133209. 8,
  133210. 3,
  133211. 9,
  133212. 2,
  133213. 10,
  133214. 1,
  133215. 11,
  133216. 0,
  133217. 12,
  133218. };
  133219. static long _vq_lengthlist__44u2__p7_1[] = {
  133220. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  133221. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  133222. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  133223. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  133224. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  133225. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  133226. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  133227. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  133228. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  133229. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  133230. 14,14,14,17,15,17,17,17,17,
  133231. };
  133232. static float _vq_quantthresh__44u2__p7_1[] = {
  133233. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133234. 32.5, 45.5, 58.5, 71.5,
  133235. };
  133236. static long _vq_quantmap__44u2__p7_1[] = {
  133237. 11, 9, 7, 5, 3, 1, 0, 2,
  133238. 4, 6, 8, 10, 12,
  133239. };
  133240. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  133241. _vq_quantthresh__44u2__p7_1,
  133242. _vq_quantmap__44u2__p7_1,
  133243. 13,
  133244. 13
  133245. };
  133246. static static_codebook _44u2__p7_1 = {
  133247. 2, 169,
  133248. _vq_lengthlist__44u2__p7_1,
  133249. 1, -523010048, 1618608128, 4, 0,
  133250. _vq_quantlist__44u2__p7_1,
  133251. NULL,
  133252. &_vq_auxt__44u2__p7_1,
  133253. NULL,
  133254. 0
  133255. };
  133256. static long _vq_quantlist__44u2__p7_2[] = {
  133257. 6,
  133258. 5,
  133259. 7,
  133260. 4,
  133261. 8,
  133262. 3,
  133263. 9,
  133264. 2,
  133265. 10,
  133266. 1,
  133267. 11,
  133268. 0,
  133269. 12,
  133270. };
  133271. static long _vq_lengthlist__44u2__p7_2[] = {
  133272. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  133273. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  133274. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  133275. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133276. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  133277. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  133278. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  133279. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133280. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  133281. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  133282. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133283. };
  133284. static float _vq_quantthresh__44u2__p7_2[] = {
  133285. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133286. 2.5, 3.5, 4.5, 5.5,
  133287. };
  133288. static long _vq_quantmap__44u2__p7_2[] = {
  133289. 11, 9, 7, 5, 3, 1, 0, 2,
  133290. 4, 6, 8, 10, 12,
  133291. };
  133292. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133293. _vq_quantthresh__44u2__p7_2,
  133294. _vq_quantmap__44u2__p7_2,
  133295. 13,
  133296. 13
  133297. };
  133298. static static_codebook _44u2__p7_2 = {
  133299. 2, 169,
  133300. _vq_lengthlist__44u2__p7_2,
  133301. 1, -531103744, 1611661312, 4, 0,
  133302. _vq_quantlist__44u2__p7_2,
  133303. NULL,
  133304. &_vq_auxt__44u2__p7_2,
  133305. NULL,
  133306. 0
  133307. };
  133308. static long _huff_lengthlist__44u2__short[] = {
  133309. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133310. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133311. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133312. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133313. };
  133314. static static_codebook _huff_book__44u2__short = {
  133315. 2, 64,
  133316. _huff_lengthlist__44u2__short,
  133317. 0, 0, 0, 0, 0,
  133318. NULL,
  133319. NULL,
  133320. NULL,
  133321. NULL,
  133322. 0
  133323. };
  133324. static long _huff_lengthlist__44u3__long[] = {
  133325. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133326. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133327. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133328. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133329. };
  133330. static static_codebook _huff_book__44u3__long = {
  133331. 2, 64,
  133332. _huff_lengthlist__44u3__long,
  133333. 0, 0, 0, 0, 0,
  133334. NULL,
  133335. NULL,
  133336. NULL,
  133337. NULL,
  133338. 0
  133339. };
  133340. static long _vq_quantlist__44u3__p1_0[] = {
  133341. 1,
  133342. 0,
  133343. 2,
  133344. };
  133345. static long _vq_lengthlist__44u3__p1_0[] = {
  133346. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133347. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133348. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133349. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133350. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133351. 13,
  133352. };
  133353. static float _vq_quantthresh__44u3__p1_0[] = {
  133354. -0.5, 0.5,
  133355. };
  133356. static long _vq_quantmap__44u3__p1_0[] = {
  133357. 1, 0, 2,
  133358. };
  133359. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133360. _vq_quantthresh__44u3__p1_0,
  133361. _vq_quantmap__44u3__p1_0,
  133362. 3,
  133363. 3
  133364. };
  133365. static static_codebook _44u3__p1_0 = {
  133366. 4, 81,
  133367. _vq_lengthlist__44u3__p1_0,
  133368. 1, -535822336, 1611661312, 2, 0,
  133369. _vq_quantlist__44u3__p1_0,
  133370. NULL,
  133371. &_vq_auxt__44u3__p1_0,
  133372. NULL,
  133373. 0
  133374. };
  133375. static long _vq_quantlist__44u3__p2_0[] = {
  133376. 1,
  133377. 0,
  133378. 2,
  133379. };
  133380. static long _vq_lengthlist__44u3__p2_0[] = {
  133381. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133382. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  133383. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133384. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133385. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  133386. 9,
  133387. };
  133388. static float _vq_quantthresh__44u3__p2_0[] = {
  133389. -0.5, 0.5,
  133390. };
  133391. static long _vq_quantmap__44u3__p2_0[] = {
  133392. 1, 0, 2,
  133393. };
  133394. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133395. _vq_quantthresh__44u3__p2_0,
  133396. _vq_quantmap__44u3__p2_0,
  133397. 3,
  133398. 3
  133399. };
  133400. static static_codebook _44u3__p2_0 = {
  133401. 4, 81,
  133402. _vq_lengthlist__44u3__p2_0,
  133403. 1, -535822336, 1611661312, 2, 0,
  133404. _vq_quantlist__44u3__p2_0,
  133405. NULL,
  133406. &_vq_auxt__44u3__p2_0,
  133407. NULL,
  133408. 0
  133409. };
  133410. static long _vq_quantlist__44u3__p3_0[] = {
  133411. 2,
  133412. 1,
  133413. 3,
  133414. 0,
  133415. 4,
  133416. };
  133417. static long _vq_lengthlist__44u3__p3_0[] = {
  133418. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133419. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133420. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133421. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133422. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133423. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133424. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133425. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133426. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133427. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133428. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133429. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133430. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133431. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133432. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133433. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133434. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133435. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133436. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133437. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133438. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133439. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133440. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133441. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133442. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133443. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133444. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133445. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133446. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133447. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133448. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133449. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133450. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133451. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133452. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133453. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133454. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133455. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133456. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133457. 0,
  133458. };
  133459. static float _vq_quantthresh__44u3__p3_0[] = {
  133460. -1.5, -0.5, 0.5, 1.5,
  133461. };
  133462. static long _vq_quantmap__44u3__p3_0[] = {
  133463. 3, 1, 0, 2, 4,
  133464. };
  133465. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133466. _vq_quantthresh__44u3__p3_0,
  133467. _vq_quantmap__44u3__p3_0,
  133468. 5,
  133469. 5
  133470. };
  133471. static static_codebook _44u3__p3_0 = {
  133472. 4, 625,
  133473. _vq_lengthlist__44u3__p3_0,
  133474. 1, -533725184, 1611661312, 3, 0,
  133475. _vq_quantlist__44u3__p3_0,
  133476. NULL,
  133477. &_vq_auxt__44u3__p3_0,
  133478. NULL,
  133479. 0
  133480. };
  133481. static long _vq_quantlist__44u3__p4_0[] = {
  133482. 2,
  133483. 1,
  133484. 3,
  133485. 0,
  133486. 4,
  133487. };
  133488. static long _vq_lengthlist__44u3__p4_0[] = {
  133489. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133490. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133491. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133492. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133493. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133494. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133495. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133496. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133497. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133498. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133499. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133500. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133501. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133502. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133503. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133504. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133505. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133506. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133507. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133508. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133509. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133510. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133511. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133512. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133513. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133514. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133515. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133516. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133517. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133518. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133519. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133520. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133521. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133522. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133523. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133524. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133525. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133526. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133527. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133528. 13,
  133529. };
  133530. static float _vq_quantthresh__44u3__p4_0[] = {
  133531. -1.5, -0.5, 0.5, 1.5,
  133532. };
  133533. static long _vq_quantmap__44u3__p4_0[] = {
  133534. 3, 1, 0, 2, 4,
  133535. };
  133536. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133537. _vq_quantthresh__44u3__p4_0,
  133538. _vq_quantmap__44u3__p4_0,
  133539. 5,
  133540. 5
  133541. };
  133542. static static_codebook _44u3__p4_0 = {
  133543. 4, 625,
  133544. _vq_lengthlist__44u3__p4_0,
  133545. 1, -533725184, 1611661312, 3, 0,
  133546. _vq_quantlist__44u3__p4_0,
  133547. NULL,
  133548. &_vq_auxt__44u3__p4_0,
  133549. NULL,
  133550. 0
  133551. };
  133552. static long _vq_quantlist__44u3__p5_0[] = {
  133553. 4,
  133554. 3,
  133555. 5,
  133556. 2,
  133557. 6,
  133558. 1,
  133559. 7,
  133560. 0,
  133561. 8,
  133562. };
  133563. static long _vq_lengthlist__44u3__p5_0[] = {
  133564. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133565. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133566. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133567. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133568. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133569. 12,
  133570. };
  133571. static float _vq_quantthresh__44u3__p5_0[] = {
  133572. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133573. };
  133574. static long _vq_quantmap__44u3__p5_0[] = {
  133575. 7, 5, 3, 1, 0, 2, 4, 6,
  133576. 8,
  133577. };
  133578. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133579. _vq_quantthresh__44u3__p5_0,
  133580. _vq_quantmap__44u3__p5_0,
  133581. 9,
  133582. 9
  133583. };
  133584. static static_codebook _44u3__p5_0 = {
  133585. 2, 81,
  133586. _vq_lengthlist__44u3__p5_0,
  133587. 1, -531628032, 1611661312, 4, 0,
  133588. _vq_quantlist__44u3__p5_0,
  133589. NULL,
  133590. &_vq_auxt__44u3__p5_0,
  133591. NULL,
  133592. 0
  133593. };
  133594. static long _vq_quantlist__44u3__p6_0[] = {
  133595. 6,
  133596. 5,
  133597. 7,
  133598. 4,
  133599. 8,
  133600. 3,
  133601. 9,
  133602. 2,
  133603. 10,
  133604. 1,
  133605. 11,
  133606. 0,
  133607. 12,
  133608. };
  133609. static long _vq_lengthlist__44u3__p6_0[] = {
  133610. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133611. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133612. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133613. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133614. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133615. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133616. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133617. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133618. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133619. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133620. 15,16,16,16,17,18,16,20,18,
  133621. };
  133622. static float _vq_quantthresh__44u3__p6_0[] = {
  133623. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133624. 12.5, 17.5, 22.5, 27.5,
  133625. };
  133626. static long _vq_quantmap__44u3__p6_0[] = {
  133627. 11, 9, 7, 5, 3, 1, 0, 2,
  133628. 4, 6, 8, 10, 12,
  133629. };
  133630. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133631. _vq_quantthresh__44u3__p6_0,
  133632. _vq_quantmap__44u3__p6_0,
  133633. 13,
  133634. 13
  133635. };
  133636. static static_codebook _44u3__p6_0 = {
  133637. 2, 169,
  133638. _vq_lengthlist__44u3__p6_0,
  133639. 1, -526516224, 1616117760, 4, 0,
  133640. _vq_quantlist__44u3__p6_0,
  133641. NULL,
  133642. &_vq_auxt__44u3__p6_0,
  133643. NULL,
  133644. 0
  133645. };
  133646. static long _vq_quantlist__44u3__p6_1[] = {
  133647. 2,
  133648. 1,
  133649. 3,
  133650. 0,
  133651. 4,
  133652. };
  133653. static long _vq_lengthlist__44u3__p6_1[] = {
  133654. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133655. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133656. };
  133657. static float _vq_quantthresh__44u3__p6_1[] = {
  133658. -1.5, -0.5, 0.5, 1.5,
  133659. };
  133660. static long _vq_quantmap__44u3__p6_1[] = {
  133661. 3, 1, 0, 2, 4,
  133662. };
  133663. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133664. _vq_quantthresh__44u3__p6_1,
  133665. _vq_quantmap__44u3__p6_1,
  133666. 5,
  133667. 5
  133668. };
  133669. static static_codebook _44u3__p6_1 = {
  133670. 2, 25,
  133671. _vq_lengthlist__44u3__p6_1,
  133672. 1, -533725184, 1611661312, 3, 0,
  133673. _vq_quantlist__44u3__p6_1,
  133674. NULL,
  133675. &_vq_auxt__44u3__p6_1,
  133676. NULL,
  133677. 0
  133678. };
  133679. static long _vq_quantlist__44u3__p7_0[] = {
  133680. 4,
  133681. 3,
  133682. 5,
  133683. 2,
  133684. 6,
  133685. 1,
  133686. 7,
  133687. 0,
  133688. 8,
  133689. };
  133690. static long _vq_lengthlist__44u3__p7_0[] = {
  133691. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  133692. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133693. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133694. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133695. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133696. 9,
  133697. };
  133698. static float _vq_quantthresh__44u3__p7_0[] = {
  133699. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  133700. };
  133701. static long _vq_quantmap__44u3__p7_0[] = {
  133702. 7, 5, 3, 1, 0, 2, 4, 6,
  133703. 8,
  133704. };
  133705. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  133706. _vq_quantthresh__44u3__p7_0,
  133707. _vq_quantmap__44u3__p7_0,
  133708. 9,
  133709. 9
  133710. };
  133711. static static_codebook _44u3__p7_0 = {
  133712. 2, 81,
  133713. _vq_lengthlist__44u3__p7_0,
  133714. 1, -515907584, 1627381760, 4, 0,
  133715. _vq_quantlist__44u3__p7_0,
  133716. NULL,
  133717. &_vq_auxt__44u3__p7_0,
  133718. NULL,
  133719. 0
  133720. };
  133721. static long _vq_quantlist__44u3__p7_1[] = {
  133722. 7,
  133723. 6,
  133724. 8,
  133725. 5,
  133726. 9,
  133727. 4,
  133728. 10,
  133729. 3,
  133730. 11,
  133731. 2,
  133732. 12,
  133733. 1,
  133734. 13,
  133735. 0,
  133736. 14,
  133737. };
  133738. static long _vq_lengthlist__44u3__p7_1[] = {
  133739. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  133740. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  133741. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  133742. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  133743. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  133744. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  133745. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  133746. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  133747. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  133748. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  133749. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  133750. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  133751. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  133752. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  133753. 17,
  133754. };
  133755. static float _vq_quantthresh__44u3__p7_1[] = {
  133756. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  133757. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  133758. };
  133759. static long _vq_quantmap__44u3__p7_1[] = {
  133760. 13, 11, 9, 7, 5, 3, 1, 0,
  133761. 2, 4, 6, 8, 10, 12, 14,
  133762. };
  133763. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  133764. _vq_quantthresh__44u3__p7_1,
  133765. _vq_quantmap__44u3__p7_1,
  133766. 15,
  133767. 15
  133768. };
  133769. static static_codebook _44u3__p7_1 = {
  133770. 2, 225,
  133771. _vq_lengthlist__44u3__p7_1,
  133772. 1, -522338304, 1620115456, 4, 0,
  133773. _vq_quantlist__44u3__p7_1,
  133774. NULL,
  133775. &_vq_auxt__44u3__p7_1,
  133776. NULL,
  133777. 0
  133778. };
  133779. static long _vq_quantlist__44u3__p7_2[] = {
  133780. 8,
  133781. 7,
  133782. 9,
  133783. 6,
  133784. 10,
  133785. 5,
  133786. 11,
  133787. 4,
  133788. 12,
  133789. 3,
  133790. 13,
  133791. 2,
  133792. 14,
  133793. 1,
  133794. 15,
  133795. 0,
  133796. 16,
  133797. };
  133798. static long _vq_lengthlist__44u3__p7_2[] = {
  133799. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  133800. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133801. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  133802. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133803. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  133804. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133805. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  133806. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133807. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  133808. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  133809. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  133810. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  133811. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  133812. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133813. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  133814. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  133815. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  133816. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  133817. 11,
  133818. };
  133819. static float _vq_quantthresh__44u3__p7_2[] = {
  133820. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  133821. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  133822. };
  133823. static long _vq_quantmap__44u3__p7_2[] = {
  133824. 15, 13, 11, 9, 7, 5, 3, 1,
  133825. 0, 2, 4, 6, 8, 10, 12, 14,
  133826. 16,
  133827. };
  133828. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  133829. _vq_quantthresh__44u3__p7_2,
  133830. _vq_quantmap__44u3__p7_2,
  133831. 17,
  133832. 17
  133833. };
  133834. static static_codebook _44u3__p7_2 = {
  133835. 2, 289,
  133836. _vq_lengthlist__44u3__p7_2,
  133837. 1, -529530880, 1611661312, 5, 0,
  133838. _vq_quantlist__44u3__p7_2,
  133839. NULL,
  133840. &_vq_auxt__44u3__p7_2,
  133841. NULL,
  133842. 0
  133843. };
  133844. static long _huff_lengthlist__44u3__short[] = {
  133845. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  133846. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  133847. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  133848. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  133849. };
  133850. static static_codebook _huff_book__44u3__short = {
  133851. 2, 64,
  133852. _huff_lengthlist__44u3__short,
  133853. 0, 0, 0, 0, 0,
  133854. NULL,
  133855. NULL,
  133856. NULL,
  133857. NULL,
  133858. 0
  133859. };
  133860. static long _huff_lengthlist__44u4__long[] = {
  133861. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  133862. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  133863. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  133864. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  133865. };
  133866. static static_codebook _huff_book__44u4__long = {
  133867. 2, 64,
  133868. _huff_lengthlist__44u4__long,
  133869. 0, 0, 0, 0, 0,
  133870. NULL,
  133871. NULL,
  133872. NULL,
  133873. NULL,
  133874. 0
  133875. };
  133876. static long _vq_quantlist__44u4__p1_0[] = {
  133877. 1,
  133878. 0,
  133879. 2,
  133880. };
  133881. static long _vq_lengthlist__44u4__p1_0[] = {
  133882. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133883. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133884. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  133885. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133886. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  133887. 13,
  133888. };
  133889. static float _vq_quantthresh__44u4__p1_0[] = {
  133890. -0.5, 0.5,
  133891. };
  133892. static long _vq_quantmap__44u4__p1_0[] = {
  133893. 1, 0, 2,
  133894. };
  133895. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  133896. _vq_quantthresh__44u4__p1_0,
  133897. _vq_quantmap__44u4__p1_0,
  133898. 3,
  133899. 3
  133900. };
  133901. static static_codebook _44u4__p1_0 = {
  133902. 4, 81,
  133903. _vq_lengthlist__44u4__p1_0,
  133904. 1, -535822336, 1611661312, 2, 0,
  133905. _vq_quantlist__44u4__p1_0,
  133906. NULL,
  133907. &_vq_auxt__44u4__p1_0,
  133908. NULL,
  133909. 0
  133910. };
  133911. static long _vq_quantlist__44u4__p2_0[] = {
  133912. 1,
  133913. 0,
  133914. 2,
  133915. };
  133916. static long _vq_lengthlist__44u4__p2_0[] = {
  133917. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133918. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  133919. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133920. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  133921. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133922. 9,
  133923. };
  133924. static float _vq_quantthresh__44u4__p2_0[] = {
  133925. -0.5, 0.5,
  133926. };
  133927. static long _vq_quantmap__44u4__p2_0[] = {
  133928. 1, 0, 2,
  133929. };
  133930. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  133931. _vq_quantthresh__44u4__p2_0,
  133932. _vq_quantmap__44u4__p2_0,
  133933. 3,
  133934. 3
  133935. };
  133936. static static_codebook _44u4__p2_0 = {
  133937. 4, 81,
  133938. _vq_lengthlist__44u4__p2_0,
  133939. 1, -535822336, 1611661312, 2, 0,
  133940. _vq_quantlist__44u4__p2_0,
  133941. NULL,
  133942. &_vq_auxt__44u4__p2_0,
  133943. NULL,
  133944. 0
  133945. };
  133946. static long _vq_quantlist__44u4__p3_0[] = {
  133947. 2,
  133948. 1,
  133949. 3,
  133950. 0,
  133951. 4,
  133952. };
  133953. static long _vq_lengthlist__44u4__p3_0[] = {
  133954. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133955. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  133956. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  133957. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  133958. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  133959. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  133960. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  133961. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  133962. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  133963. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  133964. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  133965. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  133966. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  133967. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  133968. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  133969. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  133970. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  133971. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  133972. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  133973. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  133974. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  133975. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  133976. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  133977. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  133978. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  133979. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  133980. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  133981. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  133982. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  133983. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  133984. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  133985. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  133986. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  133987. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  133988. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  133989. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  133990. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  133991. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  133992. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  133993. 0,
  133994. };
  133995. static float _vq_quantthresh__44u4__p3_0[] = {
  133996. -1.5, -0.5, 0.5, 1.5,
  133997. };
  133998. static long _vq_quantmap__44u4__p3_0[] = {
  133999. 3, 1, 0, 2, 4,
  134000. };
  134001. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  134002. _vq_quantthresh__44u4__p3_0,
  134003. _vq_quantmap__44u4__p3_0,
  134004. 5,
  134005. 5
  134006. };
  134007. static static_codebook _44u4__p3_0 = {
  134008. 4, 625,
  134009. _vq_lengthlist__44u4__p3_0,
  134010. 1, -533725184, 1611661312, 3, 0,
  134011. _vq_quantlist__44u4__p3_0,
  134012. NULL,
  134013. &_vq_auxt__44u4__p3_0,
  134014. NULL,
  134015. 0
  134016. };
  134017. static long _vq_quantlist__44u4__p4_0[] = {
  134018. 2,
  134019. 1,
  134020. 3,
  134021. 0,
  134022. 4,
  134023. };
  134024. static long _vq_lengthlist__44u4__p4_0[] = {
  134025. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  134026. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  134027. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  134028. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  134029. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  134030. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  134031. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  134032. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  134033. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  134034. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  134035. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  134036. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134037. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  134038. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  134039. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  134040. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  134041. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  134042. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134043. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  134044. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  134045. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  134046. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  134047. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  134048. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  134049. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  134050. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  134051. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  134052. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  134053. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  134054. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  134055. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  134056. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  134057. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  134058. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  134059. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  134060. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  134061. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  134062. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  134063. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  134064. 13,
  134065. };
  134066. static float _vq_quantthresh__44u4__p4_0[] = {
  134067. -1.5, -0.5, 0.5, 1.5,
  134068. };
  134069. static long _vq_quantmap__44u4__p4_0[] = {
  134070. 3, 1, 0, 2, 4,
  134071. };
  134072. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  134073. _vq_quantthresh__44u4__p4_0,
  134074. _vq_quantmap__44u4__p4_0,
  134075. 5,
  134076. 5
  134077. };
  134078. static static_codebook _44u4__p4_0 = {
  134079. 4, 625,
  134080. _vq_lengthlist__44u4__p4_0,
  134081. 1, -533725184, 1611661312, 3, 0,
  134082. _vq_quantlist__44u4__p4_0,
  134083. NULL,
  134084. &_vq_auxt__44u4__p4_0,
  134085. NULL,
  134086. 0
  134087. };
  134088. static long _vq_quantlist__44u4__p5_0[] = {
  134089. 4,
  134090. 3,
  134091. 5,
  134092. 2,
  134093. 6,
  134094. 1,
  134095. 7,
  134096. 0,
  134097. 8,
  134098. };
  134099. static long _vq_lengthlist__44u4__p5_0[] = {
  134100. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  134101. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  134102. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  134103. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  134104. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  134105. 12,
  134106. };
  134107. static float _vq_quantthresh__44u4__p5_0[] = {
  134108. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134109. };
  134110. static long _vq_quantmap__44u4__p5_0[] = {
  134111. 7, 5, 3, 1, 0, 2, 4, 6,
  134112. 8,
  134113. };
  134114. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  134115. _vq_quantthresh__44u4__p5_0,
  134116. _vq_quantmap__44u4__p5_0,
  134117. 9,
  134118. 9
  134119. };
  134120. static static_codebook _44u4__p5_0 = {
  134121. 2, 81,
  134122. _vq_lengthlist__44u4__p5_0,
  134123. 1, -531628032, 1611661312, 4, 0,
  134124. _vq_quantlist__44u4__p5_0,
  134125. NULL,
  134126. &_vq_auxt__44u4__p5_0,
  134127. NULL,
  134128. 0
  134129. };
  134130. static long _vq_quantlist__44u4__p6_0[] = {
  134131. 6,
  134132. 5,
  134133. 7,
  134134. 4,
  134135. 8,
  134136. 3,
  134137. 9,
  134138. 2,
  134139. 10,
  134140. 1,
  134141. 11,
  134142. 0,
  134143. 12,
  134144. };
  134145. static long _vq_lengthlist__44u4__p6_0[] = {
  134146. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  134147. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  134148. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  134149. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  134150. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  134151. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  134152. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  134153. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  134154. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  134155. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  134156. 16,16,16,17,17,18,17,20,21,
  134157. };
  134158. static float _vq_quantthresh__44u4__p6_0[] = {
  134159. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  134160. 12.5, 17.5, 22.5, 27.5,
  134161. };
  134162. static long _vq_quantmap__44u4__p6_0[] = {
  134163. 11, 9, 7, 5, 3, 1, 0, 2,
  134164. 4, 6, 8, 10, 12,
  134165. };
  134166. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  134167. _vq_quantthresh__44u4__p6_0,
  134168. _vq_quantmap__44u4__p6_0,
  134169. 13,
  134170. 13
  134171. };
  134172. static static_codebook _44u4__p6_0 = {
  134173. 2, 169,
  134174. _vq_lengthlist__44u4__p6_0,
  134175. 1, -526516224, 1616117760, 4, 0,
  134176. _vq_quantlist__44u4__p6_0,
  134177. NULL,
  134178. &_vq_auxt__44u4__p6_0,
  134179. NULL,
  134180. 0
  134181. };
  134182. static long _vq_quantlist__44u4__p6_1[] = {
  134183. 2,
  134184. 1,
  134185. 3,
  134186. 0,
  134187. 4,
  134188. };
  134189. static long _vq_lengthlist__44u4__p6_1[] = {
  134190. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  134191. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  134192. };
  134193. static float _vq_quantthresh__44u4__p6_1[] = {
  134194. -1.5, -0.5, 0.5, 1.5,
  134195. };
  134196. static long _vq_quantmap__44u4__p6_1[] = {
  134197. 3, 1, 0, 2, 4,
  134198. };
  134199. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  134200. _vq_quantthresh__44u4__p6_1,
  134201. _vq_quantmap__44u4__p6_1,
  134202. 5,
  134203. 5
  134204. };
  134205. static static_codebook _44u4__p6_1 = {
  134206. 2, 25,
  134207. _vq_lengthlist__44u4__p6_1,
  134208. 1, -533725184, 1611661312, 3, 0,
  134209. _vq_quantlist__44u4__p6_1,
  134210. NULL,
  134211. &_vq_auxt__44u4__p6_1,
  134212. NULL,
  134213. 0
  134214. };
  134215. static long _vq_quantlist__44u4__p7_0[] = {
  134216. 6,
  134217. 5,
  134218. 7,
  134219. 4,
  134220. 8,
  134221. 3,
  134222. 9,
  134223. 2,
  134224. 10,
  134225. 1,
  134226. 11,
  134227. 0,
  134228. 12,
  134229. };
  134230. static long _vq_lengthlist__44u4__p7_0[] = {
  134231. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  134232. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  134233. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134234. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134235. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134236. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134237. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134238. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134239. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134240. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134241. 11,11,11,11,11,11,11,11,11,
  134242. };
  134243. static float _vq_quantthresh__44u4__p7_0[] = {
  134244. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134245. 637.5, 892.5, 1147.5, 1402.5,
  134246. };
  134247. static long _vq_quantmap__44u4__p7_0[] = {
  134248. 11, 9, 7, 5, 3, 1, 0, 2,
  134249. 4, 6, 8, 10, 12,
  134250. };
  134251. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  134252. _vq_quantthresh__44u4__p7_0,
  134253. _vq_quantmap__44u4__p7_0,
  134254. 13,
  134255. 13
  134256. };
  134257. static static_codebook _44u4__p7_0 = {
  134258. 2, 169,
  134259. _vq_lengthlist__44u4__p7_0,
  134260. 1, -514332672, 1627381760, 4, 0,
  134261. _vq_quantlist__44u4__p7_0,
  134262. NULL,
  134263. &_vq_auxt__44u4__p7_0,
  134264. NULL,
  134265. 0
  134266. };
  134267. static long _vq_quantlist__44u4__p7_1[] = {
  134268. 7,
  134269. 6,
  134270. 8,
  134271. 5,
  134272. 9,
  134273. 4,
  134274. 10,
  134275. 3,
  134276. 11,
  134277. 2,
  134278. 12,
  134279. 1,
  134280. 13,
  134281. 0,
  134282. 14,
  134283. };
  134284. static long _vq_lengthlist__44u4__p7_1[] = {
  134285. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134286. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134287. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134288. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134289. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134290. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134291. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134292. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134293. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134294. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134295. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134296. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134297. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134298. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134299. 16,
  134300. };
  134301. static float _vq_quantthresh__44u4__p7_1[] = {
  134302. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134303. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134304. };
  134305. static long _vq_quantmap__44u4__p7_1[] = {
  134306. 13, 11, 9, 7, 5, 3, 1, 0,
  134307. 2, 4, 6, 8, 10, 12, 14,
  134308. };
  134309. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134310. _vq_quantthresh__44u4__p7_1,
  134311. _vq_quantmap__44u4__p7_1,
  134312. 15,
  134313. 15
  134314. };
  134315. static static_codebook _44u4__p7_1 = {
  134316. 2, 225,
  134317. _vq_lengthlist__44u4__p7_1,
  134318. 1, -522338304, 1620115456, 4, 0,
  134319. _vq_quantlist__44u4__p7_1,
  134320. NULL,
  134321. &_vq_auxt__44u4__p7_1,
  134322. NULL,
  134323. 0
  134324. };
  134325. static long _vq_quantlist__44u4__p7_2[] = {
  134326. 8,
  134327. 7,
  134328. 9,
  134329. 6,
  134330. 10,
  134331. 5,
  134332. 11,
  134333. 4,
  134334. 12,
  134335. 3,
  134336. 13,
  134337. 2,
  134338. 14,
  134339. 1,
  134340. 15,
  134341. 0,
  134342. 16,
  134343. };
  134344. static long _vq_lengthlist__44u4__p7_2[] = {
  134345. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134346. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134347. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134348. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134349. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134350. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134351. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134352. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134353. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134354. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134355. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134356. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134357. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134358. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134359. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134360. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134361. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134362. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134363. 10,
  134364. };
  134365. static float _vq_quantthresh__44u4__p7_2[] = {
  134366. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134367. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134368. };
  134369. static long _vq_quantmap__44u4__p7_2[] = {
  134370. 15, 13, 11, 9, 7, 5, 3, 1,
  134371. 0, 2, 4, 6, 8, 10, 12, 14,
  134372. 16,
  134373. };
  134374. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134375. _vq_quantthresh__44u4__p7_2,
  134376. _vq_quantmap__44u4__p7_2,
  134377. 17,
  134378. 17
  134379. };
  134380. static static_codebook _44u4__p7_2 = {
  134381. 2, 289,
  134382. _vq_lengthlist__44u4__p7_2,
  134383. 1, -529530880, 1611661312, 5, 0,
  134384. _vq_quantlist__44u4__p7_2,
  134385. NULL,
  134386. &_vq_auxt__44u4__p7_2,
  134387. NULL,
  134388. 0
  134389. };
  134390. static long _huff_lengthlist__44u4__short[] = {
  134391. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  134392. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  134393. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  134394. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134395. };
  134396. static static_codebook _huff_book__44u4__short = {
  134397. 2, 64,
  134398. _huff_lengthlist__44u4__short,
  134399. 0, 0, 0, 0, 0,
  134400. NULL,
  134401. NULL,
  134402. NULL,
  134403. NULL,
  134404. 0
  134405. };
  134406. static long _huff_lengthlist__44u5__long[] = {
  134407. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134408. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134409. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134410. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134411. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134412. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134413. 14, 8, 7, 8,
  134414. };
  134415. static static_codebook _huff_book__44u5__long = {
  134416. 2, 100,
  134417. _huff_lengthlist__44u5__long,
  134418. 0, 0, 0, 0, 0,
  134419. NULL,
  134420. NULL,
  134421. NULL,
  134422. NULL,
  134423. 0
  134424. };
  134425. static long _vq_quantlist__44u5__p1_0[] = {
  134426. 1,
  134427. 0,
  134428. 2,
  134429. };
  134430. static long _vq_lengthlist__44u5__p1_0[] = {
  134431. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134432. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134433. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134434. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134435. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134436. 12,
  134437. };
  134438. static float _vq_quantthresh__44u5__p1_0[] = {
  134439. -0.5, 0.5,
  134440. };
  134441. static long _vq_quantmap__44u5__p1_0[] = {
  134442. 1, 0, 2,
  134443. };
  134444. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134445. _vq_quantthresh__44u5__p1_0,
  134446. _vq_quantmap__44u5__p1_0,
  134447. 3,
  134448. 3
  134449. };
  134450. static static_codebook _44u5__p1_0 = {
  134451. 4, 81,
  134452. _vq_lengthlist__44u5__p1_0,
  134453. 1, -535822336, 1611661312, 2, 0,
  134454. _vq_quantlist__44u5__p1_0,
  134455. NULL,
  134456. &_vq_auxt__44u5__p1_0,
  134457. NULL,
  134458. 0
  134459. };
  134460. static long _vq_quantlist__44u5__p2_0[] = {
  134461. 1,
  134462. 0,
  134463. 2,
  134464. };
  134465. static long _vq_lengthlist__44u5__p2_0[] = {
  134466. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134467. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134468. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134469. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134470. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134471. 9,
  134472. };
  134473. static float _vq_quantthresh__44u5__p2_0[] = {
  134474. -0.5, 0.5,
  134475. };
  134476. static long _vq_quantmap__44u5__p2_0[] = {
  134477. 1, 0, 2,
  134478. };
  134479. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134480. _vq_quantthresh__44u5__p2_0,
  134481. _vq_quantmap__44u5__p2_0,
  134482. 3,
  134483. 3
  134484. };
  134485. static static_codebook _44u5__p2_0 = {
  134486. 4, 81,
  134487. _vq_lengthlist__44u5__p2_0,
  134488. 1, -535822336, 1611661312, 2, 0,
  134489. _vq_quantlist__44u5__p2_0,
  134490. NULL,
  134491. &_vq_auxt__44u5__p2_0,
  134492. NULL,
  134493. 0
  134494. };
  134495. static long _vq_quantlist__44u5__p3_0[] = {
  134496. 2,
  134497. 1,
  134498. 3,
  134499. 0,
  134500. 4,
  134501. };
  134502. static long _vq_lengthlist__44u5__p3_0[] = {
  134503. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134504. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134505. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134506. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134507. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134508. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134509. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134510. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134511. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134512. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134513. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134514. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134515. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134516. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134517. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134518. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134519. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134520. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134521. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134522. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134523. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134524. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134525. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134526. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134527. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134528. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134529. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134530. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134531. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134532. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134533. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134534. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134535. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134536. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134537. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134538. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134539. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134540. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134541. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134542. 0,
  134543. };
  134544. static float _vq_quantthresh__44u5__p3_0[] = {
  134545. -1.5, -0.5, 0.5, 1.5,
  134546. };
  134547. static long _vq_quantmap__44u5__p3_0[] = {
  134548. 3, 1, 0, 2, 4,
  134549. };
  134550. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134551. _vq_quantthresh__44u5__p3_0,
  134552. _vq_quantmap__44u5__p3_0,
  134553. 5,
  134554. 5
  134555. };
  134556. static static_codebook _44u5__p3_0 = {
  134557. 4, 625,
  134558. _vq_lengthlist__44u5__p3_0,
  134559. 1, -533725184, 1611661312, 3, 0,
  134560. _vq_quantlist__44u5__p3_0,
  134561. NULL,
  134562. &_vq_auxt__44u5__p3_0,
  134563. NULL,
  134564. 0
  134565. };
  134566. static long _vq_quantlist__44u5__p4_0[] = {
  134567. 2,
  134568. 1,
  134569. 3,
  134570. 0,
  134571. 4,
  134572. };
  134573. static long _vq_lengthlist__44u5__p4_0[] = {
  134574. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134575. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134576. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134577. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134578. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134579. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134580. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134581. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134582. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134583. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134584. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134585. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134586. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134587. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134588. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134589. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134590. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134591. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134592. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134593. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134594. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134595. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134596. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134597. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134598. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134599. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134600. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134601. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134602. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134603. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134604. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134605. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134606. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134607. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134608. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134609. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134610. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134611. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134612. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134613. 12,
  134614. };
  134615. static float _vq_quantthresh__44u5__p4_0[] = {
  134616. -1.5, -0.5, 0.5, 1.5,
  134617. };
  134618. static long _vq_quantmap__44u5__p4_0[] = {
  134619. 3, 1, 0, 2, 4,
  134620. };
  134621. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134622. _vq_quantthresh__44u5__p4_0,
  134623. _vq_quantmap__44u5__p4_0,
  134624. 5,
  134625. 5
  134626. };
  134627. static static_codebook _44u5__p4_0 = {
  134628. 4, 625,
  134629. _vq_lengthlist__44u5__p4_0,
  134630. 1, -533725184, 1611661312, 3, 0,
  134631. _vq_quantlist__44u5__p4_0,
  134632. NULL,
  134633. &_vq_auxt__44u5__p4_0,
  134634. NULL,
  134635. 0
  134636. };
  134637. static long _vq_quantlist__44u5__p5_0[] = {
  134638. 4,
  134639. 3,
  134640. 5,
  134641. 2,
  134642. 6,
  134643. 1,
  134644. 7,
  134645. 0,
  134646. 8,
  134647. };
  134648. static long _vq_lengthlist__44u5__p5_0[] = {
  134649. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134650. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134651. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134652. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134653. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134654. 14,
  134655. };
  134656. static float _vq_quantthresh__44u5__p5_0[] = {
  134657. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134658. };
  134659. static long _vq_quantmap__44u5__p5_0[] = {
  134660. 7, 5, 3, 1, 0, 2, 4, 6,
  134661. 8,
  134662. };
  134663. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134664. _vq_quantthresh__44u5__p5_0,
  134665. _vq_quantmap__44u5__p5_0,
  134666. 9,
  134667. 9
  134668. };
  134669. static static_codebook _44u5__p5_0 = {
  134670. 2, 81,
  134671. _vq_lengthlist__44u5__p5_0,
  134672. 1, -531628032, 1611661312, 4, 0,
  134673. _vq_quantlist__44u5__p5_0,
  134674. NULL,
  134675. &_vq_auxt__44u5__p5_0,
  134676. NULL,
  134677. 0
  134678. };
  134679. static long _vq_quantlist__44u5__p6_0[] = {
  134680. 4,
  134681. 3,
  134682. 5,
  134683. 2,
  134684. 6,
  134685. 1,
  134686. 7,
  134687. 0,
  134688. 8,
  134689. };
  134690. static long _vq_lengthlist__44u5__p6_0[] = {
  134691. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  134692. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  134693. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  134694. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  134695. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  134696. 11,
  134697. };
  134698. static float _vq_quantthresh__44u5__p6_0[] = {
  134699. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134700. };
  134701. static long _vq_quantmap__44u5__p6_0[] = {
  134702. 7, 5, 3, 1, 0, 2, 4, 6,
  134703. 8,
  134704. };
  134705. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  134706. _vq_quantthresh__44u5__p6_0,
  134707. _vq_quantmap__44u5__p6_0,
  134708. 9,
  134709. 9
  134710. };
  134711. static static_codebook _44u5__p6_0 = {
  134712. 2, 81,
  134713. _vq_lengthlist__44u5__p6_0,
  134714. 1, -531628032, 1611661312, 4, 0,
  134715. _vq_quantlist__44u5__p6_0,
  134716. NULL,
  134717. &_vq_auxt__44u5__p6_0,
  134718. NULL,
  134719. 0
  134720. };
  134721. static long _vq_quantlist__44u5__p7_0[] = {
  134722. 1,
  134723. 0,
  134724. 2,
  134725. };
  134726. static long _vq_lengthlist__44u5__p7_0[] = {
  134727. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  134728. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  134729. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  134730. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  134731. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  134732. 12,
  134733. };
  134734. static float _vq_quantthresh__44u5__p7_0[] = {
  134735. -5.5, 5.5,
  134736. };
  134737. static long _vq_quantmap__44u5__p7_0[] = {
  134738. 1, 0, 2,
  134739. };
  134740. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  134741. _vq_quantthresh__44u5__p7_0,
  134742. _vq_quantmap__44u5__p7_0,
  134743. 3,
  134744. 3
  134745. };
  134746. static static_codebook _44u5__p7_0 = {
  134747. 4, 81,
  134748. _vq_lengthlist__44u5__p7_0,
  134749. 1, -529137664, 1618345984, 2, 0,
  134750. _vq_quantlist__44u5__p7_0,
  134751. NULL,
  134752. &_vq_auxt__44u5__p7_0,
  134753. NULL,
  134754. 0
  134755. };
  134756. static long _vq_quantlist__44u5__p7_1[] = {
  134757. 5,
  134758. 4,
  134759. 6,
  134760. 3,
  134761. 7,
  134762. 2,
  134763. 8,
  134764. 1,
  134765. 9,
  134766. 0,
  134767. 10,
  134768. };
  134769. static long _vq_lengthlist__44u5__p7_1[] = {
  134770. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  134771. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  134772. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  134773. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  134774. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  134775. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134776. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  134777. 9, 9, 9, 9, 9,10,10,10,10,
  134778. };
  134779. static float _vq_quantthresh__44u5__p7_1[] = {
  134780. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134781. 3.5, 4.5,
  134782. };
  134783. static long _vq_quantmap__44u5__p7_1[] = {
  134784. 9, 7, 5, 3, 1, 0, 2, 4,
  134785. 6, 8, 10,
  134786. };
  134787. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  134788. _vq_quantthresh__44u5__p7_1,
  134789. _vq_quantmap__44u5__p7_1,
  134790. 11,
  134791. 11
  134792. };
  134793. static static_codebook _44u5__p7_1 = {
  134794. 2, 121,
  134795. _vq_lengthlist__44u5__p7_1,
  134796. 1, -531365888, 1611661312, 4, 0,
  134797. _vq_quantlist__44u5__p7_1,
  134798. NULL,
  134799. &_vq_auxt__44u5__p7_1,
  134800. NULL,
  134801. 0
  134802. };
  134803. static long _vq_quantlist__44u5__p8_0[] = {
  134804. 5,
  134805. 4,
  134806. 6,
  134807. 3,
  134808. 7,
  134809. 2,
  134810. 8,
  134811. 1,
  134812. 9,
  134813. 0,
  134814. 10,
  134815. };
  134816. static long _vq_lengthlist__44u5__p8_0[] = {
  134817. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  134818. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  134819. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  134820. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  134821. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  134822. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  134823. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  134824. 12,13,13,14,14,14,14,15,15,
  134825. };
  134826. static float _vq_quantthresh__44u5__p8_0[] = {
  134827. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  134828. 38.5, 49.5,
  134829. };
  134830. static long _vq_quantmap__44u5__p8_0[] = {
  134831. 9, 7, 5, 3, 1, 0, 2, 4,
  134832. 6, 8, 10,
  134833. };
  134834. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  134835. _vq_quantthresh__44u5__p8_0,
  134836. _vq_quantmap__44u5__p8_0,
  134837. 11,
  134838. 11
  134839. };
  134840. static static_codebook _44u5__p8_0 = {
  134841. 2, 121,
  134842. _vq_lengthlist__44u5__p8_0,
  134843. 1, -524582912, 1618345984, 4, 0,
  134844. _vq_quantlist__44u5__p8_0,
  134845. NULL,
  134846. &_vq_auxt__44u5__p8_0,
  134847. NULL,
  134848. 0
  134849. };
  134850. static long _vq_quantlist__44u5__p8_1[] = {
  134851. 5,
  134852. 4,
  134853. 6,
  134854. 3,
  134855. 7,
  134856. 2,
  134857. 8,
  134858. 1,
  134859. 9,
  134860. 0,
  134861. 10,
  134862. };
  134863. static long _vq_lengthlist__44u5__p8_1[] = {
  134864. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  134865. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  134866. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  134867. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  134868. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  134869. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  134870. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134871. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134872. };
  134873. static float _vq_quantthresh__44u5__p8_1[] = {
  134874. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134875. 3.5, 4.5,
  134876. };
  134877. static long _vq_quantmap__44u5__p8_1[] = {
  134878. 9, 7, 5, 3, 1, 0, 2, 4,
  134879. 6, 8, 10,
  134880. };
  134881. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  134882. _vq_quantthresh__44u5__p8_1,
  134883. _vq_quantmap__44u5__p8_1,
  134884. 11,
  134885. 11
  134886. };
  134887. static static_codebook _44u5__p8_1 = {
  134888. 2, 121,
  134889. _vq_lengthlist__44u5__p8_1,
  134890. 1, -531365888, 1611661312, 4, 0,
  134891. _vq_quantlist__44u5__p8_1,
  134892. NULL,
  134893. &_vq_auxt__44u5__p8_1,
  134894. NULL,
  134895. 0
  134896. };
  134897. static long _vq_quantlist__44u5__p9_0[] = {
  134898. 6,
  134899. 5,
  134900. 7,
  134901. 4,
  134902. 8,
  134903. 3,
  134904. 9,
  134905. 2,
  134906. 10,
  134907. 1,
  134908. 11,
  134909. 0,
  134910. 12,
  134911. };
  134912. static long _vq_lengthlist__44u5__p9_0[] = {
  134913. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  134914. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  134915. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  134916. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  134917. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134918. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134919. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134920. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134921. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  134922. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134923. 12,12,12,12,12,12,12,12,12,
  134924. };
  134925. static float _vq_quantthresh__44u5__p9_0[] = {
  134926. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134927. 637.5, 892.5, 1147.5, 1402.5,
  134928. };
  134929. static long _vq_quantmap__44u5__p9_0[] = {
  134930. 11, 9, 7, 5, 3, 1, 0, 2,
  134931. 4, 6, 8, 10, 12,
  134932. };
  134933. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  134934. _vq_quantthresh__44u5__p9_0,
  134935. _vq_quantmap__44u5__p9_0,
  134936. 13,
  134937. 13
  134938. };
  134939. static static_codebook _44u5__p9_0 = {
  134940. 2, 169,
  134941. _vq_lengthlist__44u5__p9_0,
  134942. 1, -514332672, 1627381760, 4, 0,
  134943. _vq_quantlist__44u5__p9_0,
  134944. NULL,
  134945. &_vq_auxt__44u5__p9_0,
  134946. NULL,
  134947. 0
  134948. };
  134949. static long _vq_quantlist__44u5__p9_1[] = {
  134950. 7,
  134951. 6,
  134952. 8,
  134953. 5,
  134954. 9,
  134955. 4,
  134956. 10,
  134957. 3,
  134958. 11,
  134959. 2,
  134960. 12,
  134961. 1,
  134962. 13,
  134963. 0,
  134964. 14,
  134965. };
  134966. static long _vq_lengthlist__44u5__p9_1[] = {
  134967. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  134968. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  134969. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  134970. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  134971. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  134972. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  134973. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  134974. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  134975. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  134976. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  134977. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  134978. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  134979. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  134980. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  134981. 14,
  134982. };
  134983. static float _vq_quantthresh__44u5__p9_1[] = {
  134984. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134985. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134986. };
  134987. static long _vq_quantmap__44u5__p9_1[] = {
  134988. 13, 11, 9, 7, 5, 3, 1, 0,
  134989. 2, 4, 6, 8, 10, 12, 14,
  134990. };
  134991. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  134992. _vq_quantthresh__44u5__p9_1,
  134993. _vq_quantmap__44u5__p9_1,
  134994. 15,
  134995. 15
  134996. };
  134997. static static_codebook _44u5__p9_1 = {
  134998. 2, 225,
  134999. _vq_lengthlist__44u5__p9_1,
  135000. 1, -522338304, 1620115456, 4, 0,
  135001. _vq_quantlist__44u5__p9_1,
  135002. NULL,
  135003. &_vq_auxt__44u5__p9_1,
  135004. NULL,
  135005. 0
  135006. };
  135007. static long _vq_quantlist__44u5__p9_2[] = {
  135008. 8,
  135009. 7,
  135010. 9,
  135011. 6,
  135012. 10,
  135013. 5,
  135014. 11,
  135015. 4,
  135016. 12,
  135017. 3,
  135018. 13,
  135019. 2,
  135020. 14,
  135021. 1,
  135022. 15,
  135023. 0,
  135024. 16,
  135025. };
  135026. static long _vq_lengthlist__44u5__p9_2[] = {
  135027. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135028. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135029. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135030. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135031. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135032. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  135033. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135034. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  135035. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  135036. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  135037. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  135038. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  135039. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  135040. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  135041. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  135042. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  135043. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  135044. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  135045. 10,
  135046. };
  135047. static float _vq_quantthresh__44u5__p9_2[] = {
  135048. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135049. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135050. };
  135051. static long _vq_quantmap__44u5__p9_2[] = {
  135052. 15, 13, 11, 9, 7, 5, 3, 1,
  135053. 0, 2, 4, 6, 8, 10, 12, 14,
  135054. 16,
  135055. };
  135056. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  135057. _vq_quantthresh__44u5__p9_2,
  135058. _vq_quantmap__44u5__p9_2,
  135059. 17,
  135060. 17
  135061. };
  135062. static static_codebook _44u5__p9_2 = {
  135063. 2, 289,
  135064. _vq_lengthlist__44u5__p9_2,
  135065. 1, -529530880, 1611661312, 5, 0,
  135066. _vq_quantlist__44u5__p9_2,
  135067. NULL,
  135068. &_vq_auxt__44u5__p9_2,
  135069. NULL,
  135070. 0
  135071. };
  135072. static long _huff_lengthlist__44u5__short[] = {
  135073. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  135074. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  135075. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  135076. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  135077. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  135078. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  135079. 6, 8,15,17,
  135080. };
  135081. static static_codebook _huff_book__44u5__short = {
  135082. 2, 100,
  135083. _huff_lengthlist__44u5__short,
  135084. 0, 0, 0, 0, 0,
  135085. NULL,
  135086. NULL,
  135087. NULL,
  135088. NULL,
  135089. 0
  135090. };
  135091. static long _huff_lengthlist__44u6__long[] = {
  135092. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  135093. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  135094. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  135095. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  135096. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  135097. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  135098. 13, 8, 7, 7,
  135099. };
  135100. static static_codebook _huff_book__44u6__long = {
  135101. 2, 100,
  135102. _huff_lengthlist__44u6__long,
  135103. 0, 0, 0, 0, 0,
  135104. NULL,
  135105. NULL,
  135106. NULL,
  135107. NULL,
  135108. 0
  135109. };
  135110. static long _vq_quantlist__44u6__p1_0[] = {
  135111. 1,
  135112. 0,
  135113. 2,
  135114. };
  135115. static long _vq_lengthlist__44u6__p1_0[] = {
  135116. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135117. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  135118. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135119. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  135120. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  135121. 12,
  135122. };
  135123. static float _vq_quantthresh__44u6__p1_0[] = {
  135124. -0.5, 0.5,
  135125. };
  135126. static long _vq_quantmap__44u6__p1_0[] = {
  135127. 1, 0, 2,
  135128. };
  135129. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  135130. _vq_quantthresh__44u6__p1_0,
  135131. _vq_quantmap__44u6__p1_0,
  135132. 3,
  135133. 3
  135134. };
  135135. static static_codebook _44u6__p1_0 = {
  135136. 4, 81,
  135137. _vq_lengthlist__44u6__p1_0,
  135138. 1, -535822336, 1611661312, 2, 0,
  135139. _vq_quantlist__44u6__p1_0,
  135140. NULL,
  135141. &_vq_auxt__44u6__p1_0,
  135142. NULL,
  135143. 0
  135144. };
  135145. static long _vq_quantlist__44u6__p2_0[] = {
  135146. 1,
  135147. 0,
  135148. 2,
  135149. };
  135150. static long _vq_lengthlist__44u6__p2_0[] = {
  135151. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135152. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135153. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  135154. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135155. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135156. 9,
  135157. };
  135158. static float _vq_quantthresh__44u6__p2_0[] = {
  135159. -0.5, 0.5,
  135160. };
  135161. static long _vq_quantmap__44u6__p2_0[] = {
  135162. 1, 0, 2,
  135163. };
  135164. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  135165. _vq_quantthresh__44u6__p2_0,
  135166. _vq_quantmap__44u6__p2_0,
  135167. 3,
  135168. 3
  135169. };
  135170. static static_codebook _44u6__p2_0 = {
  135171. 4, 81,
  135172. _vq_lengthlist__44u6__p2_0,
  135173. 1, -535822336, 1611661312, 2, 0,
  135174. _vq_quantlist__44u6__p2_0,
  135175. NULL,
  135176. &_vq_auxt__44u6__p2_0,
  135177. NULL,
  135178. 0
  135179. };
  135180. static long _vq_quantlist__44u6__p3_0[] = {
  135181. 2,
  135182. 1,
  135183. 3,
  135184. 0,
  135185. 4,
  135186. };
  135187. static long _vq_lengthlist__44u6__p3_0[] = {
  135188. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135189. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135190. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135191. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  135192. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  135193. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  135194. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  135195. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  135196. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  135197. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135198. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  135199. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135200. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  135201. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  135202. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  135203. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  135204. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135205. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135206. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  135207. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  135208. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  135209. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  135210. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  135211. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  135212. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  135213. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  135214. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  135215. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  135216. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  135217. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  135218. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  135219. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  135220. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  135221. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  135222. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  135223. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  135224. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  135225. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  135226. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  135227. 19,
  135228. };
  135229. static float _vq_quantthresh__44u6__p3_0[] = {
  135230. -1.5, -0.5, 0.5, 1.5,
  135231. };
  135232. static long _vq_quantmap__44u6__p3_0[] = {
  135233. 3, 1, 0, 2, 4,
  135234. };
  135235. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  135236. _vq_quantthresh__44u6__p3_0,
  135237. _vq_quantmap__44u6__p3_0,
  135238. 5,
  135239. 5
  135240. };
  135241. static static_codebook _44u6__p3_0 = {
  135242. 4, 625,
  135243. _vq_lengthlist__44u6__p3_0,
  135244. 1, -533725184, 1611661312, 3, 0,
  135245. _vq_quantlist__44u6__p3_0,
  135246. NULL,
  135247. &_vq_auxt__44u6__p3_0,
  135248. NULL,
  135249. 0
  135250. };
  135251. static long _vq_quantlist__44u6__p4_0[] = {
  135252. 2,
  135253. 1,
  135254. 3,
  135255. 0,
  135256. 4,
  135257. };
  135258. static long _vq_lengthlist__44u6__p4_0[] = {
  135259. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135260. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135261. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  135262. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  135263. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135264. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  135265. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135266. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  135267. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135268. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135269. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  135270. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135271. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135272. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  135273. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  135274. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135275. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  135276. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135277. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135278. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  135279. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135280. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135281. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  135282. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135283. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135284. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135285. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135286. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135287. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135288. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135289. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135290. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135291. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135292. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135293. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135294. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135295. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135296. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135297. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135298. 13,
  135299. };
  135300. static float _vq_quantthresh__44u6__p4_0[] = {
  135301. -1.5, -0.5, 0.5, 1.5,
  135302. };
  135303. static long _vq_quantmap__44u6__p4_0[] = {
  135304. 3, 1, 0, 2, 4,
  135305. };
  135306. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135307. _vq_quantthresh__44u6__p4_0,
  135308. _vq_quantmap__44u6__p4_0,
  135309. 5,
  135310. 5
  135311. };
  135312. static static_codebook _44u6__p4_0 = {
  135313. 4, 625,
  135314. _vq_lengthlist__44u6__p4_0,
  135315. 1, -533725184, 1611661312, 3, 0,
  135316. _vq_quantlist__44u6__p4_0,
  135317. NULL,
  135318. &_vq_auxt__44u6__p4_0,
  135319. NULL,
  135320. 0
  135321. };
  135322. static long _vq_quantlist__44u6__p5_0[] = {
  135323. 4,
  135324. 3,
  135325. 5,
  135326. 2,
  135327. 6,
  135328. 1,
  135329. 7,
  135330. 0,
  135331. 8,
  135332. };
  135333. static long _vq_lengthlist__44u6__p5_0[] = {
  135334. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135335. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135336. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135337. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135338. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135339. 14,
  135340. };
  135341. static float _vq_quantthresh__44u6__p5_0[] = {
  135342. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135343. };
  135344. static long _vq_quantmap__44u6__p5_0[] = {
  135345. 7, 5, 3, 1, 0, 2, 4, 6,
  135346. 8,
  135347. };
  135348. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135349. _vq_quantthresh__44u6__p5_0,
  135350. _vq_quantmap__44u6__p5_0,
  135351. 9,
  135352. 9
  135353. };
  135354. static static_codebook _44u6__p5_0 = {
  135355. 2, 81,
  135356. _vq_lengthlist__44u6__p5_0,
  135357. 1, -531628032, 1611661312, 4, 0,
  135358. _vq_quantlist__44u6__p5_0,
  135359. NULL,
  135360. &_vq_auxt__44u6__p5_0,
  135361. NULL,
  135362. 0
  135363. };
  135364. static long _vq_quantlist__44u6__p6_0[] = {
  135365. 4,
  135366. 3,
  135367. 5,
  135368. 2,
  135369. 6,
  135370. 1,
  135371. 7,
  135372. 0,
  135373. 8,
  135374. };
  135375. static long _vq_lengthlist__44u6__p6_0[] = {
  135376. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135377. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  135378. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135379. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  135380. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  135381. 12,
  135382. };
  135383. static float _vq_quantthresh__44u6__p6_0[] = {
  135384. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135385. };
  135386. static long _vq_quantmap__44u6__p6_0[] = {
  135387. 7, 5, 3, 1, 0, 2, 4, 6,
  135388. 8,
  135389. };
  135390. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  135391. _vq_quantthresh__44u6__p6_0,
  135392. _vq_quantmap__44u6__p6_0,
  135393. 9,
  135394. 9
  135395. };
  135396. static static_codebook _44u6__p6_0 = {
  135397. 2, 81,
  135398. _vq_lengthlist__44u6__p6_0,
  135399. 1, -531628032, 1611661312, 4, 0,
  135400. _vq_quantlist__44u6__p6_0,
  135401. NULL,
  135402. &_vq_auxt__44u6__p6_0,
  135403. NULL,
  135404. 0
  135405. };
  135406. static long _vq_quantlist__44u6__p7_0[] = {
  135407. 1,
  135408. 0,
  135409. 2,
  135410. };
  135411. static long _vq_lengthlist__44u6__p7_0[] = {
  135412. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135413. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135414. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135415. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135416. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135417. 10,
  135418. };
  135419. static float _vq_quantthresh__44u6__p7_0[] = {
  135420. -5.5, 5.5,
  135421. };
  135422. static long _vq_quantmap__44u6__p7_0[] = {
  135423. 1, 0, 2,
  135424. };
  135425. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135426. _vq_quantthresh__44u6__p7_0,
  135427. _vq_quantmap__44u6__p7_0,
  135428. 3,
  135429. 3
  135430. };
  135431. static static_codebook _44u6__p7_0 = {
  135432. 4, 81,
  135433. _vq_lengthlist__44u6__p7_0,
  135434. 1, -529137664, 1618345984, 2, 0,
  135435. _vq_quantlist__44u6__p7_0,
  135436. NULL,
  135437. &_vq_auxt__44u6__p7_0,
  135438. NULL,
  135439. 0
  135440. };
  135441. static long _vq_quantlist__44u6__p7_1[] = {
  135442. 5,
  135443. 4,
  135444. 6,
  135445. 3,
  135446. 7,
  135447. 2,
  135448. 8,
  135449. 1,
  135450. 9,
  135451. 0,
  135452. 10,
  135453. };
  135454. static long _vq_lengthlist__44u6__p7_1[] = {
  135455. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135456. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135457. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135458. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135459. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135460. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135461. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135462. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135463. };
  135464. static float _vq_quantthresh__44u6__p7_1[] = {
  135465. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135466. 3.5, 4.5,
  135467. };
  135468. static long _vq_quantmap__44u6__p7_1[] = {
  135469. 9, 7, 5, 3, 1, 0, 2, 4,
  135470. 6, 8, 10,
  135471. };
  135472. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135473. _vq_quantthresh__44u6__p7_1,
  135474. _vq_quantmap__44u6__p7_1,
  135475. 11,
  135476. 11
  135477. };
  135478. static static_codebook _44u6__p7_1 = {
  135479. 2, 121,
  135480. _vq_lengthlist__44u6__p7_1,
  135481. 1, -531365888, 1611661312, 4, 0,
  135482. _vq_quantlist__44u6__p7_1,
  135483. NULL,
  135484. &_vq_auxt__44u6__p7_1,
  135485. NULL,
  135486. 0
  135487. };
  135488. static long _vq_quantlist__44u6__p8_0[] = {
  135489. 5,
  135490. 4,
  135491. 6,
  135492. 3,
  135493. 7,
  135494. 2,
  135495. 8,
  135496. 1,
  135497. 9,
  135498. 0,
  135499. 10,
  135500. };
  135501. static long _vq_lengthlist__44u6__p8_0[] = {
  135502. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135503. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135504. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135505. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135506. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135507. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135508. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135509. 12,13,13,14,14,14,15,15,15,
  135510. };
  135511. static float _vq_quantthresh__44u6__p8_0[] = {
  135512. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135513. 38.5, 49.5,
  135514. };
  135515. static long _vq_quantmap__44u6__p8_0[] = {
  135516. 9, 7, 5, 3, 1, 0, 2, 4,
  135517. 6, 8, 10,
  135518. };
  135519. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135520. _vq_quantthresh__44u6__p8_0,
  135521. _vq_quantmap__44u6__p8_0,
  135522. 11,
  135523. 11
  135524. };
  135525. static static_codebook _44u6__p8_0 = {
  135526. 2, 121,
  135527. _vq_lengthlist__44u6__p8_0,
  135528. 1, -524582912, 1618345984, 4, 0,
  135529. _vq_quantlist__44u6__p8_0,
  135530. NULL,
  135531. &_vq_auxt__44u6__p8_0,
  135532. NULL,
  135533. 0
  135534. };
  135535. static long _vq_quantlist__44u6__p8_1[] = {
  135536. 5,
  135537. 4,
  135538. 6,
  135539. 3,
  135540. 7,
  135541. 2,
  135542. 8,
  135543. 1,
  135544. 9,
  135545. 0,
  135546. 10,
  135547. };
  135548. static long _vq_lengthlist__44u6__p8_1[] = {
  135549. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135550. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135551. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135552. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135553. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135554. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135555. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135556. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135557. };
  135558. static float _vq_quantthresh__44u6__p8_1[] = {
  135559. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135560. 3.5, 4.5,
  135561. };
  135562. static long _vq_quantmap__44u6__p8_1[] = {
  135563. 9, 7, 5, 3, 1, 0, 2, 4,
  135564. 6, 8, 10,
  135565. };
  135566. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135567. _vq_quantthresh__44u6__p8_1,
  135568. _vq_quantmap__44u6__p8_1,
  135569. 11,
  135570. 11
  135571. };
  135572. static static_codebook _44u6__p8_1 = {
  135573. 2, 121,
  135574. _vq_lengthlist__44u6__p8_1,
  135575. 1, -531365888, 1611661312, 4, 0,
  135576. _vq_quantlist__44u6__p8_1,
  135577. NULL,
  135578. &_vq_auxt__44u6__p8_1,
  135579. NULL,
  135580. 0
  135581. };
  135582. static long _vq_quantlist__44u6__p9_0[] = {
  135583. 7,
  135584. 6,
  135585. 8,
  135586. 5,
  135587. 9,
  135588. 4,
  135589. 10,
  135590. 3,
  135591. 11,
  135592. 2,
  135593. 12,
  135594. 1,
  135595. 13,
  135596. 0,
  135597. 14,
  135598. };
  135599. static long _vq_lengthlist__44u6__p9_0[] = {
  135600. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135601. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135602. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135603. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135604. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135605. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135606. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135607. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135608. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135609. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135610. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135611. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135612. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135613. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135614. 14,
  135615. };
  135616. static float _vq_quantthresh__44u6__p9_0[] = {
  135617. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135618. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135619. };
  135620. static long _vq_quantmap__44u6__p9_0[] = {
  135621. 13, 11, 9, 7, 5, 3, 1, 0,
  135622. 2, 4, 6, 8, 10, 12, 14,
  135623. };
  135624. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135625. _vq_quantthresh__44u6__p9_0,
  135626. _vq_quantmap__44u6__p9_0,
  135627. 15,
  135628. 15
  135629. };
  135630. static static_codebook _44u6__p9_0 = {
  135631. 2, 225,
  135632. _vq_lengthlist__44u6__p9_0,
  135633. 1, -514071552, 1627381760, 4, 0,
  135634. _vq_quantlist__44u6__p9_0,
  135635. NULL,
  135636. &_vq_auxt__44u6__p9_0,
  135637. NULL,
  135638. 0
  135639. };
  135640. static long _vq_quantlist__44u6__p9_1[] = {
  135641. 7,
  135642. 6,
  135643. 8,
  135644. 5,
  135645. 9,
  135646. 4,
  135647. 10,
  135648. 3,
  135649. 11,
  135650. 2,
  135651. 12,
  135652. 1,
  135653. 13,
  135654. 0,
  135655. 14,
  135656. };
  135657. static long _vq_lengthlist__44u6__p9_1[] = {
  135658. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135659. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135660. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135661. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135662. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135663. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135664. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135665. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135666. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135667. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135668. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135669. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135670. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  135671. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  135672. 13,
  135673. };
  135674. static float _vq_quantthresh__44u6__p9_1[] = {
  135675. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135676. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135677. };
  135678. static long _vq_quantmap__44u6__p9_1[] = {
  135679. 13, 11, 9, 7, 5, 3, 1, 0,
  135680. 2, 4, 6, 8, 10, 12, 14,
  135681. };
  135682. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  135683. _vq_quantthresh__44u6__p9_1,
  135684. _vq_quantmap__44u6__p9_1,
  135685. 15,
  135686. 15
  135687. };
  135688. static static_codebook _44u6__p9_1 = {
  135689. 2, 225,
  135690. _vq_lengthlist__44u6__p9_1,
  135691. 1, -522338304, 1620115456, 4, 0,
  135692. _vq_quantlist__44u6__p9_1,
  135693. NULL,
  135694. &_vq_auxt__44u6__p9_1,
  135695. NULL,
  135696. 0
  135697. };
  135698. static long _vq_quantlist__44u6__p9_2[] = {
  135699. 8,
  135700. 7,
  135701. 9,
  135702. 6,
  135703. 10,
  135704. 5,
  135705. 11,
  135706. 4,
  135707. 12,
  135708. 3,
  135709. 13,
  135710. 2,
  135711. 14,
  135712. 1,
  135713. 15,
  135714. 0,
  135715. 16,
  135716. };
  135717. static long _vq_lengthlist__44u6__p9_2[] = {
  135718. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  135719. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  135720. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  135721. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135722. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135723. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135724. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135725. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135726. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135727. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  135728. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  135729. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  135730. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  135731. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  135732. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  135733. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  135734. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  135735. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  135736. 10,
  135737. };
  135738. static float _vq_quantthresh__44u6__p9_2[] = {
  135739. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135740. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135741. };
  135742. static long _vq_quantmap__44u6__p9_2[] = {
  135743. 15, 13, 11, 9, 7, 5, 3, 1,
  135744. 0, 2, 4, 6, 8, 10, 12, 14,
  135745. 16,
  135746. };
  135747. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  135748. _vq_quantthresh__44u6__p9_2,
  135749. _vq_quantmap__44u6__p9_2,
  135750. 17,
  135751. 17
  135752. };
  135753. static static_codebook _44u6__p9_2 = {
  135754. 2, 289,
  135755. _vq_lengthlist__44u6__p9_2,
  135756. 1, -529530880, 1611661312, 5, 0,
  135757. _vq_quantlist__44u6__p9_2,
  135758. NULL,
  135759. &_vq_auxt__44u6__p9_2,
  135760. NULL,
  135761. 0
  135762. };
  135763. static long _huff_lengthlist__44u6__short[] = {
  135764. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  135765. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  135766. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  135767. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  135768. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  135769. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  135770. 7, 6, 9,16,
  135771. };
  135772. static static_codebook _huff_book__44u6__short = {
  135773. 2, 100,
  135774. _huff_lengthlist__44u6__short,
  135775. 0, 0, 0, 0, 0,
  135776. NULL,
  135777. NULL,
  135778. NULL,
  135779. NULL,
  135780. 0
  135781. };
  135782. static long _huff_lengthlist__44u7__long[] = {
  135783. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  135784. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  135785. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  135786. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  135787. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  135788. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  135789. 12, 8, 6, 7,
  135790. };
  135791. static static_codebook _huff_book__44u7__long = {
  135792. 2, 100,
  135793. _huff_lengthlist__44u7__long,
  135794. 0, 0, 0, 0, 0,
  135795. NULL,
  135796. NULL,
  135797. NULL,
  135798. NULL,
  135799. 0
  135800. };
  135801. static long _vq_quantlist__44u7__p1_0[] = {
  135802. 1,
  135803. 0,
  135804. 2,
  135805. };
  135806. static long _vq_lengthlist__44u7__p1_0[] = {
  135807. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135808. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  135809. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135810. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  135811. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  135812. 12,
  135813. };
  135814. static float _vq_quantthresh__44u7__p1_0[] = {
  135815. -0.5, 0.5,
  135816. };
  135817. static long _vq_quantmap__44u7__p1_0[] = {
  135818. 1, 0, 2,
  135819. };
  135820. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  135821. _vq_quantthresh__44u7__p1_0,
  135822. _vq_quantmap__44u7__p1_0,
  135823. 3,
  135824. 3
  135825. };
  135826. static static_codebook _44u7__p1_0 = {
  135827. 4, 81,
  135828. _vq_lengthlist__44u7__p1_0,
  135829. 1, -535822336, 1611661312, 2, 0,
  135830. _vq_quantlist__44u7__p1_0,
  135831. NULL,
  135832. &_vq_auxt__44u7__p1_0,
  135833. NULL,
  135834. 0
  135835. };
  135836. static long _vq_quantlist__44u7__p2_0[] = {
  135837. 1,
  135838. 0,
  135839. 2,
  135840. };
  135841. static long _vq_lengthlist__44u7__p2_0[] = {
  135842. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135843. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135844. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  135845. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135846. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135847. 9,
  135848. };
  135849. static float _vq_quantthresh__44u7__p2_0[] = {
  135850. -0.5, 0.5,
  135851. };
  135852. static long _vq_quantmap__44u7__p2_0[] = {
  135853. 1, 0, 2,
  135854. };
  135855. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  135856. _vq_quantthresh__44u7__p2_0,
  135857. _vq_quantmap__44u7__p2_0,
  135858. 3,
  135859. 3
  135860. };
  135861. static static_codebook _44u7__p2_0 = {
  135862. 4, 81,
  135863. _vq_lengthlist__44u7__p2_0,
  135864. 1, -535822336, 1611661312, 2, 0,
  135865. _vq_quantlist__44u7__p2_0,
  135866. NULL,
  135867. &_vq_auxt__44u7__p2_0,
  135868. NULL,
  135869. 0
  135870. };
  135871. static long _vq_quantlist__44u7__p3_0[] = {
  135872. 2,
  135873. 1,
  135874. 3,
  135875. 0,
  135876. 4,
  135877. };
  135878. static long _vq_lengthlist__44u7__p3_0[] = {
  135879. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135880. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135881. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135882. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  135883. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  135884. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  135885. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  135886. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  135887. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  135888. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  135889. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  135890. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  135891. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  135892. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  135893. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  135894. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  135895. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  135896. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135897. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  135898. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  135899. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  135900. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  135901. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  135902. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  135903. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  135904. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  135905. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  135906. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  135907. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  135908. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  135909. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  135910. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  135911. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  135912. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  135913. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  135914. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  135915. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  135916. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  135917. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  135918. 0,
  135919. };
  135920. static float _vq_quantthresh__44u7__p3_0[] = {
  135921. -1.5, -0.5, 0.5, 1.5,
  135922. };
  135923. static long _vq_quantmap__44u7__p3_0[] = {
  135924. 3, 1, 0, 2, 4,
  135925. };
  135926. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  135927. _vq_quantthresh__44u7__p3_0,
  135928. _vq_quantmap__44u7__p3_0,
  135929. 5,
  135930. 5
  135931. };
  135932. static static_codebook _44u7__p3_0 = {
  135933. 4, 625,
  135934. _vq_lengthlist__44u7__p3_0,
  135935. 1, -533725184, 1611661312, 3, 0,
  135936. _vq_quantlist__44u7__p3_0,
  135937. NULL,
  135938. &_vq_auxt__44u7__p3_0,
  135939. NULL,
  135940. 0
  135941. };
  135942. static long _vq_quantlist__44u7__p4_0[] = {
  135943. 2,
  135944. 1,
  135945. 3,
  135946. 0,
  135947. 4,
  135948. };
  135949. static long _vq_lengthlist__44u7__p4_0[] = {
  135950. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135951. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  135952. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  135953. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  135954. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135955. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  135956. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  135957. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  135958. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135959. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135960. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  135961. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135962. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135963. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  135964. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  135965. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135966. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  135967. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135968. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  135969. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  135970. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135971. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135972. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  135973. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135974. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  135975. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  135976. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135977. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  135978. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  135979. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  135980. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  135981. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135982. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  135983. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135984. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  135985. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135986. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  135987. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  135988. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  135989. 14,
  135990. };
  135991. static float _vq_quantthresh__44u7__p4_0[] = {
  135992. -1.5, -0.5, 0.5, 1.5,
  135993. };
  135994. static long _vq_quantmap__44u7__p4_0[] = {
  135995. 3, 1, 0, 2, 4,
  135996. };
  135997. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  135998. _vq_quantthresh__44u7__p4_0,
  135999. _vq_quantmap__44u7__p4_0,
  136000. 5,
  136001. 5
  136002. };
  136003. static static_codebook _44u7__p4_0 = {
  136004. 4, 625,
  136005. _vq_lengthlist__44u7__p4_0,
  136006. 1, -533725184, 1611661312, 3, 0,
  136007. _vq_quantlist__44u7__p4_0,
  136008. NULL,
  136009. &_vq_auxt__44u7__p4_0,
  136010. NULL,
  136011. 0
  136012. };
  136013. static long _vq_quantlist__44u7__p5_0[] = {
  136014. 4,
  136015. 3,
  136016. 5,
  136017. 2,
  136018. 6,
  136019. 1,
  136020. 7,
  136021. 0,
  136022. 8,
  136023. };
  136024. static long _vq_lengthlist__44u7__p5_0[] = {
  136025. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  136026. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  136027. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  136028. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  136029. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  136030. 14,
  136031. };
  136032. static float _vq_quantthresh__44u7__p5_0[] = {
  136033. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136034. };
  136035. static long _vq_quantmap__44u7__p5_0[] = {
  136036. 7, 5, 3, 1, 0, 2, 4, 6,
  136037. 8,
  136038. };
  136039. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  136040. _vq_quantthresh__44u7__p5_0,
  136041. _vq_quantmap__44u7__p5_0,
  136042. 9,
  136043. 9
  136044. };
  136045. static static_codebook _44u7__p5_0 = {
  136046. 2, 81,
  136047. _vq_lengthlist__44u7__p5_0,
  136048. 1, -531628032, 1611661312, 4, 0,
  136049. _vq_quantlist__44u7__p5_0,
  136050. NULL,
  136051. &_vq_auxt__44u7__p5_0,
  136052. NULL,
  136053. 0
  136054. };
  136055. static long _vq_quantlist__44u7__p6_0[] = {
  136056. 4,
  136057. 3,
  136058. 5,
  136059. 2,
  136060. 6,
  136061. 1,
  136062. 7,
  136063. 0,
  136064. 8,
  136065. };
  136066. static long _vq_lengthlist__44u7__p6_0[] = {
  136067. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  136068. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136069. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  136070. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  136071. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  136072. 12,
  136073. };
  136074. static float _vq_quantthresh__44u7__p6_0[] = {
  136075. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136076. };
  136077. static long _vq_quantmap__44u7__p6_0[] = {
  136078. 7, 5, 3, 1, 0, 2, 4, 6,
  136079. 8,
  136080. };
  136081. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  136082. _vq_quantthresh__44u7__p6_0,
  136083. _vq_quantmap__44u7__p6_0,
  136084. 9,
  136085. 9
  136086. };
  136087. static static_codebook _44u7__p6_0 = {
  136088. 2, 81,
  136089. _vq_lengthlist__44u7__p6_0,
  136090. 1, -531628032, 1611661312, 4, 0,
  136091. _vq_quantlist__44u7__p6_0,
  136092. NULL,
  136093. &_vq_auxt__44u7__p6_0,
  136094. NULL,
  136095. 0
  136096. };
  136097. static long _vq_quantlist__44u7__p7_0[] = {
  136098. 1,
  136099. 0,
  136100. 2,
  136101. };
  136102. static long _vq_lengthlist__44u7__p7_0[] = {
  136103. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  136104. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  136105. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  136106. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  136107. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  136108. 10,
  136109. };
  136110. static float _vq_quantthresh__44u7__p7_0[] = {
  136111. -5.5, 5.5,
  136112. };
  136113. static long _vq_quantmap__44u7__p7_0[] = {
  136114. 1, 0, 2,
  136115. };
  136116. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  136117. _vq_quantthresh__44u7__p7_0,
  136118. _vq_quantmap__44u7__p7_0,
  136119. 3,
  136120. 3
  136121. };
  136122. static static_codebook _44u7__p7_0 = {
  136123. 4, 81,
  136124. _vq_lengthlist__44u7__p7_0,
  136125. 1, -529137664, 1618345984, 2, 0,
  136126. _vq_quantlist__44u7__p7_0,
  136127. NULL,
  136128. &_vq_auxt__44u7__p7_0,
  136129. NULL,
  136130. 0
  136131. };
  136132. static long _vq_quantlist__44u7__p7_1[] = {
  136133. 5,
  136134. 4,
  136135. 6,
  136136. 3,
  136137. 7,
  136138. 2,
  136139. 8,
  136140. 1,
  136141. 9,
  136142. 0,
  136143. 10,
  136144. };
  136145. static long _vq_lengthlist__44u7__p7_1[] = {
  136146. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  136147. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  136148. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  136149. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  136150. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136151. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136152. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  136153. 8, 9, 9, 9, 9, 9,10,10,10,
  136154. };
  136155. static float _vq_quantthresh__44u7__p7_1[] = {
  136156. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136157. 3.5, 4.5,
  136158. };
  136159. static long _vq_quantmap__44u7__p7_1[] = {
  136160. 9, 7, 5, 3, 1, 0, 2, 4,
  136161. 6, 8, 10,
  136162. };
  136163. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  136164. _vq_quantthresh__44u7__p7_1,
  136165. _vq_quantmap__44u7__p7_1,
  136166. 11,
  136167. 11
  136168. };
  136169. static static_codebook _44u7__p7_1 = {
  136170. 2, 121,
  136171. _vq_lengthlist__44u7__p7_1,
  136172. 1, -531365888, 1611661312, 4, 0,
  136173. _vq_quantlist__44u7__p7_1,
  136174. NULL,
  136175. &_vq_auxt__44u7__p7_1,
  136176. NULL,
  136177. 0
  136178. };
  136179. static long _vq_quantlist__44u7__p8_0[] = {
  136180. 5,
  136181. 4,
  136182. 6,
  136183. 3,
  136184. 7,
  136185. 2,
  136186. 8,
  136187. 1,
  136188. 9,
  136189. 0,
  136190. 10,
  136191. };
  136192. static long _vq_lengthlist__44u7__p8_0[] = {
  136193. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  136194. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  136195. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  136196. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  136197. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  136198. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  136199. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  136200. 12,13,13,14,14,15,15,15,16,
  136201. };
  136202. static float _vq_quantthresh__44u7__p8_0[] = {
  136203. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136204. 38.5, 49.5,
  136205. };
  136206. static long _vq_quantmap__44u7__p8_0[] = {
  136207. 9, 7, 5, 3, 1, 0, 2, 4,
  136208. 6, 8, 10,
  136209. };
  136210. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  136211. _vq_quantthresh__44u7__p8_0,
  136212. _vq_quantmap__44u7__p8_0,
  136213. 11,
  136214. 11
  136215. };
  136216. static static_codebook _44u7__p8_0 = {
  136217. 2, 121,
  136218. _vq_lengthlist__44u7__p8_0,
  136219. 1, -524582912, 1618345984, 4, 0,
  136220. _vq_quantlist__44u7__p8_0,
  136221. NULL,
  136222. &_vq_auxt__44u7__p8_0,
  136223. NULL,
  136224. 0
  136225. };
  136226. static long _vq_quantlist__44u7__p8_1[] = {
  136227. 5,
  136228. 4,
  136229. 6,
  136230. 3,
  136231. 7,
  136232. 2,
  136233. 8,
  136234. 1,
  136235. 9,
  136236. 0,
  136237. 10,
  136238. };
  136239. static long _vq_lengthlist__44u7__p8_1[] = {
  136240. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136241. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  136242. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136243. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  136244. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  136245. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136246. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136247. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136248. };
  136249. static float _vq_quantthresh__44u7__p8_1[] = {
  136250. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136251. 3.5, 4.5,
  136252. };
  136253. static long _vq_quantmap__44u7__p8_1[] = {
  136254. 9, 7, 5, 3, 1, 0, 2, 4,
  136255. 6, 8, 10,
  136256. };
  136257. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  136258. _vq_quantthresh__44u7__p8_1,
  136259. _vq_quantmap__44u7__p8_1,
  136260. 11,
  136261. 11
  136262. };
  136263. static static_codebook _44u7__p8_1 = {
  136264. 2, 121,
  136265. _vq_lengthlist__44u7__p8_1,
  136266. 1, -531365888, 1611661312, 4, 0,
  136267. _vq_quantlist__44u7__p8_1,
  136268. NULL,
  136269. &_vq_auxt__44u7__p8_1,
  136270. NULL,
  136271. 0
  136272. };
  136273. static long _vq_quantlist__44u7__p9_0[] = {
  136274. 5,
  136275. 4,
  136276. 6,
  136277. 3,
  136278. 7,
  136279. 2,
  136280. 8,
  136281. 1,
  136282. 9,
  136283. 0,
  136284. 10,
  136285. };
  136286. static long _vq_lengthlist__44u7__p9_0[] = {
  136287. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136288. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136289. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136290. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136291. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136292. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136293. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136294. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136295. };
  136296. static float _vq_quantthresh__44u7__p9_0[] = {
  136297. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136298. 2229.5, 2866.5,
  136299. };
  136300. static long _vq_quantmap__44u7__p9_0[] = {
  136301. 9, 7, 5, 3, 1, 0, 2, 4,
  136302. 6, 8, 10,
  136303. };
  136304. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136305. _vq_quantthresh__44u7__p9_0,
  136306. _vq_quantmap__44u7__p9_0,
  136307. 11,
  136308. 11
  136309. };
  136310. static static_codebook _44u7__p9_0 = {
  136311. 2, 121,
  136312. _vq_lengthlist__44u7__p9_0,
  136313. 1, -512171520, 1630791680, 4, 0,
  136314. _vq_quantlist__44u7__p9_0,
  136315. NULL,
  136316. &_vq_auxt__44u7__p9_0,
  136317. NULL,
  136318. 0
  136319. };
  136320. static long _vq_quantlist__44u7__p9_1[] = {
  136321. 6,
  136322. 5,
  136323. 7,
  136324. 4,
  136325. 8,
  136326. 3,
  136327. 9,
  136328. 2,
  136329. 10,
  136330. 1,
  136331. 11,
  136332. 0,
  136333. 12,
  136334. };
  136335. static long _vq_lengthlist__44u7__p9_1[] = {
  136336. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136337. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136338. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136339. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136340. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136341. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136342. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136343. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136344. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136345. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136346. 15,15,15,15,17,17,16,17,16,
  136347. };
  136348. static float _vq_quantthresh__44u7__p9_1[] = {
  136349. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136350. 122.5, 171.5, 220.5, 269.5,
  136351. };
  136352. static long _vq_quantmap__44u7__p9_1[] = {
  136353. 11, 9, 7, 5, 3, 1, 0, 2,
  136354. 4, 6, 8, 10, 12,
  136355. };
  136356. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136357. _vq_quantthresh__44u7__p9_1,
  136358. _vq_quantmap__44u7__p9_1,
  136359. 13,
  136360. 13
  136361. };
  136362. static static_codebook _44u7__p9_1 = {
  136363. 2, 169,
  136364. _vq_lengthlist__44u7__p9_1,
  136365. 1, -518889472, 1622704128, 4, 0,
  136366. _vq_quantlist__44u7__p9_1,
  136367. NULL,
  136368. &_vq_auxt__44u7__p9_1,
  136369. NULL,
  136370. 0
  136371. };
  136372. static long _vq_quantlist__44u7__p9_2[] = {
  136373. 24,
  136374. 23,
  136375. 25,
  136376. 22,
  136377. 26,
  136378. 21,
  136379. 27,
  136380. 20,
  136381. 28,
  136382. 19,
  136383. 29,
  136384. 18,
  136385. 30,
  136386. 17,
  136387. 31,
  136388. 16,
  136389. 32,
  136390. 15,
  136391. 33,
  136392. 14,
  136393. 34,
  136394. 13,
  136395. 35,
  136396. 12,
  136397. 36,
  136398. 11,
  136399. 37,
  136400. 10,
  136401. 38,
  136402. 9,
  136403. 39,
  136404. 8,
  136405. 40,
  136406. 7,
  136407. 41,
  136408. 6,
  136409. 42,
  136410. 5,
  136411. 43,
  136412. 4,
  136413. 44,
  136414. 3,
  136415. 45,
  136416. 2,
  136417. 46,
  136418. 1,
  136419. 47,
  136420. 0,
  136421. 48,
  136422. };
  136423. static long _vq_lengthlist__44u7__p9_2[] = {
  136424. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136425. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136426. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136427. 8,
  136428. };
  136429. static float _vq_quantthresh__44u7__p9_2[] = {
  136430. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136431. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136432. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136433. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136434. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136435. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136436. };
  136437. static long _vq_quantmap__44u7__p9_2[] = {
  136438. 47, 45, 43, 41, 39, 37, 35, 33,
  136439. 31, 29, 27, 25, 23, 21, 19, 17,
  136440. 15, 13, 11, 9, 7, 5, 3, 1,
  136441. 0, 2, 4, 6, 8, 10, 12, 14,
  136442. 16, 18, 20, 22, 24, 26, 28, 30,
  136443. 32, 34, 36, 38, 40, 42, 44, 46,
  136444. 48,
  136445. };
  136446. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136447. _vq_quantthresh__44u7__p9_2,
  136448. _vq_quantmap__44u7__p9_2,
  136449. 49,
  136450. 49
  136451. };
  136452. static static_codebook _44u7__p9_2 = {
  136453. 1, 49,
  136454. _vq_lengthlist__44u7__p9_2,
  136455. 1, -526909440, 1611661312, 6, 0,
  136456. _vq_quantlist__44u7__p9_2,
  136457. NULL,
  136458. &_vq_auxt__44u7__p9_2,
  136459. NULL,
  136460. 0
  136461. };
  136462. static long _huff_lengthlist__44u7__short[] = {
  136463. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136464. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136465. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136466. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136467. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136468. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136469. 6, 8, 5, 9,
  136470. };
  136471. static static_codebook _huff_book__44u7__short = {
  136472. 2, 100,
  136473. _huff_lengthlist__44u7__short,
  136474. 0, 0, 0, 0, 0,
  136475. NULL,
  136476. NULL,
  136477. NULL,
  136478. NULL,
  136479. 0
  136480. };
  136481. static long _huff_lengthlist__44u8__long[] = {
  136482. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136483. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136484. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136485. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136486. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136487. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136488. 10, 8, 8, 9,
  136489. };
  136490. static static_codebook _huff_book__44u8__long = {
  136491. 2, 100,
  136492. _huff_lengthlist__44u8__long,
  136493. 0, 0, 0, 0, 0,
  136494. NULL,
  136495. NULL,
  136496. NULL,
  136497. NULL,
  136498. 0
  136499. };
  136500. static long _huff_lengthlist__44u8__short[] = {
  136501. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136502. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136503. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136504. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136505. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136506. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136507. 10,10,15,17,
  136508. };
  136509. static static_codebook _huff_book__44u8__short = {
  136510. 2, 100,
  136511. _huff_lengthlist__44u8__short,
  136512. 0, 0, 0, 0, 0,
  136513. NULL,
  136514. NULL,
  136515. NULL,
  136516. NULL,
  136517. 0
  136518. };
  136519. static long _vq_quantlist__44u8_p1_0[] = {
  136520. 1,
  136521. 0,
  136522. 2,
  136523. };
  136524. static long _vq_lengthlist__44u8_p1_0[] = {
  136525. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136526. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136527. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136528. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136529. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136530. 10,
  136531. };
  136532. static float _vq_quantthresh__44u8_p1_0[] = {
  136533. -0.5, 0.5,
  136534. };
  136535. static long _vq_quantmap__44u8_p1_0[] = {
  136536. 1, 0, 2,
  136537. };
  136538. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136539. _vq_quantthresh__44u8_p1_0,
  136540. _vq_quantmap__44u8_p1_0,
  136541. 3,
  136542. 3
  136543. };
  136544. static static_codebook _44u8_p1_0 = {
  136545. 4, 81,
  136546. _vq_lengthlist__44u8_p1_0,
  136547. 1, -535822336, 1611661312, 2, 0,
  136548. _vq_quantlist__44u8_p1_0,
  136549. NULL,
  136550. &_vq_auxt__44u8_p1_0,
  136551. NULL,
  136552. 0
  136553. };
  136554. static long _vq_quantlist__44u8_p2_0[] = {
  136555. 2,
  136556. 1,
  136557. 3,
  136558. 0,
  136559. 4,
  136560. };
  136561. static long _vq_lengthlist__44u8_p2_0[] = {
  136562. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136563. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136564. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136565. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136566. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136567. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136568. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136569. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136570. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136571. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136572. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136573. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136574. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136575. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136576. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136577. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136578. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136579. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136580. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136581. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136582. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136583. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136584. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136585. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136586. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136587. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136588. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136589. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136590. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136591. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136592. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136593. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136594. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136595. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136596. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136597. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136598. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136599. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136600. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136601. 14,
  136602. };
  136603. static float _vq_quantthresh__44u8_p2_0[] = {
  136604. -1.5, -0.5, 0.5, 1.5,
  136605. };
  136606. static long _vq_quantmap__44u8_p2_0[] = {
  136607. 3, 1, 0, 2, 4,
  136608. };
  136609. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136610. _vq_quantthresh__44u8_p2_0,
  136611. _vq_quantmap__44u8_p2_0,
  136612. 5,
  136613. 5
  136614. };
  136615. static static_codebook _44u8_p2_0 = {
  136616. 4, 625,
  136617. _vq_lengthlist__44u8_p2_0,
  136618. 1, -533725184, 1611661312, 3, 0,
  136619. _vq_quantlist__44u8_p2_0,
  136620. NULL,
  136621. &_vq_auxt__44u8_p2_0,
  136622. NULL,
  136623. 0
  136624. };
  136625. static long _vq_quantlist__44u8_p3_0[] = {
  136626. 4,
  136627. 3,
  136628. 5,
  136629. 2,
  136630. 6,
  136631. 1,
  136632. 7,
  136633. 0,
  136634. 8,
  136635. };
  136636. static long _vq_lengthlist__44u8_p3_0[] = {
  136637. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136638. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136639. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136640. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136641. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136642. 12,
  136643. };
  136644. static float _vq_quantthresh__44u8_p3_0[] = {
  136645. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136646. };
  136647. static long _vq_quantmap__44u8_p3_0[] = {
  136648. 7, 5, 3, 1, 0, 2, 4, 6,
  136649. 8,
  136650. };
  136651. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136652. _vq_quantthresh__44u8_p3_0,
  136653. _vq_quantmap__44u8_p3_0,
  136654. 9,
  136655. 9
  136656. };
  136657. static static_codebook _44u8_p3_0 = {
  136658. 2, 81,
  136659. _vq_lengthlist__44u8_p3_0,
  136660. 1, -531628032, 1611661312, 4, 0,
  136661. _vq_quantlist__44u8_p3_0,
  136662. NULL,
  136663. &_vq_auxt__44u8_p3_0,
  136664. NULL,
  136665. 0
  136666. };
  136667. static long _vq_quantlist__44u8_p4_0[] = {
  136668. 8,
  136669. 7,
  136670. 9,
  136671. 6,
  136672. 10,
  136673. 5,
  136674. 11,
  136675. 4,
  136676. 12,
  136677. 3,
  136678. 13,
  136679. 2,
  136680. 14,
  136681. 1,
  136682. 15,
  136683. 0,
  136684. 16,
  136685. };
  136686. static long _vq_lengthlist__44u8_p4_0[] = {
  136687. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  136688. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  136689. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  136690. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  136691. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  136692. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  136693. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  136694. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  136695. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  136696. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  136697. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  136698. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  136699. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  136700. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  136701. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  136702. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  136703. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  136704. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  136705. 14,
  136706. };
  136707. static float _vq_quantthresh__44u8_p4_0[] = {
  136708. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136709. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136710. };
  136711. static long _vq_quantmap__44u8_p4_0[] = {
  136712. 15, 13, 11, 9, 7, 5, 3, 1,
  136713. 0, 2, 4, 6, 8, 10, 12, 14,
  136714. 16,
  136715. };
  136716. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  136717. _vq_quantthresh__44u8_p4_0,
  136718. _vq_quantmap__44u8_p4_0,
  136719. 17,
  136720. 17
  136721. };
  136722. static static_codebook _44u8_p4_0 = {
  136723. 2, 289,
  136724. _vq_lengthlist__44u8_p4_0,
  136725. 1, -529530880, 1611661312, 5, 0,
  136726. _vq_quantlist__44u8_p4_0,
  136727. NULL,
  136728. &_vq_auxt__44u8_p4_0,
  136729. NULL,
  136730. 0
  136731. };
  136732. static long _vq_quantlist__44u8_p5_0[] = {
  136733. 1,
  136734. 0,
  136735. 2,
  136736. };
  136737. static long _vq_lengthlist__44u8_p5_0[] = {
  136738. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  136739. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  136740. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  136741. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  136742. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  136743. 10,
  136744. };
  136745. static float _vq_quantthresh__44u8_p5_0[] = {
  136746. -5.5, 5.5,
  136747. };
  136748. static long _vq_quantmap__44u8_p5_0[] = {
  136749. 1, 0, 2,
  136750. };
  136751. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  136752. _vq_quantthresh__44u8_p5_0,
  136753. _vq_quantmap__44u8_p5_0,
  136754. 3,
  136755. 3
  136756. };
  136757. static static_codebook _44u8_p5_0 = {
  136758. 4, 81,
  136759. _vq_lengthlist__44u8_p5_0,
  136760. 1, -529137664, 1618345984, 2, 0,
  136761. _vq_quantlist__44u8_p5_0,
  136762. NULL,
  136763. &_vq_auxt__44u8_p5_0,
  136764. NULL,
  136765. 0
  136766. };
  136767. static long _vq_quantlist__44u8_p5_1[] = {
  136768. 5,
  136769. 4,
  136770. 6,
  136771. 3,
  136772. 7,
  136773. 2,
  136774. 8,
  136775. 1,
  136776. 9,
  136777. 0,
  136778. 10,
  136779. };
  136780. static long _vq_lengthlist__44u8_p5_1[] = {
  136781. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  136782. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  136783. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  136784. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  136785. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  136786. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  136787. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  136788. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  136789. };
  136790. static float _vq_quantthresh__44u8_p5_1[] = {
  136791. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136792. 3.5, 4.5,
  136793. };
  136794. static long _vq_quantmap__44u8_p5_1[] = {
  136795. 9, 7, 5, 3, 1, 0, 2, 4,
  136796. 6, 8, 10,
  136797. };
  136798. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  136799. _vq_quantthresh__44u8_p5_1,
  136800. _vq_quantmap__44u8_p5_1,
  136801. 11,
  136802. 11
  136803. };
  136804. static static_codebook _44u8_p5_1 = {
  136805. 2, 121,
  136806. _vq_lengthlist__44u8_p5_1,
  136807. 1, -531365888, 1611661312, 4, 0,
  136808. _vq_quantlist__44u8_p5_1,
  136809. NULL,
  136810. &_vq_auxt__44u8_p5_1,
  136811. NULL,
  136812. 0
  136813. };
  136814. static long _vq_quantlist__44u8_p6_0[] = {
  136815. 6,
  136816. 5,
  136817. 7,
  136818. 4,
  136819. 8,
  136820. 3,
  136821. 9,
  136822. 2,
  136823. 10,
  136824. 1,
  136825. 11,
  136826. 0,
  136827. 12,
  136828. };
  136829. static long _vq_lengthlist__44u8_p6_0[] = {
  136830. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  136831. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  136832. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  136833. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  136834. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  136835. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  136836. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  136837. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  136838. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  136839. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  136840. 11,11,11,11,11,12,11,12,12,
  136841. };
  136842. static float _vq_quantthresh__44u8_p6_0[] = {
  136843. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  136844. 12.5, 17.5, 22.5, 27.5,
  136845. };
  136846. static long _vq_quantmap__44u8_p6_0[] = {
  136847. 11, 9, 7, 5, 3, 1, 0, 2,
  136848. 4, 6, 8, 10, 12,
  136849. };
  136850. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  136851. _vq_quantthresh__44u8_p6_0,
  136852. _vq_quantmap__44u8_p6_0,
  136853. 13,
  136854. 13
  136855. };
  136856. static static_codebook _44u8_p6_0 = {
  136857. 2, 169,
  136858. _vq_lengthlist__44u8_p6_0,
  136859. 1, -526516224, 1616117760, 4, 0,
  136860. _vq_quantlist__44u8_p6_0,
  136861. NULL,
  136862. &_vq_auxt__44u8_p6_0,
  136863. NULL,
  136864. 0
  136865. };
  136866. static long _vq_quantlist__44u8_p6_1[] = {
  136867. 2,
  136868. 1,
  136869. 3,
  136870. 0,
  136871. 4,
  136872. };
  136873. static long _vq_lengthlist__44u8_p6_1[] = {
  136874. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  136875. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  136876. };
  136877. static float _vq_quantthresh__44u8_p6_1[] = {
  136878. -1.5, -0.5, 0.5, 1.5,
  136879. };
  136880. static long _vq_quantmap__44u8_p6_1[] = {
  136881. 3, 1, 0, 2, 4,
  136882. };
  136883. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  136884. _vq_quantthresh__44u8_p6_1,
  136885. _vq_quantmap__44u8_p6_1,
  136886. 5,
  136887. 5
  136888. };
  136889. static static_codebook _44u8_p6_1 = {
  136890. 2, 25,
  136891. _vq_lengthlist__44u8_p6_1,
  136892. 1, -533725184, 1611661312, 3, 0,
  136893. _vq_quantlist__44u8_p6_1,
  136894. NULL,
  136895. &_vq_auxt__44u8_p6_1,
  136896. NULL,
  136897. 0
  136898. };
  136899. static long _vq_quantlist__44u8_p7_0[] = {
  136900. 6,
  136901. 5,
  136902. 7,
  136903. 4,
  136904. 8,
  136905. 3,
  136906. 9,
  136907. 2,
  136908. 10,
  136909. 1,
  136910. 11,
  136911. 0,
  136912. 12,
  136913. };
  136914. static long _vq_lengthlist__44u8_p7_0[] = {
  136915. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  136916. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  136917. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  136918. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  136919. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  136920. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  136921. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  136922. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  136923. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  136924. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  136925. 13,13,14,14,14,15,15,15,16,
  136926. };
  136927. static float _vq_quantthresh__44u8_p7_0[] = {
  136928. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  136929. 27.5, 38.5, 49.5, 60.5,
  136930. };
  136931. static long _vq_quantmap__44u8_p7_0[] = {
  136932. 11, 9, 7, 5, 3, 1, 0, 2,
  136933. 4, 6, 8, 10, 12,
  136934. };
  136935. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  136936. _vq_quantthresh__44u8_p7_0,
  136937. _vq_quantmap__44u8_p7_0,
  136938. 13,
  136939. 13
  136940. };
  136941. static static_codebook _44u8_p7_0 = {
  136942. 2, 169,
  136943. _vq_lengthlist__44u8_p7_0,
  136944. 1, -523206656, 1618345984, 4, 0,
  136945. _vq_quantlist__44u8_p7_0,
  136946. NULL,
  136947. &_vq_auxt__44u8_p7_0,
  136948. NULL,
  136949. 0
  136950. };
  136951. static long _vq_quantlist__44u8_p7_1[] = {
  136952. 5,
  136953. 4,
  136954. 6,
  136955. 3,
  136956. 7,
  136957. 2,
  136958. 8,
  136959. 1,
  136960. 9,
  136961. 0,
  136962. 10,
  136963. };
  136964. static long _vq_lengthlist__44u8_p7_1[] = {
  136965. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136966. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  136967. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136968. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  136969. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  136970. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136971. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136972. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136973. };
  136974. static float _vq_quantthresh__44u8_p7_1[] = {
  136975. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136976. 3.5, 4.5,
  136977. };
  136978. static long _vq_quantmap__44u8_p7_1[] = {
  136979. 9, 7, 5, 3, 1, 0, 2, 4,
  136980. 6, 8, 10,
  136981. };
  136982. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  136983. _vq_quantthresh__44u8_p7_1,
  136984. _vq_quantmap__44u8_p7_1,
  136985. 11,
  136986. 11
  136987. };
  136988. static static_codebook _44u8_p7_1 = {
  136989. 2, 121,
  136990. _vq_lengthlist__44u8_p7_1,
  136991. 1, -531365888, 1611661312, 4, 0,
  136992. _vq_quantlist__44u8_p7_1,
  136993. NULL,
  136994. &_vq_auxt__44u8_p7_1,
  136995. NULL,
  136996. 0
  136997. };
  136998. static long _vq_quantlist__44u8_p8_0[] = {
  136999. 7,
  137000. 6,
  137001. 8,
  137002. 5,
  137003. 9,
  137004. 4,
  137005. 10,
  137006. 3,
  137007. 11,
  137008. 2,
  137009. 12,
  137010. 1,
  137011. 13,
  137012. 0,
  137013. 14,
  137014. };
  137015. static long _vq_lengthlist__44u8_p8_0[] = {
  137016. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  137017. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137018. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  137019. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  137020. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  137021. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  137022. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  137023. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  137024. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  137025. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  137026. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  137027. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  137028. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  137029. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  137030. 17,
  137031. };
  137032. static float _vq_quantthresh__44u8_p8_0[] = {
  137033. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137034. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137035. };
  137036. static long _vq_quantmap__44u8_p8_0[] = {
  137037. 13, 11, 9, 7, 5, 3, 1, 0,
  137038. 2, 4, 6, 8, 10, 12, 14,
  137039. };
  137040. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  137041. _vq_quantthresh__44u8_p8_0,
  137042. _vq_quantmap__44u8_p8_0,
  137043. 15,
  137044. 15
  137045. };
  137046. static static_codebook _44u8_p8_0 = {
  137047. 2, 225,
  137048. _vq_lengthlist__44u8_p8_0,
  137049. 1, -520986624, 1620377600, 4, 0,
  137050. _vq_quantlist__44u8_p8_0,
  137051. NULL,
  137052. &_vq_auxt__44u8_p8_0,
  137053. NULL,
  137054. 0
  137055. };
  137056. static long _vq_quantlist__44u8_p8_1[] = {
  137057. 10,
  137058. 9,
  137059. 11,
  137060. 8,
  137061. 12,
  137062. 7,
  137063. 13,
  137064. 6,
  137065. 14,
  137066. 5,
  137067. 15,
  137068. 4,
  137069. 16,
  137070. 3,
  137071. 17,
  137072. 2,
  137073. 18,
  137074. 1,
  137075. 19,
  137076. 0,
  137077. 20,
  137078. };
  137079. static long _vq_lengthlist__44u8_p8_1[] = {
  137080. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137081. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137082. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  137083. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137084. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137085. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137086. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137087. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  137088. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137089. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137090. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  137091. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  137092. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137093. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137094. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137095. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137096. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  137097. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137098. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137099. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137100. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137101. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137102. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137103. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  137104. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137105. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137106. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  137107. 10,10,10,10,10,10,10,10,10,
  137108. };
  137109. static float _vq_quantthresh__44u8_p8_1[] = {
  137110. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137111. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137112. 6.5, 7.5, 8.5, 9.5,
  137113. };
  137114. static long _vq_quantmap__44u8_p8_1[] = {
  137115. 19, 17, 15, 13, 11, 9, 7, 5,
  137116. 3, 1, 0, 2, 4, 6, 8, 10,
  137117. 12, 14, 16, 18, 20,
  137118. };
  137119. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  137120. _vq_quantthresh__44u8_p8_1,
  137121. _vq_quantmap__44u8_p8_1,
  137122. 21,
  137123. 21
  137124. };
  137125. static static_codebook _44u8_p8_1 = {
  137126. 2, 441,
  137127. _vq_lengthlist__44u8_p8_1,
  137128. 1, -529268736, 1611661312, 5, 0,
  137129. _vq_quantlist__44u8_p8_1,
  137130. NULL,
  137131. &_vq_auxt__44u8_p8_1,
  137132. NULL,
  137133. 0
  137134. };
  137135. static long _vq_quantlist__44u8_p9_0[] = {
  137136. 4,
  137137. 3,
  137138. 5,
  137139. 2,
  137140. 6,
  137141. 1,
  137142. 7,
  137143. 0,
  137144. 8,
  137145. };
  137146. static long _vq_lengthlist__44u8_p9_0[] = {
  137147. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  137148. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137149. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137150. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137151. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  137152. 8,
  137153. };
  137154. static float _vq_quantthresh__44u8_p9_0[] = {
  137155. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  137156. };
  137157. static long _vq_quantmap__44u8_p9_0[] = {
  137158. 7, 5, 3, 1, 0, 2, 4, 6,
  137159. 8,
  137160. };
  137161. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  137162. _vq_quantthresh__44u8_p9_0,
  137163. _vq_quantmap__44u8_p9_0,
  137164. 9,
  137165. 9
  137166. };
  137167. static static_codebook _44u8_p9_0 = {
  137168. 2, 81,
  137169. _vq_lengthlist__44u8_p9_0,
  137170. 1, -511895552, 1631393792, 4, 0,
  137171. _vq_quantlist__44u8_p9_0,
  137172. NULL,
  137173. &_vq_auxt__44u8_p9_0,
  137174. NULL,
  137175. 0
  137176. };
  137177. static long _vq_quantlist__44u8_p9_1[] = {
  137178. 9,
  137179. 8,
  137180. 10,
  137181. 7,
  137182. 11,
  137183. 6,
  137184. 12,
  137185. 5,
  137186. 13,
  137187. 4,
  137188. 14,
  137189. 3,
  137190. 15,
  137191. 2,
  137192. 16,
  137193. 1,
  137194. 17,
  137195. 0,
  137196. 18,
  137197. };
  137198. static long _vq_lengthlist__44u8_p9_1[] = {
  137199. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  137200. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  137201. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  137202. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  137203. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  137204. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  137205. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  137206. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  137207. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  137208. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  137209. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  137210. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  137211. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  137212. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  137213. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  137214. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  137215. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  137216. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  137217. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  137218. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  137219. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  137220. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  137221. 16,15,16,16,16,16,16,16,16,
  137222. };
  137223. static float _vq_quantthresh__44u8_p9_1[] = {
  137224. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137225. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137226. 367.5, 416.5,
  137227. };
  137228. static long _vq_quantmap__44u8_p9_1[] = {
  137229. 17, 15, 13, 11, 9, 7, 5, 3,
  137230. 1, 0, 2, 4, 6, 8, 10, 12,
  137231. 14, 16, 18,
  137232. };
  137233. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  137234. _vq_quantthresh__44u8_p9_1,
  137235. _vq_quantmap__44u8_p9_1,
  137236. 19,
  137237. 19
  137238. };
  137239. static static_codebook _44u8_p9_1 = {
  137240. 2, 361,
  137241. _vq_lengthlist__44u8_p9_1,
  137242. 1, -518287360, 1622704128, 5, 0,
  137243. _vq_quantlist__44u8_p9_1,
  137244. NULL,
  137245. &_vq_auxt__44u8_p9_1,
  137246. NULL,
  137247. 0
  137248. };
  137249. static long _vq_quantlist__44u8_p9_2[] = {
  137250. 24,
  137251. 23,
  137252. 25,
  137253. 22,
  137254. 26,
  137255. 21,
  137256. 27,
  137257. 20,
  137258. 28,
  137259. 19,
  137260. 29,
  137261. 18,
  137262. 30,
  137263. 17,
  137264. 31,
  137265. 16,
  137266. 32,
  137267. 15,
  137268. 33,
  137269. 14,
  137270. 34,
  137271. 13,
  137272. 35,
  137273. 12,
  137274. 36,
  137275. 11,
  137276. 37,
  137277. 10,
  137278. 38,
  137279. 9,
  137280. 39,
  137281. 8,
  137282. 40,
  137283. 7,
  137284. 41,
  137285. 6,
  137286. 42,
  137287. 5,
  137288. 43,
  137289. 4,
  137290. 44,
  137291. 3,
  137292. 45,
  137293. 2,
  137294. 46,
  137295. 1,
  137296. 47,
  137297. 0,
  137298. 48,
  137299. };
  137300. static long _vq_lengthlist__44u8_p9_2[] = {
  137301. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137302. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137303. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137304. 7,
  137305. };
  137306. static float _vq_quantthresh__44u8_p9_2[] = {
  137307. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137308. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137309. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137310. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137311. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137312. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137313. };
  137314. static long _vq_quantmap__44u8_p9_2[] = {
  137315. 47, 45, 43, 41, 39, 37, 35, 33,
  137316. 31, 29, 27, 25, 23, 21, 19, 17,
  137317. 15, 13, 11, 9, 7, 5, 3, 1,
  137318. 0, 2, 4, 6, 8, 10, 12, 14,
  137319. 16, 18, 20, 22, 24, 26, 28, 30,
  137320. 32, 34, 36, 38, 40, 42, 44, 46,
  137321. 48,
  137322. };
  137323. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137324. _vq_quantthresh__44u8_p9_2,
  137325. _vq_quantmap__44u8_p9_2,
  137326. 49,
  137327. 49
  137328. };
  137329. static static_codebook _44u8_p9_2 = {
  137330. 1, 49,
  137331. _vq_lengthlist__44u8_p9_2,
  137332. 1, -526909440, 1611661312, 6, 0,
  137333. _vq_quantlist__44u8_p9_2,
  137334. NULL,
  137335. &_vq_auxt__44u8_p9_2,
  137336. NULL,
  137337. 0
  137338. };
  137339. static long _huff_lengthlist__44u9__long[] = {
  137340. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137341. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137342. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137343. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137344. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137345. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137346. 10, 8, 8, 9,
  137347. };
  137348. static static_codebook _huff_book__44u9__long = {
  137349. 2, 100,
  137350. _huff_lengthlist__44u9__long,
  137351. 0, 0, 0, 0, 0,
  137352. NULL,
  137353. NULL,
  137354. NULL,
  137355. NULL,
  137356. 0
  137357. };
  137358. static long _huff_lengthlist__44u9__short[] = {
  137359. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137360. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137361. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137362. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137363. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137364. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137365. 9, 9,12,15,
  137366. };
  137367. static static_codebook _huff_book__44u9__short = {
  137368. 2, 100,
  137369. _huff_lengthlist__44u9__short,
  137370. 0, 0, 0, 0, 0,
  137371. NULL,
  137372. NULL,
  137373. NULL,
  137374. NULL,
  137375. 0
  137376. };
  137377. static long _vq_quantlist__44u9_p1_0[] = {
  137378. 1,
  137379. 0,
  137380. 2,
  137381. };
  137382. static long _vq_lengthlist__44u9_p1_0[] = {
  137383. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  137384. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  137385. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  137386. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  137387. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  137388. 10,
  137389. };
  137390. static float _vq_quantthresh__44u9_p1_0[] = {
  137391. -0.5, 0.5,
  137392. };
  137393. static long _vq_quantmap__44u9_p1_0[] = {
  137394. 1, 0, 2,
  137395. };
  137396. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137397. _vq_quantthresh__44u9_p1_0,
  137398. _vq_quantmap__44u9_p1_0,
  137399. 3,
  137400. 3
  137401. };
  137402. static static_codebook _44u9_p1_0 = {
  137403. 4, 81,
  137404. _vq_lengthlist__44u9_p1_0,
  137405. 1, -535822336, 1611661312, 2, 0,
  137406. _vq_quantlist__44u9_p1_0,
  137407. NULL,
  137408. &_vq_auxt__44u9_p1_0,
  137409. NULL,
  137410. 0
  137411. };
  137412. static long _vq_quantlist__44u9_p2_0[] = {
  137413. 2,
  137414. 1,
  137415. 3,
  137416. 0,
  137417. 4,
  137418. };
  137419. static long _vq_lengthlist__44u9_p2_0[] = {
  137420. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137421. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137422. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137423. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137424. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137425. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137426. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137427. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137428. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137429. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137430. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137431. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137432. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137433. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137434. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137435. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137436. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137437. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137438. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137439. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137440. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137441. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137442. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137443. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137444. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137445. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137446. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137447. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137448. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137449. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137450. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137451. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137452. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137453. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137454. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137455. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137456. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137457. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137458. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137459. 14,
  137460. };
  137461. static float _vq_quantthresh__44u9_p2_0[] = {
  137462. -1.5, -0.5, 0.5, 1.5,
  137463. };
  137464. static long _vq_quantmap__44u9_p2_0[] = {
  137465. 3, 1, 0, 2, 4,
  137466. };
  137467. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137468. _vq_quantthresh__44u9_p2_0,
  137469. _vq_quantmap__44u9_p2_0,
  137470. 5,
  137471. 5
  137472. };
  137473. static static_codebook _44u9_p2_0 = {
  137474. 4, 625,
  137475. _vq_lengthlist__44u9_p2_0,
  137476. 1, -533725184, 1611661312, 3, 0,
  137477. _vq_quantlist__44u9_p2_0,
  137478. NULL,
  137479. &_vq_auxt__44u9_p2_0,
  137480. NULL,
  137481. 0
  137482. };
  137483. static long _vq_quantlist__44u9_p3_0[] = {
  137484. 4,
  137485. 3,
  137486. 5,
  137487. 2,
  137488. 6,
  137489. 1,
  137490. 7,
  137491. 0,
  137492. 8,
  137493. };
  137494. static long _vq_lengthlist__44u9_p3_0[] = {
  137495. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137496. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137497. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137498. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137499. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137500. 11,
  137501. };
  137502. static float _vq_quantthresh__44u9_p3_0[] = {
  137503. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137504. };
  137505. static long _vq_quantmap__44u9_p3_0[] = {
  137506. 7, 5, 3, 1, 0, 2, 4, 6,
  137507. 8,
  137508. };
  137509. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137510. _vq_quantthresh__44u9_p3_0,
  137511. _vq_quantmap__44u9_p3_0,
  137512. 9,
  137513. 9
  137514. };
  137515. static static_codebook _44u9_p3_0 = {
  137516. 2, 81,
  137517. _vq_lengthlist__44u9_p3_0,
  137518. 1, -531628032, 1611661312, 4, 0,
  137519. _vq_quantlist__44u9_p3_0,
  137520. NULL,
  137521. &_vq_auxt__44u9_p3_0,
  137522. NULL,
  137523. 0
  137524. };
  137525. static long _vq_quantlist__44u9_p4_0[] = {
  137526. 8,
  137527. 7,
  137528. 9,
  137529. 6,
  137530. 10,
  137531. 5,
  137532. 11,
  137533. 4,
  137534. 12,
  137535. 3,
  137536. 13,
  137537. 2,
  137538. 14,
  137539. 1,
  137540. 15,
  137541. 0,
  137542. 16,
  137543. };
  137544. static long _vq_lengthlist__44u9_p4_0[] = {
  137545. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137546. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137547. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137548. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137549. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137550. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137551. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137552. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137553. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137554. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137555. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137556. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137557. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137558. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137559. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137560. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137561. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137562. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137563. 14,
  137564. };
  137565. static float _vq_quantthresh__44u9_p4_0[] = {
  137566. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137567. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137568. };
  137569. static long _vq_quantmap__44u9_p4_0[] = {
  137570. 15, 13, 11, 9, 7, 5, 3, 1,
  137571. 0, 2, 4, 6, 8, 10, 12, 14,
  137572. 16,
  137573. };
  137574. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137575. _vq_quantthresh__44u9_p4_0,
  137576. _vq_quantmap__44u9_p4_0,
  137577. 17,
  137578. 17
  137579. };
  137580. static static_codebook _44u9_p4_0 = {
  137581. 2, 289,
  137582. _vq_lengthlist__44u9_p4_0,
  137583. 1, -529530880, 1611661312, 5, 0,
  137584. _vq_quantlist__44u9_p4_0,
  137585. NULL,
  137586. &_vq_auxt__44u9_p4_0,
  137587. NULL,
  137588. 0
  137589. };
  137590. static long _vq_quantlist__44u9_p5_0[] = {
  137591. 1,
  137592. 0,
  137593. 2,
  137594. };
  137595. static long _vq_lengthlist__44u9_p5_0[] = {
  137596. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137597. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137598. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137599. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137600. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137601. 10,
  137602. };
  137603. static float _vq_quantthresh__44u9_p5_0[] = {
  137604. -5.5, 5.5,
  137605. };
  137606. static long _vq_quantmap__44u9_p5_0[] = {
  137607. 1, 0, 2,
  137608. };
  137609. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137610. _vq_quantthresh__44u9_p5_0,
  137611. _vq_quantmap__44u9_p5_0,
  137612. 3,
  137613. 3
  137614. };
  137615. static static_codebook _44u9_p5_0 = {
  137616. 4, 81,
  137617. _vq_lengthlist__44u9_p5_0,
  137618. 1, -529137664, 1618345984, 2, 0,
  137619. _vq_quantlist__44u9_p5_0,
  137620. NULL,
  137621. &_vq_auxt__44u9_p5_0,
  137622. NULL,
  137623. 0
  137624. };
  137625. static long _vq_quantlist__44u9_p5_1[] = {
  137626. 5,
  137627. 4,
  137628. 6,
  137629. 3,
  137630. 7,
  137631. 2,
  137632. 8,
  137633. 1,
  137634. 9,
  137635. 0,
  137636. 10,
  137637. };
  137638. static long _vq_lengthlist__44u9_p5_1[] = {
  137639. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137640. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137641. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137642. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137643. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137644. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137645. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137646. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137647. };
  137648. static float _vq_quantthresh__44u9_p5_1[] = {
  137649. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137650. 3.5, 4.5,
  137651. };
  137652. static long _vq_quantmap__44u9_p5_1[] = {
  137653. 9, 7, 5, 3, 1, 0, 2, 4,
  137654. 6, 8, 10,
  137655. };
  137656. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137657. _vq_quantthresh__44u9_p5_1,
  137658. _vq_quantmap__44u9_p5_1,
  137659. 11,
  137660. 11
  137661. };
  137662. static static_codebook _44u9_p5_1 = {
  137663. 2, 121,
  137664. _vq_lengthlist__44u9_p5_1,
  137665. 1, -531365888, 1611661312, 4, 0,
  137666. _vq_quantlist__44u9_p5_1,
  137667. NULL,
  137668. &_vq_auxt__44u9_p5_1,
  137669. NULL,
  137670. 0
  137671. };
  137672. static long _vq_quantlist__44u9_p6_0[] = {
  137673. 6,
  137674. 5,
  137675. 7,
  137676. 4,
  137677. 8,
  137678. 3,
  137679. 9,
  137680. 2,
  137681. 10,
  137682. 1,
  137683. 11,
  137684. 0,
  137685. 12,
  137686. };
  137687. static long _vq_lengthlist__44u9_p6_0[] = {
  137688. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137689. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  137690. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137691. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  137692. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  137693. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137694. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137695. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  137696. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  137697. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137698. 10,11,11,11,11,12,11,12,12,
  137699. };
  137700. static float _vq_quantthresh__44u9_p6_0[] = {
  137701. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137702. 12.5, 17.5, 22.5, 27.5,
  137703. };
  137704. static long _vq_quantmap__44u9_p6_0[] = {
  137705. 11, 9, 7, 5, 3, 1, 0, 2,
  137706. 4, 6, 8, 10, 12,
  137707. };
  137708. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  137709. _vq_quantthresh__44u9_p6_0,
  137710. _vq_quantmap__44u9_p6_0,
  137711. 13,
  137712. 13
  137713. };
  137714. static static_codebook _44u9_p6_0 = {
  137715. 2, 169,
  137716. _vq_lengthlist__44u9_p6_0,
  137717. 1, -526516224, 1616117760, 4, 0,
  137718. _vq_quantlist__44u9_p6_0,
  137719. NULL,
  137720. &_vq_auxt__44u9_p6_0,
  137721. NULL,
  137722. 0
  137723. };
  137724. static long _vq_quantlist__44u9_p6_1[] = {
  137725. 2,
  137726. 1,
  137727. 3,
  137728. 0,
  137729. 4,
  137730. };
  137731. static long _vq_lengthlist__44u9_p6_1[] = {
  137732. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  137733. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137734. };
  137735. static float _vq_quantthresh__44u9_p6_1[] = {
  137736. -1.5, -0.5, 0.5, 1.5,
  137737. };
  137738. static long _vq_quantmap__44u9_p6_1[] = {
  137739. 3, 1, 0, 2, 4,
  137740. };
  137741. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  137742. _vq_quantthresh__44u9_p6_1,
  137743. _vq_quantmap__44u9_p6_1,
  137744. 5,
  137745. 5
  137746. };
  137747. static static_codebook _44u9_p6_1 = {
  137748. 2, 25,
  137749. _vq_lengthlist__44u9_p6_1,
  137750. 1, -533725184, 1611661312, 3, 0,
  137751. _vq_quantlist__44u9_p6_1,
  137752. NULL,
  137753. &_vq_auxt__44u9_p6_1,
  137754. NULL,
  137755. 0
  137756. };
  137757. static long _vq_quantlist__44u9_p7_0[] = {
  137758. 6,
  137759. 5,
  137760. 7,
  137761. 4,
  137762. 8,
  137763. 3,
  137764. 9,
  137765. 2,
  137766. 10,
  137767. 1,
  137768. 11,
  137769. 0,
  137770. 12,
  137771. };
  137772. static long _vq_lengthlist__44u9_p7_0[] = {
  137773. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  137774. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  137775. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  137776. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  137777. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137778. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137779. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  137780. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  137781. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  137782. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  137783. 12,13,13,14,14,14,15,15,15,
  137784. };
  137785. static float _vq_quantthresh__44u9_p7_0[] = {
  137786. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137787. 27.5, 38.5, 49.5, 60.5,
  137788. };
  137789. static long _vq_quantmap__44u9_p7_0[] = {
  137790. 11, 9, 7, 5, 3, 1, 0, 2,
  137791. 4, 6, 8, 10, 12,
  137792. };
  137793. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  137794. _vq_quantthresh__44u9_p7_0,
  137795. _vq_quantmap__44u9_p7_0,
  137796. 13,
  137797. 13
  137798. };
  137799. static static_codebook _44u9_p7_0 = {
  137800. 2, 169,
  137801. _vq_lengthlist__44u9_p7_0,
  137802. 1, -523206656, 1618345984, 4, 0,
  137803. _vq_quantlist__44u9_p7_0,
  137804. NULL,
  137805. &_vq_auxt__44u9_p7_0,
  137806. NULL,
  137807. 0
  137808. };
  137809. static long _vq_quantlist__44u9_p7_1[] = {
  137810. 5,
  137811. 4,
  137812. 6,
  137813. 3,
  137814. 7,
  137815. 2,
  137816. 8,
  137817. 1,
  137818. 9,
  137819. 0,
  137820. 10,
  137821. };
  137822. static long _vq_lengthlist__44u9_p7_1[] = {
  137823. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  137824. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137825. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  137826. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137827. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137828. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137829. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  137830. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137831. };
  137832. static float _vq_quantthresh__44u9_p7_1[] = {
  137833. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137834. 3.5, 4.5,
  137835. };
  137836. static long _vq_quantmap__44u9_p7_1[] = {
  137837. 9, 7, 5, 3, 1, 0, 2, 4,
  137838. 6, 8, 10,
  137839. };
  137840. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  137841. _vq_quantthresh__44u9_p7_1,
  137842. _vq_quantmap__44u9_p7_1,
  137843. 11,
  137844. 11
  137845. };
  137846. static static_codebook _44u9_p7_1 = {
  137847. 2, 121,
  137848. _vq_lengthlist__44u9_p7_1,
  137849. 1, -531365888, 1611661312, 4, 0,
  137850. _vq_quantlist__44u9_p7_1,
  137851. NULL,
  137852. &_vq_auxt__44u9_p7_1,
  137853. NULL,
  137854. 0
  137855. };
  137856. static long _vq_quantlist__44u9_p8_0[] = {
  137857. 7,
  137858. 6,
  137859. 8,
  137860. 5,
  137861. 9,
  137862. 4,
  137863. 10,
  137864. 3,
  137865. 11,
  137866. 2,
  137867. 12,
  137868. 1,
  137869. 13,
  137870. 0,
  137871. 14,
  137872. };
  137873. static long _vq_lengthlist__44u9_p8_0[] = {
  137874. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  137875. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137876. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  137877. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  137878. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  137879. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  137880. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  137881. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  137882. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  137883. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  137884. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  137885. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  137886. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  137887. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  137888. 15,
  137889. };
  137890. static float _vq_quantthresh__44u9_p8_0[] = {
  137891. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137892. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137893. };
  137894. static long _vq_quantmap__44u9_p8_0[] = {
  137895. 13, 11, 9, 7, 5, 3, 1, 0,
  137896. 2, 4, 6, 8, 10, 12, 14,
  137897. };
  137898. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  137899. _vq_quantthresh__44u9_p8_0,
  137900. _vq_quantmap__44u9_p8_0,
  137901. 15,
  137902. 15
  137903. };
  137904. static static_codebook _44u9_p8_0 = {
  137905. 2, 225,
  137906. _vq_lengthlist__44u9_p8_0,
  137907. 1, -520986624, 1620377600, 4, 0,
  137908. _vq_quantlist__44u9_p8_0,
  137909. NULL,
  137910. &_vq_auxt__44u9_p8_0,
  137911. NULL,
  137912. 0
  137913. };
  137914. static long _vq_quantlist__44u9_p8_1[] = {
  137915. 10,
  137916. 9,
  137917. 11,
  137918. 8,
  137919. 12,
  137920. 7,
  137921. 13,
  137922. 6,
  137923. 14,
  137924. 5,
  137925. 15,
  137926. 4,
  137927. 16,
  137928. 3,
  137929. 17,
  137930. 2,
  137931. 18,
  137932. 1,
  137933. 19,
  137934. 0,
  137935. 20,
  137936. };
  137937. static long _vq_lengthlist__44u9_p8_1[] = {
  137938. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137939. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137940. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  137941. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137942. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  137943. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137944. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137945. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  137946. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137947. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137948. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  137949. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  137950. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137951. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137952. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137953. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137954. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137955. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137956. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  137957. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137958. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137959. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  137960. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  137961. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  137962. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137963. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  137964. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137965. 10,10,10,10,10,10,10,10,10,
  137966. };
  137967. static float _vq_quantthresh__44u9_p8_1[] = {
  137968. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137969. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137970. 6.5, 7.5, 8.5, 9.5,
  137971. };
  137972. static long _vq_quantmap__44u9_p8_1[] = {
  137973. 19, 17, 15, 13, 11, 9, 7, 5,
  137974. 3, 1, 0, 2, 4, 6, 8, 10,
  137975. 12, 14, 16, 18, 20,
  137976. };
  137977. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  137978. _vq_quantthresh__44u9_p8_1,
  137979. _vq_quantmap__44u9_p8_1,
  137980. 21,
  137981. 21
  137982. };
  137983. static static_codebook _44u9_p8_1 = {
  137984. 2, 441,
  137985. _vq_lengthlist__44u9_p8_1,
  137986. 1, -529268736, 1611661312, 5, 0,
  137987. _vq_quantlist__44u9_p8_1,
  137988. NULL,
  137989. &_vq_auxt__44u9_p8_1,
  137990. NULL,
  137991. 0
  137992. };
  137993. static long _vq_quantlist__44u9_p9_0[] = {
  137994. 7,
  137995. 6,
  137996. 8,
  137997. 5,
  137998. 9,
  137999. 4,
  138000. 10,
  138001. 3,
  138002. 11,
  138003. 2,
  138004. 12,
  138005. 1,
  138006. 13,
  138007. 0,
  138008. 14,
  138009. };
  138010. static long _vq_lengthlist__44u9_p9_0[] = {
  138011. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  138012. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  138013. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138014. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138015. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138016. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138017. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138018. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138019. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138020. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138021. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138022. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138023. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138024. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138025. 10,
  138026. };
  138027. static float _vq_quantthresh__44u9_p9_0[] = {
  138028. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  138029. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  138030. };
  138031. static long _vq_quantmap__44u9_p9_0[] = {
  138032. 13, 11, 9, 7, 5, 3, 1, 0,
  138033. 2, 4, 6, 8, 10, 12, 14,
  138034. };
  138035. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  138036. _vq_quantthresh__44u9_p9_0,
  138037. _vq_quantmap__44u9_p9_0,
  138038. 15,
  138039. 15
  138040. };
  138041. static static_codebook _44u9_p9_0 = {
  138042. 2, 225,
  138043. _vq_lengthlist__44u9_p9_0,
  138044. 1, -510036736, 1631393792, 4, 0,
  138045. _vq_quantlist__44u9_p9_0,
  138046. NULL,
  138047. &_vq_auxt__44u9_p9_0,
  138048. NULL,
  138049. 0
  138050. };
  138051. static long _vq_quantlist__44u9_p9_1[] = {
  138052. 9,
  138053. 8,
  138054. 10,
  138055. 7,
  138056. 11,
  138057. 6,
  138058. 12,
  138059. 5,
  138060. 13,
  138061. 4,
  138062. 14,
  138063. 3,
  138064. 15,
  138065. 2,
  138066. 16,
  138067. 1,
  138068. 17,
  138069. 0,
  138070. 18,
  138071. };
  138072. static long _vq_lengthlist__44u9_p9_1[] = {
  138073. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  138074. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  138075. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  138076. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  138077. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  138078. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  138079. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  138080. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  138081. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  138082. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  138083. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  138084. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  138085. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  138086. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  138087. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  138088. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  138089. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  138090. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  138091. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  138092. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  138093. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  138094. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  138095. 17,17,15,17,15,17,16,16,17,
  138096. };
  138097. static float _vq_quantthresh__44u9_p9_1[] = {
  138098. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  138099. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  138100. 367.5, 416.5,
  138101. };
  138102. static long _vq_quantmap__44u9_p9_1[] = {
  138103. 17, 15, 13, 11, 9, 7, 5, 3,
  138104. 1, 0, 2, 4, 6, 8, 10, 12,
  138105. 14, 16, 18,
  138106. };
  138107. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  138108. _vq_quantthresh__44u9_p9_1,
  138109. _vq_quantmap__44u9_p9_1,
  138110. 19,
  138111. 19
  138112. };
  138113. static static_codebook _44u9_p9_1 = {
  138114. 2, 361,
  138115. _vq_lengthlist__44u9_p9_1,
  138116. 1, -518287360, 1622704128, 5, 0,
  138117. _vq_quantlist__44u9_p9_1,
  138118. NULL,
  138119. &_vq_auxt__44u9_p9_1,
  138120. NULL,
  138121. 0
  138122. };
  138123. static long _vq_quantlist__44u9_p9_2[] = {
  138124. 24,
  138125. 23,
  138126. 25,
  138127. 22,
  138128. 26,
  138129. 21,
  138130. 27,
  138131. 20,
  138132. 28,
  138133. 19,
  138134. 29,
  138135. 18,
  138136. 30,
  138137. 17,
  138138. 31,
  138139. 16,
  138140. 32,
  138141. 15,
  138142. 33,
  138143. 14,
  138144. 34,
  138145. 13,
  138146. 35,
  138147. 12,
  138148. 36,
  138149. 11,
  138150. 37,
  138151. 10,
  138152. 38,
  138153. 9,
  138154. 39,
  138155. 8,
  138156. 40,
  138157. 7,
  138158. 41,
  138159. 6,
  138160. 42,
  138161. 5,
  138162. 43,
  138163. 4,
  138164. 44,
  138165. 3,
  138166. 45,
  138167. 2,
  138168. 46,
  138169. 1,
  138170. 47,
  138171. 0,
  138172. 48,
  138173. };
  138174. static long _vq_lengthlist__44u9_p9_2[] = {
  138175. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  138176. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138177. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138178. 7,
  138179. };
  138180. static float _vq_quantthresh__44u9_p9_2[] = {
  138181. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  138182. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  138183. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  138184. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  138185. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  138186. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  138187. };
  138188. static long _vq_quantmap__44u9_p9_2[] = {
  138189. 47, 45, 43, 41, 39, 37, 35, 33,
  138190. 31, 29, 27, 25, 23, 21, 19, 17,
  138191. 15, 13, 11, 9, 7, 5, 3, 1,
  138192. 0, 2, 4, 6, 8, 10, 12, 14,
  138193. 16, 18, 20, 22, 24, 26, 28, 30,
  138194. 32, 34, 36, 38, 40, 42, 44, 46,
  138195. 48,
  138196. };
  138197. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  138198. _vq_quantthresh__44u9_p9_2,
  138199. _vq_quantmap__44u9_p9_2,
  138200. 49,
  138201. 49
  138202. };
  138203. static static_codebook _44u9_p9_2 = {
  138204. 1, 49,
  138205. _vq_lengthlist__44u9_p9_2,
  138206. 1, -526909440, 1611661312, 6, 0,
  138207. _vq_quantlist__44u9_p9_2,
  138208. NULL,
  138209. &_vq_auxt__44u9_p9_2,
  138210. NULL,
  138211. 0
  138212. };
  138213. static long _huff_lengthlist__44un1__long[] = {
  138214. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  138215. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  138216. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  138217. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  138218. };
  138219. static static_codebook _huff_book__44un1__long = {
  138220. 2, 64,
  138221. _huff_lengthlist__44un1__long,
  138222. 0, 0, 0, 0, 0,
  138223. NULL,
  138224. NULL,
  138225. NULL,
  138226. NULL,
  138227. 0
  138228. };
  138229. static long _vq_quantlist__44un1__p1_0[] = {
  138230. 1,
  138231. 0,
  138232. 2,
  138233. };
  138234. static long _vq_lengthlist__44un1__p1_0[] = {
  138235. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  138236. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  138237. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  138238. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  138239. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  138240. 12,
  138241. };
  138242. static float _vq_quantthresh__44un1__p1_0[] = {
  138243. -0.5, 0.5,
  138244. };
  138245. static long _vq_quantmap__44un1__p1_0[] = {
  138246. 1, 0, 2,
  138247. };
  138248. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  138249. _vq_quantthresh__44un1__p1_0,
  138250. _vq_quantmap__44un1__p1_0,
  138251. 3,
  138252. 3
  138253. };
  138254. static static_codebook _44un1__p1_0 = {
  138255. 4, 81,
  138256. _vq_lengthlist__44un1__p1_0,
  138257. 1, -535822336, 1611661312, 2, 0,
  138258. _vq_quantlist__44un1__p1_0,
  138259. NULL,
  138260. &_vq_auxt__44un1__p1_0,
  138261. NULL,
  138262. 0
  138263. };
  138264. static long _vq_quantlist__44un1__p2_0[] = {
  138265. 1,
  138266. 0,
  138267. 2,
  138268. };
  138269. static long _vq_lengthlist__44un1__p2_0[] = {
  138270. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  138271. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  138272. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  138273. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  138274. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  138275. 8,
  138276. };
  138277. static float _vq_quantthresh__44un1__p2_0[] = {
  138278. -0.5, 0.5,
  138279. };
  138280. static long _vq_quantmap__44un1__p2_0[] = {
  138281. 1, 0, 2,
  138282. };
  138283. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138284. _vq_quantthresh__44un1__p2_0,
  138285. _vq_quantmap__44un1__p2_0,
  138286. 3,
  138287. 3
  138288. };
  138289. static static_codebook _44un1__p2_0 = {
  138290. 4, 81,
  138291. _vq_lengthlist__44un1__p2_0,
  138292. 1, -535822336, 1611661312, 2, 0,
  138293. _vq_quantlist__44un1__p2_0,
  138294. NULL,
  138295. &_vq_auxt__44un1__p2_0,
  138296. NULL,
  138297. 0
  138298. };
  138299. static long _vq_quantlist__44un1__p3_0[] = {
  138300. 2,
  138301. 1,
  138302. 3,
  138303. 0,
  138304. 4,
  138305. };
  138306. static long _vq_lengthlist__44un1__p3_0[] = {
  138307. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138308. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138309. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138310. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138311. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138312. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138313. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138314. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138315. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138316. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138317. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138318. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138319. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138320. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138321. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138322. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138323. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138324. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138325. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138326. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138327. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138328. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138329. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138330. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138331. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138332. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138333. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138334. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138335. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138336. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138337. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138338. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138339. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138340. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138341. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138342. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138343. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138344. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138345. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138346. 17,
  138347. };
  138348. static float _vq_quantthresh__44un1__p3_0[] = {
  138349. -1.5, -0.5, 0.5, 1.5,
  138350. };
  138351. static long _vq_quantmap__44un1__p3_0[] = {
  138352. 3, 1, 0, 2, 4,
  138353. };
  138354. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138355. _vq_quantthresh__44un1__p3_0,
  138356. _vq_quantmap__44un1__p3_0,
  138357. 5,
  138358. 5
  138359. };
  138360. static static_codebook _44un1__p3_0 = {
  138361. 4, 625,
  138362. _vq_lengthlist__44un1__p3_0,
  138363. 1, -533725184, 1611661312, 3, 0,
  138364. _vq_quantlist__44un1__p3_0,
  138365. NULL,
  138366. &_vq_auxt__44un1__p3_0,
  138367. NULL,
  138368. 0
  138369. };
  138370. static long _vq_quantlist__44un1__p4_0[] = {
  138371. 2,
  138372. 1,
  138373. 3,
  138374. 0,
  138375. 4,
  138376. };
  138377. static long _vq_lengthlist__44un1__p4_0[] = {
  138378. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  138379. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  138380. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  138381. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  138382. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  138383. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  138384. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  138385. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  138386. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  138387. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  138388. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  138389. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  138390. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  138391. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  138392. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  138393. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  138394. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138395. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138396. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138397. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138398. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138399. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138400. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138401. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138402. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138403. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138404. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138405. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138406. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138407. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138408. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138409. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138410. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138411. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138412. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138413. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138414. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138415. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138416. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138417. 12,
  138418. };
  138419. static float _vq_quantthresh__44un1__p4_0[] = {
  138420. -1.5, -0.5, 0.5, 1.5,
  138421. };
  138422. static long _vq_quantmap__44un1__p4_0[] = {
  138423. 3, 1, 0, 2, 4,
  138424. };
  138425. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138426. _vq_quantthresh__44un1__p4_0,
  138427. _vq_quantmap__44un1__p4_0,
  138428. 5,
  138429. 5
  138430. };
  138431. static static_codebook _44un1__p4_0 = {
  138432. 4, 625,
  138433. _vq_lengthlist__44un1__p4_0,
  138434. 1, -533725184, 1611661312, 3, 0,
  138435. _vq_quantlist__44un1__p4_0,
  138436. NULL,
  138437. &_vq_auxt__44un1__p4_0,
  138438. NULL,
  138439. 0
  138440. };
  138441. static long _vq_quantlist__44un1__p5_0[] = {
  138442. 4,
  138443. 3,
  138444. 5,
  138445. 2,
  138446. 6,
  138447. 1,
  138448. 7,
  138449. 0,
  138450. 8,
  138451. };
  138452. static long _vq_lengthlist__44un1__p5_0[] = {
  138453. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138454. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138455. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138456. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138457. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138458. 12,
  138459. };
  138460. static float _vq_quantthresh__44un1__p5_0[] = {
  138461. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138462. };
  138463. static long _vq_quantmap__44un1__p5_0[] = {
  138464. 7, 5, 3, 1, 0, 2, 4, 6,
  138465. 8,
  138466. };
  138467. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138468. _vq_quantthresh__44un1__p5_0,
  138469. _vq_quantmap__44un1__p5_0,
  138470. 9,
  138471. 9
  138472. };
  138473. static static_codebook _44un1__p5_0 = {
  138474. 2, 81,
  138475. _vq_lengthlist__44un1__p5_0,
  138476. 1, -531628032, 1611661312, 4, 0,
  138477. _vq_quantlist__44un1__p5_0,
  138478. NULL,
  138479. &_vq_auxt__44un1__p5_0,
  138480. NULL,
  138481. 0
  138482. };
  138483. static long _vq_quantlist__44un1__p6_0[] = {
  138484. 6,
  138485. 5,
  138486. 7,
  138487. 4,
  138488. 8,
  138489. 3,
  138490. 9,
  138491. 2,
  138492. 10,
  138493. 1,
  138494. 11,
  138495. 0,
  138496. 12,
  138497. };
  138498. static long _vq_lengthlist__44un1__p6_0[] = {
  138499. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138500. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138501. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138502. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138503. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138504. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138505. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138506. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138507. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138508. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138509. 16, 0,15,18,18, 0,16, 0, 0,
  138510. };
  138511. static float _vq_quantthresh__44un1__p6_0[] = {
  138512. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138513. 12.5, 17.5, 22.5, 27.5,
  138514. };
  138515. static long _vq_quantmap__44un1__p6_0[] = {
  138516. 11, 9, 7, 5, 3, 1, 0, 2,
  138517. 4, 6, 8, 10, 12,
  138518. };
  138519. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138520. _vq_quantthresh__44un1__p6_0,
  138521. _vq_quantmap__44un1__p6_0,
  138522. 13,
  138523. 13
  138524. };
  138525. static static_codebook _44un1__p6_0 = {
  138526. 2, 169,
  138527. _vq_lengthlist__44un1__p6_0,
  138528. 1, -526516224, 1616117760, 4, 0,
  138529. _vq_quantlist__44un1__p6_0,
  138530. NULL,
  138531. &_vq_auxt__44un1__p6_0,
  138532. NULL,
  138533. 0
  138534. };
  138535. static long _vq_quantlist__44un1__p6_1[] = {
  138536. 2,
  138537. 1,
  138538. 3,
  138539. 0,
  138540. 4,
  138541. };
  138542. static long _vq_lengthlist__44un1__p6_1[] = {
  138543. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138544. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138545. };
  138546. static float _vq_quantthresh__44un1__p6_1[] = {
  138547. -1.5, -0.5, 0.5, 1.5,
  138548. };
  138549. static long _vq_quantmap__44un1__p6_1[] = {
  138550. 3, 1, 0, 2, 4,
  138551. };
  138552. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138553. _vq_quantthresh__44un1__p6_1,
  138554. _vq_quantmap__44un1__p6_1,
  138555. 5,
  138556. 5
  138557. };
  138558. static static_codebook _44un1__p6_1 = {
  138559. 2, 25,
  138560. _vq_lengthlist__44un1__p6_1,
  138561. 1, -533725184, 1611661312, 3, 0,
  138562. _vq_quantlist__44un1__p6_1,
  138563. NULL,
  138564. &_vq_auxt__44un1__p6_1,
  138565. NULL,
  138566. 0
  138567. };
  138568. static long _vq_quantlist__44un1__p7_0[] = {
  138569. 2,
  138570. 1,
  138571. 3,
  138572. 0,
  138573. 4,
  138574. };
  138575. static long _vq_lengthlist__44un1__p7_0[] = {
  138576. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138577. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  138578. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138579. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138580. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138581. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138582. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138583. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138584. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138585. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138586. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138587. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138588. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138589. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138590. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138591. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  138592. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138593. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  138594. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138595. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138596. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138597. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138598. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138599. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138600. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138601. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138602. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138603. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138604. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138605. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138606. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138607. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138608. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138609. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138610. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138611. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138612. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138613. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138614. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138615. 10,
  138616. };
  138617. static float _vq_quantthresh__44un1__p7_0[] = {
  138618. -253.5, -84.5, 84.5, 253.5,
  138619. };
  138620. static long _vq_quantmap__44un1__p7_0[] = {
  138621. 3, 1, 0, 2, 4,
  138622. };
  138623. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138624. _vq_quantthresh__44un1__p7_0,
  138625. _vq_quantmap__44un1__p7_0,
  138626. 5,
  138627. 5
  138628. };
  138629. static static_codebook _44un1__p7_0 = {
  138630. 4, 625,
  138631. _vq_lengthlist__44un1__p7_0,
  138632. 1, -518709248, 1626677248, 3, 0,
  138633. _vq_quantlist__44un1__p7_0,
  138634. NULL,
  138635. &_vq_auxt__44un1__p7_0,
  138636. NULL,
  138637. 0
  138638. };
  138639. static long _vq_quantlist__44un1__p7_1[] = {
  138640. 6,
  138641. 5,
  138642. 7,
  138643. 4,
  138644. 8,
  138645. 3,
  138646. 9,
  138647. 2,
  138648. 10,
  138649. 1,
  138650. 11,
  138651. 0,
  138652. 12,
  138653. };
  138654. static long _vq_lengthlist__44un1__p7_1[] = {
  138655. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138656. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138657. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138658. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138659. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138660. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138661. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138662. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138663. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138664. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138665. 12,13,13,12,13,13,14,14,14,
  138666. };
  138667. static float _vq_quantthresh__44un1__p7_1[] = {
  138668. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138669. 32.5, 45.5, 58.5, 71.5,
  138670. };
  138671. static long _vq_quantmap__44un1__p7_1[] = {
  138672. 11, 9, 7, 5, 3, 1, 0, 2,
  138673. 4, 6, 8, 10, 12,
  138674. };
  138675. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  138676. _vq_quantthresh__44un1__p7_1,
  138677. _vq_quantmap__44un1__p7_1,
  138678. 13,
  138679. 13
  138680. };
  138681. static static_codebook _44un1__p7_1 = {
  138682. 2, 169,
  138683. _vq_lengthlist__44un1__p7_1,
  138684. 1, -523010048, 1618608128, 4, 0,
  138685. _vq_quantlist__44un1__p7_1,
  138686. NULL,
  138687. &_vq_auxt__44un1__p7_1,
  138688. NULL,
  138689. 0
  138690. };
  138691. static long _vq_quantlist__44un1__p7_2[] = {
  138692. 6,
  138693. 5,
  138694. 7,
  138695. 4,
  138696. 8,
  138697. 3,
  138698. 9,
  138699. 2,
  138700. 10,
  138701. 1,
  138702. 11,
  138703. 0,
  138704. 12,
  138705. };
  138706. static long _vq_lengthlist__44un1__p7_2[] = {
  138707. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  138708. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  138709. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  138710. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  138711. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  138712. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  138713. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  138714. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  138715. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  138716. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  138717. 9, 9, 9,10,10,10,10,10,10,
  138718. };
  138719. static float _vq_quantthresh__44un1__p7_2[] = {
  138720. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  138721. 2.5, 3.5, 4.5, 5.5,
  138722. };
  138723. static long _vq_quantmap__44un1__p7_2[] = {
  138724. 11, 9, 7, 5, 3, 1, 0, 2,
  138725. 4, 6, 8, 10, 12,
  138726. };
  138727. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  138728. _vq_quantthresh__44un1__p7_2,
  138729. _vq_quantmap__44un1__p7_2,
  138730. 13,
  138731. 13
  138732. };
  138733. static static_codebook _44un1__p7_2 = {
  138734. 2, 169,
  138735. _vq_lengthlist__44un1__p7_2,
  138736. 1, -531103744, 1611661312, 4, 0,
  138737. _vq_quantlist__44un1__p7_2,
  138738. NULL,
  138739. &_vq_auxt__44un1__p7_2,
  138740. NULL,
  138741. 0
  138742. };
  138743. static long _huff_lengthlist__44un1__short[] = {
  138744. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  138745. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  138746. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  138747. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  138748. };
  138749. static static_codebook _huff_book__44un1__short = {
  138750. 2, 64,
  138751. _huff_lengthlist__44un1__short,
  138752. 0, 0, 0, 0, 0,
  138753. NULL,
  138754. NULL,
  138755. NULL,
  138756. NULL,
  138757. 0
  138758. };
  138759. /*** End of inlined file: res_books_uncoupled.h ***/
  138760. static vorbis_info_residue0 _residue_44_low_un={
  138761. 0,-1, -1, 8,-1,
  138762. {0},
  138763. {-1},
  138764. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  138765. { -1, 25, -1, 45, -1, -1, -1}
  138766. };
  138767. static vorbis_info_residue0 _residue_44_mid_un={
  138768. 0,-1, -1, 10,-1,
  138769. {0},
  138770. {-1},
  138771. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  138772. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  138773. };
  138774. static vorbis_info_residue0 _residue_44_hi_un={
  138775. 0,-1, -1, 10,-1,
  138776. {0},
  138777. {-1},
  138778. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  138779. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  138780. };
  138781. static vorbis_info_mapping0 _map_nominal_u[2]={
  138782. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  138783. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  138784. };
  138785. static static_bookblock _resbook_44u_n1={
  138786. {
  138787. {0},
  138788. {0,0,&_44un1__p1_0},
  138789. {0,0,&_44un1__p2_0},
  138790. {0,0,&_44un1__p3_0},
  138791. {0,0,&_44un1__p4_0},
  138792. {0,0,&_44un1__p5_0},
  138793. {&_44un1__p6_0,&_44un1__p6_1},
  138794. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  138795. }
  138796. };
  138797. static static_bookblock _resbook_44u_0={
  138798. {
  138799. {0},
  138800. {0,0,&_44u0__p1_0},
  138801. {0,0,&_44u0__p2_0},
  138802. {0,0,&_44u0__p3_0},
  138803. {0,0,&_44u0__p4_0},
  138804. {0,0,&_44u0__p5_0},
  138805. {&_44u0__p6_0,&_44u0__p6_1},
  138806. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  138807. }
  138808. };
  138809. static static_bookblock _resbook_44u_1={
  138810. {
  138811. {0},
  138812. {0,0,&_44u1__p1_0},
  138813. {0,0,&_44u1__p2_0},
  138814. {0,0,&_44u1__p3_0},
  138815. {0,0,&_44u1__p4_0},
  138816. {0,0,&_44u1__p5_0},
  138817. {&_44u1__p6_0,&_44u1__p6_1},
  138818. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  138819. }
  138820. };
  138821. static static_bookblock _resbook_44u_2={
  138822. {
  138823. {0},
  138824. {0,0,&_44u2__p1_0},
  138825. {0,0,&_44u2__p2_0},
  138826. {0,0,&_44u2__p3_0},
  138827. {0,0,&_44u2__p4_0},
  138828. {0,0,&_44u2__p5_0},
  138829. {&_44u2__p6_0,&_44u2__p6_1},
  138830. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  138831. }
  138832. };
  138833. static static_bookblock _resbook_44u_3={
  138834. {
  138835. {0},
  138836. {0,0,&_44u3__p1_0},
  138837. {0,0,&_44u3__p2_0},
  138838. {0,0,&_44u3__p3_0},
  138839. {0,0,&_44u3__p4_0},
  138840. {0,0,&_44u3__p5_0},
  138841. {&_44u3__p6_0,&_44u3__p6_1},
  138842. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  138843. }
  138844. };
  138845. static static_bookblock _resbook_44u_4={
  138846. {
  138847. {0},
  138848. {0,0,&_44u4__p1_0},
  138849. {0,0,&_44u4__p2_0},
  138850. {0,0,&_44u4__p3_0},
  138851. {0,0,&_44u4__p4_0},
  138852. {0,0,&_44u4__p5_0},
  138853. {&_44u4__p6_0,&_44u4__p6_1},
  138854. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  138855. }
  138856. };
  138857. static static_bookblock _resbook_44u_5={
  138858. {
  138859. {0},
  138860. {0,0,&_44u5__p1_0},
  138861. {0,0,&_44u5__p2_0},
  138862. {0,0,&_44u5__p3_0},
  138863. {0,0,&_44u5__p4_0},
  138864. {0,0,&_44u5__p5_0},
  138865. {0,0,&_44u5__p6_0},
  138866. {&_44u5__p7_0,&_44u5__p7_1},
  138867. {&_44u5__p8_0,&_44u5__p8_1},
  138868. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  138869. }
  138870. };
  138871. static static_bookblock _resbook_44u_6={
  138872. {
  138873. {0},
  138874. {0,0,&_44u6__p1_0},
  138875. {0,0,&_44u6__p2_0},
  138876. {0,0,&_44u6__p3_0},
  138877. {0,0,&_44u6__p4_0},
  138878. {0,0,&_44u6__p5_0},
  138879. {0,0,&_44u6__p6_0},
  138880. {&_44u6__p7_0,&_44u6__p7_1},
  138881. {&_44u6__p8_0,&_44u6__p8_1},
  138882. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  138883. }
  138884. };
  138885. static static_bookblock _resbook_44u_7={
  138886. {
  138887. {0},
  138888. {0,0,&_44u7__p1_0},
  138889. {0,0,&_44u7__p2_0},
  138890. {0,0,&_44u7__p3_0},
  138891. {0,0,&_44u7__p4_0},
  138892. {0,0,&_44u7__p5_0},
  138893. {0,0,&_44u7__p6_0},
  138894. {&_44u7__p7_0,&_44u7__p7_1},
  138895. {&_44u7__p8_0,&_44u7__p8_1},
  138896. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  138897. }
  138898. };
  138899. static static_bookblock _resbook_44u_8={
  138900. {
  138901. {0},
  138902. {0,0,&_44u8_p1_0},
  138903. {0,0,&_44u8_p2_0},
  138904. {0,0,&_44u8_p3_0},
  138905. {0,0,&_44u8_p4_0},
  138906. {&_44u8_p5_0,&_44u8_p5_1},
  138907. {&_44u8_p6_0,&_44u8_p6_1},
  138908. {&_44u8_p7_0,&_44u8_p7_1},
  138909. {&_44u8_p8_0,&_44u8_p8_1},
  138910. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  138911. }
  138912. };
  138913. static static_bookblock _resbook_44u_9={
  138914. {
  138915. {0},
  138916. {0,0,&_44u9_p1_0},
  138917. {0,0,&_44u9_p2_0},
  138918. {0,0,&_44u9_p3_0},
  138919. {0,0,&_44u9_p4_0},
  138920. {&_44u9_p5_0,&_44u9_p5_1},
  138921. {&_44u9_p6_0,&_44u9_p6_1},
  138922. {&_44u9_p7_0,&_44u9_p7_1},
  138923. {&_44u9_p8_0,&_44u9_p8_1},
  138924. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  138925. }
  138926. };
  138927. static vorbis_residue_template _res_44u_n1[]={
  138928. {1,0, &_residue_44_low_un,
  138929. &_huff_book__44un1__short,&_huff_book__44un1__short,
  138930. &_resbook_44u_n1,&_resbook_44u_n1},
  138931. {1,0, &_residue_44_low_un,
  138932. &_huff_book__44un1__long,&_huff_book__44un1__long,
  138933. &_resbook_44u_n1,&_resbook_44u_n1}
  138934. };
  138935. static vorbis_residue_template _res_44u_0[]={
  138936. {1,0, &_residue_44_low_un,
  138937. &_huff_book__44u0__short,&_huff_book__44u0__short,
  138938. &_resbook_44u_0,&_resbook_44u_0},
  138939. {1,0, &_residue_44_low_un,
  138940. &_huff_book__44u0__long,&_huff_book__44u0__long,
  138941. &_resbook_44u_0,&_resbook_44u_0}
  138942. };
  138943. static vorbis_residue_template _res_44u_1[]={
  138944. {1,0, &_residue_44_low_un,
  138945. &_huff_book__44u1__short,&_huff_book__44u1__short,
  138946. &_resbook_44u_1,&_resbook_44u_1},
  138947. {1,0, &_residue_44_low_un,
  138948. &_huff_book__44u1__long,&_huff_book__44u1__long,
  138949. &_resbook_44u_1,&_resbook_44u_1}
  138950. };
  138951. static vorbis_residue_template _res_44u_2[]={
  138952. {1,0, &_residue_44_low_un,
  138953. &_huff_book__44u2__short,&_huff_book__44u2__short,
  138954. &_resbook_44u_2,&_resbook_44u_2},
  138955. {1,0, &_residue_44_low_un,
  138956. &_huff_book__44u2__long,&_huff_book__44u2__long,
  138957. &_resbook_44u_2,&_resbook_44u_2}
  138958. };
  138959. static vorbis_residue_template _res_44u_3[]={
  138960. {1,0, &_residue_44_low_un,
  138961. &_huff_book__44u3__short,&_huff_book__44u3__short,
  138962. &_resbook_44u_3,&_resbook_44u_3},
  138963. {1,0, &_residue_44_low_un,
  138964. &_huff_book__44u3__long,&_huff_book__44u3__long,
  138965. &_resbook_44u_3,&_resbook_44u_3}
  138966. };
  138967. static vorbis_residue_template _res_44u_4[]={
  138968. {1,0, &_residue_44_low_un,
  138969. &_huff_book__44u4__short,&_huff_book__44u4__short,
  138970. &_resbook_44u_4,&_resbook_44u_4},
  138971. {1,0, &_residue_44_low_un,
  138972. &_huff_book__44u4__long,&_huff_book__44u4__long,
  138973. &_resbook_44u_4,&_resbook_44u_4}
  138974. };
  138975. static vorbis_residue_template _res_44u_5[]={
  138976. {1,0, &_residue_44_mid_un,
  138977. &_huff_book__44u5__short,&_huff_book__44u5__short,
  138978. &_resbook_44u_5,&_resbook_44u_5},
  138979. {1,0, &_residue_44_mid_un,
  138980. &_huff_book__44u5__long,&_huff_book__44u5__long,
  138981. &_resbook_44u_5,&_resbook_44u_5}
  138982. };
  138983. static vorbis_residue_template _res_44u_6[]={
  138984. {1,0, &_residue_44_mid_un,
  138985. &_huff_book__44u6__short,&_huff_book__44u6__short,
  138986. &_resbook_44u_6,&_resbook_44u_6},
  138987. {1,0, &_residue_44_mid_un,
  138988. &_huff_book__44u6__long,&_huff_book__44u6__long,
  138989. &_resbook_44u_6,&_resbook_44u_6}
  138990. };
  138991. static vorbis_residue_template _res_44u_7[]={
  138992. {1,0, &_residue_44_mid_un,
  138993. &_huff_book__44u7__short,&_huff_book__44u7__short,
  138994. &_resbook_44u_7,&_resbook_44u_7},
  138995. {1,0, &_residue_44_mid_un,
  138996. &_huff_book__44u7__long,&_huff_book__44u7__long,
  138997. &_resbook_44u_7,&_resbook_44u_7}
  138998. };
  138999. static vorbis_residue_template _res_44u_8[]={
  139000. {1,0, &_residue_44_hi_un,
  139001. &_huff_book__44u8__short,&_huff_book__44u8__short,
  139002. &_resbook_44u_8,&_resbook_44u_8},
  139003. {1,0, &_residue_44_hi_un,
  139004. &_huff_book__44u8__long,&_huff_book__44u8__long,
  139005. &_resbook_44u_8,&_resbook_44u_8}
  139006. };
  139007. static vorbis_residue_template _res_44u_9[]={
  139008. {1,0, &_residue_44_hi_un,
  139009. &_huff_book__44u9__short,&_huff_book__44u9__short,
  139010. &_resbook_44u_9,&_resbook_44u_9},
  139011. {1,0, &_residue_44_hi_un,
  139012. &_huff_book__44u9__long,&_huff_book__44u9__long,
  139013. &_resbook_44u_9,&_resbook_44u_9}
  139014. };
  139015. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  139016. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  139017. { _map_nominal_u, _res_44u_0 }, /* 0 */
  139018. { _map_nominal_u, _res_44u_1 }, /* 1 */
  139019. { _map_nominal_u, _res_44u_2 }, /* 2 */
  139020. { _map_nominal_u, _res_44u_3 }, /* 3 */
  139021. { _map_nominal_u, _res_44u_4 }, /* 4 */
  139022. { _map_nominal_u, _res_44u_5 }, /* 5 */
  139023. { _map_nominal_u, _res_44u_6 }, /* 6 */
  139024. { _map_nominal_u, _res_44u_7 }, /* 7 */
  139025. { _map_nominal_u, _res_44u_8 }, /* 8 */
  139026. { _map_nominal_u, _res_44u_9 }, /* 9 */
  139027. };
  139028. /*** End of inlined file: residue_44u.h ***/
  139029. static double rate_mapping_44_un[12]={
  139030. 32000.,48000.,60000.,70000.,80000.,86000.,
  139031. 96000.,110000.,120000.,140000.,160000.,240001.
  139032. };
  139033. ve_setup_data_template ve_setup_44_uncoupled={
  139034. 11,
  139035. rate_mapping_44_un,
  139036. quality_mapping_44,
  139037. -1,
  139038. 40000,
  139039. 50000,
  139040. blocksize_short_44,
  139041. blocksize_long_44,
  139042. _psy_tone_masteratt_44,
  139043. _psy_tone_0dB,
  139044. _psy_tone_suppress,
  139045. _vp_tonemask_adj_otherblock,
  139046. _vp_tonemask_adj_longblock,
  139047. _vp_tonemask_adj_otherblock,
  139048. _psy_noiseguards_44,
  139049. _psy_noisebias_impulse,
  139050. _psy_noisebias_padding,
  139051. _psy_noisebias_trans,
  139052. _psy_noisebias_long,
  139053. _psy_noise_suppress,
  139054. _psy_compand_44,
  139055. _psy_compand_short_mapping,
  139056. _psy_compand_long_mapping,
  139057. {_noise_start_short_44,_noise_start_long_44},
  139058. {_noise_part_short_44,_noise_part_long_44},
  139059. _noise_thresh_44,
  139060. _psy_ath_floater,
  139061. _psy_ath_abs,
  139062. _psy_lowpass_44,
  139063. _psy_global_44,
  139064. _global_mapping_44,
  139065. NULL,
  139066. _floor_books,
  139067. _floor,
  139068. _floor_short_mapping_44,
  139069. _floor_long_mapping_44,
  139070. _mapres_template_44_uncoupled
  139071. };
  139072. /*** End of inlined file: setup_44u.h ***/
  139073. /*** Start of inlined file: setup_32.h ***/
  139074. static double rate_mapping_32[12]={
  139075. 18000.,28000.,35000.,45000.,56000.,60000.,
  139076. 75000.,90000.,100000.,115000.,150000.,190000.,
  139077. };
  139078. static double rate_mapping_32_un[12]={
  139079. 30000.,42000.,52000.,64000.,72000.,78000.,
  139080. 86000.,92000.,110000.,120000.,140000.,190000.,
  139081. };
  139082. static double _psy_lowpass_32[12]={
  139083. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  139084. };
  139085. ve_setup_data_template ve_setup_32_stereo={
  139086. 11,
  139087. rate_mapping_32,
  139088. quality_mapping_44,
  139089. 2,
  139090. 26000,
  139091. 40000,
  139092. blocksize_short_44,
  139093. blocksize_long_44,
  139094. _psy_tone_masteratt_44,
  139095. _psy_tone_0dB,
  139096. _psy_tone_suppress,
  139097. _vp_tonemask_adj_otherblock,
  139098. _vp_tonemask_adj_longblock,
  139099. _vp_tonemask_adj_otherblock,
  139100. _psy_noiseguards_44,
  139101. _psy_noisebias_impulse,
  139102. _psy_noisebias_padding,
  139103. _psy_noisebias_trans,
  139104. _psy_noisebias_long,
  139105. _psy_noise_suppress,
  139106. _psy_compand_44,
  139107. _psy_compand_short_mapping,
  139108. _psy_compand_long_mapping,
  139109. {_noise_start_short_44,_noise_start_long_44},
  139110. {_noise_part_short_44,_noise_part_long_44},
  139111. _noise_thresh_44,
  139112. _psy_ath_floater,
  139113. _psy_ath_abs,
  139114. _psy_lowpass_32,
  139115. _psy_global_44,
  139116. _global_mapping_44,
  139117. _psy_stereo_modes_44,
  139118. _floor_books,
  139119. _floor,
  139120. _floor_short_mapping_44,
  139121. _floor_long_mapping_44,
  139122. _mapres_template_44_stereo
  139123. };
  139124. ve_setup_data_template ve_setup_32_uncoupled={
  139125. 11,
  139126. rate_mapping_32_un,
  139127. quality_mapping_44,
  139128. -1,
  139129. 26000,
  139130. 40000,
  139131. blocksize_short_44,
  139132. blocksize_long_44,
  139133. _psy_tone_masteratt_44,
  139134. _psy_tone_0dB,
  139135. _psy_tone_suppress,
  139136. _vp_tonemask_adj_otherblock,
  139137. _vp_tonemask_adj_longblock,
  139138. _vp_tonemask_adj_otherblock,
  139139. _psy_noiseguards_44,
  139140. _psy_noisebias_impulse,
  139141. _psy_noisebias_padding,
  139142. _psy_noisebias_trans,
  139143. _psy_noisebias_long,
  139144. _psy_noise_suppress,
  139145. _psy_compand_44,
  139146. _psy_compand_short_mapping,
  139147. _psy_compand_long_mapping,
  139148. {_noise_start_short_44,_noise_start_long_44},
  139149. {_noise_part_short_44,_noise_part_long_44},
  139150. _noise_thresh_44,
  139151. _psy_ath_floater,
  139152. _psy_ath_abs,
  139153. _psy_lowpass_32,
  139154. _psy_global_44,
  139155. _global_mapping_44,
  139156. NULL,
  139157. _floor_books,
  139158. _floor,
  139159. _floor_short_mapping_44,
  139160. _floor_long_mapping_44,
  139161. _mapres_template_44_uncoupled
  139162. };
  139163. /*** End of inlined file: setup_32.h ***/
  139164. /*** Start of inlined file: setup_8.h ***/
  139165. /*** Start of inlined file: psych_8.h ***/
  139166. static att3 _psy_tone_masteratt_8[3]={
  139167. {{ 32, 25, 12}, 0, 0}, /* 0 */
  139168. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139169. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139170. };
  139171. static vp_adjblock _vp_tonemask_adj_8[3]={
  139172. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139173. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139174. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  139175. };
  139176. static noise3 _psy_noisebias_8[3]={
  139177. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139178. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  139179. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139180. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139181. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139182. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139183. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139184. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139185. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139186. };
  139187. static adj_stereo _psy_stereo_modes_8[3]={
  139188. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139189. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139190. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139191. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139192. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139193. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139194. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139195. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139196. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139197. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139198. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139199. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139200. };
  139201. static noiseguard _psy_noiseguards_8[2]={
  139202. {10,10,-1},
  139203. {10,10,-1},
  139204. };
  139205. static compandblock _psy_compand_8[2]={
  139206. {{
  139207. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  139208. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  139209. 12,12,13,13,14,14,15, 15, /* 23dB */
  139210. 16,16,17,17,17,18,18, 19, /* 31dB */
  139211. 19,19,20,21,22,23,24, 25, /* 39dB */
  139212. }},
  139213. {{
  139214. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  139215. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  139216. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  139217. 9,10,11,12,13,14,15, 16, /* 31dB */
  139218. 17,18,19,20,21,22,23, 24, /* 39dB */
  139219. }},
  139220. };
  139221. static double _psy_lowpass_8[3]={3.,4.,4.};
  139222. static int _noise_start_8[2]={
  139223. 64,64,
  139224. };
  139225. static int _noise_part_8[2]={
  139226. 8,8,
  139227. };
  139228. static int _psy_ath_floater_8[3]={
  139229. -100,-100,-105,
  139230. };
  139231. static int _psy_ath_abs_8[3]={
  139232. -130,-130,-140,
  139233. };
  139234. /*** End of inlined file: psych_8.h ***/
  139235. /*** Start of inlined file: residue_8.h ***/
  139236. static static_bookblock _resbook_8s_0={
  139237. {
  139238. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  139239. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  139240. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  139241. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  139242. }
  139243. };
  139244. static static_bookblock _resbook_8s_1={
  139245. {
  139246. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  139247. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  139248. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  139249. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  139250. }
  139251. };
  139252. static vorbis_residue_template _res_8s_0[]={
  139253. {2,0, &_residue_44_mid,
  139254. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  139255. &_resbook_8s_0,&_resbook_8s_0},
  139256. };
  139257. static vorbis_residue_template _res_8s_1[]={
  139258. {2,0, &_residue_44_mid,
  139259. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  139260. &_resbook_8s_1,&_resbook_8s_1},
  139261. };
  139262. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  139263. { _map_nominal, _res_8s_0 }, /* 0 */
  139264. { _map_nominal, _res_8s_1 }, /* 1 */
  139265. };
  139266. static static_bookblock _resbook_8u_0={
  139267. {
  139268. {0},
  139269. {0,0,&_8u0__p1_0},
  139270. {0,0,&_8u0__p2_0},
  139271. {0,0,&_8u0__p3_0},
  139272. {0,0,&_8u0__p4_0},
  139273. {0,0,&_8u0__p5_0},
  139274. {&_8u0__p6_0,&_8u0__p6_1},
  139275. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  139276. }
  139277. };
  139278. static static_bookblock _resbook_8u_1={
  139279. {
  139280. {0},
  139281. {0,0,&_8u1__p1_0},
  139282. {0,0,&_8u1__p2_0},
  139283. {0,0,&_8u1__p3_0},
  139284. {0,0,&_8u1__p4_0},
  139285. {0,0,&_8u1__p5_0},
  139286. {0,0,&_8u1__p6_0},
  139287. {&_8u1__p7_0,&_8u1__p7_1},
  139288. {&_8u1__p8_0,&_8u1__p8_1},
  139289. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139290. }
  139291. };
  139292. static vorbis_residue_template _res_8u_0[]={
  139293. {1,0, &_residue_44_low_un,
  139294. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139295. &_resbook_8u_0,&_resbook_8u_0},
  139296. };
  139297. static vorbis_residue_template _res_8u_1[]={
  139298. {1,0, &_residue_44_mid_un,
  139299. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139300. &_resbook_8u_1,&_resbook_8u_1},
  139301. };
  139302. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139303. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139304. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139305. };
  139306. /*** End of inlined file: residue_8.h ***/
  139307. static int blocksize_8[2]={
  139308. 512,512
  139309. };
  139310. static int _floor_mapping_8[2]={
  139311. 6,6,
  139312. };
  139313. static double rate_mapping_8[3]={
  139314. 6000.,9000.,32000.,
  139315. };
  139316. static double rate_mapping_8_uncoupled[3]={
  139317. 8000.,14000.,42000.,
  139318. };
  139319. static double quality_mapping_8[3]={
  139320. -.1,.0,1.
  139321. };
  139322. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139323. static double _global_mapping_8[3]={ 1., 2., 3. };
  139324. ve_setup_data_template ve_setup_8_stereo={
  139325. 2,
  139326. rate_mapping_8,
  139327. quality_mapping_8,
  139328. 2,
  139329. 8000,
  139330. 9000,
  139331. blocksize_8,
  139332. blocksize_8,
  139333. _psy_tone_masteratt_8,
  139334. _psy_tone_0dB,
  139335. _psy_tone_suppress,
  139336. _vp_tonemask_adj_8,
  139337. NULL,
  139338. _vp_tonemask_adj_8,
  139339. _psy_noiseguards_8,
  139340. _psy_noisebias_8,
  139341. _psy_noisebias_8,
  139342. NULL,
  139343. NULL,
  139344. _psy_noise_suppress,
  139345. _psy_compand_8,
  139346. _psy_compand_8_mapping,
  139347. NULL,
  139348. {_noise_start_8,_noise_start_8},
  139349. {_noise_part_8,_noise_part_8},
  139350. _noise_thresh_5only,
  139351. _psy_ath_floater_8,
  139352. _psy_ath_abs_8,
  139353. _psy_lowpass_8,
  139354. _psy_global_44,
  139355. _global_mapping_8,
  139356. _psy_stereo_modes_8,
  139357. _floor_books,
  139358. _floor,
  139359. _floor_mapping_8,
  139360. NULL,
  139361. _mapres_template_8_stereo
  139362. };
  139363. ve_setup_data_template ve_setup_8_uncoupled={
  139364. 2,
  139365. rate_mapping_8_uncoupled,
  139366. quality_mapping_8,
  139367. -1,
  139368. 8000,
  139369. 9000,
  139370. blocksize_8,
  139371. blocksize_8,
  139372. _psy_tone_masteratt_8,
  139373. _psy_tone_0dB,
  139374. _psy_tone_suppress,
  139375. _vp_tonemask_adj_8,
  139376. NULL,
  139377. _vp_tonemask_adj_8,
  139378. _psy_noiseguards_8,
  139379. _psy_noisebias_8,
  139380. _psy_noisebias_8,
  139381. NULL,
  139382. NULL,
  139383. _psy_noise_suppress,
  139384. _psy_compand_8,
  139385. _psy_compand_8_mapping,
  139386. NULL,
  139387. {_noise_start_8,_noise_start_8},
  139388. {_noise_part_8,_noise_part_8},
  139389. _noise_thresh_5only,
  139390. _psy_ath_floater_8,
  139391. _psy_ath_abs_8,
  139392. _psy_lowpass_8,
  139393. _psy_global_44,
  139394. _global_mapping_8,
  139395. _psy_stereo_modes_8,
  139396. _floor_books,
  139397. _floor,
  139398. _floor_mapping_8,
  139399. NULL,
  139400. _mapres_template_8_uncoupled
  139401. };
  139402. /*** End of inlined file: setup_8.h ***/
  139403. /*** Start of inlined file: setup_11.h ***/
  139404. /*** Start of inlined file: psych_11.h ***/
  139405. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139406. static att3 _psy_tone_masteratt_11[3]={
  139407. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139408. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139409. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139410. };
  139411. static vp_adjblock _vp_tonemask_adj_11[3]={
  139412. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139413. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139414. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139415. };
  139416. static noise3 _psy_noisebias_11[3]={
  139417. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139418. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139419. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139420. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139421. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139422. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139423. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139424. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139425. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139426. };
  139427. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139428. /*** End of inlined file: psych_11.h ***/
  139429. static int blocksize_11[2]={
  139430. 512,512
  139431. };
  139432. static int _floor_mapping_11[2]={
  139433. 6,6,
  139434. };
  139435. static double rate_mapping_11[3]={
  139436. 8000.,13000.,44000.,
  139437. };
  139438. static double rate_mapping_11_uncoupled[3]={
  139439. 12000.,20000.,50000.,
  139440. };
  139441. static double quality_mapping_11[3]={
  139442. -.1,.0,1.
  139443. };
  139444. ve_setup_data_template ve_setup_11_stereo={
  139445. 2,
  139446. rate_mapping_11,
  139447. quality_mapping_11,
  139448. 2,
  139449. 9000,
  139450. 15000,
  139451. blocksize_11,
  139452. blocksize_11,
  139453. _psy_tone_masteratt_11,
  139454. _psy_tone_0dB,
  139455. _psy_tone_suppress,
  139456. _vp_tonemask_adj_11,
  139457. NULL,
  139458. _vp_tonemask_adj_11,
  139459. _psy_noiseguards_8,
  139460. _psy_noisebias_11,
  139461. _psy_noisebias_11,
  139462. NULL,
  139463. NULL,
  139464. _psy_noise_suppress,
  139465. _psy_compand_8,
  139466. _psy_compand_8_mapping,
  139467. NULL,
  139468. {_noise_start_8,_noise_start_8},
  139469. {_noise_part_8,_noise_part_8},
  139470. _noise_thresh_11,
  139471. _psy_ath_floater_8,
  139472. _psy_ath_abs_8,
  139473. _psy_lowpass_11,
  139474. _psy_global_44,
  139475. _global_mapping_8,
  139476. _psy_stereo_modes_8,
  139477. _floor_books,
  139478. _floor,
  139479. _floor_mapping_11,
  139480. NULL,
  139481. _mapres_template_8_stereo
  139482. };
  139483. ve_setup_data_template ve_setup_11_uncoupled={
  139484. 2,
  139485. rate_mapping_11_uncoupled,
  139486. quality_mapping_11,
  139487. -1,
  139488. 9000,
  139489. 15000,
  139490. blocksize_11,
  139491. blocksize_11,
  139492. _psy_tone_masteratt_11,
  139493. _psy_tone_0dB,
  139494. _psy_tone_suppress,
  139495. _vp_tonemask_adj_11,
  139496. NULL,
  139497. _vp_tonemask_adj_11,
  139498. _psy_noiseguards_8,
  139499. _psy_noisebias_11,
  139500. _psy_noisebias_11,
  139501. NULL,
  139502. NULL,
  139503. _psy_noise_suppress,
  139504. _psy_compand_8,
  139505. _psy_compand_8_mapping,
  139506. NULL,
  139507. {_noise_start_8,_noise_start_8},
  139508. {_noise_part_8,_noise_part_8},
  139509. _noise_thresh_11,
  139510. _psy_ath_floater_8,
  139511. _psy_ath_abs_8,
  139512. _psy_lowpass_11,
  139513. _psy_global_44,
  139514. _global_mapping_8,
  139515. _psy_stereo_modes_8,
  139516. _floor_books,
  139517. _floor,
  139518. _floor_mapping_11,
  139519. NULL,
  139520. _mapres_template_8_uncoupled
  139521. };
  139522. /*** End of inlined file: setup_11.h ***/
  139523. /*** Start of inlined file: setup_16.h ***/
  139524. /*** Start of inlined file: psych_16.h ***/
  139525. static adj_stereo _psy_stereo_modes_16[4]={
  139526. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139527. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139528. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139529. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139530. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139531. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139532. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139533. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139534. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139535. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139536. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139537. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139538. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139539. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139540. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139541. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139542. };
  139543. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139544. static att3 _psy_tone_masteratt_16[4]={
  139545. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139546. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139547. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139548. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139549. };
  139550. static vp_adjblock _vp_tonemask_adj_16[4]={
  139551. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139552. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139553. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139554. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139555. };
  139556. static noise3 _psy_noisebias_16_short[4]={
  139557. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139558. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139559. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139560. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139561. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139562. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139563. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139564. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139565. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139566. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139567. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139568. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139569. };
  139570. static noise3 _psy_noisebias_16_impulse[4]={
  139571. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139572. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139573. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139574. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139575. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139576. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139577. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139578. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139579. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139580. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139581. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139582. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139583. };
  139584. static noise3 _psy_noisebias_16[4]={
  139585. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139586. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139587. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139588. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139589. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139590. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139591. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139592. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139593. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139594. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139595. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139596. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139597. };
  139598. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139599. static int _noise_start_16[3]={ 256,256,9999 };
  139600. static int _noise_part_16[4]={ 8,8,8,8 };
  139601. static int _psy_ath_floater_16[4]={
  139602. -100,-100,-100,-105,
  139603. };
  139604. static int _psy_ath_abs_16[4]={
  139605. -130,-130,-130,-140,
  139606. };
  139607. /*** End of inlined file: psych_16.h ***/
  139608. /*** Start of inlined file: residue_16.h ***/
  139609. static static_bookblock _resbook_16s_0={
  139610. {
  139611. {0},
  139612. {0,0,&_16c0_s_p1_0},
  139613. {0,0,&_16c0_s_p2_0},
  139614. {0,0,&_16c0_s_p3_0},
  139615. {0,0,&_16c0_s_p4_0},
  139616. {0,0,&_16c0_s_p5_0},
  139617. {0,0,&_16c0_s_p6_0},
  139618. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139619. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139620. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139621. }
  139622. };
  139623. static static_bookblock _resbook_16s_1={
  139624. {
  139625. {0},
  139626. {0,0,&_16c1_s_p1_0},
  139627. {0,0,&_16c1_s_p2_0},
  139628. {0,0,&_16c1_s_p3_0},
  139629. {0,0,&_16c1_s_p4_0},
  139630. {0,0,&_16c1_s_p5_0},
  139631. {0,0,&_16c1_s_p6_0},
  139632. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139633. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139634. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139635. }
  139636. };
  139637. static static_bookblock _resbook_16s_2={
  139638. {
  139639. {0},
  139640. {0,0,&_16c2_s_p1_0},
  139641. {0,0,&_16c2_s_p2_0},
  139642. {0,0,&_16c2_s_p3_0},
  139643. {0,0,&_16c2_s_p4_0},
  139644. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139645. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139646. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139647. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139648. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139649. }
  139650. };
  139651. static vorbis_residue_template _res_16s_0[]={
  139652. {2,0, &_residue_44_mid,
  139653. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139654. &_resbook_16s_0,&_resbook_16s_0},
  139655. };
  139656. static vorbis_residue_template _res_16s_1[]={
  139657. {2,0, &_residue_44_mid,
  139658. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139659. &_resbook_16s_1,&_resbook_16s_1},
  139660. {2,0, &_residue_44_mid,
  139661. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139662. &_resbook_16s_1,&_resbook_16s_1}
  139663. };
  139664. static vorbis_residue_template _res_16s_2[]={
  139665. {2,0, &_residue_44_high,
  139666. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139667. &_resbook_16s_2,&_resbook_16s_2},
  139668. {2,0, &_residue_44_high,
  139669. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139670. &_resbook_16s_2,&_resbook_16s_2}
  139671. };
  139672. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  139673. { _map_nominal, _res_16s_0 }, /* 0 */
  139674. { _map_nominal, _res_16s_1 }, /* 1 */
  139675. { _map_nominal, _res_16s_2 }, /* 2 */
  139676. };
  139677. static static_bookblock _resbook_16u_0={
  139678. {
  139679. {0},
  139680. {0,0,&_16u0__p1_0},
  139681. {0,0,&_16u0__p2_0},
  139682. {0,0,&_16u0__p3_0},
  139683. {0,0,&_16u0__p4_0},
  139684. {0,0,&_16u0__p5_0},
  139685. {&_16u0__p6_0,&_16u0__p6_1},
  139686. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  139687. }
  139688. };
  139689. static static_bookblock _resbook_16u_1={
  139690. {
  139691. {0},
  139692. {0,0,&_16u1__p1_0},
  139693. {0,0,&_16u1__p2_0},
  139694. {0,0,&_16u1__p3_0},
  139695. {0,0,&_16u1__p4_0},
  139696. {0,0,&_16u1__p5_0},
  139697. {0,0,&_16u1__p6_0},
  139698. {&_16u1__p7_0,&_16u1__p7_1},
  139699. {&_16u1__p8_0,&_16u1__p8_1},
  139700. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  139701. }
  139702. };
  139703. static static_bookblock _resbook_16u_2={
  139704. {
  139705. {0},
  139706. {0,0,&_16u2_p1_0},
  139707. {0,0,&_16u2_p2_0},
  139708. {0,0,&_16u2_p3_0},
  139709. {0,0,&_16u2_p4_0},
  139710. {&_16u2_p5_0,&_16u2_p5_1},
  139711. {&_16u2_p6_0,&_16u2_p6_1},
  139712. {&_16u2_p7_0,&_16u2_p7_1},
  139713. {&_16u2_p8_0,&_16u2_p8_1},
  139714. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  139715. }
  139716. };
  139717. static vorbis_residue_template _res_16u_0[]={
  139718. {1,0, &_residue_44_low_un,
  139719. &_huff_book__16u0__single,&_huff_book__16u0__single,
  139720. &_resbook_16u_0,&_resbook_16u_0},
  139721. };
  139722. static vorbis_residue_template _res_16u_1[]={
  139723. {1,0, &_residue_44_mid_un,
  139724. &_huff_book__16u1__short,&_huff_book__16u1__short,
  139725. &_resbook_16u_1,&_resbook_16u_1},
  139726. {1,0, &_residue_44_mid_un,
  139727. &_huff_book__16u1__long,&_huff_book__16u1__long,
  139728. &_resbook_16u_1,&_resbook_16u_1}
  139729. };
  139730. static vorbis_residue_template _res_16u_2[]={
  139731. {1,0, &_residue_44_hi_un,
  139732. &_huff_book__16u2__short,&_huff_book__16u2__short,
  139733. &_resbook_16u_2,&_resbook_16u_2},
  139734. {1,0, &_residue_44_hi_un,
  139735. &_huff_book__16u2__long,&_huff_book__16u2__long,
  139736. &_resbook_16u_2,&_resbook_16u_2}
  139737. };
  139738. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  139739. { _map_nominal_u, _res_16u_0 }, /* 0 */
  139740. { _map_nominal_u, _res_16u_1 }, /* 1 */
  139741. { _map_nominal_u, _res_16u_2 }, /* 2 */
  139742. };
  139743. /*** End of inlined file: residue_16.h ***/
  139744. static int blocksize_16_short[3]={
  139745. 1024,512,512
  139746. };
  139747. static int blocksize_16_long[3]={
  139748. 1024,1024,1024
  139749. };
  139750. static int _floor_mapping_16_short[3]={
  139751. 9,3,3
  139752. };
  139753. static int _floor_mapping_16[3]={
  139754. 9,9,9
  139755. };
  139756. static double rate_mapping_16[4]={
  139757. 12000.,20000.,44000.,86000.
  139758. };
  139759. static double rate_mapping_16_uncoupled[4]={
  139760. 16000.,28000.,64000.,100000.
  139761. };
  139762. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  139763. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  139764. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  139765. ve_setup_data_template ve_setup_16_stereo={
  139766. 3,
  139767. rate_mapping_16,
  139768. quality_mapping_16,
  139769. 2,
  139770. 15000,
  139771. 19000,
  139772. blocksize_16_short,
  139773. blocksize_16_long,
  139774. _psy_tone_masteratt_16,
  139775. _psy_tone_0dB,
  139776. _psy_tone_suppress,
  139777. _vp_tonemask_adj_16,
  139778. _vp_tonemask_adj_16,
  139779. _vp_tonemask_adj_16,
  139780. _psy_noiseguards_8,
  139781. _psy_noisebias_16_impulse,
  139782. _psy_noisebias_16_short,
  139783. _psy_noisebias_16_short,
  139784. _psy_noisebias_16,
  139785. _psy_noise_suppress,
  139786. _psy_compand_8,
  139787. _psy_compand_16_mapping,
  139788. _psy_compand_16_mapping,
  139789. {_noise_start_16,_noise_start_16},
  139790. { _noise_part_16, _noise_part_16},
  139791. _noise_thresh_16,
  139792. _psy_ath_floater_16,
  139793. _psy_ath_abs_16,
  139794. _psy_lowpass_16,
  139795. _psy_global_44,
  139796. _global_mapping_16,
  139797. _psy_stereo_modes_16,
  139798. _floor_books,
  139799. _floor,
  139800. _floor_mapping_16_short,
  139801. _floor_mapping_16,
  139802. _mapres_template_16_stereo
  139803. };
  139804. ve_setup_data_template ve_setup_16_uncoupled={
  139805. 3,
  139806. rate_mapping_16_uncoupled,
  139807. quality_mapping_16,
  139808. -1,
  139809. 15000,
  139810. 19000,
  139811. blocksize_16_short,
  139812. blocksize_16_long,
  139813. _psy_tone_masteratt_16,
  139814. _psy_tone_0dB,
  139815. _psy_tone_suppress,
  139816. _vp_tonemask_adj_16,
  139817. _vp_tonemask_adj_16,
  139818. _vp_tonemask_adj_16,
  139819. _psy_noiseguards_8,
  139820. _psy_noisebias_16_impulse,
  139821. _psy_noisebias_16_short,
  139822. _psy_noisebias_16_short,
  139823. _psy_noisebias_16,
  139824. _psy_noise_suppress,
  139825. _psy_compand_8,
  139826. _psy_compand_16_mapping,
  139827. _psy_compand_16_mapping,
  139828. {_noise_start_16,_noise_start_16},
  139829. { _noise_part_16, _noise_part_16},
  139830. _noise_thresh_16,
  139831. _psy_ath_floater_16,
  139832. _psy_ath_abs_16,
  139833. _psy_lowpass_16,
  139834. _psy_global_44,
  139835. _global_mapping_16,
  139836. _psy_stereo_modes_16,
  139837. _floor_books,
  139838. _floor,
  139839. _floor_mapping_16_short,
  139840. _floor_mapping_16,
  139841. _mapres_template_16_uncoupled
  139842. };
  139843. /*** End of inlined file: setup_16.h ***/
  139844. /*** Start of inlined file: setup_22.h ***/
  139845. static double rate_mapping_22[4]={
  139846. 15000.,20000.,44000.,86000.
  139847. };
  139848. static double rate_mapping_22_uncoupled[4]={
  139849. 16000.,28000.,50000.,90000.
  139850. };
  139851. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  139852. ve_setup_data_template ve_setup_22_stereo={
  139853. 3,
  139854. rate_mapping_22,
  139855. quality_mapping_16,
  139856. 2,
  139857. 19000,
  139858. 26000,
  139859. blocksize_16_short,
  139860. blocksize_16_long,
  139861. _psy_tone_masteratt_16,
  139862. _psy_tone_0dB,
  139863. _psy_tone_suppress,
  139864. _vp_tonemask_adj_16,
  139865. _vp_tonemask_adj_16,
  139866. _vp_tonemask_adj_16,
  139867. _psy_noiseguards_8,
  139868. _psy_noisebias_16_impulse,
  139869. _psy_noisebias_16_short,
  139870. _psy_noisebias_16_short,
  139871. _psy_noisebias_16,
  139872. _psy_noise_suppress,
  139873. _psy_compand_8,
  139874. _psy_compand_8_mapping,
  139875. _psy_compand_8_mapping,
  139876. {_noise_start_16,_noise_start_16},
  139877. { _noise_part_16, _noise_part_16},
  139878. _noise_thresh_16,
  139879. _psy_ath_floater_16,
  139880. _psy_ath_abs_16,
  139881. _psy_lowpass_22,
  139882. _psy_global_44,
  139883. _global_mapping_16,
  139884. _psy_stereo_modes_16,
  139885. _floor_books,
  139886. _floor,
  139887. _floor_mapping_16_short,
  139888. _floor_mapping_16,
  139889. _mapres_template_16_stereo
  139890. };
  139891. ve_setup_data_template ve_setup_22_uncoupled={
  139892. 3,
  139893. rate_mapping_22_uncoupled,
  139894. quality_mapping_16,
  139895. -1,
  139896. 19000,
  139897. 26000,
  139898. blocksize_16_short,
  139899. blocksize_16_long,
  139900. _psy_tone_masteratt_16,
  139901. _psy_tone_0dB,
  139902. _psy_tone_suppress,
  139903. _vp_tonemask_adj_16,
  139904. _vp_tonemask_adj_16,
  139905. _vp_tonemask_adj_16,
  139906. _psy_noiseguards_8,
  139907. _psy_noisebias_16_impulse,
  139908. _psy_noisebias_16_short,
  139909. _psy_noisebias_16_short,
  139910. _psy_noisebias_16,
  139911. _psy_noise_suppress,
  139912. _psy_compand_8,
  139913. _psy_compand_8_mapping,
  139914. _psy_compand_8_mapping,
  139915. {_noise_start_16,_noise_start_16},
  139916. { _noise_part_16, _noise_part_16},
  139917. _noise_thresh_16,
  139918. _psy_ath_floater_16,
  139919. _psy_ath_abs_16,
  139920. _psy_lowpass_22,
  139921. _psy_global_44,
  139922. _global_mapping_16,
  139923. _psy_stereo_modes_16,
  139924. _floor_books,
  139925. _floor,
  139926. _floor_mapping_16_short,
  139927. _floor_mapping_16,
  139928. _mapres_template_16_uncoupled
  139929. };
  139930. /*** End of inlined file: setup_22.h ***/
  139931. /*** Start of inlined file: setup_X.h ***/
  139932. static double rate_mapping_X[12]={
  139933. -1.,-1.,-1.,-1.,-1.,-1.,
  139934. -1.,-1.,-1.,-1.,-1.,-1.
  139935. };
  139936. ve_setup_data_template ve_setup_X_stereo={
  139937. 11,
  139938. rate_mapping_X,
  139939. quality_mapping_44,
  139940. 2,
  139941. 50000,
  139942. 200000,
  139943. blocksize_short_44,
  139944. blocksize_long_44,
  139945. _psy_tone_masteratt_44,
  139946. _psy_tone_0dB,
  139947. _psy_tone_suppress,
  139948. _vp_tonemask_adj_otherblock,
  139949. _vp_tonemask_adj_longblock,
  139950. _vp_tonemask_adj_otherblock,
  139951. _psy_noiseguards_44,
  139952. _psy_noisebias_impulse,
  139953. _psy_noisebias_padding,
  139954. _psy_noisebias_trans,
  139955. _psy_noisebias_long,
  139956. _psy_noise_suppress,
  139957. _psy_compand_44,
  139958. _psy_compand_short_mapping,
  139959. _psy_compand_long_mapping,
  139960. {_noise_start_short_44,_noise_start_long_44},
  139961. {_noise_part_short_44,_noise_part_long_44},
  139962. _noise_thresh_44,
  139963. _psy_ath_floater,
  139964. _psy_ath_abs,
  139965. _psy_lowpass_44,
  139966. _psy_global_44,
  139967. _global_mapping_44,
  139968. _psy_stereo_modes_44,
  139969. _floor_books,
  139970. _floor,
  139971. _floor_short_mapping_44,
  139972. _floor_long_mapping_44,
  139973. _mapres_template_44_stereo
  139974. };
  139975. ve_setup_data_template ve_setup_X_uncoupled={
  139976. 11,
  139977. rate_mapping_X,
  139978. quality_mapping_44,
  139979. -1,
  139980. 50000,
  139981. 200000,
  139982. blocksize_short_44,
  139983. blocksize_long_44,
  139984. _psy_tone_masteratt_44,
  139985. _psy_tone_0dB,
  139986. _psy_tone_suppress,
  139987. _vp_tonemask_adj_otherblock,
  139988. _vp_tonemask_adj_longblock,
  139989. _vp_tonemask_adj_otherblock,
  139990. _psy_noiseguards_44,
  139991. _psy_noisebias_impulse,
  139992. _psy_noisebias_padding,
  139993. _psy_noisebias_trans,
  139994. _psy_noisebias_long,
  139995. _psy_noise_suppress,
  139996. _psy_compand_44,
  139997. _psy_compand_short_mapping,
  139998. _psy_compand_long_mapping,
  139999. {_noise_start_short_44,_noise_start_long_44},
  140000. {_noise_part_short_44,_noise_part_long_44},
  140001. _noise_thresh_44,
  140002. _psy_ath_floater,
  140003. _psy_ath_abs,
  140004. _psy_lowpass_44,
  140005. _psy_global_44,
  140006. _global_mapping_44,
  140007. NULL,
  140008. _floor_books,
  140009. _floor,
  140010. _floor_short_mapping_44,
  140011. _floor_long_mapping_44,
  140012. _mapres_template_44_uncoupled
  140013. };
  140014. ve_setup_data_template ve_setup_XX_stereo={
  140015. 2,
  140016. rate_mapping_X,
  140017. quality_mapping_8,
  140018. 2,
  140019. 0,
  140020. 8000,
  140021. blocksize_8,
  140022. blocksize_8,
  140023. _psy_tone_masteratt_8,
  140024. _psy_tone_0dB,
  140025. _psy_tone_suppress,
  140026. _vp_tonemask_adj_8,
  140027. NULL,
  140028. _vp_tonemask_adj_8,
  140029. _psy_noiseguards_8,
  140030. _psy_noisebias_8,
  140031. _psy_noisebias_8,
  140032. NULL,
  140033. NULL,
  140034. _psy_noise_suppress,
  140035. _psy_compand_8,
  140036. _psy_compand_8_mapping,
  140037. NULL,
  140038. {_noise_start_8,_noise_start_8},
  140039. {_noise_part_8,_noise_part_8},
  140040. _noise_thresh_5only,
  140041. _psy_ath_floater_8,
  140042. _psy_ath_abs_8,
  140043. _psy_lowpass_8,
  140044. _psy_global_44,
  140045. _global_mapping_8,
  140046. _psy_stereo_modes_8,
  140047. _floor_books,
  140048. _floor,
  140049. _floor_mapping_8,
  140050. NULL,
  140051. _mapres_template_8_stereo
  140052. };
  140053. ve_setup_data_template ve_setup_XX_uncoupled={
  140054. 2,
  140055. rate_mapping_X,
  140056. quality_mapping_8,
  140057. -1,
  140058. 0,
  140059. 8000,
  140060. blocksize_8,
  140061. blocksize_8,
  140062. _psy_tone_masteratt_8,
  140063. _psy_tone_0dB,
  140064. _psy_tone_suppress,
  140065. _vp_tonemask_adj_8,
  140066. NULL,
  140067. _vp_tonemask_adj_8,
  140068. _psy_noiseguards_8,
  140069. _psy_noisebias_8,
  140070. _psy_noisebias_8,
  140071. NULL,
  140072. NULL,
  140073. _psy_noise_suppress,
  140074. _psy_compand_8,
  140075. _psy_compand_8_mapping,
  140076. NULL,
  140077. {_noise_start_8,_noise_start_8},
  140078. {_noise_part_8,_noise_part_8},
  140079. _noise_thresh_5only,
  140080. _psy_ath_floater_8,
  140081. _psy_ath_abs_8,
  140082. _psy_lowpass_8,
  140083. _psy_global_44,
  140084. _global_mapping_8,
  140085. _psy_stereo_modes_8,
  140086. _floor_books,
  140087. _floor,
  140088. _floor_mapping_8,
  140089. NULL,
  140090. _mapres_template_8_uncoupled
  140091. };
  140092. /*** End of inlined file: setup_X.h ***/
  140093. static ve_setup_data_template *setup_list[]={
  140094. &ve_setup_44_stereo,
  140095. &ve_setup_44_uncoupled,
  140096. &ve_setup_32_stereo,
  140097. &ve_setup_32_uncoupled,
  140098. &ve_setup_22_stereo,
  140099. &ve_setup_22_uncoupled,
  140100. &ve_setup_16_stereo,
  140101. &ve_setup_16_uncoupled,
  140102. &ve_setup_11_stereo,
  140103. &ve_setup_11_uncoupled,
  140104. &ve_setup_8_stereo,
  140105. &ve_setup_8_uncoupled,
  140106. &ve_setup_X_stereo,
  140107. &ve_setup_X_uncoupled,
  140108. &ve_setup_XX_stereo,
  140109. &ve_setup_XX_uncoupled,
  140110. 0
  140111. };
  140112. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  140113. if(vi && vi->codec_setup){
  140114. vi->version=0;
  140115. vi->channels=ch;
  140116. vi->rate=rate;
  140117. return(0);
  140118. }
  140119. return(OV_EINVAL);
  140120. }
  140121. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  140122. static_codebook ***books,
  140123. vorbis_info_floor1 *in,
  140124. int *x){
  140125. int i,k,is=s;
  140126. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  140127. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140128. memcpy(f,in+x[is],sizeof(*f));
  140129. f->n=ci->blocksizes[block]>>1;
  140130. {
  140131. int partitions=f->partitions;
  140132. int maxclass=-1;
  140133. int maxbook=-1;
  140134. for(i=0;i<partitions;i++)
  140135. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  140136. for(i=0;i<=maxclass;i++){
  140137. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  140138. f->class_book[i]+=ci->books;
  140139. for(k=0;k<(1<<f->class_subs[i]);k++){
  140140. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  140141. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  140142. }
  140143. }
  140144. for(i=0;i<=maxbook;i++)
  140145. ci->book_param[ci->books++]=books[x[is]][i];
  140146. }
  140147. ci->floor_type[ci->floors]=1;
  140148. ci->floor_param[ci->floors]=f;
  140149. ci->floors++;
  140150. return;
  140151. }
  140152. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  140153. vorbis_info_psy_global *in,
  140154. double *x){
  140155. int i,is=s;
  140156. double ds=s-is;
  140157. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140158. vorbis_info_psy_global *g=&ci->psy_g_param;
  140159. memcpy(g,in+(int)x[is],sizeof(*g));
  140160. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140161. is=(int)ds;
  140162. ds-=is;
  140163. if(ds==0 && is>0){
  140164. is--;
  140165. ds=1.;
  140166. }
  140167. for(i=0;i<4;i++){
  140168. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  140169. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  140170. }
  140171. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  140172. return;
  140173. }
  140174. static void vorbis_encode_global_stereo(vorbis_info *vi,
  140175. highlevel_encode_setup *hi,
  140176. adj_stereo *p){
  140177. float s=hi->stereo_point_setting;
  140178. int i,is=s;
  140179. double ds=s-is;
  140180. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140181. vorbis_info_psy_global *g=&ci->psy_g_param;
  140182. if(p){
  140183. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  140184. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  140185. if(hi->managed){
  140186. for(i=0;i<PACKETBLOBS;i++){
  140187. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  140188. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140189. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140190. g->coupling_pkHz[i]=kHz;
  140191. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  140192. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140193. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140194. }
  140195. }else{
  140196. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  140197. for(i=0;i<PACKETBLOBS;i++){
  140198. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140199. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140200. g->coupling_pkHz[i]=kHz;
  140201. }
  140202. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  140203. for(i=0;i<PACKETBLOBS;i++){
  140204. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140205. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140206. }
  140207. }
  140208. }else{
  140209. for(i=0;i<PACKETBLOBS;i++){
  140210. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  140211. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  140212. }
  140213. }
  140214. return;
  140215. }
  140216. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  140217. int *nn_start,
  140218. int *nn_partition,
  140219. double *nn_thresh,
  140220. int block){
  140221. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140222. vorbis_info_psy *p=ci->psy_param[block];
  140223. highlevel_encode_setup *hi=&ci->hi;
  140224. int is=s;
  140225. if(block>=ci->psys)
  140226. ci->psys=block+1;
  140227. if(!p){
  140228. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  140229. ci->psy_param[block]=p;
  140230. }
  140231. memcpy(p,&_psy_info_template,sizeof(*p));
  140232. p->blockflag=block>>1;
  140233. if(hi->noise_normalize_p){
  140234. p->normal_channel_p=1;
  140235. p->normal_point_p=1;
  140236. p->normal_start=nn_start[is];
  140237. p->normal_partition=nn_partition[is];
  140238. p->normal_thresh=nn_thresh[is];
  140239. }
  140240. return;
  140241. }
  140242. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  140243. att3 *att,
  140244. int *max,
  140245. vp_adjblock *in){
  140246. int i,is=s;
  140247. double ds=s-is;
  140248. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140249. vorbis_info_psy *p=ci->psy_param[block];
  140250. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  140251. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  140252. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  140253. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  140254. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  140255. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  140256. for(i=0;i<P_BANDS;i++)
  140257. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  140258. return;
  140259. }
  140260. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  140261. compandblock *in, double *x){
  140262. int i,is=s;
  140263. double ds=s-is;
  140264. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140265. vorbis_info_psy *p=ci->psy_param[block];
  140266. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140267. is=(int)ds;
  140268. ds-=is;
  140269. if(ds==0 && is>0){
  140270. is--;
  140271. ds=1.;
  140272. }
  140273. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  140274. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  140275. return;
  140276. }
  140277. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  140278. int *suppress){
  140279. int is=s;
  140280. double ds=s-is;
  140281. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140282. vorbis_info_psy *p=ci->psy_param[block];
  140283. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140284. return;
  140285. }
  140286. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140287. int *suppress,
  140288. noise3 *in,
  140289. noiseguard *guard,
  140290. double userbias){
  140291. int i,is=s,j;
  140292. double ds=s-is;
  140293. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140294. vorbis_info_psy *p=ci->psy_param[block];
  140295. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140296. p->noisewindowlomin=guard[block].lo;
  140297. p->noisewindowhimin=guard[block].hi;
  140298. p->noisewindowfixed=guard[block].fixed;
  140299. for(j=0;j<P_NOISECURVES;j++)
  140300. for(i=0;i<P_BANDS;i++)
  140301. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140302. for(j=0;j<P_NOISECURVES;j++){
  140303. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140304. for(i=0;i<P_BANDS;i++){
  140305. p->noiseoff[j][i]+=userbias;
  140306. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140307. }
  140308. }
  140309. return;
  140310. }
  140311. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140312. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140313. vorbis_info_psy *p=ci->psy_param[block];
  140314. p->ath_adjatt=ci->hi.ath_floating_dB;
  140315. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140316. return;
  140317. }
  140318. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140319. int i;
  140320. for(i=0;i<ci->books;i++)
  140321. if(ci->book_param[i]==book)return(i);
  140322. return(ci->books++);
  140323. }
  140324. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140325. int *shortb,int *longb){
  140326. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140327. int is=s;
  140328. int blockshort=shortb[is];
  140329. int blocklong=longb[is];
  140330. ci->blocksizes[0]=blockshort;
  140331. ci->blocksizes[1]=blocklong;
  140332. }
  140333. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140334. int number, int block,
  140335. vorbis_residue_template *res){
  140336. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140337. int i,n;
  140338. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140339. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140340. memcpy(r,res->res,sizeof(*r));
  140341. if(ci->residues<=number)ci->residues=number+1;
  140342. switch(ci->blocksizes[block]){
  140343. case 64:case 128:case 256:
  140344. r->grouping=16;
  140345. break;
  140346. default:
  140347. r->grouping=32;
  140348. break;
  140349. }
  140350. ci->residue_type[number]=res->res_type;
  140351. n=r->end=ci->blocksizes[block]>>1;
  140352. if(res->res_type==2)
  140353. n=r->end*=vi->channels;
  140354. {
  140355. int booklist=0,k;
  140356. if(ci->hi.managed){
  140357. for(i=0;i<r->partitions;i++)
  140358. for(k=0;k<3;k++)
  140359. if(res->books_base_managed->books[i][k])
  140360. r->secondstages[i]|=(1<<k);
  140361. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140362. ci->book_param[r->groupbook]=res->book_aux_managed;
  140363. for(i=0;i<r->partitions;i++){
  140364. for(k=0;k<3;k++){
  140365. if(res->books_base_managed->books[i][k]){
  140366. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140367. r->booklist[booklist++]=bookid;
  140368. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140369. }
  140370. }
  140371. }
  140372. }else{
  140373. for(i=0;i<r->partitions;i++)
  140374. for(k=0;k<3;k++)
  140375. if(res->books_base->books[i][k])
  140376. r->secondstages[i]|=(1<<k);
  140377. r->groupbook=book_dup_or_new(ci,res->book_aux);
  140378. ci->book_param[r->groupbook]=res->book_aux;
  140379. for(i=0;i<r->partitions;i++){
  140380. for(k=0;k<3;k++){
  140381. if(res->books_base->books[i][k]){
  140382. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  140383. r->booklist[booklist++]=bookid;
  140384. ci->book_param[bookid]=res->books_base->books[i][k];
  140385. }
  140386. }
  140387. }
  140388. }
  140389. }
  140390. {
  140391. double freq=ci->hi.lowpass_kHz*1000.;
  140392. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  140393. double nyq=vi->rate/2.;
  140394. long blocksize=ci->blocksizes[block]>>1;
  140395. if(freq>nyq)freq=nyq;
  140396. f->n=freq/nyq*blocksize;
  140397. if(res->limit_type){
  140398. if(ci->hi.managed)
  140399. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140400. else
  140401. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140402. if(freq>nyq)freq=nyq;
  140403. }
  140404. if(ci->residue_type[block]==2)
  140405. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140406. r->grouping;
  140407. else
  140408. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140409. r->grouping;
  140410. }
  140411. }
  140412. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140413. vorbis_mapping_template *maps){
  140414. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140415. int i,j,is=s,modes=2;
  140416. vorbis_info_mapping0 *map=maps[is].map;
  140417. vorbis_info_mode *mode=_mode_template;
  140418. vorbis_residue_template *res=maps[is].res;
  140419. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140420. for(i=0;i<modes;i++){
  140421. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140422. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140423. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140424. if(i>=ci->modes)ci->modes=i+1;
  140425. ci->map_type[i]=0;
  140426. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140427. if(i>=ci->maps)ci->maps=i+1;
  140428. for(j=0;j<map[i].submaps;j++)
  140429. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140430. ,res+map[i].residuesubmap[j]);
  140431. }
  140432. }
  140433. static double setting_to_approx_bitrate(vorbis_info *vi){
  140434. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140435. highlevel_encode_setup *hi=&ci->hi;
  140436. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140437. int is=hi->base_setting;
  140438. double ds=hi->base_setting-is;
  140439. int ch=vi->channels;
  140440. double *r=setup->rate_mapping;
  140441. if(r==NULL)
  140442. return(-1);
  140443. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140444. }
  140445. static void get_setup_template(vorbis_info *vi,
  140446. long ch,long srate,
  140447. double req,int q_or_bitrate){
  140448. int i=0,j;
  140449. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140450. highlevel_encode_setup *hi=&ci->hi;
  140451. if(q_or_bitrate)req/=ch;
  140452. while(setup_list[i]){
  140453. if(setup_list[i]->coupling_restriction==-1 ||
  140454. setup_list[i]->coupling_restriction==ch){
  140455. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140456. srate<=setup_list[i]->samplerate_max_restriction){
  140457. int mappings=setup_list[i]->mappings;
  140458. double *map=(q_or_bitrate?
  140459. setup_list[i]->rate_mapping:
  140460. setup_list[i]->quality_mapping);
  140461. if(req<map[0]){++i;continue;}
  140462. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140463. for(j=0;j<mappings;j++)
  140464. if(req>=map[j] && req<map[j+1])break;
  140465. hi->setup=setup_list[i];
  140466. if(j==mappings)
  140467. hi->base_setting=j-.001;
  140468. else{
  140469. float low=map[j];
  140470. float high=map[j+1];
  140471. float del=(req-low)/(high-low);
  140472. hi->base_setting=j+del;
  140473. }
  140474. return;
  140475. }
  140476. }
  140477. i++;
  140478. }
  140479. hi->setup=NULL;
  140480. }
  140481. int vorbis_encode_setup_init(vorbis_info *vi){
  140482. int i0=0,singleblock=0;
  140483. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140484. ve_setup_data_template *setup=NULL;
  140485. highlevel_encode_setup *hi=&ci->hi;
  140486. if(ci==NULL)return(OV_EINVAL);
  140487. if(!hi->impulse_block_p)i0=1;
  140488. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140489. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140490. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140491. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140492. setup=(ve_setup_data_template *)hi->setup;
  140493. if(setup==NULL)return(OV_EINVAL);
  140494. hi->set_in_stone=1;
  140495. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140496. setup->blocksize_short,
  140497. setup->blocksize_long);
  140498. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140499. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140500. setup->floor_books,
  140501. setup->floor_params,
  140502. setup->floor_short_mapping);
  140503. if(!singleblock)
  140504. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140505. setup->floor_books,
  140506. setup->floor_params,
  140507. setup->floor_long_mapping);
  140508. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140509. setup->global_params,
  140510. setup->global_mapping);
  140511. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140512. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140513. setup->psy_noise_normal_start[0],
  140514. setup->psy_noise_normal_partition[0],
  140515. setup->psy_noise_normal_thresh,
  140516. 0);
  140517. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140518. setup->psy_noise_normal_start[0],
  140519. setup->psy_noise_normal_partition[0],
  140520. setup->psy_noise_normal_thresh,
  140521. 1);
  140522. if(!singleblock){
  140523. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140524. setup->psy_noise_normal_start[1],
  140525. setup->psy_noise_normal_partition[1],
  140526. setup->psy_noise_normal_thresh,
  140527. 2);
  140528. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140529. setup->psy_noise_normal_start[1],
  140530. setup->psy_noise_normal_partition[1],
  140531. setup->psy_noise_normal_thresh,
  140532. 3);
  140533. }
  140534. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140535. setup->psy_tone_masteratt,
  140536. setup->psy_tone_0dB,
  140537. setup->psy_tone_adj_impulse);
  140538. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140539. setup->psy_tone_masteratt,
  140540. setup->psy_tone_0dB,
  140541. setup->psy_tone_adj_other);
  140542. if(!singleblock){
  140543. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140544. setup->psy_tone_masteratt,
  140545. setup->psy_tone_0dB,
  140546. setup->psy_tone_adj_other);
  140547. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140548. setup->psy_tone_masteratt,
  140549. setup->psy_tone_0dB,
  140550. setup->psy_tone_adj_long);
  140551. }
  140552. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140553. setup->psy_noise_compand,
  140554. setup->psy_noise_compand_short_mapping);
  140555. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140556. setup->psy_noise_compand,
  140557. setup->psy_noise_compand_short_mapping);
  140558. if(!singleblock){
  140559. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140560. setup->psy_noise_compand,
  140561. setup->psy_noise_compand_long_mapping);
  140562. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140563. setup->psy_noise_compand,
  140564. setup->psy_noise_compand_long_mapping);
  140565. }
  140566. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140567. setup->psy_tone_dBsuppress);
  140568. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140569. setup->psy_tone_dBsuppress);
  140570. if(!singleblock){
  140571. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140572. setup->psy_tone_dBsuppress);
  140573. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140574. setup->psy_tone_dBsuppress);
  140575. }
  140576. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140577. setup->psy_noise_dBsuppress,
  140578. setup->psy_noise_bias_impulse,
  140579. setup->psy_noiseguards,
  140580. (i0==0?hi->impulse_noisetune:0.));
  140581. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140582. setup->psy_noise_dBsuppress,
  140583. setup->psy_noise_bias_padding,
  140584. setup->psy_noiseguards,0.);
  140585. if(!singleblock){
  140586. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140587. setup->psy_noise_dBsuppress,
  140588. setup->psy_noise_bias_trans,
  140589. setup->psy_noiseguards,0.);
  140590. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140591. setup->psy_noise_dBsuppress,
  140592. setup->psy_noise_bias_long,
  140593. setup->psy_noiseguards,0.);
  140594. }
  140595. vorbis_encode_ath_setup(vi,0);
  140596. vorbis_encode_ath_setup(vi,1);
  140597. if(!singleblock){
  140598. vorbis_encode_ath_setup(vi,2);
  140599. vorbis_encode_ath_setup(vi,3);
  140600. }
  140601. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140602. if(hi->bitrate_av>0)
  140603. vi->bitrate_nominal=hi->bitrate_av;
  140604. else{
  140605. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140606. }
  140607. vi->bitrate_lower=hi->bitrate_min;
  140608. vi->bitrate_upper=hi->bitrate_max;
  140609. if(hi->bitrate_av)
  140610. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140611. else
  140612. vi->bitrate_window=0.;
  140613. if(hi->managed){
  140614. ci->bi.avg_rate=hi->bitrate_av;
  140615. ci->bi.min_rate=hi->bitrate_min;
  140616. ci->bi.max_rate=hi->bitrate_max;
  140617. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140618. ci->bi.reservoir_bias=
  140619. hi->bitrate_reservoir_bias;
  140620. ci->bi.slew_damp=hi->bitrate_av_damp;
  140621. }
  140622. return(0);
  140623. }
  140624. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140625. long channels,
  140626. long rate){
  140627. int ret=0,i,is;
  140628. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140629. highlevel_encode_setup *hi=&ci->hi;
  140630. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140631. double ds;
  140632. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140633. if(ret)return(ret);
  140634. is=hi->base_setting;
  140635. ds=hi->base_setting-is;
  140636. hi->short_setting=hi->base_setting;
  140637. hi->long_setting=hi->base_setting;
  140638. hi->managed=0;
  140639. hi->impulse_block_p=1;
  140640. hi->noise_normalize_p=1;
  140641. hi->stereo_point_setting=hi->base_setting;
  140642. hi->lowpass_kHz=
  140643. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140644. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140645. setup->psy_ath_float[is+1]*ds;
  140646. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140647. setup->psy_ath_abs[is+1]*ds;
  140648. hi->amplitude_track_dBpersec=-6.;
  140649. hi->trigger_setting=hi->base_setting;
  140650. for(i=0;i<4;i++){
  140651. hi->block[i].tone_mask_setting=hi->base_setting;
  140652. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140653. hi->block[i].noise_bias_setting=hi->base_setting;
  140654. hi->block[i].noise_compand_setting=hi->base_setting;
  140655. }
  140656. return(ret);
  140657. }
  140658. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140659. long channels,
  140660. long rate,
  140661. float quality){
  140662. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140663. highlevel_encode_setup *hi=&ci->hi;
  140664. quality+=.0000001;
  140665. if(quality>=1.)quality=.9999;
  140666. get_setup_template(vi,channels,rate,quality,0);
  140667. if(!hi->setup)return OV_EIMPL;
  140668. return vorbis_encode_setup_setting(vi,channels,rate);
  140669. }
  140670. int vorbis_encode_init_vbr(vorbis_info *vi,
  140671. long channels,
  140672. long rate,
  140673. float base_quality /* 0. to 1. */
  140674. ){
  140675. int ret=0;
  140676. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  140677. if(ret){
  140678. vorbis_info_clear(vi);
  140679. return ret;
  140680. }
  140681. ret=vorbis_encode_setup_init(vi);
  140682. if(ret)
  140683. vorbis_info_clear(vi);
  140684. return(ret);
  140685. }
  140686. int vorbis_encode_setup_managed(vorbis_info *vi,
  140687. long channels,
  140688. long rate,
  140689. long max_bitrate,
  140690. long nominal_bitrate,
  140691. long min_bitrate){
  140692. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140693. highlevel_encode_setup *hi=&ci->hi;
  140694. double tnominal=nominal_bitrate;
  140695. int ret=0;
  140696. if(nominal_bitrate<=0.){
  140697. if(max_bitrate>0.){
  140698. if(min_bitrate>0.)
  140699. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  140700. else
  140701. nominal_bitrate=max_bitrate*.875;
  140702. }else{
  140703. if(min_bitrate>0.){
  140704. nominal_bitrate=min_bitrate;
  140705. }else{
  140706. return(OV_EINVAL);
  140707. }
  140708. }
  140709. }
  140710. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  140711. if(!hi->setup)return OV_EIMPL;
  140712. ret=vorbis_encode_setup_setting(vi,channels,rate);
  140713. if(ret){
  140714. vorbis_info_clear(vi);
  140715. return ret;
  140716. }
  140717. hi->managed=1;
  140718. hi->bitrate_min=min_bitrate;
  140719. hi->bitrate_max=max_bitrate;
  140720. hi->bitrate_av=tnominal;
  140721. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  140722. hi->bitrate_reservoir=nominal_bitrate*2;
  140723. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  140724. return(ret);
  140725. }
  140726. int vorbis_encode_init(vorbis_info *vi,
  140727. long channels,
  140728. long rate,
  140729. long max_bitrate,
  140730. long nominal_bitrate,
  140731. long min_bitrate){
  140732. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  140733. max_bitrate,
  140734. nominal_bitrate,
  140735. min_bitrate);
  140736. if(ret){
  140737. vorbis_info_clear(vi);
  140738. return(ret);
  140739. }
  140740. ret=vorbis_encode_setup_init(vi);
  140741. if(ret)
  140742. vorbis_info_clear(vi);
  140743. return(ret);
  140744. }
  140745. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  140746. if(vi){
  140747. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140748. highlevel_encode_setup *hi=&ci->hi;
  140749. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  140750. if(setp && hi->set_in_stone)return(OV_EINVAL);
  140751. switch(number){
  140752. case OV_ECTL_RATEMANAGE_GET:
  140753. {
  140754. struct ovectl_ratemanage_arg *ai=
  140755. (struct ovectl_ratemanage_arg *)arg;
  140756. ai->management_active=hi->managed;
  140757. ai->bitrate_hard_window=ai->bitrate_av_window=
  140758. (double)hi->bitrate_reservoir/vi->rate;
  140759. ai->bitrate_av_window_center=1.;
  140760. ai->bitrate_hard_min=hi->bitrate_min;
  140761. ai->bitrate_hard_max=hi->bitrate_max;
  140762. ai->bitrate_av_lo=hi->bitrate_av;
  140763. ai->bitrate_av_hi=hi->bitrate_av;
  140764. }
  140765. return(0);
  140766. case OV_ECTL_RATEMANAGE_SET:
  140767. {
  140768. struct ovectl_ratemanage_arg *ai=
  140769. (struct ovectl_ratemanage_arg *)arg;
  140770. if(ai==NULL){
  140771. hi->managed=0;
  140772. }else{
  140773. hi->managed=ai->management_active;
  140774. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  140775. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  140776. }
  140777. }
  140778. return 0;
  140779. case OV_ECTL_RATEMANAGE_AVG:
  140780. {
  140781. struct ovectl_ratemanage_arg *ai=
  140782. (struct ovectl_ratemanage_arg *)arg;
  140783. if(ai==NULL){
  140784. hi->bitrate_av=0;
  140785. }else{
  140786. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  140787. }
  140788. }
  140789. return(0);
  140790. case OV_ECTL_RATEMANAGE_HARD:
  140791. {
  140792. struct ovectl_ratemanage_arg *ai=
  140793. (struct ovectl_ratemanage_arg *)arg;
  140794. if(ai==NULL){
  140795. hi->bitrate_min=0;
  140796. hi->bitrate_max=0;
  140797. }else{
  140798. hi->bitrate_min=ai->bitrate_hard_min;
  140799. hi->bitrate_max=ai->bitrate_hard_max;
  140800. hi->bitrate_reservoir=ai->bitrate_hard_window*
  140801. (hi->bitrate_max+hi->bitrate_min)*.5;
  140802. }
  140803. if(hi->bitrate_reservoir<128.)
  140804. hi->bitrate_reservoir=128.;
  140805. }
  140806. return(0);
  140807. case OV_ECTL_RATEMANAGE2_GET:
  140808. {
  140809. struct ovectl_ratemanage2_arg *ai=
  140810. (struct ovectl_ratemanage2_arg *)arg;
  140811. if(ai==NULL)return OV_EINVAL;
  140812. ai->management_active=hi->managed;
  140813. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  140814. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  140815. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  140816. ai->bitrate_average_damping=hi->bitrate_av_damp;
  140817. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  140818. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  140819. }
  140820. return (0);
  140821. case OV_ECTL_RATEMANAGE2_SET:
  140822. {
  140823. struct ovectl_ratemanage2_arg *ai=
  140824. (struct ovectl_ratemanage2_arg *)arg;
  140825. if(ai==NULL){
  140826. hi->managed=0;
  140827. }else{
  140828. if(ai->bitrate_limit_min_kbps>0 &&
  140829. ai->bitrate_average_kbps>0 &&
  140830. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  140831. return OV_EINVAL;
  140832. if(ai->bitrate_limit_max_kbps>0 &&
  140833. ai->bitrate_average_kbps>0 &&
  140834. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  140835. return OV_EINVAL;
  140836. if(ai->bitrate_limit_min_kbps>0 &&
  140837. ai->bitrate_limit_max_kbps>0 &&
  140838. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  140839. return OV_EINVAL;
  140840. if(ai->bitrate_average_damping <= 0.)
  140841. return OV_EINVAL;
  140842. if(ai->bitrate_limit_reservoir_bits < 0)
  140843. return OV_EINVAL;
  140844. if(ai->bitrate_limit_reservoir_bias < 0.)
  140845. return OV_EINVAL;
  140846. if(ai->bitrate_limit_reservoir_bias > 1.)
  140847. return OV_EINVAL;
  140848. hi->managed=ai->management_active;
  140849. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  140850. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  140851. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  140852. hi->bitrate_av_damp=ai->bitrate_average_damping;
  140853. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  140854. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  140855. }
  140856. }
  140857. return 0;
  140858. case OV_ECTL_LOWPASS_GET:
  140859. {
  140860. double *farg=(double *)arg;
  140861. *farg=hi->lowpass_kHz;
  140862. }
  140863. return(0);
  140864. case OV_ECTL_LOWPASS_SET:
  140865. {
  140866. double *farg=(double *)arg;
  140867. hi->lowpass_kHz=*farg;
  140868. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  140869. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  140870. }
  140871. return(0);
  140872. case OV_ECTL_IBLOCK_GET:
  140873. {
  140874. double *farg=(double *)arg;
  140875. *farg=hi->impulse_noisetune;
  140876. }
  140877. return(0);
  140878. case OV_ECTL_IBLOCK_SET:
  140879. {
  140880. double *farg=(double *)arg;
  140881. hi->impulse_noisetune=*farg;
  140882. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  140883. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  140884. }
  140885. return(0);
  140886. }
  140887. return(OV_EIMPL);
  140888. }
  140889. return(OV_EINVAL);
  140890. }
  140891. #endif
  140892. /*** End of inlined file: vorbisenc.c ***/
  140893. /*** Start of inlined file: vorbisfile.c ***/
  140894. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  140895. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  140896. // tasks..
  140897. #if JUCE_MSVC
  140898. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  140899. #endif
  140900. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  140901. #if JUCE_USE_OGGVORBIS
  140902. #include <stdlib.h>
  140903. #include <stdio.h>
  140904. #include <errno.h>
  140905. #include <string.h>
  140906. #include <math.h>
  140907. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  140908. over 8k gets what they deserve */
  140909. static long _get_data(OggVorbis_File *vf){
  140910. errno=0;
  140911. if(vf->datasource){
  140912. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  140913. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  140914. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  140915. if(bytes==0 && errno)return(-1);
  140916. return(bytes);
  140917. }else
  140918. return(0);
  140919. }
  140920. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  140921. if(vf->datasource){
  140922. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  140923. vf->offset=offset;
  140924. ogg_sync_reset(&vf->oy);
  140925. }else{
  140926. return;
  140927. }
  140928. }
  140929. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  140930. ogg_int64_t boundary){
  140931. if(boundary>0)boundary+=vf->offset;
  140932. while(1){
  140933. long more;
  140934. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  140935. more=ogg_sync_pageseek(&vf->oy,og);
  140936. if(more<0){
  140937. vf->offset-=more;
  140938. }else{
  140939. if(more==0){
  140940. if(!boundary)return(OV_FALSE);
  140941. {
  140942. long ret=_get_data(vf);
  140943. if(ret==0)return(OV_EOF);
  140944. if(ret<0)return(OV_EREAD);
  140945. }
  140946. }else{
  140947. ogg_int64_t ret=vf->offset;
  140948. vf->offset+=more;
  140949. return(ret);
  140950. }
  140951. }
  140952. }
  140953. }
  140954. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  140955. ogg_int64_t begin=vf->offset;
  140956. ogg_int64_t end=begin;
  140957. ogg_int64_t ret;
  140958. ogg_int64_t offset=-1;
  140959. while(offset==-1){
  140960. begin-=CHUNKSIZE;
  140961. if(begin<0)
  140962. begin=0;
  140963. _seek_helper(vf,begin);
  140964. while(vf->offset<end){
  140965. ret=_get_next_page(vf,og,end-vf->offset);
  140966. if(ret==OV_EREAD)return(OV_EREAD);
  140967. if(ret<0){
  140968. break;
  140969. }else{
  140970. offset=ret;
  140971. }
  140972. }
  140973. }
  140974. _seek_helper(vf,offset);
  140975. ret=_get_next_page(vf,og,CHUNKSIZE);
  140976. if(ret<0)
  140977. return(OV_EFAULT);
  140978. return(offset);
  140979. }
  140980. static int _bisect_forward_serialno(OggVorbis_File *vf,
  140981. ogg_int64_t begin,
  140982. ogg_int64_t searched,
  140983. ogg_int64_t end,
  140984. long currentno,
  140985. long m){
  140986. ogg_int64_t endsearched=end;
  140987. ogg_int64_t next=end;
  140988. ogg_page og;
  140989. ogg_int64_t ret;
  140990. while(searched<endsearched){
  140991. ogg_int64_t bisect;
  140992. if(endsearched-searched<CHUNKSIZE){
  140993. bisect=searched;
  140994. }else{
  140995. bisect=(searched+endsearched)/2;
  140996. }
  140997. _seek_helper(vf,bisect);
  140998. ret=_get_next_page(vf,&og,-1);
  140999. if(ret==OV_EREAD)return(OV_EREAD);
  141000. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  141001. endsearched=bisect;
  141002. if(ret>=0)next=ret;
  141003. }else{
  141004. searched=ret+og.header_len+og.body_len;
  141005. }
  141006. }
  141007. _seek_helper(vf,next);
  141008. ret=_get_next_page(vf,&og,-1);
  141009. if(ret==OV_EREAD)return(OV_EREAD);
  141010. if(searched>=end || ret<0){
  141011. vf->links=m+1;
  141012. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  141013. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  141014. vf->offsets[m+1]=searched;
  141015. }else{
  141016. ret=_bisect_forward_serialno(vf,next,vf->offset,
  141017. end,ogg_page_serialno(&og),m+1);
  141018. if(ret==OV_EREAD)return(OV_EREAD);
  141019. }
  141020. vf->offsets[m]=begin;
  141021. vf->serialnos[m]=currentno;
  141022. return(0);
  141023. }
  141024. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  141025. long *serialno,ogg_page *og_ptr){
  141026. ogg_page og;
  141027. ogg_packet op;
  141028. int i,ret;
  141029. if(!og_ptr){
  141030. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  141031. if(llret==OV_EREAD)return(OV_EREAD);
  141032. if(llret<0)return OV_ENOTVORBIS;
  141033. og_ptr=&og;
  141034. }
  141035. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  141036. if(serialno)*serialno=vf->os.serialno;
  141037. vf->ready_state=STREAMSET;
  141038. vorbis_info_init(vi);
  141039. vorbis_comment_init(vc);
  141040. i=0;
  141041. while(i<3){
  141042. ogg_stream_pagein(&vf->os,og_ptr);
  141043. while(i<3){
  141044. int result=ogg_stream_packetout(&vf->os,&op);
  141045. if(result==0)break;
  141046. if(result==-1){
  141047. ret=OV_EBADHEADER;
  141048. goto bail_header;
  141049. }
  141050. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  141051. goto bail_header;
  141052. }
  141053. i++;
  141054. }
  141055. if(i<3)
  141056. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  141057. ret=OV_EBADHEADER;
  141058. goto bail_header;
  141059. }
  141060. }
  141061. return 0;
  141062. bail_header:
  141063. vorbis_info_clear(vi);
  141064. vorbis_comment_clear(vc);
  141065. vf->ready_state=OPENED;
  141066. return ret;
  141067. }
  141068. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  141069. ogg_page og;
  141070. int i;
  141071. ogg_int64_t ret;
  141072. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  141073. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  141074. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  141075. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  141076. for(i=0;i<vf->links;i++){
  141077. if(i==0){
  141078. vf->dataoffsets[i]=dataoffset;
  141079. _seek_helper(vf,dataoffset);
  141080. }else{
  141081. _seek_helper(vf,vf->offsets[i]);
  141082. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  141083. vf->dataoffsets[i]=-1;
  141084. }else{
  141085. vf->dataoffsets[i]=vf->offset;
  141086. }
  141087. }
  141088. if(vf->dataoffsets[i]!=-1){
  141089. ogg_int64_t accumulated=0;
  141090. long lastblock=-1;
  141091. int result;
  141092. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  141093. while(1){
  141094. ogg_packet op;
  141095. ret=_get_next_page(vf,&og,-1);
  141096. if(ret<0)
  141097. break;
  141098. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  141099. break;
  141100. ogg_stream_pagein(&vf->os,&og);
  141101. while((result=ogg_stream_packetout(&vf->os,&op))){
  141102. if(result>0){ /* ignore holes */
  141103. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  141104. if(lastblock!=-1)
  141105. accumulated+=(lastblock+thisblock)>>2;
  141106. lastblock=thisblock;
  141107. }
  141108. }
  141109. if(ogg_page_granulepos(&og)!=-1){
  141110. accumulated= ogg_page_granulepos(&og)-accumulated;
  141111. break;
  141112. }
  141113. }
  141114. if(accumulated<0)accumulated=0;
  141115. vf->pcmlengths[i*2]=accumulated;
  141116. }
  141117. {
  141118. ogg_int64_t end=vf->offsets[i+1];
  141119. _seek_helper(vf,end);
  141120. while(1){
  141121. ret=_get_prev_page(vf,&og);
  141122. if(ret<0){
  141123. vorbis_info_clear(vf->vi+i);
  141124. vorbis_comment_clear(vf->vc+i);
  141125. break;
  141126. }
  141127. if(ogg_page_granulepos(&og)!=-1){
  141128. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  141129. break;
  141130. }
  141131. vf->offset=ret;
  141132. }
  141133. }
  141134. }
  141135. }
  141136. static int _make_decode_ready(OggVorbis_File *vf){
  141137. if(vf->ready_state>STREAMSET)return 0;
  141138. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  141139. if(vf->seekable){
  141140. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  141141. return OV_EBADLINK;
  141142. }else{
  141143. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  141144. return OV_EBADLINK;
  141145. }
  141146. vorbis_block_init(&vf->vd,&vf->vb);
  141147. vf->ready_state=INITSET;
  141148. vf->bittrack=0.f;
  141149. vf->samptrack=0.f;
  141150. return 0;
  141151. }
  141152. static int _open_seekable2(OggVorbis_File *vf){
  141153. long serialno=vf->current_serialno;
  141154. ogg_int64_t dataoffset=vf->offset, end;
  141155. ogg_page og;
  141156. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  141157. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  141158. end=_get_prev_page(vf,&og);
  141159. if(end<0)return(end);
  141160. if(ogg_page_serialno(&og)!=serialno){
  141161. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  141162. }else{
  141163. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  141164. }
  141165. _prefetch_all_headers(vf,dataoffset);
  141166. return(ov_raw_seek(vf,0));
  141167. }
  141168. static void _decode_clear(OggVorbis_File *vf){
  141169. vorbis_dsp_clear(&vf->vd);
  141170. vorbis_block_clear(&vf->vb);
  141171. vf->ready_state=OPENED;
  141172. }
  141173. static int _fetch_and_process_packet(OggVorbis_File *vf,
  141174. ogg_packet *op_in,
  141175. int readp,
  141176. int spanp){
  141177. ogg_page og;
  141178. while(1){
  141179. if(vf->ready_state==INITSET){
  141180. while(1) {
  141181. ogg_packet op;
  141182. ogg_packet *op_ptr=(op_in?op_in:&op);
  141183. int result=ogg_stream_packetout(&vf->os,op_ptr);
  141184. ogg_int64_t granulepos;
  141185. op_in=NULL;
  141186. if(result==-1)return(OV_HOLE); /* hole in the data. */
  141187. if(result>0){
  141188. granulepos=op_ptr->granulepos;
  141189. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  141190. header handling. The
  141191. header packets aren't
  141192. audio, so if/when we
  141193. submit them,
  141194. vorbis_synthesis will
  141195. reject them */
  141196. {
  141197. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141198. if(oldsamples)return(OV_EFAULT);
  141199. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141200. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  141201. vf->bittrack+=op_ptr->bytes*8;
  141202. }
  141203. if(granulepos!=-1 && !op_ptr->e_o_s){
  141204. int link=(vf->seekable?vf->current_link:0);
  141205. int i,samples;
  141206. if(vf->seekable && link>0)
  141207. granulepos-=vf->pcmlengths[link*2];
  141208. if(granulepos<0)granulepos=0; /* actually, this
  141209. shouldn't be possible
  141210. here unless the stream
  141211. is very broken */
  141212. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141213. granulepos-=samples;
  141214. for(i=0;i<link;i++)
  141215. granulepos+=vf->pcmlengths[i*2+1];
  141216. vf->pcm_offset=granulepos;
  141217. }
  141218. return(1);
  141219. }
  141220. }
  141221. else
  141222. break;
  141223. }
  141224. }
  141225. if(vf->ready_state>=OPENED){
  141226. ogg_int64_t ret;
  141227. if(!readp)return(0);
  141228. if((ret=_get_next_page(vf,&og,-1))<0){
  141229. return(OV_EOF); /* eof.
  141230. leave unitialized */
  141231. }
  141232. vf->bittrack+=og.header_len*8;
  141233. if(vf->ready_state==INITSET){
  141234. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141235. if(!spanp)
  141236. return(OV_EOF);
  141237. _decode_clear(vf);
  141238. if(!vf->seekable){
  141239. vorbis_info_clear(vf->vi);
  141240. vorbis_comment_clear(vf->vc);
  141241. }
  141242. }
  141243. }
  141244. }
  141245. if(vf->ready_state!=INITSET){
  141246. int link;
  141247. if(vf->ready_state<STREAMSET){
  141248. if(vf->seekable){
  141249. vf->current_serialno=ogg_page_serialno(&og);
  141250. for(link=0;link<vf->links;link++)
  141251. if(vf->serialnos[link]==vf->current_serialno)break;
  141252. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  141253. stream. error out,
  141254. leave machine
  141255. uninitialized */
  141256. vf->current_link=link;
  141257. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141258. vf->ready_state=STREAMSET;
  141259. }else{
  141260. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  141261. if(ret)return(ret);
  141262. vf->current_link++;
  141263. link=0;
  141264. }
  141265. }
  141266. {
  141267. int ret=_make_decode_ready(vf);
  141268. if(ret<0)return ret;
  141269. }
  141270. }
  141271. ogg_stream_pagein(&vf->os,&og);
  141272. }
  141273. }
  141274. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  141275. if(f==NULL)return(-1);
  141276. return fseek(f,off,whence);
  141277. }
  141278. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  141279. long ibytes, ov_callbacks callbacks){
  141280. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  141281. int ret;
  141282. memset(vf,0,sizeof(*vf));
  141283. vf->datasource=f;
  141284. vf->callbacks = callbacks;
  141285. ogg_sync_init(&vf->oy);
  141286. if(initial){
  141287. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141288. memcpy(buffer,initial,ibytes);
  141289. ogg_sync_wrote(&vf->oy,ibytes);
  141290. }
  141291. if(offsettest!=-1)vf->seekable=1;
  141292. vf->links=1;
  141293. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141294. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141295. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141296. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141297. vf->datasource=NULL;
  141298. ov_clear(vf);
  141299. }else
  141300. vf->ready_state=PARTOPEN;
  141301. return(ret);
  141302. }
  141303. static int _ov_open2(OggVorbis_File *vf){
  141304. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141305. vf->ready_state=OPENED;
  141306. if(vf->seekable){
  141307. int ret=_open_seekable2(vf);
  141308. if(ret){
  141309. vf->datasource=NULL;
  141310. ov_clear(vf);
  141311. }
  141312. return(ret);
  141313. }else
  141314. vf->ready_state=STREAMSET;
  141315. return 0;
  141316. }
  141317. int ov_clear(OggVorbis_File *vf){
  141318. if(vf){
  141319. vorbis_block_clear(&vf->vb);
  141320. vorbis_dsp_clear(&vf->vd);
  141321. ogg_stream_clear(&vf->os);
  141322. if(vf->vi && vf->links){
  141323. int i;
  141324. for(i=0;i<vf->links;i++){
  141325. vorbis_info_clear(vf->vi+i);
  141326. vorbis_comment_clear(vf->vc+i);
  141327. }
  141328. _ogg_free(vf->vi);
  141329. _ogg_free(vf->vc);
  141330. }
  141331. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141332. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141333. if(vf->serialnos)_ogg_free(vf->serialnos);
  141334. if(vf->offsets)_ogg_free(vf->offsets);
  141335. ogg_sync_clear(&vf->oy);
  141336. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141337. memset(vf,0,sizeof(*vf));
  141338. }
  141339. #ifdef DEBUG_LEAKS
  141340. _VDBG_dump();
  141341. #endif
  141342. return(0);
  141343. }
  141344. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141345. ov_callbacks callbacks){
  141346. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141347. if(ret)return ret;
  141348. return _ov_open2(vf);
  141349. }
  141350. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141351. ov_callbacks callbacks = {
  141352. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141353. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141354. (int (*)(void *)) fclose,
  141355. (long (*)(void *)) ftell
  141356. };
  141357. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141358. }
  141359. int ov_halfrate(OggVorbis_File *vf,int flag){
  141360. int i;
  141361. if(vf->vi==NULL)return OV_EINVAL;
  141362. if(!vf->seekable)return OV_EINVAL;
  141363. if(vf->ready_state>=STREAMSET)
  141364. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141365. will be able to swap this on the fly, but
  141366. for now dumping the decode machine is needed
  141367. to reinit the MDCT lookups. 1.1 libvorbis
  141368. is planned to be able to switch on the fly */
  141369. for(i=0;i<vf->links;i++){
  141370. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141371. ov_halfrate(vf,0);
  141372. return OV_EINVAL;
  141373. }
  141374. }
  141375. return 0;
  141376. }
  141377. int ov_halfrate_p(OggVorbis_File *vf){
  141378. if(vf->vi==NULL)return OV_EINVAL;
  141379. return vorbis_synthesis_halfrate_p(vf->vi);
  141380. }
  141381. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141382. ov_callbacks callbacks)
  141383. {
  141384. return _ov_open1(f,vf,initial,ibytes,callbacks);
  141385. }
  141386. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141387. ov_callbacks callbacks = {
  141388. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141389. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141390. (int (*)(void *)) fclose,
  141391. (long (*)(void *)) ftell
  141392. };
  141393. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141394. }
  141395. int ov_test_open(OggVorbis_File *vf){
  141396. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141397. return _ov_open2(vf);
  141398. }
  141399. long ov_streams(OggVorbis_File *vf){
  141400. return vf->links;
  141401. }
  141402. long ov_seekable(OggVorbis_File *vf){
  141403. return vf->seekable;
  141404. }
  141405. long ov_bitrate(OggVorbis_File *vf,int i){
  141406. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141407. if(i>=vf->links)return(OV_EINVAL);
  141408. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141409. if(i<0){
  141410. ogg_int64_t bits=0;
  141411. int i;
  141412. float br;
  141413. for(i=0;i<vf->links;i++)
  141414. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141415. br = bits/ov_time_total(vf,-1);
  141416. return(rint(br));
  141417. }else{
  141418. if(vf->seekable){
  141419. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141420. }else{
  141421. if(vf->vi[i].bitrate_nominal>0){
  141422. return vf->vi[i].bitrate_nominal;
  141423. }else{
  141424. if(vf->vi[i].bitrate_upper>0){
  141425. if(vf->vi[i].bitrate_lower>0){
  141426. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141427. }else{
  141428. return vf->vi[i].bitrate_upper;
  141429. }
  141430. }
  141431. return(OV_FALSE);
  141432. }
  141433. }
  141434. }
  141435. }
  141436. long ov_bitrate_instant(OggVorbis_File *vf){
  141437. int link=(vf->seekable?vf->current_link:0);
  141438. long ret;
  141439. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141440. if(vf->samptrack==0)return(OV_FALSE);
  141441. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141442. vf->bittrack=0.f;
  141443. vf->samptrack=0.f;
  141444. return(ret);
  141445. }
  141446. long ov_serialnumber(OggVorbis_File *vf,int i){
  141447. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141448. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141449. if(i<0){
  141450. return(vf->current_serialno);
  141451. }else{
  141452. return(vf->serialnos[i]);
  141453. }
  141454. }
  141455. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141456. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141457. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141458. if(i<0){
  141459. ogg_int64_t acc=0;
  141460. int i;
  141461. for(i=0;i<vf->links;i++)
  141462. acc+=ov_raw_total(vf,i);
  141463. return(acc);
  141464. }else{
  141465. return(vf->offsets[i+1]-vf->offsets[i]);
  141466. }
  141467. }
  141468. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141469. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141470. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141471. if(i<0){
  141472. ogg_int64_t acc=0;
  141473. int i;
  141474. for(i=0;i<vf->links;i++)
  141475. acc+=ov_pcm_total(vf,i);
  141476. return(acc);
  141477. }else{
  141478. return(vf->pcmlengths[i*2+1]);
  141479. }
  141480. }
  141481. double ov_time_total(OggVorbis_File *vf,int i){
  141482. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141483. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141484. if(i<0){
  141485. double acc=0;
  141486. int i;
  141487. for(i=0;i<vf->links;i++)
  141488. acc+=ov_time_total(vf,i);
  141489. return(acc);
  141490. }else{
  141491. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141492. }
  141493. }
  141494. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141495. ogg_stream_state work_os;
  141496. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141497. if(!vf->seekable)
  141498. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141499. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141500. vf->pcm_offset=-1;
  141501. ogg_stream_reset_serialno(&vf->os,
  141502. vf->current_serialno); /* must set serialno */
  141503. vorbis_synthesis_restart(&vf->vd);
  141504. _seek_helper(vf,pos);
  141505. {
  141506. ogg_page og;
  141507. ogg_packet op;
  141508. int lastblock=0;
  141509. int accblock=0;
  141510. int thisblock;
  141511. int eosflag;
  141512. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141513. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141514. return from not necessarily
  141515. starting from the beginning */
  141516. while(1){
  141517. if(vf->ready_state>=STREAMSET){
  141518. int result=ogg_stream_packetout(&work_os,&op);
  141519. if(result>0){
  141520. if(vf->vi[vf->current_link].codec_setup){
  141521. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141522. if(thisblock<0){
  141523. ogg_stream_packetout(&vf->os,NULL);
  141524. thisblock=0;
  141525. }else{
  141526. if(eosflag)
  141527. ogg_stream_packetout(&vf->os,NULL);
  141528. else
  141529. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141530. }
  141531. if(op.granulepos!=-1){
  141532. int i,link=vf->current_link;
  141533. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141534. if(granulepos<0)granulepos=0;
  141535. for(i=0;i<link;i++)
  141536. granulepos+=vf->pcmlengths[i*2+1];
  141537. vf->pcm_offset=granulepos-accblock;
  141538. break;
  141539. }
  141540. lastblock=thisblock;
  141541. continue;
  141542. }else
  141543. ogg_stream_packetout(&vf->os,NULL);
  141544. }
  141545. }
  141546. if(!lastblock){
  141547. if(_get_next_page(vf,&og,-1)<0){
  141548. vf->pcm_offset=ov_pcm_total(vf,-1);
  141549. break;
  141550. }
  141551. }else{
  141552. vf->pcm_offset=-1;
  141553. break;
  141554. }
  141555. if(vf->ready_state>=STREAMSET)
  141556. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141557. _decode_clear(vf); /* clear out stream state */
  141558. ogg_stream_clear(&work_os);
  141559. }
  141560. if(vf->ready_state<STREAMSET){
  141561. int link;
  141562. vf->current_serialno=ogg_page_serialno(&og);
  141563. for(link=0;link<vf->links;link++)
  141564. if(vf->serialnos[link]==vf->current_serialno)break;
  141565. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141566. error out, leave
  141567. machine uninitialized */
  141568. vf->current_link=link;
  141569. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141570. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141571. vf->ready_state=STREAMSET;
  141572. }
  141573. ogg_stream_pagein(&vf->os,&og);
  141574. ogg_stream_pagein(&work_os,&og);
  141575. eosflag=ogg_page_eos(&og);
  141576. }
  141577. }
  141578. ogg_stream_clear(&work_os);
  141579. vf->bittrack=0.f;
  141580. vf->samptrack=0.f;
  141581. return(0);
  141582. seek_error:
  141583. vf->pcm_offset=-1;
  141584. ogg_stream_clear(&work_os);
  141585. _decode_clear(vf);
  141586. return OV_EBADLINK;
  141587. }
  141588. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141589. int link=-1;
  141590. ogg_int64_t result=0;
  141591. ogg_int64_t total=ov_pcm_total(vf,-1);
  141592. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141593. if(!vf->seekable)return(OV_ENOSEEK);
  141594. if(pos<0 || pos>total)return(OV_EINVAL);
  141595. for(link=vf->links-1;link>=0;link--){
  141596. total-=vf->pcmlengths[link*2+1];
  141597. if(pos>=total)break;
  141598. }
  141599. {
  141600. ogg_int64_t end=vf->offsets[link+1];
  141601. ogg_int64_t begin=vf->offsets[link];
  141602. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141603. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141604. ogg_int64_t target=pos-total+begintime;
  141605. ogg_int64_t best=begin;
  141606. ogg_page og;
  141607. while(begin<end){
  141608. ogg_int64_t bisect;
  141609. if(end-begin<CHUNKSIZE){
  141610. bisect=begin;
  141611. }else{
  141612. bisect=begin +
  141613. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141614. if(bisect<=begin)
  141615. bisect=begin+1;
  141616. }
  141617. _seek_helper(vf,bisect);
  141618. while(begin<end){
  141619. result=_get_next_page(vf,&og,end-vf->offset);
  141620. if(result==OV_EREAD) goto seek_error;
  141621. if(result<0){
  141622. if(bisect<=begin+1)
  141623. end=begin; /* found it */
  141624. else{
  141625. if(bisect==0) goto seek_error;
  141626. bisect-=CHUNKSIZE;
  141627. if(bisect<=begin)bisect=begin+1;
  141628. _seek_helper(vf,bisect);
  141629. }
  141630. }else{
  141631. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141632. if(granulepos==-1)continue;
  141633. if(granulepos<target){
  141634. best=result; /* raw offset of packet with granulepos */
  141635. begin=vf->offset; /* raw offset of next page */
  141636. begintime=granulepos;
  141637. if(target-begintime>44100)break;
  141638. bisect=begin; /* *not* begin + 1 */
  141639. }else{
  141640. if(bisect<=begin+1)
  141641. end=begin; /* found it */
  141642. else{
  141643. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141644. end=result;
  141645. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141646. if(bisect<=begin)bisect=begin+1;
  141647. _seek_helper(vf,bisect);
  141648. }else{
  141649. end=result;
  141650. endtime=granulepos;
  141651. break;
  141652. }
  141653. }
  141654. }
  141655. }
  141656. }
  141657. }
  141658. {
  141659. ogg_page og;
  141660. ogg_packet op;
  141661. _seek_helper(vf,best);
  141662. vf->pcm_offset=-1;
  141663. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141664. if(link!=vf->current_link){
  141665. _decode_clear(vf);
  141666. vf->current_link=link;
  141667. vf->current_serialno=ogg_page_serialno(&og);
  141668. vf->ready_state=STREAMSET;
  141669. }else{
  141670. vorbis_synthesis_restart(&vf->vd);
  141671. }
  141672. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141673. ogg_stream_pagein(&vf->os,&og);
  141674. while(1){
  141675. result=ogg_stream_packetpeek(&vf->os,&op);
  141676. if(result==0){
  141677. _seek_helper(vf,best);
  141678. while(1){
  141679. result=_get_prev_page(vf,&og);
  141680. if(result<0) goto seek_error;
  141681. if(ogg_page_granulepos(&og)>-1 ||
  141682. !ogg_page_continued(&og)){
  141683. return ov_raw_seek(vf,result);
  141684. }
  141685. vf->offset=result;
  141686. }
  141687. }
  141688. if(result<0){
  141689. result = OV_EBADPACKET;
  141690. goto seek_error;
  141691. }
  141692. if(op.granulepos!=-1){
  141693. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141694. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141695. vf->pcm_offset+=total;
  141696. break;
  141697. }else
  141698. result=ogg_stream_packetout(&vf->os,NULL);
  141699. }
  141700. }
  141701. }
  141702. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  141703. result=OV_EFAULT;
  141704. goto seek_error;
  141705. }
  141706. vf->bittrack=0.f;
  141707. vf->samptrack=0.f;
  141708. return(0);
  141709. seek_error:
  141710. vf->pcm_offset=-1;
  141711. _decode_clear(vf);
  141712. return (int)result;
  141713. }
  141714. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141715. int thisblock,lastblock=0;
  141716. int ret=ov_pcm_seek_page(vf,pos);
  141717. if(ret<0)return(ret);
  141718. if((ret=_make_decode_ready(vf)))return ret;
  141719. while(1){
  141720. ogg_packet op;
  141721. ogg_page og;
  141722. int ret=ogg_stream_packetpeek(&vf->os,&op);
  141723. if(ret>0){
  141724. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141725. if(thisblock<0){
  141726. ogg_stream_packetout(&vf->os,NULL);
  141727. continue; /* non audio packet */
  141728. }
  141729. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  141730. if(vf->pcm_offset+((thisblock+
  141731. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  141732. ogg_stream_packetout(&vf->os,NULL);
  141733. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  141734. only tracking, no
  141735. pcm_decode */
  141736. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141737. if(op.granulepos>-1){
  141738. int i;
  141739. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141740. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141741. for(i=0;i<vf->current_link;i++)
  141742. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  141743. }
  141744. lastblock=thisblock;
  141745. }else{
  141746. if(ret<0 && ret!=OV_HOLE)break;
  141747. if(_get_next_page(vf,&og,-1)<0)break;
  141748. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  141749. if(vf->ready_state<STREAMSET){
  141750. int link;
  141751. vf->current_serialno=ogg_page_serialno(&og);
  141752. for(link=0;link<vf->links;link++)
  141753. if(vf->serialnos[link]==vf->current_serialno)break;
  141754. if(link==vf->links)return(OV_EBADLINK);
  141755. vf->current_link=link;
  141756. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141757. vf->ready_state=STREAMSET;
  141758. ret=_make_decode_ready(vf);
  141759. if(ret)return ret;
  141760. lastblock=0;
  141761. }
  141762. ogg_stream_pagein(&vf->os,&og);
  141763. }
  141764. }
  141765. vf->bittrack=0.f;
  141766. vf->samptrack=0.f;
  141767. while(vf->pcm_offset<pos){
  141768. ogg_int64_t target=pos-vf->pcm_offset;
  141769. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141770. if(samples>target)samples=target;
  141771. vorbis_synthesis_read(&vf->vd,samples);
  141772. vf->pcm_offset+=samples;
  141773. if(samples<target)
  141774. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  141775. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  141776. }
  141777. return 0;
  141778. }
  141779. int ov_time_seek(OggVorbis_File *vf,double seconds){
  141780. int link=-1;
  141781. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141782. double time_total=ov_time_total(vf,-1);
  141783. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141784. if(!vf->seekable)return(OV_ENOSEEK);
  141785. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141786. for(link=vf->links-1;link>=0;link--){
  141787. pcm_total-=vf->pcmlengths[link*2+1];
  141788. time_total-=ov_time_total(vf,link);
  141789. if(seconds>=time_total)break;
  141790. }
  141791. {
  141792. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141793. return(ov_pcm_seek(vf,target));
  141794. }
  141795. }
  141796. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  141797. int link=-1;
  141798. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141799. double time_total=ov_time_total(vf,-1);
  141800. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141801. if(!vf->seekable)return(OV_ENOSEEK);
  141802. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141803. for(link=vf->links-1;link>=0;link--){
  141804. pcm_total-=vf->pcmlengths[link*2+1];
  141805. time_total-=ov_time_total(vf,link);
  141806. if(seconds>=time_total)break;
  141807. }
  141808. {
  141809. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141810. return(ov_pcm_seek_page(vf,target));
  141811. }
  141812. }
  141813. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  141814. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141815. return(vf->offset);
  141816. }
  141817. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  141818. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141819. return(vf->pcm_offset);
  141820. }
  141821. double ov_time_tell(OggVorbis_File *vf){
  141822. int link=0;
  141823. ogg_int64_t pcm_total=0;
  141824. double time_total=0.f;
  141825. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141826. if(vf->seekable){
  141827. pcm_total=ov_pcm_total(vf,-1);
  141828. time_total=ov_time_total(vf,-1);
  141829. for(link=vf->links-1;link>=0;link--){
  141830. pcm_total-=vf->pcmlengths[link*2+1];
  141831. time_total-=ov_time_total(vf,link);
  141832. if(vf->pcm_offset>=pcm_total)break;
  141833. }
  141834. }
  141835. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  141836. }
  141837. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  141838. if(vf->seekable){
  141839. if(link<0)
  141840. if(vf->ready_state>=STREAMSET)
  141841. return vf->vi+vf->current_link;
  141842. else
  141843. return vf->vi;
  141844. else
  141845. if(link>=vf->links)
  141846. return NULL;
  141847. else
  141848. return vf->vi+link;
  141849. }else{
  141850. return vf->vi;
  141851. }
  141852. }
  141853. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  141854. if(vf->seekable){
  141855. if(link<0)
  141856. if(vf->ready_state>=STREAMSET)
  141857. return vf->vc+vf->current_link;
  141858. else
  141859. return vf->vc;
  141860. else
  141861. if(link>=vf->links)
  141862. return NULL;
  141863. else
  141864. return vf->vc+link;
  141865. }else{
  141866. return vf->vc;
  141867. }
  141868. }
  141869. static int host_is_big_endian() {
  141870. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  141871. unsigned char *bytewise = (unsigned char *)&pattern;
  141872. if (bytewise[0] == 0xfe) return 1;
  141873. return 0;
  141874. }
  141875. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  141876. int bigendianp,int word,int sgned,int *bitstream){
  141877. int i,j;
  141878. int host_endian = host_is_big_endian();
  141879. float **pcm;
  141880. long samples;
  141881. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141882. while(1){
  141883. if(vf->ready_state==INITSET){
  141884. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141885. if(samples)break;
  141886. }
  141887. {
  141888. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141889. if(ret==OV_EOF)
  141890. return(0);
  141891. if(ret<=0)
  141892. return(ret);
  141893. }
  141894. }
  141895. if(samples>0){
  141896. long channels=ov_info(vf,-1)->channels;
  141897. long bytespersample=word * channels;
  141898. vorbis_fpu_control fpu;
  141899. (void) fpu; // (to avoid a warning about it being unused)
  141900. if(samples>length/bytespersample)samples=length/bytespersample;
  141901. if(samples <= 0)
  141902. return OV_EINVAL;
  141903. {
  141904. int val;
  141905. if(word==1){
  141906. int off=(sgned?0:128);
  141907. vorbis_fpu_setround(&fpu);
  141908. for(j=0;j<samples;j++)
  141909. for(i=0;i<channels;i++){
  141910. val=vorbis_ftoi(pcm[i][j]*128.f);
  141911. if(val>127)val=127;
  141912. else if(val<-128)val=-128;
  141913. *buffer++=val+off;
  141914. }
  141915. vorbis_fpu_restore(fpu);
  141916. }else{
  141917. int off=(sgned?0:32768);
  141918. if(host_endian==bigendianp){
  141919. if(sgned){
  141920. vorbis_fpu_setround(&fpu);
  141921. for(i=0;i<channels;i++) { /* It's faster in this order */
  141922. float *src=pcm[i];
  141923. short *dest=((short *)buffer)+i;
  141924. for(j=0;j<samples;j++) {
  141925. val=vorbis_ftoi(src[j]*32768.f);
  141926. if(val>32767)val=32767;
  141927. else if(val<-32768)val=-32768;
  141928. *dest=val;
  141929. dest+=channels;
  141930. }
  141931. }
  141932. vorbis_fpu_restore(fpu);
  141933. }else{
  141934. vorbis_fpu_setround(&fpu);
  141935. for(i=0;i<channels;i++) {
  141936. float *src=pcm[i];
  141937. short *dest=((short *)buffer)+i;
  141938. for(j=0;j<samples;j++) {
  141939. val=vorbis_ftoi(src[j]*32768.f);
  141940. if(val>32767)val=32767;
  141941. else if(val<-32768)val=-32768;
  141942. *dest=val+off;
  141943. dest+=channels;
  141944. }
  141945. }
  141946. vorbis_fpu_restore(fpu);
  141947. }
  141948. }else if(bigendianp){
  141949. vorbis_fpu_setround(&fpu);
  141950. for(j=0;j<samples;j++)
  141951. for(i=0;i<channels;i++){
  141952. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141953. if(val>32767)val=32767;
  141954. else if(val<-32768)val=-32768;
  141955. val+=off;
  141956. *buffer++=(val>>8);
  141957. *buffer++=(val&0xff);
  141958. }
  141959. vorbis_fpu_restore(fpu);
  141960. }else{
  141961. int val;
  141962. vorbis_fpu_setround(&fpu);
  141963. for(j=0;j<samples;j++)
  141964. for(i=0;i<channels;i++){
  141965. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141966. if(val>32767)val=32767;
  141967. else if(val<-32768)val=-32768;
  141968. val+=off;
  141969. *buffer++=(val&0xff);
  141970. *buffer++=(val>>8);
  141971. }
  141972. vorbis_fpu_restore(fpu);
  141973. }
  141974. }
  141975. }
  141976. vorbis_synthesis_read(&vf->vd,samples);
  141977. vf->pcm_offset+=samples;
  141978. if(bitstream)*bitstream=vf->current_link;
  141979. return(samples*bytespersample);
  141980. }else{
  141981. return(samples);
  141982. }
  141983. }
  141984. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  141985. int *bitstream){
  141986. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141987. while(1){
  141988. if(vf->ready_state==INITSET){
  141989. float **pcm;
  141990. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141991. if(samples){
  141992. if(pcm_channels)*pcm_channels=pcm;
  141993. if(samples>length)samples=length;
  141994. vorbis_synthesis_read(&vf->vd,samples);
  141995. vf->pcm_offset+=samples;
  141996. if(bitstream)*bitstream=vf->current_link;
  141997. return samples;
  141998. }
  141999. }
  142000. {
  142001. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142002. if(ret==OV_EOF)return(0);
  142003. if(ret<=0)return(ret);
  142004. }
  142005. }
  142006. }
  142007. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  142008. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  142009. ogg_int64_t off);
  142010. static void _ov_splice(float **pcm,float **lappcm,
  142011. int n1, int n2,
  142012. int ch1, int ch2,
  142013. float *w1, float *w2){
  142014. int i,j;
  142015. float *w=w1;
  142016. int n=n1;
  142017. if(n1>n2){
  142018. n=n2;
  142019. w=w2;
  142020. }
  142021. for(j=0;j<ch1 && j<ch2;j++){
  142022. float *s=lappcm[j];
  142023. float *d=pcm[j];
  142024. for(i=0;i<n;i++){
  142025. float wd=w[i]*w[i];
  142026. float ws=1.-wd;
  142027. d[i]=d[i]*wd + s[i]*ws;
  142028. }
  142029. }
  142030. for(;j<ch2;j++){
  142031. float *d=pcm[j];
  142032. for(i=0;i<n;i++){
  142033. float wd=w[i]*w[i];
  142034. d[i]=d[i]*wd;
  142035. }
  142036. }
  142037. }
  142038. static int _ov_initset(OggVorbis_File *vf){
  142039. while(1){
  142040. if(vf->ready_state==INITSET)break;
  142041. {
  142042. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142043. if(ret<0 && ret!=OV_HOLE)return(ret);
  142044. }
  142045. }
  142046. return 0;
  142047. }
  142048. static int _ov_initprime(OggVorbis_File *vf){
  142049. vorbis_dsp_state *vd=&vf->vd;
  142050. while(1){
  142051. if(vf->ready_state==INITSET)
  142052. if(vorbis_synthesis_pcmout(vd,NULL))break;
  142053. {
  142054. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142055. if(ret<0 && ret!=OV_HOLE)return(ret);
  142056. }
  142057. }
  142058. return 0;
  142059. }
  142060. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  142061. float **lappcm,int lapsize){
  142062. int lapcount=0,i;
  142063. float **pcm;
  142064. while(lapcount<lapsize){
  142065. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  142066. if(samples){
  142067. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142068. for(i=0;i<vi->channels;i++)
  142069. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142070. lapcount+=samples;
  142071. vorbis_synthesis_read(vd,samples);
  142072. }else{
  142073. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  142074. if(ret==OV_EOF)break;
  142075. }
  142076. }
  142077. if(lapcount<lapsize){
  142078. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  142079. if(samples==0){
  142080. for(i=0;i<vi->channels;i++)
  142081. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  142082. lapcount=lapsize;
  142083. }else{
  142084. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142085. for(i=0;i<vi->channels;i++)
  142086. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142087. lapcount+=samples;
  142088. }
  142089. }
  142090. }
  142091. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  142092. vorbis_info *vi1,*vi2;
  142093. float **lappcm;
  142094. float **pcm;
  142095. float *w1,*w2;
  142096. int n1,n2,i,ret,hs1,hs2;
  142097. if(vf1==vf2)return(0); /* degenerate case */
  142098. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  142099. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  142100. ret=_ov_initset(vf1);
  142101. if(ret)return(ret);
  142102. ret=_ov_initprime(vf2);
  142103. if(ret)return(ret);
  142104. vi1=ov_info(vf1,-1);
  142105. vi2=ov_info(vf2,-1);
  142106. hs1=ov_halfrate_p(vf1);
  142107. hs2=ov_halfrate_p(vf2);
  142108. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  142109. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  142110. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  142111. w1=vorbis_window(&vf1->vd,0);
  142112. w2=vorbis_window(&vf2->vd,0);
  142113. for(i=0;i<vi1->channels;i++)
  142114. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142115. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  142116. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  142117. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  142118. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  142119. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  142120. return(0);
  142121. }
  142122. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  142123. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  142124. vorbis_info *vi;
  142125. float **lappcm;
  142126. float **pcm;
  142127. float *w1,*w2;
  142128. int n1,n2,ch1,ch2,hs;
  142129. int i,ret;
  142130. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142131. ret=_ov_initset(vf);
  142132. if(ret)return(ret);
  142133. vi=ov_info(vf,-1);
  142134. hs=ov_halfrate_p(vf);
  142135. ch1=vi->channels;
  142136. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142137. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142138. persistent; even if the decode state
  142139. from this link gets dumped, this
  142140. window array continues to exist */
  142141. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142142. for(i=0;i<ch1;i++)
  142143. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142144. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142145. ret=localseek(vf,pos);
  142146. if(ret)return ret;
  142147. ret=_ov_initprime(vf);
  142148. if(ret)return(ret);
  142149. vi=ov_info(vf,-1);
  142150. ch2=vi->channels;
  142151. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142152. w2=vorbis_window(&vf->vd,0);
  142153. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142154. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142155. return(0);
  142156. }
  142157. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142158. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  142159. }
  142160. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142161. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  142162. }
  142163. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142164. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  142165. }
  142166. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  142167. int (*localseek)(OggVorbis_File *,double)){
  142168. vorbis_info *vi;
  142169. float **lappcm;
  142170. float **pcm;
  142171. float *w1,*w2;
  142172. int n1,n2,ch1,ch2,hs;
  142173. int i,ret;
  142174. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142175. ret=_ov_initset(vf);
  142176. if(ret)return(ret);
  142177. vi=ov_info(vf,-1);
  142178. hs=ov_halfrate_p(vf);
  142179. ch1=vi->channels;
  142180. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142181. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142182. persistent; even if the decode state
  142183. from this link gets dumped, this
  142184. window array continues to exist */
  142185. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142186. for(i=0;i<ch1;i++)
  142187. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142188. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142189. ret=localseek(vf,pos);
  142190. if(ret)return ret;
  142191. ret=_ov_initprime(vf);
  142192. if(ret)return(ret);
  142193. vi=ov_info(vf,-1);
  142194. ch2=vi->channels;
  142195. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142196. w2=vorbis_window(&vf->vd,0);
  142197. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142198. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142199. return(0);
  142200. }
  142201. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  142202. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  142203. }
  142204. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  142205. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  142206. }
  142207. #endif
  142208. /*** End of inlined file: vorbisfile.c ***/
  142209. /*** Start of inlined file: window.c ***/
  142210. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  142211. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  142212. // tasks..
  142213. #if JUCE_MSVC
  142214. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  142215. #endif
  142216. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  142217. #if JUCE_USE_OGGVORBIS
  142218. #include <stdlib.h>
  142219. #include <math.h>
  142220. static float vwin64[32] = {
  142221. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  142222. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  142223. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  142224. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  142225. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  142226. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  142227. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  142228. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  142229. };
  142230. static float vwin128[64] = {
  142231. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  142232. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  142233. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  142234. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  142235. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  142236. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  142237. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  142238. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  142239. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  142240. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  142241. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  142242. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  142243. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  142244. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  142245. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  142246. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  142247. };
  142248. static float vwin256[128] = {
  142249. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  142250. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  142251. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  142252. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  142253. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  142254. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  142255. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  142256. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  142257. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  142258. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  142259. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  142260. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  142261. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  142262. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  142263. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  142264. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  142265. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  142266. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  142267. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  142268. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  142269. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  142270. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  142271. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  142272. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  142273. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  142274. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  142275. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  142276. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  142277. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  142278. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  142279. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  142280. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  142281. };
  142282. static float vwin512[256] = {
  142283. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142284. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142285. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142286. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142287. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142288. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142289. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142290. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142291. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142292. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142293. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142294. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142295. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142296. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142297. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142298. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142299. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142300. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142301. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142302. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142303. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142304. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142305. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142306. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142307. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142308. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142309. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142310. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142311. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142312. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142313. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142314. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142315. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142316. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142317. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142318. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142319. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142320. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142321. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142322. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142323. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142324. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142325. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142326. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142327. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142328. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142329. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142330. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142331. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142332. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142333. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142334. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142335. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142336. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142337. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142338. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142339. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142340. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142341. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142342. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142343. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142344. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142345. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142346. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142347. };
  142348. static float vwin1024[512] = {
  142349. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142350. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142351. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142352. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142353. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142354. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142355. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142356. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142357. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142358. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142359. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142360. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142361. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142362. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142363. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142364. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142365. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142366. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142367. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142368. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142369. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142370. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142371. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142372. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142373. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142374. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142375. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  142376. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  142377. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  142378. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  142379. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  142380. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  142381. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  142382. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  142383. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  142384. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  142385. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  142386. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  142387. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  142388. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  142389. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  142390. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  142391. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  142392. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  142393. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  142394. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142395. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142396. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142397. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142398. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142399. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142400. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142401. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142402. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142403. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142404. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142405. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142406. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142407. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142408. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142409. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142410. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142411. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142412. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142413. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142414. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142415. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142416. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142417. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142418. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142419. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142420. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142421. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142422. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142423. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142424. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142425. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142426. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142427. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142428. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142429. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142430. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142431. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142432. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142433. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142434. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142435. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142436. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142437. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142438. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142439. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142440. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142441. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142442. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142443. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142444. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142445. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142446. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142447. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142448. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142449. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142450. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142451. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142452. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142453. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142454. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142455. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142456. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142457. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142458. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142459. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142460. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142461. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142462. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142463. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142464. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142465. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142466. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142467. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142468. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142469. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142470. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142471. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142472. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142473. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142474. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142475. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142476. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142477. };
  142478. static float vwin2048[1024] = {
  142479. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142480. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142481. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142482. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142483. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142484. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142485. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142486. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142487. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142488. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142489. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142490. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142491. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142492. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142493. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142494. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142495. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142496. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142497. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142498. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142499. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142500. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142501. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142502. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142503. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142504. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142505. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142506. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142507. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142508. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142509. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142510. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142511. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142512. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142513. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142514. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142515. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142516. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142517. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142518. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142519. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142520. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142521. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142522. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142523. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142524. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142525. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142526. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142527. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142528. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142529. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142530. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142531. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142532. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142533. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142534. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142535. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142536. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142537. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142538. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142539. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142540. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142541. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142542. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142543. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142544. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142545. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142546. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142547. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142548. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142549. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142550. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142551. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142552. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142553. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142554. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142555. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142556. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142557. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142558. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142559. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142560. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142561. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142562. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142563. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142564. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142565. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142566. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142567. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142568. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142569. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142570. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142571. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142572. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142573. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142574. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142575. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142576. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142577. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142578. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142579. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142580. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142581. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142582. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142583. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142584. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142585. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142586. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142587. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142588. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142589. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142590. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142591. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142592. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142593. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142594. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142595. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142596. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142597. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142598. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142599. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142600. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142601. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142602. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142603. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142604. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142605. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142606. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142607. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142608. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142609. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142610. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142611. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142612. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142613. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142614. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142615. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142616. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142617. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142618. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142619. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142620. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142621. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142622. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142623. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142624. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142625. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142626. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142627. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142628. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142629. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142630. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142631. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142632. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142633. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142634. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142635. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142636. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142637. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142638. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142639. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142640. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142641. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142642. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142643. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142644. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142645. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142646. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142647. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142648. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142649. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142650. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142651. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142652. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142653. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142654. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142655. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142656. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142657. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142658. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142659. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142660. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142661. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142662. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142663. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142664. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142665. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142666. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142667. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142668. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142669. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142670. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  142671. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  142672. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  142673. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  142674. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  142675. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  142676. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  142677. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  142678. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  142679. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  142680. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  142681. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  142682. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  142683. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  142684. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  142685. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  142686. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  142687. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  142688. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  142689. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  142690. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  142691. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  142692. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  142693. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  142694. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  142695. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  142696. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  142697. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  142698. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  142699. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  142700. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  142701. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  142702. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  142703. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  142704. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  142705. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  142706. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  142707. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  142708. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  142709. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  142710. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  142711. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  142712. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  142713. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  142714. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  142715. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  142716. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  142717. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  142718. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  142719. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  142720. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  142721. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  142722. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  142723. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  142724. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  142725. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  142726. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  142727. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  142728. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  142729. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  142730. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  142731. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  142732. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  142733. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  142734. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  142735. };
  142736. static float vwin4096[2048] = {
  142737. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  142738. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  142739. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  142740. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  142741. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  142742. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  142743. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  142744. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  142745. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  142746. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  142747. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  142748. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  142749. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  142750. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  142751. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  142752. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  142753. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  142754. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  142755. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  142756. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  142757. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  142758. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  142759. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  142760. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  142761. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  142762. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  142763. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  142764. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  142765. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  142766. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  142767. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  142768. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  142769. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  142770. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  142771. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  142772. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  142773. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  142774. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  142775. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  142776. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  142777. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  142778. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  142779. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  142780. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  142781. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  142782. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  142783. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  142784. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  142785. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  142786. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  142787. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  142788. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  142789. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  142790. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  142791. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  142792. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  142793. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  142794. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  142795. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  142796. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  142797. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  142798. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  142799. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  142800. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  142801. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  142802. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  142803. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  142804. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  142805. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  142806. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  142807. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  142808. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  142809. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  142810. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  142811. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  142812. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  142813. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  142814. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  142815. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  142816. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  142817. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  142818. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  142819. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  142820. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  142821. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  142822. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  142823. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  142824. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  142825. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  142826. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  142827. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  142828. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  142829. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  142830. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  142831. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  142832. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  142833. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  142834. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  142835. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  142836. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  142837. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  142838. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  142839. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  142840. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  142841. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  142842. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  142843. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  142844. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  142845. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  142846. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  142847. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  142848. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  142849. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  142850. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  142851. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  142852. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  142853. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  142854. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  142855. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  142856. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  142857. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  142858. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  142859. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  142860. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  142861. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  142862. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  142863. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  142864. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  142865. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  142866. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  142867. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  142868. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  142869. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  142870. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  142871. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  142872. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  142873. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  142874. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  142875. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  142876. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  142877. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  142878. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  142879. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  142880. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  142881. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  142882. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  142883. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  142884. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  142885. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  142886. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  142887. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  142888. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  142889. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  142890. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  142891. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  142892. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  142893. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  142894. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  142895. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  142896. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  142897. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  142898. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  142899. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  142900. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  142901. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  142902. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  142903. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  142904. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  142905. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  142906. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  142907. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  142908. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  142909. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  142910. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  142911. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  142912. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  142913. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  142914. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  142915. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  142916. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  142917. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  142918. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  142919. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  142920. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  142921. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  142922. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  142923. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  142924. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  142925. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  142926. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  142927. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  142928. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  142929. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  142930. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  142931. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  142932. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  142933. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  142934. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  142935. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  142936. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  142937. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  142938. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  142939. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  142940. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  142941. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  142942. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  142943. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  142944. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  142945. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  142946. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  142947. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  142948. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  142949. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  142950. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  142951. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  142952. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  142953. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  142954. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  142955. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  142956. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  142957. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  142958. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  142959. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  142960. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  142961. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  142962. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  142963. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  142964. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  142965. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  142966. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  142967. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  142968. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  142969. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  142970. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  142971. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  142972. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  142973. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  142974. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  142975. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  142976. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  142977. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  142978. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  142979. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  142980. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  142981. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  142982. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  142983. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  142984. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  142985. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  142986. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  142987. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  142988. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  142989. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  142990. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  142991. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  142992. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  142993. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  142994. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  142995. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  142996. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  142997. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  142998. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  142999. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  143000. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  143001. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  143002. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  143003. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  143004. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  143005. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  143006. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  143007. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  143008. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  143009. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  143010. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  143011. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  143012. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  143013. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  143014. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  143015. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  143016. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  143017. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  143018. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  143019. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  143020. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  143021. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  143022. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  143023. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  143024. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  143025. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  143026. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  143027. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  143028. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  143029. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  143030. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  143031. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  143032. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  143033. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  143034. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  143035. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  143036. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  143037. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  143038. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  143039. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  143040. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  143041. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  143042. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  143043. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  143044. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  143045. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  143046. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  143047. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  143048. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  143049. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  143050. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  143051. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  143052. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  143053. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  143054. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  143055. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  143056. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  143057. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  143058. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  143059. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  143060. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  143061. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  143062. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  143063. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  143064. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  143065. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  143066. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  143067. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  143068. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  143069. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  143070. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  143071. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  143072. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  143073. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  143074. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  143075. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  143076. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  143077. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  143078. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  143079. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  143080. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  143081. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  143082. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  143083. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  143084. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  143085. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  143086. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  143087. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  143088. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  143089. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  143090. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  143091. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  143092. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  143093. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  143094. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  143095. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  143096. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  143097. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  143098. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  143099. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  143100. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  143101. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  143102. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  143103. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  143104. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  143105. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  143106. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  143107. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  143108. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  143109. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  143110. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  143111. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  143112. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  143113. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  143114. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  143115. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  143116. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  143117. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  143118. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  143119. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  143120. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  143121. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  143122. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  143123. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  143124. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  143125. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  143126. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  143127. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  143128. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  143129. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  143130. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  143131. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  143132. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  143133. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  143134. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  143135. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  143136. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  143137. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  143138. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  143139. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  143140. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  143141. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  143142. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  143143. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  143144. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  143145. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  143146. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  143147. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  143148. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  143149. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  143150. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  143151. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  143152. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  143153. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  143154. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  143155. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  143156. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  143157. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  143158. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  143159. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  143160. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  143161. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  143162. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  143163. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  143164. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  143165. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  143166. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  143167. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  143168. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  143169. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  143170. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  143171. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  143172. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  143173. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  143174. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  143175. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  143176. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  143177. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  143178. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  143179. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  143180. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  143181. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  143182. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  143183. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  143184. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  143185. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  143186. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  143187. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  143188. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  143189. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  143190. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  143191. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  143192. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  143193. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  143194. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  143195. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  143196. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  143197. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  143198. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  143199. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  143200. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  143201. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  143202. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  143203. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  143204. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  143205. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  143206. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  143207. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  143208. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  143209. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  143210. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  143211. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  143212. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  143213. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  143214. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  143215. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  143216. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  143217. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  143218. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  143219. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  143220. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  143221. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  143222. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  143223. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  143224. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  143225. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  143226. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  143227. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  143228. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  143229. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  143230. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  143231. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  143232. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  143233. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  143234. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  143235. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  143236. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  143237. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  143238. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  143239. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  143240. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  143241. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  143242. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  143243. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  143244. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  143245. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  143246. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  143247. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  143248. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143249. };
  143250. static float vwin8192[4096] = {
  143251. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  143252. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  143253. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  143254. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  143255. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  143256. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  143257. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  143258. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  143259. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  143260. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  143261. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  143262. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  143263. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  143264. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  143265. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  143266. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  143267. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  143268. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  143269. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  143270. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  143271. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  143272. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  143273. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  143274. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  143275. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  143276. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  143277. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  143278. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  143279. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  143280. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  143281. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  143282. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  143283. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143284. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143285. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143286. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143287. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143288. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143289. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143290. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143291. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143292. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143293. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143294. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143295. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143296. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143297. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143298. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143299. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143300. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143301. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143302. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143303. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143304. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143305. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143306. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143307. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143308. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143309. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143310. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143311. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143312. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143313. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143314. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143315. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143316. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143317. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143318. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143319. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143320. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143321. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143322. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143323. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143324. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143325. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143326. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143327. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143328. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143329. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143330. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143331. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143332. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143333. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143334. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143335. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143336. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143337. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143338. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143339. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143340. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143341. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143342. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143343. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143344. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143345. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143346. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143347. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143348. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143349. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143350. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143351. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143352. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143353. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143354. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143355. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143356. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143357. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143358. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143359. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143360. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143361. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143362. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143363. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143364. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143365. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143366. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143367. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143368. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143369. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143370. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143371. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143372. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143373. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143374. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143375. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  143376. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  143377. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  143378. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  143379. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  143380. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  143381. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  143382. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  143383. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  143384. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  143385. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  143386. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  143387. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  143388. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  143389. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  143390. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  143391. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  143392. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  143393. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  143394. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143395. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143396. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143397. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143398. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143399. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143400. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143401. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143402. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143403. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143404. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143405. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143406. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143407. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143408. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143409. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143410. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143411. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143412. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143413. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143414. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143415. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143416. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143417. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143418. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143419. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143420. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143421. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143422. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143423. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143424. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143425. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143426. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143427. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143428. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143429. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143430. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143431. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143432. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143433. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143434. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143435. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143436. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143437. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143438. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143439. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143440. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143441. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143442. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143443. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143444. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143445. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143446. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143447. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143448. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143449. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143450. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143451. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143452. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143453. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143454. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143455. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143456. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143457. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143458. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143459. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143460. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143461. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143462. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143463. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143464. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143465. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143466. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143467. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143468. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143469. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143470. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143471. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143472. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143473. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143474. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143475. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143476. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143477. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143478. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143479. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143480. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143481. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143482. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143483. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143484. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143485. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143486. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143487. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143488. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143489. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143490. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143491. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143492. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143493. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143494. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143495. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143496. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143497. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143498. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143499. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143500. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143501. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143502. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143503. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143504. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143505. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143506. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143507. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143508. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143509. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143510. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143511. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143512. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143513. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143514. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143515. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143516. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143517. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143518. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143519. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143520. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143521. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143522. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143523. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143524. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143525. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143526. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143527. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143528. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143529. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143530. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143531. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143532. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143533. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143534. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143535. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143536. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143537. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143538. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143539. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143540. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143541. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143542. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143543. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143544. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143545. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143546. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143547. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143548. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143549. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143550. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143551. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143552. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143553. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143554. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143555. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143556. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143557. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143558. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143559. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143560. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143561. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143562. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143563. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143564. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143565. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143566. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143567. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143568. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143569. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143570. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143571. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143572. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143573. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143574. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143575. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143576. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143577. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143578. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143579. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143580. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143581. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143582. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143583. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143584. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143585. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143586. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143587. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143588. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143589. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143590. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143591. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143592. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143593. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143594. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143595. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143596. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143597. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143598. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143599. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143600. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143601. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143602. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143603. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143604. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143605. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143606. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143607. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143608. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143609. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143610. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143611. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143612. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143613. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143614. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143615. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143616. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143617. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143618. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143619. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143620. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143621. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143622. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143623. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143624. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143625. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143626. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143627. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143628. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143629. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143630. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143631. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143632. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143633. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143634. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143635. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143636. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143637. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143638. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143639. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143640. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143641. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143642. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143643. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143644. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143645. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143646. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143647. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143648. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143649. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143650. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143651. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143652. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143653. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143654. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143655. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143656. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143657. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143658. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143659. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143660. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143661. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143662. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143663. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143664. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143665. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143666. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143667. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143668. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143669. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143670. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  143671. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  143672. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  143673. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  143674. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  143675. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  143676. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  143677. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  143678. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  143679. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  143680. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  143681. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  143682. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  143683. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  143684. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  143685. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  143686. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  143687. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  143688. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  143689. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  143690. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  143691. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  143692. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  143693. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  143694. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  143695. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  143696. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  143697. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  143698. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  143699. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  143700. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  143701. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  143702. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  143703. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  143704. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  143705. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  143706. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  143707. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  143708. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  143709. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  143710. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  143711. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  143712. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  143713. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  143714. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  143715. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  143716. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  143717. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  143718. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  143719. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  143720. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  143721. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  143722. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  143723. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  143724. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  143725. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  143726. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  143727. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  143728. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  143729. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  143730. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  143731. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  143732. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  143733. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  143734. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  143735. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  143736. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  143737. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  143738. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  143739. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  143740. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  143741. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  143742. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  143743. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  143744. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  143745. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  143746. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  143747. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  143748. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  143749. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  143750. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  143751. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  143752. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  143753. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  143754. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  143755. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  143756. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  143757. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  143758. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  143759. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  143760. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  143761. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  143762. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  143763. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  143764. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  143765. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  143766. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  143767. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  143768. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  143769. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  143770. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  143771. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  143772. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  143773. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  143774. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  143775. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  143776. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  143777. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  143778. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  143779. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  143780. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  143781. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  143782. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  143783. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  143784. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  143785. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  143786. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  143787. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  143788. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  143789. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  143790. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  143791. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  143792. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  143793. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  143794. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  143795. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  143796. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  143797. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  143798. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  143799. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  143800. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  143801. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  143802. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  143803. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  143804. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  143805. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  143806. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  143807. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  143808. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  143809. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  143810. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  143811. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  143812. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  143813. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  143814. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  143815. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  143816. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  143817. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  143818. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  143819. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  143820. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  143821. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  143822. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  143823. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  143824. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  143825. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  143826. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  143827. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  143828. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  143829. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  143830. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  143831. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  143832. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  143833. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  143834. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  143835. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  143836. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  143837. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  143838. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  143839. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  143840. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  143841. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  143842. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  143843. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  143844. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  143845. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  143846. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  143847. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  143848. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  143849. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  143850. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  143851. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  143852. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  143853. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  143854. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  143855. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  143856. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  143857. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  143858. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  143859. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  143860. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  143861. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  143862. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  143863. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  143864. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  143865. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  143866. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  143867. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  143868. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  143869. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  143870. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  143871. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  143872. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  143873. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  143874. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  143875. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  143876. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  143877. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  143878. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  143879. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  143880. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  143881. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  143882. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  143883. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  143884. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  143885. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  143886. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  143887. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  143888. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  143889. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  143890. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  143891. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  143892. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  143893. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  143894. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  143895. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  143896. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  143897. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  143898. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  143899. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  143900. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  143901. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  143902. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  143903. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  143904. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  143905. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  143906. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  143907. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  143908. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  143909. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  143910. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  143911. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  143912. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  143913. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  143914. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  143915. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  143916. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  143917. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  143918. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  143919. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  143920. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  143921. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  143922. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  143923. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  143924. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  143925. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  143926. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  143927. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  143928. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  143929. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  143930. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  143931. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  143932. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  143933. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  143934. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  143935. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  143936. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  143937. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  143938. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  143939. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  143940. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  143941. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  143942. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  143943. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  143944. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  143945. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  143946. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  143947. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  143948. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  143949. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  143950. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  143951. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  143952. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  143953. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  143954. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  143955. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  143956. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  143957. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  143958. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  143959. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  143960. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  143961. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  143962. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  143963. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  143964. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  143965. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  143966. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  143967. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  143968. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  143969. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  143970. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  143971. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  143972. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  143973. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  143974. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  143975. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  143976. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  143977. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  143978. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  143979. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  143980. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  143981. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  143982. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  143983. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  143984. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  143985. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  143986. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  143987. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  143988. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  143989. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  143990. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  143991. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  143992. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  143993. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  143994. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  143995. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  143996. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  143997. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  143998. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  143999. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  144000. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  144001. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  144002. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  144003. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  144004. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  144005. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  144006. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  144007. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  144008. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  144009. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  144010. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  144011. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  144012. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  144013. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  144014. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  144015. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  144016. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  144017. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  144018. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  144019. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  144020. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  144021. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  144022. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  144023. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  144024. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  144025. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  144026. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  144027. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  144028. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  144029. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  144030. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  144031. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  144032. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  144033. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  144034. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  144035. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  144036. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  144037. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  144038. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  144039. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  144040. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  144041. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  144042. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  144043. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  144044. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  144045. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  144046. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  144047. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  144048. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  144049. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  144050. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  144051. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  144052. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  144053. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  144054. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  144055. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  144056. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  144057. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  144058. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  144059. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  144060. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  144061. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  144062. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  144063. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  144064. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  144065. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  144066. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  144067. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  144068. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  144069. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  144070. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  144071. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  144072. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  144073. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  144074. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  144075. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  144076. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  144077. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  144078. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  144079. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  144080. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  144081. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  144082. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  144083. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  144084. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  144085. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  144086. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  144087. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  144088. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  144089. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  144090. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  144091. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  144092. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  144093. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  144094. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  144095. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  144096. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  144097. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  144098. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  144099. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  144100. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  144101. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  144102. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  144103. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  144104. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  144105. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  144106. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  144107. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  144108. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  144109. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  144110. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  144111. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  144112. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  144113. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  144114. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  144115. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  144116. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  144117. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  144118. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  144119. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  144120. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  144121. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  144122. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  144123. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  144124. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  144125. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  144126. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  144127. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  144128. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  144129. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  144130. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  144131. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  144132. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  144133. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  144134. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  144135. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  144136. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  144137. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  144138. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  144139. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  144140. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  144141. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  144142. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  144143. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  144144. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  144145. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  144146. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  144147. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  144148. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  144149. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  144150. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  144151. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  144152. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  144153. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  144154. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  144155. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  144156. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  144157. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  144158. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  144159. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  144160. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  144161. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  144162. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  144163. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  144164. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  144165. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  144166. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  144167. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  144168. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  144169. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  144170. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  144171. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  144172. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  144173. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  144174. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  144175. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  144176. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  144177. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  144178. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  144179. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  144180. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  144181. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  144182. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  144183. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  144184. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  144185. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  144186. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  144187. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  144188. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  144189. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  144190. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  144191. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  144192. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  144193. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  144194. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  144195. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  144196. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  144197. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  144198. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  144199. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  144200. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  144201. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  144202. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  144203. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  144204. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  144205. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  144206. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  144207. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  144208. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  144209. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  144210. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  144211. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  144212. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  144213. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  144214. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  144215. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  144216. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  144217. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  144218. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  144219. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  144220. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  144221. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  144222. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  144223. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  144224. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  144225. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  144226. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  144227. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  144228. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  144229. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  144230. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  144231. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  144232. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  144233. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  144234. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  144235. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  144236. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  144237. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  144238. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  144239. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  144240. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  144241. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  144242. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  144243. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  144244. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  144245. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  144246. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  144247. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  144248. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  144249. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  144250. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  144251. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  144252. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  144253. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  144254. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  144255. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  144256. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  144257. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  144258. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  144259. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  144260. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  144261. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  144262. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  144263. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  144264. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  144265. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  144266. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  144267. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  144268. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  144269. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  144270. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  144271. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  144272. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  144273. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144274. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144275. };
  144276. static float *vwin[8] = {
  144277. vwin64,
  144278. vwin128,
  144279. vwin256,
  144280. vwin512,
  144281. vwin1024,
  144282. vwin2048,
  144283. vwin4096,
  144284. vwin8192,
  144285. };
  144286. float *_vorbis_window_get(int n){
  144287. return vwin[n];
  144288. }
  144289. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144290. int lW,int W,int nW){
  144291. lW=(W?lW:0);
  144292. nW=(W?nW:0);
  144293. {
  144294. float *windowLW=vwin[winno[lW]];
  144295. float *windowNW=vwin[winno[nW]];
  144296. long n=blocksizes[W];
  144297. long ln=blocksizes[lW];
  144298. long rn=blocksizes[nW];
  144299. long leftbegin=n/4-ln/4;
  144300. long leftend=leftbegin+ln/2;
  144301. long rightbegin=n/2+n/4-rn/4;
  144302. long rightend=rightbegin+rn/2;
  144303. int i,p;
  144304. for(i=0;i<leftbegin;i++)
  144305. d[i]=0.f;
  144306. for(p=0;i<leftend;i++,p++)
  144307. d[i]*=windowLW[p];
  144308. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144309. d[i]*=windowNW[p];
  144310. for(;i<n;i++)
  144311. d[i]=0.f;
  144312. }
  144313. }
  144314. #endif
  144315. /*** End of inlined file: window.c ***/
  144316. #else
  144317. #include <vorbis/vorbisenc.h>
  144318. #include <vorbis/codec.h>
  144319. #include <vorbis/vorbisfile.h>
  144320. #endif
  144321. }
  144322. BEGIN_JUCE_NAMESPACE
  144323. using namespace OggVorbisNamespace;
  144324. static const char* const oggFormatName = "Ogg-Vorbis file";
  144325. static const tchar* const oggExtensions[] = { T(".ogg"), 0 };
  144326. class OggReader : public AudioFormatReader
  144327. {
  144328. OggVorbis_File ovFile;
  144329. ov_callbacks callbacks;
  144330. AudioSampleBuffer reservoir;
  144331. int reservoirStart, samplesInReservoir;
  144332. public:
  144333. OggReader (InputStream* const inp)
  144334. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144335. reservoir (2, 4096),
  144336. reservoirStart (0),
  144337. samplesInReservoir (0)
  144338. {
  144339. sampleRate = 0;
  144340. usesFloatingPointData = true;
  144341. callbacks.read_func = &oggReadCallback;
  144342. callbacks.seek_func = &oggSeekCallback;
  144343. callbacks.close_func = &oggCloseCallback;
  144344. callbacks.tell_func = &oggTellCallback;
  144345. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144346. if (err == 0)
  144347. {
  144348. vorbis_info* info = ov_info (&ovFile, -1);
  144349. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144350. numChannels = info->channels;
  144351. bitsPerSample = 16;
  144352. sampleRate = info->rate;
  144353. reservoir.setSize (numChannels,
  144354. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144355. }
  144356. }
  144357. ~OggReader()
  144358. {
  144359. ov_clear (&ovFile);
  144360. }
  144361. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144362. int64 startSampleInFile, int numSamples)
  144363. {
  144364. while (numSamples > 0)
  144365. {
  144366. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144367. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144368. {
  144369. // got a few samples overlapping, so use them before seeking..
  144370. const int numToUse = jmin (numSamples, numAvailable);
  144371. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144372. if (destSamples[i] != 0)
  144373. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144374. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144375. sizeof (float) * numToUse);
  144376. startSampleInFile += numToUse;
  144377. numSamples -= numToUse;
  144378. startOffsetInDestBuffer += numToUse;
  144379. if (numSamples == 0)
  144380. break;
  144381. }
  144382. if (startSampleInFile < reservoirStart
  144383. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  144384. {
  144385. // buffer miss, so refill the reservoir
  144386. int bitStream = 0;
  144387. reservoirStart = jmax (0, (int) startSampleInFile);
  144388. samplesInReservoir = reservoir.getNumSamples();
  144389. if (reservoirStart != (int) ov_pcm_tell (&ovFile))
  144390. ov_pcm_seek (&ovFile, reservoirStart);
  144391. int offset = 0;
  144392. int numToRead = samplesInReservoir;
  144393. while (numToRead > 0)
  144394. {
  144395. float** dataIn = 0;
  144396. const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144397. if (samps <= 0)
  144398. break;
  144399. jassert (samps <= numToRead);
  144400. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144401. {
  144402. memcpy (reservoir.getSampleData (i, offset),
  144403. dataIn[i],
  144404. sizeof (float) * samps);
  144405. }
  144406. numToRead -= samps;
  144407. offset += samps;
  144408. }
  144409. if (numToRead > 0)
  144410. reservoir.clear (offset, numToRead);
  144411. }
  144412. }
  144413. if (numSamples > 0)
  144414. {
  144415. for (int i = numDestChannels; --i >= 0;)
  144416. if (destSamples[i] != 0)
  144417. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144418. sizeof (int) * numSamples);
  144419. }
  144420. return true;
  144421. }
  144422. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144423. {
  144424. return (size_t) (((InputStream*) datasource)->read (ptr, (int) (size * nmemb)) / size);
  144425. }
  144426. static int oggSeekCallback (void* datasource, ogg_int64_t offset, int whence)
  144427. {
  144428. InputStream* const in = (InputStream*) datasource;
  144429. if (whence == SEEK_CUR)
  144430. offset += in->getPosition();
  144431. else if (whence == SEEK_END)
  144432. offset += in->getTotalLength();
  144433. in->setPosition (offset);
  144434. return 0;
  144435. }
  144436. static int oggCloseCallback (void*)
  144437. {
  144438. return 0;
  144439. }
  144440. static long oggTellCallback (void* datasource)
  144441. {
  144442. return (long) ((InputStream*) datasource)->getPosition();
  144443. }
  144444. juce_UseDebuggingNewOperator
  144445. };
  144446. class OggWriter : public AudioFormatWriter
  144447. {
  144448. ogg_stream_state os;
  144449. ogg_page og;
  144450. ogg_packet op;
  144451. vorbis_info vi;
  144452. vorbis_comment vc;
  144453. vorbis_dsp_state vd;
  144454. vorbis_block vb;
  144455. public:
  144456. bool ok;
  144457. OggWriter (OutputStream* const out,
  144458. const double sampleRate,
  144459. const int numChannels,
  144460. const int bitsPerSample,
  144461. const int qualityIndex)
  144462. : AudioFormatWriter (out, TRANS (oggFormatName),
  144463. sampleRate,
  144464. numChannels,
  144465. bitsPerSample)
  144466. {
  144467. ok = false;
  144468. vorbis_info_init (&vi);
  144469. if (vorbis_encode_init_vbr (&vi,
  144470. numChannels,
  144471. (int) sampleRate,
  144472. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144473. {
  144474. vorbis_comment_init (&vc);
  144475. if (JUCEApplication::getInstance() != 0)
  144476. vorbis_comment_add_tag (&vc, "ENCODER", const_cast <char*> (JUCEApplication::getInstance()->getApplicationName().toUTF8()));
  144477. vorbis_analysis_init (&vd, &vi);
  144478. vorbis_block_init (&vd, &vb);
  144479. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144480. ogg_packet header;
  144481. ogg_packet header_comm;
  144482. ogg_packet header_code;
  144483. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144484. ogg_stream_packetin (&os, &header);
  144485. ogg_stream_packetin (&os, &header_comm);
  144486. ogg_stream_packetin (&os, &header_code);
  144487. for (;;)
  144488. {
  144489. if (ogg_stream_flush (&os, &og) == 0)
  144490. break;
  144491. output->write (og.header, og.header_len);
  144492. output->write (og.body, og.body_len);
  144493. }
  144494. ok = true;
  144495. }
  144496. }
  144497. ~OggWriter()
  144498. {
  144499. if (ok)
  144500. {
  144501. // write a zero-length packet to show ogg that we're finished..
  144502. write (0, 0);
  144503. ogg_stream_clear (&os);
  144504. vorbis_block_clear (&vb);
  144505. vorbis_dsp_clear (&vd);
  144506. vorbis_comment_clear (&vc);
  144507. vorbis_info_clear (&vi);
  144508. output->flush();
  144509. }
  144510. else
  144511. {
  144512. vorbis_info_clear (&vi);
  144513. output = 0; // to stop the base class deleting this, as it needs to be returned
  144514. // to the caller of createWriter()
  144515. }
  144516. }
  144517. bool write (const int** samplesToWrite, int numSamples)
  144518. {
  144519. if (! ok)
  144520. return false;
  144521. if (numSamples > 0)
  144522. {
  144523. const double gain = 1.0 / 0x80000000u;
  144524. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144525. for (int i = numChannels; --i >= 0;)
  144526. {
  144527. float* const dst = vorbisBuffer[i];
  144528. const int* const src = samplesToWrite [i];
  144529. if (src != 0 && dst != 0)
  144530. {
  144531. for (int j = 0; j < numSamples; ++j)
  144532. dst[j] = (float) (src[j] * gain);
  144533. }
  144534. }
  144535. }
  144536. vorbis_analysis_wrote (&vd, numSamples);
  144537. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144538. {
  144539. vorbis_analysis (&vb, 0);
  144540. vorbis_bitrate_addblock (&vb);
  144541. while (vorbis_bitrate_flushpacket (&vd, &op))
  144542. {
  144543. ogg_stream_packetin (&os, &op);
  144544. for (;;)
  144545. {
  144546. if (ogg_stream_pageout (&os, &og) == 0)
  144547. break;
  144548. output->write (og.header, og.header_len);
  144549. output->write (og.body, og.body_len);
  144550. if (ogg_page_eos (&og))
  144551. break;
  144552. }
  144553. }
  144554. }
  144555. return true;
  144556. }
  144557. juce_UseDebuggingNewOperator
  144558. };
  144559. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144560. : AudioFormat (TRANS (oggFormatName), (const tchar**) oggExtensions)
  144561. {
  144562. }
  144563. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144564. {
  144565. }
  144566. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144567. {
  144568. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144569. return Array <int> (rates);
  144570. }
  144571. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144572. {
  144573. Array <int> depths;
  144574. depths.add (32);
  144575. return depths;
  144576. }
  144577. bool OggVorbisAudioFormat::canDoStereo()
  144578. {
  144579. return true;
  144580. }
  144581. bool OggVorbisAudioFormat::canDoMono()
  144582. {
  144583. return true;
  144584. }
  144585. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144586. const bool deleteStreamIfOpeningFails)
  144587. {
  144588. ScopedPointer <OggReader> r (new OggReader (in));
  144589. if (r->sampleRate != 0)
  144590. return r.release();
  144591. if (! deleteStreamIfOpeningFails)
  144592. r->input = 0;
  144593. return 0;
  144594. }
  144595. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144596. double sampleRate,
  144597. unsigned int numChannels,
  144598. int bitsPerSample,
  144599. const StringPairArray& /*metadataValues*/,
  144600. int qualityOptionIndex)
  144601. {
  144602. ScopedPointer <OggWriter> w (new OggWriter (out,
  144603. sampleRate,
  144604. numChannels,
  144605. bitsPerSample,
  144606. qualityOptionIndex));
  144607. return w->ok ? w.release() : 0;
  144608. }
  144609. bool OggVorbisAudioFormat::isCompressed()
  144610. {
  144611. return true;
  144612. }
  144613. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144614. {
  144615. StringArray s;
  144616. s.add ("Low Quality");
  144617. s.add ("Medium Quality");
  144618. s.add ("High Quality");
  144619. return s;
  144620. }
  144621. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144622. {
  144623. FileInputStream* const in = source.createInputStream();
  144624. if (in != 0)
  144625. {
  144626. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144627. if (r != 0)
  144628. {
  144629. const int64 numSamps = r->lengthInSamples;
  144630. r = 0;
  144631. const int64 fileNumSamps = source.getSize() / 4;
  144632. const double ratio = numSamps / (double) fileNumSamps;
  144633. if (ratio > 12.0)
  144634. return 0;
  144635. else if (ratio > 6.0)
  144636. return 1;
  144637. else
  144638. return 2;
  144639. }
  144640. }
  144641. return 1;
  144642. }
  144643. END_JUCE_NAMESPACE
  144644. #endif
  144645. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144646. #endif
  144647. #if JUCE_BUILD_CORE && ! JUCE_ONLY_BUILD_CORE_LIBRARY // do these in the core section to help balance the sizes
  144648. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144649. #if JUCE_MSVC
  144650. #pragma warning (push)
  144651. #endif
  144652. namespace jpeglibNamespace
  144653. {
  144654. #if JUCE_INCLUDE_JPEGLIB_CODE
  144655. #if JUCE_MINGW
  144656. typedef unsigned char boolean;
  144657. #endif
  144658. extern "C"
  144659. {
  144660. #define JPEG_INTERNALS
  144661. #undef FAR
  144662. /*** Start of inlined file: jpeglib.h ***/
  144663. #ifndef JPEGLIB_H
  144664. #define JPEGLIB_H
  144665. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144666. /*** Start of inlined file: jconfig.h ***/
  144667. // disable all the warnings under MSVC
  144668. #ifdef _MSC_VER
  144669. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  144670. #endif
  144671. #ifdef __BORLANDC__
  144672. #pragma warn -8057
  144673. #pragma warn -8019
  144674. #pragma warn -8004
  144675. #pragma warn -8008
  144676. #endif
  144677. #define HAVE_PROTOTYPES
  144678. #define HAVE_UNSIGNED_CHAR
  144679. #define HAVE_UNSIGNED_SHORT
  144680. #undef CHAR_IS_UNSIGNED
  144681. #define HAVE_STDDEF_H
  144682. #define HAVE_STDLIB_H
  144683. #undef NEED_BSD_STRINGS
  144684. #undef NEED_SYS_TYPES_H
  144685. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  144686. #undef NEED_SHORT_EXTERNAL_NAMES
  144687. #undef INCOMPLETE_TYPES_BROKEN
  144688. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  144689. typedef unsigned char boolean;
  144690. #endif
  144691. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  144692. #ifdef JPEG_INTERNALS
  144693. #undef RIGHT_SHIFT_IS_UNSIGNED
  144694. #endif /* JPEG_INTERNALS */
  144695. #ifdef JPEG_CJPEG_DJPEG
  144696. #define BMP_SUPPORTED /* BMP image file format */
  144697. #define GIF_SUPPORTED /* GIF image file format */
  144698. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  144699. #undef RLE_SUPPORTED /* Utah RLE image file format */
  144700. #define TARGA_SUPPORTED /* Targa image file format */
  144701. #define TWO_FILE_COMMANDLINE /* optional */
  144702. #define USE_SETMODE /* Microsoft has setmode() */
  144703. #undef NEED_SIGNAL_CATCHER
  144704. #undef DONT_USE_B_MODE
  144705. #undef PROGRESS_REPORT /* optional */
  144706. #endif /* JPEG_CJPEG_DJPEG */
  144707. /*** End of inlined file: jconfig.h ***/
  144708. /* widely used configuration options */
  144709. #endif
  144710. /*** Start of inlined file: jmorecfg.h ***/
  144711. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  144712. #define MAX_COMPONENTS 10 /* maximum number of image components */
  144713. #if BITS_IN_JSAMPLE == 8
  144714. #ifdef HAVE_UNSIGNED_CHAR
  144715. typedef unsigned char JSAMPLE;
  144716. #define GETJSAMPLE(value) ((int) (value))
  144717. #else /* not HAVE_UNSIGNED_CHAR */
  144718. typedef char JSAMPLE;
  144719. #ifdef CHAR_IS_UNSIGNED
  144720. #define GETJSAMPLE(value) ((int) (value))
  144721. #else
  144722. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  144723. #endif /* CHAR_IS_UNSIGNED */
  144724. #endif /* HAVE_UNSIGNED_CHAR */
  144725. #define MAXJSAMPLE 255
  144726. #define CENTERJSAMPLE 128
  144727. #endif /* BITS_IN_JSAMPLE == 8 */
  144728. #if BITS_IN_JSAMPLE == 12
  144729. typedef short JSAMPLE;
  144730. #define GETJSAMPLE(value) ((int) (value))
  144731. #define MAXJSAMPLE 4095
  144732. #define CENTERJSAMPLE 2048
  144733. #endif /* BITS_IN_JSAMPLE == 12 */
  144734. typedef short JCOEF;
  144735. #ifdef HAVE_UNSIGNED_CHAR
  144736. typedef unsigned char JOCTET;
  144737. #define GETJOCTET(value) (value)
  144738. #else /* not HAVE_UNSIGNED_CHAR */
  144739. typedef char JOCTET;
  144740. #ifdef CHAR_IS_UNSIGNED
  144741. #define GETJOCTET(value) (value)
  144742. #else
  144743. #define GETJOCTET(value) ((value) & 0xFF)
  144744. #endif /* CHAR_IS_UNSIGNED */
  144745. #endif /* HAVE_UNSIGNED_CHAR */
  144746. #ifdef HAVE_UNSIGNED_CHAR
  144747. typedef unsigned char UINT8;
  144748. #else /* not HAVE_UNSIGNED_CHAR */
  144749. #ifdef CHAR_IS_UNSIGNED
  144750. typedef char UINT8;
  144751. #else /* not CHAR_IS_UNSIGNED */
  144752. typedef short UINT8;
  144753. #endif /* CHAR_IS_UNSIGNED */
  144754. #endif /* HAVE_UNSIGNED_CHAR */
  144755. #ifdef HAVE_UNSIGNED_SHORT
  144756. typedef unsigned short UINT16;
  144757. #else /* not HAVE_UNSIGNED_SHORT */
  144758. typedef unsigned int UINT16;
  144759. #endif /* HAVE_UNSIGNED_SHORT */
  144760. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  144761. typedef short INT16;
  144762. #endif
  144763. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  144764. typedef long INT32;
  144765. #endif
  144766. typedef unsigned int JDIMENSION;
  144767. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  144768. #define METHODDEF(type) static type
  144769. #define LOCAL(type) static type
  144770. #define GLOBAL(type) type
  144771. #define EXTERN(type) extern type
  144772. #ifdef HAVE_PROTOTYPES
  144773. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  144774. #else
  144775. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  144776. #endif
  144777. #ifdef NEED_FAR_POINTERS
  144778. #define FAR far
  144779. #else
  144780. #define FAR
  144781. #endif
  144782. #ifndef HAVE_BOOLEAN
  144783. typedef int boolean;
  144784. #endif
  144785. #ifndef FALSE /* in case these macros already exist */
  144786. #define FALSE 0 /* values of boolean */
  144787. #endif
  144788. #ifndef TRUE
  144789. #define TRUE 1
  144790. #endif
  144791. #ifdef JPEG_INTERNALS
  144792. #define JPEG_INTERNAL_OPTIONS
  144793. #endif
  144794. #ifdef JPEG_INTERNAL_OPTIONS
  144795. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  144796. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  144797. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  144798. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144799. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144800. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144801. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  144802. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  144803. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144804. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144805. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144806. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  144807. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  144808. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  144809. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  144810. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  144811. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  144812. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  144813. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  144814. #define RGB_GREEN 1 /* Offset of Green */
  144815. #define RGB_BLUE 2 /* Offset of Blue */
  144816. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  144817. #ifndef INLINE
  144818. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  144819. #define INLINE __inline__
  144820. #endif
  144821. #ifndef INLINE
  144822. #define INLINE /* default is to define it as empty */
  144823. #endif
  144824. #endif
  144825. #ifndef MULTIPLIER
  144826. #define MULTIPLIER int /* type for fastest integer multiply */
  144827. #endif
  144828. #ifndef FAST_FLOAT
  144829. #ifdef HAVE_PROTOTYPES
  144830. #define FAST_FLOAT float
  144831. #else
  144832. #define FAST_FLOAT double
  144833. #endif
  144834. #endif
  144835. #endif /* JPEG_INTERNAL_OPTIONS */
  144836. /*** End of inlined file: jmorecfg.h ***/
  144837. /* seldom changed options */
  144838. #define JPEG_LIB_VERSION 62 /* Version 6b */
  144839. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  144840. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  144841. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  144842. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  144843. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  144844. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  144845. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  144846. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  144847. #ifndef D_MAX_BLOCKS_IN_MCU
  144848. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  144849. #endif
  144850. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  144851. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  144852. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  144853. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  144854. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  144855. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  144856. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  144857. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  144858. typedef struct {
  144859. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  144860. boolean sent_table; /* TRUE when table has been output */
  144861. } JQUANT_TBL;
  144862. typedef struct {
  144863. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  144864. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  144865. boolean sent_table; /* TRUE when table has been output */
  144866. } JHUFF_TBL;
  144867. typedef struct {
  144868. int component_id; /* identifier for this component (0..255) */
  144869. int component_index; /* its index in SOF or cinfo->comp_info[] */
  144870. int h_samp_factor; /* horizontal sampling factor (1..4) */
  144871. int v_samp_factor; /* vertical sampling factor (1..4) */
  144872. int quant_tbl_no; /* quantization table selector (0..3) */
  144873. int dc_tbl_no; /* DC entropy table selector (0..3) */
  144874. int ac_tbl_no; /* AC entropy table selector (0..3) */
  144875. JDIMENSION width_in_blocks;
  144876. JDIMENSION height_in_blocks;
  144877. int DCT_scaled_size;
  144878. JDIMENSION downsampled_width; /* actual width in samples */
  144879. JDIMENSION downsampled_height; /* actual height in samples */
  144880. boolean component_needed; /* do we need the value of this component? */
  144881. int MCU_width; /* number of blocks per MCU, horizontally */
  144882. int MCU_height; /* number of blocks per MCU, vertically */
  144883. int MCU_blocks; /* MCU_width * MCU_height */
  144884. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  144885. int last_col_width; /* # of non-dummy blocks across in last MCU */
  144886. int last_row_height; /* # of non-dummy blocks down in last MCU */
  144887. JQUANT_TBL * quant_table;
  144888. void * dct_table;
  144889. } jpeg_component_info;
  144890. typedef struct {
  144891. int comps_in_scan; /* number of components encoded in this scan */
  144892. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  144893. int Ss, Se; /* progressive JPEG spectral selection parms */
  144894. int Ah, Al; /* progressive JPEG successive approx. parms */
  144895. } jpeg_scan_info;
  144896. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  144897. struct jpeg_marker_struct {
  144898. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  144899. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  144900. unsigned int original_length; /* # bytes of data in the file */
  144901. unsigned int data_length; /* # bytes of data saved at data[] */
  144902. JOCTET FAR * data; /* the data contained in the marker */
  144903. };
  144904. typedef enum {
  144905. JCS_UNKNOWN, /* error/unspecified */
  144906. JCS_GRAYSCALE, /* monochrome */
  144907. JCS_RGB, /* red/green/blue */
  144908. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  144909. JCS_CMYK, /* C/M/Y/K */
  144910. JCS_YCCK /* Y/Cb/Cr/K */
  144911. } J_COLOR_SPACE;
  144912. typedef enum {
  144913. JDCT_ISLOW, /* slow but accurate integer algorithm */
  144914. JDCT_IFAST, /* faster, less accurate integer method */
  144915. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  144916. } J_DCT_METHOD;
  144917. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  144918. #define JDCT_DEFAULT JDCT_ISLOW
  144919. #endif
  144920. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  144921. #define JDCT_FASTEST JDCT_IFAST
  144922. #endif
  144923. typedef enum {
  144924. JDITHER_NONE, /* no dithering */
  144925. JDITHER_ORDERED, /* simple ordered dither */
  144926. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  144927. } J_DITHER_MODE;
  144928. #define jpeg_common_fields \
  144929. struct jpeg_error_mgr * err; /* Error handler module */\
  144930. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  144931. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  144932. void * client_data; /* Available for use by application */\
  144933. boolean is_decompressor; /* So common code can tell which is which */\
  144934. int global_state /* For checking call sequence validity */
  144935. struct jpeg_common_struct {
  144936. jpeg_common_fields; /* Fields common to both master struct types */
  144937. };
  144938. typedef struct jpeg_common_struct * j_common_ptr;
  144939. typedef struct jpeg_compress_struct * j_compress_ptr;
  144940. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  144941. struct jpeg_compress_struct {
  144942. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  144943. struct jpeg_destination_mgr * dest;
  144944. JDIMENSION image_width; /* input image width */
  144945. JDIMENSION image_height; /* input image height */
  144946. int input_components; /* # of color components in input image */
  144947. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  144948. double input_gamma; /* image gamma of input image */
  144949. int data_precision; /* bits of precision in image data */
  144950. int num_components; /* # of color components in JPEG image */
  144951. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144952. jpeg_component_info * comp_info;
  144953. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144954. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144955. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144956. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144957. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144958. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144959. int num_scans; /* # of entries in scan_info array */
  144960. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  144961. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  144962. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144963. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  144964. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144965. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  144966. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  144967. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  144968. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  144969. boolean write_JFIF_header; /* should a JFIF marker be written? */
  144970. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  144971. UINT8 JFIF_minor_version;
  144972. UINT8 density_unit; /* JFIF code for pixel size units */
  144973. UINT16 X_density; /* Horizontal pixel density */
  144974. UINT16 Y_density; /* Vertical pixel density */
  144975. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  144976. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  144977. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  144978. int max_h_samp_factor; /* largest h_samp_factor */
  144979. int max_v_samp_factor; /* largest v_samp_factor */
  144980. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  144981. int comps_in_scan; /* # of JPEG components in this scan */
  144982. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144983. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144984. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144985. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144986. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  144987. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144988. struct jpeg_comp_master * master;
  144989. struct jpeg_c_main_controller * main;
  144990. struct jpeg_c_prep_controller * prep;
  144991. struct jpeg_c_coef_controller * coef;
  144992. struct jpeg_marker_writer * marker;
  144993. struct jpeg_color_converter * cconvert;
  144994. struct jpeg_downsampler * downsample;
  144995. struct jpeg_forward_dct * fdct;
  144996. struct jpeg_entropy_encoder * entropy;
  144997. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  144998. int script_space_size;
  144999. };
  145000. struct jpeg_decompress_struct {
  145001. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  145002. struct jpeg_source_mgr * src;
  145003. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  145004. JDIMENSION image_height; /* nominal image height */
  145005. int num_components; /* # of color components in JPEG image */
  145006. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145007. J_COLOR_SPACE out_color_space; /* colorspace for output */
  145008. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  145009. double output_gamma; /* image gamma wanted in output */
  145010. boolean buffered_image; /* TRUE=multiple output passes */
  145011. boolean raw_data_out; /* TRUE=downsampled data wanted */
  145012. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  145013. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  145014. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  145015. boolean quantize_colors; /* TRUE=colormapped output wanted */
  145016. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  145017. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  145018. int desired_number_of_colors; /* max # colors to use in created colormap */
  145019. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  145020. boolean enable_external_quant;/* enable future use of external colormap */
  145021. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  145022. JDIMENSION output_width; /* scaled image width */
  145023. JDIMENSION output_height; /* scaled image height */
  145024. int out_color_components; /* # of color components in out_color_space */
  145025. int output_components; /* # of color components returned */
  145026. int rec_outbuf_height; /* min recommended height of scanline buffer */
  145027. int actual_number_of_colors; /* number of entries in use */
  145028. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  145029. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  145030. int input_scan_number; /* Number of SOS markers seen so far */
  145031. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  145032. int output_scan_number; /* Nominal scan number being displayed */
  145033. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  145034. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  145035. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145036. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145037. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145038. int data_precision; /* bits of precision in image data */
  145039. jpeg_component_info * comp_info;
  145040. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  145041. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145042. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145043. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145044. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145045. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  145046. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  145047. UINT8 JFIF_major_version; /* JFIF version number */
  145048. UINT8 JFIF_minor_version;
  145049. UINT8 density_unit; /* JFIF code for pixel size units */
  145050. UINT16 X_density; /* Horizontal pixel density */
  145051. UINT16 Y_density; /* Vertical pixel density */
  145052. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  145053. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  145054. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145055. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  145056. int max_h_samp_factor; /* largest h_samp_factor */
  145057. int max_v_samp_factor; /* largest v_samp_factor */
  145058. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  145059. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  145060. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  145061. int comps_in_scan; /* # of JPEG components in this scan */
  145062. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145063. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145064. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145065. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145066. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  145067. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145068. int unread_marker;
  145069. struct jpeg_decomp_master * master;
  145070. struct jpeg_d_main_controller * main;
  145071. struct jpeg_d_coef_controller * coef;
  145072. struct jpeg_d_post_controller * post;
  145073. struct jpeg_input_controller * inputctl;
  145074. struct jpeg_marker_reader * marker;
  145075. struct jpeg_entropy_decoder * entropy;
  145076. struct jpeg_inverse_dct * idct;
  145077. struct jpeg_upsampler * upsample;
  145078. struct jpeg_color_deconverter * cconvert;
  145079. struct jpeg_color_quantizer * cquantize;
  145080. };
  145081. struct jpeg_error_mgr {
  145082. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  145083. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  145084. JMETHOD(void, output_message, (j_common_ptr cinfo));
  145085. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  145086. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  145087. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  145088. int msg_code;
  145089. #define JMSG_STR_PARM_MAX 80
  145090. union {
  145091. int i[8];
  145092. char s[JMSG_STR_PARM_MAX];
  145093. } msg_parm;
  145094. int trace_level; /* max msg_level that will be displayed */
  145095. long num_warnings; /* number of corrupt-data warnings */
  145096. const char * const * jpeg_message_table; /* Library errors */
  145097. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  145098. const char * const * addon_message_table; /* Non-library errors */
  145099. int first_addon_message; /* code for first string in addon table */
  145100. int last_addon_message; /* code for last string in addon table */
  145101. };
  145102. struct jpeg_progress_mgr {
  145103. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  145104. long pass_counter; /* work units completed in this pass */
  145105. long pass_limit; /* total number of work units in this pass */
  145106. int completed_passes; /* passes completed so far */
  145107. int total_passes; /* total number of passes expected */
  145108. };
  145109. struct jpeg_destination_mgr {
  145110. JOCTET * next_output_byte; /* => next byte to write in buffer */
  145111. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  145112. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  145113. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  145114. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  145115. };
  145116. struct jpeg_source_mgr {
  145117. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  145118. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  145119. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  145120. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  145121. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  145122. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  145123. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  145124. };
  145125. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  145126. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  145127. #define JPOOL_NUMPOOLS 2
  145128. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  145129. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  145130. struct jpeg_memory_mgr {
  145131. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  145132. size_t sizeofobject));
  145133. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  145134. size_t sizeofobject));
  145135. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  145136. JDIMENSION samplesperrow,
  145137. JDIMENSION numrows));
  145138. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  145139. JDIMENSION blocksperrow,
  145140. JDIMENSION numrows));
  145141. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  145142. int pool_id,
  145143. boolean pre_zero,
  145144. JDIMENSION samplesperrow,
  145145. JDIMENSION numrows,
  145146. JDIMENSION maxaccess));
  145147. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  145148. int pool_id,
  145149. boolean pre_zero,
  145150. JDIMENSION blocksperrow,
  145151. JDIMENSION numrows,
  145152. JDIMENSION maxaccess));
  145153. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  145154. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  145155. jvirt_sarray_ptr ptr,
  145156. JDIMENSION start_row,
  145157. JDIMENSION num_rows,
  145158. boolean writable));
  145159. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  145160. jvirt_barray_ptr ptr,
  145161. JDIMENSION start_row,
  145162. JDIMENSION num_rows,
  145163. boolean writable));
  145164. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  145165. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  145166. long max_memory_to_use;
  145167. long max_alloc_chunk;
  145168. };
  145169. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  145170. #ifdef HAVE_PROTOTYPES
  145171. #define JPP(arglist) arglist
  145172. #else
  145173. #define JPP(arglist) ()
  145174. #endif
  145175. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145176. #define jpeg_std_error jStdError
  145177. #define jpeg_CreateCompress jCreaCompress
  145178. #define jpeg_CreateDecompress jCreaDecompress
  145179. #define jpeg_destroy_compress jDestCompress
  145180. #define jpeg_destroy_decompress jDestDecompress
  145181. #define jpeg_stdio_dest jStdDest
  145182. #define jpeg_stdio_src jStdSrc
  145183. #define jpeg_set_defaults jSetDefaults
  145184. #define jpeg_set_colorspace jSetColorspace
  145185. #define jpeg_default_colorspace jDefColorspace
  145186. #define jpeg_set_quality jSetQuality
  145187. #define jpeg_set_linear_quality jSetLQuality
  145188. #define jpeg_add_quant_table jAddQuantTable
  145189. #define jpeg_quality_scaling jQualityScaling
  145190. #define jpeg_simple_progression jSimProgress
  145191. #define jpeg_suppress_tables jSuppressTables
  145192. #define jpeg_alloc_quant_table jAlcQTable
  145193. #define jpeg_alloc_huff_table jAlcHTable
  145194. #define jpeg_start_compress jStrtCompress
  145195. #define jpeg_write_scanlines jWrtScanlines
  145196. #define jpeg_finish_compress jFinCompress
  145197. #define jpeg_write_raw_data jWrtRawData
  145198. #define jpeg_write_marker jWrtMarker
  145199. #define jpeg_write_m_header jWrtMHeader
  145200. #define jpeg_write_m_byte jWrtMByte
  145201. #define jpeg_write_tables jWrtTables
  145202. #define jpeg_read_header jReadHeader
  145203. #define jpeg_start_decompress jStrtDecompress
  145204. #define jpeg_read_scanlines jReadScanlines
  145205. #define jpeg_finish_decompress jFinDecompress
  145206. #define jpeg_read_raw_data jReadRawData
  145207. #define jpeg_has_multiple_scans jHasMultScn
  145208. #define jpeg_start_output jStrtOutput
  145209. #define jpeg_finish_output jFinOutput
  145210. #define jpeg_input_complete jInComplete
  145211. #define jpeg_new_colormap jNewCMap
  145212. #define jpeg_consume_input jConsumeInput
  145213. #define jpeg_calc_output_dimensions jCalcDimensions
  145214. #define jpeg_save_markers jSaveMarkers
  145215. #define jpeg_set_marker_processor jSetMarker
  145216. #define jpeg_read_coefficients jReadCoefs
  145217. #define jpeg_write_coefficients jWrtCoefs
  145218. #define jpeg_copy_critical_parameters jCopyCrit
  145219. #define jpeg_abort_compress jAbrtCompress
  145220. #define jpeg_abort_decompress jAbrtDecompress
  145221. #define jpeg_abort jAbort
  145222. #define jpeg_destroy jDestroy
  145223. #define jpeg_resync_to_restart jResyncRestart
  145224. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145225. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  145226. JPP((struct jpeg_error_mgr * err));
  145227. #define jpeg_create_compress(cinfo) \
  145228. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  145229. (size_t) sizeof(struct jpeg_compress_struct))
  145230. #define jpeg_create_decompress(cinfo) \
  145231. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  145232. (size_t) sizeof(struct jpeg_decompress_struct))
  145233. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  145234. int version, size_t structsize));
  145235. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  145236. int version, size_t structsize));
  145237. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  145238. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  145239. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  145240. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  145241. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  145242. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  145243. J_COLOR_SPACE colorspace));
  145244. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  145245. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  145246. boolean force_baseline));
  145247. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  145248. int scale_factor,
  145249. boolean force_baseline));
  145250. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  145251. const unsigned int *basic_table,
  145252. int scale_factor,
  145253. boolean force_baseline));
  145254. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  145255. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  145256. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  145257. boolean suppress));
  145258. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  145259. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  145260. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  145261. boolean write_all_tables));
  145262. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  145263. JSAMPARRAY scanlines,
  145264. JDIMENSION num_lines));
  145265. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  145266. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  145267. JSAMPIMAGE data,
  145268. JDIMENSION num_lines));
  145269. EXTERN(void) jpeg_write_marker
  145270. JPP((j_compress_ptr cinfo, int marker,
  145271. const JOCTET * dataptr, unsigned int datalen));
  145272. EXTERN(void) jpeg_write_m_header
  145273. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  145274. EXTERN(void) jpeg_write_m_byte
  145275. JPP((j_compress_ptr cinfo, int val));
  145276. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  145277. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  145278. boolean require_image));
  145279. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145280. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145281. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145282. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145283. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145284. JSAMPARRAY scanlines,
  145285. JDIMENSION max_lines));
  145286. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145287. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145288. JSAMPIMAGE data,
  145289. JDIMENSION max_lines));
  145290. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145291. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145292. int scan_number));
  145293. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145294. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145295. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145296. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145297. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145298. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145299. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145300. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145301. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145302. EXTERN(void) jpeg_save_markers
  145303. JPP((j_decompress_ptr cinfo, int marker_code,
  145304. unsigned int length_limit));
  145305. EXTERN(void) jpeg_set_marker_processor
  145306. JPP((j_decompress_ptr cinfo, int marker_code,
  145307. jpeg_marker_parser_method routine));
  145308. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145309. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145310. jvirt_barray_ptr * coef_arrays));
  145311. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145312. j_compress_ptr dstinfo));
  145313. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145314. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145315. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145316. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145317. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145318. int desired));
  145319. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145320. #define JPEG_EOI 0xD9 /* EOI marker code */
  145321. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145322. #define JPEG_COM 0xFE /* COM marker code */
  145323. #ifdef INCOMPLETE_TYPES_BROKEN
  145324. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145325. struct jvirt_sarray_control { long dummy; };
  145326. struct jvirt_barray_control { long dummy; };
  145327. struct jpeg_comp_master { long dummy; };
  145328. struct jpeg_c_main_controller { long dummy; };
  145329. struct jpeg_c_prep_controller { long dummy; };
  145330. struct jpeg_c_coef_controller { long dummy; };
  145331. struct jpeg_marker_writer { long dummy; };
  145332. struct jpeg_color_converter { long dummy; };
  145333. struct jpeg_downsampler { long dummy; };
  145334. struct jpeg_forward_dct { long dummy; };
  145335. struct jpeg_entropy_encoder { long dummy; };
  145336. struct jpeg_decomp_master { long dummy; };
  145337. struct jpeg_d_main_controller { long dummy; };
  145338. struct jpeg_d_coef_controller { long dummy; };
  145339. struct jpeg_d_post_controller { long dummy; };
  145340. struct jpeg_input_controller { long dummy; };
  145341. struct jpeg_marker_reader { long dummy; };
  145342. struct jpeg_entropy_decoder { long dummy; };
  145343. struct jpeg_inverse_dct { long dummy; };
  145344. struct jpeg_upsampler { long dummy; };
  145345. struct jpeg_color_deconverter { long dummy; };
  145346. struct jpeg_color_quantizer { long dummy; };
  145347. #endif /* JPEG_INTERNALS */
  145348. #endif /* INCOMPLETE_TYPES_BROKEN */
  145349. #ifdef JPEG_INTERNALS
  145350. /*** Start of inlined file: jpegint.h ***/
  145351. typedef enum { /* Operating modes for buffer controllers */
  145352. JBUF_PASS_THRU, /* Plain stripwise operation */
  145353. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145354. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145355. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145356. } J_BUF_MODE;
  145357. #define CSTATE_START 100 /* after create_compress */
  145358. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145359. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145360. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145361. #define DSTATE_START 200 /* after create_decompress */
  145362. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145363. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145364. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145365. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145366. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145367. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145368. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145369. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145370. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145371. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145372. struct jpeg_comp_master {
  145373. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145374. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145375. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145376. boolean call_pass_startup; /* True if pass_startup must be called */
  145377. boolean is_last_pass; /* True during last pass */
  145378. };
  145379. struct jpeg_c_main_controller {
  145380. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145381. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  145382. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  145383. JDIMENSION in_rows_avail));
  145384. };
  145385. struct jpeg_c_prep_controller {
  145386. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145387. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  145388. JSAMPARRAY input_buf,
  145389. JDIMENSION *in_row_ctr,
  145390. JDIMENSION in_rows_avail,
  145391. JSAMPIMAGE output_buf,
  145392. JDIMENSION *out_row_group_ctr,
  145393. JDIMENSION out_row_groups_avail));
  145394. };
  145395. struct jpeg_c_coef_controller {
  145396. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145397. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145398. JSAMPIMAGE input_buf));
  145399. };
  145400. struct jpeg_color_converter {
  145401. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145402. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145403. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145404. JDIMENSION output_row, int num_rows));
  145405. };
  145406. struct jpeg_downsampler {
  145407. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145408. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145409. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145410. JSAMPIMAGE output_buf,
  145411. JDIMENSION out_row_group_index));
  145412. boolean need_context_rows; /* TRUE if need rows above & below */
  145413. };
  145414. struct jpeg_forward_dct {
  145415. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145416. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145417. jpeg_component_info * compptr,
  145418. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145419. JDIMENSION start_row, JDIMENSION start_col,
  145420. JDIMENSION num_blocks));
  145421. };
  145422. struct jpeg_entropy_encoder {
  145423. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145424. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145425. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145426. };
  145427. struct jpeg_marker_writer {
  145428. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145429. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145430. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145431. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145432. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145433. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145434. unsigned int datalen));
  145435. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145436. };
  145437. struct jpeg_decomp_master {
  145438. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145439. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145440. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145441. };
  145442. struct jpeg_input_controller {
  145443. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145444. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145445. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145446. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145447. boolean has_multiple_scans; /* True if file has multiple scans */
  145448. boolean eoi_reached; /* True when EOI has been consumed */
  145449. };
  145450. struct jpeg_d_main_controller {
  145451. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145452. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145453. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145454. JDIMENSION out_rows_avail));
  145455. };
  145456. struct jpeg_d_coef_controller {
  145457. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145458. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145459. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145460. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145461. JSAMPIMAGE output_buf));
  145462. jvirt_barray_ptr *coef_arrays;
  145463. };
  145464. struct jpeg_d_post_controller {
  145465. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145466. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145467. JSAMPIMAGE input_buf,
  145468. JDIMENSION *in_row_group_ctr,
  145469. JDIMENSION in_row_groups_avail,
  145470. JSAMPARRAY output_buf,
  145471. JDIMENSION *out_row_ctr,
  145472. JDIMENSION out_rows_avail));
  145473. };
  145474. struct jpeg_marker_reader {
  145475. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145476. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145477. jpeg_marker_parser_method read_restart_marker;
  145478. boolean saw_SOI; /* found SOI? */
  145479. boolean saw_SOF; /* found SOF? */
  145480. int next_restart_num; /* next restart number expected (0-7) */
  145481. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145482. };
  145483. struct jpeg_entropy_decoder {
  145484. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145485. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145486. JBLOCKROW *MCU_data));
  145487. boolean insufficient_data; /* set TRUE after emitting warning */
  145488. };
  145489. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145490. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145491. JCOEFPTR coef_block,
  145492. JSAMPARRAY output_buf, JDIMENSION output_col));
  145493. struct jpeg_inverse_dct {
  145494. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145495. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145496. };
  145497. struct jpeg_upsampler {
  145498. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145499. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145500. JSAMPIMAGE input_buf,
  145501. JDIMENSION *in_row_group_ctr,
  145502. JDIMENSION in_row_groups_avail,
  145503. JSAMPARRAY output_buf,
  145504. JDIMENSION *out_row_ctr,
  145505. JDIMENSION out_rows_avail));
  145506. boolean need_context_rows; /* TRUE if need rows above & below */
  145507. };
  145508. struct jpeg_color_deconverter {
  145509. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145510. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145511. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145512. JSAMPARRAY output_buf, int num_rows));
  145513. };
  145514. struct jpeg_color_quantizer {
  145515. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145516. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145517. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145518. int num_rows));
  145519. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145520. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145521. };
  145522. #undef MAX
  145523. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145524. #undef MIN
  145525. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145526. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145527. #define SHIFT_TEMPS INT32 shift_temp;
  145528. #define RIGHT_SHIFT(x,shft) \
  145529. ((shift_temp = (x)) < 0 ? \
  145530. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145531. (shift_temp >> (shft)))
  145532. #else
  145533. #define SHIFT_TEMPS
  145534. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145535. #endif
  145536. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145537. #define jinit_compress_master jICompress
  145538. #define jinit_c_master_control jICMaster
  145539. #define jinit_c_main_controller jICMainC
  145540. #define jinit_c_prep_controller jICPrepC
  145541. #define jinit_c_coef_controller jICCoefC
  145542. #define jinit_color_converter jICColor
  145543. #define jinit_downsampler jIDownsampler
  145544. #define jinit_forward_dct jIFDCT
  145545. #define jinit_huff_encoder jIHEncoder
  145546. #define jinit_phuff_encoder jIPHEncoder
  145547. #define jinit_marker_writer jIMWriter
  145548. #define jinit_master_decompress jIDMaster
  145549. #define jinit_d_main_controller jIDMainC
  145550. #define jinit_d_coef_controller jIDCoefC
  145551. #define jinit_d_post_controller jIDPostC
  145552. #define jinit_input_controller jIInCtlr
  145553. #define jinit_marker_reader jIMReader
  145554. #define jinit_huff_decoder jIHDecoder
  145555. #define jinit_phuff_decoder jIPHDecoder
  145556. #define jinit_inverse_dct jIIDCT
  145557. #define jinit_upsampler jIUpsampler
  145558. #define jinit_color_deconverter jIDColor
  145559. #define jinit_1pass_quantizer jI1Quant
  145560. #define jinit_2pass_quantizer jI2Quant
  145561. #define jinit_merged_upsampler jIMUpsampler
  145562. #define jinit_memory_mgr jIMemMgr
  145563. #define jdiv_round_up jDivRound
  145564. #define jround_up jRound
  145565. #define jcopy_sample_rows jCopySamples
  145566. #define jcopy_block_row jCopyBlocks
  145567. #define jzero_far jZeroFar
  145568. #define jpeg_zigzag_order jZIGTable
  145569. #define jpeg_natural_order jZAGTable
  145570. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145571. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145572. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145573. boolean transcode_only));
  145574. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145575. boolean need_full_buffer));
  145576. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145577. boolean need_full_buffer));
  145578. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145579. boolean need_full_buffer));
  145580. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145581. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145582. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145583. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145584. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145585. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145586. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145587. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145588. boolean need_full_buffer));
  145589. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145590. boolean need_full_buffer));
  145591. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145592. boolean need_full_buffer));
  145593. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145594. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145595. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145596. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145597. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145598. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145599. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145600. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145601. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145602. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145603. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145604. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145605. EXTERN(long) jround_up JPP((long a, long b));
  145606. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145607. JSAMPARRAY output_array, int dest_row,
  145608. int num_rows, JDIMENSION num_cols));
  145609. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145610. JDIMENSION num_blocks));
  145611. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145612. #if 0 /* This table is not actually needed in v6a */
  145613. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145614. #endif
  145615. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145616. #ifdef INCOMPLETE_TYPES_BROKEN
  145617. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145618. struct jvirt_sarray_control { long dummy; };
  145619. struct jvirt_barray_control { long dummy; };
  145620. #endif
  145621. #endif /* INCOMPLETE_TYPES_BROKEN */
  145622. /*** End of inlined file: jpegint.h ***/
  145623. /* fetch private declarations */
  145624. /*** Start of inlined file: jerror.h ***/
  145625. #ifndef JMESSAGE
  145626. #ifndef JERROR_H
  145627. #define JMAKE_ENUM_LIST
  145628. #else
  145629. #define JMESSAGE(code,string)
  145630. #endif /* JERROR_H */
  145631. #endif /* JMESSAGE */
  145632. #ifdef JMAKE_ENUM_LIST
  145633. typedef enum {
  145634. #define JMESSAGE(code,string) code ,
  145635. #endif /* JMAKE_ENUM_LIST */
  145636. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145637. JMESSAGE(JERR_ARITH_NOTIMPL,
  145638. "Sorry, there are legal restrictions on arithmetic coding")
  145639. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145640. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145641. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145642. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145643. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145644. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145645. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145646. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145647. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145648. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145649. JMESSAGE(JERR_BAD_LIB_VERSION,
  145650. "Wrong JPEG library version: library is %d, caller expects %d")
  145651. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145652. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145653. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145654. JMESSAGE(JERR_BAD_PROGRESSION,
  145655. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145656. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145657. "Invalid progressive parameters at scan script entry %d")
  145658. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145659. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145660. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145661. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145662. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145663. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145664. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145665. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145666. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145667. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145668. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145669. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  145670. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  145671. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  145672. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  145673. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  145674. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  145675. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  145676. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  145677. JMESSAGE(JERR_FILE_READ, "Input file read error")
  145678. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  145679. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  145680. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  145681. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  145682. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  145683. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  145684. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  145685. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  145686. "Cannot transcode due to multiple use of quantization table %d")
  145687. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  145688. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  145689. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  145690. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  145691. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  145692. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  145693. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  145694. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  145695. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  145696. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  145697. JMESSAGE(JERR_QUANT_COMPONENTS,
  145698. "Cannot quantize more than %d color components")
  145699. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  145700. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  145701. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  145702. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  145703. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  145704. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  145705. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  145706. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  145707. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  145708. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  145709. JMESSAGE(JERR_TFILE_WRITE,
  145710. "Write failed on temporary file --- out of disk space?")
  145711. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  145712. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  145713. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  145714. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  145715. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  145716. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  145717. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  145718. JMESSAGE(JMSG_VERSION, JVERSION)
  145719. JMESSAGE(JTRC_16BIT_TABLES,
  145720. "Caution: quantization tables are too coarse for baseline JPEG")
  145721. JMESSAGE(JTRC_ADOBE,
  145722. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  145723. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  145724. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  145725. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  145726. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  145727. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  145728. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  145729. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  145730. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  145731. JMESSAGE(JTRC_EOI, "End Of Image")
  145732. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  145733. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  145734. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  145735. "Warning: thumbnail image size does not match data length %u")
  145736. JMESSAGE(JTRC_JFIF_EXTENSION,
  145737. "JFIF extension marker: type 0x%02x, length %u")
  145738. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  145739. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  145740. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  145741. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  145742. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  145743. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  145744. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  145745. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  145746. JMESSAGE(JTRC_RST, "RST%d")
  145747. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  145748. "Smoothing not supported with nonstandard sampling ratios")
  145749. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  145750. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  145751. JMESSAGE(JTRC_SOI, "Start of Image")
  145752. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  145753. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  145754. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  145755. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  145756. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  145757. JMESSAGE(JTRC_THUMB_JPEG,
  145758. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  145759. JMESSAGE(JTRC_THUMB_PALETTE,
  145760. "JFIF extension marker: palette thumbnail image, length %u")
  145761. JMESSAGE(JTRC_THUMB_RGB,
  145762. "JFIF extension marker: RGB thumbnail image, length %u")
  145763. JMESSAGE(JTRC_UNKNOWN_IDS,
  145764. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  145765. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  145766. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  145767. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  145768. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  145769. "Inconsistent progression sequence for component %d coefficient %d")
  145770. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  145771. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  145772. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  145773. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  145774. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  145775. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  145776. JMESSAGE(JWRN_MUST_RESYNC,
  145777. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  145778. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  145779. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  145780. #ifdef JMAKE_ENUM_LIST
  145781. JMSG_LASTMSGCODE
  145782. } J_MESSAGE_CODE;
  145783. #undef JMAKE_ENUM_LIST
  145784. #endif /* JMAKE_ENUM_LIST */
  145785. #undef JMESSAGE
  145786. #ifndef JERROR_H
  145787. #define JERROR_H
  145788. #define ERREXIT(cinfo,code) \
  145789. ((cinfo)->err->msg_code = (code), \
  145790. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145791. #define ERREXIT1(cinfo,code,p1) \
  145792. ((cinfo)->err->msg_code = (code), \
  145793. (cinfo)->err->msg_parm.i[0] = (p1), \
  145794. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145795. #define ERREXIT2(cinfo,code,p1,p2) \
  145796. ((cinfo)->err->msg_code = (code), \
  145797. (cinfo)->err->msg_parm.i[0] = (p1), \
  145798. (cinfo)->err->msg_parm.i[1] = (p2), \
  145799. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145800. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  145801. ((cinfo)->err->msg_code = (code), \
  145802. (cinfo)->err->msg_parm.i[0] = (p1), \
  145803. (cinfo)->err->msg_parm.i[1] = (p2), \
  145804. (cinfo)->err->msg_parm.i[2] = (p3), \
  145805. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145806. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  145807. ((cinfo)->err->msg_code = (code), \
  145808. (cinfo)->err->msg_parm.i[0] = (p1), \
  145809. (cinfo)->err->msg_parm.i[1] = (p2), \
  145810. (cinfo)->err->msg_parm.i[2] = (p3), \
  145811. (cinfo)->err->msg_parm.i[3] = (p4), \
  145812. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145813. #define ERREXITS(cinfo,code,str) \
  145814. ((cinfo)->err->msg_code = (code), \
  145815. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145816. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145817. #define MAKESTMT(stuff) do { stuff } while (0)
  145818. #define WARNMS(cinfo,code) \
  145819. ((cinfo)->err->msg_code = (code), \
  145820. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145821. #define WARNMS1(cinfo,code,p1) \
  145822. ((cinfo)->err->msg_code = (code), \
  145823. (cinfo)->err->msg_parm.i[0] = (p1), \
  145824. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145825. #define WARNMS2(cinfo,code,p1,p2) \
  145826. ((cinfo)->err->msg_code = (code), \
  145827. (cinfo)->err->msg_parm.i[0] = (p1), \
  145828. (cinfo)->err->msg_parm.i[1] = (p2), \
  145829. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145830. #define TRACEMS(cinfo,lvl,code) \
  145831. ((cinfo)->err->msg_code = (code), \
  145832. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145833. #define TRACEMS1(cinfo,lvl,code,p1) \
  145834. ((cinfo)->err->msg_code = (code), \
  145835. (cinfo)->err->msg_parm.i[0] = (p1), \
  145836. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145837. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  145838. ((cinfo)->err->msg_code = (code), \
  145839. (cinfo)->err->msg_parm.i[0] = (p1), \
  145840. (cinfo)->err->msg_parm.i[1] = (p2), \
  145841. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145842. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  145843. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145844. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  145845. (cinfo)->err->msg_code = (code); \
  145846. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145847. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  145848. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145849. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145850. (cinfo)->err->msg_code = (code); \
  145851. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145852. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  145853. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145854. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145855. _mp[4] = (p5); \
  145856. (cinfo)->err->msg_code = (code); \
  145857. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145858. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  145859. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145860. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145861. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  145862. (cinfo)->err->msg_code = (code); \
  145863. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145864. #define TRACEMSS(cinfo,lvl,code,str) \
  145865. ((cinfo)->err->msg_code = (code), \
  145866. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145867. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145868. #endif /* JERROR_H */
  145869. /*** End of inlined file: jerror.h ***/
  145870. /* fetch error codes too */
  145871. #endif
  145872. #endif /* JPEGLIB_H */
  145873. /*** End of inlined file: jpeglib.h ***/
  145874. /*** Start of inlined file: jcapimin.c ***/
  145875. #define JPEG_INTERNALS
  145876. /*** Start of inlined file: jinclude.h ***/
  145877. #ifndef __jinclude_h__
  145878. #define __jinclude_h__
  145879. /*** Start of inlined file: jconfig.h ***/
  145880. // disable all the warnings under MSVC
  145881. #ifdef _MSC_VER
  145882. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  145883. #endif
  145884. #ifdef __BORLANDC__
  145885. #pragma warn -8057
  145886. #pragma warn -8019
  145887. #pragma warn -8004
  145888. #pragma warn -8008
  145889. #endif
  145890. #define HAVE_PROTOTYPES
  145891. #define HAVE_UNSIGNED_CHAR
  145892. #define HAVE_UNSIGNED_SHORT
  145893. #undef CHAR_IS_UNSIGNED
  145894. #define HAVE_STDDEF_H
  145895. #define HAVE_STDLIB_H
  145896. #undef NEED_BSD_STRINGS
  145897. #undef NEED_SYS_TYPES_H
  145898. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  145899. #undef NEED_SHORT_EXTERNAL_NAMES
  145900. #undef INCOMPLETE_TYPES_BROKEN
  145901. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  145902. typedef unsigned char boolean;
  145903. #endif
  145904. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  145905. #ifdef JPEG_INTERNALS
  145906. #undef RIGHT_SHIFT_IS_UNSIGNED
  145907. #endif /* JPEG_INTERNALS */
  145908. #ifdef JPEG_CJPEG_DJPEG
  145909. #define BMP_SUPPORTED /* BMP image file format */
  145910. #define GIF_SUPPORTED /* GIF image file format */
  145911. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  145912. #undef RLE_SUPPORTED /* Utah RLE image file format */
  145913. #define TARGA_SUPPORTED /* Targa image file format */
  145914. #define TWO_FILE_COMMANDLINE /* optional */
  145915. #define USE_SETMODE /* Microsoft has setmode() */
  145916. #undef NEED_SIGNAL_CATCHER
  145917. #undef DONT_USE_B_MODE
  145918. #undef PROGRESS_REPORT /* optional */
  145919. #endif /* JPEG_CJPEG_DJPEG */
  145920. /*** End of inlined file: jconfig.h ***/
  145921. /* auto configuration options */
  145922. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  145923. #ifdef HAVE_STDDEF_H
  145924. #include <stddef.h>
  145925. #endif
  145926. #ifdef HAVE_STDLIB_H
  145927. #include <stdlib.h>
  145928. #endif
  145929. #ifdef NEED_SYS_TYPES_H
  145930. #include <sys/types.h>
  145931. #endif
  145932. #include <stdio.h>
  145933. #ifdef NEED_BSD_STRINGS
  145934. #include <strings.h>
  145935. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  145936. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  145937. #else /* not BSD, assume ANSI/SysV string lib */
  145938. #include <string.h>
  145939. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  145940. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  145941. #endif
  145942. #define SIZEOF(object) ((size_t) sizeof(object))
  145943. #define JFREAD(file,buf,sizeofbuf) \
  145944. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145945. #define JFWRITE(file,buf,sizeofbuf) \
  145946. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145947. typedef enum { /* JPEG marker codes */
  145948. M_SOF0 = 0xc0,
  145949. M_SOF1 = 0xc1,
  145950. M_SOF2 = 0xc2,
  145951. M_SOF3 = 0xc3,
  145952. M_SOF5 = 0xc5,
  145953. M_SOF6 = 0xc6,
  145954. M_SOF7 = 0xc7,
  145955. M_JPG = 0xc8,
  145956. M_SOF9 = 0xc9,
  145957. M_SOF10 = 0xca,
  145958. M_SOF11 = 0xcb,
  145959. M_SOF13 = 0xcd,
  145960. M_SOF14 = 0xce,
  145961. M_SOF15 = 0xcf,
  145962. M_DHT = 0xc4,
  145963. M_DAC = 0xcc,
  145964. M_RST0 = 0xd0,
  145965. M_RST1 = 0xd1,
  145966. M_RST2 = 0xd2,
  145967. M_RST3 = 0xd3,
  145968. M_RST4 = 0xd4,
  145969. M_RST5 = 0xd5,
  145970. M_RST6 = 0xd6,
  145971. M_RST7 = 0xd7,
  145972. M_SOI = 0xd8,
  145973. M_EOI = 0xd9,
  145974. M_SOS = 0xda,
  145975. M_DQT = 0xdb,
  145976. M_DNL = 0xdc,
  145977. M_DRI = 0xdd,
  145978. M_DHP = 0xde,
  145979. M_EXP = 0xdf,
  145980. M_APP0 = 0xe0,
  145981. M_APP1 = 0xe1,
  145982. M_APP2 = 0xe2,
  145983. M_APP3 = 0xe3,
  145984. M_APP4 = 0xe4,
  145985. M_APP5 = 0xe5,
  145986. M_APP6 = 0xe6,
  145987. M_APP7 = 0xe7,
  145988. M_APP8 = 0xe8,
  145989. M_APP9 = 0xe9,
  145990. M_APP10 = 0xea,
  145991. M_APP11 = 0xeb,
  145992. M_APP12 = 0xec,
  145993. M_APP13 = 0xed,
  145994. M_APP14 = 0xee,
  145995. M_APP15 = 0xef,
  145996. M_JPG0 = 0xf0,
  145997. M_JPG13 = 0xfd,
  145998. M_COM = 0xfe,
  145999. M_TEM = 0x01,
  146000. M_ERROR = 0x100
  146001. } JPEG_MARKER;
  146002. #ifdef AVOID_TABLES
  146003. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  146004. #else
  146005. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  146006. static const int extend_test[16] = /* entry n is 2**(n-1) */
  146007. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  146008. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  146009. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  146010. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  146011. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  146012. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  146013. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  146014. #endif /* AVOID_TABLES */
  146015. #endif
  146016. /*** End of inlined file: jinclude.h ***/
  146017. GLOBAL(void)
  146018. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  146019. {
  146020. int i;
  146021. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  146022. if (version != JPEG_LIB_VERSION)
  146023. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  146024. if (structsize != SIZEOF(struct jpeg_compress_struct))
  146025. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  146026. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  146027. {
  146028. struct jpeg_error_mgr * err = cinfo->err;
  146029. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  146030. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  146031. cinfo->err = err;
  146032. cinfo->client_data = client_data;
  146033. }
  146034. cinfo->is_decompressor = FALSE;
  146035. jinit_memory_mgr((j_common_ptr) cinfo);
  146036. cinfo->progress = NULL;
  146037. cinfo->dest = NULL;
  146038. cinfo->comp_info = NULL;
  146039. for (i = 0; i < NUM_QUANT_TBLS; i++)
  146040. cinfo->quant_tbl_ptrs[i] = NULL;
  146041. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146042. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  146043. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  146044. }
  146045. cinfo->script_space = NULL;
  146046. cinfo->input_gamma = 1.0; /* in case application forgets */
  146047. cinfo->global_state = CSTATE_START;
  146048. }
  146049. GLOBAL(void)
  146050. jpeg_destroy_compress (j_compress_ptr cinfo)
  146051. {
  146052. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  146053. }
  146054. GLOBAL(void)
  146055. jpeg_abort_compress (j_compress_ptr cinfo)
  146056. {
  146057. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  146058. }
  146059. GLOBAL(void)
  146060. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  146061. {
  146062. int i;
  146063. JQUANT_TBL * qtbl;
  146064. JHUFF_TBL * htbl;
  146065. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146066. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  146067. qtbl->sent_table = suppress;
  146068. }
  146069. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146070. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  146071. htbl->sent_table = suppress;
  146072. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  146073. htbl->sent_table = suppress;
  146074. }
  146075. }
  146076. GLOBAL(void)
  146077. jpeg_finish_compress (j_compress_ptr cinfo)
  146078. {
  146079. JDIMENSION iMCU_row;
  146080. if (cinfo->global_state == CSTATE_SCANNING ||
  146081. cinfo->global_state == CSTATE_RAW_OK) {
  146082. if (cinfo->next_scanline < cinfo->image_height)
  146083. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  146084. (*cinfo->master->finish_pass) (cinfo);
  146085. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  146086. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146087. while (! cinfo->master->is_last_pass) {
  146088. (*cinfo->master->prepare_for_pass) (cinfo);
  146089. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  146090. if (cinfo->progress != NULL) {
  146091. cinfo->progress->pass_counter = (long) iMCU_row;
  146092. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  146093. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146094. }
  146095. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  146096. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  146097. }
  146098. (*cinfo->master->finish_pass) (cinfo);
  146099. }
  146100. (*cinfo->marker->write_file_trailer) (cinfo);
  146101. (*cinfo->dest->term_destination) (cinfo);
  146102. jpeg_abort((j_common_ptr) cinfo);
  146103. }
  146104. GLOBAL(void)
  146105. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  146106. const JOCTET *dataptr, unsigned int datalen)
  146107. {
  146108. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  146109. if (cinfo->next_scanline != 0 ||
  146110. (cinfo->global_state != CSTATE_SCANNING &&
  146111. cinfo->global_state != CSTATE_RAW_OK &&
  146112. cinfo->global_state != CSTATE_WRCOEFS))
  146113. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146114. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146115. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  146116. while (datalen--) {
  146117. (*write_marker_byte) (cinfo, *dataptr);
  146118. dataptr++;
  146119. }
  146120. }
  146121. GLOBAL(void)
  146122. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  146123. {
  146124. if (cinfo->next_scanline != 0 ||
  146125. (cinfo->global_state != CSTATE_SCANNING &&
  146126. cinfo->global_state != CSTATE_RAW_OK &&
  146127. cinfo->global_state != CSTATE_WRCOEFS))
  146128. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146129. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146130. }
  146131. GLOBAL(void)
  146132. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  146133. {
  146134. (*cinfo->marker->write_marker_byte) (cinfo, val);
  146135. }
  146136. GLOBAL(void)
  146137. jpeg_write_tables (j_compress_ptr cinfo)
  146138. {
  146139. if (cinfo->global_state != CSTATE_START)
  146140. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146141. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146142. (*cinfo->dest->init_destination) (cinfo);
  146143. jinit_marker_writer(cinfo);
  146144. (*cinfo->marker->write_tables_only) (cinfo);
  146145. (*cinfo->dest->term_destination) (cinfo);
  146146. }
  146147. /*** End of inlined file: jcapimin.c ***/
  146148. /*** Start of inlined file: jcapistd.c ***/
  146149. #define JPEG_INTERNALS
  146150. GLOBAL(void)
  146151. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  146152. {
  146153. if (cinfo->global_state != CSTATE_START)
  146154. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146155. if (write_all_tables)
  146156. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  146157. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146158. (*cinfo->dest->init_destination) (cinfo);
  146159. jinit_compress_master(cinfo);
  146160. (*cinfo->master->prepare_for_pass) (cinfo);
  146161. cinfo->next_scanline = 0;
  146162. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  146163. }
  146164. GLOBAL(JDIMENSION)
  146165. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  146166. JDIMENSION num_lines)
  146167. {
  146168. JDIMENSION row_ctr, rows_left;
  146169. if (cinfo->global_state != CSTATE_SCANNING)
  146170. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146171. if (cinfo->next_scanline >= cinfo->image_height)
  146172. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146173. if (cinfo->progress != NULL) {
  146174. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146175. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146176. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146177. }
  146178. if (cinfo->master->call_pass_startup)
  146179. (*cinfo->master->pass_startup) (cinfo);
  146180. rows_left = cinfo->image_height - cinfo->next_scanline;
  146181. if (num_lines > rows_left)
  146182. num_lines = rows_left;
  146183. row_ctr = 0;
  146184. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  146185. cinfo->next_scanline += row_ctr;
  146186. return row_ctr;
  146187. }
  146188. GLOBAL(JDIMENSION)
  146189. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  146190. JDIMENSION num_lines)
  146191. {
  146192. JDIMENSION lines_per_iMCU_row;
  146193. if (cinfo->global_state != CSTATE_RAW_OK)
  146194. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146195. if (cinfo->next_scanline >= cinfo->image_height) {
  146196. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146197. return 0;
  146198. }
  146199. if (cinfo->progress != NULL) {
  146200. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146201. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146202. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146203. }
  146204. if (cinfo->master->call_pass_startup)
  146205. (*cinfo->master->pass_startup) (cinfo);
  146206. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  146207. if (num_lines < lines_per_iMCU_row)
  146208. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  146209. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  146210. return 0;
  146211. }
  146212. cinfo->next_scanline += lines_per_iMCU_row;
  146213. return lines_per_iMCU_row;
  146214. }
  146215. /*** End of inlined file: jcapistd.c ***/
  146216. /*** Start of inlined file: jccoefct.c ***/
  146217. #define JPEG_INTERNALS
  146218. #ifdef ENTROPY_OPT_SUPPORTED
  146219. #define FULL_COEF_BUFFER_SUPPORTED
  146220. #else
  146221. #ifdef C_MULTISCAN_FILES_SUPPORTED
  146222. #define FULL_COEF_BUFFER_SUPPORTED
  146223. #endif
  146224. #endif
  146225. typedef struct {
  146226. struct jpeg_c_coef_controller pub; /* public fields */
  146227. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  146228. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  146229. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  146230. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  146231. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  146232. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  146233. } my_coef_controller;
  146234. typedef my_coef_controller * my_coef_ptr;
  146235. METHODDEF(boolean) compress_data
  146236. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146237. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146238. METHODDEF(boolean) compress_first_pass
  146239. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146240. METHODDEF(boolean) compress_output
  146241. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146242. #endif
  146243. LOCAL(void)
  146244. start_iMCU_row (j_compress_ptr cinfo)
  146245. {
  146246. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146247. if (cinfo->comps_in_scan > 1) {
  146248. coef->MCU_rows_per_iMCU_row = 1;
  146249. } else {
  146250. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  146251. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  146252. else
  146253. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  146254. }
  146255. coef->mcu_ctr = 0;
  146256. coef->MCU_vert_offset = 0;
  146257. }
  146258. METHODDEF(void)
  146259. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  146260. {
  146261. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146262. coef->iMCU_row_num = 0;
  146263. start_iMCU_row(cinfo);
  146264. switch (pass_mode) {
  146265. case JBUF_PASS_THRU:
  146266. if (coef->whole_image[0] != NULL)
  146267. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146268. coef->pub.compress_data = compress_data;
  146269. break;
  146270. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146271. case JBUF_SAVE_AND_PASS:
  146272. if (coef->whole_image[0] == NULL)
  146273. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146274. coef->pub.compress_data = compress_first_pass;
  146275. break;
  146276. case JBUF_CRANK_DEST:
  146277. if (coef->whole_image[0] == NULL)
  146278. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146279. coef->pub.compress_data = compress_output;
  146280. break;
  146281. #endif
  146282. default:
  146283. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146284. break;
  146285. }
  146286. }
  146287. METHODDEF(boolean)
  146288. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146289. {
  146290. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146291. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146292. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146293. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146294. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146295. JDIMENSION ypos, xpos;
  146296. jpeg_component_info *compptr;
  146297. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146298. yoffset++) {
  146299. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146300. MCU_col_num++) {
  146301. blkn = 0;
  146302. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146303. compptr = cinfo->cur_comp_info[ci];
  146304. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146305. : compptr->last_col_width;
  146306. xpos = MCU_col_num * compptr->MCU_sample_width;
  146307. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146308. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146309. if (coef->iMCU_row_num < last_iMCU_row ||
  146310. yoffset+yindex < compptr->last_row_height) {
  146311. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146312. input_buf[compptr->component_index],
  146313. coef->MCU_buffer[blkn],
  146314. ypos, xpos, (JDIMENSION) blockcnt);
  146315. if (blockcnt < compptr->MCU_width) {
  146316. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146317. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146318. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146319. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146320. }
  146321. }
  146322. } else {
  146323. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146324. compptr->MCU_width * SIZEOF(JBLOCK));
  146325. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146326. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146327. }
  146328. }
  146329. blkn += compptr->MCU_width;
  146330. ypos += DCTSIZE;
  146331. }
  146332. }
  146333. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146334. coef->MCU_vert_offset = yoffset;
  146335. coef->mcu_ctr = MCU_col_num;
  146336. return FALSE;
  146337. }
  146338. }
  146339. coef->mcu_ctr = 0;
  146340. }
  146341. coef->iMCU_row_num++;
  146342. start_iMCU_row(cinfo);
  146343. return TRUE;
  146344. }
  146345. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146346. METHODDEF(boolean)
  146347. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146348. {
  146349. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146350. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146351. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146352. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146353. JCOEF lastDC;
  146354. jpeg_component_info *compptr;
  146355. JBLOCKARRAY buffer;
  146356. JBLOCKROW thisblockrow, lastblockrow;
  146357. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146358. ci++, compptr++) {
  146359. buffer = (*cinfo->mem->access_virt_barray)
  146360. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146361. coef->iMCU_row_num * compptr->v_samp_factor,
  146362. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146363. if (coef->iMCU_row_num < last_iMCU_row)
  146364. block_rows = compptr->v_samp_factor;
  146365. else {
  146366. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146367. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146368. }
  146369. blocks_across = compptr->width_in_blocks;
  146370. h_samp_factor = compptr->h_samp_factor;
  146371. ndummy = (int) (blocks_across % h_samp_factor);
  146372. if (ndummy > 0)
  146373. ndummy = h_samp_factor - ndummy;
  146374. for (block_row = 0; block_row < block_rows; block_row++) {
  146375. thisblockrow = buffer[block_row];
  146376. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146377. input_buf[ci], thisblockrow,
  146378. (JDIMENSION) (block_row * DCTSIZE),
  146379. (JDIMENSION) 0, blocks_across);
  146380. if (ndummy > 0) {
  146381. thisblockrow += blocks_across; /* => first dummy block */
  146382. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  146383. lastDC = thisblockrow[-1][0];
  146384. for (bi = 0; bi < ndummy; bi++) {
  146385. thisblockrow[bi][0] = lastDC;
  146386. }
  146387. }
  146388. }
  146389. if (coef->iMCU_row_num == last_iMCU_row) {
  146390. blocks_across += ndummy; /* include lower right corner */
  146391. MCUs_across = blocks_across / h_samp_factor;
  146392. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146393. block_row++) {
  146394. thisblockrow = buffer[block_row];
  146395. lastblockrow = buffer[block_row-1];
  146396. jzero_far((void FAR *) thisblockrow,
  146397. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146398. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146399. lastDC = lastblockrow[h_samp_factor-1][0];
  146400. for (bi = 0; bi < h_samp_factor; bi++) {
  146401. thisblockrow[bi][0] = lastDC;
  146402. }
  146403. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146404. lastblockrow += h_samp_factor;
  146405. }
  146406. }
  146407. }
  146408. }
  146409. return compress_output(cinfo, input_buf);
  146410. }
  146411. METHODDEF(boolean)
  146412. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146413. {
  146414. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146415. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146416. int blkn, ci, xindex, yindex, yoffset;
  146417. JDIMENSION start_col;
  146418. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146419. JBLOCKROW buffer_ptr;
  146420. jpeg_component_info *compptr;
  146421. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146422. compptr = cinfo->cur_comp_info[ci];
  146423. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146424. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146425. coef->iMCU_row_num * compptr->v_samp_factor,
  146426. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146427. }
  146428. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146429. yoffset++) {
  146430. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146431. MCU_col_num++) {
  146432. blkn = 0; /* index of current DCT block within MCU */
  146433. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146434. compptr = cinfo->cur_comp_info[ci];
  146435. start_col = MCU_col_num * compptr->MCU_width;
  146436. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146437. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146438. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146439. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146440. }
  146441. }
  146442. }
  146443. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146444. coef->MCU_vert_offset = yoffset;
  146445. coef->mcu_ctr = MCU_col_num;
  146446. return FALSE;
  146447. }
  146448. }
  146449. coef->mcu_ctr = 0;
  146450. }
  146451. coef->iMCU_row_num++;
  146452. start_iMCU_row(cinfo);
  146453. return TRUE;
  146454. }
  146455. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146456. GLOBAL(void)
  146457. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146458. {
  146459. my_coef_ptr coef;
  146460. coef = (my_coef_ptr)
  146461. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146462. SIZEOF(my_coef_controller));
  146463. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146464. coef->pub.start_pass = start_pass_coef;
  146465. if (need_full_buffer) {
  146466. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146467. int ci;
  146468. jpeg_component_info *compptr;
  146469. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146470. ci++, compptr++) {
  146471. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146472. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146473. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146474. (long) compptr->h_samp_factor),
  146475. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146476. (long) compptr->v_samp_factor),
  146477. (JDIMENSION) compptr->v_samp_factor);
  146478. }
  146479. #else
  146480. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146481. #endif
  146482. } else {
  146483. JBLOCKROW buffer;
  146484. int i;
  146485. buffer = (JBLOCKROW)
  146486. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146487. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146488. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146489. coef->MCU_buffer[i] = buffer + i;
  146490. }
  146491. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146492. }
  146493. }
  146494. /*** End of inlined file: jccoefct.c ***/
  146495. /*** Start of inlined file: jccolor.c ***/
  146496. #define JPEG_INTERNALS
  146497. typedef struct {
  146498. struct jpeg_color_converter pub; /* public fields */
  146499. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146500. } my_color_converter;
  146501. typedef my_color_converter * my_cconvert_ptr;
  146502. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146503. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146504. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146505. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146506. #define R_Y_OFF 0 /* offset to R => Y section */
  146507. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146508. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146509. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146510. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146511. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146512. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146513. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146514. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146515. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146516. METHODDEF(void)
  146517. rgb_ycc_start (j_compress_ptr cinfo)
  146518. {
  146519. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146520. INT32 * rgb_ycc_tab;
  146521. INT32 i;
  146522. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146523. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146524. (TABLE_SIZE * SIZEOF(INT32)));
  146525. for (i = 0; i <= MAXJSAMPLE; i++) {
  146526. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146527. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146528. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146529. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146530. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146531. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146532. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146533. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146534. }
  146535. }
  146536. METHODDEF(void)
  146537. rgb_ycc_convert (j_compress_ptr cinfo,
  146538. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146539. JDIMENSION output_row, int num_rows)
  146540. {
  146541. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146542. register int r, g, b;
  146543. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146544. register JSAMPROW inptr;
  146545. register JSAMPROW outptr0, outptr1, outptr2;
  146546. register JDIMENSION col;
  146547. JDIMENSION num_cols = cinfo->image_width;
  146548. while (--num_rows >= 0) {
  146549. inptr = *input_buf++;
  146550. outptr0 = output_buf[0][output_row];
  146551. outptr1 = output_buf[1][output_row];
  146552. outptr2 = output_buf[2][output_row];
  146553. output_row++;
  146554. for (col = 0; col < num_cols; col++) {
  146555. r = GETJSAMPLE(inptr[RGB_RED]);
  146556. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146557. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146558. inptr += RGB_PIXELSIZE;
  146559. outptr0[col] = (JSAMPLE)
  146560. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146561. >> SCALEBITS);
  146562. outptr1[col] = (JSAMPLE)
  146563. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146564. >> SCALEBITS);
  146565. outptr2[col] = (JSAMPLE)
  146566. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146567. >> SCALEBITS);
  146568. }
  146569. }
  146570. }
  146571. METHODDEF(void)
  146572. rgb_gray_convert (j_compress_ptr cinfo,
  146573. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146574. JDIMENSION output_row, int num_rows)
  146575. {
  146576. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146577. register int r, g, b;
  146578. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146579. register JSAMPROW inptr;
  146580. register JSAMPROW outptr;
  146581. register JDIMENSION col;
  146582. JDIMENSION num_cols = cinfo->image_width;
  146583. while (--num_rows >= 0) {
  146584. inptr = *input_buf++;
  146585. outptr = output_buf[0][output_row];
  146586. output_row++;
  146587. for (col = 0; col < num_cols; col++) {
  146588. r = GETJSAMPLE(inptr[RGB_RED]);
  146589. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146590. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146591. inptr += RGB_PIXELSIZE;
  146592. outptr[col] = (JSAMPLE)
  146593. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146594. >> SCALEBITS);
  146595. }
  146596. }
  146597. }
  146598. METHODDEF(void)
  146599. cmyk_ycck_convert (j_compress_ptr cinfo,
  146600. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146601. JDIMENSION output_row, int num_rows)
  146602. {
  146603. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146604. register int r, g, b;
  146605. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146606. register JSAMPROW inptr;
  146607. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  146608. register JDIMENSION col;
  146609. JDIMENSION num_cols = cinfo->image_width;
  146610. while (--num_rows >= 0) {
  146611. inptr = *input_buf++;
  146612. outptr0 = output_buf[0][output_row];
  146613. outptr1 = output_buf[1][output_row];
  146614. outptr2 = output_buf[2][output_row];
  146615. outptr3 = output_buf[3][output_row];
  146616. output_row++;
  146617. for (col = 0; col < num_cols; col++) {
  146618. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146619. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146620. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146621. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146622. inptr += 4;
  146623. outptr0[col] = (JSAMPLE)
  146624. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146625. >> SCALEBITS);
  146626. outptr1[col] = (JSAMPLE)
  146627. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146628. >> SCALEBITS);
  146629. outptr2[col] = (JSAMPLE)
  146630. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146631. >> SCALEBITS);
  146632. }
  146633. }
  146634. }
  146635. METHODDEF(void)
  146636. grayscale_convert (j_compress_ptr cinfo,
  146637. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146638. JDIMENSION output_row, int num_rows)
  146639. {
  146640. register JSAMPROW inptr;
  146641. register JSAMPROW outptr;
  146642. register JDIMENSION col;
  146643. JDIMENSION num_cols = cinfo->image_width;
  146644. int instride = cinfo->input_components;
  146645. while (--num_rows >= 0) {
  146646. inptr = *input_buf++;
  146647. outptr = output_buf[0][output_row];
  146648. output_row++;
  146649. for (col = 0; col < num_cols; col++) {
  146650. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146651. inptr += instride;
  146652. }
  146653. }
  146654. }
  146655. METHODDEF(void)
  146656. null_convert (j_compress_ptr cinfo,
  146657. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146658. JDIMENSION output_row, int num_rows)
  146659. {
  146660. register JSAMPROW inptr;
  146661. register JSAMPROW outptr;
  146662. register JDIMENSION col;
  146663. register int ci;
  146664. int nc = cinfo->num_components;
  146665. JDIMENSION num_cols = cinfo->image_width;
  146666. while (--num_rows >= 0) {
  146667. for (ci = 0; ci < nc; ci++) {
  146668. inptr = *input_buf;
  146669. outptr = output_buf[ci][output_row];
  146670. for (col = 0; col < num_cols; col++) {
  146671. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  146672. inptr += nc;
  146673. }
  146674. }
  146675. input_buf++;
  146676. output_row++;
  146677. }
  146678. }
  146679. METHODDEF(void)
  146680. null_method (j_compress_ptr cinfo)
  146681. {
  146682. }
  146683. GLOBAL(void)
  146684. jinit_color_converter (j_compress_ptr cinfo)
  146685. {
  146686. my_cconvert_ptr cconvert;
  146687. cconvert = (my_cconvert_ptr)
  146688. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146689. SIZEOF(my_color_converter));
  146690. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  146691. cconvert->pub.start_pass = null_method;
  146692. switch (cinfo->in_color_space) {
  146693. case JCS_GRAYSCALE:
  146694. if (cinfo->input_components != 1)
  146695. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146696. break;
  146697. case JCS_RGB:
  146698. #if RGB_PIXELSIZE != 3
  146699. if (cinfo->input_components != RGB_PIXELSIZE)
  146700. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146701. break;
  146702. #endif /* else share code with YCbCr */
  146703. case JCS_YCbCr:
  146704. if (cinfo->input_components != 3)
  146705. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146706. break;
  146707. case JCS_CMYK:
  146708. case JCS_YCCK:
  146709. if (cinfo->input_components != 4)
  146710. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146711. break;
  146712. default: /* JCS_UNKNOWN can be anything */
  146713. if (cinfo->input_components < 1)
  146714. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146715. break;
  146716. }
  146717. switch (cinfo->jpeg_color_space) {
  146718. case JCS_GRAYSCALE:
  146719. if (cinfo->num_components != 1)
  146720. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146721. if (cinfo->in_color_space == JCS_GRAYSCALE)
  146722. cconvert->pub.color_convert = grayscale_convert;
  146723. else if (cinfo->in_color_space == JCS_RGB) {
  146724. cconvert->pub.start_pass = rgb_ycc_start;
  146725. cconvert->pub.color_convert = rgb_gray_convert;
  146726. } else if (cinfo->in_color_space == JCS_YCbCr)
  146727. cconvert->pub.color_convert = grayscale_convert;
  146728. else
  146729. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146730. break;
  146731. case JCS_RGB:
  146732. if (cinfo->num_components != 3)
  146733. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146734. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  146735. cconvert->pub.color_convert = null_convert;
  146736. else
  146737. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146738. break;
  146739. case JCS_YCbCr:
  146740. if (cinfo->num_components != 3)
  146741. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146742. if (cinfo->in_color_space == JCS_RGB) {
  146743. cconvert->pub.start_pass = rgb_ycc_start;
  146744. cconvert->pub.color_convert = rgb_ycc_convert;
  146745. } else if (cinfo->in_color_space == JCS_YCbCr)
  146746. cconvert->pub.color_convert = null_convert;
  146747. else
  146748. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146749. break;
  146750. case JCS_CMYK:
  146751. if (cinfo->num_components != 4)
  146752. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146753. if (cinfo->in_color_space == JCS_CMYK)
  146754. cconvert->pub.color_convert = null_convert;
  146755. else
  146756. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146757. break;
  146758. case JCS_YCCK:
  146759. if (cinfo->num_components != 4)
  146760. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146761. if (cinfo->in_color_space == JCS_CMYK) {
  146762. cconvert->pub.start_pass = rgb_ycc_start;
  146763. cconvert->pub.color_convert = cmyk_ycck_convert;
  146764. } else if (cinfo->in_color_space == JCS_YCCK)
  146765. cconvert->pub.color_convert = null_convert;
  146766. else
  146767. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146768. break;
  146769. default: /* allow null conversion of JCS_UNKNOWN */
  146770. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  146771. cinfo->num_components != cinfo->input_components)
  146772. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146773. cconvert->pub.color_convert = null_convert;
  146774. break;
  146775. }
  146776. }
  146777. /*** End of inlined file: jccolor.c ***/
  146778. #undef FIX
  146779. /*** Start of inlined file: jcdctmgr.c ***/
  146780. #define JPEG_INTERNALS
  146781. /*** Start of inlined file: jdct.h ***/
  146782. #ifndef __jdct_h__
  146783. #define __jdct_h__
  146784. #if BITS_IN_JSAMPLE == 8
  146785. typedef int DCTELEM; /* 16 or 32 bits is fine */
  146786. #else
  146787. typedef INT32 DCTELEM; /* must have 32 bits */
  146788. #endif
  146789. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  146790. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  146791. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  146792. #if BITS_IN_JSAMPLE == 8
  146793. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  146794. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  146795. #else
  146796. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  146797. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  146798. #endif
  146799. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  146800. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  146801. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  146802. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146803. #define jpeg_fdct_islow jFDislow
  146804. #define jpeg_fdct_ifast jFDifast
  146805. #define jpeg_fdct_float jFDfloat
  146806. #define jpeg_idct_islow jRDislow
  146807. #define jpeg_idct_ifast jRDifast
  146808. #define jpeg_idct_float jRDfloat
  146809. #define jpeg_idct_4x4 jRD4x4
  146810. #define jpeg_idct_2x2 jRD2x2
  146811. #define jpeg_idct_1x1 jRD1x1
  146812. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146813. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  146814. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  146815. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  146816. EXTERN(void) jpeg_idct_islow
  146817. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146818. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146819. EXTERN(void) jpeg_idct_ifast
  146820. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146821. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146822. EXTERN(void) jpeg_idct_float
  146823. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146824. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146825. EXTERN(void) jpeg_idct_4x4
  146826. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146827. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146828. EXTERN(void) jpeg_idct_2x2
  146829. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146830. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146831. EXTERN(void) jpeg_idct_1x1
  146832. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146833. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146834. #define ONE ((INT32) 1)
  146835. #define CONST_SCALE (ONE << CONST_BITS)
  146836. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  146837. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  146838. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146839. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  146840. #endif
  146841. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  146842. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  146843. #endif
  146844. #ifndef MULTIPLY16C16 /* default definition */
  146845. #define MULTIPLY16C16(var,const) ((var) * (const))
  146846. #endif
  146847. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146848. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  146849. #endif
  146850. #ifndef MULTIPLY16V16 /* default definition */
  146851. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  146852. #endif
  146853. #endif
  146854. /*** End of inlined file: jdct.h ***/
  146855. /* Private declarations for DCT subsystem */
  146856. typedef struct {
  146857. struct jpeg_forward_dct pub; /* public fields */
  146858. forward_DCT_method_ptr do_dct;
  146859. DCTELEM * divisors[NUM_QUANT_TBLS];
  146860. #ifdef DCT_FLOAT_SUPPORTED
  146861. float_DCT_method_ptr do_float_dct;
  146862. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  146863. #endif
  146864. } my_fdct_controller;
  146865. typedef my_fdct_controller * my_fdct_ptr;
  146866. METHODDEF(void)
  146867. start_pass_fdctmgr (j_compress_ptr cinfo)
  146868. {
  146869. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146870. int ci, qtblno, i;
  146871. jpeg_component_info *compptr;
  146872. JQUANT_TBL * qtbl;
  146873. DCTELEM * dtbl;
  146874. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146875. ci++, compptr++) {
  146876. qtblno = compptr->quant_tbl_no;
  146877. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  146878. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  146879. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  146880. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  146881. switch (cinfo->dct_method) {
  146882. #ifdef DCT_ISLOW_SUPPORTED
  146883. case JDCT_ISLOW:
  146884. if (fdct->divisors[qtblno] == NULL) {
  146885. fdct->divisors[qtblno] = (DCTELEM *)
  146886. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146887. DCTSIZE2 * SIZEOF(DCTELEM));
  146888. }
  146889. dtbl = fdct->divisors[qtblno];
  146890. for (i = 0; i < DCTSIZE2; i++) {
  146891. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  146892. }
  146893. break;
  146894. #endif
  146895. #ifdef DCT_IFAST_SUPPORTED
  146896. case JDCT_IFAST:
  146897. {
  146898. #define CONST_BITS 14
  146899. static const INT16 aanscales[DCTSIZE2] = {
  146900. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146901. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  146902. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  146903. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  146904. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146905. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  146906. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  146907. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  146908. };
  146909. SHIFT_TEMPS
  146910. if (fdct->divisors[qtblno] == NULL) {
  146911. fdct->divisors[qtblno] = (DCTELEM *)
  146912. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146913. DCTSIZE2 * SIZEOF(DCTELEM));
  146914. }
  146915. dtbl = fdct->divisors[qtblno];
  146916. for (i = 0; i < DCTSIZE2; i++) {
  146917. dtbl[i] = (DCTELEM)
  146918. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  146919. (INT32) aanscales[i]),
  146920. CONST_BITS-3);
  146921. }
  146922. }
  146923. break;
  146924. #endif
  146925. #ifdef DCT_FLOAT_SUPPORTED
  146926. case JDCT_FLOAT:
  146927. {
  146928. FAST_FLOAT * fdtbl;
  146929. int row, col;
  146930. static const double aanscalefactor[DCTSIZE] = {
  146931. 1.0, 1.387039845, 1.306562965, 1.175875602,
  146932. 1.0, 0.785694958, 0.541196100, 0.275899379
  146933. };
  146934. if (fdct->float_divisors[qtblno] == NULL) {
  146935. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  146936. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146937. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  146938. }
  146939. fdtbl = fdct->float_divisors[qtblno];
  146940. i = 0;
  146941. for (row = 0; row < DCTSIZE; row++) {
  146942. for (col = 0; col < DCTSIZE; col++) {
  146943. fdtbl[i] = (FAST_FLOAT)
  146944. (1.0 / (((double) qtbl->quantval[i] *
  146945. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  146946. i++;
  146947. }
  146948. }
  146949. }
  146950. break;
  146951. #endif
  146952. default:
  146953. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146954. break;
  146955. }
  146956. }
  146957. }
  146958. METHODDEF(void)
  146959. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146960. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146961. JDIMENSION start_row, JDIMENSION start_col,
  146962. JDIMENSION num_blocks)
  146963. {
  146964. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146965. forward_DCT_method_ptr do_dct = fdct->do_dct;
  146966. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  146967. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146968. JDIMENSION bi;
  146969. sample_data += start_row; /* fold in the vertical offset once */
  146970. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146971. { register DCTELEM *workspaceptr;
  146972. register JSAMPROW elemptr;
  146973. register int elemr;
  146974. workspaceptr = workspace;
  146975. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146976. elemptr = sample_data[elemr] + start_col;
  146977. #if DCTSIZE == 8 /* unroll the inner loop */
  146978. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146979. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146980. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146981. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146982. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146983. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146984. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146985. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146986. #else
  146987. { register int elemc;
  146988. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146989. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146990. }
  146991. }
  146992. #endif
  146993. }
  146994. }
  146995. (*do_dct) (workspace);
  146996. { register DCTELEM temp, qval;
  146997. register int i;
  146998. register JCOEFPTR output_ptr = coef_blocks[bi];
  146999. for (i = 0; i < DCTSIZE2; i++) {
  147000. qval = divisors[i];
  147001. temp = workspace[i];
  147002. #ifdef FAST_DIVIDE
  147003. #define DIVIDE_BY(a,b) a /= b
  147004. #else
  147005. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  147006. #endif
  147007. if (temp < 0) {
  147008. temp = -temp;
  147009. temp += qval>>1; /* for rounding */
  147010. DIVIDE_BY(temp, qval);
  147011. temp = -temp;
  147012. } else {
  147013. temp += qval>>1; /* for rounding */
  147014. DIVIDE_BY(temp, qval);
  147015. }
  147016. output_ptr[i] = (JCOEF) temp;
  147017. }
  147018. }
  147019. }
  147020. }
  147021. #ifdef DCT_FLOAT_SUPPORTED
  147022. METHODDEF(void)
  147023. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147024. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147025. JDIMENSION start_row, JDIMENSION start_col,
  147026. JDIMENSION num_blocks)
  147027. {
  147028. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147029. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  147030. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  147031. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147032. JDIMENSION bi;
  147033. sample_data += start_row; /* fold in the vertical offset once */
  147034. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147035. { register FAST_FLOAT *workspaceptr;
  147036. register JSAMPROW elemptr;
  147037. register int elemr;
  147038. workspaceptr = workspace;
  147039. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147040. elemptr = sample_data[elemr] + start_col;
  147041. #if DCTSIZE == 8 /* unroll the inner loop */
  147042. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147043. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147044. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147045. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147046. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147047. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147048. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147049. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147050. #else
  147051. { register int elemc;
  147052. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147053. *workspaceptr++ = (FAST_FLOAT)
  147054. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147055. }
  147056. }
  147057. #endif
  147058. }
  147059. }
  147060. (*do_dct) (workspace);
  147061. { register FAST_FLOAT temp;
  147062. register int i;
  147063. register JCOEFPTR output_ptr = coef_blocks[bi];
  147064. for (i = 0; i < DCTSIZE2; i++) {
  147065. temp = workspace[i] * divisors[i];
  147066. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  147067. }
  147068. }
  147069. }
  147070. }
  147071. #endif /* DCT_FLOAT_SUPPORTED */
  147072. GLOBAL(void)
  147073. jinit_forward_dct (j_compress_ptr cinfo)
  147074. {
  147075. my_fdct_ptr fdct;
  147076. int i;
  147077. fdct = (my_fdct_ptr)
  147078. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147079. SIZEOF(my_fdct_controller));
  147080. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  147081. fdct->pub.start_pass = start_pass_fdctmgr;
  147082. switch (cinfo->dct_method) {
  147083. #ifdef DCT_ISLOW_SUPPORTED
  147084. case JDCT_ISLOW:
  147085. fdct->pub.forward_DCT = forward_DCT;
  147086. fdct->do_dct = jpeg_fdct_islow;
  147087. break;
  147088. #endif
  147089. #ifdef DCT_IFAST_SUPPORTED
  147090. case JDCT_IFAST:
  147091. fdct->pub.forward_DCT = forward_DCT;
  147092. fdct->do_dct = jpeg_fdct_ifast;
  147093. break;
  147094. #endif
  147095. #ifdef DCT_FLOAT_SUPPORTED
  147096. case JDCT_FLOAT:
  147097. fdct->pub.forward_DCT = forward_DCT_float;
  147098. fdct->do_float_dct = jpeg_fdct_float;
  147099. break;
  147100. #endif
  147101. default:
  147102. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147103. break;
  147104. }
  147105. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  147106. fdct->divisors[i] = NULL;
  147107. #ifdef DCT_FLOAT_SUPPORTED
  147108. fdct->float_divisors[i] = NULL;
  147109. #endif
  147110. }
  147111. }
  147112. /*** End of inlined file: jcdctmgr.c ***/
  147113. #undef CONST_BITS
  147114. /*** Start of inlined file: jchuff.c ***/
  147115. #define JPEG_INTERNALS
  147116. /*** Start of inlined file: jchuff.h ***/
  147117. #ifndef _jchuff_h_
  147118. #define _jchuff_h_
  147119. #if BITS_IN_JSAMPLE == 8
  147120. #define MAX_COEF_BITS 10
  147121. #else
  147122. #define MAX_COEF_BITS 14
  147123. #endif
  147124. typedef struct {
  147125. unsigned int ehufco[256]; /* code for each symbol */
  147126. char ehufsi[256]; /* length of code for each symbol */
  147127. } c_derived_tbl;
  147128. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147129. #define jpeg_make_c_derived_tbl jMkCDerived
  147130. #define jpeg_gen_optimal_table jGenOptTbl
  147131. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147132. EXTERN(void) jpeg_make_c_derived_tbl
  147133. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  147134. c_derived_tbl ** pdtbl));
  147135. EXTERN(void) jpeg_gen_optimal_table
  147136. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  147137. #endif
  147138. /*** End of inlined file: jchuff.h ***/
  147139. /* Declarations shared with jcphuff.c */
  147140. typedef struct {
  147141. INT32 put_buffer; /* current bit-accumulation buffer */
  147142. int put_bits; /* # of bits now in it */
  147143. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  147144. } savable_state;
  147145. #ifndef NO_STRUCT_ASSIGN
  147146. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  147147. #else
  147148. #if MAX_COMPS_IN_SCAN == 4
  147149. #define ASSIGN_STATE(dest,src) \
  147150. ((dest).put_buffer = (src).put_buffer, \
  147151. (dest).put_bits = (src).put_bits, \
  147152. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  147153. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  147154. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  147155. (dest).last_dc_val[3] = (src).last_dc_val[3])
  147156. #endif
  147157. #endif
  147158. typedef struct {
  147159. struct jpeg_entropy_encoder pub; /* public fields */
  147160. savable_state saved; /* Bit buffer & DC state at start of MCU */
  147161. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  147162. int next_restart_num; /* next restart number to write (0-7) */
  147163. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  147164. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  147165. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  147166. long * dc_count_ptrs[NUM_HUFF_TBLS];
  147167. long * ac_count_ptrs[NUM_HUFF_TBLS];
  147168. #endif
  147169. } huff_entropy_encoder;
  147170. typedef huff_entropy_encoder * huff_entropy_ptr;
  147171. typedef struct {
  147172. JOCTET * next_output_byte; /* => next byte to write in buffer */
  147173. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  147174. savable_state cur; /* Current bit buffer & DC state */
  147175. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  147176. } working_state;
  147177. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  147178. JBLOCKROW *MCU_data));
  147179. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  147180. #ifdef ENTROPY_OPT_SUPPORTED
  147181. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  147182. JBLOCKROW *MCU_data));
  147183. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  147184. #endif
  147185. METHODDEF(void)
  147186. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  147187. {
  147188. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147189. int ci, dctbl, actbl;
  147190. jpeg_component_info * compptr;
  147191. if (gather_statistics) {
  147192. #ifdef ENTROPY_OPT_SUPPORTED
  147193. entropy->pub.encode_mcu = encode_mcu_gather;
  147194. entropy->pub.finish_pass = finish_pass_gather;
  147195. #else
  147196. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147197. #endif
  147198. } else {
  147199. entropy->pub.encode_mcu = encode_mcu_huff;
  147200. entropy->pub.finish_pass = finish_pass_huff;
  147201. }
  147202. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147203. compptr = cinfo->cur_comp_info[ci];
  147204. dctbl = compptr->dc_tbl_no;
  147205. actbl = compptr->ac_tbl_no;
  147206. if (gather_statistics) {
  147207. #ifdef ENTROPY_OPT_SUPPORTED
  147208. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  147209. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  147210. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  147211. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  147212. if (entropy->dc_count_ptrs[dctbl] == NULL)
  147213. entropy->dc_count_ptrs[dctbl] = (long *)
  147214. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147215. 257 * SIZEOF(long));
  147216. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  147217. if (entropy->ac_count_ptrs[actbl] == NULL)
  147218. entropy->ac_count_ptrs[actbl] = (long *)
  147219. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147220. 257 * SIZEOF(long));
  147221. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  147222. #endif
  147223. } else {
  147224. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  147225. & entropy->dc_derived_tbls[dctbl]);
  147226. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  147227. & entropy->ac_derived_tbls[actbl]);
  147228. }
  147229. entropy->saved.last_dc_val[ci] = 0;
  147230. }
  147231. entropy->saved.put_buffer = 0;
  147232. entropy->saved.put_bits = 0;
  147233. entropy->restarts_to_go = cinfo->restart_interval;
  147234. entropy->next_restart_num = 0;
  147235. }
  147236. GLOBAL(void)
  147237. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  147238. c_derived_tbl ** pdtbl)
  147239. {
  147240. JHUFF_TBL *htbl;
  147241. c_derived_tbl *dtbl;
  147242. int p, i, l, lastp, si, maxsymbol;
  147243. char huffsize[257];
  147244. unsigned int huffcode[257];
  147245. unsigned int code;
  147246. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  147247. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147248. htbl =
  147249. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  147250. if (htbl == NULL)
  147251. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147252. if (*pdtbl == NULL)
  147253. *pdtbl = (c_derived_tbl *)
  147254. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147255. SIZEOF(c_derived_tbl));
  147256. dtbl = *pdtbl;
  147257. p = 0;
  147258. for (l = 1; l <= 16; l++) {
  147259. i = (int) htbl->bits[l];
  147260. if (i < 0 || p + i > 256) /* protect against table overrun */
  147261. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147262. while (i--)
  147263. huffsize[p++] = (char) l;
  147264. }
  147265. huffsize[p] = 0;
  147266. lastp = p;
  147267. code = 0;
  147268. si = huffsize[0];
  147269. p = 0;
  147270. while (huffsize[p]) {
  147271. while (((int) huffsize[p]) == si) {
  147272. huffcode[p++] = code;
  147273. code++;
  147274. }
  147275. if (((INT32) code) >= (((INT32) 1) << si))
  147276. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147277. code <<= 1;
  147278. si++;
  147279. }
  147280. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147281. maxsymbol = isDC ? 15 : 255;
  147282. for (p = 0; p < lastp; p++) {
  147283. i = htbl->huffval[p];
  147284. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147285. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147286. dtbl->ehufco[i] = huffcode[p];
  147287. dtbl->ehufsi[i] = huffsize[p];
  147288. }
  147289. }
  147290. #define emit_byte(state,val,action) \
  147291. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147292. if (--(state)->free_in_buffer == 0) \
  147293. if (! dump_buffer(state)) \
  147294. { action; } }
  147295. LOCAL(boolean)
  147296. dump_buffer (working_state * state)
  147297. {
  147298. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147299. if (! (*dest->empty_output_buffer) (state->cinfo))
  147300. return FALSE;
  147301. state->next_output_byte = dest->next_output_byte;
  147302. state->free_in_buffer = dest->free_in_buffer;
  147303. return TRUE;
  147304. }
  147305. INLINE
  147306. LOCAL(boolean)
  147307. emit_bits (working_state * state, unsigned int code, int size)
  147308. {
  147309. register INT32 put_buffer = (INT32) code;
  147310. register int put_bits = state->cur.put_bits;
  147311. if (size == 0)
  147312. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147313. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147314. put_bits += size; /* new number of bits in buffer */
  147315. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147316. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147317. while (put_bits >= 8) {
  147318. int c = (int) ((put_buffer >> 16) & 0xFF);
  147319. emit_byte(state, c, return FALSE);
  147320. if (c == 0xFF) { /* need to stuff a zero byte? */
  147321. emit_byte(state, 0, return FALSE);
  147322. }
  147323. put_buffer <<= 8;
  147324. put_bits -= 8;
  147325. }
  147326. state->cur.put_buffer = put_buffer; /* update state variables */
  147327. state->cur.put_bits = put_bits;
  147328. return TRUE;
  147329. }
  147330. LOCAL(boolean)
  147331. flush_bits (working_state * state)
  147332. {
  147333. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147334. return FALSE;
  147335. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147336. state->cur.put_bits = 0;
  147337. return TRUE;
  147338. }
  147339. LOCAL(boolean)
  147340. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147341. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147342. {
  147343. register int temp, temp2;
  147344. register int nbits;
  147345. register int k, r, i;
  147346. temp = temp2 = block[0] - last_dc_val;
  147347. if (temp < 0) {
  147348. temp = -temp; /* temp is abs value of input */
  147349. temp2--;
  147350. }
  147351. nbits = 0;
  147352. while (temp) {
  147353. nbits++;
  147354. temp >>= 1;
  147355. }
  147356. if (nbits > MAX_COEF_BITS+1)
  147357. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147358. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147359. return FALSE;
  147360. if (nbits) /* emit_bits rejects calls with size 0 */
  147361. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147362. return FALSE;
  147363. r = 0; /* r = run length of zeros */
  147364. for (k = 1; k < DCTSIZE2; k++) {
  147365. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147366. r++;
  147367. } else {
  147368. while (r > 15) {
  147369. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147370. return FALSE;
  147371. r -= 16;
  147372. }
  147373. temp2 = temp;
  147374. if (temp < 0) {
  147375. temp = -temp; /* temp is abs value of input */
  147376. temp2--;
  147377. }
  147378. nbits = 1; /* there must be at least one 1 bit */
  147379. while ((temp >>= 1))
  147380. nbits++;
  147381. if (nbits > MAX_COEF_BITS)
  147382. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147383. i = (r << 4) + nbits;
  147384. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  147385. return FALSE;
  147386. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147387. return FALSE;
  147388. r = 0;
  147389. }
  147390. }
  147391. if (r > 0)
  147392. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147393. return FALSE;
  147394. return TRUE;
  147395. }
  147396. LOCAL(boolean)
  147397. emit_restart (working_state * state, int restart_num)
  147398. {
  147399. int ci;
  147400. if (! flush_bits(state))
  147401. return FALSE;
  147402. emit_byte(state, 0xFF, return FALSE);
  147403. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147404. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147405. state->cur.last_dc_val[ci] = 0;
  147406. return TRUE;
  147407. }
  147408. METHODDEF(boolean)
  147409. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147410. {
  147411. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147412. working_state state;
  147413. int blkn, ci;
  147414. jpeg_component_info * compptr;
  147415. state.next_output_byte = cinfo->dest->next_output_byte;
  147416. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147417. ASSIGN_STATE(state.cur, entropy->saved);
  147418. state.cinfo = cinfo;
  147419. if (cinfo->restart_interval) {
  147420. if (entropy->restarts_to_go == 0)
  147421. if (! emit_restart(&state, entropy->next_restart_num))
  147422. return FALSE;
  147423. }
  147424. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147425. ci = cinfo->MCU_membership[blkn];
  147426. compptr = cinfo->cur_comp_info[ci];
  147427. if (! encode_one_block(&state,
  147428. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147429. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147430. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147431. return FALSE;
  147432. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147433. }
  147434. cinfo->dest->next_output_byte = state.next_output_byte;
  147435. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147436. ASSIGN_STATE(entropy->saved, state.cur);
  147437. if (cinfo->restart_interval) {
  147438. if (entropy->restarts_to_go == 0) {
  147439. entropy->restarts_to_go = cinfo->restart_interval;
  147440. entropy->next_restart_num++;
  147441. entropy->next_restart_num &= 7;
  147442. }
  147443. entropy->restarts_to_go--;
  147444. }
  147445. return TRUE;
  147446. }
  147447. METHODDEF(void)
  147448. finish_pass_huff (j_compress_ptr cinfo)
  147449. {
  147450. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147451. working_state state;
  147452. state.next_output_byte = cinfo->dest->next_output_byte;
  147453. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147454. ASSIGN_STATE(state.cur, entropy->saved);
  147455. state.cinfo = cinfo;
  147456. if (! flush_bits(&state))
  147457. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147458. cinfo->dest->next_output_byte = state.next_output_byte;
  147459. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147460. ASSIGN_STATE(entropy->saved, state.cur);
  147461. }
  147462. #ifdef ENTROPY_OPT_SUPPORTED
  147463. LOCAL(void)
  147464. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147465. long dc_counts[], long ac_counts[])
  147466. {
  147467. register int temp;
  147468. register int nbits;
  147469. register int k, r;
  147470. temp = block[0] - last_dc_val;
  147471. if (temp < 0)
  147472. temp = -temp;
  147473. nbits = 0;
  147474. while (temp) {
  147475. nbits++;
  147476. temp >>= 1;
  147477. }
  147478. if (nbits > MAX_COEF_BITS+1)
  147479. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147480. dc_counts[nbits]++;
  147481. r = 0; /* r = run length of zeros */
  147482. for (k = 1; k < DCTSIZE2; k++) {
  147483. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147484. r++;
  147485. } else {
  147486. while (r > 15) {
  147487. ac_counts[0xF0]++;
  147488. r -= 16;
  147489. }
  147490. if (temp < 0)
  147491. temp = -temp;
  147492. nbits = 1; /* there must be at least one 1 bit */
  147493. while ((temp >>= 1))
  147494. nbits++;
  147495. if (nbits > MAX_COEF_BITS)
  147496. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147497. ac_counts[(r << 4) + nbits]++;
  147498. r = 0;
  147499. }
  147500. }
  147501. if (r > 0)
  147502. ac_counts[0]++;
  147503. }
  147504. METHODDEF(boolean)
  147505. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147506. {
  147507. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147508. int blkn, ci;
  147509. jpeg_component_info * compptr;
  147510. if (cinfo->restart_interval) {
  147511. if (entropy->restarts_to_go == 0) {
  147512. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147513. entropy->saved.last_dc_val[ci] = 0;
  147514. entropy->restarts_to_go = cinfo->restart_interval;
  147515. }
  147516. entropy->restarts_to_go--;
  147517. }
  147518. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147519. ci = cinfo->MCU_membership[blkn];
  147520. compptr = cinfo->cur_comp_info[ci];
  147521. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147522. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147523. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147524. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147525. }
  147526. return TRUE;
  147527. }
  147528. GLOBAL(void)
  147529. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147530. {
  147531. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147532. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147533. int codesize[257]; /* codesize[k] = code length of symbol k */
  147534. int others[257]; /* next symbol in current branch of tree */
  147535. int c1, c2;
  147536. int p, i, j;
  147537. long v;
  147538. MEMZERO(bits, SIZEOF(bits));
  147539. MEMZERO(codesize, SIZEOF(codesize));
  147540. for (i = 0; i < 257; i++)
  147541. others[i] = -1; /* init links to empty */
  147542. freq[256] = 1; /* make sure 256 has a nonzero count */
  147543. for (;;) {
  147544. c1 = -1;
  147545. v = 1000000000L;
  147546. for (i = 0; i <= 256; i++) {
  147547. if (freq[i] && freq[i] <= v) {
  147548. v = freq[i];
  147549. c1 = i;
  147550. }
  147551. }
  147552. c2 = -1;
  147553. v = 1000000000L;
  147554. for (i = 0; i <= 256; i++) {
  147555. if (freq[i] && freq[i] <= v && i != c1) {
  147556. v = freq[i];
  147557. c2 = i;
  147558. }
  147559. }
  147560. if (c2 < 0)
  147561. break;
  147562. freq[c1] += freq[c2];
  147563. freq[c2] = 0;
  147564. codesize[c1]++;
  147565. while (others[c1] >= 0) {
  147566. c1 = others[c1];
  147567. codesize[c1]++;
  147568. }
  147569. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147570. codesize[c2]++;
  147571. while (others[c2] >= 0) {
  147572. c2 = others[c2];
  147573. codesize[c2]++;
  147574. }
  147575. }
  147576. for (i = 0; i <= 256; i++) {
  147577. if (codesize[i]) {
  147578. if (codesize[i] > MAX_CLEN)
  147579. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147580. bits[codesize[i]]++;
  147581. }
  147582. }
  147583. for (i = MAX_CLEN; i > 16; i--) {
  147584. while (bits[i] > 0) {
  147585. j = i - 2; /* find length of new prefix to be used */
  147586. while (bits[j] == 0)
  147587. j--;
  147588. bits[i] -= 2; /* remove two symbols */
  147589. bits[i-1]++; /* one goes in this length */
  147590. bits[j+1] += 2; /* two new symbols in this length */
  147591. bits[j]--; /* symbol of this length is now a prefix */
  147592. }
  147593. }
  147594. while (bits[i] == 0) /* find largest codelength still in use */
  147595. i--;
  147596. bits[i]--;
  147597. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147598. p = 0;
  147599. for (i = 1; i <= MAX_CLEN; i++) {
  147600. for (j = 0; j <= 255; j++) {
  147601. if (codesize[j] == i) {
  147602. htbl->huffval[p] = (UINT8) j;
  147603. p++;
  147604. }
  147605. }
  147606. }
  147607. htbl->sent_table = FALSE;
  147608. }
  147609. METHODDEF(void)
  147610. finish_pass_gather (j_compress_ptr cinfo)
  147611. {
  147612. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147613. int ci, dctbl, actbl;
  147614. jpeg_component_info * compptr;
  147615. JHUFF_TBL **htblptr;
  147616. boolean did_dc[NUM_HUFF_TBLS];
  147617. boolean did_ac[NUM_HUFF_TBLS];
  147618. MEMZERO(did_dc, SIZEOF(did_dc));
  147619. MEMZERO(did_ac, SIZEOF(did_ac));
  147620. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147621. compptr = cinfo->cur_comp_info[ci];
  147622. dctbl = compptr->dc_tbl_no;
  147623. actbl = compptr->ac_tbl_no;
  147624. if (! did_dc[dctbl]) {
  147625. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147626. if (*htblptr == NULL)
  147627. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147628. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147629. did_dc[dctbl] = TRUE;
  147630. }
  147631. if (! did_ac[actbl]) {
  147632. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147633. if (*htblptr == NULL)
  147634. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147635. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147636. did_ac[actbl] = TRUE;
  147637. }
  147638. }
  147639. }
  147640. #endif /* ENTROPY_OPT_SUPPORTED */
  147641. GLOBAL(void)
  147642. jinit_huff_encoder (j_compress_ptr cinfo)
  147643. {
  147644. huff_entropy_ptr entropy;
  147645. int i;
  147646. entropy = (huff_entropy_ptr)
  147647. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147648. SIZEOF(huff_entropy_encoder));
  147649. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147650. entropy->pub.start_pass = start_pass_huff;
  147651. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147652. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147653. #ifdef ENTROPY_OPT_SUPPORTED
  147654. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147655. #endif
  147656. }
  147657. }
  147658. /*** End of inlined file: jchuff.c ***/
  147659. #undef emit_byte
  147660. /*** Start of inlined file: jcinit.c ***/
  147661. #define JPEG_INTERNALS
  147662. GLOBAL(void)
  147663. jinit_compress_master (j_compress_ptr cinfo)
  147664. {
  147665. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147666. if (! cinfo->raw_data_in) {
  147667. jinit_color_converter(cinfo);
  147668. jinit_downsampler(cinfo);
  147669. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  147670. }
  147671. jinit_forward_dct(cinfo);
  147672. if (cinfo->arith_code) {
  147673. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  147674. } else {
  147675. if (cinfo->progressive_mode) {
  147676. #ifdef C_PROGRESSIVE_SUPPORTED
  147677. jinit_phuff_encoder(cinfo);
  147678. #else
  147679. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147680. #endif
  147681. } else
  147682. jinit_huff_encoder(cinfo);
  147683. }
  147684. jinit_c_coef_controller(cinfo,
  147685. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  147686. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  147687. jinit_marker_writer(cinfo);
  147688. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  147689. (*cinfo->marker->write_file_header) (cinfo);
  147690. }
  147691. /*** End of inlined file: jcinit.c ***/
  147692. /*** Start of inlined file: jcmainct.c ***/
  147693. #define JPEG_INTERNALS
  147694. #undef FULL_MAIN_BUFFER_SUPPORTED
  147695. typedef struct {
  147696. struct jpeg_c_main_controller pub; /* public fields */
  147697. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  147698. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  147699. boolean suspended; /* remember if we suspended output */
  147700. J_BUF_MODE pass_mode; /* current operating mode */
  147701. JSAMPARRAY buffer[MAX_COMPONENTS];
  147702. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147703. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  147704. #endif
  147705. } my_main_controller;
  147706. typedef my_main_controller * my_main_ptr;
  147707. METHODDEF(void) process_data_simple_main
  147708. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147709. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147710. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147711. METHODDEF(void) process_data_buffer_main
  147712. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147713. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147714. #endif
  147715. METHODDEF(void)
  147716. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  147717. {
  147718. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147719. if (cinfo->raw_data_in)
  147720. return;
  147721. main_->cur_iMCU_row = 0; /* initialize counters */
  147722. main_->rowgroup_ctr = 0;
  147723. main_->suspended = FALSE;
  147724. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  147725. switch (pass_mode) {
  147726. case JBUF_PASS_THRU:
  147727. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147728. if (main_->whole_image[0] != NULL)
  147729. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147730. #endif
  147731. main_->pub.process_data = process_data_simple_main;
  147732. break;
  147733. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147734. case JBUF_SAVE_SOURCE:
  147735. case JBUF_CRANK_DEST:
  147736. case JBUF_SAVE_AND_PASS:
  147737. if (main_->whole_image[0] == NULL)
  147738. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147739. main_->pub.process_data = process_data_buffer_main;
  147740. break;
  147741. #endif
  147742. default:
  147743. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147744. break;
  147745. }
  147746. }
  147747. METHODDEF(void)
  147748. process_data_simple_main (j_compress_ptr cinfo,
  147749. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147750. JDIMENSION in_rows_avail)
  147751. {
  147752. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147753. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147754. if (main_->rowgroup_ctr < DCTSIZE)
  147755. (*cinfo->prep->pre_process_data) (cinfo,
  147756. input_buf, in_row_ctr, in_rows_avail,
  147757. main_->buffer, &main_->rowgroup_ctr,
  147758. (JDIMENSION) DCTSIZE);
  147759. if (main_->rowgroup_ctr != DCTSIZE)
  147760. return;
  147761. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  147762. if (! main_->suspended) {
  147763. (*in_row_ctr)--;
  147764. main_->suspended = TRUE;
  147765. }
  147766. return;
  147767. }
  147768. if (main_->suspended) {
  147769. (*in_row_ctr)++;
  147770. main_->suspended = FALSE;
  147771. }
  147772. main_->rowgroup_ctr = 0;
  147773. main_->cur_iMCU_row++;
  147774. }
  147775. }
  147776. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147777. METHODDEF(void)
  147778. process_data_buffer_main (j_compress_ptr cinfo,
  147779. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147780. JDIMENSION in_rows_avail)
  147781. {
  147782. my_main_ptr main = (my_main_ptr) cinfo->main;
  147783. int ci;
  147784. jpeg_component_info *compptr;
  147785. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  147786. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147787. if (main->rowgroup_ctr == 0) {
  147788. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147789. ci++, compptr++) {
  147790. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  147791. ((j_common_ptr) cinfo, main->whole_image[ci],
  147792. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  147793. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  147794. }
  147795. if (! writing) {
  147796. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  147797. main->rowgroup_ctr = DCTSIZE;
  147798. }
  147799. }
  147800. if (writing) {
  147801. (*cinfo->prep->pre_process_data) (cinfo,
  147802. input_buf, in_row_ctr, in_rows_avail,
  147803. main->buffer, &main->rowgroup_ctr,
  147804. (JDIMENSION) DCTSIZE);
  147805. if (main->rowgroup_ctr < DCTSIZE)
  147806. return;
  147807. }
  147808. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  147809. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  147810. if (! main->suspended) {
  147811. (*in_row_ctr)--;
  147812. main->suspended = TRUE;
  147813. }
  147814. return;
  147815. }
  147816. if (main->suspended) {
  147817. (*in_row_ctr)++;
  147818. main->suspended = FALSE;
  147819. }
  147820. }
  147821. main->rowgroup_ctr = 0;
  147822. main->cur_iMCU_row++;
  147823. }
  147824. }
  147825. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  147826. GLOBAL(void)
  147827. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  147828. {
  147829. my_main_ptr main_;
  147830. int ci;
  147831. jpeg_component_info *compptr;
  147832. main_ = (my_main_ptr)
  147833. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147834. SIZEOF(my_main_controller));
  147835. cinfo->main = (struct jpeg_c_main_controller *) main_;
  147836. main_->pub.start_pass = start_pass_main;
  147837. if (cinfo->raw_data_in)
  147838. return;
  147839. if (need_full_buffer) {
  147840. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147841. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147842. ci++, compptr++) {
  147843. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  147844. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  147845. compptr->width_in_blocks * DCTSIZE,
  147846. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  147847. (long) compptr->v_samp_factor) * DCTSIZE,
  147848. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147849. }
  147850. #else
  147851. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147852. #endif
  147853. } else {
  147854. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147855. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  147856. #endif
  147857. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147858. ci++, compptr++) {
  147859. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  147860. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147861. compptr->width_in_blocks * DCTSIZE,
  147862. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147863. }
  147864. }
  147865. }
  147866. /*** End of inlined file: jcmainct.c ***/
  147867. /*** Start of inlined file: jcmarker.c ***/
  147868. #define JPEG_INTERNALS
  147869. typedef struct {
  147870. struct jpeg_marker_writer pub; /* public fields */
  147871. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  147872. } my_marker_writer;
  147873. typedef my_marker_writer * my_marker_ptr;
  147874. LOCAL(void)
  147875. emit_byte (j_compress_ptr cinfo, int val)
  147876. {
  147877. struct jpeg_destination_mgr * dest = cinfo->dest;
  147878. *(dest->next_output_byte)++ = (JOCTET) val;
  147879. if (--dest->free_in_buffer == 0) {
  147880. if (! (*dest->empty_output_buffer) (cinfo))
  147881. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147882. }
  147883. }
  147884. LOCAL(void)
  147885. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  147886. {
  147887. emit_byte(cinfo, 0xFF);
  147888. emit_byte(cinfo, (int) mark);
  147889. }
  147890. LOCAL(void)
  147891. emit_2bytes (j_compress_ptr cinfo, int value)
  147892. {
  147893. emit_byte(cinfo, (value >> 8) & 0xFF);
  147894. emit_byte(cinfo, value & 0xFF);
  147895. }
  147896. LOCAL(int)
  147897. emit_dqt (j_compress_ptr cinfo, int index)
  147898. {
  147899. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  147900. int prec;
  147901. int i;
  147902. if (qtbl == NULL)
  147903. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  147904. prec = 0;
  147905. for (i = 0; i < DCTSIZE2; i++) {
  147906. if (qtbl->quantval[i] > 255)
  147907. prec = 1;
  147908. }
  147909. if (! qtbl->sent_table) {
  147910. emit_marker(cinfo, M_DQT);
  147911. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  147912. emit_byte(cinfo, index + (prec<<4));
  147913. for (i = 0; i < DCTSIZE2; i++) {
  147914. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  147915. if (prec)
  147916. emit_byte(cinfo, (int) (qval >> 8));
  147917. emit_byte(cinfo, (int) (qval & 0xFF));
  147918. }
  147919. qtbl->sent_table = TRUE;
  147920. }
  147921. return prec;
  147922. }
  147923. LOCAL(void)
  147924. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  147925. {
  147926. JHUFF_TBL * htbl;
  147927. int length, i;
  147928. if (is_ac) {
  147929. htbl = cinfo->ac_huff_tbl_ptrs[index];
  147930. index += 0x10; /* output index has AC bit set */
  147931. } else {
  147932. htbl = cinfo->dc_huff_tbl_ptrs[index];
  147933. }
  147934. if (htbl == NULL)
  147935. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  147936. if (! htbl->sent_table) {
  147937. emit_marker(cinfo, M_DHT);
  147938. length = 0;
  147939. for (i = 1; i <= 16; i++)
  147940. length += htbl->bits[i];
  147941. emit_2bytes(cinfo, length + 2 + 1 + 16);
  147942. emit_byte(cinfo, index);
  147943. for (i = 1; i <= 16; i++)
  147944. emit_byte(cinfo, htbl->bits[i]);
  147945. for (i = 0; i < length; i++)
  147946. emit_byte(cinfo, htbl->huffval[i]);
  147947. htbl->sent_table = TRUE;
  147948. }
  147949. }
  147950. LOCAL(void)
  147951. emit_dac (j_compress_ptr cinfo)
  147952. {
  147953. #ifdef C_ARITH_CODING_SUPPORTED
  147954. char dc_in_use[NUM_ARITH_TBLS];
  147955. char ac_in_use[NUM_ARITH_TBLS];
  147956. int length, i;
  147957. jpeg_component_info *compptr;
  147958. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147959. dc_in_use[i] = ac_in_use[i] = 0;
  147960. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147961. compptr = cinfo->cur_comp_info[i];
  147962. dc_in_use[compptr->dc_tbl_no] = 1;
  147963. ac_in_use[compptr->ac_tbl_no] = 1;
  147964. }
  147965. length = 0;
  147966. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147967. length += dc_in_use[i] + ac_in_use[i];
  147968. emit_marker(cinfo, M_DAC);
  147969. emit_2bytes(cinfo, length*2 + 2);
  147970. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  147971. if (dc_in_use[i]) {
  147972. emit_byte(cinfo, i);
  147973. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  147974. }
  147975. if (ac_in_use[i]) {
  147976. emit_byte(cinfo, i + 0x10);
  147977. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  147978. }
  147979. }
  147980. #endif /* C_ARITH_CODING_SUPPORTED */
  147981. }
  147982. LOCAL(void)
  147983. emit_dri (j_compress_ptr cinfo)
  147984. {
  147985. emit_marker(cinfo, M_DRI);
  147986. emit_2bytes(cinfo, 4); /* fixed length */
  147987. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  147988. }
  147989. LOCAL(void)
  147990. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  147991. {
  147992. int ci;
  147993. jpeg_component_info *compptr;
  147994. emit_marker(cinfo, code);
  147995. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  147996. if ((long) cinfo->image_height > 65535L ||
  147997. (long) cinfo->image_width > 65535L)
  147998. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  147999. emit_byte(cinfo, cinfo->data_precision);
  148000. emit_2bytes(cinfo, (int) cinfo->image_height);
  148001. emit_2bytes(cinfo, (int) cinfo->image_width);
  148002. emit_byte(cinfo, cinfo->num_components);
  148003. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148004. ci++, compptr++) {
  148005. emit_byte(cinfo, compptr->component_id);
  148006. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  148007. emit_byte(cinfo, compptr->quant_tbl_no);
  148008. }
  148009. }
  148010. LOCAL(void)
  148011. emit_sos (j_compress_ptr cinfo)
  148012. {
  148013. int i, td, ta;
  148014. jpeg_component_info *compptr;
  148015. emit_marker(cinfo, M_SOS);
  148016. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  148017. emit_byte(cinfo, cinfo->comps_in_scan);
  148018. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148019. compptr = cinfo->cur_comp_info[i];
  148020. emit_byte(cinfo, compptr->component_id);
  148021. td = compptr->dc_tbl_no;
  148022. ta = compptr->ac_tbl_no;
  148023. if (cinfo->progressive_mode) {
  148024. if (cinfo->Ss == 0) {
  148025. ta = 0; /* DC scan */
  148026. if (cinfo->Ah != 0 && !cinfo->arith_code)
  148027. td = 0; /* no DC table either */
  148028. } else {
  148029. td = 0; /* AC scan */
  148030. }
  148031. }
  148032. emit_byte(cinfo, (td << 4) + ta);
  148033. }
  148034. emit_byte(cinfo, cinfo->Ss);
  148035. emit_byte(cinfo, cinfo->Se);
  148036. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  148037. }
  148038. LOCAL(void)
  148039. emit_jfif_app0 (j_compress_ptr cinfo)
  148040. {
  148041. emit_marker(cinfo, M_APP0);
  148042. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  148043. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  148044. emit_byte(cinfo, 0x46);
  148045. emit_byte(cinfo, 0x49);
  148046. emit_byte(cinfo, 0x46);
  148047. emit_byte(cinfo, 0);
  148048. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  148049. emit_byte(cinfo, cinfo->JFIF_minor_version);
  148050. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  148051. emit_2bytes(cinfo, (int) cinfo->X_density);
  148052. emit_2bytes(cinfo, (int) cinfo->Y_density);
  148053. emit_byte(cinfo, 0); /* No thumbnail image */
  148054. emit_byte(cinfo, 0);
  148055. }
  148056. LOCAL(void)
  148057. emit_adobe_app14 (j_compress_ptr cinfo)
  148058. {
  148059. emit_marker(cinfo, M_APP14);
  148060. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  148061. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  148062. emit_byte(cinfo, 0x64);
  148063. emit_byte(cinfo, 0x6F);
  148064. emit_byte(cinfo, 0x62);
  148065. emit_byte(cinfo, 0x65);
  148066. emit_2bytes(cinfo, 100); /* Version */
  148067. emit_2bytes(cinfo, 0); /* Flags0 */
  148068. emit_2bytes(cinfo, 0); /* Flags1 */
  148069. switch (cinfo->jpeg_color_space) {
  148070. case JCS_YCbCr:
  148071. emit_byte(cinfo, 1); /* Color transform = 1 */
  148072. break;
  148073. case JCS_YCCK:
  148074. emit_byte(cinfo, 2); /* Color transform = 2 */
  148075. break;
  148076. default:
  148077. emit_byte(cinfo, 0); /* Color transform = 0 */
  148078. break;
  148079. }
  148080. }
  148081. METHODDEF(void)
  148082. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  148083. {
  148084. if (datalen > (unsigned int) 65533) /* safety check */
  148085. ERREXIT(cinfo, JERR_BAD_LENGTH);
  148086. emit_marker(cinfo, (JPEG_MARKER) marker);
  148087. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  148088. }
  148089. METHODDEF(void)
  148090. write_marker_byte (j_compress_ptr cinfo, int val)
  148091. {
  148092. emit_byte(cinfo, val);
  148093. }
  148094. METHODDEF(void)
  148095. write_file_header (j_compress_ptr cinfo)
  148096. {
  148097. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148098. emit_marker(cinfo, M_SOI); /* first the SOI */
  148099. marker->last_restart_interval = 0;
  148100. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  148101. emit_jfif_app0(cinfo);
  148102. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  148103. emit_adobe_app14(cinfo);
  148104. }
  148105. METHODDEF(void)
  148106. write_frame_header (j_compress_ptr cinfo)
  148107. {
  148108. int ci, prec;
  148109. boolean is_baseline;
  148110. jpeg_component_info *compptr;
  148111. prec = 0;
  148112. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148113. ci++, compptr++) {
  148114. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  148115. }
  148116. if (cinfo->arith_code || cinfo->progressive_mode ||
  148117. cinfo->data_precision != 8) {
  148118. is_baseline = FALSE;
  148119. } else {
  148120. is_baseline = TRUE;
  148121. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148122. ci++, compptr++) {
  148123. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  148124. is_baseline = FALSE;
  148125. }
  148126. if (prec && is_baseline) {
  148127. is_baseline = FALSE;
  148128. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  148129. }
  148130. }
  148131. if (cinfo->arith_code) {
  148132. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  148133. } else {
  148134. if (cinfo->progressive_mode)
  148135. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  148136. else if (is_baseline)
  148137. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  148138. else
  148139. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  148140. }
  148141. }
  148142. METHODDEF(void)
  148143. write_scan_header (j_compress_ptr cinfo)
  148144. {
  148145. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148146. int i;
  148147. jpeg_component_info *compptr;
  148148. if (cinfo->arith_code) {
  148149. emit_dac(cinfo);
  148150. } else {
  148151. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148152. compptr = cinfo->cur_comp_info[i];
  148153. if (cinfo->progressive_mode) {
  148154. if (cinfo->Ss == 0) {
  148155. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  148156. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148157. } else {
  148158. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148159. }
  148160. } else {
  148161. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148162. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148163. }
  148164. }
  148165. }
  148166. if (cinfo->restart_interval != marker->last_restart_interval) {
  148167. emit_dri(cinfo);
  148168. marker->last_restart_interval = cinfo->restart_interval;
  148169. }
  148170. emit_sos(cinfo);
  148171. }
  148172. METHODDEF(void)
  148173. write_file_trailer (j_compress_ptr cinfo)
  148174. {
  148175. emit_marker(cinfo, M_EOI);
  148176. }
  148177. METHODDEF(void)
  148178. write_tables_only (j_compress_ptr cinfo)
  148179. {
  148180. int i;
  148181. emit_marker(cinfo, M_SOI);
  148182. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  148183. if (cinfo->quant_tbl_ptrs[i] != NULL)
  148184. (void) emit_dqt(cinfo, i);
  148185. }
  148186. if (! cinfo->arith_code) {
  148187. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  148188. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  148189. emit_dht(cinfo, i, FALSE);
  148190. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  148191. emit_dht(cinfo, i, TRUE);
  148192. }
  148193. }
  148194. emit_marker(cinfo, M_EOI);
  148195. }
  148196. GLOBAL(void)
  148197. jinit_marker_writer (j_compress_ptr cinfo)
  148198. {
  148199. my_marker_ptr marker;
  148200. marker = (my_marker_ptr)
  148201. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148202. SIZEOF(my_marker_writer));
  148203. cinfo->marker = (struct jpeg_marker_writer *) marker;
  148204. marker->pub.write_file_header = write_file_header;
  148205. marker->pub.write_frame_header = write_frame_header;
  148206. marker->pub.write_scan_header = write_scan_header;
  148207. marker->pub.write_file_trailer = write_file_trailer;
  148208. marker->pub.write_tables_only = write_tables_only;
  148209. marker->pub.write_marker_header = write_marker_header;
  148210. marker->pub.write_marker_byte = write_marker_byte;
  148211. marker->last_restart_interval = 0;
  148212. }
  148213. /*** End of inlined file: jcmarker.c ***/
  148214. /*** Start of inlined file: jcmaster.c ***/
  148215. #define JPEG_INTERNALS
  148216. typedef enum {
  148217. main_pass, /* input data, also do first output step */
  148218. huff_opt_pass, /* Huffman code optimization pass */
  148219. output_pass /* data output pass */
  148220. } c_pass_type;
  148221. typedef struct {
  148222. struct jpeg_comp_master pub; /* public fields */
  148223. c_pass_type pass_type; /* the type of the current pass */
  148224. int pass_number; /* # of passes completed */
  148225. int total_passes; /* total # of passes needed */
  148226. int scan_number; /* current index in scan_info[] */
  148227. } my_comp_master;
  148228. typedef my_comp_master * my_master_ptr;
  148229. LOCAL(void)
  148230. initial_setup (j_compress_ptr cinfo)
  148231. {
  148232. int ci;
  148233. jpeg_component_info *compptr;
  148234. long samplesperrow;
  148235. JDIMENSION jd_samplesperrow;
  148236. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  148237. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  148238. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  148239. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  148240. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  148241. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  148242. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  148243. jd_samplesperrow = (JDIMENSION) samplesperrow;
  148244. if ((long) jd_samplesperrow != samplesperrow)
  148245. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  148246. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  148247. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  148248. if (cinfo->num_components > MAX_COMPONENTS)
  148249. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148250. MAX_COMPONENTS);
  148251. cinfo->max_h_samp_factor = 1;
  148252. cinfo->max_v_samp_factor = 1;
  148253. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148254. ci++, compptr++) {
  148255. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  148256. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  148257. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  148258. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  148259. compptr->h_samp_factor);
  148260. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  148261. compptr->v_samp_factor);
  148262. }
  148263. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148264. ci++, compptr++) {
  148265. compptr->component_index = ci;
  148266. compptr->DCT_scaled_size = DCTSIZE;
  148267. compptr->width_in_blocks = (JDIMENSION)
  148268. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148269. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  148270. compptr->height_in_blocks = (JDIMENSION)
  148271. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148272. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  148273. compptr->downsampled_width = (JDIMENSION)
  148274. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148275. (long) cinfo->max_h_samp_factor);
  148276. compptr->downsampled_height = (JDIMENSION)
  148277. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148278. (long) cinfo->max_v_samp_factor);
  148279. compptr->component_needed = TRUE;
  148280. }
  148281. cinfo->total_iMCU_rows = (JDIMENSION)
  148282. jdiv_round_up((long) cinfo->image_height,
  148283. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148284. }
  148285. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148286. LOCAL(void)
  148287. validate_script (j_compress_ptr cinfo)
  148288. {
  148289. const jpeg_scan_info * scanptr;
  148290. int scanno, ncomps, ci, coefi, thisi;
  148291. int Ss, Se, Ah, Al;
  148292. boolean component_sent[MAX_COMPONENTS];
  148293. #ifdef C_PROGRESSIVE_SUPPORTED
  148294. int * last_bitpos_ptr;
  148295. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148296. #endif
  148297. if (cinfo->num_scans <= 0)
  148298. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148299. scanptr = cinfo->scan_info;
  148300. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148301. #ifdef C_PROGRESSIVE_SUPPORTED
  148302. cinfo->progressive_mode = TRUE;
  148303. last_bitpos_ptr = & last_bitpos[0][0];
  148304. for (ci = 0; ci < cinfo->num_components; ci++)
  148305. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148306. *last_bitpos_ptr++ = -1;
  148307. #else
  148308. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148309. #endif
  148310. } else {
  148311. cinfo->progressive_mode = FALSE;
  148312. for (ci = 0; ci < cinfo->num_components; ci++)
  148313. component_sent[ci] = FALSE;
  148314. }
  148315. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148316. ncomps = scanptr->comps_in_scan;
  148317. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148318. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148319. for (ci = 0; ci < ncomps; ci++) {
  148320. thisi = scanptr->component_index[ci];
  148321. if (thisi < 0 || thisi >= cinfo->num_components)
  148322. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148323. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148324. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148325. }
  148326. Ss = scanptr->Ss;
  148327. Se = scanptr->Se;
  148328. Ah = scanptr->Ah;
  148329. Al = scanptr->Al;
  148330. if (cinfo->progressive_mode) {
  148331. #ifdef C_PROGRESSIVE_SUPPORTED
  148332. #if BITS_IN_JSAMPLE == 8
  148333. #define MAX_AH_AL 10
  148334. #else
  148335. #define MAX_AH_AL 13
  148336. #endif
  148337. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148338. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148339. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148340. if (Ss == 0) {
  148341. if (Se != 0) /* DC and AC together not OK */
  148342. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148343. } else {
  148344. if (ncomps != 1) /* AC scans must be for only one component */
  148345. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148346. }
  148347. for (ci = 0; ci < ncomps; ci++) {
  148348. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148349. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148350. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148351. for (coefi = Ss; coefi <= Se; coefi++) {
  148352. if (last_bitpos_ptr[coefi] < 0) {
  148353. if (Ah != 0)
  148354. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148355. } else {
  148356. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148357. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148358. }
  148359. last_bitpos_ptr[coefi] = Al;
  148360. }
  148361. }
  148362. #endif
  148363. } else {
  148364. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148365. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148366. for (ci = 0; ci < ncomps; ci++) {
  148367. thisi = scanptr->component_index[ci];
  148368. if (component_sent[thisi])
  148369. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148370. component_sent[thisi] = TRUE;
  148371. }
  148372. }
  148373. }
  148374. if (cinfo->progressive_mode) {
  148375. #ifdef C_PROGRESSIVE_SUPPORTED
  148376. for (ci = 0; ci < cinfo->num_components; ci++) {
  148377. if (last_bitpos[ci][0] < 0)
  148378. ERREXIT(cinfo, JERR_MISSING_DATA);
  148379. }
  148380. #endif
  148381. } else {
  148382. for (ci = 0; ci < cinfo->num_components; ci++) {
  148383. if (! component_sent[ci])
  148384. ERREXIT(cinfo, JERR_MISSING_DATA);
  148385. }
  148386. }
  148387. }
  148388. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  148389. LOCAL(void)
  148390. select_scan_parameters (j_compress_ptr cinfo)
  148391. {
  148392. int ci;
  148393. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148394. if (cinfo->scan_info != NULL) {
  148395. my_master_ptr master = (my_master_ptr) cinfo->master;
  148396. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148397. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148398. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148399. cinfo->cur_comp_info[ci] =
  148400. &cinfo->comp_info[scanptr->component_index[ci]];
  148401. }
  148402. cinfo->Ss = scanptr->Ss;
  148403. cinfo->Se = scanptr->Se;
  148404. cinfo->Ah = scanptr->Ah;
  148405. cinfo->Al = scanptr->Al;
  148406. }
  148407. else
  148408. #endif
  148409. {
  148410. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148411. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148412. MAX_COMPS_IN_SCAN);
  148413. cinfo->comps_in_scan = cinfo->num_components;
  148414. for (ci = 0; ci < cinfo->num_components; ci++) {
  148415. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148416. }
  148417. cinfo->Ss = 0;
  148418. cinfo->Se = DCTSIZE2-1;
  148419. cinfo->Ah = 0;
  148420. cinfo->Al = 0;
  148421. }
  148422. }
  148423. LOCAL(void)
  148424. per_scan_setup (j_compress_ptr cinfo)
  148425. {
  148426. int ci, mcublks, tmp;
  148427. jpeg_component_info *compptr;
  148428. if (cinfo->comps_in_scan == 1) {
  148429. compptr = cinfo->cur_comp_info[0];
  148430. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148431. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148432. compptr->MCU_width = 1;
  148433. compptr->MCU_height = 1;
  148434. compptr->MCU_blocks = 1;
  148435. compptr->MCU_sample_width = DCTSIZE;
  148436. compptr->last_col_width = 1;
  148437. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148438. if (tmp == 0) tmp = compptr->v_samp_factor;
  148439. compptr->last_row_height = tmp;
  148440. cinfo->blocks_in_MCU = 1;
  148441. cinfo->MCU_membership[0] = 0;
  148442. } else {
  148443. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148444. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148445. MAX_COMPS_IN_SCAN);
  148446. cinfo->MCUs_per_row = (JDIMENSION)
  148447. jdiv_round_up((long) cinfo->image_width,
  148448. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148449. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148450. jdiv_round_up((long) cinfo->image_height,
  148451. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148452. cinfo->blocks_in_MCU = 0;
  148453. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148454. compptr = cinfo->cur_comp_info[ci];
  148455. compptr->MCU_width = compptr->h_samp_factor;
  148456. compptr->MCU_height = compptr->v_samp_factor;
  148457. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148458. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148459. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148460. if (tmp == 0) tmp = compptr->MCU_width;
  148461. compptr->last_col_width = tmp;
  148462. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148463. if (tmp == 0) tmp = compptr->MCU_height;
  148464. compptr->last_row_height = tmp;
  148465. mcublks = compptr->MCU_blocks;
  148466. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148467. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148468. while (mcublks-- > 0) {
  148469. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148470. }
  148471. }
  148472. }
  148473. if (cinfo->restart_in_rows > 0) {
  148474. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148475. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148476. }
  148477. }
  148478. METHODDEF(void)
  148479. prepare_for_pass (j_compress_ptr cinfo)
  148480. {
  148481. my_master_ptr master = (my_master_ptr) cinfo->master;
  148482. switch (master->pass_type) {
  148483. case main_pass:
  148484. select_scan_parameters(cinfo);
  148485. per_scan_setup(cinfo);
  148486. if (! cinfo->raw_data_in) {
  148487. (*cinfo->cconvert->start_pass) (cinfo);
  148488. (*cinfo->downsample->start_pass) (cinfo);
  148489. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148490. }
  148491. (*cinfo->fdct->start_pass) (cinfo);
  148492. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148493. (*cinfo->coef->start_pass) (cinfo,
  148494. (master->total_passes > 1 ?
  148495. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148496. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148497. if (cinfo->optimize_coding) {
  148498. master->pub.call_pass_startup = FALSE;
  148499. } else {
  148500. master->pub.call_pass_startup = TRUE;
  148501. }
  148502. break;
  148503. #ifdef ENTROPY_OPT_SUPPORTED
  148504. case huff_opt_pass:
  148505. select_scan_parameters(cinfo);
  148506. per_scan_setup(cinfo);
  148507. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148508. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148509. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148510. master->pub.call_pass_startup = FALSE;
  148511. break;
  148512. }
  148513. master->pass_type = output_pass;
  148514. master->pass_number++;
  148515. #endif
  148516. case output_pass:
  148517. if (! cinfo->optimize_coding) {
  148518. select_scan_parameters(cinfo);
  148519. per_scan_setup(cinfo);
  148520. }
  148521. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148522. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148523. if (master->scan_number == 0)
  148524. (*cinfo->marker->write_frame_header) (cinfo);
  148525. (*cinfo->marker->write_scan_header) (cinfo);
  148526. master->pub.call_pass_startup = FALSE;
  148527. break;
  148528. default:
  148529. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148530. }
  148531. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148532. if (cinfo->progress != NULL) {
  148533. cinfo->progress->completed_passes = master->pass_number;
  148534. cinfo->progress->total_passes = master->total_passes;
  148535. }
  148536. }
  148537. METHODDEF(void)
  148538. pass_startup (j_compress_ptr cinfo)
  148539. {
  148540. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148541. (*cinfo->marker->write_frame_header) (cinfo);
  148542. (*cinfo->marker->write_scan_header) (cinfo);
  148543. }
  148544. METHODDEF(void)
  148545. finish_pass_master (j_compress_ptr cinfo)
  148546. {
  148547. my_master_ptr master = (my_master_ptr) cinfo->master;
  148548. (*cinfo->entropy->finish_pass) (cinfo);
  148549. switch (master->pass_type) {
  148550. case main_pass:
  148551. master->pass_type = output_pass;
  148552. if (! cinfo->optimize_coding)
  148553. master->scan_number++;
  148554. break;
  148555. case huff_opt_pass:
  148556. master->pass_type = output_pass;
  148557. break;
  148558. case output_pass:
  148559. if (cinfo->optimize_coding)
  148560. master->pass_type = huff_opt_pass;
  148561. master->scan_number++;
  148562. break;
  148563. }
  148564. master->pass_number++;
  148565. }
  148566. GLOBAL(void)
  148567. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148568. {
  148569. my_master_ptr master;
  148570. master = (my_master_ptr)
  148571. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148572. SIZEOF(my_comp_master));
  148573. cinfo->master = (struct jpeg_comp_master *) master;
  148574. master->pub.prepare_for_pass = prepare_for_pass;
  148575. master->pub.pass_startup = pass_startup;
  148576. master->pub.finish_pass = finish_pass_master;
  148577. master->pub.is_last_pass = FALSE;
  148578. initial_setup(cinfo);
  148579. if (cinfo->scan_info != NULL) {
  148580. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148581. validate_script(cinfo);
  148582. #else
  148583. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148584. #endif
  148585. } else {
  148586. cinfo->progressive_mode = FALSE;
  148587. cinfo->num_scans = 1;
  148588. }
  148589. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148590. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148591. if (transcode_only) {
  148592. if (cinfo->optimize_coding)
  148593. master->pass_type = huff_opt_pass;
  148594. else
  148595. master->pass_type = output_pass;
  148596. } else {
  148597. master->pass_type = main_pass;
  148598. }
  148599. master->scan_number = 0;
  148600. master->pass_number = 0;
  148601. if (cinfo->optimize_coding)
  148602. master->total_passes = cinfo->num_scans * 2;
  148603. else
  148604. master->total_passes = cinfo->num_scans;
  148605. }
  148606. /*** End of inlined file: jcmaster.c ***/
  148607. /*** Start of inlined file: jcomapi.c ***/
  148608. #define JPEG_INTERNALS
  148609. GLOBAL(void)
  148610. jpeg_abort (j_common_ptr cinfo)
  148611. {
  148612. int pool;
  148613. if (cinfo->mem == NULL)
  148614. return;
  148615. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148616. (*cinfo->mem->free_pool) (cinfo, pool);
  148617. }
  148618. if (cinfo->is_decompressor) {
  148619. cinfo->global_state = DSTATE_START;
  148620. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148621. } else {
  148622. cinfo->global_state = CSTATE_START;
  148623. }
  148624. }
  148625. GLOBAL(void)
  148626. jpeg_destroy (j_common_ptr cinfo)
  148627. {
  148628. if (cinfo->mem != NULL)
  148629. (*cinfo->mem->self_destruct) (cinfo);
  148630. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148631. cinfo->global_state = 0; /* mark it destroyed */
  148632. }
  148633. GLOBAL(JQUANT_TBL *)
  148634. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148635. {
  148636. JQUANT_TBL *tbl;
  148637. tbl = (JQUANT_TBL *)
  148638. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148639. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148640. return tbl;
  148641. }
  148642. GLOBAL(JHUFF_TBL *)
  148643. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148644. {
  148645. JHUFF_TBL *tbl;
  148646. tbl = (JHUFF_TBL *)
  148647. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148648. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148649. return tbl;
  148650. }
  148651. /*** End of inlined file: jcomapi.c ***/
  148652. /*** Start of inlined file: jcparam.c ***/
  148653. #define JPEG_INTERNALS
  148654. GLOBAL(void)
  148655. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148656. const unsigned int *basic_table,
  148657. int scale_factor, boolean force_baseline)
  148658. {
  148659. JQUANT_TBL ** qtblptr;
  148660. int i;
  148661. long temp;
  148662. if (cinfo->global_state != CSTATE_START)
  148663. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148664. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148665. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148666. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148667. if (*qtblptr == NULL)
  148668. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148669. for (i = 0; i < DCTSIZE2; i++) {
  148670. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  148671. if (temp <= 0L) temp = 1L;
  148672. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  148673. if (force_baseline && temp > 255L)
  148674. temp = 255L; /* limit to baseline range if requested */
  148675. (*qtblptr)->quantval[i] = (UINT16) temp;
  148676. }
  148677. (*qtblptr)->sent_table = FALSE;
  148678. }
  148679. GLOBAL(void)
  148680. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  148681. boolean force_baseline)
  148682. {
  148683. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  148684. 16, 11, 10, 16, 24, 40, 51, 61,
  148685. 12, 12, 14, 19, 26, 58, 60, 55,
  148686. 14, 13, 16, 24, 40, 57, 69, 56,
  148687. 14, 17, 22, 29, 51, 87, 80, 62,
  148688. 18, 22, 37, 56, 68, 109, 103, 77,
  148689. 24, 35, 55, 64, 81, 104, 113, 92,
  148690. 49, 64, 78, 87, 103, 121, 120, 101,
  148691. 72, 92, 95, 98, 112, 100, 103, 99
  148692. };
  148693. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  148694. 17, 18, 24, 47, 99, 99, 99, 99,
  148695. 18, 21, 26, 66, 99, 99, 99, 99,
  148696. 24, 26, 56, 99, 99, 99, 99, 99,
  148697. 47, 66, 99, 99, 99, 99, 99, 99,
  148698. 99, 99, 99, 99, 99, 99, 99, 99,
  148699. 99, 99, 99, 99, 99, 99, 99, 99,
  148700. 99, 99, 99, 99, 99, 99, 99, 99,
  148701. 99, 99, 99, 99, 99, 99, 99, 99
  148702. };
  148703. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  148704. scale_factor, force_baseline);
  148705. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  148706. scale_factor, force_baseline);
  148707. }
  148708. GLOBAL(int)
  148709. jpeg_quality_scaling (int quality)
  148710. {
  148711. if (quality <= 0) quality = 1;
  148712. if (quality > 100) quality = 100;
  148713. if (quality < 50)
  148714. quality = 5000 / quality;
  148715. else
  148716. quality = 200 - quality*2;
  148717. return quality;
  148718. }
  148719. GLOBAL(void)
  148720. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  148721. {
  148722. quality = jpeg_quality_scaling(quality);
  148723. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  148724. }
  148725. LOCAL(void)
  148726. add_huff_table (j_compress_ptr cinfo,
  148727. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  148728. {
  148729. int nsymbols, len;
  148730. if (*htblptr == NULL)
  148731. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148732. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  148733. nsymbols = 0;
  148734. for (len = 1; len <= 16; len++)
  148735. nsymbols += bits[len];
  148736. if (nsymbols < 1 || nsymbols > 256)
  148737. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  148738. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  148739. (*htblptr)->sent_table = FALSE;
  148740. }
  148741. LOCAL(void)
  148742. std_huff_tables (j_compress_ptr cinfo)
  148743. {
  148744. static const UINT8 bits_dc_luminance[17] =
  148745. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  148746. static const UINT8 val_dc_luminance[] =
  148747. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148748. static const UINT8 bits_dc_chrominance[17] =
  148749. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  148750. static const UINT8 val_dc_chrominance[] =
  148751. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148752. static const UINT8 bits_ac_luminance[17] =
  148753. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  148754. static const UINT8 val_ac_luminance[] =
  148755. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  148756. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  148757. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  148758. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  148759. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  148760. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  148761. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  148762. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  148763. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  148764. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  148765. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  148766. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  148767. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  148768. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  148769. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  148770. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  148771. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  148772. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  148773. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  148774. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148775. 0xf9, 0xfa };
  148776. static const UINT8 bits_ac_chrominance[17] =
  148777. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  148778. static const UINT8 val_ac_chrominance[] =
  148779. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  148780. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  148781. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  148782. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  148783. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  148784. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  148785. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  148786. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  148787. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  148788. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  148789. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  148790. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  148791. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  148792. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  148793. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  148794. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  148795. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  148796. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  148797. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  148798. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148799. 0xf9, 0xfa };
  148800. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  148801. bits_dc_luminance, val_dc_luminance);
  148802. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  148803. bits_ac_luminance, val_ac_luminance);
  148804. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  148805. bits_dc_chrominance, val_dc_chrominance);
  148806. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  148807. bits_ac_chrominance, val_ac_chrominance);
  148808. }
  148809. GLOBAL(void)
  148810. jpeg_set_defaults (j_compress_ptr cinfo)
  148811. {
  148812. int i;
  148813. if (cinfo->global_state != CSTATE_START)
  148814. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148815. if (cinfo->comp_info == NULL)
  148816. cinfo->comp_info = (jpeg_component_info *)
  148817. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148818. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  148819. cinfo->data_precision = BITS_IN_JSAMPLE;
  148820. jpeg_set_quality(cinfo, 75, TRUE);
  148821. std_huff_tables(cinfo);
  148822. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148823. cinfo->arith_dc_L[i] = 0;
  148824. cinfo->arith_dc_U[i] = 1;
  148825. cinfo->arith_ac_K[i] = 5;
  148826. }
  148827. cinfo->scan_info = NULL;
  148828. cinfo->num_scans = 0;
  148829. cinfo->raw_data_in = FALSE;
  148830. cinfo->arith_code = FALSE;
  148831. cinfo->optimize_coding = FALSE;
  148832. if (cinfo->data_precision > 8)
  148833. cinfo->optimize_coding = TRUE;
  148834. cinfo->CCIR601_sampling = FALSE;
  148835. cinfo->smoothing_factor = 0;
  148836. cinfo->dct_method = JDCT_DEFAULT;
  148837. cinfo->restart_interval = 0;
  148838. cinfo->restart_in_rows = 0;
  148839. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  148840. cinfo->JFIF_minor_version = 1;
  148841. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  148842. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  148843. cinfo->Y_density = 1;
  148844. jpeg_default_colorspace(cinfo);
  148845. }
  148846. GLOBAL(void)
  148847. jpeg_default_colorspace (j_compress_ptr cinfo)
  148848. {
  148849. switch (cinfo->in_color_space) {
  148850. case JCS_GRAYSCALE:
  148851. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  148852. break;
  148853. case JCS_RGB:
  148854. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148855. break;
  148856. case JCS_YCbCr:
  148857. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148858. break;
  148859. case JCS_CMYK:
  148860. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  148861. break;
  148862. case JCS_YCCK:
  148863. jpeg_set_colorspace(cinfo, JCS_YCCK);
  148864. break;
  148865. case JCS_UNKNOWN:
  148866. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  148867. break;
  148868. default:
  148869. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  148870. }
  148871. }
  148872. GLOBAL(void)
  148873. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  148874. {
  148875. jpeg_component_info * compptr;
  148876. int ci;
  148877. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  148878. (compptr = &cinfo->comp_info[index], \
  148879. compptr->component_id = (id), \
  148880. compptr->h_samp_factor = (hsamp), \
  148881. compptr->v_samp_factor = (vsamp), \
  148882. compptr->quant_tbl_no = (quant), \
  148883. compptr->dc_tbl_no = (dctbl), \
  148884. compptr->ac_tbl_no = (actbl) )
  148885. if (cinfo->global_state != CSTATE_START)
  148886. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148887. cinfo->jpeg_color_space = colorspace;
  148888. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  148889. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  148890. switch (colorspace) {
  148891. case JCS_GRAYSCALE:
  148892. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148893. cinfo->num_components = 1;
  148894. SET_COMP(0, 1, 1,1, 0, 0,0);
  148895. break;
  148896. case JCS_RGB:
  148897. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  148898. cinfo->num_components = 3;
  148899. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  148900. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  148901. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  148902. break;
  148903. case JCS_YCbCr:
  148904. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148905. cinfo->num_components = 3;
  148906. SET_COMP(0, 1, 2,2, 0, 0,0);
  148907. SET_COMP(1, 2, 1,1, 1, 1,1);
  148908. SET_COMP(2, 3, 1,1, 1, 1,1);
  148909. break;
  148910. case JCS_CMYK:
  148911. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  148912. cinfo->num_components = 4;
  148913. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  148914. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  148915. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  148916. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  148917. break;
  148918. case JCS_YCCK:
  148919. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  148920. cinfo->num_components = 4;
  148921. SET_COMP(0, 1, 2,2, 0, 0,0);
  148922. SET_COMP(1, 2, 1,1, 1, 1,1);
  148923. SET_COMP(2, 3, 1,1, 1, 1,1);
  148924. SET_COMP(3, 4, 2,2, 0, 0,0);
  148925. break;
  148926. case JCS_UNKNOWN:
  148927. cinfo->num_components = cinfo->input_components;
  148928. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  148929. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148930. MAX_COMPONENTS);
  148931. for (ci = 0; ci < cinfo->num_components; ci++) {
  148932. SET_COMP(ci, ci, 1,1, 0, 0,0);
  148933. }
  148934. break;
  148935. default:
  148936. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  148937. }
  148938. }
  148939. #ifdef C_PROGRESSIVE_SUPPORTED
  148940. LOCAL(jpeg_scan_info *)
  148941. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  148942. int Ss, int Se, int Ah, int Al)
  148943. {
  148944. scanptr->comps_in_scan = 1;
  148945. scanptr->component_index[0] = ci;
  148946. scanptr->Ss = Ss;
  148947. scanptr->Se = Se;
  148948. scanptr->Ah = Ah;
  148949. scanptr->Al = Al;
  148950. scanptr++;
  148951. return scanptr;
  148952. }
  148953. LOCAL(jpeg_scan_info *)
  148954. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  148955. int Ss, int Se, int Ah, int Al)
  148956. {
  148957. int ci;
  148958. for (ci = 0; ci < ncomps; ci++) {
  148959. scanptr->comps_in_scan = 1;
  148960. scanptr->component_index[0] = ci;
  148961. scanptr->Ss = Ss;
  148962. scanptr->Se = Se;
  148963. scanptr->Ah = Ah;
  148964. scanptr->Al = Al;
  148965. scanptr++;
  148966. }
  148967. return scanptr;
  148968. }
  148969. LOCAL(jpeg_scan_info *)
  148970. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  148971. {
  148972. int ci;
  148973. if (ncomps <= MAX_COMPS_IN_SCAN) {
  148974. scanptr->comps_in_scan = ncomps;
  148975. for (ci = 0; ci < ncomps; ci++)
  148976. scanptr->component_index[ci] = ci;
  148977. scanptr->Ss = scanptr->Se = 0;
  148978. scanptr->Ah = Ah;
  148979. scanptr->Al = Al;
  148980. scanptr++;
  148981. } else {
  148982. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  148983. }
  148984. return scanptr;
  148985. }
  148986. GLOBAL(void)
  148987. jpeg_simple_progression (j_compress_ptr cinfo)
  148988. {
  148989. int ncomps = cinfo->num_components;
  148990. int nscans;
  148991. jpeg_scan_info * scanptr;
  148992. if (cinfo->global_state != CSTATE_START)
  148993. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148994. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148995. nscans = 10;
  148996. } else {
  148997. if (ncomps > MAX_COMPS_IN_SCAN)
  148998. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  148999. else
  149000. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  149001. }
  149002. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  149003. cinfo->script_space_size = MAX(nscans, 10);
  149004. cinfo->script_space = (jpeg_scan_info *)
  149005. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149006. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  149007. }
  149008. scanptr = cinfo->script_space;
  149009. cinfo->scan_info = scanptr;
  149010. cinfo->num_scans = nscans;
  149011. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149012. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149013. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  149014. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  149015. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  149016. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  149017. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  149018. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149019. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  149020. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  149021. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  149022. } else {
  149023. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149024. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  149025. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  149026. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  149027. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149028. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  149029. }
  149030. }
  149031. #endif /* C_PROGRESSIVE_SUPPORTED */
  149032. /*** End of inlined file: jcparam.c ***/
  149033. /*** Start of inlined file: jcphuff.c ***/
  149034. #define JPEG_INTERNALS
  149035. #ifdef C_PROGRESSIVE_SUPPORTED
  149036. typedef struct {
  149037. struct jpeg_entropy_encoder pub; /* public fields */
  149038. boolean gather_statistics;
  149039. JOCTET * next_output_byte; /* => next byte to write in buffer */
  149040. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  149041. INT32 put_buffer; /* current bit-accumulation buffer */
  149042. int put_bits; /* # of bits now in it */
  149043. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  149044. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  149045. int ac_tbl_no; /* the table number of the single component */
  149046. unsigned int EOBRUN; /* run length of EOBs */
  149047. unsigned int BE; /* # of buffered correction bits before MCU */
  149048. char * bit_buffer; /* buffer for correction bits (1 per char) */
  149049. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  149050. int next_restart_num; /* next restart number to write (0-7) */
  149051. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  149052. long * count_ptrs[NUM_HUFF_TBLS];
  149053. } phuff_entropy_encoder;
  149054. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  149055. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  149056. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  149057. #define ISHIFT_TEMPS int ishift_temp;
  149058. #define IRIGHT_SHIFT(x,shft) \
  149059. ((ishift_temp = (x)) < 0 ? \
  149060. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  149061. (ishift_temp >> (shft)))
  149062. #else
  149063. #define ISHIFT_TEMPS
  149064. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  149065. #endif
  149066. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  149067. JBLOCKROW *MCU_data));
  149068. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  149069. JBLOCKROW *MCU_data));
  149070. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  149071. JBLOCKROW *MCU_data));
  149072. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  149073. JBLOCKROW *MCU_data));
  149074. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  149075. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  149076. METHODDEF(void)
  149077. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  149078. {
  149079. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149080. boolean is_DC_band;
  149081. int ci, tbl;
  149082. jpeg_component_info * compptr;
  149083. entropy->cinfo = cinfo;
  149084. entropy->gather_statistics = gather_statistics;
  149085. is_DC_band = (cinfo->Ss == 0);
  149086. if (cinfo->Ah == 0) {
  149087. if (is_DC_band)
  149088. entropy->pub.encode_mcu = encode_mcu_DC_first;
  149089. else
  149090. entropy->pub.encode_mcu = encode_mcu_AC_first;
  149091. } else {
  149092. if (is_DC_band)
  149093. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  149094. else {
  149095. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  149096. if (entropy->bit_buffer == NULL)
  149097. entropy->bit_buffer = (char *)
  149098. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149099. MAX_CORR_BITS * SIZEOF(char));
  149100. }
  149101. }
  149102. if (gather_statistics)
  149103. entropy->pub.finish_pass = finish_pass_gather_phuff;
  149104. else
  149105. entropy->pub.finish_pass = finish_pass_phuff;
  149106. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149107. compptr = cinfo->cur_comp_info[ci];
  149108. entropy->last_dc_val[ci] = 0;
  149109. if (is_DC_band) {
  149110. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149111. continue;
  149112. tbl = compptr->dc_tbl_no;
  149113. } else {
  149114. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  149115. }
  149116. if (gather_statistics) {
  149117. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  149118. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  149119. if (entropy->count_ptrs[tbl] == NULL)
  149120. entropy->count_ptrs[tbl] = (long *)
  149121. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149122. 257 * SIZEOF(long));
  149123. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  149124. } else {
  149125. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  149126. & entropy->derived_tbls[tbl]);
  149127. }
  149128. }
  149129. entropy->EOBRUN = 0;
  149130. entropy->BE = 0;
  149131. entropy->put_buffer = 0;
  149132. entropy->put_bits = 0;
  149133. entropy->restarts_to_go = cinfo->restart_interval;
  149134. entropy->next_restart_num = 0;
  149135. }
  149136. #define emit_byte(entropy,val) \
  149137. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  149138. if (--(entropy)->free_in_buffer == 0) \
  149139. dump_buffer_p(entropy); }
  149140. LOCAL(void)
  149141. dump_buffer_p (phuff_entropy_ptr entropy)
  149142. {
  149143. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  149144. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  149145. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  149146. entropy->next_output_byte = dest->next_output_byte;
  149147. entropy->free_in_buffer = dest->free_in_buffer;
  149148. }
  149149. INLINE
  149150. LOCAL(void)
  149151. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  149152. {
  149153. register INT32 put_buffer = (INT32) code;
  149154. register int put_bits = entropy->put_bits;
  149155. if (size == 0)
  149156. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149157. if (entropy->gather_statistics)
  149158. return; /* do nothing if we're only getting stats */
  149159. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  149160. put_bits += size; /* new number of bits in buffer */
  149161. put_buffer <<= 24 - put_bits; /* align incoming bits */
  149162. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  149163. while (put_bits >= 8) {
  149164. int c = (int) ((put_buffer >> 16) & 0xFF);
  149165. emit_byte(entropy, c);
  149166. if (c == 0xFF) { /* need to stuff a zero byte? */
  149167. emit_byte(entropy, 0);
  149168. }
  149169. put_buffer <<= 8;
  149170. put_bits -= 8;
  149171. }
  149172. entropy->put_buffer = put_buffer; /* update variables */
  149173. entropy->put_bits = put_bits;
  149174. }
  149175. LOCAL(void)
  149176. flush_bits_p (phuff_entropy_ptr entropy)
  149177. {
  149178. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  149179. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  149180. entropy->put_bits = 0;
  149181. }
  149182. INLINE
  149183. LOCAL(void)
  149184. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  149185. {
  149186. if (entropy->gather_statistics)
  149187. entropy->count_ptrs[tbl_no][symbol]++;
  149188. else {
  149189. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  149190. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  149191. }
  149192. }
  149193. LOCAL(void)
  149194. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  149195. unsigned int nbits)
  149196. {
  149197. if (entropy->gather_statistics)
  149198. return; /* no real work */
  149199. while (nbits > 0) {
  149200. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  149201. bufstart++;
  149202. nbits--;
  149203. }
  149204. }
  149205. LOCAL(void)
  149206. emit_eobrun (phuff_entropy_ptr entropy)
  149207. {
  149208. register int temp, nbits;
  149209. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  149210. temp = entropy->EOBRUN;
  149211. nbits = 0;
  149212. while ((temp >>= 1))
  149213. nbits++;
  149214. if (nbits > 14)
  149215. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149216. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  149217. if (nbits)
  149218. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  149219. entropy->EOBRUN = 0;
  149220. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  149221. entropy->BE = 0;
  149222. }
  149223. }
  149224. LOCAL(void)
  149225. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  149226. {
  149227. int ci;
  149228. emit_eobrun(entropy);
  149229. if (! entropy->gather_statistics) {
  149230. flush_bits_p(entropy);
  149231. emit_byte(entropy, 0xFF);
  149232. emit_byte(entropy, JPEG_RST0 + restart_num);
  149233. }
  149234. if (entropy->cinfo->Ss == 0) {
  149235. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  149236. entropy->last_dc_val[ci] = 0;
  149237. } else {
  149238. entropy->EOBRUN = 0;
  149239. entropy->BE = 0;
  149240. }
  149241. }
  149242. METHODDEF(boolean)
  149243. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149244. {
  149245. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149246. register int temp, temp2;
  149247. register int nbits;
  149248. int blkn, ci;
  149249. int Al = cinfo->Al;
  149250. JBLOCKROW block;
  149251. jpeg_component_info * compptr;
  149252. ISHIFT_TEMPS
  149253. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149254. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149255. if (cinfo->restart_interval)
  149256. if (entropy->restarts_to_go == 0)
  149257. emit_restart_p(entropy, entropy->next_restart_num);
  149258. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149259. block = MCU_data[blkn];
  149260. ci = cinfo->MCU_membership[blkn];
  149261. compptr = cinfo->cur_comp_info[ci];
  149262. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  149263. temp = temp2 - entropy->last_dc_val[ci];
  149264. entropy->last_dc_val[ci] = temp2;
  149265. temp2 = temp;
  149266. if (temp < 0) {
  149267. temp = -temp; /* temp is abs value of input */
  149268. temp2--;
  149269. }
  149270. nbits = 0;
  149271. while (temp) {
  149272. nbits++;
  149273. temp >>= 1;
  149274. }
  149275. if (nbits > MAX_COEF_BITS+1)
  149276. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149277. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  149278. if (nbits) /* emit_bits rejects calls with size 0 */
  149279. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149280. }
  149281. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149282. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149283. if (cinfo->restart_interval) {
  149284. if (entropy->restarts_to_go == 0) {
  149285. entropy->restarts_to_go = cinfo->restart_interval;
  149286. entropy->next_restart_num++;
  149287. entropy->next_restart_num &= 7;
  149288. }
  149289. entropy->restarts_to_go--;
  149290. }
  149291. return TRUE;
  149292. }
  149293. METHODDEF(boolean)
  149294. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149295. {
  149296. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149297. register int temp, temp2;
  149298. register int nbits;
  149299. register int r, k;
  149300. int Se = cinfo->Se;
  149301. int Al = cinfo->Al;
  149302. JBLOCKROW block;
  149303. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149304. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149305. if (cinfo->restart_interval)
  149306. if (entropy->restarts_to_go == 0)
  149307. emit_restart_p(entropy, entropy->next_restart_num);
  149308. block = MCU_data[0];
  149309. r = 0; /* r = run length of zeros */
  149310. for (k = cinfo->Ss; k <= Se; k++) {
  149311. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149312. r++;
  149313. continue;
  149314. }
  149315. if (temp < 0) {
  149316. temp = -temp; /* temp is abs value of input */
  149317. temp >>= Al; /* apply the point transform */
  149318. temp2 = ~temp;
  149319. } else {
  149320. temp >>= Al; /* apply the point transform */
  149321. temp2 = temp;
  149322. }
  149323. if (temp == 0) {
  149324. r++;
  149325. continue;
  149326. }
  149327. if (entropy->EOBRUN > 0)
  149328. emit_eobrun(entropy);
  149329. while (r > 15) {
  149330. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149331. r -= 16;
  149332. }
  149333. nbits = 1; /* there must be at least one 1 bit */
  149334. while ((temp >>= 1))
  149335. nbits++;
  149336. if (nbits > MAX_COEF_BITS)
  149337. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149338. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149339. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149340. r = 0; /* reset zero run length */
  149341. }
  149342. if (r > 0) { /* If there are trailing zeroes, */
  149343. entropy->EOBRUN++; /* count an EOB */
  149344. if (entropy->EOBRUN == 0x7FFF)
  149345. emit_eobrun(entropy); /* force it out to avoid overflow */
  149346. }
  149347. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149348. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149349. if (cinfo->restart_interval) {
  149350. if (entropy->restarts_to_go == 0) {
  149351. entropy->restarts_to_go = cinfo->restart_interval;
  149352. entropy->next_restart_num++;
  149353. entropy->next_restart_num &= 7;
  149354. }
  149355. entropy->restarts_to_go--;
  149356. }
  149357. return TRUE;
  149358. }
  149359. METHODDEF(boolean)
  149360. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149361. {
  149362. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149363. register int temp;
  149364. int blkn;
  149365. int Al = cinfo->Al;
  149366. JBLOCKROW block;
  149367. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149368. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149369. if (cinfo->restart_interval)
  149370. if (entropy->restarts_to_go == 0)
  149371. emit_restart_p(entropy, entropy->next_restart_num);
  149372. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149373. block = MCU_data[blkn];
  149374. temp = (*block)[0];
  149375. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149376. }
  149377. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149378. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149379. if (cinfo->restart_interval) {
  149380. if (entropy->restarts_to_go == 0) {
  149381. entropy->restarts_to_go = cinfo->restart_interval;
  149382. entropy->next_restart_num++;
  149383. entropy->next_restart_num &= 7;
  149384. }
  149385. entropy->restarts_to_go--;
  149386. }
  149387. return TRUE;
  149388. }
  149389. METHODDEF(boolean)
  149390. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149391. {
  149392. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149393. register int temp;
  149394. register int r, k;
  149395. int EOB;
  149396. char *BR_buffer;
  149397. unsigned int BR;
  149398. int Se = cinfo->Se;
  149399. int Al = cinfo->Al;
  149400. JBLOCKROW block;
  149401. int absvalues[DCTSIZE2];
  149402. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149403. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149404. if (cinfo->restart_interval)
  149405. if (entropy->restarts_to_go == 0)
  149406. emit_restart_p(entropy, entropy->next_restart_num);
  149407. block = MCU_data[0];
  149408. EOB = 0;
  149409. for (k = cinfo->Ss; k <= Se; k++) {
  149410. temp = (*block)[jpeg_natural_order[k]];
  149411. if (temp < 0)
  149412. temp = -temp; /* temp is abs value of input */
  149413. temp >>= Al; /* apply the point transform */
  149414. absvalues[k] = temp; /* save abs value for main pass */
  149415. if (temp == 1)
  149416. EOB = k; /* EOB = index of last newly-nonzero coef */
  149417. }
  149418. r = 0; /* r = run length of zeros */
  149419. BR = 0; /* BR = count of buffered bits added now */
  149420. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149421. for (k = cinfo->Ss; k <= Se; k++) {
  149422. if ((temp = absvalues[k]) == 0) {
  149423. r++;
  149424. continue;
  149425. }
  149426. while (r > 15 && k <= EOB) {
  149427. emit_eobrun(entropy);
  149428. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149429. r -= 16;
  149430. emit_buffered_bits(entropy, BR_buffer, BR);
  149431. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149432. BR = 0;
  149433. }
  149434. if (temp > 1) {
  149435. BR_buffer[BR++] = (char) (temp & 1);
  149436. continue;
  149437. }
  149438. emit_eobrun(entropy);
  149439. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149440. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149441. emit_bits_p(entropy, (unsigned int) temp, 1);
  149442. emit_buffered_bits(entropy, BR_buffer, BR);
  149443. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149444. BR = 0;
  149445. r = 0; /* reset zero run length */
  149446. }
  149447. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149448. entropy->EOBRUN++; /* count an EOB */
  149449. entropy->BE += BR; /* concat my correction bits to older ones */
  149450. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149451. emit_eobrun(entropy);
  149452. }
  149453. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149454. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149455. if (cinfo->restart_interval) {
  149456. if (entropy->restarts_to_go == 0) {
  149457. entropy->restarts_to_go = cinfo->restart_interval;
  149458. entropy->next_restart_num++;
  149459. entropy->next_restart_num &= 7;
  149460. }
  149461. entropy->restarts_to_go--;
  149462. }
  149463. return TRUE;
  149464. }
  149465. METHODDEF(void)
  149466. finish_pass_phuff (j_compress_ptr cinfo)
  149467. {
  149468. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149469. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149470. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149471. emit_eobrun(entropy);
  149472. flush_bits_p(entropy);
  149473. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149474. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149475. }
  149476. METHODDEF(void)
  149477. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149478. {
  149479. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149480. boolean is_DC_band;
  149481. int ci, tbl;
  149482. jpeg_component_info * compptr;
  149483. JHUFF_TBL **htblptr;
  149484. boolean did[NUM_HUFF_TBLS];
  149485. emit_eobrun(entropy);
  149486. is_DC_band = (cinfo->Ss == 0);
  149487. MEMZERO(did, SIZEOF(did));
  149488. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149489. compptr = cinfo->cur_comp_info[ci];
  149490. if (is_DC_band) {
  149491. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149492. continue;
  149493. tbl = compptr->dc_tbl_no;
  149494. } else {
  149495. tbl = compptr->ac_tbl_no;
  149496. }
  149497. if (! did[tbl]) {
  149498. if (is_DC_band)
  149499. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149500. else
  149501. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149502. if (*htblptr == NULL)
  149503. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149504. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149505. did[tbl] = TRUE;
  149506. }
  149507. }
  149508. }
  149509. GLOBAL(void)
  149510. jinit_phuff_encoder (j_compress_ptr cinfo)
  149511. {
  149512. phuff_entropy_ptr entropy;
  149513. int i;
  149514. entropy = (phuff_entropy_ptr)
  149515. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149516. SIZEOF(phuff_entropy_encoder));
  149517. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149518. entropy->pub.start_pass = start_pass_phuff;
  149519. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149520. entropy->derived_tbls[i] = NULL;
  149521. entropy->count_ptrs[i] = NULL;
  149522. }
  149523. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149524. }
  149525. #endif /* C_PROGRESSIVE_SUPPORTED */
  149526. /*** End of inlined file: jcphuff.c ***/
  149527. /*** Start of inlined file: jcprepct.c ***/
  149528. #define JPEG_INTERNALS
  149529. #ifdef INPUT_SMOOTHING_SUPPORTED
  149530. #define CONTEXT_ROWS_SUPPORTED
  149531. #endif
  149532. typedef struct {
  149533. struct jpeg_c_prep_controller pub; /* public fields */
  149534. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149535. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149536. int next_buf_row; /* index of next row to store in color_buf */
  149537. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149538. int this_row_group; /* starting row index of group to process */
  149539. int next_buf_stop; /* downsample when we reach this index */
  149540. #endif
  149541. } my_prep_controller;
  149542. typedef my_prep_controller * my_prep_ptr;
  149543. METHODDEF(void)
  149544. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149545. {
  149546. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149547. if (pass_mode != JBUF_PASS_THRU)
  149548. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149549. prep->rows_to_go = cinfo->image_height;
  149550. prep->next_buf_row = 0;
  149551. #ifdef CONTEXT_ROWS_SUPPORTED
  149552. prep->this_row_group = 0;
  149553. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149554. #endif
  149555. }
  149556. LOCAL(void)
  149557. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149558. int input_rows, int output_rows)
  149559. {
  149560. register int row;
  149561. for (row = input_rows; row < output_rows; row++) {
  149562. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149563. 1, num_cols);
  149564. }
  149565. }
  149566. METHODDEF(void)
  149567. pre_process_data (j_compress_ptr cinfo,
  149568. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149569. JDIMENSION in_rows_avail,
  149570. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149571. JDIMENSION out_row_groups_avail)
  149572. {
  149573. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149574. int numrows, ci;
  149575. JDIMENSION inrows;
  149576. jpeg_component_info * compptr;
  149577. while (*in_row_ctr < in_rows_avail &&
  149578. *out_row_group_ctr < out_row_groups_avail) {
  149579. inrows = in_rows_avail - *in_row_ctr;
  149580. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149581. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149582. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149583. prep->color_buf,
  149584. (JDIMENSION) prep->next_buf_row,
  149585. numrows);
  149586. *in_row_ctr += numrows;
  149587. prep->next_buf_row += numrows;
  149588. prep->rows_to_go -= numrows;
  149589. if (prep->rows_to_go == 0 &&
  149590. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149591. for (ci = 0; ci < cinfo->num_components; ci++) {
  149592. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149593. prep->next_buf_row, cinfo->max_v_samp_factor);
  149594. }
  149595. prep->next_buf_row = cinfo->max_v_samp_factor;
  149596. }
  149597. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149598. (*cinfo->downsample->downsample) (cinfo,
  149599. prep->color_buf, (JDIMENSION) 0,
  149600. output_buf, *out_row_group_ctr);
  149601. prep->next_buf_row = 0;
  149602. (*out_row_group_ctr)++;
  149603. }
  149604. if (prep->rows_to_go == 0 &&
  149605. *out_row_group_ctr < out_row_groups_avail) {
  149606. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149607. ci++, compptr++) {
  149608. expand_bottom_edge(output_buf[ci],
  149609. compptr->width_in_blocks * DCTSIZE,
  149610. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149611. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149612. }
  149613. *out_row_group_ctr = out_row_groups_avail;
  149614. break; /* can exit outer loop without test */
  149615. }
  149616. }
  149617. }
  149618. #ifdef CONTEXT_ROWS_SUPPORTED
  149619. METHODDEF(void)
  149620. pre_process_context (j_compress_ptr cinfo,
  149621. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149622. JDIMENSION in_rows_avail,
  149623. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149624. JDIMENSION out_row_groups_avail)
  149625. {
  149626. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149627. int numrows, ci;
  149628. int buf_height = cinfo->max_v_samp_factor * 3;
  149629. JDIMENSION inrows;
  149630. while (*out_row_group_ctr < out_row_groups_avail) {
  149631. if (*in_row_ctr < in_rows_avail) {
  149632. inrows = in_rows_avail - *in_row_ctr;
  149633. numrows = prep->next_buf_stop - prep->next_buf_row;
  149634. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149635. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149636. prep->color_buf,
  149637. (JDIMENSION) prep->next_buf_row,
  149638. numrows);
  149639. if (prep->rows_to_go == cinfo->image_height) {
  149640. for (ci = 0; ci < cinfo->num_components; ci++) {
  149641. int row;
  149642. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149643. jcopy_sample_rows(prep->color_buf[ci], 0,
  149644. prep->color_buf[ci], -row,
  149645. 1, cinfo->image_width);
  149646. }
  149647. }
  149648. }
  149649. *in_row_ctr += numrows;
  149650. prep->next_buf_row += numrows;
  149651. prep->rows_to_go -= numrows;
  149652. } else {
  149653. if (prep->rows_to_go != 0)
  149654. break;
  149655. if (prep->next_buf_row < prep->next_buf_stop) {
  149656. for (ci = 0; ci < cinfo->num_components; ci++) {
  149657. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149658. prep->next_buf_row, prep->next_buf_stop);
  149659. }
  149660. prep->next_buf_row = prep->next_buf_stop;
  149661. }
  149662. }
  149663. if (prep->next_buf_row == prep->next_buf_stop) {
  149664. (*cinfo->downsample->downsample) (cinfo,
  149665. prep->color_buf,
  149666. (JDIMENSION) prep->this_row_group,
  149667. output_buf, *out_row_group_ctr);
  149668. (*out_row_group_ctr)++;
  149669. prep->this_row_group += cinfo->max_v_samp_factor;
  149670. if (prep->this_row_group >= buf_height)
  149671. prep->this_row_group = 0;
  149672. if (prep->next_buf_row >= buf_height)
  149673. prep->next_buf_row = 0;
  149674. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  149675. }
  149676. }
  149677. }
  149678. LOCAL(void)
  149679. create_context_buffer (j_compress_ptr cinfo)
  149680. {
  149681. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149682. int rgroup_height = cinfo->max_v_samp_factor;
  149683. int ci, i;
  149684. jpeg_component_info * compptr;
  149685. JSAMPARRAY true_buffer, fake_buffer;
  149686. fake_buffer = (JSAMPARRAY)
  149687. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149688. (cinfo->num_components * 5 * rgroup_height) *
  149689. SIZEOF(JSAMPROW));
  149690. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149691. ci++, compptr++) {
  149692. true_buffer = (*cinfo->mem->alloc_sarray)
  149693. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149694. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149695. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149696. (JDIMENSION) (3 * rgroup_height));
  149697. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  149698. 3 * rgroup_height * SIZEOF(JSAMPROW));
  149699. for (i = 0; i < rgroup_height; i++) {
  149700. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  149701. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  149702. }
  149703. prep->color_buf[ci] = fake_buffer + rgroup_height;
  149704. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  149705. }
  149706. }
  149707. #endif /* CONTEXT_ROWS_SUPPORTED */
  149708. GLOBAL(void)
  149709. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  149710. {
  149711. my_prep_ptr prep;
  149712. int ci;
  149713. jpeg_component_info * compptr;
  149714. if (need_full_buffer) /* safety check */
  149715. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149716. prep = (my_prep_ptr)
  149717. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149718. SIZEOF(my_prep_controller));
  149719. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  149720. prep->pub.start_pass = start_pass_prep;
  149721. if (cinfo->downsample->need_context_rows) {
  149722. #ifdef CONTEXT_ROWS_SUPPORTED
  149723. prep->pub.pre_process_data = pre_process_context;
  149724. create_context_buffer(cinfo);
  149725. #else
  149726. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149727. #endif
  149728. } else {
  149729. prep->pub.pre_process_data = pre_process_data;
  149730. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149731. ci++, compptr++) {
  149732. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  149733. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149734. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149735. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149736. (JDIMENSION) cinfo->max_v_samp_factor);
  149737. }
  149738. }
  149739. }
  149740. /*** End of inlined file: jcprepct.c ***/
  149741. /*** Start of inlined file: jcsample.c ***/
  149742. #define JPEG_INTERNALS
  149743. typedef JMETHOD(void, downsample1_ptr,
  149744. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149745. JSAMPARRAY input_data, JSAMPARRAY output_data));
  149746. typedef struct {
  149747. struct jpeg_downsampler pub; /* public fields */
  149748. downsample1_ptr methods[MAX_COMPONENTS];
  149749. } my_downsampler;
  149750. typedef my_downsampler * my_downsample_ptr;
  149751. METHODDEF(void)
  149752. start_pass_downsample (j_compress_ptr cinfo)
  149753. {
  149754. }
  149755. LOCAL(void)
  149756. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  149757. JDIMENSION input_cols, JDIMENSION output_cols)
  149758. {
  149759. register JSAMPROW ptr;
  149760. register JSAMPLE pixval;
  149761. register int count;
  149762. int row;
  149763. int numcols = (int) (output_cols - input_cols);
  149764. if (numcols > 0) {
  149765. for (row = 0; row < num_rows; row++) {
  149766. ptr = image_data[row] + input_cols;
  149767. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  149768. for (count = numcols; count > 0; count--)
  149769. *ptr++ = pixval;
  149770. }
  149771. }
  149772. }
  149773. METHODDEF(void)
  149774. sep_downsample (j_compress_ptr cinfo,
  149775. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  149776. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  149777. {
  149778. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  149779. int ci;
  149780. jpeg_component_info * compptr;
  149781. JSAMPARRAY in_ptr, out_ptr;
  149782. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149783. ci++, compptr++) {
  149784. in_ptr = input_buf[ci] + in_row_index;
  149785. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  149786. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  149787. }
  149788. }
  149789. METHODDEF(void)
  149790. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149791. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149792. {
  149793. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  149794. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  149795. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149796. JSAMPROW inptr, outptr;
  149797. INT32 outvalue;
  149798. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  149799. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  149800. numpix = h_expand * v_expand;
  149801. numpix2 = numpix/2;
  149802. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149803. cinfo->image_width, output_cols * h_expand);
  149804. inrow = 0;
  149805. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149806. outptr = output_data[outrow];
  149807. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  149808. outcol++, outcol_h += h_expand) {
  149809. outvalue = 0;
  149810. for (v = 0; v < v_expand; v++) {
  149811. inptr = input_data[inrow+v] + outcol_h;
  149812. for (h = 0; h < h_expand; h++) {
  149813. outvalue += (INT32) GETJSAMPLE(*inptr++);
  149814. }
  149815. }
  149816. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  149817. }
  149818. inrow += v_expand;
  149819. }
  149820. }
  149821. METHODDEF(void)
  149822. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149823. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149824. {
  149825. jcopy_sample_rows(input_data, 0, output_data, 0,
  149826. cinfo->max_v_samp_factor, cinfo->image_width);
  149827. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  149828. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  149829. }
  149830. METHODDEF(void)
  149831. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149832. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149833. {
  149834. int outrow;
  149835. JDIMENSION outcol;
  149836. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149837. register JSAMPROW inptr, outptr;
  149838. register int bias;
  149839. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149840. cinfo->image_width, output_cols * 2);
  149841. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149842. outptr = output_data[outrow];
  149843. inptr = input_data[outrow];
  149844. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  149845. for (outcol = 0; outcol < output_cols; outcol++) {
  149846. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  149847. + bias) >> 1);
  149848. bias ^= 1; /* 0=>1, 1=>0 */
  149849. inptr += 2;
  149850. }
  149851. }
  149852. }
  149853. METHODDEF(void)
  149854. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149855. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149856. {
  149857. int inrow, outrow;
  149858. JDIMENSION outcol;
  149859. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149860. register JSAMPROW inptr0, inptr1, outptr;
  149861. register int bias;
  149862. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149863. cinfo->image_width, output_cols * 2);
  149864. inrow = 0;
  149865. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149866. outptr = output_data[outrow];
  149867. inptr0 = input_data[inrow];
  149868. inptr1 = input_data[inrow+1];
  149869. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  149870. for (outcol = 0; outcol < output_cols; outcol++) {
  149871. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149872. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  149873. + bias) >> 2);
  149874. bias ^= 3; /* 1=>2, 2=>1 */
  149875. inptr0 += 2; inptr1 += 2;
  149876. }
  149877. inrow += 2;
  149878. }
  149879. }
  149880. #ifdef INPUT_SMOOTHING_SUPPORTED
  149881. METHODDEF(void)
  149882. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149883. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149884. {
  149885. int inrow, outrow;
  149886. JDIMENSION colctr;
  149887. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149888. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  149889. INT32 membersum, neighsum, memberscale, neighscale;
  149890. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149891. cinfo->image_width, output_cols * 2);
  149892. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  149893. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  149894. inrow = 0;
  149895. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149896. outptr = output_data[outrow];
  149897. inptr0 = input_data[inrow];
  149898. inptr1 = input_data[inrow+1];
  149899. above_ptr = input_data[inrow-1];
  149900. below_ptr = input_data[inrow+2];
  149901. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149902. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149903. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149904. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149905. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  149906. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  149907. neighsum += neighsum;
  149908. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  149909. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  149910. membersum = membersum * memberscale + neighsum * neighscale;
  149911. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149912. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149913. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149914. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149915. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149916. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149917. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149918. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  149919. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  149920. neighsum += neighsum;
  149921. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  149922. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  149923. membersum = membersum * memberscale + neighsum * neighscale;
  149924. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149925. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149926. }
  149927. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149928. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149929. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149930. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149931. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  149932. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  149933. neighsum += neighsum;
  149934. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  149935. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  149936. membersum = membersum * memberscale + neighsum * neighscale;
  149937. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149938. inrow += 2;
  149939. }
  149940. }
  149941. METHODDEF(void)
  149942. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  149943. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149944. {
  149945. int outrow;
  149946. JDIMENSION colctr;
  149947. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149948. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  149949. INT32 membersum, neighsum, memberscale, neighscale;
  149950. int colsum, lastcolsum, nextcolsum;
  149951. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149952. cinfo->image_width, output_cols);
  149953. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  149954. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  149955. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149956. outptr = output_data[outrow];
  149957. inptr = input_data[outrow];
  149958. above_ptr = input_data[outrow-1];
  149959. below_ptr = input_data[outrow+1];
  149960. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  149961. GETJSAMPLE(*inptr);
  149962. membersum = GETJSAMPLE(*inptr++);
  149963. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149964. GETJSAMPLE(*inptr);
  149965. neighsum = colsum + (colsum - membersum) + nextcolsum;
  149966. membersum = membersum * memberscale + neighsum * neighscale;
  149967. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149968. lastcolsum = colsum; colsum = nextcolsum;
  149969. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149970. membersum = GETJSAMPLE(*inptr++);
  149971. above_ptr++; below_ptr++;
  149972. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149973. GETJSAMPLE(*inptr);
  149974. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  149975. membersum = membersum * memberscale + neighsum * neighscale;
  149976. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149977. lastcolsum = colsum; colsum = nextcolsum;
  149978. }
  149979. membersum = GETJSAMPLE(*inptr);
  149980. neighsum = lastcolsum + (colsum - membersum) + colsum;
  149981. membersum = membersum * memberscale + neighsum * neighscale;
  149982. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149983. }
  149984. }
  149985. #endif /* INPUT_SMOOTHING_SUPPORTED */
  149986. GLOBAL(void)
  149987. jinit_downsampler (j_compress_ptr cinfo)
  149988. {
  149989. my_downsample_ptr downsample;
  149990. int ci;
  149991. jpeg_component_info * compptr;
  149992. boolean smoothok = TRUE;
  149993. downsample = (my_downsample_ptr)
  149994. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149995. SIZEOF(my_downsampler));
  149996. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  149997. downsample->pub.start_pass = start_pass_downsample;
  149998. downsample->pub.downsample = sep_downsample;
  149999. downsample->pub.need_context_rows = FALSE;
  150000. if (cinfo->CCIR601_sampling)
  150001. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  150002. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150003. ci++, compptr++) {
  150004. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  150005. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150006. #ifdef INPUT_SMOOTHING_SUPPORTED
  150007. if (cinfo->smoothing_factor) {
  150008. downsample->methods[ci] = fullsize_smooth_downsample;
  150009. downsample->pub.need_context_rows = TRUE;
  150010. } else
  150011. #endif
  150012. downsample->methods[ci] = fullsize_downsample;
  150013. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150014. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150015. smoothok = FALSE;
  150016. downsample->methods[ci] = h2v1_downsample;
  150017. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150018. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  150019. #ifdef INPUT_SMOOTHING_SUPPORTED
  150020. if (cinfo->smoothing_factor) {
  150021. downsample->methods[ci] = h2v2_smooth_downsample;
  150022. downsample->pub.need_context_rows = TRUE;
  150023. } else
  150024. #endif
  150025. downsample->methods[ci] = h2v2_downsample;
  150026. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  150027. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  150028. smoothok = FALSE;
  150029. downsample->methods[ci] = int_downsample;
  150030. } else
  150031. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  150032. }
  150033. #ifdef INPUT_SMOOTHING_SUPPORTED
  150034. if (cinfo->smoothing_factor && !smoothok)
  150035. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  150036. #endif
  150037. }
  150038. /*** End of inlined file: jcsample.c ***/
  150039. /*** Start of inlined file: jctrans.c ***/
  150040. #define JPEG_INTERNALS
  150041. LOCAL(void) transencode_master_selection
  150042. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150043. LOCAL(void) transencode_coef_controller
  150044. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150045. GLOBAL(void)
  150046. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  150047. {
  150048. if (cinfo->global_state != CSTATE_START)
  150049. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150050. jpeg_suppress_tables(cinfo, FALSE);
  150051. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  150052. (*cinfo->dest->init_destination) (cinfo);
  150053. transencode_master_selection(cinfo, coef_arrays);
  150054. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  150055. cinfo->global_state = CSTATE_WRCOEFS;
  150056. }
  150057. GLOBAL(void)
  150058. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  150059. j_compress_ptr dstinfo)
  150060. {
  150061. JQUANT_TBL ** qtblptr;
  150062. jpeg_component_info *incomp, *outcomp;
  150063. JQUANT_TBL *c_quant, *slot_quant;
  150064. int tblno, ci, coefi;
  150065. if (dstinfo->global_state != CSTATE_START)
  150066. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  150067. dstinfo->image_width = srcinfo->image_width;
  150068. dstinfo->image_height = srcinfo->image_height;
  150069. dstinfo->input_components = srcinfo->num_components;
  150070. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  150071. jpeg_set_defaults(dstinfo);
  150072. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  150073. dstinfo->data_precision = srcinfo->data_precision;
  150074. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  150075. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  150076. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  150077. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  150078. if (*qtblptr == NULL)
  150079. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  150080. MEMCOPY((*qtblptr)->quantval,
  150081. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  150082. SIZEOF((*qtblptr)->quantval));
  150083. (*qtblptr)->sent_table = FALSE;
  150084. }
  150085. }
  150086. dstinfo->num_components = srcinfo->num_components;
  150087. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  150088. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  150089. MAX_COMPONENTS);
  150090. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  150091. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  150092. outcomp->component_id = incomp->component_id;
  150093. outcomp->h_samp_factor = incomp->h_samp_factor;
  150094. outcomp->v_samp_factor = incomp->v_samp_factor;
  150095. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  150096. tblno = outcomp->quant_tbl_no;
  150097. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  150098. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  150099. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  150100. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  150101. c_quant = incomp->quant_table;
  150102. if (c_quant != NULL) {
  150103. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  150104. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  150105. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  150106. }
  150107. }
  150108. }
  150109. if (srcinfo->saw_JFIF_marker) {
  150110. if (srcinfo->JFIF_major_version == 1) {
  150111. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  150112. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  150113. }
  150114. dstinfo->density_unit = srcinfo->density_unit;
  150115. dstinfo->X_density = srcinfo->X_density;
  150116. dstinfo->Y_density = srcinfo->Y_density;
  150117. }
  150118. }
  150119. LOCAL(void)
  150120. transencode_master_selection (j_compress_ptr cinfo,
  150121. jvirt_barray_ptr * coef_arrays)
  150122. {
  150123. cinfo->input_components = 1;
  150124. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  150125. if (cinfo->arith_code) {
  150126. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  150127. } else {
  150128. if (cinfo->progressive_mode) {
  150129. #ifdef C_PROGRESSIVE_SUPPORTED
  150130. jinit_phuff_encoder(cinfo);
  150131. #else
  150132. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150133. #endif
  150134. } else
  150135. jinit_huff_encoder(cinfo);
  150136. }
  150137. transencode_coef_controller(cinfo, coef_arrays);
  150138. jinit_marker_writer(cinfo);
  150139. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  150140. (*cinfo->marker->write_file_header) (cinfo);
  150141. }
  150142. typedef struct {
  150143. struct jpeg_c_coef_controller pub; /* public fields */
  150144. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  150145. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  150146. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150147. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150148. jvirt_barray_ptr * whole_image;
  150149. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  150150. } my_coef_controller2;
  150151. typedef my_coef_controller2 * my_coef_ptr2;
  150152. LOCAL(void)
  150153. start_iMCU_row2 (j_compress_ptr cinfo)
  150154. {
  150155. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150156. if (cinfo->comps_in_scan > 1) {
  150157. coef->MCU_rows_per_iMCU_row = 1;
  150158. } else {
  150159. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  150160. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150161. else
  150162. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150163. }
  150164. coef->mcu_ctr = 0;
  150165. coef->MCU_vert_offset = 0;
  150166. }
  150167. METHODDEF(void)
  150168. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  150169. {
  150170. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150171. if (pass_mode != JBUF_CRANK_DEST)
  150172. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150173. coef->iMCU_row_num = 0;
  150174. start_iMCU_row2(cinfo);
  150175. }
  150176. METHODDEF(boolean)
  150177. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  150178. {
  150179. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150180. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150181. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150182. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150183. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  150184. JDIMENSION start_col;
  150185. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150186. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  150187. JBLOCKROW buffer_ptr;
  150188. jpeg_component_info *compptr;
  150189. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150190. compptr = cinfo->cur_comp_info[ci];
  150191. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150192. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150193. coef->iMCU_row_num * compptr->v_samp_factor,
  150194. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150195. }
  150196. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150197. yoffset++) {
  150198. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150199. MCU_col_num++) {
  150200. blkn = 0; /* index of current DCT block within MCU */
  150201. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150202. compptr = cinfo->cur_comp_info[ci];
  150203. start_col = MCU_col_num * compptr->MCU_width;
  150204. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150205. : compptr->last_col_width;
  150206. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150207. if (coef->iMCU_row_num < last_iMCU_row ||
  150208. yindex+yoffset < compptr->last_row_height) {
  150209. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150210. for (xindex = 0; xindex < blockcnt; xindex++)
  150211. MCU_buffer[blkn++] = buffer_ptr++;
  150212. } else {
  150213. xindex = 0;
  150214. }
  150215. for (; xindex < compptr->MCU_width; xindex++) {
  150216. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  150217. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  150218. blkn++;
  150219. }
  150220. }
  150221. }
  150222. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  150223. coef->MCU_vert_offset = yoffset;
  150224. coef->mcu_ctr = MCU_col_num;
  150225. return FALSE;
  150226. }
  150227. }
  150228. coef->mcu_ctr = 0;
  150229. }
  150230. coef->iMCU_row_num++;
  150231. start_iMCU_row2(cinfo);
  150232. return TRUE;
  150233. }
  150234. LOCAL(void)
  150235. transencode_coef_controller (j_compress_ptr cinfo,
  150236. jvirt_barray_ptr * coef_arrays)
  150237. {
  150238. my_coef_ptr2 coef;
  150239. JBLOCKROW buffer;
  150240. int i;
  150241. coef = (my_coef_ptr2)
  150242. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150243. SIZEOF(my_coef_controller2));
  150244. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  150245. coef->pub.start_pass = start_pass_coef2;
  150246. coef->pub.compress_data = compress_output2;
  150247. coef->whole_image = coef_arrays;
  150248. buffer = (JBLOCKROW)
  150249. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150250. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150251. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150252. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  150253. coef->dummy_buffer[i] = buffer + i;
  150254. }
  150255. }
  150256. /*** End of inlined file: jctrans.c ***/
  150257. /*** Start of inlined file: jdapistd.c ***/
  150258. #define JPEG_INTERNALS
  150259. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  150260. GLOBAL(boolean)
  150261. jpeg_start_decompress (j_decompress_ptr cinfo)
  150262. {
  150263. if (cinfo->global_state == DSTATE_READY) {
  150264. jinit_master_decompress(cinfo);
  150265. if (cinfo->buffered_image) {
  150266. cinfo->global_state = DSTATE_BUFIMAGE;
  150267. return TRUE;
  150268. }
  150269. cinfo->global_state = DSTATE_PRELOAD;
  150270. }
  150271. if (cinfo->global_state == DSTATE_PRELOAD) {
  150272. if (cinfo->inputctl->has_multiple_scans) {
  150273. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150274. for (;;) {
  150275. int retcode;
  150276. if (cinfo->progress != NULL)
  150277. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150278. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150279. if (retcode == JPEG_SUSPENDED)
  150280. return FALSE;
  150281. if (retcode == JPEG_REACHED_EOI)
  150282. break;
  150283. if (cinfo->progress != NULL &&
  150284. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150285. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150286. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150287. }
  150288. }
  150289. }
  150290. #else
  150291. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150292. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150293. }
  150294. cinfo->output_scan_number = cinfo->input_scan_number;
  150295. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150296. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150297. return output_pass_setup(cinfo);
  150298. }
  150299. LOCAL(boolean)
  150300. output_pass_setup (j_decompress_ptr cinfo)
  150301. {
  150302. if (cinfo->global_state != DSTATE_PRESCAN) {
  150303. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150304. cinfo->output_scanline = 0;
  150305. cinfo->global_state = DSTATE_PRESCAN;
  150306. }
  150307. while (cinfo->master->is_dummy_pass) {
  150308. #ifdef QUANT_2PASS_SUPPORTED
  150309. while (cinfo->output_scanline < cinfo->output_height) {
  150310. JDIMENSION last_scanline;
  150311. if (cinfo->progress != NULL) {
  150312. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150313. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150314. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150315. }
  150316. last_scanline = cinfo->output_scanline;
  150317. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150318. &cinfo->output_scanline, (JDIMENSION) 0);
  150319. if (cinfo->output_scanline == last_scanline)
  150320. return FALSE; /* No progress made, must suspend */
  150321. }
  150322. (*cinfo->master->finish_output_pass) (cinfo);
  150323. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150324. cinfo->output_scanline = 0;
  150325. #else
  150326. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150327. #endif /* QUANT_2PASS_SUPPORTED */
  150328. }
  150329. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150330. return TRUE;
  150331. }
  150332. GLOBAL(JDIMENSION)
  150333. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150334. JDIMENSION max_lines)
  150335. {
  150336. JDIMENSION row_ctr;
  150337. if (cinfo->global_state != DSTATE_SCANNING)
  150338. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150339. if (cinfo->output_scanline >= cinfo->output_height) {
  150340. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150341. return 0;
  150342. }
  150343. if (cinfo->progress != NULL) {
  150344. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150345. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150346. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150347. }
  150348. row_ctr = 0;
  150349. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150350. cinfo->output_scanline += row_ctr;
  150351. return row_ctr;
  150352. }
  150353. GLOBAL(JDIMENSION)
  150354. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150355. JDIMENSION max_lines)
  150356. {
  150357. JDIMENSION lines_per_iMCU_row;
  150358. if (cinfo->global_state != DSTATE_RAW_OK)
  150359. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150360. if (cinfo->output_scanline >= cinfo->output_height) {
  150361. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150362. return 0;
  150363. }
  150364. if (cinfo->progress != NULL) {
  150365. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150366. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150367. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150368. }
  150369. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150370. if (max_lines < lines_per_iMCU_row)
  150371. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150372. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150373. return 0; /* suspension forced, can do nothing more */
  150374. cinfo->output_scanline += lines_per_iMCU_row;
  150375. return lines_per_iMCU_row;
  150376. }
  150377. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150378. GLOBAL(boolean)
  150379. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150380. {
  150381. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150382. cinfo->global_state != DSTATE_PRESCAN)
  150383. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150384. if (scan_number <= 0)
  150385. scan_number = 1;
  150386. if (cinfo->inputctl->eoi_reached &&
  150387. scan_number > cinfo->input_scan_number)
  150388. scan_number = cinfo->input_scan_number;
  150389. cinfo->output_scan_number = scan_number;
  150390. return output_pass_setup(cinfo);
  150391. }
  150392. GLOBAL(boolean)
  150393. jpeg_finish_output (j_decompress_ptr cinfo)
  150394. {
  150395. if ((cinfo->global_state == DSTATE_SCANNING ||
  150396. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150397. (*cinfo->master->finish_output_pass) (cinfo);
  150398. cinfo->global_state = DSTATE_BUFPOST;
  150399. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150400. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150401. }
  150402. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150403. ! cinfo->inputctl->eoi_reached) {
  150404. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150405. return FALSE; /* Suspend, come back later */
  150406. }
  150407. cinfo->global_state = DSTATE_BUFIMAGE;
  150408. return TRUE;
  150409. }
  150410. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150411. /*** End of inlined file: jdapistd.c ***/
  150412. /*** Start of inlined file: jdapimin.c ***/
  150413. #define JPEG_INTERNALS
  150414. GLOBAL(void)
  150415. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150416. {
  150417. int i;
  150418. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150419. if (version != JPEG_LIB_VERSION)
  150420. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150421. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150422. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150423. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150424. {
  150425. struct jpeg_error_mgr * err = cinfo->err;
  150426. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150427. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150428. cinfo->err = err;
  150429. cinfo->client_data = client_data;
  150430. }
  150431. cinfo->is_decompressor = TRUE;
  150432. jinit_memory_mgr((j_common_ptr) cinfo);
  150433. cinfo->progress = NULL;
  150434. cinfo->src = NULL;
  150435. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150436. cinfo->quant_tbl_ptrs[i] = NULL;
  150437. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150438. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150439. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150440. }
  150441. cinfo->marker_list = NULL;
  150442. jinit_marker_reader(cinfo);
  150443. jinit_input_controller(cinfo);
  150444. cinfo->global_state = DSTATE_START;
  150445. }
  150446. GLOBAL(void)
  150447. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150448. {
  150449. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150450. }
  150451. GLOBAL(void)
  150452. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150453. {
  150454. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150455. }
  150456. LOCAL(void)
  150457. default_decompress_parms (j_decompress_ptr cinfo)
  150458. {
  150459. switch (cinfo->num_components) {
  150460. case 1:
  150461. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150462. cinfo->out_color_space = JCS_GRAYSCALE;
  150463. break;
  150464. case 3:
  150465. if (cinfo->saw_JFIF_marker) {
  150466. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150467. } else if (cinfo->saw_Adobe_marker) {
  150468. switch (cinfo->Adobe_transform) {
  150469. case 0:
  150470. cinfo->jpeg_color_space = JCS_RGB;
  150471. break;
  150472. case 1:
  150473. cinfo->jpeg_color_space = JCS_YCbCr;
  150474. break;
  150475. default:
  150476. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150477. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150478. break;
  150479. }
  150480. } else {
  150481. int cid0 = cinfo->comp_info[0].component_id;
  150482. int cid1 = cinfo->comp_info[1].component_id;
  150483. int cid2 = cinfo->comp_info[2].component_id;
  150484. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150485. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150486. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150487. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150488. else {
  150489. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150490. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150491. }
  150492. }
  150493. cinfo->out_color_space = JCS_RGB;
  150494. break;
  150495. case 4:
  150496. if (cinfo->saw_Adobe_marker) {
  150497. switch (cinfo->Adobe_transform) {
  150498. case 0:
  150499. cinfo->jpeg_color_space = JCS_CMYK;
  150500. break;
  150501. case 2:
  150502. cinfo->jpeg_color_space = JCS_YCCK;
  150503. break;
  150504. default:
  150505. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150506. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150507. break;
  150508. }
  150509. } else {
  150510. cinfo->jpeg_color_space = JCS_CMYK;
  150511. }
  150512. cinfo->out_color_space = JCS_CMYK;
  150513. break;
  150514. default:
  150515. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150516. cinfo->out_color_space = JCS_UNKNOWN;
  150517. break;
  150518. }
  150519. cinfo->scale_num = 1; /* 1:1 scaling */
  150520. cinfo->scale_denom = 1;
  150521. cinfo->output_gamma = 1.0;
  150522. cinfo->buffered_image = FALSE;
  150523. cinfo->raw_data_out = FALSE;
  150524. cinfo->dct_method = JDCT_DEFAULT;
  150525. cinfo->do_fancy_upsampling = TRUE;
  150526. cinfo->do_block_smoothing = TRUE;
  150527. cinfo->quantize_colors = FALSE;
  150528. cinfo->dither_mode = JDITHER_FS;
  150529. #ifdef QUANT_2PASS_SUPPORTED
  150530. cinfo->two_pass_quantize = TRUE;
  150531. #else
  150532. cinfo->two_pass_quantize = FALSE;
  150533. #endif
  150534. cinfo->desired_number_of_colors = 256;
  150535. cinfo->colormap = NULL;
  150536. cinfo->enable_1pass_quant = FALSE;
  150537. cinfo->enable_external_quant = FALSE;
  150538. cinfo->enable_2pass_quant = FALSE;
  150539. }
  150540. GLOBAL(int)
  150541. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150542. {
  150543. int retcode;
  150544. if (cinfo->global_state != DSTATE_START &&
  150545. cinfo->global_state != DSTATE_INHEADER)
  150546. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150547. retcode = jpeg_consume_input(cinfo);
  150548. switch (retcode) {
  150549. case JPEG_REACHED_SOS:
  150550. retcode = JPEG_HEADER_OK;
  150551. break;
  150552. case JPEG_REACHED_EOI:
  150553. if (require_image) /* Complain if application wanted an image */
  150554. ERREXIT(cinfo, JERR_NO_IMAGE);
  150555. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150556. retcode = JPEG_HEADER_TABLES_ONLY;
  150557. break;
  150558. case JPEG_SUSPENDED:
  150559. break;
  150560. }
  150561. return retcode;
  150562. }
  150563. GLOBAL(int)
  150564. jpeg_consume_input (j_decompress_ptr cinfo)
  150565. {
  150566. int retcode = JPEG_SUSPENDED;
  150567. switch (cinfo->global_state) {
  150568. case DSTATE_START:
  150569. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150570. (*cinfo->src->init_source) (cinfo);
  150571. cinfo->global_state = DSTATE_INHEADER;
  150572. case DSTATE_INHEADER:
  150573. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150574. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150575. default_decompress_parms(cinfo);
  150576. cinfo->global_state = DSTATE_READY;
  150577. }
  150578. break;
  150579. case DSTATE_READY:
  150580. retcode = JPEG_REACHED_SOS;
  150581. break;
  150582. case DSTATE_PRELOAD:
  150583. case DSTATE_PRESCAN:
  150584. case DSTATE_SCANNING:
  150585. case DSTATE_RAW_OK:
  150586. case DSTATE_BUFIMAGE:
  150587. case DSTATE_BUFPOST:
  150588. case DSTATE_STOPPING:
  150589. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150590. break;
  150591. default:
  150592. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150593. }
  150594. return retcode;
  150595. }
  150596. GLOBAL(boolean)
  150597. jpeg_input_complete (j_decompress_ptr cinfo)
  150598. {
  150599. if (cinfo->global_state < DSTATE_START ||
  150600. cinfo->global_state > DSTATE_STOPPING)
  150601. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150602. return cinfo->inputctl->eoi_reached;
  150603. }
  150604. GLOBAL(boolean)
  150605. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150606. {
  150607. if (cinfo->global_state < DSTATE_READY ||
  150608. cinfo->global_state > DSTATE_STOPPING)
  150609. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150610. return cinfo->inputctl->has_multiple_scans;
  150611. }
  150612. GLOBAL(boolean)
  150613. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150614. {
  150615. if ((cinfo->global_state == DSTATE_SCANNING ||
  150616. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150617. if (cinfo->output_scanline < cinfo->output_height)
  150618. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150619. (*cinfo->master->finish_output_pass) (cinfo);
  150620. cinfo->global_state = DSTATE_STOPPING;
  150621. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150622. cinfo->global_state = DSTATE_STOPPING;
  150623. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150624. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150625. }
  150626. while (! cinfo->inputctl->eoi_reached) {
  150627. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150628. return FALSE; /* Suspend, come back later */
  150629. }
  150630. (*cinfo->src->term_source) (cinfo);
  150631. jpeg_abort((j_common_ptr) cinfo);
  150632. return TRUE;
  150633. }
  150634. /*** End of inlined file: jdapimin.c ***/
  150635. /*** Start of inlined file: jdatasrc.c ***/
  150636. /*** Start of inlined file: jerror.h ***/
  150637. #ifndef JMESSAGE
  150638. #ifndef JERROR_H
  150639. #define JMAKE_ENUM_LIST
  150640. #else
  150641. #define JMESSAGE(code,string)
  150642. #endif /* JERROR_H */
  150643. #endif /* JMESSAGE */
  150644. #ifdef JMAKE_ENUM_LIST
  150645. typedef enum {
  150646. #define JMESSAGE(code,string) code ,
  150647. #endif /* JMAKE_ENUM_LIST */
  150648. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150649. JMESSAGE(JERR_ARITH_NOTIMPL,
  150650. "Sorry, there are legal restrictions on arithmetic coding")
  150651. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150652. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150653. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150654. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150655. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150656. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150657. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150658. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150659. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150660. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150661. JMESSAGE(JERR_BAD_LIB_VERSION,
  150662. "Wrong JPEG library version: library is %d, caller expects %d")
  150663. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150664. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150665. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150666. JMESSAGE(JERR_BAD_PROGRESSION,
  150667. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150668. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150669. "Invalid progressive parameters at scan script entry %d")
  150670. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  150671. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  150672. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  150673. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  150674. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  150675. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  150676. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  150677. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  150678. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  150679. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  150680. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  150681. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  150682. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  150683. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  150684. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  150685. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  150686. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  150687. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  150688. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  150689. JMESSAGE(JERR_FILE_READ, "Input file read error")
  150690. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  150691. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  150692. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  150693. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  150694. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  150695. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  150696. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  150697. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  150698. "Cannot transcode due to multiple use of quantization table %d")
  150699. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  150700. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  150701. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  150702. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  150703. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  150704. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  150705. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  150706. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  150707. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  150708. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  150709. JMESSAGE(JERR_QUANT_COMPONENTS,
  150710. "Cannot quantize more than %d color components")
  150711. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  150712. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  150713. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  150714. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  150715. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  150716. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  150717. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  150718. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  150719. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  150720. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  150721. JMESSAGE(JERR_TFILE_WRITE,
  150722. "Write failed on temporary file --- out of disk space?")
  150723. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  150724. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  150725. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  150726. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  150727. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  150728. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  150729. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  150730. JMESSAGE(JMSG_VERSION, JVERSION)
  150731. JMESSAGE(JTRC_16BIT_TABLES,
  150732. "Caution: quantization tables are too coarse for baseline JPEG")
  150733. JMESSAGE(JTRC_ADOBE,
  150734. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  150735. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  150736. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  150737. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  150738. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  150739. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  150740. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  150741. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  150742. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  150743. JMESSAGE(JTRC_EOI, "End Of Image")
  150744. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  150745. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  150746. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  150747. "Warning: thumbnail image size does not match data length %u")
  150748. JMESSAGE(JTRC_JFIF_EXTENSION,
  150749. "JFIF extension marker: type 0x%02x, length %u")
  150750. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  150751. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  150752. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  150753. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  150754. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  150755. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  150756. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  150757. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  150758. JMESSAGE(JTRC_RST, "RST%d")
  150759. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  150760. "Smoothing not supported with nonstandard sampling ratios")
  150761. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  150762. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  150763. JMESSAGE(JTRC_SOI, "Start of Image")
  150764. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  150765. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  150766. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  150767. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  150768. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  150769. JMESSAGE(JTRC_THUMB_JPEG,
  150770. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  150771. JMESSAGE(JTRC_THUMB_PALETTE,
  150772. "JFIF extension marker: palette thumbnail image, length %u")
  150773. JMESSAGE(JTRC_THUMB_RGB,
  150774. "JFIF extension marker: RGB thumbnail image, length %u")
  150775. JMESSAGE(JTRC_UNKNOWN_IDS,
  150776. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  150777. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  150778. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  150779. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  150780. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  150781. "Inconsistent progression sequence for component %d coefficient %d")
  150782. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  150783. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  150784. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  150785. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  150786. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  150787. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  150788. JMESSAGE(JWRN_MUST_RESYNC,
  150789. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  150790. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  150791. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  150792. #ifdef JMAKE_ENUM_LIST
  150793. JMSG_LASTMSGCODE
  150794. } J_MESSAGE_CODE;
  150795. #undef JMAKE_ENUM_LIST
  150796. #endif /* JMAKE_ENUM_LIST */
  150797. #undef JMESSAGE
  150798. #ifndef JERROR_H
  150799. #define JERROR_H
  150800. #define ERREXIT(cinfo,code) \
  150801. ((cinfo)->err->msg_code = (code), \
  150802. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150803. #define ERREXIT1(cinfo,code,p1) \
  150804. ((cinfo)->err->msg_code = (code), \
  150805. (cinfo)->err->msg_parm.i[0] = (p1), \
  150806. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150807. #define ERREXIT2(cinfo,code,p1,p2) \
  150808. ((cinfo)->err->msg_code = (code), \
  150809. (cinfo)->err->msg_parm.i[0] = (p1), \
  150810. (cinfo)->err->msg_parm.i[1] = (p2), \
  150811. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150812. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  150813. ((cinfo)->err->msg_code = (code), \
  150814. (cinfo)->err->msg_parm.i[0] = (p1), \
  150815. (cinfo)->err->msg_parm.i[1] = (p2), \
  150816. (cinfo)->err->msg_parm.i[2] = (p3), \
  150817. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150818. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  150819. ((cinfo)->err->msg_code = (code), \
  150820. (cinfo)->err->msg_parm.i[0] = (p1), \
  150821. (cinfo)->err->msg_parm.i[1] = (p2), \
  150822. (cinfo)->err->msg_parm.i[2] = (p3), \
  150823. (cinfo)->err->msg_parm.i[3] = (p4), \
  150824. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150825. #define ERREXITS(cinfo,code,str) \
  150826. ((cinfo)->err->msg_code = (code), \
  150827. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150828. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150829. #define MAKESTMT(stuff) do { stuff } while (0)
  150830. #define WARNMS(cinfo,code) \
  150831. ((cinfo)->err->msg_code = (code), \
  150832. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150833. #define WARNMS1(cinfo,code,p1) \
  150834. ((cinfo)->err->msg_code = (code), \
  150835. (cinfo)->err->msg_parm.i[0] = (p1), \
  150836. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150837. #define WARNMS2(cinfo,code,p1,p2) \
  150838. ((cinfo)->err->msg_code = (code), \
  150839. (cinfo)->err->msg_parm.i[0] = (p1), \
  150840. (cinfo)->err->msg_parm.i[1] = (p2), \
  150841. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150842. #define TRACEMS(cinfo,lvl,code) \
  150843. ((cinfo)->err->msg_code = (code), \
  150844. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150845. #define TRACEMS1(cinfo,lvl,code,p1) \
  150846. ((cinfo)->err->msg_code = (code), \
  150847. (cinfo)->err->msg_parm.i[0] = (p1), \
  150848. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150849. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  150850. ((cinfo)->err->msg_code = (code), \
  150851. (cinfo)->err->msg_parm.i[0] = (p1), \
  150852. (cinfo)->err->msg_parm.i[1] = (p2), \
  150853. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150854. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  150855. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150856. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  150857. (cinfo)->err->msg_code = (code); \
  150858. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150859. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  150860. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150861. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150862. (cinfo)->err->msg_code = (code); \
  150863. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150864. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  150865. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150866. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150867. _mp[4] = (p5); \
  150868. (cinfo)->err->msg_code = (code); \
  150869. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150870. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  150871. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150872. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150873. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  150874. (cinfo)->err->msg_code = (code); \
  150875. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150876. #define TRACEMSS(cinfo,lvl,code,str) \
  150877. ((cinfo)->err->msg_code = (code), \
  150878. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150879. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150880. #endif /* JERROR_H */
  150881. /*** End of inlined file: jerror.h ***/
  150882. typedef struct {
  150883. struct jpeg_source_mgr pub; /* public fields */
  150884. FILE * infile; /* source stream */
  150885. JOCTET * buffer; /* start of buffer */
  150886. boolean start_of_file; /* have we gotten any data yet? */
  150887. } my_source_mgr;
  150888. typedef my_source_mgr * my_src_ptr;
  150889. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  150890. METHODDEF(void)
  150891. init_source (j_decompress_ptr cinfo)
  150892. {
  150893. my_src_ptr src = (my_src_ptr) cinfo->src;
  150894. src->start_of_file = TRUE;
  150895. }
  150896. METHODDEF(boolean)
  150897. fill_input_buffer (j_decompress_ptr cinfo)
  150898. {
  150899. my_src_ptr src = (my_src_ptr) cinfo->src;
  150900. size_t nbytes;
  150901. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  150902. if (nbytes <= 0) {
  150903. if (src->start_of_file) /* Treat empty input file as fatal error */
  150904. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  150905. WARNMS(cinfo, JWRN_JPEG_EOF);
  150906. src->buffer[0] = (JOCTET) 0xFF;
  150907. src->buffer[1] = (JOCTET) JPEG_EOI;
  150908. nbytes = 2;
  150909. }
  150910. src->pub.next_input_byte = src->buffer;
  150911. src->pub.bytes_in_buffer = nbytes;
  150912. src->start_of_file = FALSE;
  150913. return TRUE;
  150914. }
  150915. METHODDEF(void)
  150916. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  150917. {
  150918. my_src_ptr src = (my_src_ptr) cinfo->src;
  150919. if (num_bytes > 0) {
  150920. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  150921. num_bytes -= (long) src->pub.bytes_in_buffer;
  150922. (void) fill_input_buffer(cinfo);
  150923. }
  150924. src->pub.next_input_byte += (size_t) num_bytes;
  150925. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  150926. }
  150927. }
  150928. METHODDEF(void)
  150929. term_source (j_decompress_ptr cinfo)
  150930. {
  150931. }
  150932. GLOBAL(void)
  150933. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  150934. {
  150935. my_src_ptr src;
  150936. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  150937. cinfo->src = (struct jpeg_source_mgr *)
  150938. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150939. SIZEOF(my_source_mgr));
  150940. src = (my_src_ptr) cinfo->src;
  150941. src->buffer = (JOCTET *)
  150942. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150943. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  150944. }
  150945. src = (my_src_ptr) cinfo->src;
  150946. src->pub.init_source = init_source;
  150947. src->pub.fill_input_buffer = fill_input_buffer;
  150948. src->pub.skip_input_data = skip_input_data;
  150949. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  150950. src->pub.term_source = term_source;
  150951. src->infile = infile;
  150952. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  150953. src->pub.next_input_byte = NULL; /* until buffer loaded */
  150954. }
  150955. /*** End of inlined file: jdatasrc.c ***/
  150956. /*** Start of inlined file: jdcoefct.c ***/
  150957. #define JPEG_INTERNALS
  150958. #ifndef D_PROGRESSIVE_SUPPORTED
  150959. #undef BLOCK_SMOOTHING_SUPPORTED
  150960. #endif
  150961. typedef struct {
  150962. struct jpeg_d_coef_controller pub; /* public fields */
  150963. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  150964. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150965. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150966. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  150967. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150968. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  150969. #endif
  150970. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150971. int * coef_bits_latch;
  150972. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  150973. #endif
  150974. } my_coef_controller3;
  150975. typedef my_coef_controller3 * my_coef_ptr3;
  150976. METHODDEF(int) decompress_onepass
  150977. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150978. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150979. METHODDEF(int) decompress_data
  150980. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150981. #endif
  150982. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150983. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  150984. METHODDEF(int) decompress_smooth_data
  150985. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150986. #endif
  150987. LOCAL(void)
  150988. start_iMCU_row3 (j_decompress_ptr cinfo)
  150989. {
  150990. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150991. if (cinfo->comps_in_scan > 1) {
  150992. coef->MCU_rows_per_iMCU_row = 1;
  150993. } else {
  150994. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  150995. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150996. else
  150997. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150998. }
  150999. coef->MCU_ctr = 0;
  151000. coef->MCU_vert_offset = 0;
  151001. }
  151002. METHODDEF(void)
  151003. start_input_pass (j_decompress_ptr cinfo)
  151004. {
  151005. cinfo->input_iMCU_row = 0;
  151006. start_iMCU_row3(cinfo);
  151007. }
  151008. METHODDEF(void)
  151009. start_output_pass (j_decompress_ptr cinfo)
  151010. {
  151011. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151012. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151013. if (coef->pub.coef_arrays != NULL) {
  151014. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  151015. coef->pub.decompress_data = decompress_smooth_data;
  151016. else
  151017. coef->pub.decompress_data = decompress_data;
  151018. }
  151019. #endif
  151020. cinfo->output_iMCU_row = 0;
  151021. }
  151022. METHODDEF(int)
  151023. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151024. {
  151025. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151026. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151027. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  151028. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151029. int blkn, ci, xindex, yindex, yoffset, useful_width;
  151030. JSAMPARRAY output_ptr;
  151031. JDIMENSION start_col, output_col;
  151032. jpeg_component_info *compptr;
  151033. inverse_DCT_method_ptr inverse_DCT;
  151034. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151035. yoffset++) {
  151036. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  151037. MCU_col_num++) {
  151038. jzero_far((void FAR *) coef->MCU_buffer[0],
  151039. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  151040. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151041. coef->MCU_vert_offset = yoffset;
  151042. coef->MCU_ctr = MCU_col_num;
  151043. return JPEG_SUSPENDED;
  151044. }
  151045. blkn = 0; /* index of current DCT block within MCU */
  151046. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151047. compptr = cinfo->cur_comp_info[ci];
  151048. if (! compptr->component_needed) {
  151049. blkn += compptr->MCU_blocks;
  151050. continue;
  151051. }
  151052. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  151053. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  151054. : compptr->last_col_width;
  151055. output_ptr = output_buf[compptr->component_index] +
  151056. yoffset * compptr->DCT_scaled_size;
  151057. start_col = MCU_col_num * compptr->MCU_sample_width;
  151058. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151059. if (cinfo->input_iMCU_row < last_iMCU_row ||
  151060. yoffset+yindex < compptr->last_row_height) {
  151061. output_col = start_col;
  151062. for (xindex = 0; xindex < useful_width; xindex++) {
  151063. (*inverse_DCT) (cinfo, compptr,
  151064. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  151065. output_ptr, output_col);
  151066. output_col += compptr->DCT_scaled_size;
  151067. }
  151068. }
  151069. blkn += compptr->MCU_width;
  151070. output_ptr += compptr->DCT_scaled_size;
  151071. }
  151072. }
  151073. }
  151074. coef->MCU_ctr = 0;
  151075. }
  151076. cinfo->output_iMCU_row++;
  151077. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151078. start_iMCU_row3(cinfo);
  151079. return JPEG_ROW_COMPLETED;
  151080. }
  151081. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151082. return JPEG_SCAN_COMPLETED;
  151083. }
  151084. METHODDEF(int)
  151085. dummy_consume_data (j_decompress_ptr cinfo)
  151086. {
  151087. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  151088. }
  151089. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151090. METHODDEF(int)
  151091. consume_data (j_decompress_ptr cinfo)
  151092. {
  151093. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151094. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151095. int blkn, ci, xindex, yindex, yoffset;
  151096. JDIMENSION start_col;
  151097. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  151098. JBLOCKROW buffer_ptr;
  151099. jpeg_component_info *compptr;
  151100. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151101. compptr = cinfo->cur_comp_info[ci];
  151102. buffer[ci] = (*cinfo->mem->access_virt_barray)
  151103. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  151104. cinfo->input_iMCU_row * compptr->v_samp_factor,
  151105. (JDIMENSION) compptr->v_samp_factor, TRUE);
  151106. }
  151107. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151108. yoffset++) {
  151109. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  151110. MCU_col_num++) {
  151111. blkn = 0; /* index of current DCT block within MCU */
  151112. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151113. compptr = cinfo->cur_comp_info[ci];
  151114. start_col = MCU_col_num * compptr->MCU_width;
  151115. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151116. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  151117. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  151118. coef->MCU_buffer[blkn++] = buffer_ptr++;
  151119. }
  151120. }
  151121. }
  151122. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151123. coef->MCU_vert_offset = yoffset;
  151124. coef->MCU_ctr = MCU_col_num;
  151125. return JPEG_SUSPENDED;
  151126. }
  151127. }
  151128. coef->MCU_ctr = 0;
  151129. }
  151130. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151131. start_iMCU_row3(cinfo);
  151132. return JPEG_ROW_COMPLETED;
  151133. }
  151134. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151135. return JPEG_SCAN_COMPLETED;
  151136. }
  151137. METHODDEF(int)
  151138. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151139. {
  151140. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151141. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151142. JDIMENSION block_num;
  151143. int ci, block_row, block_rows;
  151144. JBLOCKARRAY buffer;
  151145. JBLOCKROW buffer_ptr;
  151146. JSAMPARRAY output_ptr;
  151147. JDIMENSION output_col;
  151148. jpeg_component_info *compptr;
  151149. inverse_DCT_method_ptr inverse_DCT;
  151150. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  151151. (cinfo->input_scan_number == cinfo->output_scan_number &&
  151152. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  151153. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151154. return JPEG_SUSPENDED;
  151155. }
  151156. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151157. ci++, compptr++) {
  151158. if (! compptr->component_needed)
  151159. continue;
  151160. buffer = (*cinfo->mem->access_virt_barray)
  151161. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151162. cinfo->output_iMCU_row * compptr->v_samp_factor,
  151163. (JDIMENSION) compptr->v_samp_factor, FALSE);
  151164. if (cinfo->output_iMCU_row < last_iMCU_row)
  151165. block_rows = compptr->v_samp_factor;
  151166. else {
  151167. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151168. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151169. }
  151170. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151171. output_ptr = output_buf[ci];
  151172. for (block_row = 0; block_row < block_rows; block_row++) {
  151173. buffer_ptr = buffer[block_row];
  151174. output_col = 0;
  151175. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  151176. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  151177. output_ptr, output_col);
  151178. buffer_ptr++;
  151179. output_col += compptr->DCT_scaled_size;
  151180. }
  151181. output_ptr += compptr->DCT_scaled_size;
  151182. }
  151183. }
  151184. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151185. return JPEG_ROW_COMPLETED;
  151186. return JPEG_SCAN_COMPLETED;
  151187. }
  151188. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  151189. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151190. #define Q01_POS 1
  151191. #define Q10_POS 8
  151192. #define Q20_POS 16
  151193. #define Q11_POS 9
  151194. #define Q02_POS 2
  151195. LOCAL(boolean)
  151196. smoothing_ok (j_decompress_ptr cinfo)
  151197. {
  151198. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151199. boolean smoothing_useful = FALSE;
  151200. int ci, coefi;
  151201. jpeg_component_info *compptr;
  151202. JQUANT_TBL * qtable;
  151203. int * coef_bits;
  151204. int * coef_bits_latch;
  151205. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  151206. return FALSE;
  151207. if (coef->coef_bits_latch == NULL)
  151208. coef->coef_bits_latch = (int *)
  151209. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151210. cinfo->num_components *
  151211. (SAVED_COEFS * SIZEOF(int)));
  151212. coef_bits_latch = coef->coef_bits_latch;
  151213. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151214. ci++, compptr++) {
  151215. if ((qtable = compptr->quant_table) == NULL)
  151216. return FALSE;
  151217. if (qtable->quantval[0] == 0 ||
  151218. qtable->quantval[Q01_POS] == 0 ||
  151219. qtable->quantval[Q10_POS] == 0 ||
  151220. qtable->quantval[Q20_POS] == 0 ||
  151221. qtable->quantval[Q11_POS] == 0 ||
  151222. qtable->quantval[Q02_POS] == 0)
  151223. return FALSE;
  151224. coef_bits = cinfo->coef_bits[ci];
  151225. if (coef_bits[0] < 0)
  151226. return FALSE;
  151227. for (coefi = 1; coefi <= 5; coefi++) {
  151228. coef_bits_latch[coefi] = coef_bits[coefi];
  151229. if (coef_bits[coefi] != 0)
  151230. smoothing_useful = TRUE;
  151231. }
  151232. coef_bits_latch += SAVED_COEFS;
  151233. }
  151234. return smoothing_useful;
  151235. }
  151236. METHODDEF(int)
  151237. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151238. {
  151239. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151240. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151241. JDIMENSION block_num, last_block_column;
  151242. int ci, block_row, block_rows, access_rows;
  151243. JBLOCKARRAY buffer;
  151244. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  151245. JSAMPARRAY output_ptr;
  151246. JDIMENSION output_col;
  151247. jpeg_component_info *compptr;
  151248. inverse_DCT_method_ptr inverse_DCT;
  151249. boolean first_row, last_row;
  151250. JBLOCK workspace;
  151251. int *coef_bits;
  151252. JQUANT_TBL *quanttbl;
  151253. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  151254. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  151255. int Al, pred;
  151256. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151257. ! cinfo->inputctl->eoi_reached) {
  151258. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  151259. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  151260. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  151261. break;
  151262. }
  151263. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151264. return JPEG_SUSPENDED;
  151265. }
  151266. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151267. ci++, compptr++) {
  151268. if (! compptr->component_needed)
  151269. continue;
  151270. if (cinfo->output_iMCU_row < last_iMCU_row) {
  151271. block_rows = compptr->v_samp_factor;
  151272. access_rows = block_rows * 2; /* this and next iMCU row */
  151273. last_row = FALSE;
  151274. } else {
  151275. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151276. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151277. access_rows = block_rows; /* this iMCU row only */
  151278. last_row = TRUE;
  151279. }
  151280. if (cinfo->output_iMCU_row > 0) {
  151281. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151282. buffer = (*cinfo->mem->access_virt_barray)
  151283. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151284. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151285. (JDIMENSION) access_rows, FALSE);
  151286. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151287. first_row = FALSE;
  151288. } else {
  151289. buffer = (*cinfo->mem->access_virt_barray)
  151290. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151291. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151292. first_row = TRUE;
  151293. }
  151294. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151295. quanttbl = compptr->quant_table;
  151296. Q00 = quanttbl->quantval[0];
  151297. Q01 = quanttbl->quantval[Q01_POS];
  151298. Q10 = quanttbl->quantval[Q10_POS];
  151299. Q20 = quanttbl->quantval[Q20_POS];
  151300. Q11 = quanttbl->quantval[Q11_POS];
  151301. Q02 = quanttbl->quantval[Q02_POS];
  151302. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151303. output_ptr = output_buf[ci];
  151304. for (block_row = 0; block_row < block_rows; block_row++) {
  151305. buffer_ptr = buffer[block_row];
  151306. if (first_row && block_row == 0)
  151307. prev_block_row = buffer_ptr;
  151308. else
  151309. prev_block_row = buffer[block_row-1];
  151310. if (last_row && block_row == block_rows-1)
  151311. next_block_row = buffer_ptr;
  151312. else
  151313. next_block_row = buffer[block_row+1];
  151314. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151315. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151316. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151317. output_col = 0;
  151318. last_block_column = compptr->width_in_blocks - 1;
  151319. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151320. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151321. if (block_num < last_block_column) {
  151322. DC3 = (int) prev_block_row[1][0];
  151323. DC6 = (int) buffer_ptr[1][0];
  151324. DC9 = (int) next_block_row[1][0];
  151325. }
  151326. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151327. num = 36 * Q00 * (DC4 - DC6);
  151328. if (num >= 0) {
  151329. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151330. if (Al > 0 && pred >= (1<<Al))
  151331. pred = (1<<Al)-1;
  151332. } else {
  151333. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151334. if (Al > 0 && pred >= (1<<Al))
  151335. pred = (1<<Al)-1;
  151336. pred = -pred;
  151337. }
  151338. workspace[1] = (JCOEF) pred;
  151339. }
  151340. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151341. num = 36 * Q00 * (DC2 - DC8);
  151342. if (num >= 0) {
  151343. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151344. if (Al > 0 && pred >= (1<<Al))
  151345. pred = (1<<Al)-1;
  151346. } else {
  151347. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151348. if (Al > 0 && pred >= (1<<Al))
  151349. pred = (1<<Al)-1;
  151350. pred = -pred;
  151351. }
  151352. workspace[8] = (JCOEF) pred;
  151353. }
  151354. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151355. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151356. if (num >= 0) {
  151357. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151358. if (Al > 0 && pred >= (1<<Al))
  151359. pred = (1<<Al)-1;
  151360. } else {
  151361. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151362. if (Al > 0 && pred >= (1<<Al))
  151363. pred = (1<<Al)-1;
  151364. pred = -pred;
  151365. }
  151366. workspace[16] = (JCOEF) pred;
  151367. }
  151368. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151369. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151370. if (num >= 0) {
  151371. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151372. if (Al > 0 && pred >= (1<<Al))
  151373. pred = (1<<Al)-1;
  151374. } else {
  151375. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151376. if (Al > 0 && pred >= (1<<Al))
  151377. pred = (1<<Al)-1;
  151378. pred = -pred;
  151379. }
  151380. workspace[9] = (JCOEF) pred;
  151381. }
  151382. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151383. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  151384. if (num >= 0) {
  151385. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  151386. if (Al > 0 && pred >= (1<<Al))
  151387. pred = (1<<Al)-1;
  151388. } else {
  151389. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151390. if (Al > 0 && pred >= (1<<Al))
  151391. pred = (1<<Al)-1;
  151392. pred = -pred;
  151393. }
  151394. workspace[2] = (JCOEF) pred;
  151395. }
  151396. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151397. output_ptr, output_col);
  151398. DC1 = DC2; DC2 = DC3;
  151399. DC4 = DC5; DC5 = DC6;
  151400. DC7 = DC8; DC8 = DC9;
  151401. buffer_ptr++, prev_block_row++, next_block_row++;
  151402. output_col += compptr->DCT_scaled_size;
  151403. }
  151404. output_ptr += compptr->DCT_scaled_size;
  151405. }
  151406. }
  151407. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151408. return JPEG_ROW_COMPLETED;
  151409. return JPEG_SCAN_COMPLETED;
  151410. }
  151411. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151412. GLOBAL(void)
  151413. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151414. {
  151415. my_coef_ptr3 coef;
  151416. coef = (my_coef_ptr3)
  151417. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151418. SIZEOF(my_coef_controller3));
  151419. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151420. coef->pub.start_input_pass = start_input_pass;
  151421. coef->pub.start_output_pass = start_output_pass;
  151422. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151423. coef->coef_bits_latch = NULL;
  151424. #endif
  151425. if (need_full_buffer) {
  151426. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151427. int ci, access_rows;
  151428. jpeg_component_info *compptr;
  151429. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151430. ci++, compptr++) {
  151431. access_rows = compptr->v_samp_factor;
  151432. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151433. if (cinfo->progressive_mode)
  151434. access_rows *= 3;
  151435. #endif
  151436. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151437. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151438. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151439. (long) compptr->h_samp_factor),
  151440. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151441. (long) compptr->v_samp_factor),
  151442. (JDIMENSION) access_rows);
  151443. }
  151444. coef->pub.consume_data = consume_data;
  151445. coef->pub.decompress_data = decompress_data;
  151446. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151447. #else
  151448. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151449. #endif
  151450. } else {
  151451. JBLOCKROW buffer;
  151452. int i;
  151453. buffer = (JBLOCKROW)
  151454. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151455. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151456. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151457. coef->MCU_buffer[i] = buffer + i;
  151458. }
  151459. coef->pub.consume_data = dummy_consume_data;
  151460. coef->pub.decompress_data = decompress_onepass;
  151461. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151462. }
  151463. }
  151464. /*** End of inlined file: jdcoefct.c ***/
  151465. #undef FIX
  151466. /*** Start of inlined file: jdcolor.c ***/
  151467. #define JPEG_INTERNALS
  151468. typedef struct {
  151469. struct jpeg_color_deconverter pub; /* public fields */
  151470. int * Cr_r_tab; /* => table for Cr to R conversion */
  151471. int * Cb_b_tab; /* => table for Cb to B conversion */
  151472. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151473. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151474. } my_color_deconverter2;
  151475. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151476. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151477. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151478. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151479. LOCAL(void)
  151480. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151481. {
  151482. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151483. int i;
  151484. INT32 x;
  151485. SHIFT_TEMPS
  151486. cconvert->Cr_r_tab = (int *)
  151487. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151488. (MAXJSAMPLE+1) * SIZEOF(int));
  151489. cconvert->Cb_b_tab = (int *)
  151490. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151491. (MAXJSAMPLE+1) * SIZEOF(int));
  151492. cconvert->Cr_g_tab = (INT32 *)
  151493. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151494. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151495. cconvert->Cb_g_tab = (INT32 *)
  151496. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151497. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151498. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151499. cconvert->Cr_r_tab[i] = (int)
  151500. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151501. cconvert->Cb_b_tab[i] = (int)
  151502. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151503. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151504. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151505. }
  151506. }
  151507. METHODDEF(void)
  151508. ycc_rgb_convert (j_decompress_ptr cinfo,
  151509. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151510. JSAMPARRAY output_buf, int num_rows)
  151511. {
  151512. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151513. register int y, cb, cr;
  151514. register JSAMPROW outptr;
  151515. register JSAMPROW inptr0, inptr1, inptr2;
  151516. register JDIMENSION col;
  151517. JDIMENSION num_cols = cinfo->output_width;
  151518. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151519. register int * Crrtab = cconvert->Cr_r_tab;
  151520. register int * Cbbtab = cconvert->Cb_b_tab;
  151521. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151522. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151523. SHIFT_TEMPS
  151524. while (--num_rows >= 0) {
  151525. inptr0 = input_buf[0][input_row];
  151526. inptr1 = input_buf[1][input_row];
  151527. inptr2 = input_buf[2][input_row];
  151528. input_row++;
  151529. outptr = *output_buf++;
  151530. for (col = 0; col < num_cols; col++) {
  151531. y = GETJSAMPLE(inptr0[col]);
  151532. cb = GETJSAMPLE(inptr1[col]);
  151533. cr = GETJSAMPLE(inptr2[col]);
  151534. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151535. outptr[RGB_GREEN] = range_limit[y +
  151536. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151537. SCALEBITS))];
  151538. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151539. outptr += RGB_PIXELSIZE;
  151540. }
  151541. }
  151542. }
  151543. METHODDEF(void)
  151544. null_convert2 (j_decompress_ptr cinfo,
  151545. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151546. JSAMPARRAY output_buf, int num_rows)
  151547. {
  151548. register JSAMPROW inptr, outptr;
  151549. register JDIMENSION count;
  151550. register int num_components = cinfo->num_components;
  151551. JDIMENSION num_cols = cinfo->output_width;
  151552. int ci;
  151553. while (--num_rows >= 0) {
  151554. for (ci = 0; ci < num_components; ci++) {
  151555. inptr = input_buf[ci][input_row];
  151556. outptr = output_buf[0] + ci;
  151557. for (count = num_cols; count > 0; count--) {
  151558. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151559. outptr += num_components;
  151560. }
  151561. }
  151562. input_row++;
  151563. output_buf++;
  151564. }
  151565. }
  151566. METHODDEF(void)
  151567. grayscale_convert2 (j_decompress_ptr cinfo,
  151568. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151569. JSAMPARRAY output_buf, int num_rows)
  151570. {
  151571. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151572. num_rows, cinfo->output_width);
  151573. }
  151574. METHODDEF(void)
  151575. gray_rgb_convert (j_decompress_ptr cinfo,
  151576. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151577. JSAMPARRAY output_buf, int num_rows)
  151578. {
  151579. register JSAMPROW inptr, outptr;
  151580. register JDIMENSION col;
  151581. JDIMENSION num_cols = cinfo->output_width;
  151582. while (--num_rows >= 0) {
  151583. inptr = input_buf[0][input_row++];
  151584. outptr = *output_buf++;
  151585. for (col = 0; col < num_cols; col++) {
  151586. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151587. outptr += RGB_PIXELSIZE;
  151588. }
  151589. }
  151590. }
  151591. METHODDEF(void)
  151592. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151593. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151594. JSAMPARRAY output_buf, int num_rows)
  151595. {
  151596. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151597. register int y, cb, cr;
  151598. register JSAMPROW outptr;
  151599. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151600. register JDIMENSION col;
  151601. JDIMENSION num_cols = cinfo->output_width;
  151602. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151603. register int * Crrtab = cconvert->Cr_r_tab;
  151604. register int * Cbbtab = cconvert->Cb_b_tab;
  151605. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151606. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151607. SHIFT_TEMPS
  151608. while (--num_rows >= 0) {
  151609. inptr0 = input_buf[0][input_row];
  151610. inptr1 = input_buf[1][input_row];
  151611. inptr2 = input_buf[2][input_row];
  151612. inptr3 = input_buf[3][input_row];
  151613. input_row++;
  151614. outptr = *output_buf++;
  151615. for (col = 0; col < num_cols; col++) {
  151616. y = GETJSAMPLE(inptr0[col]);
  151617. cb = GETJSAMPLE(inptr1[col]);
  151618. cr = GETJSAMPLE(inptr2[col]);
  151619. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151620. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151621. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151622. SCALEBITS)))];
  151623. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151624. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151625. outptr += 4;
  151626. }
  151627. }
  151628. }
  151629. METHODDEF(void)
  151630. start_pass_dcolor (j_decompress_ptr cinfo)
  151631. {
  151632. }
  151633. GLOBAL(void)
  151634. jinit_color_deconverter (j_decompress_ptr cinfo)
  151635. {
  151636. my_cconvert_ptr2 cconvert;
  151637. int ci;
  151638. cconvert = (my_cconvert_ptr2)
  151639. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151640. SIZEOF(my_color_deconverter2));
  151641. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151642. cconvert->pub.start_pass = start_pass_dcolor;
  151643. switch (cinfo->jpeg_color_space) {
  151644. case JCS_GRAYSCALE:
  151645. if (cinfo->num_components != 1)
  151646. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151647. break;
  151648. case JCS_RGB:
  151649. case JCS_YCbCr:
  151650. if (cinfo->num_components != 3)
  151651. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151652. break;
  151653. case JCS_CMYK:
  151654. case JCS_YCCK:
  151655. if (cinfo->num_components != 4)
  151656. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151657. break;
  151658. default: /* JCS_UNKNOWN can be anything */
  151659. if (cinfo->num_components < 1)
  151660. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151661. break;
  151662. }
  151663. switch (cinfo->out_color_space) {
  151664. case JCS_GRAYSCALE:
  151665. cinfo->out_color_components = 1;
  151666. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151667. cinfo->jpeg_color_space == JCS_YCbCr) {
  151668. cconvert->pub.color_convert = grayscale_convert2;
  151669. for (ci = 1; ci < cinfo->num_components; ci++)
  151670. cinfo->comp_info[ci].component_needed = FALSE;
  151671. } else
  151672. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151673. break;
  151674. case JCS_RGB:
  151675. cinfo->out_color_components = RGB_PIXELSIZE;
  151676. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  151677. cconvert->pub.color_convert = ycc_rgb_convert;
  151678. build_ycc_rgb_table(cinfo);
  151679. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  151680. cconvert->pub.color_convert = gray_rgb_convert;
  151681. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  151682. cconvert->pub.color_convert = null_convert2;
  151683. } else
  151684. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151685. break;
  151686. case JCS_CMYK:
  151687. cinfo->out_color_components = 4;
  151688. if (cinfo->jpeg_color_space == JCS_YCCK) {
  151689. cconvert->pub.color_convert = ycck_cmyk_convert;
  151690. build_ycc_rgb_table(cinfo);
  151691. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  151692. cconvert->pub.color_convert = null_convert2;
  151693. } else
  151694. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151695. break;
  151696. default:
  151697. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  151698. cinfo->out_color_components = cinfo->num_components;
  151699. cconvert->pub.color_convert = null_convert2;
  151700. } else /* unsupported non-null conversion */
  151701. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151702. break;
  151703. }
  151704. if (cinfo->quantize_colors)
  151705. cinfo->output_components = 1; /* single colormapped output component */
  151706. else
  151707. cinfo->output_components = cinfo->out_color_components;
  151708. }
  151709. /*** End of inlined file: jdcolor.c ***/
  151710. #undef FIX
  151711. /*** Start of inlined file: jddctmgr.c ***/
  151712. #define JPEG_INTERNALS
  151713. typedef struct {
  151714. struct jpeg_inverse_dct pub; /* public fields */
  151715. int cur_method[MAX_COMPONENTS];
  151716. } my_idct_controller;
  151717. typedef my_idct_controller * my_idct_ptr;
  151718. typedef union {
  151719. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  151720. #ifdef DCT_IFAST_SUPPORTED
  151721. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  151722. #endif
  151723. #ifdef DCT_FLOAT_SUPPORTED
  151724. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  151725. #endif
  151726. } multiplier_table;
  151727. #ifdef DCT_ISLOW_SUPPORTED
  151728. #define PROVIDE_ISLOW_TABLES
  151729. #else
  151730. #ifdef IDCT_SCALING_SUPPORTED
  151731. #define PROVIDE_ISLOW_TABLES
  151732. #endif
  151733. #endif
  151734. METHODDEF(void)
  151735. start_pass (j_decompress_ptr cinfo)
  151736. {
  151737. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  151738. int ci, i;
  151739. jpeg_component_info *compptr;
  151740. int method = 0;
  151741. inverse_DCT_method_ptr method_ptr = NULL;
  151742. JQUANT_TBL * qtbl;
  151743. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151744. ci++, compptr++) {
  151745. switch (compptr->DCT_scaled_size) {
  151746. #ifdef IDCT_SCALING_SUPPORTED
  151747. case 1:
  151748. method_ptr = jpeg_idct_1x1;
  151749. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151750. break;
  151751. case 2:
  151752. method_ptr = jpeg_idct_2x2;
  151753. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151754. break;
  151755. case 4:
  151756. method_ptr = jpeg_idct_4x4;
  151757. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151758. break;
  151759. #endif
  151760. case DCTSIZE:
  151761. switch (cinfo->dct_method) {
  151762. #ifdef DCT_ISLOW_SUPPORTED
  151763. case JDCT_ISLOW:
  151764. method_ptr = jpeg_idct_islow;
  151765. method = JDCT_ISLOW;
  151766. break;
  151767. #endif
  151768. #ifdef DCT_IFAST_SUPPORTED
  151769. case JDCT_IFAST:
  151770. method_ptr = jpeg_idct_ifast;
  151771. method = JDCT_IFAST;
  151772. break;
  151773. #endif
  151774. #ifdef DCT_FLOAT_SUPPORTED
  151775. case JDCT_FLOAT:
  151776. method_ptr = jpeg_idct_float;
  151777. method = JDCT_FLOAT;
  151778. break;
  151779. #endif
  151780. default:
  151781. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151782. break;
  151783. }
  151784. break;
  151785. default:
  151786. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  151787. break;
  151788. }
  151789. idct->pub.inverse_DCT[ci] = method_ptr;
  151790. if (! compptr->component_needed || idct->cur_method[ci] == method)
  151791. continue;
  151792. qtbl = compptr->quant_table;
  151793. if (qtbl == NULL) /* happens if no data yet for component */
  151794. continue;
  151795. idct->cur_method[ci] = method;
  151796. switch (method) {
  151797. #ifdef PROVIDE_ISLOW_TABLES
  151798. case JDCT_ISLOW:
  151799. {
  151800. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  151801. for (i = 0; i < DCTSIZE2; i++) {
  151802. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  151803. }
  151804. }
  151805. break;
  151806. #endif
  151807. #ifdef DCT_IFAST_SUPPORTED
  151808. case JDCT_IFAST:
  151809. {
  151810. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  151811. #define CONST_BITS 14
  151812. static const INT16 aanscales[DCTSIZE2] = {
  151813. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151814. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  151815. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  151816. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  151817. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151818. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  151819. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  151820. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  151821. };
  151822. SHIFT_TEMPS
  151823. for (i = 0; i < DCTSIZE2; i++) {
  151824. ifmtbl[i] = (IFAST_MULT_TYPE)
  151825. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  151826. (INT32) aanscales[i]),
  151827. CONST_BITS-IFAST_SCALE_BITS);
  151828. }
  151829. }
  151830. break;
  151831. #endif
  151832. #ifdef DCT_FLOAT_SUPPORTED
  151833. case JDCT_FLOAT:
  151834. {
  151835. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  151836. int row, col;
  151837. static const double aanscalefactor[DCTSIZE] = {
  151838. 1.0, 1.387039845, 1.306562965, 1.175875602,
  151839. 1.0, 0.785694958, 0.541196100, 0.275899379
  151840. };
  151841. i = 0;
  151842. for (row = 0; row < DCTSIZE; row++) {
  151843. for (col = 0; col < DCTSIZE; col++) {
  151844. fmtbl[i] = (FLOAT_MULT_TYPE)
  151845. ((double) qtbl->quantval[i] *
  151846. aanscalefactor[row] * aanscalefactor[col]);
  151847. i++;
  151848. }
  151849. }
  151850. }
  151851. break;
  151852. #endif
  151853. default:
  151854. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151855. break;
  151856. }
  151857. }
  151858. }
  151859. GLOBAL(void)
  151860. jinit_inverse_dct (j_decompress_ptr cinfo)
  151861. {
  151862. my_idct_ptr idct;
  151863. int ci;
  151864. jpeg_component_info *compptr;
  151865. idct = (my_idct_ptr)
  151866. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151867. SIZEOF(my_idct_controller));
  151868. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  151869. idct->pub.start_pass = start_pass;
  151870. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151871. ci++, compptr++) {
  151872. compptr->dct_table =
  151873. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151874. SIZEOF(multiplier_table));
  151875. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  151876. idct->cur_method[ci] = -1;
  151877. }
  151878. }
  151879. /*** End of inlined file: jddctmgr.c ***/
  151880. #undef CONST_BITS
  151881. #undef ASSIGN_STATE
  151882. /*** Start of inlined file: jdhuff.c ***/
  151883. #define JPEG_INTERNALS
  151884. /*** Start of inlined file: jdhuff.h ***/
  151885. #ifndef __jdhuff_h__
  151886. #define __jdhuff_h__
  151887. #ifdef NEED_SHORT_EXTERNAL_NAMES
  151888. #define jpeg_make_d_derived_tbl jMkDDerived
  151889. #define jpeg_fill_bit_buffer jFilBitBuf
  151890. #define jpeg_huff_decode jHufDecode
  151891. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  151892. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  151893. typedef struct {
  151894. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  151895. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  151896. JHUFF_TBL *pub;
  151897. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  151898. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  151899. } d_derived_tbl;
  151900. EXTERN(void) jpeg_make_d_derived_tbl
  151901. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  151902. d_derived_tbl ** pdtbl));
  151903. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  151904. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  151905. typedef struct { /* Bitreading state saved across MCUs */
  151906. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151907. int bits_left; /* # of unused bits in it */
  151908. } bitread_perm_state;
  151909. typedef struct { /* Bitreading working state within an MCU */
  151910. const JOCTET * next_input_byte; /* => next byte to read from source */
  151911. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  151912. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151913. int bits_left; /* # of unused bits in it */
  151914. j_decompress_ptr cinfo; /* back link to decompress master record */
  151915. } bitread_working_state;
  151916. #define BITREAD_STATE_VARS \
  151917. register bit_buf_type get_buffer; \
  151918. register int bits_left; \
  151919. bitread_working_state br_state
  151920. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  151921. br_state.cinfo = cinfop; \
  151922. br_state.next_input_byte = cinfop->src->next_input_byte; \
  151923. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  151924. get_buffer = permstate.get_buffer; \
  151925. bits_left = permstate.bits_left;
  151926. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  151927. cinfop->src->next_input_byte = br_state.next_input_byte; \
  151928. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  151929. permstate.get_buffer = get_buffer; \
  151930. permstate.bits_left = bits_left
  151931. #define CHECK_BIT_BUFFER(state,nbits,action) \
  151932. { if (bits_left < (nbits)) { \
  151933. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  151934. { action; } \
  151935. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  151936. #define GET_BITS(nbits) \
  151937. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  151938. #define PEEK_BITS(nbits) \
  151939. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  151940. #define DROP_BITS(nbits) \
  151941. (bits_left -= (nbits))
  151942. EXTERN(boolean) jpeg_fill_bit_buffer
  151943. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151944. register int bits_left, int nbits));
  151945. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  151946. { register int nb, look; \
  151947. if (bits_left < HUFF_LOOKAHEAD) { \
  151948. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  151949. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151950. if (bits_left < HUFF_LOOKAHEAD) { \
  151951. nb = 1; goto slowlabel; \
  151952. } \
  151953. } \
  151954. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  151955. if ((nb = htbl->look_nbits[look]) != 0) { \
  151956. DROP_BITS(nb); \
  151957. result = htbl->look_sym[look]; \
  151958. } else { \
  151959. nb = HUFF_LOOKAHEAD+1; \
  151960. slowlabel: \
  151961. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  151962. { failaction; } \
  151963. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151964. } \
  151965. }
  151966. EXTERN(int) jpeg_huff_decode
  151967. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151968. register int bits_left, d_derived_tbl * htbl, int min_bits));
  151969. #endif
  151970. /*** End of inlined file: jdhuff.h ***/
  151971. /* Declarations shared with jdphuff.c */
  151972. typedef struct {
  151973. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  151974. } savable_state2;
  151975. #ifndef NO_STRUCT_ASSIGN
  151976. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  151977. #else
  151978. #if MAX_COMPS_IN_SCAN == 4
  151979. #define ASSIGN_STATE(dest,src) \
  151980. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  151981. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  151982. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  151983. (dest).last_dc_val[3] = (src).last_dc_val[3])
  151984. #endif
  151985. #endif
  151986. typedef struct {
  151987. struct jpeg_entropy_decoder pub; /* public fields */
  151988. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  151989. savable_state2 saved; /* Other state at start of MCU */
  151990. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  151991. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  151992. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  151993. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151994. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151995. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  151996. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  151997. } huff_entropy_decoder2;
  151998. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  151999. METHODDEF(void)
  152000. start_pass_huff_decoder (j_decompress_ptr cinfo)
  152001. {
  152002. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152003. int ci, blkn, dctbl, actbl;
  152004. jpeg_component_info * compptr;
  152005. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  152006. cinfo->Ah != 0 || cinfo->Al != 0)
  152007. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  152008. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152009. compptr = cinfo->cur_comp_info[ci];
  152010. dctbl = compptr->dc_tbl_no;
  152011. actbl = compptr->ac_tbl_no;
  152012. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  152013. & entropy->dc_derived_tbls[dctbl]);
  152014. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  152015. & entropy->ac_derived_tbls[actbl]);
  152016. entropy->saved.last_dc_val[ci] = 0;
  152017. }
  152018. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152019. ci = cinfo->MCU_membership[blkn];
  152020. compptr = cinfo->cur_comp_info[ci];
  152021. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  152022. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  152023. if (compptr->component_needed) {
  152024. entropy->dc_needed[blkn] = TRUE;
  152025. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  152026. } else {
  152027. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  152028. }
  152029. }
  152030. entropy->bitstate.bits_left = 0;
  152031. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  152032. entropy->pub.insufficient_data = FALSE;
  152033. entropy->restarts_to_go = cinfo->restart_interval;
  152034. }
  152035. GLOBAL(void)
  152036. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  152037. d_derived_tbl ** pdtbl)
  152038. {
  152039. JHUFF_TBL *htbl;
  152040. d_derived_tbl *dtbl;
  152041. int p, i, l, si, numsymbols;
  152042. int lookbits, ctr;
  152043. char huffsize[257];
  152044. unsigned int huffcode[257];
  152045. unsigned int code;
  152046. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  152047. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152048. htbl =
  152049. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  152050. if (htbl == NULL)
  152051. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152052. if (*pdtbl == NULL)
  152053. *pdtbl = (d_derived_tbl *)
  152054. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152055. SIZEOF(d_derived_tbl));
  152056. dtbl = *pdtbl;
  152057. dtbl->pub = htbl; /* fill in back link */
  152058. p = 0;
  152059. for (l = 1; l <= 16; l++) {
  152060. i = (int) htbl->bits[l];
  152061. if (i < 0 || p + i > 256) /* protect against table overrun */
  152062. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152063. while (i--)
  152064. huffsize[p++] = (char) l;
  152065. }
  152066. huffsize[p] = 0;
  152067. numsymbols = p;
  152068. code = 0;
  152069. si = huffsize[0];
  152070. p = 0;
  152071. while (huffsize[p]) {
  152072. while (((int) huffsize[p]) == si) {
  152073. huffcode[p++] = code;
  152074. code++;
  152075. }
  152076. if (((INT32) code) >= (((INT32) 1) << si))
  152077. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152078. code <<= 1;
  152079. si++;
  152080. }
  152081. p = 0;
  152082. for (l = 1; l <= 16; l++) {
  152083. if (htbl->bits[l]) {
  152084. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  152085. p += htbl->bits[l];
  152086. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  152087. } else {
  152088. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  152089. }
  152090. }
  152091. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  152092. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  152093. p = 0;
  152094. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  152095. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  152096. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  152097. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  152098. dtbl->look_nbits[lookbits] = l;
  152099. dtbl->look_sym[lookbits] = htbl->huffval[p];
  152100. lookbits++;
  152101. }
  152102. }
  152103. }
  152104. if (isDC) {
  152105. for (i = 0; i < numsymbols; i++) {
  152106. int sym = htbl->huffval[i];
  152107. if (sym < 0 || sym > 15)
  152108. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152109. }
  152110. }
  152111. }
  152112. #ifdef SLOW_SHIFT_32
  152113. #define MIN_GET_BITS 15 /* minimum allowable value */
  152114. #else
  152115. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  152116. #endif
  152117. GLOBAL(boolean)
  152118. jpeg_fill_bit_buffer (bitread_working_state * state,
  152119. register bit_buf_type get_buffer, register int bits_left,
  152120. int nbits)
  152121. {
  152122. register const JOCTET * next_input_byte = state->next_input_byte;
  152123. register size_t bytes_in_buffer = state->bytes_in_buffer;
  152124. j_decompress_ptr cinfo = state->cinfo;
  152125. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  152126. while (bits_left < MIN_GET_BITS) {
  152127. register int c;
  152128. if (bytes_in_buffer == 0) {
  152129. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152130. return FALSE;
  152131. next_input_byte = cinfo->src->next_input_byte;
  152132. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152133. }
  152134. bytes_in_buffer--;
  152135. c = GETJOCTET(*next_input_byte++);
  152136. if (c == 0xFF) {
  152137. do {
  152138. if (bytes_in_buffer == 0) {
  152139. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152140. return FALSE;
  152141. next_input_byte = cinfo->src->next_input_byte;
  152142. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152143. }
  152144. bytes_in_buffer--;
  152145. c = GETJOCTET(*next_input_byte++);
  152146. } while (c == 0xFF);
  152147. if (c == 0) {
  152148. c = 0xFF;
  152149. } else {
  152150. cinfo->unread_marker = c;
  152151. goto no_more_bytes;
  152152. }
  152153. }
  152154. get_buffer = (get_buffer << 8) | c;
  152155. bits_left += 8;
  152156. } /* end while */
  152157. } else {
  152158. no_more_bytes:
  152159. if (nbits > bits_left) {
  152160. if (! cinfo->entropy->insufficient_data) {
  152161. WARNMS(cinfo, JWRN_HIT_MARKER);
  152162. cinfo->entropy->insufficient_data = TRUE;
  152163. }
  152164. get_buffer <<= MIN_GET_BITS - bits_left;
  152165. bits_left = MIN_GET_BITS;
  152166. }
  152167. }
  152168. state->next_input_byte = next_input_byte;
  152169. state->bytes_in_buffer = bytes_in_buffer;
  152170. state->get_buffer = get_buffer;
  152171. state->bits_left = bits_left;
  152172. return TRUE;
  152173. }
  152174. GLOBAL(int)
  152175. jpeg_huff_decode (bitread_working_state * state,
  152176. register bit_buf_type get_buffer, register int bits_left,
  152177. d_derived_tbl * htbl, int min_bits)
  152178. {
  152179. register int l = min_bits;
  152180. register INT32 code;
  152181. CHECK_BIT_BUFFER(*state, l, return -1);
  152182. code = GET_BITS(l);
  152183. while (code > htbl->maxcode[l]) {
  152184. code <<= 1;
  152185. CHECK_BIT_BUFFER(*state, 1, return -1);
  152186. code |= GET_BITS(1);
  152187. l++;
  152188. }
  152189. state->get_buffer = get_buffer;
  152190. state->bits_left = bits_left;
  152191. if (l > 16) {
  152192. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  152193. return 0; /* fake a zero as the safest result */
  152194. }
  152195. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  152196. }
  152197. LOCAL(boolean)
  152198. process_restart (j_decompress_ptr cinfo)
  152199. {
  152200. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152201. int ci;
  152202. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  152203. entropy->bitstate.bits_left = 0;
  152204. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  152205. return FALSE;
  152206. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  152207. entropy->saved.last_dc_val[ci] = 0;
  152208. entropy->restarts_to_go = cinfo->restart_interval;
  152209. if (cinfo->unread_marker == 0)
  152210. entropy->pub.insufficient_data = FALSE;
  152211. return TRUE;
  152212. }
  152213. METHODDEF(boolean)
  152214. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  152215. {
  152216. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152217. int blkn;
  152218. BITREAD_STATE_VARS;
  152219. savable_state2 state;
  152220. if (cinfo->restart_interval) {
  152221. if (entropy->restarts_to_go == 0)
  152222. if (! process_restart(cinfo))
  152223. return FALSE;
  152224. }
  152225. if (! entropy->pub.insufficient_data) {
  152226. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  152227. ASSIGN_STATE(state, entropy->saved);
  152228. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152229. JBLOCKROW block = MCU_data[blkn];
  152230. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  152231. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  152232. register int s, k, r;
  152233. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  152234. if (s) {
  152235. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152236. r = GET_BITS(s);
  152237. s = HUFF_EXTEND(r, s);
  152238. }
  152239. if (entropy->dc_needed[blkn]) {
  152240. int ci = cinfo->MCU_membership[blkn];
  152241. s += state.last_dc_val[ci];
  152242. state.last_dc_val[ci] = s;
  152243. (*block)[0] = (JCOEF) s;
  152244. }
  152245. if (entropy->ac_needed[blkn]) {
  152246. for (k = 1; k < DCTSIZE2; k++) {
  152247. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  152248. r = s >> 4;
  152249. s &= 15;
  152250. if (s) {
  152251. k += r;
  152252. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152253. r = GET_BITS(s);
  152254. s = HUFF_EXTEND(r, s);
  152255. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  152256. } else {
  152257. if (r != 15)
  152258. break;
  152259. k += 15;
  152260. }
  152261. }
  152262. } else {
  152263. for (k = 1; k < DCTSIZE2; k++) {
  152264. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  152265. r = s >> 4;
  152266. s &= 15;
  152267. if (s) {
  152268. k += r;
  152269. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152270. DROP_BITS(s);
  152271. } else {
  152272. if (r != 15)
  152273. break;
  152274. k += 15;
  152275. }
  152276. }
  152277. }
  152278. }
  152279. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152280. ASSIGN_STATE(entropy->saved, state);
  152281. }
  152282. entropy->restarts_to_go--;
  152283. return TRUE;
  152284. }
  152285. GLOBAL(void)
  152286. jinit_huff_decoder (j_decompress_ptr cinfo)
  152287. {
  152288. huff_entropy_ptr2 entropy;
  152289. int i;
  152290. entropy = (huff_entropy_ptr2)
  152291. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152292. SIZEOF(huff_entropy_decoder2));
  152293. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152294. entropy->pub.start_pass = start_pass_huff_decoder;
  152295. entropy->pub.decode_mcu = decode_mcu;
  152296. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152297. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152298. }
  152299. }
  152300. /*** End of inlined file: jdhuff.c ***/
  152301. /*** Start of inlined file: jdinput.c ***/
  152302. #define JPEG_INTERNALS
  152303. typedef struct {
  152304. struct jpeg_input_controller pub; /* public fields */
  152305. boolean inheaders; /* TRUE until first SOS is reached */
  152306. } my_input_controller;
  152307. typedef my_input_controller * my_inputctl_ptr;
  152308. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152309. LOCAL(void)
  152310. initial_setup2 (j_decompress_ptr cinfo)
  152311. {
  152312. int ci;
  152313. jpeg_component_info *compptr;
  152314. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152315. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152316. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152317. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152318. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152319. if (cinfo->num_components > MAX_COMPONENTS)
  152320. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152321. MAX_COMPONENTS);
  152322. cinfo->max_h_samp_factor = 1;
  152323. cinfo->max_v_samp_factor = 1;
  152324. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152325. ci++, compptr++) {
  152326. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152327. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152328. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152329. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152330. compptr->h_samp_factor);
  152331. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152332. compptr->v_samp_factor);
  152333. }
  152334. cinfo->min_DCT_scaled_size = DCTSIZE;
  152335. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152336. ci++, compptr++) {
  152337. compptr->DCT_scaled_size = DCTSIZE;
  152338. compptr->width_in_blocks = (JDIMENSION)
  152339. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152340. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152341. compptr->height_in_blocks = (JDIMENSION)
  152342. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152343. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152344. compptr->downsampled_width = (JDIMENSION)
  152345. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152346. (long) cinfo->max_h_samp_factor);
  152347. compptr->downsampled_height = (JDIMENSION)
  152348. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152349. (long) cinfo->max_v_samp_factor);
  152350. compptr->component_needed = TRUE;
  152351. compptr->quant_table = NULL;
  152352. }
  152353. cinfo->total_iMCU_rows = (JDIMENSION)
  152354. jdiv_round_up((long) cinfo->image_height,
  152355. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152356. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152357. cinfo->inputctl->has_multiple_scans = TRUE;
  152358. else
  152359. cinfo->inputctl->has_multiple_scans = FALSE;
  152360. }
  152361. LOCAL(void)
  152362. per_scan_setup2 (j_decompress_ptr cinfo)
  152363. {
  152364. int ci, mcublks, tmp;
  152365. jpeg_component_info *compptr;
  152366. if (cinfo->comps_in_scan == 1) {
  152367. compptr = cinfo->cur_comp_info[0];
  152368. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152369. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152370. compptr->MCU_width = 1;
  152371. compptr->MCU_height = 1;
  152372. compptr->MCU_blocks = 1;
  152373. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152374. compptr->last_col_width = 1;
  152375. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152376. if (tmp == 0) tmp = compptr->v_samp_factor;
  152377. compptr->last_row_height = tmp;
  152378. cinfo->blocks_in_MCU = 1;
  152379. cinfo->MCU_membership[0] = 0;
  152380. } else {
  152381. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152382. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152383. MAX_COMPS_IN_SCAN);
  152384. cinfo->MCUs_per_row = (JDIMENSION)
  152385. jdiv_round_up((long) cinfo->image_width,
  152386. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  152387. cinfo->MCU_rows_in_scan = (JDIMENSION)
  152388. jdiv_round_up((long) cinfo->image_height,
  152389. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152390. cinfo->blocks_in_MCU = 0;
  152391. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152392. compptr = cinfo->cur_comp_info[ci];
  152393. compptr->MCU_width = compptr->h_samp_factor;
  152394. compptr->MCU_height = compptr->v_samp_factor;
  152395. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152396. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152397. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152398. if (tmp == 0) tmp = compptr->MCU_width;
  152399. compptr->last_col_width = tmp;
  152400. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152401. if (tmp == 0) tmp = compptr->MCU_height;
  152402. compptr->last_row_height = tmp;
  152403. mcublks = compptr->MCU_blocks;
  152404. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152405. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152406. while (mcublks-- > 0) {
  152407. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152408. }
  152409. }
  152410. }
  152411. }
  152412. LOCAL(void)
  152413. latch_quant_tables (j_decompress_ptr cinfo)
  152414. {
  152415. int ci, qtblno;
  152416. jpeg_component_info *compptr;
  152417. JQUANT_TBL * qtbl;
  152418. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152419. compptr = cinfo->cur_comp_info[ci];
  152420. if (compptr->quant_table != NULL)
  152421. continue;
  152422. qtblno = compptr->quant_tbl_no;
  152423. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152424. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152425. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152426. qtbl = (JQUANT_TBL *)
  152427. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152428. SIZEOF(JQUANT_TBL));
  152429. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152430. compptr->quant_table = qtbl;
  152431. }
  152432. }
  152433. METHODDEF(void)
  152434. start_input_pass2 (j_decompress_ptr cinfo)
  152435. {
  152436. per_scan_setup2(cinfo);
  152437. latch_quant_tables(cinfo);
  152438. (*cinfo->entropy->start_pass) (cinfo);
  152439. (*cinfo->coef->start_input_pass) (cinfo);
  152440. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152441. }
  152442. METHODDEF(void)
  152443. finish_input_pass (j_decompress_ptr cinfo)
  152444. {
  152445. cinfo->inputctl->consume_input = consume_markers;
  152446. }
  152447. METHODDEF(int)
  152448. consume_markers (j_decompress_ptr cinfo)
  152449. {
  152450. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152451. int val;
  152452. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152453. return JPEG_REACHED_EOI;
  152454. val = (*cinfo->marker->read_markers) (cinfo);
  152455. switch (val) {
  152456. case JPEG_REACHED_SOS: /* Found SOS */
  152457. if (inputctl->inheaders) { /* 1st SOS */
  152458. initial_setup2(cinfo);
  152459. inputctl->inheaders = FALSE;
  152460. } else { /* 2nd or later SOS marker */
  152461. if (! inputctl->pub.has_multiple_scans)
  152462. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152463. start_input_pass2(cinfo);
  152464. }
  152465. break;
  152466. case JPEG_REACHED_EOI: /* Found EOI */
  152467. inputctl->pub.eoi_reached = TRUE;
  152468. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152469. if (cinfo->marker->saw_SOF)
  152470. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152471. } else {
  152472. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152473. cinfo->output_scan_number = cinfo->input_scan_number;
  152474. }
  152475. break;
  152476. case JPEG_SUSPENDED:
  152477. break;
  152478. }
  152479. return val;
  152480. }
  152481. METHODDEF(void)
  152482. reset_input_controller (j_decompress_ptr cinfo)
  152483. {
  152484. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152485. inputctl->pub.consume_input = consume_markers;
  152486. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152487. inputctl->pub.eoi_reached = FALSE;
  152488. inputctl->inheaders = TRUE;
  152489. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152490. (*cinfo->marker->reset_marker_reader) (cinfo);
  152491. cinfo->coef_bits = NULL;
  152492. }
  152493. GLOBAL(void)
  152494. jinit_input_controller (j_decompress_ptr cinfo)
  152495. {
  152496. my_inputctl_ptr inputctl;
  152497. inputctl = (my_inputctl_ptr)
  152498. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152499. SIZEOF(my_input_controller));
  152500. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152501. inputctl->pub.consume_input = consume_markers;
  152502. inputctl->pub.reset_input_controller = reset_input_controller;
  152503. inputctl->pub.start_input_pass = start_input_pass2;
  152504. inputctl->pub.finish_input_pass = finish_input_pass;
  152505. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152506. inputctl->pub.eoi_reached = FALSE;
  152507. inputctl->inheaders = TRUE;
  152508. }
  152509. /*** End of inlined file: jdinput.c ***/
  152510. /*** Start of inlined file: jdmainct.c ***/
  152511. #define JPEG_INTERNALS
  152512. typedef struct {
  152513. struct jpeg_d_main_controller pub; /* public fields */
  152514. JSAMPARRAY buffer[MAX_COMPONENTS];
  152515. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152516. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152517. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152518. int whichptr; /* indicates which pointer set is now in use */
  152519. int context_state; /* process_data state machine status */
  152520. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152521. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152522. } my_main_controller4;
  152523. typedef my_main_controller4 * my_main_ptr4;
  152524. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152525. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152526. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152527. METHODDEF(void) process_data_simple_main2
  152528. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152529. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152530. METHODDEF(void) process_data_context_main
  152531. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152532. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152533. #ifdef QUANT_2PASS_SUPPORTED
  152534. METHODDEF(void) process_data_crank_post
  152535. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152536. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152537. #endif
  152538. LOCAL(void)
  152539. alloc_funny_pointers (j_decompress_ptr cinfo)
  152540. {
  152541. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152542. int ci, rgroup;
  152543. int M = cinfo->min_DCT_scaled_size;
  152544. jpeg_component_info *compptr;
  152545. JSAMPARRAY xbuf;
  152546. main_->xbuffer[0] = (JSAMPIMAGE)
  152547. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152548. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152549. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152550. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152551. ci++, compptr++) {
  152552. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152553. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152554. xbuf = (JSAMPARRAY)
  152555. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152556. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152557. xbuf += rgroup; /* want one row group at negative offsets */
  152558. main_->xbuffer[0][ci] = xbuf;
  152559. xbuf += rgroup * (M + 4);
  152560. main_->xbuffer[1][ci] = xbuf;
  152561. }
  152562. }
  152563. LOCAL(void)
  152564. make_funny_pointers (j_decompress_ptr cinfo)
  152565. {
  152566. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152567. int ci, i, rgroup;
  152568. int M = cinfo->min_DCT_scaled_size;
  152569. jpeg_component_info *compptr;
  152570. JSAMPARRAY buf, xbuf0, xbuf1;
  152571. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152572. ci++, compptr++) {
  152573. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152574. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152575. xbuf0 = main_->xbuffer[0][ci];
  152576. xbuf1 = main_->xbuffer[1][ci];
  152577. buf = main_->buffer[ci];
  152578. for (i = 0; i < rgroup * (M + 2); i++) {
  152579. xbuf0[i] = xbuf1[i] = buf[i];
  152580. }
  152581. for (i = 0; i < rgroup * 2; i++) {
  152582. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152583. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152584. }
  152585. for (i = 0; i < rgroup; i++) {
  152586. xbuf0[i - rgroup] = xbuf0[0];
  152587. }
  152588. }
  152589. }
  152590. LOCAL(void)
  152591. set_wraparound_pointers (j_decompress_ptr cinfo)
  152592. {
  152593. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152594. int ci, i, rgroup;
  152595. int M = cinfo->min_DCT_scaled_size;
  152596. jpeg_component_info *compptr;
  152597. JSAMPARRAY xbuf0, xbuf1;
  152598. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152599. ci++, compptr++) {
  152600. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152601. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152602. xbuf0 = main_->xbuffer[0][ci];
  152603. xbuf1 = main_->xbuffer[1][ci];
  152604. for (i = 0; i < rgroup; i++) {
  152605. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152606. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152607. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152608. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152609. }
  152610. }
  152611. }
  152612. LOCAL(void)
  152613. set_bottom_pointers (j_decompress_ptr cinfo)
  152614. {
  152615. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152616. int ci, i, rgroup, iMCUheight, rows_left;
  152617. jpeg_component_info *compptr;
  152618. JSAMPARRAY xbuf;
  152619. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152620. ci++, compptr++) {
  152621. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152622. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152623. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152624. if (rows_left == 0) rows_left = iMCUheight;
  152625. if (ci == 0) {
  152626. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152627. }
  152628. xbuf = main_->xbuffer[main_->whichptr][ci];
  152629. for (i = 0; i < rgroup * 2; i++) {
  152630. xbuf[rows_left + i] = xbuf[rows_left-1];
  152631. }
  152632. }
  152633. }
  152634. METHODDEF(void)
  152635. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152636. {
  152637. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152638. switch (pass_mode) {
  152639. case JBUF_PASS_THRU:
  152640. if (cinfo->upsample->need_context_rows) {
  152641. main_->pub.process_data = process_data_context_main;
  152642. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152643. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152644. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152645. main_->iMCU_row_ctr = 0;
  152646. } else {
  152647. main_->pub.process_data = process_data_simple_main2;
  152648. }
  152649. main_->buffer_full = FALSE; /* Mark buffer empty */
  152650. main_->rowgroup_ctr = 0;
  152651. break;
  152652. #ifdef QUANT_2PASS_SUPPORTED
  152653. case JBUF_CRANK_DEST:
  152654. main_->pub.process_data = process_data_crank_post;
  152655. break;
  152656. #endif
  152657. default:
  152658. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152659. break;
  152660. }
  152661. }
  152662. METHODDEF(void)
  152663. process_data_simple_main2 (j_decompress_ptr cinfo,
  152664. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152665. JDIMENSION out_rows_avail)
  152666. {
  152667. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152668. JDIMENSION rowgroups_avail;
  152669. if (! main_->buffer_full) {
  152670. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  152671. return; /* suspension forced, can do nothing more */
  152672. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152673. }
  152674. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  152675. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  152676. &main_->rowgroup_ctr, rowgroups_avail,
  152677. output_buf, out_row_ctr, out_rows_avail);
  152678. if (main_->rowgroup_ctr >= rowgroups_avail) {
  152679. main_->buffer_full = FALSE;
  152680. main_->rowgroup_ctr = 0;
  152681. }
  152682. }
  152683. METHODDEF(void)
  152684. process_data_context_main (j_decompress_ptr cinfo,
  152685. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152686. JDIMENSION out_rows_avail)
  152687. {
  152688. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152689. if (! main_->buffer_full) {
  152690. if (! (*cinfo->coef->decompress_data) (cinfo,
  152691. main_->xbuffer[main_->whichptr]))
  152692. return; /* suspension forced, can do nothing more */
  152693. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152694. main_->iMCU_row_ctr++; /* count rows received */
  152695. }
  152696. switch (main_->context_state) {
  152697. case CTX_POSTPONED_ROW:
  152698. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152699. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152700. output_buf, out_row_ctr, out_rows_avail);
  152701. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152702. return; /* Need to suspend */
  152703. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152704. if (*out_row_ctr >= out_rows_avail)
  152705. return; /* Postprocessor exactly filled output buf */
  152706. case CTX_PREPARE_FOR_IMCU:
  152707. main_->rowgroup_ctr = 0;
  152708. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  152709. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  152710. set_bottom_pointers(cinfo);
  152711. main_->context_state = CTX_PROCESS_IMCU;
  152712. case CTX_PROCESS_IMCU:
  152713. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152714. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152715. output_buf, out_row_ctr, out_rows_avail);
  152716. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152717. return; /* Need to suspend */
  152718. if (main_->iMCU_row_ctr == 1)
  152719. set_wraparound_pointers(cinfo);
  152720. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  152721. main_->buffer_full = FALSE;
  152722. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  152723. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  152724. main_->context_state = CTX_POSTPONED_ROW;
  152725. }
  152726. }
  152727. #ifdef QUANT_2PASS_SUPPORTED
  152728. METHODDEF(void)
  152729. process_data_crank_post (j_decompress_ptr cinfo,
  152730. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152731. JDIMENSION out_rows_avail)
  152732. {
  152733. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  152734. (JDIMENSION *) NULL, (JDIMENSION) 0,
  152735. output_buf, out_row_ctr, out_rows_avail);
  152736. }
  152737. #endif /* QUANT_2PASS_SUPPORTED */
  152738. GLOBAL(void)
  152739. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  152740. {
  152741. my_main_ptr4 main_;
  152742. int ci, rgroup, ngroups;
  152743. jpeg_component_info *compptr;
  152744. main_ = (my_main_ptr4)
  152745. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152746. SIZEOF(my_main_controller4));
  152747. cinfo->main = (struct jpeg_d_main_controller *) main_;
  152748. main_->pub.start_pass = start_pass_main2;
  152749. if (need_full_buffer) /* shouldn't happen */
  152750. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152751. if (cinfo->upsample->need_context_rows) {
  152752. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  152753. ERREXIT(cinfo, JERR_NOTIMPL);
  152754. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  152755. ngroups = cinfo->min_DCT_scaled_size + 2;
  152756. } else {
  152757. ngroups = cinfo->min_DCT_scaled_size;
  152758. }
  152759. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152760. ci++, compptr++) {
  152761. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152762. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152763. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  152764. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152765. compptr->width_in_blocks * compptr->DCT_scaled_size,
  152766. (JDIMENSION) (rgroup * ngroups));
  152767. }
  152768. }
  152769. /*** End of inlined file: jdmainct.c ***/
  152770. /*** Start of inlined file: jdmarker.c ***/
  152771. #define JPEG_INTERNALS
  152772. typedef struct {
  152773. struct jpeg_marker_reader pub; /* public fields */
  152774. jpeg_marker_parser_method process_COM;
  152775. jpeg_marker_parser_method process_APPn[16];
  152776. unsigned int length_limit_COM;
  152777. unsigned int length_limit_APPn[16];
  152778. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  152779. unsigned int bytes_read; /* data bytes read so far in marker */
  152780. } my_marker_reader;
  152781. typedef my_marker_reader * my_marker_ptr2;
  152782. #define INPUT_VARS(cinfo) \
  152783. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  152784. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  152785. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  152786. #define INPUT_SYNC(cinfo) \
  152787. ( datasrc->next_input_byte = next_input_byte, \
  152788. datasrc->bytes_in_buffer = bytes_in_buffer )
  152789. #define INPUT_RELOAD(cinfo) \
  152790. ( next_input_byte = datasrc->next_input_byte, \
  152791. bytes_in_buffer = datasrc->bytes_in_buffer )
  152792. #define MAKE_BYTE_AVAIL(cinfo,action) \
  152793. if (bytes_in_buffer == 0) { \
  152794. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  152795. { action; } \
  152796. INPUT_RELOAD(cinfo); \
  152797. }
  152798. #define INPUT_BYTE(cinfo,V,action) \
  152799. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152800. bytes_in_buffer--; \
  152801. V = GETJOCTET(*next_input_byte++); )
  152802. #define INPUT_2BYTES(cinfo,V,action) \
  152803. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152804. bytes_in_buffer--; \
  152805. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  152806. MAKE_BYTE_AVAIL(cinfo,action); \
  152807. bytes_in_buffer--; \
  152808. V += GETJOCTET(*next_input_byte++); )
  152809. LOCAL(boolean)
  152810. get_soi (j_decompress_ptr cinfo)
  152811. {
  152812. int i;
  152813. TRACEMS(cinfo, 1, JTRC_SOI);
  152814. if (cinfo->marker->saw_SOI)
  152815. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  152816. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  152817. cinfo->arith_dc_L[i] = 0;
  152818. cinfo->arith_dc_U[i] = 1;
  152819. cinfo->arith_ac_K[i] = 5;
  152820. }
  152821. cinfo->restart_interval = 0;
  152822. cinfo->jpeg_color_space = JCS_UNKNOWN;
  152823. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  152824. cinfo->saw_JFIF_marker = FALSE;
  152825. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  152826. cinfo->JFIF_minor_version = 1;
  152827. cinfo->density_unit = 0;
  152828. cinfo->X_density = 1;
  152829. cinfo->Y_density = 1;
  152830. cinfo->saw_Adobe_marker = FALSE;
  152831. cinfo->Adobe_transform = 0;
  152832. cinfo->marker->saw_SOI = TRUE;
  152833. return TRUE;
  152834. }
  152835. LOCAL(boolean)
  152836. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  152837. {
  152838. INT32 length;
  152839. int c, ci;
  152840. jpeg_component_info * compptr;
  152841. INPUT_VARS(cinfo);
  152842. cinfo->progressive_mode = is_prog;
  152843. cinfo->arith_code = is_arith;
  152844. INPUT_2BYTES(cinfo, length, return FALSE);
  152845. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  152846. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  152847. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  152848. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  152849. length -= 8;
  152850. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  152851. (int) cinfo->image_width, (int) cinfo->image_height,
  152852. cinfo->num_components);
  152853. if (cinfo->marker->saw_SOF)
  152854. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  152855. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  152856. || cinfo->num_components <= 0)
  152857. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  152858. if (length != (cinfo->num_components * 3))
  152859. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152860. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  152861. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  152862. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152863. cinfo->num_components * SIZEOF(jpeg_component_info));
  152864. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152865. ci++, compptr++) {
  152866. compptr->component_index = ci;
  152867. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  152868. INPUT_BYTE(cinfo, c, return FALSE);
  152869. compptr->h_samp_factor = (c >> 4) & 15;
  152870. compptr->v_samp_factor = (c ) & 15;
  152871. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  152872. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  152873. compptr->component_id, compptr->h_samp_factor,
  152874. compptr->v_samp_factor, compptr->quant_tbl_no);
  152875. }
  152876. cinfo->marker->saw_SOF = TRUE;
  152877. INPUT_SYNC(cinfo);
  152878. return TRUE;
  152879. }
  152880. LOCAL(boolean)
  152881. get_sos (j_decompress_ptr cinfo)
  152882. {
  152883. INT32 length;
  152884. int i, ci, n, c, cc;
  152885. jpeg_component_info * compptr;
  152886. INPUT_VARS(cinfo);
  152887. if (! cinfo->marker->saw_SOF)
  152888. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  152889. INPUT_2BYTES(cinfo, length, return FALSE);
  152890. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  152891. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  152892. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  152893. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152894. cinfo->comps_in_scan = n;
  152895. for (i = 0; i < n; i++) {
  152896. INPUT_BYTE(cinfo, cc, return FALSE);
  152897. INPUT_BYTE(cinfo, c, return FALSE);
  152898. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152899. ci++, compptr++) {
  152900. if (cc == compptr->component_id)
  152901. goto id_found;
  152902. }
  152903. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  152904. id_found:
  152905. cinfo->cur_comp_info[i] = compptr;
  152906. compptr->dc_tbl_no = (c >> 4) & 15;
  152907. compptr->ac_tbl_no = (c ) & 15;
  152908. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  152909. compptr->dc_tbl_no, compptr->ac_tbl_no);
  152910. }
  152911. INPUT_BYTE(cinfo, c, return FALSE);
  152912. cinfo->Ss = c;
  152913. INPUT_BYTE(cinfo, c, return FALSE);
  152914. cinfo->Se = c;
  152915. INPUT_BYTE(cinfo, c, return FALSE);
  152916. cinfo->Ah = (c >> 4) & 15;
  152917. cinfo->Al = (c ) & 15;
  152918. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  152919. cinfo->Ah, cinfo->Al);
  152920. cinfo->marker->next_restart_num = 0;
  152921. cinfo->input_scan_number++;
  152922. INPUT_SYNC(cinfo);
  152923. return TRUE;
  152924. }
  152925. #ifdef D_ARITH_CODING_SUPPORTED
  152926. LOCAL(boolean)
  152927. get_dac (j_decompress_ptr cinfo)
  152928. {
  152929. INT32 length;
  152930. int index, val;
  152931. INPUT_VARS(cinfo);
  152932. INPUT_2BYTES(cinfo, length, return FALSE);
  152933. length -= 2;
  152934. while (length > 0) {
  152935. INPUT_BYTE(cinfo, index, return FALSE);
  152936. INPUT_BYTE(cinfo, val, return FALSE);
  152937. length -= 2;
  152938. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  152939. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  152940. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  152941. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  152942. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  152943. } else { /* define DC table */
  152944. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  152945. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  152946. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  152947. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  152948. }
  152949. }
  152950. if (length != 0)
  152951. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152952. INPUT_SYNC(cinfo);
  152953. return TRUE;
  152954. }
  152955. #else /* ! D_ARITH_CODING_SUPPORTED */
  152956. #define get_dac(cinfo) skip_variable(cinfo)
  152957. #endif /* D_ARITH_CODING_SUPPORTED */
  152958. LOCAL(boolean)
  152959. get_dht (j_decompress_ptr cinfo)
  152960. {
  152961. INT32 length;
  152962. UINT8 bits[17];
  152963. UINT8 huffval[256];
  152964. int i, index, count;
  152965. JHUFF_TBL **htblptr;
  152966. INPUT_VARS(cinfo);
  152967. INPUT_2BYTES(cinfo, length, return FALSE);
  152968. length -= 2;
  152969. while (length > 16) {
  152970. INPUT_BYTE(cinfo, index, return FALSE);
  152971. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  152972. bits[0] = 0;
  152973. count = 0;
  152974. for (i = 1; i <= 16; i++) {
  152975. INPUT_BYTE(cinfo, bits[i], return FALSE);
  152976. count += bits[i];
  152977. }
  152978. length -= 1 + 16;
  152979. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152980. bits[1], bits[2], bits[3], bits[4],
  152981. bits[5], bits[6], bits[7], bits[8]);
  152982. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152983. bits[9], bits[10], bits[11], bits[12],
  152984. bits[13], bits[14], bits[15], bits[16]);
  152985. if (count > 256 || ((INT32) count) > length)
  152986. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152987. for (i = 0; i < count; i++)
  152988. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  152989. length -= count;
  152990. if (index & 0x10) { /* AC table definition */
  152991. index -= 0x10;
  152992. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  152993. } else { /* DC table definition */
  152994. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  152995. }
  152996. if (index < 0 || index >= NUM_HUFF_TBLS)
  152997. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  152998. if (*htblptr == NULL)
  152999. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  153000. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  153001. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  153002. }
  153003. if (length != 0)
  153004. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153005. INPUT_SYNC(cinfo);
  153006. return TRUE;
  153007. }
  153008. LOCAL(boolean)
  153009. get_dqt (j_decompress_ptr cinfo)
  153010. {
  153011. INT32 length;
  153012. int n, i, prec;
  153013. unsigned int tmp;
  153014. JQUANT_TBL *quant_ptr;
  153015. INPUT_VARS(cinfo);
  153016. INPUT_2BYTES(cinfo, length, return FALSE);
  153017. length -= 2;
  153018. while (length > 0) {
  153019. INPUT_BYTE(cinfo, n, return FALSE);
  153020. prec = n >> 4;
  153021. n &= 0x0F;
  153022. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  153023. if (n >= NUM_QUANT_TBLS)
  153024. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  153025. if (cinfo->quant_tbl_ptrs[n] == NULL)
  153026. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  153027. quant_ptr = cinfo->quant_tbl_ptrs[n];
  153028. for (i = 0; i < DCTSIZE2; i++) {
  153029. if (prec)
  153030. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153031. else
  153032. INPUT_BYTE(cinfo, tmp, return FALSE);
  153033. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  153034. }
  153035. if (cinfo->err->trace_level >= 2) {
  153036. for (i = 0; i < DCTSIZE2; i += 8) {
  153037. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  153038. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  153039. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  153040. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  153041. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  153042. }
  153043. }
  153044. length -= DCTSIZE2+1;
  153045. if (prec) length -= DCTSIZE2;
  153046. }
  153047. if (length != 0)
  153048. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153049. INPUT_SYNC(cinfo);
  153050. return TRUE;
  153051. }
  153052. LOCAL(boolean)
  153053. get_dri (j_decompress_ptr cinfo)
  153054. {
  153055. INT32 length;
  153056. unsigned int tmp;
  153057. INPUT_VARS(cinfo);
  153058. INPUT_2BYTES(cinfo, length, return FALSE);
  153059. if (length != 4)
  153060. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153061. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153062. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  153063. cinfo->restart_interval = tmp;
  153064. INPUT_SYNC(cinfo);
  153065. return TRUE;
  153066. }
  153067. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  153068. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  153069. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  153070. LOCAL(void)
  153071. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153072. unsigned int datalen, INT32 remaining)
  153073. {
  153074. INT32 totallen = (INT32) datalen + remaining;
  153075. if (datalen >= APP0_DATA_LEN &&
  153076. GETJOCTET(data[0]) == 0x4A &&
  153077. GETJOCTET(data[1]) == 0x46 &&
  153078. GETJOCTET(data[2]) == 0x49 &&
  153079. GETJOCTET(data[3]) == 0x46 &&
  153080. GETJOCTET(data[4]) == 0) {
  153081. cinfo->saw_JFIF_marker = TRUE;
  153082. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  153083. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  153084. cinfo->density_unit = GETJOCTET(data[7]);
  153085. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  153086. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  153087. if (cinfo->JFIF_major_version != 1)
  153088. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  153089. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  153090. TRACEMS5(cinfo, 1, JTRC_JFIF,
  153091. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  153092. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  153093. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  153094. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  153095. GETJOCTET(data[12]), GETJOCTET(data[13]));
  153096. totallen -= APP0_DATA_LEN;
  153097. if (totallen !=
  153098. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  153099. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  153100. } else if (datalen >= 6 &&
  153101. GETJOCTET(data[0]) == 0x4A &&
  153102. GETJOCTET(data[1]) == 0x46 &&
  153103. GETJOCTET(data[2]) == 0x58 &&
  153104. GETJOCTET(data[3]) == 0x58 &&
  153105. GETJOCTET(data[4]) == 0) {
  153106. switch (GETJOCTET(data[5])) {
  153107. case 0x10:
  153108. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  153109. break;
  153110. case 0x11:
  153111. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  153112. break;
  153113. case 0x13:
  153114. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  153115. break;
  153116. default:
  153117. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  153118. GETJOCTET(data[5]), (int) totallen);
  153119. break;
  153120. }
  153121. } else {
  153122. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  153123. }
  153124. }
  153125. LOCAL(void)
  153126. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153127. unsigned int datalen, INT32 remaining)
  153128. {
  153129. unsigned int version, flags0, flags1, transform;
  153130. if (datalen >= APP14_DATA_LEN &&
  153131. GETJOCTET(data[0]) == 0x41 &&
  153132. GETJOCTET(data[1]) == 0x64 &&
  153133. GETJOCTET(data[2]) == 0x6F &&
  153134. GETJOCTET(data[3]) == 0x62 &&
  153135. GETJOCTET(data[4]) == 0x65) {
  153136. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  153137. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  153138. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  153139. transform = GETJOCTET(data[11]);
  153140. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  153141. cinfo->saw_Adobe_marker = TRUE;
  153142. cinfo->Adobe_transform = (UINT8) transform;
  153143. } else {
  153144. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  153145. }
  153146. }
  153147. METHODDEF(boolean)
  153148. get_interesting_appn (j_decompress_ptr cinfo)
  153149. {
  153150. INT32 length;
  153151. JOCTET b[APPN_DATA_LEN];
  153152. unsigned int i, numtoread;
  153153. INPUT_VARS(cinfo);
  153154. INPUT_2BYTES(cinfo, length, return FALSE);
  153155. length -= 2;
  153156. if (length >= APPN_DATA_LEN)
  153157. numtoread = APPN_DATA_LEN;
  153158. else if (length > 0)
  153159. numtoread = (unsigned int) length;
  153160. else
  153161. numtoread = 0;
  153162. for (i = 0; i < numtoread; i++)
  153163. INPUT_BYTE(cinfo, b[i], return FALSE);
  153164. length -= numtoread;
  153165. switch (cinfo->unread_marker) {
  153166. case M_APP0:
  153167. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  153168. break;
  153169. case M_APP14:
  153170. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  153171. break;
  153172. default:
  153173. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153174. break;
  153175. }
  153176. INPUT_SYNC(cinfo);
  153177. if (length > 0)
  153178. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153179. return TRUE;
  153180. }
  153181. #ifdef SAVE_MARKERS_SUPPORTED
  153182. METHODDEF(boolean)
  153183. save_marker (j_decompress_ptr cinfo)
  153184. {
  153185. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153186. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  153187. unsigned int bytes_read, data_length;
  153188. JOCTET FAR * data;
  153189. INT32 length = 0;
  153190. INPUT_VARS(cinfo);
  153191. if (cur_marker == NULL) {
  153192. INPUT_2BYTES(cinfo, length, return FALSE);
  153193. length -= 2;
  153194. if (length >= 0) { /* watch out for bogus length word */
  153195. unsigned int limit;
  153196. if (cinfo->unread_marker == (int) M_COM)
  153197. limit = marker->length_limit_COM;
  153198. else
  153199. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  153200. if ((unsigned int) length < limit)
  153201. limit = (unsigned int) length;
  153202. cur_marker = (jpeg_saved_marker_ptr)
  153203. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153204. SIZEOF(struct jpeg_marker_struct) + limit);
  153205. cur_marker->next = NULL;
  153206. cur_marker->marker = (UINT8) cinfo->unread_marker;
  153207. cur_marker->original_length = (unsigned int) length;
  153208. cur_marker->data_length = limit;
  153209. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  153210. marker->cur_marker = cur_marker;
  153211. marker->bytes_read = 0;
  153212. bytes_read = 0;
  153213. data_length = limit;
  153214. } else {
  153215. bytes_read = data_length = 0;
  153216. data = NULL;
  153217. }
  153218. } else {
  153219. bytes_read = marker->bytes_read;
  153220. data_length = cur_marker->data_length;
  153221. data = cur_marker->data + bytes_read;
  153222. }
  153223. while (bytes_read < data_length) {
  153224. INPUT_SYNC(cinfo); /* move the restart point to here */
  153225. marker->bytes_read = bytes_read;
  153226. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  153227. while (bytes_read < data_length && bytes_in_buffer > 0) {
  153228. *data++ = *next_input_byte++;
  153229. bytes_in_buffer--;
  153230. bytes_read++;
  153231. }
  153232. }
  153233. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  153234. if (cinfo->marker_list == NULL) {
  153235. cinfo->marker_list = cur_marker;
  153236. } else {
  153237. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  153238. while (prev->next != NULL)
  153239. prev = prev->next;
  153240. prev->next = cur_marker;
  153241. }
  153242. data = cur_marker->data;
  153243. length = cur_marker->original_length - data_length;
  153244. }
  153245. marker->cur_marker = NULL;
  153246. switch (cinfo->unread_marker) {
  153247. case M_APP0:
  153248. examine_app0(cinfo, data, data_length, length);
  153249. break;
  153250. case M_APP14:
  153251. examine_app14(cinfo, data, data_length, length);
  153252. break;
  153253. default:
  153254. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  153255. (int) (data_length + length));
  153256. break;
  153257. }
  153258. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153259. if (length > 0)
  153260. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153261. return TRUE;
  153262. }
  153263. #endif /* SAVE_MARKERS_SUPPORTED */
  153264. METHODDEF(boolean)
  153265. skip_variable (j_decompress_ptr cinfo)
  153266. {
  153267. INT32 length;
  153268. INPUT_VARS(cinfo);
  153269. INPUT_2BYTES(cinfo, length, return FALSE);
  153270. length -= 2;
  153271. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  153272. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153273. if (length > 0)
  153274. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153275. return TRUE;
  153276. }
  153277. LOCAL(boolean)
  153278. next_marker (j_decompress_ptr cinfo)
  153279. {
  153280. int c;
  153281. INPUT_VARS(cinfo);
  153282. for (;;) {
  153283. INPUT_BYTE(cinfo, c, return FALSE);
  153284. while (c != 0xFF) {
  153285. cinfo->marker->discarded_bytes++;
  153286. INPUT_SYNC(cinfo);
  153287. INPUT_BYTE(cinfo, c, return FALSE);
  153288. }
  153289. do {
  153290. INPUT_BYTE(cinfo, c, return FALSE);
  153291. } while (c == 0xFF);
  153292. if (c != 0)
  153293. break; /* found a valid marker, exit loop */
  153294. cinfo->marker->discarded_bytes += 2;
  153295. INPUT_SYNC(cinfo);
  153296. }
  153297. if (cinfo->marker->discarded_bytes != 0) {
  153298. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153299. cinfo->marker->discarded_bytes = 0;
  153300. }
  153301. cinfo->unread_marker = c;
  153302. INPUT_SYNC(cinfo);
  153303. return TRUE;
  153304. }
  153305. LOCAL(boolean)
  153306. first_marker (j_decompress_ptr cinfo)
  153307. {
  153308. int c, c2;
  153309. INPUT_VARS(cinfo);
  153310. INPUT_BYTE(cinfo, c, return FALSE);
  153311. INPUT_BYTE(cinfo, c2, return FALSE);
  153312. if (c != 0xFF || c2 != (int) M_SOI)
  153313. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153314. cinfo->unread_marker = c2;
  153315. INPUT_SYNC(cinfo);
  153316. return TRUE;
  153317. }
  153318. METHODDEF(int)
  153319. read_markers (j_decompress_ptr cinfo)
  153320. {
  153321. for (;;) {
  153322. if (cinfo->unread_marker == 0) {
  153323. if (! cinfo->marker->saw_SOI) {
  153324. if (! first_marker(cinfo))
  153325. return JPEG_SUSPENDED;
  153326. } else {
  153327. if (! next_marker(cinfo))
  153328. return JPEG_SUSPENDED;
  153329. }
  153330. }
  153331. switch (cinfo->unread_marker) {
  153332. case M_SOI:
  153333. if (! get_soi(cinfo))
  153334. return JPEG_SUSPENDED;
  153335. break;
  153336. case M_SOF0: /* Baseline */
  153337. case M_SOF1: /* Extended sequential, Huffman */
  153338. if (! get_sof(cinfo, FALSE, FALSE))
  153339. return JPEG_SUSPENDED;
  153340. break;
  153341. case M_SOF2: /* Progressive, Huffman */
  153342. if (! get_sof(cinfo, TRUE, FALSE))
  153343. return JPEG_SUSPENDED;
  153344. break;
  153345. case M_SOF9: /* Extended sequential, arithmetic */
  153346. if (! get_sof(cinfo, FALSE, TRUE))
  153347. return JPEG_SUSPENDED;
  153348. break;
  153349. case M_SOF10: /* Progressive, arithmetic */
  153350. if (! get_sof(cinfo, TRUE, TRUE))
  153351. return JPEG_SUSPENDED;
  153352. break;
  153353. case M_SOF3: /* Lossless, Huffman */
  153354. case M_SOF5: /* Differential sequential, Huffman */
  153355. case M_SOF6: /* Differential progressive, Huffman */
  153356. case M_SOF7: /* Differential lossless, Huffman */
  153357. case M_JPG: /* Reserved for JPEG extensions */
  153358. case M_SOF11: /* Lossless, arithmetic */
  153359. case M_SOF13: /* Differential sequential, arithmetic */
  153360. case M_SOF14: /* Differential progressive, arithmetic */
  153361. case M_SOF15: /* Differential lossless, arithmetic */
  153362. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153363. break;
  153364. case M_SOS:
  153365. if (! get_sos(cinfo))
  153366. return JPEG_SUSPENDED;
  153367. cinfo->unread_marker = 0; /* processed the marker */
  153368. return JPEG_REACHED_SOS;
  153369. case M_EOI:
  153370. TRACEMS(cinfo, 1, JTRC_EOI);
  153371. cinfo->unread_marker = 0; /* processed the marker */
  153372. return JPEG_REACHED_EOI;
  153373. case M_DAC:
  153374. if (! get_dac(cinfo))
  153375. return JPEG_SUSPENDED;
  153376. break;
  153377. case M_DHT:
  153378. if (! get_dht(cinfo))
  153379. return JPEG_SUSPENDED;
  153380. break;
  153381. case M_DQT:
  153382. if (! get_dqt(cinfo))
  153383. return JPEG_SUSPENDED;
  153384. break;
  153385. case M_DRI:
  153386. if (! get_dri(cinfo))
  153387. return JPEG_SUSPENDED;
  153388. break;
  153389. case M_APP0:
  153390. case M_APP1:
  153391. case M_APP2:
  153392. case M_APP3:
  153393. case M_APP4:
  153394. case M_APP5:
  153395. case M_APP6:
  153396. case M_APP7:
  153397. case M_APP8:
  153398. case M_APP9:
  153399. case M_APP10:
  153400. case M_APP11:
  153401. case M_APP12:
  153402. case M_APP13:
  153403. case M_APP14:
  153404. case M_APP15:
  153405. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153406. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153407. return JPEG_SUSPENDED;
  153408. break;
  153409. case M_COM:
  153410. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153411. return JPEG_SUSPENDED;
  153412. break;
  153413. case M_RST0: /* these are all parameterless */
  153414. case M_RST1:
  153415. case M_RST2:
  153416. case M_RST3:
  153417. case M_RST4:
  153418. case M_RST5:
  153419. case M_RST6:
  153420. case M_RST7:
  153421. case M_TEM:
  153422. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153423. break;
  153424. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153425. if (! skip_variable(cinfo))
  153426. return JPEG_SUSPENDED;
  153427. break;
  153428. default: /* must be DHP, EXP, JPGn, or RESn */
  153429. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153430. break;
  153431. }
  153432. cinfo->unread_marker = 0;
  153433. } /* end loop */
  153434. }
  153435. METHODDEF(boolean)
  153436. read_restart_marker (j_decompress_ptr cinfo)
  153437. {
  153438. if (cinfo->unread_marker == 0) {
  153439. if (! next_marker(cinfo))
  153440. return FALSE;
  153441. }
  153442. if (cinfo->unread_marker ==
  153443. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153444. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153445. cinfo->unread_marker = 0;
  153446. } else {
  153447. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153448. cinfo->marker->next_restart_num))
  153449. return FALSE;
  153450. }
  153451. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153452. return TRUE;
  153453. }
  153454. GLOBAL(boolean)
  153455. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153456. {
  153457. int marker = cinfo->unread_marker;
  153458. int action = 1;
  153459. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153460. for (;;) {
  153461. if (marker < (int) M_SOF0)
  153462. action = 2; /* invalid marker */
  153463. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153464. action = 3; /* valid non-restart marker */
  153465. else {
  153466. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153467. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153468. action = 3; /* one of the next two expected restarts */
  153469. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153470. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153471. action = 2; /* a prior restart, so advance */
  153472. else
  153473. action = 1; /* desired restart or too far away */
  153474. }
  153475. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153476. switch (action) {
  153477. case 1:
  153478. cinfo->unread_marker = 0;
  153479. return TRUE;
  153480. case 2:
  153481. if (! next_marker(cinfo))
  153482. return FALSE;
  153483. marker = cinfo->unread_marker;
  153484. break;
  153485. case 3:
  153486. return TRUE;
  153487. }
  153488. } /* end loop */
  153489. }
  153490. METHODDEF(void)
  153491. reset_marker_reader (j_decompress_ptr cinfo)
  153492. {
  153493. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153494. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153495. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153496. cinfo->unread_marker = 0; /* no pending marker */
  153497. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153498. marker->pub.saw_SOF = FALSE;
  153499. marker->pub.discarded_bytes = 0;
  153500. marker->cur_marker = NULL;
  153501. }
  153502. GLOBAL(void)
  153503. jinit_marker_reader (j_decompress_ptr cinfo)
  153504. {
  153505. my_marker_ptr2 marker;
  153506. int i;
  153507. marker = (my_marker_ptr2)
  153508. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153509. SIZEOF(my_marker_reader));
  153510. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153511. marker->pub.reset_marker_reader = reset_marker_reader;
  153512. marker->pub.read_markers = read_markers;
  153513. marker->pub.read_restart_marker = read_restart_marker;
  153514. marker->process_COM = skip_variable;
  153515. marker->length_limit_COM = 0;
  153516. for (i = 0; i < 16; i++) {
  153517. marker->process_APPn[i] = skip_variable;
  153518. marker->length_limit_APPn[i] = 0;
  153519. }
  153520. marker->process_APPn[0] = get_interesting_appn;
  153521. marker->process_APPn[14] = get_interesting_appn;
  153522. reset_marker_reader(cinfo);
  153523. }
  153524. #ifdef SAVE_MARKERS_SUPPORTED
  153525. GLOBAL(void)
  153526. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153527. unsigned int length_limit)
  153528. {
  153529. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153530. long maxlength;
  153531. jpeg_marker_parser_method processor;
  153532. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153533. if (((long) length_limit) > maxlength)
  153534. length_limit = (unsigned int) maxlength;
  153535. if (length_limit) {
  153536. processor = save_marker;
  153537. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153538. length_limit = APP0_DATA_LEN;
  153539. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153540. length_limit = APP14_DATA_LEN;
  153541. } else {
  153542. processor = skip_variable;
  153543. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153544. processor = get_interesting_appn;
  153545. }
  153546. if (marker_code == (int) M_COM) {
  153547. marker->process_COM = processor;
  153548. marker->length_limit_COM = length_limit;
  153549. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153550. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153551. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153552. } else
  153553. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153554. }
  153555. #endif /* SAVE_MARKERS_SUPPORTED */
  153556. GLOBAL(void)
  153557. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153558. jpeg_marker_parser_method routine)
  153559. {
  153560. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153561. if (marker_code == (int) M_COM)
  153562. marker->process_COM = routine;
  153563. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153564. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153565. else
  153566. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153567. }
  153568. /*** End of inlined file: jdmarker.c ***/
  153569. /*** Start of inlined file: jdmaster.c ***/
  153570. #define JPEG_INTERNALS
  153571. typedef struct {
  153572. struct jpeg_decomp_master pub; /* public fields */
  153573. int pass_number; /* # of passes completed */
  153574. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153575. struct jpeg_color_quantizer * quantizer_1pass;
  153576. struct jpeg_color_quantizer * quantizer_2pass;
  153577. } my_decomp_master;
  153578. typedef my_decomp_master * my_master_ptr6;
  153579. LOCAL(boolean)
  153580. use_merged_upsample (j_decompress_ptr cinfo)
  153581. {
  153582. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153583. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153584. return FALSE;
  153585. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153586. cinfo->out_color_space != JCS_RGB ||
  153587. cinfo->out_color_components != RGB_PIXELSIZE)
  153588. return FALSE;
  153589. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153590. cinfo->comp_info[1].h_samp_factor != 1 ||
  153591. cinfo->comp_info[2].h_samp_factor != 1 ||
  153592. cinfo->comp_info[0].v_samp_factor > 2 ||
  153593. cinfo->comp_info[1].v_samp_factor != 1 ||
  153594. cinfo->comp_info[2].v_samp_factor != 1)
  153595. return FALSE;
  153596. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153597. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153598. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153599. return FALSE;
  153600. return TRUE; /* by golly, it'll work... */
  153601. #else
  153602. return FALSE;
  153603. #endif
  153604. }
  153605. GLOBAL(void)
  153606. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153607. {
  153608. #ifdef IDCT_SCALING_SUPPORTED
  153609. int ci;
  153610. jpeg_component_info *compptr;
  153611. #endif
  153612. if (cinfo->global_state != DSTATE_READY)
  153613. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153614. #ifdef IDCT_SCALING_SUPPORTED
  153615. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153616. cinfo->output_width = (JDIMENSION)
  153617. jdiv_round_up((long) cinfo->image_width, 8L);
  153618. cinfo->output_height = (JDIMENSION)
  153619. jdiv_round_up((long) cinfo->image_height, 8L);
  153620. cinfo->min_DCT_scaled_size = 1;
  153621. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153622. cinfo->output_width = (JDIMENSION)
  153623. jdiv_round_up((long) cinfo->image_width, 4L);
  153624. cinfo->output_height = (JDIMENSION)
  153625. jdiv_round_up((long) cinfo->image_height, 4L);
  153626. cinfo->min_DCT_scaled_size = 2;
  153627. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153628. cinfo->output_width = (JDIMENSION)
  153629. jdiv_round_up((long) cinfo->image_width, 2L);
  153630. cinfo->output_height = (JDIMENSION)
  153631. jdiv_round_up((long) cinfo->image_height, 2L);
  153632. cinfo->min_DCT_scaled_size = 4;
  153633. } else {
  153634. cinfo->output_width = cinfo->image_width;
  153635. cinfo->output_height = cinfo->image_height;
  153636. cinfo->min_DCT_scaled_size = DCTSIZE;
  153637. }
  153638. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153639. ci++, compptr++) {
  153640. int ssize = cinfo->min_DCT_scaled_size;
  153641. while (ssize < DCTSIZE &&
  153642. (compptr->h_samp_factor * ssize * 2 <=
  153643. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153644. (compptr->v_samp_factor * ssize * 2 <=
  153645. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153646. ssize = ssize * 2;
  153647. }
  153648. compptr->DCT_scaled_size = ssize;
  153649. }
  153650. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153651. ci++, compptr++) {
  153652. compptr->downsampled_width = (JDIMENSION)
  153653. jdiv_round_up((long) cinfo->image_width *
  153654. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153655. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153656. compptr->downsampled_height = (JDIMENSION)
  153657. jdiv_round_up((long) cinfo->image_height *
  153658. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153659. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153660. }
  153661. #else /* !IDCT_SCALING_SUPPORTED */
  153662. cinfo->output_width = cinfo->image_width;
  153663. cinfo->output_height = cinfo->image_height;
  153664. #endif /* IDCT_SCALING_SUPPORTED */
  153665. switch (cinfo->out_color_space) {
  153666. case JCS_GRAYSCALE:
  153667. cinfo->out_color_components = 1;
  153668. break;
  153669. case JCS_RGB:
  153670. #if RGB_PIXELSIZE != 3
  153671. cinfo->out_color_components = RGB_PIXELSIZE;
  153672. break;
  153673. #endif /* else share code with YCbCr */
  153674. case JCS_YCbCr:
  153675. cinfo->out_color_components = 3;
  153676. break;
  153677. case JCS_CMYK:
  153678. case JCS_YCCK:
  153679. cinfo->out_color_components = 4;
  153680. break;
  153681. default: /* else must be same colorspace as in file */
  153682. cinfo->out_color_components = cinfo->num_components;
  153683. break;
  153684. }
  153685. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  153686. cinfo->out_color_components);
  153687. if (use_merged_upsample(cinfo))
  153688. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  153689. else
  153690. cinfo->rec_outbuf_height = 1;
  153691. }
  153692. LOCAL(void)
  153693. prepare_range_limit_table (j_decompress_ptr cinfo)
  153694. {
  153695. JSAMPLE * table;
  153696. int i;
  153697. table = (JSAMPLE *)
  153698. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153699. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153700. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  153701. cinfo->sample_range_limit = table;
  153702. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  153703. for (i = 0; i <= MAXJSAMPLE; i++)
  153704. table[i] = (JSAMPLE) i;
  153705. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  153706. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  153707. table[i] = MAXJSAMPLE;
  153708. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  153709. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153710. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  153711. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  153712. }
  153713. LOCAL(void)
  153714. master_selection (j_decompress_ptr cinfo)
  153715. {
  153716. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153717. boolean use_c_buffer;
  153718. long samplesperrow;
  153719. JDIMENSION jd_samplesperrow;
  153720. jpeg_calc_output_dimensions(cinfo);
  153721. prepare_range_limit_table(cinfo);
  153722. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  153723. jd_samplesperrow = (JDIMENSION) samplesperrow;
  153724. if ((long) jd_samplesperrow != samplesperrow)
  153725. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  153726. master->pass_number = 0;
  153727. master->using_merged_upsample = use_merged_upsample(cinfo);
  153728. master->quantizer_1pass = NULL;
  153729. master->quantizer_2pass = NULL;
  153730. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  153731. cinfo->enable_1pass_quant = FALSE;
  153732. cinfo->enable_external_quant = FALSE;
  153733. cinfo->enable_2pass_quant = FALSE;
  153734. }
  153735. if (cinfo->quantize_colors) {
  153736. if (cinfo->raw_data_out)
  153737. ERREXIT(cinfo, JERR_NOTIMPL);
  153738. if (cinfo->out_color_components != 3) {
  153739. cinfo->enable_1pass_quant = TRUE;
  153740. cinfo->enable_external_quant = FALSE;
  153741. cinfo->enable_2pass_quant = FALSE;
  153742. cinfo->colormap = NULL;
  153743. } else if (cinfo->colormap != NULL) {
  153744. cinfo->enable_external_quant = TRUE;
  153745. } else if (cinfo->two_pass_quantize) {
  153746. cinfo->enable_2pass_quant = TRUE;
  153747. } else {
  153748. cinfo->enable_1pass_quant = TRUE;
  153749. }
  153750. if (cinfo->enable_1pass_quant) {
  153751. #ifdef QUANT_1PASS_SUPPORTED
  153752. jinit_1pass_quantizer(cinfo);
  153753. master->quantizer_1pass = cinfo->cquantize;
  153754. #else
  153755. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153756. #endif
  153757. }
  153758. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  153759. #ifdef QUANT_2PASS_SUPPORTED
  153760. jinit_2pass_quantizer(cinfo);
  153761. master->quantizer_2pass = cinfo->cquantize;
  153762. #else
  153763. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153764. #endif
  153765. }
  153766. }
  153767. if (! cinfo->raw_data_out) {
  153768. if (master->using_merged_upsample) {
  153769. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153770. jinit_merged_upsampler(cinfo); /* does color conversion too */
  153771. #else
  153772. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153773. #endif
  153774. } else {
  153775. jinit_color_deconverter(cinfo);
  153776. jinit_upsampler(cinfo);
  153777. }
  153778. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  153779. }
  153780. jinit_inverse_dct(cinfo);
  153781. if (cinfo->arith_code) {
  153782. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  153783. } else {
  153784. if (cinfo->progressive_mode) {
  153785. #ifdef D_PROGRESSIVE_SUPPORTED
  153786. jinit_phuff_decoder(cinfo);
  153787. #else
  153788. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153789. #endif
  153790. } else
  153791. jinit_huff_decoder(cinfo);
  153792. }
  153793. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  153794. jinit_d_coef_controller(cinfo, use_c_buffer);
  153795. if (! cinfo->raw_data_out)
  153796. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  153797. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  153798. (*cinfo->inputctl->start_input_pass) (cinfo);
  153799. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153800. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  153801. cinfo->inputctl->has_multiple_scans) {
  153802. int nscans;
  153803. if (cinfo->progressive_mode) {
  153804. nscans = 2 + 3 * cinfo->num_components;
  153805. } else {
  153806. nscans = cinfo->num_components;
  153807. }
  153808. cinfo->progress->pass_counter = 0L;
  153809. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  153810. cinfo->progress->completed_passes = 0;
  153811. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  153812. master->pass_number++;
  153813. }
  153814. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153815. }
  153816. METHODDEF(void)
  153817. prepare_for_output_pass (j_decompress_ptr cinfo)
  153818. {
  153819. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153820. if (master->pub.is_dummy_pass) {
  153821. #ifdef QUANT_2PASS_SUPPORTED
  153822. master->pub.is_dummy_pass = FALSE;
  153823. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  153824. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  153825. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  153826. #else
  153827. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153828. #endif /* QUANT_2PASS_SUPPORTED */
  153829. } else {
  153830. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  153831. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  153832. cinfo->cquantize = master->quantizer_2pass;
  153833. master->pub.is_dummy_pass = TRUE;
  153834. } else if (cinfo->enable_1pass_quant) {
  153835. cinfo->cquantize = master->quantizer_1pass;
  153836. } else {
  153837. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153838. }
  153839. }
  153840. (*cinfo->idct->start_pass) (cinfo);
  153841. (*cinfo->coef->start_output_pass) (cinfo);
  153842. if (! cinfo->raw_data_out) {
  153843. if (! master->using_merged_upsample)
  153844. (*cinfo->cconvert->start_pass) (cinfo);
  153845. (*cinfo->upsample->start_pass) (cinfo);
  153846. if (cinfo->quantize_colors)
  153847. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  153848. (*cinfo->post->start_pass) (cinfo,
  153849. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  153850. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  153851. }
  153852. }
  153853. if (cinfo->progress != NULL) {
  153854. cinfo->progress->completed_passes = master->pass_number;
  153855. cinfo->progress->total_passes = master->pass_number +
  153856. (master->pub.is_dummy_pass ? 2 : 1);
  153857. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  153858. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  153859. }
  153860. }
  153861. }
  153862. METHODDEF(void)
  153863. finish_output_pass (j_decompress_ptr cinfo)
  153864. {
  153865. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153866. if (cinfo->quantize_colors)
  153867. (*cinfo->cquantize->finish_pass) (cinfo);
  153868. master->pass_number++;
  153869. }
  153870. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153871. GLOBAL(void)
  153872. jpeg_new_colormap (j_decompress_ptr cinfo)
  153873. {
  153874. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153875. if (cinfo->global_state != DSTATE_BUFIMAGE)
  153876. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153877. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  153878. cinfo->colormap != NULL) {
  153879. cinfo->cquantize = master->quantizer_2pass;
  153880. (*cinfo->cquantize->new_color_map) (cinfo);
  153881. master->pub.is_dummy_pass = FALSE; /* just in case */
  153882. } else
  153883. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153884. }
  153885. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153886. GLOBAL(void)
  153887. jinit_master_decompress (j_decompress_ptr cinfo)
  153888. {
  153889. my_master_ptr6 master;
  153890. master = (my_master_ptr6)
  153891. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153892. SIZEOF(my_decomp_master));
  153893. cinfo->master = (struct jpeg_decomp_master *) master;
  153894. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  153895. master->pub.finish_output_pass = finish_output_pass;
  153896. master->pub.is_dummy_pass = FALSE;
  153897. master_selection(cinfo);
  153898. }
  153899. /*** End of inlined file: jdmaster.c ***/
  153900. #undef FIX
  153901. /*** Start of inlined file: jdmerge.c ***/
  153902. #define JPEG_INTERNALS
  153903. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153904. typedef struct {
  153905. struct jpeg_upsampler pub; /* public fields */
  153906. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  153907. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153908. JSAMPARRAY output_buf));
  153909. int * Cr_r_tab; /* => table for Cr to R conversion */
  153910. int * Cb_b_tab; /* => table for Cb to B conversion */
  153911. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  153912. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  153913. JSAMPROW spare_row;
  153914. boolean spare_full; /* T if spare buffer is occupied */
  153915. JDIMENSION out_row_width; /* samples per output row */
  153916. JDIMENSION rows_to_go; /* counts rows remaining in image */
  153917. } my_upsampler;
  153918. typedef my_upsampler * my_upsample_ptr;
  153919. #define SCALEBITS 16 /* speediest right-shift on some machines */
  153920. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  153921. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  153922. LOCAL(void)
  153923. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  153924. {
  153925. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153926. int i;
  153927. INT32 x;
  153928. SHIFT_TEMPS
  153929. upsample->Cr_r_tab = (int *)
  153930. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153931. (MAXJSAMPLE+1) * SIZEOF(int));
  153932. upsample->Cb_b_tab = (int *)
  153933. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153934. (MAXJSAMPLE+1) * SIZEOF(int));
  153935. upsample->Cr_g_tab = (INT32 *)
  153936. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153937. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153938. upsample->Cb_g_tab = (INT32 *)
  153939. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153940. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153941. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  153942. upsample->Cr_r_tab[i] = (int)
  153943. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  153944. upsample->Cb_b_tab[i] = (int)
  153945. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  153946. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  153947. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  153948. }
  153949. }
  153950. METHODDEF(void)
  153951. start_pass_merged_upsample (j_decompress_ptr cinfo)
  153952. {
  153953. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153954. upsample->spare_full = FALSE;
  153955. upsample->rows_to_go = cinfo->output_height;
  153956. }
  153957. METHODDEF(void)
  153958. merged_2v_upsample (j_decompress_ptr cinfo,
  153959. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153960. JDIMENSION in_row_groups_avail,
  153961. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153962. JDIMENSION out_rows_avail)
  153963. {
  153964. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153965. JSAMPROW work_ptrs[2];
  153966. JDIMENSION num_rows; /* number of rows returned to caller */
  153967. if (upsample->spare_full) {
  153968. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  153969. 1, upsample->out_row_width);
  153970. num_rows = 1;
  153971. upsample->spare_full = FALSE;
  153972. } else {
  153973. num_rows = 2;
  153974. if (num_rows > upsample->rows_to_go)
  153975. num_rows = upsample->rows_to_go;
  153976. out_rows_avail -= *out_row_ctr;
  153977. if (num_rows > out_rows_avail)
  153978. num_rows = out_rows_avail;
  153979. work_ptrs[0] = output_buf[*out_row_ctr];
  153980. if (num_rows > 1) {
  153981. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  153982. } else {
  153983. work_ptrs[1] = upsample->spare_row;
  153984. upsample->spare_full = TRUE;
  153985. }
  153986. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  153987. }
  153988. *out_row_ctr += num_rows;
  153989. upsample->rows_to_go -= num_rows;
  153990. if (! upsample->spare_full)
  153991. (*in_row_group_ctr)++;
  153992. }
  153993. METHODDEF(void)
  153994. merged_1v_upsample (j_decompress_ptr cinfo,
  153995. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153996. JDIMENSION in_row_groups_avail,
  153997. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153998. JDIMENSION out_rows_avail)
  153999. {
  154000. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154001. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  154002. output_buf + *out_row_ctr);
  154003. (*out_row_ctr)++;
  154004. (*in_row_group_ctr)++;
  154005. }
  154006. METHODDEF(void)
  154007. h2v1_merged_upsample (j_decompress_ptr cinfo,
  154008. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154009. JSAMPARRAY output_buf)
  154010. {
  154011. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154012. register int y, cred, cgreen, cblue;
  154013. int cb, cr;
  154014. register JSAMPROW outptr;
  154015. JSAMPROW inptr0, inptr1, inptr2;
  154016. JDIMENSION col;
  154017. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154018. int * Crrtab = upsample->Cr_r_tab;
  154019. int * Cbbtab = upsample->Cb_b_tab;
  154020. INT32 * Crgtab = upsample->Cr_g_tab;
  154021. INT32 * Cbgtab = upsample->Cb_g_tab;
  154022. SHIFT_TEMPS
  154023. inptr0 = input_buf[0][in_row_group_ctr];
  154024. inptr1 = input_buf[1][in_row_group_ctr];
  154025. inptr2 = input_buf[2][in_row_group_ctr];
  154026. outptr = output_buf[0];
  154027. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154028. cb = GETJSAMPLE(*inptr1++);
  154029. cr = GETJSAMPLE(*inptr2++);
  154030. cred = Crrtab[cr];
  154031. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154032. cblue = Cbbtab[cb];
  154033. y = GETJSAMPLE(*inptr0++);
  154034. outptr[RGB_RED] = range_limit[y + cred];
  154035. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154036. outptr[RGB_BLUE] = range_limit[y + cblue];
  154037. outptr += RGB_PIXELSIZE;
  154038. y = GETJSAMPLE(*inptr0++);
  154039. outptr[RGB_RED] = range_limit[y + cred];
  154040. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154041. outptr[RGB_BLUE] = range_limit[y + cblue];
  154042. outptr += RGB_PIXELSIZE;
  154043. }
  154044. if (cinfo->output_width & 1) {
  154045. cb = GETJSAMPLE(*inptr1);
  154046. cr = GETJSAMPLE(*inptr2);
  154047. cred = Crrtab[cr];
  154048. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154049. cblue = Cbbtab[cb];
  154050. y = GETJSAMPLE(*inptr0);
  154051. outptr[RGB_RED] = range_limit[y + cred];
  154052. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154053. outptr[RGB_BLUE] = range_limit[y + cblue];
  154054. }
  154055. }
  154056. METHODDEF(void)
  154057. h2v2_merged_upsample (j_decompress_ptr cinfo,
  154058. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154059. JSAMPARRAY output_buf)
  154060. {
  154061. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154062. register int y, cred, cgreen, cblue;
  154063. int cb, cr;
  154064. register JSAMPROW outptr0, outptr1;
  154065. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  154066. JDIMENSION col;
  154067. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154068. int * Crrtab = upsample->Cr_r_tab;
  154069. int * Cbbtab = upsample->Cb_b_tab;
  154070. INT32 * Crgtab = upsample->Cr_g_tab;
  154071. INT32 * Cbgtab = upsample->Cb_g_tab;
  154072. SHIFT_TEMPS
  154073. inptr00 = input_buf[0][in_row_group_ctr*2];
  154074. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  154075. inptr1 = input_buf[1][in_row_group_ctr];
  154076. inptr2 = input_buf[2][in_row_group_ctr];
  154077. outptr0 = output_buf[0];
  154078. outptr1 = output_buf[1];
  154079. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154080. cb = GETJSAMPLE(*inptr1++);
  154081. cr = GETJSAMPLE(*inptr2++);
  154082. cred = Crrtab[cr];
  154083. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154084. cblue = Cbbtab[cb];
  154085. y = GETJSAMPLE(*inptr00++);
  154086. outptr0[RGB_RED] = range_limit[y + cred];
  154087. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154088. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154089. outptr0 += RGB_PIXELSIZE;
  154090. y = GETJSAMPLE(*inptr00++);
  154091. outptr0[RGB_RED] = range_limit[y + cred];
  154092. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154093. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154094. outptr0 += RGB_PIXELSIZE;
  154095. y = GETJSAMPLE(*inptr01++);
  154096. outptr1[RGB_RED] = range_limit[y + cred];
  154097. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154098. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154099. outptr1 += RGB_PIXELSIZE;
  154100. y = GETJSAMPLE(*inptr01++);
  154101. outptr1[RGB_RED] = range_limit[y + cred];
  154102. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154103. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154104. outptr1 += RGB_PIXELSIZE;
  154105. }
  154106. if (cinfo->output_width & 1) {
  154107. cb = GETJSAMPLE(*inptr1);
  154108. cr = GETJSAMPLE(*inptr2);
  154109. cred = Crrtab[cr];
  154110. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154111. cblue = Cbbtab[cb];
  154112. y = GETJSAMPLE(*inptr00);
  154113. outptr0[RGB_RED] = range_limit[y + cred];
  154114. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154115. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154116. y = GETJSAMPLE(*inptr01);
  154117. outptr1[RGB_RED] = range_limit[y + cred];
  154118. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154119. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154120. }
  154121. }
  154122. GLOBAL(void)
  154123. jinit_merged_upsampler (j_decompress_ptr cinfo)
  154124. {
  154125. my_upsample_ptr upsample;
  154126. upsample = (my_upsample_ptr)
  154127. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154128. SIZEOF(my_upsampler));
  154129. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154130. upsample->pub.start_pass = start_pass_merged_upsample;
  154131. upsample->pub.need_context_rows = FALSE;
  154132. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  154133. if (cinfo->max_v_samp_factor == 2) {
  154134. upsample->pub.upsample = merged_2v_upsample;
  154135. upsample->upmethod = h2v2_merged_upsample;
  154136. upsample->spare_row = (JSAMPROW)
  154137. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154138. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  154139. } else {
  154140. upsample->pub.upsample = merged_1v_upsample;
  154141. upsample->upmethod = h2v1_merged_upsample;
  154142. upsample->spare_row = NULL;
  154143. }
  154144. build_ycc_rgb_table2(cinfo);
  154145. }
  154146. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  154147. /*** End of inlined file: jdmerge.c ***/
  154148. #undef ASSIGN_STATE
  154149. /*** Start of inlined file: jdphuff.c ***/
  154150. #define JPEG_INTERNALS
  154151. #ifdef D_PROGRESSIVE_SUPPORTED
  154152. typedef struct {
  154153. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  154154. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  154155. } savable_state3;
  154156. #ifndef NO_STRUCT_ASSIGN
  154157. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  154158. #else
  154159. #if MAX_COMPS_IN_SCAN == 4
  154160. #define ASSIGN_STATE(dest,src) \
  154161. ((dest).EOBRUN = (src).EOBRUN, \
  154162. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  154163. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  154164. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  154165. (dest).last_dc_val[3] = (src).last_dc_val[3])
  154166. #endif
  154167. #endif
  154168. typedef struct {
  154169. struct jpeg_entropy_decoder pub; /* public fields */
  154170. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  154171. savable_state3 saved; /* Other state at start of MCU */
  154172. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  154173. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  154174. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  154175. } phuff_entropy_decoder;
  154176. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  154177. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  154178. JBLOCKROW *MCU_data));
  154179. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  154180. JBLOCKROW *MCU_data));
  154181. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  154182. JBLOCKROW *MCU_data));
  154183. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  154184. JBLOCKROW *MCU_data));
  154185. METHODDEF(void)
  154186. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  154187. {
  154188. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154189. boolean is_DC_band, bad;
  154190. int ci, coefi, tbl;
  154191. int *coef_bit_ptr;
  154192. jpeg_component_info * compptr;
  154193. is_DC_band = (cinfo->Ss == 0);
  154194. bad = FALSE;
  154195. if (is_DC_band) {
  154196. if (cinfo->Se != 0)
  154197. bad = TRUE;
  154198. } else {
  154199. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  154200. bad = TRUE;
  154201. if (cinfo->comps_in_scan != 1)
  154202. bad = TRUE;
  154203. }
  154204. if (cinfo->Ah != 0) {
  154205. if (cinfo->Al != cinfo->Ah-1)
  154206. bad = TRUE;
  154207. }
  154208. if (cinfo->Al > 13) /* need not check for < 0 */
  154209. bad = TRUE;
  154210. if (bad)
  154211. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  154212. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  154213. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154214. int cindex = cinfo->cur_comp_info[ci]->component_index;
  154215. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  154216. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  154217. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  154218. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  154219. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  154220. if (cinfo->Ah != expected)
  154221. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  154222. coef_bit_ptr[coefi] = cinfo->Al;
  154223. }
  154224. }
  154225. if (cinfo->Ah == 0) {
  154226. if (is_DC_band)
  154227. entropy->pub.decode_mcu = decode_mcu_DC_first;
  154228. else
  154229. entropy->pub.decode_mcu = decode_mcu_AC_first;
  154230. } else {
  154231. if (is_DC_band)
  154232. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  154233. else
  154234. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  154235. }
  154236. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154237. compptr = cinfo->cur_comp_info[ci];
  154238. if (is_DC_band) {
  154239. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  154240. tbl = compptr->dc_tbl_no;
  154241. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  154242. & entropy->derived_tbls[tbl]);
  154243. }
  154244. } else {
  154245. tbl = compptr->ac_tbl_no;
  154246. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  154247. & entropy->derived_tbls[tbl]);
  154248. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  154249. }
  154250. entropy->saved.last_dc_val[ci] = 0;
  154251. }
  154252. entropy->bitstate.bits_left = 0;
  154253. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  154254. entropy->pub.insufficient_data = FALSE;
  154255. entropy->saved.EOBRUN = 0;
  154256. entropy->restarts_to_go = cinfo->restart_interval;
  154257. }
  154258. LOCAL(boolean)
  154259. process_restartp (j_decompress_ptr cinfo)
  154260. {
  154261. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154262. int ci;
  154263. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  154264. entropy->bitstate.bits_left = 0;
  154265. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  154266. return FALSE;
  154267. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  154268. entropy->saved.last_dc_val[ci] = 0;
  154269. entropy->saved.EOBRUN = 0;
  154270. entropy->restarts_to_go = cinfo->restart_interval;
  154271. if (cinfo->unread_marker == 0)
  154272. entropy->pub.insufficient_data = FALSE;
  154273. return TRUE;
  154274. }
  154275. METHODDEF(boolean)
  154276. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154277. {
  154278. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154279. int Al = cinfo->Al;
  154280. register int s, r;
  154281. int blkn, ci;
  154282. JBLOCKROW block;
  154283. BITREAD_STATE_VARS;
  154284. savable_state3 state;
  154285. d_derived_tbl * tbl;
  154286. jpeg_component_info * compptr;
  154287. if (cinfo->restart_interval) {
  154288. if (entropy->restarts_to_go == 0)
  154289. if (! process_restartp(cinfo))
  154290. return FALSE;
  154291. }
  154292. if (! entropy->pub.insufficient_data) {
  154293. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154294. ASSIGN_STATE(state, entropy->saved);
  154295. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154296. block = MCU_data[blkn];
  154297. ci = cinfo->MCU_membership[blkn];
  154298. compptr = cinfo->cur_comp_info[ci];
  154299. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154300. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154301. if (s) {
  154302. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154303. r = GET_BITS(s);
  154304. s = HUFF_EXTEND(r, s);
  154305. }
  154306. s += state.last_dc_val[ci];
  154307. state.last_dc_val[ci] = s;
  154308. (*block)[0] = (JCOEF) (s << Al);
  154309. }
  154310. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154311. ASSIGN_STATE(entropy->saved, state);
  154312. }
  154313. entropy->restarts_to_go--;
  154314. return TRUE;
  154315. }
  154316. METHODDEF(boolean)
  154317. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154318. {
  154319. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154320. int Se = cinfo->Se;
  154321. int Al = cinfo->Al;
  154322. register int s, k, r;
  154323. unsigned int EOBRUN;
  154324. JBLOCKROW block;
  154325. BITREAD_STATE_VARS;
  154326. d_derived_tbl * tbl;
  154327. if (cinfo->restart_interval) {
  154328. if (entropy->restarts_to_go == 0)
  154329. if (! process_restartp(cinfo))
  154330. return FALSE;
  154331. }
  154332. if (! entropy->pub.insufficient_data) {
  154333. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154334. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154335. EOBRUN--; /* ...process it now (we do nothing) */
  154336. else {
  154337. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154338. block = MCU_data[0];
  154339. tbl = entropy->ac_derived_tbl;
  154340. for (k = cinfo->Ss; k <= Se; k++) {
  154341. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154342. r = s >> 4;
  154343. s &= 15;
  154344. if (s) {
  154345. k += r;
  154346. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154347. r = GET_BITS(s);
  154348. s = HUFF_EXTEND(r, s);
  154349. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154350. } else {
  154351. if (r == 15) { /* ZRL */
  154352. k += 15; /* skip 15 zeroes in band */
  154353. } else { /* EOBr, run length is 2^r + appended bits */
  154354. EOBRUN = 1 << r;
  154355. if (r) { /* EOBr, r > 0 */
  154356. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154357. r = GET_BITS(r);
  154358. EOBRUN += r;
  154359. }
  154360. EOBRUN--; /* this band is processed at this moment */
  154361. break; /* force end-of-band */
  154362. }
  154363. }
  154364. }
  154365. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154366. }
  154367. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154368. }
  154369. entropy->restarts_to_go--;
  154370. return TRUE;
  154371. }
  154372. METHODDEF(boolean)
  154373. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154374. {
  154375. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154376. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154377. int blkn;
  154378. JBLOCKROW block;
  154379. BITREAD_STATE_VARS;
  154380. if (cinfo->restart_interval) {
  154381. if (entropy->restarts_to_go == 0)
  154382. if (! process_restartp(cinfo))
  154383. return FALSE;
  154384. }
  154385. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154386. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154387. block = MCU_data[blkn];
  154388. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  154389. if (GET_BITS(1))
  154390. (*block)[0] |= p1;
  154391. }
  154392. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154393. entropy->restarts_to_go--;
  154394. return TRUE;
  154395. }
  154396. METHODDEF(boolean)
  154397. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154398. {
  154399. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154400. int Se = cinfo->Se;
  154401. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154402. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154403. register int s, k, r;
  154404. unsigned int EOBRUN;
  154405. JBLOCKROW block;
  154406. JCOEFPTR thiscoef;
  154407. BITREAD_STATE_VARS;
  154408. d_derived_tbl * tbl;
  154409. int num_newnz;
  154410. int newnz_pos[DCTSIZE2];
  154411. if (cinfo->restart_interval) {
  154412. if (entropy->restarts_to_go == 0)
  154413. if (! process_restartp(cinfo))
  154414. return FALSE;
  154415. }
  154416. if (! entropy->pub.insufficient_data) {
  154417. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154418. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154419. block = MCU_data[0];
  154420. tbl = entropy->ac_derived_tbl;
  154421. num_newnz = 0;
  154422. k = cinfo->Ss;
  154423. if (EOBRUN == 0) {
  154424. for (; k <= Se; k++) {
  154425. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154426. r = s >> 4;
  154427. s &= 15;
  154428. if (s) {
  154429. if (s != 1) /* size of new coef should always be 1 */
  154430. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154431. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154432. if (GET_BITS(1))
  154433. s = p1; /* newly nonzero coef is positive */
  154434. else
  154435. s = m1; /* newly nonzero coef is negative */
  154436. } else {
  154437. if (r != 15) {
  154438. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154439. if (r) {
  154440. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154441. r = GET_BITS(r);
  154442. EOBRUN += r;
  154443. }
  154444. break; /* rest of block is handled by EOB logic */
  154445. }
  154446. }
  154447. do {
  154448. thiscoef = *block + jpeg_natural_order[k];
  154449. if (*thiscoef != 0) {
  154450. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154451. if (GET_BITS(1)) {
  154452. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154453. if (*thiscoef >= 0)
  154454. *thiscoef += p1;
  154455. else
  154456. *thiscoef += m1;
  154457. }
  154458. }
  154459. } else {
  154460. if (--r < 0)
  154461. break; /* reached target zero coefficient */
  154462. }
  154463. k++;
  154464. } while (k <= Se);
  154465. if (s) {
  154466. int pos = jpeg_natural_order[k];
  154467. (*block)[pos] = (JCOEF) s;
  154468. newnz_pos[num_newnz++] = pos;
  154469. }
  154470. }
  154471. }
  154472. if (EOBRUN > 0) {
  154473. for (; k <= Se; k++) {
  154474. thiscoef = *block + jpeg_natural_order[k];
  154475. if (*thiscoef != 0) {
  154476. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154477. if (GET_BITS(1)) {
  154478. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  154479. if (*thiscoef >= 0)
  154480. *thiscoef += p1;
  154481. else
  154482. *thiscoef += m1;
  154483. }
  154484. }
  154485. }
  154486. }
  154487. EOBRUN--;
  154488. }
  154489. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154490. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154491. }
  154492. entropy->restarts_to_go--;
  154493. return TRUE;
  154494. undoit:
  154495. while (num_newnz > 0)
  154496. (*block)[newnz_pos[--num_newnz]] = 0;
  154497. return FALSE;
  154498. }
  154499. GLOBAL(void)
  154500. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154501. {
  154502. phuff_entropy_ptr2 entropy;
  154503. int *coef_bit_ptr;
  154504. int ci, i;
  154505. entropy = (phuff_entropy_ptr2)
  154506. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154507. SIZEOF(phuff_entropy_decoder));
  154508. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154509. entropy->pub.start_pass = start_pass_phuff_decoder;
  154510. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154511. entropy->derived_tbls[i] = NULL;
  154512. }
  154513. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154514. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154515. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154516. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154517. for (ci = 0; ci < cinfo->num_components; ci++)
  154518. for (i = 0; i < DCTSIZE2; i++)
  154519. *coef_bit_ptr++ = -1;
  154520. }
  154521. #endif /* D_PROGRESSIVE_SUPPORTED */
  154522. /*** End of inlined file: jdphuff.c ***/
  154523. /*** Start of inlined file: jdpostct.c ***/
  154524. #define JPEG_INTERNALS
  154525. typedef struct {
  154526. struct jpeg_d_post_controller pub; /* public fields */
  154527. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154528. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154529. JDIMENSION strip_height; /* buffer size in rows */
  154530. JDIMENSION starting_row; /* row # of first row in current strip */
  154531. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154532. } my_post_controller;
  154533. typedef my_post_controller * my_post_ptr;
  154534. METHODDEF(void) post_process_1pass
  154535. JPP((j_decompress_ptr cinfo,
  154536. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154537. JDIMENSION in_row_groups_avail,
  154538. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154539. JDIMENSION out_rows_avail));
  154540. #ifdef QUANT_2PASS_SUPPORTED
  154541. METHODDEF(void) post_process_prepass
  154542. JPP((j_decompress_ptr cinfo,
  154543. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154544. JDIMENSION in_row_groups_avail,
  154545. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154546. JDIMENSION out_rows_avail));
  154547. METHODDEF(void) post_process_2pass
  154548. JPP((j_decompress_ptr cinfo,
  154549. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154550. JDIMENSION in_row_groups_avail,
  154551. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154552. JDIMENSION out_rows_avail));
  154553. #endif
  154554. METHODDEF(void)
  154555. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154556. {
  154557. my_post_ptr post = (my_post_ptr) cinfo->post;
  154558. switch (pass_mode) {
  154559. case JBUF_PASS_THRU:
  154560. if (cinfo->quantize_colors) {
  154561. post->pub.post_process_data = post_process_1pass;
  154562. if (post->buffer == NULL) {
  154563. post->buffer = (*cinfo->mem->access_virt_sarray)
  154564. ((j_common_ptr) cinfo, post->whole_image,
  154565. (JDIMENSION) 0, post->strip_height, TRUE);
  154566. }
  154567. } else {
  154568. post->pub.post_process_data = cinfo->upsample->upsample;
  154569. }
  154570. break;
  154571. #ifdef QUANT_2PASS_SUPPORTED
  154572. case JBUF_SAVE_AND_PASS:
  154573. if (post->whole_image == NULL)
  154574. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154575. post->pub.post_process_data = post_process_prepass;
  154576. break;
  154577. case JBUF_CRANK_DEST:
  154578. if (post->whole_image == NULL)
  154579. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154580. post->pub.post_process_data = post_process_2pass;
  154581. break;
  154582. #endif /* QUANT_2PASS_SUPPORTED */
  154583. default:
  154584. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154585. break;
  154586. }
  154587. post->starting_row = post->next_row = 0;
  154588. }
  154589. METHODDEF(void)
  154590. post_process_1pass (j_decompress_ptr cinfo,
  154591. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154592. JDIMENSION in_row_groups_avail,
  154593. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154594. JDIMENSION out_rows_avail)
  154595. {
  154596. my_post_ptr post = (my_post_ptr) cinfo->post;
  154597. JDIMENSION num_rows, max_rows;
  154598. max_rows = out_rows_avail - *out_row_ctr;
  154599. if (max_rows > post->strip_height)
  154600. max_rows = post->strip_height;
  154601. num_rows = 0;
  154602. (*cinfo->upsample->upsample) (cinfo,
  154603. input_buf, in_row_group_ctr, in_row_groups_avail,
  154604. post->buffer, &num_rows, max_rows);
  154605. (*cinfo->cquantize->color_quantize) (cinfo,
  154606. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154607. *out_row_ctr += num_rows;
  154608. }
  154609. #ifdef QUANT_2PASS_SUPPORTED
  154610. METHODDEF(void)
  154611. post_process_prepass (j_decompress_ptr cinfo,
  154612. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154613. JDIMENSION in_row_groups_avail,
  154614. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154615. JDIMENSION out_rows_avail)
  154616. {
  154617. my_post_ptr post = (my_post_ptr) cinfo->post;
  154618. JDIMENSION old_next_row, num_rows;
  154619. if (post->next_row == 0) {
  154620. post->buffer = (*cinfo->mem->access_virt_sarray)
  154621. ((j_common_ptr) cinfo, post->whole_image,
  154622. post->starting_row, post->strip_height, TRUE);
  154623. }
  154624. old_next_row = post->next_row;
  154625. (*cinfo->upsample->upsample) (cinfo,
  154626. input_buf, in_row_group_ctr, in_row_groups_avail,
  154627. post->buffer, &post->next_row, post->strip_height);
  154628. if (post->next_row > old_next_row) {
  154629. num_rows = post->next_row - old_next_row;
  154630. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154631. (JSAMPARRAY) NULL, (int) num_rows);
  154632. *out_row_ctr += num_rows;
  154633. }
  154634. if (post->next_row >= post->strip_height) {
  154635. post->starting_row += post->strip_height;
  154636. post->next_row = 0;
  154637. }
  154638. }
  154639. METHODDEF(void)
  154640. post_process_2pass (j_decompress_ptr cinfo,
  154641. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154642. JDIMENSION in_row_groups_avail,
  154643. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154644. JDIMENSION out_rows_avail)
  154645. {
  154646. my_post_ptr post = (my_post_ptr) cinfo->post;
  154647. JDIMENSION num_rows, max_rows;
  154648. if (post->next_row == 0) {
  154649. post->buffer = (*cinfo->mem->access_virt_sarray)
  154650. ((j_common_ptr) cinfo, post->whole_image,
  154651. post->starting_row, post->strip_height, FALSE);
  154652. }
  154653. num_rows = post->strip_height - post->next_row; /* available in strip */
  154654. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154655. if (num_rows > max_rows)
  154656. num_rows = max_rows;
  154657. max_rows = cinfo->output_height - post->starting_row;
  154658. if (num_rows > max_rows)
  154659. num_rows = max_rows;
  154660. (*cinfo->cquantize->color_quantize) (cinfo,
  154661. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154662. (int) num_rows);
  154663. *out_row_ctr += num_rows;
  154664. post->next_row += num_rows;
  154665. if (post->next_row >= post->strip_height) {
  154666. post->starting_row += post->strip_height;
  154667. post->next_row = 0;
  154668. }
  154669. }
  154670. #endif /* QUANT_2PASS_SUPPORTED */
  154671. GLOBAL(void)
  154672. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  154673. {
  154674. my_post_ptr post;
  154675. post = (my_post_ptr)
  154676. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154677. SIZEOF(my_post_controller));
  154678. cinfo->post = (struct jpeg_d_post_controller *) post;
  154679. post->pub.start_pass = start_pass_dpost;
  154680. post->whole_image = NULL; /* flag for no virtual arrays */
  154681. post->buffer = NULL; /* flag for no strip buffer */
  154682. if (cinfo->quantize_colors) {
  154683. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  154684. if (need_full_buffer) {
  154685. #ifdef QUANT_2PASS_SUPPORTED
  154686. post->whole_image = (*cinfo->mem->request_virt_sarray)
  154687. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  154688. cinfo->output_width * cinfo->out_color_components,
  154689. (JDIMENSION) jround_up((long) cinfo->output_height,
  154690. (long) post->strip_height),
  154691. post->strip_height);
  154692. #else
  154693. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154694. #endif /* QUANT_2PASS_SUPPORTED */
  154695. } else {
  154696. post->buffer = (*cinfo->mem->alloc_sarray)
  154697. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154698. cinfo->output_width * cinfo->out_color_components,
  154699. post->strip_height);
  154700. }
  154701. }
  154702. }
  154703. /*** End of inlined file: jdpostct.c ***/
  154704. #undef FIX
  154705. /*** Start of inlined file: jdsample.c ***/
  154706. #define JPEG_INTERNALS
  154707. typedef JMETHOD(void, upsample1_ptr,
  154708. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154709. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  154710. typedef struct {
  154711. struct jpeg_upsampler pub; /* public fields */
  154712. JSAMPARRAY color_buf[MAX_COMPONENTS];
  154713. upsample1_ptr methods[MAX_COMPONENTS];
  154714. int next_row_out; /* counts rows emitted from color_buf */
  154715. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154716. int rowgroup_height[MAX_COMPONENTS];
  154717. UINT8 h_expand[MAX_COMPONENTS];
  154718. UINT8 v_expand[MAX_COMPONENTS];
  154719. } my_upsampler2;
  154720. typedef my_upsampler2 * my_upsample_ptr2;
  154721. METHODDEF(void)
  154722. start_pass_upsample (j_decompress_ptr cinfo)
  154723. {
  154724. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154725. upsample->next_row_out = cinfo->max_v_samp_factor;
  154726. upsample->rows_to_go = cinfo->output_height;
  154727. }
  154728. METHODDEF(void)
  154729. sep_upsample (j_decompress_ptr cinfo,
  154730. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154731. JDIMENSION in_row_groups_avail,
  154732. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154733. JDIMENSION out_rows_avail)
  154734. {
  154735. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154736. int ci;
  154737. jpeg_component_info * compptr;
  154738. JDIMENSION num_rows;
  154739. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  154740. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154741. ci++, compptr++) {
  154742. (*upsample->methods[ci]) (cinfo, compptr,
  154743. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  154744. upsample->color_buf + ci);
  154745. }
  154746. upsample->next_row_out = 0;
  154747. }
  154748. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  154749. if (num_rows > upsample->rows_to_go)
  154750. num_rows = upsample->rows_to_go;
  154751. out_rows_avail -= *out_row_ctr;
  154752. if (num_rows > out_rows_avail)
  154753. num_rows = out_rows_avail;
  154754. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  154755. (JDIMENSION) upsample->next_row_out,
  154756. output_buf + *out_row_ctr,
  154757. (int) num_rows);
  154758. *out_row_ctr += num_rows;
  154759. upsample->rows_to_go -= num_rows;
  154760. upsample->next_row_out += num_rows;
  154761. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  154762. (*in_row_group_ctr)++;
  154763. }
  154764. METHODDEF(void)
  154765. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154766. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154767. {
  154768. *output_data_ptr = input_data;
  154769. }
  154770. METHODDEF(void)
  154771. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154772. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154773. {
  154774. *output_data_ptr = NULL; /* safety check */
  154775. }
  154776. METHODDEF(void)
  154777. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154778. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154779. {
  154780. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154781. JSAMPARRAY output_data = *output_data_ptr;
  154782. register JSAMPROW inptr, outptr;
  154783. register JSAMPLE invalue;
  154784. register int h;
  154785. JSAMPROW outend;
  154786. int h_expand, v_expand;
  154787. int inrow, outrow;
  154788. h_expand = upsample->h_expand[compptr->component_index];
  154789. v_expand = upsample->v_expand[compptr->component_index];
  154790. inrow = outrow = 0;
  154791. while (outrow < cinfo->max_v_samp_factor) {
  154792. inptr = input_data[inrow];
  154793. outptr = output_data[outrow];
  154794. outend = outptr + cinfo->output_width;
  154795. while (outptr < outend) {
  154796. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154797. for (h = h_expand; h > 0; h--) {
  154798. *outptr++ = invalue;
  154799. }
  154800. }
  154801. if (v_expand > 1) {
  154802. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154803. v_expand-1, cinfo->output_width);
  154804. }
  154805. inrow++;
  154806. outrow += v_expand;
  154807. }
  154808. }
  154809. METHODDEF(void)
  154810. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154811. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154812. {
  154813. JSAMPARRAY output_data = *output_data_ptr;
  154814. register JSAMPROW inptr, outptr;
  154815. register JSAMPLE invalue;
  154816. JSAMPROW outend;
  154817. int inrow;
  154818. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154819. inptr = input_data[inrow];
  154820. outptr = output_data[inrow];
  154821. outend = outptr + cinfo->output_width;
  154822. while (outptr < outend) {
  154823. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154824. *outptr++ = invalue;
  154825. *outptr++ = invalue;
  154826. }
  154827. }
  154828. }
  154829. METHODDEF(void)
  154830. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154831. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154832. {
  154833. JSAMPARRAY output_data = *output_data_ptr;
  154834. register JSAMPROW inptr, outptr;
  154835. register JSAMPLE invalue;
  154836. JSAMPROW outend;
  154837. int inrow, outrow;
  154838. inrow = outrow = 0;
  154839. while (outrow < cinfo->max_v_samp_factor) {
  154840. inptr = input_data[inrow];
  154841. outptr = output_data[outrow];
  154842. outend = outptr + cinfo->output_width;
  154843. while (outptr < outend) {
  154844. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154845. *outptr++ = invalue;
  154846. *outptr++ = invalue;
  154847. }
  154848. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154849. 1, cinfo->output_width);
  154850. inrow++;
  154851. outrow += 2;
  154852. }
  154853. }
  154854. METHODDEF(void)
  154855. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154856. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154857. {
  154858. JSAMPARRAY output_data = *output_data_ptr;
  154859. register JSAMPROW inptr, outptr;
  154860. register int invalue;
  154861. register JDIMENSION colctr;
  154862. int inrow;
  154863. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154864. inptr = input_data[inrow];
  154865. outptr = output_data[inrow];
  154866. invalue = GETJSAMPLE(*inptr++);
  154867. *outptr++ = (JSAMPLE) invalue;
  154868. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  154869. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154870. invalue = GETJSAMPLE(*inptr++) * 3;
  154871. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  154872. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  154873. }
  154874. invalue = GETJSAMPLE(*inptr);
  154875. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  154876. *outptr++ = (JSAMPLE) invalue;
  154877. }
  154878. }
  154879. METHODDEF(void)
  154880. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154881. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154882. {
  154883. JSAMPARRAY output_data = *output_data_ptr;
  154884. register JSAMPROW inptr0, inptr1, outptr;
  154885. #if BITS_IN_JSAMPLE == 8
  154886. register int thiscolsum, lastcolsum, nextcolsum;
  154887. #else
  154888. register INT32 thiscolsum, lastcolsum, nextcolsum;
  154889. #endif
  154890. register JDIMENSION colctr;
  154891. int inrow, outrow, v;
  154892. inrow = outrow = 0;
  154893. while (outrow < cinfo->max_v_samp_factor) {
  154894. for (v = 0; v < 2; v++) {
  154895. inptr0 = input_data[inrow];
  154896. if (v == 0) /* next nearest is row above */
  154897. inptr1 = input_data[inrow-1];
  154898. else /* next nearest is row below */
  154899. inptr1 = input_data[inrow+1];
  154900. outptr = output_data[outrow++];
  154901. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154902. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154903. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  154904. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154905. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154906. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154907. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154908. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154909. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154910. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154911. }
  154912. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154913. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  154914. }
  154915. inrow++;
  154916. }
  154917. }
  154918. GLOBAL(void)
  154919. jinit_upsampler (j_decompress_ptr cinfo)
  154920. {
  154921. my_upsample_ptr2 upsample;
  154922. int ci;
  154923. jpeg_component_info * compptr;
  154924. boolean need_buffer, do_fancy;
  154925. int h_in_group, v_in_group, h_out_group, v_out_group;
  154926. upsample = (my_upsample_ptr2)
  154927. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154928. SIZEOF(my_upsampler2));
  154929. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154930. upsample->pub.start_pass = start_pass_upsample;
  154931. upsample->pub.upsample = sep_upsample;
  154932. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  154933. if (cinfo->CCIR601_sampling) /* this isn't supported */
  154934. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  154935. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  154936. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154937. ci++, compptr++) {
  154938. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  154939. cinfo->min_DCT_scaled_size;
  154940. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  154941. cinfo->min_DCT_scaled_size;
  154942. h_out_group = cinfo->max_h_samp_factor;
  154943. v_out_group = cinfo->max_v_samp_factor;
  154944. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  154945. need_buffer = TRUE;
  154946. if (! compptr->component_needed) {
  154947. upsample->methods[ci] = noop_upsample;
  154948. need_buffer = FALSE;
  154949. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  154950. upsample->methods[ci] = fullsize_upsample;
  154951. need_buffer = FALSE;
  154952. } else if (h_in_group * 2 == h_out_group &&
  154953. v_in_group == v_out_group) {
  154954. if (do_fancy && compptr->downsampled_width > 2)
  154955. upsample->methods[ci] = h2v1_fancy_upsample;
  154956. else
  154957. upsample->methods[ci] = h2v1_upsample;
  154958. } else if (h_in_group * 2 == h_out_group &&
  154959. v_in_group * 2 == v_out_group) {
  154960. if (do_fancy && compptr->downsampled_width > 2) {
  154961. upsample->methods[ci] = h2v2_fancy_upsample;
  154962. upsample->pub.need_context_rows = TRUE;
  154963. } else
  154964. upsample->methods[ci] = h2v2_upsample;
  154965. } else if ((h_out_group % h_in_group) == 0 &&
  154966. (v_out_group % v_in_group) == 0) {
  154967. upsample->methods[ci] = int_upsample;
  154968. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  154969. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  154970. } else
  154971. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  154972. if (need_buffer) {
  154973. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  154974. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154975. (JDIMENSION) jround_up((long) cinfo->output_width,
  154976. (long) cinfo->max_h_samp_factor),
  154977. (JDIMENSION) cinfo->max_v_samp_factor);
  154978. }
  154979. }
  154980. }
  154981. /*** End of inlined file: jdsample.c ***/
  154982. /*** Start of inlined file: jdtrans.c ***/
  154983. #define JPEG_INTERNALS
  154984. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  154985. GLOBAL(jvirt_barray_ptr *)
  154986. jpeg_read_coefficients (j_decompress_ptr cinfo)
  154987. {
  154988. if (cinfo->global_state == DSTATE_READY) {
  154989. transdecode_master_selection(cinfo);
  154990. cinfo->global_state = DSTATE_RDCOEFS;
  154991. }
  154992. if (cinfo->global_state == DSTATE_RDCOEFS) {
  154993. for (;;) {
  154994. int retcode;
  154995. if (cinfo->progress != NULL)
  154996. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  154997. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  154998. if (retcode == JPEG_SUSPENDED)
  154999. return NULL;
  155000. if (retcode == JPEG_REACHED_EOI)
  155001. break;
  155002. if (cinfo->progress != NULL &&
  155003. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  155004. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  155005. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  155006. }
  155007. }
  155008. }
  155009. cinfo->global_state = DSTATE_STOPPING;
  155010. }
  155011. if ((cinfo->global_state == DSTATE_STOPPING ||
  155012. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  155013. return cinfo->coef->coef_arrays;
  155014. }
  155015. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  155016. return NULL; /* keep compiler happy */
  155017. }
  155018. LOCAL(void)
  155019. transdecode_master_selection (j_decompress_ptr cinfo)
  155020. {
  155021. cinfo->buffered_image = TRUE;
  155022. if (cinfo->arith_code) {
  155023. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  155024. } else {
  155025. if (cinfo->progressive_mode) {
  155026. #ifdef D_PROGRESSIVE_SUPPORTED
  155027. jinit_phuff_decoder(cinfo);
  155028. #else
  155029. ERREXIT(cinfo, JERR_NOT_COMPILED);
  155030. #endif
  155031. } else
  155032. jinit_huff_decoder(cinfo);
  155033. }
  155034. jinit_d_coef_controller(cinfo, TRUE);
  155035. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  155036. (*cinfo->inputctl->start_input_pass) (cinfo);
  155037. if (cinfo->progress != NULL) {
  155038. int nscans;
  155039. if (cinfo->progressive_mode) {
  155040. nscans = 2 + 3 * cinfo->num_components;
  155041. } else if (cinfo->inputctl->has_multiple_scans) {
  155042. nscans = cinfo->num_components;
  155043. } else {
  155044. nscans = 1;
  155045. }
  155046. cinfo->progress->pass_counter = 0L;
  155047. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  155048. cinfo->progress->completed_passes = 0;
  155049. cinfo->progress->total_passes = 1;
  155050. }
  155051. }
  155052. /*** End of inlined file: jdtrans.c ***/
  155053. /*** Start of inlined file: jfdctflt.c ***/
  155054. #define JPEG_INTERNALS
  155055. #ifdef DCT_FLOAT_SUPPORTED
  155056. #if DCTSIZE != 8
  155057. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155058. #endif
  155059. GLOBAL(void)
  155060. jpeg_fdct_float (FAST_FLOAT * data)
  155061. {
  155062. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155063. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155064. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  155065. FAST_FLOAT *dataptr;
  155066. int ctr;
  155067. dataptr = data;
  155068. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155069. tmp0 = dataptr[0] + dataptr[7];
  155070. tmp7 = dataptr[0] - dataptr[7];
  155071. tmp1 = dataptr[1] + dataptr[6];
  155072. tmp6 = dataptr[1] - dataptr[6];
  155073. tmp2 = dataptr[2] + dataptr[5];
  155074. tmp5 = dataptr[2] - dataptr[5];
  155075. tmp3 = dataptr[3] + dataptr[4];
  155076. tmp4 = dataptr[3] - dataptr[4];
  155077. tmp10 = tmp0 + tmp3; /* phase 2 */
  155078. tmp13 = tmp0 - tmp3;
  155079. tmp11 = tmp1 + tmp2;
  155080. tmp12 = tmp1 - tmp2;
  155081. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155082. dataptr[4] = tmp10 - tmp11;
  155083. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155084. dataptr[2] = tmp13 + z1; /* phase 5 */
  155085. dataptr[6] = tmp13 - z1;
  155086. tmp10 = tmp4 + tmp5; /* phase 2 */
  155087. tmp11 = tmp5 + tmp6;
  155088. tmp12 = tmp6 + tmp7;
  155089. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155090. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155091. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155092. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155093. z11 = tmp7 + z3; /* phase 5 */
  155094. z13 = tmp7 - z3;
  155095. dataptr[5] = z13 + z2; /* phase 6 */
  155096. dataptr[3] = z13 - z2;
  155097. dataptr[1] = z11 + z4;
  155098. dataptr[7] = z11 - z4;
  155099. dataptr += DCTSIZE; /* advance pointer to next row */
  155100. }
  155101. dataptr = data;
  155102. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155103. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155104. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155105. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155106. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155107. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155108. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155109. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155110. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155111. tmp10 = tmp0 + tmp3; /* phase 2 */
  155112. tmp13 = tmp0 - tmp3;
  155113. tmp11 = tmp1 + tmp2;
  155114. tmp12 = tmp1 - tmp2;
  155115. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155116. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155117. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155118. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155119. dataptr[DCTSIZE*6] = tmp13 - z1;
  155120. tmp10 = tmp4 + tmp5; /* phase 2 */
  155121. tmp11 = tmp5 + tmp6;
  155122. tmp12 = tmp6 + tmp7;
  155123. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155124. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155125. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155126. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155127. z11 = tmp7 + z3; /* phase 5 */
  155128. z13 = tmp7 - z3;
  155129. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155130. dataptr[DCTSIZE*3] = z13 - z2;
  155131. dataptr[DCTSIZE*1] = z11 + z4;
  155132. dataptr[DCTSIZE*7] = z11 - z4;
  155133. dataptr++; /* advance pointer to next column */
  155134. }
  155135. }
  155136. #endif /* DCT_FLOAT_SUPPORTED */
  155137. /*** End of inlined file: jfdctflt.c ***/
  155138. /*** Start of inlined file: jfdctint.c ***/
  155139. #define JPEG_INTERNALS
  155140. #ifdef DCT_ISLOW_SUPPORTED
  155141. #if DCTSIZE != 8
  155142. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155143. #endif
  155144. #if BITS_IN_JSAMPLE == 8
  155145. #define CONST_BITS 13
  155146. #define PASS1_BITS 2
  155147. #else
  155148. #define CONST_BITS 13
  155149. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155150. #endif
  155151. #if CONST_BITS == 13
  155152. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155153. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155154. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155155. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155156. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155157. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155158. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155159. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155160. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155161. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155162. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155163. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155164. #else
  155165. #define FIX_0_298631336 FIX(0.298631336)
  155166. #define FIX_0_390180644 FIX(0.390180644)
  155167. #define FIX_0_541196100 FIX(0.541196100)
  155168. #define FIX_0_765366865 FIX(0.765366865)
  155169. #define FIX_0_899976223 FIX(0.899976223)
  155170. #define FIX_1_175875602 FIX(1.175875602)
  155171. #define FIX_1_501321110 FIX(1.501321110)
  155172. #define FIX_1_847759065 FIX(1.847759065)
  155173. #define FIX_1_961570560 FIX(1.961570560)
  155174. #define FIX_2_053119869 FIX(2.053119869)
  155175. #define FIX_2_562915447 FIX(2.562915447)
  155176. #define FIX_3_072711026 FIX(3.072711026)
  155177. #endif
  155178. #if BITS_IN_JSAMPLE == 8
  155179. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155180. #else
  155181. #define MULTIPLY(var,const) ((var) * (const))
  155182. #endif
  155183. GLOBAL(void)
  155184. jpeg_fdct_islow (DCTELEM * data)
  155185. {
  155186. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155187. INT32 tmp10, tmp11, tmp12, tmp13;
  155188. INT32 z1, z2, z3, z4, z5;
  155189. DCTELEM *dataptr;
  155190. int ctr;
  155191. SHIFT_TEMPS
  155192. dataptr = data;
  155193. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155194. tmp0 = dataptr[0] + dataptr[7];
  155195. tmp7 = dataptr[0] - dataptr[7];
  155196. tmp1 = dataptr[1] + dataptr[6];
  155197. tmp6 = dataptr[1] - dataptr[6];
  155198. tmp2 = dataptr[2] + dataptr[5];
  155199. tmp5 = dataptr[2] - dataptr[5];
  155200. tmp3 = dataptr[3] + dataptr[4];
  155201. tmp4 = dataptr[3] - dataptr[4];
  155202. tmp10 = tmp0 + tmp3;
  155203. tmp13 = tmp0 - tmp3;
  155204. tmp11 = tmp1 + tmp2;
  155205. tmp12 = tmp1 - tmp2;
  155206. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  155207. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  155208. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155209. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155210. CONST_BITS-PASS1_BITS);
  155211. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155212. CONST_BITS-PASS1_BITS);
  155213. z1 = tmp4 + tmp7;
  155214. z2 = tmp5 + tmp6;
  155215. z3 = tmp4 + tmp6;
  155216. z4 = tmp5 + tmp7;
  155217. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155218. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155219. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155220. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155221. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155222. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155223. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155224. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155225. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155226. z3 += z5;
  155227. z4 += z5;
  155228. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  155229. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  155230. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  155231. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  155232. dataptr += DCTSIZE; /* advance pointer to next row */
  155233. }
  155234. dataptr = data;
  155235. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155236. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155237. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155238. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155239. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155240. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155241. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155242. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155243. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155244. tmp10 = tmp0 + tmp3;
  155245. tmp13 = tmp0 - tmp3;
  155246. tmp11 = tmp1 + tmp2;
  155247. tmp12 = tmp1 - tmp2;
  155248. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  155249. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  155250. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155251. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155252. CONST_BITS+PASS1_BITS);
  155253. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155254. CONST_BITS+PASS1_BITS);
  155255. z1 = tmp4 + tmp7;
  155256. z2 = tmp5 + tmp6;
  155257. z3 = tmp4 + tmp6;
  155258. z4 = tmp5 + tmp7;
  155259. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155260. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155261. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155262. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155263. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155264. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155265. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155266. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155267. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155268. z3 += z5;
  155269. z4 += z5;
  155270. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  155271. CONST_BITS+PASS1_BITS);
  155272. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  155273. CONST_BITS+PASS1_BITS);
  155274. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  155275. CONST_BITS+PASS1_BITS);
  155276. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  155277. CONST_BITS+PASS1_BITS);
  155278. dataptr++; /* advance pointer to next column */
  155279. }
  155280. }
  155281. #endif /* DCT_ISLOW_SUPPORTED */
  155282. /*** End of inlined file: jfdctint.c ***/
  155283. #undef CONST_BITS
  155284. #undef MULTIPLY
  155285. #undef FIX_0_541196100
  155286. /*** Start of inlined file: jfdctfst.c ***/
  155287. #define JPEG_INTERNALS
  155288. #ifdef DCT_IFAST_SUPPORTED
  155289. #if DCTSIZE != 8
  155290. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155291. #endif
  155292. #define CONST_BITS 8
  155293. #if CONST_BITS == 8
  155294. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155295. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155296. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155297. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155298. #else
  155299. #define FIX_0_382683433 FIX(0.382683433)
  155300. #define FIX_0_541196100 FIX(0.541196100)
  155301. #define FIX_0_707106781 FIX(0.707106781)
  155302. #define FIX_1_306562965 FIX(1.306562965)
  155303. #endif
  155304. #ifndef USE_ACCURATE_ROUNDING
  155305. #undef DESCALE
  155306. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155307. #endif
  155308. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155309. GLOBAL(void)
  155310. jpeg_fdct_ifast (DCTELEM * data)
  155311. {
  155312. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155313. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155314. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155315. DCTELEM *dataptr;
  155316. int ctr;
  155317. SHIFT_TEMPS
  155318. dataptr = data;
  155319. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155320. tmp0 = dataptr[0] + dataptr[7];
  155321. tmp7 = dataptr[0] - dataptr[7];
  155322. tmp1 = dataptr[1] + dataptr[6];
  155323. tmp6 = dataptr[1] - dataptr[6];
  155324. tmp2 = dataptr[2] + dataptr[5];
  155325. tmp5 = dataptr[2] - dataptr[5];
  155326. tmp3 = dataptr[3] + dataptr[4];
  155327. tmp4 = dataptr[3] - dataptr[4];
  155328. tmp10 = tmp0 + tmp3; /* phase 2 */
  155329. tmp13 = tmp0 - tmp3;
  155330. tmp11 = tmp1 + tmp2;
  155331. tmp12 = tmp1 - tmp2;
  155332. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155333. dataptr[4] = tmp10 - tmp11;
  155334. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155335. dataptr[2] = tmp13 + z1; /* phase 5 */
  155336. dataptr[6] = tmp13 - z1;
  155337. tmp10 = tmp4 + tmp5; /* phase 2 */
  155338. tmp11 = tmp5 + tmp6;
  155339. tmp12 = tmp6 + tmp7;
  155340. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155341. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155342. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155343. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155344. z11 = tmp7 + z3; /* phase 5 */
  155345. z13 = tmp7 - z3;
  155346. dataptr[5] = z13 + z2; /* phase 6 */
  155347. dataptr[3] = z13 - z2;
  155348. dataptr[1] = z11 + z4;
  155349. dataptr[7] = z11 - z4;
  155350. dataptr += DCTSIZE; /* advance pointer to next row */
  155351. }
  155352. dataptr = data;
  155353. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155354. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155355. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155356. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155357. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155358. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155359. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155360. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155361. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155362. tmp10 = tmp0 + tmp3; /* phase 2 */
  155363. tmp13 = tmp0 - tmp3;
  155364. tmp11 = tmp1 + tmp2;
  155365. tmp12 = tmp1 - tmp2;
  155366. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155367. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155368. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155369. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155370. dataptr[DCTSIZE*6] = tmp13 - z1;
  155371. tmp10 = tmp4 + tmp5; /* phase 2 */
  155372. tmp11 = tmp5 + tmp6;
  155373. tmp12 = tmp6 + tmp7;
  155374. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155375. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155376. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155377. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155378. z11 = tmp7 + z3; /* phase 5 */
  155379. z13 = tmp7 - z3;
  155380. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155381. dataptr[DCTSIZE*3] = z13 - z2;
  155382. dataptr[DCTSIZE*1] = z11 + z4;
  155383. dataptr[DCTSIZE*7] = z11 - z4;
  155384. dataptr++; /* advance pointer to next column */
  155385. }
  155386. }
  155387. #endif /* DCT_IFAST_SUPPORTED */
  155388. /*** End of inlined file: jfdctfst.c ***/
  155389. #undef FIX_0_541196100
  155390. /*** Start of inlined file: jidctflt.c ***/
  155391. #define JPEG_INTERNALS
  155392. #ifdef DCT_FLOAT_SUPPORTED
  155393. #if DCTSIZE != 8
  155394. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155395. #endif
  155396. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155397. GLOBAL(void)
  155398. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155399. JCOEFPTR coef_block,
  155400. JSAMPARRAY output_buf, JDIMENSION output_col)
  155401. {
  155402. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155403. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155404. FAST_FLOAT z5, z10, z11, z12, z13;
  155405. JCOEFPTR inptr;
  155406. FLOAT_MULT_TYPE * quantptr;
  155407. FAST_FLOAT * wsptr;
  155408. JSAMPROW outptr;
  155409. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155410. int ctr;
  155411. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155412. SHIFT_TEMPS
  155413. inptr = coef_block;
  155414. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155415. wsptr = workspace;
  155416. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155417. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155418. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155419. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155420. inptr[DCTSIZE*7] == 0) {
  155421. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155422. wsptr[DCTSIZE*0] = dcval;
  155423. wsptr[DCTSIZE*1] = dcval;
  155424. wsptr[DCTSIZE*2] = dcval;
  155425. wsptr[DCTSIZE*3] = dcval;
  155426. wsptr[DCTSIZE*4] = dcval;
  155427. wsptr[DCTSIZE*5] = dcval;
  155428. wsptr[DCTSIZE*6] = dcval;
  155429. wsptr[DCTSIZE*7] = dcval;
  155430. inptr++; /* advance pointers to next column */
  155431. quantptr++;
  155432. wsptr++;
  155433. continue;
  155434. }
  155435. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155436. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155437. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155438. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155439. tmp10 = tmp0 + tmp2; /* phase 3 */
  155440. tmp11 = tmp0 - tmp2;
  155441. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155442. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155443. tmp0 = tmp10 + tmp13; /* phase 2 */
  155444. tmp3 = tmp10 - tmp13;
  155445. tmp1 = tmp11 + tmp12;
  155446. tmp2 = tmp11 - tmp12;
  155447. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155448. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155449. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155450. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155451. z13 = tmp6 + tmp5; /* phase 6 */
  155452. z10 = tmp6 - tmp5;
  155453. z11 = tmp4 + tmp7;
  155454. z12 = tmp4 - tmp7;
  155455. tmp7 = z11 + z13; /* phase 5 */
  155456. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155457. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155458. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155459. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155460. tmp6 = tmp12 - tmp7; /* phase 2 */
  155461. tmp5 = tmp11 - tmp6;
  155462. tmp4 = tmp10 + tmp5;
  155463. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155464. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155465. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155466. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155467. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155468. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155469. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155470. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155471. inptr++; /* advance pointers to next column */
  155472. quantptr++;
  155473. wsptr++;
  155474. }
  155475. wsptr = workspace;
  155476. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155477. outptr = output_buf[ctr] + output_col;
  155478. tmp10 = wsptr[0] + wsptr[4];
  155479. tmp11 = wsptr[0] - wsptr[4];
  155480. tmp13 = wsptr[2] + wsptr[6];
  155481. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155482. tmp0 = tmp10 + tmp13;
  155483. tmp3 = tmp10 - tmp13;
  155484. tmp1 = tmp11 + tmp12;
  155485. tmp2 = tmp11 - tmp12;
  155486. z13 = wsptr[5] + wsptr[3];
  155487. z10 = wsptr[5] - wsptr[3];
  155488. z11 = wsptr[1] + wsptr[7];
  155489. z12 = wsptr[1] - wsptr[7];
  155490. tmp7 = z11 + z13;
  155491. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155492. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155493. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155494. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155495. tmp6 = tmp12 - tmp7;
  155496. tmp5 = tmp11 - tmp6;
  155497. tmp4 = tmp10 + tmp5;
  155498. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155499. & RANGE_MASK];
  155500. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155501. & RANGE_MASK];
  155502. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155503. & RANGE_MASK];
  155504. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155505. & RANGE_MASK];
  155506. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155507. & RANGE_MASK];
  155508. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155509. & RANGE_MASK];
  155510. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155511. & RANGE_MASK];
  155512. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155513. & RANGE_MASK];
  155514. wsptr += DCTSIZE; /* advance pointer to next row */
  155515. }
  155516. }
  155517. #endif /* DCT_FLOAT_SUPPORTED */
  155518. /*** End of inlined file: jidctflt.c ***/
  155519. #undef CONST_BITS
  155520. #undef FIX_1_847759065
  155521. #undef MULTIPLY
  155522. #undef DEQUANTIZE
  155523. #undef DESCALE
  155524. /*** Start of inlined file: jidctfst.c ***/
  155525. #define JPEG_INTERNALS
  155526. #ifdef DCT_IFAST_SUPPORTED
  155527. #if DCTSIZE != 8
  155528. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155529. #endif
  155530. #if BITS_IN_JSAMPLE == 8
  155531. #define CONST_BITS 8
  155532. #define PASS1_BITS 2
  155533. #else
  155534. #define CONST_BITS 8
  155535. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155536. #endif
  155537. #if CONST_BITS == 8
  155538. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155539. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155540. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155541. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155542. #else
  155543. #define FIX_1_082392200 FIX(1.082392200)
  155544. #define FIX_1_414213562 FIX(1.414213562)
  155545. #define FIX_1_847759065 FIX(1.847759065)
  155546. #define FIX_2_613125930 FIX(2.613125930)
  155547. #endif
  155548. #ifndef USE_ACCURATE_ROUNDING
  155549. #undef DESCALE
  155550. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155551. #endif
  155552. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155553. #if BITS_IN_JSAMPLE == 8
  155554. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155555. #else
  155556. #define DEQUANTIZE(coef,quantval) \
  155557. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155558. #endif
  155559. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155560. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155561. #if BITS_IN_JSAMPLE == 8
  155562. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155563. #else
  155564. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155565. #endif
  155566. #define IRIGHT_SHIFT(x,shft) \
  155567. ((ishift_temp = (x)) < 0 ? \
  155568. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155569. (ishift_temp >> (shft)))
  155570. #else
  155571. #define ISHIFT_TEMPS
  155572. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155573. #endif
  155574. #ifdef USE_ACCURATE_ROUNDING
  155575. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155576. #else
  155577. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155578. #endif
  155579. GLOBAL(void)
  155580. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155581. JCOEFPTR coef_block,
  155582. JSAMPARRAY output_buf, JDIMENSION output_col)
  155583. {
  155584. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155585. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155586. DCTELEM z5, z10, z11, z12, z13;
  155587. JCOEFPTR inptr;
  155588. IFAST_MULT_TYPE * quantptr;
  155589. int * wsptr;
  155590. JSAMPROW outptr;
  155591. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155592. int ctr;
  155593. int workspace[DCTSIZE2]; /* buffers data between passes */
  155594. SHIFT_TEMPS /* for DESCALE */
  155595. ISHIFT_TEMPS /* for IDESCALE */
  155596. inptr = coef_block;
  155597. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155598. wsptr = workspace;
  155599. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155600. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155601. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155602. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155603. inptr[DCTSIZE*7] == 0) {
  155604. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155605. wsptr[DCTSIZE*0] = dcval;
  155606. wsptr[DCTSIZE*1] = dcval;
  155607. wsptr[DCTSIZE*2] = dcval;
  155608. wsptr[DCTSIZE*3] = dcval;
  155609. wsptr[DCTSIZE*4] = dcval;
  155610. wsptr[DCTSIZE*5] = dcval;
  155611. wsptr[DCTSIZE*6] = dcval;
  155612. wsptr[DCTSIZE*7] = dcval;
  155613. inptr++; /* advance pointers to next column */
  155614. quantptr++;
  155615. wsptr++;
  155616. continue;
  155617. }
  155618. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155619. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155620. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155621. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155622. tmp10 = tmp0 + tmp2; /* phase 3 */
  155623. tmp11 = tmp0 - tmp2;
  155624. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155625. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155626. tmp0 = tmp10 + tmp13; /* phase 2 */
  155627. tmp3 = tmp10 - tmp13;
  155628. tmp1 = tmp11 + tmp12;
  155629. tmp2 = tmp11 - tmp12;
  155630. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155631. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155632. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155633. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155634. z13 = tmp6 + tmp5; /* phase 6 */
  155635. z10 = tmp6 - tmp5;
  155636. z11 = tmp4 + tmp7;
  155637. z12 = tmp4 - tmp7;
  155638. tmp7 = z11 + z13; /* phase 5 */
  155639. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155640. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155641. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155642. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155643. tmp6 = tmp12 - tmp7; /* phase 2 */
  155644. tmp5 = tmp11 - tmp6;
  155645. tmp4 = tmp10 + tmp5;
  155646. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155647. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155648. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155649. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155650. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155651. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155652. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155653. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155654. inptr++; /* advance pointers to next column */
  155655. quantptr++;
  155656. wsptr++;
  155657. }
  155658. wsptr = workspace;
  155659. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155660. outptr = output_buf[ctr] + output_col;
  155661. #ifndef NO_ZERO_ROW_TEST
  155662. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155663. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155664. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155665. & RANGE_MASK];
  155666. outptr[0] = dcval;
  155667. outptr[1] = dcval;
  155668. outptr[2] = dcval;
  155669. outptr[3] = dcval;
  155670. outptr[4] = dcval;
  155671. outptr[5] = dcval;
  155672. outptr[6] = dcval;
  155673. outptr[7] = dcval;
  155674. wsptr += DCTSIZE; /* advance pointer to next row */
  155675. continue;
  155676. }
  155677. #endif
  155678. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  155679. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  155680. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  155681. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  155682. - tmp13;
  155683. tmp0 = tmp10 + tmp13;
  155684. tmp3 = tmp10 - tmp13;
  155685. tmp1 = tmp11 + tmp12;
  155686. tmp2 = tmp11 - tmp12;
  155687. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  155688. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  155689. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  155690. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  155691. tmp7 = z11 + z13; /* phase 5 */
  155692. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155693. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155694. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155695. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155696. tmp6 = tmp12 - tmp7; /* phase 2 */
  155697. tmp5 = tmp11 - tmp6;
  155698. tmp4 = tmp10 + tmp5;
  155699. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  155700. & RANGE_MASK];
  155701. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  155702. & RANGE_MASK];
  155703. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  155704. & RANGE_MASK];
  155705. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  155706. & RANGE_MASK];
  155707. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  155708. & RANGE_MASK];
  155709. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  155710. & RANGE_MASK];
  155711. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  155712. & RANGE_MASK];
  155713. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  155714. & RANGE_MASK];
  155715. wsptr += DCTSIZE; /* advance pointer to next row */
  155716. }
  155717. }
  155718. #endif /* DCT_IFAST_SUPPORTED */
  155719. /*** End of inlined file: jidctfst.c ***/
  155720. #undef CONST_BITS
  155721. #undef FIX_1_847759065
  155722. #undef MULTIPLY
  155723. #undef DEQUANTIZE
  155724. /*** Start of inlined file: jidctint.c ***/
  155725. #define JPEG_INTERNALS
  155726. #ifdef DCT_ISLOW_SUPPORTED
  155727. #if DCTSIZE != 8
  155728. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155729. #endif
  155730. #if BITS_IN_JSAMPLE == 8
  155731. #define CONST_BITS 13
  155732. #define PASS1_BITS 2
  155733. #else
  155734. #define CONST_BITS 13
  155735. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155736. #endif
  155737. #if CONST_BITS == 13
  155738. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155739. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155740. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155741. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155742. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155743. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155744. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155745. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155746. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155747. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155748. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155749. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155750. #else
  155751. #define FIX_0_298631336 FIX(0.298631336)
  155752. #define FIX_0_390180644 FIX(0.390180644)
  155753. #define FIX_0_541196100 FIX(0.541196100)
  155754. #define FIX_0_765366865 FIX(0.765366865)
  155755. #define FIX_0_899976223 FIX(0.899976223)
  155756. #define FIX_1_175875602 FIX(1.175875602)
  155757. #define FIX_1_501321110 FIX(1.501321110)
  155758. #define FIX_1_847759065 FIX(1.847759065)
  155759. #define FIX_1_961570560 FIX(1.961570560)
  155760. #define FIX_2_053119869 FIX(2.053119869)
  155761. #define FIX_2_562915447 FIX(2.562915447)
  155762. #define FIX_3_072711026 FIX(3.072711026)
  155763. #endif
  155764. #if BITS_IN_JSAMPLE == 8
  155765. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155766. #else
  155767. #define MULTIPLY(var,const) ((var) * (const))
  155768. #endif
  155769. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155770. GLOBAL(void)
  155771. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155772. JCOEFPTR coef_block,
  155773. JSAMPARRAY output_buf, JDIMENSION output_col)
  155774. {
  155775. INT32 tmp0, tmp1, tmp2, tmp3;
  155776. INT32 tmp10, tmp11, tmp12, tmp13;
  155777. INT32 z1, z2, z3, z4, z5;
  155778. JCOEFPTR inptr;
  155779. ISLOW_MULT_TYPE * quantptr;
  155780. int * wsptr;
  155781. JSAMPROW outptr;
  155782. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155783. int ctr;
  155784. int workspace[DCTSIZE2]; /* buffers data between passes */
  155785. SHIFT_TEMPS
  155786. inptr = coef_block;
  155787. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155788. wsptr = workspace;
  155789. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155790. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155791. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155792. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155793. inptr[DCTSIZE*7] == 0) {
  155794. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155795. wsptr[DCTSIZE*0] = dcval;
  155796. wsptr[DCTSIZE*1] = dcval;
  155797. wsptr[DCTSIZE*2] = dcval;
  155798. wsptr[DCTSIZE*3] = dcval;
  155799. wsptr[DCTSIZE*4] = dcval;
  155800. wsptr[DCTSIZE*5] = dcval;
  155801. wsptr[DCTSIZE*6] = dcval;
  155802. wsptr[DCTSIZE*7] = dcval;
  155803. inptr++; /* advance pointers to next column */
  155804. quantptr++;
  155805. wsptr++;
  155806. continue;
  155807. }
  155808. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155809. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155810. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155811. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155812. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155813. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155814. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155815. tmp0 = (z2 + z3) << CONST_BITS;
  155816. tmp1 = (z2 - z3) << CONST_BITS;
  155817. tmp10 = tmp0 + tmp3;
  155818. tmp13 = tmp0 - tmp3;
  155819. tmp11 = tmp1 + tmp2;
  155820. tmp12 = tmp1 - tmp2;
  155821. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155822. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155823. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155824. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155825. z1 = tmp0 + tmp3;
  155826. z2 = tmp1 + tmp2;
  155827. z3 = tmp0 + tmp2;
  155828. z4 = tmp1 + tmp3;
  155829. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155830. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155831. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155832. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155833. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155834. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155835. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155836. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155837. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155838. z3 += z5;
  155839. z4 += z5;
  155840. tmp0 += z1 + z3;
  155841. tmp1 += z2 + z4;
  155842. tmp2 += z2 + z3;
  155843. tmp3 += z1 + z4;
  155844. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  155845. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  155846. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  155847. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  155848. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  155849. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  155850. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  155851. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  155852. inptr++; /* advance pointers to next column */
  155853. quantptr++;
  155854. wsptr++;
  155855. }
  155856. wsptr = workspace;
  155857. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155858. outptr = output_buf[ctr] + output_col;
  155859. #ifndef NO_ZERO_ROW_TEST
  155860. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155861. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155862. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155863. & RANGE_MASK];
  155864. outptr[0] = dcval;
  155865. outptr[1] = dcval;
  155866. outptr[2] = dcval;
  155867. outptr[3] = dcval;
  155868. outptr[4] = dcval;
  155869. outptr[5] = dcval;
  155870. outptr[6] = dcval;
  155871. outptr[7] = dcval;
  155872. wsptr += DCTSIZE; /* advance pointer to next row */
  155873. continue;
  155874. }
  155875. #endif
  155876. z2 = (INT32) wsptr[2];
  155877. z3 = (INT32) wsptr[6];
  155878. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155879. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155880. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155881. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  155882. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  155883. tmp10 = tmp0 + tmp3;
  155884. tmp13 = tmp0 - tmp3;
  155885. tmp11 = tmp1 + tmp2;
  155886. tmp12 = tmp1 - tmp2;
  155887. tmp0 = (INT32) wsptr[7];
  155888. tmp1 = (INT32) wsptr[5];
  155889. tmp2 = (INT32) wsptr[3];
  155890. tmp3 = (INT32) wsptr[1];
  155891. z1 = tmp0 + tmp3;
  155892. z2 = tmp1 + tmp2;
  155893. z3 = tmp0 + tmp2;
  155894. z4 = tmp1 + tmp3;
  155895. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155896. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155897. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155898. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155899. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155900. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155901. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155902. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155903. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155904. z3 += z5;
  155905. z4 += z5;
  155906. tmp0 += z1 + z3;
  155907. tmp1 += z2 + z4;
  155908. tmp2 += z2 + z3;
  155909. tmp3 += z1 + z4;
  155910. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  155911. CONST_BITS+PASS1_BITS+3)
  155912. & RANGE_MASK];
  155913. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  155914. CONST_BITS+PASS1_BITS+3)
  155915. & RANGE_MASK];
  155916. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  155917. CONST_BITS+PASS1_BITS+3)
  155918. & RANGE_MASK];
  155919. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  155920. CONST_BITS+PASS1_BITS+3)
  155921. & RANGE_MASK];
  155922. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  155923. CONST_BITS+PASS1_BITS+3)
  155924. & RANGE_MASK];
  155925. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  155926. CONST_BITS+PASS1_BITS+3)
  155927. & RANGE_MASK];
  155928. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  155929. CONST_BITS+PASS1_BITS+3)
  155930. & RANGE_MASK];
  155931. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  155932. CONST_BITS+PASS1_BITS+3)
  155933. & RANGE_MASK];
  155934. wsptr += DCTSIZE; /* advance pointer to next row */
  155935. }
  155936. }
  155937. #endif /* DCT_ISLOW_SUPPORTED */
  155938. /*** End of inlined file: jidctint.c ***/
  155939. /*** Start of inlined file: jidctred.c ***/
  155940. #define JPEG_INTERNALS
  155941. #ifdef IDCT_SCALING_SUPPORTED
  155942. #if DCTSIZE != 8
  155943. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155944. #endif
  155945. #if BITS_IN_JSAMPLE == 8
  155946. #define CONST_BITS 13
  155947. #define PASS1_BITS 2
  155948. #else
  155949. #define CONST_BITS 13
  155950. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155951. #endif
  155952. #if CONST_BITS == 13
  155953. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  155954. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  155955. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  155956. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  155957. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155958. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  155959. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155960. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  155961. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  155962. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  155963. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155964. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  155965. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155966. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  155967. #else
  155968. #define FIX_0_211164243 FIX(0.211164243)
  155969. #define FIX_0_509795579 FIX(0.509795579)
  155970. #define FIX_0_601344887 FIX(0.601344887)
  155971. #define FIX_0_720959822 FIX(0.720959822)
  155972. #define FIX_0_765366865 FIX(0.765366865)
  155973. #define FIX_0_850430095 FIX(0.850430095)
  155974. #define FIX_0_899976223 FIX(0.899976223)
  155975. #define FIX_1_061594337 FIX(1.061594337)
  155976. #define FIX_1_272758580 FIX(1.272758580)
  155977. #define FIX_1_451774981 FIX(1.451774981)
  155978. #define FIX_1_847759065 FIX(1.847759065)
  155979. #define FIX_2_172734803 FIX(2.172734803)
  155980. #define FIX_2_562915447 FIX(2.562915447)
  155981. #define FIX_3_624509785 FIX(3.624509785)
  155982. #endif
  155983. #if BITS_IN_JSAMPLE == 8
  155984. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155985. #else
  155986. #define MULTIPLY(var,const) ((var) * (const))
  155987. #endif
  155988. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155989. GLOBAL(void)
  155990. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155991. JCOEFPTR coef_block,
  155992. JSAMPARRAY output_buf, JDIMENSION output_col)
  155993. {
  155994. INT32 tmp0, tmp2, tmp10, tmp12;
  155995. INT32 z1, z2, z3, z4;
  155996. JCOEFPTR inptr;
  155997. ISLOW_MULT_TYPE * quantptr;
  155998. int * wsptr;
  155999. JSAMPROW outptr;
  156000. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156001. int ctr;
  156002. int workspace[DCTSIZE*4]; /* buffers data between passes */
  156003. SHIFT_TEMPS
  156004. inptr = coef_block;
  156005. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156006. wsptr = workspace;
  156007. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156008. if (ctr == DCTSIZE-4)
  156009. continue;
  156010. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156011. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  156012. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  156013. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156014. wsptr[DCTSIZE*0] = dcval;
  156015. wsptr[DCTSIZE*1] = dcval;
  156016. wsptr[DCTSIZE*2] = dcval;
  156017. wsptr[DCTSIZE*3] = dcval;
  156018. continue;
  156019. }
  156020. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156021. tmp0 <<= (CONST_BITS+1);
  156022. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156023. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156024. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  156025. tmp10 = tmp0 + tmp2;
  156026. tmp12 = tmp0 - tmp2;
  156027. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156028. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156029. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156030. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156031. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156032. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156033. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156034. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156035. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156036. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156037. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156038. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156039. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  156040. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  156041. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  156042. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  156043. }
  156044. wsptr = workspace;
  156045. for (ctr = 0; ctr < 4; ctr++) {
  156046. outptr = output_buf[ctr] + output_col;
  156047. #ifndef NO_ZERO_ROW_TEST
  156048. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  156049. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156050. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156051. & RANGE_MASK];
  156052. outptr[0] = dcval;
  156053. outptr[1] = dcval;
  156054. outptr[2] = dcval;
  156055. outptr[3] = dcval;
  156056. wsptr += DCTSIZE; /* advance pointer to next row */
  156057. continue;
  156058. }
  156059. #endif
  156060. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  156061. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  156062. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  156063. tmp10 = tmp0 + tmp2;
  156064. tmp12 = tmp0 - tmp2;
  156065. z1 = (INT32) wsptr[7];
  156066. z2 = (INT32) wsptr[5];
  156067. z3 = (INT32) wsptr[3];
  156068. z4 = (INT32) wsptr[1];
  156069. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156070. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156071. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156072. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156073. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156074. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156075. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156076. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156077. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  156078. CONST_BITS+PASS1_BITS+3+1)
  156079. & RANGE_MASK];
  156080. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  156081. CONST_BITS+PASS1_BITS+3+1)
  156082. & RANGE_MASK];
  156083. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  156084. CONST_BITS+PASS1_BITS+3+1)
  156085. & RANGE_MASK];
  156086. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  156087. CONST_BITS+PASS1_BITS+3+1)
  156088. & RANGE_MASK];
  156089. wsptr += DCTSIZE; /* advance pointer to next row */
  156090. }
  156091. }
  156092. GLOBAL(void)
  156093. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156094. JCOEFPTR coef_block,
  156095. JSAMPARRAY output_buf, JDIMENSION output_col)
  156096. {
  156097. INT32 tmp0, tmp10, z1;
  156098. JCOEFPTR inptr;
  156099. ISLOW_MULT_TYPE * quantptr;
  156100. int * wsptr;
  156101. JSAMPROW outptr;
  156102. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156103. int ctr;
  156104. int workspace[DCTSIZE*2]; /* buffers data between passes */
  156105. SHIFT_TEMPS
  156106. inptr = coef_block;
  156107. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156108. wsptr = workspace;
  156109. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156110. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  156111. continue;
  156112. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  156113. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  156114. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156115. wsptr[DCTSIZE*0] = dcval;
  156116. wsptr[DCTSIZE*1] = dcval;
  156117. continue;
  156118. }
  156119. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156120. tmp10 = z1 << (CONST_BITS+2);
  156121. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156122. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  156123. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156124. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  156125. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156126. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  156127. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156128. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156129. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  156130. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  156131. }
  156132. wsptr = workspace;
  156133. for (ctr = 0; ctr < 2; ctr++) {
  156134. outptr = output_buf[ctr] + output_col;
  156135. #ifndef NO_ZERO_ROW_TEST
  156136. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  156137. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156138. & RANGE_MASK];
  156139. outptr[0] = dcval;
  156140. outptr[1] = dcval;
  156141. wsptr += DCTSIZE; /* advance pointer to next row */
  156142. continue;
  156143. }
  156144. #endif
  156145. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  156146. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  156147. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  156148. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  156149. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156150. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  156151. CONST_BITS+PASS1_BITS+3+2)
  156152. & RANGE_MASK];
  156153. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  156154. CONST_BITS+PASS1_BITS+3+2)
  156155. & RANGE_MASK];
  156156. wsptr += DCTSIZE; /* advance pointer to next row */
  156157. }
  156158. }
  156159. GLOBAL(void)
  156160. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156161. JCOEFPTR coef_block,
  156162. JSAMPARRAY output_buf, JDIMENSION output_col)
  156163. {
  156164. int dcval;
  156165. ISLOW_MULT_TYPE * quantptr;
  156166. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156167. SHIFT_TEMPS
  156168. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156169. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  156170. dcval = (int) DESCALE((INT32) dcval, 3);
  156171. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  156172. }
  156173. #endif /* IDCT_SCALING_SUPPORTED */
  156174. /*** End of inlined file: jidctred.c ***/
  156175. /*** Start of inlined file: jmemmgr.c ***/
  156176. #define JPEG_INTERNALS
  156177. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  156178. /*** Start of inlined file: jmemsys.h ***/
  156179. #ifndef __jmemsys_h__
  156180. #define __jmemsys_h__
  156181. #ifdef NEED_SHORT_EXTERNAL_NAMES
  156182. #define jpeg_get_small jGetSmall
  156183. #define jpeg_free_small jFreeSmall
  156184. #define jpeg_get_large jGetLarge
  156185. #define jpeg_free_large jFreeLarge
  156186. #define jpeg_mem_available jMemAvail
  156187. #define jpeg_open_backing_store jOpenBackStore
  156188. #define jpeg_mem_init jMemInit
  156189. #define jpeg_mem_term jMemTerm
  156190. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  156191. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  156192. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  156193. size_t sizeofobject));
  156194. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  156195. size_t sizeofobject));
  156196. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  156197. size_t sizeofobject));
  156198. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  156199. #define MAX_ALLOC_CHUNK 1000000000L
  156200. #endif
  156201. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  156202. long min_bytes_needed,
  156203. long max_bytes_needed,
  156204. long already_allocated));
  156205. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  156206. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  156207. typedef unsigned short XMSH; /* type of extended-memory handles */
  156208. typedef unsigned short EMSH; /* type of expanded-memory handles */
  156209. typedef union {
  156210. short file_handle; /* DOS file handle if it's a temp file */
  156211. XMSH xms_handle; /* handle if it's a chunk of XMS */
  156212. EMSH ems_handle; /* handle if it's a chunk of EMS */
  156213. } handle_union;
  156214. #endif /* USE_MSDOS_MEMMGR */
  156215. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  156216. #include <Files.h>
  156217. #endif /* USE_MAC_MEMMGR */
  156218. //typedef struct backing_store_struct * backing_store_ptr;
  156219. typedef struct backing_store_struct {
  156220. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  156221. struct backing_store_struct *info,
  156222. void FAR * buffer_address,
  156223. long file_offset, long byte_count));
  156224. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  156225. struct backing_store_struct *info,
  156226. void FAR * buffer_address,
  156227. long file_offset, long byte_count));
  156228. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  156229. struct backing_store_struct *info));
  156230. #ifdef USE_MSDOS_MEMMGR
  156231. handle_union handle; /* reference to backing-store storage object */
  156232. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156233. #else
  156234. #ifdef USE_MAC_MEMMGR
  156235. short temp_file; /* file reference number to temp file */
  156236. FSSpec tempSpec; /* the FSSpec for the temp file */
  156237. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156238. #else
  156239. FILE * temp_file; /* stdio reference to temp file */
  156240. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  156241. #endif
  156242. #endif
  156243. } backing_store_info;
  156244. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  156245. struct backing_store_struct *info,
  156246. long total_bytes_needed));
  156247. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  156248. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  156249. #endif
  156250. /*** End of inlined file: jmemsys.h ***/
  156251. /* import the system-dependent declarations */
  156252. #ifndef NO_GETENV
  156253. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  156254. extern char * getenv JPP((const char * name));
  156255. #endif
  156256. #endif
  156257. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  156258. #define ALIGN_TYPE double
  156259. #endif
  156260. typedef union small_pool_struct * small_pool_ptr;
  156261. typedef union small_pool_struct {
  156262. struct {
  156263. small_pool_ptr next; /* next in list of pools */
  156264. size_t bytes_used; /* how many bytes already used within pool */
  156265. size_t bytes_left; /* bytes still available in this pool */
  156266. } hdr;
  156267. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156268. } small_pool_hdr;
  156269. typedef union large_pool_struct FAR * large_pool_ptr;
  156270. typedef union large_pool_struct {
  156271. struct {
  156272. large_pool_ptr next; /* next in list of pools */
  156273. size_t bytes_used; /* how many bytes already used within pool */
  156274. size_t bytes_left; /* bytes still available in this pool */
  156275. } hdr;
  156276. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156277. } large_pool_hdr;
  156278. typedef struct {
  156279. struct jpeg_memory_mgr pub; /* public fields */
  156280. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156281. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156282. jvirt_sarray_ptr virt_sarray_list;
  156283. jvirt_barray_ptr virt_barray_list;
  156284. long total_space_allocated;
  156285. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156286. } my_memory_mgr;
  156287. typedef my_memory_mgr * my_mem_ptr;
  156288. struct jvirt_sarray_control {
  156289. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156290. JDIMENSION rows_in_array; /* total virtual array height */
  156291. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156292. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156293. JDIMENSION rows_in_mem; /* height of memory buffer */
  156294. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156295. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156296. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156297. boolean pre_zero; /* pre-zero mode requested? */
  156298. boolean dirty; /* do current buffer contents need written? */
  156299. boolean b_s_open; /* is backing-store data valid? */
  156300. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156301. backing_store_info b_s_info; /* System-dependent control info */
  156302. };
  156303. struct jvirt_barray_control {
  156304. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156305. JDIMENSION rows_in_array; /* total virtual array height */
  156306. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156307. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156308. JDIMENSION rows_in_mem; /* height of memory buffer */
  156309. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156310. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156311. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156312. boolean pre_zero; /* pre-zero mode requested? */
  156313. boolean dirty; /* do current buffer contents need written? */
  156314. boolean b_s_open; /* is backing-store data valid? */
  156315. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156316. backing_store_info b_s_info; /* System-dependent control info */
  156317. };
  156318. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156319. LOCAL(void)
  156320. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156321. {
  156322. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156323. small_pool_ptr shdr_ptr;
  156324. large_pool_ptr lhdr_ptr;
  156325. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156326. pool_id, mem->total_space_allocated);
  156327. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156328. lhdr_ptr = lhdr_ptr->hdr.next) {
  156329. fprintf(stderr, " Large chunk used %ld\n",
  156330. (long) lhdr_ptr->hdr.bytes_used);
  156331. }
  156332. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156333. shdr_ptr = shdr_ptr->hdr.next) {
  156334. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156335. (long) shdr_ptr->hdr.bytes_used,
  156336. (long) shdr_ptr->hdr.bytes_left);
  156337. }
  156338. }
  156339. #endif /* MEM_STATS */
  156340. LOCAL(void)
  156341. out_of_memory (j_common_ptr cinfo, int which)
  156342. {
  156343. #ifdef MEM_STATS
  156344. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156345. #endif
  156346. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156347. }
  156348. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156349. {
  156350. 1600, /* first PERMANENT pool */
  156351. 16000 /* first IMAGE pool */
  156352. };
  156353. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156354. {
  156355. 0, /* additional PERMANENT pools */
  156356. 5000 /* additional IMAGE pools */
  156357. };
  156358. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156359. METHODDEF(void *)
  156360. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156361. {
  156362. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156363. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156364. char * data_ptr;
  156365. size_t odd_bytes, min_request, slop;
  156366. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156367. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156368. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156369. if (odd_bytes > 0)
  156370. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156371. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156372. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156373. prev_hdr_ptr = NULL;
  156374. hdr_ptr = mem->small_list[pool_id];
  156375. while (hdr_ptr != NULL) {
  156376. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156377. break; /* found pool with enough space */
  156378. prev_hdr_ptr = hdr_ptr;
  156379. hdr_ptr = hdr_ptr->hdr.next;
  156380. }
  156381. if (hdr_ptr == NULL) {
  156382. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156383. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156384. slop = first_pool_slop[pool_id];
  156385. else
  156386. slop = extra_pool_slop[pool_id];
  156387. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  156388. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  156389. for (;;) {
  156390. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156391. if (hdr_ptr != NULL)
  156392. break;
  156393. slop /= 2;
  156394. if (slop < MIN_SLOP) /* give up when it gets real small */
  156395. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156396. }
  156397. mem->total_space_allocated += min_request + slop;
  156398. hdr_ptr->hdr.next = NULL;
  156399. hdr_ptr->hdr.bytes_used = 0;
  156400. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156401. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156402. mem->small_list[pool_id] = hdr_ptr;
  156403. else
  156404. prev_hdr_ptr->hdr.next = hdr_ptr;
  156405. }
  156406. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156407. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156408. hdr_ptr->hdr.bytes_used += sizeofobject;
  156409. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156410. return (void *) data_ptr;
  156411. }
  156412. METHODDEF(void FAR *)
  156413. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156414. {
  156415. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156416. large_pool_ptr hdr_ptr;
  156417. size_t odd_bytes;
  156418. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156419. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156420. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156421. if (odd_bytes > 0)
  156422. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156423. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156424. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156425. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156426. SIZEOF(large_pool_hdr));
  156427. if (hdr_ptr == NULL)
  156428. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156429. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156430. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156431. hdr_ptr->hdr.bytes_used = sizeofobject;
  156432. hdr_ptr->hdr.bytes_left = 0;
  156433. mem->large_list[pool_id] = hdr_ptr;
  156434. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156435. }
  156436. METHODDEF(JSAMPARRAY)
  156437. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156438. JDIMENSION samplesperrow, JDIMENSION numrows)
  156439. {
  156440. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156441. JSAMPARRAY result;
  156442. JSAMPROW workspace;
  156443. JDIMENSION rowsperchunk, currow, i;
  156444. long ltemp;
  156445. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156446. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156447. if (ltemp <= 0)
  156448. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156449. if (ltemp < (long) numrows)
  156450. rowsperchunk = (JDIMENSION) ltemp;
  156451. else
  156452. rowsperchunk = numrows;
  156453. mem->last_rowsperchunk = rowsperchunk;
  156454. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156455. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156456. currow = 0;
  156457. while (currow < numrows) {
  156458. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156459. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156460. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156461. * SIZEOF(JSAMPLE)));
  156462. for (i = rowsperchunk; i > 0; i--) {
  156463. result[currow++] = workspace;
  156464. workspace += samplesperrow;
  156465. }
  156466. }
  156467. return result;
  156468. }
  156469. METHODDEF(JBLOCKARRAY)
  156470. alloc_barray (j_common_ptr cinfo, int pool_id,
  156471. JDIMENSION blocksperrow, JDIMENSION numrows)
  156472. {
  156473. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156474. JBLOCKARRAY result;
  156475. JBLOCKROW workspace;
  156476. JDIMENSION rowsperchunk, currow, i;
  156477. long ltemp;
  156478. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156479. ((long) blocksperrow * SIZEOF(JBLOCK));
  156480. if (ltemp <= 0)
  156481. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156482. if (ltemp < (long) numrows)
  156483. rowsperchunk = (JDIMENSION) ltemp;
  156484. else
  156485. rowsperchunk = numrows;
  156486. mem->last_rowsperchunk = rowsperchunk;
  156487. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156488. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156489. currow = 0;
  156490. while (currow < numrows) {
  156491. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156492. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156493. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156494. * SIZEOF(JBLOCK)));
  156495. for (i = rowsperchunk; i > 0; i--) {
  156496. result[currow++] = workspace;
  156497. workspace += blocksperrow;
  156498. }
  156499. }
  156500. return result;
  156501. }
  156502. METHODDEF(jvirt_sarray_ptr)
  156503. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156504. JDIMENSION samplesperrow, JDIMENSION numrows,
  156505. JDIMENSION maxaccess)
  156506. {
  156507. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156508. jvirt_sarray_ptr result;
  156509. if (pool_id != JPOOL_IMAGE)
  156510. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156511. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156512. SIZEOF(struct jvirt_sarray_control));
  156513. result->mem_buffer = NULL; /* marks array not yet realized */
  156514. result->rows_in_array = numrows;
  156515. result->samplesperrow = samplesperrow;
  156516. result->maxaccess = maxaccess;
  156517. result->pre_zero = pre_zero;
  156518. result->b_s_open = FALSE; /* no associated backing-store object */
  156519. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156520. mem->virt_sarray_list = result;
  156521. return result;
  156522. }
  156523. METHODDEF(jvirt_barray_ptr)
  156524. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156525. JDIMENSION blocksperrow, JDIMENSION numrows,
  156526. JDIMENSION maxaccess)
  156527. {
  156528. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156529. jvirt_barray_ptr result;
  156530. if (pool_id != JPOOL_IMAGE)
  156531. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156532. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156533. SIZEOF(struct jvirt_barray_control));
  156534. result->mem_buffer = NULL; /* marks array not yet realized */
  156535. result->rows_in_array = numrows;
  156536. result->blocksperrow = blocksperrow;
  156537. result->maxaccess = maxaccess;
  156538. result->pre_zero = pre_zero;
  156539. result->b_s_open = FALSE; /* no associated backing-store object */
  156540. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156541. mem->virt_barray_list = result;
  156542. return result;
  156543. }
  156544. METHODDEF(void)
  156545. realize_virt_arrays (j_common_ptr cinfo)
  156546. {
  156547. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156548. long space_per_minheight, maximum_space, avail_mem;
  156549. long minheights, max_minheights;
  156550. jvirt_sarray_ptr sptr;
  156551. jvirt_barray_ptr bptr;
  156552. space_per_minheight = 0;
  156553. maximum_space = 0;
  156554. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156555. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156556. space_per_minheight += (long) sptr->maxaccess *
  156557. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156558. maximum_space += (long) sptr->rows_in_array *
  156559. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156560. }
  156561. }
  156562. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156563. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156564. space_per_minheight += (long) bptr->maxaccess *
  156565. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156566. maximum_space += (long) bptr->rows_in_array *
  156567. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156568. }
  156569. }
  156570. if (space_per_minheight <= 0)
  156571. return; /* no unrealized arrays, no work */
  156572. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156573. mem->total_space_allocated);
  156574. if (avail_mem >= maximum_space)
  156575. max_minheights = 1000000000L;
  156576. else {
  156577. max_minheights = avail_mem / space_per_minheight;
  156578. if (max_minheights <= 0)
  156579. max_minheights = 1;
  156580. }
  156581. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156582. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156583. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156584. if (minheights <= max_minheights) {
  156585. sptr->rows_in_mem = sptr->rows_in_array;
  156586. } else {
  156587. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156588. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156589. (long) sptr->rows_in_array *
  156590. (long) sptr->samplesperrow *
  156591. (long) SIZEOF(JSAMPLE));
  156592. sptr->b_s_open = TRUE;
  156593. }
  156594. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156595. sptr->samplesperrow, sptr->rows_in_mem);
  156596. sptr->rowsperchunk = mem->last_rowsperchunk;
  156597. sptr->cur_start_row = 0;
  156598. sptr->first_undef_row = 0;
  156599. sptr->dirty = FALSE;
  156600. }
  156601. }
  156602. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156603. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156604. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156605. if (minheights <= max_minheights) {
  156606. bptr->rows_in_mem = bptr->rows_in_array;
  156607. } else {
  156608. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156609. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156610. (long) bptr->rows_in_array *
  156611. (long) bptr->blocksperrow *
  156612. (long) SIZEOF(JBLOCK));
  156613. bptr->b_s_open = TRUE;
  156614. }
  156615. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156616. bptr->blocksperrow, bptr->rows_in_mem);
  156617. bptr->rowsperchunk = mem->last_rowsperchunk;
  156618. bptr->cur_start_row = 0;
  156619. bptr->first_undef_row = 0;
  156620. bptr->dirty = FALSE;
  156621. }
  156622. }
  156623. }
  156624. LOCAL(void)
  156625. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156626. {
  156627. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156628. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156629. file_offset = ptr->cur_start_row * bytesperrow;
  156630. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156631. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156632. thisrow = (long) ptr->cur_start_row + i;
  156633. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156634. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156635. if (rows <= 0) /* this chunk might be past end of file! */
  156636. break;
  156637. byte_count = rows * bytesperrow;
  156638. if (writing)
  156639. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156640. (void FAR *) ptr->mem_buffer[i],
  156641. file_offset, byte_count);
  156642. else
  156643. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156644. (void FAR *) ptr->mem_buffer[i],
  156645. file_offset, byte_count);
  156646. file_offset += byte_count;
  156647. }
  156648. }
  156649. LOCAL(void)
  156650. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156651. {
  156652. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156653. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156654. file_offset = ptr->cur_start_row * bytesperrow;
  156655. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156656. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156657. thisrow = (long) ptr->cur_start_row + i;
  156658. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156659. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156660. if (rows <= 0) /* this chunk might be past end of file! */
  156661. break;
  156662. byte_count = rows * bytesperrow;
  156663. if (writing)
  156664. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156665. (void FAR *) ptr->mem_buffer[i],
  156666. file_offset, byte_count);
  156667. else
  156668. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156669. (void FAR *) ptr->mem_buffer[i],
  156670. file_offset, byte_count);
  156671. file_offset += byte_count;
  156672. }
  156673. }
  156674. METHODDEF(JSAMPARRAY)
  156675. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  156676. JDIMENSION start_row, JDIMENSION num_rows,
  156677. boolean writable)
  156678. {
  156679. JDIMENSION end_row = start_row + num_rows;
  156680. JDIMENSION undef_row;
  156681. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156682. ptr->mem_buffer == NULL)
  156683. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156684. if (start_row < ptr->cur_start_row ||
  156685. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156686. if (! ptr->b_s_open)
  156687. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156688. if (ptr->dirty) {
  156689. do_sarray_io(cinfo, ptr, TRUE);
  156690. ptr->dirty = FALSE;
  156691. }
  156692. if (start_row > ptr->cur_start_row) {
  156693. ptr->cur_start_row = start_row;
  156694. } else {
  156695. long ltemp;
  156696. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156697. if (ltemp < 0)
  156698. ltemp = 0; /* don't fall off front end of file */
  156699. ptr->cur_start_row = (JDIMENSION) ltemp;
  156700. }
  156701. do_sarray_io(cinfo, ptr, FALSE);
  156702. }
  156703. if (ptr->first_undef_row < end_row) {
  156704. if (ptr->first_undef_row < start_row) {
  156705. if (writable) /* writer skipped over a section of array */
  156706. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156707. undef_row = start_row; /* but reader is allowed to read ahead */
  156708. } else {
  156709. undef_row = ptr->first_undef_row;
  156710. }
  156711. if (writable)
  156712. ptr->first_undef_row = end_row;
  156713. if (ptr->pre_zero) {
  156714. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156715. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156716. end_row -= ptr->cur_start_row;
  156717. while (undef_row < end_row) {
  156718. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156719. undef_row++;
  156720. }
  156721. } else {
  156722. if (! writable) /* reader looking at undefined data */
  156723. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156724. }
  156725. }
  156726. if (writable)
  156727. ptr->dirty = TRUE;
  156728. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156729. }
  156730. METHODDEF(JBLOCKARRAY)
  156731. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  156732. JDIMENSION start_row, JDIMENSION num_rows,
  156733. boolean writable)
  156734. {
  156735. JDIMENSION end_row = start_row + num_rows;
  156736. JDIMENSION undef_row;
  156737. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156738. ptr->mem_buffer == NULL)
  156739. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156740. if (start_row < ptr->cur_start_row ||
  156741. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156742. if (! ptr->b_s_open)
  156743. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156744. if (ptr->dirty) {
  156745. do_barray_io(cinfo, ptr, TRUE);
  156746. ptr->dirty = FALSE;
  156747. }
  156748. if (start_row > ptr->cur_start_row) {
  156749. ptr->cur_start_row = start_row;
  156750. } else {
  156751. long ltemp;
  156752. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156753. if (ltemp < 0)
  156754. ltemp = 0; /* don't fall off front end of file */
  156755. ptr->cur_start_row = (JDIMENSION) ltemp;
  156756. }
  156757. do_barray_io(cinfo, ptr, FALSE);
  156758. }
  156759. if (ptr->first_undef_row < end_row) {
  156760. if (ptr->first_undef_row < start_row) {
  156761. if (writable) /* writer skipped over a section of array */
  156762. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156763. undef_row = start_row; /* but reader is allowed to read ahead */
  156764. } else {
  156765. undef_row = ptr->first_undef_row;
  156766. }
  156767. if (writable)
  156768. ptr->first_undef_row = end_row;
  156769. if (ptr->pre_zero) {
  156770. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  156771. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156772. end_row -= ptr->cur_start_row;
  156773. while (undef_row < end_row) {
  156774. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156775. undef_row++;
  156776. }
  156777. } else {
  156778. if (! writable) /* reader looking at undefined data */
  156779. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156780. }
  156781. }
  156782. if (writable)
  156783. ptr->dirty = TRUE;
  156784. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156785. }
  156786. METHODDEF(void)
  156787. free_pool (j_common_ptr cinfo, int pool_id)
  156788. {
  156789. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156790. small_pool_ptr shdr_ptr;
  156791. large_pool_ptr lhdr_ptr;
  156792. size_t space_freed;
  156793. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156794. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156795. #ifdef MEM_STATS
  156796. if (cinfo->err->trace_level > 1)
  156797. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  156798. #endif
  156799. if (pool_id == JPOOL_IMAGE) {
  156800. jvirt_sarray_ptr sptr;
  156801. jvirt_barray_ptr bptr;
  156802. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156803. if (sptr->b_s_open) { /* there may be no backing store */
  156804. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  156805. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  156806. }
  156807. }
  156808. mem->virt_sarray_list = NULL;
  156809. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156810. if (bptr->b_s_open) { /* there may be no backing store */
  156811. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  156812. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  156813. }
  156814. }
  156815. mem->virt_barray_list = NULL;
  156816. }
  156817. lhdr_ptr = mem->large_list[pool_id];
  156818. mem->large_list[pool_id] = NULL;
  156819. while (lhdr_ptr != NULL) {
  156820. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  156821. space_freed = lhdr_ptr->hdr.bytes_used +
  156822. lhdr_ptr->hdr.bytes_left +
  156823. SIZEOF(large_pool_hdr);
  156824. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  156825. mem->total_space_allocated -= space_freed;
  156826. lhdr_ptr = next_lhdr_ptr;
  156827. }
  156828. shdr_ptr = mem->small_list[pool_id];
  156829. mem->small_list[pool_id] = NULL;
  156830. while (shdr_ptr != NULL) {
  156831. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  156832. space_freed = shdr_ptr->hdr.bytes_used +
  156833. shdr_ptr->hdr.bytes_left +
  156834. SIZEOF(small_pool_hdr);
  156835. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  156836. mem->total_space_allocated -= space_freed;
  156837. shdr_ptr = next_shdr_ptr;
  156838. }
  156839. }
  156840. METHODDEF(void)
  156841. self_destruct (j_common_ptr cinfo)
  156842. {
  156843. int pool;
  156844. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156845. free_pool(cinfo, pool);
  156846. }
  156847. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  156848. cinfo->mem = NULL; /* ensures I will be called only once */
  156849. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156850. }
  156851. GLOBAL(void)
  156852. jinit_memory_mgr (j_common_ptr cinfo)
  156853. {
  156854. my_mem_ptr mem;
  156855. long max_to_use;
  156856. int pool;
  156857. size_t test_mac;
  156858. cinfo->mem = NULL; /* for safety if init fails */
  156859. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  156860. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  156861. test_mac = (size_t) MAX_ALLOC_CHUNK;
  156862. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  156863. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  156864. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  156865. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  156866. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  156867. if (mem == NULL) {
  156868. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156869. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  156870. }
  156871. mem->pub.alloc_small = alloc_small;
  156872. mem->pub.alloc_large = alloc_large;
  156873. mem->pub.alloc_sarray = alloc_sarray;
  156874. mem->pub.alloc_barray = alloc_barray;
  156875. mem->pub.request_virt_sarray = request_virt_sarray;
  156876. mem->pub.request_virt_barray = request_virt_barray;
  156877. mem->pub.realize_virt_arrays = realize_virt_arrays;
  156878. mem->pub.access_virt_sarray = access_virt_sarray;
  156879. mem->pub.access_virt_barray = access_virt_barray;
  156880. mem->pub.free_pool = free_pool;
  156881. mem->pub.self_destruct = self_destruct;
  156882. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  156883. mem->pub.max_memory_to_use = max_to_use;
  156884. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156885. mem->small_list[pool] = NULL;
  156886. mem->large_list[pool] = NULL;
  156887. }
  156888. mem->virt_sarray_list = NULL;
  156889. mem->virt_barray_list = NULL;
  156890. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  156891. cinfo->mem = & mem->pub;
  156892. #ifndef NO_GETENV
  156893. { char * memenv;
  156894. if ((memenv = getenv("JPEGMEM")) != NULL) {
  156895. char ch = 'x';
  156896. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  156897. if (ch == 'm' || ch == 'M')
  156898. max_to_use *= 1000L;
  156899. mem->pub.max_memory_to_use = max_to_use * 1000L;
  156900. }
  156901. }
  156902. }
  156903. #endif
  156904. }
  156905. /*** End of inlined file: jmemmgr.c ***/
  156906. /*** Start of inlined file: jmemnobs.c ***/
  156907. #define JPEG_INTERNALS
  156908. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  156909. extern void * malloc JPP((size_t size));
  156910. extern void free JPP((void *ptr));
  156911. #endif
  156912. GLOBAL(void *)
  156913. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  156914. {
  156915. return (void *) malloc(sizeofobject);
  156916. }
  156917. GLOBAL(void)
  156918. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  156919. {
  156920. free(object);
  156921. }
  156922. GLOBAL(void FAR *)
  156923. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  156924. {
  156925. return (void FAR *) malloc(sizeofobject);
  156926. }
  156927. GLOBAL(void)
  156928. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  156929. {
  156930. free(object);
  156931. }
  156932. GLOBAL(long)
  156933. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  156934. long max_bytes_needed, long already_allocated)
  156935. {
  156936. return max_bytes_needed;
  156937. }
  156938. GLOBAL(void)
  156939. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  156940. long total_bytes_needed)
  156941. {
  156942. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  156943. }
  156944. GLOBAL(long)
  156945. jpeg_mem_init (j_common_ptr cinfo)
  156946. {
  156947. return 0; /* just set max_memory_to_use to 0 */
  156948. }
  156949. GLOBAL(void)
  156950. jpeg_mem_term (j_common_ptr cinfo)
  156951. {
  156952. }
  156953. /*** End of inlined file: jmemnobs.c ***/
  156954. /*** Start of inlined file: jquant1.c ***/
  156955. #define JPEG_INTERNALS
  156956. #ifdef QUANT_1PASS_SUPPORTED
  156957. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  156958. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  156959. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  156960. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  156961. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  156962. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  156963. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  156964. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  156965. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  156966. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  156967. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  156968. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  156969. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  156970. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  156971. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  156972. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  156973. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  156974. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  156975. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  156976. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  156977. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  156978. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  156979. };
  156980. #if BITS_IN_JSAMPLE == 8
  156981. typedef INT16 FSERROR; /* 16 bits should be enough */
  156982. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  156983. #else
  156984. typedef INT32 FSERROR; /* may need more than 16 bits */
  156985. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  156986. #endif
  156987. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  156988. #define MAX_Q_COMPS 4 /* max components I can handle */
  156989. typedef struct {
  156990. struct jpeg_color_quantizer pub; /* public fields */
  156991. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  156992. int sv_actual; /* number of entries in use */
  156993. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  156994. boolean is_padded; /* is the colorindex padded for odither? */
  156995. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  156996. int row_index; /* cur row's vertical index in dither matrix */
  156997. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  156998. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  156999. boolean on_odd_row; /* flag to remember which row we are on */
  157000. } my_cquantizer;
  157001. typedef my_cquantizer * my_cquantize_ptr;
  157002. LOCAL(int)
  157003. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  157004. {
  157005. int nc = cinfo->out_color_components; /* number of color components */
  157006. int max_colors = cinfo->desired_number_of_colors;
  157007. int total_colors, iroot, i, j;
  157008. boolean changed;
  157009. long temp;
  157010. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  157011. iroot = 1;
  157012. do {
  157013. iroot++;
  157014. temp = iroot; /* set temp = iroot ** nc */
  157015. for (i = 1; i < nc; i++)
  157016. temp *= iroot;
  157017. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  157018. iroot--; /* now iroot = floor(root) */
  157019. if (iroot < 2)
  157020. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  157021. total_colors = 1;
  157022. for (i = 0; i < nc; i++) {
  157023. Ncolors[i] = iroot;
  157024. total_colors *= iroot;
  157025. }
  157026. do {
  157027. changed = FALSE;
  157028. for (i = 0; i < nc; i++) {
  157029. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  157030. temp = total_colors / Ncolors[j];
  157031. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  157032. if (temp > (long) max_colors)
  157033. break; /* won't fit, done with this pass */
  157034. Ncolors[j]++; /* OK, apply the increment */
  157035. total_colors = (int) temp;
  157036. changed = TRUE;
  157037. }
  157038. } while (changed);
  157039. return total_colors;
  157040. }
  157041. LOCAL(int)
  157042. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157043. {
  157044. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  157045. }
  157046. LOCAL(int)
  157047. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157048. {
  157049. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  157050. }
  157051. LOCAL(void)
  157052. create_colormap (j_decompress_ptr cinfo)
  157053. {
  157054. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157055. JSAMPARRAY colormap; /* Created colormap */
  157056. int total_colors; /* Number of distinct output colors */
  157057. int i,j,k, nci, blksize, blkdist, ptr, val;
  157058. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  157059. if (cinfo->out_color_components == 3)
  157060. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  157061. total_colors, cquantize->Ncolors[0],
  157062. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  157063. else
  157064. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  157065. colormap = (*cinfo->mem->alloc_sarray)
  157066. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157067. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  157068. blkdist = total_colors;
  157069. for (i = 0; i < cinfo->out_color_components; i++) {
  157070. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157071. blksize = blkdist / nci;
  157072. for (j = 0; j < nci; j++) {
  157073. val = output_value(cinfo, i, j, nci-1);
  157074. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  157075. for (k = 0; k < blksize; k++)
  157076. colormap[i][ptr+k] = (JSAMPLE) val;
  157077. }
  157078. }
  157079. blkdist = blksize; /* blksize of this color is blkdist of next */
  157080. }
  157081. cquantize->sv_colormap = colormap;
  157082. cquantize->sv_actual = total_colors;
  157083. }
  157084. LOCAL(void)
  157085. create_colorindex (j_decompress_ptr cinfo)
  157086. {
  157087. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157088. JSAMPROW indexptr;
  157089. int i,j,k, nci, blksize, val, pad;
  157090. if (cinfo->dither_mode == JDITHER_ORDERED) {
  157091. pad = MAXJSAMPLE*2;
  157092. cquantize->is_padded = TRUE;
  157093. } else {
  157094. pad = 0;
  157095. cquantize->is_padded = FALSE;
  157096. }
  157097. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  157098. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157099. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  157100. (JDIMENSION) cinfo->out_color_components);
  157101. blksize = cquantize->sv_actual;
  157102. for (i = 0; i < cinfo->out_color_components; i++) {
  157103. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157104. blksize = blksize / nci;
  157105. if (pad)
  157106. cquantize->colorindex[i] += MAXJSAMPLE;
  157107. indexptr = cquantize->colorindex[i];
  157108. val = 0;
  157109. k = largest_input_value(cinfo, i, 0, nci-1);
  157110. for (j = 0; j <= MAXJSAMPLE; j++) {
  157111. while (j > k) /* advance val if past boundary */
  157112. k = largest_input_value(cinfo, i, ++val, nci-1);
  157113. indexptr[j] = (JSAMPLE) (val * blksize);
  157114. }
  157115. if (pad)
  157116. for (j = 1; j <= MAXJSAMPLE; j++) {
  157117. indexptr[-j] = indexptr[0];
  157118. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  157119. }
  157120. }
  157121. }
  157122. LOCAL(ODITHER_MATRIX_PTR)
  157123. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  157124. {
  157125. ODITHER_MATRIX_PTR odither;
  157126. int j,k;
  157127. INT32 num,den;
  157128. odither = (ODITHER_MATRIX_PTR)
  157129. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157130. SIZEOF(ODITHER_MATRIX));
  157131. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  157132. for (j = 0; j < ODITHER_SIZE; j++) {
  157133. for (k = 0; k < ODITHER_SIZE; k++) {
  157134. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  157135. * MAXJSAMPLE;
  157136. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  157137. }
  157138. }
  157139. return odither;
  157140. }
  157141. LOCAL(void)
  157142. create_odither_tables (j_decompress_ptr cinfo)
  157143. {
  157144. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157145. ODITHER_MATRIX_PTR odither;
  157146. int i, j, nci;
  157147. for (i = 0; i < cinfo->out_color_components; i++) {
  157148. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157149. odither = NULL; /* search for matching prior component */
  157150. for (j = 0; j < i; j++) {
  157151. if (nci == cquantize->Ncolors[j]) {
  157152. odither = cquantize->odither[j];
  157153. break;
  157154. }
  157155. }
  157156. if (odither == NULL) /* need a new table? */
  157157. odither = make_odither_array(cinfo, nci);
  157158. cquantize->odither[i] = odither;
  157159. }
  157160. }
  157161. METHODDEF(void)
  157162. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157163. JSAMPARRAY output_buf, int num_rows)
  157164. {
  157165. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157166. JSAMPARRAY colorindex = cquantize->colorindex;
  157167. register int pixcode, ci;
  157168. register JSAMPROW ptrin, ptrout;
  157169. int row;
  157170. JDIMENSION col;
  157171. JDIMENSION width = cinfo->output_width;
  157172. register int nc = cinfo->out_color_components;
  157173. for (row = 0; row < num_rows; row++) {
  157174. ptrin = input_buf[row];
  157175. ptrout = output_buf[row];
  157176. for (col = width; col > 0; col--) {
  157177. pixcode = 0;
  157178. for (ci = 0; ci < nc; ci++) {
  157179. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  157180. }
  157181. *ptrout++ = (JSAMPLE) pixcode;
  157182. }
  157183. }
  157184. }
  157185. METHODDEF(void)
  157186. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157187. JSAMPARRAY output_buf, int num_rows)
  157188. {
  157189. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157190. register int pixcode;
  157191. register JSAMPROW ptrin, ptrout;
  157192. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157193. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157194. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157195. int row;
  157196. JDIMENSION col;
  157197. JDIMENSION width = cinfo->output_width;
  157198. for (row = 0; row < num_rows; row++) {
  157199. ptrin = input_buf[row];
  157200. ptrout = output_buf[row];
  157201. for (col = width; col > 0; col--) {
  157202. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  157203. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  157204. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  157205. *ptrout++ = (JSAMPLE) pixcode;
  157206. }
  157207. }
  157208. }
  157209. METHODDEF(void)
  157210. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157211. JSAMPARRAY output_buf, int num_rows)
  157212. {
  157213. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157214. register JSAMPROW input_ptr;
  157215. register JSAMPROW output_ptr;
  157216. JSAMPROW colorindex_ci;
  157217. int * dither; /* points to active row of dither matrix */
  157218. int row_index, col_index; /* current indexes into dither matrix */
  157219. int nc = cinfo->out_color_components;
  157220. int ci;
  157221. int row;
  157222. JDIMENSION col;
  157223. JDIMENSION width = cinfo->output_width;
  157224. for (row = 0; row < num_rows; row++) {
  157225. jzero_far((void FAR *) output_buf[row],
  157226. (size_t) (width * SIZEOF(JSAMPLE)));
  157227. row_index = cquantize->row_index;
  157228. for (ci = 0; ci < nc; ci++) {
  157229. input_ptr = input_buf[row] + ci;
  157230. output_ptr = output_buf[row];
  157231. colorindex_ci = cquantize->colorindex[ci];
  157232. dither = cquantize->odither[ci][row_index];
  157233. col_index = 0;
  157234. for (col = width; col > 0; col--) {
  157235. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  157236. input_ptr += nc;
  157237. output_ptr++;
  157238. col_index = (col_index + 1) & ODITHER_MASK;
  157239. }
  157240. }
  157241. row_index = (row_index + 1) & ODITHER_MASK;
  157242. cquantize->row_index = row_index;
  157243. }
  157244. }
  157245. METHODDEF(void)
  157246. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157247. JSAMPARRAY output_buf, int num_rows)
  157248. {
  157249. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157250. register int pixcode;
  157251. register JSAMPROW input_ptr;
  157252. register JSAMPROW output_ptr;
  157253. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157254. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157255. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157256. int * dither0; /* points to active row of dither matrix */
  157257. int * dither1;
  157258. int * dither2;
  157259. int row_index, col_index; /* current indexes into dither matrix */
  157260. int row;
  157261. JDIMENSION col;
  157262. JDIMENSION width = cinfo->output_width;
  157263. for (row = 0; row < num_rows; row++) {
  157264. row_index = cquantize->row_index;
  157265. input_ptr = input_buf[row];
  157266. output_ptr = output_buf[row];
  157267. dither0 = cquantize->odither[0][row_index];
  157268. dither1 = cquantize->odither[1][row_index];
  157269. dither2 = cquantize->odither[2][row_index];
  157270. col_index = 0;
  157271. for (col = width; col > 0; col--) {
  157272. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  157273. dither0[col_index]]);
  157274. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  157275. dither1[col_index]]);
  157276. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  157277. dither2[col_index]]);
  157278. *output_ptr++ = (JSAMPLE) pixcode;
  157279. col_index = (col_index + 1) & ODITHER_MASK;
  157280. }
  157281. row_index = (row_index + 1) & ODITHER_MASK;
  157282. cquantize->row_index = row_index;
  157283. }
  157284. }
  157285. METHODDEF(void)
  157286. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157287. JSAMPARRAY output_buf, int num_rows)
  157288. {
  157289. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157290. register LOCFSERROR cur; /* current error or pixel value */
  157291. LOCFSERROR belowerr; /* error for pixel below cur */
  157292. LOCFSERROR bpreverr; /* error for below/prev col */
  157293. LOCFSERROR bnexterr; /* error for below/next col */
  157294. LOCFSERROR delta;
  157295. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157296. register JSAMPROW input_ptr;
  157297. register JSAMPROW output_ptr;
  157298. JSAMPROW colorindex_ci;
  157299. JSAMPROW colormap_ci;
  157300. int pixcode;
  157301. int nc = cinfo->out_color_components;
  157302. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157303. int dirnc; /* dir * nc */
  157304. int ci;
  157305. int row;
  157306. JDIMENSION col;
  157307. JDIMENSION width = cinfo->output_width;
  157308. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157309. SHIFT_TEMPS
  157310. for (row = 0; row < num_rows; row++) {
  157311. jzero_far((void FAR *) output_buf[row],
  157312. (size_t) (width * SIZEOF(JSAMPLE)));
  157313. for (ci = 0; ci < nc; ci++) {
  157314. input_ptr = input_buf[row] + ci;
  157315. output_ptr = output_buf[row];
  157316. if (cquantize->on_odd_row) {
  157317. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157318. output_ptr += width-1;
  157319. dir = -1;
  157320. dirnc = -nc;
  157321. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157322. } else {
  157323. dir = 1;
  157324. dirnc = nc;
  157325. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157326. }
  157327. colorindex_ci = cquantize->colorindex[ci];
  157328. colormap_ci = cquantize->sv_colormap[ci];
  157329. cur = 0;
  157330. belowerr = bpreverr = 0;
  157331. for (col = width; col > 0; col--) {
  157332. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157333. cur += GETJSAMPLE(*input_ptr);
  157334. cur = GETJSAMPLE(range_limit[cur]);
  157335. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157336. *output_ptr += (JSAMPLE) pixcode;
  157337. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157338. bnexterr = cur;
  157339. delta = cur * 2;
  157340. cur += delta; /* form error * 3 */
  157341. errorptr[0] = (FSERROR) (bpreverr + cur);
  157342. cur += delta; /* form error * 5 */
  157343. bpreverr = belowerr + cur;
  157344. belowerr = bnexterr;
  157345. cur += delta; /* form error * 7 */
  157346. input_ptr += dirnc; /* advance input ptr to next column */
  157347. output_ptr += dir; /* advance output ptr to next column */
  157348. errorptr += dir; /* advance errorptr to current column */
  157349. }
  157350. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157351. }
  157352. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157353. }
  157354. }
  157355. LOCAL(void)
  157356. alloc_fs_workspace (j_decompress_ptr cinfo)
  157357. {
  157358. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157359. size_t arraysize;
  157360. int i;
  157361. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157362. for (i = 0; i < cinfo->out_color_components; i++) {
  157363. cquantize->fserrors[i] = (FSERRPTR)
  157364. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157365. }
  157366. }
  157367. METHODDEF(void)
  157368. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157369. {
  157370. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157371. size_t arraysize;
  157372. int i;
  157373. cinfo->colormap = cquantize->sv_colormap;
  157374. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157375. switch (cinfo->dither_mode) {
  157376. case JDITHER_NONE:
  157377. if (cinfo->out_color_components == 3)
  157378. cquantize->pub.color_quantize = color_quantize3;
  157379. else
  157380. cquantize->pub.color_quantize = color_quantize;
  157381. break;
  157382. case JDITHER_ORDERED:
  157383. if (cinfo->out_color_components == 3)
  157384. cquantize->pub.color_quantize = quantize3_ord_dither;
  157385. else
  157386. cquantize->pub.color_quantize = quantize_ord_dither;
  157387. cquantize->row_index = 0; /* initialize state for ordered dither */
  157388. if (! cquantize->is_padded)
  157389. create_colorindex(cinfo);
  157390. if (cquantize->odither[0] == NULL)
  157391. create_odither_tables(cinfo);
  157392. break;
  157393. case JDITHER_FS:
  157394. cquantize->pub.color_quantize = quantize_fs_dither;
  157395. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157396. if (cquantize->fserrors[0] == NULL)
  157397. alloc_fs_workspace(cinfo);
  157398. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157399. for (i = 0; i < cinfo->out_color_components; i++)
  157400. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157401. break;
  157402. default:
  157403. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157404. break;
  157405. }
  157406. }
  157407. METHODDEF(void)
  157408. finish_pass_1_quant (j_decompress_ptr cinfo)
  157409. {
  157410. }
  157411. METHODDEF(void)
  157412. new_color_map_1_quant (j_decompress_ptr cinfo)
  157413. {
  157414. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157415. }
  157416. GLOBAL(void)
  157417. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157418. {
  157419. my_cquantize_ptr cquantize;
  157420. cquantize = (my_cquantize_ptr)
  157421. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157422. SIZEOF(my_cquantizer));
  157423. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157424. cquantize->pub.start_pass = start_pass_1_quant;
  157425. cquantize->pub.finish_pass = finish_pass_1_quant;
  157426. cquantize->pub.new_color_map = new_color_map_1_quant;
  157427. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157428. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157429. if (cinfo->out_color_components > MAX_Q_COMPS)
  157430. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157431. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157432. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157433. create_colormap(cinfo);
  157434. create_colorindex(cinfo);
  157435. if (cinfo->dither_mode == JDITHER_FS)
  157436. alloc_fs_workspace(cinfo);
  157437. }
  157438. #endif /* QUANT_1PASS_SUPPORTED */
  157439. /*** End of inlined file: jquant1.c ***/
  157440. /*** Start of inlined file: jquant2.c ***/
  157441. #define JPEG_INTERNALS
  157442. #ifdef QUANT_2PASS_SUPPORTED
  157443. #define R_SCALE 2 /* scale R distances by this much */
  157444. #define G_SCALE 3 /* scale G distances by this much */
  157445. #define B_SCALE 1 /* and B by this much */
  157446. #if RGB_RED == 0
  157447. #define C0_SCALE R_SCALE
  157448. #endif
  157449. #if RGB_BLUE == 0
  157450. #define C0_SCALE B_SCALE
  157451. #endif
  157452. #if RGB_GREEN == 1
  157453. #define C1_SCALE G_SCALE
  157454. #endif
  157455. #if RGB_RED == 2
  157456. #define C2_SCALE R_SCALE
  157457. #endif
  157458. #if RGB_BLUE == 2
  157459. #define C2_SCALE B_SCALE
  157460. #endif
  157461. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157462. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157463. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157464. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157465. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157466. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157467. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157468. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157469. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157470. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157471. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157472. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157473. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157474. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157475. typedef hist2d * hist3d; /* type for top-level pointer */
  157476. #if BITS_IN_JSAMPLE == 8
  157477. typedef INT16 FSERROR; /* 16 bits should be enough */
  157478. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157479. #else
  157480. typedef INT32 FSERROR; /* may need more than 16 bits */
  157481. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157482. #endif
  157483. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157484. typedef struct {
  157485. struct jpeg_color_quantizer pub; /* public fields */
  157486. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157487. int desired; /* desired # of colors = size of colormap */
  157488. hist3d histogram; /* pointer to the histogram */
  157489. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157490. FSERRPTR fserrors; /* accumulated errors */
  157491. boolean on_odd_row; /* flag to remember which row we are on */
  157492. int * error_limiter; /* table for clamping the applied error */
  157493. } my_cquantizer2;
  157494. typedef my_cquantizer2 * my_cquantize_ptr2;
  157495. METHODDEF(void)
  157496. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157497. JSAMPARRAY output_buf, int num_rows)
  157498. {
  157499. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157500. register JSAMPROW ptr;
  157501. register histptr histp;
  157502. register hist3d histogram = cquantize->histogram;
  157503. int row;
  157504. JDIMENSION col;
  157505. JDIMENSION width = cinfo->output_width;
  157506. for (row = 0; row < num_rows; row++) {
  157507. ptr = input_buf[row];
  157508. for (col = width; col > 0; col--) {
  157509. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157510. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157511. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157512. if (++(*histp) <= 0)
  157513. (*histp)--;
  157514. ptr += 3;
  157515. }
  157516. }
  157517. }
  157518. typedef struct {
  157519. int c0min, c0max;
  157520. int c1min, c1max;
  157521. int c2min, c2max;
  157522. INT32 volume;
  157523. long colorcount;
  157524. } box;
  157525. typedef box * boxptr;
  157526. LOCAL(boxptr)
  157527. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157528. {
  157529. register boxptr boxp;
  157530. register int i;
  157531. register long maxc = 0;
  157532. boxptr which = NULL;
  157533. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157534. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157535. which = boxp;
  157536. maxc = boxp->colorcount;
  157537. }
  157538. }
  157539. return which;
  157540. }
  157541. LOCAL(boxptr)
  157542. find_biggest_volume (boxptr boxlist, int numboxes)
  157543. {
  157544. register boxptr boxp;
  157545. register int i;
  157546. register INT32 maxv = 0;
  157547. boxptr which = NULL;
  157548. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157549. if (boxp->volume > maxv) {
  157550. which = boxp;
  157551. maxv = boxp->volume;
  157552. }
  157553. }
  157554. return which;
  157555. }
  157556. LOCAL(void)
  157557. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157558. {
  157559. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157560. hist3d histogram = cquantize->histogram;
  157561. histptr histp;
  157562. int c0,c1,c2;
  157563. int c0min,c0max,c1min,c1max,c2min,c2max;
  157564. INT32 dist0,dist1,dist2;
  157565. long ccount;
  157566. c0min = boxp->c0min; c0max = boxp->c0max;
  157567. c1min = boxp->c1min; c1max = boxp->c1max;
  157568. c2min = boxp->c2min; c2max = boxp->c2max;
  157569. if (c0max > c0min)
  157570. for (c0 = c0min; c0 <= c0max; c0++)
  157571. for (c1 = c1min; c1 <= c1max; c1++) {
  157572. histp = & histogram[c0][c1][c2min];
  157573. for (c2 = c2min; c2 <= c2max; c2++)
  157574. if (*histp++ != 0) {
  157575. boxp->c0min = c0min = c0;
  157576. goto have_c0min;
  157577. }
  157578. }
  157579. have_c0min:
  157580. if (c0max > c0min)
  157581. for (c0 = c0max; c0 >= c0min; c0--)
  157582. for (c1 = c1min; c1 <= c1max; c1++) {
  157583. histp = & histogram[c0][c1][c2min];
  157584. for (c2 = c2min; c2 <= c2max; c2++)
  157585. if (*histp++ != 0) {
  157586. boxp->c0max = c0max = c0;
  157587. goto have_c0max;
  157588. }
  157589. }
  157590. have_c0max:
  157591. if (c1max > c1min)
  157592. for (c1 = c1min; c1 <= c1max; c1++)
  157593. for (c0 = c0min; c0 <= c0max; c0++) {
  157594. histp = & histogram[c0][c1][c2min];
  157595. for (c2 = c2min; c2 <= c2max; c2++)
  157596. if (*histp++ != 0) {
  157597. boxp->c1min = c1min = c1;
  157598. goto have_c1min;
  157599. }
  157600. }
  157601. have_c1min:
  157602. if (c1max > c1min)
  157603. for (c1 = c1max; c1 >= c1min; c1--)
  157604. for (c0 = c0min; c0 <= c0max; c0++) {
  157605. histp = & histogram[c0][c1][c2min];
  157606. for (c2 = c2min; c2 <= c2max; c2++)
  157607. if (*histp++ != 0) {
  157608. boxp->c1max = c1max = c1;
  157609. goto have_c1max;
  157610. }
  157611. }
  157612. have_c1max:
  157613. if (c2max > c2min)
  157614. for (c2 = c2min; c2 <= c2max; c2++)
  157615. for (c0 = c0min; c0 <= c0max; c0++) {
  157616. histp = & histogram[c0][c1min][c2];
  157617. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157618. if (*histp != 0) {
  157619. boxp->c2min = c2min = c2;
  157620. goto have_c2min;
  157621. }
  157622. }
  157623. have_c2min:
  157624. if (c2max > c2min)
  157625. for (c2 = c2max; c2 >= c2min; c2--)
  157626. for (c0 = c0min; c0 <= c0max; c0++) {
  157627. histp = & histogram[c0][c1min][c2];
  157628. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157629. if (*histp != 0) {
  157630. boxp->c2max = c2max = c2;
  157631. goto have_c2max;
  157632. }
  157633. }
  157634. have_c2max:
  157635. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157636. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157637. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157638. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157639. ccount = 0;
  157640. for (c0 = c0min; c0 <= c0max; c0++)
  157641. for (c1 = c1min; c1 <= c1max; c1++) {
  157642. histp = & histogram[c0][c1][c2min];
  157643. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  157644. if (*histp != 0) {
  157645. ccount++;
  157646. }
  157647. }
  157648. boxp->colorcount = ccount;
  157649. }
  157650. LOCAL(int)
  157651. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157652. int desired_colors)
  157653. {
  157654. int n,lb;
  157655. int c0,c1,c2,cmax;
  157656. register boxptr b1,b2;
  157657. while (numboxes < desired_colors) {
  157658. if (numboxes*2 <= desired_colors) {
  157659. b1 = find_biggest_color_pop(boxlist, numboxes);
  157660. } else {
  157661. b1 = find_biggest_volume(boxlist, numboxes);
  157662. }
  157663. if (b1 == NULL) /* no splittable boxes left! */
  157664. break;
  157665. b2 = &boxlist[numboxes]; /* where new box will go */
  157666. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157667. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157668. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157669. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  157670. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  157671. #if RGB_RED == 0
  157672. cmax = c1; n = 1;
  157673. if (c0 > cmax) { cmax = c0; n = 0; }
  157674. if (c2 > cmax) { n = 2; }
  157675. #else
  157676. cmax = c1; n = 1;
  157677. if (c2 > cmax) { cmax = c2; n = 2; }
  157678. if (c0 > cmax) { n = 0; }
  157679. #endif
  157680. switch (n) {
  157681. case 0:
  157682. lb = (b1->c0max + b1->c0min) / 2;
  157683. b1->c0max = lb;
  157684. b2->c0min = lb+1;
  157685. break;
  157686. case 1:
  157687. lb = (b1->c1max + b1->c1min) / 2;
  157688. b1->c1max = lb;
  157689. b2->c1min = lb+1;
  157690. break;
  157691. case 2:
  157692. lb = (b1->c2max + b1->c2min) / 2;
  157693. b1->c2max = lb;
  157694. b2->c2min = lb+1;
  157695. break;
  157696. }
  157697. update_box(cinfo, b1);
  157698. update_box(cinfo, b2);
  157699. numboxes++;
  157700. }
  157701. return numboxes;
  157702. }
  157703. LOCAL(void)
  157704. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  157705. {
  157706. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157707. hist3d histogram = cquantize->histogram;
  157708. histptr histp;
  157709. int c0,c1,c2;
  157710. int c0min,c0max,c1min,c1max,c2min,c2max;
  157711. long count;
  157712. long total = 0;
  157713. long c0total = 0;
  157714. long c1total = 0;
  157715. long c2total = 0;
  157716. c0min = boxp->c0min; c0max = boxp->c0max;
  157717. c1min = boxp->c1min; c1max = boxp->c1max;
  157718. c2min = boxp->c2min; c2max = boxp->c2max;
  157719. for (c0 = c0min; c0 <= c0max; c0++)
  157720. for (c1 = c1min; c1 <= c1max; c1++) {
  157721. histp = & histogram[c0][c1][c2min];
  157722. for (c2 = c2min; c2 <= c2max; c2++) {
  157723. if ((count = *histp++) != 0) {
  157724. total += count;
  157725. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  157726. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  157727. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  157728. }
  157729. }
  157730. }
  157731. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  157732. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  157733. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  157734. }
  157735. LOCAL(void)
  157736. select_colors (j_decompress_ptr cinfo, int desired_colors)
  157737. {
  157738. boxptr boxlist;
  157739. int numboxes;
  157740. int i;
  157741. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  157742. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  157743. numboxes = 1;
  157744. boxlist[0].c0min = 0;
  157745. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  157746. boxlist[0].c1min = 0;
  157747. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  157748. boxlist[0].c2min = 0;
  157749. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  157750. update_box(cinfo, & boxlist[0]);
  157751. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  157752. for (i = 0; i < numboxes; i++)
  157753. compute_color(cinfo, & boxlist[i], i);
  157754. cinfo->actual_number_of_colors = numboxes;
  157755. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  157756. }
  157757. #define BOX_C0_LOG (HIST_C0_BITS-3)
  157758. #define BOX_C1_LOG (HIST_C1_BITS-3)
  157759. #define BOX_C2_LOG (HIST_C2_BITS-3)
  157760. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  157761. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  157762. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  157763. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  157764. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  157765. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  157766. LOCAL(int)
  157767. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157768. JSAMPLE colorlist[])
  157769. {
  157770. int numcolors = cinfo->actual_number_of_colors;
  157771. int maxc0, maxc1, maxc2;
  157772. int centerc0, centerc1, centerc2;
  157773. int i, x, ncolors;
  157774. INT32 minmaxdist, min_dist, max_dist, tdist;
  157775. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  157776. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  157777. centerc0 = (minc0 + maxc0) >> 1;
  157778. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  157779. centerc1 = (minc1 + maxc1) >> 1;
  157780. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  157781. centerc2 = (minc2 + maxc2) >> 1;
  157782. minmaxdist = 0x7FFFFFFFL;
  157783. for (i = 0; i < numcolors; i++) {
  157784. x = GETJSAMPLE(cinfo->colormap[0][i]);
  157785. if (x < minc0) {
  157786. tdist = (x - minc0) * C0_SCALE;
  157787. min_dist = tdist*tdist;
  157788. tdist = (x - maxc0) * C0_SCALE;
  157789. max_dist = tdist*tdist;
  157790. } else if (x > maxc0) {
  157791. tdist = (x - maxc0) * C0_SCALE;
  157792. min_dist = tdist*tdist;
  157793. tdist = (x - minc0) * C0_SCALE;
  157794. max_dist = tdist*tdist;
  157795. } else {
  157796. min_dist = 0;
  157797. if (x <= centerc0) {
  157798. tdist = (x - maxc0) * C0_SCALE;
  157799. max_dist = tdist*tdist;
  157800. } else {
  157801. tdist = (x - minc0) * C0_SCALE;
  157802. max_dist = tdist*tdist;
  157803. }
  157804. }
  157805. x = GETJSAMPLE(cinfo->colormap[1][i]);
  157806. if (x < minc1) {
  157807. tdist = (x - minc1) * C1_SCALE;
  157808. min_dist += tdist*tdist;
  157809. tdist = (x - maxc1) * C1_SCALE;
  157810. max_dist += tdist*tdist;
  157811. } else if (x > maxc1) {
  157812. tdist = (x - maxc1) * C1_SCALE;
  157813. min_dist += tdist*tdist;
  157814. tdist = (x - minc1) * C1_SCALE;
  157815. max_dist += tdist*tdist;
  157816. } else {
  157817. if (x <= centerc1) {
  157818. tdist = (x - maxc1) * C1_SCALE;
  157819. max_dist += tdist*tdist;
  157820. } else {
  157821. tdist = (x - minc1) * C1_SCALE;
  157822. max_dist += tdist*tdist;
  157823. }
  157824. }
  157825. x = GETJSAMPLE(cinfo->colormap[2][i]);
  157826. if (x < minc2) {
  157827. tdist = (x - minc2) * C2_SCALE;
  157828. min_dist += tdist*tdist;
  157829. tdist = (x - maxc2) * C2_SCALE;
  157830. max_dist += tdist*tdist;
  157831. } else if (x > maxc2) {
  157832. tdist = (x - maxc2) * C2_SCALE;
  157833. min_dist += tdist*tdist;
  157834. tdist = (x - minc2) * C2_SCALE;
  157835. max_dist += tdist*tdist;
  157836. } else {
  157837. if (x <= centerc2) {
  157838. tdist = (x - maxc2) * C2_SCALE;
  157839. max_dist += tdist*tdist;
  157840. } else {
  157841. tdist = (x - minc2) * C2_SCALE;
  157842. max_dist += tdist*tdist;
  157843. }
  157844. }
  157845. mindist[i] = min_dist; /* save away the results */
  157846. if (max_dist < minmaxdist)
  157847. minmaxdist = max_dist;
  157848. }
  157849. ncolors = 0;
  157850. for (i = 0; i < numcolors; i++) {
  157851. if (mindist[i] <= minmaxdist)
  157852. colorlist[ncolors++] = (JSAMPLE) i;
  157853. }
  157854. return ncolors;
  157855. }
  157856. LOCAL(void)
  157857. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157858. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  157859. {
  157860. int ic0, ic1, ic2;
  157861. int i, icolor;
  157862. register INT32 * bptr; /* pointer into bestdist[] array */
  157863. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157864. INT32 dist0, dist1; /* initial distance values */
  157865. register INT32 dist2; /* current distance in inner loop */
  157866. INT32 xx0, xx1; /* distance increments */
  157867. register INT32 xx2;
  157868. INT32 inc0, inc1, inc2; /* initial values for increments */
  157869. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157870. bptr = bestdist;
  157871. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  157872. *bptr++ = 0x7FFFFFFFL;
  157873. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  157874. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  157875. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  157876. for (i = 0; i < numcolors; i++) {
  157877. icolor = GETJSAMPLE(colorlist[i]);
  157878. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  157879. dist0 = inc0*inc0;
  157880. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  157881. dist0 += inc1*inc1;
  157882. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  157883. dist0 += inc2*inc2;
  157884. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  157885. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  157886. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  157887. bptr = bestdist;
  157888. cptr = bestcolor;
  157889. xx0 = inc0;
  157890. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  157891. dist1 = dist0;
  157892. xx1 = inc1;
  157893. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  157894. dist2 = dist1;
  157895. xx2 = inc2;
  157896. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  157897. if (dist2 < *bptr) {
  157898. *bptr = dist2;
  157899. *cptr = (JSAMPLE) icolor;
  157900. }
  157901. dist2 += xx2;
  157902. xx2 += 2 * STEP_C2 * STEP_C2;
  157903. bptr++;
  157904. cptr++;
  157905. }
  157906. dist1 += xx1;
  157907. xx1 += 2 * STEP_C1 * STEP_C1;
  157908. }
  157909. dist0 += xx0;
  157910. xx0 += 2 * STEP_C0 * STEP_C0;
  157911. }
  157912. }
  157913. }
  157914. LOCAL(void)
  157915. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  157916. {
  157917. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157918. hist3d histogram = cquantize->histogram;
  157919. int minc0, minc1, minc2; /* lower left corner of update box */
  157920. int ic0, ic1, ic2;
  157921. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157922. register histptr cachep; /* pointer into main cache array */
  157923. JSAMPLE colorlist[MAXNUMCOLORS];
  157924. int numcolors; /* number of candidate colors */
  157925. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157926. c0 >>= BOX_C0_LOG;
  157927. c1 >>= BOX_C1_LOG;
  157928. c2 >>= BOX_C2_LOG;
  157929. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  157930. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  157931. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  157932. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  157933. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  157934. bestcolor);
  157935. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  157936. c1 <<= BOX_C1_LOG;
  157937. c2 <<= BOX_C2_LOG;
  157938. cptr = bestcolor;
  157939. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  157940. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  157941. cachep = & histogram[c0+ic0][c1+ic1][c2];
  157942. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  157943. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  157944. }
  157945. }
  157946. }
  157947. }
  157948. METHODDEF(void)
  157949. pass2_no_dither (j_decompress_ptr cinfo,
  157950. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157951. {
  157952. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157953. hist3d histogram = cquantize->histogram;
  157954. register JSAMPROW inptr, outptr;
  157955. register histptr cachep;
  157956. register int c0, c1, c2;
  157957. int row;
  157958. JDIMENSION col;
  157959. JDIMENSION width = cinfo->output_width;
  157960. for (row = 0; row < num_rows; row++) {
  157961. inptr = input_buf[row];
  157962. outptr = output_buf[row];
  157963. for (col = width; col > 0; col--) {
  157964. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  157965. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  157966. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  157967. cachep = & histogram[c0][c1][c2];
  157968. if (*cachep == 0)
  157969. fill_inverse_cmap(cinfo, c0,c1,c2);
  157970. *outptr++ = (JSAMPLE) (*cachep - 1);
  157971. }
  157972. }
  157973. }
  157974. METHODDEF(void)
  157975. pass2_fs_dither (j_decompress_ptr cinfo,
  157976. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157977. {
  157978. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157979. hist3d histogram = cquantize->histogram;
  157980. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  157981. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  157982. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  157983. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157984. JSAMPROW inptr; /* => current input pixel */
  157985. JSAMPROW outptr; /* => current output pixel */
  157986. histptr cachep;
  157987. int dir; /* +1 or -1 depending on direction */
  157988. int dir3; /* 3*dir, for advancing inptr & errorptr */
  157989. int row;
  157990. JDIMENSION col;
  157991. JDIMENSION width = cinfo->output_width;
  157992. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157993. int *error_limit = cquantize->error_limiter;
  157994. JSAMPROW colormap0 = cinfo->colormap[0];
  157995. JSAMPROW colormap1 = cinfo->colormap[1];
  157996. JSAMPROW colormap2 = cinfo->colormap[2];
  157997. SHIFT_TEMPS
  157998. for (row = 0; row < num_rows; row++) {
  157999. inptr = input_buf[row];
  158000. outptr = output_buf[row];
  158001. if (cquantize->on_odd_row) {
  158002. inptr += (width-1) * 3; /* so point to rightmost pixel */
  158003. outptr += width-1;
  158004. dir = -1;
  158005. dir3 = -3;
  158006. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  158007. cquantize->on_odd_row = FALSE; /* flip for next time */
  158008. } else {
  158009. dir = 1;
  158010. dir3 = 3;
  158011. errorptr = cquantize->fserrors; /* => entry before first real column */
  158012. cquantize->on_odd_row = TRUE; /* flip for next time */
  158013. }
  158014. cur0 = cur1 = cur2 = 0;
  158015. belowerr0 = belowerr1 = belowerr2 = 0;
  158016. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  158017. for (col = width; col > 0; col--) {
  158018. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  158019. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  158020. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  158021. cur0 = error_limit[cur0];
  158022. cur1 = error_limit[cur1];
  158023. cur2 = error_limit[cur2];
  158024. cur0 += GETJSAMPLE(inptr[0]);
  158025. cur1 += GETJSAMPLE(inptr[1]);
  158026. cur2 += GETJSAMPLE(inptr[2]);
  158027. cur0 = GETJSAMPLE(range_limit[cur0]);
  158028. cur1 = GETJSAMPLE(range_limit[cur1]);
  158029. cur2 = GETJSAMPLE(range_limit[cur2]);
  158030. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  158031. if (*cachep == 0)
  158032. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  158033. { register int pixcode = *cachep - 1;
  158034. *outptr = (JSAMPLE) pixcode;
  158035. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  158036. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  158037. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  158038. }
  158039. { register LOCFSERROR bnexterr, delta;
  158040. bnexterr = cur0; /* Process component 0 */
  158041. delta = cur0 * 2;
  158042. cur0 += delta; /* form error * 3 */
  158043. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  158044. cur0 += delta; /* form error * 5 */
  158045. bpreverr0 = belowerr0 + cur0;
  158046. belowerr0 = bnexterr;
  158047. cur0 += delta; /* form error * 7 */
  158048. bnexterr = cur1; /* Process component 1 */
  158049. delta = cur1 * 2;
  158050. cur1 += delta; /* form error * 3 */
  158051. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  158052. cur1 += delta; /* form error * 5 */
  158053. bpreverr1 = belowerr1 + cur1;
  158054. belowerr1 = bnexterr;
  158055. cur1 += delta; /* form error * 7 */
  158056. bnexterr = cur2; /* Process component 2 */
  158057. delta = cur2 * 2;
  158058. cur2 += delta; /* form error * 3 */
  158059. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  158060. cur2 += delta; /* form error * 5 */
  158061. bpreverr2 = belowerr2 + cur2;
  158062. belowerr2 = bnexterr;
  158063. cur2 += delta; /* form error * 7 */
  158064. }
  158065. inptr += dir3; /* Advance pixel pointers to next column */
  158066. outptr += dir;
  158067. errorptr += dir3; /* advance errorptr to current column */
  158068. }
  158069. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  158070. errorptr[1] = (FSERROR) bpreverr1;
  158071. errorptr[2] = (FSERROR) bpreverr2;
  158072. }
  158073. }
  158074. LOCAL(void)
  158075. init_error_limit (j_decompress_ptr cinfo)
  158076. {
  158077. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158078. int * table;
  158079. int in, out;
  158080. table = (int *) (*cinfo->mem->alloc_small)
  158081. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  158082. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  158083. cquantize->error_limiter = table;
  158084. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  158085. out = 0;
  158086. for (in = 0; in < STEPSIZE; in++, out++) {
  158087. table[in] = out; table[-in] = -out;
  158088. }
  158089. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  158090. table[in] = out; table[-in] = -out;
  158091. }
  158092. for (; in <= MAXJSAMPLE; in++) {
  158093. table[in] = out; table[-in] = -out;
  158094. }
  158095. #undef STEPSIZE
  158096. }
  158097. METHODDEF(void)
  158098. finish_pass1 (j_decompress_ptr cinfo)
  158099. {
  158100. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158101. cinfo->colormap = cquantize->sv_colormap;
  158102. select_colors(cinfo, cquantize->desired);
  158103. cquantize->needs_zeroed = TRUE;
  158104. }
  158105. METHODDEF(void)
  158106. finish_pass2 (j_decompress_ptr cinfo)
  158107. {
  158108. }
  158109. METHODDEF(void)
  158110. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  158111. {
  158112. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158113. hist3d histogram = cquantize->histogram;
  158114. int i;
  158115. if (cinfo->dither_mode != JDITHER_NONE)
  158116. cinfo->dither_mode = JDITHER_FS;
  158117. if (is_pre_scan) {
  158118. cquantize->pub.color_quantize = prescan_quantize;
  158119. cquantize->pub.finish_pass = finish_pass1;
  158120. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  158121. } else {
  158122. if (cinfo->dither_mode == JDITHER_FS)
  158123. cquantize->pub.color_quantize = pass2_fs_dither;
  158124. else
  158125. cquantize->pub.color_quantize = pass2_no_dither;
  158126. cquantize->pub.finish_pass = finish_pass2;
  158127. i = cinfo->actual_number_of_colors;
  158128. if (i < 1)
  158129. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  158130. if (i > MAXNUMCOLORS)
  158131. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158132. if (cinfo->dither_mode == JDITHER_FS) {
  158133. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  158134. (3 * SIZEOF(FSERROR)));
  158135. if (cquantize->fserrors == NULL)
  158136. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158137. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  158138. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  158139. if (cquantize->error_limiter == NULL)
  158140. init_error_limit(cinfo);
  158141. cquantize->on_odd_row = FALSE;
  158142. }
  158143. }
  158144. if (cquantize->needs_zeroed) {
  158145. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158146. jzero_far((void FAR *) histogram[i],
  158147. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158148. }
  158149. cquantize->needs_zeroed = FALSE;
  158150. }
  158151. }
  158152. METHODDEF(void)
  158153. new_color_map_2_quant (j_decompress_ptr cinfo)
  158154. {
  158155. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158156. cquantize->needs_zeroed = TRUE;
  158157. }
  158158. GLOBAL(void)
  158159. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  158160. {
  158161. my_cquantize_ptr2 cquantize;
  158162. int i;
  158163. cquantize = (my_cquantize_ptr2)
  158164. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158165. SIZEOF(my_cquantizer2));
  158166. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  158167. cquantize->pub.start_pass = start_pass_2_quant;
  158168. cquantize->pub.new_color_map = new_color_map_2_quant;
  158169. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  158170. cquantize->error_limiter = NULL;
  158171. if (cinfo->out_color_components != 3)
  158172. ERREXIT(cinfo, JERR_NOTIMPL);
  158173. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  158174. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  158175. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158176. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  158177. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158178. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158179. }
  158180. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  158181. if (cinfo->enable_2pass_quant) {
  158182. int desired = cinfo->desired_number_of_colors;
  158183. if (desired < 8)
  158184. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  158185. if (desired > MAXNUMCOLORS)
  158186. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158187. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  158188. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  158189. cquantize->desired = desired;
  158190. } else
  158191. cquantize->sv_colormap = NULL;
  158192. if (cinfo->dither_mode != JDITHER_NONE)
  158193. cinfo->dither_mode = JDITHER_FS;
  158194. if (cinfo->dither_mode == JDITHER_FS) {
  158195. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158196. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158197. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  158198. init_error_limit(cinfo);
  158199. }
  158200. }
  158201. #endif /* QUANT_2PASS_SUPPORTED */
  158202. /*** End of inlined file: jquant2.c ***/
  158203. /*** Start of inlined file: jutils.c ***/
  158204. #define JPEG_INTERNALS
  158205. #if 0 /* This table is not actually needed in v6a */
  158206. const int jpeg_zigzag_order[DCTSIZE2] = {
  158207. 0, 1, 5, 6, 14, 15, 27, 28,
  158208. 2, 4, 7, 13, 16, 26, 29, 42,
  158209. 3, 8, 12, 17, 25, 30, 41, 43,
  158210. 9, 11, 18, 24, 31, 40, 44, 53,
  158211. 10, 19, 23, 32, 39, 45, 52, 54,
  158212. 20, 22, 33, 38, 46, 51, 55, 60,
  158213. 21, 34, 37, 47, 50, 56, 59, 61,
  158214. 35, 36, 48, 49, 57, 58, 62, 63
  158215. };
  158216. #endif
  158217. const int jpeg_natural_order[DCTSIZE2+16] = {
  158218. 0, 1, 8, 16, 9, 2, 3, 10,
  158219. 17, 24, 32, 25, 18, 11, 4, 5,
  158220. 12, 19, 26, 33, 40, 48, 41, 34,
  158221. 27, 20, 13, 6, 7, 14, 21, 28,
  158222. 35, 42, 49, 56, 57, 50, 43, 36,
  158223. 29, 22, 15, 23, 30, 37, 44, 51,
  158224. 58, 59, 52, 45, 38, 31, 39, 46,
  158225. 53, 60, 61, 54, 47, 55, 62, 63,
  158226. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  158227. 63, 63, 63, 63, 63, 63, 63, 63
  158228. };
  158229. GLOBAL(long)
  158230. jdiv_round_up (long a, long b)
  158231. {
  158232. return (a + b - 1L) / b;
  158233. }
  158234. GLOBAL(long)
  158235. jround_up (long a, long b)
  158236. {
  158237. a += b - 1L;
  158238. return a - (a % b);
  158239. }
  158240. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  158241. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  158242. #define FMEMZERO(target,size) MEMZERO(target,size)
  158243. #else /* 80x86 case, define if we can */
  158244. #ifdef USE_FMEM
  158245. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  158246. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  158247. #endif
  158248. #endif
  158249. GLOBAL(void)
  158250. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  158251. JSAMPARRAY output_array, int dest_row,
  158252. int num_rows, JDIMENSION num_cols)
  158253. {
  158254. register JSAMPROW inptr, outptr;
  158255. #ifdef FMEMCOPY
  158256. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  158257. #else
  158258. register JDIMENSION count;
  158259. #endif
  158260. register int row;
  158261. input_array += source_row;
  158262. output_array += dest_row;
  158263. for (row = num_rows; row > 0; row--) {
  158264. inptr = *input_array++;
  158265. outptr = *output_array++;
  158266. #ifdef FMEMCOPY
  158267. FMEMCOPY(outptr, inptr, count);
  158268. #else
  158269. for (count = num_cols; count > 0; count--)
  158270. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  158271. #endif
  158272. }
  158273. }
  158274. GLOBAL(void)
  158275. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  158276. JDIMENSION num_blocks)
  158277. {
  158278. #ifdef FMEMCOPY
  158279. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158280. #else
  158281. register JCOEFPTR inptr, outptr;
  158282. register long count;
  158283. inptr = (JCOEFPTR) input_row;
  158284. outptr = (JCOEFPTR) output_row;
  158285. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158286. *outptr++ = *inptr++;
  158287. }
  158288. #endif
  158289. }
  158290. GLOBAL(void)
  158291. jzero_far (void FAR * target, size_t bytestozero)
  158292. {
  158293. #ifdef FMEMZERO
  158294. FMEMZERO(target, bytestozero);
  158295. #else
  158296. register char FAR * ptr = (char FAR *) target;
  158297. register size_t count;
  158298. for (count = bytestozero; count > 0; count--) {
  158299. *ptr++ = 0;
  158300. }
  158301. #endif
  158302. }
  158303. /*** End of inlined file: jutils.c ***/
  158304. /*** Start of inlined file: transupp.c ***/
  158305. #define JPEG_INTERNALS
  158306. /*** Start of inlined file: transupp.h ***/
  158307. #ifndef TRANSFORMS_SUPPORTED
  158308. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158309. #endif
  158310. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158311. #define jtransform_request_workspace jTrRequest
  158312. #define jtransform_adjust_parameters jTrAdjust
  158313. #define jtransform_execute_transformation jTrExec
  158314. #define jcopy_markers_setup jCMrkSetup
  158315. #define jcopy_markers_execute jCMrkExec
  158316. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158317. typedef enum {
  158318. JXFORM_NONE, /* no transformation */
  158319. JXFORM_FLIP_H, /* horizontal flip */
  158320. JXFORM_FLIP_V, /* vertical flip */
  158321. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158322. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158323. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158324. JXFORM_ROT_180, /* 180-degree rotation */
  158325. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158326. } JXFORM_CODE;
  158327. typedef struct {
  158328. JXFORM_CODE transform; /* image transform operator */
  158329. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158330. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158331. int num_components; /* # of components in workspace */
  158332. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158333. } jpeg_transform_info;
  158334. #if TRANSFORMS_SUPPORTED
  158335. EXTERN(void) jtransform_request_workspace
  158336. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158337. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158338. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158339. jvirt_barray_ptr *src_coef_arrays,
  158340. jpeg_transform_info *info));
  158341. EXTERN(void) jtransform_execute_transformation
  158342. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158343. jvirt_barray_ptr *src_coef_arrays,
  158344. jpeg_transform_info *info));
  158345. #endif /* TRANSFORMS_SUPPORTED */
  158346. typedef enum {
  158347. JCOPYOPT_NONE, /* copy no optional markers */
  158348. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158349. JCOPYOPT_ALL /* copy all optional markers */
  158350. } JCOPY_OPTION;
  158351. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158352. EXTERN(void) jcopy_markers_setup
  158353. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158354. EXTERN(void) jcopy_markers_execute
  158355. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158356. JCOPY_OPTION option));
  158357. /*** End of inlined file: transupp.h ***/
  158358. /* My own external interface */
  158359. #if TRANSFORMS_SUPPORTED
  158360. LOCAL(void)
  158361. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158362. jvirt_barray_ptr *src_coef_arrays)
  158363. {
  158364. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158365. int ci, k, offset_y;
  158366. JBLOCKARRAY buffer;
  158367. JCOEFPTR ptr1, ptr2;
  158368. JCOEF temp1, temp2;
  158369. jpeg_component_info *compptr;
  158370. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158371. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158372. compptr = dstinfo->comp_info + ci;
  158373. comp_width = MCU_cols * compptr->h_samp_factor;
  158374. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158375. blk_y += compptr->v_samp_factor) {
  158376. buffer = (*srcinfo->mem->access_virt_barray)
  158377. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158378. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158379. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158380. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158381. ptr1 = buffer[offset_y][blk_x];
  158382. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158383. for (k = 0; k < DCTSIZE2; k += 2) {
  158384. temp1 = *ptr1; /* swap even column */
  158385. temp2 = *ptr2;
  158386. *ptr1++ = temp2;
  158387. *ptr2++ = temp1;
  158388. temp1 = *ptr1; /* swap odd column with sign change */
  158389. temp2 = *ptr2;
  158390. *ptr1++ = -temp2;
  158391. *ptr2++ = -temp1;
  158392. }
  158393. }
  158394. }
  158395. }
  158396. }
  158397. }
  158398. LOCAL(void)
  158399. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158400. jvirt_barray_ptr *src_coef_arrays,
  158401. jvirt_barray_ptr *dst_coef_arrays)
  158402. {
  158403. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158404. int ci, i, j, offset_y;
  158405. JBLOCKARRAY src_buffer, dst_buffer;
  158406. JBLOCKROW src_row_ptr, dst_row_ptr;
  158407. JCOEFPTR src_ptr, dst_ptr;
  158408. jpeg_component_info *compptr;
  158409. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158410. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158411. compptr = dstinfo->comp_info + ci;
  158412. comp_height = MCU_rows * compptr->v_samp_factor;
  158413. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158414. dst_blk_y += compptr->v_samp_factor) {
  158415. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158416. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158417. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158418. if (dst_blk_y < comp_height) {
  158419. src_buffer = (*srcinfo->mem->access_virt_barray)
  158420. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158421. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158422. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158423. } else {
  158424. src_buffer = (*srcinfo->mem->access_virt_barray)
  158425. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158426. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158427. }
  158428. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158429. if (dst_blk_y < comp_height) {
  158430. dst_row_ptr = dst_buffer[offset_y];
  158431. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158432. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158433. dst_blk_x++) {
  158434. dst_ptr = dst_row_ptr[dst_blk_x];
  158435. src_ptr = src_row_ptr[dst_blk_x];
  158436. for (i = 0; i < DCTSIZE; i += 2) {
  158437. for (j = 0; j < DCTSIZE; j++)
  158438. *dst_ptr++ = *src_ptr++;
  158439. for (j = 0; j < DCTSIZE; j++)
  158440. *dst_ptr++ = - *src_ptr++;
  158441. }
  158442. }
  158443. } else {
  158444. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158445. compptr->width_in_blocks);
  158446. }
  158447. }
  158448. }
  158449. }
  158450. }
  158451. LOCAL(void)
  158452. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158453. jvirt_barray_ptr *src_coef_arrays,
  158454. jvirt_barray_ptr *dst_coef_arrays)
  158455. {
  158456. JDIMENSION dst_blk_x, dst_blk_y;
  158457. int ci, i, j, offset_x, offset_y;
  158458. JBLOCKARRAY src_buffer, dst_buffer;
  158459. JCOEFPTR src_ptr, dst_ptr;
  158460. jpeg_component_info *compptr;
  158461. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158462. compptr = dstinfo->comp_info + ci;
  158463. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158464. dst_blk_y += compptr->v_samp_factor) {
  158465. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158466. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158467. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158468. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158469. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158470. dst_blk_x += compptr->h_samp_factor) {
  158471. src_buffer = (*srcinfo->mem->access_virt_barray)
  158472. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158473. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158474. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158475. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158476. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158477. for (i = 0; i < DCTSIZE; i++)
  158478. for (j = 0; j < DCTSIZE; j++)
  158479. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158480. }
  158481. }
  158482. }
  158483. }
  158484. }
  158485. }
  158486. LOCAL(void)
  158487. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158488. jvirt_barray_ptr *src_coef_arrays,
  158489. jvirt_barray_ptr *dst_coef_arrays)
  158490. {
  158491. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158492. int ci, i, j, offset_x, offset_y;
  158493. JBLOCKARRAY src_buffer, dst_buffer;
  158494. JCOEFPTR src_ptr, dst_ptr;
  158495. jpeg_component_info *compptr;
  158496. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158497. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158498. compptr = dstinfo->comp_info + ci;
  158499. comp_width = MCU_cols * compptr->h_samp_factor;
  158500. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158501. dst_blk_y += compptr->v_samp_factor) {
  158502. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158503. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158504. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158505. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158506. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158507. dst_blk_x += compptr->h_samp_factor) {
  158508. src_buffer = (*srcinfo->mem->access_virt_barray)
  158509. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158510. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158511. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158512. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158513. if (dst_blk_x < comp_width) {
  158514. dst_ptr = dst_buffer[offset_y]
  158515. [comp_width - dst_blk_x - offset_x - 1];
  158516. for (i = 0; i < DCTSIZE; i++) {
  158517. for (j = 0; j < DCTSIZE; j++)
  158518. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158519. i++;
  158520. for (j = 0; j < DCTSIZE; j++)
  158521. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158522. }
  158523. } else {
  158524. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158525. for (i = 0; i < DCTSIZE; i++)
  158526. for (j = 0; j < DCTSIZE; j++)
  158527. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158528. }
  158529. }
  158530. }
  158531. }
  158532. }
  158533. }
  158534. }
  158535. LOCAL(void)
  158536. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158537. jvirt_barray_ptr *src_coef_arrays,
  158538. jvirt_barray_ptr *dst_coef_arrays)
  158539. {
  158540. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158541. int ci, i, j, offset_x, offset_y;
  158542. JBLOCKARRAY src_buffer, dst_buffer;
  158543. JCOEFPTR src_ptr, dst_ptr;
  158544. jpeg_component_info *compptr;
  158545. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158546. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158547. compptr = dstinfo->comp_info + ci;
  158548. comp_height = MCU_rows * compptr->v_samp_factor;
  158549. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158550. dst_blk_y += compptr->v_samp_factor) {
  158551. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158552. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158553. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158554. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158555. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158556. dst_blk_x += compptr->h_samp_factor) {
  158557. src_buffer = (*srcinfo->mem->access_virt_barray)
  158558. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158559. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158560. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158561. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158562. if (dst_blk_y < comp_height) {
  158563. src_ptr = src_buffer[offset_x]
  158564. [comp_height - dst_blk_y - offset_y - 1];
  158565. for (i = 0; i < DCTSIZE; i++) {
  158566. for (j = 0; j < DCTSIZE; j++) {
  158567. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158568. j++;
  158569. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158570. }
  158571. }
  158572. } else {
  158573. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158574. for (i = 0; i < DCTSIZE; i++)
  158575. for (j = 0; j < DCTSIZE; j++)
  158576. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158577. }
  158578. }
  158579. }
  158580. }
  158581. }
  158582. }
  158583. }
  158584. LOCAL(void)
  158585. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158586. jvirt_barray_ptr *src_coef_arrays,
  158587. jvirt_barray_ptr *dst_coef_arrays)
  158588. {
  158589. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158590. int ci, i, j, offset_y;
  158591. JBLOCKARRAY src_buffer, dst_buffer;
  158592. JBLOCKROW src_row_ptr, dst_row_ptr;
  158593. JCOEFPTR src_ptr, dst_ptr;
  158594. jpeg_component_info *compptr;
  158595. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158596. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158597. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158598. compptr = dstinfo->comp_info + ci;
  158599. comp_width = MCU_cols * compptr->h_samp_factor;
  158600. comp_height = MCU_rows * compptr->v_samp_factor;
  158601. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158602. dst_blk_y += compptr->v_samp_factor) {
  158603. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158604. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158605. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158606. if (dst_blk_y < comp_height) {
  158607. src_buffer = (*srcinfo->mem->access_virt_barray)
  158608. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158609. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158610. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158611. } else {
  158612. src_buffer = (*srcinfo->mem->access_virt_barray)
  158613. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158614. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158615. }
  158616. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158617. if (dst_blk_y < comp_height) {
  158618. dst_row_ptr = dst_buffer[offset_y];
  158619. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158620. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158621. dst_ptr = dst_row_ptr[dst_blk_x];
  158622. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158623. for (i = 0; i < DCTSIZE; i += 2) {
  158624. for (j = 0; j < DCTSIZE; j += 2) {
  158625. *dst_ptr++ = *src_ptr++;
  158626. *dst_ptr++ = - *src_ptr++;
  158627. }
  158628. for (j = 0; j < DCTSIZE; j += 2) {
  158629. *dst_ptr++ = - *src_ptr++;
  158630. *dst_ptr++ = *src_ptr++;
  158631. }
  158632. }
  158633. }
  158634. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158635. dst_ptr = dst_row_ptr[dst_blk_x];
  158636. src_ptr = src_row_ptr[dst_blk_x];
  158637. for (i = 0; i < DCTSIZE; i += 2) {
  158638. for (j = 0; j < DCTSIZE; j++)
  158639. *dst_ptr++ = *src_ptr++;
  158640. for (j = 0; j < DCTSIZE; j++)
  158641. *dst_ptr++ = - *src_ptr++;
  158642. }
  158643. }
  158644. } else {
  158645. dst_row_ptr = dst_buffer[offset_y];
  158646. src_row_ptr = src_buffer[offset_y];
  158647. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158648. dst_ptr = dst_row_ptr[dst_blk_x];
  158649. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158650. for (i = 0; i < DCTSIZE2; i += 2) {
  158651. *dst_ptr++ = *src_ptr++;
  158652. *dst_ptr++ = - *src_ptr++;
  158653. }
  158654. }
  158655. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158656. dst_ptr = dst_row_ptr[dst_blk_x];
  158657. src_ptr = src_row_ptr[dst_blk_x];
  158658. for (i = 0; i < DCTSIZE2; i++)
  158659. *dst_ptr++ = *src_ptr++;
  158660. }
  158661. }
  158662. }
  158663. }
  158664. }
  158665. }
  158666. LOCAL(void)
  158667. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158668. jvirt_barray_ptr *src_coef_arrays,
  158669. jvirt_barray_ptr *dst_coef_arrays)
  158670. {
  158671. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158672. int ci, i, j, offset_x, offset_y;
  158673. JBLOCKARRAY src_buffer, dst_buffer;
  158674. JCOEFPTR src_ptr, dst_ptr;
  158675. jpeg_component_info *compptr;
  158676. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158677. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158678. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158679. compptr = dstinfo->comp_info + ci;
  158680. comp_width = MCU_cols * compptr->h_samp_factor;
  158681. comp_height = MCU_rows * compptr->v_samp_factor;
  158682. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158683. dst_blk_y += compptr->v_samp_factor) {
  158684. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158685. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158686. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158687. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158688. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158689. dst_blk_x += compptr->h_samp_factor) {
  158690. src_buffer = (*srcinfo->mem->access_virt_barray)
  158691. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158692. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158693. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158694. if (dst_blk_y < comp_height) {
  158695. src_ptr = src_buffer[offset_x]
  158696. [comp_height - dst_blk_y - offset_y - 1];
  158697. if (dst_blk_x < comp_width) {
  158698. dst_ptr = dst_buffer[offset_y]
  158699. [comp_width - dst_blk_x - offset_x - 1];
  158700. for (i = 0; i < DCTSIZE; i++) {
  158701. for (j = 0; j < DCTSIZE; j++) {
  158702. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158703. j++;
  158704. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158705. }
  158706. i++;
  158707. for (j = 0; j < DCTSIZE; j++) {
  158708. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158709. j++;
  158710. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158711. }
  158712. }
  158713. } else {
  158714. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158715. for (i = 0; i < DCTSIZE; i++) {
  158716. for (j = 0; j < DCTSIZE; j++) {
  158717. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158718. j++;
  158719. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158720. }
  158721. }
  158722. }
  158723. } else {
  158724. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158725. if (dst_blk_x < comp_width) {
  158726. dst_ptr = dst_buffer[offset_y]
  158727. [comp_width - dst_blk_x - offset_x - 1];
  158728. for (i = 0; i < DCTSIZE; i++) {
  158729. for (j = 0; j < DCTSIZE; j++)
  158730. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158731. i++;
  158732. for (j = 0; j < DCTSIZE; j++)
  158733. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158734. }
  158735. } else {
  158736. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158737. for (i = 0; i < DCTSIZE; i++)
  158738. for (j = 0; j < DCTSIZE; j++)
  158739. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158740. }
  158741. }
  158742. }
  158743. }
  158744. }
  158745. }
  158746. }
  158747. }
  158748. GLOBAL(void)
  158749. jtransform_request_workspace (j_decompress_ptr srcinfo,
  158750. jpeg_transform_info *info)
  158751. {
  158752. jvirt_barray_ptr *coef_arrays = NULL;
  158753. jpeg_component_info *compptr;
  158754. int ci;
  158755. if (info->force_grayscale &&
  158756. srcinfo->jpeg_color_space == JCS_YCbCr &&
  158757. srcinfo->num_components == 3) {
  158758. info->num_components = 1;
  158759. } else {
  158760. info->num_components = srcinfo->num_components;
  158761. }
  158762. switch (info->transform) {
  158763. case JXFORM_NONE:
  158764. case JXFORM_FLIP_H:
  158765. break;
  158766. case JXFORM_FLIP_V:
  158767. case JXFORM_ROT_180:
  158768. coef_arrays = (jvirt_barray_ptr *)
  158769. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158770. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158771. for (ci = 0; ci < info->num_components; ci++) {
  158772. compptr = srcinfo->comp_info + ci;
  158773. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158774. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158775. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158776. (long) compptr->h_samp_factor),
  158777. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158778. (long) compptr->v_samp_factor),
  158779. (JDIMENSION) compptr->v_samp_factor);
  158780. }
  158781. break;
  158782. case JXFORM_TRANSPOSE:
  158783. case JXFORM_TRANSVERSE:
  158784. case JXFORM_ROT_90:
  158785. case JXFORM_ROT_270:
  158786. coef_arrays = (jvirt_barray_ptr *)
  158787. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158788. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158789. for (ci = 0; ci < info->num_components; ci++) {
  158790. compptr = srcinfo->comp_info + ci;
  158791. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158792. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158793. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158794. (long) compptr->v_samp_factor),
  158795. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158796. (long) compptr->h_samp_factor),
  158797. (JDIMENSION) compptr->h_samp_factor);
  158798. }
  158799. break;
  158800. }
  158801. info->workspace_coef_arrays = coef_arrays;
  158802. }
  158803. LOCAL(void)
  158804. transpose_critical_parameters (j_compress_ptr dstinfo)
  158805. {
  158806. int tblno, i, j, ci, itemp;
  158807. jpeg_component_info *compptr;
  158808. JQUANT_TBL *qtblptr;
  158809. JDIMENSION dtemp;
  158810. UINT16 qtemp;
  158811. dtemp = dstinfo->image_width;
  158812. dstinfo->image_width = dstinfo->image_height;
  158813. dstinfo->image_height = dtemp;
  158814. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158815. compptr = dstinfo->comp_info + ci;
  158816. itemp = compptr->h_samp_factor;
  158817. compptr->h_samp_factor = compptr->v_samp_factor;
  158818. compptr->v_samp_factor = itemp;
  158819. }
  158820. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  158821. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  158822. if (qtblptr != NULL) {
  158823. for (i = 0; i < DCTSIZE; i++) {
  158824. for (j = 0; j < i; j++) {
  158825. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  158826. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  158827. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  158828. }
  158829. }
  158830. }
  158831. }
  158832. }
  158833. LOCAL(void)
  158834. trim_right_edge (j_compress_ptr dstinfo)
  158835. {
  158836. int ci, max_h_samp_factor;
  158837. JDIMENSION MCU_cols;
  158838. max_h_samp_factor = 1;
  158839. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158840. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  158841. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  158842. }
  158843. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  158844. if (MCU_cols > 0) /* can't trim to 0 pixels */
  158845. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  158846. }
  158847. LOCAL(void)
  158848. trim_bottom_edge (j_compress_ptr dstinfo)
  158849. {
  158850. int ci, max_v_samp_factor;
  158851. JDIMENSION MCU_rows;
  158852. max_v_samp_factor = 1;
  158853. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158854. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  158855. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  158856. }
  158857. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  158858. if (MCU_rows > 0) /* can't trim to 0 pixels */
  158859. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  158860. }
  158861. GLOBAL(jvirt_barray_ptr *)
  158862. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  158863. j_compress_ptr dstinfo,
  158864. jvirt_barray_ptr *src_coef_arrays,
  158865. jpeg_transform_info *info)
  158866. {
  158867. if (info->force_grayscale) {
  158868. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  158869. dstinfo->num_components == 3) ||
  158870. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  158871. dstinfo->num_components == 1)) {
  158872. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  158873. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  158874. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  158875. } else {
  158876. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  158877. }
  158878. }
  158879. switch (info->transform) {
  158880. case JXFORM_NONE:
  158881. break;
  158882. case JXFORM_FLIP_H:
  158883. if (info->trim)
  158884. trim_right_edge(dstinfo);
  158885. break;
  158886. case JXFORM_FLIP_V:
  158887. if (info->trim)
  158888. trim_bottom_edge(dstinfo);
  158889. break;
  158890. case JXFORM_TRANSPOSE:
  158891. transpose_critical_parameters(dstinfo);
  158892. break;
  158893. case JXFORM_TRANSVERSE:
  158894. transpose_critical_parameters(dstinfo);
  158895. if (info->trim) {
  158896. trim_right_edge(dstinfo);
  158897. trim_bottom_edge(dstinfo);
  158898. }
  158899. break;
  158900. case JXFORM_ROT_90:
  158901. transpose_critical_parameters(dstinfo);
  158902. if (info->trim)
  158903. trim_right_edge(dstinfo);
  158904. break;
  158905. case JXFORM_ROT_180:
  158906. if (info->trim) {
  158907. trim_right_edge(dstinfo);
  158908. trim_bottom_edge(dstinfo);
  158909. }
  158910. break;
  158911. case JXFORM_ROT_270:
  158912. transpose_critical_parameters(dstinfo);
  158913. if (info->trim)
  158914. trim_bottom_edge(dstinfo);
  158915. break;
  158916. }
  158917. if (info->workspace_coef_arrays != NULL)
  158918. return info->workspace_coef_arrays;
  158919. return src_coef_arrays;
  158920. }
  158921. GLOBAL(void)
  158922. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  158923. j_compress_ptr dstinfo,
  158924. jvirt_barray_ptr *src_coef_arrays,
  158925. jpeg_transform_info *info)
  158926. {
  158927. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  158928. switch (info->transform) {
  158929. case JXFORM_NONE:
  158930. break;
  158931. case JXFORM_FLIP_H:
  158932. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  158933. break;
  158934. case JXFORM_FLIP_V:
  158935. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158936. break;
  158937. case JXFORM_TRANSPOSE:
  158938. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158939. break;
  158940. case JXFORM_TRANSVERSE:
  158941. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158942. break;
  158943. case JXFORM_ROT_90:
  158944. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158945. break;
  158946. case JXFORM_ROT_180:
  158947. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158948. break;
  158949. case JXFORM_ROT_270:
  158950. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158951. break;
  158952. }
  158953. }
  158954. #endif /* TRANSFORMS_SUPPORTED */
  158955. GLOBAL(void)
  158956. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  158957. {
  158958. #ifdef SAVE_MARKERS_SUPPORTED
  158959. int m;
  158960. if (option != JCOPYOPT_NONE) {
  158961. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  158962. }
  158963. if (option == JCOPYOPT_ALL) {
  158964. for (m = 0; m < 16; m++)
  158965. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  158966. }
  158967. #endif /* SAVE_MARKERS_SUPPORTED */
  158968. }
  158969. GLOBAL(void)
  158970. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158971. JCOPY_OPTION option)
  158972. {
  158973. jpeg_saved_marker_ptr marker;
  158974. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  158975. if (dstinfo->write_JFIF_header &&
  158976. marker->marker == JPEG_APP0 &&
  158977. marker->data_length >= 5 &&
  158978. GETJOCTET(marker->data[0]) == 0x4A &&
  158979. GETJOCTET(marker->data[1]) == 0x46 &&
  158980. GETJOCTET(marker->data[2]) == 0x49 &&
  158981. GETJOCTET(marker->data[3]) == 0x46 &&
  158982. GETJOCTET(marker->data[4]) == 0)
  158983. continue; /* reject duplicate JFIF */
  158984. if (dstinfo->write_Adobe_marker &&
  158985. marker->marker == JPEG_APP0+14 &&
  158986. marker->data_length >= 5 &&
  158987. GETJOCTET(marker->data[0]) == 0x41 &&
  158988. GETJOCTET(marker->data[1]) == 0x64 &&
  158989. GETJOCTET(marker->data[2]) == 0x6F &&
  158990. GETJOCTET(marker->data[3]) == 0x62 &&
  158991. GETJOCTET(marker->data[4]) == 0x65)
  158992. continue; /* reject duplicate Adobe */
  158993. #ifdef NEED_FAR_POINTERS
  158994. {
  158995. unsigned int i;
  158996. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  158997. for (i = 0; i < marker->data_length; i++)
  158998. jpeg_write_m_byte(dstinfo, marker->data[i]);
  158999. }
  159000. #else
  159001. jpeg_write_marker(dstinfo, marker->marker,
  159002. marker->data, marker->data_length);
  159003. #endif
  159004. }
  159005. }
  159006. /*** End of inlined file: transupp.c ***/
  159007. }
  159008. #else
  159009. #define JPEG_INTERNALS
  159010. #undef FAR
  159011. #include <jpeglib.h>
  159012. #endif
  159013. }
  159014. #if JUCE_MSVC
  159015. #pragma warning (pop)
  159016. #endif
  159017. BEGIN_JUCE_NAMESPACE
  159018. using namespace jpeglibNamespace;
  159019. #if ! JUCE_MSVC
  159020. using jpeglibNamespace::boolean;
  159021. #endif
  159022. struct JPEGDecodingFailure {};
  159023. static void fatalErrorHandler (j_common_ptr)
  159024. {
  159025. throw JPEGDecodingFailure();
  159026. }
  159027. static void silentErrorCallback1 (j_common_ptr) {}
  159028. static void silentErrorCallback2 (j_common_ptr, int) {}
  159029. static void silentErrorCallback3 (j_common_ptr, char*) {}
  159030. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  159031. {
  159032. zerostruct (err);
  159033. err.error_exit = fatalErrorHandler;
  159034. err.emit_message = silentErrorCallback2;
  159035. err.output_message = silentErrorCallback1;
  159036. err.format_message = silentErrorCallback3;
  159037. err.reset_error_mgr = silentErrorCallback1;
  159038. }
  159039. static void dummyCallback1 (j_decompress_ptr)
  159040. {
  159041. }
  159042. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  159043. {
  159044. decompStruct->src->next_input_byte += num;
  159045. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  159046. decompStruct->src->bytes_in_buffer -= num;
  159047. }
  159048. static boolean jpegFill (j_decompress_ptr)
  159049. {
  159050. return 0;
  159051. }
  159052. Image* juce_loadJPEGImageFromStream (InputStream& in)
  159053. {
  159054. MemoryBlock mb;
  159055. in.readIntoMemoryBlock (mb);
  159056. Image* image = 0;
  159057. if (mb.getSize() > 16)
  159058. {
  159059. struct jpeg_decompress_struct jpegDecompStruct;
  159060. struct jpeg_error_mgr jerr;
  159061. setupSilentErrorHandler (jerr);
  159062. jpegDecompStruct.err = &jerr;
  159063. jpeg_create_decompress (&jpegDecompStruct);
  159064. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  159065. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  159066. jpegDecompStruct.src->init_source = dummyCallback1;
  159067. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  159068. jpegDecompStruct.src->skip_input_data = jpegSkip;
  159069. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  159070. jpegDecompStruct.src->term_source = dummyCallback1;
  159071. jpegDecompStruct.src->next_input_byte = (const unsigned char*) mb.getData();
  159072. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  159073. try
  159074. {
  159075. jpeg_read_header (&jpegDecompStruct, TRUE);
  159076. jpeg_calc_output_dimensions (&jpegDecompStruct);
  159077. const int width = jpegDecompStruct.output_width;
  159078. const int height = jpegDecompStruct.output_height;
  159079. jpegDecompStruct.out_color_space = JCS_RGB;
  159080. JSAMPARRAY buffer
  159081. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  159082. JPOOL_IMAGE,
  159083. width * 3, 1);
  159084. if (jpeg_start_decompress (&jpegDecompStruct))
  159085. {
  159086. image = Image::createNativeImage (Image::RGB, width, height, false);
  159087. const bool hasAlphaChan = image->hasAlphaChannel();
  159088. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  159089. for (int y = 0; y < height; ++y)
  159090. {
  159091. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  159092. const uint8* src = *buffer;
  159093. uint8* dest = destData.getLinePointer (y);
  159094. if (hasAlphaChan)
  159095. {
  159096. for (int i = width; --i >= 0;)
  159097. {
  159098. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159099. ((PixelARGB*) dest)->premultiply();
  159100. dest += destData.pixelStride;
  159101. src += 3;
  159102. }
  159103. }
  159104. else
  159105. {
  159106. for (int i = width; --i >= 0;)
  159107. {
  159108. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159109. dest += destData.pixelStride;
  159110. src += 3;
  159111. }
  159112. }
  159113. }
  159114. jpeg_finish_decompress (&jpegDecompStruct);
  159115. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  159116. }
  159117. jpeg_destroy_decompress (&jpegDecompStruct);
  159118. }
  159119. catch (...)
  159120. {}
  159121. }
  159122. return image;
  159123. }
  159124. static const int jpegBufferSize = 512;
  159125. struct JuceJpegDest : public jpeg_destination_mgr
  159126. {
  159127. OutputStream* output;
  159128. char* buffer;
  159129. };
  159130. static void jpegWriteInit (j_compress_ptr)
  159131. {
  159132. }
  159133. static void jpegWriteTerminate (j_compress_ptr cinfo)
  159134. {
  159135. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159136. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  159137. dest->output->write (dest->buffer, (int) numToWrite);
  159138. }
  159139. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  159140. {
  159141. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159142. const int numToWrite = jpegBufferSize;
  159143. dest->next_output_byte = (JOCTET*) dest->buffer;
  159144. dest->free_in_buffer = jpegBufferSize;
  159145. return dest->output->write (dest->buffer, numToWrite);
  159146. }
  159147. bool juce_writeJPEGImageToStream (const Image& image,
  159148. OutputStream& out,
  159149. float quality)
  159150. {
  159151. if (image.hasAlphaChannel())
  159152. {
  159153. // this method could fill the background in white and still save the image..
  159154. jassertfalse
  159155. return true;
  159156. }
  159157. struct jpeg_compress_struct jpegCompStruct;
  159158. struct jpeg_error_mgr jerr;
  159159. setupSilentErrorHandler (jerr);
  159160. jpegCompStruct.err = &jerr;
  159161. jpeg_create_compress (&jpegCompStruct);
  159162. JuceJpegDest dest;
  159163. jpegCompStruct.dest = &dest;
  159164. dest.output = &out;
  159165. HeapBlock <char> tempBuffer (jpegBufferSize);
  159166. dest.buffer = (char*) tempBuffer;
  159167. dest.next_output_byte = (JOCTET*) dest.buffer;
  159168. dest.free_in_buffer = jpegBufferSize;
  159169. dest.init_destination = jpegWriteInit;
  159170. dest.empty_output_buffer = jpegWriteFlush;
  159171. dest.term_destination = jpegWriteTerminate;
  159172. jpegCompStruct.image_width = image.getWidth();
  159173. jpegCompStruct.image_height = image.getHeight();
  159174. jpegCompStruct.input_components = 3;
  159175. jpegCompStruct.in_color_space = JCS_RGB;
  159176. jpegCompStruct.write_JFIF_header = 1;
  159177. jpegCompStruct.X_density = 72;
  159178. jpegCompStruct.Y_density = 72;
  159179. jpeg_set_defaults (&jpegCompStruct);
  159180. jpegCompStruct.dct_method = JDCT_FLOAT;
  159181. jpegCompStruct.optimize_coding = 1;
  159182. // jpegCompStruct.smoothing_factor = 10;
  159183. if (quality < 0.0f)
  159184. quality = 0.85f;
  159185. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  159186. jpeg_start_compress (&jpegCompStruct, TRUE);
  159187. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  159188. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  159189. JPOOL_IMAGE,
  159190. strideBytes, 1);
  159191. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  159192. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  159193. {
  159194. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  159195. uint8* dst = *buffer;
  159196. for (int i = jpegCompStruct.image_width; --i >= 0;)
  159197. {
  159198. *dst++ = ((const PixelRGB*) src)->getRed();
  159199. *dst++ = ((const PixelRGB*) src)->getGreen();
  159200. *dst++ = ((const PixelRGB*) src)->getBlue();
  159201. src += srcData.pixelStride;
  159202. }
  159203. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  159204. }
  159205. jpeg_finish_compress (&jpegCompStruct);
  159206. jpeg_destroy_compress (&jpegCompStruct);
  159207. out.flush();
  159208. return true;
  159209. }
  159210. END_JUCE_NAMESPACE
  159211. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  159212. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  159213. #ifdef _MSC_VER
  159214. #pragma warning (push)
  159215. #pragma warning (disable: 4390 4611)
  159216. #endif
  159217. namespace zlibNamespace
  159218. {
  159219. #if JUCE_INCLUDE_ZLIB_CODE
  159220. #undef OS_CODE
  159221. #undef fdopen
  159222. #undef OS_CODE
  159223. #else
  159224. #include <zlib.h>
  159225. #endif
  159226. }
  159227. namespace pnglibNamespace
  159228. {
  159229. using namespace zlibNamespace;
  159230. #if JUCE_INCLUDE_PNGLIB_CODE
  159231. #if _MSC_VER != 1310
  159232. using ::calloc; // (causes conflict in VS.NET 2003)
  159233. using ::malloc;
  159234. using ::free;
  159235. #endif
  159236. extern "C"
  159237. {
  159238. using ::abs;
  159239. #define PNG_INTERNAL
  159240. #define NO_DUMMY_DECL
  159241. #define PNG_SETJMP_NOT_SUPPORTED
  159242. /*** Start of inlined file: png.h ***/
  159243. #ifndef PNG_H
  159244. #define PNG_H
  159245. #define PNG_LIBPNG_VER_STRING "1.2.21"
  159246. #define PNG_HEADER_VERSION_STRING \
  159247. " libpng version 1.2.21 - October 4, 2007\n"
  159248. #define PNG_LIBPNG_VER_SONUM 0
  159249. #define PNG_LIBPNG_VER_DLLNUM 13
  159250. #define PNG_LIBPNG_VER_MAJOR 1
  159251. #define PNG_LIBPNG_VER_MINOR 2
  159252. #define PNG_LIBPNG_VER_RELEASE 21
  159253. #define PNG_LIBPNG_VER_BUILD 0
  159254. #define PNG_LIBPNG_BUILD_ALPHA 1
  159255. #define PNG_LIBPNG_BUILD_BETA 2
  159256. #define PNG_LIBPNG_BUILD_RC 3
  159257. #define PNG_LIBPNG_BUILD_STABLE 4
  159258. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  159259. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  159260. PNG_LIBPNG_BUILD_STABLE only */
  159261. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  159262. PNG_LIBPNG_BUILD_SPECIAL */
  159263. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  159264. PNG_LIBPNG_BUILD_PRIVATE */
  159265. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  159266. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  159267. #ifndef PNG_VERSION_INFO_ONLY
  159268. #endif
  159269. /*** Start of inlined file: pngconf.h ***/
  159270. #ifndef PNGCONF_H
  159271. #define PNGCONF_H
  159272. #define PNG_1_2_X
  159273. // These are some Juce config settings that should remove any unnecessary code bloat..
  159274. #define PNG_NO_STDIO 1
  159275. #define PNG_DEBUG 0
  159276. #define PNG_NO_WARNINGS 1
  159277. #define PNG_NO_ERROR_TEXT 1
  159278. #define PNG_NO_ERROR_NUMBERS 1
  159279. #define PNG_NO_USER_MEM 1
  159280. #define PNG_NO_READ_iCCP 1
  159281. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159282. #define PNG_NO_READ_USER_CHUNKS 1
  159283. #define PNG_NO_READ_iTXt 1
  159284. #define PNG_NO_READ_sCAL 1
  159285. #define PNG_NO_READ_sPLT 1
  159286. #define png_error(a, b) png_err(a)
  159287. #define png_warning(a, b)
  159288. #define png_chunk_error(a, b) png_err(a)
  159289. #define png_chunk_warning(a, b)
  159290. #ifdef PNG_USER_CONFIG
  159291. # ifndef PNG_USER_PRIVATEBUILD
  159292. # define PNG_USER_PRIVATEBUILD
  159293. # endif
  159294. #include "pngusr.h"
  159295. #endif
  159296. #ifdef PNG_CONFIGURE_LIBPNG
  159297. #ifdef HAVE_CONFIG_H
  159298. #include "config.h"
  159299. #endif
  159300. #endif
  159301. #ifdef __STDC__
  159302. #ifdef SPECIALBUILD
  159303. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159304. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159305. #endif
  159306. #ifdef PRIVATEBUILD
  159307. # pragma message("PRIVATEBUILD is deprecated.\
  159308. Use PNG_USER_PRIVATEBUILD instead.")
  159309. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159310. #endif
  159311. #endif /* __STDC__ */
  159312. #ifndef PNG_VERSION_INFO_ONLY
  159313. # define PNG_WARN_UNINITIALIZED_ROW 1
  159314. #ifndef PNG_ZBUF_SIZE
  159315. # define PNG_ZBUF_SIZE 8192
  159316. #endif
  159317. #ifndef PNG_NO_READ_SUPPORTED
  159318. # define PNG_READ_SUPPORTED
  159319. #endif
  159320. #ifndef PNG_NO_WRITE_SUPPORTED
  159321. # define PNG_WRITE_SUPPORTED
  159322. #endif
  159323. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159324. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159325. # define PNG_MNG_FEATURES_SUPPORTED
  159326. # endif
  159327. #endif
  159328. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159329. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159330. # define PNG_FLOATING_POINT_SUPPORTED
  159331. # endif
  159332. #endif
  159333. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159334. # define PNG_MAX_MALLOC_64K
  159335. #endif
  159336. #if defined(__CYGWIN__)
  159337. # if defined(ALL_STATIC)
  159338. # if defined(PNG_BUILD_DLL)
  159339. # undef PNG_BUILD_DLL
  159340. # endif
  159341. # if defined(PNG_USE_DLL)
  159342. # undef PNG_USE_DLL
  159343. # endif
  159344. # if defined(PNG_DLL)
  159345. # undef PNG_DLL
  159346. # endif
  159347. # if !defined(PNG_STATIC)
  159348. # define PNG_STATIC
  159349. # endif
  159350. # else
  159351. # if defined (PNG_BUILD_DLL)
  159352. # if defined(PNG_STATIC)
  159353. # undef PNG_STATIC
  159354. # endif
  159355. # if defined(PNG_USE_DLL)
  159356. # undef PNG_USE_DLL
  159357. # endif
  159358. # if !defined(PNG_DLL)
  159359. # define PNG_DLL
  159360. # endif
  159361. # else
  159362. # if defined(PNG_STATIC)
  159363. # if defined(PNG_USE_DLL)
  159364. # undef PNG_USE_DLL
  159365. # endif
  159366. # if defined(PNG_DLL)
  159367. # undef PNG_DLL
  159368. # endif
  159369. # else
  159370. # if !defined(PNG_USE_DLL)
  159371. # define PNG_USE_DLL
  159372. # endif
  159373. # if !defined(PNG_DLL)
  159374. # define PNG_DLL
  159375. # endif
  159376. # endif
  159377. # endif
  159378. # endif
  159379. #endif
  159380. #if defined(_WIN32_WCE)
  159381. # include <windows.h>
  159382. # define PNG_NO_CONSOLE_IO
  159383. # ifdef PNG_DEBUG
  159384. # undef PNG_DEBUG
  159385. # endif
  159386. #endif
  159387. #ifdef PNG_BUILD_DLL
  159388. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159389. # ifndef PNG_NO_CONSOLE_IO
  159390. # define PNG_NO_CONSOLE_IO
  159391. # endif
  159392. # endif
  159393. #endif
  159394. # ifdef PNG_NO_STDIO
  159395. # ifndef PNG_NO_CONSOLE_IO
  159396. # define PNG_NO_CONSOLE_IO
  159397. # endif
  159398. # ifdef PNG_DEBUG
  159399. # if (PNG_DEBUG > 0)
  159400. # include <stdio.h>
  159401. # endif
  159402. # endif
  159403. # else
  159404. # if !defined(_WIN32_WCE)
  159405. # include <stdio.h>
  159406. # endif
  159407. # endif
  159408. #ifndef PNGARG
  159409. #ifdef OF /* zlib prototype munger */
  159410. # define PNGARG(arglist) OF(arglist)
  159411. #else
  159412. #ifdef _NO_PROTO
  159413. # define PNGARG(arglist) ()
  159414. # ifndef PNG_TYPECAST_NULL
  159415. # define PNG_TYPECAST_NULL
  159416. # endif
  159417. #else
  159418. # define PNGARG(arglist) arglist
  159419. #endif /* _NO_PROTO */
  159420. #endif /* OF */
  159421. #endif /* PNGARG */
  159422. #ifndef MACOS
  159423. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159424. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159425. # define MACOS
  159426. # endif
  159427. #endif
  159428. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159429. # include <sys/types.h>
  159430. #endif
  159431. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159432. # define PNG_SETJMP_SUPPORTED
  159433. #endif
  159434. #ifdef PNG_SETJMP_SUPPORTED
  159435. # ifdef __linux__
  159436. # ifdef _BSD_SOURCE
  159437. # define PNG_SAVE_BSD_SOURCE
  159438. # undef _BSD_SOURCE
  159439. # endif
  159440. # ifdef _SETJMP_H
  159441. __png.h__ already includes setjmp.h;
  159442. __dont__ include it again.;
  159443. # endif
  159444. # endif /* __linux__ */
  159445. # include <setjmp.h>
  159446. # ifdef __linux__
  159447. # ifdef PNG_SAVE_BSD_SOURCE
  159448. # define _BSD_SOURCE
  159449. # undef PNG_SAVE_BSD_SOURCE
  159450. # endif
  159451. # endif /* __linux__ */
  159452. #endif /* PNG_SETJMP_SUPPORTED */
  159453. #ifdef BSD
  159454. #if ! JUCE_MAC
  159455. # include <strings.h>
  159456. #endif
  159457. #else
  159458. # include <string.h>
  159459. #endif
  159460. #ifdef PNG_INTERNAL
  159461. #include <stdlib.h>
  159462. #define PNG_EXTERN
  159463. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159464. # if defined(MACOS)
  159465. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159466. # include <fp.h>
  159467. # endif
  159468. # else
  159469. # include <math.h>
  159470. # endif
  159471. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159472. # include <m68881.h>
  159473. # endif
  159474. #endif
  159475. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159476. # define PNG_ALWAYS_EXTERN
  159477. #endif
  159478. #if defined(__TURBOC__) && defined(__MSDOS__)
  159479. # include <mem.h>
  159480. # include <alloc.h>
  159481. #endif
  159482. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159483. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159484. # include <malloc.h>
  159485. #endif
  159486. #ifndef PNG_DITHER_RED_BITS
  159487. # define PNG_DITHER_RED_BITS 5
  159488. #endif
  159489. #ifndef PNG_DITHER_GREEN_BITS
  159490. # define PNG_DITHER_GREEN_BITS 5
  159491. #endif
  159492. #ifndef PNG_DITHER_BLUE_BITS
  159493. # define PNG_DITHER_BLUE_BITS 5
  159494. #endif
  159495. #ifndef PNG_MAX_GAMMA_8
  159496. # define PNG_MAX_GAMMA_8 11
  159497. #endif
  159498. #ifndef PNG_GAMMA_THRESHOLD
  159499. # define PNG_GAMMA_THRESHOLD 0.05
  159500. #endif
  159501. #endif /* PNG_INTERNAL */
  159502. #ifndef PNG_NO_CONST
  159503. # define PNG_CONST const
  159504. #else
  159505. # define PNG_CONST
  159506. #endif
  159507. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159508. # ifndef PNG_NO_iTXt_SUPPORTED
  159509. # define PNG_NO_iTXt_SUPPORTED
  159510. # endif
  159511. # ifndef PNG_NO_READ_iTXt
  159512. # define PNG_NO_READ_iTXt
  159513. # endif
  159514. # ifndef PNG_NO_WRITE_iTXt
  159515. # define PNG_NO_WRITE_iTXt
  159516. # endif
  159517. #endif
  159518. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159519. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159520. # define PNG_READ_iTXt
  159521. # endif
  159522. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159523. # define PNG_WRITE_iTXt
  159524. # endif
  159525. #endif
  159526. #ifdef PNG_LEGACY_SUPPORTED
  159527. # define PNG_NO_FREE_ME
  159528. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159529. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159530. # define PNG_NO_READ_USER_CHUNKS
  159531. # define PNG_NO_READ_iCCP
  159532. # define PNG_NO_WRITE_iCCP
  159533. # define PNG_NO_READ_iTXt
  159534. # define PNG_NO_WRITE_iTXt
  159535. # define PNG_NO_READ_sCAL
  159536. # define PNG_NO_WRITE_sCAL
  159537. # define PNG_NO_READ_sPLT
  159538. # define PNG_NO_WRITE_sPLT
  159539. # define PNG_NO_INFO_IMAGE
  159540. # define PNG_NO_READ_RGB_TO_GRAY
  159541. # define PNG_NO_READ_USER_TRANSFORM
  159542. # define PNG_NO_WRITE_USER_TRANSFORM
  159543. # define PNG_NO_USER_MEM
  159544. # define PNG_NO_READ_EMPTY_PLTE
  159545. # define PNG_NO_MNG_FEATURES
  159546. # define PNG_NO_FIXED_POINT_SUPPORTED
  159547. #endif
  159548. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159549. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159550. # define PNG_FIXED_POINT_SUPPORTED
  159551. #endif
  159552. #ifndef PNG_NO_FREE_ME
  159553. # define PNG_FREE_ME_SUPPORTED
  159554. #endif
  159555. #if defined(PNG_READ_SUPPORTED)
  159556. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159557. !defined(PNG_NO_READ_TRANSFORMS)
  159558. # define PNG_READ_TRANSFORMS_SUPPORTED
  159559. #endif
  159560. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159561. # ifndef PNG_NO_READ_EXPAND
  159562. # define PNG_READ_EXPAND_SUPPORTED
  159563. # endif
  159564. # ifndef PNG_NO_READ_SHIFT
  159565. # define PNG_READ_SHIFT_SUPPORTED
  159566. # endif
  159567. # ifndef PNG_NO_READ_PACK
  159568. # define PNG_READ_PACK_SUPPORTED
  159569. # endif
  159570. # ifndef PNG_NO_READ_BGR
  159571. # define PNG_READ_BGR_SUPPORTED
  159572. # endif
  159573. # ifndef PNG_NO_READ_SWAP
  159574. # define PNG_READ_SWAP_SUPPORTED
  159575. # endif
  159576. # ifndef PNG_NO_READ_PACKSWAP
  159577. # define PNG_READ_PACKSWAP_SUPPORTED
  159578. # endif
  159579. # ifndef PNG_NO_READ_INVERT
  159580. # define PNG_READ_INVERT_SUPPORTED
  159581. # endif
  159582. # ifndef PNG_NO_READ_DITHER
  159583. # define PNG_READ_DITHER_SUPPORTED
  159584. # endif
  159585. # ifndef PNG_NO_READ_BACKGROUND
  159586. # define PNG_READ_BACKGROUND_SUPPORTED
  159587. # endif
  159588. # ifndef PNG_NO_READ_16_TO_8
  159589. # define PNG_READ_16_TO_8_SUPPORTED
  159590. # endif
  159591. # ifndef PNG_NO_READ_FILLER
  159592. # define PNG_READ_FILLER_SUPPORTED
  159593. # endif
  159594. # ifndef PNG_NO_READ_GAMMA
  159595. # define PNG_READ_GAMMA_SUPPORTED
  159596. # endif
  159597. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159598. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159599. # endif
  159600. # ifndef PNG_NO_READ_SWAP_ALPHA
  159601. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159602. # endif
  159603. # ifndef PNG_NO_READ_INVERT_ALPHA
  159604. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159605. # endif
  159606. # ifndef PNG_NO_READ_STRIP_ALPHA
  159607. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159608. # endif
  159609. # ifndef PNG_NO_READ_USER_TRANSFORM
  159610. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159611. # endif
  159612. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159613. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159614. # endif
  159615. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159616. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159617. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159618. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159619. #endif /* about interlacing capability! You'll */
  159620. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159621. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159622. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159623. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159624. # endif
  159625. #endif
  159626. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159627. #ifndef PNG_NO_READ_EMPTY_PLTE
  159628. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159629. #endif
  159630. #endif
  159631. #endif /* PNG_READ_SUPPORTED */
  159632. #if defined(PNG_WRITE_SUPPORTED)
  159633. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159634. !defined(PNG_NO_WRITE_TRANSFORMS)
  159635. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159636. #endif
  159637. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159638. # ifndef PNG_NO_WRITE_SHIFT
  159639. # define PNG_WRITE_SHIFT_SUPPORTED
  159640. # endif
  159641. # ifndef PNG_NO_WRITE_PACK
  159642. # define PNG_WRITE_PACK_SUPPORTED
  159643. # endif
  159644. # ifndef PNG_NO_WRITE_BGR
  159645. # define PNG_WRITE_BGR_SUPPORTED
  159646. # endif
  159647. # ifndef PNG_NO_WRITE_SWAP
  159648. # define PNG_WRITE_SWAP_SUPPORTED
  159649. # endif
  159650. # ifndef PNG_NO_WRITE_PACKSWAP
  159651. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159652. # endif
  159653. # ifndef PNG_NO_WRITE_INVERT
  159654. # define PNG_WRITE_INVERT_SUPPORTED
  159655. # endif
  159656. # ifndef PNG_NO_WRITE_FILLER
  159657. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159658. # endif
  159659. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159660. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159661. # endif
  159662. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159663. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159664. # endif
  159665. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159666. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159667. # endif
  159668. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159669. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  159670. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  159671. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  159672. encoders, but can cause trouble
  159673. if left undefined */
  159674. #endif
  159675. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  159676. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  159677. defined(PNG_FLOATING_POINT_SUPPORTED)
  159678. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  159679. #endif
  159680. #ifndef PNG_NO_WRITE_FLUSH
  159681. # define PNG_WRITE_FLUSH_SUPPORTED
  159682. #endif
  159683. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159684. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  159685. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  159686. #endif
  159687. #endif
  159688. #endif /* PNG_WRITE_SUPPORTED */
  159689. #ifndef PNG_1_0_X
  159690. # ifndef PNG_NO_ERROR_NUMBERS
  159691. # define PNG_ERROR_NUMBERS_SUPPORTED
  159692. # endif
  159693. #endif /* PNG_1_0_X */
  159694. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  159695. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  159696. # ifndef PNG_NO_USER_TRANSFORM_PTR
  159697. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  159698. # endif
  159699. #endif
  159700. #ifndef PNG_NO_STDIO
  159701. # define PNG_TIME_RFC1123_SUPPORTED
  159702. #endif
  159703. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  159704. # define PNG_EASY_ACCESS_SUPPORTED
  159705. #endif
  159706. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  159707. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  159708. # define PNG_OPTIMIZED_CODE_SUPPORTED
  159709. # endif
  159710. #endif
  159711. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  159712. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  159713. # define PNG_ASSEMBLER_CODE_SUPPORTED
  159714. # endif
  159715. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  159716. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159717. # define PNG_NO_MMX_CODE
  159718. # endif
  159719. # endif
  159720. # if defined(__APPLE__)
  159721. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159722. # define PNG_NO_MMX_CODE
  159723. # endif
  159724. # endif
  159725. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  159726. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159727. # define PNG_NO_MMX_CODE
  159728. # endif
  159729. # endif
  159730. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159731. # define PNG_MMX_CODE_SUPPORTED
  159732. # endif
  159733. #endif
  159734. #if !defined(PNG_1_0_X)
  159735. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  159736. # define PNG_USER_MEM_SUPPORTED
  159737. #endif
  159738. #endif /* PNG_1_0_X */
  159739. #if !defined(PNG_1_0_X)
  159740. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  159741. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  159742. # define PNG_SET_USER_LIMITS_SUPPORTED
  159743. #endif
  159744. #endif
  159745. #endif /* PNG_1_0_X */
  159746. #ifndef PNG_USER_WIDTH_MAX
  159747. # define PNG_USER_WIDTH_MAX 1000000L
  159748. #endif
  159749. #ifndef PNG_USER_HEIGHT_MAX
  159750. # define PNG_USER_HEIGHT_MAX 1000000L
  159751. #endif
  159752. #if defined(PNG_READ_SUPPORTED) && \
  159753. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159754. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  159755. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159756. #endif
  159757. #if defined(PNG_WRITE_SUPPORTED) && \
  159758. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159759. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  159760. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159761. #endif
  159762. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159763. #ifdef PNG_NO_READ_TEXT
  159764. # define PNG_NO_READ_iTXt
  159765. # define PNG_NO_READ_tEXt
  159766. # define PNG_NO_READ_zTXt
  159767. #endif
  159768. #ifndef PNG_NO_READ_bKGD
  159769. # define PNG_READ_bKGD_SUPPORTED
  159770. # define PNG_bKGD_SUPPORTED
  159771. #endif
  159772. #ifndef PNG_NO_READ_cHRM
  159773. # define PNG_READ_cHRM_SUPPORTED
  159774. # define PNG_cHRM_SUPPORTED
  159775. #endif
  159776. #ifndef PNG_NO_READ_gAMA
  159777. # define PNG_READ_gAMA_SUPPORTED
  159778. # define PNG_gAMA_SUPPORTED
  159779. #endif
  159780. #ifndef PNG_NO_READ_hIST
  159781. # define PNG_READ_hIST_SUPPORTED
  159782. # define PNG_hIST_SUPPORTED
  159783. #endif
  159784. #ifndef PNG_NO_READ_iCCP
  159785. # define PNG_READ_iCCP_SUPPORTED
  159786. # define PNG_iCCP_SUPPORTED
  159787. #endif
  159788. #ifndef PNG_NO_READ_iTXt
  159789. # ifndef PNG_READ_iTXt_SUPPORTED
  159790. # define PNG_READ_iTXt_SUPPORTED
  159791. # endif
  159792. # ifndef PNG_iTXt_SUPPORTED
  159793. # define PNG_iTXt_SUPPORTED
  159794. # endif
  159795. #endif
  159796. #ifndef PNG_NO_READ_oFFs
  159797. # define PNG_READ_oFFs_SUPPORTED
  159798. # define PNG_oFFs_SUPPORTED
  159799. #endif
  159800. #ifndef PNG_NO_READ_pCAL
  159801. # define PNG_READ_pCAL_SUPPORTED
  159802. # define PNG_pCAL_SUPPORTED
  159803. #endif
  159804. #ifndef PNG_NO_READ_sCAL
  159805. # define PNG_READ_sCAL_SUPPORTED
  159806. # define PNG_sCAL_SUPPORTED
  159807. #endif
  159808. #ifndef PNG_NO_READ_pHYs
  159809. # define PNG_READ_pHYs_SUPPORTED
  159810. # define PNG_pHYs_SUPPORTED
  159811. #endif
  159812. #ifndef PNG_NO_READ_sBIT
  159813. # define PNG_READ_sBIT_SUPPORTED
  159814. # define PNG_sBIT_SUPPORTED
  159815. #endif
  159816. #ifndef PNG_NO_READ_sPLT
  159817. # define PNG_READ_sPLT_SUPPORTED
  159818. # define PNG_sPLT_SUPPORTED
  159819. #endif
  159820. #ifndef PNG_NO_READ_sRGB
  159821. # define PNG_READ_sRGB_SUPPORTED
  159822. # define PNG_sRGB_SUPPORTED
  159823. #endif
  159824. #ifndef PNG_NO_READ_tEXt
  159825. # define PNG_READ_tEXt_SUPPORTED
  159826. # define PNG_tEXt_SUPPORTED
  159827. #endif
  159828. #ifndef PNG_NO_READ_tIME
  159829. # define PNG_READ_tIME_SUPPORTED
  159830. # define PNG_tIME_SUPPORTED
  159831. #endif
  159832. #ifndef PNG_NO_READ_tRNS
  159833. # define PNG_READ_tRNS_SUPPORTED
  159834. # define PNG_tRNS_SUPPORTED
  159835. #endif
  159836. #ifndef PNG_NO_READ_zTXt
  159837. # define PNG_READ_zTXt_SUPPORTED
  159838. # define PNG_zTXt_SUPPORTED
  159839. #endif
  159840. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  159841. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  159842. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159843. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159844. # endif
  159845. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159846. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159847. # endif
  159848. #endif
  159849. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  159850. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  159851. # define PNG_READ_USER_CHUNKS_SUPPORTED
  159852. # define PNG_USER_CHUNKS_SUPPORTED
  159853. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  159854. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  159855. # endif
  159856. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  159857. # undef PNG_NO_HANDLE_AS_UNKNOWN
  159858. # endif
  159859. #endif
  159860. #ifndef PNG_NO_READ_OPT_PLTE
  159861. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  159862. #endif /* optional PLTE chunk in RGB and RGBA images */
  159863. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  159864. defined(PNG_READ_zTXt_SUPPORTED)
  159865. # define PNG_READ_TEXT_SUPPORTED
  159866. # define PNG_TEXT_SUPPORTED
  159867. #endif
  159868. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  159869. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159870. #ifdef PNG_NO_WRITE_TEXT
  159871. # define PNG_NO_WRITE_iTXt
  159872. # define PNG_NO_WRITE_tEXt
  159873. # define PNG_NO_WRITE_zTXt
  159874. #endif
  159875. #ifndef PNG_NO_WRITE_bKGD
  159876. # define PNG_WRITE_bKGD_SUPPORTED
  159877. # ifndef PNG_bKGD_SUPPORTED
  159878. # define PNG_bKGD_SUPPORTED
  159879. # endif
  159880. #endif
  159881. #ifndef PNG_NO_WRITE_cHRM
  159882. # define PNG_WRITE_cHRM_SUPPORTED
  159883. # ifndef PNG_cHRM_SUPPORTED
  159884. # define PNG_cHRM_SUPPORTED
  159885. # endif
  159886. #endif
  159887. #ifndef PNG_NO_WRITE_gAMA
  159888. # define PNG_WRITE_gAMA_SUPPORTED
  159889. # ifndef PNG_gAMA_SUPPORTED
  159890. # define PNG_gAMA_SUPPORTED
  159891. # endif
  159892. #endif
  159893. #ifndef PNG_NO_WRITE_hIST
  159894. # define PNG_WRITE_hIST_SUPPORTED
  159895. # ifndef PNG_hIST_SUPPORTED
  159896. # define PNG_hIST_SUPPORTED
  159897. # endif
  159898. #endif
  159899. #ifndef PNG_NO_WRITE_iCCP
  159900. # define PNG_WRITE_iCCP_SUPPORTED
  159901. # ifndef PNG_iCCP_SUPPORTED
  159902. # define PNG_iCCP_SUPPORTED
  159903. # endif
  159904. #endif
  159905. #ifndef PNG_NO_WRITE_iTXt
  159906. # ifndef PNG_WRITE_iTXt_SUPPORTED
  159907. # define PNG_WRITE_iTXt_SUPPORTED
  159908. # endif
  159909. # ifndef PNG_iTXt_SUPPORTED
  159910. # define PNG_iTXt_SUPPORTED
  159911. # endif
  159912. #endif
  159913. #ifndef PNG_NO_WRITE_oFFs
  159914. # define PNG_WRITE_oFFs_SUPPORTED
  159915. # ifndef PNG_oFFs_SUPPORTED
  159916. # define PNG_oFFs_SUPPORTED
  159917. # endif
  159918. #endif
  159919. #ifndef PNG_NO_WRITE_pCAL
  159920. # define PNG_WRITE_pCAL_SUPPORTED
  159921. # ifndef PNG_pCAL_SUPPORTED
  159922. # define PNG_pCAL_SUPPORTED
  159923. # endif
  159924. #endif
  159925. #ifndef PNG_NO_WRITE_sCAL
  159926. # define PNG_WRITE_sCAL_SUPPORTED
  159927. # ifndef PNG_sCAL_SUPPORTED
  159928. # define PNG_sCAL_SUPPORTED
  159929. # endif
  159930. #endif
  159931. #ifndef PNG_NO_WRITE_pHYs
  159932. # define PNG_WRITE_pHYs_SUPPORTED
  159933. # ifndef PNG_pHYs_SUPPORTED
  159934. # define PNG_pHYs_SUPPORTED
  159935. # endif
  159936. #endif
  159937. #ifndef PNG_NO_WRITE_sBIT
  159938. # define PNG_WRITE_sBIT_SUPPORTED
  159939. # ifndef PNG_sBIT_SUPPORTED
  159940. # define PNG_sBIT_SUPPORTED
  159941. # endif
  159942. #endif
  159943. #ifndef PNG_NO_WRITE_sPLT
  159944. # define PNG_WRITE_sPLT_SUPPORTED
  159945. # ifndef PNG_sPLT_SUPPORTED
  159946. # define PNG_sPLT_SUPPORTED
  159947. # endif
  159948. #endif
  159949. #ifndef PNG_NO_WRITE_sRGB
  159950. # define PNG_WRITE_sRGB_SUPPORTED
  159951. # ifndef PNG_sRGB_SUPPORTED
  159952. # define PNG_sRGB_SUPPORTED
  159953. # endif
  159954. #endif
  159955. #ifndef PNG_NO_WRITE_tEXt
  159956. # define PNG_WRITE_tEXt_SUPPORTED
  159957. # ifndef PNG_tEXt_SUPPORTED
  159958. # define PNG_tEXt_SUPPORTED
  159959. # endif
  159960. #endif
  159961. #ifndef PNG_NO_WRITE_tIME
  159962. # define PNG_WRITE_tIME_SUPPORTED
  159963. # ifndef PNG_tIME_SUPPORTED
  159964. # define PNG_tIME_SUPPORTED
  159965. # endif
  159966. #endif
  159967. #ifndef PNG_NO_WRITE_tRNS
  159968. # define PNG_WRITE_tRNS_SUPPORTED
  159969. # ifndef PNG_tRNS_SUPPORTED
  159970. # define PNG_tRNS_SUPPORTED
  159971. # endif
  159972. #endif
  159973. #ifndef PNG_NO_WRITE_zTXt
  159974. # define PNG_WRITE_zTXt_SUPPORTED
  159975. # ifndef PNG_zTXt_SUPPORTED
  159976. # define PNG_zTXt_SUPPORTED
  159977. # endif
  159978. #endif
  159979. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  159980. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  159981. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159982. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159983. # endif
  159984. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159985. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159986. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159987. # endif
  159988. # endif
  159989. #endif
  159990. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  159991. defined(PNG_WRITE_zTXt_SUPPORTED)
  159992. # define PNG_WRITE_TEXT_SUPPORTED
  159993. # ifndef PNG_TEXT_SUPPORTED
  159994. # define PNG_TEXT_SUPPORTED
  159995. # endif
  159996. #endif
  159997. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  159998. #ifndef PNG_NO_INFO_IMAGE
  159999. # define PNG_INFO_IMAGE_SUPPORTED
  160000. #endif
  160001. #if defined(PNG_tIME_SUPPORTED)
  160002. # if !defined(_WIN32_WCE)
  160003. # include <time.h>
  160004. # endif
  160005. #endif
  160006. typedef unsigned long png_uint_32;
  160007. typedef long png_int_32;
  160008. typedef unsigned short png_uint_16;
  160009. typedef short png_int_16;
  160010. typedef unsigned char png_byte;
  160011. #ifdef PNG_SIZE_T
  160012. typedef PNG_SIZE_T png_size_t;
  160013. # define png_sizeof(x) png_convert_size(sizeof (x))
  160014. #else
  160015. typedef size_t png_size_t;
  160016. # define png_sizeof(x) sizeof (x)
  160017. #endif
  160018. #ifdef __BORLANDC__
  160019. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  160020. # define LDATA 1
  160021. # else
  160022. # define LDATA 0
  160023. # endif
  160024. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  160025. # define PNG_MAX_MALLOC_64K
  160026. # if (LDATA != 1)
  160027. # ifndef FAR
  160028. # define FAR __far
  160029. # endif
  160030. # define USE_FAR_KEYWORD
  160031. # endif /* LDATA != 1 */
  160032. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  160033. #endif /* __BORLANDC__ */
  160034. #if defined(FAR)
  160035. # if defined(M_I86MM)
  160036. # define USE_FAR_KEYWORD
  160037. # define FARDATA FAR
  160038. # include <dos.h>
  160039. # endif
  160040. #endif
  160041. #ifndef FAR
  160042. # define FAR
  160043. #endif
  160044. #ifndef FARDATA
  160045. # define FARDATA
  160046. #endif
  160047. typedef png_int_32 png_fixed_point;
  160048. typedef void FAR * png_voidp;
  160049. typedef png_byte FAR * png_bytep;
  160050. typedef png_uint_32 FAR * png_uint_32p;
  160051. typedef png_int_32 FAR * png_int_32p;
  160052. typedef png_uint_16 FAR * png_uint_16p;
  160053. typedef png_int_16 FAR * png_int_16p;
  160054. typedef PNG_CONST char FAR * png_const_charp;
  160055. typedef char FAR * png_charp;
  160056. typedef png_fixed_point FAR * png_fixed_point_p;
  160057. #ifndef PNG_NO_STDIO
  160058. #if defined(_WIN32_WCE)
  160059. typedef HANDLE png_FILE_p;
  160060. #else
  160061. typedef FILE * png_FILE_p;
  160062. #endif
  160063. #endif
  160064. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160065. typedef double FAR * png_doublep;
  160066. #endif
  160067. typedef png_byte FAR * FAR * png_bytepp;
  160068. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  160069. typedef png_int_32 FAR * FAR * png_int_32pp;
  160070. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  160071. typedef png_int_16 FAR * FAR * png_int_16pp;
  160072. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  160073. typedef char FAR * FAR * png_charpp;
  160074. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  160075. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160076. typedef double FAR * FAR * png_doublepp;
  160077. #endif
  160078. typedef char FAR * FAR * FAR * png_charppp;
  160079. #if 0
  160080. typedef charf * png_zcharp;
  160081. typedef charf * FAR * png_zcharpp;
  160082. typedef z_stream FAR * png_zstreamp;
  160083. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  160084. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  160085. # define PNG_DLL
  160086. #endif
  160087. #if defined(__CYGWIN__)
  160088. # if !defined(PNG_STATIC)
  160089. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160090. # undef PNG_USE_GLOBAL_ARRAYS
  160091. # endif
  160092. # if !defined(PNG_USE_LOCAL_ARRAYS)
  160093. # define PNG_USE_LOCAL_ARRAYS
  160094. # endif
  160095. # else
  160096. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  160097. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160098. # undef PNG_USE_GLOBAL_ARRAYS
  160099. # endif
  160100. # endif
  160101. # endif
  160102. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160103. # define PNG_USE_LOCAL_ARRAYS
  160104. # endif
  160105. #endif
  160106. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160107. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  160108. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  160109. # define PNG_USE_LOCAL_ARRAYS
  160110. # else
  160111. # define PNG_USE_GLOBAL_ARRAYS
  160112. # endif
  160113. #endif
  160114. #if defined(__CYGWIN__)
  160115. # undef PNGAPI
  160116. # define PNGAPI __cdecl
  160117. # undef PNG_IMPEXP
  160118. # define PNG_IMPEXP
  160119. #endif
  160120. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  160121. # ifndef PNG_NO_MODULEDEF
  160122. # define PNG_NO_MODULEDEF
  160123. # endif
  160124. #endif
  160125. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  160126. # define PNG_IMPEXP
  160127. #endif
  160128. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  160129. (( defined(_Windows) || defined(_WINDOWS) || \
  160130. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  160131. # ifndef PNGAPI
  160132. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  160133. # define PNGAPI __cdecl
  160134. # else
  160135. # define PNGAPI _cdecl
  160136. # endif
  160137. # endif
  160138. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  160139. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  160140. # define PNG_IMPEXP
  160141. # endif
  160142. # if !defined(PNG_IMPEXP)
  160143. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160144. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  160145. # if defined(_MSC_VER) || defined(__BORLANDC__)
  160146. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  160147. # define PNG_EXPORT PNG_EXPORT_TYPE1
  160148. # else
  160149. # define PNG_EXPORT PNG_EXPORT_TYPE2
  160150. # if defined(PNG_BUILD_DLL)
  160151. # define PNG_IMPEXP __export
  160152. # else
  160153. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  160154. VC++ */
  160155. # endif /* Exists in Borland C++ for
  160156. C++ classes (== huge) */
  160157. # endif
  160158. # endif
  160159. # if !defined(PNG_IMPEXP)
  160160. # if defined(PNG_BUILD_DLL)
  160161. # define PNG_IMPEXP __declspec(dllexport)
  160162. # else
  160163. # define PNG_IMPEXP __declspec(dllimport)
  160164. # endif
  160165. # endif
  160166. # endif /* PNG_IMPEXP */
  160167. #else /* !(DLL || non-cygwin WINDOWS) */
  160168. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  160169. # ifndef PNGAPI
  160170. # define PNGAPI _System
  160171. # endif
  160172. # else
  160173. # if 0 /* ... other platforms, with other meanings */
  160174. # endif
  160175. # endif
  160176. #endif
  160177. #ifndef PNGAPI
  160178. # define PNGAPI
  160179. #endif
  160180. #ifndef PNG_IMPEXP
  160181. # define PNG_IMPEXP
  160182. #endif
  160183. #ifdef PNG_BUILDSYMS
  160184. # ifndef PNG_EXPORT
  160185. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  160186. # endif
  160187. # ifdef PNG_USE_GLOBAL_ARRAYS
  160188. # ifndef PNG_EXPORT_VAR
  160189. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  160190. # endif
  160191. # endif
  160192. #endif
  160193. #ifndef PNG_EXPORT
  160194. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160195. #endif
  160196. #ifdef PNG_USE_GLOBAL_ARRAYS
  160197. # ifndef PNG_EXPORT_VAR
  160198. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  160199. # endif
  160200. #endif
  160201. #ifndef PNG_ABORT
  160202. # define PNG_ABORT() abort()
  160203. #endif
  160204. #ifdef PNG_SETJMP_SUPPORTED
  160205. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  160206. #else
  160207. # define png_jmpbuf(png_ptr) \
  160208. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  160209. #endif
  160210. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  160211. # define CHECK 1
  160212. # define NOCHECK 0
  160213. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  160214. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  160215. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  160216. # define png_strcpy _fstrcpy
  160217. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  160218. # define png_strlen _fstrlen
  160219. # define png_memcmp _fmemcmp /* SJT: added */
  160220. # define png_memcpy _fmemcpy
  160221. # define png_memset _fmemset
  160222. #else /* use the usual functions */
  160223. # define CVT_PTR(ptr) (ptr)
  160224. # define CVT_PTR_NOCHECK(ptr) (ptr)
  160225. # ifndef PNG_NO_SNPRINTF
  160226. # ifdef _MSC_VER
  160227. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  160228. # define png_snprintf2 _snprintf
  160229. # define png_snprintf6 _snprintf
  160230. # else
  160231. # define png_snprintf snprintf /* Added to v 1.2.19 */
  160232. # define png_snprintf2 snprintf
  160233. # define png_snprintf6 snprintf
  160234. # endif
  160235. # else
  160236. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  160237. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  160238. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  160239. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  160240. # endif
  160241. # define png_strcpy strcpy
  160242. # define png_strncpy strncpy /* Added to v 1.2.6 */
  160243. # define png_strlen strlen
  160244. # define png_memcmp memcmp /* SJT: added */
  160245. # define png_memcpy memcpy
  160246. # define png_memset memset
  160247. #endif
  160248. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  160249. # undef PNG_ZBUF_SIZE
  160250. # define PNG_ZBUF_SIZE 65536L
  160251. #endif
  160252. #endif /* PNG_VERSION_INFO_ONLY */
  160253. #endif /* PNGCONF_H */
  160254. /*** End of inlined file: pngconf.h ***/
  160255. #ifdef _MSC_VER
  160256. #pragma warning (disable: 4996 4100)
  160257. #endif
  160258. #if defined(PNG_USER_PRIVATEBUILD)
  160259. # define PNG_LIBPNG_BUILD_TYPE \
  160260. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  160261. #else
  160262. # if defined(PNG_LIBPNG_SPECIALBUILD)
  160263. # define PNG_LIBPNG_BUILD_TYPE \
  160264. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  160265. # else
  160266. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  160267. # endif
  160268. #endif
  160269. #ifndef PNG_VERSION_INFO_ONLY
  160270. #ifdef __cplusplus
  160271. extern "C" {
  160272. #endif /* __cplusplus */
  160273. #ifndef PNG_NO_TYPECAST_NULL
  160274. #define int_p_NULL (int *)NULL
  160275. #define png_bytep_NULL (png_bytep)NULL
  160276. #define png_bytepp_NULL (png_bytepp)NULL
  160277. #define png_doublep_NULL (png_doublep)NULL
  160278. #define png_error_ptr_NULL (png_error_ptr)NULL
  160279. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160280. #define png_free_ptr_NULL (png_free_ptr)NULL
  160281. #define png_infopp_NULL (png_infopp)NULL
  160282. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160283. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160284. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160285. #define png_structp_NULL (png_structp)NULL
  160286. #define png_uint_16p_NULL (png_uint_16p)NULL
  160287. #define png_voidp_NULL (png_voidp)NULL
  160288. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160289. #else
  160290. #define int_p_NULL NULL
  160291. #define png_bytep_NULL NULL
  160292. #define png_bytepp_NULL NULL
  160293. #define png_doublep_NULL NULL
  160294. #define png_error_ptr_NULL NULL
  160295. #define png_flush_ptr_NULL NULL
  160296. #define png_free_ptr_NULL NULL
  160297. #define png_infopp_NULL NULL
  160298. #define png_malloc_ptr_NULL NULL
  160299. #define png_read_status_ptr_NULL NULL
  160300. #define png_rw_ptr_NULL NULL
  160301. #define png_structp_NULL NULL
  160302. #define png_uint_16p_NULL NULL
  160303. #define png_voidp_NULL NULL
  160304. #define png_write_status_ptr_NULL NULL
  160305. #endif
  160306. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160307. #ifdef PNG_USE_GLOBAL_ARRAYS
  160308. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160309. #else
  160310. #define png_libpng_ver png_get_header_ver(NULL)
  160311. #endif
  160312. #ifdef PNG_USE_GLOBAL_ARRAYS
  160313. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160314. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160315. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160316. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160317. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160318. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160319. #endif
  160320. #endif /* PNG_NO_EXTERN */
  160321. typedef struct png_color_struct
  160322. {
  160323. png_byte red;
  160324. png_byte green;
  160325. png_byte blue;
  160326. } png_color;
  160327. typedef png_color FAR * png_colorp;
  160328. typedef png_color FAR * FAR * png_colorpp;
  160329. typedef struct png_color_16_struct
  160330. {
  160331. png_byte index; /* used for palette files */
  160332. png_uint_16 red; /* for use in red green blue files */
  160333. png_uint_16 green;
  160334. png_uint_16 blue;
  160335. png_uint_16 gray; /* for use in grayscale files */
  160336. } png_color_16;
  160337. typedef png_color_16 FAR * png_color_16p;
  160338. typedef png_color_16 FAR * FAR * png_color_16pp;
  160339. typedef struct png_color_8_struct
  160340. {
  160341. png_byte red; /* for use in red green blue files */
  160342. png_byte green;
  160343. png_byte blue;
  160344. png_byte gray; /* for use in grayscale files */
  160345. png_byte alpha; /* for alpha channel files */
  160346. } png_color_8;
  160347. typedef png_color_8 FAR * png_color_8p;
  160348. typedef png_color_8 FAR * FAR * png_color_8pp;
  160349. typedef struct png_sPLT_entry_struct
  160350. {
  160351. png_uint_16 red;
  160352. png_uint_16 green;
  160353. png_uint_16 blue;
  160354. png_uint_16 alpha;
  160355. png_uint_16 frequency;
  160356. } png_sPLT_entry;
  160357. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160358. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160359. typedef struct png_sPLT_struct
  160360. {
  160361. png_charp name; /* palette name */
  160362. png_byte depth; /* depth of palette samples */
  160363. png_sPLT_entryp entries; /* palette entries */
  160364. png_int_32 nentries; /* number of palette entries */
  160365. } png_sPLT_t;
  160366. typedef png_sPLT_t FAR * png_sPLT_tp;
  160367. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160368. #ifdef PNG_TEXT_SUPPORTED
  160369. typedef struct png_text_struct
  160370. {
  160371. int compression; /* compression value:
  160372. -1: tEXt, none
  160373. 0: zTXt, deflate
  160374. 1: iTXt, none
  160375. 2: iTXt, deflate */
  160376. png_charp key; /* keyword, 1-79 character description of "text" */
  160377. png_charp text; /* comment, may be an empty string (ie "")
  160378. or a NULL pointer */
  160379. png_size_t text_length; /* length of the text string */
  160380. #ifdef PNG_iTXt_SUPPORTED
  160381. png_size_t itxt_length; /* length of the itxt string */
  160382. png_charp lang; /* language code, 0-79 characters
  160383. or a NULL pointer */
  160384. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160385. chars or a NULL pointer */
  160386. #endif
  160387. } png_text;
  160388. typedef png_text FAR * png_textp;
  160389. typedef png_text FAR * FAR * png_textpp;
  160390. #endif
  160391. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160392. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160393. #define PNG_TEXT_COMPRESSION_NONE -1
  160394. #define PNG_TEXT_COMPRESSION_zTXt 0
  160395. #define PNG_ITXT_COMPRESSION_NONE 1
  160396. #define PNG_ITXT_COMPRESSION_zTXt 2
  160397. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160398. typedef struct png_time_struct
  160399. {
  160400. png_uint_16 year; /* full year, as in, 1995 */
  160401. png_byte month; /* month of year, 1 - 12 */
  160402. png_byte day; /* day of month, 1 - 31 */
  160403. png_byte hour; /* hour of day, 0 - 23 */
  160404. png_byte minute; /* minute of hour, 0 - 59 */
  160405. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160406. } png_time;
  160407. typedef png_time FAR * png_timep;
  160408. typedef png_time FAR * FAR * png_timepp;
  160409. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160410. typedef struct png_unknown_chunk_t
  160411. {
  160412. png_byte name[5];
  160413. png_byte *data;
  160414. png_size_t size;
  160415. png_byte location; /* mode of operation at read time */
  160416. }
  160417. png_unknown_chunk;
  160418. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160419. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160420. #endif
  160421. typedef struct png_info_struct
  160422. {
  160423. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160424. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160425. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160426. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160427. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160428. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160429. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160430. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160431. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160432. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160433. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160434. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160435. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160436. png_byte pixel_depth; /* number of bits per pixel */
  160437. png_byte spare_byte; /* to align the data, and for future use */
  160438. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160439. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160440. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160441. #endif
  160442. #if defined(PNG_sRGB_SUPPORTED)
  160443. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160444. #endif
  160445. #if defined(PNG_TEXT_SUPPORTED)
  160446. int num_text; /* number of comments read/to write */
  160447. int max_text; /* current size of text array */
  160448. png_textp text; /* array of comments read/to write */
  160449. #endif /* PNG_TEXT_SUPPORTED */
  160450. #if defined(PNG_tIME_SUPPORTED)
  160451. png_time mod_time;
  160452. #endif
  160453. #if defined(PNG_sBIT_SUPPORTED)
  160454. png_color_8 sig_bit; /* significant bits in color channels */
  160455. #endif
  160456. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160457. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160458. png_bytep trans; /* transparent values for paletted image */
  160459. png_color_16 trans_values; /* transparent color for non-palette image */
  160460. #endif
  160461. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160462. png_color_16 background;
  160463. #endif
  160464. #if defined(PNG_oFFs_SUPPORTED)
  160465. png_int_32 x_offset; /* x offset on page */
  160466. png_int_32 y_offset; /* y offset on page */
  160467. png_byte offset_unit_type; /* offset units type */
  160468. #endif
  160469. #if defined(PNG_pHYs_SUPPORTED)
  160470. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160471. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160472. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160473. #endif
  160474. #if defined(PNG_hIST_SUPPORTED)
  160475. png_uint_16p hist;
  160476. #endif
  160477. #ifdef PNG_cHRM_SUPPORTED
  160478. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160479. float x_white;
  160480. float y_white;
  160481. float x_red;
  160482. float y_red;
  160483. float x_green;
  160484. float y_green;
  160485. float x_blue;
  160486. float y_blue;
  160487. #endif
  160488. #endif
  160489. #if defined(PNG_pCAL_SUPPORTED)
  160490. png_charp pcal_purpose; /* pCAL chunk description string */
  160491. png_int_32 pcal_X0; /* minimum value */
  160492. png_int_32 pcal_X1; /* maximum value */
  160493. png_charp pcal_units; /* Latin-1 string giving physical units */
  160494. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160495. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160496. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160497. #endif
  160498. #ifdef PNG_FREE_ME_SUPPORTED
  160499. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160500. #endif
  160501. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160502. png_unknown_chunkp unknown_chunks;
  160503. png_size_t unknown_chunks_num;
  160504. #endif
  160505. #if defined(PNG_iCCP_SUPPORTED)
  160506. png_charp iccp_name; /* profile name */
  160507. png_charp iccp_profile; /* International Color Consortium profile data */
  160508. png_uint_32 iccp_proflen; /* ICC profile data length */
  160509. png_byte iccp_compression; /* Always zero */
  160510. #endif
  160511. #if defined(PNG_sPLT_SUPPORTED)
  160512. png_sPLT_tp splt_palettes;
  160513. png_uint_32 splt_palettes_num;
  160514. #endif
  160515. #if defined(PNG_sCAL_SUPPORTED)
  160516. png_byte scal_unit; /* unit of physical scale */
  160517. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160518. double scal_pixel_width; /* width of one pixel */
  160519. double scal_pixel_height; /* height of one pixel */
  160520. #endif
  160521. #ifdef PNG_FIXED_POINT_SUPPORTED
  160522. png_charp scal_s_width; /* string containing height */
  160523. png_charp scal_s_height; /* string containing width */
  160524. #endif
  160525. #endif
  160526. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160527. png_bytepp row_pointers; /* the image bits */
  160528. #endif
  160529. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160530. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160531. #endif
  160532. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160533. png_fixed_point int_x_white;
  160534. png_fixed_point int_y_white;
  160535. png_fixed_point int_x_red;
  160536. png_fixed_point int_y_red;
  160537. png_fixed_point int_x_green;
  160538. png_fixed_point int_y_green;
  160539. png_fixed_point int_x_blue;
  160540. png_fixed_point int_y_blue;
  160541. #endif
  160542. } png_info;
  160543. typedef png_info FAR * png_infop;
  160544. typedef png_info FAR * FAR * png_infopp;
  160545. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160546. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160547. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160548. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160549. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160550. #endif
  160551. #define PNG_COLOR_MASK_PALETTE 1
  160552. #define PNG_COLOR_MASK_COLOR 2
  160553. #define PNG_COLOR_MASK_ALPHA 4
  160554. #define PNG_COLOR_TYPE_GRAY 0
  160555. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160556. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160557. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160558. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160559. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160560. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160561. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160562. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160563. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160564. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160565. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160566. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160567. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160568. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160569. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160570. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160571. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160572. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160573. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160574. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160575. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160576. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160577. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160578. #define PNG_SCALE_METER 1 /* meters per pixel */
  160579. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160580. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160581. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160582. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160583. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160584. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160585. #define PNG_sRGB_INTENT_RELATIVE 1
  160586. #define PNG_sRGB_INTENT_SATURATION 2
  160587. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160588. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160589. #define PNG_KEYWORD_MAX_LENGTH 79
  160590. #define PNG_MAX_PALETTE_LENGTH 256
  160591. #define PNG_INFO_gAMA 0x0001
  160592. #define PNG_INFO_sBIT 0x0002
  160593. #define PNG_INFO_cHRM 0x0004
  160594. #define PNG_INFO_PLTE 0x0008
  160595. #define PNG_INFO_tRNS 0x0010
  160596. #define PNG_INFO_bKGD 0x0020
  160597. #define PNG_INFO_hIST 0x0040
  160598. #define PNG_INFO_pHYs 0x0080
  160599. #define PNG_INFO_oFFs 0x0100
  160600. #define PNG_INFO_tIME 0x0200
  160601. #define PNG_INFO_pCAL 0x0400
  160602. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160603. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160604. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160605. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160606. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160607. typedef struct png_row_info_struct
  160608. {
  160609. png_uint_32 width; /* width of row */
  160610. png_uint_32 rowbytes; /* number of bytes in row */
  160611. png_byte color_type; /* color type of row */
  160612. png_byte bit_depth; /* bit depth of row */
  160613. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160614. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160615. } png_row_info;
  160616. typedef png_row_info FAR * png_row_infop;
  160617. typedef png_row_info FAR * FAR * png_row_infopp;
  160618. typedef struct png_struct_def png_struct;
  160619. typedef png_struct FAR * png_structp;
  160620. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160621. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160622. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160623. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160624. int));
  160625. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160626. int));
  160627. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160628. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160629. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160630. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160631. png_uint_32, int));
  160632. #endif
  160633. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160634. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160635. defined(PNG_LEGACY_SUPPORTED)
  160636. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160637. png_row_infop, png_bytep));
  160638. #endif
  160639. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160640. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160641. #endif
  160642. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160643. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160644. #endif
  160645. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160646. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160647. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160648. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160649. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160650. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160651. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160652. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160653. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160654. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160655. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160656. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160657. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160658. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160659. #define PNG_FLAG_MNG_FILTER_64 0x04
  160660. #define PNG_ALL_MNG_FEATURES 0x05
  160661. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160662. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160663. struct png_struct_def
  160664. {
  160665. #ifdef PNG_SETJMP_SUPPORTED
  160666. jmp_buf jmpbuf; /* used in png_error */
  160667. #endif
  160668. png_error_ptr error_fn; /* function for printing errors and aborting */
  160669. png_error_ptr warning_fn; /* function for printing warnings */
  160670. png_voidp error_ptr; /* user supplied struct for error functions */
  160671. png_rw_ptr write_data_fn; /* function for writing output data */
  160672. png_rw_ptr read_data_fn; /* function for reading input data */
  160673. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  160674. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  160675. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  160676. #endif
  160677. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160678. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  160679. #endif
  160680. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  160681. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160682. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160683. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  160684. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  160685. png_byte user_transform_channels; /* channels in user transformed pixels */
  160686. #endif
  160687. #endif
  160688. png_uint_32 mode; /* tells us where we are in the PNG file */
  160689. png_uint_32 flags; /* flags indicating various things to libpng */
  160690. png_uint_32 transformations; /* which transformations to perform */
  160691. z_stream zstream; /* pointer to decompression structure (below) */
  160692. png_bytep zbuf; /* buffer for zlib */
  160693. png_size_t zbuf_size; /* size of zbuf */
  160694. int zlib_level; /* holds zlib compression level */
  160695. int zlib_method; /* holds zlib compression method */
  160696. int zlib_window_bits; /* holds zlib compression window bits */
  160697. int zlib_mem_level; /* holds zlib compression memory level */
  160698. int zlib_strategy; /* holds zlib compression strategy */
  160699. png_uint_32 width; /* width of image in pixels */
  160700. png_uint_32 height; /* height of image in pixels */
  160701. png_uint_32 num_rows; /* number of rows in current pass */
  160702. png_uint_32 usr_width; /* width of row at start of write */
  160703. png_uint_32 rowbytes; /* size of row in bytes */
  160704. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  160705. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  160706. png_uint_32 row_number; /* current row in interlace pass */
  160707. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  160708. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  160709. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  160710. png_bytep up_row; /* buffer to save "up" row when filtering */
  160711. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  160712. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  160713. png_row_info row_info; /* used for transformation routines */
  160714. png_uint_32 idat_size; /* current IDAT size for read */
  160715. png_uint_32 crc; /* current chunk CRC value */
  160716. png_colorp palette; /* palette from the input file */
  160717. png_uint_16 num_palette; /* number of color entries in palette */
  160718. png_uint_16 num_trans; /* number of transparency values */
  160719. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  160720. png_byte compression; /* file compression type (always 0) */
  160721. png_byte filter; /* file filter type (always 0) */
  160722. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160723. png_byte pass; /* current interlace pass (0 - 6) */
  160724. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  160725. png_byte color_type; /* color type of file */
  160726. png_byte bit_depth; /* bit depth of file */
  160727. png_byte usr_bit_depth; /* bit depth of users row */
  160728. png_byte pixel_depth; /* number of bits per pixel */
  160729. png_byte channels; /* number of channels in file */
  160730. png_byte usr_channels; /* channels at start of write */
  160731. png_byte sig_bytes; /* magic bytes read/written from start of file */
  160732. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160733. #ifdef PNG_LEGACY_SUPPORTED
  160734. png_byte filler; /* filler byte for pixel expansion */
  160735. #else
  160736. png_uint_16 filler; /* filler bytes for pixel expansion */
  160737. #endif
  160738. #endif
  160739. #if defined(PNG_bKGD_SUPPORTED)
  160740. png_byte background_gamma_type;
  160741. # ifdef PNG_FLOATING_POINT_SUPPORTED
  160742. float background_gamma;
  160743. # endif
  160744. png_color_16 background; /* background color in screen gamma space */
  160745. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160746. png_color_16 background_1; /* background normalized to gamma 1.0 */
  160747. #endif
  160748. #endif /* PNG_bKGD_SUPPORTED */
  160749. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160750. png_flush_ptr output_flush_fn;/* Function for flushing output */
  160751. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  160752. png_uint_32 flush_rows; /* number of rows written since last flush */
  160753. #endif
  160754. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160755. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  160756. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160757. float gamma; /* file gamma value */
  160758. float screen_gamma; /* screen gamma value (display_exponent) */
  160759. #endif
  160760. #endif
  160761. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160762. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  160763. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  160764. png_bytep gamma_to_1; /* converts from file to 1.0 */
  160765. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  160766. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  160767. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  160768. #endif
  160769. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  160770. png_color_8 sig_bit; /* significant bits in each available channel */
  160771. #endif
  160772. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160773. png_color_8 shift; /* shift for significant bit tranformation */
  160774. #endif
  160775. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  160776. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160777. png_bytep trans; /* transparency values for paletted files */
  160778. png_color_16 trans_values; /* transparency values for non-paletted files */
  160779. #endif
  160780. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  160781. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  160782. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160783. png_progressive_info_ptr info_fn; /* called after header data fully read */
  160784. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  160785. png_progressive_end_ptr end_fn; /* called after image is complete */
  160786. png_bytep save_buffer_ptr; /* current location in save_buffer */
  160787. png_bytep save_buffer; /* buffer for previously read data */
  160788. png_bytep current_buffer_ptr; /* current location in current_buffer */
  160789. png_bytep current_buffer; /* buffer for recently used data */
  160790. png_uint_32 push_length; /* size of current input chunk */
  160791. png_uint_32 skip_length; /* bytes to skip in input data */
  160792. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  160793. png_size_t save_buffer_max; /* total size of save_buffer */
  160794. png_size_t buffer_size; /* total amount of available input data */
  160795. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  160796. int process_mode; /* what push library is currently doing */
  160797. int cur_palette; /* current push library palette index */
  160798. # if defined(PNG_TEXT_SUPPORTED)
  160799. png_size_t current_text_size; /* current size of text input data */
  160800. png_size_t current_text_left; /* how much text left to read in input */
  160801. png_charp current_text; /* current text chunk buffer */
  160802. png_charp current_text_ptr; /* current location in current_text */
  160803. # endif /* PNG_TEXT_SUPPORTED */
  160804. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  160805. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  160806. png_bytepp offset_table_ptr;
  160807. png_bytep offset_table;
  160808. png_uint_16 offset_table_number;
  160809. png_uint_16 offset_table_count;
  160810. png_uint_16 offset_table_count_free;
  160811. #endif
  160812. #if defined(PNG_READ_DITHER_SUPPORTED)
  160813. png_bytep palette_lookup; /* lookup table for dithering */
  160814. png_bytep dither_index; /* index translation for palette files */
  160815. #endif
  160816. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  160817. png_uint_16p hist; /* histogram */
  160818. #endif
  160819. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  160820. png_byte heuristic_method; /* heuristic for row filter selection */
  160821. png_byte num_prev_filters; /* number of weights for previous rows */
  160822. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  160823. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  160824. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  160825. png_uint_16p filter_costs; /* relative filter calculation cost */
  160826. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  160827. #endif
  160828. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160829. png_charp time_buffer; /* String to hold RFC 1123 time text */
  160830. #endif
  160831. #ifdef PNG_FREE_ME_SUPPORTED
  160832. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160833. #endif
  160834. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160835. png_voidp user_chunk_ptr;
  160836. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  160837. #endif
  160838. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160839. int num_chunk_list;
  160840. png_bytep chunk_list;
  160841. #endif
  160842. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160843. png_byte rgb_to_gray_status;
  160844. png_uint_16 rgb_to_gray_red_coeff;
  160845. png_uint_16 rgb_to_gray_green_coeff;
  160846. png_uint_16 rgb_to_gray_blue_coeff;
  160847. #endif
  160848. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  160849. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160850. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160851. #ifdef PNG_1_0_X
  160852. png_byte mng_features_permitted;
  160853. #else
  160854. png_uint_32 mng_features_permitted;
  160855. #endif /* PNG_1_0_X */
  160856. #endif
  160857. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160858. png_fixed_point int_gamma;
  160859. #endif
  160860. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  160861. png_byte filter_type;
  160862. #endif
  160863. #if defined(PNG_1_0_X)
  160864. png_uint_32 row_buf_size;
  160865. #endif
  160866. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  160867. # if !defined(PNG_1_0_X)
  160868. # if defined(PNG_MMX_CODE_SUPPORTED)
  160869. png_byte mmx_bitdepth_threshold;
  160870. png_uint_32 mmx_rowbytes_threshold;
  160871. # endif
  160872. png_uint_32 asm_flags;
  160873. # endif
  160874. #endif
  160875. #ifdef PNG_USER_MEM_SUPPORTED
  160876. png_voidp mem_ptr; /* user supplied struct for mem functions */
  160877. png_malloc_ptr malloc_fn; /* function for allocating memory */
  160878. png_free_ptr free_fn; /* function for freeing memory */
  160879. #endif
  160880. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  160881. #if defined(PNG_READ_DITHER_SUPPORTED)
  160882. png_bytep dither_sort; /* working sort array */
  160883. png_bytep index_to_palette; /* where the original index currently is */
  160884. png_bytep palette_to_index; /* which original index points to this */
  160885. #endif
  160886. png_byte compression_type;
  160887. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  160888. png_uint_32 user_width_max;
  160889. png_uint_32 user_height_max;
  160890. #endif
  160891. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160892. png_unknown_chunk unknown_chunk;
  160893. #endif
  160894. };
  160895. typedef png_structp version_1_2_21;
  160896. typedef png_struct FAR * FAR * png_structpp;
  160897. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  160898. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  160899. int num_bytes));
  160900. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  160901. png_size_t num_to_check));
  160902. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  160903. extern PNG_EXPORT(png_structp,png_create_read_struct)
  160904. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160905. png_error_ptr error_fn, png_error_ptr warn_fn));
  160906. extern PNG_EXPORT(png_structp,png_create_write_struct)
  160907. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160908. png_error_ptr error_fn, png_error_ptr warn_fn));
  160909. #ifdef PNG_WRITE_SUPPORTED
  160910. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  160911. PNGARG((png_structp png_ptr));
  160912. #endif
  160913. #ifdef PNG_WRITE_SUPPORTED
  160914. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  160915. PNGARG((png_structp png_ptr, png_uint_32 size));
  160916. #endif
  160917. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  160918. #ifdef PNG_USER_MEM_SUPPORTED
  160919. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  160920. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160921. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160922. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160923. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  160924. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160925. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160926. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160927. #endif
  160928. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  160929. png_bytep chunk_name, png_bytep data, png_size_t length));
  160930. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  160931. png_bytep chunk_name, png_uint_32 length));
  160932. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  160933. png_bytep data, png_size_t length));
  160934. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  160935. extern PNG_EXPORT(png_infop,png_create_info_struct)
  160936. PNGARG((png_structp png_ptr));
  160937. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160938. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  160939. #undef png_info_init
  160940. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  160941. png_sizeof(png_info));
  160942. #endif
  160943. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  160944. png_size_t png_info_struct_size));
  160945. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  160946. png_infop info_ptr));
  160947. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  160948. png_infop info_ptr));
  160949. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160950. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  160951. png_infop info_ptr));
  160952. #endif
  160953. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160954. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  160955. PNGARG((png_structp png_ptr, png_timep ptime));
  160956. #endif
  160957. #if !defined(_WIN32_WCE)
  160958. #if defined(PNG_WRITE_tIME_SUPPORTED)
  160959. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  160960. struct tm FAR * ttime));
  160961. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  160962. time_t ttime));
  160963. #endif /* PNG_WRITE_tIME_SUPPORTED */
  160964. #endif /* _WIN32_WCE */
  160965. #if defined(PNG_READ_EXPAND_SUPPORTED)
  160966. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  160967. #if !defined(PNG_1_0_X)
  160968. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  160969. png_ptr));
  160970. #endif
  160971. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  160972. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  160973. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160974. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  160975. #endif
  160976. #endif
  160977. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  160978. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  160979. #endif
  160980. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  160981. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  160982. #endif
  160983. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160984. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160985. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  160986. int error_action, double red, double green ));
  160987. #endif
  160988. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  160989. int error_action, png_fixed_point red, png_fixed_point green ));
  160990. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  160991. png_ptr));
  160992. #endif
  160993. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  160994. png_colorp palette));
  160995. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  160996. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  160997. #endif
  160998. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  160999. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161000. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  161001. #endif
  161002. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  161003. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161004. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  161005. #endif
  161006. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  161007. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  161008. png_uint_32 filler, int flags));
  161009. #define PNG_FILLER_BEFORE 0
  161010. #define PNG_FILLER_AFTER 1
  161011. #if !defined(PNG_1_0_X)
  161012. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  161013. png_uint_32 filler, int flags));
  161014. #endif
  161015. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  161016. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161017. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  161018. #endif
  161019. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  161020. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  161021. #endif
  161022. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161023. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  161024. #endif
  161025. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  161026. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  161027. png_color_8p true_bits));
  161028. #endif
  161029. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  161030. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161031. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  161032. #endif
  161033. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161034. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  161035. #endif
  161036. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161037. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161038. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  161039. png_color_16p background_color, int background_gamma_code,
  161040. int need_expand, double background_gamma));
  161041. #endif
  161042. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  161043. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  161044. #define PNG_BACKGROUND_GAMMA_FILE 2
  161045. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  161046. #endif
  161047. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161048. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  161049. #endif
  161050. #if defined(PNG_READ_DITHER_SUPPORTED)
  161051. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  161052. png_colorp palette, int num_palette, int maximum_colors,
  161053. png_uint_16p histogram, int full_dither));
  161054. #endif
  161055. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161056. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161057. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  161058. double screen_gamma, double default_file_gamma));
  161059. #endif
  161060. #endif
  161061. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161062. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161063. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161064. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  161065. int empty_plte_permitted));
  161066. #endif
  161067. #endif
  161068. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161069. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  161070. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  161071. #endif
  161072. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  161073. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  161074. png_infop info_ptr));
  161075. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161076. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  161077. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  161078. #endif
  161079. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161080. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  161081. png_bytep row,
  161082. png_bytep display_row));
  161083. #endif
  161084. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161085. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  161086. png_bytepp image));
  161087. #endif
  161088. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  161089. png_bytep row));
  161090. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  161091. png_bytepp row, png_uint_32 num_rows));
  161092. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  161093. png_bytepp image));
  161094. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  161095. png_infop info_ptr));
  161096. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161097. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  161098. png_infop info_ptr));
  161099. #endif
  161100. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  161101. png_infopp info_ptr_ptr));
  161102. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  161103. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  161104. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  161105. png_infop end_info_ptr));
  161106. extern PNG_EXPORT(void,png_destroy_write_struct)
  161107. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  161108. extern void png_write_destroy PNGARG((png_structp png_ptr));
  161109. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  161110. int crit_action, int ancil_action));
  161111. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  161112. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  161113. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  161114. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  161115. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  161116. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  161117. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  161118. int filters));
  161119. #define PNG_NO_FILTERS 0x00
  161120. #define PNG_FILTER_NONE 0x08
  161121. #define PNG_FILTER_SUB 0x10
  161122. #define PNG_FILTER_UP 0x20
  161123. #define PNG_FILTER_AVG 0x40
  161124. #define PNG_FILTER_PAETH 0x80
  161125. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  161126. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  161127. #define PNG_FILTER_VALUE_NONE 0
  161128. #define PNG_FILTER_VALUE_SUB 1
  161129. #define PNG_FILTER_VALUE_UP 2
  161130. #define PNG_FILTER_VALUE_AVG 3
  161131. #define PNG_FILTER_VALUE_PAETH 4
  161132. #define PNG_FILTER_VALUE_LAST 5
  161133. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  161134. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161135. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  161136. int heuristic_method, int num_weights, png_doublep filter_weights,
  161137. png_doublep filter_costs));
  161138. #endif
  161139. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  161140. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  161141. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  161142. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  161143. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  161144. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  161145. int level));
  161146. extern PNG_EXPORT(void,png_set_compression_mem_level)
  161147. PNGARG((png_structp png_ptr, int mem_level));
  161148. extern PNG_EXPORT(void,png_set_compression_strategy)
  161149. PNGARG((png_structp png_ptr, int strategy));
  161150. extern PNG_EXPORT(void,png_set_compression_window_bits)
  161151. PNGARG((png_structp png_ptr, int window_bits));
  161152. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  161153. int method));
  161154. #if !defined(PNG_NO_STDIO)
  161155. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  161156. #endif
  161157. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  161158. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  161159. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  161160. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  161161. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  161162. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  161163. png_voidp io_ptr, png_rw_ptr read_data_fn));
  161164. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  161165. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  161166. png_read_status_ptr read_row_fn));
  161167. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  161168. png_write_status_ptr write_row_fn));
  161169. #ifdef PNG_USER_MEM_SUPPORTED
  161170. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  161171. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161172. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  161173. #endif
  161174. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161175. defined(PNG_LEGACY_SUPPORTED)
  161176. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  161177. png_ptr, png_user_transform_ptr read_user_transform_fn));
  161178. #endif
  161179. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161180. defined(PNG_LEGACY_SUPPORTED)
  161181. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  161182. png_ptr, png_user_transform_ptr write_user_transform_fn));
  161183. #endif
  161184. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161185. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161186. defined(PNG_LEGACY_SUPPORTED)
  161187. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  161188. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  161189. int user_transform_channels));
  161190. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  161191. PNGARG((png_structp png_ptr));
  161192. #endif
  161193. #ifdef PNG_USER_CHUNKS_SUPPORTED
  161194. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  161195. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  161196. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  161197. png_ptr));
  161198. #endif
  161199. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161200. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  161201. png_voidp progressive_ptr,
  161202. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  161203. png_progressive_end_ptr end_fn));
  161204. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  161205. PNGARG((png_structp png_ptr));
  161206. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  161207. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  161208. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  161209. png_bytep old_row, png_bytep new_row));
  161210. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161211. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  161212. png_uint_32 size));
  161213. #if defined(PNG_1_0_X)
  161214. # define png_malloc_warn png_malloc
  161215. #else
  161216. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  161217. png_uint_32 size));
  161218. #endif
  161219. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  161220. #if defined(PNG_1_0_X)
  161221. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  161222. uInt size));
  161223. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  161224. #endif
  161225. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  161226. png_infop info_ptr, png_uint_32 free_me, int num));
  161227. #ifdef PNG_FREE_ME_SUPPORTED
  161228. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  161229. png_infop info_ptr, int freer, png_uint_32 mask));
  161230. #endif
  161231. #define PNG_DESTROY_WILL_FREE_DATA 1
  161232. #define PNG_SET_WILL_FREE_DATA 1
  161233. #define PNG_USER_WILL_FREE_DATA 2
  161234. #define PNG_FREE_HIST 0x0008
  161235. #define PNG_FREE_ICCP 0x0010
  161236. #define PNG_FREE_SPLT 0x0020
  161237. #define PNG_FREE_ROWS 0x0040
  161238. #define PNG_FREE_PCAL 0x0080
  161239. #define PNG_FREE_SCAL 0x0100
  161240. #define PNG_FREE_UNKN 0x0200
  161241. #define PNG_FREE_LIST 0x0400
  161242. #define PNG_FREE_PLTE 0x1000
  161243. #define PNG_FREE_TRNS 0x2000
  161244. #define PNG_FREE_TEXT 0x4000
  161245. #define PNG_FREE_ALL 0x7fff
  161246. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  161247. #ifdef PNG_USER_MEM_SUPPORTED
  161248. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  161249. png_uint_32 size));
  161250. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  161251. png_voidp ptr));
  161252. #endif
  161253. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  161254. png_voidp s1, png_voidp s2, png_uint_32 size));
  161255. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  161256. png_voidp s1, int value, png_uint_32 size));
  161257. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  161258. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  161259. int check));
  161260. #endif /* USE_FAR_KEYWORD */
  161261. #ifndef PNG_NO_ERROR_TEXT
  161262. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  161263. png_const_charp error_message));
  161264. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  161265. png_const_charp error_message));
  161266. #else
  161267. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  161268. #endif
  161269. #ifndef PNG_NO_WARNINGS
  161270. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161271. png_const_charp warning_message));
  161272. #ifdef PNG_READ_SUPPORTED
  161273. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161274. png_const_charp warning_message));
  161275. #endif /* PNG_READ_SUPPORTED */
  161276. #endif /* PNG_NO_WARNINGS */
  161277. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161278. png_infop info_ptr, png_uint_32 flag));
  161279. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161280. png_infop info_ptr));
  161281. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161282. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161283. png_infop info_ptr));
  161284. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161285. png_infop info_ptr, png_bytepp row_pointers));
  161286. #endif
  161287. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161288. png_infop info_ptr));
  161289. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161290. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161291. png_ptr, png_infop info_ptr));
  161292. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161293. png_ptr, png_infop info_ptr));
  161294. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161295. png_ptr, png_infop info_ptr));
  161296. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161297. png_ptr, png_infop info_ptr));
  161298. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161299. png_ptr, png_infop info_ptr));
  161300. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161301. png_ptr, png_infop info_ptr));
  161302. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161303. png_ptr, png_infop info_ptr));
  161304. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161305. png_ptr, png_infop info_ptr));
  161306. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161307. png_ptr, png_infop info_ptr));
  161308. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161309. png_ptr, png_infop info_ptr));
  161310. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161311. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161312. png_ptr, png_infop info_ptr));
  161313. #endif
  161314. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161315. png_ptr, png_infop info_ptr));
  161316. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161317. png_ptr, png_infop info_ptr));
  161318. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161319. png_ptr, png_infop info_ptr));
  161320. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161321. png_ptr, png_infop info_ptr));
  161322. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161323. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161324. png_infop info_ptr));
  161325. #if defined(PNG_bKGD_SUPPORTED)
  161326. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161327. png_infop info_ptr, png_color_16p *background));
  161328. #endif
  161329. #if defined(PNG_bKGD_SUPPORTED)
  161330. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161331. png_infop info_ptr, png_color_16p background));
  161332. #endif
  161333. #if defined(PNG_cHRM_SUPPORTED)
  161334. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161335. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161336. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161337. double *red_y, double *green_x, double *green_y, double *blue_x,
  161338. double *blue_y));
  161339. #endif
  161340. #ifdef PNG_FIXED_POINT_SUPPORTED
  161341. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161342. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161343. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161344. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161345. *int_blue_x, png_fixed_point *int_blue_y));
  161346. #endif
  161347. #endif
  161348. #if defined(PNG_cHRM_SUPPORTED)
  161349. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161350. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161351. png_infop info_ptr, double white_x, double white_y, double red_x,
  161352. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161353. #endif
  161354. #ifdef PNG_FIXED_POINT_SUPPORTED
  161355. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161356. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161357. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161358. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161359. png_fixed_point int_blue_y));
  161360. #endif
  161361. #endif
  161362. #if defined(PNG_gAMA_SUPPORTED)
  161363. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161364. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161365. png_infop info_ptr, double *file_gamma));
  161366. #endif
  161367. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161368. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161369. #endif
  161370. #if defined(PNG_gAMA_SUPPORTED)
  161371. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161372. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161373. png_infop info_ptr, double file_gamma));
  161374. #endif
  161375. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161376. png_infop info_ptr, png_fixed_point int_file_gamma));
  161377. #endif
  161378. #if defined(PNG_hIST_SUPPORTED)
  161379. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161380. png_infop info_ptr, png_uint_16p *hist));
  161381. #endif
  161382. #if defined(PNG_hIST_SUPPORTED)
  161383. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161384. png_infop info_ptr, png_uint_16p hist));
  161385. #endif
  161386. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161387. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161388. int *bit_depth, int *color_type, int *interlace_method,
  161389. int *compression_method, int *filter_method));
  161390. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161391. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161392. int color_type, int interlace_method, int compression_method,
  161393. int filter_method));
  161394. #if defined(PNG_oFFs_SUPPORTED)
  161395. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161396. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161397. int *unit_type));
  161398. #endif
  161399. #if defined(PNG_oFFs_SUPPORTED)
  161400. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161401. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161402. int unit_type));
  161403. #endif
  161404. #if defined(PNG_pCAL_SUPPORTED)
  161405. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161406. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161407. int *type, int *nparams, png_charp *units, png_charpp *params));
  161408. #endif
  161409. #if defined(PNG_pCAL_SUPPORTED)
  161410. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161411. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161412. int type, int nparams, png_charp units, png_charpp params));
  161413. #endif
  161414. #if defined(PNG_pHYs_SUPPORTED)
  161415. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161416. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161417. #endif
  161418. #if defined(PNG_pHYs_SUPPORTED)
  161419. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161420. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161421. #endif
  161422. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161423. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161424. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161425. png_infop info_ptr, png_colorp palette, int num_palette));
  161426. #if defined(PNG_sBIT_SUPPORTED)
  161427. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161428. png_infop info_ptr, png_color_8p *sig_bit));
  161429. #endif
  161430. #if defined(PNG_sBIT_SUPPORTED)
  161431. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161432. png_infop info_ptr, png_color_8p sig_bit));
  161433. #endif
  161434. #if defined(PNG_sRGB_SUPPORTED)
  161435. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161436. png_infop info_ptr, int *intent));
  161437. #endif
  161438. #if defined(PNG_sRGB_SUPPORTED)
  161439. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161440. png_infop info_ptr, int intent));
  161441. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161442. png_infop info_ptr, int intent));
  161443. #endif
  161444. #if defined(PNG_iCCP_SUPPORTED)
  161445. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161446. png_infop info_ptr, png_charpp name, int *compression_type,
  161447. png_charpp profile, png_uint_32 *proflen));
  161448. #endif
  161449. #if defined(PNG_iCCP_SUPPORTED)
  161450. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161451. png_infop info_ptr, png_charp name, int compression_type,
  161452. png_charp profile, png_uint_32 proflen));
  161453. #endif
  161454. #if defined(PNG_sPLT_SUPPORTED)
  161455. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161456. png_infop info_ptr, png_sPLT_tpp entries));
  161457. #endif
  161458. #if defined(PNG_sPLT_SUPPORTED)
  161459. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161460. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161461. #endif
  161462. #if defined(PNG_TEXT_SUPPORTED)
  161463. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161464. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161465. #endif
  161466. #if defined(PNG_TEXT_SUPPORTED)
  161467. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161468. png_infop info_ptr, png_textp text_ptr, int num_text));
  161469. #endif
  161470. #if defined(PNG_tIME_SUPPORTED)
  161471. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161472. png_infop info_ptr, png_timep *mod_time));
  161473. #endif
  161474. #if defined(PNG_tIME_SUPPORTED)
  161475. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161476. png_infop info_ptr, png_timep mod_time));
  161477. #endif
  161478. #if defined(PNG_tRNS_SUPPORTED)
  161479. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161480. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161481. png_color_16p *trans_values));
  161482. #endif
  161483. #if defined(PNG_tRNS_SUPPORTED)
  161484. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161485. png_infop info_ptr, png_bytep trans, int num_trans,
  161486. png_color_16p trans_values));
  161487. #endif
  161488. #if defined(PNG_tRNS_SUPPORTED)
  161489. #endif
  161490. #if defined(PNG_sCAL_SUPPORTED)
  161491. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161492. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161493. png_infop info_ptr, int *unit, double *width, double *height));
  161494. #else
  161495. #ifdef PNG_FIXED_POINT_SUPPORTED
  161496. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161497. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161498. #endif
  161499. #endif
  161500. #endif /* PNG_sCAL_SUPPORTED */
  161501. #if defined(PNG_sCAL_SUPPORTED)
  161502. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161503. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161504. png_infop info_ptr, int unit, double width, double height));
  161505. #else
  161506. #ifdef PNG_FIXED_POINT_SUPPORTED
  161507. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161508. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161509. #endif
  161510. #endif
  161511. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161512. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161513. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161514. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161515. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161516. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161517. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161518. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161519. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161520. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161521. #endif
  161522. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161523. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161524. chunk_name));
  161525. #endif
  161526. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161527. png_infop info_ptr, int mask));
  161528. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161529. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161530. png_infop info_ptr,
  161531. int transforms,
  161532. png_voidp params));
  161533. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161534. png_infop info_ptr,
  161535. int transforms,
  161536. png_voidp params));
  161537. #endif
  161538. #ifdef PNG_DEBUG
  161539. #if (PNG_DEBUG > 0)
  161540. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161541. #include <crtdbg.h>
  161542. #if (PNG_DEBUG > 1)
  161543. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161544. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161545. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161546. #endif
  161547. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161548. #ifndef PNG_DEBUG_FILE
  161549. #define PNG_DEBUG_FILE stderr
  161550. #endif /* PNG_DEBUG_FILE */
  161551. #if (PNG_DEBUG > 1)
  161552. #define png_debug(l,m) \
  161553. { \
  161554. int num_tabs=l; \
  161555. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161556. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161557. }
  161558. #define png_debug1(l,m,p1) \
  161559. { \
  161560. int num_tabs=l; \
  161561. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161562. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161563. }
  161564. #define png_debug2(l,m,p1,p2) \
  161565. { \
  161566. int num_tabs=l; \
  161567. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161568. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  161569. }
  161570. #endif /* (PNG_DEBUG > 1) */
  161571. #endif /* _MSC_VER */
  161572. #endif /* (PNG_DEBUG > 0) */
  161573. #endif /* PNG_DEBUG */
  161574. #ifndef png_debug
  161575. #define png_debug(l, m)
  161576. #endif
  161577. #ifndef png_debug1
  161578. #define png_debug1(l, m, p1)
  161579. #endif
  161580. #ifndef png_debug2
  161581. #define png_debug2(l, m, p1, p2)
  161582. #endif
  161583. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161584. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161585. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161586. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161587. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161588. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161589. png_ptr, png_uint_32 mng_features_permitted));
  161590. #endif
  161591. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161592. #define PNG_HANDLE_CHUNK_NEVER 1
  161593. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161594. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161595. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161596. #if defined(PNG_MMX_CODE_SUPPORTED)
  161597. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161598. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161599. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161600. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161601. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161602. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161603. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161604. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161605. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161606. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161607. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161608. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161609. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161610. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161611. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161612. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161613. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161614. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161615. | PNG_MMX_READ_FLAGS \
  161616. | PNG_MMX_WRITE_FLAGS )
  161617. #define PNG_SELECT_READ 1
  161618. #define PNG_SELECT_WRITE 2
  161619. #endif /* PNG_MMX_CODE_SUPPORTED */
  161620. #if !defined(PNG_1_0_X)
  161621. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161622. PNGARG((int flag_select, int *compilerID));
  161623. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161624. PNGARG((int flag_select));
  161625. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161626. PNGARG((png_structp png_ptr));
  161627. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161628. PNGARG((png_structp png_ptr));
  161629. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161630. PNGARG((png_structp png_ptr));
  161631. extern PNG_EXPORT(void,png_set_asm_flags)
  161632. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161633. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161634. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161635. png_uint_32 mmx_rowbytes_threshold));
  161636. #endif /* PNG_1_0_X */
  161637. #if !defined(PNG_1_0_X)
  161638. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161639. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161640. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161641. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161642. png_ptr, png_uint_32 strip_mode));
  161643. #endif
  161644. #endif /* PNG_1_0_X */
  161645. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161646. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161647. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161648. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161649. png_ptr));
  161650. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161651. png_ptr));
  161652. #endif
  161653. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161654. # define png_composite(composite, fg, alpha, bg) \
  161655. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161656. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161657. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161658. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161659. # define png_composite_16(composite, fg, alpha, bg) \
  161660. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161661. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161662. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161663. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161664. #else /* standard method using integer division */
  161665. # define png_composite(composite, fg, alpha, bg) \
  161666. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161667. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161668. (png_uint_16)127) / 255)
  161669. # define png_composite_16(composite, fg, alpha, bg) \
  161670. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  161671. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  161672. (png_uint_32)32767) / (png_uint_32)65535L)
  161673. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  161674. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  161675. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  161676. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  161677. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  161678. #else
  161679. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  161680. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  161681. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  161682. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  161683. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  161684. PNGARG((png_structp png_ptr, png_bytep buf));
  161685. extern PNG_EXPORT(void,png_save_uint_32)
  161686. PNGARG((png_bytep buf, png_uint_32 i));
  161687. extern PNG_EXPORT(void,png_save_int_32)
  161688. PNGARG((png_bytep buf, png_int_32 i));
  161689. extern PNG_EXPORT(void,png_save_uint_16)
  161690. PNGARG((png_bytep buf, unsigned int i));
  161691. #define PNG_HAVE_IHDR 0x01
  161692. #define PNG_HAVE_PLTE 0x02
  161693. #define PNG_HAVE_IDAT 0x04
  161694. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  161695. #define PNG_HAVE_IEND 0x10
  161696. #if defined(PNG_INTERNAL)
  161697. #define PNG_HAVE_gAMA 0x20
  161698. #define PNG_HAVE_cHRM 0x40
  161699. #define PNG_HAVE_sRGB 0x80
  161700. #define PNG_HAVE_CHUNK_HEADER 0x100
  161701. #define PNG_WROTE_tIME 0x200
  161702. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  161703. #define PNG_BACKGROUND_IS_GRAY 0x800
  161704. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  161705. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  161706. #define PNG_BGR 0x0001
  161707. #define PNG_INTERLACE 0x0002
  161708. #define PNG_PACK 0x0004
  161709. #define PNG_SHIFT 0x0008
  161710. #define PNG_SWAP_BYTES 0x0010
  161711. #define PNG_INVERT_MONO 0x0020
  161712. #define PNG_DITHER 0x0040
  161713. #define PNG_BACKGROUND 0x0080
  161714. #define PNG_BACKGROUND_EXPAND 0x0100
  161715. #define PNG_16_TO_8 0x0400
  161716. #define PNG_RGBA 0x0800
  161717. #define PNG_EXPAND 0x1000
  161718. #define PNG_GAMMA 0x2000
  161719. #define PNG_GRAY_TO_RGB 0x4000
  161720. #define PNG_FILLER 0x8000L
  161721. #define PNG_PACKSWAP 0x10000L
  161722. #define PNG_SWAP_ALPHA 0x20000L
  161723. #define PNG_STRIP_ALPHA 0x40000L
  161724. #define PNG_INVERT_ALPHA 0x80000L
  161725. #define PNG_USER_TRANSFORM 0x100000L
  161726. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  161727. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  161728. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  161729. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  161730. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  161731. #define PNG_STRUCT_PNG 0x0001
  161732. #define PNG_STRUCT_INFO 0x0002
  161733. #define PNG_WEIGHT_SHIFT 8
  161734. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  161735. #define PNG_COST_SHIFT 3
  161736. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  161737. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  161738. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  161739. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  161740. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  161741. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  161742. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  161743. #define PNG_FLAG_ROW_INIT 0x0040
  161744. #define PNG_FLAG_FILLER_AFTER 0x0080
  161745. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  161746. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  161747. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  161748. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  161749. #define PNG_FLAG_FREE_PLTE 0x1000
  161750. #define PNG_FLAG_FREE_TRNS 0x2000
  161751. #define PNG_FLAG_FREE_HIST 0x4000
  161752. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  161753. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  161754. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  161755. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  161756. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  161757. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  161758. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  161759. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  161760. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  161761. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  161762. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  161763. PNG_FLAG_CRC_CRITICAL_IGNORE)
  161764. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  161765. PNG_FLAG_CRC_CRITICAL_MASK)
  161766. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  161767. abs((int)((c1).green) - (int)((c2).green)) + \
  161768. abs((int)((c1).blue) - (int)((c2).blue)))
  161769. #define PNG_ROWBYTES(pixel_bits, width) \
  161770. ((pixel_bits) >= 8 ? \
  161771. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  161772. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  161773. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  161774. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  161775. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  161776. #ifdef PNG_USE_GLOBAL_ARRAYS
  161777. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  161778. #else
  161779. #endif
  161780. #endif /* PNG_NO_EXTERN */
  161781. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  161782. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  161783. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  161784. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  161785. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  161786. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  161787. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  161788. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  161789. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  161790. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  161791. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  161792. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  161793. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  161794. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  161795. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  161796. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  161797. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  161798. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  161799. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  161800. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  161801. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  161802. #ifdef PNG_USE_GLOBAL_ARRAYS
  161803. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  161804. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  161805. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  161806. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  161807. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  161808. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  161809. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  161810. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  161811. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  161812. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  161813. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  161814. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  161815. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  161816. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  161817. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  161818. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  161819. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  161820. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  161821. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  161822. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  161823. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  161824. #endif /* PNG_USE_GLOBAL_ARRAYS */
  161825. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161826. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  161827. #undef png_read_init
  161828. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  161829. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161830. #endif
  161831. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  161832. png_const_charp user_png_ver, png_size_t png_struct_size));
  161833. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161834. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  161835. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161836. png_info_size));
  161837. #endif
  161838. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161839. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  161840. #undef png_write_init
  161841. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  161842. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161843. #endif
  161844. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  161845. png_const_charp user_png_ver, png_size_t png_struct_size));
  161846. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  161847. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161848. png_info_size));
  161849. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  161850. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  161851. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  161852. malloc_fn, png_voidp mem_ptr));
  161853. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  161854. png_free_ptr free_fn, png_voidp mem_ptr));
  161855. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  161856. png_infop info_ptr));
  161857. #ifndef PNG_1_0_X
  161858. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  161859. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  161860. #ifdef PNG_SIZE_T
  161861. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  161862. #endif
  161863. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  161864. png_bytep data, png_size_t length));
  161865. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161866. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  161867. png_bytep buffer, png_size_t length));
  161868. #endif
  161869. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  161870. png_bytep data, png_size_t length));
  161871. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161872. #if !defined(PNG_NO_STDIO)
  161873. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  161874. #endif
  161875. #endif
  161876. #else /* PNG_1_0_X */
  161877. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161878. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  161879. png_bytep buffer, png_size_t length));
  161880. #endif
  161881. #endif /* PNG_1_0_X */
  161882. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  161883. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  161884. png_size_t length));
  161885. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  161886. png_size_t length));
  161887. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  161888. png_size_t length));
  161889. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  161890. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  161891. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  161892. int comp_type, png_charp chunkdata, png_size_t chunklength,
  161893. png_size_t prefix_length, png_size_t *data_length));
  161894. #endif
  161895. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  161896. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  161897. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  161898. png_size_t length));
  161899. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161900. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  161901. #endif
  161902. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  161903. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  161904. png_uint_32 height,
  161905. int bit_depth, int color_type, int compression_method, int filter_method,
  161906. int interlace_method));
  161907. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  161908. png_uint_32 num_pal));
  161909. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  161910. png_size_t length));
  161911. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  161912. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  161913. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161914. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  161915. #endif
  161916. #ifdef PNG_FIXED_POINT_SUPPORTED
  161917. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  161918. file_gamma));
  161919. #endif
  161920. #endif
  161921. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  161922. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  161923. int color_type));
  161924. #endif
  161925. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  161926. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161927. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  161928. double white_x, double white_y,
  161929. double red_x, double red_y, double green_x, double green_y,
  161930. double blue_x, double blue_y));
  161931. #endif
  161932. #ifdef PNG_FIXED_POINT_SUPPORTED
  161933. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  161934. png_fixed_point int_white_x, png_fixed_point int_white_y,
  161935. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161936. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161937. png_fixed_point int_blue_y));
  161938. #endif
  161939. #endif
  161940. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  161941. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  161942. int intent));
  161943. #endif
  161944. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  161945. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  161946. png_charp name, int compression_type,
  161947. png_charp profile, int proflen));
  161948. #endif
  161949. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  161950. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  161951. png_sPLT_tp palette));
  161952. #endif
  161953. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  161954. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  161955. png_color_16p values, int number, int color_type));
  161956. #endif
  161957. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  161958. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  161959. png_color_16p values, int color_type));
  161960. #endif
  161961. #if defined(PNG_WRITE_hIST_SUPPORTED)
  161962. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  161963. int num_hist));
  161964. #endif
  161965. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  161966. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  161967. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  161968. png_charp key, png_charpp new_key));
  161969. #endif
  161970. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  161971. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  161972. png_charp text, png_size_t text_len));
  161973. #endif
  161974. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  161975. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  161976. png_charp text, png_size_t text_len, int compression));
  161977. #endif
  161978. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  161979. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  161980. int compression, png_charp key, png_charp lang, png_charp lang_key,
  161981. png_charp text));
  161982. #endif
  161983. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  161984. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  161985. png_infop info_ptr, png_textp text_ptr, int num_text));
  161986. #endif
  161987. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  161988. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  161989. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  161990. #endif
  161991. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  161992. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  161993. png_int_32 X0, png_int_32 X1, int type, int nparams,
  161994. png_charp units, png_charpp params));
  161995. #endif
  161996. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  161997. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  161998. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  161999. int unit_type));
  162000. #endif
  162001. #if defined(PNG_WRITE_tIME_SUPPORTED)
  162002. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  162003. png_timep mod_time));
  162004. #endif
  162005. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  162006. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  162007. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  162008. int unit, double width, double height));
  162009. #else
  162010. #ifdef PNG_FIXED_POINT_SUPPORTED
  162011. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  162012. int unit, png_charp width, png_charp height));
  162013. #endif
  162014. #endif
  162015. #endif
  162016. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  162017. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  162018. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162019. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  162020. #endif
  162021. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  162022. int mask));
  162023. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  162024. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  162025. #endif
  162026. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  162027. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  162028. png_bytep row, int pass));
  162029. #endif
  162030. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  162031. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  162032. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  162033. png_row_infop row_info));
  162034. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  162035. png_bytep filtered_row));
  162036. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  162037. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  162038. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  162039. png_infop info_ptr));
  162040. #if defined(PNG_READ_FILLER_SUPPORTED)
  162041. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  162042. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  162043. #endif
  162044. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  162045. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  162046. png_bytep row));
  162047. #endif
  162048. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  162049. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  162050. png_bytep row));
  162051. #endif
  162052. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  162053. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  162054. png_bytep row));
  162055. #endif
  162056. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  162057. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  162058. png_bytep row));
  162059. #endif
  162060. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  162061. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  162062. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  162063. png_bytep row, png_uint_32 flags));
  162064. #endif
  162065. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  162066. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  162067. #endif
  162068. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  162069. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  162070. #endif
  162071. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  162072. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  162073. row_info, png_bytep row));
  162074. #endif
  162075. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  162076. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  162077. png_bytep row));
  162078. #endif
  162079. #if defined(PNG_READ_PACK_SUPPORTED)
  162080. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  162081. #endif
  162082. #if defined(PNG_READ_SHIFT_SUPPORTED)
  162083. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  162084. png_color_8p sig_bits));
  162085. #endif
  162086. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  162087. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  162088. #endif
  162089. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  162090. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  162091. #endif
  162092. #if defined(PNG_READ_DITHER_SUPPORTED)
  162093. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  162094. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  162095. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  162096. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  162097. png_colorp palette, int num_palette));
  162098. # endif
  162099. #endif
  162100. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  162101. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  162102. #endif
  162103. #if defined(PNG_WRITE_PACK_SUPPORTED)
  162104. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  162105. png_bytep row, png_uint_32 bit_depth));
  162106. #endif
  162107. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  162108. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  162109. png_color_8p bit_depth));
  162110. #endif
  162111. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  162112. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162113. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162114. png_color_16p trans_values, png_color_16p background,
  162115. png_color_16p background_1,
  162116. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  162117. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  162118. png_uint_16pp gamma_16_to_1, int gamma_shift));
  162119. #else
  162120. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162121. png_color_16p trans_values, png_color_16p background));
  162122. #endif
  162123. #endif
  162124. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162125. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  162126. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  162127. int gamma_shift));
  162128. #endif
  162129. #if defined(PNG_READ_EXPAND_SUPPORTED)
  162130. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  162131. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  162132. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  162133. png_bytep row, png_color_16p trans_value));
  162134. #endif
  162135. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  162136. png_uint_32 length));
  162137. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  162138. png_uint_32 length));
  162139. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  162140. png_uint_32 length));
  162141. #if defined(PNG_READ_bKGD_SUPPORTED)
  162142. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  162143. png_uint_32 length));
  162144. #endif
  162145. #if defined(PNG_READ_cHRM_SUPPORTED)
  162146. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  162147. png_uint_32 length));
  162148. #endif
  162149. #if defined(PNG_READ_gAMA_SUPPORTED)
  162150. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  162151. png_uint_32 length));
  162152. #endif
  162153. #if defined(PNG_READ_hIST_SUPPORTED)
  162154. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  162155. png_uint_32 length));
  162156. #endif
  162157. #if defined(PNG_READ_iCCP_SUPPORTED)
  162158. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  162159. png_uint_32 length));
  162160. #endif /* PNG_READ_iCCP_SUPPORTED */
  162161. #if defined(PNG_READ_iTXt_SUPPORTED)
  162162. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162163. png_uint_32 length));
  162164. #endif
  162165. #if defined(PNG_READ_oFFs_SUPPORTED)
  162166. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162167. png_uint_32 length));
  162168. #endif
  162169. #if defined(PNG_READ_pCAL_SUPPORTED)
  162170. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162171. png_uint_32 length));
  162172. #endif
  162173. #if defined(PNG_READ_pHYs_SUPPORTED)
  162174. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162175. png_uint_32 length));
  162176. #endif
  162177. #if defined(PNG_READ_sBIT_SUPPORTED)
  162178. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162179. png_uint_32 length));
  162180. #endif
  162181. #if defined(PNG_READ_sCAL_SUPPORTED)
  162182. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162183. png_uint_32 length));
  162184. #endif
  162185. #if defined(PNG_READ_sPLT_SUPPORTED)
  162186. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162187. png_uint_32 length));
  162188. #endif /* PNG_READ_sPLT_SUPPORTED */
  162189. #if defined(PNG_READ_sRGB_SUPPORTED)
  162190. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  162191. png_uint_32 length));
  162192. #endif
  162193. #if defined(PNG_READ_tEXt_SUPPORTED)
  162194. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162195. png_uint_32 length));
  162196. #endif
  162197. #if defined(PNG_READ_tIME_SUPPORTED)
  162198. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  162199. png_uint_32 length));
  162200. #endif
  162201. #if defined(PNG_READ_tRNS_SUPPORTED)
  162202. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  162203. png_uint_32 length));
  162204. #endif
  162205. #if defined(PNG_READ_zTXt_SUPPORTED)
  162206. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162207. png_uint_32 length));
  162208. #endif
  162209. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  162210. png_infop info_ptr, png_uint_32 length));
  162211. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  162212. png_bytep chunk_name));
  162213. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  162214. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  162215. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  162216. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162217. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  162218. png_infop info_ptr));
  162219. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  162220. png_infop info_ptr));
  162221. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  162222. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  162223. png_uint_32 length));
  162224. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  162225. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  162226. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  162227. png_bytep buffer, png_size_t buffer_length));
  162228. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  162229. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  162230. png_bytep buffer, png_size_t buffer_length));
  162231. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  162232. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  162233. png_infop info_ptr, png_uint_32 length));
  162234. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  162235. png_infop info_ptr));
  162236. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  162237. png_infop info_ptr));
  162238. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  162239. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  162240. png_infop info_ptr));
  162241. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  162242. png_infop info_ptr));
  162243. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  162244. #if defined(PNG_READ_tEXt_SUPPORTED)
  162245. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  162246. png_infop info_ptr, png_uint_32 length));
  162247. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  162248. png_infop info_ptr));
  162249. #endif
  162250. #if defined(PNG_READ_zTXt_SUPPORTED)
  162251. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  162252. png_infop info_ptr, png_uint_32 length));
  162253. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  162254. png_infop info_ptr));
  162255. #endif
  162256. #if defined(PNG_READ_iTXt_SUPPORTED)
  162257. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  162258. png_infop info_ptr, png_uint_32 length));
  162259. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  162260. png_infop info_ptr));
  162261. #endif
  162262. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  162263. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162264. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  162265. png_bytep row));
  162266. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  162267. png_bytep row));
  162268. #endif
  162269. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162270. #if defined(PNG_MMX_CODE_SUPPORTED)
  162271. /* PRIVATE */
  162272. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162273. #endif
  162274. #endif
  162275. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162276. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162277. png_infop info_ptr));
  162278. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162279. png_infop info_ptr));
  162280. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162281. png_infop info_ptr));
  162282. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162283. png_infop info_ptr));
  162284. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162285. png_infop info_ptr));
  162286. #if defined(PNG_pHYs_SUPPORTED)
  162287. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162288. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162289. #endif /* PNG_pHYs_SUPPORTED */
  162290. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162291. #endif /* PNG_INTERNAL */
  162292. #ifdef __cplusplus
  162293. }
  162294. #endif
  162295. #endif /* PNG_VERSION_INFO_ONLY */
  162296. #endif /* PNG_H */
  162297. /*** End of inlined file: png.h ***/
  162298. #define PNG_NO_EXTERN
  162299. /*** Start of inlined file: png.c ***/
  162300. #define PNG_INTERNAL
  162301. #define PNG_NO_EXTERN
  162302. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162303. #ifdef PNG_USE_GLOBAL_ARRAYS
  162304. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162305. #ifdef PNG_READ_SUPPORTED
  162306. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162307. #endif /* PNG_READ_SUPPORTED */
  162308. PNG_IHDR;
  162309. PNG_IDAT;
  162310. PNG_IEND;
  162311. PNG_PLTE;
  162312. PNG_bKGD;
  162313. PNG_cHRM;
  162314. PNG_gAMA;
  162315. PNG_hIST;
  162316. PNG_iCCP;
  162317. PNG_iTXt;
  162318. PNG_oFFs;
  162319. PNG_pCAL;
  162320. PNG_sCAL;
  162321. PNG_pHYs;
  162322. PNG_sBIT;
  162323. PNG_sPLT;
  162324. PNG_sRGB;
  162325. PNG_tEXt;
  162326. PNG_tIME;
  162327. PNG_tRNS;
  162328. PNG_zTXt;
  162329. #ifdef PNG_READ_SUPPORTED
  162330. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162331. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162332. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162333. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162334. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162335. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162336. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162337. #endif /* PNG_READ_SUPPORTED */
  162338. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162339. #ifdef PNG_READ_SUPPORTED
  162340. void PNGAPI
  162341. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162342. {
  162343. if(png_ptr == NULL) return;
  162344. png_debug(1, "in png_set_sig_bytes\n");
  162345. if (num_bytes > 8)
  162346. png_error(png_ptr, "Too many bytes for PNG signature.");
  162347. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162348. }
  162349. int PNGAPI
  162350. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162351. {
  162352. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162353. if (num_to_check > 8)
  162354. num_to_check = 8;
  162355. else if (num_to_check < 1)
  162356. return (-1);
  162357. if (start > 7)
  162358. return (-1);
  162359. if (start + num_to_check > 8)
  162360. num_to_check = 8 - start;
  162361. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162362. }
  162363. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162364. int PNGAPI
  162365. png_check_sig(png_bytep sig, int num)
  162366. {
  162367. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162368. }
  162369. #endif
  162370. #endif /* PNG_READ_SUPPORTED */
  162371. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162372. #ifdef PNG_1_0_X
  162373. voidpf PNGAPI
  162374. #else
  162375. voidpf /* private */
  162376. #endif
  162377. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162378. {
  162379. png_voidp ptr;
  162380. png_structp p=(png_structp)png_ptr;
  162381. png_uint_32 save_flags=p->flags;
  162382. png_uint_32 num_bytes;
  162383. if(png_ptr == NULL) return (NULL);
  162384. if (items > PNG_UINT_32_MAX/size)
  162385. {
  162386. png_warning (p, "Potential overflow in png_zalloc()");
  162387. return (NULL);
  162388. }
  162389. num_bytes = (png_uint_32)items * size;
  162390. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162391. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162392. p->flags=save_flags;
  162393. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162394. if (ptr == NULL)
  162395. return ((voidpf)ptr);
  162396. if (num_bytes > (png_uint_32)0x8000L)
  162397. {
  162398. png_memset(ptr, 0, (png_size_t)0x8000L);
  162399. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162400. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162401. }
  162402. else
  162403. {
  162404. png_memset(ptr, 0, (png_size_t)num_bytes);
  162405. }
  162406. #endif
  162407. return ((voidpf)ptr);
  162408. }
  162409. #ifdef PNG_1_0_X
  162410. void PNGAPI
  162411. #else
  162412. void /* private */
  162413. #endif
  162414. png_zfree(voidpf png_ptr, voidpf ptr)
  162415. {
  162416. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162417. }
  162418. void /* PRIVATE */
  162419. png_reset_crc(png_structp png_ptr)
  162420. {
  162421. png_ptr->crc = crc32(0, Z_NULL, 0);
  162422. }
  162423. void /* PRIVATE */
  162424. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162425. {
  162426. int need_crc = 1;
  162427. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162428. {
  162429. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162430. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162431. need_crc = 0;
  162432. }
  162433. else /* critical */
  162434. {
  162435. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162436. need_crc = 0;
  162437. }
  162438. if (need_crc)
  162439. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162440. }
  162441. png_infop PNGAPI
  162442. png_create_info_struct(png_structp png_ptr)
  162443. {
  162444. png_infop info_ptr;
  162445. png_debug(1, "in png_create_info_struct\n");
  162446. if(png_ptr == NULL) return (NULL);
  162447. #ifdef PNG_USER_MEM_SUPPORTED
  162448. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162449. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162450. #else
  162451. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162452. #endif
  162453. if (info_ptr != NULL)
  162454. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162455. return (info_ptr);
  162456. }
  162457. void PNGAPI
  162458. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162459. {
  162460. png_infop info_ptr = NULL;
  162461. if(png_ptr == NULL) return;
  162462. png_debug(1, "in png_destroy_info_struct\n");
  162463. if (info_ptr_ptr != NULL)
  162464. info_ptr = *info_ptr_ptr;
  162465. if (info_ptr != NULL)
  162466. {
  162467. png_info_destroy(png_ptr, info_ptr);
  162468. #ifdef PNG_USER_MEM_SUPPORTED
  162469. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162470. png_ptr->mem_ptr);
  162471. #else
  162472. png_destroy_struct((png_voidp)info_ptr);
  162473. #endif
  162474. *info_ptr_ptr = NULL;
  162475. }
  162476. }
  162477. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162478. #undef png_info_init
  162479. void PNGAPI
  162480. png_info_init(png_infop info_ptr)
  162481. {
  162482. png_info_init_3(&info_ptr, 0);
  162483. }
  162484. #endif
  162485. void PNGAPI
  162486. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162487. {
  162488. png_infop info_ptr = *ptr_ptr;
  162489. if(info_ptr == NULL) return;
  162490. png_debug(1, "in png_info_init_3\n");
  162491. if(png_sizeof(png_info) > png_info_struct_size)
  162492. {
  162493. png_destroy_struct(info_ptr);
  162494. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162495. *ptr_ptr = info_ptr;
  162496. }
  162497. png_memset(info_ptr, 0, png_sizeof (png_info));
  162498. }
  162499. #ifdef PNG_FREE_ME_SUPPORTED
  162500. void PNGAPI
  162501. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162502. int freer, png_uint_32 mask)
  162503. {
  162504. png_debug(1, "in png_data_freer\n");
  162505. if (png_ptr == NULL || info_ptr == NULL)
  162506. return;
  162507. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162508. info_ptr->free_me |= mask;
  162509. else if(freer == PNG_USER_WILL_FREE_DATA)
  162510. info_ptr->free_me &= ~mask;
  162511. else
  162512. png_warning(png_ptr,
  162513. "Unknown freer parameter in png_data_freer.");
  162514. }
  162515. #endif
  162516. void PNGAPI
  162517. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162518. int num)
  162519. {
  162520. png_debug(1, "in png_free_data\n");
  162521. if (png_ptr == NULL || info_ptr == NULL)
  162522. return;
  162523. #if defined(PNG_TEXT_SUPPORTED)
  162524. #ifdef PNG_FREE_ME_SUPPORTED
  162525. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162526. #else
  162527. if (mask & PNG_FREE_TEXT)
  162528. #endif
  162529. {
  162530. if (num != -1)
  162531. {
  162532. if (info_ptr->text && info_ptr->text[num].key)
  162533. {
  162534. png_free(png_ptr, info_ptr->text[num].key);
  162535. info_ptr->text[num].key = NULL;
  162536. }
  162537. }
  162538. else
  162539. {
  162540. int i;
  162541. for (i = 0; i < info_ptr->num_text; i++)
  162542. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162543. png_free(png_ptr, info_ptr->text);
  162544. info_ptr->text = NULL;
  162545. info_ptr->num_text=0;
  162546. }
  162547. }
  162548. #endif
  162549. #if defined(PNG_tRNS_SUPPORTED)
  162550. #ifdef PNG_FREE_ME_SUPPORTED
  162551. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162552. #else
  162553. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162554. #endif
  162555. {
  162556. png_free(png_ptr, info_ptr->trans);
  162557. info_ptr->valid &= ~PNG_INFO_tRNS;
  162558. #ifndef PNG_FREE_ME_SUPPORTED
  162559. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162560. #endif
  162561. info_ptr->trans = NULL;
  162562. }
  162563. #endif
  162564. #if defined(PNG_sCAL_SUPPORTED)
  162565. #ifdef PNG_FREE_ME_SUPPORTED
  162566. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162567. #else
  162568. if (mask & PNG_FREE_SCAL)
  162569. #endif
  162570. {
  162571. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162572. png_free(png_ptr, info_ptr->scal_s_width);
  162573. png_free(png_ptr, info_ptr->scal_s_height);
  162574. info_ptr->scal_s_width = NULL;
  162575. info_ptr->scal_s_height = NULL;
  162576. #endif
  162577. info_ptr->valid &= ~PNG_INFO_sCAL;
  162578. }
  162579. #endif
  162580. #if defined(PNG_pCAL_SUPPORTED)
  162581. #ifdef PNG_FREE_ME_SUPPORTED
  162582. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162583. #else
  162584. if (mask & PNG_FREE_PCAL)
  162585. #endif
  162586. {
  162587. png_free(png_ptr, info_ptr->pcal_purpose);
  162588. png_free(png_ptr, info_ptr->pcal_units);
  162589. info_ptr->pcal_purpose = NULL;
  162590. info_ptr->pcal_units = NULL;
  162591. if (info_ptr->pcal_params != NULL)
  162592. {
  162593. int i;
  162594. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162595. {
  162596. png_free(png_ptr, info_ptr->pcal_params[i]);
  162597. info_ptr->pcal_params[i]=NULL;
  162598. }
  162599. png_free(png_ptr, info_ptr->pcal_params);
  162600. info_ptr->pcal_params = NULL;
  162601. }
  162602. info_ptr->valid &= ~PNG_INFO_pCAL;
  162603. }
  162604. #endif
  162605. #if defined(PNG_iCCP_SUPPORTED)
  162606. #ifdef PNG_FREE_ME_SUPPORTED
  162607. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162608. #else
  162609. if (mask & PNG_FREE_ICCP)
  162610. #endif
  162611. {
  162612. png_free(png_ptr, info_ptr->iccp_name);
  162613. png_free(png_ptr, info_ptr->iccp_profile);
  162614. info_ptr->iccp_name = NULL;
  162615. info_ptr->iccp_profile = NULL;
  162616. info_ptr->valid &= ~PNG_INFO_iCCP;
  162617. }
  162618. #endif
  162619. #if defined(PNG_sPLT_SUPPORTED)
  162620. #ifdef PNG_FREE_ME_SUPPORTED
  162621. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162622. #else
  162623. if (mask & PNG_FREE_SPLT)
  162624. #endif
  162625. {
  162626. if (num != -1)
  162627. {
  162628. if(info_ptr->splt_palettes)
  162629. {
  162630. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162631. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162632. info_ptr->splt_palettes[num].name = NULL;
  162633. info_ptr->splt_palettes[num].entries = NULL;
  162634. }
  162635. }
  162636. else
  162637. {
  162638. if(info_ptr->splt_palettes_num)
  162639. {
  162640. int i;
  162641. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162642. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162643. png_free(png_ptr, info_ptr->splt_palettes);
  162644. info_ptr->splt_palettes = NULL;
  162645. info_ptr->splt_palettes_num = 0;
  162646. }
  162647. info_ptr->valid &= ~PNG_INFO_sPLT;
  162648. }
  162649. }
  162650. #endif
  162651. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162652. if(png_ptr->unknown_chunk.data)
  162653. {
  162654. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162655. png_ptr->unknown_chunk.data = NULL;
  162656. }
  162657. #ifdef PNG_FREE_ME_SUPPORTED
  162658. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162659. #else
  162660. if (mask & PNG_FREE_UNKN)
  162661. #endif
  162662. {
  162663. if (num != -1)
  162664. {
  162665. if(info_ptr->unknown_chunks)
  162666. {
  162667. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162668. info_ptr->unknown_chunks[num].data = NULL;
  162669. }
  162670. }
  162671. else
  162672. {
  162673. int i;
  162674. if(info_ptr->unknown_chunks_num)
  162675. {
  162676. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  162677. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  162678. png_free(png_ptr, info_ptr->unknown_chunks);
  162679. info_ptr->unknown_chunks = NULL;
  162680. info_ptr->unknown_chunks_num = 0;
  162681. }
  162682. }
  162683. }
  162684. #endif
  162685. #if defined(PNG_hIST_SUPPORTED)
  162686. #ifdef PNG_FREE_ME_SUPPORTED
  162687. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  162688. #else
  162689. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  162690. #endif
  162691. {
  162692. png_free(png_ptr, info_ptr->hist);
  162693. info_ptr->hist = NULL;
  162694. info_ptr->valid &= ~PNG_INFO_hIST;
  162695. #ifndef PNG_FREE_ME_SUPPORTED
  162696. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  162697. #endif
  162698. }
  162699. #endif
  162700. #ifdef PNG_FREE_ME_SUPPORTED
  162701. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  162702. #else
  162703. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  162704. #endif
  162705. {
  162706. png_zfree(png_ptr, info_ptr->palette);
  162707. info_ptr->palette = NULL;
  162708. info_ptr->valid &= ~PNG_INFO_PLTE;
  162709. #ifndef PNG_FREE_ME_SUPPORTED
  162710. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  162711. #endif
  162712. info_ptr->num_palette = 0;
  162713. }
  162714. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162715. #ifdef PNG_FREE_ME_SUPPORTED
  162716. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  162717. #else
  162718. if (mask & PNG_FREE_ROWS)
  162719. #endif
  162720. {
  162721. if(info_ptr->row_pointers)
  162722. {
  162723. int row;
  162724. for (row = 0; row < (int)info_ptr->height; row++)
  162725. {
  162726. png_free(png_ptr, info_ptr->row_pointers[row]);
  162727. info_ptr->row_pointers[row]=NULL;
  162728. }
  162729. png_free(png_ptr, info_ptr->row_pointers);
  162730. info_ptr->row_pointers=NULL;
  162731. }
  162732. info_ptr->valid &= ~PNG_INFO_IDAT;
  162733. }
  162734. #endif
  162735. #ifdef PNG_FREE_ME_SUPPORTED
  162736. if(num == -1)
  162737. info_ptr->free_me &= ~mask;
  162738. else
  162739. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  162740. #endif
  162741. }
  162742. void /* PRIVATE */
  162743. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  162744. {
  162745. png_debug(1, "in png_info_destroy\n");
  162746. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  162747. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162748. if (png_ptr->num_chunk_list)
  162749. {
  162750. png_free(png_ptr, png_ptr->chunk_list);
  162751. png_ptr->chunk_list=NULL;
  162752. png_ptr->num_chunk_list=0;
  162753. }
  162754. #endif
  162755. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162756. }
  162757. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162758. png_voidp PNGAPI
  162759. png_get_io_ptr(png_structp png_ptr)
  162760. {
  162761. if(png_ptr == NULL) return (NULL);
  162762. return (png_ptr->io_ptr);
  162763. }
  162764. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162765. #if !defined(PNG_NO_STDIO)
  162766. void PNGAPI
  162767. png_init_io(png_structp png_ptr, png_FILE_p fp)
  162768. {
  162769. png_debug(1, "in png_init_io\n");
  162770. if(png_ptr == NULL) return;
  162771. png_ptr->io_ptr = (png_voidp)fp;
  162772. }
  162773. #endif
  162774. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  162775. png_charp PNGAPI
  162776. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  162777. {
  162778. static PNG_CONST char short_months[12][4] =
  162779. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  162780. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  162781. if(png_ptr == NULL) return (NULL);
  162782. if (png_ptr->time_buffer == NULL)
  162783. {
  162784. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  162785. png_sizeof(char)));
  162786. }
  162787. #if defined(_WIN32_WCE)
  162788. {
  162789. wchar_t time_buf[29];
  162790. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  162791. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162792. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162793. ptime->second % 61);
  162794. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  162795. NULL, NULL);
  162796. }
  162797. #else
  162798. #ifdef USE_FAR_KEYWORD
  162799. {
  162800. char near_time_buf[29];
  162801. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  162802. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162803. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162804. ptime->second % 61);
  162805. png_memcpy(png_ptr->time_buffer, near_time_buf,
  162806. 29*png_sizeof(char));
  162807. }
  162808. #else
  162809. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  162810. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162811. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162812. ptime->second % 61);
  162813. #endif
  162814. #endif /* _WIN32_WCE */
  162815. return ((png_charp)png_ptr->time_buffer);
  162816. }
  162817. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  162818. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162819. png_charp PNGAPI
  162820. png_get_copyright(png_structp png_ptr)
  162821. {
  162822. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162823. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  162824. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  162825. Copyright (c) 1996-1997 Andreas Dilger\n\
  162826. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  162827. }
  162828. png_charp PNGAPI
  162829. png_get_libpng_ver(png_structp png_ptr)
  162830. {
  162831. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162832. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162833. }
  162834. png_charp PNGAPI
  162835. png_get_header_ver(png_structp png_ptr)
  162836. {
  162837. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162838. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162839. }
  162840. png_charp PNGAPI
  162841. png_get_header_version(png_structp png_ptr)
  162842. {
  162843. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162844. return ((png_charp) PNG_HEADER_VERSION_STRING
  162845. #ifndef PNG_READ_SUPPORTED
  162846. " (NO READ SUPPORT)"
  162847. #endif
  162848. "\n");
  162849. }
  162850. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162851. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  162852. int PNGAPI
  162853. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  162854. {
  162855. int i;
  162856. png_bytep p;
  162857. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  162858. return 0;
  162859. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  162860. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  162861. if (!png_memcmp(chunk_name, p, 4))
  162862. return ((int)*(p+4));
  162863. return 0;
  162864. }
  162865. #endif
  162866. int PNGAPI
  162867. png_reset_zstream(png_structp png_ptr)
  162868. {
  162869. if (png_ptr == NULL) return Z_STREAM_ERROR;
  162870. return (inflateReset(&png_ptr->zstream));
  162871. }
  162872. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162873. png_uint_32 PNGAPI
  162874. png_access_version_number(void)
  162875. {
  162876. return((png_uint_32) PNG_LIBPNG_VER);
  162877. }
  162878. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162879. #if !defined(PNG_1_0_X)
  162880. int PNGAPI
  162881. png_mmx_support(void)
  162882. {
  162883. return -1;
  162884. }
  162885. #endif /* PNG_1_0_X */
  162886. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  162887. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162888. #ifdef PNG_SIZE_T
  162889. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162890. png_size_t PNGAPI
  162891. png_convert_size(size_t size)
  162892. {
  162893. if (size > (png_size_t)-1)
  162894. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  162895. return ((png_size_t)size);
  162896. }
  162897. #endif /* PNG_SIZE_T */
  162898. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162899. /*** End of inlined file: png.c ***/
  162900. /*** Start of inlined file: pngerror.c ***/
  162901. #define PNG_INTERNAL
  162902. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162903. static void /* PRIVATE */
  162904. png_default_error PNGARG((png_structp png_ptr,
  162905. png_const_charp error_message));
  162906. #ifndef PNG_NO_WARNINGS
  162907. static void /* PRIVATE */
  162908. png_default_warning PNGARG((png_structp png_ptr,
  162909. png_const_charp warning_message));
  162910. #endif /* PNG_NO_WARNINGS */
  162911. #ifndef PNG_NO_ERROR_TEXT
  162912. void PNGAPI
  162913. png_error(png_structp png_ptr, png_const_charp error_message)
  162914. {
  162915. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162916. char msg[16];
  162917. if (png_ptr != NULL)
  162918. {
  162919. if (png_ptr->flags&
  162920. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162921. {
  162922. if (*error_message == '#')
  162923. {
  162924. int offset;
  162925. for (offset=1; offset<15; offset++)
  162926. if (*(error_message+offset) == ' ')
  162927. break;
  162928. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162929. {
  162930. int i;
  162931. for (i=0; i<offset-1; i++)
  162932. msg[i]=error_message[i+1];
  162933. msg[i]='\0';
  162934. error_message=msg;
  162935. }
  162936. else
  162937. error_message+=offset;
  162938. }
  162939. else
  162940. {
  162941. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162942. {
  162943. msg[0]='0';
  162944. msg[1]='\0';
  162945. error_message=msg;
  162946. }
  162947. }
  162948. }
  162949. }
  162950. #endif
  162951. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162952. (*(png_ptr->error_fn))(png_ptr, error_message);
  162953. png_default_error(png_ptr, error_message);
  162954. }
  162955. #else
  162956. void PNGAPI
  162957. png_err(png_structp png_ptr)
  162958. {
  162959. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162960. (*(png_ptr->error_fn))(png_ptr, '\0');
  162961. png_default_error(png_ptr, '\0');
  162962. }
  162963. #endif /* PNG_NO_ERROR_TEXT */
  162964. #ifndef PNG_NO_WARNINGS
  162965. void PNGAPI
  162966. png_warning(png_structp png_ptr, png_const_charp warning_message)
  162967. {
  162968. int offset = 0;
  162969. if (png_ptr != NULL)
  162970. {
  162971. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162972. if (png_ptr->flags&
  162973. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162974. #endif
  162975. {
  162976. if (*warning_message == '#')
  162977. {
  162978. for (offset=1; offset<15; offset++)
  162979. if (*(warning_message+offset) == ' ')
  162980. break;
  162981. }
  162982. }
  162983. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  162984. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  162985. }
  162986. else
  162987. png_default_warning(png_ptr, warning_message+offset);
  162988. }
  162989. #endif /* PNG_NO_WARNINGS */
  162990. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  162991. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  162992. static void /* PRIVATE */
  162993. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  162994. error_message)
  162995. {
  162996. int iout = 0, iin = 0;
  162997. while (iin < 4)
  162998. {
  162999. int c = png_ptr->chunk_name[iin++];
  163000. if (isnonalpha(c))
  163001. {
  163002. buffer[iout++] = '[';
  163003. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  163004. buffer[iout++] = png_digit[c & 0x0f];
  163005. buffer[iout++] = ']';
  163006. }
  163007. else
  163008. {
  163009. buffer[iout++] = (png_byte)c;
  163010. }
  163011. }
  163012. if (error_message == NULL)
  163013. buffer[iout] = 0;
  163014. else
  163015. {
  163016. buffer[iout++] = ':';
  163017. buffer[iout++] = ' ';
  163018. png_strncpy(buffer+iout, error_message, 63);
  163019. buffer[iout+63] = 0;
  163020. }
  163021. }
  163022. #ifdef PNG_READ_SUPPORTED
  163023. void PNGAPI
  163024. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  163025. {
  163026. char msg[18+64];
  163027. if (png_ptr == NULL)
  163028. png_error(png_ptr, error_message);
  163029. else
  163030. {
  163031. png_format_buffer(png_ptr, msg, error_message);
  163032. png_error(png_ptr, msg);
  163033. }
  163034. }
  163035. #endif /* PNG_READ_SUPPORTED */
  163036. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  163037. #ifndef PNG_NO_WARNINGS
  163038. void PNGAPI
  163039. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  163040. {
  163041. char msg[18+64];
  163042. if (png_ptr == NULL)
  163043. png_warning(png_ptr, warning_message);
  163044. else
  163045. {
  163046. png_format_buffer(png_ptr, msg, warning_message);
  163047. png_warning(png_ptr, msg);
  163048. }
  163049. }
  163050. #endif /* PNG_NO_WARNINGS */
  163051. static void /* PRIVATE */
  163052. png_default_error(png_structp png_ptr, png_const_charp error_message)
  163053. {
  163054. #ifndef PNG_NO_CONSOLE_IO
  163055. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163056. if (*error_message == '#')
  163057. {
  163058. int offset;
  163059. char error_number[16];
  163060. for (offset=0; offset<15; offset++)
  163061. {
  163062. error_number[offset] = *(error_message+offset+1);
  163063. if (*(error_message+offset) == ' ')
  163064. break;
  163065. }
  163066. if((offset > 1) && (offset < 15))
  163067. {
  163068. error_number[offset-1]='\0';
  163069. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  163070. error_message+offset);
  163071. }
  163072. else
  163073. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  163074. }
  163075. else
  163076. #endif
  163077. fprintf(stderr, "libpng error: %s\n", error_message);
  163078. #endif
  163079. #ifdef PNG_SETJMP_SUPPORTED
  163080. if (png_ptr)
  163081. {
  163082. # ifdef USE_FAR_KEYWORD
  163083. {
  163084. jmp_buf jmpbuf;
  163085. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  163086. longjmp(jmpbuf, 1);
  163087. }
  163088. # else
  163089. longjmp(png_ptr->jmpbuf, 1);
  163090. # endif
  163091. }
  163092. #else
  163093. PNG_ABORT();
  163094. #endif
  163095. #ifdef PNG_NO_CONSOLE_IO
  163096. error_message = error_message; /* make compiler happy */
  163097. #endif
  163098. }
  163099. #ifndef PNG_NO_WARNINGS
  163100. static void /* PRIVATE */
  163101. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  163102. {
  163103. #ifndef PNG_NO_CONSOLE_IO
  163104. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163105. if (*warning_message == '#')
  163106. {
  163107. int offset;
  163108. char warning_number[16];
  163109. for (offset=0; offset<15; offset++)
  163110. {
  163111. warning_number[offset]=*(warning_message+offset+1);
  163112. if (*(warning_message+offset) == ' ')
  163113. break;
  163114. }
  163115. if((offset > 1) && (offset < 15))
  163116. {
  163117. warning_number[offset-1]='\0';
  163118. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  163119. warning_message+offset);
  163120. }
  163121. else
  163122. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163123. }
  163124. else
  163125. # endif
  163126. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163127. #else
  163128. warning_message = warning_message; /* make compiler happy */
  163129. #endif
  163130. png_ptr = png_ptr; /* make compiler happy */
  163131. }
  163132. #endif /* PNG_NO_WARNINGS */
  163133. void PNGAPI
  163134. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  163135. png_error_ptr error_fn, png_error_ptr warning_fn)
  163136. {
  163137. if (png_ptr == NULL)
  163138. return;
  163139. png_ptr->error_ptr = error_ptr;
  163140. png_ptr->error_fn = error_fn;
  163141. png_ptr->warning_fn = warning_fn;
  163142. }
  163143. png_voidp PNGAPI
  163144. png_get_error_ptr(png_structp png_ptr)
  163145. {
  163146. if (png_ptr == NULL)
  163147. return NULL;
  163148. return ((png_voidp)png_ptr->error_ptr);
  163149. }
  163150. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163151. void PNGAPI
  163152. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  163153. {
  163154. if(png_ptr != NULL)
  163155. {
  163156. png_ptr->flags &=
  163157. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  163158. }
  163159. }
  163160. #endif
  163161. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163162. /*** End of inlined file: pngerror.c ***/
  163163. /*** Start of inlined file: pngget.c ***/
  163164. #define PNG_INTERNAL
  163165. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163166. png_uint_32 PNGAPI
  163167. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  163168. {
  163169. if (png_ptr != NULL && info_ptr != NULL)
  163170. return(info_ptr->valid & flag);
  163171. else
  163172. return(0);
  163173. }
  163174. png_uint_32 PNGAPI
  163175. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  163176. {
  163177. if (png_ptr != NULL && info_ptr != NULL)
  163178. return(info_ptr->rowbytes);
  163179. else
  163180. return(0);
  163181. }
  163182. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163183. png_bytepp PNGAPI
  163184. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  163185. {
  163186. if (png_ptr != NULL && info_ptr != NULL)
  163187. return(info_ptr->row_pointers);
  163188. else
  163189. return(0);
  163190. }
  163191. #endif
  163192. #ifdef PNG_EASY_ACCESS_SUPPORTED
  163193. png_uint_32 PNGAPI
  163194. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  163195. {
  163196. if (png_ptr != NULL && info_ptr != NULL)
  163197. {
  163198. return info_ptr->width;
  163199. }
  163200. return (0);
  163201. }
  163202. png_uint_32 PNGAPI
  163203. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  163204. {
  163205. if (png_ptr != NULL && info_ptr != NULL)
  163206. {
  163207. return info_ptr->height;
  163208. }
  163209. return (0);
  163210. }
  163211. png_byte PNGAPI
  163212. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  163213. {
  163214. if (png_ptr != NULL && info_ptr != NULL)
  163215. {
  163216. return info_ptr->bit_depth;
  163217. }
  163218. return (0);
  163219. }
  163220. png_byte PNGAPI
  163221. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  163222. {
  163223. if (png_ptr != NULL && info_ptr != NULL)
  163224. {
  163225. return info_ptr->color_type;
  163226. }
  163227. return (0);
  163228. }
  163229. png_byte PNGAPI
  163230. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  163231. {
  163232. if (png_ptr != NULL && info_ptr != NULL)
  163233. {
  163234. return info_ptr->filter_type;
  163235. }
  163236. return (0);
  163237. }
  163238. png_byte PNGAPI
  163239. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  163240. {
  163241. if (png_ptr != NULL && info_ptr != NULL)
  163242. {
  163243. return info_ptr->interlace_type;
  163244. }
  163245. return (0);
  163246. }
  163247. png_byte PNGAPI
  163248. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  163249. {
  163250. if (png_ptr != NULL && info_ptr != NULL)
  163251. {
  163252. return info_ptr->compression_type;
  163253. }
  163254. return (0);
  163255. }
  163256. png_uint_32 PNGAPI
  163257. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163258. {
  163259. if (png_ptr != NULL && info_ptr != NULL)
  163260. #if defined(PNG_pHYs_SUPPORTED)
  163261. if (info_ptr->valid & PNG_INFO_pHYs)
  163262. {
  163263. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  163264. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163265. return (0);
  163266. else return (info_ptr->x_pixels_per_unit);
  163267. }
  163268. #else
  163269. return (0);
  163270. #endif
  163271. return (0);
  163272. }
  163273. png_uint_32 PNGAPI
  163274. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163275. {
  163276. if (png_ptr != NULL && info_ptr != NULL)
  163277. #if defined(PNG_pHYs_SUPPORTED)
  163278. if (info_ptr->valid & PNG_INFO_pHYs)
  163279. {
  163280. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163281. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163282. return (0);
  163283. else return (info_ptr->y_pixels_per_unit);
  163284. }
  163285. #else
  163286. return (0);
  163287. #endif
  163288. return (0);
  163289. }
  163290. png_uint_32 PNGAPI
  163291. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163292. {
  163293. if (png_ptr != NULL && info_ptr != NULL)
  163294. #if defined(PNG_pHYs_SUPPORTED)
  163295. if (info_ptr->valid & PNG_INFO_pHYs)
  163296. {
  163297. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163298. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163299. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163300. return (0);
  163301. else return (info_ptr->x_pixels_per_unit);
  163302. }
  163303. #else
  163304. return (0);
  163305. #endif
  163306. return (0);
  163307. }
  163308. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163309. float PNGAPI
  163310. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163311. {
  163312. if (png_ptr != NULL && info_ptr != NULL)
  163313. #if defined(PNG_pHYs_SUPPORTED)
  163314. if (info_ptr->valid & PNG_INFO_pHYs)
  163315. {
  163316. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163317. if (info_ptr->x_pixels_per_unit == 0)
  163318. return ((float)0.0);
  163319. else
  163320. return ((float)((float)info_ptr->y_pixels_per_unit
  163321. /(float)info_ptr->x_pixels_per_unit));
  163322. }
  163323. #else
  163324. return (0.0);
  163325. #endif
  163326. return ((float)0.0);
  163327. }
  163328. #endif
  163329. png_int_32 PNGAPI
  163330. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163331. {
  163332. if (png_ptr != NULL && info_ptr != NULL)
  163333. #if defined(PNG_oFFs_SUPPORTED)
  163334. if (info_ptr->valid & PNG_INFO_oFFs)
  163335. {
  163336. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163337. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163338. return (0);
  163339. else return (info_ptr->x_offset);
  163340. }
  163341. #else
  163342. return (0);
  163343. #endif
  163344. return (0);
  163345. }
  163346. png_int_32 PNGAPI
  163347. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163348. {
  163349. if (png_ptr != NULL && info_ptr != NULL)
  163350. #if defined(PNG_oFFs_SUPPORTED)
  163351. if (info_ptr->valid & PNG_INFO_oFFs)
  163352. {
  163353. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163354. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163355. return (0);
  163356. else return (info_ptr->y_offset);
  163357. }
  163358. #else
  163359. return (0);
  163360. #endif
  163361. return (0);
  163362. }
  163363. png_int_32 PNGAPI
  163364. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163365. {
  163366. if (png_ptr != NULL && info_ptr != NULL)
  163367. #if defined(PNG_oFFs_SUPPORTED)
  163368. if (info_ptr->valid & PNG_INFO_oFFs)
  163369. {
  163370. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163371. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163372. return (0);
  163373. else return (info_ptr->x_offset);
  163374. }
  163375. #else
  163376. return (0);
  163377. #endif
  163378. return (0);
  163379. }
  163380. png_int_32 PNGAPI
  163381. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163382. {
  163383. if (png_ptr != NULL && info_ptr != NULL)
  163384. #if defined(PNG_oFFs_SUPPORTED)
  163385. if (info_ptr->valid & PNG_INFO_oFFs)
  163386. {
  163387. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163388. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163389. return (0);
  163390. else return (info_ptr->y_offset);
  163391. }
  163392. #else
  163393. return (0);
  163394. #endif
  163395. return (0);
  163396. }
  163397. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163398. png_uint_32 PNGAPI
  163399. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163400. {
  163401. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163402. *.0254 +.5));
  163403. }
  163404. png_uint_32 PNGAPI
  163405. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163406. {
  163407. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163408. *.0254 +.5));
  163409. }
  163410. png_uint_32 PNGAPI
  163411. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163412. {
  163413. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163414. *.0254 +.5));
  163415. }
  163416. float PNGAPI
  163417. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163418. {
  163419. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163420. *.00003937);
  163421. }
  163422. float PNGAPI
  163423. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163424. {
  163425. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163426. *.00003937);
  163427. }
  163428. #if defined(PNG_pHYs_SUPPORTED)
  163429. png_uint_32 PNGAPI
  163430. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163431. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163432. {
  163433. png_uint_32 retval = 0;
  163434. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163435. {
  163436. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163437. if (res_x != NULL)
  163438. {
  163439. *res_x = info_ptr->x_pixels_per_unit;
  163440. retval |= PNG_INFO_pHYs;
  163441. }
  163442. if (res_y != NULL)
  163443. {
  163444. *res_y = info_ptr->y_pixels_per_unit;
  163445. retval |= PNG_INFO_pHYs;
  163446. }
  163447. if (unit_type != NULL)
  163448. {
  163449. *unit_type = (int)info_ptr->phys_unit_type;
  163450. retval |= PNG_INFO_pHYs;
  163451. if(*unit_type == 1)
  163452. {
  163453. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163454. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163455. }
  163456. }
  163457. }
  163458. return (retval);
  163459. }
  163460. #endif /* PNG_pHYs_SUPPORTED */
  163461. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163462. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163463. png_byte PNGAPI
  163464. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163465. {
  163466. if (png_ptr != NULL && info_ptr != NULL)
  163467. return(info_ptr->channels);
  163468. else
  163469. return (0);
  163470. }
  163471. png_bytep PNGAPI
  163472. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163473. {
  163474. if (png_ptr != NULL && info_ptr != NULL)
  163475. return(info_ptr->signature);
  163476. else
  163477. return (NULL);
  163478. }
  163479. #if defined(PNG_bKGD_SUPPORTED)
  163480. png_uint_32 PNGAPI
  163481. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163482. png_color_16p *background)
  163483. {
  163484. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163485. && background != NULL)
  163486. {
  163487. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163488. *background = &(info_ptr->background);
  163489. return (PNG_INFO_bKGD);
  163490. }
  163491. return (0);
  163492. }
  163493. #endif
  163494. #if defined(PNG_cHRM_SUPPORTED)
  163495. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163496. png_uint_32 PNGAPI
  163497. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163498. double *white_x, double *white_y, double *red_x, double *red_y,
  163499. double *green_x, double *green_y, double *blue_x, double *blue_y)
  163500. {
  163501. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163502. {
  163503. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163504. if (white_x != NULL)
  163505. *white_x = (double)info_ptr->x_white;
  163506. if (white_y != NULL)
  163507. *white_y = (double)info_ptr->y_white;
  163508. if (red_x != NULL)
  163509. *red_x = (double)info_ptr->x_red;
  163510. if (red_y != NULL)
  163511. *red_y = (double)info_ptr->y_red;
  163512. if (green_x != NULL)
  163513. *green_x = (double)info_ptr->x_green;
  163514. if (green_y != NULL)
  163515. *green_y = (double)info_ptr->y_green;
  163516. if (blue_x != NULL)
  163517. *blue_x = (double)info_ptr->x_blue;
  163518. if (blue_y != NULL)
  163519. *blue_y = (double)info_ptr->y_blue;
  163520. return (PNG_INFO_cHRM);
  163521. }
  163522. return (0);
  163523. }
  163524. #endif
  163525. #ifdef PNG_FIXED_POINT_SUPPORTED
  163526. png_uint_32 PNGAPI
  163527. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163528. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163529. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163530. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163531. {
  163532. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163533. {
  163534. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163535. if (white_x != NULL)
  163536. *white_x = info_ptr->int_x_white;
  163537. if (white_y != NULL)
  163538. *white_y = info_ptr->int_y_white;
  163539. if (red_x != NULL)
  163540. *red_x = info_ptr->int_x_red;
  163541. if (red_y != NULL)
  163542. *red_y = info_ptr->int_y_red;
  163543. if (green_x != NULL)
  163544. *green_x = info_ptr->int_x_green;
  163545. if (green_y != NULL)
  163546. *green_y = info_ptr->int_y_green;
  163547. if (blue_x != NULL)
  163548. *blue_x = info_ptr->int_x_blue;
  163549. if (blue_y != NULL)
  163550. *blue_y = info_ptr->int_y_blue;
  163551. return (PNG_INFO_cHRM);
  163552. }
  163553. return (0);
  163554. }
  163555. #endif
  163556. #endif
  163557. #if defined(PNG_gAMA_SUPPORTED)
  163558. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163559. png_uint_32 PNGAPI
  163560. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163561. {
  163562. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163563. && file_gamma != NULL)
  163564. {
  163565. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163566. *file_gamma = (double)info_ptr->gamma;
  163567. return (PNG_INFO_gAMA);
  163568. }
  163569. return (0);
  163570. }
  163571. #endif
  163572. #ifdef PNG_FIXED_POINT_SUPPORTED
  163573. png_uint_32 PNGAPI
  163574. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163575. png_fixed_point *int_file_gamma)
  163576. {
  163577. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163578. && int_file_gamma != NULL)
  163579. {
  163580. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163581. *int_file_gamma = info_ptr->int_gamma;
  163582. return (PNG_INFO_gAMA);
  163583. }
  163584. return (0);
  163585. }
  163586. #endif
  163587. #endif
  163588. #if defined(PNG_sRGB_SUPPORTED)
  163589. png_uint_32 PNGAPI
  163590. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163591. {
  163592. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163593. && file_srgb_intent != NULL)
  163594. {
  163595. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163596. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163597. return (PNG_INFO_sRGB);
  163598. }
  163599. return (0);
  163600. }
  163601. #endif
  163602. #if defined(PNG_iCCP_SUPPORTED)
  163603. png_uint_32 PNGAPI
  163604. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163605. png_charpp name, int *compression_type,
  163606. png_charpp profile, png_uint_32 *proflen)
  163607. {
  163608. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163609. && name != NULL && profile != NULL && proflen != NULL)
  163610. {
  163611. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163612. *name = info_ptr->iccp_name;
  163613. *profile = info_ptr->iccp_profile;
  163614. *proflen = (int)info_ptr->iccp_proflen;
  163615. *compression_type = (int)info_ptr->iccp_compression;
  163616. return (PNG_INFO_iCCP);
  163617. }
  163618. return (0);
  163619. }
  163620. #endif
  163621. #if defined(PNG_sPLT_SUPPORTED)
  163622. png_uint_32 PNGAPI
  163623. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163624. png_sPLT_tpp spalettes)
  163625. {
  163626. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163627. {
  163628. *spalettes = info_ptr->splt_palettes;
  163629. return ((png_uint_32)info_ptr->splt_palettes_num);
  163630. }
  163631. return (0);
  163632. }
  163633. #endif
  163634. #if defined(PNG_hIST_SUPPORTED)
  163635. png_uint_32 PNGAPI
  163636. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163637. {
  163638. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163639. && hist != NULL)
  163640. {
  163641. png_debug1(1, "in %s retrieval function\n", "hIST");
  163642. *hist = info_ptr->hist;
  163643. return (PNG_INFO_hIST);
  163644. }
  163645. return (0);
  163646. }
  163647. #endif
  163648. png_uint_32 PNGAPI
  163649. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163650. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163651. int *color_type, int *interlace_type, int *compression_type,
  163652. int *filter_type)
  163653. {
  163654. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163655. bit_depth != NULL && color_type != NULL)
  163656. {
  163657. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163658. *width = info_ptr->width;
  163659. *height = info_ptr->height;
  163660. *bit_depth = info_ptr->bit_depth;
  163661. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163662. png_error(png_ptr, "Invalid bit depth");
  163663. *color_type = info_ptr->color_type;
  163664. if (info_ptr->color_type > 6)
  163665. png_error(png_ptr, "Invalid color type");
  163666. if (compression_type != NULL)
  163667. *compression_type = info_ptr->compression_type;
  163668. if (filter_type != NULL)
  163669. *filter_type = info_ptr->filter_type;
  163670. if (interlace_type != NULL)
  163671. *interlace_type = info_ptr->interlace_type;
  163672. if (*width == 0 || *width > PNG_UINT_31_MAX)
  163673. png_error(png_ptr, "Invalid image width");
  163674. if (*height == 0 || *height > PNG_UINT_31_MAX)
  163675. png_error(png_ptr, "Invalid image height");
  163676. if (info_ptr->width > (PNG_UINT_32_MAX
  163677. >> 3) /* 8-byte RGBA pixels */
  163678. - 64 /* bigrowbuf hack */
  163679. - 1 /* filter byte */
  163680. - 7*8 /* rounding of width to multiple of 8 pixels */
  163681. - 8) /* extra max_pixel_depth pad */
  163682. {
  163683. png_warning(png_ptr,
  163684. "Width too large for libpng to process image data.");
  163685. }
  163686. return (1);
  163687. }
  163688. return (0);
  163689. }
  163690. #if defined(PNG_oFFs_SUPPORTED)
  163691. png_uint_32 PNGAPI
  163692. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  163693. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  163694. {
  163695. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  163696. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  163697. {
  163698. png_debug1(1, "in %s retrieval function\n", "oFFs");
  163699. *offset_x = info_ptr->x_offset;
  163700. *offset_y = info_ptr->y_offset;
  163701. *unit_type = (int)info_ptr->offset_unit_type;
  163702. return (PNG_INFO_oFFs);
  163703. }
  163704. return (0);
  163705. }
  163706. #endif
  163707. #if defined(PNG_pCAL_SUPPORTED)
  163708. png_uint_32 PNGAPI
  163709. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  163710. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  163711. png_charp *units, png_charpp *params)
  163712. {
  163713. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  163714. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  163715. nparams != NULL && units != NULL && params != NULL)
  163716. {
  163717. png_debug1(1, "in %s retrieval function\n", "pCAL");
  163718. *purpose = info_ptr->pcal_purpose;
  163719. *X0 = info_ptr->pcal_X0;
  163720. *X1 = info_ptr->pcal_X1;
  163721. *type = (int)info_ptr->pcal_type;
  163722. *nparams = (int)info_ptr->pcal_nparams;
  163723. *units = info_ptr->pcal_units;
  163724. *params = info_ptr->pcal_params;
  163725. return (PNG_INFO_pCAL);
  163726. }
  163727. return (0);
  163728. }
  163729. #endif
  163730. #if defined(PNG_sCAL_SUPPORTED)
  163731. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163732. png_uint_32 PNGAPI
  163733. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  163734. int *unit, double *width, double *height)
  163735. {
  163736. if (png_ptr != NULL && info_ptr != NULL &&
  163737. (info_ptr->valid & PNG_INFO_sCAL))
  163738. {
  163739. *unit = info_ptr->scal_unit;
  163740. *width = info_ptr->scal_pixel_width;
  163741. *height = info_ptr->scal_pixel_height;
  163742. return (PNG_INFO_sCAL);
  163743. }
  163744. return(0);
  163745. }
  163746. #else
  163747. #ifdef PNG_FIXED_POINT_SUPPORTED
  163748. png_uint_32 PNGAPI
  163749. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  163750. int *unit, png_charpp width, png_charpp height)
  163751. {
  163752. if (png_ptr != NULL && info_ptr != NULL &&
  163753. (info_ptr->valid & PNG_INFO_sCAL))
  163754. {
  163755. *unit = info_ptr->scal_unit;
  163756. *width = info_ptr->scal_s_width;
  163757. *height = info_ptr->scal_s_height;
  163758. return (PNG_INFO_sCAL);
  163759. }
  163760. return(0);
  163761. }
  163762. #endif
  163763. #endif
  163764. #endif
  163765. #if defined(PNG_pHYs_SUPPORTED)
  163766. png_uint_32 PNGAPI
  163767. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  163768. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163769. {
  163770. png_uint_32 retval = 0;
  163771. if (png_ptr != NULL && info_ptr != NULL &&
  163772. (info_ptr->valid & PNG_INFO_pHYs))
  163773. {
  163774. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163775. if (res_x != NULL)
  163776. {
  163777. *res_x = info_ptr->x_pixels_per_unit;
  163778. retval |= PNG_INFO_pHYs;
  163779. }
  163780. if (res_y != NULL)
  163781. {
  163782. *res_y = info_ptr->y_pixels_per_unit;
  163783. retval |= PNG_INFO_pHYs;
  163784. }
  163785. if (unit_type != NULL)
  163786. {
  163787. *unit_type = (int)info_ptr->phys_unit_type;
  163788. retval |= PNG_INFO_pHYs;
  163789. }
  163790. }
  163791. return (retval);
  163792. }
  163793. #endif
  163794. png_uint_32 PNGAPI
  163795. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  163796. int *num_palette)
  163797. {
  163798. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  163799. && palette != NULL)
  163800. {
  163801. png_debug1(1, "in %s retrieval function\n", "PLTE");
  163802. *palette = info_ptr->palette;
  163803. *num_palette = info_ptr->num_palette;
  163804. png_debug1(3, "num_palette = %d\n", *num_palette);
  163805. return (PNG_INFO_PLTE);
  163806. }
  163807. return (0);
  163808. }
  163809. #if defined(PNG_sBIT_SUPPORTED)
  163810. png_uint_32 PNGAPI
  163811. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  163812. {
  163813. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  163814. && sig_bit != NULL)
  163815. {
  163816. png_debug1(1, "in %s retrieval function\n", "sBIT");
  163817. *sig_bit = &(info_ptr->sig_bit);
  163818. return (PNG_INFO_sBIT);
  163819. }
  163820. return (0);
  163821. }
  163822. #endif
  163823. #if defined(PNG_TEXT_SUPPORTED)
  163824. png_uint_32 PNGAPI
  163825. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  163826. int *num_text)
  163827. {
  163828. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  163829. {
  163830. png_debug1(1, "in %s retrieval function\n",
  163831. (png_ptr->chunk_name[0] == '\0' ? "text"
  163832. : (png_const_charp)png_ptr->chunk_name));
  163833. if (text_ptr != NULL)
  163834. *text_ptr = info_ptr->text;
  163835. if (num_text != NULL)
  163836. *num_text = info_ptr->num_text;
  163837. return ((png_uint_32)info_ptr->num_text);
  163838. }
  163839. if (num_text != NULL)
  163840. *num_text = 0;
  163841. return(0);
  163842. }
  163843. #endif
  163844. #if defined(PNG_tIME_SUPPORTED)
  163845. png_uint_32 PNGAPI
  163846. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  163847. {
  163848. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  163849. && mod_time != NULL)
  163850. {
  163851. png_debug1(1, "in %s retrieval function\n", "tIME");
  163852. *mod_time = &(info_ptr->mod_time);
  163853. return (PNG_INFO_tIME);
  163854. }
  163855. return (0);
  163856. }
  163857. #endif
  163858. #if defined(PNG_tRNS_SUPPORTED)
  163859. png_uint_32 PNGAPI
  163860. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  163861. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  163862. {
  163863. png_uint_32 retval = 0;
  163864. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  163865. {
  163866. png_debug1(1, "in %s retrieval function\n", "tRNS");
  163867. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  163868. {
  163869. if (trans != NULL)
  163870. {
  163871. *trans = info_ptr->trans;
  163872. retval |= PNG_INFO_tRNS;
  163873. }
  163874. if (trans_values != NULL)
  163875. *trans_values = &(info_ptr->trans_values);
  163876. }
  163877. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  163878. {
  163879. if (trans_values != NULL)
  163880. {
  163881. *trans_values = &(info_ptr->trans_values);
  163882. retval |= PNG_INFO_tRNS;
  163883. }
  163884. if(trans != NULL)
  163885. *trans = NULL;
  163886. }
  163887. if(num_trans != NULL)
  163888. {
  163889. *num_trans = info_ptr->num_trans;
  163890. retval |= PNG_INFO_tRNS;
  163891. }
  163892. }
  163893. return (retval);
  163894. }
  163895. #endif
  163896. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163897. png_uint_32 PNGAPI
  163898. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  163899. png_unknown_chunkpp unknowns)
  163900. {
  163901. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  163902. {
  163903. *unknowns = info_ptr->unknown_chunks;
  163904. return ((png_uint_32)info_ptr->unknown_chunks_num);
  163905. }
  163906. return (0);
  163907. }
  163908. #endif
  163909. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  163910. png_byte PNGAPI
  163911. png_get_rgb_to_gray_status (png_structp png_ptr)
  163912. {
  163913. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  163914. }
  163915. #endif
  163916. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  163917. png_voidp PNGAPI
  163918. png_get_user_chunk_ptr(png_structp png_ptr)
  163919. {
  163920. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  163921. }
  163922. #endif
  163923. #ifdef PNG_WRITE_SUPPORTED
  163924. png_uint_32 PNGAPI
  163925. png_get_compression_buffer_size(png_structp png_ptr)
  163926. {
  163927. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  163928. }
  163929. #endif
  163930. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  163931. #ifndef PNG_1_0_X
  163932. png_uint_32 PNGAPI
  163933. png_get_asm_flags (png_structp png_ptr)
  163934. {
  163935. return (png_ptr? 0L: 0L);
  163936. }
  163937. png_uint_32 PNGAPI
  163938. png_get_asm_flagmask (int flag_select)
  163939. {
  163940. flag_select=flag_select;
  163941. return 0L;
  163942. }
  163943. png_uint_32 PNGAPI
  163944. png_get_mmx_flagmask (int flag_select, int *compilerID)
  163945. {
  163946. flag_select=flag_select;
  163947. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  163948. return 0L;
  163949. }
  163950. png_byte PNGAPI
  163951. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  163952. {
  163953. return (png_ptr? 0: 0);
  163954. }
  163955. png_uint_32 PNGAPI
  163956. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  163957. {
  163958. return (png_ptr? 0L: 0L);
  163959. }
  163960. #endif /* ?PNG_1_0_X */
  163961. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  163962. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  163963. png_uint_32 PNGAPI
  163964. png_get_user_width_max (png_structp png_ptr)
  163965. {
  163966. return (png_ptr? png_ptr->user_width_max : 0);
  163967. }
  163968. png_uint_32 PNGAPI
  163969. png_get_user_height_max (png_structp png_ptr)
  163970. {
  163971. return (png_ptr? png_ptr->user_height_max : 0);
  163972. }
  163973. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  163974. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163975. /*** End of inlined file: pngget.c ***/
  163976. /*** Start of inlined file: pngmem.c ***/
  163977. #define PNG_INTERNAL
  163978. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163979. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  163980. png_voidp /* PRIVATE */
  163981. png_create_struct(int type)
  163982. {
  163983. #ifdef PNG_USER_MEM_SUPPORTED
  163984. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  163985. }
  163986. png_voidp /* PRIVATE */
  163987. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  163988. {
  163989. #endif /* PNG_USER_MEM_SUPPORTED */
  163990. png_size_t size;
  163991. png_voidp struct_ptr;
  163992. if (type == PNG_STRUCT_INFO)
  163993. size = png_sizeof(png_info);
  163994. else if (type == PNG_STRUCT_PNG)
  163995. size = png_sizeof(png_struct);
  163996. else
  163997. return (png_get_copyright(NULL));
  163998. #ifdef PNG_USER_MEM_SUPPORTED
  163999. if(malloc_fn != NULL)
  164000. {
  164001. png_struct dummy_struct;
  164002. png_structp png_ptr = &dummy_struct;
  164003. png_ptr->mem_ptr=mem_ptr;
  164004. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  164005. }
  164006. else
  164007. #endif /* PNG_USER_MEM_SUPPORTED */
  164008. struct_ptr = (png_voidp)farmalloc(size);
  164009. if (struct_ptr != NULL)
  164010. png_memset(struct_ptr, 0, size);
  164011. return (struct_ptr);
  164012. }
  164013. void /* PRIVATE */
  164014. png_destroy_struct(png_voidp struct_ptr)
  164015. {
  164016. #ifdef PNG_USER_MEM_SUPPORTED
  164017. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164018. }
  164019. void /* PRIVATE */
  164020. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164021. png_voidp mem_ptr)
  164022. {
  164023. #endif
  164024. if (struct_ptr != NULL)
  164025. {
  164026. #ifdef PNG_USER_MEM_SUPPORTED
  164027. if(free_fn != NULL)
  164028. {
  164029. png_struct dummy_struct;
  164030. png_structp png_ptr = &dummy_struct;
  164031. png_ptr->mem_ptr=mem_ptr;
  164032. (*(free_fn))(png_ptr, struct_ptr);
  164033. return;
  164034. }
  164035. #endif /* PNG_USER_MEM_SUPPORTED */
  164036. farfree (struct_ptr);
  164037. }
  164038. }
  164039. png_voidp PNGAPI
  164040. png_malloc(png_structp png_ptr, png_uint_32 size)
  164041. {
  164042. png_voidp ret;
  164043. if (png_ptr == NULL || size == 0)
  164044. return (NULL);
  164045. #ifdef PNG_USER_MEM_SUPPORTED
  164046. if(png_ptr->malloc_fn != NULL)
  164047. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164048. else
  164049. ret = (png_malloc_default(png_ptr, size));
  164050. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164051. png_error(png_ptr, "Out of memory!");
  164052. return (ret);
  164053. }
  164054. png_voidp PNGAPI
  164055. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164056. {
  164057. png_voidp ret;
  164058. #endif /* PNG_USER_MEM_SUPPORTED */
  164059. if (png_ptr == NULL || size == 0)
  164060. return (NULL);
  164061. #ifdef PNG_MAX_MALLOC_64K
  164062. if (size > (png_uint_32)65536L)
  164063. {
  164064. png_warning(png_ptr, "Cannot Allocate > 64K");
  164065. ret = NULL;
  164066. }
  164067. else
  164068. #endif
  164069. if (size != (size_t)size)
  164070. ret = NULL;
  164071. else if (size == (png_uint_32)65536L)
  164072. {
  164073. if (png_ptr->offset_table == NULL)
  164074. {
  164075. ret = farmalloc(size);
  164076. if (ret == NULL || ((png_size_t)ret & 0xffff))
  164077. {
  164078. int num_blocks;
  164079. png_uint_32 total_size;
  164080. png_bytep table;
  164081. int i;
  164082. png_byte huge * hptr;
  164083. if (ret != NULL)
  164084. {
  164085. farfree(ret);
  164086. ret = NULL;
  164087. }
  164088. if(png_ptr->zlib_window_bits > 14)
  164089. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  164090. else
  164091. num_blocks = 1;
  164092. if (png_ptr->zlib_mem_level >= 7)
  164093. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  164094. else
  164095. num_blocks++;
  164096. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  164097. table = farmalloc(total_size);
  164098. if (table == NULL)
  164099. {
  164100. #ifndef PNG_USER_MEM_SUPPORTED
  164101. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164102. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  164103. else
  164104. png_warning(png_ptr, "Out Of Memory.");
  164105. #endif
  164106. return (NULL);
  164107. }
  164108. if ((png_size_t)table & 0xfff0)
  164109. {
  164110. #ifndef PNG_USER_MEM_SUPPORTED
  164111. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164112. png_error(png_ptr,
  164113. "Farmalloc didn't return normalized pointer");
  164114. else
  164115. png_warning(png_ptr,
  164116. "Farmalloc didn't return normalized pointer");
  164117. #endif
  164118. return (NULL);
  164119. }
  164120. png_ptr->offset_table = table;
  164121. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  164122. png_sizeof (png_bytep));
  164123. if (png_ptr->offset_table_ptr == NULL)
  164124. {
  164125. #ifndef PNG_USER_MEM_SUPPORTED
  164126. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164127. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  164128. else
  164129. png_warning(png_ptr, "Out Of memory.");
  164130. #endif
  164131. return (NULL);
  164132. }
  164133. hptr = (png_byte huge *)table;
  164134. if ((png_size_t)hptr & 0xf)
  164135. {
  164136. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  164137. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  164138. }
  164139. for (i = 0; i < num_blocks; i++)
  164140. {
  164141. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  164142. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  164143. }
  164144. png_ptr->offset_table_number = num_blocks;
  164145. png_ptr->offset_table_count = 0;
  164146. png_ptr->offset_table_count_free = 0;
  164147. }
  164148. }
  164149. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  164150. {
  164151. #ifndef PNG_USER_MEM_SUPPORTED
  164152. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164153. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  164154. else
  164155. png_warning(png_ptr, "Out of Memory.");
  164156. #endif
  164157. return (NULL);
  164158. }
  164159. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  164160. }
  164161. else
  164162. ret = farmalloc(size);
  164163. #ifndef PNG_USER_MEM_SUPPORTED
  164164. if (ret == NULL)
  164165. {
  164166. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164167. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164168. else
  164169. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164170. }
  164171. #endif
  164172. return (ret);
  164173. }
  164174. void PNGAPI
  164175. png_free(png_structp png_ptr, png_voidp ptr)
  164176. {
  164177. if (png_ptr == NULL || ptr == NULL)
  164178. return;
  164179. #ifdef PNG_USER_MEM_SUPPORTED
  164180. if (png_ptr->free_fn != NULL)
  164181. {
  164182. (*(png_ptr->free_fn))(png_ptr, ptr);
  164183. return;
  164184. }
  164185. else png_free_default(png_ptr, ptr);
  164186. }
  164187. void PNGAPI
  164188. png_free_default(png_structp png_ptr, png_voidp ptr)
  164189. {
  164190. #endif /* PNG_USER_MEM_SUPPORTED */
  164191. if(png_ptr == NULL) return;
  164192. if (png_ptr->offset_table != NULL)
  164193. {
  164194. int i;
  164195. for (i = 0; i < png_ptr->offset_table_count; i++)
  164196. {
  164197. if (ptr == png_ptr->offset_table_ptr[i])
  164198. {
  164199. ptr = NULL;
  164200. png_ptr->offset_table_count_free++;
  164201. break;
  164202. }
  164203. }
  164204. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  164205. {
  164206. farfree(png_ptr->offset_table);
  164207. farfree(png_ptr->offset_table_ptr);
  164208. png_ptr->offset_table = NULL;
  164209. png_ptr->offset_table_ptr = NULL;
  164210. }
  164211. }
  164212. if (ptr != NULL)
  164213. {
  164214. farfree(ptr);
  164215. }
  164216. }
  164217. #else /* Not the Borland DOS special memory handler */
  164218. png_voidp /* PRIVATE */
  164219. png_create_struct(int type)
  164220. {
  164221. #ifdef PNG_USER_MEM_SUPPORTED
  164222. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164223. }
  164224. png_voidp /* PRIVATE */
  164225. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164226. {
  164227. #endif /* PNG_USER_MEM_SUPPORTED */
  164228. png_size_t size;
  164229. png_voidp struct_ptr;
  164230. if (type == PNG_STRUCT_INFO)
  164231. size = png_sizeof(png_info);
  164232. else if (type == PNG_STRUCT_PNG)
  164233. size = png_sizeof(png_struct);
  164234. else
  164235. return (NULL);
  164236. #ifdef PNG_USER_MEM_SUPPORTED
  164237. if(malloc_fn != NULL)
  164238. {
  164239. png_struct dummy_struct;
  164240. png_structp png_ptr = &dummy_struct;
  164241. png_ptr->mem_ptr=mem_ptr;
  164242. struct_ptr = (*(malloc_fn))(png_ptr, size);
  164243. if (struct_ptr != NULL)
  164244. png_memset(struct_ptr, 0, size);
  164245. return (struct_ptr);
  164246. }
  164247. #endif /* PNG_USER_MEM_SUPPORTED */
  164248. #if defined(__TURBOC__) && !defined(__FLAT__)
  164249. struct_ptr = (png_voidp)farmalloc(size);
  164250. #else
  164251. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164252. struct_ptr = (png_voidp)halloc(size,1);
  164253. # else
  164254. struct_ptr = (png_voidp)malloc(size);
  164255. # endif
  164256. #endif
  164257. if (struct_ptr != NULL)
  164258. png_memset(struct_ptr, 0, size);
  164259. return (struct_ptr);
  164260. }
  164261. void /* PRIVATE */
  164262. png_destroy_struct(png_voidp struct_ptr)
  164263. {
  164264. #ifdef PNG_USER_MEM_SUPPORTED
  164265. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164266. }
  164267. void /* PRIVATE */
  164268. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164269. png_voidp mem_ptr)
  164270. {
  164271. #endif /* PNG_USER_MEM_SUPPORTED */
  164272. if (struct_ptr != NULL)
  164273. {
  164274. #ifdef PNG_USER_MEM_SUPPORTED
  164275. if(free_fn != NULL)
  164276. {
  164277. png_struct dummy_struct;
  164278. png_structp png_ptr = &dummy_struct;
  164279. png_ptr->mem_ptr=mem_ptr;
  164280. (*(free_fn))(png_ptr, struct_ptr);
  164281. return;
  164282. }
  164283. #endif /* PNG_USER_MEM_SUPPORTED */
  164284. #if defined(__TURBOC__) && !defined(__FLAT__)
  164285. farfree(struct_ptr);
  164286. #else
  164287. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164288. hfree(struct_ptr);
  164289. # else
  164290. free(struct_ptr);
  164291. # endif
  164292. #endif
  164293. }
  164294. }
  164295. png_voidp PNGAPI
  164296. png_malloc(png_structp png_ptr, png_uint_32 size)
  164297. {
  164298. png_voidp ret;
  164299. #ifdef PNG_USER_MEM_SUPPORTED
  164300. if (png_ptr == NULL || size == 0)
  164301. return (NULL);
  164302. if(png_ptr->malloc_fn != NULL)
  164303. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164304. else
  164305. ret = (png_malloc_default(png_ptr, size));
  164306. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164307. png_error(png_ptr, "Out of Memory!");
  164308. return (ret);
  164309. }
  164310. png_voidp PNGAPI
  164311. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164312. {
  164313. png_voidp ret;
  164314. #endif /* PNG_USER_MEM_SUPPORTED */
  164315. if (png_ptr == NULL || size == 0)
  164316. return (NULL);
  164317. #ifdef PNG_MAX_MALLOC_64K
  164318. if (size > (png_uint_32)65536L)
  164319. {
  164320. #ifndef PNG_USER_MEM_SUPPORTED
  164321. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164322. png_error(png_ptr, "Cannot Allocate > 64K");
  164323. else
  164324. #endif
  164325. return NULL;
  164326. }
  164327. #endif
  164328. #if defined(__TURBOC__) && !defined(__FLAT__)
  164329. if (size != (unsigned long)size)
  164330. ret = NULL;
  164331. else
  164332. ret = farmalloc(size);
  164333. #else
  164334. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164335. if (size != (unsigned long)size)
  164336. ret = NULL;
  164337. else
  164338. ret = halloc(size, 1);
  164339. # else
  164340. if (size != (size_t)size)
  164341. ret = NULL;
  164342. else
  164343. ret = malloc((size_t)size);
  164344. # endif
  164345. #endif
  164346. #ifndef PNG_USER_MEM_SUPPORTED
  164347. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164348. png_error(png_ptr, "Out of Memory");
  164349. #endif
  164350. return (ret);
  164351. }
  164352. void PNGAPI
  164353. png_free(png_structp png_ptr, png_voidp ptr)
  164354. {
  164355. if (png_ptr == NULL || ptr == NULL)
  164356. return;
  164357. #ifdef PNG_USER_MEM_SUPPORTED
  164358. if (png_ptr->free_fn != NULL)
  164359. {
  164360. (*(png_ptr->free_fn))(png_ptr, ptr);
  164361. return;
  164362. }
  164363. else png_free_default(png_ptr, ptr);
  164364. }
  164365. void PNGAPI
  164366. png_free_default(png_structp png_ptr, png_voidp ptr)
  164367. {
  164368. if (png_ptr == NULL || ptr == NULL)
  164369. return;
  164370. #endif /* PNG_USER_MEM_SUPPORTED */
  164371. #if defined(__TURBOC__) && !defined(__FLAT__)
  164372. farfree(ptr);
  164373. #else
  164374. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164375. hfree(ptr);
  164376. # else
  164377. free(ptr);
  164378. # endif
  164379. #endif
  164380. }
  164381. #endif /* Not Borland DOS special memory handler */
  164382. #if defined(PNG_1_0_X)
  164383. # define png_malloc_warn png_malloc
  164384. #else
  164385. png_voidp PNGAPI
  164386. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164387. {
  164388. png_voidp ptr;
  164389. png_uint_32 save_flags;
  164390. if(png_ptr == NULL) return (NULL);
  164391. save_flags=png_ptr->flags;
  164392. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164393. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164394. png_ptr->flags=save_flags;
  164395. return(ptr);
  164396. }
  164397. #endif
  164398. png_voidp PNGAPI
  164399. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164400. png_uint_32 length)
  164401. {
  164402. png_size_t size;
  164403. size = (png_size_t)length;
  164404. if ((png_uint_32)size != length)
  164405. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164406. return(png_memcpy (s1, s2, size));
  164407. }
  164408. png_voidp PNGAPI
  164409. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164410. png_uint_32 length)
  164411. {
  164412. png_size_t size;
  164413. size = (png_size_t)length;
  164414. if ((png_uint_32)size != length)
  164415. png_error(png_ptr,"Overflow in png_memset_check.");
  164416. return (png_memset (s1, value, size));
  164417. }
  164418. #ifdef PNG_USER_MEM_SUPPORTED
  164419. void PNGAPI
  164420. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164421. malloc_fn, png_free_ptr free_fn)
  164422. {
  164423. if(png_ptr != NULL) {
  164424. png_ptr->mem_ptr = mem_ptr;
  164425. png_ptr->malloc_fn = malloc_fn;
  164426. png_ptr->free_fn = free_fn;
  164427. }
  164428. }
  164429. png_voidp PNGAPI
  164430. png_get_mem_ptr(png_structp png_ptr)
  164431. {
  164432. if(png_ptr == NULL) return (NULL);
  164433. return ((png_voidp)png_ptr->mem_ptr);
  164434. }
  164435. #endif /* PNG_USER_MEM_SUPPORTED */
  164436. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164437. /*** End of inlined file: pngmem.c ***/
  164438. /*** Start of inlined file: pngread.c ***/
  164439. #define PNG_INTERNAL
  164440. #if defined(PNG_READ_SUPPORTED)
  164441. png_structp PNGAPI
  164442. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164443. png_error_ptr error_fn, png_error_ptr warn_fn)
  164444. {
  164445. #ifdef PNG_USER_MEM_SUPPORTED
  164446. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164447. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164448. }
  164449. png_structp PNGAPI
  164450. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164451. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164452. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164453. {
  164454. #endif /* PNG_USER_MEM_SUPPORTED */
  164455. png_structp png_ptr;
  164456. #ifdef PNG_SETJMP_SUPPORTED
  164457. #ifdef USE_FAR_KEYWORD
  164458. jmp_buf jmpbuf;
  164459. #endif
  164460. #endif
  164461. int i;
  164462. png_debug(1, "in png_create_read_struct\n");
  164463. #ifdef PNG_USER_MEM_SUPPORTED
  164464. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164465. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164466. #else
  164467. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164468. #endif
  164469. if (png_ptr == NULL)
  164470. return (NULL);
  164471. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164472. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164473. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164474. #endif
  164475. #ifdef PNG_SETJMP_SUPPORTED
  164476. #ifdef USE_FAR_KEYWORD
  164477. if (setjmp(jmpbuf))
  164478. #else
  164479. if (setjmp(png_ptr->jmpbuf))
  164480. #endif
  164481. {
  164482. png_free(png_ptr, png_ptr->zbuf);
  164483. png_ptr->zbuf=NULL;
  164484. #ifdef PNG_USER_MEM_SUPPORTED
  164485. png_destroy_struct_2((png_voidp)png_ptr,
  164486. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164487. #else
  164488. png_destroy_struct((png_voidp)png_ptr);
  164489. #endif
  164490. return (NULL);
  164491. }
  164492. #ifdef USE_FAR_KEYWORD
  164493. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164494. #endif
  164495. #endif
  164496. #ifdef PNG_USER_MEM_SUPPORTED
  164497. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164498. #endif
  164499. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164500. i=0;
  164501. do
  164502. {
  164503. if(user_png_ver[i] != png_libpng_ver[i])
  164504. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164505. } while (png_libpng_ver[i++]);
  164506. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164507. {
  164508. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164509. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164510. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164511. {
  164512. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164513. char msg[80];
  164514. if (user_png_ver)
  164515. {
  164516. png_snprintf(msg, 80,
  164517. "Application was compiled with png.h from libpng-%.20s",
  164518. user_png_ver);
  164519. png_warning(png_ptr, msg);
  164520. }
  164521. png_snprintf(msg, 80,
  164522. "Application is running with png.c from libpng-%.20s",
  164523. png_libpng_ver);
  164524. png_warning(png_ptr, msg);
  164525. #endif
  164526. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164527. png_ptr->flags=0;
  164528. #endif
  164529. png_error(png_ptr,
  164530. "Incompatible libpng version in application and library");
  164531. }
  164532. }
  164533. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164534. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164535. (png_uint_32)png_ptr->zbuf_size);
  164536. png_ptr->zstream.zalloc = png_zalloc;
  164537. png_ptr->zstream.zfree = png_zfree;
  164538. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164539. switch (inflateInit(&png_ptr->zstream))
  164540. {
  164541. case Z_OK: /* Do nothing */ break;
  164542. case Z_MEM_ERROR:
  164543. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164544. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164545. default: png_error(png_ptr, "Unknown zlib error");
  164546. }
  164547. png_ptr->zstream.next_out = png_ptr->zbuf;
  164548. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164549. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164550. #ifdef PNG_SETJMP_SUPPORTED
  164551. #ifdef USE_FAR_KEYWORD
  164552. if (setjmp(jmpbuf))
  164553. PNG_ABORT();
  164554. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164555. #else
  164556. if (setjmp(png_ptr->jmpbuf))
  164557. PNG_ABORT();
  164558. #endif
  164559. #endif
  164560. return (png_ptr);
  164561. }
  164562. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164563. #undef png_read_init
  164564. void PNGAPI
  164565. png_read_init(png_structp png_ptr)
  164566. {
  164567. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164568. }
  164569. void PNGAPI
  164570. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164571. png_size_t png_struct_size, png_size_t png_info_size)
  164572. {
  164573. if(png_ptr == NULL) return;
  164574. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164575. if(png_sizeof(png_struct) > png_struct_size ||
  164576. png_sizeof(png_info) > png_info_size)
  164577. {
  164578. char msg[80];
  164579. png_ptr->warning_fn=NULL;
  164580. if (user_png_ver)
  164581. {
  164582. png_snprintf(msg, 80,
  164583. "Application was compiled with png.h from libpng-%.20s",
  164584. user_png_ver);
  164585. png_warning(png_ptr, msg);
  164586. }
  164587. png_snprintf(msg, 80,
  164588. "Application is running with png.c from libpng-%.20s",
  164589. png_libpng_ver);
  164590. png_warning(png_ptr, msg);
  164591. }
  164592. #endif
  164593. if(png_sizeof(png_struct) > png_struct_size)
  164594. {
  164595. png_ptr->error_fn=NULL;
  164596. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164597. png_ptr->flags=0;
  164598. #endif
  164599. png_error(png_ptr,
  164600. "The png struct allocated by the application for reading is too small.");
  164601. }
  164602. if(png_sizeof(png_info) > png_info_size)
  164603. {
  164604. png_ptr->error_fn=NULL;
  164605. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164606. png_ptr->flags=0;
  164607. #endif
  164608. png_error(png_ptr,
  164609. "The info struct allocated by application for reading is too small.");
  164610. }
  164611. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164612. }
  164613. #endif /* PNG_1_0_X || PNG_1_2_X */
  164614. void PNGAPI
  164615. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164616. png_size_t png_struct_size)
  164617. {
  164618. #ifdef PNG_SETJMP_SUPPORTED
  164619. jmp_buf tmp_jmp; /* to save current jump buffer */
  164620. #endif
  164621. int i=0;
  164622. png_structp png_ptr=*ptr_ptr;
  164623. if(png_ptr == NULL) return;
  164624. do
  164625. {
  164626. if(user_png_ver[i] != png_libpng_ver[i])
  164627. {
  164628. #ifdef PNG_LEGACY_SUPPORTED
  164629. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164630. #else
  164631. png_ptr->warning_fn=NULL;
  164632. png_warning(png_ptr,
  164633. "Application uses deprecated png_read_init() and should be recompiled.");
  164634. break;
  164635. #endif
  164636. }
  164637. } while (png_libpng_ver[i++]);
  164638. png_debug(1, "in png_read_init_3\n");
  164639. #ifdef PNG_SETJMP_SUPPORTED
  164640. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164641. #endif
  164642. if(png_sizeof(png_struct) > png_struct_size)
  164643. {
  164644. png_destroy_struct(png_ptr);
  164645. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164646. png_ptr = *ptr_ptr;
  164647. }
  164648. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164649. #ifdef PNG_SETJMP_SUPPORTED
  164650. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164651. #endif
  164652. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164653. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164654. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164655. #endif
  164656. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164657. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164658. (png_uint_32)png_ptr->zbuf_size);
  164659. png_ptr->zstream.zalloc = png_zalloc;
  164660. png_ptr->zstream.zfree = png_zfree;
  164661. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164662. switch (inflateInit(&png_ptr->zstream))
  164663. {
  164664. case Z_OK: /* Do nothing */ break;
  164665. case Z_MEM_ERROR:
  164666. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164667. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164668. default: png_error(png_ptr, "Unknown zlib error");
  164669. }
  164670. png_ptr->zstream.next_out = png_ptr->zbuf;
  164671. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164672. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164673. }
  164674. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164675. void PNGAPI
  164676. png_read_info(png_structp png_ptr, png_infop info_ptr)
  164677. {
  164678. if(png_ptr == NULL) return;
  164679. png_debug(1, "in png_read_info\n");
  164680. if (png_ptr->sig_bytes < 8)
  164681. {
  164682. png_size_t num_checked = png_ptr->sig_bytes,
  164683. num_to_check = 8 - num_checked;
  164684. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  164685. png_ptr->sig_bytes = 8;
  164686. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  164687. {
  164688. if (num_checked < 4 &&
  164689. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  164690. png_error(png_ptr, "Not a PNG file");
  164691. else
  164692. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  164693. }
  164694. if (num_checked < 3)
  164695. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  164696. }
  164697. for(;;)
  164698. {
  164699. #ifdef PNG_USE_LOCAL_ARRAYS
  164700. PNG_CONST PNG_IHDR;
  164701. PNG_CONST PNG_IDAT;
  164702. PNG_CONST PNG_IEND;
  164703. PNG_CONST PNG_PLTE;
  164704. #if defined(PNG_READ_bKGD_SUPPORTED)
  164705. PNG_CONST PNG_bKGD;
  164706. #endif
  164707. #if defined(PNG_READ_cHRM_SUPPORTED)
  164708. PNG_CONST PNG_cHRM;
  164709. #endif
  164710. #if defined(PNG_READ_gAMA_SUPPORTED)
  164711. PNG_CONST PNG_gAMA;
  164712. #endif
  164713. #if defined(PNG_READ_hIST_SUPPORTED)
  164714. PNG_CONST PNG_hIST;
  164715. #endif
  164716. #if defined(PNG_READ_iCCP_SUPPORTED)
  164717. PNG_CONST PNG_iCCP;
  164718. #endif
  164719. #if defined(PNG_READ_iTXt_SUPPORTED)
  164720. PNG_CONST PNG_iTXt;
  164721. #endif
  164722. #if defined(PNG_READ_oFFs_SUPPORTED)
  164723. PNG_CONST PNG_oFFs;
  164724. #endif
  164725. #if defined(PNG_READ_pCAL_SUPPORTED)
  164726. PNG_CONST PNG_pCAL;
  164727. #endif
  164728. #if defined(PNG_READ_pHYs_SUPPORTED)
  164729. PNG_CONST PNG_pHYs;
  164730. #endif
  164731. #if defined(PNG_READ_sBIT_SUPPORTED)
  164732. PNG_CONST PNG_sBIT;
  164733. #endif
  164734. #if defined(PNG_READ_sCAL_SUPPORTED)
  164735. PNG_CONST PNG_sCAL;
  164736. #endif
  164737. #if defined(PNG_READ_sPLT_SUPPORTED)
  164738. PNG_CONST PNG_sPLT;
  164739. #endif
  164740. #if defined(PNG_READ_sRGB_SUPPORTED)
  164741. PNG_CONST PNG_sRGB;
  164742. #endif
  164743. #if defined(PNG_READ_tEXt_SUPPORTED)
  164744. PNG_CONST PNG_tEXt;
  164745. #endif
  164746. #if defined(PNG_READ_tIME_SUPPORTED)
  164747. PNG_CONST PNG_tIME;
  164748. #endif
  164749. #if defined(PNG_READ_tRNS_SUPPORTED)
  164750. PNG_CONST PNG_tRNS;
  164751. #endif
  164752. #if defined(PNG_READ_zTXt_SUPPORTED)
  164753. PNG_CONST PNG_zTXt;
  164754. #endif
  164755. #endif /* PNG_USE_LOCAL_ARRAYS */
  164756. png_byte chunk_length[4];
  164757. png_uint_32 length;
  164758. png_read_data(png_ptr, chunk_length, 4);
  164759. length = png_get_uint_31(png_ptr,chunk_length);
  164760. png_reset_crc(png_ptr);
  164761. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164762. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  164763. length);
  164764. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164765. if(png_ptr->mode & PNG_AFTER_IDAT)
  164766. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  164767. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  164768. png_handle_IHDR(png_ptr, info_ptr, length);
  164769. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  164770. png_handle_IEND(png_ptr, info_ptr, length);
  164771. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  164772. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  164773. {
  164774. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164775. png_ptr->mode |= PNG_HAVE_IDAT;
  164776. png_handle_unknown(png_ptr, info_ptr, length);
  164777. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164778. png_ptr->mode |= PNG_HAVE_PLTE;
  164779. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164780. {
  164781. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164782. png_error(png_ptr, "Missing IHDR before IDAT");
  164783. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164784. !(png_ptr->mode & PNG_HAVE_PLTE))
  164785. png_error(png_ptr, "Missing PLTE before IDAT");
  164786. break;
  164787. }
  164788. }
  164789. #endif
  164790. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164791. png_handle_PLTE(png_ptr, info_ptr, length);
  164792. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164793. {
  164794. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164795. png_error(png_ptr, "Missing IHDR before IDAT");
  164796. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164797. !(png_ptr->mode & PNG_HAVE_PLTE))
  164798. png_error(png_ptr, "Missing PLTE before IDAT");
  164799. png_ptr->idat_size = length;
  164800. png_ptr->mode |= PNG_HAVE_IDAT;
  164801. break;
  164802. }
  164803. #if defined(PNG_READ_bKGD_SUPPORTED)
  164804. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  164805. png_handle_bKGD(png_ptr, info_ptr, length);
  164806. #endif
  164807. #if defined(PNG_READ_cHRM_SUPPORTED)
  164808. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  164809. png_handle_cHRM(png_ptr, info_ptr, length);
  164810. #endif
  164811. #if defined(PNG_READ_gAMA_SUPPORTED)
  164812. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  164813. png_handle_gAMA(png_ptr, info_ptr, length);
  164814. #endif
  164815. #if defined(PNG_READ_hIST_SUPPORTED)
  164816. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  164817. png_handle_hIST(png_ptr, info_ptr, length);
  164818. #endif
  164819. #if defined(PNG_READ_oFFs_SUPPORTED)
  164820. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  164821. png_handle_oFFs(png_ptr, info_ptr, length);
  164822. #endif
  164823. #if defined(PNG_READ_pCAL_SUPPORTED)
  164824. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  164825. png_handle_pCAL(png_ptr, info_ptr, length);
  164826. #endif
  164827. #if defined(PNG_READ_sCAL_SUPPORTED)
  164828. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  164829. png_handle_sCAL(png_ptr, info_ptr, length);
  164830. #endif
  164831. #if defined(PNG_READ_pHYs_SUPPORTED)
  164832. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  164833. png_handle_pHYs(png_ptr, info_ptr, length);
  164834. #endif
  164835. #if defined(PNG_READ_sBIT_SUPPORTED)
  164836. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  164837. png_handle_sBIT(png_ptr, info_ptr, length);
  164838. #endif
  164839. #if defined(PNG_READ_sRGB_SUPPORTED)
  164840. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  164841. png_handle_sRGB(png_ptr, info_ptr, length);
  164842. #endif
  164843. #if defined(PNG_READ_iCCP_SUPPORTED)
  164844. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  164845. png_handle_iCCP(png_ptr, info_ptr, length);
  164846. #endif
  164847. #if defined(PNG_READ_sPLT_SUPPORTED)
  164848. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  164849. png_handle_sPLT(png_ptr, info_ptr, length);
  164850. #endif
  164851. #if defined(PNG_READ_tEXt_SUPPORTED)
  164852. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  164853. png_handle_tEXt(png_ptr, info_ptr, length);
  164854. #endif
  164855. #if defined(PNG_READ_tIME_SUPPORTED)
  164856. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  164857. png_handle_tIME(png_ptr, info_ptr, length);
  164858. #endif
  164859. #if defined(PNG_READ_tRNS_SUPPORTED)
  164860. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  164861. png_handle_tRNS(png_ptr, info_ptr, length);
  164862. #endif
  164863. #if defined(PNG_READ_zTXt_SUPPORTED)
  164864. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  164865. png_handle_zTXt(png_ptr, info_ptr, length);
  164866. #endif
  164867. #if defined(PNG_READ_iTXt_SUPPORTED)
  164868. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  164869. png_handle_iTXt(png_ptr, info_ptr, length);
  164870. #endif
  164871. else
  164872. png_handle_unknown(png_ptr, info_ptr, length);
  164873. }
  164874. }
  164875. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164876. void PNGAPI
  164877. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  164878. {
  164879. png_debug(1, "in png_read_update_info\n");
  164880. if(png_ptr == NULL) return;
  164881. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164882. png_read_start_row(png_ptr);
  164883. else
  164884. png_warning(png_ptr,
  164885. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  164886. png_read_transform_info(png_ptr, info_ptr);
  164887. }
  164888. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164889. void PNGAPI
  164890. png_start_read_image(png_structp png_ptr)
  164891. {
  164892. png_debug(1, "in png_start_read_image\n");
  164893. if(png_ptr == NULL) return;
  164894. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164895. png_read_start_row(png_ptr);
  164896. }
  164897. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164898. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164899. void PNGAPI
  164900. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  164901. {
  164902. #ifdef PNG_USE_LOCAL_ARRAYS
  164903. PNG_CONST PNG_IDAT;
  164904. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  164905. 0xff};
  164906. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  164907. #endif
  164908. int ret;
  164909. if(png_ptr == NULL) return;
  164910. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  164911. png_ptr->row_number, png_ptr->pass);
  164912. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164913. png_read_start_row(png_ptr);
  164914. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  164915. {
  164916. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  164917. if (png_ptr->transformations & PNG_INVERT_MONO)
  164918. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  164919. #endif
  164920. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  164921. if (png_ptr->transformations & PNG_FILLER)
  164922. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  164923. #endif
  164924. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  164925. if (png_ptr->transformations & PNG_PACKSWAP)
  164926. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  164927. #endif
  164928. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  164929. if (png_ptr->transformations & PNG_PACK)
  164930. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  164931. #endif
  164932. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  164933. if (png_ptr->transformations & PNG_SHIFT)
  164934. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  164935. #endif
  164936. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  164937. if (png_ptr->transformations & PNG_BGR)
  164938. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  164939. #endif
  164940. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  164941. if (png_ptr->transformations & PNG_SWAP_BYTES)
  164942. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  164943. #endif
  164944. }
  164945. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164946. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  164947. {
  164948. switch (png_ptr->pass)
  164949. {
  164950. case 0:
  164951. if (png_ptr->row_number & 0x07)
  164952. {
  164953. if (dsp_row != NULL)
  164954. png_combine_row(png_ptr, dsp_row,
  164955. png_pass_dsp_mask[png_ptr->pass]);
  164956. png_read_finish_row(png_ptr);
  164957. return;
  164958. }
  164959. break;
  164960. case 1:
  164961. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  164962. {
  164963. if (dsp_row != NULL)
  164964. png_combine_row(png_ptr, dsp_row,
  164965. png_pass_dsp_mask[png_ptr->pass]);
  164966. png_read_finish_row(png_ptr);
  164967. return;
  164968. }
  164969. break;
  164970. case 2:
  164971. if ((png_ptr->row_number & 0x07) != 4)
  164972. {
  164973. if (dsp_row != NULL && (png_ptr->row_number & 4))
  164974. png_combine_row(png_ptr, dsp_row,
  164975. png_pass_dsp_mask[png_ptr->pass]);
  164976. png_read_finish_row(png_ptr);
  164977. return;
  164978. }
  164979. break;
  164980. case 3:
  164981. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  164982. {
  164983. if (dsp_row != NULL)
  164984. png_combine_row(png_ptr, dsp_row,
  164985. png_pass_dsp_mask[png_ptr->pass]);
  164986. png_read_finish_row(png_ptr);
  164987. return;
  164988. }
  164989. break;
  164990. case 4:
  164991. if ((png_ptr->row_number & 3) != 2)
  164992. {
  164993. if (dsp_row != NULL && (png_ptr->row_number & 2))
  164994. png_combine_row(png_ptr, dsp_row,
  164995. png_pass_dsp_mask[png_ptr->pass]);
  164996. png_read_finish_row(png_ptr);
  164997. return;
  164998. }
  164999. break;
  165000. case 5:
  165001. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  165002. {
  165003. if (dsp_row != NULL)
  165004. png_combine_row(png_ptr, dsp_row,
  165005. png_pass_dsp_mask[png_ptr->pass]);
  165006. png_read_finish_row(png_ptr);
  165007. return;
  165008. }
  165009. break;
  165010. case 6:
  165011. if (!(png_ptr->row_number & 1))
  165012. {
  165013. png_read_finish_row(png_ptr);
  165014. return;
  165015. }
  165016. break;
  165017. }
  165018. }
  165019. #endif
  165020. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  165021. png_error(png_ptr, "Invalid attempt to read row data");
  165022. png_ptr->zstream.next_out = png_ptr->row_buf;
  165023. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165024. do
  165025. {
  165026. if (!(png_ptr->zstream.avail_in))
  165027. {
  165028. while (!png_ptr->idat_size)
  165029. {
  165030. png_byte chunk_length[4];
  165031. png_crc_finish(png_ptr, 0);
  165032. png_read_data(png_ptr, chunk_length, 4);
  165033. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  165034. png_reset_crc(png_ptr);
  165035. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165036. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165037. png_error(png_ptr, "Not enough image data");
  165038. }
  165039. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  165040. png_ptr->zstream.next_in = png_ptr->zbuf;
  165041. if (png_ptr->zbuf_size > png_ptr->idat_size)
  165042. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  165043. png_crc_read(png_ptr, png_ptr->zbuf,
  165044. (png_size_t)png_ptr->zstream.avail_in);
  165045. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  165046. }
  165047. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  165048. if (ret == Z_STREAM_END)
  165049. {
  165050. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  165051. png_ptr->idat_size)
  165052. png_error(png_ptr, "Extra compressed data");
  165053. png_ptr->mode |= PNG_AFTER_IDAT;
  165054. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  165055. break;
  165056. }
  165057. if (ret != Z_OK)
  165058. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  165059. "Decompression error");
  165060. } while (png_ptr->zstream.avail_out);
  165061. png_ptr->row_info.color_type = png_ptr->color_type;
  165062. png_ptr->row_info.width = png_ptr->iwidth;
  165063. png_ptr->row_info.channels = png_ptr->channels;
  165064. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  165065. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  165066. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  165067. png_ptr->row_info.width);
  165068. if(png_ptr->row_buf[0])
  165069. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  165070. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  165071. (int)(png_ptr->row_buf[0]));
  165072. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  165073. png_ptr->rowbytes + 1);
  165074. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  165075. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  165076. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  165077. {
  165078. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  165079. }
  165080. #endif
  165081. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  165082. png_do_read_transformations(png_ptr);
  165083. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165084. if (png_ptr->interlaced &&
  165085. (png_ptr->transformations & PNG_INTERLACE))
  165086. {
  165087. if (png_ptr->pass < 6)
  165088. png_do_read_interlace(png_ptr);
  165089. if (dsp_row != NULL)
  165090. png_combine_row(png_ptr, dsp_row,
  165091. png_pass_dsp_mask[png_ptr->pass]);
  165092. if (row != NULL)
  165093. png_combine_row(png_ptr, row,
  165094. png_pass_mask[png_ptr->pass]);
  165095. }
  165096. else
  165097. #endif
  165098. {
  165099. if (row != NULL)
  165100. png_combine_row(png_ptr, row, 0xff);
  165101. if (dsp_row != NULL)
  165102. png_combine_row(png_ptr, dsp_row, 0xff);
  165103. }
  165104. png_read_finish_row(png_ptr);
  165105. if (png_ptr->read_row_fn != NULL)
  165106. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  165107. }
  165108. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165109. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165110. void PNGAPI
  165111. png_read_rows(png_structp png_ptr, png_bytepp row,
  165112. png_bytepp display_row, png_uint_32 num_rows)
  165113. {
  165114. png_uint_32 i;
  165115. png_bytepp rp;
  165116. png_bytepp dp;
  165117. png_debug(1, "in png_read_rows\n");
  165118. if(png_ptr == NULL) return;
  165119. rp = row;
  165120. dp = display_row;
  165121. if (rp != NULL && dp != NULL)
  165122. for (i = 0; i < num_rows; i++)
  165123. {
  165124. png_bytep rptr = *rp++;
  165125. png_bytep dptr = *dp++;
  165126. png_read_row(png_ptr, rptr, dptr);
  165127. }
  165128. else if(rp != NULL)
  165129. for (i = 0; i < num_rows; i++)
  165130. {
  165131. png_bytep rptr = *rp;
  165132. png_read_row(png_ptr, rptr, png_bytep_NULL);
  165133. rp++;
  165134. }
  165135. else if(dp != NULL)
  165136. for (i = 0; i < num_rows; i++)
  165137. {
  165138. png_bytep dptr = *dp;
  165139. png_read_row(png_ptr, png_bytep_NULL, dptr);
  165140. dp++;
  165141. }
  165142. }
  165143. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165144. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165145. void PNGAPI
  165146. png_read_image(png_structp png_ptr, png_bytepp image)
  165147. {
  165148. png_uint_32 i,image_height;
  165149. int pass, j;
  165150. png_bytepp rp;
  165151. png_debug(1, "in png_read_image\n");
  165152. if(png_ptr == NULL) return;
  165153. #ifdef PNG_READ_INTERLACING_SUPPORTED
  165154. pass = png_set_interlace_handling(png_ptr);
  165155. #else
  165156. if (png_ptr->interlaced)
  165157. png_error(png_ptr,
  165158. "Cannot read interlaced image -- interlace handler disabled.");
  165159. pass = 1;
  165160. #endif
  165161. image_height=png_ptr->height;
  165162. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  165163. for (j = 0; j < pass; j++)
  165164. {
  165165. rp = image;
  165166. for (i = 0; i < image_height; i++)
  165167. {
  165168. png_read_row(png_ptr, *rp, png_bytep_NULL);
  165169. rp++;
  165170. }
  165171. }
  165172. }
  165173. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165174. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165175. void PNGAPI
  165176. png_read_end(png_structp png_ptr, png_infop info_ptr)
  165177. {
  165178. png_byte chunk_length[4];
  165179. png_uint_32 length;
  165180. png_debug(1, "in png_read_end\n");
  165181. if(png_ptr == NULL) return;
  165182. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  165183. do
  165184. {
  165185. #ifdef PNG_USE_LOCAL_ARRAYS
  165186. PNG_CONST PNG_IHDR;
  165187. PNG_CONST PNG_IDAT;
  165188. PNG_CONST PNG_IEND;
  165189. PNG_CONST PNG_PLTE;
  165190. #if defined(PNG_READ_bKGD_SUPPORTED)
  165191. PNG_CONST PNG_bKGD;
  165192. #endif
  165193. #if defined(PNG_READ_cHRM_SUPPORTED)
  165194. PNG_CONST PNG_cHRM;
  165195. #endif
  165196. #if defined(PNG_READ_gAMA_SUPPORTED)
  165197. PNG_CONST PNG_gAMA;
  165198. #endif
  165199. #if defined(PNG_READ_hIST_SUPPORTED)
  165200. PNG_CONST PNG_hIST;
  165201. #endif
  165202. #if defined(PNG_READ_iCCP_SUPPORTED)
  165203. PNG_CONST PNG_iCCP;
  165204. #endif
  165205. #if defined(PNG_READ_iTXt_SUPPORTED)
  165206. PNG_CONST PNG_iTXt;
  165207. #endif
  165208. #if defined(PNG_READ_oFFs_SUPPORTED)
  165209. PNG_CONST PNG_oFFs;
  165210. #endif
  165211. #if defined(PNG_READ_pCAL_SUPPORTED)
  165212. PNG_CONST PNG_pCAL;
  165213. #endif
  165214. #if defined(PNG_READ_pHYs_SUPPORTED)
  165215. PNG_CONST PNG_pHYs;
  165216. #endif
  165217. #if defined(PNG_READ_sBIT_SUPPORTED)
  165218. PNG_CONST PNG_sBIT;
  165219. #endif
  165220. #if defined(PNG_READ_sCAL_SUPPORTED)
  165221. PNG_CONST PNG_sCAL;
  165222. #endif
  165223. #if defined(PNG_READ_sPLT_SUPPORTED)
  165224. PNG_CONST PNG_sPLT;
  165225. #endif
  165226. #if defined(PNG_READ_sRGB_SUPPORTED)
  165227. PNG_CONST PNG_sRGB;
  165228. #endif
  165229. #if defined(PNG_READ_tEXt_SUPPORTED)
  165230. PNG_CONST PNG_tEXt;
  165231. #endif
  165232. #if defined(PNG_READ_tIME_SUPPORTED)
  165233. PNG_CONST PNG_tIME;
  165234. #endif
  165235. #if defined(PNG_READ_tRNS_SUPPORTED)
  165236. PNG_CONST PNG_tRNS;
  165237. #endif
  165238. #if defined(PNG_READ_zTXt_SUPPORTED)
  165239. PNG_CONST PNG_zTXt;
  165240. #endif
  165241. #endif /* PNG_USE_LOCAL_ARRAYS */
  165242. png_read_data(png_ptr, chunk_length, 4);
  165243. length = png_get_uint_31(png_ptr,chunk_length);
  165244. png_reset_crc(png_ptr);
  165245. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165246. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  165247. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165248. png_handle_IHDR(png_ptr, info_ptr, length);
  165249. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165250. png_handle_IEND(png_ptr, info_ptr, length);
  165251. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165252. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165253. {
  165254. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165255. {
  165256. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165257. png_error(png_ptr, "Too many IDAT's found");
  165258. }
  165259. png_handle_unknown(png_ptr, info_ptr, length);
  165260. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165261. png_ptr->mode |= PNG_HAVE_PLTE;
  165262. }
  165263. #endif
  165264. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165265. {
  165266. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165267. png_error(png_ptr, "Too many IDAT's found");
  165268. png_crc_finish(png_ptr, length);
  165269. }
  165270. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165271. png_handle_PLTE(png_ptr, info_ptr, length);
  165272. #if defined(PNG_READ_bKGD_SUPPORTED)
  165273. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165274. png_handle_bKGD(png_ptr, info_ptr, length);
  165275. #endif
  165276. #if defined(PNG_READ_cHRM_SUPPORTED)
  165277. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165278. png_handle_cHRM(png_ptr, info_ptr, length);
  165279. #endif
  165280. #if defined(PNG_READ_gAMA_SUPPORTED)
  165281. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165282. png_handle_gAMA(png_ptr, info_ptr, length);
  165283. #endif
  165284. #if defined(PNG_READ_hIST_SUPPORTED)
  165285. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165286. png_handle_hIST(png_ptr, info_ptr, length);
  165287. #endif
  165288. #if defined(PNG_READ_oFFs_SUPPORTED)
  165289. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165290. png_handle_oFFs(png_ptr, info_ptr, length);
  165291. #endif
  165292. #if defined(PNG_READ_pCAL_SUPPORTED)
  165293. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165294. png_handle_pCAL(png_ptr, info_ptr, length);
  165295. #endif
  165296. #if defined(PNG_READ_sCAL_SUPPORTED)
  165297. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165298. png_handle_sCAL(png_ptr, info_ptr, length);
  165299. #endif
  165300. #if defined(PNG_READ_pHYs_SUPPORTED)
  165301. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165302. png_handle_pHYs(png_ptr, info_ptr, length);
  165303. #endif
  165304. #if defined(PNG_READ_sBIT_SUPPORTED)
  165305. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165306. png_handle_sBIT(png_ptr, info_ptr, length);
  165307. #endif
  165308. #if defined(PNG_READ_sRGB_SUPPORTED)
  165309. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165310. png_handle_sRGB(png_ptr, info_ptr, length);
  165311. #endif
  165312. #if defined(PNG_READ_iCCP_SUPPORTED)
  165313. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165314. png_handle_iCCP(png_ptr, info_ptr, length);
  165315. #endif
  165316. #if defined(PNG_READ_sPLT_SUPPORTED)
  165317. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165318. png_handle_sPLT(png_ptr, info_ptr, length);
  165319. #endif
  165320. #if defined(PNG_READ_tEXt_SUPPORTED)
  165321. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165322. png_handle_tEXt(png_ptr, info_ptr, length);
  165323. #endif
  165324. #if defined(PNG_READ_tIME_SUPPORTED)
  165325. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165326. png_handle_tIME(png_ptr, info_ptr, length);
  165327. #endif
  165328. #if defined(PNG_READ_tRNS_SUPPORTED)
  165329. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165330. png_handle_tRNS(png_ptr, info_ptr, length);
  165331. #endif
  165332. #if defined(PNG_READ_zTXt_SUPPORTED)
  165333. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165334. png_handle_zTXt(png_ptr, info_ptr, length);
  165335. #endif
  165336. #if defined(PNG_READ_iTXt_SUPPORTED)
  165337. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165338. png_handle_iTXt(png_ptr, info_ptr, length);
  165339. #endif
  165340. else
  165341. png_handle_unknown(png_ptr, info_ptr, length);
  165342. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165343. }
  165344. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165345. void PNGAPI
  165346. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165347. png_infopp end_info_ptr_ptr)
  165348. {
  165349. png_structp png_ptr = NULL;
  165350. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165351. #ifdef PNG_USER_MEM_SUPPORTED
  165352. png_free_ptr free_fn;
  165353. png_voidp mem_ptr;
  165354. #endif
  165355. png_debug(1, "in png_destroy_read_struct\n");
  165356. if (png_ptr_ptr != NULL)
  165357. png_ptr = *png_ptr_ptr;
  165358. if (info_ptr_ptr != NULL)
  165359. info_ptr = *info_ptr_ptr;
  165360. if (end_info_ptr_ptr != NULL)
  165361. end_info_ptr = *end_info_ptr_ptr;
  165362. #ifdef PNG_USER_MEM_SUPPORTED
  165363. free_fn = png_ptr->free_fn;
  165364. mem_ptr = png_ptr->mem_ptr;
  165365. #endif
  165366. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165367. if (info_ptr != NULL)
  165368. {
  165369. #if defined(PNG_TEXT_SUPPORTED)
  165370. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165371. #endif
  165372. #ifdef PNG_USER_MEM_SUPPORTED
  165373. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165374. (png_voidp)mem_ptr);
  165375. #else
  165376. png_destroy_struct((png_voidp)info_ptr);
  165377. #endif
  165378. *info_ptr_ptr = NULL;
  165379. }
  165380. if (end_info_ptr != NULL)
  165381. {
  165382. #if defined(PNG_READ_TEXT_SUPPORTED)
  165383. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165384. #endif
  165385. #ifdef PNG_USER_MEM_SUPPORTED
  165386. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165387. (png_voidp)mem_ptr);
  165388. #else
  165389. png_destroy_struct((png_voidp)end_info_ptr);
  165390. #endif
  165391. *end_info_ptr_ptr = NULL;
  165392. }
  165393. if (png_ptr != NULL)
  165394. {
  165395. #ifdef PNG_USER_MEM_SUPPORTED
  165396. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165397. (png_voidp)mem_ptr);
  165398. #else
  165399. png_destroy_struct((png_voidp)png_ptr);
  165400. #endif
  165401. *png_ptr_ptr = NULL;
  165402. }
  165403. }
  165404. void /* PRIVATE */
  165405. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165406. {
  165407. #ifdef PNG_SETJMP_SUPPORTED
  165408. jmp_buf tmp_jmp;
  165409. #endif
  165410. png_error_ptr error_fn;
  165411. png_error_ptr warning_fn;
  165412. png_voidp error_ptr;
  165413. #ifdef PNG_USER_MEM_SUPPORTED
  165414. png_free_ptr free_fn;
  165415. #endif
  165416. png_debug(1, "in png_read_destroy\n");
  165417. if (info_ptr != NULL)
  165418. png_info_destroy(png_ptr, info_ptr);
  165419. if (end_info_ptr != NULL)
  165420. png_info_destroy(png_ptr, end_info_ptr);
  165421. png_free(png_ptr, png_ptr->zbuf);
  165422. png_free(png_ptr, png_ptr->big_row_buf);
  165423. png_free(png_ptr, png_ptr->prev_row);
  165424. #if defined(PNG_READ_DITHER_SUPPORTED)
  165425. png_free(png_ptr, png_ptr->palette_lookup);
  165426. png_free(png_ptr, png_ptr->dither_index);
  165427. #endif
  165428. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165429. png_free(png_ptr, png_ptr->gamma_table);
  165430. #endif
  165431. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165432. png_free(png_ptr, png_ptr->gamma_from_1);
  165433. png_free(png_ptr, png_ptr->gamma_to_1);
  165434. #endif
  165435. #ifdef PNG_FREE_ME_SUPPORTED
  165436. if (png_ptr->free_me & PNG_FREE_PLTE)
  165437. png_zfree(png_ptr, png_ptr->palette);
  165438. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165439. #else
  165440. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165441. png_zfree(png_ptr, png_ptr->palette);
  165442. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165443. #endif
  165444. #if defined(PNG_tRNS_SUPPORTED) || \
  165445. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165446. #ifdef PNG_FREE_ME_SUPPORTED
  165447. if (png_ptr->free_me & PNG_FREE_TRNS)
  165448. png_free(png_ptr, png_ptr->trans);
  165449. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165450. #else
  165451. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165452. png_free(png_ptr, png_ptr->trans);
  165453. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165454. #endif
  165455. #endif
  165456. #if defined(PNG_READ_hIST_SUPPORTED)
  165457. #ifdef PNG_FREE_ME_SUPPORTED
  165458. if (png_ptr->free_me & PNG_FREE_HIST)
  165459. png_free(png_ptr, png_ptr->hist);
  165460. png_ptr->free_me &= ~PNG_FREE_HIST;
  165461. #else
  165462. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165463. png_free(png_ptr, png_ptr->hist);
  165464. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165465. #endif
  165466. #endif
  165467. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165468. if (png_ptr->gamma_16_table != NULL)
  165469. {
  165470. int i;
  165471. int istop = (1 << (8 - png_ptr->gamma_shift));
  165472. for (i = 0; i < istop; i++)
  165473. {
  165474. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165475. }
  165476. png_free(png_ptr, png_ptr->gamma_16_table);
  165477. }
  165478. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165479. if (png_ptr->gamma_16_from_1 != NULL)
  165480. {
  165481. int i;
  165482. int istop = (1 << (8 - png_ptr->gamma_shift));
  165483. for (i = 0; i < istop; i++)
  165484. {
  165485. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165486. }
  165487. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165488. }
  165489. if (png_ptr->gamma_16_to_1 != NULL)
  165490. {
  165491. int i;
  165492. int istop = (1 << (8 - png_ptr->gamma_shift));
  165493. for (i = 0; i < istop; i++)
  165494. {
  165495. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165496. }
  165497. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165498. }
  165499. #endif
  165500. #endif
  165501. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165502. png_free(png_ptr, png_ptr->time_buffer);
  165503. #endif
  165504. inflateEnd(&png_ptr->zstream);
  165505. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165506. png_free(png_ptr, png_ptr->save_buffer);
  165507. #endif
  165508. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165509. #ifdef PNG_TEXT_SUPPORTED
  165510. png_free(png_ptr, png_ptr->current_text);
  165511. #endif /* PNG_TEXT_SUPPORTED */
  165512. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165513. #ifdef PNG_SETJMP_SUPPORTED
  165514. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165515. #endif
  165516. error_fn = png_ptr->error_fn;
  165517. warning_fn = png_ptr->warning_fn;
  165518. error_ptr = png_ptr->error_ptr;
  165519. #ifdef PNG_USER_MEM_SUPPORTED
  165520. free_fn = png_ptr->free_fn;
  165521. #endif
  165522. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165523. png_ptr->error_fn = error_fn;
  165524. png_ptr->warning_fn = warning_fn;
  165525. png_ptr->error_ptr = error_ptr;
  165526. #ifdef PNG_USER_MEM_SUPPORTED
  165527. png_ptr->free_fn = free_fn;
  165528. #endif
  165529. #ifdef PNG_SETJMP_SUPPORTED
  165530. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165531. #endif
  165532. }
  165533. void PNGAPI
  165534. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165535. {
  165536. if(png_ptr == NULL) return;
  165537. png_ptr->read_row_fn = read_row_fn;
  165538. }
  165539. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165540. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165541. void PNGAPI
  165542. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165543. int transforms,
  165544. voidp params)
  165545. {
  165546. int row;
  165547. if(png_ptr == NULL) return;
  165548. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165549. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165550. png_set_invert_alpha(png_ptr);
  165551. #endif
  165552. png_read_info(png_ptr, info_ptr);
  165553. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165554. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165555. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165556. if (transforms & PNG_TRANSFORM_STRIP_16)
  165557. png_set_strip_16(png_ptr);
  165558. #endif
  165559. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165560. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165561. png_set_strip_alpha(png_ptr);
  165562. #endif
  165563. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165564. if (transforms & PNG_TRANSFORM_PACKING)
  165565. png_set_packing(png_ptr);
  165566. #endif
  165567. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165568. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165569. png_set_packswap(png_ptr);
  165570. #endif
  165571. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165572. if (transforms & PNG_TRANSFORM_EXPAND)
  165573. if ((png_ptr->bit_depth < 8) ||
  165574. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165575. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165576. png_set_expand(png_ptr);
  165577. #endif
  165578. #if defined(PNG_READ_INVERT_SUPPORTED)
  165579. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165580. png_set_invert_mono(png_ptr);
  165581. #endif
  165582. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165583. if ((transforms & PNG_TRANSFORM_SHIFT)
  165584. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165585. {
  165586. png_color_8p sig_bit;
  165587. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165588. png_set_shift(png_ptr, sig_bit);
  165589. }
  165590. #endif
  165591. #if defined(PNG_READ_BGR_SUPPORTED)
  165592. if (transforms & PNG_TRANSFORM_BGR)
  165593. png_set_bgr(png_ptr);
  165594. #endif
  165595. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165596. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165597. png_set_swap_alpha(png_ptr);
  165598. #endif
  165599. #if defined(PNG_READ_SWAP_SUPPORTED)
  165600. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165601. png_set_swap(png_ptr);
  165602. #endif
  165603. png_read_update_info(png_ptr, info_ptr);
  165604. #ifdef PNG_FREE_ME_SUPPORTED
  165605. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165606. #endif
  165607. if(info_ptr->row_pointers == NULL)
  165608. {
  165609. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165610. info_ptr->height * png_sizeof(png_bytep));
  165611. #ifdef PNG_FREE_ME_SUPPORTED
  165612. info_ptr->free_me |= PNG_FREE_ROWS;
  165613. #endif
  165614. for (row = 0; row < (int)info_ptr->height; row++)
  165615. {
  165616. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165617. png_get_rowbytes(png_ptr, info_ptr));
  165618. }
  165619. }
  165620. png_read_image(png_ptr, info_ptr->row_pointers);
  165621. info_ptr->valid |= PNG_INFO_IDAT;
  165622. png_read_end(png_ptr, info_ptr);
  165623. transforms = transforms; /* quiet compiler warnings */
  165624. params = params;
  165625. }
  165626. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165627. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165628. #endif /* PNG_READ_SUPPORTED */
  165629. /*** End of inlined file: pngread.c ***/
  165630. /*** Start of inlined file: pngpread.c ***/
  165631. #define PNG_INTERNAL
  165632. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165633. #define PNG_READ_SIG_MODE 0
  165634. #define PNG_READ_CHUNK_MODE 1
  165635. #define PNG_READ_IDAT_MODE 2
  165636. #define PNG_SKIP_MODE 3
  165637. #define PNG_READ_tEXt_MODE 4
  165638. #define PNG_READ_zTXt_MODE 5
  165639. #define PNG_READ_DONE_MODE 6
  165640. #define PNG_READ_iTXt_MODE 7
  165641. #define PNG_ERROR_MODE 8
  165642. void PNGAPI
  165643. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165644. png_bytep buffer, png_size_t buffer_size)
  165645. {
  165646. if(png_ptr == NULL) return;
  165647. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165648. while (png_ptr->buffer_size)
  165649. {
  165650. png_process_some_data(png_ptr, info_ptr);
  165651. }
  165652. }
  165653. void /* PRIVATE */
  165654. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165655. {
  165656. if(png_ptr == NULL) return;
  165657. switch (png_ptr->process_mode)
  165658. {
  165659. case PNG_READ_SIG_MODE:
  165660. {
  165661. png_push_read_sig(png_ptr, info_ptr);
  165662. break;
  165663. }
  165664. case PNG_READ_CHUNK_MODE:
  165665. {
  165666. png_push_read_chunk(png_ptr, info_ptr);
  165667. break;
  165668. }
  165669. case PNG_READ_IDAT_MODE:
  165670. {
  165671. png_push_read_IDAT(png_ptr);
  165672. break;
  165673. }
  165674. #if defined(PNG_READ_tEXt_SUPPORTED)
  165675. case PNG_READ_tEXt_MODE:
  165676. {
  165677. png_push_read_tEXt(png_ptr, info_ptr);
  165678. break;
  165679. }
  165680. #endif
  165681. #if defined(PNG_READ_zTXt_SUPPORTED)
  165682. case PNG_READ_zTXt_MODE:
  165683. {
  165684. png_push_read_zTXt(png_ptr, info_ptr);
  165685. break;
  165686. }
  165687. #endif
  165688. #if defined(PNG_READ_iTXt_SUPPORTED)
  165689. case PNG_READ_iTXt_MODE:
  165690. {
  165691. png_push_read_iTXt(png_ptr, info_ptr);
  165692. break;
  165693. }
  165694. #endif
  165695. case PNG_SKIP_MODE:
  165696. {
  165697. png_push_crc_finish(png_ptr);
  165698. break;
  165699. }
  165700. default:
  165701. {
  165702. png_ptr->buffer_size = 0;
  165703. break;
  165704. }
  165705. }
  165706. }
  165707. void /* PRIVATE */
  165708. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  165709. {
  165710. png_size_t num_checked = png_ptr->sig_bytes,
  165711. num_to_check = 8 - num_checked;
  165712. if (png_ptr->buffer_size < num_to_check)
  165713. {
  165714. num_to_check = png_ptr->buffer_size;
  165715. }
  165716. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  165717. num_to_check);
  165718. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  165719. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165720. {
  165721. if (num_checked < 4 &&
  165722. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165723. png_error(png_ptr, "Not a PNG file");
  165724. else
  165725. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165726. }
  165727. else
  165728. {
  165729. if (png_ptr->sig_bytes >= 8)
  165730. {
  165731. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165732. }
  165733. }
  165734. }
  165735. void /* PRIVATE */
  165736. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  165737. {
  165738. #ifdef PNG_USE_LOCAL_ARRAYS
  165739. PNG_CONST PNG_IHDR;
  165740. PNG_CONST PNG_IDAT;
  165741. PNG_CONST PNG_IEND;
  165742. PNG_CONST PNG_PLTE;
  165743. #if defined(PNG_READ_bKGD_SUPPORTED)
  165744. PNG_CONST PNG_bKGD;
  165745. #endif
  165746. #if defined(PNG_READ_cHRM_SUPPORTED)
  165747. PNG_CONST PNG_cHRM;
  165748. #endif
  165749. #if defined(PNG_READ_gAMA_SUPPORTED)
  165750. PNG_CONST PNG_gAMA;
  165751. #endif
  165752. #if defined(PNG_READ_hIST_SUPPORTED)
  165753. PNG_CONST PNG_hIST;
  165754. #endif
  165755. #if defined(PNG_READ_iCCP_SUPPORTED)
  165756. PNG_CONST PNG_iCCP;
  165757. #endif
  165758. #if defined(PNG_READ_iTXt_SUPPORTED)
  165759. PNG_CONST PNG_iTXt;
  165760. #endif
  165761. #if defined(PNG_READ_oFFs_SUPPORTED)
  165762. PNG_CONST PNG_oFFs;
  165763. #endif
  165764. #if defined(PNG_READ_pCAL_SUPPORTED)
  165765. PNG_CONST PNG_pCAL;
  165766. #endif
  165767. #if defined(PNG_READ_pHYs_SUPPORTED)
  165768. PNG_CONST PNG_pHYs;
  165769. #endif
  165770. #if defined(PNG_READ_sBIT_SUPPORTED)
  165771. PNG_CONST PNG_sBIT;
  165772. #endif
  165773. #if defined(PNG_READ_sCAL_SUPPORTED)
  165774. PNG_CONST PNG_sCAL;
  165775. #endif
  165776. #if defined(PNG_READ_sRGB_SUPPORTED)
  165777. PNG_CONST PNG_sRGB;
  165778. #endif
  165779. #if defined(PNG_READ_sPLT_SUPPORTED)
  165780. PNG_CONST PNG_sPLT;
  165781. #endif
  165782. #if defined(PNG_READ_tEXt_SUPPORTED)
  165783. PNG_CONST PNG_tEXt;
  165784. #endif
  165785. #if defined(PNG_READ_tIME_SUPPORTED)
  165786. PNG_CONST PNG_tIME;
  165787. #endif
  165788. #if defined(PNG_READ_tRNS_SUPPORTED)
  165789. PNG_CONST PNG_tRNS;
  165790. #endif
  165791. #if defined(PNG_READ_zTXt_SUPPORTED)
  165792. PNG_CONST PNG_zTXt;
  165793. #endif
  165794. #endif /* PNG_USE_LOCAL_ARRAYS */
  165795. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  165796. {
  165797. png_byte chunk_length[4];
  165798. if (png_ptr->buffer_size < 8)
  165799. {
  165800. png_push_save_buffer(png_ptr);
  165801. return;
  165802. }
  165803. png_push_fill_buffer(png_ptr, chunk_length, 4);
  165804. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  165805. png_reset_crc(png_ptr);
  165806. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165807. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  165808. }
  165809. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165810. if(png_ptr->mode & PNG_AFTER_IDAT)
  165811. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165812. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165813. {
  165814. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165815. {
  165816. png_push_save_buffer(png_ptr);
  165817. return;
  165818. }
  165819. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  165820. }
  165821. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165822. {
  165823. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165824. {
  165825. png_push_save_buffer(png_ptr);
  165826. return;
  165827. }
  165828. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  165829. png_ptr->process_mode = PNG_READ_DONE_MODE;
  165830. png_push_have_end(png_ptr, info_ptr);
  165831. }
  165832. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165833. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165834. {
  165835. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165836. {
  165837. png_push_save_buffer(png_ptr);
  165838. return;
  165839. }
  165840. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165841. png_ptr->mode |= PNG_HAVE_IDAT;
  165842. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165843. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165844. png_ptr->mode |= PNG_HAVE_PLTE;
  165845. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165846. {
  165847. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165848. png_error(png_ptr, "Missing IHDR before IDAT");
  165849. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165850. !(png_ptr->mode & PNG_HAVE_PLTE))
  165851. png_error(png_ptr, "Missing PLTE before IDAT");
  165852. }
  165853. }
  165854. #endif
  165855. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165856. {
  165857. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165858. {
  165859. png_push_save_buffer(png_ptr);
  165860. return;
  165861. }
  165862. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  165863. }
  165864. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165865. {
  165866. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165867. png_error(png_ptr, "Missing IHDR before IDAT");
  165868. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165869. !(png_ptr->mode & PNG_HAVE_PLTE))
  165870. png_error(png_ptr, "Missing PLTE before IDAT");
  165871. if (png_ptr->mode & PNG_HAVE_IDAT)
  165872. {
  165873. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165874. if (png_ptr->push_length == 0)
  165875. return;
  165876. if (png_ptr->mode & PNG_AFTER_IDAT)
  165877. png_error(png_ptr, "Too many IDAT's found");
  165878. }
  165879. png_ptr->idat_size = png_ptr->push_length;
  165880. png_ptr->mode |= PNG_HAVE_IDAT;
  165881. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  165882. png_push_have_info(png_ptr, info_ptr);
  165883. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165884. png_ptr->zstream.next_out = png_ptr->row_buf;
  165885. return;
  165886. }
  165887. #if defined(PNG_READ_gAMA_SUPPORTED)
  165888. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165889. {
  165890. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165891. {
  165892. png_push_save_buffer(png_ptr);
  165893. return;
  165894. }
  165895. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  165896. }
  165897. #endif
  165898. #if defined(PNG_READ_sBIT_SUPPORTED)
  165899. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165900. {
  165901. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165902. {
  165903. png_push_save_buffer(png_ptr);
  165904. return;
  165905. }
  165906. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  165907. }
  165908. #endif
  165909. #if defined(PNG_READ_cHRM_SUPPORTED)
  165910. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165911. {
  165912. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165913. {
  165914. png_push_save_buffer(png_ptr);
  165915. return;
  165916. }
  165917. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  165918. }
  165919. #endif
  165920. #if defined(PNG_READ_sRGB_SUPPORTED)
  165921. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165922. {
  165923. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165924. {
  165925. png_push_save_buffer(png_ptr);
  165926. return;
  165927. }
  165928. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  165929. }
  165930. #endif
  165931. #if defined(PNG_READ_iCCP_SUPPORTED)
  165932. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165933. {
  165934. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165935. {
  165936. png_push_save_buffer(png_ptr);
  165937. return;
  165938. }
  165939. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  165940. }
  165941. #endif
  165942. #if defined(PNG_READ_sPLT_SUPPORTED)
  165943. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165944. {
  165945. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165946. {
  165947. png_push_save_buffer(png_ptr);
  165948. return;
  165949. }
  165950. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  165951. }
  165952. #endif
  165953. #if defined(PNG_READ_tRNS_SUPPORTED)
  165954. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165955. {
  165956. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165957. {
  165958. png_push_save_buffer(png_ptr);
  165959. return;
  165960. }
  165961. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  165962. }
  165963. #endif
  165964. #if defined(PNG_READ_bKGD_SUPPORTED)
  165965. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165966. {
  165967. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165968. {
  165969. png_push_save_buffer(png_ptr);
  165970. return;
  165971. }
  165972. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  165973. }
  165974. #endif
  165975. #if defined(PNG_READ_hIST_SUPPORTED)
  165976. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165977. {
  165978. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165979. {
  165980. png_push_save_buffer(png_ptr);
  165981. return;
  165982. }
  165983. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  165984. }
  165985. #endif
  165986. #if defined(PNG_READ_pHYs_SUPPORTED)
  165987. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165988. {
  165989. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165990. {
  165991. png_push_save_buffer(png_ptr);
  165992. return;
  165993. }
  165994. png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  165995. }
  165996. #endif
  165997. #if defined(PNG_READ_oFFs_SUPPORTED)
  165998. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165999. {
  166000. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166001. {
  166002. png_push_save_buffer(png_ptr);
  166003. return;
  166004. }
  166005. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  166006. }
  166007. #endif
  166008. #if defined(PNG_READ_pCAL_SUPPORTED)
  166009. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  166010. {
  166011. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166012. {
  166013. png_push_save_buffer(png_ptr);
  166014. return;
  166015. }
  166016. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  166017. }
  166018. #endif
  166019. #if defined(PNG_READ_sCAL_SUPPORTED)
  166020. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  166021. {
  166022. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166023. {
  166024. png_push_save_buffer(png_ptr);
  166025. return;
  166026. }
  166027. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  166028. }
  166029. #endif
  166030. #if defined(PNG_READ_tIME_SUPPORTED)
  166031. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  166032. {
  166033. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166034. {
  166035. png_push_save_buffer(png_ptr);
  166036. return;
  166037. }
  166038. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  166039. }
  166040. #endif
  166041. #if defined(PNG_READ_tEXt_SUPPORTED)
  166042. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  166043. {
  166044. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166045. {
  166046. png_push_save_buffer(png_ptr);
  166047. return;
  166048. }
  166049. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  166050. }
  166051. #endif
  166052. #if defined(PNG_READ_zTXt_SUPPORTED)
  166053. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  166054. {
  166055. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166056. {
  166057. png_push_save_buffer(png_ptr);
  166058. return;
  166059. }
  166060. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  166061. }
  166062. #endif
  166063. #if defined(PNG_READ_iTXt_SUPPORTED)
  166064. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  166065. {
  166066. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166067. {
  166068. png_push_save_buffer(png_ptr);
  166069. return;
  166070. }
  166071. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  166072. }
  166073. #endif
  166074. else
  166075. {
  166076. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166077. {
  166078. png_push_save_buffer(png_ptr);
  166079. return;
  166080. }
  166081. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166082. }
  166083. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166084. }
  166085. void /* PRIVATE */
  166086. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  166087. {
  166088. png_ptr->process_mode = PNG_SKIP_MODE;
  166089. png_ptr->skip_length = skip;
  166090. }
  166091. void /* PRIVATE */
  166092. png_push_crc_finish(png_structp png_ptr)
  166093. {
  166094. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  166095. {
  166096. png_size_t save_size;
  166097. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  166098. save_size = (png_size_t)png_ptr->skip_length;
  166099. else
  166100. save_size = png_ptr->save_buffer_size;
  166101. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166102. png_ptr->skip_length -= save_size;
  166103. png_ptr->buffer_size -= save_size;
  166104. png_ptr->save_buffer_size -= save_size;
  166105. png_ptr->save_buffer_ptr += save_size;
  166106. }
  166107. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  166108. {
  166109. png_size_t save_size;
  166110. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  166111. save_size = (png_size_t)png_ptr->skip_length;
  166112. else
  166113. save_size = png_ptr->current_buffer_size;
  166114. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166115. png_ptr->skip_length -= save_size;
  166116. png_ptr->buffer_size -= save_size;
  166117. png_ptr->current_buffer_size -= save_size;
  166118. png_ptr->current_buffer_ptr += save_size;
  166119. }
  166120. if (!png_ptr->skip_length)
  166121. {
  166122. if (png_ptr->buffer_size < 4)
  166123. {
  166124. png_push_save_buffer(png_ptr);
  166125. return;
  166126. }
  166127. png_crc_finish(png_ptr, 0);
  166128. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166129. }
  166130. }
  166131. void PNGAPI
  166132. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  166133. {
  166134. png_bytep ptr;
  166135. if(png_ptr == NULL) return;
  166136. ptr = buffer;
  166137. if (png_ptr->save_buffer_size)
  166138. {
  166139. png_size_t save_size;
  166140. if (length < png_ptr->save_buffer_size)
  166141. save_size = length;
  166142. else
  166143. save_size = png_ptr->save_buffer_size;
  166144. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  166145. length -= save_size;
  166146. ptr += save_size;
  166147. png_ptr->buffer_size -= save_size;
  166148. png_ptr->save_buffer_size -= save_size;
  166149. png_ptr->save_buffer_ptr += save_size;
  166150. }
  166151. if (length && png_ptr->current_buffer_size)
  166152. {
  166153. png_size_t save_size;
  166154. if (length < png_ptr->current_buffer_size)
  166155. save_size = length;
  166156. else
  166157. save_size = png_ptr->current_buffer_size;
  166158. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  166159. png_ptr->buffer_size -= save_size;
  166160. png_ptr->current_buffer_size -= save_size;
  166161. png_ptr->current_buffer_ptr += save_size;
  166162. }
  166163. }
  166164. void /* PRIVATE */
  166165. png_push_save_buffer(png_structp png_ptr)
  166166. {
  166167. if (png_ptr->save_buffer_size)
  166168. {
  166169. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  166170. {
  166171. png_size_t i,istop;
  166172. png_bytep sp;
  166173. png_bytep dp;
  166174. istop = png_ptr->save_buffer_size;
  166175. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  166176. i < istop; i++, sp++, dp++)
  166177. {
  166178. *dp = *sp;
  166179. }
  166180. }
  166181. }
  166182. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  166183. png_ptr->save_buffer_max)
  166184. {
  166185. png_size_t new_max;
  166186. png_bytep old_buffer;
  166187. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  166188. (png_ptr->current_buffer_size + 256))
  166189. {
  166190. png_error(png_ptr, "Potential overflow of save_buffer");
  166191. }
  166192. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  166193. old_buffer = png_ptr->save_buffer;
  166194. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  166195. (png_uint_32)new_max);
  166196. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  166197. png_free(png_ptr, old_buffer);
  166198. png_ptr->save_buffer_max = new_max;
  166199. }
  166200. if (png_ptr->current_buffer_size)
  166201. {
  166202. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  166203. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  166204. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  166205. png_ptr->current_buffer_size = 0;
  166206. }
  166207. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  166208. png_ptr->buffer_size = 0;
  166209. }
  166210. void /* PRIVATE */
  166211. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  166212. png_size_t buffer_length)
  166213. {
  166214. png_ptr->current_buffer = buffer;
  166215. png_ptr->current_buffer_size = buffer_length;
  166216. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  166217. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  166218. }
  166219. void /* PRIVATE */
  166220. png_push_read_IDAT(png_structp png_ptr)
  166221. {
  166222. #ifdef PNG_USE_LOCAL_ARRAYS
  166223. PNG_CONST PNG_IDAT;
  166224. #endif
  166225. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166226. {
  166227. png_byte chunk_length[4];
  166228. if (png_ptr->buffer_size < 8)
  166229. {
  166230. png_push_save_buffer(png_ptr);
  166231. return;
  166232. }
  166233. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166234. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166235. png_reset_crc(png_ptr);
  166236. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166237. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166238. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166239. {
  166240. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166241. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166242. png_error(png_ptr, "Not enough compressed data");
  166243. return;
  166244. }
  166245. png_ptr->idat_size = png_ptr->push_length;
  166246. }
  166247. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  166248. {
  166249. png_size_t save_size;
  166250. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  166251. {
  166252. save_size = (png_size_t)png_ptr->idat_size;
  166253. if((png_uint_32)save_size != png_ptr->idat_size)
  166254. png_error(png_ptr, "save_size overflowed in pngpread");
  166255. }
  166256. else
  166257. save_size = png_ptr->save_buffer_size;
  166258. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166259. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166260. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166261. png_ptr->idat_size -= save_size;
  166262. png_ptr->buffer_size -= save_size;
  166263. png_ptr->save_buffer_size -= save_size;
  166264. png_ptr->save_buffer_ptr += save_size;
  166265. }
  166266. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  166267. {
  166268. png_size_t save_size;
  166269. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  166270. {
  166271. save_size = (png_size_t)png_ptr->idat_size;
  166272. if((png_uint_32)save_size != png_ptr->idat_size)
  166273. png_error(png_ptr, "save_size overflowed in pngpread");
  166274. }
  166275. else
  166276. save_size = png_ptr->current_buffer_size;
  166277. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166278. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166279. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166280. png_ptr->idat_size -= save_size;
  166281. png_ptr->buffer_size -= save_size;
  166282. png_ptr->current_buffer_size -= save_size;
  166283. png_ptr->current_buffer_ptr += save_size;
  166284. }
  166285. if (!png_ptr->idat_size)
  166286. {
  166287. if (png_ptr->buffer_size < 4)
  166288. {
  166289. png_push_save_buffer(png_ptr);
  166290. return;
  166291. }
  166292. png_crc_finish(png_ptr, 0);
  166293. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166294. png_ptr->mode |= PNG_AFTER_IDAT;
  166295. }
  166296. }
  166297. void /* PRIVATE */
  166298. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166299. png_size_t buffer_length)
  166300. {
  166301. int ret;
  166302. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166303. png_error(png_ptr, "Extra compression data");
  166304. png_ptr->zstream.next_in = buffer;
  166305. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166306. for(;;)
  166307. {
  166308. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166309. if (ret != Z_OK)
  166310. {
  166311. if (ret == Z_STREAM_END)
  166312. {
  166313. if (png_ptr->zstream.avail_in)
  166314. png_error(png_ptr, "Extra compressed data");
  166315. if (!(png_ptr->zstream.avail_out))
  166316. {
  166317. png_push_process_row(png_ptr);
  166318. }
  166319. png_ptr->mode |= PNG_AFTER_IDAT;
  166320. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166321. break;
  166322. }
  166323. else if (ret == Z_BUF_ERROR)
  166324. break;
  166325. else
  166326. png_error(png_ptr, "Decompression Error");
  166327. }
  166328. if (!(png_ptr->zstream.avail_out))
  166329. {
  166330. if ((
  166331. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166332. png_ptr->interlaced && png_ptr->pass > 6) ||
  166333. (!png_ptr->interlaced &&
  166334. #endif
  166335. png_ptr->row_number == png_ptr->num_rows))
  166336. {
  166337. if (png_ptr->zstream.avail_in)
  166338. {
  166339. png_warning(png_ptr, "Too much data in IDAT chunks");
  166340. }
  166341. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166342. break;
  166343. }
  166344. png_push_process_row(png_ptr);
  166345. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166346. png_ptr->zstream.next_out = png_ptr->row_buf;
  166347. }
  166348. else
  166349. break;
  166350. }
  166351. }
  166352. void /* PRIVATE */
  166353. png_push_process_row(png_structp png_ptr)
  166354. {
  166355. png_ptr->row_info.color_type = png_ptr->color_type;
  166356. png_ptr->row_info.width = png_ptr->iwidth;
  166357. png_ptr->row_info.channels = png_ptr->channels;
  166358. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166359. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166360. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166361. png_ptr->row_info.width);
  166362. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166363. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166364. (int)(png_ptr->row_buf[0]));
  166365. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166366. png_ptr->rowbytes + 1);
  166367. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166368. png_do_read_transformations(png_ptr);
  166369. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166370. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166371. {
  166372. if (png_ptr->pass < 6)
  166373. png_do_read_interlace(png_ptr);
  166374. switch (png_ptr->pass)
  166375. {
  166376. case 0:
  166377. {
  166378. int i;
  166379. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166380. {
  166381. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166382. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166383. }
  166384. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166385. {
  166386. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166387. {
  166388. png_push_have_row(png_ptr, png_bytep_NULL);
  166389. png_read_push_finish_row(png_ptr);
  166390. }
  166391. }
  166392. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166393. {
  166394. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166395. {
  166396. png_push_have_row(png_ptr, png_bytep_NULL);
  166397. png_read_push_finish_row(png_ptr);
  166398. }
  166399. }
  166400. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166401. {
  166402. png_push_have_row(png_ptr, png_bytep_NULL);
  166403. png_read_push_finish_row(png_ptr);
  166404. }
  166405. break;
  166406. }
  166407. case 1:
  166408. {
  166409. int i;
  166410. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166411. {
  166412. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166413. png_read_push_finish_row(png_ptr);
  166414. }
  166415. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166416. {
  166417. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166418. {
  166419. png_push_have_row(png_ptr, png_bytep_NULL);
  166420. png_read_push_finish_row(png_ptr);
  166421. }
  166422. }
  166423. break;
  166424. }
  166425. case 2:
  166426. {
  166427. int i;
  166428. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166429. {
  166430. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166431. png_read_push_finish_row(png_ptr);
  166432. }
  166433. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166434. {
  166435. png_push_have_row(png_ptr, png_bytep_NULL);
  166436. png_read_push_finish_row(png_ptr);
  166437. }
  166438. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166439. {
  166440. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166441. {
  166442. png_push_have_row(png_ptr, png_bytep_NULL);
  166443. png_read_push_finish_row(png_ptr);
  166444. }
  166445. }
  166446. break;
  166447. }
  166448. case 3:
  166449. {
  166450. int i;
  166451. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166452. {
  166453. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166454. png_read_push_finish_row(png_ptr);
  166455. }
  166456. if (png_ptr->pass == 4) /* skip top two generated rows */
  166457. {
  166458. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166459. {
  166460. png_push_have_row(png_ptr, png_bytep_NULL);
  166461. png_read_push_finish_row(png_ptr);
  166462. }
  166463. }
  166464. break;
  166465. }
  166466. case 4:
  166467. {
  166468. int i;
  166469. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166470. {
  166471. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166472. png_read_push_finish_row(png_ptr);
  166473. }
  166474. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166475. {
  166476. png_push_have_row(png_ptr, png_bytep_NULL);
  166477. png_read_push_finish_row(png_ptr);
  166478. }
  166479. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166480. {
  166481. png_push_have_row(png_ptr, png_bytep_NULL);
  166482. png_read_push_finish_row(png_ptr);
  166483. }
  166484. break;
  166485. }
  166486. case 5:
  166487. {
  166488. int i;
  166489. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166490. {
  166491. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166492. png_read_push_finish_row(png_ptr);
  166493. }
  166494. if (png_ptr->pass == 6) /* skip top generated row */
  166495. {
  166496. png_push_have_row(png_ptr, png_bytep_NULL);
  166497. png_read_push_finish_row(png_ptr);
  166498. }
  166499. break;
  166500. }
  166501. case 6:
  166502. {
  166503. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166504. png_read_push_finish_row(png_ptr);
  166505. if (png_ptr->pass != 6)
  166506. break;
  166507. png_push_have_row(png_ptr, png_bytep_NULL);
  166508. png_read_push_finish_row(png_ptr);
  166509. }
  166510. }
  166511. }
  166512. else
  166513. #endif
  166514. {
  166515. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166516. png_read_push_finish_row(png_ptr);
  166517. }
  166518. }
  166519. void /* PRIVATE */
  166520. png_read_push_finish_row(png_structp png_ptr)
  166521. {
  166522. #ifdef PNG_USE_LOCAL_ARRAYS
  166523. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166524. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166525. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166526. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166527. #endif
  166528. png_ptr->row_number++;
  166529. if (png_ptr->row_number < png_ptr->num_rows)
  166530. return;
  166531. if (png_ptr->interlaced)
  166532. {
  166533. png_ptr->row_number = 0;
  166534. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166535. png_ptr->rowbytes + 1);
  166536. do
  166537. {
  166538. png_ptr->pass++;
  166539. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166540. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166541. (png_ptr->pass == 5 && png_ptr->width < 2))
  166542. png_ptr->pass++;
  166543. if (png_ptr->pass > 7)
  166544. png_ptr->pass--;
  166545. if (png_ptr->pass >= 7)
  166546. break;
  166547. png_ptr->iwidth = (png_ptr->width +
  166548. png_pass_inc[png_ptr->pass] - 1 -
  166549. png_pass_start[png_ptr->pass]) /
  166550. png_pass_inc[png_ptr->pass];
  166551. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166552. png_ptr->iwidth) + 1;
  166553. if (png_ptr->transformations & PNG_INTERLACE)
  166554. break;
  166555. png_ptr->num_rows = (png_ptr->height +
  166556. png_pass_yinc[png_ptr->pass] - 1 -
  166557. png_pass_ystart[png_ptr->pass]) /
  166558. png_pass_yinc[png_ptr->pass];
  166559. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166560. }
  166561. }
  166562. #if defined(PNG_READ_tEXt_SUPPORTED)
  166563. void /* PRIVATE */
  166564. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166565. length)
  166566. {
  166567. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166568. {
  166569. png_error(png_ptr, "Out of place tEXt");
  166570. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166571. }
  166572. #ifdef PNG_MAX_MALLOC_64K
  166573. png_ptr->skip_length = 0; /* This may not be necessary */
  166574. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166575. {
  166576. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166577. png_ptr->skip_length = length - (png_uint_32)65535L;
  166578. length = (png_uint_32)65535L;
  166579. }
  166580. #endif
  166581. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166582. (png_uint_32)(length+1));
  166583. png_ptr->current_text[length] = '\0';
  166584. png_ptr->current_text_ptr = png_ptr->current_text;
  166585. png_ptr->current_text_size = (png_size_t)length;
  166586. png_ptr->current_text_left = (png_size_t)length;
  166587. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166588. }
  166589. void /* PRIVATE */
  166590. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166591. {
  166592. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166593. {
  166594. png_size_t text_size;
  166595. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166596. text_size = png_ptr->buffer_size;
  166597. else
  166598. text_size = png_ptr->current_text_left;
  166599. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166600. png_ptr->current_text_left -= text_size;
  166601. png_ptr->current_text_ptr += text_size;
  166602. }
  166603. if (!(png_ptr->current_text_left))
  166604. {
  166605. png_textp text_ptr;
  166606. png_charp text;
  166607. png_charp key;
  166608. int ret;
  166609. if (png_ptr->buffer_size < 4)
  166610. {
  166611. png_push_save_buffer(png_ptr);
  166612. return;
  166613. }
  166614. png_push_crc_finish(png_ptr);
  166615. #if defined(PNG_MAX_MALLOC_64K)
  166616. if (png_ptr->skip_length)
  166617. return;
  166618. #endif
  166619. key = png_ptr->current_text;
  166620. for (text = key; *text; text++)
  166621. ;
  166622. if (text < key + png_ptr->current_text_size)
  166623. text++;
  166624. text_ptr = (png_textp)png_malloc(png_ptr,
  166625. (png_uint_32)png_sizeof(png_text));
  166626. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166627. text_ptr->key = key;
  166628. #ifdef PNG_iTXt_SUPPORTED
  166629. text_ptr->lang = NULL;
  166630. text_ptr->lang_key = NULL;
  166631. #endif
  166632. text_ptr->text = text;
  166633. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166634. png_free(png_ptr, key);
  166635. png_free(png_ptr, text_ptr);
  166636. png_ptr->current_text = NULL;
  166637. if (ret)
  166638. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166639. }
  166640. }
  166641. #endif
  166642. #if defined(PNG_READ_zTXt_SUPPORTED)
  166643. void /* PRIVATE */
  166644. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166645. length)
  166646. {
  166647. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166648. {
  166649. png_error(png_ptr, "Out of place zTXt");
  166650. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166651. }
  166652. #ifdef PNG_MAX_MALLOC_64K
  166653. if (length > (png_uint_32)65535L)
  166654. {
  166655. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166656. png_push_crc_skip(png_ptr, length);
  166657. return;
  166658. }
  166659. #endif
  166660. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166661. (png_uint_32)(length+1));
  166662. png_ptr->current_text[length] = '\0';
  166663. png_ptr->current_text_ptr = png_ptr->current_text;
  166664. png_ptr->current_text_size = (png_size_t)length;
  166665. png_ptr->current_text_left = (png_size_t)length;
  166666. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166667. }
  166668. void /* PRIVATE */
  166669. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  166670. {
  166671. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166672. {
  166673. png_size_t text_size;
  166674. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  166675. text_size = png_ptr->buffer_size;
  166676. else
  166677. text_size = png_ptr->current_text_left;
  166678. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166679. png_ptr->current_text_left -= text_size;
  166680. png_ptr->current_text_ptr += text_size;
  166681. }
  166682. if (!(png_ptr->current_text_left))
  166683. {
  166684. png_textp text_ptr;
  166685. png_charp text;
  166686. png_charp key;
  166687. int ret;
  166688. png_size_t text_size, key_size;
  166689. if (png_ptr->buffer_size < 4)
  166690. {
  166691. png_push_save_buffer(png_ptr);
  166692. return;
  166693. }
  166694. png_push_crc_finish(png_ptr);
  166695. key = png_ptr->current_text;
  166696. for (text = key; *text; text++)
  166697. ;
  166698. if (text >= key + png_ptr->current_text_size)
  166699. {
  166700. png_ptr->current_text = NULL;
  166701. png_free(png_ptr, key);
  166702. return;
  166703. }
  166704. text++;
  166705. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  166706. {
  166707. png_ptr->current_text = NULL;
  166708. png_free(png_ptr, key);
  166709. return;
  166710. }
  166711. text++;
  166712. png_ptr->zstream.next_in = (png_bytep )text;
  166713. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  166714. (text - key));
  166715. png_ptr->zstream.next_out = png_ptr->zbuf;
  166716. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166717. key_size = text - key;
  166718. text_size = 0;
  166719. text = NULL;
  166720. ret = Z_STREAM_END;
  166721. while (png_ptr->zstream.avail_in)
  166722. {
  166723. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166724. if (ret != Z_OK && ret != Z_STREAM_END)
  166725. {
  166726. inflateReset(&png_ptr->zstream);
  166727. png_ptr->zstream.avail_in = 0;
  166728. png_ptr->current_text = NULL;
  166729. png_free(png_ptr, key);
  166730. png_free(png_ptr, text);
  166731. return;
  166732. }
  166733. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  166734. {
  166735. if (text == NULL)
  166736. {
  166737. text = (png_charp)png_malloc(png_ptr,
  166738. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166739. + key_size + 1));
  166740. png_memcpy(text + key_size, png_ptr->zbuf,
  166741. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166742. png_memcpy(text, key, key_size);
  166743. text_size = key_size + png_ptr->zbuf_size -
  166744. png_ptr->zstream.avail_out;
  166745. *(text + text_size) = '\0';
  166746. }
  166747. else
  166748. {
  166749. png_charp tmp;
  166750. tmp = text;
  166751. text = (png_charp)png_malloc(png_ptr, text_size +
  166752. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166753. + 1));
  166754. png_memcpy(text, tmp, text_size);
  166755. png_free(png_ptr, tmp);
  166756. png_memcpy(text + text_size, png_ptr->zbuf,
  166757. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166758. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  166759. *(text + text_size) = '\0';
  166760. }
  166761. if (ret != Z_STREAM_END)
  166762. {
  166763. png_ptr->zstream.next_out = png_ptr->zbuf;
  166764. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166765. }
  166766. }
  166767. else
  166768. {
  166769. break;
  166770. }
  166771. if (ret == Z_STREAM_END)
  166772. break;
  166773. }
  166774. inflateReset(&png_ptr->zstream);
  166775. png_ptr->zstream.avail_in = 0;
  166776. if (ret != Z_STREAM_END)
  166777. {
  166778. png_ptr->current_text = NULL;
  166779. png_free(png_ptr, key);
  166780. png_free(png_ptr, text);
  166781. return;
  166782. }
  166783. png_ptr->current_text = NULL;
  166784. png_free(png_ptr, key);
  166785. key = text;
  166786. text += key_size;
  166787. text_ptr = (png_textp)png_malloc(png_ptr,
  166788. (png_uint_32)png_sizeof(png_text));
  166789. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  166790. text_ptr->key = key;
  166791. #ifdef PNG_iTXt_SUPPORTED
  166792. text_ptr->lang = NULL;
  166793. text_ptr->lang_key = NULL;
  166794. #endif
  166795. text_ptr->text = text;
  166796. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166797. png_free(png_ptr, key);
  166798. png_free(png_ptr, text_ptr);
  166799. if (ret)
  166800. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166801. }
  166802. }
  166803. #endif
  166804. #if defined(PNG_READ_iTXt_SUPPORTED)
  166805. void /* PRIVATE */
  166806. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166807. length)
  166808. {
  166809. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166810. {
  166811. png_error(png_ptr, "Out of place iTXt");
  166812. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166813. }
  166814. #ifdef PNG_MAX_MALLOC_64K
  166815. png_ptr->skip_length = 0; /* This may not be necessary */
  166816. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166817. {
  166818. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  166819. png_ptr->skip_length = length - (png_uint_32)65535L;
  166820. length = (png_uint_32)65535L;
  166821. }
  166822. #endif
  166823. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166824. (png_uint_32)(length+1));
  166825. png_ptr->current_text[length] = '\0';
  166826. png_ptr->current_text_ptr = png_ptr->current_text;
  166827. png_ptr->current_text_size = (png_size_t)length;
  166828. png_ptr->current_text_left = (png_size_t)length;
  166829. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  166830. }
  166831. void /* PRIVATE */
  166832. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  166833. {
  166834. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166835. {
  166836. png_size_t text_size;
  166837. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166838. text_size = png_ptr->buffer_size;
  166839. else
  166840. text_size = png_ptr->current_text_left;
  166841. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166842. png_ptr->current_text_left -= text_size;
  166843. png_ptr->current_text_ptr += text_size;
  166844. }
  166845. if (!(png_ptr->current_text_left))
  166846. {
  166847. png_textp text_ptr;
  166848. png_charp key;
  166849. int comp_flag;
  166850. png_charp lang;
  166851. png_charp lang_key;
  166852. png_charp text;
  166853. int ret;
  166854. if (png_ptr->buffer_size < 4)
  166855. {
  166856. png_push_save_buffer(png_ptr);
  166857. return;
  166858. }
  166859. png_push_crc_finish(png_ptr);
  166860. #if defined(PNG_MAX_MALLOC_64K)
  166861. if (png_ptr->skip_length)
  166862. return;
  166863. #endif
  166864. key = png_ptr->current_text;
  166865. for (lang = key; *lang; lang++)
  166866. ;
  166867. if (lang < key + png_ptr->current_text_size - 3)
  166868. lang++;
  166869. comp_flag = *lang++;
  166870. lang++; /* skip comp_type, always zero */
  166871. for (lang_key = lang; *lang_key; lang_key++)
  166872. ;
  166873. lang_key++; /* skip NUL separator */
  166874. text=lang_key;
  166875. if (lang_key < key + png_ptr->current_text_size - 1)
  166876. {
  166877. for (; *text; text++)
  166878. ;
  166879. }
  166880. if (text < key + png_ptr->current_text_size)
  166881. text++;
  166882. text_ptr = (png_textp)png_malloc(png_ptr,
  166883. (png_uint_32)png_sizeof(png_text));
  166884. text_ptr->compression = comp_flag + 2;
  166885. text_ptr->key = key;
  166886. text_ptr->lang = lang;
  166887. text_ptr->lang_key = lang_key;
  166888. text_ptr->text = text;
  166889. text_ptr->text_length = 0;
  166890. text_ptr->itxt_length = png_strlen(text);
  166891. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166892. png_ptr->current_text = NULL;
  166893. png_free(png_ptr, text_ptr);
  166894. if (ret)
  166895. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  166896. }
  166897. }
  166898. #endif
  166899. void /* PRIVATE */
  166900. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166901. length)
  166902. {
  166903. png_uint_32 skip=0;
  166904. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  166905. if (!(png_ptr->chunk_name[0] & 0x20))
  166906. {
  166907. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166908. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166909. PNG_HANDLE_CHUNK_ALWAYS
  166910. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166911. && png_ptr->read_user_chunk_fn == NULL
  166912. #endif
  166913. )
  166914. #endif
  166915. png_chunk_error(png_ptr, "unknown critical chunk");
  166916. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166917. }
  166918. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166919. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  166920. {
  166921. #ifdef PNG_MAX_MALLOC_64K
  166922. if (length > (png_uint_32)65535L)
  166923. {
  166924. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  166925. skip = length - (png_uint_32)65535L;
  166926. length = (png_uint_32)65535L;
  166927. }
  166928. #endif
  166929. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  166930. (png_charp)png_ptr->chunk_name, 5);
  166931. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  166932. png_ptr->unknown_chunk.size = (png_size_t)length;
  166933. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  166934. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166935. if(png_ptr->read_user_chunk_fn != NULL)
  166936. {
  166937. int ret;
  166938. ret = (*(png_ptr->read_user_chunk_fn))
  166939. (png_ptr, &png_ptr->unknown_chunk);
  166940. if (ret < 0)
  166941. png_chunk_error(png_ptr, "error in user chunk");
  166942. if (ret == 0)
  166943. {
  166944. if (!(png_ptr->chunk_name[0] & 0x20))
  166945. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166946. PNG_HANDLE_CHUNK_ALWAYS)
  166947. png_chunk_error(png_ptr, "unknown critical chunk");
  166948. png_set_unknown_chunks(png_ptr, info_ptr,
  166949. &png_ptr->unknown_chunk, 1);
  166950. }
  166951. }
  166952. #else
  166953. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  166954. #endif
  166955. png_free(png_ptr, png_ptr->unknown_chunk.data);
  166956. png_ptr->unknown_chunk.data = NULL;
  166957. }
  166958. else
  166959. #endif
  166960. skip=length;
  166961. png_push_crc_skip(png_ptr, skip);
  166962. }
  166963. void /* PRIVATE */
  166964. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  166965. {
  166966. if (png_ptr->info_fn != NULL)
  166967. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  166968. }
  166969. void /* PRIVATE */
  166970. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  166971. {
  166972. if (png_ptr->end_fn != NULL)
  166973. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  166974. }
  166975. void /* PRIVATE */
  166976. png_push_have_row(png_structp png_ptr, png_bytep row)
  166977. {
  166978. if (png_ptr->row_fn != NULL)
  166979. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  166980. (int)png_ptr->pass);
  166981. }
  166982. void PNGAPI
  166983. png_progressive_combine_row (png_structp png_ptr,
  166984. png_bytep old_row, png_bytep new_row)
  166985. {
  166986. #ifdef PNG_USE_LOCAL_ARRAYS
  166987. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  166988. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  166989. #endif
  166990. if(png_ptr == NULL) return;
  166991. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  166992. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  166993. }
  166994. void PNGAPI
  166995. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  166996. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  166997. png_progressive_end_ptr end_fn)
  166998. {
  166999. if(png_ptr == NULL) return;
  167000. png_ptr->info_fn = info_fn;
  167001. png_ptr->row_fn = row_fn;
  167002. png_ptr->end_fn = end_fn;
  167003. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  167004. }
  167005. png_voidp PNGAPI
  167006. png_get_progressive_ptr(png_structp png_ptr)
  167007. {
  167008. if(png_ptr == NULL) return (NULL);
  167009. return png_ptr->io_ptr;
  167010. }
  167011. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  167012. /*** End of inlined file: pngpread.c ***/
  167013. /*** Start of inlined file: pngrio.c ***/
  167014. #define PNG_INTERNAL
  167015. #if defined(PNG_READ_SUPPORTED)
  167016. void /* PRIVATE */
  167017. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167018. {
  167019. png_debug1(4,"reading %d bytes\n", (int)length);
  167020. if (png_ptr->read_data_fn != NULL)
  167021. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  167022. else
  167023. png_error(png_ptr, "Call to NULL read function");
  167024. }
  167025. #if !defined(PNG_NO_STDIO)
  167026. #ifndef USE_FAR_KEYWORD
  167027. void PNGAPI
  167028. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167029. {
  167030. png_size_t check;
  167031. if(png_ptr == NULL) return;
  167032. #if defined(_WIN32_WCE)
  167033. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167034. check = 0;
  167035. #else
  167036. check = (png_size_t)fread(data, (png_size_t)1, length,
  167037. (png_FILE_p)png_ptr->io_ptr);
  167038. #endif
  167039. if (check != length)
  167040. png_error(png_ptr, "Read Error");
  167041. }
  167042. #else
  167043. #define NEAR_BUF_SIZE 1024
  167044. #define MIN(a,b) (a <= b ? a : b)
  167045. static void PNGAPI
  167046. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167047. {
  167048. int check;
  167049. png_byte *n_data;
  167050. png_FILE_p io_ptr;
  167051. if(png_ptr == NULL) return;
  167052. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  167053. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  167054. if ((png_bytep)n_data == data)
  167055. {
  167056. #if defined(_WIN32_WCE)
  167057. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167058. check = 0;
  167059. #else
  167060. check = fread(n_data, 1, length, io_ptr);
  167061. #endif
  167062. }
  167063. else
  167064. {
  167065. png_byte buf[NEAR_BUF_SIZE];
  167066. png_size_t read, remaining, err;
  167067. check = 0;
  167068. remaining = length;
  167069. do
  167070. {
  167071. read = MIN(NEAR_BUF_SIZE, remaining);
  167072. #if defined(_WIN32_WCE)
  167073. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  167074. err = 0;
  167075. #else
  167076. err = fread(buf, (png_size_t)1, read, io_ptr);
  167077. #endif
  167078. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  167079. if(err != read)
  167080. break;
  167081. else
  167082. check += err;
  167083. data += read;
  167084. remaining -= read;
  167085. }
  167086. while (remaining != 0);
  167087. }
  167088. if ((png_uint_32)check != (png_uint_32)length)
  167089. png_error(png_ptr, "read Error");
  167090. }
  167091. #endif
  167092. #endif
  167093. void PNGAPI
  167094. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  167095. png_rw_ptr read_data_fn)
  167096. {
  167097. if(png_ptr == NULL) return;
  167098. png_ptr->io_ptr = io_ptr;
  167099. #if !defined(PNG_NO_STDIO)
  167100. if (read_data_fn != NULL)
  167101. png_ptr->read_data_fn = read_data_fn;
  167102. else
  167103. png_ptr->read_data_fn = png_default_read_data;
  167104. #else
  167105. png_ptr->read_data_fn = read_data_fn;
  167106. #endif
  167107. if (png_ptr->write_data_fn != NULL)
  167108. {
  167109. png_ptr->write_data_fn = NULL;
  167110. png_warning(png_ptr,
  167111. "It's an error to set both read_data_fn and write_data_fn in the ");
  167112. png_warning(png_ptr,
  167113. "same structure. Resetting write_data_fn to NULL.");
  167114. }
  167115. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  167116. png_ptr->output_flush_fn = NULL;
  167117. #endif
  167118. }
  167119. #endif /* PNG_READ_SUPPORTED */
  167120. /*** End of inlined file: pngrio.c ***/
  167121. /*** Start of inlined file: pngrtran.c ***/
  167122. #define PNG_INTERNAL
  167123. #if defined(PNG_READ_SUPPORTED)
  167124. void PNGAPI
  167125. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  167126. {
  167127. png_debug(1, "in png_set_crc_action\n");
  167128. if(png_ptr == NULL) return;
  167129. switch (crit_action)
  167130. {
  167131. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167132. break;
  167133. case PNG_CRC_WARN_USE: /* warn/use data */
  167134. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167135. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  167136. break;
  167137. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167138. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167139. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  167140. PNG_FLAG_CRC_CRITICAL_IGNORE;
  167141. break;
  167142. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  167143. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  167144. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167145. case PNG_CRC_DEFAULT:
  167146. default:
  167147. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167148. break;
  167149. }
  167150. switch (ancil_action)
  167151. {
  167152. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167153. break;
  167154. case PNG_CRC_WARN_USE: /* warn/use data */
  167155. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167156. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  167157. break;
  167158. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167159. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167160. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  167161. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167162. break;
  167163. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167164. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167165. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167166. break;
  167167. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  167168. case PNG_CRC_DEFAULT:
  167169. default:
  167170. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167171. break;
  167172. }
  167173. }
  167174. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  167175. defined(PNG_FLOATING_POINT_SUPPORTED)
  167176. void PNGAPI
  167177. png_set_background(png_structp png_ptr,
  167178. png_color_16p background_color, int background_gamma_code,
  167179. int need_expand, double background_gamma)
  167180. {
  167181. png_debug(1, "in png_set_background\n");
  167182. if(png_ptr == NULL) return;
  167183. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  167184. {
  167185. png_warning(png_ptr, "Application must supply a known background gamma");
  167186. return;
  167187. }
  167188. png_ptr->transformations |= PNG_BACKGROUND;
  167189. png_memcpy(&(png_ptr->background), background_color,
  167190. png_sizeof(png_color_16));
  167191. png_ptr->background_gamma = (float)background_gamma;
  167192. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  167193. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  167194. }
  167195. #endif
  167196. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167197. void PNGAPI
  167198. png_set_strip_16(png_structp png_ptr)
  167199. {
  167200. png_debug(1, "in png_set_strip_16\n");
  167201. if(png_ptr == NULL) return;
  167202. png_ptr->transformations |= PNG_16_TO_8;
  167203. }
  167204. #endif
  167205. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167206. void PNGAPI
  167207. png_set_strip_alpha(png_structp png_ptr)
  167208. {
  167209. png_debug(1, "in png_set_strip_alpha\n");
  167210. if(png_ptr == NULL) return;
  167211. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  167212. }
  167213. #endif
  167214. #if defined(PNG_READ_DITHER_SUPPORTED)
  167215. typedef struct png_dsort_struct
  167216. {
  167217. struct png_dsort_struct FAR * next;
  167218. png_byte left;
  167219. png_byte right;
  167220. } png_dsort;
  167221. typedef png_dsort FAR * png_dsortp;
  167222. typedef png_dsort FAR * FAR * png_dsortpp;
  167223. void PNGAPI
  167224. png_set_dither(png_structp png_ptr, png_colorp palette,
  167225. int num_palette, int maximum_colors, png_uint_16p histogram,
  167226. int full_dither)
  167227. {
  167228. png_debug(1, "in png_set_dither\n");
  167229. if(png_ptr == NULL) return;
  167230. png_ptr->transformations |= PNG_DITHER;
  167231. if (!full_dither)
  167232. {
  167233. int i;
  167234. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  167235. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167236. for (i = 0; i < num_palette; i++)
  167237. png_ptr->dither_index[i] = (png_byte)i;
  167238. }
  167239. if (num_palette > maximum_colors)
  167240. {
  167241. if (histogram != NULL)
  167242. {
  167243. int i;
  167244. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  167245. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167246. for (i = 0; i < num_palette; i++)
  167247. png_ptr->dither_sort[i] = (png_byte)i;
  167248. for (i = num_palette - 1; i >= maximum_colors; i--)
  167249. {
  167250. int done; /* to stop early if the list is pre-sorted */
  167251. int j;
  167252. done = 1;
  167253. for (j = 0; j < i; j++)
  167254. {
  167255. if (histogram[png_ptr->dither_sort[j]]
  167256. < histogram[png_ptr->dither_sort[j + 1]])
  167257. {
  167258. png_byte t;
  167259. t = png_ptr->dither_sort[j];
  167260. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  167261. png_ptr->dither_sort[j + 1] = t;
  167262. done = 0;
  167263. }
  167264. }
  167265. if (done)
  167266. break;
  167267. }
  167268. if (full_dither)
  167269. {
  167270. int j = num_palette;
  167271. for (i = 0; i < maximum_colors; i++)
  167272. {
  167273. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167274. {
  167275. do
  167276. j--;
  167277. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167278. palette[i] = palette[j];
  167279. }
  167280. }
  167281. }
  167282. else
  167283. {
  167284. int j = num_palette;
  167285. for (i = 0; i < maximum_colors; i++)
  167286. {
  167287. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167288. {
  167289. png_color tmp_color;
  167290. do
  167291. j--;
  167292. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167293. tmp_color = palette[j];
  167294. palette[j] = palette[i];
  167295. palette[i] = tmp_color;
  167296. png_ptr->dither_index[j] = (png_byte)i;
  167297. png_ptr->dither_index[i] = (png_byte)j;
  167298. }
  167299. }
  167300. for (i = 0; i < num_palette; i++)
  167301. {
  167302. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167303. {
  167304. int min_d, k, min_k, d_index;
  167305. d_index = png_ptr->dither_index[i];
  167306. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167307. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167308. {
  167309. int d;
  167310. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167311. if (d < min_d)
  167312. {
  167313. min_d = d;
  167314. min_k = k;
  167315. }
  167316. }
  167317. png_ptr->dither_index[i] = (png_byte)min_k;
  167318. }
  167319. }
  167320. }
  167321. png_free(png_ptr, png_ptr->dither_sort);
  167322. png_ptr->dither_sort=NULL;
  167323. }
  167324. else
  167325. {
  167326. int i;
  167327. int max_d;
  167328. int num_new_palette;
  167329. png_dsortp t;
  167330. png_dsortpp hash;
  167331. t=NULL;
  167332. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167333. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167334. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167335. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167336. for (i = 0; i < num_palette; i++)
  167337. {
  167338. png_ptr->index_to_palette[i] = (png_byte)i;
  167339. png_ptr->palette_to_index[i] = (png_byte)i;
  167340. }
  167341. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167342. png_sizeof (png_dsortp)));
  167343. for (i = 0; i < 769; i++)
  167344. hash[i] = NULL;
  167345. num_new_palette = num_palette;
  167346. max_d = 96;
  167347. while (num_new_palette > maximum_colors)
  167348. {
  167349. for (i = 0; i < num_new_palette - 1; i++)
  167350. {
  167351. int j;
  167352. for (j = i + 1; j < num_new_palette; j++)
  167353. {
  167354. int d;
  167355. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167356. if (d <= max_d)
  167357. {
  167358. t = (png_dsortp)png_malloc_warn(png_ptr,
  167359. (png_uint_32)(png_sizeof(png_dsort)));
  167360. if (t == NULL)
  167361. break;
  167362. t->next = hash[d];
  167363. t->left = (png_byte)i;
  167364. t->right = (png_byte)j;
  167365. hash[d] = t;
  167366. }
  167367. }
  167368. if (t == NULL)
  167369. break;
  167370. }
  167371. if (t != NULL)
  167372. for (i = 0; i <= max_d; i++)
  167373. {
  167374. if (hash[i] != NULL)
  167375. {
  167376. png_dsortp p;
  167377. for (p = hash[i]; p; p = p->next)
  167378. {
  167379. if ((int)png_ptr->index_to_palette[p->left]
  167380. < num_new_palette &&
  167381. (int)png_ptr->index_to_palette[p->right]
  167382. < num_new_palette)
  167383. {
  167384. int j, next_j;
  167385. if (num_new_palette & 0x01)
  167386. {
  167387. j = p->left;
  167388. next_j = p->right;
  167389. }
  167390. else
  167391. {
  167392. j = p->right;
  167393. next_j = p->left;
  167394. }
  167395. num_new_palette--;
  167396. palette[png_ptr->index_to_palette[j]]
  167397. = palette[num_new_palette];
  167398. if (!full_dither)
  167399. {
  167400. int k;
  167401. for (k = 0; k < num_palette; k++)
  167402. {
  167403. if (png_ptr->dither_index[k] ==
  167404. png_ptr->index_to_palette[j])
  167405. png_ptr->dither_index[k] =
  167406. png_ptr->index_to_palette[next_j];
  167407. if ((int)png_ptr->dither_index[k] ==
  167408. num_new_palette)
  167409. png_ptr->dither_index[k] =
  167410. png_ptr->index_to_palette[j];
  167411. }
  167412. }
  167413. png_ptr->index_to_palette[png_ptr->palette_to_index
  167414. [num_new_palette]] = png_ptr->index_to_palette[j];
  167415. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167416. = png_ptr->palette_to_index[num_new_palette];
  167417. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167418. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167419. }
  167420. if (num_new_palette <= maximum_colors)
  167421. break;
  167422. }
  167423. if (num_new_palette <= maximum_colors)
  167424. break;
  167425. }
  167426. }
  167427. for (i = 0; i < 769; i++)
  167428. {
  167429. if (hash[i] != NULL)
  167430. {
  167431. png_dsortp p = hash[i];
  167432. while (p)
  167433. {
  167434. t = p->next;
  167435. png_free(png_ptr, p);
  167436. p = t;
  167437. }
  167438. }
  167439. hash[i] = 0;
  167440. }
  167441. max_d += 96;
  167442. }
  167443. png_free(png_ptr, hash);
  167444. png_free(png_ptr, png_ptr->palette_to_index);
  167445. png_free(png_ptr, png_ptr->index_to_palette);
  167446. png_ptr->palette_to_index=NULL;
  167447. png_ptr->index_to_palette=NULL;
  167448. }
  167449. num_palette = maximum_colors;
  167450. }
  167451. if (png_ptr->palette == NULL)
  167452. {
  167453. png_ptr->palette = palette;
  167454. }
  167455. png_ptr->num_palette = (png_uint_16)num_palette;
  167456. if (full_dither)
  167457. {
  167458. int i;
  167459. png_bytep distance;
  167460. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167461. PNG_DITHER_BLUE_BITS;
  167462. int num_red = (1 << PNG_DITHER_RED_BITS);
  167463. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167464. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167465. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167466. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167467. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167468. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167469. png_sizeof (png_byte));
  167470. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167471. png_sizeof(png_byte)));
  167472. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167473. for (i = 0; i < num_palette; i++)
  167474. {
  167475. int ir, ig, ib;
  167476. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167477. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167478. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167479. for (ir = 0; ir < num_red; ir++)
  167480. {
  167481. int dr = ((ir > r) ? ir - r : r - ir);
  167482. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167483. for (ig = 0; ig < num_green; ig++)
  167484. {
  167485. int dg = ((ig > g) ? ig - g : g - ig);
  167486. int dt = dr + dg;
  167487. int dm = ((dr > dg) ? dr : dg);
  167488. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167489. for (ib = 0; ib < num_blue; ib++)
  167490. {
  167491. int d_index = index_g | ib;
  167492. int db = ((ib > b) ? ib - b : b - ib);
  167493. int dmax = ((dm > db) ? dm : db);
  167494. int d = dmax + dt + db;
  167495. if (d < (int)distance[d_index])
  167496. {
  167497. distance[d_index] = (png_byte)d;
  167498. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167499. }
  167500. }
  167501. }
  167502. }
  167503. }
  167504. png_free(png_ptr, distance);
  167505. }
  167506. }
  167507. #endif
  167508. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167509. void PNGAPI
  167510. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167511. {
  167512. png_debug(1, "in png_set_gamma\n");
  167513. if(png_ptr == NULL) return;
  167514. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167515. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167516. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167517. png_ptr->transformations |= PNG_GAMMA;
  167518. png_ptr->gamma = (float)file_gamma;
  167519. png_ptr->screen_gamma = (float)scrn_gamma;
  167520. }
  167521. #endif
  167522. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167523. void PNGAPI
  167524. png_set_expand(png_structp png_ptr)
  167525. {
  167526. png_debug(1, "in png_set_expand\n");
  167527. if(png_ptr == NULL) return;
  167528. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167529. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167530. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167531. #endif
  167532. }
  167533. void PNGAPI
  167534. png_set_palette_to_rgb(png_structp png_ptr)
  167535. {
  167536. png_debug(1, "in png_set_palette_to_rgb\n");
  167537. if(png_ptr == NULL) return;
  167538. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167539. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167540. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167541. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167542. #endif
  167543. }
  167544. #if !defined(PNG_1_0_X)
  167545. void PNGAPI
  167546. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167547. {
  167548. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167549. if(png_ptr == NULL) return;
  167550. png_ptr->transformations |= PNG_EXPAND;
  167551. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167552. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167553. #endif
  167554. }
  167555. #endif
  167556. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167557. void PNGAPI
  167558. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167559. {
  167560. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167561. if(png_ptr == NULL) return;
  167562. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167563. }
  167564. #endif
  167565. void PNGAPI
  167566. png_set_tRNS_to_alpha(png_structp png_ptr)
  167567. {
  167568. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167569. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167570. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167571. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167572. #endif
  167573. }
  167574. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167575. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167576. void PNGAPI
  167577. png_set_gray_to_rgb(png_structp png_ptr)
  167578. {
  167579. png_debug(1, "in png_set_gray_to_rgb\n");
  167580. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167581. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167582. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167583. #endif
  167584. }
  167585. #endif
  167586. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167587. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167588. void PNGAPI
  167589. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167590. double green)
  167591. {
  167592. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167593. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167594. if(png_ptr == NULL) return;
  167595. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167596. }
  167597. #endif
  167598. void PNGAPI
  167599. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167600. png_fixed_point red, png_fixed_point green)
  167601. {
  167602. png_debug(1, "in png_set_rgb_to_gray\n");
  167603. if(png_ptr == NULL) return;
  167604. switch(error_action)
  167605. {
  167606. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167607. break;
  167608. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167609. break;
  167610. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167611. }
  167612. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167613. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167614. png_ptr->transformations |= PNG_EXPAND;
  167615. #else
  167616. {
  167617. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167618. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167619. }
  167620. #endif
  167621. {
  167622. png_uint_16 red_int, green_int;
  167623. if(red < 0 || green < 0)
  167624. {
  167625. red_int = 6968; /* .212671 * 32768 + .5 */
  167626. green_int = 23434; /* .715160 * 32768 + .5 */
  167627. }
  167628. else if(red + green < 100000L)
  167629. {
  167630. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167631. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167632. }
  167633. else
  167634. {
  167635. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167636. red_int = 6968;
  167637. green_int = 23434;
  167638. }
  167639. png_ptr->rgb_to_gray_red_coeff = red_int;
  167640. png_ptr->rgb_to_gray_green_coeff = green_int;
  167641. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167642. }
  167643. }
  167644. #endif
  167645. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167646. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167647. defined(PNG_LEGACY_SUPPORTED)
  167648. void PNGAPI
  167649. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167650. read_user_transform_fn)
  167651. {
  167652. png_debug(1, "in png_set_read_user_transform_fn\n");
  167653. if(png_ptr == NULL) return;
  167654. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167655. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167656. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167657. #endif
  167658. #ifdef PNG_LEGACY_SUPPORTED
  167659. if(read_user_transform_fn)
  167660. png_warning(png_ptr,
  167661. "This version of libpng does not support user transforms");
  167662. #endif
  167663. }
  167664. #endif
  167665. void /* PRIVATE */
  167666. png_init_read_transformations(png_structp png_ptr)
  167667. {
  167668. png_debug(1, "in png_init_read_transformations\n");
  167669. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167670. if(png_ptr != NULL)
  167671. #endif
  167672. {
  167673. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  167674. || defined(PNG_READ_GAMMA_SUPPORTED)
  167675. int color_type = png_ptr->color_type;
  167676. #endif
  167677. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  167678. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167679. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167680. !(color_type & PNG_COLOR_MASK_COLOR))
  167681. {
  167682. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167683. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167684. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167685. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167686. png_ptr->background.red == png_ptr->background.green &&
  167687. png_ptr->background.red == png_ptr->background.blue)
  167688. {
  167689. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167690. png_ptr->background.gray = png_ptr->background.red;
  167691. }
  167692. #endif
  167693. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167694. (png_ptr->transformations & PNG_EXPAND))
  167695. {
  167696. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  167697. {
  167698. switch (png_ptr->bit_depth)
  167699. {
  167700. case 1:
  167701. png_ptr->background.gray *= (png_uint_16)0xff;
  167702. png_ptr->background.red = png_ptr->background.green
  167703. = png_ptr->background.blue = png_ptr->background.gray;
  167704. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167705. {
  167706. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  167707. png_ptr->trans_values.red = png_ptr->trans_values.green
  167708. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167709. }
  167710. break;
  167711. case 2:
  167712. png_ptr->background.gray *= (png_uint_16)0x55;
  167713. png_ptr->background.red = png_ptr->background.green
  167714. = png_ptr->background.blue = png_ptr->background.gray;
  167715. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167716. {
  167717. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  167718. png_ptr->trans_values.red = png_ptr->trans_values.green
  167719. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167720. }
  167721. break;
  167722. case 4:
  167723. png_ptr->background.gray *= (png_uint_16)0x11;
  167724. png_ptr->background.red = png_ptr->background.green
  167725. = png_ptr->background.blue = png_ptr->background.gray;
  167726. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167727. {
  167728. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  167729. png_ptr->trans_values.red = png_ptr->trans_values.green
  167730. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167731. }
  167732. break;
  167733. case 8:
  167734. case 16:
  167735. png_ptr->background.red = png_ptr->background.green
  167736. = png_ptr->background.blue = png_ptr->background.gray;
  167737. break;
  167738. }
  167739. }
  167740. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  167741. {
  167742. png_ptr->background.red =
  167743. png_ptr->palette[png_ptr->background.index].red;
  167744. png_ptr->background.green =
  167745. png_ptr->palette[png_ptr->background.index].green;
  167746. png_ptr->background.blue =
  167747. png_ptr->palette[png_ptr->background.index].blue;
  167748. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  167749. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  167750. {
  167751. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167752. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167753. #endif
  167754. {
  167755. int i,istop;
  167756. istop=(int)png_ptr->num_trans;
  167757. for (i=0; i<istop; i++)
  167758. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  167759. }
  167760. }
  167761. #endif
  167762. }
  167763. }
  167764. #endif
  167765. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  167766. png_ptr->background_1 = png_ptr->background;
  167767. #endif
  167768. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167769. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  167770. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  167771. < PNG_GAMMA_THRESHOLD))
  167772. {
  167773. int i,k;
  167774. k=0;
  167775. for (i=0; i<png_ptr->num_trans; i++)
  167776. {
  167777. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  167778. k=1; /* partial transparency is present */
  167779. }
  167780. if (k == 0)
  167781. png_ptr->transformations &= (~PNG_GAMMA);
  167782. }
  167783. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  167784. png_ptr->gamma != 0.0)
  167785. {
  167786. png_build_gamma_table(png_ptr);
  167787. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167788. if (png_ptr->transformations & PNG_BACKGROUND)
  167789. {
  167790. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167791. {
  167792. png_color back, back_1;
  167793. png_colorp palette = png_ptr->palette;
  167794. int num_palette = png_ptr->num_palette;
  167795. int i;
  167796. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  167797. {
  167798. back.red = png_ptr->gamma_table[png_ptr->background.red];
  167799. back.green = png_ptr->gamma_table[png_ptr->background.green];
  167800. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  167801. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  167802. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  167803. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  167804. }
  167805. else
  167806. {
  167807. double g, gs;
  167808. switch (png_ptr->background_gamma_type)
  167809. {
  167810. case PNG_BACKGROUND_GAMMA_SCREEN:
  167811. g = (png_ptr->screen_gamma);
  167812. gs = 1.0;
  167813. break;
  167814. case PNG_BACKGROUND_GAMMA_FILE:
  167815. g = 1.0 / (png_ptr->gamma);
  167816. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167817. break;
  167818. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167819. g = 1.0 / (png_ptr->background_gamma);
  167820. gs = 1.0 / (png_ptr->background_gamma *
  167821. png_ptr->screen_gamma);
  167822. break;
  167823. default:
  167824. g = 1.0; /* back_1 */
  167825. gs = 1.0; /* back */
  167826. }
  167827. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  167828. {
  167829. back.red = (png_byte)png_ptr->background.red;
  167830. back.green = (png_byte)png_ptr->background.green;
  167831. back.blue = (png_byte)png_ptr->background.blue;
  167832. }
  167833. else
  167834. {
  167835. back.red = (png_byte)(pow(
  167836. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  167837. back.green = (png_byte)(pow(
  167838. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  167839. back.blue = (png_byte)(pow(
  167840. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  167841. }
  167842. back_1.red = (png_byte)(pow(
  167843. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  167844. back_1.green = (png_byte)(pow(
  167845. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  167846. back_1.blue = (png_byte)(pow(
  167847. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  167848. }
  167849. for (i = 0; i < num_palette; i++)
  167850. {
  167851. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  167852. {
  167853. if (png_ptr->trans[i] == 0)
  167854. {
  167855. palette[i] = back;
  167856. }
  167857. else /* if (png_ptr->trans[i] != 0xff) */
  167858. {
  167859. png_byte v, w;
  167860. v = png_ptr->gamma_to_1[palette[i].red];
  167861. png_composite(w, v, png_ptr->trans[i], back_1.red);
  167862. palette[i].red = png_ptr->gamma_from_1[w];
  167863. v = png_ptr->gamma_to_1[palette[i].green];
  167864. png_composite(w, v, png_ptr->trans[i], back_1.green);
  167865. palette[i].green = png_ptr->gamma_from_1[w];
  167866. v = png_ptr->gamma_to_1[palette[i].blue];
  167867. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  167868. palette[i].blue = png_ptr->gamma_from_1[w];
  167869. }
  167870. }
  167871. else
  167872. {
  167873. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167874. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167875. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167876. }
  167877. }
  167878. }
  167879. else
  167880. {
  167881. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  167882. double g = 1.0;
  167883. double gs = 1.0;
  167884. switch (png_ptr->background_gamma_type)
  167885. {
  167886. case PNG_BACKGROUND_GAMMA_SCREEN:
  167887. g = (png_ptr->screen_gamma);
  167888. gs = 1.0;
  167889. break;
  167890. case PNG_BACKGROUND_GAMMA_FILE:
  167891. g = 1.0 / (png_ptr->gamma);
  167892. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167893. break;
  167894. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167895. g = 1.0 / (png_ptr->background_gamma);
  167896. gs = 1.0 / (png_ptr->background_gamma *
  167897. png_ptr->screen_gamma);
  167898. break;
  167899. }
  167900. png_ptr->background_1.gray = (png_uint_16)(pow(
  167901. (double)png_ptr->background.gray / m, g) * m + .5);
  167902. png_ptr->background.gray = (png_uint_16)(pow(
  167903. (double)png_ptr->background.gray / m, gs) * m + .5);
  167904. if ((png_ptr->background.red != png_ptr->background.green) ||
  167905. (png_ptr->background.red != png_ptr->background.blue) ||
  167906. (png_ptr->background.red != png_ptr->background.gray))
  167907. {
  167908. png_ptr->background_1.red = (png_uint_16)(pow(
  167909. (double)png_ptr->background.red / m, g) * m + .5);
  167910. png_ptr->background_1.green = (png_uint_16)(pow(
  167911. (double)png_ptr->background.green / m, g) * m + .5);
  167912. png_ptr->background_1.blue = (png_uint_16)(pow(
  167913. (double)png_ptr->background.blue / m, g) * m + .5);
  167914. png_ptr->background.red = (png_uint_16)(pow(
  167915. (double)png_ptr->background.red / m, gs) * m + .5);
  167916. png_ptr->background.green = (png_uint_16)(pow(
  167917. (double)png_ptr->background.green / m, gs) * m + .5);
  167918. png_ptr->background.blue = (png_uint_16)(pow(
  167919. (double)png_ptr->background.blue / m, gs) * m + .5);
  167920. }
  167921. else
  167922. {
  167923. png_ptr->background_1.red = png_ptr->background_1.green
  167924. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  167925. png_ptr->background.red = png_ptr->background.green
  167926. = png_ptr->background.blue = png_ptr->background.gray;
  167927. }
  167928. }
  167929. }
  167930. else
  167931. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167932. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167933. {
  167934. png_colorp palette = png_ptr->palette;
  167935. int num_palette = png_ptr->num_palette;
  167936. int i;
  167937. for (i = 0; i < num_palette; i++)
  167938. {
  167939. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167940. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167941. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167942. }
  167943. }
  167944. }
  167945. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167946. else
  167947. #endif
  167948. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  167949. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167950. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167951. (color_type == PNG_COLOR_TYPE_PALETTE))
  167952. {
  167953. int i;
  167954. int istop = (int)png_ptr->num_trans;
  167955. png_color back;
  167956. png_colorp palette = png_ptr->palette;
  167957. back.red = (png_byte)png_ptr->background.red;
  167958. back.green = (png_byte)png_ptr->background.green;
  167959. back.blue = (png_byte)png_ptr->background.blue;
  167960. for (i = 0; i < istop; i++)
  167961. {
  167962. if (png_ptr->trans[i] == 0)
  167963. {
  167964. palette[i] = back;
  167965. }
  167966. else if (png_ptr->trans[i] != 0xff)
  167967. {
  167968. png_composite(palette[i].red, palette[i].red,
  167969. png_ptr->trans[i], back.red);
  167970. png_composite(palette[i].green, palette[i].green,
  167971. png_ptr->trans[i], back.green);
  167972. png_composite(palette[i].blue, palette[i].blue,
  167973. png_ptr->trans[i], back.blue);
  167974. }
  167975. }
  167976. }
  167977. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167978. #if defined(PNG_READ_SHIFT_SUPPORTED)
  167979. if ((png_ptr->transformations & PNG_SHIFT) &&
  167980. (color_type == PNG_COLOR_TYPE_PALETTE))
  167981. {
  167982. png_uint_16 i;
  167983. png_uint_16 istop = png_ptr->num_palette;
  167984. int sr = 8 - png_ptr->sig_bit.red;
  167985. int sg = 8 - png_ptr->sig_bit.green;
  167986. int sb = 8 - png_ptr->sig_bit.blue;
  167987. if (sr < 0 || sr > 8)
  167988. sr = 0;
  167989. if (sg < 0 || sg > 8)
  167990. sg = 0;
  167991. if (sb < 0 || sb > 8)
  167992. sb = 0;
  167993. for (i = 0; i < istop; i++)
  167994. {
  167995. png_ptr->palette[i].red >>= sr;
  167996. png_ptr->palette[i].green >>= sg;
  167997. png_ptr->palette[i].blue >>= sb;
  167998. }
  167999. }
  168000. #endif /* PNG_READ_SHIFT_SUPPORTED */
  168001. }
  168002. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  168003. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  168004. if(png_ptr)
  168005. return;
  168006. #endif
  168007. }
  168008. void /* PRIVATE */
  168009. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  168010. {
  168011. png_debug(1, "in png_read_transform_info\n");
  168012. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168013. if (png_ptr->transformations & PNG_EXPAND)
  168014. {
  168015. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168016. {
  168017. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  168018. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  168019. else
  168020. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  168021. info_ptr->bit_depth = 8;
  168022. info_ptr->num_trans = 0;
  168023. }
  168024. else
  168025. {
  168026. if (png_ptr->num_trans)
  168027. {
  168028. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  168029. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168030. else
  168031. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168032. }
  168033. if (info_ptr->bit_depth < 8)
  168034. info_ptr->bit_depth = 8;
  168035. info_ptr->num_trans = 0;
  168036. }
  168037. }
  168038. #endif
  168039. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168040. if (png_ptr->transformations & PNG_BACKGROUND)
  168041. {
  168042. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168043. info_ptr->num_trans = 0;
  168044. info_ptr->background = png_ptr->background;
  168045. }
  168046. #endif
  168047. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168048. if (png_ptr->transformations & PNG_GAMMA)
  168049. {
  168050. #ifdef PNG_FLOATING_POINT_SUPPORTED
  168051. info_ptr->gamma = png_ptr->gamma;
  168052. #endif
  168053. #ifdef PNG_FIXED_POINT_SUPPORTED
  168054. info_ptr->int_gamma = png_ptr->int_gamma;
  168055. #endif
  168056. }
  168057. #endif
  168058. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168059. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  168060. info_ptr->bit_depth = 8;
  168061. #endif
  168062. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168063. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  168064. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168065. #endif
  168066. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168067. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168068. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  168069. #endif
  168070. #if defined(PNG_READ_DITHER_SUPPORTED)
  168071. if (png_ptr->transformations & PNG_DITHER)
  168072. {
  168073. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168074. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  168075. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  168076. {
  168077. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  168078. }
  168079. }
  168080. #endif
  168081. #if defined(PNG_READ_PACK_SUPPORTED)
  168082. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  168083. info_ptr->bit_depth = 8;
  168084. #endif
  168085. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168086. info_ptr->channels = 1;
  168087. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  168088. info_ptr->channels = 3;
  168089. else
  168090. info_ptr->channels = 1;
  168091. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168092. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168093. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168094. #endif
  168095. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  168096. info_ptr->channels++;
  168097. #if defined(PNG_READ_FILLER_SUPPORTED)
  168098. if ((png_ptr->transformations & PNG_FILLER) &&
  168099. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168100. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  168101. {
  168102. info_ptr->channels++;
  168103. #if !defined(PNG_1_0_X)
  168104. if (png_ptr->transformations & PNG_ADD_ALPHA)
  168105. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168106. #endif
  168107. }
  168108. #endif
  168109. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  168110. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168111. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  168112. {
  168113. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  168114. info_ptr->bit_depth = png_ptr->user_transform_depth;
  168115. if(info_ptr->channels < png_ptr->user_transform_channels)
  168116. info_ptr->channels = png_ptr->user_transform_channels;
  168117. }
  168118. #endif
  168119. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  168120. info_ptr->bit_depth);
  168121. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  168122. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  168123. if(png_ptr)
  168124. return;
  168125. #endif
  168126. }
  168127. void /* PRIVATE */
  168128. png_do_read_transformations(png_structp png_ptr)
  168129. {
  168130. png_debug(1, "in png_do_read_transformations\n");
  168131. if (png_ptr->row_buf == NULL)
  168132. {
  168133. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  168134. char msg[50];
  168135. png_snprintf2(msg, 50,
  168136. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  168137. png_ptr->pass);
  168138. png_error(png_ptr, msg);
  168139. #else
  168140. png_error(png_ptr, "NULL row buffer");
  168141. #endif
  168142. }
  168143. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168144. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  168145. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  168146. png_error(png_ptr, "Uninitialized row");
  168147. #else
  168148. png_warning(png_ptr, "Uninitialized row");
  168149. #endif
  168150. #endif
  168151. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168152. if (png_ptr->transformations & PNG_EXPAND)
  168153. {
  168154. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  168155. {
  168156. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168157. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  168158. }
  168159. else
  168160. {
  168161. if (png_ptr->num_trans &&
  168162. (png_ptr->transformations & PNG_EXPAND_tRNS))
  168163. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168164. &(png_ptr->trans_values));
  168165. else
  168166. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168167. NULL);
  168168. }
  168169. }
  168170. #endif
  168171. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168172. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168173. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168174. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  168175. #endif
  168176. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168177. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168178. {
  168179. int rgb_error =
  168180. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  168181. if(rgb_error)
  168182. {
  168183. png_ptr->rgb_to_gray_status=1;
  168184. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168185. PNG_RGB_TO_GRAY_WARN)
  168186. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168187. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168188. PNG_RGB_TO_GRAY_ERR)
  168189. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168190. }
  168191. }
  168192. #endif
  168193. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168194. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168195. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168196. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168197. #endif
  168198. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168199. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168200. ((png_ptr->num_trans != 0 ) ||
  168201. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  168202. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168203. &(png_ptr->trans_values), &(png_ptr->background)
  168204. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168205. , &(png_ptr->background_1),
  168206. png_ptr->gamma_table, png_ptr->gamma_from_1,
  168207. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  168208. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  168209. png_ptr->gamma_shift
  168210. #endif
  168211. );
  168212. #endif
  168213. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168214. if ((png_ptr->transformations & PNG_GAMMA) &&
  168215. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168216. !((png_ptr->transformations & PNG_BACKGROUND) &&
  168217. ((png_ptr->num_trans != 0) ||
  168218. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  168219. #endif
  168220. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  168221. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168222. png_ptr->gamma_table, png_ptr->gamma_16_table,
  168223. png_ptr->gamma_shift);
  168224. #endif
  168225. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168226. if (png_ptr->transformations & PNG_16_TO_8)
  168227. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168228. #endif
  168229. #if defined(PNG_READ_DITHER_SUPPORTED)
  168230. if (png_ptr->transformations & PNG_DITHER)
  168231. {
  168232. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  168233. png_ptr->palette_lookup, png_ptr->dither_index);
  168234. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  168235. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  168236. }
  168237. #endif
  168238. #if defined(PNG_READ_INVERT_SUPPORTED)
  168239. if (png_ptr->transformations & PNG_INVERT_MONO)
  168240. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168241. #endif
  168242. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168243. if (png_ptr->transformations & PNG_SHIFT)
  168244. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168245. &(png_ptr->shift));
  168246. #endif
  168247. #if defined(PNG_READ_PACK_SUPPORTED)
  168248. if (png_ptr->transformations & PNG_PACK)
  168249. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168250. #endif
  168251. #if defined(PNG_READ_BGR_SUPPORTED)
  168252. if (png_ptr->transformations & PNG_BGR)
  168253. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168254. #endif
  168255. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  168256. if (png_ptr->transformations & PNG_PACKSWAP)
  168257. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168258. #endif
  168259. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168260. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168261. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168262. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168263. #endif
  168264. #if defined(PNG_READ_FILLER_SUPPORTED)
  168265. if (png_ptr->transformations & PNG_FILLER)
  168266. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168267. (png_uint_32)png_ptr->filler, png_ptr->flags);
  168268. #endif
  168269. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168270. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168271. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168272. #endif
  168273. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168274. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168275. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168276. #endif
  168277. #if defined(PNG_READ_SWAP_SUPPORTED)
  168278. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168279. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168280. #endif
  168281. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168282. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168283. {
  168284. if(png_ptr->read_user_transform_fn != NULL)
  168285. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168286. (png_ptr, /* png_ptr */
  168287. &(png_ptr->row_info), /* row_info: */
  168288. png_ptr->row_buf + 1); /* start of pixel data for row */
  168289. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168290. if(png_ptr->user_transform_depth)
  168291. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168292. if(png_ptr->user_transform_channels)
  168293. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168294. #endif
  168295. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168296. png_ptr->row_info.channels);
  168297. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168298. png_ptr->row_info.width);
  168299. }
  168300. #endif
  168301. }
  168302. #if defined(PNG_READ_PACK_SUPPORTED)
  168303. void /* PRIVATE */
  168304. png_do_unpack(png_row_infop row_info, png_bytep row)
  168305. {
  168306. png_debug(1, "in png_do_unpack\n");
  168307. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168308. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168309. #else
  168310. if (row_info->bit_depth < 8)
  168311. #endif
  168312. {
  168313. png_uint_32 i;
  168314. png_uint_32 row_width=row_info->width;
  168315. switch (row_info->bit_depth)
  168316. {
  168317. case 1:
  168318. {
  168319. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168320. png_bytep dp = row + (png_size_t)row_width - 1;
  168321. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168322. for (i = 0; i < row_width; i++)
  168323. {
  168324. *dp = (png_byte)((*sp >> shift) & 0x01);
  168325. if (shift == 7)
  168326. {
  168327. shift = 0;
  168328. sp--;
  168329. }
  168330. else
  168331. shift++;
  168332. dp--;
  168333. }
  168334. break;
  168335. }
  168336. case 2:
  168337. {
  168338. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168339. png_bytep dp = row + (png_size_t)row_width - 1;
  168340. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168341. for (i = 0; i < row_width; i++)
  168342. {
  168343. *dp = (png_byte)((*sp >> shift) & 0x03);
  168344. if (shift == 6)
  168345. {
  168346. shift = 0;
  168347. sp--;
  168348. }
  168349. else
  168350. shift += 2;
  168351. dp--;
  168352. }
  168353. break;
  168354. }
  168355. case 4:
  168356. {
  168357. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168358. png_bytep dp = row + (png_size_t)row_width - 1;
  168359. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168360. for (i = 0; i < row_width; i++)
  168361. {
  168362. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168363. if (shift == 4)
  168364. {
  168365. shift = 0;
  168366. sp--;
  168367. }
  168368. else
  168369. shift = 4;
  168370. dp--;
  168371. }
  168372. break;
  168373. }
  168374. }
  168375. row_info->bit_depth = 8;
  168376. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168377. row_info->rowbytes = row_width * row_info->channels;
  168378. }
  168379. }
  168380. #endif
  168381. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168382. void /* PRIVATE */
  168383. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168384. {
  168385. png_debug(1, "in png_do_unshift\n");
  168386. if (
  168387. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168388. row != NULL && row_info != NULL && sig_bits != NULL &&
  168389. #endif
  168390. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168391. {
  168392. int shift[4];
  168393. int channels = 0;
  168394. int c;
  168395. png_uint_16 value = 0;
  168396. png_uint_32 row_width = row_info->width;
  168397. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168398. {
  168399. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168400. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168401. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168402. }
  168403. else
  168404. {
  168405. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168406. }
  168407. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168408. {
  168409. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168410. }
  168411. for (c = 0; c < channels; c++)
  168412. {
  168413. if (shift[c] <= 0)
  168414. shift[c] = 0;
  168415. else
  168416. value = 1;
  168417. }
  168418. if (!value)
  168419. return;
  168420. switch (row_info->bit_depth)
  168421. {
  168422. case 2:
  168423. {
  168424. png_bytep bp;
  168425. png_uint_32 i;
  168426. png_uint_32 istop = row_info->rowbytes;
  168427. for (bp = row, i = 0; i < istop; i++)
  168428. {
  168429. *bp >>= 1;
  168430. *bp++ &= 0x55;
  168431. }
  168432. break;
  168433. }
  168434. case 4:
  168435. {
  168436. png_bytep bp = row;
  168437. png_uint_32 i;
  168438. png_uint_32 istop = row_info->rowbytes;
  168439. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168440. (png_byte)((int)0xf >> shift[0]));
  168441. for (i = 0; i < istop; i++)
  168442. {
  168443. *bp >>= shift[0];
  168444. *bp++ &= mask;
  168445. }
  168446. break;
  168447. }
  168448. case 8:
  168449. {
  168450. png_bytep bp = row;
  168451. png_uint_32 i;
  168452. png_uint_32 istop = row_width * channels;
  168453. for (i = 0; i < istop; i++)
  168454. {
  168455. *bp++ >>= shift[i%channels];
  168456. }
  168457. break;
  168458. }
  168459. case 16:
  168460. {
  168461. png_bytep bp = row;
  168462. png_uint_32 i;
  168463. png_uint_32 istop = channels * row_width;
  168464. for (i = 0; i < istop; i++)
  168465. {
  168466. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168467. value >>= shift[i%channels];
  168468. *bp++ = (png_byte)(value >> 8);
  168469. *bp++ = (png_byte)(value & 0xff);
  168470. }
  168471. break;
  168472. }
  168473. }
  168474. }
  168475. }
  168476. #endif
  168477. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168478. void /* PRIVATE */
  168479. png_do_chop(png_row_infop row_info, png_bytep row)
  168480. {
  168481. png_debug(1, "in png_do_chop\n");
  168482. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168483. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168484. #else
  168485. if (row_info->bit_depth == 16)
  168486. #endif
  168487. {
  168488. png_bytep sp = row;
  168489. png_bytep dp = row;
  168490. png_uint_32 i;
  168491. png_uint_32 istop = row_info->width * row_info->channels;
  168492. for (i = 0; i<istop; i++, sp += 2, dp++)
  168493. {
  168494. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168495. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168496. #else
  168497. *dp = *sp;
  168498. #endif
  168499. }
  168500. row_info->bit_depth = 8;
  168501. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168502. row_info->rowbytes = row_info->width * row_info->channels;
  168503. }
  168504. }
  168505. #endif
  168506. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168507. void /* PRIVATE */
  168508. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168509. {
  168510. png_debug(1, "in png_do_read_swap_alpha\n");
  168511. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168512. if (row != NULL && row_info != NULL)
  168513. #endif
  168514. {
  168515. png_uint_32 row_width = row_info->width;
  168516. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168517. {
  168518. if (row_info->bit_depth == 8)
  168519. {
  168520. png_bytep sp = row + row_info->rowbytes;
  168521. png_bytep dp = sp;
  168522. png_byte save;
  168523. png_uint_32 i;
  168524. for (i = 0; i < row_width; i++)
  168525. {
  168526. save = *(--sp);
  168527. *(--dp) = *(--sp);
  168528. *(--dp) = *(--sp);
  168529. *(--dp) = *(--sp);
  168530. *(--dp) = save;
  168531. }
  168532. }
  168533. else
  168534. {
  168535. png_bytep sp = row + row_info->rowbytes;
  168536. png_bytep dp = sp;
  168537. png_byte save[2];
  168538. png_uint_32 i;
  168539. for (i = 0; i < row_width; i++)
  168540. {
  168541. save[0] = *(--sp);
  168542. save[1] = *(--sp);
  168543. *(--dp) = *(--sp);
  168544. *(--dp) = *(--sp);
  168545. *(--dp) = *(--sp);
  168546. *(--dp) = *(--sp);
  168547. *(--dp) = *(--sp);
  168548. *(--dp) = *(--sp);
  168549. *(--dp) = save[0];
  168550. *(--dp) = save[1];
  168551. }
  168552. }
  168553. }
  168554. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168555. {
  168556. if (row_info->bit_depth == 8)
  168557. {
  168558. png_bytep sp = row + row_info->rowbytes;
  168559. png_bytep dp = sp;
  168560. png_byte save;
  168561. png_uint_32 i;
  168562. for (i = 0; i < row_width; i++)
  168563. {
  168564. save = *(--sp);
  168565. *(--dp) = *(--sp);
  168566. *(--dp) = save;
  168567. }
  168568. }
  168569. else
  168570. {
  168571. png_bytep sp = row + row_info->rowbytes;
  168572. png_bytep dp = sp;
  168573. png_byte save[2];
  168574. png_uint_32 i;
  168575. for (i = 0; i < row_width; i++)
  168576. {
  168577. save[0] = *(--sp);
  168578. save[1] = *(--sp);
  168579. *(--dp) = *(--sp);
  168580. *(--dp) = *(--sp);
  168581. *(--dp) = save[0];
  168582. *(--dp) = save[1];
  168583. }
  168584. }
  168585. }
  168586. }
  168587. }
  168588. #endif
  168589. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168590. void /* PRIVATE */
  168591. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168592. {
  168593. png_debug(1, "in png_do_read_invert_alpha\n");
  168594. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168595. if (row != NULL && row_info != NULL)
  168596. #endif
  168597. {
  168598. png_uint_32 row_width = row_info->width;
  168599. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168600. {
  168601. if (row_info->bit_depth == 8)
  168602. {
  168603. png_bytep sp = row + row_info->rowbytes;
  168604. png_bytep dp = sp;
  168605. png_uint_32 i;
  168606. for (i = 0; i < row_width; i++)
  168607. {
  168608. *(--dp) = (png_byte)(255 - *(--sp));
  168609. sp-=3;
  168610. dp=sp;
  168611. }
  168612. }
  168613. else
  168614. {
  168615. png_bytep sp = row + row_info->rowbytes;
  168616. png_bytep dp = sp;
  168617. png_uint_32 i;
  168618. for (i = 0; i < row_width; i++)
  168619. {
  168620. *(--dp) = (png_byte)(255 - *(--sp));
  168621. *(--dp) = (png_byte)(255 - *(--sp));
  168622. sp-=6;
  168623. dp=sp;
  168624. }
  168625. }
  168626. }
  168627. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168628. {
  168629. if (row_info->bit_depth == 8)
  168630. {
  168631. png_bytep sp = row + row_info->rowbytes;
  168632. png_bytep dp = sp;
  168633. png_uint_32 i;
  168634. for (i = 0; i < row_width; i++)
  168635. {
  168636. *(--dp) = (png_byte)(255 - *(--sp));
  168637. *(--dp) = *(--sp);
  168638. }
  168639. }
  168640. else
  168641. {
  168642. png_bytep sp = row + row_info->rowbytes;
  168643. png_bytep dp = sp;
  168644. png_uint_32 i;
  168645. for (i = 0; i < row_width; i++)
  168646. {
  168647. *(--dp) = (png_byte)(255 - *(--sp));
  168648. *(--dp) = (png_byte)(255 - *(--sp));
  168649. sp-=2;
  168650. dp=sp;
  168651. }
  168652. }
  168653. }
  168654. }
  168655. }
  168656. #endif
  168657. #if defined(PNG_READ_FILLER_SUPPORTED)
  168658. void /* PRIVATE */
  168659. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168660. png_uint_32 filler, png_uint_32 flags)
  168661. {
  168662. png_uint_32 i;
  168663. png_uint_32 row_width = row_info->width;
  168664. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168665. png_byte lo_filler = (png_byte)(filler & 0xff);
  168666. png_debug(1, "in png_do_read_filler\n");
  168667. if (
  168668. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168669. row != NULL && row_info != NULL &&
  168670. #endif
  168671. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168672. {
  168673. if(row_info->bit_depth == 8)
  168674. {
  168675. if (flags & PNG_FLAG_FILLER_AFTER)
  168676. {
  168677. png_bytep sp = row + (png_size_t)row_width;
  168678. png_bytep dp = sp + (png_size_t)row_width;
  168679. for (i = 1; i < row_width; i++)
  168680. {
  168681. *(--dp) = lo_filler;
  168682. *(--dp) = *(--sp);
  168683. }
  168684. *(--dp) = lo_filler;
  168685. row_info->channels = 2;
  168686. row_info->pixel_depth = 16;
  168687. row_info->rowbytes = row_width * 2;
  168688. }
  168689. else
  168690. {
  168691. png_bytep sp = row + (png_size_t)row_width;
  168692. png_bytep dp = sp + (png_size_t)row_width;
  168693. for (i = 0; i < row_width; i++)
  168694. {
  168695. *(--dp) = *(--sp);
  168696. *(--dp) = lo_filler;
  168697. }
  168698. row_info->channels = 2;
  168699. row_info->pixel_depth = 16;
  168700. row_info->rowbytes = row_width * 2;
  168701. }
  168702. }
  168703. else if(row_info->bit_depth == 16)
  168704. {
  168705. if (flags & PNG_FLAG_FILLER_AFTER)
  168706. {
  168707. png_bytep sp = row + (png_size_t)row_width * 2;
  168708. png_bytep dp = sp + (png_size_t)row_width * 2;
  168709. for (i = 1; i < row_width; i++)
  168710. {
  168711. *(--dp) = hi_filler;
  168712. *(--dp) = lo_filler;
  168713. *(--dp) = *(--sp);
  168714. *(--dp) = *(--sp);
  168715. }
  168716. *(--dp) = hi_filler;
  168717. *(--dp) = lo_filler;
  168718. row_info->channels = 2;
  168719. row_info->pixel_depth = 32;
  168720. row_info->rowbytes = row_width * 4;
  168721. }
  168722. else
  168723. {
  168724. png_bytep sp = row + (png_size_t)row_width * 2;
  168725. png_bytep dp = sp + (png_size_t)row_width * 2;
  168726. for (i = 0; i < row_width; i++)
  168727. {
  168728. *(--dp) = *(--sp);
  168729. *(--dp) = *(--sp);
  168730. *(--dp) = hi_filler;
  168731. *(--dp) = lo_filler;
  168732. }
  168733. row_info->channels = 2;
  168734. row_info->pixel_depth = 32;
  168735. row_info->rowbytes = row_width * 4;
  168736. }
  168737. }
  168738. } /* COLOR_TYPE == GRAY */
  168739. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168740. {
  168741. if(row_info->bit_depth == 8)
  168742. {
  168743. if (flags & PNG_FLAG_FILLER_AFTER)
  168744. {
  168745. png_bytep sp = row + (png_size_t)row_width * 3;
  168746. png_bytep dp = sp + (png_size_t)row_width;
  168747. for (i = 1; i < row_width; i++)
  168748. {
  168749. *(--dp) = lo_filler;
  168750. *(--dp) = *(--sp);
  168751. *(--dp) = *(--sp);
  168752. *(--dp) = *(--sp);
  168753. }
  168754. *(--dp) = lo_filler;
  168755. row_info->channels = 4;
  168756. row_info->pixel_depth = 32;
  168757. row_info->rowbytes = row_width * 4;
  168758. }
  168759. else
  168760. {
  168761. png_bytep sp = row + (png_size_t)row_width * 3;
  168762. png_bytep dp = sp + (png_size_t)row_width;
  168763. for (i = 0; i < row_width; i++)
  168764. {
  168765. *(--dp) = *(--sp);
  168766. *(--dp) = *(--sp);
  168767. *(--dp) = *(--sp);
  168768. *(--dp) = lo_filler;
  168769. }
  168770. row_info->channels = 4;
  168771. row_info->pixel_depth = 32;
  168772. row_info->rowbytes = row_width * 4;
  168773. }
  168774. }
  168775. else if(row_info->bit_depth == 16)
  168776. {
  168777. if (flags & PNG_FLAG_FILLER_AFTER)
  168778. {
  168779. png_bytep sp = row + (png_size_t)row_width * 6;
  168780. png_bytep dp = sp + (png_size_t)row_width * 2;
  168781. for (i = 1; i < row_width; i++)
  168782. {
  168783. *(--dp) = hi_filler;
  168784. *(--dp) = lo_filler;
  168785. *(--dp) = *(--sp);
  168786. *(--dp) = *(--sp);
  168787. *(--dp) = *(--sp);
  168788. *(--dp) = *(--sp);
  168789. *(--dp) = *(--sp);
  168790. *(--dp) = *(--sp);
  168791. }
  168792. *(--dp) = hi_filler;
  168793. *(--dp) = lo_filler;
  168794. row_info->channels = 4;
  168795. row_info->pixel_depth = 64;
  168796. row_info->rowbytes = row_width * 8;
  168797. }
  168798. else
  168799. {
  168800. png_bytep sp = row + (png_size_t)row_width * 6;
  168801. png_bytep dp = sp + (png_size_t)row_width * 2;
  168802. for (i = 0; i < row_width; i++)
  168803. {
  168804. *(--dp) = *(--sp);
  168805. *(--dp) = *(--sp);
  168806. *(--dp) = *(--sp);
  168807. *(--dp) = *(--sp);
  168808. *(--dp) = *(--sp);
  168809. *(--dp) = *(--sp);
  168810. *(--dp) = hi_filler;
  168811. *(--dp) = lo_filler;
  168812. }
  168813. row_info->channels = 4;
  168814. row_info->pixel_depth = 64;
  168815. row_info->rowbytes = row_width * 8;
  168816. }
  168817. }
  168818. } /* COLOR_TYPE == RGB */
  168819. }
  168820. #endif
  168821. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168822. void /* PRIVATE */
  168823. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  168824. {
  168825. png_uint_32 i;
  168826. png_uint_32 row_width = row_info->width;
  168827. png_debug(1, "in png_do_gray_to_rgb\n");
  168828. if (row_info->bit_depth >= 8 &&
  168829. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168830. row != NULL && row_info != NULL &&
  168831. #endif
  168832. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  168833. {
  168834. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168835. {
  168836. if (row_info->bit_depth == 8)
  168837. {
  168838. png_bytep sp = row + (png_size_t)row_width - 1;
  168839. png_bytep dp = sp + (png_size_t)row_width * 2;
  168840. for (i = 0; i < row_width; i++)
  168841. {
  168842. *(dp--) = *sp;
  168843. *(dp--) = *sp;
  168844. *(dp--) = *(sp--);
  168845. }
  168846. }
  168847. else
  168848. {
  168849. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168850. png_bytep dp = sp + (png_size_t)row_width * 4;
  168851. for (i = 0; i < row_width; i++)
  168852. {
  168853. *(dp--) = *sp;
  168854. *(dp--) = *(sp - 1);
  168855. *(dp--) = *sp;
  168856. *(dp--) = *(sp - 1);
  168857. *(dp--) = *(sp--);
  168858. *(dp--) = *(sp--);
  168859. }
  168860. }
  168861. }
  168862. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168863. {
  168864. if (row_info->bit_depth == 8)
  168865. {
  168866. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168867. png_bytep dp = sp + (png_size_t)row_width * 2;
  168868. for (i = 0; i < row_width; i++)
  168869. {
  168870. *(dp--) = *(sp--);
  168871. *(dp--) = *sp;
  168872. *(dp--) = *sp;
  168873. *(dp--) = *(sp--);
  168874. }
  168875. }
  168876. else
  168877. {
  168878. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  168879. png_bytep dp = sp + (png_size_t)row_width * 4;
  168880. for (i = 0; i < row_width; i++)
  168881. {
  168882. *(dp--) = *(sp--);
  168883. *(dp--) = *(sp--);
  168884. *(dp--) = *sp;
  168885. *(dp--) = *(sp - 1);
  168886. *(dp--) = *sp;
  168887. *(dp--) = *(sp - 1);
  168888. *(dp--) = *(sp--);
  168889. *(dp--) = *(sp--);
  168890. }
  168891. }
  168892. }
  168893. row_info->channels += (png_byte)2;
  168894. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  168895. row_info->pixel_depth = (png_byte)(row_info->channels *
  168896. row_info->bit_depth);
  168897. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168898. }
  168899. }
  168900. #endif
  168901. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168902. int /* PRIVATE */
  168903. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  168904. {
  168905. png_uint_32 i;
  168906. png_uint_32 row_width = row_info->width;
  168907. int rgb_error = 0;
  168908. png_debug(1, "in png_do_rgb_to_gray\n");
  168909. if (
  168910. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168911. row != NULL && row_info != NULL &&
  168912. #endif
  168913. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  168914. {
  168915. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  168916. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  168917. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  168918. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168919. {
  168920. if (row_info->bit_depth == 8)
  168921. {
  168922. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168923. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168924. {
  168925. png_bytep sp = row;
  168926. png_bytep dp = row;
  168927. for (i = 0; i < row_width; i++)
  168928. {
  168929. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168930. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168931. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168932. if(red != green || red != blue)
  168933. {
  168934. rgb_error |= 1;
  168935. *(dp++) = png_ptr->gamma_from_1[
  168936. (rc*red+gc*green+bc*blue)>>15];
  168937. }
  168938. else
  168939. *(dp++) = *(sp-1);
  168940. }
  168941. }
  168942. else
  168943. #endif
  168944. {
  168945. png_bytep sp = row;
  168946. png_bytep dp = row;
  168947. for (i = 0; i < row_width; i++)
  168948. {
  168949. png_byte red = *(sp++);
  168950. png_byte green = *(sp++);
  168951. png_byte blue = *(sp++);
  168952. if(red != green || red != blue)
  168953. {
  168954. rgb_error |= 1;
  168955. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  168956. }
  168957. else
  168958. *(dp++) = *(sp-1);
  168959. }
  168960. }
  168961. }
  168962. else /* RGB bit_depth == 16 */
  168963. {
  168964. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168965. if (png_ptr->gamma_16_to_1 != NULL &&
  168966. png_ptr->gamma_16_from_1 != NULL)
  168967. {
  168968. png_bytep sp = row;
  168969. png_bytep dp = row;
  168970. for (i = 0; i < row_width; i++)
  168971. {
  168972. png_uint_16 red, green, blue, w;
  168973. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168974. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168975. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168976. if(red == green && red == blue)
  168977. w = red;
  168978. else
  168979. {
  168980. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168981. png_ptr->gamma_shift][red>>8];
  168982. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168983. png_ptr->gamma_shift][green>>8];
  168984. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168985. png_ptr->gamma_shift][blue>>8];
  168986. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  168987. + bc*blue_1)>>15);
  168988. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168989. png_ptr->gamma_shift][gray16 >> 8];
  168990. rgb_error |= 1;
  168991. }
  168992. *(dp++) = (png_byte)((w>>8) & 0xff);
  168993. *(dp++) = (png_byte)(w & 0xff);
  168994. }
  168995. }
  168996. else
  168997. #endif
  168998. {
  168999. png_bytep sp = row;
  169000. png_bytep dp = row;
  169001. for (i = 0; i < row_width; i++)
  169002. {
  169003. png_uint_16 red, green, blue, gray16;
  169004. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169005. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169006. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169007. if(red != green || red != blue)
  169008. rgb_error |= 1;
  169009. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169010. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169011. *(dp++) = (png_byte)(gray16 & 0xff);
  169012. }
  169013. }
  169014. }
  169015. }
  169016. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  169017. {
  169018. if (row_info->bit_depth == 8)
  169019. {
  169020. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169021. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169022. {
  169023. png_bytep sp = row;
  169024. png_bytep dp = row;
  169025. for (i = 0; i < row_width; i++)
  169026. {
  169027. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169028. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169029. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169030. if(red != green || red != blue)
  169031. rgb_error |= 1;
  169032. *(dp++) = png_ptr->gamma_from_1
  169033. [(rc*red + gc*green + bc*blue)>>15];
  169034. *(dp++) = *(sp++); /* alpha */
  169035. }
  169036. }
  169037. else
  169038. #endif
  169039. {
  169040. png_bytep sp = row;
  169041. png_bytep dp = row;
  169042. for (i = 0; i < row_width; i++)
  169043. {
  169044. png_byte red = *(sp++);
  169045. png_byte green = *(sp++);
  169046. png_byte blue = *(sp++);
  169047. if(red != green || red != blue)
  169048. rgb_error |= 1;
  169049. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  169050. *(dp++) = *(sp++); /* alpha */
  169051. }
  169052. }
  169053. }
  169054. else /* RGBA bit_depth == 16 */
  169055. {
  169056. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169057. if (png_ptr->gamma_16_to_1 != NULL &&
  169058. png_ptr->gamma_16_from_1 != NULL)
  169059. {
  169060. png_bytep sp = row;
  169061. png_bytep dp = row;
  169062. for (i = 0; i < row_width; i++)
  169063. {
  169064. png_uint_16 red, green, blue, w;
  169065. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169066. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169067. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169068. if(red == green && red == blue)
  169069. w = red;
  169070. else
  169071. {
  169072. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169073. png_ptr->gamma_shift][red>>8];
  169074. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169075. png_ptr->gamma_shift][green>>8];
  169076. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169077. png_ptr->gamma_shift][blue>>8];
  169078. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  169079. + gc * green_1 + bc * blue_1)>>15);
  169080. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169081. png_ptr->gamma_shift][gray16 >> 8];
  169082. rgb_error |= 1;
  169083. }
  169084. *(dp++) = (png_byte)((w>>8) & 0xff);
  169085. *(dp++) = (png_byte)(w & 0xff);
  169086. *(dp++) = *(sp++); /* alpha */
  169087. *(dp++) = *(sp++);
  169088. }
  169089. }
  169090. else
  169091. #endif
  169092. {
  169093. png_bytep sp = row;
  169094. png_bytep dp = row;
  169095. for (i = 0; i < row_width; i++)
  169096. {
  169097. png_uint_16 red, green, blue, gray16;
  169098. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169099. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169100. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169101. if(red != green || red != blue)
  169102. rgb_error |= 1;
  169103. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169104. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169105. *(dp++) = (png_byte)(gray16 & 0xff);
  169106. *(dp++) = *(sp++); /* alpha */
  169107. *(dp++) = *(sp++);
  169108. }
  169109. }
  169110. }
  169111. }
  169112. row_info->channels -= (png_byte)2;
  169113. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  169114. row_info->pixel_depth = (png_byte)(row_info->channels *
  169115. row_info->bit_depth);
  169116. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169117. }
  169118. return rgb_error;
  169119. }
  169120. #endif
  169121. void PNGAPI
  169122. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  169123. {
  169124. int num_palette;
  169125. int color_inc;
  169126. int i;
  169127. int v;
  169128. png_debug(1, "in png_do_build_grayscale_palette\n");
  169129. if (palette == NULL)
  169130. return;
  169131. switch (bit_depth)
  169132. {
  169133. case 1:
  169134. num_palette = 2;
  169135. color_inc = 0xff;
  169136. break;
  169137. case 2:
  169138. num_palette = 4;
  169139. color_inc = 0x55;
  169140. break;
  169141. case 4:
  169142. num_palette = 16;
  169143. color_inc = 0x11;
  169144. break;
  169145. case 8:
  169146. num_palette = 256;
  169147. color_inc = 1;
  169148. break;
  169149. default:
  169150. num_palette = 0;
  169151. color_inc = 0;
  169152. break;
  169153. }
  169154. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  169155. {
  169156. palette[i].red = (png_byte)v;
  169157. palette[i].green = (png_byte)v;
  169158. palette[i].blue = (png_byte)v;
  169159. }
  169160. }
  169161. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  169162. void /* PRIVATE */
  169163. png_correct_palette(png_structp png_ptr, png_colorp palette,
  169164. int num_palette)
  169165. {
  169166. png_debug(1, "in png_correct_palette\n");
  169167. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  169168. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  169169. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  169170. {
  169171. png_color back, back_1;
  169172. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  169173. {
  169174. back.red = png_ptr->gamma_table[png_ptr->background.red];
  169175. back.green = png_ptr->gamma_table[png_ptr->background.green];
  169176. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  169177. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  169178. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  169179. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  169180. }
  169181. else
  169182. {
  169183. double g;
  169184. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  169185. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  169186. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  169187. {
  169188. back.red = png_ptr->background.red;
  169189. back.green = png_ptr->background.green;
  169190. back.blue = png_ptr->background.blue;
  169191. }
  169192. else
  169193. {
  169194. back.red =
  169195. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169196. 255.0 + 0.5);
  169197. back.green =
  169198. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169199. 255.0 + 0.5);
  169200. back.blue =
  169201. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169202. 255.0 + 0.5);
  169203. }
  169204. g = 1.0 / png_ptr->background_gamma;
  169205. back_1.red =
  169206. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169207. 255.0 + 0.5);
  169208. back_1.green =
  169209. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169210. 255.0 + 0.5);
  169211. back_1.blue =
  169212. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169213. 255.0 + 0.5);
  169214. }
  169215. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169216. {
  169217. png_uint_32 i;
  169218. for (i = 0; i < (png_uint_32)num_palette; i++)
  169219. {
  169220. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  169221. {
  169222. palette[i] = back;
  169223. }
  169224. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  169225. {
  169226. png_byte v, w;
  169227. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  169228. png_composite(w, v, png_ptr->trans[i], back_1.red);
  169229. palette[i].red = png_ptr->gamma_from_1[w];
  169230. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  169231. png_composite(w, v, png_ptr->trans[i], back_1.green);
  169232. palette[i].green = png_ptr->gamma_from_1[w];
  169233. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  169234. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  169235. palette[i].blue = png_ptr->gamma_from_1[w];
  169236. }
  169237. else
  169238. {
  169239. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169240. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169241. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169242. }
  169243. }
  169244. }
  169245. else
  169246. {
  169247. int i;
  169248. for (i = 0; i < num_palette; i++)
  169249. {
  169250. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  169251. {
  169252. palette[i] = back;
  169253. }
  169254. else
  169255. {
  169256. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169257. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169258. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169259. }
  169260. }
  169261. }
  169262. }
  169263. else
  169264. #endif
  169265. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169266. if (png_ptr->transformations & PNG_GAMMA)
  169267. {
  169268. int i;
  169269. for (i = 0; i < num_palette; i++)
  169270. {
  169271. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169272. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169273. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169274. }
  169275. }
  169276. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169277. else
  169278. #endif
  169279. #endif
  169280. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169281. if (png_ptr->transformations & PNG_BACKGROUND)
  169282. {
  169283. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169284. {
  169285. png_color back;
  169286. back.red = (png_byte)png_ptr->background.red;
  169287. back.green = (png_byte)png_ptr->background.green;
  169288. back.blue = (png_byte)png_ptr->background.blue;
  169289. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169290. {
  169291. if (png_ptr->trans[i] == 0)
  169292. {
  169293. palette[i].red = back.red;
  169294. palette[i].green = back.green;
  169295. palette[i].blue = back.blue;
  169296. }
  169297. else if (png_ptr->trans[i] != 0xff)
  169298. {
  169299. png_composite(palette[i].red, png_ptr->palette[i].red,
  169300. png_ptr->trans[i], back.red);
  169301. png_composite(palette[i].green, png_ptr->palette[i].green,
  169302. png_ptr->trans[i], back.green);
  169303. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169304. png_ptr->trans[i], back.blue);
  169305. }
  169306. }
  169307. }
  169308. else /* assume grayscale palette (what else could it be?) */
  169309. {
  169310. int i;
  169311. for (i = 0; i < num_palette; i++)
  169312. {
  169313. if (i == (png_byte)png_ptr->trans_values.gray)
  169314. {
  169315. palette[i].red = (png_byte)png_ptr->background.red;
  169316. palette[i].green = (png_byte)png_ptr->background.green;
  169317. palette[i].blue = (png_byte)png_ptr->background.blue;
  169318. }
  169319. }
  169320. }
  169321. }
  169322. #endif
  169323. }
  169324. #endif
  169325. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169326. void /* PRIVATE */
  169327. png_do_background(png_row_infop row_info, png_bytep row,
  169328. png_color_16p trans_values, png_color_16p background
  169329. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169330. , png_color_16p background_1,
  169331. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169332. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169333. png_uint_16pp gamma_16_to_1, int gamma_shift
  169334. #endif
  169335. )
  169336. {
  169337. png_bytep sp, dp;
  169338. png_uint_32 i;
  169339. png_uint_32 row_width=row_info->width;
  169340. int shift;
  169341. png_debug(1, "in png_do_background\n");
  169342. if (background != NULL &&
  169343. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169344. row != NULL && row_info != NULL &&
  169345. #endif
  169346. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169347. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169348. {
  169349. switch (row_info->color_type)
  169350. {
  169351. case PNG_COLOR_TYPE_GRAY:
  169352. {
  169353. switch (row_info->bit_depth)
  169354. {
  169355. case 1:
  169356. {
  169357. sp = row;
  169358. shift = 7;
  169359. for (i = 0; i < row_width; i++)
  169360. {
  169361. if ((png_uint_16)((*sp >> shift) & 0x01)
  169362. == trans_values->gray)
  169363. {
  169364. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169365. *sp |= (png_byte)(background->gray << shift);
  169366. }
  169367. if (!shift)
  169368. {
  169369. shift = 7;
  169370. sp++;
  169371. }
  169372. else
  169373. shift--;
  169374. }
  169375. break;
  169376. }
  169377. case 2:
  169378. {
  169379. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169380. if (gamma_table != NULL)
  169381. {
  169382. sp = row;
  169383. shift = 6;
  169384. for (i = 0; i < row_width; i++)
  169385. {
  169386. if ((png_uint_16)((*sp >> shift) & 0x03)
  169387. == trans_values->gray)
  169388. {
  169389. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169390. *sp |= (png_byte)(background->gray << shift);
  169391. }
  169392. else
  169393. {
  169394. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169395. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169396. (p << 4) | (p << 6)] >> 6) & 0x03);
  169397. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169398. *sp |= (png_byte)(g << shift);
  169399. }
  169400. if (!shift)
  169401. {
  169402. shift = 6;
  169403. sp++;
  169404. }
  169405. else
  169406. shift -= 2;
  169407. }
  169408. }
  169409. else
  169410. #endif
  169411. {
  169412. sp = row;
  169413. shift = 6;
  169414. for (i = 0; i < row_width; i++)
  169415. {
  169416. if ((png_uint_16)((*sp >> shift) & 0x03)
  169417. == trans_values->gray)
  169418. {
  169419. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169420. *sp |= (png_byte)(background->gray << shift);
  169421. }
  169422. if (!shift)
  169423. {
  169424. shift = 6;
  169425. sp++;
  169426. }
  169427. else
  169428. shift -= 2;
  169429. }
  169430. }
  169431. break;
  169432. }
  169433. case 4:
  169434. {
  169435. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169436. if (gamma_table != NULL)
  169437. {
  169438. sp = row;
  169439. shift = 4;
  169440. for (i = 0; i < row_width; i++)
  169441. {
  169442. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169443. == trans_values->gray)
  169444. {
  169445. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169446. *sp |= (png_byte)(background->gray << shift);
  169447. }
  169448. else
  169449. {
  169450. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169451. png_byte g = (png_byte)((gamma_table[p |
  169452. (p << 4)] >> 4) & 0x0f);
  169453. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169454. *sp |= (png_byte)(g << shift);
  169455. }
  169456. if (!shift)
  169457. {
  169458. shift = 4;
  169459. sp++;
  169460. }
  169461. else
  169462. shift -= 4;
  169463. }
  169464. }
  169465. else
  169466. #endif
  169467. {
  169468. sp = row;
  169469. shift = 4;
  169470. for (i = 0; i < row_width; i++)
  169471. {
  169472. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169473. == trans_values->gray)
  169474. {
  169475. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169476. *sp |= (png_byte)(background->gray << shift);
  169477. }
  169478. if (!shift)
  169479. {
  169480. shift = 4;
  169481. sp++;
  169482. }
  169483. else
  169484. shift -= 4;
  169485. }
  169486. }
  169487. break;
  169488. }
  169489. case 8:
  169490. {
  169491. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169492. if (gamma_table != NULL)
  169493. {
  169494. sp = row;
  169495. for (i = 0; i < row_width; i++, sp++)
  169496. {
  169497. if (*sp == trans_values->gray)
  169498. {
  169499. *sp = (png_byte)background->gray;
  169500. }
  169501. else
  169502. {
  169503. *sp = gamma_table[*sp];
  169504. }
  169505. }
  169506. }
  169507. else
  169508. #endif
  169509. {
  169510. sp = row;
  169511. for (i = 0; i < row_width; i++, sp++)
  169512. {
  169513. if (*sp == trans_values->gray)
  169514. {
  169515. *sp = (png_byte)background->gray;
  169516. }
  169517. }
  169518. }
  169519. break;
  169520. }
  169521. case 16:
  169522. {
  169523. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169524. if (gamma_16 != NULL)
  169525. {
  169526. sp = row;
  169527. for (i = 0; i < row_width; i++, sp += 2)
  169528. {
  169529. png_uint_16 v;
  169530. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169531. if (v == trans_values->gray)
  169532. {
  169533. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169534. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169535. }
  169536. else
  169537. {
  169538. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169539. *sp = (png_byte)((v >> 8) & 0xff);
  169540. *(sp + 1) = (png_byte)(v & 0xff);
  169541. }
  169542. }
  169543. }
  169544. else
  169545. #endif
  169546. {
  169547. sp = row;
  169548. for (i = 0; i < row_width; i++, sp += 2)
  169549. {
  169550. png_uint_16 v;
  169551. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169552. if (v == trans_values->gray)
  169553. {
  169554. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169555. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169556. }
  169557. }
  169558. }
  169559. break;
  169560. }
  169561. }
  169562. break;
  169563. }
  169564. case PNG_COLOR_TYPE_RGB:
  169565. {
  169566. if (row_info->bit_depth == 8)
  169567. {
  169568. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169569. if (gamma_table != NULL)
  169570. {
  169571. sp = row;
  169572. for (i = 0; i < row_width; i++, sp += 3)
  169573. {
  169574. if (*sp == trans_values->red &&
  169575. *(sp + 1) == trans_values->green &&
  169576. *(sp + 2) == trans_values->blue)
  169577. {
  169578. *sp = (png_byte)background->red;
  169579. *(sp + 1) = (png_byte)background->green;
  169580. *(sp + 2) = (png_byte)background->blue;
  169581. }
  169582. else
  169583. {
  169584. *sp = gamma_table[*sp];
  169585. *(sp + 1) = gamma_table[*(sp + 1)];
  169586. *(sp + 2) = gamma_table[*(sp + 2)];
  169587. }
  169588. }
  169589. }
  169590. else
  169591. #endif
  169592. {
  169593. sp = row;
  169594. for (i = 0; i < row_width; i++, sp += 3)
  169595. {
  169596. if (*sp == trans_values->red &&
  169597. *(sp + 1) == trans_values->green &&
  169598. *(sp + 2) == trans_values->blue)
  169599. {
  169600. *sp = (png_byte)background->red;
  169601. *(sp + 1) = (png_byte)background->green;
  169602. *(sp + 2) = (png_byte)background->blue;
  169603. }
  169604. }
  169605. }
  169606. }
  169607. else /* if (row_info->bit_depth == 16) */
  169608. {
  169609. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169610. if (gamma_16 != NULL)
  169611. {
  169612. sp = row;
  169613. for (i = 0; i < row_width; i++, sp += 6)
  169614. {
  169615. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169616. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169617. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169618. if (r == trans_values->red && g == trans_values->green &&
  169619. b == trans_values->blue)
  169620. {
  169621. *sp = (png_byte)((background->red >> 8) & 0xff);
  169622. *(sp + 1) = (png_byte)(background->red & 0xff);
  169623. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169624. *(sp + 3) = (png_byte)(background->green & 0xff);
  169625. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169626. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169627. }
  169628. else
  169629. {
  169630. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169631. *sp = (png_byte)((v >> 8) & 0xff);
  169632. *(sp + 1) = (png_byte)(v & 0xff);
  169633. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169634. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169635. *(sp + 3) = (png_byte)(v & 0xff);
  169636. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169637. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169638. *(sp + 5) = (png_byte)(v & 0xff);
  169639. }
  169640. }
  169641. }
  169642. else
  169643. #endif
  169644. {
  169645. sp = row;
  169646. for (i = 0; i < row_width; i++, sp += 6)
  169647. {
  169648. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  169649. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169650. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169651. if (r == trans_values->red && g == trans_values->green &&
  169652. b == trans_values->blue)
  169653. {
  169654. *sp = (png_byte)((background->red >> 8) & 0xff);
  169655. *(sp + 1) = (png_byte)(background->red & 0xff);
  169656. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169657. *(sp + 3) = (png_byte)(background->green & 0xff);
  169658. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169659. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169660. }
  169661. }
  169662. }
  169663. }
  169664. break;
  169665. }
  169666. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169667. {
  169668. if (row_info->bit_depth == 8)
  169669. {
  169670. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169671. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169672. gamma_table != NULL)
  169673. {
  169674. sp = row;
  169675. dp = row;
  169676. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169677. {
  169678. png_uint_16 a = *(sp + 1);
  169679. if (a == 0xff)
  169680. {
  169681. *dp = gamma_table[*sp];
  169682. }
  169683. else if (a == 0)
  169684. {
  169685. *dp = (png_byte)background->gray;
  169686. }
  169687. else
  169688. {
  169689. png_byte v, w;
  169690. v = gamma_to_1[*sp];
  169691. png_composite(w, v, a, background_1->gray);
  169692. *dp = gamma_from_1[w];
  169693. }
  169694. }
  169695. }
  169696. else
  169697. #endif
  169698. {
  169699. sp = row;
  169700. dp = row;
  169701. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169702. {
  169703. png_byte a = *(sp + 1);
  169704. if (a == 0xff)
  169705. {
  169706. *dp = *sp;
  169707. }
  169708. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169709. else if (a == 0)
  169710. {
  169711. *dp = (png_byte)background->gray;
  169712. }
  169713. else
  169714. {
  169715. png_composite(*dp, *sp, a, background_1->gray);
  169716. }
  169717. #else
  169718. *dp = (png_byte)background->gray;
  169719. #endif
  169720. }
  169721. }
  169722. }
  169723. else /* if (png_ptr->bit_depth == 16) */
  169724. {
  169725. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169726. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169727. gamma_16_to_1 != NULL)
  169728. {
  169729. sp = row;
  169730. dp = row;
  169731. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169732. {
  169733. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169734. if (a == (png_uint_16)0xffff)
  169735. {
  169736. png_uint_16 v;
  169737. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169738. *dp = (png_byte)((v >> 8) & 0xff);
  169739. *(dp + 1) = (png_byte)(v & 0xff);
  169740. }
  169741. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169742. else if (a == 0)
  169743. #else
  169744. else
  169745. #endif
  169746. {
  169747. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169748. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169749. }
  169750. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169751. else
  169752. {
  169753. png_uint_16 g, v, w;
  169754. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169755. png_composite_16(v, g, a, background_1->gray);
  169756. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  169757. *dp = (png_byte)((w >> 8) & 0xff);
  169758. *(dp + 1) = (png_byte)(w & 0xff);
  169759. }
  169760. #endif
  169761. }
  169762. }
  169763. else
  169764. #endif
  169765. {
  169766. sp = row;
  169767. dp = row;
  169768. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169769. {
  169770. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169771. if (a == (png_uint_16)0xffff)
  169772. {
  169773. png_memcpy(dp, sp, 2);
  169774. }
  169775. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169776. else if (a == 0)
  169777. #else
  169778. else
  169779. #endif
  169780. {
  169781. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169782. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169783. }
  169784. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169785. else
  169786. {
  169787. png_uint_16 g, v;
  169788. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169789. png_composite_16(v, g, a, background_1->gray);
  169790. *dp = (png_byte)((v >> 8) & 0xff);
  169791. *(dp + 1) = (png_byte)(v & 0xff);
  169792. }
  169793. #endif
  169794. }
  169795. }
  169796. }
  169797. break;
  169798. }
  169799. case PNG_COLOR_TYPE_RGB_ALPHA:
  169800. {
  169801. if (row_info->bit_depth == 8)
  169802. {
  169803. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169804. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169805. gamma_table != NULL)
  169806. {
  169807. sp = row;
  169808. dp = row;
  169809. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169810. {
  169811. png_byte a = *(sp + 3);
  169812. if (a == 0xff)
  169813. {
  169814. *dp = gamma_table[*sp];
  169815. *(dp + 1) = gamma_table[*(sp + 1)];
  169816. *(dp + 2) = gamma_table[*(sp + 2)];
  169817. }
  169818. else if (a == 0)
  169819. {
  169820. *dp = (png_byte)background->red;
  169821. *(dp + 1) = (png_byte)background->green;
  169822. *(dp + 2) = (png_byte)background->blue;
  169823. }
  169824. else
  169825. {
  169826. png_byte v, w;
  169827. v = gamma_to_1[*sp];
  169828. png_composite(w, v, a, background_1->red);
  169829. *dp = gamma_from_1[w];
  169830. v = gamma_to_1[*(sp + 1)];
  169831. png_composite(w, v, a, background_1->green);
  169832. *(dp + 1) = gamma_from_1[w];
  169833. v = gamma_to_1[*(sp + 2)];
  169834. png_composite(w, v, a, background_1->blue);
  169835. *(dp + 2) = gamma_from_1[w];
  169836. }
  169837. }
  169838. }
  169839. else
  169840. #endif
  169841. {
  169842. sp = row;
  169843. dp = row;
  169844. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169845. {
  169846. png_byte a = *(sp + 3);
  169847. if (a == 0xff)
  169848. {
  169849. *dp = *sp;
  169850. *(dp + 1) = *(sp + 1);
  169851. *(dp + 2) = *(sp + 2);
  169852. }
  169853. else if (a == 0)
  169854. {
  169855. *dp = (png_byte)background->red;
  169856. *(dp + 1) = (png_byte)background->green;
  169857. *(dp + 2) = (png_byte)background->blue;
  169858. }
  169859. else
  169860. {
  169861. png_composite(*dp, *sp, a, background->red);
  169862. png_composite(*(dp + 1), *(sp + 1), a,
  169863. background->green);
  169864. png_composite(*(dp + 2), *(sp + 2), a,
  169865. background->blue);
  169866. }
  169867. }
  169868. }
  169869. }
  169870. else /* if (row_info->bit_depth == 16) */
  169871. {
  169872. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169873. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169874. gamma_16_to_1 != NULL)
  169875. {
  169876. sp = row;
  169877. dp = row;
  169878. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169879. {
  169880. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169881. << 8) + (png_uint_16)(*(sp + 7)));
  169882. if (a == (png_uint_16)0xffff)
  169883. {
  169884. png_uint_16 v;
  169885. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169886. *dp = (png_byte)((v >> 8) & 0xff);
  169887. *(dp + 1) = (png_byte)(v & 0xff);
  169888. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169889. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169890. *(dp + 3) = (png_byte)(v & 0xff);
  169891. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169892. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169893. *(dp + 5) = (png_byte)(v & 0xff);
  169894. }
  169895. else if (a == 0)
  169896. {
  169897. *dp = (png_byte)((background->red >> 8) & 0xff);
  169898. *(dp + 1) = (png_byte)(background->red & 0xff);
  169899. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169900. *(dp + 3) = (png_byte)(background->green & 0xff);
  169901. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169902. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169903. }
  169904. else
  169905. {
  169906. png_uint_16 v, w, x;
  169907. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169908. png_composite_16(w, v, a, background_1->red);
  169909. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169910. *dp = (png_byte)((x >> 8) & 0xff);
  169911. *(dp + 1) = (png_byte)(x & 0xff);
  169912. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169913. png_composite_16(w, v, a, background_1->green);
  169914. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169915. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  169916. *(dp + 3) = (png_byte)(x & 0xff);
  169917. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169918. png_composite_16(w, v, a, background_1->blue);
  169919. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  169920. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  169921. *(dp + 5) = (png_byte)(x & 0xff);
  169922. }
  169923. }
  169924. }
  169925. else
  169926. #endif
  169927. {
  169928. sp = row;
  169929. dp = row;
  169930. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169931. {
  169932. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169933. << 8) + (png_uint_16)(*(sp + 7)));
  169934. if (a == (png_uint_16)0xffff)
  169935. {
  169936. png_memcpy(dp, sp, 6);
  169937. }
  169938. else if (a == 0)
  169939. {
  169940. *dp = (png_byte)((background->red >> 8) & 0xff);
  169941. *(dp + 1) = (png_byte)(background->red & 0xff);
  169942. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169943. *(dp + 3) = (png_byte)(background->green & 0xff);
  169944. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169945. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169946. }
  169947. else
  169948. {
  169949. png_uint_16 v;
  169950. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169951. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  169952. + *(sp + 3));
  169953. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  169954. + *(sp + 5));
  169955. png_composite_16(v, r, a, background->red);
  169956. *dp = (png_byte)((v >> 8) & 0xff);
  169957. *(dp + 1) = (png_byte)(v & 0xff);
  169958. png_composite_16(v, g, a, background->green);
  169959. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169960. *(dp + 3) = (png_byte)(v & 0xff);
  169961. png_composite_16(v, b, a, background->blue);
  169962. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169963. *(dp + 5) = (png_byte)(v & 0xff);
  169964. }
  169965. }
  169966. }
  169967. }
  169968. break;
  169969. }
  169970. }
  169971. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  169972. {
  169973. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  169974. row_info->channels--;
  169975. row_info->pixel_depth = (png_byte)(row_info->channels *
  169976. row_info->bit_depth);
  169977. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169978. }
  169979. }
  169980. }
  169981. #endif
  169982. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169983. void /* PRIVATE */
  169984. png_do_gamma(png_row_infop row_info, png_bytep row,
  169985. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  169986. int gamma_shift)
  169987. {
  169988. png_bytep sp;
  169989. png_uint_32 i;
  169990. png_uint_32 row_width=row_info->width;
  169991. png_debug(1, "in png_do_gamma\n");
  169992. if (
  169993. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169994. row != NULL && row_info != NULL &&
  169995. #endif
  169996. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  169997. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  169998. {
  169999. switch (row_info->color_type)
  170000. {
  170001. case PNG_COLOR_TYPE_RGB:
  170002. {
  170003. if (row_info->bit_depth == 8)
  170004. {
  170005. sp = row;
  170006. for (i = 0; i < row_width; i++)
  170007. {
  170008. *sp = gamma_table[*sp];
  170009. sp++;
  170010. *sp = gamma_table[*sp];
  170011. sp++;
  170012. *sp = gamma_table[*sp];
  170013. sp++;
  170014. }
  170015. }
  170016. else /* if (row_info->bit_depth == 16) */
  170017. {
  170018. sp = row;
  170019. for (i = 0; i < row_width; i++)
  170020. {
  170021. png_uint_16 v;
  170022. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170023. *sp = (png_byte)((v >> 8) & 0xff);
  170024. *(sp + 1) = (png_byte)(v & 0xff);
  170025. sp += 2;
  170026. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170027. *sp = (png_byte)((v >> 8) & 0xff);
  170028. *(sp + 1) = (png_byte)(v & 0xff);
  170029. sp += 2;
  170030. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170031. *sp = (png_byte)((v >> 8) & 0xff);
  170032. *(sp + 1) = (png_byte)(v & 0xff);
  170033. sp += 2;
  170034. }
  170035. }
  170036. break;
  170037. }
  170038. case PNG_COLOR_TYPE_RGB_ALPHA:
  170039. {
  170040. if (row_info->bit_depth == 8)
  170041. {
  170042. sp = row;
  170043. for (i = 0; i < row_width; i++)
  170044. {
  170045. *sp = gamma_table[*sp];
  170046. sp++;
  170047. *sp = gamma_table[*sp];
  170048. sp++;
  170049. *sp = gamma_table[*sp];
  170050. sp++;
  170051. sp++;
  170052. }
  170053. }
  170054. else /* if (row_info->bit_depth == 16) */
  170055. {
  170056. sp = row;
  170057. for (i = 0; i < row_width; i++)
  170058. {
  170059. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170060. *sp = (png_byte)((v >> 8) & 0xff);
  170061. *(sp + 1) = (png_byte)(v & 0xff);
  170062. sp += 2;
  170063. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170064. *sp = (png_byte)((v >> 8) & 0xff);
  170065. *(sp + 1) = (png_byte)(v & 0xff);
  170066. sp += 2;
  170067. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170068. *sp = (png_byte)((v >> 8) & 0xff);
  170069. *(sp + 1) = (png_byte)(v & 0xff);
  170070. sp += 4;
  170071. }
  170072. }
  170073. break;
  170074. }
  170075. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170076. {
  170077. if (row_info->bit_depth == 8)
  170078. {
  170079. sp = row;
  170080. for (i = 0; i < row_width; i++)
  170081. {
  170082. *sp = gamma_table[*sp];
  170083. sp += 2;
  170084. }
  170085. }
  170086. else /* if (row_info->bit_depth == 16) */
  170087. {
  170088. sp = row;
  170089. for (i = 0; i < row_width; i++)
  170090. {
  170091. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170092. *sp = (png_byte)((v >> 8) & 0xff);
  170093. *(sp + 1) = (png_byte)(v & 0xff);
  170094. sp += 4;
  170095. }
  170096. }
  170097. break;
  170098. }
  170099. case PNG_COLOR_TYPE_GRAY:
  170100. {
  170101. if (row_info->bit_depth == 2)
  170102. {
  170103. sp = row;
  170104. for (i = 0; i < row_width; i += 4)
  170105. {
  170106. int a = *sp & 0xc0;
  170107. int b = *sp & 0x30;
  170108. int c = *sp & 0x0c;
  170109. int d = *sp & 0x03;
  170110. *sp = (png_byte)(
  170111. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  170112. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  170113. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  170114. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  170115. sp++;
  170116. }
  170117. }
  170118. if (row_info->bit_depth == 4)
  170119. {
  170120. sp = row;
  170121. for (i = 0; i < row_width; i += 2)
  170122. {
  170123. int msb = *sp & 0xf0;
  170124. int lsb = *sp & 0x0f;
  170125. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  170126. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  170127. sp++;
  170128. }
  170129. }
  170130. else if (row_info->bit_depth == 8)
  170131. {
  170132. sp = row;
  170133. for (i = 0; i < row_width; i++)
  170134. {
  170135. *sp = gamma_table[*sp];
  170136. sp++;
  170137. }
  170138. }
  170139. else if (row_info->bit_depth == 16)
  170140. {
  170141. sp = row;
  170142. for (i = 0; i < row_width; i++)
  170143. {
  170144. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170145. *sp = (png_byte)((v >> 8) & 0xff);
  170146. *(sp + 1) = (png_byte)(v & 0xff);
  170147. sp += 2;
  170148. }
  170149. }
  170150. break;
  170151. }
  170152. }
  170153. }
  170154. }
  170155. #endif
  170156. #if defined(PNG_READ_EXPAND_SUPPORTED)
  170157. void /* PRIVATE */
  170158. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  170159. png_colorp palette, png_bytep trans, int num_trans)
  170160. {
  170161. int shift, value;
  170162. png_bytep sp, dp;
  170163. png_uint_32 i;
  170164. png_uint_32 row_width=row_info->width;
  170165. png_debug(1, "in png_do_expand_palette\n");
  170166. if (
  170167. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170168. row != NULL && row_info != NULL &&
  170169. #endif
  170170. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  170171. {
  170172. if (row_info->bit_depth < 8)
  170173. {
  170174. switch (row_info->bit_depth)
  170175. {
  170176. case 1:
  170177. {
  170178. sp = row + (png_size_t)((row_width - 1) >> 3);
  170179. dp = row + (png_size_t)row_width - 1;
  170180. shift = 7 - (int)((row_width + 7) & 0x07);
  170181. for (i = 0; i < row_width; i++)
  170182. {
  170183. if ((*sp >> shift) & 0x01)
  170184. *dp = 1;
  170185. else
  170186. *dp = 0;
  170187. if (shift == 7)
  170188. {
  170189. shift = 0;
  170190. sp--;
  170191. }
  170192. else
  170193. shift++;
  170194. dp--;
  170195. }
  170196. break;
  170197. }
  170198. case 2:
  170199. {
  170200. sp = row + (png_size_t)((row_width - 1) >> 2);
  170201. dp = row + (png_size_t)row_width - 1;
  170202. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170203. for (i = 0; i < row_width; i++)
  170204. {
  170205. value = (*sp >> shift) & 0x03;
  170206. *dp = (png_byte)value;
  170207. if (shift == 6)
  170208. {
  170209. shift = 0;
  170210. sp--;
  170211. }
  170212. else
  170213. shift += 2;
  170214. dp--;
  170215. }
  170216. break;
  170217. }
  170218. case 4:
  170219. {
  170220. sp = row + (png_size_t)((row_width - 1) >> 1);
  170221. dp = row + (png_size_t)row_width - 1;
  170222. shift = (int)((row_width & 0x01) << 2);
  170223. for (i = 0; i < row_width; i++)
  170224. {
  170225. value = (*sp >> shift) & 0x0f;
  170226. *dp = (png_byte)value;
  170227. if (shift == 4)
  170228. {
  170229. shift = 0;
  170230. sp--;
  170231. }
  170232. else
  170233. shift += 4;
  170234. dp--;
  170235. }
  170236. break;
  170237. }
  170238. }
  170239. row_info->bit_depth = 8;
  170240. row_info->pixel_depth = 8;
  170241. row_info->rowbytes = row_width;
  170242. }
  170243. switch (row_info->bit_depth)
  170244. {
  170245. case 8:
  170246. {
  170247. if (trans != NULL)
  170248. {
  170249. sp = row + (png_size_t)row_width - 1;
  170250. dp = row + (png_size_t)(row_width << 2) - 1;
  170251. for (i = 0; i < row_width; i++)
  170252. {
  170253. if ((int)(*sp) >= num_trans)
  170254. *dp-- = 0xff;
  170255. else
  170256. *dp-- = trans[*sp];
  170257. *dp-- = palette[*sp].blue;
  170258. *dp-- = palette[*sp].green;
  170259. *dp-- = palette[*sp].red;
  170260. sp--;
  170261. }
  170262. row_info->bit_depth = 8;
  170263. row_info->pixel_depth = 32;
  170264. row_info->rowbytes = row_width * 4;
  170265. row_info->color_type = 6;
  170266. row_info->channels = 4;
  170267. }
  170268. else
  170269. {
  170270. sp = row + (png_size_t)row_width - 1;
  170271. dp = row + (png_size_t)(row_width * 3) - 1;
  170272. for (i = 0; i < row_width; i++)
  170273. {
  170274. *dp-- = palette[*sp].blue;
  170275. *dp-- = palette[*sp].green;
  170276. *dp-- = palette[*sp].red;
  170277. sp--;
  170278. }
  170279. row_info->bit_depth = 8;
  170280. row_info->pixel_depth = 24;
  170281. row_info->rowbytes = row_width * 3;
  170282. row_info->color_type = 2;
  170283. row_info->channels = 3;
  170284. }
  170285. break;
  170286. }
  170287. }
  170288. }
  170289. }
  170290. void /* PRIVATE */
  170291. png_do_expand(png_row_infop row_info, png_bytep row,
  170292. png_color_16p trans_value)
  170293. {
  170294. int shift, value;
  170295. png_bytep sp, dp;
  170296. png_uint_32 i;
  170297. png_uint_32 row_width=row_info->width;
  170298. png_debug(1, "in png_do_expand\n");
  170299. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170300. if (row != NULL && row_info != NULL)
  170301. #endif
  170302. {
  170303. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170304. {
  170305. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170306. if (row_info->bit_depth < 8)
  170307. {
  170308. switch (row_info->bit_depth)
  170309. {
  170310. case 1:
  170311. {
  170312. gray = (png_uint_16)((gray&0x01)*0xff);
  170313. sp = row + (png_size_t)((row_width - 1) >> 3);
  170314. dp = row + (png_size_t)row_width - 1;
  170315. shift = 7 - (int)((row_width + 7) & 0x07);
  170316. for (i = 0; i < row_width; i++)
  170317. {
  170318. if ((*sp >> shift) & 0x01)
  170319. *dp = 0xff;
  170320. else
  170321. *dp = 0;
  170322. if (shift == 7)
  170323. {
  170324. shift = 0;
  170325. sp--;
  170326. }
  170327. else
  170328. shift++;
  170329. dp--;
  170330. }
  170331. break;
  170332. }
  170333. case 2:
  170334. {
  170335. gray = (png_uint_16)((gray&0x03)*0x55);
  170336. sp = row + (png_size_t)((row_width - 1) >> 2);
  170337. dp = row + (png_size_t)row_width - 1;
  170338. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170339. for (i = 0; i < row_width; i++)
  170340. {
  170341. value = (*sp >> shift) & 0x03;
  170342. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170343. (value << 6));
  170344. if (shift == 6)
  170345. {
  170346. shift = 0;
  170347. sp--;
  170348. }
  170349. else
  170350. shift += 2;
  170351. dp--;
  170352. }
  170353. break;
  170354. }
  170355. case 4:
  170356. {
  170357. gray = (png_uint_16)((gray&0x0f)*0x11);
  170358. sp = row + (png_size_t)((row_width - 1) >> 1);
  170359. dp = row + (png_size_t)row_width - 1;
  170360. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170361. for (i = 0; i < row_width; i++)
  170362. {
  170363. value = (*sp >> shift) & 0x0f;
  170364. *dp = (png_byte)(value | (value << 4));
  170365. if (shift == 4)
  170366. {
  170367. shift = 0;
  170368. sp--;
  170369. }
  170370. else
  170371. shift = 4;
  170372. dp--;
  170373. }
  170374. break;
  170375. }
  170376. }
  170377. row_info->bit_depth = 8;
  170378. row_info->pixel_depth = 8;
  170379. row_info->rowbytes = row_width;
  170380. }
  170381. if (trans_value != NULL)
  170382. {
  170383. if (row_info->bit_depth == 8)
  170384. {
  170385. gray = gray & 0xff;
  170386. sp = row + (png_size_t)row_width - 1;
  170387. dp = row + (png_size_t)(row_width << 1) - 1;
  170388. for (i = 0; i < row_width; i++)
  170389. {
  170390. if (*sp == gray)
  170391. *dp-- = 0;
  170392. else
  170393. *dp-- = 0xff;
  170394. *dp-- = *sp--;
  170395. }
  170396. }
  170397. else if (row_info->bit_depth == 16)
  170398. {
  170399. png_byte gray_high = (gray >> 8) & 0xff;
  170400. png_byte gray_low = gray & 0xff;
  170401. sp = row + row_info->rowbytes - 1;
  170402. dp = row + (row_info->rowbytes << 1) - 1;
  170403. for (i = 0; i < row_width; i++)
  170404. {
  170405. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170406. {
  170407. *dp-- = 0;
  170408. *dp-- = 0;
  170409. }
  170410. else
  170411. {
  170412. *dp-- = 0xff;
  170413. *dp-- = 0xff;
  170414. }
  170415. *dp-- = *sp--;
  170416. *dp-- = *sp--;
  170417. }
  170418. }
  170419. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170420. row_info->channels = 2;
  170421. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170422. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170423. row_width);
  170424. }
  170425. }
  170426. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170427. {
  170428. if (row_info->bit_depth == 8)
  170429. {
  170430. png_byte red = trans_value->red & 0xff;
  170431. png_byte green = trans_value->green & 0xff;
  170432. png_byte blue = trans_value->blue & 0xff;
  170433. sp = row + (png_size_t)row_info->rowbytes - 1;
  170434. dp = row + (png_size_t)(row_width << 2) - 1;
  170435. for (i = 0; i < row_width; i++)
  170436. {
  170437. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170438. *dp-- = 0;
  170439. else
  170440. *dp-- = 0xff;
  170441. *dp-- = *sp--;
  170442. *dp-- = *sp--;
  170443. *dp-- = *sp--;
  170444. }
  170445. }
  170446. else if (row_info->bit_depth == 16)
  170447. {
  170448. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170449. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170450. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170451. png_byte red_low = trans_value->red & 0xff;
  170452. png_byte green_low = trans_value->green & 0xff;
  170453. png_byte blue_low = trans_value->blue & 0xff;
  170454. sp = row + row_info->rowbytes - 1;
  170455. dp = row + (png_size_t)(row_width << 3) - 1;
  170456. for (i = 0; i < row_width; i++)
  170457. {
  170458. if (*(sp - 5) == red_high &&
  170459. *(sp - 4) == red_low &&
  170460. *(sp - 3) == green_high &&
  170461. *(sp - 2) == green_low &&
  170462. *(sp - 1) == blue_high &&
  170463. *(sp ) == blue_low)
  170464. {
  170465. *dp-- = 0;
  170466. *dp-- = 0;
  170467. }
  170468. else
  170469. {
  170470. *dp-- = 0xff;
  170471. *dp-- = 0xff;
  170472. }
  170473. *dp-- = *sp--;
  170474. *dp-- = *sp--;
  170475. *dp-- = *sp--;
  170476. *dp-- = *sp--;
  170477. *dp-- = *sp--;
  170478. *dp-- = *sp--;
  170479. }
  170480. }
  170481. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170482. row_info->channels = 4;
  170483. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170484. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170485. }
  170486. }
  170487. }
  170488. #endif
  170489. #if defined(PNG_READ_DITHER_SUPPORTED)
  170490. void /* PRIVATE */
  170491. png_do_dither(png_row_infop row_info, png_bytep row,
  170492. png_bytep palette_lookup, png_bytep dither_lookup)
  170493. {
  170494. png_bytep sp, dp;
  170495. png_uint_32 i;
  170496. png_uint_32 row_width=row_info->width;
  170497. png_debug(1, "in png_do_dither\n");
  170498. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170499. if (row != NULL && row_info != NULL)
  170500. #endif
  170501. {
  170502. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170503. palette_lookup && row_info->bit_depth == 8)
  170504. {
  170505. int r, g, b, p;
  170506. sp = row;
  170507. dp = row;
  170508. for (i = 0; i < row_width; i++)
  170509. {
  170510. r = *sp++;
  170511. g = *sp++;
  170512. b = *sp++;
  170513. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170514. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170515. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170516. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170517. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170518. (PNG_DITHER_BLUE_BITS)) |
  170519. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170520. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170521. *dp++ = palette_lookup[p];
  170522. }
  170523. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170524. row_info->channels = 1;
  170525. row_info->pixel_depth = row_info->bit_depth;
  170526. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170527. }
  170528. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170529. palette_lookup != NULL && row_info->bit_depth == 8)
  170530. {
  170531. int r, g, b, p;
  170532. sp = row;
  170533. dp = row;
  170534. for (i = 0; i < row_width; i++)
  170535. {
  170536. r = *sp++;
  170537. g = *sp++;
  170538. b = *sp++;
  170539. sp++;
  170540. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170541. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170542. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170543. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170544. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170545. (PNG_DITHER_BLUE_BITS)) |
  170546. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170547. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170548. *dp++ = palette_lookup[p];
  170549. }
  170550. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170551. row_info->channels = 1;
  170552. row_info->pixel_depth = row_info->bit_depth;
  170553. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170554. }
  170555. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170556. dither_lookup && row_info->bit_depth == 8)
  170557. {
  170558. sp = row;
  170559. for (i = 0; i < row_width; i++, sp++)
  170560. {
  170561. *sp = dither_lookup[*sp];
  170562. }
  170563. }
  170564. }
  170565. }
  170566. #endif
  170567. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170568. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170569. static PNG_CONST int png_gamma_shift[] =
  170570. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170571. void /* PRIVATE */
  170572. png_build_gamma_table(png_structp png_ptr)
  170573. {
  170574. png_debug(1, "in png_build_gamma_table\n");
  170575. if (png_ptr->bit_depth <= 8)
  170576. {
  170577. int i;
  170578. double g;
  170579. if (png_ptr->screen_gamma > .000001)
  170580. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170581. else
  170582. g = 1.0;
  170583. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170584. (png_uint_32)256);
  170585. for (i = 0; i < 256; i++)
  170586. {
  170587. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170588. g) * 255.0 + .5);
  170589. }
  170590. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170591. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170592. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170593. {
  170594. g = 1.0 / (png_ptr->gamma);
  170595. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170596. (png_uint_32)256);
  170597. for (i = 0; i < 256; i++)
  170598. {
  170599. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170600. g) * 255.0 + .5);
  170601. }
  170602. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170603. (png_uint_32)256);
  170604. if(png_ptr->screen_gamma > 0.000001)
  170605. g = 1.0 / png_ptr->screen_gamma;
  170606. else
  170607. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170608. for (i = 0; i < 256; i++)
  170609. {
  170610. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170611. g) * 255.0 + .5);
  170612. }
  170613. }
  170614. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170615. }
  170616. else
  170617. {
  170618. double g;
  170619. int i, j, shift, num;
  170620. int sig_bit;
  170621. png_uint_32 ig;
  170622. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170623. {
  170624. sig_bit = (int)png_ptr->sig_bit.red;
  170625. if ((int)png_ptr->sig_bit.green > sig_bit)
  170626. sig_bit = png_ptr->sig_bit.green;
  170627. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170628. sig_bit = png_ptr->sig_bit.blue;
  170629. }
  170630. else
  170631. {
  170632. sig_bit = (int)png_ptr->sig_bit.gray;
  170633. }
  170634. if (sig_bit > 0)
  170635. shift = 16 - sig_bit;
  170636. else
  170637. shift = 0;
  170638. if (png_ptr->transformations & PNG_16_TO_8)
  170639. {
  170640. if (shift < (16 - PNG_MAX_GAMMA_8))
  170641. shift = (16 - PNG_MAX_GAMMA_8);
  170642. }
  170643. if (shift > 8)
  170644. shift = 8;
  170645. if (shift < 0)
  170646. shift = 0;
  170647. png_ptr->gamma_shift = (png_byte)shift;
  170648. num = (1 << (8 - shift));
  170649. if (png_ptr->screen_gamma > .000001)
  170650. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170651. else
  170652. g = 1.0;
  170653. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170654. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170655. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170656. {
  170657. double fin, fout;
  170658. png_uint_32 last, max;
  170659. for (i = 0; i < num; i++)
  170660. {
  170661. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170662. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170663. }
  170664. g = 1.0 / g;
  170665. last = 0;
  170666. for (i = 0; i < 256; i++)
  170667. {
  170668. fout = ((double)i + 0.5) / 256.0;
  170669. fin = pow(fout, g);
  170670. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  170671. while (last <= max)
  170672. {
  170673. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170674. [(int)(last >> (8 - shift))] = (png_uint_16)(
  170675. (png_uint_16)i | ((png_uint_16)i << 8));
  170676. last++;
  170677. }
  170678. }
  170679. while (last < ((png_uint_32)num << 8))
  170680. {
  170681. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170682. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  170683. last++;
  170684. }
  170685. }
  170686. else
  170687. {
  170688. for (i = 0; i < num; i++)
  170689. {
  170690. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170691. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170692. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  170693. for (j = 0; j < 256; j++)
  170694. {
  170695. png_ptr->gamma_16_table[i][j] =
  170696. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170697. 65535.0, g) * 65535.0 + .5);
  170698. }
  170699. }
  170700. }
  170701. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170702. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170703. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  170704. {
  170705. g = 1.0 / (png_ptr->gamma);
  170706. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  170707. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  170708. for (i = 0; i < num; i++)
  170709. {
  170710. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170711. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170712. ig = (((png_uint_32)i *
  170713. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170714. for (j = 0; j < 256; j++)
  170715. {
  170716. png_ptr->gamma_16_to_1[i][j] =
  170717. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170718. 65535.0, g) * 65535.0 + .5);
  170719. }
  170720. }
  170721. if(png_ptr->screen_gamma > 0.000001)
  170722. g = 1.0 / png_ptr->screen_gamma;
  170723. else
  170724. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170725. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  170726. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170727. for (i = 0; i < num; i++)
  170728. {
  170729. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170730. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170731. ig = (((png_uint_32)i *
  170732. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170733. for (j = 0; j < 256; j++)
  170734. {
  170735. png_ptr->gamma_16_from_1[i][j] =
  170736. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170737. 65535.0, g) * 65535.0 + .5);
  170738. }
  170739. }
  170740. }
  170741. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170742. }
  170743. }
  170744. #endif
  170745. #endif
  170746. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170747. void /* PRIVATE */
  170748. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  170749. {
  170750. png_debug(1, "in png_do_read_intrapixel\n");
  170751. if (
  170752. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170753. row != NULL && row_info != NULL &&
  170754. #endif
  170755. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  170756. {
  170757. int bytes_per_pixel;
  170758. png_uint_32 row_width = row_info->width;
  170759. if (row_info->bit_depth == 8)
  170760. {
  170761. png_bytep rp;
  170762. png_uint_32 i;
  170763. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170764. bytes_per_pixel = 3;
  170765. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170766. bytes_per_pixel = 4;
  170767. else
  170768. return;
  170769. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170770. {
  170771. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  170772. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  170773. }
  170774. }
  170775. else if (row_info->bit_depth == 16)
  170776. {
  170777. png_bytep rp;
  170778. png_uint_32 i;
  170779. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170780. bytes_per_pixel = 6;
  170781. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170782. bytes_per_pixel = 8;
  170783. else
  170784. return;
  170785. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170786. {
  170787. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  170788. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  170789. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  170790. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  170791. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  170792. *(rp ) = (png_byte)((red >> 8) & 0xff);
  170793. *(rp+1) = (png_byte)(red & 0xff);
  170794. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  170795. *(rp+5) = (png_byte)(blue & 0xff);
  170796. }
  170797. }
  170798. }
  170799. }
  170800. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  170801. #endif /* PNG_READ_SUPPORTED */
  170802. /*** End of inlined file: pngrtran.c ***/
  170803. /*** Start of inlined file: pngrutil.c ***/
  170804. #define PNG_INTERNAL
  170805. #if defined(PNG_READ_SUPPORTED)
  170806. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  170807. # define WIN32_WCE_OLD
  170808. #endif
  170809. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170810. # if defined(WIN32_WCE_OLD)
  170811. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  170812. {
  170813. double result = 0;
  170814. int len;
  170815. wchar_t *str, *end;
  170816. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  170817. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  170818. if ( NULL != str )
  170819. {
  170820. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  170821. result = wcstod(str, &end);
  170822. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  170823. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  170824. png_free(png_ptr, str);
  170825. }
  170826. return result;
  170827. }
  170828. # else
  170829. # define png_strtod(p,a,b) strtod(a,b)
  170830. # endif
  170831. #endif
  170832. png_uint_32 PNGAPI
  170833. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  170834. {
  170835. png_uint_32 i = png_get_uint_32(buf);
  170836. if (i > PNG_UINT_31_MAX)
  170837. png_error(png_ptr, "PNG unsigned integer out of range.");
  170838. return (i);
  170839. }
  170840. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  170841. png_uint_32 PNGAPI
  170842. png_get_uint_32(png_bytep buf)
  170843. {
  170844. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  170845. ((png_uint_32)(*(buf + 1)) << 16) +
  170846. ((png_uint_32)(*(buf + 2)) << 8) +
  170847. (png_uint_32)(*(buf + 3));
  170848. return (i);
  170849. }
  170850. png_int_32 PNGAPI
  170851. png_get_int_32(png_bytep buf)
  170852. {
  170853. png_int_32 i = ((png_int_32)(*buf) << 24) +
  170854. ((png_int_32)(*(buf + 1)) << 16) +
  170855. ((png_int_32)(*(buf + 2)) << 8) +
  170856. (png_int_32)(*(buf + 3));
  170857. return (i);
  170858. }
  170859. png_uint_16 PNGAPI
  170860. png_get_uint_16(png_bytep buf)
  170861. {
  170862. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  170863. (png_uint_16)(*(buf + 1)));
  170864. return (i);
  170865. }
  170866. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  170867. void /* PRIVATE */
  170868. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  170869. {
  170870. if(png_ptr == NULL) return;
  170871. png_read_data(png_ptr, buf, length);
  170872. png_calculate_crc(png_ptr, buf, length);
  170873. }
  170874. int /* PRIVATE */
  170875. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  170876. {
  170877. png_size_t i;
  170878. png_size_t istop = png_ptr->zbuf_size;
  170879. for (i = (png_size_t)skip; i > istop; i -= istop)
  170880. {
  170881. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  170882. }
  170883. if (i)
  170884. {
  170885. png_crc_read(png_ptr, png_ptr->zbuf, i);
  170886. }
  170887. if (png_crc_error(png_ptr))
  170888. {
  170889. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  170890. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  170891. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  170892. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  170893. {
  170894. png_chunk_warning(png_ptr, "CRC error");
  170895. }
  170896. else
  170897. {
  170898. png_chunk_error(png_ptr, "CRC error");
  170899. }
  170900. return (1);
  170901. }
  170902. return (0);
  170903. }
  170904. int /* PRIVATE */
  170905. png_crc_error(png_structp png_ptr)
  170906. {
  170907. png_byte crc_bytes[4];
  170908. png_uint_32 crc;
  170909. int need_crc = 1;
  170910. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  170911. {
  170912. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  170913. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  170914. need_crc = 0;
  170915. }
  170916. else /* critical */
  170917. {
  170918. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  170919. need_crc = 0;
  170920. }
  170921. png_read_data(png_ptr, crc_bytes, 4);
  170922. if (need_crc)
  170923. {
  170924. crc = png_get_uint_32(crc_bytes);
  170925. return ((int)(crc != png_ptr->crc));
  170926. }
  170927. else
  170928. return (0);
  170929. }
  170930. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  170931. defined(PNG_READ_iCCP_SUPPORTED)
  170932. png_charp /* PRIVATE */
  170933. png_decompress_chunk(png_structp png_ptr, int comp_type,
  170934. png_charp chunkdata, png_size_t chunklength,
  170935. png_size_t prefix_size, png_size_t *newlength)
  170936. {
  170937. static PNG_CONST char msg[] = "Error decoding compressed text";
  170938. png_charp text;
  170939. png_size_t text_size;
  170940. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  170941. {
  170942. int ret = Z_OK;
  170943. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  170944. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  170945. png_ptr->zstream.next_out = png_ptr->zbuf;
  170946. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170947. text_size = 0;
  170948. text = NULL;
  170949. while (png_ptr->zstream.avail_in)
  170950. {
  170951. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  170952. if (ret != Z_OK && ret != Z_STREAM_END)
  170953. {
  170954. if (png_ptr->zstream.msg != NULL)
  170955. png_warning(png_ptr, png_ptr->zstream.msg);
  170956. else
  170957. png_warning(png_ptr, msg);
  170958. inflateReset(&png_ptr->zstream);
  170959. png_ptr->zstream.avail_in = 0;
  170960. if (text == NULL)
  170961. {
  170962. text_size = prefix_size + png_sizeof(msg) + 1;
  170963. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  170964. if (text == NULL)
  170965. {
  170966. png_free(png_ptr,chunkdata);
  170967. png_error(png_ptr,"Not enough memory to decompress chunk");
  170968. }
  170969. png_memcpy(text, chunkdata, prefix_size);
  170970. }
  170971. text[text_size - 1] = 0x00;
  170972. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  170973. text_size = png_sizeof(msg) > text_size ? text_size :
  170974. png_sizeof(msg);
  170975. png_memcpy(text + prefix_size, msg, text_size + 1);
  170976. break;
  170977. }
  170978. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  170979. {
  170980. if (text == NULL)
  170981. {
  170982. text_size = prefix_size +
  170983. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170984. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  170985. if (text == NULL)
  170986. {
  170987. png_free(png_ptr,chunkdata);
  170988. png_error(png_ptr,"Not enough memory to decompress chunk.");
  170989. }
  170990. png_memcpy(text + prefix_size, png_ptr->zbuf,
  170991. text_size - prefix_size);
  170992. png_memcpy(text, chunkdata, prefix_size);
  170993. *(text + text_size) = 0x00;
  170994. }
  170995. else
  170996. {
  170997. png_charp tmp;
  170998. tmp = text;
  170999. text = (png_charp)png_malloc_warn(png_ptr,
  171000. (png_uint_32)(text_size +
  171001. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  171002. if (text == NULL)
  171003. {
  171004. png_free(png_ptr, tmp);
  171005. png_free(png_ptr, chunkdata);
  171006. png_error(png_ptr,"Not enough memory to decompress chunk..");
  171007. }
  171008. png_memcpy(text, tmp, text_size);
  171009. png_free(png_ptr, tmp);
  171010. png_memcpy(text + text_size, png_ptr->zbuf,
  171011. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  171012. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171013. *(text + text_size) = 0x00;
  171014. }
  171015. if (ret == Z_STREAM_END)
  171016. break;
  171017. else
  171018. {
  171019. png_ptr->zstream.next_out = png_ptr->zbuf;
  171020. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171021. }
  171022. }
  171023. }
  171024. if (ret != Z_STREAM_END)
  171025. {
  171026. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171027. char umsg[52];
  171028. if (ret == Z_BUF_ERROR)
  171029. png_snprintf(umsg, 52,
  171030. "Buffer error in compressed datastream in %s chunk",
  171031. png_ptr->chunk_name);
  171032. else if (ret == Z_DATA_ERROR)
  171033. png_snprintf(umsg, 52,
  171034. "Data error in compressed datastream in %s chunk",
  171035. png_ptr->chunk_name);
  171036. else
  171037. png_snprintf(umsg, 52,
  171038. "Incomplete compressed datastream in %s chunk",
  171039. png_ptr->chunk_name);
  171040. png_warning(png_ptr, umsg);
  171041. #else
  171042. png_warning(png_ptr,
  171043. "Incomplete compressed datastream in chunk other than IDAT");
  171044. #endif
  171045. text_size=prefix_size;
  171046. if (text == NULL)
  171047. {
  171048. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  171049. if (text == NULL)
  171050. {
  171051. png_free(png_ptr, chunkdata);
  171052. png_error(png_ptr,"Not enough memory for text.");
  171053. }
  171054. png_memcpy(text, chunkdata, prefix_size);
  171055. }
  171056. *(text + text_size) = 0x00;
  171057. }
  171058. inflateReset(&png_ptr->zstream);
  171059. png_ptr->zstream.avail_in = 0;
  171060. png_free(png_ptr, chunkdata);
  171061. chunkdata = text;
  171062. *newlength=text_size;
  171063. }
  171064. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  171065. {
  171066. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171067. char umsg[50];
  171068. png_snprintf(umsg, 50,
  171069. "Unknown zTXt compression type %d", comp_type);
  171070. png_warning(png_ptr, umsg);
  171071. #else
  171072. png_warning(png_ptr, "Unknown zTXt compression type");
  171073. #endif
  171074. *(chunkdata + prefix_size) = 0x00;
  171075. *newlength=prefix_size;
  171076. }
  171077. return chunkdata;
  171078. }
  171079. #endif
  171080. void /* PRIVATE */
  171081. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171082. {
  171083. png_byte buf[13];
  171084. png_uint_32 width, height;
  171085. int bit_depth, color_type, compression_type, filter_type;
  171086. int interlace_type;
  171087. png_debug(1, "in png_handle_IHDR\n");
  171088. if (png_ptr->mode & PNG_HAVE_IHDR)
  171089. png_error(png_ptr, "Out of place IHDR");
  171090. if (length != 13)
  171091. png_error(png_ptr, "Invalid IHDR chunk");
  171092. png_ptr->mode |= PNG_HAVE_IHDR;
  171093. png_crc_read(png_ptr, buf, 13);
  171094. png_crc_finish(png_ptr, 0);
  171095. width = png_get_uint_31(png_ptr, buf);
  171096. height = png_get_uint_31(png_ptr, buf + 4);
  171097. bit_depth = buf[8];
  171098. color_type = buf[9];
  171099. compression_type = buf[10];
  171100. filter_type = buf[11];
  171101. interlace_type = buf[12];
  171102. png_ptr->width = width;
  171103. png_ptr->height = height;
  171104. png_ptr->bit_depth = (png_byte)bit_depth;
  171105. png_ptr->interlaced = (png_byte)interlace_type;
  171106. png_ptr->color_type = (png_byte)color_type;
  171107. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  171108. png_ptr->filter_type = (png_byte)filter_type;
  171109. #endif
  171110. png_ptr->compression_type = (png_byte)compression_type;
  171111. switch (png_ptr->color_type)
  171112. {
  171113. case PNG_COLOR_TYPE_GRAY:
  171114. case PNG_COLOR_TYPE_PALETTE:
  171115. png_ptr->channels = 1;
  171116. break;
  171117. case PNG_COLOR_TYPE_RGB:
  171118. png_ptr->channels = 3;
  171119. break;
  171120. case PNG_COLOR_TYPE_GRAY_ALPHA:
  171121. png_ptr->channels = 2;
  171122. break;
  171123. case PNG_COLOR_TYPE_RGB_ALPHA:
  171124. png_ptr->channels = 4;
  171125. break;
  171126. }
  171127. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  171128. png_ptr->channels);
  171129. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  171130. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  171131. png_debug1(3,"channels = %d\n", png_ptr->channels);
  171132. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  171133. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  171134. color_type, interlace_type, compression_type, filter_type);
  171135. }
  171136. void /* PRIVATE */
  171137. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171138. {
  171139. png_color palette[PNG_MAX_PALETTE_LENGTH];
  171140. int num, i;
  171141. #ifndef PNG_NO_POINTER_INDEXING
  171142. png_colorp pal_ptr;
  171143. #endif
  171144. png_debug(1, "in png_handle_PLTE\n");
  171145. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171146. png_error(png_ptr, "Missing IHDR before PLTE");
  171147. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171148. {
  171149. png_warning(png_ptr, "Invalid PLTE after IDAT");
  171150. png_crc_finish(png_ptr, length);
  171151. return;
  171152. }
  171153. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171154. png_error(png_ptr, "Duplicate PLTE chunk");
  171155. png_ptr->mode |= PNG_HAVE_PLTE;
  171156. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  171157. {
  171158. png_warning(png_ptr,
  171159. "Ignoring PLTE chunk in grayscale PNG");
  171160. png_crc_finish(png_ptr, length);
  171161. return;
  171162. }
  171163. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171164. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171165. {
  171166. png_crc_finish(png_ptr, length);
  171167. return;
  171168. }
  171169. #endif
  171170. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  171171. {
  171172. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171173. {
  171174. png_warning(png_ptr, "Invalid palette chunk");
  171175. png_crc_finish(png_ptr, length);
  171176. return;
  171177. }
  171178. else
  171179. {
  171180. png_error(png_ptr, "Invalid palette chunk");
  171181. }
  171182. }
  171183. num = (int)length / 3;
  171184. #ifndef PNG_NO_POINTER_INDEXING
  171185. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  171186. {
  171187. png_byte buf[3];
  171188. png_crc_read(png_ptr, buf, 3);
  171189. pal_ptr->red = buf[0];
  171190. pal_ptr->green = buf[1];
  171191. pal_ptr->blue = buf[2];
  171192. }
  171193. #else
  171194. for (i = 0; i < num; i++)
  171195. {
  171196. png_byte buf[3];
  171197. png_crc_read(png_ptr, buf, 3);
  171198. palette[i].red = buf[0];
  171199. palette[i].green = buf[1];
  171200. palette[i].blue = buf[2];
  171201. }
  171202. #endif
  171203. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171204. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171205. #endif
  171206. {
  171207. png_crc_finish(png_ptr, 0);
  171208. }
  171209. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171210. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  171211. {
  171212. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  171213. {
  171214. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  171215. {
  171216. png_chunk_error(png_ptr, "CRC error");
  171217. }
  171218. else
  171219. {
  171220. png_chunk_warning(png_ptr, "CRC error");
  171221. return;
  171222. }
  171223. }
  171224. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171225. {
  171226. png_chunk_warning(png_ptr, "CRC error");
  171227. }
  171228. }
  171229. #endif
  171230. png_set_PLTE(png_ptr, info_ptr, palette, num);
  171231. #if defined(PNG_READ_tRNS_SUPPORTED)
  171232. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171233. {
  171234. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171235. {
  171236. if (png_ptr->num_trans > (png_uint_16)num)
  171237. {
  171238. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  171239. png_ptr->num_trans = (png_uint_16)num;
  171240. }
  171241. if (info_ptr->num_trans > (png_uint_16)num)
  171242. {
  171243. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  171244. info_ptr->num_trans = (png_uint_16)num;
  171245. }
  171246. }
  171247. }
  171248. #endif
  171249. }
  171250. void /* PRIVATE */
  171251. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171252. {
  171253. png_debug(1, "in png_handle_IEND\n");
  171254. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  171255. {
  171256. png_error(png_ptr, "No image in file");
  171257. }
  171258. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  171259. if (length != 0)
  171260. {
  171261. png_warning(png_ptr, "Incorrect IEND chunk length");
  171262. }
  171263. png_crc_finish(png_ptr, length);
  171264. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  171265. }
  171266. #if defined(PNG_READ_gAMA_SUPPORTED)
  171267. void /* PRIVATE */
  171268. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171269. {
  171270. png_fixed_point igamma;
  171271. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171272. float file_gamma;
  171273. #endif
  171274. png_byte buf[4];
  171275. png_debug(1, "in png_handle_gAMA\n");
  171276. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171277. png_error(png_ptr, "Missing IHDR before gAMA");
  171278. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171279. {
  171280. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171281. png_crc_finish(png_ptr, length);
  171282. return;
  171283. }
  171284. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171285. png_warning(png_ptr, "Out of place gAMA chunk");
  171286. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171287. #if defined(PNG_READ_sRGB_SUPPORTED)
  171288. && !(info_ptr->valid & PNG_INFO_sRGB)
  171289. #endif
  171290. )
  171291. {
  171292. png_warning(png_ptr, "Duplicate gAMA chunk");
  171293. png_crc_finish(png_ptr, length);
  171294. return;
  171295. }
  171296. if (length != 4)
  171297. {
  171298. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171299. png_crc_finish(png_ptr, length);
  171300. return;
  171301. }
  171302. png_crc_read(png_ptr, buf, 4);
  171303. if (png_crc_finish(png_ptr, 0))
  171304. return;
  171305. igamma = (png_fixed_point)png_get_uint_32(buf);
  171306. if (igamma == 0)
  171307. {
  171308. png_warning(png_ptr,
  171309. "Ignoring gAMA chunk with gamma=0");
  171310. return;
  171311. }
  171312. #if defined(PNG_READ_sRGB_SUPPORTED)
  171313. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171314. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171315. {
  171316. png_warning(png_ptr,
  171317. "Ignoring incorrect gAMA value when sRGB is also present");
  171318. #ifndef PNG_NO_CONSOLE_IO
  171319. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171320. #endif
  171321. return;
  171322. }
  171323. #endif /* PNG_READ_sRGB_SUPPORTED */
  171324. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171325. file_gamma = (float)igamma / (float)100000.0;
  171326. # ifdef PNG_READ_GAMMA_SUPPORTED
  171327. png_ptr->gamma = file_gamma;
  171328. # endif
  171329. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171330. #endif
  171331. #ifdef PNG_FIXED_POINT_SUPPORTED
  171332. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171333. #endif
  171334. }
  171335. #endif
  171336. #if defined(PNG_READ_sBIT_SUPPORTED)
  171337. void /* PRIVATE */
  171338. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171339. {
  171340. png_size_t truelen;
  171341. png_byte buf[4];
  171342. png_debug(1, "in png_handle_sBIT\n");
  171343. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171344. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171345. png_error(png_ptr, "Missing IHDR before sBIT");
  171346. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171347. {
  171348. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171349. png_crc_finish(png_ptr, length);
  171350. return;
  171351. }
  171352. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171353. {
  171354. png_warning(png_ptr, "Out of place sBIT chunk");
  171355. }
  171356. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171357. {
  171358. png_warning(png_ptr, "Duplicate sBIT chunk");
  171359. png_crc_finish(png_ptr, length);
  171360. return;
  171361. }
  171362. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171363. truelen = 3;
  171364. else
  171365. truelen = (png_size_t)png_ptr->channels;
  171366. if (length != truelen || length > 4)
  171367. {
  171368. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171369. png_crc_finish(png_ptr, length);
  171370. return;
  171371. }
  171372. png_crc_read(png_ptr, buf, truelen);
  171373. if (png_crc_finish(png_ptr, 0))
  171374. return;
  171375. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171376. {
  171377. png_ptr->sig_bit.red = buf[0];
  171378. png_ptr->sig_bit.green = buf[1];
  171379. png_ptr->sig_bit.blue = buf[2];
  171380. png_ptr->sig_bit.alpha = buf[3];
  171381. }
  171382. else
  171383. {
  171384. png_ptr->sig_bit.gray = buf[0];
  171385. png_ptr->sig_bit.red = buf[0];
  171386. png_ptr->sig_bit.green = buf[0];
  171387. png_ptr->sig_bit.blue = buf[0];
  171388. png_ptr->sig_bit.alpha = buf[1];
  171389. }
  171390. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171391. }
  171392. #endif
  171393. #if defined(PNG_READ_cHRM_SUPPORTED)
  171394. void /* PRIVATE */
  171395. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171396. {
  171397. png_byte buf[4];
  171398. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171399. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171400. #endif
  171401. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171402. int_y_green, int_x_blue, int_y_blue;
  171403. png_uint_32 uint_x, uint_y;
  171404. png_debug(1, "in png_handle_cHRM\n");
  171405. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171406. png_error(png_ptr, "Missing IHDR before cHRM");
  171407. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171408. {
  171409. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171410. png_crc_finish(png_ptr, length);
  171411. return;
  171412. }
  171413. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171414. png_warning(png_ptr, "Missing PLTE before cHRM");
  171415. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171416. #if defined(PNG_READ_sRGB_SUPPORTED)
  171417. && !(info_ptr->valid & PNG_INFO_sRGB)
  171418. #endif
  171419. )
  171420. {
  171421. png_warning(png_ptr, "Duplicate cHRM chunk");
  171422. png_crc_finish(png_ptr, length);
  171423. return;
  171424. }
  171425. if (length != 32)
  171426. {
  171427. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171428. png_crc_finish(png_ptr, length);
  171429. return;
  171430. }
  171431. png_crc_read(png_ptr, buf, 4);
  171432. uint_x = png_get_uint_32(buf);
  171433. png_crc_read(png_ptr, buf, 4);
  171434. uint_y = png_get_uint_32(buf);
  171435. if (uint_x > 80000L || uint_y > 80000L ||
  171436. uint_x + uint_y > 100000L)
  171437. {
  171438. png_warning(png_ptr, "Invalid cHRM white point");
  171439. png_crc_finish(png_ptr, 24);
  171440. return;
  171441. }
  171442. int_x_white = (png_fixed_point)uint_x;
  171443. int_y_white = (png_fixed_point)uint_y;
  171444. png_crc_read(png_ptr, buf, 4);
  171445. uint_x = png_get_uint_32(buf);
  171446. png_crc_read(png_ptr, buf, 4);
  171447. uint_y = png_get_uint_32(buf);
  171448. if (uint_x + uint_y > 100000L)
  171449. {
  171450. png_warning(png_ptr, "Invalid cHRM red point");
  171451. png_crc_finish(png_ptr, 16);
  171452. return;
  171453. }
  171454. int_x_red = (png_fixed_point)uint_x;
  171455. int_y_red = (png_fixed_point)uint_y;
  171456. png_crc_read(png_ptr, buf, 4);
  171457. uint_x = png_get_uint_32(buf);
  171458. png_crc_read(png_ptr, buf, 4);
  171459. uint_y = png_get_uint_32(buf);
  171460. if (uint_x + uint_y > 100000L)
  171461. {
  171462. png_warning(png_ptr, "Invalid cHRM green point");
  171463. png_crc_finish(png_ptr, 8);
  171464. return;
  171465. }
  171466. int_x_green = (png_fixed_point)uint_x;
  171467. int_y_green = (png_fixed_point)uint_y;
  171468. png_crc_read(png_ptr, buf, 4);
  171469. uint_x = png_get_uint_32(buf);
  171470. png_crc_read(png_ptr, buf, 4);
  171471. uint_y = png_get_uint_32(buf);
  171472. if (uint_x + uint_y > 100000L)
  171473. {
  171474. png_warning(png_ptr, "Invalid cHRM blue point");
  171475. png_crc_finish(png_ptr, 0);
  171476. return;
  171477. }
  171478. int_x_blue = (png_fixed_point)uint_x;
  171479. int_y_blue = (png_fixed_point)uint_y;
  171480. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171481. white_x = (float)int_x_white / (float)100000.0;
  171482. white_y = (float)int_y_white / (float)100000.0;
  171483. red_x = (float)int_x_red / (float)100000.0;
  171484. red_y = (float)int_y_red / (float)100000.0;
  171485. green_x = (float)int_x_green / (float)100000.0;
  171486. green_y = (float)int_y_green / (float)100000.0;
  171487. blue_x = (float)int_x_blue / (float)100000.0;
  171488. blue_y = (float)int_y_blue / (float)100000.0;
  171489. #endif
  171490. #if defined(PNG_READ_sRGB_SUPPORTED)
  171491. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171492. {
  171493. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171494. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171495. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171496. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171497. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171498. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171499. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171500. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171501. {
  171502. png_warning(png_ptr,
  171503. "Ignoring incorrect cHRM value when sRGB is also present");
  171504. #ifndef PNG_NO_CONSOLE_IO
  171505. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171506. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171507. white_x, white_y, red_x, red_y);
  171508. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171509. green_x, green_y, blue_x, blue_y);
  171510. #else
  171511. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171512. int_x_white, int_y_white, int_x_red, int_y_red);
  171513. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171514. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171515. #endif
  171516. #endif /* PNG_NO_CONSOLE_IO */
  171517. }
  171518. png_crc_finish(png_ptr, 0);
  171519. return;
  171520. }
  171521. #endif /* PNG_READ_sRGB_SUPPORTED */
  171522. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171523. png_set_cHRM(png_ptr, info_ptr,
  171524. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171525. #endif
  171526. #ifdef PNG_FIXED_POINT_SUPPORTED
  171527. png_set_cHRM_fixed(png_ptr, info_ptr,
  171528. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171529. int_y_green, int_x_blue, int_y_blue);
  171530. #endif
  171531. if (png_crc_finish(png_ptr, 0))
  171532. return;
  171533. }
  171534. #endif
  171535. #if defined(PNG_READ_sRGB_SUPPORTED)
  171536. void /* PRIVATE */
  171537. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171538. {
  171539. int intent;
  171540. png_byte buf[1];
  171541. png_debug(1, "in png_handle_sRGB\n");
  171542. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171543. png_error(png_ptr, "Missing IHDR before sRGB");
  171544. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171545. {
  171546. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171547. png_crc_finish(png_ptr, length);
  171548. return;
  171549. }
  171550. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171551. png_warning(png_ptr, "Out of place sRGB chunk");
  171552. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171553. {
  171554. png_warning(png_ptr, "Duplicate sRGB chunk");
  171555. png_crc_finish(png_ptr, length);
  171556. return;
  171557. }
  171558. if (length != 1)
  171559. {
  171560. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171561. png_crc_finish(png_ptr, length);
  171562. return;
  171563. }
  171564. png_crc_read(png_ptr, buf, 1);
  171565. if (png_crc_finish(png_ptr, 0))
  171566. return;
  171567. intent = buf[0];
  171568. if (intent >= PNG_sRGB_INTENT_LAST)
  171569. {
  171570. png_warning(png_ptr, "Unknown sRGB intent");
  171571. return;
  171572. }
  171573. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171574. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171575. {
  171576. png_fixed_point igamma;
  171577. #ifdef PNG_FIXED_POINT_SUPPORTED
  171578. igamma=info_ptr->int_gamma;
  171579. #else
  171580. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171581. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171582. # endif
  171583. #endif
  171584. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171585. {
  171586. png_warning(png_ptr,
  171587. "Ignoring incorrect gAMA value when sRGB is also present");
  171588. #ifndef PNG_NO_CONSOLE_IO
  171589. # ifdef PNG_FIXED_POINT_SUPPORTED
  171590. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171591. # else
  171592. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171593. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171594. # endif
  171595. # endif
  171596. #endif
  171597. }
  171598. }
  171599. #endif /* PNG_READ_gAMA_SUPPORTED */
  171600. #ifdef PNG_READ_cHRM_SUPPORTED
  171601. #ifdef PNG_FIXED_POINT_SUPPORTED
  171602. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171603. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171604. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171605. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171606. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171607. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171608. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171609. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171610. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171611. {
  171612. png_warning(png_ptr,
  171613. "Ignoring incorrect cHRM value when sRGB is also present");
  171614. }
  171615. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171616. #endif /* PNG_READ_cHRM_SUPPORTED */
  171617. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171618. }
  171619. #endif /* PNG_READ_sRGB_SUPPORTED */
  171620. #if defined(PNG_READ_iCCP_SUPPORTED)
  171621. void /* PRIVATE */
  171622. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171623. {
  171624. png_charp chunkdata;
  171625. png_byte compression_type;
  171626. png_bytep pC;
  171627. png_charp profile;
  171628. png_uint_32 skip = 0;
  171629. png_uint_32 profile_size, profile_length;
  171630. png_size_t slength, prefix_length, data_length;
  171631. png_debug(1, "in png_handle_iCCP\n");
  171632. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171633. png_error(png_ptr, "Missing IHDR before iCCP");
  171634. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171635. {
  171636. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171637. png_crc_finish(png_ptr, length);
  171638. return;
  171639. }
  171640. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171641. png_warning(png_ptr, "Out of place iCCP chunk");
  171642. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171643. {
  171644. png_warning(png_ptr, "Duplicate iCCP chunk");
  171645. png_crc_finish(png_ptr, length);
  171646. return;
  171647. }
  171648. #ifdef PNG_MAX_MALLOC_64K
  171649. if (length > (png_uint_32)65535L)
  171650. {
  171651. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171652. skip = length - (png_uint_32)65535L;
  171653. length = (png_uint_32)65535L;
  171654. }
  171655. #endif
  171656. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171657. slength = (png_size_t)length;
  171658. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171659. if (png_crc_finish(png_ptr, skip))
  171660. {
  171661. png_free(png_ptr, chunkdata);
  171662. return;
  171663. }
  171664. chunkdata[slength] = 0x00;
  171665. for (profile = chunkdata; *profile; profile++)
  171666. ;
  171667. ++profile;
  171668. if ( profile >= chunkdata + slength - 1)
  171669. {
  171670. png_free(png_ptr, chunkdata);
  171671. png_warning(png_ptr, "Malformed iCCP chunk");
  171672. return;
  171673. }
  171674. compression_type = *profile++;
  171675. if (compression_type)
  171676. {
  171677. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  171678. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  171679. wrote nonzero) */
  171680. }
  171681. prefix_length = profile - chunkdata;
  171682. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  171683. slength, prefix_length, &data_length);
  171684. profile_length = data_length - prefix_length;
  171685. if ( prefix_length > data_length || profile_length < 4)
  171686. {
  171687. png_free(png_ptr, chunkdata);
  171688. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  171689. return;
  171690. }
  171691. pC = (png_bytep)(chunkdata+prefix_length);
  171692. profile_size = ((*(pC ))<<24) |
  171693. ((*(pC+1))<<16) |
  171694. ((*(pC+2))<< 8) |
  171695. ((*(pC+3)) );
  171696. if(profile_size < profile_length)
  171697. profile_length = profile_size;
  171698. if(profile_size > profile_length)
  171699. {
  171700. png_free(png_ptr, chunkdata);
  171701. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  171702. return;
  171703. }
  171704. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  171705. chunkdata + prefix_length, profile_length);
  171706. png_free(png_ptr, chunkdata);
  171707. }
  171708. #endif /* PNG_READ_iCCP_SUPPORTED */
  171709. #if defined(PNG_READ_sPLT_SUPPORTED)
  171710. void /* PRIVATE */
  171711. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171712. {
  171713. png_bytep chunkdata;
  171714. png_bytep entry_start;
  171715. png_sPLT_t new_palette;
  171716. #ifdef PNG_NO_POINTER_INDEXING
  171717. png_sPLT_entryp pp;
  171718. #endif
  171719. int data_length, entry_size, i;
  171720. png_uint_32 skip = 0;
  171721. png_size_t slength;
  171722. png_debug(1, "in png_handle_sPLT\n");
  171723. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171724. png_error(png_ptr, "Missing IHDR before sPLT");
  171725. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171726. {
  171727. png_warning(png_ptr, "Invalid sPLT after IDAT");
  171728. png_crc_finish(png_ptr, length);
  171729. return;
  171730. }
  171731. #ifdef PNG_MAX_MALLOC_64K
  171732. if (length > (png_uint_32)65535L)
  171733. {
  171734. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  171735. skip = length - (png_uint_32)65535L;
  171736. length = (png_uint_32)65535L;
  171737. }
  171738. #endif
  171739. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  171740. slength = (png_size_t)length;
  171741. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171742. if (png_crc_finish(png_ptr, skip))
  171743. {
  171744. png_free(png_ptr, chunkdata);
  171745. return;
  171746. }
  171747. chunkdata[slength] = 0x00;
  171748. for (entry_start = chunkdata; *entry_start; entry_start++)
  171749. ;
  171750. ++entry_start;
  171751. if (entry_start > chunkdata + slength - 2)
  171752. {
  171753. png_free(png_ptr, chunkdata);
  171754. png_warning(png_ptr, "malformed sPLT chunk");
  171755. return;
  171756. }
  171757. new_palette.depth = *entry_start++;
  171758. entry_size = (new_palette.depth == 8 ? 6 : 10);
  171759. data_length = (slength - (entry_start - chunkdata));
  171760. if (data_length % entry_size)
  171761. {
  171762. png_free(png_ptr, chunkdata);
  171763. png_warning(png_ptr, "sPLT chunk has bad length");
  171764. return;
  171765. }
  171766. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  171767. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  171768. png_sizeof(png_sPLT_entry)))
  171769. {
  171770. png_warning(png_ptr, "sPLT chunk too long");
  171771. return;
  171772. }
  171773. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  171774. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  171775. if (new_palette.entries == NULL)
  171776. {
  171777. png_warning(png_ptr, "sPLT chunk requires too much memory");
  171778. return;
  171779. }
  171780. #ifndef PNG_NO_POINTER_INDEXING
  171781. for (i = 0; i < new_palette.nentries; i++)
  171782. {
  171783. png_sPLT_entryp pp = new_palette.entries + i;
  171784. if (new_palette.depth == 8)
  171785. {
  171786. pp->red = *entry_start++;
  171787. pp->green = *entry_start++;
  171788. pp->blue = *entry_start++;
  171789. pp->alpha = *entry_start++;
  171790. }
  171791. else
  171792. {
  171793. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  171794. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  171795. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  171796. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  171797. }
  171798. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171799. }
  171800. #else
  171801. pp = new_palette.entries;
  171802. for (i = 0; i < new_palette.nentries; i++)
  171803. {
  171804. if (new_palette.depth == 8)
  171805. {
  171806. pp[i].red = *entry_start++;
  171807. pp[i].green = *entry_start++;
  171808. pp[i].blue = *entry_start++;
  171809. pp[i].alpha = *entry_start++;
  171810. }
  171811. else
  171812. {
  171813. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  171814. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  171815. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  171816. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  171817. }
  171818. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171819. }
  171820. #endif
  171821. new_palette.name = (png_charp)chunkdata;
  171822. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  171823. png_free(png_ptr, chunkdata);
  171824. png_free(png_ptr, new_palette.entries);
  171825. }
  171826. #endif /* PNG_READ_sPLT_SUPPORTED */
  171827. #if defined(PNG_READ_tRNS_SUPPORTED)
  171828. void /* PRIVATE */
  171829. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171830. {
  171831. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  171832. int bit_mask;
  171833. png_debug(1, "in png_handle_tRNS\n");
  171834. bit_mask = (1 << png_ptr->bit_depth) - 1;
  171835. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171836. png_error(png_ptr, "Missing IHDR before tRNS");
  171837. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171838. {
  171839. png_warning(png_ptr, "Invalid tRNS after IDAT");
  171840. png_crc_finish(png_ptr, length);
  171841. return;
  171842. }
  171843. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171844. {
  171845. png_warning(png_ptr, "Duplicate tRNS chunk");
  171846. png_crc_finish(png_ptr, length);
  171847. return;
  171848. }
  171849. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  171850. {
  171851. png_byte buf[2];
  171852. if (length != 2)
  171853. {
  171854. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171855. png_crc_finish(png_ptr, length);
  171856. return;
  171857. }
  171858. png_crc_read(png_ptr, buf, 2);
  171859. png_ptr->num_trans = 1;
  171860. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  171861. }
  171862. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  171863. {
  171864. png_byte buf[6];
  171865. if (length != 6)
  171866. {
  171867. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171868. png_crc_finish(png_ptr, length);
  171869. return;
  171870. }
  171871. png_crc_read(png_ptr, buf, (png_size_t)length);
  171872. png_ptr->num_trans = 1;
  171873. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  171874. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  171875. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  171876. }
  171877. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171878. {
  171879. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171880. {
  171881. png_warning(png_ptr, "Missing PLTE before tRNS");
  171882. }
  171883. if (length > (png_uint_32)png_ptr->num_palette ||
  171884. length > PNG_MAX_PALETTE_LENGTH)
  171885. {
  171886. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171887. png_crc_finish(png_ptr, length);
  171888. return;
  171889. }
  171890. if (length == 0)
  171891. {
  171892. png_warning(png_ptr, "Zero length tRNS chunk");
  171893. png_crc_finish(png_ptr, length);
  171894. return;
  171895. }
  171896. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  171897. png_ptr->num_trans = (png_uint_16)length;
  171898. }
  171899. else
  171900. {
  171901. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  171902. png_crc_finish(png_ptr, length);
  171903. return;
  171904. }
  171905. if (png_crc_finish(png_ptr, 0))
  171906. {
  171907. png_ptr->num_trans = 0;
  171908. return;
  171909. }
  171910. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  171911. &(png_ptr->trans_values));
  171912. }
  171913. #endif
  171914. #if defined(PNG_READ_bKGD_SUPPORTED)
  171915. void /* PRIVATE */
  171916. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171917. {
  171918. png_size_t truelen;
  171919. png_byte buf[6];
  171920. png_debug(1, "in png_handle_bKGD\n");
  171921. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171922. png_error(png_ptr, "Missing IHDR before bKGD");
  171923. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171924. {
  171925. png_warning(png_ptr, "Invalid bKGD after IDAT");
  171926. png_crc_finish(png_ptr, length);
  171927. return;
  171928. }
  171929. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  171930. !(png_ptr->mode & PNG_HAVE_PLTE))
  171931. {
  171932. png_warning(png_ptr, "Missing PLTE before bKGD");
  171933. png_crc_finish(png_ptr, length);
  171934. return;
  171935. }
  171936. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  171937. {
  171938. png_warning(png_ptr, "Duplicate bKGD chunk");
  171939. png_crc_finish(png_ptr, length);
  171940. return;
  171941. }
  171942. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171943. truelen = 1;
  171944. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171945. truelen = 6;
  171946. else
  171947. truelen = 2;
  171948. if (length != truelen)
  171949. {
  171950. png_warning(png_ptr, "Incorrect bKGD chunk length");
  171951. png_crc_finish(png_ptr, length);
  171952. return;
  171953. }
  171954. png_crc_read(png_ptr, buf, truelen);
  171955. if (png_crc_finish(png_ptr, 0))
  171956. return;
  171957. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171958. {
  171959. png_ptr->background.index = buf[0];
  171960. if(info_ptr->num_palette)
  171961. {
  171962. if(buf[0] > info_ptr->num_palette)
  171963. {
  171964. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  171965. return;
  171966. }
  171967. png_ptr->background.red =
  171968. (png_uint_16)png_ptr->palette[buf[0]].red;
  171969. png_ptr->background.green =
  171970. (png_uint_16)png_ptr->palette[buf[0]].green;
  171971. png_ptr->background.blue =
  171972. (png_uint_16)png_ptr->palette[buf[0]].blue;
  171973. }
  171974. }
  171975. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  171976. {
  171977. png_ptr->background.red =
  171978. png_ptr->background.green =
  171979. png_ptr->background.blue =
  171980. png_ptr->background.gray = png_get_uint_16(buf);
  171981. }
  171982. else
  171983. {
  171984. png_ptr->background.red = png_get_uint_16(buf);
  171985. png_ptr->background.green = png_get_uint_16(buf + 2);
  171986. png_ptr->background.blue = png_get_uint_16(buf + 4);
  171987. }
  171988. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  171989. }
  171990. #endif
  171991. #if defined(PNG_READ_hIST_SUPPORTED)
  171992. void /* PRIVATE */
  171993. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171994. {
  171995. unsigned int num, i;
  171996. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  171997. png_debug(1, "in png_handle_hIST\n");
  171998. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171999. png_error(png_ptr, "Missing IHDR before hIST");
  172000. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172001. {
  172002. png_warning(png_ptr, "Invalid hIST after IDAT");
  172003. png_crc_finish(png_ptr, length);
  172004. return;
  172005. }
  172006. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172007. {
  172008. png_warning(png_ptr, "Missing PLTE before hIST");
  172009. png_crc_finish(png_ptr, length);
  172010. return;
  172011. }
  172012. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  172013. {
  172014. png_warning(png_ptr, "Duplicate hIST chunk");
  172015. png_crc_finish(png_ptr, length);
  172016. return;
  172017. }
  172018. num = length / 2 ;
  172019. if (num != (unsigned int) png_ptr->num_palette || num >
  172020. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  172021. {
  172022. png_warning(png_ptr, "Incorrect hIST chunk length");
  172023. png_crc_finish(png_ptr, length);
  172024. return;
  172025. }
  172026. for (i = 0; i < num; i++)
  172027. {
  172028. png_byte buf[2];
  172029. png_crc_read(png_ptr, buf, 2);
  172030. readbuf[i] = png_get_uint_16(buf);
  172031. }
  172032. if (png_crc_finish(png_ptr, 0))
  172033. return;
  172034. png_set_hIST(png_ptr, info_ptr, readbuf);
  172035. }
  172036. #endif
  172037. #if defined(PNG_READ_pHYs_SUPPORTED)
  172038. void /* PRIVATE */
  172039. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172040. {
  172041. png_byte buf[9];
  172042. png_uint_32 res_x, res_y;
  172043. int unit_type;
  172044. png_debug(1, "in png_handle_pHYs\n");
  172045. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172046. png_error(png_ptr, "Missing IHDR before pHYs");
  172047. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172048. {
  172049. png_warning(png_ptr, "Invalid pHYs after IDAT");
  172050. png_crc_finish(png_ptr, length);
  172051. return;
  172052. }
  172053. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  172054. {
  172055. png_warning(png_ptr, "Duplicate pHYs chunk");
  172056. png_crc_finish(png_ptr, length);
  172057. return;
  172058. }
  172059. if (length != 9)
  172060. {
  172061. png_warning(png_ptr, "Incorrect pHYs chunk length");
  172062. png_crc_finish(png_ptr, length);
  172063. return;
  172064. }
  172065. png_crc_read(png_ptr, buf, 9);
  172066. if (png_crc_finish(png_ptr, 0))
  172067. return;
  172068. res_x = png_get_uint_32(buf);
  172069. res_y = png_get_uint_32(buf + 4);
  172070. unit_type = buf[8];
  172071. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  172072. }
  172073. #endif
  172074. #if defined(PNG_READ_oFFs_SUPPORTED)
  172075. void /* PRIVATE */
  172076. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172077. {
  172078. png_byte buf[9];
  172079. png_int_32 offset_x, offset_y;
  172080. int unit_type;
  172081. png_debug(1, "in png_handle_oFFs\n");
  172082. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172083. png_error(png_ptr, "Missing IHDR before oFFs");
  172084. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172085. {
  172086. png_warning(png_ptr, "Invalid oFFs after IDAT");
  172087. png_crc_finish(png_ptr, length);
  172088. return;
  172089. }
  172090. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  172091. {
  172092. png_warning(png_ptr, "Duplicate oFFs chunk");
  172093. png_crc_finish(png_ptr, length);
  172094. return;
  172095. }
  172096. if (length != 9)
  172097. {
  172098. png_warning(png_ptr, "Incorrect oFFs chunk length");
  172099. png_crc_finish(png_ptr, length);
  172100. return;
  172101. }
  172102. png_crc_read(png_ptr, buf, 9);
  172103. if (png_crc_finish(png_ptr, 0))
  172104. return;
  172105. offset_x = png_get_int_32(buf);
  172106. offset_y = png_get_int_32(buf + 4);
  172107. unit_type = buf[8];
  172108. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  172109. }
  172110. #endif
  172111. #if defined(PNG_READ_pCAL_SUPPORTED)
  172112. void /* PRIVATE */
  172113. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172114. {
  172115. png_charp purpose;
  172116. png_int_32 X0, X1;
  172117. png_byte type, nparams;
  172118. png_charp buf, units, endptr;
  172119. png_charpp params;
  172120. png_size_t slength;
  172121. int i;
  172122. png_debug(1, "in png_handle_pCAL\n");
  172123. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172124. png_error(png_ptr, "Missing IHDR before pCAL");
  172125. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172126. {
  172127. png_warning(png_ptr, "Invalid pCAL after IDAT");
  172128. png_crc_finish(png_ptr, length);
  172129. return;
  172130. }
  172131. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  172132. {
  172133. png_warning(png_ptr, "Duplicate pCAL chunk");
  172134. png_crc_finish(png_ptr, length);
  172135. return;
  172136. }
  172137. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  172138. length + 1);
  172139. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172140. if (purpose == NULL)
  172141. {
  172142. png_warning(png_ptr, "No memory for pCAL purpose.");
  172143. return;
  172144. }
  172145. slength = (png_size_t)length;
  172146. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  172147. if (png_crc_finish(png_ptr, 0))
  172148. {
  172149. png_free(png_ptr, purpose);
  172150. return;
  172151. }
  172152. purpose[slength] = 0x00; /* null terminate the last string */
  172153. png_debug(3, "Finding end of pCAL purpose string\n");
  172154. for (buf = purpose; *buf; buf++)
  172155. ;
  172156. endptr = purpose + slength;
  172157. if (endptr <= buf + 12)
  172158. {
  172159. png_warning(png_ptr, "Invalid pCAL data");
  172160. png_free(png_ptr, purpose);
  172161. return;
  172162. }
  172163. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  172164. X0 = png_get_int_32((png_bytep)buf+1);
  172165. X1 = png_get_int_32((png_bytep)buf+5);
  172166. type = buf[9];
  172167. nparams = buf[10];
  172168. units = buf + 11;
  172169. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  172170. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  172171. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  172172. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  172173. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  172174. {
  172175. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  172176. png_free(png_ptr, purpose);
  172177. return;
  172178. }
  172179. else if (type >= PNG_EQUATION_LAST)
  172180. {
  172181. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  172182. }
  172183. for (buf = units; *buf; buf++)
  172184. ;
  172185. png_debug(3, "Allocating pCAL parameters array\n");
  172186. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  172187. *png_sizeof(png_charp))) ;
  172188. if (params == NULL)
  172189. {
  172190. png_free(png_ptr, purpose);
  172191. png_warning(png_ptr, "No memory for pCAL params.");
  172192. return;
  172193. }
  172194. for (i = 0; i < (int)nparams; i++)
  172195. {
  172196. buf++; /* Skip the null string terminator from previous parameter. */
  172197. png_debug1(3, "Reading pCAL parameter %d\n", i);
  172198. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  172199. ;
  172200. if (buf > endptr)
  172201. {
  172202. png_warning(png_ptr, "Invalid pCAL data");
  172203. png_free(png_ptr, purpose);
  172204. png_free(png_ptr, params);
  172205. return;
  172206. }
  172207. }
  172208. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  172209. units, params);
  172210. png_free(png_ptr, purpose);
  172211. png_free(png_ptr, params);
  172212. }
  172213. #endif
  172214. #if defined(PNG_READ_sCAL_SUPPORTED)
  172215. void /* PRIVATE */
  172216. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172217. {
  172218. png_charp buffer, ep;
  172219. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172220. double width, height;
  172221. png_charp vp;
  172222. #else
  172223. #ifdef PNG_FIXED_POINT_SUPPORTED
  172224. png_charp swidth, sheight;
  172225. #endif
  172226. #endif
  172227. png_size_t slength;
  172228. png_debug(1, "in png_handle_sCAL\n");
  172229. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172230. png_error(png_ptr, "Missing IHDR before sCAL");
  172231. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172232. {
  172233. png_warning(png_ptr, "Invalid sCAL after IDAT");
  172234. png_crc_finish(png_ptr, length);
  172235. return;
  172236. }
  172237. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  172238. {
  172239. png_warning(png_ptr, "Duplicate sCAL chunk");
  172240. png_crc_finish(png_ptr, length);
  172241. return;
  172242. }
  172243. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  172244. length + 1);
  172245. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172246. if (buffer == NULL)
  172247. {
  172248. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  172249. return;
  172250. }
  172251. slength = (png_size_t)length;
  172252. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  172253. if (png_crc_finish(png_ptr, 0))
  172254. {
  172255. png_free(png_ptr, buffer);
  172256. return;
  172257. }
  172258. buffer[slength] = 0x00; /* null terminate the last string */
  172259. ep = buffer + 1; /* skip unit byte */
  172260. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172261. width = png_strtod(png_ptr, ep, &vp);
  172262. if (*vp)
  172263. {
  172264. png_warning(png_ptr, "malformed width string in sCAL chunk");
  172265. return;
  172266. }
  172267. #else
  172268. #ifdef PNG_FIXED_POINT_SUPPORTED
  172269. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172270. if (swidth == NULL)
  172271. {
  172272. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  172273. return;
  172274. }
  172275. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172276. #endif
  172277. #endif
  172278. for (ep = buffer; *ep; ep++)
  172279. ;
  172280. ep++;
  172281. if (buffer + slength < ep)
  172282. {
  172283. png_warning(png_ptr, "Truncated sCAL chunk");
  172284. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172285. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172286. png_free(png_ptr, swidth);
  172287. #endif
  172288. png_free(png_ptr, buffer);
  172289. return;
  172290. }
  172291. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172292. height = png_strtod(png_ptr, ep, &vp);
  172293. if (*vp)
  172294. {
  172295. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172296. return;
  172297. }
  172298. #else
  172299. #ifdef PNG_FIXED_POINT_SUPPORTED
  172300. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172301. if (swidth == NULL)
  172302. {
  172303. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172304. return;
  172305. }
  172306. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172307. #endif
  172308. #endif
  172309. if (buffer + slength < ep
  172310. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172311. || width <= 0. || height <= 0.
  172312. #endif
  172313. )
  172314. {
  172315. png_warning(png_ptr, "Invalid sCAL data");
  172316. png_free(png_ptr, buffer);
  172317. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172318. png_free(png_ptr, swidth);
  172319. png_free(png_ptr, sheight);
  172320. #endif
  172321. return;
  172322. }
  172323. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172324. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172325. #else
  172326. #ifdef PNG_FIXED_POINT_SUPPORTED
  172327. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172328. #endif
  172329. #endif
  172330. png_free(png_ptr, buffer);
  172331. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172332. png_free(png_ptr, swidth);
  172333. png_free(png_ptr, sheight);
  172334. #endif
  172335. }
  172336. #endif
  172337. #if defined(PNG_READ_tIME_SUPPORTED)
  172338. void /* PRIVATE */
  172339. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172340. {
  172341. png_byte buf[7];
  172342. png_time mod_time;
  172343. png_debug(1, "in png_handle_tIME\n");
  172344. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172345. png_error(png_ptr, "Out of place tIME chunk");
  172346. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172347. {
  172348. png_warning(png_ptr, "Duplicate tIME chunk");
  172349. png_crc_finish(png_ptr, length);
  172350. return;
  172351. }
  172352. if (png_ptr->mode & PNG_HAVE_IDAT)
  172353. png_ptr->mode |= PNG_AFTER_IDAT;
  172354. if (length != 7)
  172355. {
  172356. png_warning(png_ptr, "Incorrect tIME chunk length");
  172357. png_crc_finish(png_ptr, length);
  172358. return;
  172359. }
  172360. png_crc_read(png_ptr, buf, 7);
  172361. if (png_crc_finish(png_ptr, 0))
  172362. return;
  172363. mod_time.second = buf[6];
  172364. mod_time.minute = buf[5];
  172365. mod_time.hour = buf[4];
  172366. mod_time.day = buf[3];
  172367. mod_time.month = buf[2];
  172368. mod_time.year = png_get_uint_16(buf);
  172369. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172370. }
  172371. #endif
  172372. #if defined(PNG_READ_tEXt_SUPPORTED)
  172373. void /* PRIVATE */
  172374. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172375. {
  172376. png_textp text_ptr;
  172377. png_charp key;
  172378. png_charp text;
  172379. png_uint_32 skip = 0;
  172380. png_size_t slength;
  172381. int ret;
  172382. png_debug(1, "in png_handle_tEXt\n");
  172383. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172384. png_error(png_ptr, "Missing IHDR before tEXt");
  172385. if (png_ptr->mode & PNG_HAVE_IDAT)
  172386. png_ptr->mode |= PNG_AFTER_IDAT;
  172387. #ifdef PNG_MAX_MALLOC_64K
  172388. if (length > (png_uint_32)65535L)
  172389. {
  172390. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172391. skip = length - (png_uint_32)65535L;
  172392. length = (png_uint_32)65535L;
  172393. }
  172394. #endif
  172395. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172396. if (key == NULL)
  172397. {
  172398. png_warning(png_ptr, "No memory to process text chunk.");
  172399. return;
  172400. }
  172401. slength = (png_size_t)length;
  172402. png_crc_read(png_ptr, (png_bytep)key, slength);
  172403. if (png_crc_finish(png_ptr, skip))
  172404. {
  172405. png_free(png_ptr, key);
  172406. return;
  172407. }
  172408. key[slength] = 0x00;
  172409. for (text = key; *text; text++)
  172410. ;
  172411. if (text != key + slength)
  172412. text++;
  172413. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172414. (png_uint_32)png_sizeof(png_text));
  172415. if (text_ptr == NULL)
  172416. {
  172417. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172418. png_free(png_ptr, key);
  172419. return;
  172420. }
  172421. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172422. text_ptr->key = key;
  172423. #ifdef PNG_iTXt_SUPPORTED
  172424. text_ptr->lang = NULL;
  172425. text_ptr->lang_key = NULL;
  172426. text_ptr->itxt_length = 0;
  172427. #endif
  172428. text_ptr->text = text;
  172429. text_ptr->text_length = png_strlen(text);
  172430. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172431. png_free(png_ptr, key);
  172432. png_free(png_ptr, text_ptr);
  172433. if (ret)
  172434. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172435. }
  172436. #endif
  172437. #if defined(PNG_READ_zTXt_SUPPORTED)
  172438. void /* PRIVATE */
  172439. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172440. {
  172441. png_textp text_ptr;
  172442. png_charp chunkdata;
  172443. png_charp text;
  172444. int comp_type;
  172445. int ret;
  172446. png_size_t slength, prefix_len, data_len;
  172447. png_debug(1, "in png_handle_zTXt\n");
  172448. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172449. png_error(png_ptr, "Missing IHDR before zTXt");
  172450. if (png_ptr->mode & PNG_HAVE_IDAT)
  172451. png_ptr->mode |= PNG_AFTER_IDAT;
  172452. #ifdef PNG_MAX_MALLOC_64K
  172453. if (length > (png_uint_32)65535L)
  172454. {
  172455. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172456. png_crc_finish(png_ptr, length);
  172457. return;
  172458. }
  172459. #endif
  172460. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172461. if (chunkdata == NULL)
  172462. {
  172463. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172464. return;
  172465. }
  172466. slength = (png_size_t)length;
  172467. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172468. if (png_crc_finish(png_ptr, 0))
  172469. {
  172470. png_free(png_ptr, chunkdata);
  172471. return;
  172472. }
  172473. chunkdata[slength] = 0x00;
  172474. for (text = chunkdata; *text; text++)
  172475. ;
  172476. if (text >= chunkdata + slength - 2)
  172477. {
  172478. png_warning(png_ptr, "Truncated zTXt chunk");
  172479. png_free(png_ptr, chunkdata);
  172480. return;
  172481. }
  172482. else
  172483. {
  172484. comp_type = *(++text);
  172485. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172486. {
  172487. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172488. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172489. }
  172490. text++; /* skip the compression_method byte */
  172491. }
  172492. prefix_len = text - chunkdata;
  172493. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172494. (png_size_t)length, prefix_len, &data_len);
  172495. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172496. (png_uint_32)png_sizeof(png_text));
  172497. if (text_ptr == NULL)
  172498. {
  172499. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172500. png_free(png_ptr, chunkdata);
  172501. return;
  172502. }
  172503. text_ptr->compression = comp_type;
  172504. text_ptr->key = chunkdata;
  172505. #ifdef PNG_iTXt_SUPPORTED
  172506. text_ptr->lang = NULL;
  172507. text_ptr->lang_key = NULL;
  172508. text_ptr->itxt_length = 0;
  172509. #endif
  172510. text_ptr->text = chunkdata + prefix_len;
  172511. text_ptr->text_length = data_len;
  172512. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172513. png_free(png_ptr, text_ptr);
  172514. png_free(png_ptr, chunkdata);
  172515. if (ret)
  172516. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172517. }
  172518. #endif
  172519. #if defined(PNG_READ_iTXt_SUPPORTED)
  172520. void /* PRIVATE */
  172521. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172522. {
  172523. png_textp text_ptr;
  172524. png_charp chunkdata;
  172525. png_charp key, lang, text, lang_key;
  172526. int comp_flag;
  172527. int comp_type = 0;
  172528. int ret;
  172529. png_size_t slength, prefix_len, data_len;
  172530. png_debug(1, "in png_handle_iTXt\n");
  172531. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172532. png_error(png_ptr, "Missing IHDR before iTXt");
  172533. if (png_ptr->mode & PNG_HAVE_IDAT)
  172534. png_ptr->mode |= PNG_AFTER_IDAT;
  172535. #ifdef PNG_MAX_MALLOC_64K
  172536. if (length > (png_uint_32)65535L)
  172537. {
  172538. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172539. png_crc_finish(png_ptr, length);
  172540. return;
  172541. }
  172542. #endif
  172543. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172544. if (chunkdata == NULL)
  172545. {
  172546. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172547. return;
  172548. }
  172549. slength = (png_size_t)length;
  172550. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172551. if (png_crc_finish(png_ptr, 0))
  172552. {
  172553. png_free(png_ptr, chunkdata);
  172554. return;
  172555. }
  172556. chunkdata[slength] = 0x00;
  172557. for (lang = chunkdata; *lang; lang++)
  172558. ;
  172559. lang++; /* skip NUL separator */
  172560. if (lang >= chunkdata + slength - 3)
  172561. {
  172562. png_warning(png_ptr, "Truncated iTXt chunk");
  172563. png_free(png_ptr, chunkdata);
  172564. return;
  172565. }
  172566. else
  172567. {
  172568. comp_flag = *lang++;
  172569. comp_type = *lang++;
  172570. }
  172571. for (lang_key = lang; *lang_key; lang_key++)
  172572. ;
  172573. lang_key++; /* skip NUL separator */
  172574. if (lang_key >= chunkdata + slength)
  172575. {
  172576. png_warning(png_ptr, "Truncated iTXt chunk");
  172577. png_free(png_ptr, chunkdata);
  172578. return;
  172579. }
  172580. for (text = lang_key; *text; text++)
  172581. ;
  172582. text++; /* skip NUL separator */
  172583. if (text >= chunkdata + slength)
  172584. {
  172585. png_warning(png_ptr, "Malformed iTXt chunk");
  172586. png_free(png_ptr, chunkdata);
  172587. return;
  172588. }
  172589. prefix_len = text - chunkdata;
  172590. key=chunkdata;
  172591. if (comp_flag)
  172592. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172593. (size_t)length, prefix_len, &data_len);
  172594. else
  172595. data_len=png_strlen(chunkdata + prefix_len);
  172596. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172597. (png_uint_32)png_sizeof(png_text));
  172598. if (text_ptr == NULL)
  172599. {
  172600. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172601. png_free(png_ptr, chunkdata);
  172602. return;
  172603. }
  172604. text_ptr->compression = (int)comp_flag + 1;
  172605. text_ptr->lang_key = chunkdata+(lang_key-key);
  172606. text_ptr->lang = chunkdata+(lang-key);
  172607. text_ptr->itxt_length = data_len;
  172608. text_ptr->text_length = 0;
  172609. text_ptr->key = chunkdata;
  172610. text_ptr->text = chunkdata + prefix_len;
  172611. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172612. png_free(png_ptr, text_ptr);
  172613. png_free(png_ptr, chunkdata);
  172614. if (ret)
  172615. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172616. }
  172617. #endif
  172618. void /* PRIVATE */
  172619. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172620. {
  172621. png_uint_32 skip = 0;
  172622. png_debug(1, "in png_handle_unknown\n");
  172623. if (png_ptr->mode & PNG_HAVE_IDAT)
  172624. {
  172625. #ifdef PNG_USE_LOCAL_ARRAYS
  172626. PNG_CONST PNG_IDAT;
  172627. #endif
  172628. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172629. png_ptr->mode |= PNG_AFTER_IDAT;
  172630. }
  172631. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172632. if (!(png_ptr->chunk_name[0] & 0x20))
  172633. {
  172634. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172635. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172636. PNG_HANDLE_CHUNK_ALWAYS
  172637. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172638. && png_ptr->read_user_chunk_fn == NULL
  172639. #endif
  172640. )
  172641. #endif
  172642. png_chunk_error(png_ptr, "unknown critical chunk");
  172643. }
  172644. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172645. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172646. (png_ptr->read_user_chunk_fn != NULL))
  172647. {
  172648. #ifdef PNG_MAX_MALLOC_64K
  172649. if (length > (png_uint_32)65535L)
  172650. {
  172651. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172652. skip = length - (png_uint_32)65535L;
  172653. length = (png_uint_32)65535L;
  172654. }
  172655. #endif
  172656. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172657. (png_charp)png_ptr->chunk_name, 5);
  172658. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172659. png_ptr->unknown_chunk.size = (png_size_t)length;
  172660. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172661. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172662. if(png_ptr->read_user_chunk_fn != NULL)
  172663. {
  172664. int ret;
  172665. ret = (*(png_ptr->read_user_chunk_fn))
  172666. (png_ptr, &png_ptr->unknown_chunk);
  172667. if (ret < 0)
  172668. png_chunk_error(png_ptr, "error in user chunk");
  172669. if (ret == 0)
  172670. {
  172671. if (!(png_ptr->chunk_name[0] & 0x20))
  172672. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172673. PNG_HANDLE_CHUNK_ALWAYS)
  172674. png_chunk_error(png_ptr, "unknown critical chunk");
  172675. png_set_unknown_chunks(png_ptr, info_ptr,
  172676. &png_ptr->unknown_chunk, 1);
  172677. }
  172678. }
  172679. #else
  172680. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  172681. #endif
  172682. png_free(png_ptr, png_ptr->unknown_chunk.data);
  172683. png_ptr->unknown_chunk.data = NULL;
  172684. }
  172685. else
  172686. #endif
  172687. skip = length;
  172688. png_crc_finish(png_ptr, skip);
  172689. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172690. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  172691. #endif
  172692. }
  172693. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  172694. void /* PRIVATE */
  172695. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  172696. {
  172697. png_debug(1, "in png_check_chunk_name\n");
  172698. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  172699. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  172700. {
  172701. png_chunk_error(png_ptr, "invalid chunk type");
  172702. }
  172703. }
  172704. void /* PRIVATE */
  172705. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  172706. {
  172707. png_debug(1,"in png_combine_row\n");
  172708. if (mask == 0xff)
  172709. {
  172710. png_memcpy(row, png_ptr->row_buf + 1,
  172711. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  172712. }
  172713. else
  172714. {
  172715. switch (png_ptr->row_info.pixel_depth)
  172716. {
  172717. case 1:
  172718. {
  172719. png_bytep sp = png_ptr->row_buf + 1;
  172720. png_bytep dp = row;
  172721. int s_inc, s_start, s_end;
  172722. int m = 0x80;
  172723. int shift;
  172724. png_uint_32 i;
  172725. png_uint_32 row_width = png_ptr->width;
  172726. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172727. if (png_ptr->transformations & PNG_PACKSWAP)
  172728. {
  172729. s_start = 0;
  172730. s_end = 7;
  172731. s_inc = 1;
  172732. }
  172733. else
  172734. #endif
  172735. {
  172736. s_start = 7;
  172737. s_end = 0;
  172738. s_inc = -1;
  172739. }
  172740. shift = s_start;
  172741. for (i = 0; i < row_width; i++)
  172742. {
  172743. if (m & mask)
  172744. {
  172745. int value;
  172746. value = (*sp >> shift) & 0x01;
  172747. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  172748. *dp |= (png_byte)(value << shift);
  172749. }
  172750. if (shift == s_end)
  172751. {
  172752. shift = s_start;
  172753. sp++;
  172754. dp++;
  172755. }
  172756. else
  172757. shift += s_inc;
  172758. if (m == 1)
  172759. m = 0x80;
  172760. else
  172761. m >>= 1;
  172762. }
  172763. break;
  172764. }
  172765. case 2:
  172766. {
  172767. png_bytep sp = png_ptr->row_buf + 1;
  172768. png_bytep dp = row;
  172769. int s_start, s_end, s_inc;
  172770. int m = 0x80;
  172771. int shift;
  172772. png_uint_32 i;
  172773. png_uint_32 row_width = png_ptr->width;
  172774. int value;
  172775. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172776. if (png_ptr->transformations & PNG_PACKSWAP)
  172777. {
  172778. s_start = 0;
  172779. s_end = 6;
  172780. s_inc = 2;
  172781. }
  172782. else
  172783. #endif
  172784. {
  172785. s_start = 6;
  172786. s_end = 0;
  172787. s_inc = -2;
  172788. }
  172789. shift = s_start;
  172790. for (i = 0; i < row_width; i++)
  172791. {
  172792. if (m & mask)
  172793. {
  172794. value = (*sp >> shift) & 0x03;
  172795. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  172796. *dp |= (png_byte)(value << shift);
  172797. }
  172798. if (shift == s_end)
  172799. {
  172800. shift = s_start;
  172801. sp++;
  172802. dp++;
  172803. }
  172804. else
  172805. shift += s_inc;
  172806. if (m == 1)
  172807. m = 0x80;
  172808. else
  172809. m >>= 1;
  172810. }
  172811. break;
  172812. }
  172813. case 4:
  172814. {
  172815. png_bytep sp = png_ptr->row_buf + 1;
  172816. png_bytep dp = row;
  172817. int s_start, s_end, s_inc;
  172818. int m = 0x80;
  172819. int shift;
  172820. png_uint_32 i;
  172821. png_uint_32 row_width = png_ptr->width;
  172822. int value;
  172823. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172824. if (png_ptr->transformations & PNG_PACKSWAP)
  172825. {
  172826. s_start = 0;
  172827. s_end = 4;
  172828. s_inc = 4;
  172829. }
  172830. else
  172831. #endif
  172832. {
  172833. s_start = 4;
  172834. s_end = 0;
  172835. s_inc = -4;
  172836. }
  172837. shift = s_start;
  172838. for (i = 0; i < row_width; i++)
  172839. {
  172840. if (m & mask)
  172841. {
  172842. value = (*sp >> shift) & 0xf;
  172843. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  172844. *dp |= (png_byte)(value << shift);
  172845. }
  172846. if (shift == s_end)
  172847. {
  172848. shift = s_start;
  172849. sp++;
  172850. dp++;
  172851. }
  172852. else
  172853. shift += s_inc;
  172854. if (m == 1)
  172855. m = 0x80;
  172856. else
  172857. m >>= 1;
  172858. }
  172859. break;
  172860. }
  172861. default:
  172862. {
  172863. png_bytep sp = png_ptr->row_buf + 1;
  172864. png_bytep dp = row;
  172865. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  172866. png_uint_32 i;
  172867. png_uint_32 row_width = png_ptr->width;
  172868. png_byte m = 0x80;
  172869. for (i = 0; i < row_width; i++)
  172870. {
  172871. if (m & mask)
  172872. {
  172873. png_memcpy(dp, sp, pixel_bytes);
  172874. }
  172875. sp += pixel_bytes;
  172876. dp += pixel_bytes;
  172877. if (m == 1)
  172878. m = 0x80;
  172879. else
  172880. m >>= 1;
  172881. }
  172882. break;
  172883. }
  172884. }
  172885. }
  172886. }
  172887. #ifdef PNG_READ_INTERLACING_SUPPORTED
  172888. void /* PRIVATE */
  172889. png_do_read_interlace(png_structp png_ptr)
  172890. {
  172891. png_row_infop row_info = &(png_ptr->row_info);
  172892. png_bytep row = png_ptr->row_buf + 1;
  172893. int pass = png_ptr->pass;
  172894. png_uint_32 transformations = png_ptr->transformations;
  172895. #ifdef PNG_USE_LOCAL_ARRAYS
  172896. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  172897. #endif
  172898. png_debug(1,"in png_do_read_interlace\n");
  172899. if (row != NULL && row_info != NULL)
  172900. {
  172901. png_uint_32 final_width;
  172902. final_width = row_info->width * png_pass_inc[pass];
  172903. switch (row_info->pixel_depth)
  172904. {
  172905. case 1:
  172906. {
  172907. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  172908. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  172909. int sshift, dshift;
  172910. int s_start, s_end, s_inc;
  172911. int jstop = png_pass_inc[pass];
  172912. png_byte v;
  172913. png_uint_32 i;
  172914. int j;
  172915. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172916. if (transformations & PNG_PACKSWAP)
  172917. {
  172918. sshift = (int)((row_info->width + 7) & 0x07);
  172919. dshift = (int)((final_width + 7) & 0x07);
  172920. s_start = 7;
  172921. s_end = 0;
  172922. s_inc = -1;
  172923. }
  172924. else
  172925. #endif
  172926. {
  172927. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  172928. dshift = 7 - (int)((final_width + 7) & 0x07);
  172929. s_start = 0;
  172930. s_end = 7;
  172931. s_inc = 1;
  172932. }
  172933. for (i = 0; i < row_info->width; i++)
  172934. {
  172935. v = (png_byte)((*sp >> sshift) & 0x01);
  172936. for (j = 0; j < jstop; j++)
  172937. {
  172938. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  172939. *dp |= (png_byte)(v << dshift);
  172940. if (dshift == s_end)
  172941. {
  172942. dshift = s_start;
  172943. dp--;
  172944. }
  172945. else
  172946. dshift += s_inc;
  172947. }
  172948. if (sshift == s_end)
  172949. {
  172950. sshift = s_start;
  172951. sp--;
  172952. }
  172953. else
  172954. sshift += s_inc;
  172955. }
  172956. break;
  172957. }
  172958. case 2:
  172959. {
  172960. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  172961. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  172962. int sshift, dshift;
  172963. int s_start, s_end, s_inc;
  172964. int jstop = png_pass_inc[pass];
  172965. png_uint_32 i;
  172966. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172967. if (transformations & PNG_PACKSWAP)
  172968. {
  172969. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  172970. dshift = (int)(((final_width + 3) & 0x03) << 1);
  172971. s_start = 6;
  172972. s_end = 0;
  172973. s_inc = -2;
  172974. }
  172975. else
  172976. #endif
  172977. {
  172978. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  172979. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  172980. s_start = 0;
  172981. s_end = 6;
  172982. s_inc = 2;
  172983. }
  172984. for (i = 0; i < row_info->width; i++)
  172985. {
  172986. png_byte v;
  172987. int j;
  172988. v = (png_byte)((*sp >> sshift) & 0x03);
  172989. for (j = 0; j < jstop; j++)
  172990. {
  172991. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  172992. *dp |= (png_byte)(v << dshift);
  172993. if (dshift == s_end)
  172994. {
  172995. dshift = s_start;
  172996. dp--;
  172997. }
  172998. else
  172999. dshift += s_inc;
  173000. }
  173001. if (sshift == s_end)
  173002. {
  173003. sshift = s_start;
  173004. sp--;
  173005. }
  173006. else
  173007. sshift += s_inc;
  173008. }
  173009. break;
  173010. }
  173011. case 4:
  173012. {
  173013. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  173014. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  173015. int sshift, dshift;
  173016. int s_start, s_end, s_inc;
  173017. png_uint_32 i;
  173018. int jstop = png_pass_inc[pass];
  173019. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173020. if (transformations & PNG_PACKSWAP)
  173021. {
  173022. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  173023. dshift = (int)(((final_width + 1) & 0x01) << 2);
  173024. s_start = 4;
  173025. s_end = 0;
  173026. s_inc = -4;
  173027. }
  173028. else
  173029. #endif
  173030. {
  173031. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  173032. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  173033. s_start = 0;
  173034. s_end = 4;
  173035. s_inc = 4;
  173036. }
  173037. for (i = 0; i < row_info->width; i++)
  173038. {
  173039. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  173040. int j;
  173041. for (j = 0; j < jstop; j++)
  173042. {
  173043. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  173044. *dp |= (png_byte)(v << dshift);
  173045. if (dshift == s_end)
  173046. {
  173047. dshift = s_start;
  173048. dp--;
  173049. }
  173050. else
  173051. dshift += s_inc;
  173052. }
  173053. if (sshift == s_end)
  173054. {
  173055. sshift = s_start;
  173056. sp--;
  173057. }
  173058. else
  173059. sshift += s_inc;
  173060. }
  173061. break;
  173062. }
  173063. default:
  173064. {
  173065. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  173066. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  173067. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  173068. int jstop = png_pass_inc[pass];
  173069. png_uint_32 i;
  173070. for (i = 0; i < row_info->width; i++)
  173071. {
  173072. png_byte v[8];
  173073. int j;
  173074. png_memcpy(v, sp, pixel_bytes);
  173075. for (j = 0; j < jstop; j++)
  173076. {
  173077. png_memcpy(dp, v, pixel_bytes);
  173078. dp -= pixel_bytes;
  173079. }
  173080. sp -= pixel_bytes;
  173081. }
  173082. break;
  173083. }
  173084. }
  173085. row_info->width = final_width;
  173086. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  173087. }
  173088. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  173089. transformations = transformations; /* silence compiler warning */
  173090. #endif
  173091. }
  173092. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  173093. void /* PRIVATE */
  173094. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  173095. png_bytep prev_row, int filter)
  173096. {
  173097. png_debug(1, "in png_read_filter_row\n");
  173098. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  173099. switch (filter)
  173100. {
  173101. case PNG_FILTER_VALUE_NONE:
  173102. break;
  173103. case PNG_FILTER_VALUE_SUB:
  173104. {
  173105. png_uint_32 i;
  173106. png_uint_32 istop = row_info->rowbytes;
  173107. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173108. png_bytep rp = row + bpp;
  173109. png_bytep lp = row;
  173110. for (i = bpp; i < istop; i++)
  173111. {
  173112. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  173113. rp++;
  173114. }
  173115. break;
  173116. }
  173117. case PNG_FILTER_VALUE_UP:
  173118. {
  173119. png_uint_32 i;
  173120. png_uint_32 istop = row_info->rowbytes;
  173121. png_bytep rp = row;
  173122. png_bytep pp = prev_row;
  173123. for (i = 0; i < istop; i++)
  173124. {
  173125. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173126. rp++;
  173127. }
  173128. break;
  173129. }
  173130. case PNG_FILTER_VALUE_AVG:
  173131. {
  173132. png_uint_32 i;
  173133. png_bytep rp = row;
  173134. png_bytep pp = prev_row;
  173135. png_bytep lp = row;
  173136. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173137. png_uint_32 istop = row_info->rowbytes - bpp;
  173138. for (i = 0; i < bpp; i++)
  173139. {
  173140. *rp = (png_byte)(((int)(*rp) +
  173141. ((int)(*pp++) / 2 )) & 0xff);
  173142. rp++;
  173143. }
  173144. for (i = 0; i < istop; i++)
  173145. {
  173146. *rp = (png_byte)(((int)(*rp) +
  173147. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  173148. rp++;
  173149. }
  173150. break;
  173151. }
  173152. case PNG_FILTER_VALUE_PAETH:
  173153. {
  173154. png_uint_32 i;
  173155. png_bytep rp = row;
  173156. png_bytep pp = prev_row;
  173157. png_bytep lp = row;
  173158. png_bytep cp = prev_row;
  173159. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173160. png_uint_32 istop=row_info->rowbytes - bpp;
  173161. for (i = 0; i < bpp; i++)
  173162. {
  173163. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173164. rp++;
  173165. }
  173166. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  173167. {
  173168. int a, b, c, pa, pb, pc, p;
  173169. a = *lp++;
  173170. b = *pp++;
  173171. c = *cp++;
  173172. p = b - c;
  173173. pc = a - c;
  173174. #ifdef PNG_USE_ABS
  173175. pa = abs(p);
  173176. pb = abs(pc);
  173177. pc = abs(p + pc);
  173178. #else
  173179. pa = p < 0 ? -p : p;
  173180. pb = pc < 0 ? -pc : pc;
  173181. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  173182. #endif
  173183. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  173184. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  173185. rp++;
  173186. }
  173187. break;
  173188. }
  173189. default:
  173190. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  173191. *row=0;
  173192. break;
  173193. }
  173194. }
  173195. void /* PRIVATE */
  173196. png_read_finish_row(png_structp png_ptr)
  173197. {
  173198. #ifdef PNG_USE_LOCAL_ARRAYS
  173199. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173200. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173201. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173202. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173203. #endif
  173204. png_debug(1, "in png_read_finish_row\n");
  173205. png_ptr->row_number++;
  173206. if (png_ptr->row_number < png_ptr->num_rows)
  173207. return;
  173208. if (png_ptr->interlaced)
  173209. {
  173210. png_ptr->row_number = 0;
  173211. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  173212. png_ptr->rowbytes + 1);
  173213. do
  173214. {
  173215. png_ptr->pass++;
  173216. if (png_ptr->pass >= 7)
  173217. break;
  173218. png_ptr->iwidth = (png_ptr->width +
  173219. png_pass_inc[png_ptr->pass] - 1 -
  173220. png_pass_start[png_ptr->pass]) /
  173221. png_pass_inc[png_ptr->pass];
  173222. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  173223. png_ptr->iwidth) + 1;
  173224. if (!(png_ptr->transformations & PNG_INTERLACE))
  173225. {
  173226. png_ptr->num_rows = (png_ptr->height +
  173227. png_pass_yinc[png_ptr->pass] - 1 -
  173228. png_pass_ystart[png_ptr->pass]) /
  173229. png_pass_yinc[png_ptr->pass];
  173230. if (!(png_ptr->num_rows))
  173231. continue;
  173232. }
  173233. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  173234. break;
  173235. } while (png_ptr->iwidth == 0);
  173236. if (png_ptr->pass < 7)
  173237. return;
  173238. }
  173239. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  173240. {
  173241. #ifdef PNG_USE_LOCAL_ARRAYS
  173242. PNG_CONST PNG_IDAT;
  173243. #endif
  173244. char extra;
  173245. int ret;
  173246. png_ptr->zstream.next_out = (Bytef *)&extra;
  173247. png_ptr->zstream.avail_out = (uInt)1;
  173248. for(;;)
  173249. {
  173250. if (!(png_ptr->zstream.avail_in))
  173251. {
  173252. while (!png_ptr->idat_size)
  173253. {
  173254. png_byte chunk_length[4];
  173255. png_crc_finish(png_ptr, 0);
  173256. png_read_data(png_ptr, chunk_length, 4);
  173257. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  173258. png_reset_crc(png_ptr);
  173259. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  173260. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  173261. png_error(png_ptr, "Not enough image data");
  173262. }
  173263. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  173264. png_ptr->zstream.next_in = png_ptr->zbuf;
  173265. if (png_ptr->zbuf_size > png_ptr->idat_size)
  173266. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  173267. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  173268. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  173269. }
  173270. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173271. if (ret == Z_STREAM_END)
  173272. {
  173273. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173274. png_ptr->idat_size)
  173275. png_warning(png_ptr, "Extra compressed data");
  173276. png_ptr->mode |= PNG_AFTER_IDAT;
  173277. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173278. break;
  173279. }
  173280. if (ret != Z_OK)
  173281. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173282. "Decompression Error");
  173283. if (!(png_ptr->zstream.avail_out))
  173284. {
  173285. png_warning(png_ptr, "Extra compressed data.");
  173286. png_ptr->mode |= PNG_AFTER_IDAT;
  173287. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173288. break;
  173289. }
  173290. }
  173291. png_ptr->zstream.avail_out = 0;
  173292. }
  173293. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173294. png_warning(png_ptr, "Extra compression data");
  173295. inflateReset(&png_ptr->zstream);
  173296. png_ptr->mode |= PNG_AFTER_IDAT;
  173297. }
  173298. void /* PRIVATE */
  173299. png_read_start_row(png_structp png_ptr)
  173300. {
  173301. #ifdef PNG_USE_LOCAL_ARRAYS
  173302. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173303. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173304. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173305. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173306. #endif
  173307. int max_pixel_depth;
  173308. png_uint_32 row_bytes;
  173309. png_debug(1, "in png_read_start_row\n");
  173310. png_ptr->zstream.avail_in = 0;
  173311. png_init_read_transformations(png_ptr);
  173312. if (png_ptr->interlaced)
  173313. {
  173314. if (!(png_ptr->transformations & PNG_INTERLACE))
  173315. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173316. png_pass_ystart[0]) / png_pass_yinc[0];
  173317. else
  173318. png_ptr->num_rows = png_ptr->height;
  173319. png_ptr->iwidth = (png_ptr->width +
  173320. png_pass_inc[png_ptr->pass] - 1 -
  173321. png_pass_start[png_ptr->pass]) /
  173322. png_pass_inc[png_ptr->pass];
  173323. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173324. png_ptr->irowbytes = (png_size_t)row_bytes;
  173325. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173326. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173327. }
  173328. else
  173329. {
  173330. png_ptr->num_rows = png_ptr->height;
  173331. png_ptr->iwidth = png_ptr->width;
  173332. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173333. }
  173334. max_pixel_depth = png_ptr->pixel_depth;
  173335. #if defined(PNG_READ_PACK_SUPPORTED)
  173336. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173337. max_pixel_depth = 8;
  173338. #endif
  173339. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173340. if (png_ptr->transformations & PNG_EXPAND)
  173341. {
  173342. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173343. {
  173344. if (png_ptr->num_trans)
  173345. max_pixel_depth = 32;
  173346. else
  173347. max_pixel_depth = 24;
  173348. }
  173349. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173350. {
  173351. if (max_pixel_depth < 8)
  173352. max_pixel_depth = 8;
  173353. if (png_ptr->num_trans)
  173354. max_pixel_depth *= 2;
  173355. }
  173356. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173357. {
  173358. if (png_ptr->num_trans)
  173359. {
  173360. max_pixel_depth *= 4;
  173361. max_pixel_depth /= 3;
  173362. }
  173363. }
  173364. }
  173365. #endif
  173366. #if defined(PNG_READ_FILLER_SUPPORTED)
  173367. if (png_ptr->transformations & (PNG_FILLER))
  173368. {
  173369. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173370. max_pixel_depth = 32;
  173371. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173372. {
  173373. if (max_pixel_depth <= 8)
  173374. max_pixel_depth = 16;
  173375. else
  173376. max_pixel_depth = 32;
  173377. }
  173378. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173379. {
  173380. if (max_pixel_depth <= 32)
  173381. max_pixel_depth = 32;
  173382. else
  173383. max_pixel_depth = 64;
  173384. }
  173385. }
  173386. #endif
  173387. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173388. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173389. {
  173390. if (
  173391. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173392. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173393. #endif
  173394. #if defined(PNG_READ_FILLER_SUPPORTED)
  173395. (png_ptr->transformations & (PNG_FILLER)) ||
  173396. #endif
  173397. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173398. {
  173399. if (max_pixel_depth <= 16)
  173400. max_pixel_depth = 32;
  173401. else
  173402. max_pixel_depth = 64;
  173403. }
  173404. else
  173405. {
  173406. if (max_pixel_depth <= 8)
  173407. {
  173408. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173409. max_pixel_depth = 32;
  173410. else
  173411. max_pixel_depth = 24;
  173412. }
  173413. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173414. max_pixel_depth = 64;
  173415. else
  173416. max_pixel_depth = 48;
  173417. }
  173418. }
  173419. #endif
  173420. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173421. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173422. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173423. {
  173424. int user_pixel_depth=png_ptr->user_transform_depth*
  173425. png_ptr->user_transform_channels;
  173426. if(user_pixel_depth > max_pixel_depth)
  173427. max_pixel_depth=user_pixel_depth;
  173428. }
  173429. #endif
  173430. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173431. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173432. 1 + ((max_pixel_depth + 7) >> 3);
  173433. #ifdef PNG_MAX_MALLOC_64K
  173434. if (row_bytes > (png_uint_32)65536L)
  173435. png_error(png_ptr, "This image requires a row greater than 64KB");
  173436. #endif
  173437. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173438. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173439. #ifdef PNG_MAX_MALLOC_64K
  173440. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173441. png_error(png_ptr, "This image requires a row greater than 64KB");
  173442. #endif
  173443. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173444. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173445. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173446. png_ptr->rowbytes + 1));
  173447. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173448. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173449. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173450. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173451. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173452. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173453. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173454. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173455. }
  173456. #endif /* PNG_READ_SUPPORTED */
  173457. /*** End of inlined file: pngrutil.c ***/
  173458. /*** Start of inlined file: pngset.c ***/
  173459. #define PNG_INTERNAL
  173460. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173461. #if defined(PNG_bKGD_SUPPORTED)
  173462. void PNGAPI
  173463. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173464. {
  173465. png_debug1(1, "in %s storage function\n", "bKGD");
  173466. if (png_ptr == NULL || info_ptr == NULL)
  173467. return;
  173468. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173469. info_ptr->valid |= PNG_INFO_bKGD;
  173470. }
  173471. #endif
  173472. #if defined(PNG_cHRM_SUPPORTED)
  173473. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173474. void PNGAPI
  173475. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173476. double white_x, double white_y, double red_x, double red_y,
  173477. double green_x, double green_y, double blue_x, double blue_y)
  173478. {
  173479. png_debug1(1, "in %s storage function\n", "cHRM");
  173480. if (png_ptr == NULL || info_ptr == NULL)
  173481. return;
  173482. if (white_x < 0.0 || white_y < 0.0 ||
  173483. red_x < 0.0 || red_y < 0.0 ||
  173484. green_x < 0.0 || green_y < 0.0 ||
  173485. blue_x < 0.0 || blue_y < 0.0)
  173486. {
  173487. png_warning(png_ptr,
  173488. "Ignoring attempt to set negative chromaticity value");
  173489. return;
  173490. }
  173491. if (white_x > 21474.83 || white_y > 21474.83 ||
  173492. red_x > 21474.83 || red_y > 21474.83 ||
  173493. green_x > 21474.83 || green_y > 21474.83 ||
  173494. blue_x > 21474.83 || blue_y > 21474.83)
  173495. {
  173496. png_warning(png_ptr,
  173497. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173498. return;
  173499. }
  173500. info_ptr->x_white = (float)white_x;
  173501. info_ptr->y_white = (float)white_y;
  173502. info_ptr->x_red = (float)red_x;
  173503. info_ptr->y_red = (float)red_y;
  173504. info_ptr->x_green = (float)green_x;
  173505. info_ptr->y_green = (float)green_y;
  173506. info_ptr->x_blue = (float)blue_x;
  173507. info_ptr->y_blue = (float)blue_y;
  173508. #ifdef PNG_FIXED_POINT_SUPPORTED
  173509. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173510. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173511. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173512. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173513. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173514. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173515. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173516. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173517. #endif
  173518. info_ptr->valid |= PNG_INFO_cHRM;
  173519. }
  173520. #endif
  173521. #ifdef PNG_FIXED_POINT_SUPPORTED
  173522. void PNGAPI
  173523. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173524. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173525. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173526. png_fixed_point blue_x, png_fixed_point blue_y)
  173527. {
  173528. png_debug1(1, "in %s storage function\n", "cHRM");
  173529. if (png_ptr == NULL || info_ptr == NULL)
  173530. return;
  173531. if (white_x < 0 || white_y < 0 ||
  173532. red_x < 0 || red_y < 0 ||
  173533. green_x < 0 || green_y < 0 ||
  173534. blue_x < 0 || blue_y < 0)
  173535. {
  173536. png_warning(png_ptr,
  173537. "Ignoring attempt to set negative chromaticity value");
  173538. return;
  173539. }
  173540. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173541. if (white_x > (double) PNG_UINT_31_MAX ||
  173542. white_y > (double) PNG_UINT_31_MAX ||
  173543. red_x > (double) PNG_UINT_31_MAX ||
  173544. red_y > (double) PNG_UINT_31_MAX ||
  173545. green_x > (double) PNG_UINT_31_MAX ||
  173546. green_y > (double) PNG_UINT_31_MAX ||
  173547. blue_x > (double) PNG_UINT_31_MAX ||
  173548. blue_y > (double) PNG_UINT_31_MAX)
  173549. #else
  173550. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173551. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173552. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173553. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173554. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173555. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173556. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173557. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173558. #endif
  173559. {
  173560. png_warning(png_ptr,
  173561. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173562. return;
  173563. }
  173564. info_ptr->int_x_white = white_x;
  173565. info_ptr->int_y_white = white_y;
  173566. info_ptr->int_x_red = red_x;
  173567. info_ptr->int_y_red = red_y;
  173568. info_ptr->int_x_green = green_x;
  173569. info_ptr->int_y_green = green_y;
  173570. info_ptr->int_x_blue = blue_x;
  173571. info_ptr->int_y_blue = blue_y;
  173572. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173573. info_ptr->x_white = (float)(white_x/100000.);
  173574. info_ptr->y_white = (float)(white_y/100000.);
  173575. info_ptr->x_red = (float)( red_x/100000.);
  173576. info_ptr->y_red = (float)( red_y/100000.);
  173577. info_ptr->x_green = (float)(green_x/100000.);
  173578. info_ptr->y_green = (float)(green_y/100000.);
  173579. info_ptr->x_blue = (float)( blue_x/100000.);
  173580. info_ptr->y_blue = (float)( blue_y/100000.);
  173581. #endif
  173582. info_ptr->valid |= PNG_INFO_cHRM;
  173583. }
  173584. #endif
  173585. #endif
  173586. #if defined(PNG_gAMA_SUPPORTED)
  173587. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173588. void PNGAPI
  173589. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173590. {
  173591. double gamma;
  173592. png_debug1(1, "in %s storage function\n", "gAMA");
  173593. if (png_ptr == NULL || info_ptr == NULL)
  173594. return;
  173595. if (file_gamma > 21474.83)
  173596. {
  173597. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173598. gamma=21474.83;
  173599. }
  173600. else
  173601. gamma=file_gamma;
  173602. info_ptr->gamma = (float)gamma;
  173603. #ifdef PNG_FIXED_POINT_SUPPORTED
  173604. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173605. #endif
  173606. info_ptr->valid |= PNG_INFO_gAMA;
  173607. if(gamma == 0.0)
  173608. png_warning(png_ptr, "Setting gamma=0");
  173609. }
  173610. #endif
  173611. void PNGAPI
  173612. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173613. int_gamma)
  173614. {
  173615. png_fixed_point gamma;
  173616. png_debug1(1, "in %s storage function\n", "gAMA");
  173617. if (png_ptr == NULL || info_ptr == NULL)
  173618. return;
  173619. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173620. {
  173621. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173622. gamma=PNG_UINT_31_MAX;
  173623. }
  173624. else
  173625. {
  173626. if (int_gamma < 0)
  173627. {
  173628. png_warning(png_ptr, "Setting negative gamma to zero");
  173629. gamma=0;
  173630. }
  173631. else
  173632. gamma=int_gamma;
  173633. }
  173634. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173635. info_ptr->gamma = (float)(gamma/100000.);
  173636. #endif
  173637. #ifdef PNG_FIXED_POINT_SUPPORTED
  173638. info_ptr->int_gamma = gamma;
  173639. #endif
  173640. info_ptr->valid |= PNG_INFO_gAMA;
  173641. if(gamma == 0)
  173642. png_warning(png_ptr, "Setting gamma=0");
  173643. }
  173644. #endif
  173645. #if defined(PNG_hIST_SUPPORTED)
  173646. void PNGAPI
  173647. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173648. {
  173649. int i;
  173650. png_debug1(1, "in %s storage function\n", "hIST");
  173651. if (png_ptr == NULL || info_ptr == NULL)
  173652. return;
  173653. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173654. > PNG_MAX_PALETTE_LENGTH)
  173655. {
  173656. png_warning(png_ptr,
  173657. "Invalid palette size, hIST allocation skipped.");
  173658. return;
  173659. }
  173660. #ifdef PNG_FREE_ME_SUPPORTED
  173661. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173662. #endif
  173663. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173664. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173665. if (png_ptr->hist == NULL)
  173666. {
  173667. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173668. return;
  173669. }
  173670. for (i = 0; i < info_ptr->num_palette; i++)
  173671. png_ptr->hist[i] = hist[i];
  173672. info_ptr->hist = png_ptr->hist;
  173673. info_ptr->valid |= PNG_INFO_hIST;
  173674. #ifdef PNG_FREE_ME_SUPPORTED
  173675. info_ptr->free_me |= PNG_FREE_HIST;
  173676. #else
  173677. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  173678. #endif
  173679. }
  173680. #endif
  173681. void PNGAPI
  173682. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  173683. png_uint_32 width, png_uint_32 height, int bit_depth,
  173684. int color_type, int interlace_type, int compression_type,
  173685. int filter_type)
  173686. {
  173687. png_debug1(1, "in %s storage function\n", "IHDR");
  173688. if (png_ptr == NULL || info_ptr == NULL)
  173689. return;
  173690. if (width == 0 || height == 0)
  173691. png_error(png_ptr, "Image width or height is zero in IHDR");
  173692. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  173693. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  173694. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173695. #else
  173696. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  173697. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173698. #endif
  173699. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  173700. png_error(png_ptr, "Invalid image size in IHDR");
  173701. if ( width > (PNG_UINT_32_MAX
  173702. >> 3) /* 8-byte RGBA pixels */
  173703. - 64 /* bigrowbuf hack */
  173704. - 1 /* filter byte */
  173705. - 7*8 /* rounding of width to multiple of 8 pixels */
  173706. - 8) /* extra max_pixel_depth pad */
  173707. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  173708. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  173709. bit_depth != 8 && bit_depth != 16)
  173710. png_error(png_ptr, "Invalid bit depth in IHDR");
  173711. if (color_type < 0 || color_type == 1 ||
  173712. color_type == 5 || color_type > 6)
  173713. png_error(png_ptr, "Invalid color type in IHDR");
  173714. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  173715. ((color_type == PNG_COLOR_TYPE_RGB ||
  173716. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  173717. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  173718. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  173719. if (interlace_type >= PNG_INTERLACE_LAST)
  173720. png_error(png_ptr, "Unknown interlace method in IHDR");
  173721. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  173722. png_error(png_ptr, "Unknown compression method in IHDR");
  173723. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  173724. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  173725. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  173726. if(filter_type != PNG_FILTER_TYPE_BASE)
  173727. {
  173728. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  173729. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  173730. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  173731. (color_type == PNG_COLOR_TYPE_RGB ||
  173732. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  173733. png_error(png_ptr, "Unknown filter method in IHDR");
  173734. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  173735. png_warning(png_ptr, "Invalid filter method in IHDR");
  173736. }
  173737. #else
  173738. if(filter_type != PNG_FILTER_TYPE_BASE)
  173739. png_error(png_ptr, "Unknown filter method in IHDR");
  173740. #endif
  173741. info_ptr->width = width;
  173742. info_ptr->height = height;
  173743. info_ptr->bit_depth = (png_byte)bit_depth;
  173744. info_ptr->color_type =(png_byte) color_type;
  173745. info_ptr->compression_type = (png_byte)compression_type;
  173746. info_ptr->filter_type = (png_byte)filter_type;
  173747. info_ptr->interlace_type = (png_byte)interlace_type;
  173748. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173749. info_ptr->channels = 1;
  173750. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  173751. info_ptr->channels = 3;
  173752. else
  173753. info_ptr->channels = 1;
  173754. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  173755. info_ptr->channels++;
  173756. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  173757. if (width > (PNG_UINT_32_MAX
  173758. >> 3) /* 8-byte RGBA pixels */
  173759. - 64 /* bigrowbuf hack */
  173760. - 1 /* filter byte */
  173761. - 7*8 /* rounding of width to multiple of 8 pixels */
  173762. - 8) /* extra max_pixel_depth pad */
  173763. info_ptr->rowbytes = (png_size_t)0;
  173764. else
  173765. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  173766. }
  173767. #if defined(PNG_oFFs_SUPPORTED)
  173768. void PNGAPI
  173769. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  173770. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  173771. {
  173772. png_debug1(1, "in %s storage function\n", "oFFs");
  173773. if (png_ptr == NULL || info_ptr == NULL)
  173774. return;
  173775. info_ptr->x_offset = offset_x;
  173776. info_ptr->y_offset = offset_y;
  173777. info_ptr->offset_unit_type = (png_byte)unit_type;
  173778. info_ptr->valid |= PNG_INFO_oFFs;
  173779. }
  173780. #endif
  173781. #if defined(PNG_pCAL_SUPPORTED)
  173782. void PNGAPI
  173783. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  173784. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  173785. png_charp units, png_charpp params)
  173786. {
  173787. png_uint_32 length;
  173788. int i;
  173789. png_debug1(1, "in %s storage function\n", "pCAL");
  173790. if (png_ptr == NULL || info_ptr == NULL)
  173791. return;
  173792. length = png_strlen(purpose) + 1;
  173793. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  173794. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  173795. if (info_ptr->pcal_purpose == NULL)
  173796. {
  173797. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  173798. return;
  173799. }
  173800. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  173801. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  173802. info_ptr->pcal_X0 = X0;
  173803. info_ptr->pcal_X1 = X1;
  173804. info_ptr->pcal_type = (png_byte)type;
  173805. info_ptr->pcal_nparams = (png_byte)nparams;
  173806. length = png_strlen(units) + 1;
  173807. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  173808. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  173809. if (info_ptr->pcal_units == NULL)
  173810. {
  173811. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  173812. return;
  173813. }
  173814. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  173815. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  173816. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  173817. if (info_ptr->pcal_params == NULL)
  173818. {
  173819. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  173820. return;
  173821. }
  173822. info_ptr->pcal_params[nparams] = NULL;
  173823. for (i = 0; i < nparams; i++)
  173824. {
  173825. length = png_strlen(params[i]) + 1;
  173826. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  173827. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  173828. if (info_ptr->pcal_params[i] == NULL)
  173829. {
  173830. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  173831. return;
  173832. }
  173833. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  173834. }
  173835. info_ptr->valid |= PNG_INFO_pCAL;
  173836. #ifdef PNG_FREE_ME_SUPPORTED
  173837. info_ptr->free_me |= PNG_FREE_PCAL;
  173838. #endif
  173839. }
  173840. #endif
  173841. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  173842. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173843. void PNGAPI
  173844. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  173845. int unit, double width, double height)
  173846. {
  173847. png_debug1(1, "in %s storage function\n", "sCAL");
  173848. if (png_ptr == NULL || info_ptr == NULL)
  173849. return;
  173850. info_ptr->scal_unit = (png_byte)unit;
  173851. info_ptr->scal_pixel_width = width;
  173852. info_ptr->scal_pixel_height = height;
  173853. info_ptr->valid |= PNG_INFO_sCAL;
  173854. }
  173855. #else
  173856. #ifdef PNG_FIXED_POINT_SUPPORTED
  173857. void PNGAPI
  173858. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  173859. int unit, png_charp swidth, png_charp sheight)
  173860. {
  173861. png_uint_32 length;
  173862. png_debug1(1, "in %s storage function\n", "sCAL");
  173863. if (png_ptr == NULL || info_ptr == NULL)
  173864. return;
  173865. info_ptr->scal_unit = (png_byte)unit;
  173866. length = png_strlen(swidth) + 1;
  173867. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173868. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  173869. if (info_ptr->scal_s_width == NULL)
  173870. {
  173871. png_warning(png_ptr,
  173872. "Memory allocation failed while processing sCAL.");
  173873. }
  173874. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  173875. length = png_strlen(sheight) + 1;
  173876. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173877. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  173878. if (info_ptr->scal_s_height == NULL)
  173879. {
  173880. png_free (png_ptr, info_ptr->scal_s_width);
  173881. png_warning(png_ptr,
  173882. "Memory allocation failed while processing sCAL.");
  173883. }
  173884. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  173885. info_ptr->valid |= PNG_INFO_sCAL;
  173886. #ifdef PNG_FREE_ME_SUPPORTED
  173887. info_ptr->free_me |= PNG_FREE_SCAL;
  173888. #endif
  173889. }
  173890. #endif
  173891. #endif
  173892. #endif
  173893. #if defined(PNG_pHYs_SUPPORTED)
  173894. void PNGAPI
  173895. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  173896. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  173897. {
  173898. png_debug1(1, "in %s storage function\n", "pHYs");
  173899. if (png_ptr == NULL || info_ptr == NULL)
  173900. return;
  173901. info_ptr->x_pixels_per_unit = res_x;
  173902. info_ptr->y_pixels_per_unit = res_y;
  173903. info_ptr->phys_unit_type = (png_byte)unit_type;
  173904. info_ptr->valid |= PNG_INFO_pHYs;
  173905. }
  173906. #endif
  173907. void PNGAPI
  173908. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  173909. png_colorp palette, int num_palette)
  173910. {
  173911. png_debug1(1, "in %s storage function\n", "PLTE");
  173912. if (png_ptr == NULL || info_ptr == NULL)
  173913. return;
  173914. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  173915. {
  173916. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173917. png_error(png_ptr, "Invalid palette length");
  173918. else
  173919. {
  173920. png_warning(png_ptr, "Invalid palette length");
  173921. return;
  173922. }
  173923. }
  173924. #ifdef PNG_FREE_ME_SUPPORTED
  173925. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  173926. #endif
  173927. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  173928. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  173929. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  173930. png_sizeof(png_color));
  173931. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  173932. info_ptr->palette = png_ptr->palette;
  173933. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  173934. #ifdef PNG_FREE_ME_SUPPORTED
  173935. info_ptr->free_me |= PNG_FREE_PLTE;
  173936. #else
  173937. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  173938. #endif
  173939. info_ptr->valid |= PNG_INFO_PLTE;
  173940. }
  173941. #if defined(PNG_sBIT_SUPPORTED)
  173942. void PNGAPI
  173943. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  173944. png_color_8p sig_bit)
  173945. {
  173946. png_debug1(1, "in %s storage function\n", "sBIT");
  173947. if (png_ptr == NULL || info_ptr == NULL)
  173948. return;
  173949. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  173950. info_ptr->valid |= PNG_INFO_sBIT;
  173951. }
  173952. #endif
  173953. #if defined(PNG_sRGB_SUPPORTED)
  173954. void PNGAPI
  173955. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  173956. {
  173957. png_debug1(1, "in %s storage function\n", "sRGB");
  173958. if (png_ptr == NULL || info_ptr == NULL)
  173959. return;
  173960. info_ptr->srgb_intent = (png_byte)intent;
  173961. info_ptr->valid |= PNG_INFO_sRGB;
  173962. }
  173963. void PNGAPI
  173964. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  173965. int intent)
  173966. {
  173967. #if defined(PNG_gAMA_SUPPORTED)
  173968. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173969. float file_gamma;
  173970. #endif
  173971. #ifdef PNG_FIXED_POINT_SUPPORTED
  173972. png_fixed_point int_file_gamma;
  173973. #endif
  173974. #endif
  173975. #if defined(PNG_cHRM_SUPPORTED)
  173976. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173977. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  173978. #endif
  173979. #ifdef PNG_FIXED_POINT_SUPPORTED
  173980. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  173981. int_green_y, int_blue_x, int_blue_y;
  173982. #endif
  173983. #endif
  173984. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  173985. if (png_ptr == NULL || info_ptr == NULL)
  173986. return;
  173987. png_set_sRGB(png_ptr, info_ptr, intent);
  173988. #if defined(PNG_gAMA_SUPPORTED)
  173989. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173990. file_gamma = (float).45455;
  173991. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  173992. #endif
  173993. #ifdef PNG_FIXED_POINT_SUPPORTED
  173994. int_file_gamma = 45455L;
  173995. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  173996. #endif
  173997. #endif
  173998. #if defined(PNG_cHRM_SUPPORTED)
  173999. #ifdef PNG_FIXED_POINT_SUPPORTED
  174000. int_white_x = 31270L;
  174001. int_white_y = 32900L;
  174002. int_red_x = 64000L;
  174003. int_red_y = 33000L;
  174004. int_green_x = 30000L;
  174005. int_green_y = 60000L;
  174006. int_blue_x = 15000L;
  174007. int_blue_y = 6000L;
  174008. png_set_cHRM_fixed(png_ptr, info_ptr,
  174009. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  174010. int_blue_x, int_blue_y);
  174011. #endif
  174012. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174013. white_x = (float).3127;
  174014. white_y = (float).3290;
  174015. red_x = (float).64;
  174016. red_y = (float).33;
  174017. green_x = (float).30;
  174018. green_y = (float).60;
  174019. blue_x = (float).15;
  174020. blue_y = (float).06;
  174021. png_set_cHRM(png_ptr, info_ptr,
  174022. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  174023. #endif
  174024. #endif
  174025. }
  174026. #endif
  174027. #if defined(PNG_iCCP_SUPPORTED)
  174028. void PNGAPI
  174029. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  174030. png_charp name, int compression_type,
  174031. png_charp profile, png_uint_32 proflen)
  174032. {
  174033. png_charp new_iccp_name;
  174034. png_charp new_iccp_profile;
  174035. png_debug1(1, "in %s storage function\n", "iCCP");
  174036. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  174037. return;
  174038. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  174039. if (new_iccp_name == NULL)
  174040. {
  174041. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  174042. return;
  174043. }
  174044. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  174045. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  174046. if (new_iccp_profile == NULL)
  174047. {
  174048. png_free (png_ptr, new_iccp_name);
  174049. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  174050. return;
  174051. }
  174052. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  174053. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  174054. info_ptr->iccp_proflen = proflen;
  174055. info_ptr->iccp_name = new_iccp_name;
  174056. info_ptr->iccp_profile = new_iccp_profile;
  174057. info_ptr->iccp_compression = (png_byte)compression_type;
  174058. #ifdef PNG_FREE_ME_SUPPORTED
  174059. info_ptr->free_me |= PNG_FREE_ICCP;
  174060. #endif
  174061. info_ptr->valid |= PNG_INFO_iCCP;
  174062. }
  174063. #endif
  174064. #if defined(PNG_TEXT_SUPPORTED)
  174065. void PNGAPI
  174066. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174067. int num_text)
  174068. {
  174069. int ret;
  174070. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  174071. if (ret)
  174072. png_error(png_ptr, "Insufficient memory to store text");
  174073. }
  174074. int /* PRIVATE */
  174075. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174076. int num_text)
  174077. {
  174078. int i;
  174079. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  174080. "text" : (png_const_charp)png_ptr->chunk_name));
  174081. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  174082. return(0);
  174083. if (info_ptr->num_text + num_text > info_ptr->max_text)
  174084. {
  174085. if (info_ptr->text != NULL)
  174086. {
  174087. png_textp old_text;
  174088. int old_max;
  174089. old_max = info_ptr->max_text;
  174090. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  174091. old_text = info_ptr->text;
  174092. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174093. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174094. if (info_ptr->text == NULL)
  174095. {
  174096. png_free(png_ptr, old_text);
  174097. return(1);
  174098. }
  174099. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  174100. png_sizeof(png_text)));
  174101. png_free(png_ptr, old_text);
  174102. }
  174103. else
  174104. {
  174105. info_ptr->max_text = num_text + 8;
  174106. info_ptr->num_text = 0;
  174107. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174108. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174109. if (info_ptr->text == NULL)
  174110. return(1);
  174111. #ifdef PNG_FREE_ME_SUPPORTED
  174112. info_ptr->free_me |= PNG_FREE_TEXT;
  174113. #endif
  174114. }
  174115. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  174116. info_ptr->max_text);
  174117. }
  174118. for (i = 0; i < num_text; i++)
  174119. {
  174120. png_size_t text_length,key_len;
  174121. png_size_t lang_len,lang_key_len;
  174122. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  174123. if (text_ptr[i].key == NULL)
  174124. continue;
  174125. key_len = png_strlen(text_ptr[i].key);
  174126. if(text_ptr[i].compression <= 0)
  174127. {
  174128. lang_len = 0;
  174129. lang_key_len = 0;
  174130. }
  174131. else
  174132. #ifdef PNG_iTXt_SUPPORTED
  174133. {
  174134. if (text_ptr[i].lang != NULL)
  174135. lang_len = png_strlen(text_ptr[i].lang);
  174136. else
  174137. lang_len = 0;
  174138. if (text_ptr[i].lang_key != NULL)
  174139. lang_key_len = png_strlen(text_ptr[i].lang_key);
  174140. else
  174141. lang_key_len = 0;
  174142. }
  174143. #else
  174144. {
  174145. png_warning(png_ptr, "iTXt chunk not supported.");
  174146. continue;
  174147. }
  174148. #endif
  174149. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  174150. {
  174151. text_length = 0;
  174152. #ifdef PNG_iTXt_SUPPORTED
  174153. if(text_ptr[i].compression > 0)
  174154. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  174155. else
  174156. #endif
  174157. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  174158. }
  174159. else
  174160. {
  174161. text_length = png_strlen(text_ptr[i].text);
  174162. textp->compression = text_ptr[i].compression;
  174163. }
  174164. textp->key = (png_charp)png_malloc_warn(png_ptr,
  174165. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  174166. if (textp->key == NULL)
  174167. return(1);
  174168. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  174169. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  174170. (int)textp->key);
  174171. png_memcpy(textp->key, text_ptr[i].key,
  174172. (png_size_t)(key_len));
  174173. *(textp->key+key_len) = '\0';
  174174. #ifdef PNG_iTXt_SUPPORTED
  174175. if (text_ptr[i].compression > 0)
  174176. {
  174177. textp->lang=textp->key + key_len + 1;
  174178. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  174179. *(textp->lang+lang_len) = '\0';
  174180. textp->lang_key=textp->lang + lang_len + 1;
  174181. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  174182. *(textp->lang_key+lang_key_len) = '\0';
  174183. textp->text=textp->lang_key + lang_key_len + 1;
  174184. }
  174185. else
  174186. #endif
  174187. {
  174188. #ifdef PNG_iTXt_SUPPORTED
  174189. textp->lang=NULL;
  174190. textp->lang_key=NULL;
  174191. #endif
  174192. textp->text=textp->key + key_len + 1;
  174193. }
  174194. if(text_length)
  174195. png_memcpy(textp->text, text_ptr[i].text,
  174196. (png_size_t)(text_length));
  174197. *(textp->text+text_length) = '\0';
  174198. #ifdef PNG_iTXt_SUPPORTED
  174199. if(textp->compression > 0)
  174200. {
  174201. textp->text_length = 0;
  174202. textp->itxt_length = text_length;
  174203. }
  174204. else
  174205. #endif
  174206. {
  174207. textp->text_length = text_length;
  174208. #ifdef PNG_iTXt_SUPPORTED
  174209. textp->itxt_length = 0;
  174210. #endif
  174211. }
  174212. info_ptr->num_text++;
  174213. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  174214. }
  174215. return(0);
  174216. }
  174217. #endif
  174218. #if defined(PNG_tIME_SUPPORTED)
  174219. void PNGAPI
  174220. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  174221. {
  174222. png_debug1(1, "in %s storage function\n", "tIME");
  174223. if (png_ptr == NULL || info_ptr == NULL ||
  174224. (png_ptr->mode & PNG_WROTE_tIME))
  174225. return;
  174226. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  174227. info_ptr->valid |= PNG_INFO_tIME;
  174228. }
  174229. #endif
  174230. #if defined(PNG_tRNS_SUPPORTED)
  174231. void PNGAPI
  174232. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  174233. png_bytep trans, int num_trans, png_color_16p trans_values)
  174234. {
  174235. png_debug1(1, "in %s storage function\n", "tRNS");
  174236. if (png_ptr == NULL || info_ptr == NULL)
  174237. return;
  174238. if (trans != NULL)
  174239. {
  174240. #ifdef PNG_FREE_ME_SUPPORTED
  174241. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  174242. #endif
  174243. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  174244. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  174245. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  174246. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  174247. #ifdef PNG_FREE_ME_SUPPORTED
  174248. info_ptr->free_me |= PNG_FREE_TRNS;
  174249. #else
  174250. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  174251. #endif
  174252. }
  174253. if (trans_values != NULL)
  174254. {
  174255. png_memcpy(&(info_ptr->trans_values), trans_values,
  174256. png_sizeof(png_color_16));
  174257. if (num_trans == 0)
  174258. num_trans = 1;
  174259. }
  174260. info_ptr->num_trans = (png_uint_16)num_trans;
  174261. info_ptr->valid |= PNG_INFO_tRNS;
  174262. }
  174263. #endif
  174264. #if defined(PNG_sPLT_SUPPORTED)
  174265. void PNGAPI
  174266. png_set_sPLT(png_structp png_ptr,
  174267. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  174268. {
  174269. png_sPLT_tp np;
  174270. int i;
  174271. if (png_ptr == NULL || info_ptr == NULL)
  174272. return;
  174273. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174274. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174275. if (np == NULL)
  174276. {
  174277. png_warning(png_ptr, "No memory for sPLT palettes.");
  174278. return;
  174279. }
  174280. png_memcpy(np, info_ptr->splt_palettes,
  174281. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174282. png_free(png_ptr, info_ptr->splt_palettes);
  174283. info_ptr->splt_palettes=NULL;
  174284. for (i = 0; i < nentries; i++)
  174285. {
  174286. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174287. png_sPLT_tp from = entries + i;
  174288. to->name = (png_charp)png_malloc_warn(png_ptr,
  174289. png_strlen(from->name) + 1);
  174290. if (to->name == NULL)
  174291. {
  174292. png_warning(png_ptr,
  174293. "Out of memory while processing sPLT chunk");
  174294. }
  174295. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174296. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174297. from->nentries * png_sizeof(png_sPLT_entry));
  174298. png_memcpy(to->entries, from->entries,
  174299. from->nentries * png_sizeof(png_sPLT_entry));
  174300. if (to->entries == NULL)
  174301. {
  174302. png_warning(png_ptr,
  174303. "Out of memory while processing sPLT chunk");
  174304. png_free(png_ptr,to->name);
  174305. to->name = NULL;
  174306. }
  174307. to->nentries = from->nentries;
  174308. to->depth = from->depth;
  174309. }
  174310. info_ptr->splt_palettes = np;
  174311. info_ptr->splt_palettes_num += nentries;
  174312. info_ptr->valid |= PNG_INFO_sPLT;
  174313. #ifdef PNG_FREE_ME_SUPPORTED
  174314. info_ptr->free_me |= PNG_FREE_SPLT;
  174315. #endif
  174316. }
  174317. #endif /* PNG_sPLT_SUPPORTED */
  174318. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174319. void PNGAPI
  174320. png_set_unknown_chunks(png_structp png_ptr,
  174321. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174322. {
  174323. png_unknown_chunkp np;
  174324. int i;
  174325. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174326. return;
  174327. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174328. (info_ptr->unknown_chunks_num + num_unknowns) *
  174329. png_sizeof(png_unknown_chunk));
  174330. if (np == NULL)
  174331. {
  174332. png_warning(png_ptr,
  174333. "Out of memory while processing unknown chunk.");
  174334. return;
  174335. }
  174336. png_memcpy(np, info_ptr->unknown_chunks,
  174337. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174338. png_free(png_ptr, info_ptr->unknown_chunks);
  174339. info_ptr->unknown_chunks=NULL;
  174340. for (i = 0; i < num_unknowns; i++)
  174341. {
  174342. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174343. png_unknown_chunkp from = unknowns + i;
  174344. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174345. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174346. if (to->data == NULL)
  174347. {
  174348. png_warning(png_ptr,
  174349. "Out of memory while processing unknown chunk.");
  174350. }
  174351. else
  174352. {
  174353. png_memcpy(to->data, from->data, from->size);
  174354. to->size = from->size;
  174355. to->location = (png_byte)(png_ptr->mode & 0xff);
  174356. }
  174357. }
  174358. info_ptr->unknown_chunks = np;
  174359. info_ptr->unknown_chunks_num += num_unknowns;
  174360. #ifdef PNG_FREE_ME_SUPPORTED
  174361. info_ptr->free_me |= PNG_FREE_UNKN;
  174362. #endif
  174363. }
  174364. void PNGAPI
  174365. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174366. int chunk, int location)
  174367. {
  174368. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174369. (int)info_ptr->unknown_chunks_num)
  174370. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174371. }
  174372. #endif
  174373. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174374. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174375. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174376. void PNGAPI
  174377. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174378. {
  174379. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174380. if (png_ptr == NULL)
  174381. return;
  174382. png_ptr->mng_features_permitted = (png_byte)
  174383. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174384. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174385. }
  174386. #endif
  174387. #endif
  174388. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174389. png_uint_32 PNGAPI
  174390. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174391. {
  174392. png_debug(1, "in png_permit_mng_features\n");
  174393. if (png_ptr == NULL)
  174394. return (png_uint_32)0;
  174395. png_ptr->mng_features_permitted =
  174396. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174397. return (png_uint_32)png_ptr->mng_features_permitted;
  174398. }
  174399. #endif
  174400. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174401. void PNGAPI
  174402. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174403. chunk_list, int num_chunks)
  174404. {
  174405. png_bytep new_list, p;
  174406. int i, old_num_chunks;
  174407. if (png_ptr == NULL)
  174408. return;
  174409. if (num_chunks == 0)
  174410. {
  174411. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174412. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174413. else
  174414. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174415. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174416. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174417. else
  174418. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174419. return;
  174420. }
  174421. if (chunk_list == NULL)
  174422. return;
  174423. old_num_chunks=png_ptr->num_chunk_list;
  174424. new_list=(png_bytep)png_malloc(png_ptr,
  174425. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174426. if(png_ptr->chunk_list != NULL)
  174427. {
  174428. png_memcpy(new_list, png_ptr->chunk_list,
  174429. (png_size_t)(5*old_num_chunks));
  174430. png_free(png_ptr, png_ptr->chunk_list);
  174431. png_ptr->chunk_list=NULL;
  174432. }
  174433. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174434. (png_size_t)(5*num_chunks));
  174435. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174436. *p=(png_byte)keep;
  174437. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174438. png_ptr->chunk_list=new_list;
  174439. #ifdef PNG_FREE_ME_SUPPORTED
  174440. png_ptr->free_me |= PNG_FREE_LIST;
  174441. #endif
  174442. }
  174443. #endif
  174444. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174445. void PNGAPI
  174446. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174447. png_user_chunk_ptr read_user_chunk_fn)
  174448. {
  174449. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174450. if (png_ptr == NULL)
  174451. return;
  174452. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174453. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174454. }
  174455. #endif
  174456. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174457. void PNGAPI
  174458. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174459. {
  174460. png_debug1(1, "in %s storage function\n", "rows");
  174461. if (png_ptr == NULL || info_ptr == NULL)
  174462. return;
  174463. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174464. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174465. info_ptr->row_pointers = row_pointers;
  174466. if(row_pointers)
  174467. info_ptr->valid |= PNG_INFO_IDAT;
  174468. }
  174469. #endif
  174470. #ifdef PNG_WRITE_SUPPORTED
  174471. void PNGAPI
  174472. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174473. {
  174474. if (png_ptr == NULL)
  174475. return;
  174476. if(png_ptr->zbuf)
  174477. png_free(png_ptr, png_ptr->zbuf);
  174478. png_ptr->zbuf_size = (png_size_t)size;
  174479. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174480. png_ptr->zstream.next_out = png_ptr->zbuf;
  174481. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174482. }
  174483. #endif
  174484. void PNGAPI
  174485. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174486. {
  174487. if (png_ptr && info_ptr)
  174488. info_ptr->valid &= ~(mask);
  174489. }
  174490. #ifndef PNG_1_0_X
  174491. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174492. void PNGAPI
  174493. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174494. {
  174495. if (png_ptr != NULL)
  174496. png_ptr->asm_flags = 0;
  174497. }
  174498. void PNGAPI
  174499. png_set_mmx_thresholds (png_structp png_ptr,
  174500. png_byte mmx_bitdepth_threshold,
  174501. png_uint_32 mmx_rowbytes_threshold)
  174502. {
  174503. if (png_ptr == NULL)
  174504. return;
  174505. }
  174506. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174507. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174508. void PNGAPI
  174509. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174510. png_uint_32 user_height_max)
  174511. {
  174512. if(png_ptr == NULL) return;
  174513. png_ptr->user_width_max = user_width_max;
  174514. png_ptr->user_height_max = user_height_max;
  174515. }
  174516. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174517. #endif /* ?PNG_1_0_X */
  174518. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174519. /*** End of inlined file: pngset.c ***/
  174520. /*** Start of inlined file: pngtrans.c ***/
  174521. #define PNG_INTERNAL
  174522. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174523. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174524. void PNGAPI
  174525. png_set_bgr(png_structp png_ptr)
  174526. {
  174527. png_debug(1, "in png_set_bgr\n");
  174528. if(png_ptr == NULL) return;
  174529. png_ptr->transformations |= PNG_BGR;
  174530. }
  174531. #endif
  174532. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174533. void PNGAPI
  174534. png_set_swap(png_structp png_ptr)
  174535. {
  174536. png_debug(1, "in png_set_swap\n");
  174537. if(png_ptr == NULL) return;
  174538. if (png_ptr->bit_depth == 16)
  174539. png_ptr->transformations |= PNG_SWAP_BYTES;
  174540. }
  174541. #endif
  174542. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174543. void PNGAPI
  174544. png_set_packing(png_structp png_ptr)
  174545. {
  174546. png_debug(1, "in png_set_packing\n");
  174547. if(png_ptr == NULL) return;
  174548. if (png_ptr->bit_depth < 8)
  174549. {
  174550. png_ptr->transformations |= PNG_PACK;
  174551. png_ptr->usr_bit_depth = 8;
  174552. }
  174553. }
  174554. #endif
  174555. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174556. void PNGAPI
  174557. png_set_packswap(png_structp png_ptr)
  174558. {
  174559. png_debug(1, "in png_set_packswap\n");
  174560. if(png_ptr == NULL) return;
  174561. if (png_ptr->bit_depth < 8)
  174562. png_ptr->transformations |= PNG_PACKSWAP;
  174563. }
  174564. #endif
  174565. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174566. void PNGAPI
  174567. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174568. {
  174569. png_debug(1, "in png_set_shift\n");
  174570. if(png_ptr == NULL) return;
  174571. png_ptr->transformations |= PNG_SHIFT;
  174572. png_ptr->shift = *true_bits;
  174573. }
  174574. #endif
  174575. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174576. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174577. int PNGAPI
  174578. png_set_interlace_handling(png_structp png_ptr)
  174579. {
  174580. png_debug(1, "in png_set_interlace handling\n");
  174581. if (png_ptr && png_ptr->interlaced)
  174582. {
  174583. png_ptr->transformations |= PNG_INTERLACE;
  174584. return (7);
  174585. }
  174586. return (1);
  174587. }
  174588. #endif
  174589. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174590. void PNGAPI
  174591. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174592. {
  174593. png_debug(1, "in png_set_filler\n");
  174594. if(png_ptr == NULL) return;
  174595. png_ptr->transformations |= PNG_FILLER;
  174596. png_ptr->filler = (png_byte)filler;
  174597. if (filler_loc == PNG_FILLER_AFTER)
  174598. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174599. else
  174600. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174601. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174602. {
  174603. png_ptr->usr_channels = 4;
  174604. }
  174605. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174606. {
  174607. png_ptr->usr_channels = 2;
  174608. }
  174609. }
  174610. #if !defined(PNG_1_0_X)
  174611. void PNGAPI
  174612. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174613. {
  174614. png_debug(1, "in png_set_add_alpha\n");
  174615. if(png_ptr == NULL) return;
  174616. png_set_filler(png_ptr, filler, filler_loc);
  174617. png_ptr->transformations |= PNG_ADD_ALPHA;
  174618. }
  174619. #endif
  174620. #endif
  174621. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174622. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174623. void PNGAPI
  174624. png_set_swap_alpha(png_structp png_ptr)
  174625. {
  174626. png_debug(1, "in png_set_swap_alpha\n");
  174627. if(png_ptr == NULL) return;
  174628. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174629. }
  174630. #endif
  174631. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174632. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174633. void PNGAPI
  174634. png_set_invert_alpha(png_structp png_ptr)
  174635. {
  174636. png_debug(1, "in png_set_invert_alpha\n");
  174637. if(png_ptr == NULL) return;
  174638. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174639. }
  174640. #endif
  174641. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174642. void PNGAPI
  174643. png_set_invert_mono(png_structp png_ptr)
  174644. {
  174645. png_debug(1, "in png_set_invert_mono\n");
  174646. if(png_ptr == NULL) return;
  174647. png_ptr->transformations |= PNG_INVERT_MONO;
  174648. }
  174649. void /* PRIVATE */
  174650. png_do_invert(png_row_infop row_info, png_bytep row)
  174651. {
  174652. png_debug(1, "in png_do_invert\n");
  174653. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174654. if (row == NULL || row_info == NULL)
  174655. return;
  174656. #endif
  174657. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174658. {
  174659. png_bytep rp = row;
  174660. png_uint_32 i;
  174661. png_uint_32 istop = row_info->rowbytes;
  174662. for (i = 0; i < istop; i++)
  174663. {
  174664. *rp = (png_byte)(~(*rp));
  174665. rp++;
  174666. }
  174667. }
  174668. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174669. row_info->bit_depth == 8)
  174670. {
  174671. png_bytep rp = row;
  174672. png_uint_32 i;
  174673. png_uint_32 istop = row_info->rowbytes;
  174674. for (i = 0; i < istop; i+=2)
  174675. {
  174676. *rp = (png_byte)(~(*rp));
  174677. rp+=2;
  174678. }
  174679. }
  174680. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174681. row_info->bit_depth == 16)
  174682. {
  174683. png_bytep rp = row;
  174684. png_uint_32 i;
  174685. png_uint_32 istop = row_info->rowbytes;
  174686. for (i = 0; i < istop; i+=4)
  174687. {
  174688. *rp = (png_byte)(~(*rp));
  174689. *(rp+1) = (png_byte)(~(*(rp+1)));
  174690. rp+=4;
  174691. }
  174692. }
  174693. }
  174694. #endif
  174695. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174696. void /* PRIVATE */
  174697. png_do_swap(png_row_infop row_info, png_bytep row)
  174698. {
  174699. png_debug(1, "in png_do_swap\n");
  174700. if (
  174701. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174702. row != NULL && row_info != NULL &&
  174703. #endif
  174704. row_info->bit_depth == 16)
  174705. {
  174706. png_bytep rp = row;
  174707. png_uint_32 i;
  174708. png_uint_32 istop= row_info->width * row_info->channels;
  174709. for (i = 0; i < istop; i++, rp += 2)
  174710. {
  174711. png_byte t = *rp;
  174712. *rp = *(rp + 1);
  174713. *(rp + 1) = t;
  174714. }
  174715. }
  174716. }
  174717. #endif
  174718. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174719. static PNG_CONST png_byte onebppswaptable[256] = {
  174720. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  174721. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  174722. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  174723. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  174724. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  174725. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  174726. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  174727. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  174728. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  174729. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  174730. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  174731. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  174732. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  174733. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  174734. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  174735. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  174736. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  174737. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  174738. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  174739. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  174740. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  174741. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  174742. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  174743. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  174744. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  174745. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  174746. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  174747. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  174748. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  174749. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  174750. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  174751. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  174752. };
  174753. static PNG_CONST png_byte twobppswaptable[256] = {
  174754. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  174755. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  174756. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  174757. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  174758. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  174759. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  174760. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  174761. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  174762. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  174763. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  174764. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  174765. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  174766. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  174767. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  174768. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  174769. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  174770. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  174771. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  174772. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  174773. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  174774. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  174775. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  174776. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  174777. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  174778. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  174779. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  174780. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  174781. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  174782. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  174783. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  174784. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  174785. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  174786. };
  174787. static PNG_CONST png_byte fourbppswaptable[256] = {
  174788. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  174789. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  174790. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  174791. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  174792. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  174793. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  174794. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  174795. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  174796. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  174797. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  174798. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  174799. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  174800. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  174801. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  174802. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  174803. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  174804. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  174805. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  174806. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  174807. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  174808. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  174809. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  174810. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  174811. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  174812. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  174813. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  174814. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  174815. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  174816. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  174817. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  174818. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  174819. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  174820. };
  174821. void /* PRIVATE */
  174822. png_do_packswap(png_row_infop row_info, png_bytep row)
  174823. {
  174824. png_debug(1, "in png_do_packswap\n");
  174825. if (
  174826. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174827. row != NULL && row_info != NULL &&
  174828. #endif
  174829. row_info->bit_depth < 8)
  174830. {
  174831. png_bytep rp, end, table;
  174832. end = row + row_info->rowbytes;
  174833. if (row_info->bit_depth == 1)
  174834. table = (png_bytep)onebppswaptable;
  174835. else if (row_info->bit_depth == 2)
  174836. table = (png_bytep)twobppswaptable;
  174837. else if (row_info->bit_depth == 4)
  174838. table = (png_bytep)fourbppswaptable;
  174839. else
  174840. return;
  174841. for (rp = row; rp < end; rp++)
  174842. *rp = table[*rp];
  174843. }
  174844. }
  174845. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  174846. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  174847. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  174848. void /* PRIVATE */
  174849. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  174850. {
  174851. png_debug(1, "in png_do_strip_filler\n");
  174852. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174853. if (row != NULL && row_info != NULL)
  174854. #endif
  174855. {
  174856. png_bytep sp=row;
  174857. png_bytep dp=row;
  174858. png_uint_32 row_width=row_info->width;
  174859. png_uint_32 i;
  174860. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  174861. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  174862. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174863. row_info->channels == 4)
  174864. {
  174865. if (row_info->bit_depth == 8)
  174866. {
  174867. if (flags & PNG_FLAG_FILLER_AFTER)
  174868. {
  174869. dp+=3; sp+=4;
  174870. for (i = 1; i < row_width; i++)
  174871. {
  174872. *dp++ = *sp++;
  174873. *dp++ = *sp++;
  174874. *dp++ = *sp++;
  174875. sp++;
  174876. }
  174877. }
  174878. else
  174879. {
  174880. for (i = 0; i < row_width; i++)
  174881. {
  174882. sp++;
  174883. *dp++ = *sp++;
  174884. *dp++ = *sp++;
  174885. *dp++ = *sp++;
  174886. }
  174887. }
  174888. row_info->pixel_depth = 24;
  174889. row_info->rowbytes = row_width * 3;
  174890. }
  174891. else /* if (row_info->bit_depth == 16) */
  174892. {
  174893. if (flags & PNG_FLAG_FILLER_AFTER)
  174894. {
  174895. sp += 8; dp += 6;
  174896. for (i = 1; i < row_width; i++)
  174897. {
  174898. *dp++ = *sp++;
  174899. *dp++ = *sp++;
  174900. *dp++ = *sp++;
  174901. *dp++ = *sp++;
  174902. *dp++ = *sp++;
  174903. *dp++ = *sp++;
  174904. sp += 2;
  174905. }
  174906. }
  174907. else
  174908. {
  174909. for (i = 0; i < row_width; i++)
  174910. {
  174911. sp+=2;
  174912. *dp++ = *sp++;
  174913. *dp++ = *sp++;
  174914. *dp++ = *sp++;
  174915. *dp++ = *sp++;
  174916. *dp++ = *sp++;
  174917. *dp++ = *sp++;
  174918. }
  174919. }
  174920. row_info->pixel_depth = 48;
  174921. row_info->rowbytes = row_width * 6;
  174922. }
  174923. row_info->channels = 3;
  174924. }
  174925. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  174926. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174927. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174928. row_info->channels == 2)
  174929. {
  174930. if (row_info->bit_depth == 8)
  174931. {
  174932. if (flags & PNG_FLAG_FILLER_AFTER)
  174933. {
  174934. for (i = 0; i < row_width; i++)
  174935. {
  174936. *dp++ = *sp++;
  174937. sp++;
  174938. }
  174939. }
  174940. else
  174941. {
  174942. for (i = 0; i < row_width; i++)
  174943. {
  174944. sp++;
  174945. *dp++ = *sp++;
  174946. }
  174947. }
  174948. row_info->pixel_depth = 8;
  174949. row_info->rowbytes = row_width;
  174950. }
  174951. else /* if (row_info->bit_depth == 16) */
  174952. {
  174953. if (flags & PNG_FLAG_FILLER_AFTER)
  174954. {
  174955. sp += 4; dp += 2;
  174956. for (i = 1; i < row_width; i++)
  174957. {
  174958. *dp++ = *sp++;
  174959. *dp++ = *sp++;
  174960. sp += 2;
  174961. }
  174962. }
  174963. else
  174964. {
  174965. for (i = 0; i < row_width; i++)
  174966. {
  174967. sp += 2;
  174968. *dp++ = *sp++;
  174969. *dp++ = *sp++;
  174970. }
  174971. }
  174972. row_info->pixel_depth = 16;
  174973. row_info->rowbytes = row_width * 2;
  174974. }
  174975. row_info->channels = 1;
  174976. }
  174977. if (flags & PNG_FLAG_STRIP_ALPHA)
  174978. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  174979. }
  174980. }
  174981. #endif
  174982. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174983. void /* PRIVATE */
  174984. png_do_bgr(png_row_infop row_info, png_bytep row)
  174985. {
  174986. png_debug(1, "in png_do_bgr\n");
  174987. if (
  174988. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174989. row != NULL && row_info != NULL &&
  174990. #endif
  174991. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  174992. {
  174993. png_uint_32 row_width = row_info->width;
  174994. if (row_info->bit_depth == 8)
  174995. {
  174996. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174997. {
  174998. png_bytep rp;
  174999. png_uint_32 i;
  175000. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  175001. {
  175002. png_byte save = *rp;
  175003. *rp = *(rp + 2);
  175004. *(rp + 2) = save;
  175005. }
  175006. }
  175007. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175008. {
  175009. png_bytep rp;
  175010. png_uint_32 i;
  175011. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  175012. {
  175013. png_byte save = *rp;
  175014. *rp = *(rp + 2);
  175015. *(rp + 2) = save;
  175016. }
  175017. }
  175018. }
  175019. else if (row_info->bit_depth == 16)
  175020. {
  175021. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175022. {
  175023. png_bytep rp;
  175024. png_uint_32 i;
  175025. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  175026. {
  175027. png_byte save = *rp;
  175028. *rp = *(rp + 4);
  175029. *(rp + 4) = save;
  175030. save = *(rp + 1);
  175031. *(rp + 1) = *(rp + 5);
  175032. *(rp + 5) = save;
  175033. }
  175034. }
  175035. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175036. {
  175037. png_bytep rp;
  175038. png_uint_32 i;
  175039. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  175040. {
  175041. png_byte save = *rp;
  175042. *rp = *(rp + 4);
  175043. *(rp + 4) = save;
  175044. save = *(rp + 1);
  175045. *(rp + 1) = *(rp + 5);
  175046. *(rp + 5) = save;
  175047. }
  175048. }
  175049. }
  175050. }
  175051. }
  175052. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  175053. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  175054. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  175055. defined(PNG_LEGACY_SUPPORTED)
  175056. void PNGAPI
  175057. png_set_user_transform_info(png_structp png_ptr, png_voidp
  175058. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  175059. {
  175060. png_debug(1, "in png_set_user_transform_info\n");
  175061. if(png_ptr == NULL) return;
  175062. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175063. png_ptr->user_transform_ptr = user_transform_ptr;
  175064. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  175065. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  175066. #else
  175067. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  175068. png_warning(png_ptr,
  175069. "This version of libpng does not support user transform info");
  175070. #endif
  175071. }
  175072. #endif
  175073. png_voidp PNGAPI
  175074. png_get_user_transform_ptr(png_structp png_ptr)
  175075. {
  175076. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175077. if (png_ptr == NULL) return (NULL);
  175078. return ((png_voidp)png_ptr->user_transform_ptr);
  175079. #else
  175080. return (NULL);
  175081. #endif
  175082. }
  175083. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  175084. /*** End of inlined file: pngtrans.c ***/
  175085. /*** Start of inlined file: pngwio.c ***/
  175086. #define PNG_INTERNAL
  175087. #ifdef PNG_WRITE_SUPPORTED
  175088. void /* PRIVATE */
  175089. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175090. {
  175091. if (png_ptr->write_data_fn != NULL )
  175092. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  175093. else
  175094. png_error(png_ptr, "Call to NULL write function");
  175095. }
  175096. #if !defined(PNG_NO_STDIO)
  175097. #ifndef USE_FAR_KEYWORD
  175098. void PNGAPI
  175099. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175100. {
  175101. png_uint_32 check;
  175102. if(png_ptr == NULL) return;
  175103. #if defined(_WIN32_WCE)
  175104. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  175105. check = 0;
  175106. #else
  175107. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  175108. #endif
  175109. if (check != length)
  175110. png_error(png_ptr, "Write Error");
  175111. }
  175112. #else
  175113. #define NEAR_BUF_SIZE 1024
  175114. #define MIN(a,b) (a <= b ? a : b)
  175115. void PNGAPI
  175116. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175117. {
  175118. png_uint_32 check;
  175119. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  175120. png_FILE_p io_ptr;
  175121. if(png_ptr == NULL) return;
  175122. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  175123. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  175124. if ((png_bytep)near_data == data)
  175125. {
  175126. #if defined(_WIN32_WCE)
  175127. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  175128. check = 0;
  175129. #else
  175130. check = fwrite(near_data, 1, length, io_ptr);
  175131. #endif
  175132. }
  175133. else
  175134. {
  175135. png_byte buf[NEAR_BUF_SIZE];
  175136. png_size_t written, remaining, err;
  175137. check = 0;
  175138. remaining = length;
  175139. do
  175140. {
  175141. written = MIN(NEAR_BUF_SIZE, remaining);
  175142. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  175143. #if defined(_WIN32_WCE)
  175144. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  175145. err = 0;
  175146. #else
  175147. err = fwrite(buf, 1, written, io_ptr);
  175148. #endif
  175149. if (err != written)
  175150. break;
  175151. else
  175152. check += err;
  175153. data += written;
  175154. remaining -= written;
  175155. }
  175156. while (remaining != 0);
  175157. }
  175158. if (check != length)
  175159. png_error(png_ptr, "Write Error");
  175160. }
  175161. #endif
  175162. #endif
  175163. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175164. void /* PRIVATE */
  175165. png_flush(png_structp png_ptr)
  175166. {
  175167. if (png_ptr->output_flush_fn != NULL)
  175168. (*(png_ptr->output_flush_fn))(png_ptr);
  175169. }
  175170. #if !defined(PNG_NO_STDIO)
  175171. void PNGAPI
  175172. png_default_flush(png_structp png_ptr)
  175173. {
  175174. #if !defined(_WIN32_WCE)
  175175. png_FILE_p io_ptr;
  175176. #endif
  175177. if(png_ptr == NULL) return;
  175178. #if !defined(_WIN32_WCE)
  175179. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  175180. if (io_ptr != NULL)
  175181. fflush(io_ptr);
  175182. #endif
  175183. }
  175184. #endif
  175185. #endif
  175186. void PNGAPI
  175187. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  175188. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  175189. {
  175190. if(png_ptr == NULL) return;
  175191. png_ptr->io_ptr = io_ptr;
  175192. #if !defined(PNG_NO_STDIO)
  175193. if (write_data_fn != NULL)
  175194. png_ptr->write_data_fn = write_data_fn;
  175195. else
  175196. png_ptr->write_data_fn = png_default_write_data;
  175197. #else
  175198. png_ptr->write_data_fn = write_data_fn;
  175199. #endif
  175200. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175201. #if !defined(PNG_NO_STDIO)
  175202. if (output_flush_fn != NULL)
  175203. png_ptr->output_flush_fn = output_flush_fn;
  175204. else
  175205. png_ptr->output_flush_fn = png_default_flush;
  175206. #else
  175207. png_ptr->output_flush_fn = output_flush_fn;
  175208. #endif
  175209. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175210. if (png_ptr->read_data_fn != NULL)
  175211. {
  175212. png_ptr->read_data_fn = NULL;
  175213. png_warning(png_ptr,
  175214. "Attempted to set both read_data_fn and write_data_fn in");
  175215. png_warning(png_ptr,
  175216. "the same structure. Resetting read_data_fn to NULL.");
  175217. }
  175218. }
  175219. #if defined(USE_FAR_KEYWORD)
  175220. #if defined(_MSC_VER)
  175221. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175222. {
  175223. void *near_ptr;
  175224. void FAR *far_ptr;
  175225. FP_OFF(near_ptr) = FP_OFF(ptr);
  175226. far_ptr = (void FAR *)near_ptr;
  175227. if(check != 0)
  175228. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  175229. png_error(png_ptr,"segment lost in conversion");
  175230. return(near_ptr);
  175231. }
  175232. # else
  175233. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175234. {
  175235. void *near_ptr;
  175236. void FAR *far_ptr;
  175237. near_ptr = (void FAR *)ptr;
  175238. far_ptr = (void FAR *)near_ptr;
  175239. if(check != 0)
  175240. if(far_ptr != ptr)
  175241. png_error(png_ptr,"segment lost in conversion");
  175242. return(near_ptr);
  175243. }
  175244. # endif
  175245. # endif
  175246. #endif /* PNG_WRITE_SUPPORTED */
  175247. /*** End of inlined file: pngwio.c ***/
  175248. /*** Start of inlined file: pngwrite.c ***/
  175249. #define PNG_INTERNAL
  175250. #ifdef PNG_WRITE_SUPPORTED
  175251. void PNGAPI
  175252. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  175253. {
  175254. png_debug(1, "in png_write_info_before_PLTE\n");
  175255. if (png_ptr == NULL || info_ptr == NULL)
  175256. return;
  175257. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175258. {
  175259. png_write_sig(png_ptr); /* write PNG signature */
  175260. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175261. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  175262. {
  175263. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  175264. png_ptr->mng_features_permitted=0;
  175265. }
  175266. #endif
  175267. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  175268. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  175269. info_ptr->filter_type,
  175270. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175271. info_ptr->interlace_type);
  175272. #else
  175273. 0);
  175274. #endif
  175275. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175276. if (info_ptr->valid & PNG_INFO_gAMA)
  175277. {
  175278. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175279. png_write_gAMA(png_ptr, info_ptr->gamma);
  175280. #else
  175281. #ifdef PNG_FIXED_POINT_SUPPORTED
  175282. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175283. # endif
  175284. #endif
  175285. }
  175286. #endif
  175287. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175288. if (info_ptr->valid & PNG_INFO_sRGB)
  175289. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175290. #endif
  175291. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175292. if (info_ptr->valid & PNG_INFO_iCCP)
  175293. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175294. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175295. #endif
  175296. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175297. if (info_ptr->valid & PNG_INFO_sBIT)
  175298. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175299. #endif
  175300. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175301. if (info_ptr->valid & PNG_INFO_cHRM)
  175302. {
  175303. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175304. png_write_cHRM(png_ptr,
  175305. info_ptr->x_white, info_ptr->y_white,
  175306. info_ptr->x_red, info_ptr->y_red,
  175307. info_ptr->x_green, info_ptr->y_green,
  175308. info_ptr->x_blue, info_ptr->y_blue);
  175309. #else
  175310. # ifdef PNG_FIXED_POINT_SUPPORTED
  175311. png_write_cHRM_fixed(png_ptr,
  175312. info_ptr->int_x_white, info_ptr->int_y_white,
  175313. info_ptr->int_x_red, info_ptr->int_y_red,
  175314. info_ptr->int_x_green, info_ptr->int_y_green,
  175315. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175316. # endif
  175317. #endif
  175318. }
  175319. #endif
  175320. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175321. if (info_ptr->unknown_chunks_num)
  175322. {
  175323. png_unknown_chunk *up;
  175324. png_debug(5, "writing extra chunks\n");
  175325. for (up = info_ptr->unknown_chunks;
  175326. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175327. up++)
  175328. {
  175329. int keep=png_handle_as_unknown(png_ptr, up->name);
  175330. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175331. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175332. !(up->location & PNG_HAVE_IDAT) &&
  175333. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175334. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175335. {
  175336. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175337. }
  175338. }
  175339. }
  175340. #endif
  175341. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175342. }
  175343. }
  175344. void PNGAPI
  175345. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175346. {
  175347. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175348. int i;
  175349. #endif
  175350. png_debug(1, "in png_write_info\n");
  175351. if (png_ptr == NULL || info_ptr == NULL)
  175352. return;
  175353. png_write_info_before_PLTE(png_ptr, info_ptr);
  175354. if (info_ptr->valid & PNG_INFO_PLTE)
  175355. png_write_PLTE(png_ptr, info_ptr->palette,
  175356. (png_uint_32)info_ptr->num_palette);
  175357. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175358. png_error(png_ptr, "Valid palette required for paletted images");
  175359. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175360. if (info_ptr->valid & PNG_INFO_tRNS)
  175361. {
  175362. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175363. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175364. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175365. {
  175366. int j;
  175367. for (j=0; j<(int)info_ptr->num_trans; j++)
  175368. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175369. }
  175370. #endif
  175371. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175372. info_ptr->num_trans, info_ptr->color_type);
  175373. }
  175374. #endif
  175375. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175376. if (info_ptr->valid & PNG_INFO_bKGD)
  175377. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175378. #endif
  175379. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175380. if (info_ptr->valid & PNG_INFO_hIST)
  175381. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175382. #endif
  175383. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175384. if (info_ptr->valid & PNG_INFO_oFFs)
  175385. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175386. info_ptr->offset_unit_type);
  175387. #endif
  175388. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175389. if (info_ptr->valid & PNG_INFO_pCAL)
  175390. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175391. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175392. info_ptr->pcal_units, info_ptr->pcal_params);
  175393. #endif
  175394. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175395. if (info_ptr->valid & PNG_INFO_sCAL)
  175396. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175397. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175398. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175399. #else
  175400. #ifdef PNG_FIXED_POINT_SUPPORTED
  175401. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175402. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175403. #else
  175404. png_warning(png_ptr,
  175405. "png_write_sCAL not supported; sCAL chunk not written.");
  175406. #endif
  175407. #endif
  175408. #endif
  175409. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175410. if (info_ptr->valid & PNG_INFO_pHYs)
  175411. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175412. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175413. #endif
  175414. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175415. if (info_ptr->valid & PNG_INFO_tIME)
  175416. {
  175417. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175418. png_ptr->mode |= PNG_WROTE_tIME;
  175419. }
  175420. #endif
  175421. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175422. if (info_ptr->valid & PNG_INFO_sPLT)
  175423. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175424. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175425. #endif
  175426. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175427. for (i = 0; i < info_ptr->num_text; i++)
  175428. {
  175429. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175430. info_ptr->text[i].compression);
  175431. if (info_ptr->text[i].compression > 0)
  175432. {
  175433. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175434. png_write_iTXt(png_ptr,
  175435. info_ptr->text[i].compression,
  175436. info_ptr->text[i].key,
  175437. info_ptr->text[i].lang,
  175438. info_ptr->text[i].lang_key,
  175439. info_ptr->text[i].text);
  175440. #else
  175441. png_warning(png_ptr, "Unable to write international text");
  175442. #endif
  175443. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175444. }
  175445. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175446. {
  175447. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175448. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175449. info_ptr->text[i].text, 0,
  175450. info_ptr->text[i].compression);
  175451. #else
  175452. png_warning(png_ptr, "Unable to write compressed text");
  175453. #endif
  175454. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175455. }
  175456. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175457. {
  175458. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175459. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175460. info_ptr->text[i].text,
  175461. 0);
  175462. #else
  175463. png_warning(png_ptr, "Unable to write uncompressed text");
  175464. #endif
  175465. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175466. }
  175467. }
  175468. #endif
  175469. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175470. if (info_ptr->unknown_chunks_num)
  175471. {
  175472. png_unknown_chunk *up;
  175473. png_debug(5, "writing extra chunks\n");
  175474. for (up = info_ptr->unknown_chunks;
  175475. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175476. up++)
  175477. {
  175478. int keep=png_handle_as_unknown(png_ptr, up->name);
  175479. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175480. up->location && (up->location & PNG_HAVE_PLTE) &&
  175481. !(up->location & PNG_HAVE_IDAT) &&
  175482. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175483. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175484. {
  175485. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175486. }
  175487. }
  175488. }
  175489. #endif
  175490. }
  175491. void PNGAPI
  175492. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175493. {
  175494. png_debug(1, "in png_write_end\n");
  175495. if (png_ptr == NULL)
  175496. return;
  175497. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175498. png_error(png_ptr, "No IDATs written into file");
  175499. if (info_ptr != NULL)
  175500. {
  175501. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175502. int i; /* local index variable */
  175503. #endif
  175504. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175505. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175506. !(png_ptr->mode & PNG_WROTE_tIME))
  175507. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175508. #endif
  175509. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175510. for (i = 0; i < info_ptr->num_text; i++)
  175511. {
  175512. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175513. info_ptr->text[i].compression);
  175514. if (info_ptr->text[i].compression > 0)
  175515. {
  175516. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175517. png_write_iTXt(png_ptr,
  175518. info_ptr->text[i].compression,
  175519. info_ptr->text[i].key,
  175520. info_ptr->text[i].lang,
  175521. info_ptr->text[i].lang_key,
  175522. info_ptr->text[i].text);
  175523. #else
  175524. png_warning(png_ptr, "Unable to write international text");
  175525. #endif
  175526. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175527. }
  175528. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175529. {
  175530. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175531. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175532. info_ptr->text[i].text, 0,
  175533. info_ptr->text[i].compression);
  175534. #else
  175535. png_warning(png_ptr, "Unable to write compressed text");
  175536. #endif
  175537. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175538. }
  175539. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175540. {
  175541. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175542. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175543. info_ptr->text[i].text, 0);
  175544. #else
  175545. png_warning(png_ptr, "Unable to write uncompressed text");
  175546. #endif
  175547. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175548. }
  175549. }
  175550. #endif
  175551. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175552. if (info_ptr->unknown_chunks_num)
  175553. {
  175554. png_unknown_chunk *up;
  175555. png_debug(5, "writing extra chunks\n");
  175556. for (up = info_ptr->unknown_chunks;
  175557. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175558. up++)
  175559. {
  175560. int keep=png_handle_as_unknown(png_ptr, up->name);
  175561. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175562. up->location && (up->location & PNG_AFTER_IDAT) &&
  175563. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175564. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175565. {
  175566. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175567. }
  175568. }
  175569. }
  175570. #endif
  175571. }
  175572. png_ptr->mode |= PNG_AFTER_IDAT;
  175573. png_write_IEND(png_ptr);
  175574. }
  175575. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175576. #if !defined(_WIN32_WCE)
  175577. void PNGAPI
  175578. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175579. {
  175580. png_debug(1, "in png_convert_from_struct_tm\n");
  175581. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175582. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175583. ptime->day = (png_byte)ttime->tm_mday;
  175584. ptime->hour = (png_byte)ttime->tm_hour;
  175585. ptime->minute = (png_byte)ttime->tm_min;
  175586. ptime->second = (png_byte)ttime->tm_sec;
  175587. }
  175588. void PNGAPI
  175589. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175590. {
  175591. struct tm *tbuf;
  175592. png_debug(1, "in png_convert_from_time_t\n");
  175593. tbuf = gmtime(&ttime);
  175594. png_convert_from_struct_tm(ptime, tbuf);
  175595. }
  175596. #endif
  175597. #endif
  175598. png_structp PNGAPI
  175599. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175600. png_error_ptr error_fn, png_error_ptr warn_fn)
  175601. {
  175602. #ifdef PNG_USER_MEM_SUPPORTED
  175603. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175604. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175605. }
  175606. png_structp PNGAPI
  175607. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175608. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175609. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175610. {
  175611. #endif /* PNG_USER_MEM_SUPPORTED */
  175612. png_structp png_ptr;
  175613. #ifdef PNG_SETJMP_SUPPORTED
  175614. #ifdef USE_FAR_KEYWORD
  175615. jmp_buf jmpbuf;
  175616. #endif
  175617. #endif
  175618. int i;
  175619. png_debug(1, "in png_create_write_struct\n");
  175620. #ifdef PNG_USER_MEM_SUPPORTED
  175621. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175622. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175623. #else
  175624. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175625. #endif /* PNG_USER_MEM_SUPPORTED */
  175626. if (png_ptr == NULL)
  175627. return (NULL);
  175628. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175629. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175630. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175631. #endif
  175632. #ifdef PNG_SETJMP_SUPPORTED
  175633. #ifdef USE_FAR_KEYWORD
  175634. if (setjmp(jmpbuf))
  175635. #else
  175636. if (setjmp(png_ptr->jmpbuf))
  175637. #endif
  175638. {
  175639. png_free(png_ptr, png_ptr->zbuf);
  175640. png_ptr->zbuf=NULL;
  175641. png_destroy_struct(png_ptr);
  175642. return (NULL);
  175643. }
  175644. #ifdef USE_FAR_KEYWORD
  175645. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175646. #endif
  175647. #endif
  175648. #ifdef PNG_USER_MEM_SUPPORTED
  175649. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175650. #endif /* PNG_USER_MEM_SUPPORTED */
  175651. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175652. i=0;
  175653. do
  175654. {
  175655. if(user_png_ver[i] != png_libpng_ver[i])
  175656. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175657. } while (png_libpng_ver[i++]);
  175658. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175659. {
  175660. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175661. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175662. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175663. {
  175664. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175665. char msg[80];
  175666. if (user_png_ver)
  175667. {
  175668. png_snprintf(msg, 80,
  175669. "Application was compiled with png.h from libpng-%.20s",
  175670. user_png_ver);
  175671. png_warning(png_ptr, msg);
  175672. }
  175673. png_snprintf(msg, 80,
  175674. "Application is running with png.c from libpng-%.20s",
  175675. png_libpng_ver);
  175676. png_warning(png_ptr, msg);
  175677. #endif
  175678. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175679. png_ptr->flags=0;
  175680. #endif
  175681. png_error(png_ptr,
  175682. "Incompatible libpng version in application and library");
  175683. }
  175684. }
  175685. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175686. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175687. (png_uint_32)png_ptr->zbuf_size);
  175688. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175689. png_flush_ptr_NULL);
  175690. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175691. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175692. 1, png_doublep_NULL, png_doublep_NULL);
  175693. #endif
  175694. #ifdef PNG_SETJMP_SUPPORTED
  175695. #ifdef USE_FAR_KEYWORD
  175696. if (setjmp(jmpbuf))
  175697. PNG_ABORT();
  175698. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175699. #else
  175700. if (setjmp(png_ptr->jmpbuf))
  175701. PNG_ABORT();
  175702. #endif
  175703. #endif
  175704. return (png_ptr);
  175705. }
  175706. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  175707. #undef png_write_init
  175708. void PNGAPI
  175709. png_write_init(png_structp png_ptr)
  175710. {
  175711. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  175712. }
  175713. void PNGAPI
  175714. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  175715. png_size_t png_struct_size, png_size_t png_info_size)
  175716. {
  175717. if(png_ptr == NULL) return;
  175718. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175719. if(png_sizeof(png_struct) > png_struct_size ||
  175720. png_sizeof(png_info) > png_info_size)
  175721. {
  175722. char msg[80];
  175723. png_ptr->warning_fn=NULL;
  175724. if (user_png_ver)
  175725. {
  175726. png_snprintf(msg, 80,
  175727. "Application was compiled with png.h from libpng-%.20s",
  175728. user_png_ver);
  175729. png_warning(png_ptr, msg);
  175730. }
  175731. png_snprintf(msg, 80,
  175732. "Application is running with png.c from libpng-%.20s",
  175733. png_libpng_ver);
  175734. png_warning(png_ptr, msg);
  175735. }
  175736. #endif
  175737. if(png_sizeof(png_struct) > png_struct_size)
  175738. {
  175739. png_ptr->error_fn=NULL;
  175740. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175741. png_ptr->flags=0;
  175742. #endif
  175743. png_error(png_ptr,
  175744. "The png struct allocated by the application for writing is too small.");
  175745. }
  175746. if(png_sizeof(png_info) > png_info_size)
  175747. {
  175748. png_ptr->error_fn=NULL;
  175749. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175750. png_ptr->flags=0;
  175751. #endif
  175752. png_error(png_ptr,
  175753. "The info struct allocated by the application for writing is too small.");
  175754. }
  175755. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  175756. }
  175757. #endif /* PNG_1_0_X || PNG_1_2_X */
  175758. void PNGAPI
  175759. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  175760. png_size_t png_struct_size)
  175761. {
  175762. png_structp png_ptr=*ptr_ptr;
  175763. #ifdef PNG_SETJMP_SUPPORTED
  175764. jmp_buf tmp_jmp; /* to save current jump buffer */
  175765. #endif
  175766. int i = 0;
  175767. if (png_ptr == NULL)
  175768. return;
  175769. do
  175770. {
  175771. if (user_png_ver[i] != png_libpng_ver[i])
  175772. {
  175773. #ifdef PNG_LEGACY_SUPPORTED
  175774. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175775. #else
  175776. png_ptr->warning_fn=NULL;
  175777. png_warning(png_ptr,
  175778. "Application uses deprecated png_write_init() and should be recompiled.");
  175779. break;
  175780. #endif
  175781. }
  175782. } while (png_libpng_ver[i++]);
  175783. png_debug(1, "in png_write_init_3\n");
  175784. #ifdef PNG_SETJMP_SUPPORTED
  175785. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175786. #endif
  175787. if (png_sizeof(png_struct) > png_struct_size)
  175788. {
  175789. png_destroy_struct(png_ptr);
  175790. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175791. *ptr_ptr = png_ptr;
  175792. }
  175793. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175794. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175795. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175796. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175797. #endif
  175798. #ifdef PNG_SETJMP_SUPPORTED
  175799. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175800. #endif
  175801. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175802. png_flush_ptr_NULL);
  175803. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175804. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175805. (png_uint_32)png_ptr->zbuf_size);
  175806. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175807. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175808. 1, png_doublep_NULL, png_doublep_NULL);
  175809. #endif
  175810. }
  175811. void PNGAPI
  175812. png_write_rows(png_structp png_ptr, png_bytepp row,
  175813. png_uint_32 num_rows)
  175814. {
  175815. png_uint_32 i; /* row counter */
  175816. png_bytepp rp; /* row pointer */
  175817. png_debug(1, "in png_write_rows\n");
  175818. if (png_ptr == NULL)
  175819. return;
  175820. for (i = 0, rp = row; i < num_rows; i++, rp++)
  175821. {
  175822. png_write_row(png_ptr, *rp);
  175823. }
  175824. }
  175825. void PNGAPI
  175826. png_write_image(png_structp png_ptr, png_bytepp image)
  175827. {
  175828. png_uint_32 i; /* row index */
  175829. int pass, num_pass; /* pass variables */
  175830. png_bytepp rp; /* points to current row */
  175831. if (png_ptr == NULL)
  175832. return;
  175833. png_debug(1, "in png_write_image\n");
  175834. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175835. num_pass = png_set_interlace_handling(png_ptr);
  175836. #else
  175837. num_pass = 1;
  175838. #endif
  175839. for (pass = 0; pass < num_pass; pass++)
  175840. {
  175841. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  175842. {
  175843. png_write_row(png_ptr, *rp);
  175844. }
  175845. }
  175846. }
  175847. void PNGAPI
  175848. png_write_row(png_structp png_ptr, png_bytep row)
  175849. {
  175850. if (png_ptr == NULL)
  175851. return;
  175852. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  175853. png_ptr->row_number, png_ptr->pass);
  175854. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  175855. {
  175856. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175857. png_error(png_ptr,
  175858. "png_write_info was never called before png_write_row.");
  175859. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  175860. if (png_ptr->transformations & PNG_INVERT_MONO)
  175861. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  175862. #endif
  175863. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  175864. if (png_ptr->transformations & PNG_FILLER)
  175865. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  175866. #endif
  175867. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  175868. if (png_ptr->transformations & PNG_PACKSWAP)
  175869. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  175870. #endif
  175871. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  175872. if (png_ptr->transformations & PNG_PACK)
  175873. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  175874. #endif
  175875. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  175876. if (png_ptr->transformations & PNG_SHIFT)
  175877. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  175878. #endif
  175879. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  175880. if (png_ptr->transformations & PNG_BGR)
  175881. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  175882. #endif
  175883. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  175884. if (png_ptr->transformations & PNG_SWAP_BYTES)
  175885. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  175886. #endif
  175887. png_write_start_row(png_ptr);
  175888. }
  175889. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175890. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  175891. {
  175892. switch (png_ptr->pass)
  175893. {
  175894. case 0:
  175895. if (png_ptr->row_number & 0x07)
  175896. {
  175897. png_write_finish_row(png_ptr);
  175898. return;
  175899. }
  175900. break;
  175901. case 1:
  175902. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  175903. {
  175904. png_write_finish_row(png_ptr);
  175905. return;
  175906. }
  175907. break;
  175908. case 2:
  175909. if ((png_ptr->row_number & 0x07) != 4)
  175910. {
  175911. png_write_finish_row(png_ptr);
  175912. return;
  175913. }
  175914. break;
  175915. case 3:
  175916. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  175917. {
  175918. png_write_finish_row(png_ptr);
  175919. return;
  175920. }
  175921. break;
  175922. case 4:
  175923. if ((png_ptr->row_number & 0x03) != 2)
  175924. {
  175925. png_write_finish_row(png_ptr);
  175926. return;
  175927. }
  175928. break;
  175929. case 5:
  175930. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  175931. {
  175932. png_write_finish_row(png_ptr);
  175933. return;
  175934. }
  175935. break;
  175936. case 6:
  175937. if (!(png_ptr->row_number & 0x01))
  175938. {
  175939. png_write_finish_row(png_ptr);
  175940. return;
  175941. }
  175942. break;
  175943. }
  175944. }
  175945. #endif
  175946. png_ptr->row_info.color_type = png_ptr->color_type;
  175947. png_ptr->row_info.width = png_ptr->usr_width;
  175948. png_ptr->row_info.channels = png_ptr->usr_channels;
  175949. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  175950. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  175951. png_ptr->row_info.channels);
  175952. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  175953. png_ptr->row_info.width);
  175954. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  175955. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  175956. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  175957. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  175958. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  175959. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  175960. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  175961. png_ptr->row_info.rowbytes);
  175962. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175963. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  175964. (png_ptr->transformations & PNG_INTERLACE))
  175965. {
  175966. png_do_write_interlace(&(png_ptr->row_info),
  175967. png_ptr->row_buf + 1, png_ptr->pass);
  175968. if (!(png_ptr->row_info.width))
  175969. {
  175970. png_write_finish_row(png_ptr);
  175971. return;
  175972. }
  175973. }
  175974. #endif
  175975. if (png_ptr->transformations)
  175976. png_do_write_transformations(png_ptr);
  175977. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175978. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175979. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  175980. {
  175981. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  175982. }
  175983. #endif
  175984. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  175985. if (png_ptr->write_row_fn != NULL)
  175986. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  175987. }
  175988. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175989. void PNGAPI
  175990. png_set_flush(png_structp png_ptr, int nrows)
  175991. {
  175992. png_debug(1, "in png_set_flush\n");
  175993. if (png_ptr == NULL)
  175994. return;
  175995. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  175996. }
  175997. void PNGAPI
  175998. png_write_flush(png_structp png_ptr)
  175999. {
  176000. int wrote_IDAT;
  176001. png_debug(1, "in png_write_flush\n");
  176002. if (png_ptr == NULL)
  176003. return;
  176004. if (png_ptr->row_number >= png_ptr->num_rows)
  176005. return;
  176006. do
  176007. {
  176008. int ret;
  176009. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  176010. wrote_IDAT = 0;
  176011. if (ret != Z_OK)
  176012. {
  176013. if (png_ptr->zstream.msg != NULL)
  176014. png_error(png_ptr, png_ptr->zstream.msg);
  176015. else
  176016. png_error(png_ptr, "zlib error");
  176017. }
  176018. if (!(png_ptr->zstream.avail_out))
  176019. {
  176020. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176021. png_ptr->zbuf_size);
  176022. png_ptr->zstream.next_out = png_ptr->zbuf;
  176023. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176024. wrote_IDAT = 1;
  176025. }
  176026. } while(wrote_IDAT == 1);
  176027. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  176028. {
  176029. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176030. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  176031. png_ptr->zstream.next_out = png_ptr->zbuf;
  176032. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176033. }
  176034. png_ptr->flush_rows = 0;
  176035. png_flush(png_ptr);
  176036. }
  176037. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  176038. void PNGAPI
  176039. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  176040. {
  176041. png_structp png_ptr = NULL;
  176042. png_infop info_ptr = NULL;
  176043. #ifdef PNG_USER_MEM_SUPPORTED
  176044. png_free_ptr free_fn = NULL;
  176045. png_voidp mem_ptr = NULL;
  176046. #endif
  176047. png_debug(1, "in png_destroy_write_struct\n");
  176048. if (png_ptr_ptr != NULL)
  176049. {
  176050. png_ptr = *png_ptr_ptr;
  176051. #ifdef PNG_USER_MEM_SUPPORTED
  176052. free_fn = png_ptr->free_fn;
  176053. mem_ptr = png_ptr->mem_ptr;
  176054. #endif
  176055. }
  176056. if (info_ptr_ptr != NULL)
  176057. info_ptr = *info_ptr_ptr;
  176058. if (info_ptr != NULL)
  176059. {
  176060. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  176061. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  176062. if (png_ptr->num_chunk_list)
  176063. {
  176064. png_free(png_ptr, png_ptr->chunk_list);
  176065. png_ptr->chunk_list=NULL;
  176066. png_ptr->num_chunk_list=0;
  176067. }
  176068. #endif
  176069. #ifdef PNG_USER_MEM_SUPPORTED
  176070. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  176071. (png_voidp)mem_ptr);
  176072. #else
  176073. png_destroy_struct((png_voidp)info_ptr);
  176074. #endif
  176075. *info_ptr_ptr = NULL;
  176076. }
  176077. if (png_ptr != NULL)
  176078. {
  176079. png_write_destroy(png_ptr);
  176080. #ifdef PNG_USER_MEM_SUPPORTED
  176081. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  176082. (png_voidp)mem_ptr);
  176083. #else
  176084. png_destroy_struct((png_voidp)png_ptr);
  176085. #endif
  176086. *png_ptr_ptr = NULL;
  176087. }
  176088. }
  176089. void /* PRIVATE */
  176090. png_write_destroy(png_structp png_ptr)
  176091. {
  176092. #ifdef PNG_SETJMP_SUPPORTED
  176093. jmp_buf tmp_jmp; /* save jump buffer */
  176094. #endif
  176095. png_error_ptr error_fn;
  176096. png_error_ptr warning_fn;
  176097. png_voidp error_ptr;
  176098. #ifdef PNG_USER_MEM_SUPPORTED
  176099. png_free_ptr free_fn;
  176100. #endif
  176101. png_debug(1, "in png_write_destroy\n");
  176102. deflateEnd(&png_ptr->zstream);
  176103. png_free(png_ptr, png_ptr->zbuf);
  176104. png_free(png_ptr, png_ptr->row_buf);
  176105. png_free(png_ptr, png_ptr->prev_row);
  176106. png_free(png_ptr, png_ptr->sub_row);
  176107. png_free(png_ptr, png_ptr->up_row);
  176108. png_free(png_ptr, png_ptr->avg_row);
  176109. png_free(png_ptr, png_ptr->paeth_row);
  176110. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  176111. png_free(png_ptr, png_ptr->time_buffer);
  176112. #endif
  176113. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176114. png_free(png_ptr, png_ptr->prev_filters);
  176115. png_free(png_ptr, png_ptr->filter_weights);
  176116. png_free(png_ptr, png_ptr->inv_filter_weights);
  176117. png_free(png_ptr, png_ptr->filter_costs);
  176118. png_free(png_ptr, png_ptr->inv_filter_costs);
  176119. #endif
  176120. #ifdef PNG_SETJMP_SUPPORTED
  176121. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176122. #endif
  176123. error_fn = png_ptr->error_fn;
  176124. warning_fn = png_ptr->warning_fn;
  176125. error_ptr = png_ptr->error_ptr;
  176126. #ifdef PNG_USER_MEM_SUPPORTED
  176127. free_fn = png_ptr->free_fn;
  176128. #endif
  176129. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176130. png_ptr->error_fn = error_fn;
  176131. png_ptr->warning_fn = warning_fn;
  176132. png_ptr->error_ptr = error_ptr;
  176133. #ifdef PNG_USER_MEM_SUPPORTED
  176134. png_ptr->free_fn = free_fn;
  176135. #endif
  176136. #ifdef PNG_SETJMP_SUPPORTED
  176137. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176138. #endif
  176139. }
  176140. void PNGAPI
  176141. png_set_filter(png_structp png_ptr, int method, int filters)
  176142. {
  176143. png_debug(1, "in png_set_filter\n");
  176144. if (png_ptr == NULL)
  176145. return;
  176146. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176147. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176148. (method == PNG_INTRAPIXEL_DIFFERENCING))
  176149. method = PNG_FILTER_TYPE_BASE;
  176150. #endif
  176151. if (method == PNG_FILTER_TYPE_BASE)
  176152. {
  176153. switch (filters & (PNG_ALL_FILTERS | 0x07))
  176154. {
  176155. #ifndef PNG_NO_WRITE_FILTER
  176156. case 5:
  176157. case 6:
  176158. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  176159. #endif /* PNG_NO_WRITE_FILTER */
  176160. case PNG_FILTER_VALUE_NONE:
  176161. png_ptr->do_filter=PNG_FILTER_NONE; break;
  176162. #ifndef PNG_NO_WRITE_FILTER
  176163. case PNG_FILTER_VALUE_SUB:
  176164. png_ptr->do_filter=PNG_FILTER_SUB; break;
  176165. case PNG_FILTER_VALUE_UP:
  176166. png_ptr->do_filter=PNG_FILTER_UP; break;
  176167. case PNG_FILTER_VALUE_AVG:
  176168. png_ptr->do_filter=PNG_FILTER_AVG; break;
  176169. case PNG_FILTER_VALUE_PAETH:
  176170. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  176171. default: png_ptr->do_filter = (png_byte)filters; break;
  176172. #else
  176173. default: png_warning(png_ptr, "Unknown row filter for method 0");
  176174. #endif /* PNG_NO_WRITE_FILTER */
  176175. }
  176176. if (png_ptr->row_buf != NULL)
  176177. {
  176178. #ifndef PNG_NO_WRITE_FILTER
  176179. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  176180. {
  176181. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  176182. (png_ptr->rowbytes + 1));
  176183. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  176184. }
  176185. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  176186. {
  176187. if (png_ptr->prev_row == NULL)
  176188. {
  176189. png_warning(png_ptr, "Can't add Up filter after starting");
  176190. png_ptr->do_filter &= ~PNG_FILTER_UP;
  176191. }
  176192. else
  176193. {
  176194. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  176195. (png_ptr->rowbytes + 1));
  176196. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  176197. }
  176198. }
  176199. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  176200. {
  176201. if (png_ptr->prev_row == NULL)
  176202. {
  176203. png_warning(png_ptr, "Can't add Average filter after starting");
  176204. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  176205. }
  176206. else
  176207. {
  176208. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  176209. (png_ptr->rowbytes + 1));
  176210. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  176211. }
  176212. }
  176213. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  176214. png_ptr->paeth_row == NULL)
  176215. {
  176216. if (png_ptr->prev_row == NULL)
  176217. {
  176218. png_warning(png_ptr, "Can't add Paeth filter after starting");
  176219. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  176220. }
  176221. else
  176222. {
  176223. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  176224. (png_ptr->rowbytes + 1));
  176225. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  176226. }
  176227. }
  176228. if (png_ptr->do_filter == PNG_NO_FILTERS)
  176229. #endif /* PNG_NO_WRITE_FILTER */
  176230. png_ptr->do_filter = PNG_FILTER_NONE;
  176231. }
  176232. }
  176233. else
  176234. png_error(png_ptr, "Unknown custom filter method");
  176235. }
  176236. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  176237. void PNGAPI
  176238. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  176239. int num_weights, png_doublep filter_weights,
  176240. png_doublep filter_costs)
  176241. {
  176242. int i;
  176243. png_debug(1, "in png_set_filter_heuristics\n");
  176244. if (png_ptr == NULL)
  176245. return;
  176246. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  176247. {
  176248. png_warning(png_ptr, "Unknown filter heuristic method");
  176249. return;
  176250. }
  176251. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  176252. {
  176253. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  176254. }
  176255. if (num_weights < 0 || filter_weights == NULL ||
  176256. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  176257. {
  176258. num_weights = 0;
  176259. }
  176260. png_ptr->num_prev_filters = (png_byte)num_weights;
  176261. png_ptr->heuristic_method = (png_byte)heuristic_method;
  176262. if (num_weights > 0)
  176263. {
  176264. if (png_ptr->prev_filters == NULL)
  176265. {
  176266. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  176267. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  176268. for (i = 0; i < num_weights; i++)
  176269. {
  176270. png_ptr->prev_filters[i] = 255;
  176271. }
  176272. }
  176273. if (png_ptr->filter_weights == NULL)
  176274. {
  176275. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176276. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176277. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176278. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176279. for (i = 0; i < num_weights; i++)
  176280. {
  176281. png_ptr->inv_filter_weights[i] =
  176282. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176283. }
  176284. }
  176285. for (i = 0; i < num_weights; i++)
  176286. {
  176287. if (filter_weights[i] < 0.0)
  176288. {
  176289. png_ptr->inv_filter_weights[i] =
  176290. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176291. }
  176292. else
  176293. {
  176294. png_ptr->inv_filter_weights[i] =
  176295. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176296. png_ptr->filter_weights[i] =
  176297. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176298. }
  176299. }
  176300. }
  176301. if (png_ptr->filter_costs == NULL)
  176302. {
  176303. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176304. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176305. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176306. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176307. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176308. {
  176309. png_ptr->inv_filter_costs[i] =
  176310. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176311. }
  176312. }
  176313. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176314. {
  176315. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176316. {
  176317. png_ptr->inv_filter_costs[i] =
  176318. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176319. }
  176320. else if (filter_costs[i] >= 1.0)
  176321. {
  176322. png_ptr->inv_filter_costs[i] =
  176323. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176324. png_ptr->filter_costs[i] =
  176325. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176326. }
  176327. }
  176328. }
  176329. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176330. void PNGAPI
  176331. png_set_compression_level(png_structp png_ptr, int level)
  176332. {
  176333. png_debug(1, "in png_set_compression_level\n");
  176334. if (png_ptr == NULL)
  176335. return;
  176336. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176337. png_ptr->zlib_level = level;
  176338. }
  176339. void PNGAPI
  176340. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176341. {
  176342. png_debug(1, "in png_set_compression_mem_level\n");
  176343. if (png_ptr == NULL)
  176344. return;
  176345. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176346. png_ptr->zlib_mem_level = mem_level;
  176347. }
  176348. void PNGAPI
  176349. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176350. {
  176351. png_debug(1, "in png_set_compression_strategy\n");
  176352. if (png_ptr == NULL)
  176353. return;
  176354. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176355. png_ptr->zlib_strategy = strategy;
  176356. }
  176357. void PNGAPI
  176358. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176359. {
  176360. if (png_ptr == NULL)
  176361. return;
  176362. if (window_bits > 15)
  176363. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176364. else if (window_bits < 8)
  176365. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176366. #ifndef WBITS_8_OK
  176367. if (window_bits == 8)
  176368. {
  176369. png_warning(png_ptr, "Compression window is being reset to 512");
  176370. window_bits=9;
  176371. }
  176372. #endif
  176373. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176374. png_ptr->zlib_window_bits = window_bits;
  176375. }
  176376. void PNGAPI
  176377. png_set_compression_method(png_structp png_ptr, int method)
  176378. {
  176379. png_debug(1, "in png_set_compression_method\n");
  176380. if (png_ptr == NULL)
  176381. return;
  176382. if (method != 8)
  176383. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176384. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176385. png_ptr->zlib_method = method;
  176386. }
  176387. void PNGAPI
  176388. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176389. {
  176390. if (png_ptr == NULL)
  176391. return;
  176392. png_ptr->write_row_fn = write_row_fn;
  176393. }
  176394. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176395. void PNGAPI
  176396. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176397. write_user_transform_fn)
  176398. {
  176399. png_debug(1, "in png_set_write_user_transform_fn\n");
  176400. if (png_ptr == NULL)
  176401. return;
  176402. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176403. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176404. }
  176405. #endif
  176406. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176407. void PNGAPI
  176408. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176409. int transforms, voidp params)
  176410. {
  176411. if (png_ptr == NULL || info_ptr == NULL)
  176412. return;
  176413. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176414. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176415. png_set_invert_alpha(png_ptr);
  176416. #endif
  176417. png_write_info(png_ptr, info_ptr);
  176418. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176419. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176420. png_set_invert_mono(png_ptr);
  176421. #endif
  176422. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176423. if ((transforms & PNG_TRANSFORM_SHIFT)
  176424. && (info_ptr->valid & PNG_INFO_sBIT))
  176425. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176426. #endif
  176427. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176428. if (transforms & PNG_TRANSFORM_PACKING)
  176429. png_set_packing(png_ptr);
  176430. #endif
  176431. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176432. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176433. png_set_swap_alpha(png_ptr);
  176434. #endif
  176435. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176436. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176437. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176438. #endif
  176439. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176440. if (transforms & PNG_TRANSFORM_BGR)
  176441. png_set_bgr(png_ptr);
  176442. #endif
  176443. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176444. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176445. png_set_swap(png_ptr);
  176446. #endif
  176447. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176448. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176449. png_set_packswap(png_ptr);
  176450. #endif
  176451. if (info_ptr->valid & PNG_INFO_IDAT)
  176452. png_write_image(png_ptr, info_ptr->row_pointers);
  176453. png_write_end(png_ptr, info_ptr);
  176454. transforms = transforms; /* quiet compiler warnings */
  176455. params = params;
  176456. }
  176457. #endif
  176458. #endif /* PNG_WRITE_SUPPORTED */
  176459. /*** End of inlined file: pngwrite.c ***/
  176460. /*** Start of inlined file: pngwtran.c ***/
  176461. #define PNG_INTERNAL
  176462. #ifdef PNG_WRITE_SUPPORTED
  176463. void /* PRIVATE */
  176464. png_do_write_transformations(png_structp png_ptr)
  176465. {
  176466. png_debug(1, "in png_do_write_transformations\n");
  176467. if (png_ptr == NULL)
  176468. return;
  176469. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176470. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176471. if(png_ptr->write_user_transform_fn != NULL)
  176472. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176473. (png_ptr, /* png_ptr */
  176474. &(png_ptr->row_info), /* row_info: */
  176475. png_ptr->row_buf + 1); /* start of pixel data for row */
  176476. #endif
  176477. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176478. if (png_ptr->transformations & PNG_FILLER)
  176479. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176480. png_ptr->flags);
  176481. #endif
  176482. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176483. if (png_ptr->transformations & PNG_PACKSWAP)
  176484. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176485. #endif
  176486. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176487. if (png_ptr->transformations & PNG_PACK)
  176488. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176489. (png_uint_32)png_ptr->bit_depth);
  176490. #endif
  176491. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176492. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176493. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176494. #endif
  176495. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176496. if (png_ptr->transformations & PNG_SHIFT)
  176497. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176498. &(png_ptr->shift));
  176499. #endif
  176500. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176501. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176502. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176503. #endif
  176504. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176505. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176506. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176507. #endif
  176508. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176509. if (png_ptr->transformations & PNG_BGR)
  176510. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176511. #endif
  176512. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176513. if (png_ptr->transformations & PNG_INVERT_MONO)
  176514. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176515. #endif
  176516. }
  176517. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176518. void /* PRIVATE */
  176519. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176520. {
  176521. png_debug(1, "in png_do_pack\n");
  176522. if (row_info->bit_depth == 8 &&
  176523. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176524. row != NULL && row_info != NULL &&
  176525. #endif
  176526. row_info->channels == 1)
  176527. {
  176528. switch ((int)bit_depth)
  176529. {
  176530. case 1:
  176531. {
  176532. png_bytep sp, dp;
  176533. int mask, v;
  176534. png_uint_32 i;
  176535. png_uint_32 row_width = row_info->width;
  176536. sp = row;
  176537. dp = row;
  176538. mask = 0x80;
  176539. v = 0;
  176540. for (i = 0; i < row_width; i++)
  176541. {
  176542. if (*sp != 0)
  176543. v |= mask;
  176544. sp++;
  176545. if (mask > 1)
  176546. mask >>= 1;
  176547. else
  176548. {
  176549. mask = 0x80;
  176550. *dp = (png_byte)v;
  176551. dp++;
  176552. v = 0;
  176553. }
  176554. }
  176555. if (mask != 0x80)
  176556. *dp = (png_byte)v;
  176557. break;
  176558. }
  176559. case 2:
  176560. {
  176561. png_bytep sp, dp;
  176562. int shift, v;
  176563. png_uint_32 i;
  176564. png_uint_32 row_width = row_info->width;
  176565. sp = row;
  176566. dp = row;
  176567. shift = 6;
  176568. v = 0;
  176569. for (i = 0; i < row_width; i++)
  176570. {
  176571. png_byte value;
  176572. value = (png_byte)(*sp & 0x03);
  176573. v |= (value << shift);
  176574. if (shift == 0)
  176575. {
  176576. shift = 6;
  176577. *dp = (png_byte)v;
  176578. dp++;
  176579. v = 0;
  176580. }
  176581. else
  176582. shift -= 2;
  176583. sp++;
  176584. }
  176585. if (shift != 6)
  176586. *dp = (png_byte)v;
  176587. break;
  176588. }
  176589. case 4:
  176590. {
  176591. png_bytep sp, dp;
  176592. int shift, v;
  176593. png_uint_32 i;
  176594. png_uint_32 row_width = row_info->width;
  176595. sp = row;
  176596. dp = row;
  176597. shift = 4;
  176598. v = 0;
  176599. for (i = 0; i < row_width; i++)
  176600. {
  176601. png_byte value;
  176602. value = (png_byte)(*sp & 0x0f);
  176603. v |= (value << shift);
  176604. if (shift == 0)
  176605. {
  176606. shift = 4;
  176607. *dp = (png_byte)v;
  176608. dp++;
  176609. v = 0;
  176610. }
  176611. else
  176612. shift -= 4;
  176613. sp++;
  176614. }
  176615. if (shift != 4)
  176616. *dp = (png_byte)v;
  176617. break;
  176618. }
  176619. }
  176620. row_info->bit_depth = (png_byte)bit_depth;
  176621. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176622. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176623. row_info->width);
  176624. }
  176625. }
  176626. #endif
  176627. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176628. void /* PRIVATE */
  176629. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176630. {
  176631. png_debug(1, "in png_do_shift\n");
  176632. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176633. if (row != NULL && row_info != NULL &&
  176634. #else
  176635. if (
  176636. #endif
  176637. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176638. {
  176639. int shift_start[4], shift_dec[4];
  176640. int channels = 0;
  176641. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176642. {
  176643. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176644. shift_dec[channels] = bit_depth->red;
  176645. channels++;
  176646. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176647. shift_dec[channels] = bit_depth->green;
  176648. channels++;
  176649. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176650. shift_dec[channels] = bit_depth->blue;
  176651. channels++;
  176652. }
  176653. else
  176654. {
  176655. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176656. shift_dec[channels] = bit_depth->gray;
  176657. channels++;
  176658. }
  176659. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176660. {
  176661. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176662. shift_dec[channels] = bit_depth->alpha;
  176663. channels++;
  176664. }
  176665. if (row_info->bit_depth < 8)
  176666. {
  176667. png_bytep bp = row;
  176668. png_uint_32 i;
  176669. png_byte mask;
  176670. png_uint_32 row_bytes = row_info->rowbytes;
  176671. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  176672. mask = 0x55;
  176673. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  176674. mask = 0x11;
  176675. else
  176676. mask = 0xff;
  176677. for (i = 0; i < row_bytes; i++, bp++)
  176678. {
  176679. png_uint_16 v;
  176680. int j;
  176681. v = *bp;
  176682. *bp = 0;
  176683. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  176684. {
  176685. if (j > 0)
  176686. *bp |= (png_byte)((v << j) & 0xff);
  176687. else
  176688. *bp |= (png_byte)((v >> (-j)) & mask);
  176689. }
  176690. }
  176691. }
  176692. else if (row_info->bit_depth == 8)
  176693. {
  176694. png_bytep bp = row;
  176695. png_uint_32 i;
  176696. png_uint_32 istop = channels * row_info->width;
  176697. for (i = 0; i < istop; i++, bp++)
  176698. {
  176699. png_uint_16 v;
  176700. int j;
  176701. int c = (int)(i%channels);
  176702. v = *bp;
  176703. *bp = 0;
  176704. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176705. {
  176706. if (j > 0)
  176707. *bp |= (png_byte)((v << j) & 0xff);
  176708. else
  176709. *bp |= (png_byte)((v >> (-j)) & 0xff);
  176710. }
  176711. }
  176712. }
  176713. else
  176714. {
  176715. png_bytep bp;
  176716. png_uint_32 i;
  176717. png_uint_32 istop = channels * row_info->width;
  176718. for (bp = row, i = 0; i < istop; i++)
  176719. {
  176720. int c = (int)(i%channels);
  176721. png_uint_16 value, v;
  176722. int j;
  176723. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  176724. value = 0;
  176725. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176726. {
  176727. if (j > 0)
  176728. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  176729. else
  176730. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  176731. }
  176732. *bp++ = (png_byte)(value >> 8);
  176733. *bp++ = (png_byte)(value & 0xff);
  176734. }
  176735. }
  176736. }
  176737. }
  176738. #endif
  176739. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176740. void /* PRIVATE */
  176741. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  176742. {
  176743. png_debug(1, "in png_do_write_swap_alpha\n");
  176744. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176745. if (row != NULL && row_info != NULL)
  176746. #endif
  176747. {
  176748. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176749. {
  176750. if (row_info->bit_depth == 8)
  176751. {
  176752. png_bytep sp, dp;
  176753. png_uint_32 i;
  176754. png_uint_32 row_width = row_info->width;
  176755. for (i = 0, sp = dp = row; i < row_width; i++)
  176756. {
  176757. png_byte save = *(sp++);
  176758. *(dp++) = *(sp++);
  176759. *(dp++) = *(sp++);
  176760. *(dp++) = *(sp++);
  176761. *(dp++) = save;
  176762. }
  176763. }
  176764. else
  176765. {
  176766. png_bytep sp, dp;
  176767. png_uint_32 i;
  176768. png_uint_32 row_width = row_info->width;
  176769. for (i = 0, sp = dp = row; i < row_width; i++)
  176770. {
  176771. png_byte save[2];
  176772. save[0] = *(sp++);
  176773. save[1] = *(sp++);
  176774. *(dp++) = *(sp++);
  176775. *(dp++) = *(sp++);
  176776. *(dp++) = *(sp++);
  176777. *(dp++) = *(sp++);
  176778. *(dp++) = *(sp++);
  176779. *(dp++) = *(sp++);
  176780. *(dp++) = save[0];
  176781. *(dp++) = save[1];
  176782. }
  176783. }
  176784. }
  176785. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176786. {
  176787. if (row_info->bit_depth == 8)
  176788. {
  176789. png_bytep sp, dp;
  176790. png_uint_32 i;
  176791. png_uint_32 row_width = row_info->width;
  176792. for (i = 0, sp = dp = row; i < row_width; i++)
  176793. {
  176794. png_byte save = *(sp++);
  176795. *(dp++) = *(sp++);
  176796. *(dp++) = save;
  176797. }
  176798. }
  176799. else
  176800. {
  176801. png_bytep sp, dp;
  176802. png_uint_32 i;
  176803. png_uint_32 row_width = row_info->width;
  176804. for (i = 0, sp = dp = row; i < row_width; i++)
  176805. {
  176806. png_byte save[2];
  176807. save[0] = *(sp++);
  176808. save[1] = *(sp++);
  176809. *(dp++) = *(sp++);
  176810. *(dp++) = *(sp++);
  176811. *(dp++) = save[0];
  176812. *(dp++) = save[1];
  176813. }
  176814. }
  176815. }
  176816. }
  176817. }
  176818. #endif
  176819. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176820. void /* PRIVATE */
  176821. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  176822. {
  176823. png_debug(1, "in png_do_write_invert_alpha\n");
  176824. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176825. if (row != NULL && row_info != NULL)
  176826. #endif
  176827. {
  176828. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176829. {
  176830. if (row_info->bit_depth == 8)
  176831. {
  176832. png_bytep sp, dp;
  176833. png_uint_32 i;
  176834. png_uint_32 row_width = row_info->width;
  176835. for (i = 0, sp = dp = row; i < row_width; i++)
  176836. {
  176837. sp+=3; dp = sp;
  176838. *(dp++) = (png_byte)(255 - *(sp++));
  176839. }
  176840. }
  176841. else
  176842. {
  176843. png_bytep sp, dp;
  176844. png_uint_32 i;
  176845. png_uint_32 row_width = row_info->width;
  176846. for (i = 0, sp = dp = row; i < row_width; i++)
  176847. {
  176848. sp+=6; dp = sp;
  176849. *(dp++) = (png_byte)(255 - *(sp++));
  176850. *(dp++) = (png_byte)(255 - *(sp++));
  176851. }
  176852. }
  176853. }
  176854. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176855. {
  176856. if (row_info->bit_depth == 8)
  176857. {
  176858. png_bytep sp, dp;
  176859. png_uint_32 i;
  176860. png_uint_32 row_width = row_info->width;
  176861. for (i = 0, sp = dp = row; i < row_width; i++)
  176862. {
  176863. *(dp++) = *(sp++);
  176864. *(dp++) = (png_byte)(255 - *(sp++));
  176865. }
  176866. }
  176867. else
  176868. {
  176869. png_bytep sp, dp;
  176870. png_uint_32 i;
  176871. png_uint_32 row_width = row_info->width;
  176872. for (i = 0, sp = dp = row; i < row_width; i++)
  176873. {
  176874. sp+=2; dp = sp;
  176875. *(dp++) = (png_byte)(255 - *(sp++));
  176876. *(dp++) = (png_byte)(255 - *(sp++));
  176877. }
  176878. }
  176879. }
  176880. }
  176881. }
  176882. #endif
  176883. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176884. void /* PRIVATE */
  176885. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  176886. {
  176887. png_debug(1, "in png_do_write_intrapixel\n");
  176888. if (
  176889. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176890. row != NULL && row_info != NULL &&
  176891. #endif
  176892. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  176893. {
  176894. int bytes_per_pixel;
  176895. png_uint_32 row_width = row_info->width;
  176896. if (row_info->bit_depth == 8)
  176897. {
  176898. png_bytep rp;
  176899. png_uint_32 i;
  176900. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176901. bytes_per_pixel = 3;
  176902. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176903. bytes_per_pixel = 4;
  176904. else
  176905. return;
  176906. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176907. {
  176908. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  176909. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  176910. }
  176911. }
  176912. else if (row_info->bit_depth == 16)
  176913. {
  176914. png_bytep rp;
  176915. png_uint_32 i;
  176916. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176917. bytes_per_pixel = 6;
  176918. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176919. bytes_per_pixel = 8;
  176920. else
  176921. return;
  176922. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176923. {
  176924. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  176925. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  176926. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  176927. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  176928. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  176929. *(rp ) = (png_byte)((red >> 8) & 0xff);
  176930. *(rp+1) = (png_byte)(red & 0xff);
  176931. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  176932. *(rp+5) = (png_byte)(blue & 0xff);
  176933. }
  176934. }
  176935. }
  176936. }
  176937. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  176938. #endif /* PNG_WRITE_SUPPORTED */
  176939. /*** End of inlined file: pngwtran.c ***/
  176940. /*** Start of inlined file: pngwutil.c ***/
  176941. #define PNG_INTERNAL
  176942. #ifdef PNG_WRITE_SUPPORTED
  176943. void PNGAPI
  176944. png_save_uint_32(png_bytep buf, png_uint_32 i)
  176945. {
  176946. buf[0] = (png_byte)((i >> 24) & 0xff);
  176947. buf[1] = (png_byte)((i >> 16) & 0xff);
  176948. buf[2] = (png_byte)((i >> 8) & 0xff);
  176949. buf[3] = (png_byte)(i & 0xff);
  176950. }
  176951. void PNGAPI
  176952. png_save_int_32(png_bytep buf, png_int_32 i)
  176953. {
  176954. buf[0] = (png_byte)((i >> 24) & 0xff);
  176955. buf[1] = (png_byte)((i >> 16) & 0xff);
  176956. buf[2] = (png_byte)((i >> 8) & 0xff);
  176957. buf[3] = (png_byte)(i & 0xff);
  176958. }
  176959. void PNGAPI
  176960. png_save_uint_16(png_bytep buf, unsigned int i)
  176961. {
  176962. buf[0] = (png_byte)((i >> 8) & 0xff);
  176963. buf[1] = (png_byte)(i & 0xff);
  176964. }
  176965. void PNGAPI
  176966. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  176967. png_bytep data, png_size_t length)
  176968. {
  176969. if(png_ptr == NULL) return;
  176970. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  176971. png_write_chunk_data(png_ptr, data, length);
  176972. png_write_chunk_end(png_ptr);
  176973. }
  176974. void PNGAPI
  176975. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  176976. png_uint_32 length)
  176977. {
  176978. png_byte buf[4];
  176979. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  176980. if(png_ptr == NULL) return;
  176981. png_save_uint_32(buf, length);
  176982. png_write_data(png_ptr, buf, (png_size_t)4);
  176983. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  176984. png_reset_crc(png_ptr);
  176985. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  176986. }
  176987. void PNGAPI
  176988. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  176989. {
  176990. if(png_ptr == NULL) return;
  176991. if (data != NULL && length > 0)
  176992. {
  176993. png_calculate_crc(png_ptr, data, length);
  176994. png_write_data(png_ptr, data, length);
  176995. }
  176996. }
  176997. void PNGAPI
  176998. png_write_chunk_end(png_structp png_ptr)
  176999. {
  177000. png_byte buf[4];
  177001. if(png_ptr == NULL) return;
  177002. png_save_uint_32(buf, png_ptr->crc);
  177003. png_write_data(png_ptr, buf, (png_size_t)4);
  177004. }
  177005. void /* PRIVATE */
  177006. png_write_sig(png_structp png_ptr)
  177007. {
  177008. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  177009. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  177010. (png_size_t)8 - png_ptr->sig_bytes);
  177011. if(png_ptr->sig_bytes < 3)
  177012. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  177013. }
  177014. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  177015. typedef struct
  177016. {
  177017. char *input; /* the uncompressed input data */
  177018. int input_len; /* its length */
  177019. int num_output_ptr; /* number of output pointers used */
  177020. int max_output_ptr; /* size of output_ptr */
  177021. png_charpp output_ptr; /* array of pointers to output */
  177022. } compression_state;
  177023. static int /* PRIVATE */
  177024. png_text_compress(png_structp png_ptr,
  177025. png_charp text, png_size_t text_len, int compression,
  177026. compression_state *comp)
  177027. {
  177028. int ret;
  177029. comp->num_output_ptr = 0;
  177030. comp->max_output_ptr = 0;
  177031. comp->output_ptr = NULL;
  177032. comp->input = NULL;
  177033. comp->input_len = 0;
  177034. if (compression == PNG_TEXT_COMPRESSION_NONE)
  177035. {
  177036. comp->input = text;
  177037. comp->input_len = text_len;
  177038. return((int)text_len);
  177039. }
  177040. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  177041. {
  177042. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177043. char msg[50];
  177044. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  177045. png_warning(png_ptr, msg);
  177046. #else
  177047. png_warning(png_ptr, "Unknown compression type");
  177048. #endif
  177049. }
  177050. png_ptr->zstream.avail_in = (uInt)text_len;
  177051. png_ptr->zstream.next_in = (Bytef *)text;
  177052. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177053. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  177054. do
  177055. {
  177056. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  177057. if (ret != Z_OK)
  177058. {
  177059. if (png_ptr->zstream.msg != NULL)
  177060. png_error(png_ptr, png_ptr->zstream.msg);
  177061. else
  177062. png_error(png_ptr, "zlib error");
  177063. }
  177064. if (!(png_ptr->zstream.avail_out))
  177065. {
  177066. if (comp->num_output_ptr >= comp->max_output_ptr)
  177067. {
  177068. int old_max;
  177069. old_max = comp->max_output_ptr;
  177070. comp->max_output_ptr = comp->num_output_ptr + 4;
  177071. if (comp->output_ptr != NULL)
  177072. {
  177073. png_charpp old_ptr;
  177074. old_ptr = comp->output_ptr;
  177075. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177076. (png_uint_32)(comp->max_output_ptr *
  177077. png_sizeof (png_charpp)));
  177078. png_memcpy(comp->output_ptr, old_ptr, old_max
  177079. * png_sizeof (png_charp));
  177080. png_free(png_ptr, old_ptr);
  177081. }
  177082. else
  177083. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177084. (png_uint_32)(comp->max_output_ptr *
  177085. png_sizeof (png_charp)));
  177086. }
  177087. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  177088. (png_uint_32)png_ptr->zbuf_size);
  177089. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177090. png_ptr->zbuf_size);
  177091. comp->num_output_ptr++;
  177092. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177093. png_ptr->zstream.next_out = png_ptr->zbuf;
  177094. }
  177095. } while (png_ptr->zstream.avail_in);
  177096. do
  177097. {
  177098. ret = deflate(&png_ptr->zstream, Z_FINISH);
  177099. if (ret == Z_OK)
  177100. {
  177101. if (!(png_ptr->zstream.avail_out))
  177102. {
  177103. if (comp->num_output_ptr >= comp->max_output_ptr)
  177104. {
  177105. int old_max;
  177106. old_max = comp->max_output_ptr;
  177107. comp->max_output_ptr = comp->num_output_ptr + 4;
  177108. if (comp->output_ptr != NULL)
  177109. {
  177110. png_charpp old_ptr;
  177111. old_ptr = comp->output_ptr;
  177112. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177113. (png_uint_32)(comp->max_output_ptr *
  177114. png_sizeof (png_charpp)));
  177115. png_memcpy(comp->output_ptr, old_ptr,
  177116. old_max * png_sizeof (png_charp));
  177117. png_free(png_ptr, old_ptr);
  177118. }
  177119. else
  177120. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177121. (png_uint_32)(comp->max_output_ptr *
  177122. png_sizeof (png_charp)));
  177123. }
  177124. comp->output_ptr[comp->num_output_ptr] =
  177125. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  177126. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177127. png_ptr->zbuf_size);
  177128. comp->num_output_ptr++;
  177129. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177130. png_ptr->zstream.next_out = png_ptr->zbuf;
  177131. }
  177132. }
  177133. else if (ret != Z_STREAM_END)
  177134. {
  177135. if (png_ptr->zstream.msg != NULL)
  177136. png_error(png_ptr, png_ptr->zstream.msg);
  177137. else
  177138. png_error(png_ptr, "zlib error");
  177139. }
  177140. } while (ret != Z_STREAM_END);
  177141. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  177142. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  177143. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  177144. return((int)text_len);
  177145. }
  177146. static void /* PRIVATE */
  177147. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  177148. {
  177149. int i;
  177150. if (comp->input)
  177151. {
  177152. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  177153. (png_size_t)comp->input_len);
  177154. return;
  177155. }
  177156. for (i = 0; i < comp->num_output_ptr; i++)
  177157. {
  177158. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  177159. png_ptr->zbuf_size);
  177160. png_free(png_ptr, comp->output_ptr[i]);
  177161. comp->output_ptr[i]=NULL;
  177162. }
  177163. if (comp->max_output_ptr != 0)
  177164. png_free(png_ptr, comp->output_ptr);
  177165. comp->output_ptr=NULL;
  177166. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  177167. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  177168. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  177169. deflateReset(&png_ptr->zstream);
  177170. png_ptr->zstream.data_type = Z_BINARY;
  177171. }
  177172. #endif
  177173. void /* PRIVATE */
  177174. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  177175. int bit_depth, int color_type, int compression_type, int filter_type,
  177176. int interlace_type)
  177177. {
  177178. #ifdef PNG_USE_LOCAL_ARRAYS
  177179. PNG_IHDR;
  177180. #endif
  177181. png_byte buf[13]; /* buffer to store the IHDR info */
  177182. png_debug(1, "in png_write_IHDR\n");
  177183. switch (color_type)
  177184. {
  177185. case PNG_COLOR_TYPE_GRAY:
  177186. switch (bit_depth)
  177187. {
  177188. case 1:
  177189. case 2:
  177190. case 4:
  177191. case 8:
  177192. case 16: png_ptr->channels = 1; break;
  177193. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  177194. }
  177195. break;
  177196. case PNG_COLOR_TYPE_RGB:
  177197. if (bit_depth != 8 && bit_depth != 16)
  177198. png_error(png_ptr, "Invalid bit depth for RGB image");
  177199. png_ptr->channels = 3;
  177200. break;
  177201. case PNG_COLOR_TYPE_PALETTE:
  177202. switch (bit_depth)
  177203. {
  177204. case 1:
  177205. case 2:
  177206. case 4:
  177207. case 8: png_ptr->channels = 1; break;
  177208. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  177209. }
  177210. break;
  177211. case PNG_COLOR_TYPE_GRAY_ALPHA:
  177212. if (bit_depth != 8 && bit_depth != 16)
  177213. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  177214. png_ptr->channels = 2;
  177215. break;
  177216. case PNG_COLOR_TYPE_RGB_ALPHA:
  177217. if (bit_depth != 8 && bit_depth != 16)
  177218. png_error(png_ptr, "Invalid bit depth for RGBA image");
  177219. png_ptr->channels = 4;
  177220. break;
  177221. default:
  177222. png_error(png_ptr, "Invalid image color type specified");
  177223. }
  177224. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177225. {
  177226. png_warning(png_ptr, "Invalid compression type specified");
  177227. compression_type = PNG_COMPRESSION_TYPE_BASE;
  177228. }
  177229. if (
  177230. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177231. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  177232. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  177233. (color_type == PNG_COLOR_TYPE_RGB ||
  177234. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  177235. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  177236. #endif
  177237. filter_type != PNG_FILTER_TYPE_BASE)
  177238. {
  177239. png_warning(png_ptr, "Invalid filter type specified");
  177240. filter_type = PNG_FILTER_TYPE_BASE;
  177241. }
  177242. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177243. if (interlace_type != PNG_INTERLACE_NONE &&
  177244. interlace_type != PNG_INTERLACE_ADAM7)
  177245. {
  177246. png_warning(png_ptr, "Invalid interlace type specified");
  177247. interlace_type = PNG_INTERLACE_ADAM7;
  177248. }
  177249. #else
  177250. interlace_type=PNG_INTERLACE_NONE;
  177251. #endif
  177252. png_ptr->bit_depth = (png_byte)bit_depth;
  177253. png_ptr->color_type = (png_byte)color_type;
  177254. png_ptr->interlaced = (png_byte)interlace_type;
  177255. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177256. png_ptr->filter_type = (png_byte)filter_type;
  177257. #endif
  177258. png_ptr->compression_type = (png_byte)compression_type;
  177259. png_ptr->width = width;
  177260. png_ptr->height = height;
  177261. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  177262. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  177263. png_ptr->usr_width = png_ptr->width;
  177264. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  177265. png_ptr->usr_channels = png_ptr->channels;
  177266. png_save_uint_32(buf, width);
  177267. png_save_uint_32(buf + 4, height);
  177268. buf[8] = (png_byte)bit_depth;
  177269. buf[9] = (png_byte)color_type;
  177270. buf[10] = (png_byte)compression_type;
  177271. buf[11] = (png_byte)filter_type;
  177272. buf[12] = (png_byte)interlace_type;
  177273. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177274. png_ptr->zstream.zalloc = png_zalloc;
  177275. png_ptr->zstream.zfree = png_zfree;
  177276. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177277. if (!(png_ptr->do_filter))
  177278. {
  177279. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177280. png_ptr->bit_depth < 8)
  177281. png_ptr->do_filter = PNG_FILTER_NONE;
  177282. else
  177283. png_ptr->do_filter = PNG_ALL_FILTERS;
  177284. }
  177285. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177286. {
  177287. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177288. png_ptr->zlib_strategy = Z_FILTERED;
  177289. else
  177290. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177291. }
  177292. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177293. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177294. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177295. png_ptr->zlib_mem_level = 8;
  177296. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177297. png_ptr->zlib_window_bits = 15;
  177298. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177299. png_ptr->zlib_method = 8;
  177300. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177301. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177302. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177303. png_error(png_ptr, "zlib failed to initialize compressor");
  177304. png_ptr->zstream.next_out = png_ptr->zbuf;
  177305. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177306. png_ptr->zstream.data_type = Z_BINARY;
  177307. png_ptr->mode = PNG_HAVE_IHDR;
  177308. }
  177309. void /* PRIVATE */
  177310. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177311. {
  177312. #ifdef PNG_USE_LOCAL_ARRAYS
  177313. PNG_PLTE;
  177314. #endif
  177315. png_uint_32 i;
  177316. png_colorp pal_ptr;
  177317. png_byte buf[3];
  177318. png_debug(1, "in png_write_PLTE\n");
  177319. if ((
  177320. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177321. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177322. #endif
  177323. num_pal == 0) || num_pal > 256)
  177324. {
  177325. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177326. {
  177327. png_error(png_ptr, "Invalid number of colors in palette");
  177328. }
  177329. else
  177330. {
  177331. png_warning(png_ptr, "Invalid number of colors in palette");
  177332. return;
  177333. }
  177334. }
  177335. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177336. {
  177337. png_warning(png_ptr,
  177338. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177339. return;
  177340. }
  177341. png_ptr->num_palette = (png_uint_16)num_pal;
  177342. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177343. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177344. #ifndef PNG_NO_POINTER_INDEXING
  177345. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177346. {
  177347. buf[0] = pal_ptr->red;
  177348. buf[1] = pal_ptr->green;
  177349. buf[2] = pal_ptr->blue;
  177350. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177351. }
  177352. #else
  177353. pal_ptr=palette;
  177354. for (i = 0; i < num_pal; i++)
  177355. {
  177356. buf[0] = pal_ptr[i].red;
  177357. buf[1] = pal_ptr[i].green;
  177358. buf[2] = pal_ptr[i].blue;
  177359. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177360. }
  177361. #endif
  177362. png_write_chunk_end(png_ptr);
  177363. png_ptr->mode |= PNG_HAVE_PLTE;
  177364. }
  177365. void /* PRIVATE */
  177366. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177367. {
  177368. #ifdef PNG_USE_LOCAL_ARRAYS
  177369. PNG_IDAT;
  177370. #endif
  177371. png_debug(1, "in png_write_IDAT\n");
  177372. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177373. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177374. {
  177375. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177376. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177377. {
  177378. if (length >= 2 &&
  177379. png_ptr->height < 16384 && png_ptr->width < 16384)
  177380. {
  177381. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177382. ((png_ptr->width *
  177383. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177384. unsigned int z_cinfo = z_cmf >> 4;
  177385. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177386. while (uncompressed_idat_size <= half_z_window_size &&
  177387. half_z_window_size >= 256)
  177388. {
  177389. z_cinfo--;
  177390. half_z_window_size >>= 1;
  177391. }
  177392. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177393. if (data[0] != (png_byte)z_cmf)
  177394. {
  177395. data[0] = (png_byte)z_cmf;
  177396. data[1] &= 0xe0;
  177397. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177398. }
  177399. }
  177400. }
  177401. else
  177402. png_error(png_ptr,
  177403. "Invalid zlib compression method or flags in IDAT");
  177404. }
  177405. png_write_chunk(png_ptr, png_IDAT, data, length);
  177406. png_ptr->mode |= PNG_HAVE_IDAT;
  177407. }
  177408. void /* PRIVATE */
  177409. png_write_IEND(png_structp png_ptr)
  177410. {
  177411. #ifdef PNG_USE_LOCAL_ARRAYS
  177412. PNG_IEND;
  177413. #endif
  177414. png_debug(1, "in png_write_IEND\n");
  177415. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177416. (png_size_t)0);
  177417. png_ptr->mode |= PNG_HAVE_IEND;
  177418. }
  177419. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177420. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177421. void /* PRIVATE */
  177422. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177423. {
  177424. #ifdef PNG_USE_LOCAL_ARRAYS
  177425. PNG_gAMA;
  177426. #endif
  177427. png_uint_32 igamma;
  177428. png_byte buf[4];
  177429. png_debug(1, "in png_write_gAMA\n");
  177430. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177431. png_save_uint_32(buf, igamma);
  177432. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177433. }
  177434. #endif
  177435. #ifdef PNG_FIXED_POINT_SUPPORTED
  177436. void /* PRIVATE */
  177437. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177438. {
  177439. #ifdef PNG_USE_LOCAL_ARRAYS
  177440. PNG_gAMA;
  177441. #endif
  177442. png_byte buf[4];
  177443. png_debug(1, "in png_write_gAMA\n");
  177444. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177445. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177446. }
  177447. #endif
  177448. #endif
  177449. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177450. void /* PRIVATE */
  177451. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177452. {
  177453. #ifdef PNG_USE_LOCAL_ARRAYS
  177454. PNG_sRGB;
  177455. #endif
  177456. png_byte buf[1];
  177457. png_debug(1, "in png_write_sRGB\n");
  177458. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177459. png_warning(png_ptr,
  177460. "Invalid sRGB rendering intent specified");
  177461. buf[0]=(png_byte)srgb_intent;
  177462. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177463. }
  177464. #endif
  177465. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177466. void /* PRIVATE */
  177467. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177468. png_charp profile, int profile_len)
  177469. {
  177470. #ifdef PNG_USE_LOCAL_ARRAYS
  177471. PNG_iCCP;
  177472. #endif
  177473. png_size_t name_len;
  177474. png_charp new_name;
  177475. compression_state comp;
  177476. int embedded_profile_len = 0;
  177477. png_debug(1, "in png_write_iCCP\n");
  177478. comp.num_output_ptr = 0;
  177479. comp.max_output_ptr = 0;
  177480. comp.output_ptr = NULL;
  177481. comp.input = NULL;
  177482. comp.input_len = 0;
  177483. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177484. &new_name)) == 0)
  177485. {
  177486. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177487. return;
  177488. }
  177489. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177490. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177491. if (profile == NULL)
  177492. profile_len = 0;
  177493. if (profile_len > 3)
  177494. embedded_profile_len =
  177495. ((*( (png_bytep)profile ))<<24) |
  177496. ((*( (png_bytep)profile+1))<<16) |
  177497. ((*( (png_bytep)profile+2))<< 8) |
  177498. ((*( (png_bytep)profile+3)) );
  177499. if (profile_len < embedded_profile_len)
  177500. {
  177501. png_warning(png_ptr,
  177502. "Embedded profile length too large in iCCP chunk");
  177503. return;
  177504. }
  177505. if (profile_len > embedded_profile_len)
  177506. {
  177507. png_warning(png_ptr,
  177508. "Truncating profile to actual length in iCCP chunk");
  177509. profile_len = embedded_profile_len;
  177510. }
  177511. if (profile_len)
  177512. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177513. PNG_COMPRESSION_TYPE_BASE, &comp);
  177514. png_write_chunk_start(png_ptr, png_iCCP,
  177515. (png_uint_32)name_len+profile_len+2);
  177516. new_name[name_len+1]=0x00;
  177517. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177518. if (profile_len)
  177519. png_write_compressed_data_out(png_ptr, &comp);
  177520. png_write_chunk_end(png_ptr);
  177521. png_free(png_ptr, new_name);
  177522. }
  177523. #endif
  177524. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177525. void /* PRIVATE */
  177526. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177527. {
  177528. #ifdef PNG_USE_LOCAL_ARRAYS
  177529. PNG_sPLT;
  177530. #endif
  177531. png_size_t name_len;
  177532. png_charp new_name;
  177533. png_byte entrybuf[10];
  177534. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177535. int palette_size = entry_size * spalette->nentries;
  177536. png_sPLT_entryp ep;
  177537. #ifdef PNG_NO_POINTER_INDEXING
  177538. int i;
  177539. #endif
  177540. png_debug(1, "in png_write_sPLT\n");
  177541. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177542. spalette->name, &new_name))==0)
  177543. {
  177544. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177545. return;
  177546. }
  177547. png_write_chunk_start(png_ptr, png_sPLT,
  177548. (png_uint_32)(name_len + 2 + palette_size));
  177549. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177550. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177551. #ifndef PNG_NO_POINTER_INDEXING
  177552. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177553. {
  177554. if (spalette->depth == 8)
  177555. {
  177556. entrybuf[0] = (png_byte)ep->red;
  177557. entrybuf[1] = (png_byte)ep->green;
  177558. entrybuf[2] = (png_byte)ep->blue;
  177559. entrybuf[3] = (png_byte)ep->alpha;
  177560. png_save_uint_16(entrybuf + 4, ep->frequency);
  177561. }
  177562. else
  177563. {
  177564. png_save_uint_16(entrybuf + 0, ep->red);
  177565. png_save_uint_16(entrybuf + 2, ep->green);
  177566. png_save_uint_16(entrybuf + 4, ep->blue);
  177567. png_save_uint_16(entrybuf + 6, ep->alpha);
  177568. png_save_uint_16(entrybuf + 8, ep->frequency);
  177569. }
  177570. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177571. }
  177572. #else
  177573. ep=spalette->entries;
  177574. for (i=0; i>spalette->nentries; i++)
  177575. {
  177576. if (spalette->depth == 8)
  177577. {
  177578. entrybuf[0] = (png_byte)ep[i].red;
  177579. entrybuf[1] = (png_byte)ep[i].green;
  177580. entrybuf[2] = (png_byte)ep[i].blue;
  177581. entrybuf[3] = (png_byte)ep[i].alpha;
  177582. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177583. }
  177584. else
  177585. {
  177586. png_save_uint_16(entrybuf + 0, ep[i].red);
  177587. png_save_uint_16(entrybuf + 2, ep[i].green);
  177588. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177589. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177590. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177591. }
  177592. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177593. }
  177594. #endif
  177595. png_write_chunk_end(png_ptr);
  177596. png_free(png_ptr, new_name);
  177597. }
  177598. #endif
  177599. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177600. void /* PRIVATE */
  177601. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177602. {
  177603. #ifdef PNG_USE_LOCAL_ARRAYS
  177604. PNG_sBIT;
  177605. #endif
  177606. png_byte buf[4];
  177607. png_size_t size;
  177608. png_debug(1, "in png_write_sBIT\n");
  177609. if (color_type & PNG_COLOR_MASK_COLOR)
  177610. {
  177611. png_byte maxbits;
  177612. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177613. png_ptr->usr_bit_depth);
  177614. if (sbit->red == 0 || sbit->red > maxbits ||
  177615. sbit->green == 0 || sbit->green > maxbits ||
  177616. sbit->blue == 0 || sbit->blue > maxbits)
  177617. {
  177618. png_warning(png_ptr, "Invalid sBIT depth specified");
  177619. return;
  177620. }
  177621. buf[0] = sbit->red;
  177622. buf[1] = sbit->green;
  177623. buf[2] = sbit->blue;
  177624. size = 3;
  177625. }
  177626. else
  177627. {
  177628. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177629. {
  177630. png_warning(png_ptr, "Invalid sBIT depth specified");
  177631. return;
  177632. }
  177633. buf[0] = sbit->gray;
  177634. size = 1;
  177635. }
  177636. if (color_type & PNG_COLOR_MASK_ALPHA)
  177637. {
  177638. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177639. {
  177640. png_warning(png_ptr, "Invalid sBIT depth specified");
  177641. return;
  177642. }
  177643. buf[size++] = sbit->alpha;
  177644. }
  177645. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177646. }
  177647. #endif
  177648. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177649. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177650. void /* PRIVATE */
  177651. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177652. double red_x, double red_y, double green_x, double green_y,
  177653. double blue_x, double blue_y)
  177654. {
  177655. #ifdef PNG_USE_LOCAL_ARRAYS
  177656. PNG_cHRM;
  177657. #endif
  177658. png_byte buf[32];
  177659. png_uint_32 itemp;
  177660. png_debug(1, "in png_write_cHRM\n");
  177661. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177662. white_x + white_y > 1.0)
  177663. {
  177664. png_warning(png_ptr, "Invalid cHRM white point specified");
  177665. #if !defined(PNG_NO_CONSOLE_IO)
  177666. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177667. #endif
  177668. return;
  177669. }
  177670. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  177671. png_save_uint_32(buf, itemp);
  177672. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  177673. png_save_uint_32(buf + 4, itemp);
  177674. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  177675. {
  177676. png_warning(png_ptr, "Invalid cHRM red point specified");
  177677. return;
  177678. }
  177679. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  177680. png_save_uint_32(buf + 8, itemp);
  177681. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  177682. png_save_uint_32(buf + 12, itemp);
  177683. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  177684. {
  177685. png_warning(png_ptr, "Invalid cHRM green point specified");
  177686. return;
  177687. }
  177688. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  177689. png_save_uint_32(buf + 16, itemp);
  177690. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  177691. png_save_uint_32(buf + 20, itemp);
  177692. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  177693. {
  177694. png_warning(png_ptr, "Invalid cHRM blue point specified");
  177695. return;
  177696. }
  177697. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  177698. png_save_uint_32(buf + 24, itemp);
  177699. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  177700. png_save_uint_32(buf + 28, itemp);
  177701. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177702. }
  177703. #endif
  177704. #ifdef PNG_FIXED_POINT_SUPPORTED
  177705. void /* PRIVATE */
  177706. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  177707. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  177708. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  177709. png_fixed_point blue_y)
  177710. {
  177711. #ifdef PNG_USE_LOCAL_ARRAYS
  177712. PNG_cHRM;
  177713. #endif
  177714. png_byte buf[32];
  177715. png_debug(1, "in png_write_cHRM\n");
  177716. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  177717. {
  177718. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  177719. #if !defined(PNG_NO_CONSOLE_IO)
  177720. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  177721. #endif
  177722. return;
  177723. }
  177724. png_save_uint_32(buf, (png_uint_32)white_x);
  177725. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  177726. if (red_x + red_y > 100000L)
  177727. {
  177728. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  177729. return;
  177730. }
  177731. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  177732. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  177733. if (green_x + green_y > 100000L)
  177734. {
  177735. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  177736. return;
  177737. }
  177738. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  177739. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  177740. if (blue_x + blue_y > 100000L)
  177741. {
  177742. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  177743. return;
  177744. }
  177745. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  177746. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  177747. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177748. }
  177749. #endif
  177750. #endif
  177751. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  177752. void /* PRIVATE */
  177753. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  177754. int num_trans, int color_type)
  177755. {
  177756. #ifdef PNG_USE_LOCAL_ARRAYS
  177757. PNG_tRNS;
  177758. #endif
  177759. png_byte buf[6];
  177760. png_debug(1, "in png_write_tRNS\n");
  177761. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177762. {
  177763. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  177764. {
  177765. png_warning(png_ptr,"Invalid number of transparent colors specified");
  177766. return;
  177767. }
  177768. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  177769. }
  177770. else if (color_type == PNG_COLOR_TYPE_GRAY)
  177771. {
  177772. if(tran->gray >= (1 << png_ptr->bit_depth))
  177773. {
  177774. png_warning(png_ptr,
  177775. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  177776. return;
  177777. }
  177778. png_save_uint_16(buf, tran->gray);
  177779. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  177780. }
  177781. else if (color_type == PNG_COLOR_TYPE_RGB)
  177782. {
  177783. png_save_uint_16(buf, tran->red);
  177784. png_save_uint_16(buf + 2, tran->green);
  177785. png_save_uint_16(buf + 4, tran->blue);
  177786. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177787. {
  177788. png_warning(png_ptr,
  177789. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  177790. return;
  177791. }
  177792. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  177793. }
  177794. else
  177795. {
  177796. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  177797. }
  177798. }
  177799. #endif
  177800. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  177801. void /* PRIVATE */
  177802. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  177803. {
  177804. #ifdef PNG_USE_LOCAL_ARRAYS
  177805. PNG_bKGD;
  177806. #endif
  177807. png_byte buf[6];
  177808. png_debug(1, "in png_write_bKGD\n");
  177809. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177810. {
  177811. if (
  177812. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177813. (png_ptr->num_palette ||
  177814. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  177815. #endif
  177816. back->index > png_ptr->num_palette)
  177817. {
  177818. png_warning(png_ptr, "Invalid background palette index");
  177819. return;
  177820. }
  177821. buf[0] = back->index;
  177822. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  177823. }
  177824. else if (color_type & PNG_COLOR_MASK_COLOR)
  177825. {
  177826. png_save_uint_16(buf, back->red);
  177827. png_save_uint_16(buf + 2, back->green);
  177828. png_save_uint_16(buf + 4, back->blue);
  177829. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177830. {
  177831. png_warning(png_ptr,
  177832. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  177833. return;
  177834. }
  177835. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  177836. }
  177837. else
  177838. {
  177839. if(back->gray >= (1 << png_ptr->bit_depth))
  177840. {
  177841. png_warning(png_ptr,
  177842. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  177843. return;
  177844. }
  177845. png_save_uint_16(buf, back->gray);
  177846. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  177847. }
  177848. }
  177849. #endif
  177850. #if defined(PNG_WRITE_hIST_SUPPORTED)
  177851. void /* PRIVATE */
  177852. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  177853. {
  177854. #ifdef PNG_USE_LOCAL_ARRAYS
  177855. PNG_hIST;
  177856. #endif
  177857. int i;
  177858. png_byte buf[3];
  177859. png_debug(1, "in png_write_hIST\n");
  177860. if (num_hist > (int)png_ptr->num_palette)
  177861. {
  177862. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  177863. png_ptr->num_palette);
  177864. png_warning(png_ptr, "Invalid number of histogram entries specified");
  177865. return;
  177866. }
  177867. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  177868. for (i = 0; i < num_hist; i++)
  177869. {
  177870. png_save_uint_16(buf, hist[i]);
  177871. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  177872. }
  177873. png_write_chunk_end(png_ptr);
  177874. }
  177875. #endif
  177876. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  177877. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  177878. png_size_t /* PRIVATE */
  177879. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  177880. {
  177881. png_size_t key_len;
  177882. png_charp kp, dp;
  177883. int kflag;
  177884. int kwarn=0;
  177885. png_debug(1, "in png_check_keyword\n");
  177886. *new_key = NULL;
  177887. if (key == NULL || (key_len = png_strlen(key)) == 0)
  177888. {
  177889. png_warning(png_ptr, "zero length keyword");
  177890. return ((png_size_t)0);
  177891. }
  177892. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  177893. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  177894. if (*new_key == NULL)
  177895. {
  177896. png_warning(png_ptr, "Out of memory while procesing keyword");
  177897. return ((png_size_t)0);
  177898. }
  177899. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  177900. {
  177901. if ((png_byte)*kp < 0x20 ||
  177902. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  177903. {
  177904. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177905. char msg[40];
  177906. png_snprintf(msg, 40,
  177907. "invalid keyword character 0x%02X", (png_byte)*kp);
  177908. png_warning(png_ptr, msg);
  177909. #else
  177910. png_warning(png_ptr, "invalid character in keyword");
  177911. #endif
  177912. *dp = ' ';
  177913. }
  177914. else
  177915. {
  177916. *dp = *kp;
  177917. }
  177918. }
  177919. *dp = '\0';
  177920. kp = *new_key + key_len - 1;
  177921. if (*kp == ' ')
  177922. {
  177923. png_warning(png_ptr, "trailing spaces removed from keyword");
  177924. while (*kp == ' ')
  177925. {
  177926. *(kp--) = '\0';
  177927. key_len--;
  177928. }
  177929. }
  177930. kp = *new_key;
  177931. if (*kp == ' ')
  177932. {
  177933. png_warning(png_ptr, "leading spaces removed from keyword");
  177934. while (*kp == ' ')
  177935. {
  177936. kp++;
  177937. key_len--;
  177938. }
  177939. }
  177940. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  177941. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  177942. {
  177943. if (*kp == ' ' && kflag == 0)
  177944. {
  177945. *(dp++) = *kp;
  177946. kflag = 1;
  177947. }
  177948. else if (*kp == ' ')
  177949. {
  177950. key_len--;
  177951. kwarn=1;
  177952. }
  177953. else
  177954. {
  177955. *(dp++) = *kp;
  177956. kflag = 0;
  177957. }
  177958. }
  177959. *dp = '\0';
  177960. if(kwarn)
  177961. png_warning(png_ptr, "extra interior spaces removed from keyword");
  177962. if (key_len == 0)
  177963. {
  177964. png_free(png_ptr, *new_key);
  177965. *new_key=NULL;
  177966. png_warning(png_ptr, "Zero length keyword");
  177967. }
  177968. if (key_len > 79)
  177969. {
  177970. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  177971. new_key[79] = '\0';
  177972. key_len = 79;
  177973. }
  177974. return (key_len);
  177975. }
  177976. #endif
  177977. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  177978. void /* PRIVATE */
  177979. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  177980. png_size_t text_len)
  177981. {
  177982. #ifdef PNG_USE_LOCAL_ARRAYS
  177983. PNG_tEXt;
  177984. #endif
  177985. png_size_t key_len;
  177986. png_charp new_key;
  177987. png_debug(1, "in png_write_tEXt\n");
  177988. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177989. {
  177990. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  177991. return;
  177992. }
  177993. if (text == NULL || *text == '\0')
  177994. text_len = 0;
  177995. else
  177996. text_len = png_strlen(text);
  177997. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  177998. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177999. if (text_len)
  178000. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  178001. png_write_chunk_end(png_ptr);
  178002. png_free(png_ptr, new_key);
  178003. }
  178004. #endif
  178005. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  178006. void /* PRIVATE */
  178007. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  178008. png_size_t text_len, int compression)
  178009. {
  178010. #ifdef PNG_USE_LOCAL_ARRAYS
  178011. PNG_zTXt;
  178012. #endif
  178013. png_size_t key_len;
  178014. char buf[1];
  178015. png_charp new_key;
  178016. compression_state comp;
  178017. png_debug(1, "in png_write_zTXt\n");
  178018. comp.num_output_ptr = 0;
  178019. comp.max_output_ptr = 0;
  178020. comp.output_ptr = NULL;
  178021. comp.input = NULL;
  178022. comp.input_len = 0;
  178023. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178024. {
  178025. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  178026. return;
  178027. }
  178028. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  178029. {
  178030. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  178031. png_free(png_ptr, new_key);
  178032. return;
  178033. }
  178034. text_len = png_strlen(text);
  178035. text_len = png_text_compress(png_ptr, text, text_len, compression,
  178036. &comp);
  178037. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  178038. (key_len+text_len+2));
  178039. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178040. png_free(png_ptr, new_key);
  178041. buf[0] = (png_byte)compression;
  178042. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  178043. png_write_compressed_data_out(png_ptr, &comp);
  178044. png_write_chunk_end(png_ptr);
  178045. }
  178046. #endif
  178047. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  178048. void /* PRIVATE */
  178049. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  178050. png_charp lang, png_charp lang_key, png_charp text)
  178051. {
  178052. #ifdef PNG_USE_LOCAL_ARRAYS
  178053. PNG_iTXt;
  178054. #endif
  178055. png_size_t lang_len, key_len, lang_key_len, text_len;
  178056. png_charp new_lang, new_key;
  178057. png_byte cbuf[2];
  178058. compression_state comp;
  178059. png_debug(1, "in png_write_iTXt\n");
  178060. comp.num_output_ptr = 0;
  178061. comp.max_output_ptr = 0;
  178062. comp.output_ptr = NULL;
  178063. comp.input = NULL;
  178064. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178065. {
  178066. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  178067. return;
  178068. }
  178069. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  178070. {
  178071. png_warning(png_ptr, "Empty language field in iTXt chunk");
  178072. new_lang = NULL;
  178073. lang_len = 0;
  178074. }
  178075. if (lang_key == NULL)
  178076. lang_key_len = 0;
  178077. else
  178078. lang_key_len = png_strlen(lang_key);
  178079. if (text == NULL)
  178080. text_len = 0;
  178081. else
  178082. text_len = png_strlen(text);
  178083. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  178084. &comp);
  178085. png_write_chunk_start(png_ptr, png_iTXt,
  178086. (png_uint_32)(
  178087. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  178088. + key_len
  178089. + lang_len
  178090. + lang_key_len
  178091. + text_len));
  178092. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178093. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  178094. compression == PNG_TEXT_COMPRESSION_NONE)
  178095. cbuf[0] = 0;
  178096. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  178097. cbuf[0] = 1;
  178098. cbuf[1] = 0;
  178099. png_write_chunk_data(png_ptr, cbuf, 2);
  178100. cbuf[0] = 0;
  178101. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  178102. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  178103. png_write_compressed_data_out(png_ptr, &comp);
  178104. png_write_chunk_end(png_ptr);
  178105. png_free(png_ptr, new_key);
  178106. if (new_lang)
  178107. png_free(png_ptr, new_lang);
  178108. }
  178109. #endif
  178110. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  178111. void /* PRIVATE */
  178112. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  178113. int unit_type)
  178114. {
  178115. #ifdef PNG_USE_LOCAL_ARRAYS
  178116. PNG_oFFs;
  178117. #endif
  178118. png_byte buf[9];
  178119. png_debug(1, "in png_write_oFFs\n");
  178120. if (unit_type >= PNG_OFFSET_LAST)
  178121. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  178122. png_save_int_32(buf, x_offset);
  178123. png_save_int_32(buf + 4, y_offset);
  178124. buf[8] = (png_byte)unit_type;
  178125. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  178126. }
  178127. #endif
  178128. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  178129. void /* PRIVATE */
  178130. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  178131. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  178132. {
  178133. #ifdef PNG_USE_LOCAL_ARRAYS
  178134. PNG_pCAL;
  178135. #endif
  178136. png_size_t purpose_len, units_len, total_len;
  178137. png_uint_32p params_len;
  178138. png_byte buf[10];
  178139. png_charp new_purpose;
  178140. int i;
  178141. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  178142. if (type >= PNG_EQUATION_LAST)
  178143. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  178144. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  178145. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  178146. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  178147. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  178148. total_len = purpose_len + units_len + 10;
  178149. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  178150. *png_sizeof(png_uint_32)));
  178151. for (i = 0; i < nparams; i++)
  178152. {
  178153. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  178154. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  178155. total_len += (png_size_t)params_len[i];
  178156. }
  178157. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  178158. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  178159. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  178160. png_save_int_32(buf, X0);
  178161. png_save_int_32(buf + 4, X1);
  178162. buf[8] = (png_byte)type;
  178163. buf[9] = (png_byte)nparams;
  178164. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  178165. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  178166. png_free(png_ptr, new_purpose);
  178167. for (i = 0; i < nparams; i++)
  178168. {
  178169. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  178170. (png_size_t)params_len[i]);
  178171. }
  178172. png_free(png_ptr, params_len);
  178173. png_write_chunk_end(png_ptr);
  178174. }
  178175. #endif
  178176. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  178177. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  178178. void /* PRIVATE */
  178179. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  178180. {
  178181. #ifdef PNG_USE_LOCAL_ARRAYS
  178182. PNG_sCAL;
  178183. #endif
  178184. char buf[64];
  178185. png_size_t total_len;
  178186. png_debug(1, "in png_write_sCAL\n");
  178187. buf[0] = (char)unit;
  178188. #if defined(_WIN32_WCE)
  178189. {
  178190. wchar_t wc_buf[32];
  178191. size_t wc_len;
  178192. swprintf(wc_buf, TEXT("%12.12e"), width);
  178193. wc_len = wcslen(wc_buf);
  178194. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  178195. total_len = wc_len + 2;
  178196. swprintf(wc_buf, TEXT("%12.12e"), height);
  178197. wc_len = wcslen(wc_buf);
  178198. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  178199. NULL, NULL);
  178200. total_len += wc_len;
  178201. }
  178202. #else
  178203. png_snprintf(buf + 1, 63, "%12.12e", width);
  178204. total_len = 1 + png_strlen(buf + 1) + 1;
  178205. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  178206. total_len += png_strlen(buf + total_len);
  178207. #endif
  178208. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178209. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  178210. }
  178211. #else
  178212. #ifdef PNG_FIXED_POINT_SUPPORTED
  178213. void /* PRIVATE */
  178214. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  178215. png_charp height)
  178216. {
  178217. #ifdef PNG_USE_LOCAL_ARRAYS
  178218. PNG_sCAL;
  178219. #endif
  178220. png_byte buf[64];
  178221. png_size_t wlen, hlen, total_len;
  178222. png_debug(1, "in png_write_sCAL_s\n");
  178223. wlen = png_strlen(width);
  178224. hlen = png_strlen(height);
  178225. total_len = wlen + hlen + 2;
  178226. if (total_len > 64)
  178227. {
  178228. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  178229. return;
  178230. }
  178231. buf[0] = (png_byte)unit;
  178232. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  178233. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  178234. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178235. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  178236. }
  178237. #endif
  178238. #endif
  178239. #endif
  178240. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  178241. void /* PRIVATE */
  178242. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  178243. png_uint_32 y_pixels_per_unit,
  178244. int unit_type)
  178245. {
  178246. #ifdef PNG_USE_LOCAL_ARRAYS
  178247. PNG_pHYs;
  178248. #endif
  178249. png_byte buf[9];
  178250. png_debug(1, "in png_write_pHYs\n");
  178251. if (unit_type >= PNG_RESOLUTION_LAST)
  178252. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  178253. png_save_uint_32(buf, x_pixels_per_unit);
  178254. png_save_uint_32(buf + 4, y_pixels_per_unit);
  178255. buf[8] = (png_byte)unit_type;
  178256. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  178257. }
  178258. #endif
  178259. #if defined(PNG_WRITE_tIME_SUPPORTED)
  178260. void /* PRIVATE */
  178261. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  178262. {
  178263. #ifdef PNG_USE_LOCAL_ARRAYS
  178264. PNG_tIME;
  178265. #endif
  178266. png_byte buf[7];
  178267. png_debug(1, "in png_write_tIME\n");
  178268. if (mod_time->month > 12 || mod_time->month < 1 ||
  178269. mod_time->day > 31 || mod_time->day < 1 ||
  178270. mod_time->hour > 23 || mod_time->second > 60)
  178271. {
  178272. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178273. return;
  178274. }
  178275. png_save_uint_16(buf, mod_time->year);
  178276. buf[2] = mod_time->month;
  178277. buf[3] = mod_time->day;
  178278. buf[4] = mod_time->hour;
  178279. buf[5] = mod_time->minute;
  178280. buf[6] = mod_time->second;
  178281. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178282. }
  178283. #endif
  178284. void /* PRIVATE */
  178285. png_write_start_row(png_structp png_ptr)
  178286. {
  178287. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178288. #ifdef PNG_USE_LOCAL_ARRAYS
  178289. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178290. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178291. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178292. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178293. #endif
  178294. #endif
  178295. png_size_t buf_size;
  178296. png_debug(1, "in png_write_start_row\n");
  178297. buf_size = (png_size_t)(PNG_ROWBYTES(
  178298. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178299. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178300. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178301. #ifndef PNG_NO_WRITE_FILTERING
  178302. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178303. {
  178304. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178305. (png_ptr->rowbytes + 1));
  178306. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178307. }
  178308. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178309. {
  178310. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178311. png_memset(png_ptr->prev_row, 0, buf_size);
  178312. if (png_ptr->do_filter & PNG_FILTER_UP)
  178313. {
  178314. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178315. (png_ptr->rowbytes + 1));
  178316. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178317. }
  178318. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178319. {
  178320. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178321. (png_ptr->rowbytes + 1));
  178322. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178323. }
  178324. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178325. {
  178326. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178327. (png_ptr->rowbytes + 1));
  178328. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178329. }
  178330. #endif /* PNG_NO_WRITE_FILTERING */
  178331. }
  178332. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178333. if (png_ptr->interlaced)
  178334. {
  178335. if (!(png_ptr->transformations & PNG_INTERLACE))
  178336. {
  178337. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178338. png_pass_ystart[0]) / png_pass_yinc[0];
  178339. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178340. png_pass_start[0]) / png_pass_inc[0];
  178341. }
  178342. else
  178343. {
  178344. png_ptr->num_rows = png_ptr->height;
  178345. png_ptr->usr_width = png_ptr->width;
  178346. }
  178347. }
  178348. else
  178349. #endif
  178350. {
  178351. png_ptr->num_rows = png_ptr->height;
  178352. png_ptr->usr_width = png_ptr->width;
  178353. }
  178354. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178355. png_ptr->zstream.next_out = png_ptr->zbuf;
  178356. }
  178357. void /* PRIVATE */
  178358. png_write_finish_row(png_structp png_ptr)
  178359. {
  178360. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178361. #ifdef PNG_USE_LOCAL_ARRAYS
  178362. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178363. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178364. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178365. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178366. #endif
  178367. #endif
  178368. int ret;
  178369. png_debug(1, "in png_write_finish_row\n");
  178370. png_ptr->row_number++;
  178371. if (png_ptr->row_number < png_ptr->num_rows)
  178372. return;
  178373. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178374. if (png_ptr->interlaced)
  178375. {
  178376. png_ptr->row_number = 0;
  178377. if (png_ptr->transformations & PNG_INTERLACE)
  178378. {
  178379. png_ptr->pass++;
  178380. }
  178381. else
  178382. {
  178383. do
  178384. {
  178385. png_ptr->pass++;
  178386. if (png_ptr->pass >= 7)
  178387. break;
  178388. png_ptr->usr_width = (png_ptr->width +
  178389. png_pass_inc[png_ptr->pass] - 1 -
  178390. png_pass_start[png_ptr->pass]) /
  178391. png_pass_inc[png_ptr->pass];
  178392. png_ptr->num_rows = (png_ptr->height +
  178393. png_pass_yinc[png_ptr->pass] - 1 -
  178394. png_pass_ystart[png_ptr->pass]) /
  178395. png_pass_yinc[png_ptr->pass];
  178396. if (png_ptr->transformations & PNG_INTERLACE)
  178397. break;
  178398. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178399. }
  178400. if (png_ptr->pass < 7)
  178401. {
  178402. if (png_ptr->prev_row != NULL)
  178403. png_memset(png_ptr->prev_row, 0,
  178404. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178405. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178406. return;
  178407. }
  178408. }
  178409. #endif
  178410. do
  178411. {
  178412. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178413. if (ret == Z_OK)
  178414. {
  178415. if (!(png_ptr->zstream.avail_out))
  178416. {
  178417. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178418. png_ptr->zstream.next_out = png_ptr->zbuf;
  178419. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178420. }
  178421. }
  178422. else if (ret != Z_STREAM_END)
  178423. {
  178424. if (png_ptr->zstream.msg != NULL)
  178425. png_error(png_ptr, png_ptr->zstream.msg);
  178426. else
  178427. png_error(png_ptr, "zlib error");
  178428. }
  178429. } while (ret != Z_STREAM_END);
  178430. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178431. {
  178432. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178433. png_ptr->zstream.avail_out);
  178434. }
  178435. deflateReset(&png_ptr->zstream);
  178436. png_ptr->zstream.data_type = Z_BINARY;
  178437. }
  178438. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178439. void /* PRIVATE */
  178440. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178441. {
  178442. #ifdef PNG_USE_LOCAL_ARRAYS
  178443. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178444. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178445. #endif
  178446. png_debug(1, "in png_do_write_interlace\n");
  178447. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178448. if (row != NULL && row_info != NULL && pass < 6)
  178449. #else
  178450. if (pass < 6)
  178451. #endif
  178452. {
  178453. switch (row_info->pixel_depth)
  178454. {
  178455. case 1:
  178456. {
  178457. png_bytep sp;
  178458. png_bytep dp;
  178459. int shift;
  178460. int d;
  178461. int value;
  178462. png_uint_32 i;
  178463. png_uint_32 row_width = row_info->width;
  178464. dp = row;
  178465. d = 0;
  178466. shift = 7;
  178467. for (i = png_pass_start[pass]; i < row_width;
  178468. i += png_pass_inc[pass])
  178469. {
  178470. sp = row + (png_size_t)(i >> 3);
  178471. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178472. d |= (value << shift);
  178473. if (shift == 0)
  178474. {
  178475. shift = 7;
  178476. *dp++ = (png_byte)d;
  178477. d = 0;
  178478. }
  178479. else
  178480. shift--;
  178481. }
  178482. if (shift != 7)
  178483. *dp = (png_byte)d;
  178484. break;
  178485. }
  178486. case 2:
  178487. {
  178488. png_bytep sp;
  178489. png_bytep dp;
  178490. int shift;
  178491. int d;
  178492. int value;
  178493. png_uint_32 i;
  178494. png_uint_32 row_width = row_info->width;
  178495. dp = row;
  178496. shift = 6;
  178497. d = 0;
  178498. for (i = png_pass_start[pass]; i < row_width;
  178499. i += png_pass_inc[pass])
  178500. {
  178501. sp = row + (png_size_t)(i >> 2);
  178502. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178503. d |= (value << shift);
  178504. if (shift == 0)
  178505. {
  178506. shift = 6;
  178507. *dp++ = (png_byte)d;
  178508. d = 0;
  178509. }
  178510. else
  178511. shift -= 2;
  178512. }
  178513. if (shift != 6)
  178514. *dp = (png_byte)d;
  178515. break;
  178516. }
  178517. case 4:
  178518. {
  178519. png_bytep sp;
  178520. png_bytep dp;
  178521. int shift;
  178522. int d;
  178523. int value;
  178524. png_uint_32 i;
  178525. png_uint_32 row_width = row_info->width;
  178526. dp = row;
  178527. shift = 4;
  178528. d = 0;
  178529. for (i = png_pass_start[pass]; i < row_width;
  178530. i += png_pass_inc[pass])
  178531. {
  178532. sp = row + (png_size_t)(i >> 1);
  178533. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178534. d |= (value << shift);
  178535. if (shift == 0)
  178536. {
  178537. shift = 4;
  178538. *dp++ = (png_byte)d;
  178539. d = 0;
  178540. }
  178541. else
  178542. shift -= 4;
  178543. }
  178544. if (shift != 4)
  178545. *dp = (png_byte)d;
  178546. break;
  178547. }
  178548. default:
  178549. {
  178550. png_bytep sp;
  178551. png_bytep dp;
  178552. png_uint_32 i;
  178553. png_uint_32 row_width = row_info->width;
  178554. png_size_t pixel_bytes;
  178555. dp = row;
  178556. pixel_bytes = (row_info->pixel_depth >> 3);
  178557. for (i = png_pass_start[pass]; i < row_width;
  178558. i += png_pass_inc[pass])
  178559. {
  178560. sp = row + (png_size_t)i * pixel_bytes;
  178561. if (dp != sp)
  178562. png_memcpy(dp, sp, pixel_bytes);
  178563. dp += pixel_bytes;
  178564. }
  178565. break;
  178566. }
  178567. }
  178568. row_info->width = (row_info->width +
  178569. png_pass_inc[pass] - 1 -
  178570. png_pass_start[pass]) /
  178571. png_pass_inc[pass];
  178572. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178573. row_info->width);
  178574. }
  178575. }
  178576. #endif
  178577. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178578. #define PNG_HISHIFT 10
  178579. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178580. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178581. void /* PRIVATE */
  178582. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178583. {
  178584. png_bytep best_row;
  178585. #ifndef PNG_NO_WRITE_FILTER
  178586. png_bytep prev_row, row_buf;
  178587. png_uint_32 mins, bpp;
  178588. png_byte filter_to_do = png_ptr->do_filter;
  178589. png_uint_32 row_bytes = row_info->rowbytes;
  178590. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178591. int num_p_filters = (int)png_ptr->num_prev_filters;
  178592. #endif
  178593. png_debug(1, "in png_write_find_filter\n");
  178594. bpp = (row_info->pixel_depth + 7) >> 3;
  178595. prev_row = png_ptr->prev_row;
  178596. #endif
  178597. best_row = png_ptr->row_buf;
  178598. #ifndef PNG_NO_WRITE_FILTER
  178599. row_buf = best_row;
  178600. mins = PNG_MAXSUM;
  178601. if ((filter_to_do & PNG_FILTER_NONE) &&
  178602. filter_to_do != PNG_FILTER_NONE)
  178603. {
  178604. png_bytep rp;
  178605. png_uint_32 sum = 0;
  178606. png_uint_32 i;
  178607. int v;
  178608. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178609. {
  178610. v = *rp;
  178611. sum += (v < 128) ? v : 256 - v;
  178612. }
  178613. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178614. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178615. {
  178616. png_uint_32 sumhi, sumlo;
  178617. int j;
  178618. sumlo = sum & PNG_LOMASK;
  178619. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178620. for (j = 0; j < num_p_filters; j++)
  178621. {
  178622. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178623. {
  178624. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178625. PNG_WEIGHT_SHIFT;
  178626. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178627. PNG_WEIGHT_SHIFT;
  178628. }
  178629. }
  178630. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178631. PNG_COST_SHIFT;
  178632. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178633. PNG_COST_SHIFT;
  178634. if (sumhi > PNG_HIMASK)
  178635. sum = PNG_MAXSUM;
  178636. else
  178637. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178638. }
  178639. #endif
  178640. mins = sum;
  178641. }
  178642. if (filter_to_do == PNG_FILTER_SUB)
  178643. {
  178644. png_bytep rp, lp, dp;
  178645. png_uint_32 i;
  178646. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178647. i++, rp++, dp++)
  178648. {
  178649. *dp = *rp;
  178650. }
  178651. for (lp = row_buf + 1; i < row_bytes;
  178652. i++, rp++, lp++, dp++)
  178653. {
  178654. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178655. }
  178656. best_row = png_ptr->sub_row;
  178657. }
  178658. else if (filter_to_do & PNG_FILTER_SUB)
  178659. {
  178660. png_bytep rp, dp, lp;
  178661. png_uint_32 sum = 0, lmins = mins;
  178662. png_uint_32 i;
  178663. int v;
  178664. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178665. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178666. {
  178667. int j;
  178668. png_uint_32 lmhi, lmlo;
  178669. lmlo = lmins & PNG_LOMASK;
  178670. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178671. for (j = 0; j < num_p_filters; j++)
  178672. {
  178673. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178674. {
  178675. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178676. PNG_WEIGHT_SHIFT;
  178677. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178678. PNG_WEIGHT_SHIFT;
  178679. }
  178680. }
  178681. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178682. PNG_COST_SHIFT;
  178683. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178684. PNG_COST_SHIFT;
  178685. if (lmhi > PNG_HIMASK)
  178686. lmins = PNG_MAXSUM;
  178687. else
  178688. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178689. }
  178690. #endif
  178691. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178692. i++, rp++, dp++)
  178693. {
  178694. v = *dp = *rp;
  178695. sum += (v < 128) ? v : 256 - v;
  178696. }
  178697. for (lp = row_buf + 1; i < row_bytes;
  178698. i++, rp++, lp++, dp++)
  178699. {
  178700. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178701. sum += (v < 128) ? v : 256 - v;
  178702. if (sum > lmins) /* We are already worse, don't continue. */
  178703. break;
  178704. }
  178705. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178706. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178707. {
  178708. int j;
  178709. png_uint_32 sumhi, sumlo;
  178710. sumlo = sum & PNG_LOMASK;
  178711. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178712. for (j = 0; j < num_p_filters; j++)
  178713. {
  178714. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178715. {
  178716. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  178717. PNG_WEIGHT_SHIFT;
  178718. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  178719. PNG_WEIGHT_SHIFT;
  178720. }
  178721. }
  178722. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178723. PNG_COST_SHIFT;
  178724. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178725. PNG_COST_SHIFT;
  178726. if (sumhi > PNG_HIMASK)
  178727. sum = PNG_MAXSUM;
  178728. else
  178729. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178730. }
  178731. #endif
  178732. if (sum < mins)
  178733. {
  178734. mins = sum;
  178735. best_row = png_ptr->sub_row;
  178736. }
  178737. }
  178738. if (filter_to_do == PNG_FILTER_UP)
  178739. {
  178740. png_bytep rp, dp, pp;
  178741. png_uint_32 i;
  178742. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178743. pp = prev_row + 1; i < row_bytes;
  178744. i++, rp++, pp++, dp++)
  178745. {
  178746. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  178747. }
  178748. best_row = png_ptr->up_row;
  178749. }
  178750. else if (filter_to_do & PNG_FILTER_UP)
  178751. {
  178752. png_bytep rp, dp, pp;
  178753. png_uint_32 sum = 0, lmins = mins;
  178754. png_uint_32 i;
  178755. int v;
  178756. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178757. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178758. {
  178759. int j;
  178760. png_uint_32 lmhi, lmlo;
  178761. lmlo = lmins & PNG_LOMASK;
  178762. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178763. for (j = 0; j < num_p_filters; j++)
  178764. {
  178765. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178766. {
  178767. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178768. PNG_WEIGHT_SHIFT;
  178769. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178770. PNG_WEIGHT_SHIFT;
  178771. }
  178772. }
  178773. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178774. PNG_COST_SHIFT;
  178775. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178776. PNG_COST_SHIFT;
  178777. if (lmhi > PNG_HIMASK)
  178778. lmins = PNG_MAXSUM;
  178779. else
  178780. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178781. }
  178782. #endif
  178783. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178784. pp = prev_row + 1; i < row_bytes; i++)
  178785. {
  178786. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178787. sum += (v < 128) ? v : 256 - v;
  178788. if (sum > lmins) /* We are already worse, don't continue. */
  178789. break;
  178790. }
  178791. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178792. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178793. {
  178794. int j;
  178795. png_uint_32 sumhi, sumlo;
  178796. sumlo = sum & PNG_LOMASK;
  178797. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178798. for (j = 0; j < num_p_filters; j++)
  178799. {
  178800. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178801. {
  178802. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178803. PNG_WEIGHT_SHIFT;
  178804. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178805. PNG_WEIGHT_SHIFT;
  178806. }
  178807. }
  178808. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178809. PNG_COST_SHIFT;
  178810. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178811. PNG_COST_SHIFT;
  178812. if (sumhi > PNG_HIMASK)
  178813. sum = PNG_MAXSUM;
  178814. else
  178815. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178816. }
  178817. #endif
  178818. if (sum < mins)
  178819. {
  178820. mins = sum;
  178821. best_row = png_ptr->up_row;
  178822. }
  178823. }
  178824. if (filter_to_do == PNG_FILTER_AVG)
  178825. {
  178826. png_bytep rp, dp, pp, lp;
  178827. png_uint_32 i;
  178828. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178829. pp = prev_row + 1; i < bpp; i++)
  178830. {
  178831. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178832. }
  178833. for (lp = row_buf + 1; i < row_bytes; i++)
  178834. {
  178835. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  178836. & 0xff);
  178837. }
  178838. best_row = png_ptr->avg_row;
  178839. }
  178840. else if (filter_to_do & PNG_FILTER_AVG)
  178841. {
  178842. png_bytep rp, dp, pp, lp;
  178843. png_uint_32 sum = 0, lmins = mins;
  178844. png_uint_32 i;
  178845. int v;
  178846. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178847. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178848. {
  178849. int j;
  178850. png_uint_32 lmhi, lmlo;
  178851. lmlo = lmins & PNG_LOMASK;
  178852. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178853. for (j = 0; j < num_p_filters; j++)
  178854. {
  178855. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  178856. {
  178857. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178858. PNG_WEIGHT_SHIFT;
  178859. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178860. PNG_WEIGHT_SHIFT;
  178861. }
  178862. }
  178863. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178864. PNG_COST_SHIFT;
  178865. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178866. PNG_COST_SHIFT;
  178867. if (lmhi > PNG_HIMASK)
  178868. lmins = PNG_MAXSUM;
  178869. else
  178870. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178871. }
  178872. #endif
  178873. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178874. pp = prev_row + 1; i < bpp; i++)
  178875. {
  178876. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178877. sum += (v < 128) ? v : 256 - v;
  178878. }
  178879. for (lp = row_buf + 1; i < row_bytes; i++)
  178880. {
  178881. v = *dp++ =
  178882. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  178883. sum += (v < 128) ? v : 256 - v;
  178884. if (sum > lmins) /* We are already worse, don't continue. */
  178885. break;
  178886. }
  178887. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178888. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178889. {
  178890. int j;
  178891. png_uint_32 sumhi, sumlo;
  178892. sumlo = sum & PNG_LOMASK;
  178893. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178894. for (j = 0; j < num_p_filters; j++)
  178895. {
  178896. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178897. {
  178898. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178899. PNG_WEIGHT_SHIFT;
  178900. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178901. PNG_WEIGHT_SHIFT;
  178902. }
  178903. }
  178904. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178905. PNG_COST_SHIFT;
  178906. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178907. PNG_COST_SHIFT;
  178908. if (sumhi > PNG_HIMASK)
  178909. sum = PNG_MAXSUM;
  178910. else
  178911. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178912. }
  178913. #endif
  178914. if (sum < mins)
  178915. {
  178916. mins = sum;
  178917. best_row = png_ptr->avg_row;
  178918. }
  178919. }
  178920. if (filter_to_do == PNG_FILTER_PAETH)
  178921. {
  178922. png_bytep rp, dp, pp, cp, lp;
  178923. png_uint_32 i;
  178924. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178925. pp = prev_row + 1; i < bpp; i++)
  178926. {
  178927. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178928. }
  178929. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178930. {
  178931. int a, b, c, pa, pb, pc, p;
  178932. b = *pp++;
  178933. c = *cp++;
  178934. a = *lp++;
  178935. p = b - c;
  178936. pc = a - c;
  178937. #ifdef PNG_USE_ABS
  178938. pa = abs(p);
  178939. pb = abs(pc);
  178940. pc = abs(p + pc);
  178941. #else
  178942. pa = p < 0 ? -p : p;
  178943. pb = pc < 0 ? -pc : pc;
  178944. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178945. #endif
  178946. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178947. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178948. }
  178949. best_row = png_ptr->paeth_row;
  178950. }
  178951. else if (filter_to_do & PNG_FILTER_PAETH)
  178952. {
  178953. png_bytep rp, dp, pp, cp, lp;
  178954. png_uint_32 sum = 0, lmins = mins;
  178955. png_uint_32 i;
  178956. int v;
  178957. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178958. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178959. {
  178960. int j;
  178961. png_uint_32 lmhi, lmlo;
  178962. lmlo = lmins & PNG_LOMASK;
  178963. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178964. for (j = 0; j < num_p_filters; j++)
  178965. {
  178966. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178967. {
  178968. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178969. PNG_WEIGHT_SHIFT;
  178970. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178971. PNG_WEIGHT_SHIFT;
  178972. }
  178973. }
  178974. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178975. PNG_COST_SHIFT;
  178976. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178977. PNG_COST_SHIFT;
  178978. if (lmhi > PNG_HIMASK)
  178979. lmins = PNG_MAXSUM;
  178980. else
  178981. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178982. }
  178983. #endif
  178984. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178985. pp = prev_row + 1; i < bpp; i++)
  178986. {
  178987. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178988. sum += (v < 128) ? v : 256 - v;
  178989. }
  178990. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178991. {
  178992. int a, b, c, pa, pb, pc, p;
  178993. b = *pp++;
  178994. c = *cp++;
  178995. a = *lp++;
  178996. #ifndef PNG_SLOW_PAETH
  178997. p = b - c;
  178998. pc = a - c;
  178999. #ifdef PNG_USE_ABS
  179000. pa = abs(p);
  179001. pb = abs(pc);
  179002. pc = abs(p + pc);
  179003. #else
  179004. pa = p < 0 ? -p : p;
  179005. pb = pc < 0 ? -pc : pc;
  179006. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179007. #endif
  179008. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179009. #else /* PNG_SLOW_PAETH */
  179010. p = a + b - c;
  179011. pa = abs(p - a);
  179012. pb = abs(p - b);
  179013. pc = abs(p - c);
  179014. if (pa <= pb && pa <= pc)
  179015. p = a;
  179016. else if (pb <= pc)
  179017. p = b;
  179018. else
  179019. p = c;
  179020. #endif /* PNG_SLOW_PAETH */
  179021. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179022. sum += (v < 128) ? v : 256 - v;
  179023. if (sum > lmins) /* We are already worse, don't continue. */
  179024. break;
  179025. }
  179026. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179027. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179028. {
  179029. int j;
  179030. png_uint_32 sumhi, sumlo;
  179031. sumlo = sum & PNG_LOMASK;
  179032. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179033. for (j = 0; j < num_p_filters; j++)
  179034. {
  179035. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179036. {
  179037. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179038. PNG_WEIGHT_SHIFT;
  179039. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179040. PNG_WEIGHT_SHIFT;
  179041. }
  179042. }
  179043. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179044. PNG_COST_SHIFT;
  179045. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179046. PNG_COST_SHIFT;
  179047. if (sumhi > PNG_HIMASK)
  179048. sum = PNG_MAXSUM;
  179049. else
  179050. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179051. }
  179052. #endif
  179053. if (sum < mins)
  179054. {
  179055. best_row = png_ptr->paeth_row;
  179056. }
  179057. }
  179058. #endif /* PNG_NO_WRITE_FILTER */
  179059. png_write_filtered_row(png_ptr, best_row);
  179060. #ifndef PNG_NO_WRITE_FILTER
  179061. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179062. if (png_ptr->num_prev_filters > 0)
  179063. {
  179064. int j;
  179065. for (j = 1; j < num_p_filters; j++)
  179066. {
  179067. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  179068. }
  179069. png_ptr->prev_filters[j] = best_row[0];
  179070. }
  179071. #endif
  179072. #endif /* PNG_NO_WRITE_FILTER */
  179073. }
  179074. void /* PRIVATE */
  179075. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  179076. {
  179077. png_debug(1, "in png_write_filtered_row\n");
  179078. png_debug1(2, "filter = %d\n", filtered_row[0]);
  179079. png_ptr->zstream.next_in = filtered_row;
  179080. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  179081. do
  179082. {
  179083. int ret; /* return of zlib */
  179084. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  179085. if (ret != Z_OK)
  179086. {
  179087. if (png_ptr->zstream.msg != NULL)
  179088. png_error(png_ptr, png_ptr->zstream.msg);
  179089. else
  179090. png_error(png_ptr, "zlib error");
  179091. }
  179092. if (!(png_ptr->zstream.avail_out))
  179093. {
  179094. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  179095. png_ptr->zstream.next_out = png_ptr->zbuf;
  179096. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  179097. }
  179098. } while (png_ptr->zstream.avail_in);
  179099. if (png_ptr->prev_row != NULL)
  179100. {
  179101. png_bytep tptr;
  179102. tptr = png_ptr->prev_row;
  179103. png_ptr->prev_row = png_ptr->row_buf;
  179104. png_ptr->row_buf = tptr;
  179105. }
  179106. png_write_finish_row(png_ptr);
  179107. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  179108. png_ptr->flush_rows++;
  179109. if (png_ptr->flush_dist > 0 &&
  179110. png_ptr->flush_rows >= png_ptr->flush_dist)
  179111. {
  179112. png_write_flush(png_ptr);
  179113. }
  179114. #endif
  179115. }
  179116. #endif /* PNG_WRITE_SUPPORTED */
  179117. /*** End of inlined file: pngwutil.c ***/
  179118. }
  179119. #else
  179120. #define PNG_INTERNAL
  179121. #define PNG_SETJMP_NOT_SUPPORTED
  179122. #include <png.h>
  179123. #include <pngconf.h>
  179124. #endif
  179125. }
  179126. #ifdef _MSC_VER
  179127. #pragma warning (pop)
  179128. #endif
  179129. BEGIN_JUCE_NAMESPACE
  179130. using namespace pnglibNamespace;
  179131. using ::calloc;
  179132. using ::malloc;
  179133. using ::free;
  179134. static void pngReadCallback (png_structp pngReadStruct, png_bytep data, png_size_t length)
  179135. {
  179136. InputStream* const in = (InputStream*) png_get_io_ptr (pngReadStruct);
  179137. in->read (data, (int) length);
  179138. }
  179139. struct PNGErrorStruct {};
  179140. static void pngErrorCallback (png_structp, png_const_charp)
  179141. {
  179142. throw PNGErrorStruct();
  179143. }
  179144. Image* juce_loadPNGImageFromStream (InputStream& in)
  179145. {
  179146. Image* image = 0;
  179147. png_structp pngReadStruct;
  179148. png_infop pngInfoStruct;
  179149. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179150. if (pngReadStruct != 0)
  179151. {
  179152. pngInfoStruct = png_create_info_struct (pngReadStruct);
  179153. if (pngInfoStruct == 0)
  179154. {
  179155. png_destroy_read_struct (&pngReadStruct, 0, 0);
  179156. return 0;
  179157. }
  179158. png_set_error_fn (pngReadStruct, 0, pngErrorCallback, pngErrorCallback);
  179159. // read the header..
  179160. png_set_read_fn (pngReadStruct, &in, pngReadCallback);
  179161. png_uint_32 width, height;
  179162. int bitDepth, colorType, interlaceType;
  179163. png_read_info (pngReadStruct, pngInfoStruct);
  179164. png_get_IHDR (pngReadStruct, pngInfoStruct,
  179165. &width, &height,
  179166. &bitDepth, &colorType,
  179167. &interlaceType, 0, 0);
  179168. if (bitDepth == 16)
  179169. png_set_strip_16 (pngReadStruct);
  179170. if (colorType == PNG_COLOR_TYPE_PALETTE)
  179171. png_set_expand (pngReadStruct);
  179172. if (bitDepth < 8)
  179173. png_set_expand (pngReadStruct);
  179174. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  179175. png_set_expand (pngReadStruct);
  179176. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  179177. png_set_gray_to_rgb (pngReadStruct);
  179178. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  179179. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  179180. || pngInfoStruct->num_trans > 0;
  179181. // Load the image into a temp buffer in the pnglib format..
  179182. HeapBlock <uint8> tempBuffer (height * (width << 2));
  179183. {
  179184. HeapBlock <png_bytep> rows (height);
  179185. for (int y = (int) height; --y >= 0;)
  179186. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  179187. png_read_image (pngReadStruct, rows);
  179188. png_read_end (pngReadStruct, pngInfoStruct);
  179189. }
  179190. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  179191. // now convert the data to a juce image format..
  179192. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  179193. (int) width, (int) height, hasAlphaChan);
  179194. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  179195. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  179196. uint8* srcRow = tempBuffer;
  179197. uint8* destRow = destData.data;
  179198. for (int y = 0; y < (int) height; ++y)
  179199. {
  179200. const uint8* src = srcRow;
  179201. srcRow += (width << 2);
  179202. uint8* dest = destRow;
  179203. destRow += destData.lineStride;
  179204. if (hasAlphaChan)
  179205. {
  179206. for (int i = (int) width; --i >= 0;)
  179207. {
  179208. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  179209. ((PixelARGB*) dest)->premultiply();
  179210. dest += destData.pixelStride;
  179211. src += 4;
  179212. }
  179213. }
  179214. else
  179215. {
  179216. for (int i = (int) width; --i >= 0;)
  179217. {
  179218. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  179219. dest += destData.pixelStride;
  179220. src += 4;
  179221. }
  179222. }
  179223. }
  179224. }
  179225. return image;
  179226. }
  179227. static void pngWriteDataCallback (png_structp png_ptr, png_bytep data, png_size_t length)
  179228. {
  179229. OutputStream* const out = (OutputStream*) png_ptr->io_ptr;
  179230. const bool ok = out->write (data, (int) length);
  179231. (void) ok;
  179232. jassert (ok);
  179233. }
  179234. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  179235. {
  179236. const int width = image.getWidth();
  179237. const int height = image.getHeight();
  179238. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179239. if (pngWriteStruct == 0)
  179240. return false;
  179241. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  179242. if (pngInfoStruct == 0)
  179243. {
  179244. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  179245. return false;
  179246. }
  179247. png_set_write_fn (pngWriteStruct, &out, pngWriteDataCallback, 0);
  179248. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  179249. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  179250. : PNG_COLOR_TYPE_RGB,
  179251. PNG_INTERLACE_NONE,
  179252. PNG_COMPRESSION_TYPE_BASE,
  179253. PNG_FILTER_TYPE_BASE);
  179254. HeapBlock <png_byte> rowData (width * 4);
  179255. png_color_8 sig_bit;
  179256. sig_bit.red = 8;
  179257. sig_bit.green = 8;
  179258. sig_bit.blue = 8;
  179259. sig_bit.alpha = 8;
  179260. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  179261. png_write_info (pngWriteStruct, pngInfoStruct);
  179262. png_set_shift (pngWriteStruct, &sig_bit);
  179263. png_set_packing (pngWriteStruct);
  179264. const Image::BitmapData srcData (image, 0, 0, width, height);
  179265. for (int y = 0; y < height; ++y)
  179266. {
  179267. uint8* dst = (uint8*) rowData;
  179268. const uint8* src = srcData.getLinePointer (y);
  179269. if (image.hasAlphaChannel())
  179270. {
  179271. for (int i = width; --i >= 0;)
  179272. {
  179273. PixelARGB p (*(const PixelARGB*) src);
  179274. p.unpremultiply();
  179275. *dst++ = p.getRed();
  179276. *dst++ = p.getGreen();
  179277. *dst++ = p.getBlue();
  179278. *dst++ = p.getAlpha();
  179279. src += srcData.pixelStride;
  179280. }
  179281. }
  179282. else
  179283. {
  179284. for (int i = width; --i >= 0;)
  179285. {
  179286. *dst++ = ((const PixelRGB*) src)->getRed();
  179287. *dst++ = ((const PixelRGB*) src)->getGreen();
  179288. *dst++ = ((const PixelRGB*) src)->getBlue();
  179289. src += srcData.pixelStride;
  179290. }
  179291. }
  179292. png_write_rows (pngWriteStruct, &rowData, 1);
  179293. }
  179294. png_write_end (pngWriteStruct, pngInfoStruct);
  179295. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179296. out.flush();
  179297. return true;
  179298. }
  179299. END_JUCE_NAMESPACE
  179300. /*** End of inlined file: juce_PNGLoader.cpp ***/
  179301. #endif
  179302. //==============================================================================
  179303. #if JUCE_BUILD_NATIVE
  179304. #if JUCE_WINDOWS
  179305. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  179306. BEGIN_JUCE_NAMESPACE
  179307. #define JUCE_INCLUDED_FILE 1
  179308. // Now include the actual code files..
  179309. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179310. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179311. // compiled on its own).
  179312. #if JUCE_INCLUDED_FILE
  179313. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179314. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179315. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179316. #ifndef DOXYGEN
  179317. // use with DynamicLibraryLoader to simplify importing functions
  179318. //
  179319. // functionName: function to import
  179320. // localFunctionName: name you want to use to actually call it (must be different)
  179321. // returnType: the return type
  179322. // object: the DynamicLibraryLoader to use
  179323. // params: list of params (bracketed)
  179324. //
  179325. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179326. typedef returnType (WINAPI *type##localFunctionName) params; \
  179327. type##localFunctionName localFunctionName \
  179328. = (type##localFunctionName)object.findProcAddress (#functionName);
  179329. // loads and unloads a DLL automatically
  179330. class JUCE_API DynamicLibraryLoader
  179331. {
  179332. public:
  179333. DynamicLibraryLoader (const String& name);
  179334. ~DynamicLibraryLoader();
  179335. void* findProcAddress (const String& functionName);
  179336. private:
  179337. void* libHandle;
  179338. };
  179339. #endif
  179340. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179341. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179342. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179343. {
  179344. libHandle = LoadLibrary (name);
  179345. }
  179346. DynamicLibraryLoader::~DynamicLibraryLoader()
  179347. {
  179348. FreeLibrary ((HMODULE) libHandle);
  179349. }
  179350. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179351. {
  179352. return (void*) GetProcAddress ((HMODULE) libHandle, functionName.toCString());
  179353. }
  179354. #endif
  179355. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179356. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  179357. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179358. // compiled on its own).
  179359. #if JUCE_INCLUDED_FILE
  179360. extern void juce_initialiseThreadEvents();
  179361. void Logger::outputDebugString (const String& text) throw()
  179362. {
  179363. OutputDebugString (text + T("\n"));
  179364. }
  179365. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  179366. {
  179367. String text;
  179368. va_list args;
  179369. va_start (args, format);
  179370. text.vprintf(format, args);
  179371. outputDebugString (text);
  179372. }
  179373. static int64 hiResTicksPerSecond;
  179374. static double hiResTicksScaleFactor;
  179375. #if JUCE_USE_INTRINSICS
  179376. // CPU info functions using intrinsics...
  179377. #pragma intrinsic (__cpuid)
  179378. #pragma intrinsic (__rdtsc)
  179379. const String SystemStats::getCpuVendor() throw()
  179380. {
  179381. int info [4];
  179382. __cpuid (info, 0);
  179383. char v [12];
  179384. memcpy (v, info + 1, 4);
  179385. memcpy (v + 4, info + 3, 4);
  179386. memcpy (v + 8, info + 2, 4);
  179387. return String (v, 12);
  179388. }
  179389. #else
  179390. // CPU info functions using old fashioned inline asm...
  179391. static void juce_getCpuVendor (char* const v)
  179392. {
  179393. int vendor[4];
  179394. zeromem (vendor, 16);
  179395. #ifdef JUCE_64BIT
  179396. #else
  179397. #ifndef __MINGW32__
  179398. __try
  179399. #endif
  179400. {
  179401. #if JUCE_GCC
  179402. unsigned int dummy = 0;
  179403. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179404. #else
  179405. __asm
  179406. {
  179407. mov eax, 0
  179408. cpuid
  179409. mov [vendor], ebx
  179410. mov [vendor + 4], edx
  179411. mov [vendor + 8], ecx
  179412. }
  179413. #endif
  179414. }
  179415. #ifndef __MINGW32__
  179416. __except (EXCEPTION_EXECUTE_HANDLER)
  179417. {
  179418. *v = 0;
  179419. }
  179420. #endif
  179421. #endif
  179422. memcpy (v, vendor, 16);
  179423. }
  179424. const String SystemStats::getCpuVendor() throw()
  179425. {
  179426. char v [16];
  179427. juce_getCpuVendor (v);
  179428. return String (v, 16);
  179429. }
  179430. #endif
  179431. struct CPUFlags
  179432. {
  179433. bool hasMMX : 1;
  179434. bool hasSSE : 1;
  179435. bool hasSSE2 : 1;
  179436. bool has3DNow : 1;
  179437. };
  179438. static CPUFlags cpuFlags;
  179439. bool SystemStats::hasMMX() throw()
  179440. {
  179441. return cpuFlags.hasMMX;
  179442. }
  179443. bool SystemStats::hasSSE() throw()
  179444. {
  179445. return cpuFlags.hasSSE;
  179446. }
  179447. bool SystemStats::hasSSE2() throw()
  179448. {
  179449. return cpuFlags.hasSSE2;
  179450. }
  179451. bool SystemStats::has3DNow() throw()
  179452. {
  179453. return cpuFlags.has3DNow;
  179454. }
  179455. void SystemStats::initialiseStats() throw()
  179456. {
  179457. juce_initialiseThreadEvents();
  179458. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179459. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179460. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179461. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179462. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179463. #else
  179464. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179465. #endif
  179466. LARGE_INTEGER f;
  179467. QueryPerformanceFrequency (&f);
  179468. hiResTicksPerSecond = f.QuadPart;
  179469. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179470. String s (SystemStats::getJUCEVersion());
  179471. #ifdef JUCE_DEBUG
  179472. const MMRESULT res = timeBeginPeriod (1);
  179473. jassert (res == TIMERR_NOERROR);
  179474. #else
  179475. timeBeginPeriod (1);
  179476. #endif
  179477. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179478. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179479. #endif
  179480. }
  179481. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179482. {
  179483. OSVERSIONINFO info;
  179484. info.dwOSVersionInfoSize = sizeof (info);
  179485. GetVersionEx (&info);
  179486. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179487. {
  179488. switch (info.dwMajorVersion)
  179489. {
  179490. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179491. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179492. default: jassertfalse; break; // !! not a supported OS!
  179493. }
  179494. }
  179495. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179496. {
  179497. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179498. return Win98;
  179499. }
  179500. return UnknownOS;
  179501. }
  179502. const String SystemStats::getOperatingSystemName() throw()
  179503. {
  179504. const char* name = "Unknown OS";
  179505. switch (getOperatingSystemType())
  179506. {
  179507. case Windows7: name = "Windows 7"; break;
  179508. case WinVista: name = "Windows Vista"; break;
  179509. case WinXP: name = "Windows XP"; break;
  179510. case Win2000: name = "Windows 2000"; break;
  179511. case Win98: name = "Windows 98"; break;
  179512. default: jassertfalse; break; // !! new type of OS?
  179513. }
  179514. return name;
  179515. }
  179516. bool SystemStats::isOperatingSystem64Bit() throw()
  179517. {
  179518. #ifdef _WIN64
  179519. return true;
  179520. #else
  179521. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179522. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179523. BOOL isWow64 = FALSE;
  179524. return (fnIsWow64Process != 0)
  179525. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179526. && (isWow64 != FALSE);
  179527. #endif
  179528. }
  179529. int SystemStats::getMemorySizeInMegabytes() throw()
  179530. {
  179531. MEMORYSTATUSEX mem;
  179532. mem.dwLength = sizeof (mem);
  179533. GlobalMemoryStatusEx (&mem);
  179534. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179535. }
  179536. int SystemStats::getNumCpus() throw()
  179537. {
  179538. SYSTEM_INFO systemInfo;
  179539. GetSystemInfo (&systemInfo);
  179540. return systemInfo.dwNumberOfProcessors;
  179541. }
  179542. uint32 juce_millisecondsSinceStartup() throw()
  179543. {
  179544. return (uint32) GetTickCount();
  179545. }
  179546. int64 Time::getHighResolutionTicks() throw()
  179547. {
  179548. LARGE_INTEGER ticks;
  179549. QueryPerformanceCounter (&ticks);
  179550. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179551. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179552. // fix for a very obscure PCI hardware bug that can make the counter
  179553. // sometimes jump forwards by a few seconds..
  179554. static int64 hiResTicksOffset = 0;
  179555. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179556. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179557. hiResTicksOffset = newOffset;
  179558. return ticks.QuadPart + hiResTicksOffset;
  179559. }
  179560. double Time::getMillisecondCounterHiRes() throw()
  179561. {
  179562. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179563. }
  179564. int64 Time::getHighResolutionTicksPerSecond() throw()
  179565. {
  179566. return hiResTicksPerSecond;
  179567. }
  179568. int64 SystemStats::getClockCycleCounter() throw()
  179569. {
  179570. #if JUCE_USE_INTRINSICS
  179571. // MS intrinsics version...
  179572. return __rdtsc();
  179573. #elif JUCE_GCC
  179574. // GNU inline asm version...
  179575. unsigned int hi = 0, lo = 0;
  179576. __asm__ __volatile__ (
  179577. "xor %%eax, %%eax \n\
  179578. xor %%edx, %%edx \n\
  179579. rdtsc \n\
  179580. movl %%eax, %[lo] \n\
  179581. movl %%edx, %[hi]"
  179582. :
  179583. : [hi] "m" (hi),
  179584. [lo] "m" (lo)
  179585. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179586. return (int64) ((((uint64) hi) << 32) | lo);
  179587. #else
  179588. // MSVC inline asm version...
  179589. unsigned int hi = 0, lo = 0;
  179590. __asm
  179591. {
  179592. xor eax, eax
  179593. xor edx, edx
  179594. rdtsc
  179595. mov lo, eax
  179596. mov hi, edx
  179597. }
  179598. return (int64) ((((uint64) hi) << 32) | lo);
  179599. #endif
  179600. }
  179601. int SystemStats::getCpuSpeedInMegaherz() throw()
  179602. {
  179603. const int64 cycles = SystemStats::getClockCycleCounter();
  179604. const uint32 millis = Time::getMillisecondCounter();
  179605. int lastResult = 0;
  179606. for (;;)
  179607. {
  179608. int n = 1000000;
  179609. while (--n > 0) {}
  179610. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179611. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179612. if (millisElapsed > 80)
  179613. {
  179614. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179615. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179616. return newResult;
  179617. lastResult = newResult;
  179618. }
  179619. }
  179620. }
  179621. bool Time::setSystemTimeToThisTime() const throw()
  179622. {
  179623. SYSTEMTIME st;
  179624. st.wDayOfWeek = 0;
  179625. st.wYear = (WORD) getYear();
  179626. st.wMonth = (WORD) (getMonth() + 1);
  179627. st.wDay = (WORD) getDayOfMonth();
  179628. st.wHour = (WORD) getHours();
  179629. st.wMinute = (WORD) getMinutes();
  179630. st.wSecond = (WORD) getSeconds();
  179631. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179632. // do this twice because of daylight saving conversion problems - the
  179633. // first one sets it up, the second one kicks it in.
  179634. return SetLocalTime (&st) != 0
  179635. && SetLocalTime (&st) != 0;
  179636. }
  179637. int SystemStats::getPageSize() throw()
  179638. {
  179639. SYSTEM_INFO systemInfo;
  179640. GetSystemInfo (&systemInfo);
  179641. return systemInfo.dwPageSize;
  179642. }
  179643. const String SystemStats::getLogonName()
  179644. {
  179645. TCHAR text [256];
  179646. DWORD len = numElementsInArray (text) - 2;
  179647. zerostruct (text);
  179648. GetUserName (text, &len);
  179649. return String (text, len);
  179650. }
  179651. const String SystemStats::getFullUserName()
  179652. {
  179653. return getLogonName();
  179654. }
  179655. #endif
  179656. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179657. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179658. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179659. // compiled on its own).
  179660. #if JUCE_INCLUDED_FILE
  179661. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179662. extern HWND juce_messageWindowHandle;
  179663. #endif
  179664. #if ! JUCE_USE_INTRINSICS
  179665. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179666. // older ones we have to actually call the ops as win32 functions..
  179667. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179668. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179669. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179670. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179671. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  179672. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  179673. #endif
  179674. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  179675. CriticalSection::CriticalSection() throw()
  179676. {
  179677. // (just to check the MS haven't changed this structure and broken things...)
  179678. #if _MSC_VER >= 1400
  179679. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  179680. #else
  179681. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  179682. #endif
  179683. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  179684. }
  179685. CriticalSection::~CriticalSection() throw()
  179686. {
  179687. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  179688. }
  179689. void CriticalSection::enter() const throw()
  179690. {
  179691. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  179692. }
  179693. bool CriticalSection::tryEnter() const throw()
  179694. {
  179695. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  179696. }
  179697. void CriticalSection::exit() const throw()
  179698. {
  179699. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  179700. }
  179701. WaitableEvent::WaitableEvent() throw()
  179702. : internal (CreateEvent (0, FALSE, FALSE, 0))
  179703. {
  179704. }
  179705. WaitableEvent::~WaitableEvent() throw()
  179706. {
  179707. CloseHandle (internal);
  179708. }
  179709. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  179710. {
  179711. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  179712. }
  179713. void WaitableEvent::signal() const throw()
  179714. {
  179715. SetEvent (internal);
  179716. }
  179717. void WaitableEvent::reset() const throw()
  179718. {
  179719. ResetEvent (internal);
  179720. }
  179721. void JUCE_API juce_threadEntryPoint (void*);
  179722. static unsigned int __stdcall threadEntryProc (void* userData)
  179723. {
  179724. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179725. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  179726. GetCurrentThreadId(), TRUE);
  179727. #endif
  179728. juce_threadEntryPoint (userData);
  179729. _endthreadex (0);
  179730. return 0;
  179731. }
  179732. void juce_CloseThreadHandle (void* handle)
  179733. {
  179734. CloseHandle ((HANDLE) handle);
  179735. }
  179736. void* juce_createThread (void* userData)
  179737. {
  179738. unsigned int threadId;
  179739. return (void*) _beginthreadex (0, 0,
  179740. &threadEntryProc,
  179741. userData,
  179742. 0, &threadId);
  179743. }
  179744. void juce_killThread (void* handle)
  179745. {
  179746. if (handle != 0)
  179747. {
  179748. #ifdef JUCE_DEBUG
  179749. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  179750. #endif
  179751. TerminateThread (handle, 0);
  179752. }
  179753. }
  179754. void juce_setCurrentThreadName (const String& name)
  179755. {
  179756. #if defined (JUCE_DEBUG) && JUCE_MSVC
  179757. struct
  179758. {
  179759. DWORD dwType;
  179760. LPCSTR szName;
  179761. DWORD dwThreadID;
  179762. DWORD dwFlags;
  179763. } info;
  179764. info.dwType = 0x1000;
  179765. info.szName = name.toCString();
  179766. info.dwThreadID = GetCurrentThreadId();
  179767. info.dwFlags = 0;
  179768. #define MS_VC_EXCEPTION 0x406d1388
  179769. __try
  179770. {
  179771. RaiseException (MS_VC_EXCEPTION, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  179772. }
  179773. __except (EXCEPTION_CONTINUE_EXECUTION)
  179774. {}
  179775. #else
  179776. (void) name;
  179777. #endif
  179778. }
  179779. Thread::ThreadID Thread::getCurrentThreadId()
  179780. {
  179781. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  179782. }
  179783. // priority 1 to 10 where 5=normal, 1=low
  179784. bool juce_setThreadPriority (void* threadHandle, int priority)
  179785. {
  179786. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  179787. if (priority < 1)
  179788. pri = THREAD_PRIORITY_IDLE;
  179789. else if (priority < 2)
  179790. pri = THREAD_PRIORITY_LOWEST;
  179791. else if (priority < 5)
  179792. pri = THREAD_PRIORITY_BELOW_NORMAL;
  179793. else if (priority < 7)
  179794. pri = THREAD_PRIORITY_NORMAL;
  179795. else if (priority < 9)
  179796. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  179797. else if (priority < 10)
  179798. pri = THREAD_PRIORITY_HIGHEST;
  179799. if (threadHandle == 0)
  179800. threadHandle = GetCurrentThread();
  179801. return SetThreadPriority (threadHandle, pri) != FALSE;
  179802. }
  179803. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  179804. {
  179805. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  179806. }
  179807. static HANDLE sleepEvent = 0;
  179808. void juce_initialiseThreadEvents()
  179809. {
  179810. if (sleepEvent == 0)
  179811. #ifdef JUCE_DEBUG
  179812. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  179813. #else
  179814. sleepEvent = CreateEvent (0, 0, 0, 0);
  179815. #endif
  179816. }
  179817. void Thread::yield()
  179818. {
  179819. Sleep (0);
  179820. }
  179821. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  179822. {
  179823. if (millisecs >= 10)
  179824. {
  179825. Sleep (millisecs);
  179826. }
  179827. else
  179828. {
  179829. jassert (sleepEvent != 0);
  179830. // unlike Sleep() this is guaranteed to return to the current thread after
  179831. // the time expires, so we'll use this for short waits, which are more likely
  179832. // to need to be accurate
  179833. WaitForSingleObject (sleepEvent, millisecs);
  179834. }
  179835. }
  179836. static int lastProcessPriority = -1;
  179837. // called by WindowDriver because Windows does wierd things to process priority
  179838. // when you swap apps, and this forces an update when the app is brought to the front.
  179839. void juce_repeatLastProcessPriority()
  179840. {
  179841. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  179842. {
  179843. DWORD p;
  179844. switch (lastProcessPriority)
  179845. {
  179846. case Process::LowPriority:
  179847. p = IDLE_PRIORITY_CLASS;
  179848. break;
  179849. case Process::NormalPriority:
  179850. p = NORMAL_PRIORITY_CLASS;
  179851. break;
  179852. case Process::HighPriority:
  179853. p = HIGH_PRIORITY_CLASS;
  179854. break;
  179855. case Process::RealtimePriority:
  179856. p = REALTIME_PRIORITY_CLASS;
  179857. break;
  179858. default:
  179859. jassertfalse // bad priority value
  179860. return;
  179861. }
  179862. SetPriorityClass (GetCurrentProcess(), p);
  179863. }
  179864. }
  179865. void Process::setPriority (ProcessPriority prior)
  179866. {
  179867. if (lastProcessPriority != (int) prior)
  179868. {
  179869. lastProcessPriority = (int) prior;
  179870. juce_repeatLastProcessPriority();
  179871. }
  179872. }
  179873. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  179874. {
  179875. return IsDebuggerPresent() != FALSE;
  179876. }
  179877. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  179878. {
  179879. return juce_isRunningUnderDebugger();
  179880. }
  179881. void Process::raisePrivilege()
  179882. {
  179883. jassertfalse // xxx not implemented
  179884. }
  179885. void Process::lowerPrivilege()
  179886. {
  179887. jassertfalse // xxx not implemented
  179888. }
  179889. void Process::terminate()
  179890. {
  179891. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179892. _CrtDumpMemoryLeaks();
  179893. #endif
  179894. // bullet in the head in case there's a problem shutting down..
  179895. ExitProcess (0);
  179896. }
  179897. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  179898. {
  179899. void* result = 0;
  179900. JUCE_TRY
  179901. {
  179902. result = (void*) LoadLibrary (name);
  179903. }
  179904. JUCE_CATCH_ALL
  179905. return result;
  179906. }
  179907. void PlatformUtilities::freeDynamicLibrary (void* h)
  179908. {
  179909. JUCE_TRY
  179910. {
  179911. if (h != 0)
  179912. FreeLibrary ((HMODULE) h);
  179913. }
  179914. JUCE_CATCH_ALL
  179915. }
  179916. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  179917. {
  179918. return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name.toCString()) : 0;
  179919. }
  179920. InterProcessLock::InterProcessLock (const String& name_)
  179921. : internal (0),
  179922. name (name_),
  179923. reentrancyLevel (0)
  179924. {
  179925. }
  179926. InterProcessLock::~InterProcessLock()
  179927. {
  179928. exit();
  179929. }
  179930. bool InterProcessLock::enter (const int timeOutMillisecs)
  179931. {
  179932. if (reentrancyLevel++ == 0)
  179933. {
  179934. internal = CreateMutex (0, TRUE, "Global\\" + name);
  179935. if (internal != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  179936. {
  179937. if (timeOutMillisecs == 0
  179938. || WaitForSingleObject (internal, (timeOutMillisecs < 0) ? INFINITE : timeOutMillisecs)
  179939. == WAIT_TIMEOUT)
  179940. {
  179941. ReleaseMutex (internal);
  179942. CloseHandle (internal);
  179943. internal = 0;
  179944. }
  179945. }
  179946. }
  179947. return (internal != 0);
  179948. }
  179949. void InterProcessLock::exit()
  179950. {
  179951. if (--reentrancyLevel == 0 && internal != 0)
  179952. {
  179953. ReleaseMutex (internal);
  179954. CloseHandle (internal);
  179955. internal = 0;
  179956. }
  179957. }
  179958. #endif
  179959. /*** End of inlined file: juce_win32_Threads.cpp ***/
  179960. /*** Start of inlined file: juce_win32_Files.cpp ***/
  179961. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179962. // compiled on its own).
  179963. #if JUCE_INCLUDED_FILE
  179964. #ifndef CSIDL_MYMUSIC
  179965. #define CSIDL_MYMUSIC 0x000d
  179966. #endif
  179967. #ifndef CSIDL_MYVIDEO
  179968. #define CSIDL_MYVIDEO 0x000e
  179969. #endif
  179970. const tchar File::separator = T('\\');
  179971. const tchar* File::separatorString = T("\\");
  179972. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  179973. {
  179974. if (fileName.isEmpty())
  179975. return false;
  179976. const DWORD attr = GetFileAttributes (fileName);
  179977. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  179978. : (attr != 0xffffffff);
  179979. }
  179980. bool juce_isDirectory (const String& fileName)
  179981. {
  179982. const DWORD attr = GetFileAttributes (fileName);
  179983. return (attr != 0xffffffff)
  179984. && ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0);
  179985. }
  179986. bool juce_canWriteToFile (const String& fileName)
  179987. {
  179988. const DWORD attr = GetFileAttributes (fileName);
  179989. return ((attr & FILE_ATTRIBUTE_READONLY) == 0);
  179990. }
  179991. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  179992. {
  179993. DWORD attr = GetFileAttributes (fileName);
  179994. if (attr == 0xffffffff)
  179995. return false;
  179996. if (isReadOnly != juce_canWriteToFile (fileName))
  179997. return true;
  179998. if (isReadOnly)
  179999. attr |= FILE_ATTRIBUTE_READONLY;
  180000. else
  180001. attr &= ~FILE_ATTRIBUTE_READONLY;
  180002. return SetFileAttributes (fileName, attr) != FALSE;
  180003. }
  180004. bool File::isHidden() const
  180005. {
  180006. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  180007. }
  180008. bool juce_deleteFile (const String& fileName)
  180009. {
  180010. if (juce_isDirectory (fileName))
  180011. return RemoveDirectory (fileName) != 0;
  180012. return DeleteFile (fileName) != 0;
  180013. }
  180014. bool File::moveToTrash() const
  180015. {
  180016. if (! exists())
  180017. return true;
  180018. SHFILEOPSTRUCT fos;
  180019. zerostruct (fos);
  180020. // The string we pass in must be double null terminated..
  180021. String doubleNullTermPath (getFullPathName() + " ");
  180022. TCHAR* p = (TCHAR*) (const TCHAR*) doubleNullTermPath;
  180023. p [getFullPathName().length()] = 0;
  180024. fos.wFunc = FO_DELETE;
  180025. fos.hwnd = (HWND) 0;
  180026. fos.pFrom = p;
  180027. fos.pTo = NULL;
  180028. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  180029. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  180030. return SHFileOperation (&fos) == 0;
  180031. }
  180032. bool juce_moveFile (const String& source, const String& dest)
  180033. {
  180034. return MoveFile (source, dest) != 0;
  180035. }
  180036. bool juce_copyFile (const String& source, const String& dest)
  180037. {
  180038. return CopyFile (source, dest, false) != 0;
  180039. }
  180040. void juce_createDirectory (const String& fileName)
  180041. {
  180042. if (! juce_fileExists (fileName, true))
  180043. {
  180044. CreateDirectory (fileName, 0);
  180045. }
  180046. }
  180047. // return 0 if not possible
  180048. void* juce_fileOpen (const String& fileName, bool forWriting)
  180049. {
  180050. HANDLE h;
  180051. if (forWriting)
  180052. {
  180053. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  180054. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  180055. if (h != INVALID_HANDLE_VALUE)
  180056. SetFilePointer (h, 0, 0, FILE_END);
  180057. else
  180058. h = 0;
  180059. }
  180060. else
  180061. {
  180062. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  180063. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  180064. if (h == INVALID_HANDLE_VALUE)
  180065. h = 0;
  180066. }
  180067. return (void*) h;
  180068. }
  180069. void juce_fileClose (void* handle)
  180070. {
  180071. CloseHandle (handle);
  180072. }
  180073. int juce_fileRead (void* handle, void* buffer, int size)
  180074. {
  180075. DWORD num = 0;
  180076. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  180077. return num;
  180078. }
  180079. int juce_fileWrite (void* handle, const void* buffer, int size)
  180080. {
  180081. DWORD num;
  180082. WriteFile ((HANDLE) handle,
  180083. buffer, size,
  180084. &num, 0);
  180085. return num;
  180086. }
  180087. int64 juce_fileSetPosition (void* handle, int64 pos)
  180088. {
  180089. LARGE_INTEGER li;
  180090. li.QuadPart = pos;
  180091. li.LowPart = SetFilePointer ((HANDLE) handle,
  180092. li.LowPart,
  180093. &li.HighPart,
  180094. FILE_BEGIN); // (returns -1 if it fails)
  180095. return li.QuadPart;
  180096. }
  180097. int64 juce_fileGetPosition (void* handle)
  180098. {
  180099. LARGE_INTEGER li;
  180100. li.QuadPart = 0;
  180101. li.LowPart = SetFilePointer ((HANDLE) handle,
  180102. 0, &li.HighPart,
  180103. FILE_CURRENT); // (returns -1 if it fails)
  180104. return jmax ((int64) 0, li.QuadPart);
  180105. }
  180106. void juce_fileFlush (void* handle)
  180107. {
  180108. FlushFileBuffers ((HANDLE) handle);
  180109. }
  180110. int64 juce_getFileSize (const String& fileName)
  180111. {
  180112. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180113. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180114. {
  180115. return (((int64) attributes.nFileSizeHigh) << 32)
  180116. | attributes.nFileSizeLow;
  180117. }
  180118. return 0;
  180119. }
  180120. static int64 fileTimeToTime (const FILETIME* const ft)
  180121. {
  180122. // tell me if this fails!
  180123. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME));
  180124. #if JUCE_GCC
  180125. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000LL) / 10000;
  180126. #else
  180127. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000) / 10000;
  180128. #endif
  180129. }
  180130. static void timeToFileTime (const int64 time, FILETIME* const ft)
  180131. {
  180132. #if JUCE_GCC
  180133. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000LL;
  180134. #else
  180135. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000;
  180136. #endif
  180137. }
  180138. void juce_getFileTimes (const String& fileName,
  180139. int64& modificationTime,
  180140. int64& accessTime,
  180141. int64& creationTime)
  180142. {
  180143. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180144. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180145. {
  180146. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  180147. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  180148. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  180149. }
  180150. else
  180151. {
  180152. creationTime = accessTime = modificationTime = 0;
  180153. }
  180154. }
  180155. bool juce_setFileTimes (const String& fileName,
  180156. int64 modificationTime,
  180157. int64 accessTime,
  180158. int64 creationTime)
  180159. {
  180160. FILETIME m, a, c;
  180161. if (modificationTime > 0)
  180162. timeToFileTime (modificationTime, &m);
  180163. if (accessTime > 0)
  180164. timeToFileTime (accessTime, &a);
  180165. if (creationTime > 0)
  180166. timeToFileTime (creationTime, &c);
  180167. void* const h = juce_fileOpen (fileName, true);
  180168. bool ok = false;
  180169. if (h != 0)
  180170. {
  180171. ok = SetFileTime ((HANDLE) h,
  180172. (creationTime > 0) ? &c : 0,
  180173. (accessTime > 0) ? &a : 0,
  180174. (modificationTime > 0) ? &m : 0) != 0;
  180175. juce_fileClose (h);
  180176. }
  180177. return ok;
  180178. }
  180179. // return '\0' separated list of strings
  180180. const StringArray juce_getFileSystemRoots()
  180181. {
  180182. TCHAR buffer [2048];
  180183. buffer[0] = 0;
  180184. buffer[1] = 0;
  180185. GetLogicalDriveStrings (2048, buffer);
  180186. TCHAR* n = buffer;
  180187. StringArray roots;
  180188. while (*n != 0)
  180189. {
  180190. roots.add (String (n));
  180191. while (*n++ != 0)
  180192. {
  180193. }
  180194. }
  180195. roots.sort (true);
  180196. return roots;
  180197. }
  180198. const String juce_getVolumeLabel (const String& filenameOnVolume,
  180199. int& volumeSerialNumber)
  180200. {
  180201. TCHAR n [4];
  180202. n[0] = *(const TCHAR*) filenameOnVolume;
  180203. n[1] = L':';
  180204. n[2] = L'\\';
  180205. n[3] = 0;
  180206. TCHAR dest [64];
  180207. DWORD serialNum;
  180208. if (! GetVolumeInformation (n, dest, 64, (DWORD*) &serialNum, 0, 0, 0, 0))
  180209. {
  180210. dest[0] = 0;
  180211. serialNum = 0;
  180212. }
  180213. volumeSerialNumber = serialNum;
  180214. return String (dest);
  180215. }
  180216. static int64 getDiskSpaceInfo (String fn, const bool total)
  180217. {
  180218. if (fn[1] == T(':'))
  180219. fn = fn.substring (0, 2) + T("\\");
  180220. ULARGE_INTEGER spc, tot, totFree;
  180221. if (GetDiskFreeSpaceEx (fn, &spc, &tot, &totFree))
  180222. return (int64) (total ? tot.QuadPart
  180223. : spc.QuadPart);
  180224. return 0;
  180225. }
  180226. int64 File::getBytesFreeOnVolume() const
  180227. {
  180228. return getDiskSpaceInfo (getFullPathName(), false);
  180229. }
  180230. int64 File::getVolumeTotalSize() const
  180231. {
  180232. return getDiskSpaceInfo (getFullPathName(), true);
  180233. }
  180234. static unsigned int getWindowsDriveType (const String& fileName)
  180235. {
  180236. TCHAR n[4];
  180237. n[0] = *(const TCHAR*) fileName;
  180238. n[1] = L':';
  180239. n[2] = L'\\';
  180240. n[3] = 0;
  180241. return GetDriveType (n);
  180242. }
  180243. bool File::isOnCDRomDrive() const
  180244. {
  180245. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  180246. }
  180247. bool File::isOnHardDisk() const
  180248. {
  180249. if (fullPath.isEmpty())
  180250. return false;
  180251. const unsigned int n = getWindowsDriveType (getFullPathName());
  180252. if (fullPath.toLowerCase()[0] <= 'b'
  180253. && fullPath[1] == T(':'))
  180254. {
  180255. return n != DRIVE_REMOVABLE;
  180256. }
  180257. else
  180258. {
  180259. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  180260. }
  180261. }
  180262. bool File::isOnRemovableDrive() const
  180263. {
  180264. if (fullPath.isEmpty())
  180265. return false;
  180266. const unsigned int n = getWindowsDriveType (getFullPathName());
  180267. return n == DRIVE_CDROM
  180268. || n == DRIVE_REMOTE
  180269. || n == DRIVE_REMOVABLE
  180270. || n == DRIVE_RAMDISK;
  180271. }
  180272. #define MAX_PATH_CHARS (MAX_PATH + 256)
  180273. static const File juce_getSpecialFolderPath (int type)
  180274. {
  180275. WCHAR path [MAX_PATH_CHARS];
  180276. if (SHGetSpecialFolderPath (0, path, type, 0))
  180277. return File (String (path));
  180278. return File::nonexistent;
  180279. }
  180280. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  180281. {
  180282. int csidlType = 0;
  180283. switch (type)
  180284. {
  180285. case userHomeDirectory:
  180286. csidlType = CSIDL_PROFILE;
  180287. break;
  180288. case userDocumentsDirectory:
  180289. csidlType = CSIDL_PERSONAL;
  180290. break;
  180291. case userDesktopDirectory:
  180292. csidlType = CSIDL_DESKTOP;
  180293. break;
  180294. case userApplicationDataDirectory:
  180295. csidlType = CSIDL_APPDATA;
  180296. break;
  180297. case commonApplicationDataDirectory:
  180298. csidlType = CSIDL_COMMON_APPDATA;
  180299. break;
  180300. case globalApplicationsDirectory:
  180301. csidlType = CSIDL_PROGRAM_FILES;
  180302. break;
  180303. case userMusicDirectory:
  180304. csidlType = CSIDL_MYMUSIC;
  180305. break;
  180306. case userMoviesDirectory:
  180307. csidlType = CSIDL_MYVIDEO;
  180308. break;
  180309. case tempDirectory:
  180310. {
  180311. WCHAR dest [2048];
  180312. dest[0] = 0;
  180313. GetTempPath (2048, dest);
  180314. return File (String (dest));
  180315. }
  180316. case invokedExecutableFile:
  180317. case currentExecutableFile:
  180318. case currentApplicationFile:
  180319. {
  180320. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180321. WCHAR dest [MAX_PATH_CHARS];
  180322. dest[0] = 0;
  180323. GetModuleFileName (moduleHandle, dest, MAX_PATH_CHARS);
  180324. return File (String (dest));
  180325. }
  180326. break;
  180327. default:
  180328. jassertfalse // unknown type?
  180329. return File::nonexistent;
  180330. }
  180331. return juce_getSpecialFolderPath (csidlType);
  180332. }
  180333. const File File::getCurrentWorkingDirectory()
  180334. {
  180335. WCHAR dest [MAX_PATH_CHARS];
  180336. dest[0] = 0;
  180337. GetCurrentDirectory (MAX_PATH_CHARS, dest);
  180338. return File (String (dest));
  180339. }
  180340. bool File::setAsCurrentWorkingDirectory() const
  180341. {
  180342. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180343. }
  180344. const String File::getVersion() const
  180345. {
  180346. String result;
  180347. DWORD handle = 0;
  180348. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180349. HeapBlock <char> buffer;
  180350. buffer.calloc (bufferSize);
  180351. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180352. {
  180353. VS_FIXEDFILEINFO* vffi;
  180354. UINT len = 0;
  180355. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  180356. {
  180357. result << (int) HIWORD (vffi->dwFileVersionMS) << "."
  180358. << (int) LOWORD (vffi->dwFileVersionMS) << "."
  180359. << (int) HIWORD (vffi->dwFileVersionLS) << "."
  180360. << (int) LOWORD (vffi->dwFileVersionLS);
  180361. }
  180362. }
  180363. return result;
  180364. }
  180365. const File File::getLinkedTarget() const
  180366. {
  180367. File result (*this);
  180368. String p (getFullPathName());
  180369. if (! exists())
  180370. p += T(".lnk");
  180371. else if (getFileExtension() != T(".lnk"))
  180372. return result;
  180373. ComSmartPtr <IShellLink> shellLink;
  180374. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180375. {
  180376. ComSmartPtr <IPersistFile> persistFile;
  180377. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180378. {
  180379. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180380. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180381. {
  180382. WIN32_FIND_DATA winFindData;
  180383. WCHAR resolvedPath [MAX_PATH];
  180384. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180385. result = File (resolvedPath);
  180386. }
  180387. }
  180388. }
  180389. return result;
  180390. }
  180391. template <class FindDataType>
  180392. static void getFindFileInfo (FindDataType& findData,
  180393. String& filename, bool* const isDir, bool* const isHidden,
  180394. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180395. bool* const isReadOnly)
  180396. {
  180397. filename = findData.cFileName;
  180398. if (isDir != 0)
  180399. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180400. if (isHidden != 0)
  180401. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180402. if (fileSize != 0)
  180403. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180404. if (modTime != 0)
  180405. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180406. if (creationTime != 0)
  180407. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180408. if (isReadOnly != 0)
  180409. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180410. }
  180411. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  180412. bool* isDir, bool* isHidden, int64* fileSize,
  180413. Time* modTime, Time* creationTime, bool* isReadOnly)
  180414. {
  180415. String wc (directory);
  180416. if (! wc.endsWithChar (File::separator))
  180417. wc += File::separator;
  180418. wc += wildCard;
  180419. WIN32_FIND_DATA findData;
  180420. HANDLE h = FindFirstFile (wc, &findData);
  180421. if (h != INVALID_HANDLE_VALUE)
  180422. {
  180423. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  180424. modTime, creationTime, isReadOnly);
  180425. return h;
  180426. }
  180427. firstResult = String::empty;
  180428. return 0;
  180429. }
  180430. bool juce_findFileNext (void* handle, String& resultFile,
  180431. bool* isDir, bool* isHidden, int64* fileSize,
  180432. Time* modTime, Time* creationTime, bool* isReadOnly)
  180433. {
  180434. WIN32_FIND_DATA findData;
  180435. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  180436. {
  180437. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  180438. modTime, creationTime, isReadOnly);
  180439. return true;
  180440. }
  180441. resultFile = String::empty;
  180442. return false;
  180443. }
  180444. void juce_findFileClose (void* handle)
  180445. {
  180446. FindClose (handle);
  180447. }
  180448. bool juce_launchFile (const String& fileName,
  180449. const String& parameters)
  180450. {
  180451. HINSTANCE hInstance = 0;
  180452. JUCE_TRY
  180453. {
  180454. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180455. }
  180456. JUCE_CATCH_ALL
  180457. return hInstance > (HINSTANCE) 32;
  180458. }
  180459. void File::revealToUser() const
  180460. {
  180461. if (isDirectory())
  180462. startAsProcess();
  180463. else if (getParentDirectory().exists())
  180464. getParentDirectory().startAsProcess();
  180465. }
  180466. struct NamedPipeInternal
  180467. {
  180468. HANDLE pipeH;
  180469. HANDLE cancelEvent;
  180470. bool connected, createdPipe;
  180471. NamedPipeInternal()
  180472. : pipeH (0),
  180473. cancelEvent (0),
  180474. connected (false),
  180475. createdPipe (false)
  180476. {
  180477. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180478. }
  180479. ~NamedPipeInternal()
  180480. {
  180481. disconnect();
  180482. if (pipeH != 0)
  180483. CloseHandle (pipeH);
  180484. CloseHandle (cancelEvent);
  180485. }
  180486. bool connect (const int timeOutMs)
  180487. {
  180488. if (! createdPipe)
  180489. return true;
  180490. if (! connected)
  180491. {
  180492. OVERLAPPED over;
  180493. zerostruct (over);
  180494. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180495. if (ConnectNamedPipe (pipeH, &over))
  180496. {
  180497. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180498. }
  180499. else
  180500. {
  180501. const int err = GetLastError();
  180502. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180503. {
  180504. HANDLE handles[] = { over.hEvent, cancelEvent };
  180505. if (WaitForMultipleObjects (2, handles, FALSE,
  180506. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180507. connected = true;
  180508. }
  180509. else if (err == ERROR_PIPE_CONNECTED)
  180510. {
  180511. connected = true;
  180512. }
  180513. }
  180514. CloseHandle (over.hEvent);
  180515. }
  180516. return connected;
  180517. }
  180518. void disconnect()
  180519. {
  180520. if (connected)
  180521. {
  180522. DisconnectNamedPipe (pipeH);
  180523. connected = false;
  180524. }
  180525. }
  180526. };
  180527. void NamedPipe::close()
  180528. {
  180529. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180530. delete intern;
  180531. internal = 0;
  180532. }
  180533. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180534. {
  180535. close();
  180536. NamedPipeInternal* const intern = new NamedPipeInternal();
  180537. String file ("\\\\.\\pipe\\");
  180538. file += pipeName;
  180539. intern->createdPipe = createPipe;
  180540. if (createPipe)
  180541. {
  180542. intern->pipeH = CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180543. PIPE_UNLIMITED_INSTANCES,
  180544. 4096, 4096, 0, NULL);
  180545. }
  180546. else
  180547. {
  180548. intern->pipeH = CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
  180549. FILE_FLAG_OVERLAPPED, 0);
  180550. }
  180551. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180552. {
  180553. internal = intern;
  180554. return true;
  180555. }
  180556. delete intern;
  180557. return false;
  180558. }
  180559. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180560. {
  180561. int bytesRead = -1;
  180562. bool waitAgain = true;
  180563. while (waitAgain && internal != 0)
  180564. {
  180565. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180566. waitAgain = false;
  180567. if (! intern->connect (timeOutMilliseconds))
  180568. break;
  180569. if (maxBytesToRead <= 0)
  180570. return 0;
  180571. OVERLAPPED over;
  180572. zerostruct (over);
  180573. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180574. unsigned long numRead;
  180575. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180576. {
  180577. bytesRead = (int) numRead;
  180578. }
  180579. else if (GetLastError() == ERROR_IO_PENDING)
  180580. {
  180581. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180582. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180583. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180584. : INFINITE);
  180585. if (waitResult != WAIT_OBJECT_0)
  180586. {
  180587. // if the operation timed out, let's cancel it...
  180588. CancelIo (intern->pipeH);
  180589. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180590. }
  180591. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180592. {
  180593. bytesRead = (int) numRead;
  180594. }
  180595. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180596. {
  180597. intern->disconnect();
  180598. waitAgain = true;
  180599. }
  180600. }
  180601. else
  180602. {
  180603. waitAgain = internal != 0;
  180604. Sleep (5);
  180605. }
  180606. CloseHandle (over.hEvent);
  180607. }
  180608. return bytesRead;
  180609. }
  180610. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180611. {
  180612. int bytesWritten = -1;
  180613. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180614. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180615. {
  180616. if (numBytesToWrite <= 0)
  180617. return 0;
  180618. OVERLAPPED over;
  180619. zerostruct (over);
  180620. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180621. unsigned long numWritten;
  180622. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180623. {
  180624. bytesWritten = (int) numWritten;
  180625. }
  180626. else if (GetLastError() == ERROR_IO_PENDING)
  180627. {
  180628. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180629. DWORD waitResult;
  180630. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180631. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180632. : INFINITE);
  180633. if (waitResult != WAIT_OBJECT_0)
  180634. {
  180635. CancelIo (intern->pipeH);
  180636. WaitForSingleObject (over.hEvent, INFINITE);
  180637. }
  180638. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180639. {
  180640. bytesWritten = (int) numWritten;
  180641. }
  180642. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180643. {
  180644. intern->disconnect();
  180645. }
  180646. }
  180647. CloseHandle (over.hEvent);
  180648. }
  180649. return bytesWritten;
  180650. }
  180651. void NamedPipe::cancelPendingReads()
  180652. {
  180653. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180654. if (intern != 0)
  180655. SetEvent (intern->cancelEvent);
  180656. }
  180657. #endif
  180658. /*** End of inlined file: juce_win32_Files.cpp ***/
  180659. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180660. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180661. // compiled on its own).
  180662. #if JUCE_INCLUDED_FILE
  180663. #ifndef INTERNET_FLAG_NEED_FILE
  180664. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180665. #endif
  180666. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180667. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180668. #endif
  180669. bool juce_isOnLine()
  180670. {
  180671. DWORD connectionType;
  180672. return InternetGetConnectedState (&connectionType, 0) != 0
  180673. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  180674. }
  180675. struct ConnectionAndRequestStruct
  180676. {
  180677. HINTERNET connection, request;
  180678. };
  180679. static HINTERNET sessionHandle = 0;
  180680. #ifndef WORKAROUND_TIMEOUT_BUG
  180681. //#define WORKAROUND_TIMEOUT_BUG 1
  180682. #endif
  180683. #if WORKAROUND_TIMEOUT_BUG
  180684. // Required because of a Microsoft bug in setting a timeout
  180685. class InternetConnectThread : public Thread
  180686. {
  180687. public:
  180688. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  180689. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  180690. {
  180691. startThread();
  180692. }
  180693. ~InternetConnectThread()
  180694. {
  180695. stopThread (60000);
  180696. }
  180697. void run()
  180698. {
  180699. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  180700. uc.nPort, _T(""), _T(""),
  180701. isFtp ? INTERNET_SERVICE_FTP
  180702. : INTERNET_SERVICE_HTTP,
  180703. 0, 0);
  180704. notify();
  180705. }
  180706. juce_UseDebuggingNewOperator
  180707. private:
  180708. URL_COMPONENTS& uc;
  180709. HINTERNET& connection;
  180710. const bool isFtp;
  180711. InternetConnectThread (const InternetConnectThread&);
  180712. InternetConnectThread& operator= (const InternetConnectThread&);
  180713. };
  180714. #endif
  180715. void* juce_openInternetFile (const String& url,
  180716. const String& headers,
  180717. const MemoryBlock& postData,
  180718. const bool isPost,
  180719. URL::OpenStreamProgressCallback* callback,
  180720. void* callbackContext,
  180721. int timeOutMs)
  180722. {
  180723. if (sessionHandle == 0)
  180724. sessionHandle = InternetOpen (_T("juce"),
  180725. INTERNET_OPEN_TYPE_PRECONFIG,
  180726. 0, 0, 0);
  180727. if (sessionHandle != 0)
  180728. {
  180729. // break up the url..
  180730. TCHAR file[1024], server[1024];
  180731. URL_COMPONENTS uc;
  180732. zerostruct (uc);
  180733. uc.dwStructSize = sizeof (uc);
  180734. uc.dwUrlPathLength = sizeof (file);
  180735. uc.dwHostNameLength = sizeof (server);
  180736. uc.lpszUrlPath = file;
  180737. uc.lpszHostName = server;
  180738. if (InternetCrackUrl (url, 0, 0, &uc))
  180739. {
  180740. int disable = 1;
  180741. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  180742. if (timeOutMs == 0)
  180743. timeOutMs = 30000;
  180744. else if (timeOutMs < 0)
  180745. timeOutMs = -1;
  180746. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  180747. const bool isFtp = url.startsWithIgnoreCase (T("ftp:"));
  180748. #if WORKAROUND_TIMEOUT_BUG
  180749. HINTERNET connection = 0;
  180750. {
  180751. InternetConnectThread connectThread (uc, connection, isFtp);
  180752. connectThread.wait (timeOutMs);
  180753. if (connection == 0)
  180754. {
  180755. InternetCloseHandle (sessionHandle);
  180756. sessionHandle = 0;
  180757. }
  180758. }
  180759. #else
  180760. HINTERNET connection = InternetConnect (sessionHandle,
  180761. uc.lpszHostName,
  180762. uc.nPort,
  180763. _T(""), _T(""),
  180764. isFtp ? INTERNET_SERVICE_FTP
  180765. : INTERNET_SERVICE_HTTP,
  180766. 0, 0);
  180767. #endif
  180768. if (connection != 0)
  180769. {
  180770. if (isFtp)
  180771. {
  180772. HINTERNET request = FtpOpenFile (connection,
  180773. uc.lpszUrlPath,
  180774. GENERIC_READ,
  180775. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  180776. 0);
  180777. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  180778. result->connection = connection;
  180779. result->request = request;
  180780. return result;
  180781. }
  180782. else
  180783. {
  180784. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  180785. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  180786. if (url.startsWithIgnoreCase (T("https:")))
  180787. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  180788. // IE7 seems to automatically work out when it's https)
  180789. HINTERNET request = HttpOpenRequest (connection,
  180790. isPost ? _T("POST")
  180791. : _T("GET"),
  180792. uc.lpszUrlPath,
  180793. 0, 0, mimeTypes, flags, 0);
  180794. if (request != 0)
  180795. {
  180796. INTERNET_BUFFERS buffers;
  180797. zerostruct (buffers);
  180798. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  180799. buffers.lpcszHeader = (LPCTSTR) headers;
  180800. buffers.dwHeadersLength = headers.length();
  180801. buffers.dwBufferTotal = (DWORD) postData.getSize();
  180802. ConnectionAndRequestStruct* result = 0;
  180803. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  180804. {
  180805. int bytesSent = 0;
  180806. for (;;)
  180807. {
  180808. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  180809. DWORD bytesDone = 0;
  180810. if (bytesToDo > 0
  180811. && ! InternetWriteFile (request,
  180812. ((const char*) postData.getData()) + bytesSent,
  180813. bytesToDo, &bytesDone))
  180814. {
  180815. break;
  180816. }
  180817. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  180818. {
  180819. result = new ConnectionAndRequestStruct();
  180820. result->connection = connection;
  180821. result->request = request;
  180822. HttpEndRequest (request, 0, 0, 0);
  180823. return result;
  180824. }
  180825. bytesSent += bytesDone;
  180826. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  180827. break;
  180828. }
  180829. }
  180830. InternetCloseHandle (request);
  180831. }
  180832. InternetCloseHandle (connection);
  180833. }
  180834. }
  180835. }
  180836. }
  180837. return 0;
  180838. }
  180839. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  180840. {
  180841. DWORD bytesRead = 0;
  180842. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180843. if (crs != 0)
  180844. InternetReadFile (crs->request,
  180845. buffer, bytesToRead,
  180846. &bytesRead);
  180847. return bytesRead;
  180848. }
  180849. int juce_seekInInternetFile (void* handle, int newPosition)
  180850. {
  180851. if (handle != 0)
  180852. {
  180853. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180854. return InternetSetFilePointer (crs->request,
  180855. newPosition, 0,
  180856. FILE_BEGIN, 0);
  180857. }
  180858. else
  180859. {
  180860. return -1;
  180861. }
  180862. }
  180863. int64 juce_getInternetFileContentLength (void* handle)
  180864. {
  180865. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180866. if (crs != 0)
  180867. {
  180868. DWORD index = 0;
  180869. DWORD result = 0;
  180870. DWORD size = sizeof (result);
  180871. if (HttpQueryInfo (crs->request,
  180872. HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  180873. &result,
  180874. &size,
  180875. &index))
  180876. {
  180877. return (int64) result;
  180878. }
  180879. }
  180880. return -1;
  180881. }
  180882. void juce_closeInternetFile (void* handle)
  180883. {
  180884. if (handle != 0)
  180885. {
  180886. ConnectionAndRequestStruct* const crs = (ConnectionAndRequestStruct*) handle;
  180887. InternetCloseHandle (crs->request);
  180888. InternetCloseHandle (crs->connection);
  180889. delete crs;
  180890. }
  180891. }
  180892. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  180893. {
  180894. int numFound = 0;
  180895. DynamicLibraryLoader dll ("iphlpapi.dll");
  180896. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  180897. if (getAdaptersInfo != 0)
  180898. {
  180899. ULONG len = sizeof (IP_ADAPTER_INFO);
  180900. MemoryBlock mb;
  180901. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180902. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  180903. {
  180904. mb.setSize (len);
  180905. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180906. }
  180907. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  180908. {
  180909. PIP_ADAPTER_INFO adapter = adapterInfo;
  180910. while (adapter != 0)
  180911. {
  180912. int64 mac = 0;
  180913. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  180914. mac = (mac << 8) | adapter->Address[i];
  180915. if (littleEndian)
  180916. mac = (int64) ByteOrder::swap ((uint64) mac);
  180917. if (numFound < maxNum && mac != 0)
  180918. addresses [numFound++] = mac;
  180919. adapter = adapter->Next;
  180920. }
  180921. }
  180922. }
  180923. return numFound;
  180924. }
  180925. struct ASTAT
  180926. {
  180927. ADAPTER_STATUS adapt;
  180928. NAME_BUFFER NameBuff [30];
  180929. };
  180930. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  180931. {
  180932. int numFound = 0;
  180933. DynamicLibraryLoader dll ("netapi32.dll");
  180934. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  180935. if (NetbiosCall != 0)
  180936. {
  180937. NCB ncb;
  180938. zerostruct (ncb);
  180939. ASTAT astat;
  180940. zerostruct (astat);
  180941. LANA_ENUM enums;
  180942. zerostruct (enums);
  180943. ncb.ncb_command = NCBENUM;
  180944. ncb.ncb_buffer = (unsigned char*) &enums;
  180945. ncb.ncb_length = sizeof (LANA_ENUM);
  180946. NetbiosCall (&ncb);
  180947. for (int i = 0; i < enums.length; ++i)
  180948. {
  180949. zerostruct (ncb);
  180950. ncb.ncb_command = NCBRESET;
  180951. ncb.ncb_lana_num = enums.lana[i];
  180952. if (NetbiosCall (&ncb) == 0)
  180953. {
  180954. zerostruct (ncb);
  180955. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  180956. ncb.ncb_command = NCBASTAT;
  180957. ncb.ncb_lana_num = enums.lana[i];
  180958. ncb.ncb_buffer = (unsigned char*) &astat;
  180959. ncb.ncb_length = sizeof (ASTAT);
  180960. if (NetbiosCall (&ncb) == 0)
  180961. {
  180962. if (astat.adapt.adapter_type == 0xfe)
  180963. {
  180964. uint64 mac = 0;
  180965. for (int i = 6; --i >= 0;)
  180966. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  180967. if (numFound < maxNum && mac != 0)
  180968. addresses [numFound++] = mac;
  180969. }
  180970. }
  180971. }
  180972. }
  180973. }
  180974. return numFound;
  180975. }
  180976. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  180977. {
  180978. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  180979. if (numFound == 0)
  180980. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  180981. return numFound;
  180982. }
  180983. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  180984. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  180985. const String& emailSubject,
  180986. const String& bodyText,
  180987. const StringArray& filesToAttach)
  180988. {
  180989. HMODULE h = LoadLibraryA ("MAPI32.dll");
  180990. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  180991. bool ok = false;
  180992. if (mapiSendMail != 0)
  180993. {
  180994. MapiMessage message;
  180995. zerostruct (message);
  180996. message.lpszSubject = (LPSTR) emailSubject.toCString();
  180997. message.lpszNoteText = (LPSTR) bodyText.toCString();
  180998. MapiRecipDesc recip;
  180999. zerostruct (recip);
  181000. recip.ulRecipClass = MAPI_TO;
  181001. String targetEmailAddress_ (targetEmailAddress);
  181002. if (targetEmailAddress_.isEmpty())
  181003. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  181004. recip.lpszName = (LPSTR) targetEmailAddress_.toCString();
  181005. message.nRecipCount = 1;
  181006. message.lpRecips = &recip;
  181007. MemoryBlock mb (sizeof (MapiFileDesc) * filesToAttach.size());
  181008. mb.fillWith (0);
  181009. MapiFileDesc* files = (MapiFileDesc*) mb.getData();
  181010. message.nFileCount = filesToAttach.size();
  181011. message.lpFiles = files;
  181012. for (int i = 0; i < filesToAttach.size(); ++i)
  181013. {
  181014. files[i].nPosition = (ULONG) -1;
  181015. files[i].lpszPathName = (LPSTR) filesToAttach[i].toCString();
  181016. }
  181017. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  181018. }
  181019. FreeLibrary (h);
  181020. return ok;
  181021. }
  181022. #endif
  181023. /*** End of inlined file: juce_win32_Network.cpp ***/
  181024. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  181025. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181026. // compiled on its own).
  181027. #if JUCE_INCLUDED_FILE
  181028. static HKEY findKeyForPath (String name,
  181029. const bool createForWriting,
  181030. String& valueName)
  181031. {
  181032. HKEY rootKey = 0;
  181033. if (name.startsWithIgnoreCase (T("HKEY_CURRENT_USER\\")))
  181034. rootKey = HKEY_CURRENT_USER;
  181035. else if (name.startsWithIgnoreCase (T("HKEY_LOCAL_MACHINE\\")))
  181036. rootKey = HKEY_LOCAL_MACHINE;
  181037. else if (name.startsWithIgnoreCase (T("HKEY_CLASSES_ROOT\\")))
  181038. rootKey = HKEY_CLASSES_ROOT;
  181039. if (rootKey != 0)
  181040. {
  181041. name = name.substring (name.indexOfChar (T('\\')) + 1);
  181042. const int lastSlash = name.lastIndexOfChar (T('\\'));
  181043. valueName = name.substring (lastSlash + 1);
  181044. name = name.substring (0, lastSlash);
  181045. HKEY key;
  181046. DWORD result;
  181047. if (createForWriting)
  181048. {
  181049. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  181050. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  181051. return key;
  181052. }
  181053. else
  181054. {
  181055. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  181056. return key;
  181057. }
  181058. }
  181059. return 0;
  181060. }
  181061. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  181062. const String& defaultValue)
  181063. {
  181064. String valueName, result (defaultValue);
  181065. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181066. if (k != 0)
  181067. {
  181068. WCHAR buffer [2048];
  181069. unsigned long bufferSize = sizeof (buffer);
  181070. DWORD type = REG_SZ;
  181071. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  181072. {
  181073. if (type == REG_SZ)
  181074. result = buffer;
  181075. else if (type == REG_DWORD)
  181076. result = String ((int) *(DWORD*) buffer);
  181077. }
  181078. RegCloseKey (k);
  181079. }
  181080. return result;
  181081. }
  181082. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  181083. const String& value)
  181084. {
  181085. String valueName;
  181086. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181087. if (k != 0)
  181088. {
  181089. RegSetValueEx (k, valueName, 0, REG_SZ,
  181090. (const BYTE*) (const WCHAR*) value,
  181091. sizeof (WCHAR) * (value.length() + 1));
  181092. RegCloseKey (k);
  181093. }
  181094. }
  181095. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  181096. {
  181097. bool exists = false;
  181098. String valueName;
  181099. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181100. if (k != 0)
  181101. {
  181102. unsigned char buffer [2048];
  181103. unsigned long bufferSize = sizeof (buffer);
  181104. DWORD type = 0;
  181105. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  181106. exists = true;
  181107. RegCloseKey (k);
  181108. }
  181109. return exists;
  181110. }
  181111. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  181112. {
  181113. String valueName;
  181114. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181115. if (k != 0)
  181116. {
  181117. RegDeleteValue (k, valueName);
  181118. RegCloseKey (k);
  181119. }
  181120. }
  181121. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  181122. {
  181123. String valueName;
  181124. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  181125. if (k != 0)
  181126. {
  181127. RegDeleteKey (k, valueName);
  181128. RegCloseKey (k);
  181129. }
  181130. }
  181131. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  181132. const String& symbolicDescription,
  181133. const String& fullDescription,
  181134. const File& targetExecutable,
  181135. int iconResourceNumber)
  181136. {
  181137. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  181138. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  181139. if (iconResourceNumber != 0)
  181140. setRegistryValue (key + "\\DefaultIcon\\",
  181141. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  181142. setRegistryValue (key + "\\", fullDescription);
  181143. setRegistryValue (key + "\\shell\\open\\command\\",
  181144. targetExecutable.getFullPathName() + " %1");
  181145. }
  181146. bool juce_IsRunningInWine()
  181147. {
  181148. HKEY key;
  181149. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  181150. {
  181151. RegCloseKey (key);
  181152. return true;
  181153. }
  181154. return false;
  181155. }
  181156. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  181157. {
  181158. String s (::GetCommandLineW());
  181159. StringArray tokens;
  181160. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  181161. return tokens.joinIntoString (T(" "), 1);
  181162. }
  181163. static void* currentModuleHandle = 0;
  181164. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  181165. {
  181166. if (currentModuleHandle == 0)
  181167. currentModuleHandle = GetModuleHandle (0);
  181168. return currentModuleHandle;
  181169. }
  181170. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  181171. {
  181172. currentModuleHandle = newHandle;
  181173. }
  181174. void PlatformUtilities::fpuReset()
  181175. {
  181176. #if JUCE_MSVC
  181177. _clearfp();
  181178. #endif
  181179. }
  181180. void PlatformUtilities::beep()
  181181. {
  181182. MessageBeep (MB_OK);
  181183. }
  181184. #endif
  181185. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  181186. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  181187. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  181188. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181189. // compiled on its own).
  181190. #if JUCE_INCLUDED_FILE
  181191. static const unsigned int specialId = WM_APP + 0x4400;
  181192. static const unsigned int broadcastId = WM_APP + 0x4403;
  181193. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  181194. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  181195. HWND juce_messageWindowHandle = 0;
  181196. extern long improbableWindowNumber; // defined in windowing.cpp
  181197. #ifndef WM_APPCOMMAND
  181198. #define WM_APPCOMMAND 0x0319
  181199. #endif
  181200. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  181201. const UINT message,
  181202. const WPARAM wParam,
  181203. const LPARAM lParam) throw()
  181204. {
  181205. JUCE_TRY
  181206. {
  181207. if (h == juce_messageWindowHandle)
  181208. {
  181209. if (message == specialCallbackId)
  181210. {
  181211. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  181212. return (LRESULT) (*func) ((void*) lParam);
  181213. }
  181214. else if (message == specialId)
  181215. {
  181216. // these are trapped early in the dispatch call, but must also be checked
  181217. // here in case there are windows modal dialog boxes doing their own
  181218. // dispatch loop and not calling our version
  181219. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  181220. return 0;
  181221. }
  181222. else if (message == broadcastId)
  181223. {
  181224. const ScopedPointer <String> messageString ((String*) lParam);
  181225. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  181226. return 0;
  181227. }
  181228. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  181229. {
  181230. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  181231. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  181232. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  181233. return 0;
  181234. }
  181235. }
  181236. }
  181237. JUCE_CATCH_EXCEPTION
  181238. return DefWindowProc (h, message, wParam, lParam);
  181239. }
  181240. static bool isEventBlockedByModalComps (MSG& m)
  181241. {
  181242. if (Component::getNumCurrentlyModalComponents() == 0
  181243. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  181244. return false;
  181245. switch (m.message)
  181246. {
  181247. case WM_MOUSEMOVE:
  181248. case WM_NCMOUSEMOVE:
  181249. case 0x020A: /* WM_MOUSEWHEEL */
  181250. case 0x020E: /* WM_MOUSEHWHEEL */
  181251. case WM_KEYUP:
  181252. case WM_SYSKEYUP:
  181253. case WM_CHAR:
  181254. case WM_APPCOMMAND:
  181255. case WM_LBUTTONUP:
  181256. case WM_MBUTTONUP:
  181257. case WM_RBUTTONUP:
  181258. case WM_MOUSEACTIVATE:
  181259. case WM_NCMOUSEHOVER:
  181260. case WM_MOUSEHOVER:
  181261. return true;
  181262. case WM_NCLBUTTONDOWN:
  181263. case WM_NCLBUTTONDBLCLK:
  181264. case WM_NCRBUTTONDOWN:
  181265. case WM_NCRBUTTONDBLCLK:
  181266. case WM_NCMBUTTONDOWN:
  181267. case WM_NCMBUTTONDBLCLK:
  181268. case WM_LBUTTONDOWN:
  181269. case WM_LBUTTONDBLCLK:
  181270. case WM_MBUTTONDOWN:
  181271. case WM_MBUTTONDBLCLK:
  181272. case WM_RBUTTONDOWN:
  181273. case WM_RBUTTONDBLCLK:
  181274. case WM_KEYDOWN:
  181275. case WM_SYSKEYDOWN:
  181276. {
  181277. Component* const modal = Component::getCurrentlyModalComponent (0);
  181278. if (modal != 0)
  181279. modal->inputAttemptWhenModal();
  181280. return true;
  181281. }
  181282. default:
  181283. break;
  181284. }
  181285. return false;
  181286. }
  181287. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  181288. {
  181289. MSG m;
  181290. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  181291. return false;
  181292. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  181293. {
  181294. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  181295. {
  181296. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  181297. }
  181298. else if (m.message == WM_QUIT)
  181299. {
  181300. if (JUCEApplication::getInstance())
  181301. JUCEApplication::getInstance()->systemRequestedQuit();
  181302. }
  181303. else if (! isEventBlockedByModalComps (m))
  181304. {
  181305. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  181306. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  181307. {
  181308. // if it's someone else's window being clicked on, and the focus is
  181309. // currently on a juce window, pass the kb focus over..
  181310. HWND currentFocus = GetFocus();
  181311. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  181312. SetFocus (m.hwnd);
  181313. }
  181314. TranslateMessage (&m);
  181315. DispatchMessage (&m);
  181316. }
  181317. }
  181318. return true;
  181319. }
  181320. bool juce_postMessageToSystemQueue (void* message)
  181321. {
  181322. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181323. }
  181324. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181325. void* userData)
  181326. {
  181327. if (MessageManager::getInstance()->isThisTheMessageThread())
  181328. {
  181329. return (*callback) (userData);
  181330. }
  181331. else
  181332. {
  181333. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181334. // deadlock because the message manager is blocked from running, and can't
  181335. // call your function..
  181336. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181337. return (void*) SendMessage (juce_messageWindowHandle,
  181338. specialCallbackId,
  181339. (WPARAM) callback,
  181340. (LPARAM) userData);
  181341. }
  181342. }
  181343. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181344. {
  181345. if (hwnd != juce_messageWindowHandle)
  181346. (reinterpret_cast <VoidArray*> (lParam))->add ((void*) hwnd);
  181347. return TRUE;
  181348. }
  181349. void MessageManager::broadcastMessage (const String& value) throw()
  181350. {
  181351. VoidArray windows;
  181352. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181353. const String localCopy (value);
  181354. COPYDATASTRUCT data;
  181355. data.dwData = broadcastId;
  181356. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181357. data.lpData = (void*) (const juce_wchar*) localCopy;
  181358. for (int i = windows.size(); --i >= 0;)
  181359. {
  181360. HWND hwnd = (HWND) windows.getUnchecked(i);
  181361. TCHAR windowName [64]; // no need to read longer strings than this
  181362. GetWindowText (hwnd, windowName, 64);
  181363. windowName [63] = 0;
  181364. if (String (windowName) == String (messageWindowName))
  181365. {
  181366. DWORD_PTR result;
  181367. SendMessageTimeout (hwnd, WM_COPYDATA,
  181368. (WPARAM) juce_messageWindowHandle,
  181369. (LPARAM) &data,
  181370. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181371. 8000,
  181372. &result);
  181373. }
  181374. }
  181375. }
  181376. static const String getMessageWindowClassName()
  181377. {
  181378. // this name has to be different for each app/dll instance because otherwise
  181379. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181380. // window class).
  181381. static int number = 0;
  181382. if (number == 0)
  181383. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181384. return T("JUCEcs_") + String (number);
  181385. }
  181386. void MessageManager::doPlatformSpecificInitialisation()
  181387. {
  181388. OleInitialize (0);
  181389. const String className (getMessageWindowClassName());
  181390. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181391. WNDCLASSEX wc;
  181392. zerostruct (wc);
  181393. wc.cbSize = sizeof (wc);
  181394. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181395. wc.cbWndExtra = 4;
  181396. wc.hInstance = hmod;
  181397. wc.lpszClassName = className;
  181398. RegisterClassEx (&wc);
  181399. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181400. messageWindowName,
  181401. 0, 0, 0, 0, 0, 0, 0,
  181402. hmod, 0);
  181403. }
  181404. void MessageManager::doPlatformSpecificShutdown()
  181405. {
  181406. DestroyWindow (juce_messageWindowHandle);
  181407. UnregisterClass (getMessageWindowClassName(), 0);
  181408. OleUninitialize();
  181409. }
  181410. #endif
  181411. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  181412. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  181413. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181414. // compiled on its own).
  181415. #if JUCE_INCLUDED_FILE
  181416. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181417. // these are in the windows SDK, but need to be repeated here for GCC..
  181418. #ifndef GET_APPCOMMAND_LPARAM
  181419. #define FAPPCOMMAND_MASK 0xF000
  181420. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181421. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181422. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181423. #define APPCOMMAND_MEDIA_STOP 13
  181424. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181425. #define WM_APPCOMMAND 0x0319
  181426. #endif
  181427. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181428. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181429. extern bool juce_IsRunningInWine();
  181430. #ifndef ULW_ALPHA
  181431. #define ULW_ALPHA 0x00000002
  181432. #endif
  181433. #ifndef AC_SRC_ALPHA
  181434. #define AC_SRC_ALPHA 0x01
  181435. #endif
  181436. #define DEBUG_REPAINT_TIMES 0
  181437. static HPALETTE palette = 0;
  181438. static bool createPaletteIfNeeded = true;
  181439. static bool shouldDeactivateTitleBar = true;
  181440. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181441. #define WM_TRAYNOTIFY WM_USER + 100
  181442. using ::abs;
  181443. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181444. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181445. bool Desktop::canUseSemiTransparentWindows() throw()
  181446. {
  181447. if (updateLayeredWindow == 0)
  181448. {
  181449. if (! juce_IsRunningInWine())
  181450. {
  181451. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181452. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181453. }
  181454. }
  181455. return updateLayeredWindow != 0;
  181456. }
  181457. #undef DefWindowProc
  181458. #define DefWindowProc DefWindowProcW
  181459. const int extendedKeyModifier = 0x10000;
  181460. const int KeyPress::spaceKey = VK_SPACE;
  181461. const int KeyPress::returnKey = VK_RETURN;
  181462. const int KeyPress::escapeKey = VK_ESCAPE;
  181463. const int KeyPress::backspaceKey = VK_BACK;
  181464. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181465. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181466. const int KeyPress::tabKey = VK_TAB;
  181467. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181468. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181469. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181470. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181471. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181472. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181473. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181474. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181475. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181476. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181477. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181478. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181479. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181480. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181481. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181482. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181483. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181484. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181485. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181486. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181487. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181488. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181489. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181490. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181491. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181492. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181493. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181494. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181495. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181496. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181497. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181498. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181499. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181500. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181501. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181502. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181503. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181504. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181505. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181506. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181507. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181508. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181509. const int KeyPress::playKey = 0x30000;
  181510. const int KeyPress::stopKey = 0x30001;
  181511. const int KeyPress::fastForwardKey = 0x30002;
  181512. const int KeyPress::rewindKey = 0x30003;
  181513. class WindowsBitmapImage : public Image
  181514. {
  181515. public:
  181516. HBITMAP hBitmap;
  181517. BITMAPV4HEADER bitmapInfo;
  181518. HDC hdc;
  181519. unsigned char* bitmapData;
  181520. WindowsBitmapImage (const PixelFormat format_,
  181521. const int w, const int h, const bool clearImage)
  181522. : Image (format_, w, h)
  181523. {
  181524. jassert (format_ == RGB || format_ == ARGB);
  181525. pixelStride = (format_ == RGB) ? 3 : 4;
  181526. zerostruct (bitmapInfo);
  181527. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181528. bitmapInfo.bV4Width = w;
  181529. bitmapInfo.bV4Height = h;
  181530. bitmapInfo.bV4Planes = 1;
  181531. bitmapInfo.bV4CSType = 1;
  181532. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181533. if (format_ == ARGB)
  181534. {
  181535. bitmapInfo.bV4AlphaMask = 0xff000000;
  181536. bitmapInfo.bV4RedMask = 0xff0000;
  181537. bitmapInfo.bV4GreenMask = 0xff00;
  181538. bitmapInfo.bV4BlueMask = 0xff;
  181539. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181540. }
  181541. else
  181542. {
  181543. bitmapInfo.bV4V4Compression = BI_RGB;
  181544. }
  181545. lineStride = -((w * pixelStride + 3) & ~3);
  181546. HDC dc = GetDC (0);
  181547. hdc = CreateCompatibleDC (dc);
  181548. ReleaseDC (0, dc);
  181549. SetMapMode (hdc, MM_TEXT);
  181550. hBitmap = CreateDIBSection (hdc,
  181551. (BITMAPINFO*) &(bitmapInfo),
  181552. DIB_RGB_COLORS,
  181553. (void**) &bitmapData,
  181554. 0, 0);
  181555. SelectObject (hdc, hBitmap);
  181556. if (format_ == ARGB && clearImage)
  181557. zeromem (bitmapData, abs (h * lineStride));
  181558. imageData = bitmapData - (lineStride * (h - 1));
  181559. }
  181560. ~WindowsBitmapImage()
  181561. {
  181562. DeleteDC (hdc);
  181563. DeleteObject (hBitmap);
  181564. }
  181565. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181566. const int x, const int y,
  181567. const RectangleList& maskedRegion) throw()
  181568. {
  181569. static HDRAWDIB hdd = 0;
  181570. static bool needToCreateDrawDib = true;
  181571. if (needToCreateDrawDib)
  181572. {
  181573. needToCreateDrawDib = false;
  181574. HDC dc = GetDC (0);
  181575. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181576. ReleaseDC (0, dc);
  181577. // only open if we're not palettised
  181578. if (n > 8)
  181579. hdd = DrawDibOpen();
  181580. }
  181581. if (createPaletteIfNeeded)
  181582. {
  181583. HDC dc = GetDC (0);
  181584. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181585. ReleaseDC (0, dc);
  181586. if (n <= 8)
  181587. palette = CreateHalftonePalette (dc);
  181588. createPaletteIfNeeded = false;
  181589. }
  181590. if (palette != 0)
  181591. {
  181592. SelectPalette (dc, palette, FALSE);
  181593. RealizePalette (dc);
  181594. SetStretchBltMode (dc, HALFTONE);
  181595. }
  181596. SetMapMode (dc, MM_TEXT);
  181597. if (transparent)
  181598. {
  181599. POINT p, pos;
  181600. SIZE size;
  181601. RECT windowBounds;
  181602. GetWindowRect (hwnd, &windowBounds);
  181603. p.x = -x;
  181604. p.y = -y;
  181605. pos.x = windowBounds.left;
  181606. pos.y = windowBounds.top;
  181607. size.cx = windowBounds.right - windowBounds.left;
  181608. size.cy = windowBounds.bottom - windowBounds.top;
  181609. BLENDFUNCTION bf;
  181610. bf.AlphaFormat = AC_SRC_ALPHA;
  181611. bf.BlendFlags = 0;
  181612. bf.BlendOp = AC_SRC_OVER;
  181613. bf.SourceConstantAlpha = 0xff;
  181614. if (! maskedRegion.isEmpty())
  181615. {
  181616. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181617. {
  181618. const Rectangle<int>& r = *i.getRectangle();
  181619. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181620. }
  181621. }
  181622. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181623. }
  181624. else
  181625. {
  181626. int savedDC = 0;
  181627. if (! maskedRegion.isEmpty())
  181628. {
  181629. savedDC = SaveDC (dc);
  181630. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181631. {
  181632. const Rectangle<int>& r = *i.getRectangle();
  181633. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181634. }
  181635. }
  181636. const int w = getWidth();
  181637. const int h = getHeight();
  181638. if (hdd == 0)
  181639. {
  181640. StretchDIBits (dc,
  181641. x, y, w, h,
  181642. 0, 0, w, h,
  181643. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181644. DIB_RGB_COLORS, SRCCOPY);
  181645. }
  181646. else
  181647. {
  181648. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181649. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181650. 0, 0, w, h, 0);
  181651. }
  181652. if (! maskedRegion.isEmpty())
  181653. RestoreDC (dc, savedDC);
  181654. }
  181655. }
  181656. juce_UseDebuggingNewOperator
  181657. private:
  181658. WindowsBitmapImage (const WindowsBitmapImage&);
  181659. WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181660. };
  181661. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181662. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  181663. {
  181664. SHORT k = (SHORT) keyCode;
  181665. if ((keyCode & extendedKeyModifier) == 0
  181666. && (k >= (SHORT) T('a') && k <= (SHORT) T('z')))
  181667. k += (SHORT) T('A') - (SHORT) T('a');
  181668. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  181669. (SHORT) '+', VK_OEM_PLUS,
  181670. (SHORT) '-', VK_OEM_MINUS,
  181671. (SHORT) '.', VK_OEM_PERIOD,
  181672. (SHORT) ';', VK_OEM_1,
  181673. (SHORT) ':', VK_OEM_1,
  181674. (SHORT) '/', VK_OEM_2,
  181675. (SHORT) '?', VK_OEM_2,
  181676. (SHORT) '[', VK_OEM_4,
  181677. (SHORT) ']', VK_OEM_6 };
  181678. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  181679. if (k == translatedValues [i])
  181680. k = translatedValues [i + 1];
  181681. return (GetKeyState (k) & 0x8000) != 0;
  181682. }
  181683. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  181684. {
  181685. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  181686. return callback (userData);
  181687. else
  181688. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  181689. }
  181690. class Win32ComponentPeer : public ComponentPeer
  181691. {
  181692. public:
  181693. Win32ComponentPeer (Component* const component,
  181694. const int windowStyleFlags)
  181695. : ComponentPeer (component, windowStyleFlags),
  181696. dontRepaint (false),
  181697. fullScreen (false),
  181698. isDragging (false),
  181699. isMouseOver (false),
  181700. hasCreatedCaret (false),
  181701. currentWindowIcon (0),
  181702. taskBarIcon (0),
  181703. dropTarget (0)
  181704. {
  181705. callFunctionIfNotLocked (&createWindowCallback, (void*) this);
  181706. setTitle (component->getName());
  181707. if ((windowStyleFlags & windowHasDropShadow) != 0
  181708. && Desktop::canUseSemiTransparentWindows())
  181709. {
  181710. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  181711. if (shadower != 0)
  181712. shadower->setOwner (component);
  181713. }
  181714. else
  181715. {
  181716. shadower = 0;
  181717. }
  181718. }
  181719. ~Win32ComponentPeer()
  181720. {
  181721. setTaskBarIcon (0);
  181722. deleteAndZero (shadower);
  181723. // do this before the next bit to avoid messages arriving for this window
  181724. // before it's destroyed
  181725. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  181726. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  181727. if (currentWindowIcon != 0)
  181728. DestroyIcon (currentWindowIcon);
  181729. if (dropTarget != 0)
  181730. {
  181731. dropTarget->Release();
  181732. dropTarget = 0;
  181733. }
  181734. }
  181735. void* getNativeHandle() const
  181736. {
  181737. return (void*) hwnd;
  181738. }
  181739. void setVisible (bool shouldBeVisible)
  181740. {
  181741. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  181742. if (shouldBeVisible)
  181743. InvalidateRect (hwnd, 0, 0);
  181744. else
  181745. lastPaintTime = 0;
  181746. }
  181747. void setTitle (const String& title)
  181748. {
  181749. SetWindowText (hwnd, title);
  181750. }
  181751. void setPosition (int x, int y)
  181752. {
  181753. offsetWithinParent (x, y);
  181754. SetWindowPos (hwnd, 0,
  181755. x - windowBorder.getLeft(),
  181756. y - windowBorder.getTop(),
  181757. 0, 0,
  181758. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181759. }
  181760. void repaintNowIfTransparent()
  181761. {
  181762. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  181763. handlePaintMessage();
  181764. }
  181765. void updateBorderSize()
  181766. {
  181767. WINDOWINFO info;
  181768. info.cbSize = sizeof (info);
  181769. if (GetWindowInfo (hwnd, &info))
  181770. {
  181771. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  181772. info.rcClient.left - info.rcWindow.left,
  181773. info.rcWindow.bottom - info.rcClient.bottom,
  181774. info.rcWindow.right - info.rcClient.right);
  181775. }
  181776. }
  181777. void setSize (int w, int h)
  181778. {
  181779. SetWindowPos (hwnd, 0, 0, 0,
  181780. w + windowBorder.getLeftAndRight(),
  181781. h + windowBorder.getTopAndBottom(),
  181782. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181783. updateBorderSize();
  181784. repaintNowIfTransparent();
  181785. }
  181786. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  181787. {
  181788. fullScreen = isNowFullScreen;
  181789. offsetWithinParent (x, y);
  181790. SetWindowPos (hwnd, 0,
  181791. x - windowBorder.getLeft(),
  181792. y - windowBorder.getTop(),
  181793. w + windowBorder.getLeftAndRight(),
  181794. h + windowBorder.getTopAndBottom(),
  181795. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181796. updateBorderSize();
  181797. repaintNowIfTransparent();
  181798. }
  181799. const Rectangle<int> getBounds() const
  181800. {
  181801. RECT r;
  181802. GetWindowRect (hwnd, &r);
  181803. Rectangle<int> bounds (r.left, r.top, r.right - r.left, r.bottom - r.top);
  181804. HWND parentH = GetParent (hwnd);
  181805. if (parentH != 0)
  181806. {
  181807. GetWindowRect (parentH, &r);
  181808. bounds.translate (-r.left, -r.top);
  181809. }
  181810. return windowBorder.subtractedFrom (bounds);
  181811. }
  181812. const Point<int> getScreenPosition() const
  181813. {
  181814. RECT r;
  181815. GetWindowRect (hwnd, &r);
  181816. return Point<int> (r.left + windowBorder.getLeft(),
  181817. r.top + windowBorder.getTop());
  181818. }
  181819. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  181820. {
  181821. return relativePosition + getScreenPosition();
  181822. }
  181823. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  181824. {
  181825. return screenPosition - getScreenPosition();
  181826. }
  181827. void setMinimised (bool shouldBeMinimised)
  181828. {
  181829. if (shouldBeMinimised != isMinimised())
  181830. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  181831. }
  181832. bool isMinimised() const
  181833. {
  181834. WINDOWPLACEMENT wp;
  181835. wp.length = sizeof (WINDOWPLACEMENT);
  181836. GetWindowPlacement (hwnd, &wp);
  181837. return wp.showCmd == SW_SHOWMINIMIZED;
  181838. }
  181839. void setFullScreen (bool shouldBeFullScreen)
  181840. {
  181841. setMinimised (false);
  181842. if (fullScreen != shouldBeFullScreen)
  181843. {
  181844. fullScreen = shouldBeFullScreen;
  181845. const Component::SafePointer<Component> deletionChecker (component);
  181846. if (! fullScreen)
  181847. {
  181848. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  181849. if (hasTitleBar())
  181850. ShowWindow (hwnd, SW_SHOWNORMAL);
  181851. if (! boundsCopy.isEmpty())
  181852. {
  181853. setBounds (boundsCopy.getX(),
  181854. boundsCopy.getY(),
  181855. boundsCopy.getWidth(),
  181856. boundsCopy.getHeight(),
  181857. false);
  181858. }
  181859. }
  181860. else
  181861. {
  181862. if (hasTitleBar())
  181863. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  181864. else
  181865. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  181866. }
  181867. if (deletionChecker != 0)
  181868. handleMovedOrResized();
  181869. }
  181870. }
  181871. bool isFullScreen() const
  181872. {
  181873. if (! hasTitleBar())
  181874. return fullScreen;
  181875. WINDOWPLACEMENT wp;
  181876. wp.length = sizeof (wp);
  181877. GetWindowPlacement (hwnd, &wp);
  181878. return wp.showCmd == SW_SHOWMAXIMIZED;
  181879. }
  181880. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  181881. {
  181882. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  181883. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  181884. return false;
  181885. RECT r;
  181886. GetWindowRect (hwnd, &r);
  181887. POINT p;
  181888. p.x = position.getX() + r.left + windowBorder.getLeft();
  181889. p.y = position.getY() + r.top + windowBorder.getTop();
  181890. HWND w = WindowFromPoint (p);
  181891. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  181892. }
  181893. const BorderSize getFrameSize() const
  181894. {
  181895. return windowBorder;
  181896. }
  181897. bool setAlwaysOnTop (bool alwaysOnTop)
  181898. {
  181899. const bool oldDeactivate = shouldDeactivateTitleBar;
  181900. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181901. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  181902. 0, 0, 0, 0,
  181903. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181904. shouldDeactivateTitleBar = oldDeactivate;
  181905. if (shadower != 0)
  181906. shadower->componentBroughtToFront (*component);
  181907. return true;
  181908. }
  181909. void toFront (bool makeActive)
  181910. {
  181911. setMinimised (false);
  181912. const bool oldDeactivate = shouldDeactivateTitleBar;
  181913. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181914. callFunctionIfNotLocked (makeActive ? &toFrontCallback1
  181915. : &toFrontCallback2,
  181916. (void*) hwnd);
  181917. shouldDeactivateTitleBar = oldDeactivate;
  181918. if (! makeActive)
  181919. {
  181920. // in this case a broughttofront call won't have occured, so do it now..
  181921. handleBroughtToFront();
  181922. }
  181923. }
  181924. void toBehind (ComponentPeer* other)
  181925. {
  181926. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  181927. jassert (otherPeer != 0); // wrong type of window?
  181928. if (otherPeer != 0)
  181929. {
  181930. setMinimised (false);
  181931. // must be careful not to try to put a topmost window behind a normal one, or win32
  181932. // promotes the normal one to be topmost!
  181933. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  181934. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  181935. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181936. else if (otherPeer->getComponent()->isAlwaysOnTop())
  181937. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  181938. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181939. }
  181940. }
  181941. bool isFocused() const
  181942. {
  181943. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  181944. }
  181945. void grabFocus()
  181946. {
  181947. const bool oldDeactivate = shouldDeactivateTitleBar;
  181948. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181949. callFunctionIfNotLocked (&setFocusCallback, (void*) hwnd);
  181950. shouldDeactivateTitleBar = oldDeactivate;
  181951. }
  181952. void textInputRequired (const Point<int>&)
  181953. {
  181954. if (! hasCreatedCaret)
  181955. {
  181956. hasCreatedCaret = true;
  181957. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  181958. }
  181959. ShowCaret (hwnd);
  181960. SetCaretPos (0, 0);
  181961. }
  181962. void repaint (int x, int y, int w, int h)
  181963. {
  181964. const RECT r = { x, y, x + w, y + h };
  181965. InvalidateRect (hwnd, &r, FALSE);
  181966. }
  181967. void performAnyPendingRepaintsNow()
  181968. {
  181969. MSG m;
  181970. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  181971. DispatchMessage (&m);
  181972. }
  181973. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  181974. {
  181975. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  181976. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  181977. return 0;
  181978. }
  181979. void setTaskBarIcon (const Image* const image)
  181980. {
  181981. if (image != 0)
  181982. {
  181983. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  181984. if (taskBarIcon == 0)
  181985. {
  181986. taskBarIcon = new NOTIFYICONDATA();
  181987. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  181988. taskBarIcon->hWnd = (HWND) hwnd;
  181989. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  181990. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  181991. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  181992. taskBarIcon->hIcon = hicon;
  181993. taskBarIcon->szTip[0] = 0;
  181994. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  181995. }
  181996. else
  181997. {
  181998. HICON oldIcon = taskBarIcon->hIcon;
  181999. taskBarIcon->hIcon = hicon;
  182000. taskBarIcon->uFlags = NIF_ICON;
  182001. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182002. DestroyIcon (oldIcon);
  182003. }
  182004. DestroyIcon (hicon);
  182005. }
  182006. else if (taskBarIcon != 0)
  182007. {
  182008. taskBarIcon->uFlags = 0;
  182009. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  182010. DestroyIcon (taskBarIcon->hIcon);
  182011. deleteAndZero (taskBarIcon);
  182012. }
  182013. }
  182014. void setTaskBarIconToolTip (const String& toolTip) const
  182015. {
  182016. if (taskBarIcon != 0)
  182017. {
  182018. taskBarIcon->uFlags = NIF_TIP;
  182019. toolTip.copyToUnicode (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  182020. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182021. }
  182022. }
  182023. bool isInside (HWND h) const
  182024. {
  182025. return GetAncestor (hwnd, GA_ROOT) == h;
  182026. }
  182027. static void updateKeyModifiers() throw()
  182028. {
  182029. int keyMods = 0;
  182030. if (GetKeyState (VK_SHIFT) & 0x8000) keyMods |= ModifierKeys::shiftModifier;
  182031. if (GetKeyState (VK_CONTROL) & 0x8000) keyMods |= ModifierKeys::ctrlModifier;
  182032. if (GetKeyState (VK_MENU) & 0x8000) keyMods |= ModifierKeys::altModifier;
  182033. if (GetKeyState (VK_RMENU) & 0x8000) keyMods &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  182034. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  182035. }
  182036. static void updateModifiersFromWParam (const WPARAM wParam)
  182037. {
  182038. int mouseMods = 0;
  182039. if (wParam & MK_LBUTTON) mouseMods |= ModifierKeys::leftButtonModifier;
  182040. if (wParam & MK_RBUTTON) mouseMods |= ModifierKeys::rightButtonModifier;
  182041. if (wParam & MK_MBUTTON) mouseMods |= ModifierKeys::middleButtonModifier;
  182042. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  182043. updateKeyModifiers();
  182044. }
  182045. static int64 getMouseEventTime()
  182046. {
  182047. static int64 eventTimeOffset = 0;
  182048. static DWORD lastMessageTime = 0;
  182049. const DWORD thisMessageTime = GetMessageTime();
  182050. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  182051. {
  182052. lastMessageTime = thisMessageTime;
  182053. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  182054. }
  182055. return eventTimeOffset + thisMessageTime;
  182056. }
  182057. juce_UseDebuggingNewOperator
  182058. bool dontRepaint;
  182059. static ModifierKeys currentModifiers;
  182060. static ModifierKeys modifiersAtLastCallback;
  182061. private:
  182062. HWND hwnd;
  182063. DropShadower* shadower;
  182064. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  182065. BorderSize windowBorder;
  182066. HICON currentWindowIcon;
  182067. NOTIFYICONDATA* taskBarIcon;
  182068. IDropTarget* dropTarget;
  182069. class TemporaryImage : public Timer
  182070. {
  182071. public:
  182072. TemporaryImage()
  182073. : image (0)
  182074. {
  182075. }
  182076. ~TemporaryImage()
  182077. {
  182078. delete image;
  182079. }
  182080. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  182081. {
  182082. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  182083. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  182084. {
  182085. delete image;
  182086. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  182087. }
  182088. startTimer (3000);
  182089. return image;
  182090. }
  182091. void timerCallback()
  182092. {
  182093. stopTimer();
  182094. deleteAndZero (image);
  182095. }
  182096. private:
  182097. WindowsBitmapImage* image;
  182098. TemporaryImage (const TemporaryImage&);
  182099. TemporaryImage& operator= (const TemporaryImage&);
  182100. };
  182101. TemporaryImage offscreenImageGenerator;
  182102. class WindowClassHolder : public DeletedAtShutdown
  182103. {
  182104. public:
  182105. WindowClassHolder()
  182106. : windowClassName ("JUCE_")
  182107. {
  182108. // this name has to be different for each app/dll instance because otherwise
  182109. // poor old Win32 can get a bit confused (even despite it not being a process-global
  182110. // window class).
  182111. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  182112. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  182113. TCHAR moduleFile [1024];
  182114. moduleFile[0] = 0;
  182115. GetModuleFileName (moduleHandle, moduleFile, 1024);
  182116. WORD iconNum = 0;
  182117. WNDCLASSEX wcex;
  182118. wcex.cbSize = sizeof (wcex);
  182119. wcex.style = CS_OWNDC;
  182120. wcex.lpfnWndProc = (WNDPROC) windowProc;
  182121. wcex.lpszClassName = windowClassName;
  182122. wcex.cbClsExtra = 0;
  182123. wcex.cbWndExtra = 32;
  182124. wcex.hInstance = moduleHandle;
  182125. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182126. iconNum = 1;
  182127. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182128. wcex.hCursor = 0;
  182129. wcex.hbrBackground = 0;
  182130. wcex.lpszMenuName = 0;
  182131. RegisterClassEx (&wcex);
  182132. }
  182133. ~WindowClassHolder()
  182134. {
  182135. if (ComponentPeer::getNumPeers() == 0)
  182136. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  182137. clearSingletonInstance();
  182138. }
  182139. String windowClassName;
  182140. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  182141. };
  182142. static void* createWindowCallback (void* userData)
  182143. {
  182144. ((Win32ComponentPeer*) userData)->createWindow();
  182145. return 0;
  182146. }
  182147. void createWindow()
  182148. {
  182149. DWORD exstyle = WS_EX_ACCEPTFILES;
  182150. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  182151. if (hasTitleBar())
  182152. {
  182153. type |= WS_OVERLAPPED;
  182154. exstyle |= WS_EX_APPWINDOW;
  182155. if ((styleFlags & windowHasCloseButton) != 0)
  182156. {
  182157. type |= WS_SYSMENU;
  182158. }
  182159. else
  182160. {
  182161. // annoyingly, windows won't let you have a min/max button without a close button
  182162. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  182163. }
  182164. if ((styleFlags & windowIsResizable) != 0)
  182165. type |= WS_THICKFRAME;
  182166. }
  182167. else
  182168. {
  182169. type |= WS_POPUP | WS_SYSMENU;
  182170. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  182171. exstyle |= WS_EX_TOOLWINDOW;
  182172. else
  182173. exstyle |= WS_EX_APPWINDOW;
  182174. }
  182175. if ((styleFlags & windowHasMinimiseButton) != 0)
  182176. type |= WS_MINIMIZEBOX;
  182177. if ((styleFlags & windowHasMaximiseButton) != 0)
  182178. type |= WS_MAXIMIZEBOX;
  182179. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182180. exstyle |= WS_EX_TRANSPARENT;
  182181. if ((styleFlags & windowIsSemiTransparent) != 0
  182182. && Desktop::canUseSemiTransparentWindows())
  182183. exstyle |= WS_EX_LAYERED;
  182184. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  182185. if (hwnd != 0)
  182186. {
  182187. SetWindowLongPtr (hwnd, 0, 0);
  182188. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  182189. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  182190. if (dropTarget == 0)
  182191. dropTarget = new JuceDropTarget (this);
  182192. RegisterDragDrop (hwnd, dropTarget);
  182193. updateBorderSize();
  182194. // Calling this function here is (for some reason) necessary to make Windows
  182195. // correctly enable the menu items that we specify in the wm_initmenu message.
  182196. GetSystemMenu (hwnd, false);
  182197. }
  182198. else
  182199. {
  182200. jassertfalse
  182201. }
  182202. }
  182203. static void* destroyWindowCallback (void* handle)
  182204. {
  182205. RevokeDragDrop ((HWND) handle);
  182206. DestroyWindow ((HWND) handle);
  182207. return 0;
  182208. }
  182209. static void* toFrontCallback1 (void* h)
  182210. {
  182211. SetForegroundWindow ((HWND) h);
  182212. return 0;
  182213. }
  182214. static void* toFrontCallback2 (void* h)
  182215. {
  182216. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182217. return 0;
  182218. }
  182219. static void* setFocusCallback (void* h)
  182220. {
  182221. SetFocus ((HWND) h);
  182222. return 0;
  182223. }
  182224. static void* getFocusCallback (void*)
  182225. {
  182226. return (void*) GetFocus();
  182227. }
  182228. void offsetWithinParent (int& x, int& y) const
  182229. {
  182230. if (isTransparent())
  182231. {
  182232. HWND parentHwnd = GetParent (hwnd);
  182233. if (parentHwnd != 0)
  182234. {
  182235. RECT parentRect;
  182236. GetWindowRect (parentHwnd, &parentRect);
  182237. x += parentRect.left;
  182238. y += parentRect.top;
  182239. }
  182240. }
  182241. }
  182242. bool isTransparent() const
  182243. {
  182244. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  182245. }
  182246. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  182247. void setIcon (const Image& newIcon)
  182248. {
  182249. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  182250. if (hicon != 0)
  182251. {
  182252. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  182253. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  182254. if (currentWindowIcon != 0)
  182255. DestroyIcon (currentWindowIcon);
  182256. currentWindowIcon = hicon;
  182257. }
  182258. }
  182259. void handlePaintMessage()
  182260. {
  182261. #if DEBUG_REPAINT_TIMES
  182262. const double paintStart = Time::getMillisecondCounterHiRes();
  182263. #endif
  182264. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  182265. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  182266. PAINTSTRUCT paintStruct;
  182267. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  182268. // message and become re-entrant, but that's OK
  182269. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  182270. // corrupt the image it's using to paint into, so do a check here.
  182271. static bool reentrant = false;
  182272. if (reentrant)
  182273. {
  182274. DeleteObject (rgn);
  182275. EndPaint (hwnd, &paintStruct);
  182276. return;
  182277. }
  182278. reentrant = true;
  182279. // this is the rectangle to update..
  182280. int x = paintStruct.rcPaint.left;
  182281. int y = paintStruct.rcPaint.top;
  182282. int w = paintStruct.rcPaint.right - x;
  182283. int h = paintStruct.rcPaint.bottom - y;
  182284. const bool transparent = isTransparent();
  182285. if (transparent)
  182286. {
  182287. // it's not possible to have a transparent window with a title bar at the moment!
  182288. jassert (! hasTitleBar());
  182289. RECT r;
  182290. GetWindowRect (hwnd, &r);
  182291. x = y = 0;
  182292. w = r.right - r.left;
  182293. h = r.bottom - r.top;
  182294. }
  182295. if (w > 0 && h > 0)
  182296. {
  182297. clearMaskedRegion();
  182298. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  182299. RectangleList contextClip;
  182300. bool needToPaintAll = true;
  182301. if (regionType == COMPLEXREGION && ! transparent)
  182302. {
  182303. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  182304. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  182305. DeleteObject (clipRgn);
  182306. char rgnData [8192];
  182307. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  182308. if (res > 0 && res <= sizeof (rgnData))
  182309. {
  182310. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  182311. if (hdr->iType == RDH_RECTANGLES
  182312. && hdr->rcBound.right - hdr->rcBound.left >= w
  182313. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  182314. {
  182315. needToPaintAll = false;
  182316. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  182317. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  182318. while (--num >= 0)
  182319. {
  182320. // (need to move this one pixel to the left because of a win32 bug)
  182321. const int cx = jmax (x, (int) rects->left - 1);
  182322. const int cy = rects->top;
  182323. const int cw = rects->right - cx;
  182324. const int ch = rects->bottom - rects->top;
  182325. if (cx + cw - x <= w && cy + ch - y <= h)
  182326. {
  182327. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  182328. }
  182329. else
  182330. {
  182331. needToPaintAll = true;
  182332. break;
  182333. }
  182334. ++rects;
  182335. }
  182336. }
  182337. }
  182338. }
  182339. if (needToPaintAll)
  182340. {
  182341. contextClip.clear();
  182342. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  182343. }
  182344. if (transparent)
  182345. {
  182346. RectangleList::Iterator i (contextClip);
  182347. while (i.next())
  182348. {
  182349. const Rectangle<int>& r = *i.getRectangle();
  182350. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182351. }
  182352. }
  182353. // if the component's not opaque, this won't draw properly unless the platform can support this
  182354. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182355. updateCurrentModifiers();
  182356. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182357. context.clipToRectangleList (contextClip);
  182358. context.setOrigin (-x, -y);
  182359. handlePaint (context);
  182360. if (! dontRepaint)
  182361. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182362. }
  182363. DeleteObject (rgn);
  182364. EndPaint (hwnd, &paintStruct);
  182365. reentrant = false;
  182366. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182367. _fpreset(); // because some graphics cards can unmask FP exceptions
  182368. #endif
  182369. lastPaintTime = Time::getMillisecondCounter();
  182370. #if DEBUG_REPAINT_TIMES
  182371. const double elapsed = Time::getMillisecondCounterHiRes() - paintStart;
  182372. Logger::outputDebugString (T("repaint time: ") + String (elapsed, 2));
  182373. #endif
  182374. }
  182375. void doMouseEvent (const Point<int>& position)
  182376. {
  182377. handleMouseEvent (0, position, currentModifiers, getMouseEventTime());
  182378. }
  182379. void doMouseMove (const Point<int>& position)
  182380. {
  182381. if (! isMouseOver)
  182382. {
  182383. isMouseOver = true;
  182384. updateKeyModifiers();
  182385. TRACKMOUSEEVENT tme;
  182386. tme.cbSize = sizeof (tme);
  182387. tme.dwFlags = TME_LEAVE;
  182388. tme.hwndTrack = hwnd;
  182389. tme.dwHoverTime = 0;
  182390. if (! TrackMouseEvent (&tme))
  182391. jassertfalse;
  182392. }
  182393. else if (! isDragging)
  182394. {
  182395. if (! contains (position, false))
  182396. return;
  182397. }
  182398. doMouseEvent (position);
  182399. }
  182400. void doMouseDown (const Point<int>& position, const WPARAM wParam)
  182401. {
  182402. if (GetCapture() != hwnd)
  182403. SetCapture (hwnd);
  182404. doMouseMove (position);
  182405. updateModifiersFromWParam (wParam);
  182406. isDragging = true;
  182407. doMouseEvent (position);
  182408. }
  182409. void doMouseUp (const Point<int>& position, const WPARAM wParam)
  182410. {
  182411. updateModifiersFromWParam (wParam);
  182412. isDragging = false;
  182413. // release the mouse capture if the user has released all buttons
  182414. if ((wParam & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON)) == 0 && hwnd == GetCapture())
  182415. ReleaseCapture();
  182416. doMouseEvent (position);
  182417. }
  182418. void doCaptureChanged()
  182419. {
  182420. if (isDragging)
  182421. doMouseUp (getCurrentMousePos(), (WPARAM) 0);
  182422. }
  182423. void doMouseExit()
  182424. {
  182425. isMouseOver = false;
  182426. doMouseEvent (getCurrentMousePos());
  182427. }
  182428. void doMouseWheel (const Point<int>& position, const WPARAM wParam, const bool isVertical)
  182429. {
  182430. updateKeyModifiers();
  182431. const float amount = jlimit (-1000.0f, 1000.0f, 0.75f * (short) HIWORD (wParam));
  182432. handleMouseWheel (0, position, getMouseEventTime(),
  182433. isVertical ? 0.0f : amount,
  182434. isVertical ? amount : 0.0f);
  182435. }
  182436. void sendModifierKeyChangeIfNeeded()
  182437. {
  182438. if (modifiersAtLastCallback != currentModifiers)
  182439. {
  182440. modifiersAtLastCallback = currentModifiers;
  182441. handleModifierKeysChange();
  182442. }
  182443. }
  182444. bool doKeyUp (const WPARAM key)
  182445. {
  182446. updateKeyModifiers();
  182447. switch (key)
  182448. {
  182449. case VK_SHIFT:
  182450. case VK_CONTROL:
  182451. case VK_MENU:
  182452. case VK_CAPITAL:
  182453. case VK_LWIN:
  182454. case VK_RWIN:
  182455. case VK_APPS:
  182456. case VK_NUMLOCK:
  182457. case VK_SCROLL:
  182458. case VK_LSHIFT:
  182459. case VK_RSHIFT:
  182460. case VK_LCONTROL:
  182461. case VK_LMENU:
  182462. case VK_RCONTROL:
  182463. case VK_RMENU:
  182464. sendModifierKeyChangeIfNeeded();
  182465. }
  182466. return handleKeyUpOrDown (false)
  182467. || Component::getCurrentlyModalComponent() != 0;
  182468. }
  182469. bool doKeyDown (const WPARAM key)
  182470. {
  182471. updateKeyModifiers();
  182472. bool used = false;
  182473. switch (key)
  182474. {
  182475. case VK_SHIFT:
  182476. case VK_LSHIFT:
  182477. case VK_RSHIFT:
  182478. case VK_CONTROL:
  182479. case VK_LCONTROL:
  182480. case VK_RCONTROL:
  182481. case VK_MENU:
  182482. case VK_LMENU:
  182483. case VK_RMENU:
  182484. case VK_LWIN:
  182485. case VK_RWIN:
  182486. case VK_CAPITAL:
  182487. case VK_NUMLOCK:
  182488. case VK_SCROLL:
  182489. case VK_APPS:
  182490. sendModifierKeyChangeIfNeeded();
  182491. break;
  182492. case VK_LEFT:
  182493. case VK_RIGHT:
  182494. case VK_UP:
  182495. case VK_DOWN:
  182496. case VK_PRIOR:
  182497. case VK_NEXT:
  182498. case VK_HOME:
  182499. case VK_END:
  182500. case VK_DELETE:
  182501. case VK_INSERT:
  182502. case VK_F1:
  182503. case VK_F2:
  182504. case VK_F3:
  182505. case VK_F4:
  182506. case VK_F5:
  182507. case VK_F6:
  182508. case VK_F7:
  182509. case VK_F8:
  182510. case VK_F9:
  182511. case VK_F10:
  182512. case VK_F11:
  182513. case VK_F12:
  182514. case VK_F13:
  182515. case VK_F14:
  182516. case VK_F15:
  182517. case VK_F16:
  182518. used = handleKeyUpOrDown (true);
  182519. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182520. break;
  182521. case VK_ADD:
  182522. case VK_SUBTRACT:
  182523. case VK_MULTIPLY:
  182524. case VK_DIVIDE:
  182525. case VK_SEPARATOR:
  182526. case VK_DECIMAL:
  182527. used = handleKeyUpOrDown (true);
  182528. break;
  182529. default:
  182530. used = handleKeyUpOrDown (true);
  182531. {
  182532. MSG msg;
  182533. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182534. {
  182535. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182536. // manually generate the key-press event that matches this key-down.
  182537. const UINT keyChar = MapVirtualKey (key, 2);
  182538. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182539. }
  182540. }
  182541. break;
  182542. }
  182543. if (Component::getCurrentlyModalComponent() != 0)
  182544. used = true;
  182545. return used;
  182546. }
  182547. bool doKeyChar (int key, const LPARAM flags)
  182548. {
  182549. updateKeyModifiers();
  182550. juce_wchar textChar = (juce_wchar) key;
  182551. const int virtualScanCode = (flags >> 16) & 0xff;
  182552. if (key >= '0' && key <= '9')
  182553. {
  182554. switch (virtualScanCode) // check for a numeric keypad scan-code
  182555. {
  182556. case 0x52:
  182557. case 0x4f:
  182558. case 0x50:
  182559. case 0x51:
  182560. case 0x4b:
  182561. case 0x4c:
  182562. case 0x4d:
  182563. case 0x47:
  182564. case 0x48:
  182565. case 0x49:
  182566. key = (key - '0') + KeyPress::numberPad0;
  182567. break;
  182568. default:
  182569. break;
  182570. }
  182571. }
  182572. else
  182573. {
  182574. // convert the scan code to an unmodified character code..
  182575. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  182576. UINT keyChar = MapVirtualKey (virtualKey, 2);
  182577. keyChar = LOWORD (keyChar);
  182578. if (keyChar != 0)
  182579. key = (int) keyChar;
  182580. // avoid sending junk text characters for some control-key combinations
  182581. if (textChar < ' ' && currentModifiers.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::altModifier))
  182582. textChar = 0;
  182583. }
  182584. return handleKeyPress (key, textChar);
  182585. }
  182586. bool doAppCommand (const LPARAM lParam)
  182587. {
  182588. int key = 0;
  182589. switch (GET_APPCOMMAND_LPARAM (lParam))
  182590. {
  182591. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  182592. key = KeyPress::playKey;
  182593. break;
  182594. case APPCOMMAND_MEDIA_STOP:
  182595. key = KeyPress::stopKey;
  182596. break;
  182597. case APPCOMMAND_MEDIA_NEXTTRACK:
  182598. key = KeyPress::fastForwardKey;
  182599. break;
  182600. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  182601. key = KeyPress::rewindKey;
  182602. break;
  182603. }
  182604. if (key != 0)
  182605. {
  182606. updateKeyModifiers();
  182607. if (hwnd == GetActiveWindow())
  182608. {
  182609. handleKeyPress (key, 0);
  182610. return true;
  182611. }
  182612. }
  182613. return false;
  182614. }
  182615. class JuceDropTarget : public IDropTarget
  182616. {
  182617. public:
  182618. JuceDropTarget (Win32ComponentPeer* const owner_)
  182619. : owner (owner_),
  182620. refCount (1)
  182621. {
  182622. }
  182623. virtual ~JuceDropTarget()
  182624. {
  182625. jassert (refCount == 0);
  182626. }
  182627. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  182628. {
  182629. if (id == IID_IUnknown || id == IID_IDropTarget)
  182630. {
  182631. AddRef();
  182632. *result = this;
  182633. return S_OK;
  182634. }
  182635. *result = 0;
  182636. return E_NOINTERFACE;
  182637. }
  182638. ULONG __stdcall AddRef() { return ++refCount; }
  182639. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  182640. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182641. {
  182642. updateFileList (pDataObject);
  182643. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182644. *pdwEffect = DROPEFFECT_COPY;
  182645. return S_OK;
  182646. }
  182647. HRESULT __stdcall DragLeave()
  182648. {
  182649. owner->handleFileDragExit (files);
  182650. return S_OK;
  182651. }
  182652. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182653. {
  182654. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182655. *pdwEffect = DROPEFFECT_COPY;
  182656. return S_OK;
  182657. }
  182658. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182659. {
  182660. updateFileList (pDataObject);
  182661. owner->handleFileDragDrop (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182662. *pdwEffect = DROPEFFECT_COPY;
  182663. return S_OK;
  182664. }
  182665. private:
  182666. Win32ComponentPeer* const owner;
  182667. int refCount;
  182668. StringArray files;
  182669. void updateFileList (IDataObject* const pDataObject)
  182670. {
  182671. files.clear();
  182672. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  182673. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  182674. if (pDataObject->GetData (&format, &medium) == S_OK)
  182675. {
  182676. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  182677. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  182678. unsigned int i = 0;
  182679. if (pDropFiles->fWide)
  182680. {
  182681. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  182682. for (;;)
  182683. {
  182684. unsigned int len = 0;
  182685. while (i + len < totalLen && fname [i + len] != 0)
  182686. ++len;
  182687. if (len == 0)
  182688. break;
  182689. files.add (String (fname + i, len));
  182690. i += len + 1;
  182691. }
  182692. }
  182693. else
  182694. {
  182695. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  182696. for (;;)
  182697. {
  182698. unsigned int len = 0;
  182699. while (i + len < totalLen && fname [i + len] != 0)
  182700. ++len;
  182701. if (len == 0)
  182702. break;
  182703. files.add (String (fname + i, len));
  182704. i += len + 1;
  182705. }
  182706. }
  182707. GlobalUnlock (medium.hGlobal);
  182708. }
  182709. }
  182710. JuceDropTarget (const JuceDropTarget&);
  182711. JuceDropTarget& operator= (const JuceDropTarget&);
  182712. };
  182713. void doSettingChange()
  182714. {
  182715. Desktop::getInstance().refreshMonitorSizes();
  182716. if (fullScreen && ! isMinimised())
  182717. {
  182718. const Rectangle<int> r (component->getParentMonitorArea());
  182719. SetWindowPos (hwnd, 0,
  182720. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  182721. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  182722. }
  182723. }
  182724. public:
  182725. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182726. {
  182727. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  182728. if (peer != 0)
  182729. return peer->peerWindowProc (h, message, wParam, lParam);
  182730. return DefWindowProc (h, message, wParam, lParam);
  182731. }
  182732. private:
  182733. static const Point<int> getPointFromLParam (LPARAM lParam) throw()
  182734. {
  182735. return Point<int> (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  182736. }
  182737. const Point<int> getCurrentMousePos() throw()
  182738. {
  182739. RECT wr;
  182740. GetWindowRect (hwnd, &wr);
  182741. const DWORD mp = GetMessagePos();
  182742. return Point<int> (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182743. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop());
  182744. }
  182745. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182746. {
  182747. if (isValidPeer (this))
  182748. {
  182749. switch (message)
  182750. {
  182751. case WM_NCHITTEST:
  182752. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182753. return HTTRANSPARENT;
  182754. if (hasTitleBar())
  182755. break;
  182756. return HTCLIENT;
  182757. case WM_PAINT:
  182758. handlePaintMessage();
  182759. return 0;
  182760. case WM_NCPAINT:
  182761. if (wParam != 1)
  182762. handlePaintMessage();
  182763. if (hasTitleBar())
  182764. break;
  182765. return 0;
  182766. case WM_ERASEBKGND:
  182767. case WM_NCCALCSIZE:
  182768. if (hasTitleBar())
  182769. break;
  182770. return 1;
  182771. case WM_MOUSEMOVE:
  182772. doMouseMove (getPointFromLParam (lParam));
  182773. return 0;
  182774. case WM_MOUSELEAVE:
  182775. doMouseExit();
  182776. return 0;
  182777. case WM_LBUTTONDOWN:
  182778. case WM_MBUTTONDOWN:
  182779. case WM_RBUTTONDOWN:
  182780. doMouseDown (getPointFromLParam (lParam), wParam);
  182781. return 0;
  182782. case WM_LBUTTONUP:
  182783. case WM_MBUTTONUP:
  182784. case WM_RBUTTONUP:
  182785. doMouseUp (getPointFromLParam (lParam), wParam);
  182786. return 0;
  182787. case WM_CAPTURECHANGED:
  182788. doCaptureChanged();
  182789. return 0;
  182790. case WM_NCMOUSEMOVE:
  182791. if (hasTitleBar())
  182792. break;
  182793. return 0;
  182794. case 0x020A: /* WM_MOUSEWHEEL */
  182795. doMouseWheel (getCurrentMousePos(), wParam, true);
  182796. return 0;
  182797. case 0x020E: /* WM_MOUSEHWHEEL */
  182798. doMouseWheel (getCurrentMousePos(), wParam, false);
  182799. return 0;
  182800. case WM_WINDOWPOSCHANGING:
  182801. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  182802. {
  182803. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  182804. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  182805. {
  182806. if (constrainer != 0)
  182807. {
  182808. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  182809. component->getY() - windowBorder.getTop(),
  182810. component->getWidth() + windowBorder.getLeftAndRight(),
  182811. component->getHeight() + windowBorder.getTopAndBottom());
  182812. Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
  182813. constrainer->checkBounds (pos, current,
  182814. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  182815. pos.getY() != current.getY() && pos.getBottom() == current.getBottom(),
  182816. pos.getX() != current.getX() && pos.getRight() == current.getRight(),
  182817. pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
  182818. pos.getX() == current.getX() && pos.getRight() != current.getRight());
  182819. wp->x = pos.getX();
  182820. wp->y = pos.getY();
  182821. wp->cx = pos.getWidth();
  182822. wp->cy = pos.getHeight();
  182823. }
  182824. }
  182825. }
  182826. return 0;
  182827. case WM_WINDOWPOSCHANGED:
  182828. handleMovedOrResized();
  182829. if (dontRepaint)
  182830. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  182831. return 0;
  182832. case WM_KEYDOWN:
  182833. case WM_SYSKEYDOWN:
  182834. if (doKeyDown (wParam))
  182835. return 0;
  182836. break;
  182837. case WM_KEYUP:
  182838. case WM_SYSKEYUP:
  182839. if (doKeyUp (wParam))
  182840. return 0;
  182841. break;
  182842. case WM_CHAR:
  182843. if (doKeyChar ((int) wParam, lParam))
  182844. return 0;
  182845. break;
  182846. case WM_APPCOMMAND:
  182847. if (doAppCommand (lParam))
  182848. return TRUE;
  182849. break;
  182850. case WM_SETFOCUS:
  182851. updateKeyModifiers();
  182852. handleFocusGain();
  182853. break;
  182854. case WM_KILLFOCUS:
  182855. if (hasCreatedCaret)
  182856. {
  182857. hasCreatedCaret = false;
  182858. DestroyCaret();
  182859. }
  182860. handleFocusLoss();
  182861. break;
  182862. case WM_ACTIVATEAPP:
  182863. // Windows does weird things to process priority when you swap apps,
  182864. // so this forces an update when the app is brought to the front
  182865. if (wParam != FALSE)
  182866. juce_repeatLastProcessPriority();
  182867. else
  182868. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  182869. juce_CheckCurrentlyFocusedTopLevelWindow();
  182870. modifiersAtLastCallback = -1;
  182871. return 0;
  182872. case WM_ACTIVATE:
  182873. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  182874. {
  182875. modifiersAtLastCallback = -1;
  182876. updateKeyModifiers();
  182877. if (isMinimised())
  182878. {
  182879. component->repaint();
  182880. handleMovedOrResized();
  182881. if (! ComponentPeer::isValidPeer (this))
  182882. return 0;
  182883. }
  182884. if (LOWORD (wParam) == WA_CLICKACTIVE
  182885. && component->isCurrentlyBlockedByAnotherModalComponent())
  182886. {
  182887. const Point<int> mousePos (component->getMouseXYRelative());
  182888. Component* const underMouse = component->getComponentAt (mousePos.getX(), mousePos.getY());
  182889. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  182890. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  182891. return 0;
  182892. }
  182893. handleBroughtToFront();
  182894. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182895. Component::getCurrentlyModalComponent()->toFront (true);
  182896. return 0;
  182897. }
  182898. break;
  182899. case WM_NCACTIVATE:
  182900. // while a temporary window is being shown, prevent Windows from deactivating the
  182901. // title bars of our main windows.
  182902. if (wParam == 0 && ! shouldDeactivateTitleBar)
  182903. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  182904. break;
  182905. case WM_MOUSEACTIVATE:
  182906. if (! component->getMouseClickGrabsKeyboardFocus())
  182907. return MA_NOACTIVATE;
  182908. break;
  182909. case WM_SHOWWINDOW:
  182910. if (wParam != 0)
  182911. handleBroughtToFront();
  182912. break;
  182913. case WM_CLOSE:
  182914. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  182915. handleUserClosingWindow();
  182916. return 0;
  182917. case WM_QUERYENDSESSION:
  182918. if (JUCEApplication::getInstance() != 0)
  182919. {
  182920. JUCEApplication::getInstance()->systemRequestedQuit();
  182921. return MessageManager::getInstance()->hasStopMessageBeenSent();
  182922. }
  182923. return TRUE;
  182924. case WM_TRAYNOTIFY:
  182925. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182926. {
  182927. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  182928. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182929. {
  182930. Component* const current = Component::getCurrentlyModalComponent();
  182931. if (current != 0)
  182932. current->inputAttemptWhenModal();
  182933. }
  182934. }
  182935. else
  182936. {
  182937. ModifierKeys eventMods (ModifierKeys::getCurrentModifiersRealtime());
  182938. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  182939. eventMods = eventMods.withFlags (ModifierKeys::leftButtonModifier);
  182940. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  182941. eventMods = eventMods.withFlags (ModifierKeys::rightButtonModifier);
  182942. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182943. eventMods = eventMods.withoutMouseButtons();
  182944. const MouseEvent e (Desktop::getInstance().getMainMouseSource(),
  182945. Point<int>(), eventMods, component, getMouseEventTime(),
  182946. Point<int>(), getMouseEventTime(), 1, false);
  182947. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  182948. {
  182949. SetFocus (hwnd);
  182950. SetForegroundWindow (hwnd);
  182951. component->mouseDown (e);
  182952. }
  182953. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182954. {
  182955. component->mouseUp (e);
  182956. }
  182957. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182958. {
  182959. component->mouseDoubleClick (e);
  182960. }
  182961. else if (lParam == WM_MOUSEMOVE)
  182962. {
  182963. component->mouseMove (e);
  182964. }
  182965. }
  182966. break;
  182967. case WM_SYNCPAINT:
  182968. return 0;
  182969. case WM_PALETTECHANGED:
  182970. InvalidateRect (h, 0, 0);
  182971. break;
  182972. case WM_DISPLAYCHANGE:
  182973. InvalidateRect (h, 0, 0);
  182974. createPaletteIfNeeded = true;
  182975. // intentional fall-through...
  182976. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  182977. doSettingChange();
  182978. break;
  182979. case WM_INITMENU:
  182980. if (! hasTitleBar())
  182981. {
  182982. if (isFullScreen())
  182983. {
  182984. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  182985. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  182986. }
  182987. else if (! isMinimised())
  182988. {
  182989. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  182990. }
  182991. }
  182992. break;
  182993. case WM_SYSCOMMAND:
  182994. switch (wParam & 0xfff0)
  182995. {
  182996. case SC_CLOSE:
  182997. if (sendInputAttemptWhenModalMessage())
  182998. return 0;
  182999. if (hasTitleBar())
  183000. {
  183001. PostMessage (h, WM_CLOSE, 0, 0);
  183002. return 0;
  183003. }
  183004. break;
  183005. case SC_KEYMENU:
  183006. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  183007. // obscure situations that can arise if a modal loop is started from an alt-key
  183008. // keypress).
  183009. if (hasTitleBar() && h == GetCapture())
  183010. ReleaseCapture();
  183011. break;
  183012. case SC_MAXIMIZE:
  183013. if (sendInputAttemptWhenModalMessage())
  183014. return 0;
  183015. setFullScreen (true);
  183016. return 0;
  183017. case SC_MINIMIZE:
  183018. if (sendInputAttemptWhenModalMessage())
  183019. return 0;
  183020. if (! hasTitleBar())
  183021. {
  183022. setMinimised (true);
  183023. return 0;
  183024. }
  183025. break;
  183026. case SC_RESTORE:
  183027. if (sendInputAttemptWhenModalMessage())
  183028. return 0;
  183029. if (hasTitleBar())
  183030. {
  183031. if (isFullScreen())
  183032. {
  183033. setFullScreen (false);
  183034. return 0;
  183035. }
  183036. }
  183037. else
  183038. {
  183039. if (isMinimised())
  183040. setMinimised (false);
  183041. else if (isFullScreen())
  183042. setFullScreen (false);
  183043. return 0;
  183044. }
  183045. break;
  183046. }
  183047. break;
  183048. case WM_NCLBUTTONDOWN:
  183049. case WM_NCRBUTTONDOWN:
  183050. case WM_NCMBUTTONDOWN:
  183051. sendInputAttemptWhenModalMessage();
  183052. break;
  183053. //case WM_IME_STARTCOMPOSITION;
  183054. // return 0;
  183055. case WM_GETDLGCODE:
  183056. return DLGC_WANTALLKEYS;
  183057. default:
  183058. break;
  183059. }
  183060. }
  183061. return DefWindowProc (h, message, wParam, lParam);
  183062. }
  183063. bool sendInputAttemptWhenModalMessage()
  183064. {
  183065. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183066. {
  183067. Component* const current = Component::getCurrentlyModalComponent();
  183068. if (current != 0)
  183069. current->inputAttemptWhenModal();
  183070. return true;
  183071. }
  183072. return false;
  183073. }
  183074. Win32ComponentPeer (const Win32ComponentPeer&);
  183075. Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  183076. };
  183077. ModifierKeys Win32ComponentPeer::currentModifiers;
  183078. ModifierKeys Win32ComponentPeer::modifiersAtLastCallback;
  183079. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  183080. {
  183081. return new Win32ComponentPeer (this, styleFlags);
  183082. }
  183083. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  183084. void ModifierKeys::updateCurrentModifiers() throw()
  183085. {
  183086. currentModifiers = Win32ComponentPeer::currentModifiers;
  183087. }
  183088. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  183089. {
  183090. Win32ComponentPeer::updateKeyModifiers();
  183091. int keyMods = 0;
  183092. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::leftButtonModifier;
  183093. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::rightButtonModifier;
  183094. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::middleButtonModifier;
  183095. Win32ComponentPeer::currentModifiers
  183096. = Win32ComponentPeer::currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  183097. return Win32ComponentPeer::currentModifiers;
  183098. }
  183099. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  183100. {
  183101. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183102. if (wp != 0)
  183103. wp->setTaskBarIcon (&newImage);
  183104. }
  183105. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  183106. {
  183107. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183108. if (wp != 0)
  183109. wp->setTaskBarIconToolTip (tooltip);
  183110. }
  183111. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  183112. {
  183113. DWORD val = GetWindowLong (h, styleType);
  183114. if (bitIsSet)
  183115. val |= feature;
  183116. else
  183117. val &= ~feature;
  183118. SetWindowLongPtr (h, styleType, val);
  183119. SetWindowPos (h, 0, 0, 0, 0, 0,
  183120. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  183121. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  183122. }
  183123. bool Process::isForegroundProcess()
  183124. {
  183125. HWND fg = GetForegroundWindow();
  183126. if (fg == 0)
  183127. return true;
  183128. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  183129. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  183130. // have to see if any of our windows are children of the foreground window
  183131. fg = GetAncestor (fg, GA_ROOT);
  183132. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  183133. {
  183134. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  183135. if (wp != 0 && wp->isInside (fg))
  183136. return true;
  183137. }
  183138. return false;
  183139. }
  183140. bool AlertWindow::showNativeDialogBox (const String& title,
  183141. const String& bodyText,
  183142. bool isOkCancel)
  183143. {
  183144. return MessageBox (0, bodyText, title,
  183145. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  183146. : MB_OK)) == IDOK;
  183147. }
  183148. void Desktop::createMouseInputSources()
  183149. {
  183150. mouseSources.add (new MouseInputSource (0, true));
  183151. }
  183152. const Point<int> Desktop::getMousePosition()
  183153. {
  183154. POINT mousePos;
  183155. GetCursorPos (&mousePos);
  183156. return Point<int> (mousePos.x, mousePos.y);
  183157. }
  183158. void Desktop::setMousePosition (const Point<int>& newPosition)
  183159. {
  183160. SetCursorPos (newPosition.getX(), newPosition.getY());
  183161. }
  183162. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  183163. {
  183164. return new Image (format, imageWidth, imageHeight, clearImage);
  183165. }
  183166. class ScreenSaverDefeater : public Timer,
  183167. public DeletedAtShutdown
  183168. {
  183169. public:
  183170. ScreenSaverDefeater() throw()
  183171. {
  183172. startTimer (10000);
  183173. timerCallback();
  183174. }
  183175. ~ScreenSaverDefeater() {}
  183176. void timerCallback()
  183177. {
  183178. if (Process::isForegroundProcess())
  183179. {
  183180. // simulate a shift key getting pressed..
  183181. INPUT input[2];
  183182. input[0].type = INPUT_KEYBOARD;
  183183. input[0].ki.wVk = VK_SHIFT;
  183184. input[0].ki.dwFlags = 0;
  183185. input[0].ki.dwExtraInfo = 0;
  183186. input[1].type = INPUT_KEYBOARD;
  183187. input[1].ki.wVk = VK_SHIFT;
  183188. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  183189. input[1].ki.dwExtraInfo = 0;
  183190. SendInput (2, input, sizeof (INPUT));
  183191. }
  183192. }
  183193. };
  183194. static ScreenSaverDefeater* screenSaverDefeater = 0;
  183195. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  183196. {
  183197. if (isEnabled)
  183198. {
  183199. deleteAndZero (screenSaverDefeater);
  183200. }
  183201. else if (screenSaverDefeater == 0)
  183202. {
  183203. screenSaverDefeater = new ScreenSaverDefeater();
  183204. }
  183205. }
  183206. bool Desktop::isScreenSaverEnabled() throw()
  183207. {
  183208. return screenSaverDefeater == 0;
  183209. }
  183210. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  183211. {
  183212. if (enableOrDisable)
  183213. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  183214. }
  183215. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  183216. {
  183217. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  183218. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  183219. return TRUE;
  183220. }
  183221. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  183222. {
  183223. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  183224. // make sure the first in the list is the main monitor
  183225. for (int i = 1; i < monitorCoords.size(); ++i)
  183226. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  183227. monitorCoords.swap (i, 0);
  183228. if (monitorCoords.size() == 0)
  183229. {
  183230. RECT r;
  183231. GetWindowRect (GetDesktopWindow(), &r);
  183232. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  183233. }
  183234. if (clipToWorkArea)
  183235. {
  183236. // clip the main monitor to the active non-taskbar area
  183237. RECT r;
  183238. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  183239. Rectangle<int>& screen = monitorCoords.getReference (0);
  183240. screen.setPosition (jmax (screen.getX(), (int) r.left),
  183241. jmax (screen.getY(), (int) r.top));
  183242. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  183243. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  183244. }
  183245. }
  183246. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  183247. {
  183248. Image* im = 0;
  183249. if (bitmap != 0)
  183250. {
  183251. BITMAP bm;
  183252. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  183253. && bm.bmWidth > 0 && bm.bmHeight > 0)
  183254. {
  183255. HDC tempDC = GetDC (0);
  183256. HDC dc = CreateCompatibleDC (tempDC);
  183257. ReleaseDC (0, tempDC);
  183258. SelectObject (dc, bitmap);
  183259. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  183260. for (int y = bm.bmHeight; --y >= 0;)
  183261. {
  183262. for (int x = bm.bmWidth; --x >= 0;)
  183263. {
  183264. COLORREF col = GetPixel (dc, x, y);
  183265. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  183266. (uint8) GetGValue (col),
  183267. (uint8) GetBValue (col)));
  183268. }
  183269. }
  183270. DeleteDC (dc);
  183271. }
  183272. }
  183273. return im;
  183274. }
  183275. static Image* createImageFromHICON (HICON icon) throw()
  183276. {
  183277. ICONINFO info;
  183278. if (GetIconInfo (icon, &info))
  183279. {
  183280. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  183281. if (mask == 0)
  183282. return 0;
  183283. Image* const image = createImageFromHBITMAP (info.hbmColor);
  183284. if (image == 0)
  183285. return mask;
  183286. for (int y = image->getHeight(); --y >= 0;)
  183287. {
  183288. for (int x = image->getWidth(); --x >= 0;)
  183289. {
  183290. const float brightness = mask->getPixelAt (x, y).getBrightness();
  183291. if (brightness > 0.0f)
  183292. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  183293. }
  183294. }
  183295. delete mask;
  183296. return image;
  183297. }
  183298. return 0;
  183299. }
  183300. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  183301. {
  183302. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  183303. ICONINFO info;
  183304. info.fIcon = isIcon;
  183305. info.xHotspot = hotspotX;
  183306. info.yHotspot = hotspotY;
  183307. info.hbmMask = mask;
  183308. HICON hi = 0;
  183309. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  183310. {
  183311. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  183312. Graphics g (bitmap);
  183313. g.drawImageAt (&image, 0, 0);
  183314. info.hbmColor = bitmap.hBitmap;
  183315. hi = CreateIconIndirect (&info);
  183316. }
  183317. else
  183318. {
  183319. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  183320. HDC colDC = CreateCompatibleDC (GetDC (0));
  183321. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  183322. SelectObject (colDC, colour);
  183323. SelectObject (alphaDC, mask);
  183324. for (int y = image.getHeight(); --y >= 0;)
  183325. {
  183326. for (int x = image.getWidth(); --x >= 0;)
  183327. {
  183328. const Colour c (image.getPixelAt (x, y));
  183329. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183330. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183331. }
  183332. }
  183333. DeleteDC (colDC);
  183334. DeleteDC (alphaDC);
  183335. info.hbmColor = colour;
  183336. hi = CreateIconIndirect (&info);
  183337. DeleteObject (colour);
  183338. }
  183339. DeleteObject (mask);
  183340. return hi;
  183341. }
  183342. Image* juce_createIconForFile (const File& file)
  183343. {
  183344. Image* image = 0;
  183345. WCHAR filename [1024];
  183346. file.getFullPathName().copyToUnicode (filename, 1023);
  183347. WORD iconNum = 0;
  183348. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183349. filename, &iconNum);
  183350. if (icon != 0)
  183351. {
  183352. image = createImageFromHICON (icon);
  183353. DestroyIcon (icon);
  183354. }
  183355. return image;
  183356. }
  183357. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  183358. {
  183359. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183360. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183361. const Image* im = &image;
  183362. Image* newIm = 0;
  183363. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183364. {
  183365. im = newIm = image.createCopy (maxW, maxH);
  183366. hotspotX = (hotspotX * maxW) / image.getWidth();
  183367. hotspotY = (hotspotY * maxH) / image.getHeight();
  183368. }
  183369. void* cursorH = 0;
  183370. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183371. if (os == SystemStats::WinXP)
  183372. {
  183373. cursorH = (void*) createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183374. }
  183375. else
  183376. {
  183377. const int stride = (maxW + 7) >> 3;
  183378. HeapBlock <uint8> andPlane, xorPlane;
  183379. andPlane.calloc (stride * maxH);
  183380. xorPlane.calloc (stride * maxH);
  183381. int index = 0;
  183382. for (int y = 0; y < maxH; ++y)
  183383. {
  183384. for (int x = 0; x < maxW; ++x)
  183385. {
  183386. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183387. const Colour pixelColour (im->getPixelAt (x, y));
  183388. if (pixelColour.getAlpha() < 127)
  183389. andPlane [index + (x >> 3)] |= bit;
  183390. else if (pixelColour.getBrightness() >= 0.5f)
  183391. xorPlane [index + (x >> 3)] |= bit;
  183392. }
  183393. index += stride;
  183394. }
  183395. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183396. }
  183397. delete newIm;
  183398. return cursorH;
  183399. }
  183400. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  183401. {
  183402. if (cursorHandle != 0 && ! isStandard)
  183403. DestroyCursor ((HCURSOR) cursorHandle);
  183404. }
  183405. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  183406. {
  183407. LPCTSTR cursorName = IDC_ARROW;
  183408. switch (type)
  183409. {
  183410. case MouseCursor::NormalCursor:
  183411. cursorName = IDC_ARROW;
  183412. break;
  183413. case MouseCursor::NoCursor:
  183414. return 0;
  183415. case MouseCursor::DraggingHandCursor:
  183416. {
  183417. static void* dragHandCursor = 0;
  183418. if (dragHandCursor == 0)
  183419. {
  183420. static const unsigned char dragHandData[] =
  183421. { 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,
  183422. 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,
  183423. 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 };
  183424. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  183425. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  183426. }
  183427. return dragHandCursor;
  183428. }
  183429. case MouseCursor::WaitCursor:
  183430. cursorName = IDC_WAIT;
  183431. break;
  183432. case MouseCursor::IBeamCursor:
  183433. cursorName = IDC_IBEAM;
  183434. break;
  183435. case MouseCursor::PointingHandCursor:
  183436. cursorName = MAKEINTRESOURCE(32649);
  183437. break;
  183438. case MouseCursor::LeftRightResizeCursor:
  183439. case MouseCursor::LeftEdgeResizeCursor:
  183440. case MouseCursor::RightEdgeResizeCursor:
  183441. cursorName = IDC_SIZEWE;
  183442. break;
  183443. case MouseCursor::UpDownResizeCursor:
  183444. case MouseCursor::TopEdgeResizeCursor:
  183445. case MouseCursor::BottomEdgeResizeCursor:
  183446. cursorName = IDC_SIZENS;
  183447. break;
  183448. case MouseCursor::TopLeftCornerResizeCursor:
  183449. case MouseCursor::BottomRightCornerResizeCursor:
  183450. cursorName = IDC_SIZENWSE;
  183451. break;
  183452. case MouseCursor::TopRightCornerResizeCursor:
  183453. case MouseCursor::BottomLeftCornerResizeCursor:
  183454. cursorName = IDC_SIZENESW;
  183455. break;
  183456. case MouseCursor::UpDownLeftRightResizeCursor:
  183457. cursorName = IDC_SIZEALL;
  183458. break;
  183459. case MouseCursor::CrosshairCursor:
  183460. cursorName = IDC_CROSS;
  183461. break;
  183462. case MouseCursor::CopyingCursor:
  183463. // can't seem to find one of these in the win32 list..
  183464. break;
  183465. }
  183466. HCURSOR cursorH = LoadCursor (0, cursorName);
  183467. if (cursorH == 0)
  183468. cursorH = LoadCursor (0, IDC_ARROW);
  183469. return (void*) cursorH;
  183470. }
  183471. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  183472. {
  183473. SetCursor ((HCURSOR) getHandle());
  183474. }
  183475. void MouseCursor::showInAllWindows() const throw()
  183476. {
  183477. showInWindow (0);
  183478. }
  183479. class JuceDropSource : public IDropSource
  183480. {
  183481. int refCount;
  183482. public:
  183483. JuceDropSource()
  183484. : refCount (1)
  183485. {
  183486. }
  183487. virtual ~JuceDropSource()
  183488. {
  183489. jassert (refCount == 0);
  183490. }
  183491. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183492. {
  183493. if (id == IID_IUnknown || id == IID_IDropSource)
  183494. {
  183495. AddRef();
  183496. *result = this;
  183497. return S_OK;
  183498. }
  183499. *result = 0;
  183500. return E_NOINTERFACE;
  183501. }
  183502. ULONG __stdcall AddRef() { return ++refCount; }
  183503. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183504. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183505. {
  183506. if (escapePressed)
  183507. return DRAGDROP_S_CANCEL;
  183508. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183509. return DRAGDROP_S_DROP;
  183510. return S_OK;
  183511. }
  183512. HRESULT __stdcall GiveFeedback (DWORD)
  183513. {
  183514. return DRAGDROP_S_USEDEFAULTCURSORS;
  183515. }
  183516. };
  183517. class JuceEnumFormatEtc : public IEnumFORMATETC
  183518. {
  183519. public:
  183520. JuceEnumFormatEtc (const FORMATETC* const format_)
  183521. : refCount (1),
  183522. format (format_),
  183523. index (0)
  183524. {
  183525. }
  183526. virtual ~JuceEnumFormatEtc()
  183527. {
  183528. jassert (refCount == 0);
  183529. }
  183530. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183531. {
  183532. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  183533. {
  183534. AddRef();
  183535. *result = this;
  183536. return S_OK;
  183537. }
  183538. *result = 0;
  183539. return E_NOINTERFACE;
  183540. }
  183541. ULONG __stdcall AddRef() { return ++refCount; }
  183542. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183543. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  183544. {
  183545. if (result == 0)
  183546. return E_POINTER;
  183547. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183548. newOne->index = index;
  183549. *result = newOne;
  183550. return S_OK;
  183551. }
  183552. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183553. {
  183554. if (pceltFetched != 0)
  183555. *pceltFetched = 0;
  183556. else if (celt != 1)
  183557. return S_FALSE;
  183558. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183559. {
  183560. copyFormatEtc (lpFormatEtc [0], *format);
  183561. ++index;
  183562. if (pceltFetched != 0)
  183563. *pceltFetched = 1;
  183564. return S_OK;
  183565. }
  183566. return S_FALSE;
  183567. }
  183568. HRESULT __stdcall Skip (ULONG celt)
  183569. {
  183570. if (index + (int) celt >= 1)
  183571. return S_FALSE;
  183572. index += celt;
  183573. return S_OK;
  183574. }
  183575. HRESULT __stdcall Reset()
  183576. {
  183577. index = 0;
  183578. return S_OK;
  183579. }
  183580. private:
  183581. int refCount;
  183582. const FORMATETC* const format;
  183583. int index;
  183584. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183585. {
  183586. dest = source;
  183587. if (source.ptd != 0)
  183588. {
  183589. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183590. *(dest.ptd) = *(source.ptd);
  183591. }
  183592. }
  183593. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183594. JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183595. };
  183596. class JuceDataObject : public IDataObject
  183597. {
  183598. JuceDropSource* const dropSource;
  183599. const FORMATETC* const format;
  183600. const STGMEDIUM* const medium;
  183601. int refCount;
  183602. JuceDataObject (const JuceDataObject&);
  183603. JuceDataObject& operator= (const JuceDataObject&);
  183604. public:
  183605. JuceDataObject (JuceDropSource* const dropSource_,
  183606. const FORMATETC* const format_,
  183607. const STGMEDIUM* const medium_)
  183608. : dropSource (dropSource_),
  183609. format (format_),
  183610. medium (medium_),
  183611. refCount (1)
  183612. {
  183613. }
  183614. virtual ~JuceDataObject()
  183615. {
  183616. jassert (refCount == 0);
  183617. }
  183618. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183619. {
  183620. if (id == IID_IUnknown || id == IID_IDataObject)
  183621. {
  183622. AddRef();
  183623. *result = this;
  183624. return S_OK;
  183625. }
  183626. *result = 0;
  183627. return E_NOINTERFACE;
  183628. }
  183629. ULONG __stdcall AddRef() { return ++refCount; }
  183630. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183631. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  183632. {
  183633. if ((pFormatEtc->tymed & format->tymed) != 0
  183634. && pFormatEtc->cfFormat == format->cfFormat
  183635. && pFormatEtc->dwAspect == format->dwAspect)
  183636. {
  183637. pMedium->tymed = format->tymed;
  183638. pMedium->pUnkForRelease = 0;
  183639. if (format->tymed == TYMED_HGLOBAL)
  183640. {
  183641. const SIZE_T len = GlobalSize (medium->hGlobal);
  183642. void* const src = GlobalLock (medium->hGlobal);
  183643. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  183644. memcpy (dst, src, len);
  183645. GlobalUnlock (medium->hGlobal);
  183646. pMedium->hGlobal = dst;
  183647. return S_OK;
  183648. }
  183649. }
  183650. return DV_E_FORMATETC;
  183651. }
  183652. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  183653. {
  183654. if (f == 0)
  183655. return E_INVALIDARG;
  183656. if (f->tymed == format->tymed
  183657. && f->cfFormat == format->cfFormat
  183658. && f->dwAspect == format->dwAspect)
  183659. return S_OK;
  183660. return DV_E_FORMATETC;
  183661. }
  183662. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  183663. {
  183664. pFormatEtcOut->ptd = 0;
  183665. return E_NOTIMPL;
  183666. }
  183667. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  183668. {
  183669. if (result == 0)
  183670. return E_POINTER;
  183671. if (direction == DATADIR_GET)
  183672. {
  183673. *result = new JuceEnumFormatEtc (format);
  183674. return S_OK;
  183675. }
  183676. *result = 0;
  183677. return E_NOTIMPL;
  183678. }
  183679. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  183680. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  183681. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  183682. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  183683. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  183684. };
  183685. static HDROP createHDrop (const StringArray& fileNames) throw()
  183686. {
  183687. int totalChars = 0;
  183688. for (int i = fileNames.size(); --i >= 0;)
  183689. totalChars += fileNames[i].length() + 1;
  183690. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  183691. sizeof (DROPFILES)
  183692. + sizeof (WCHAR) * (totalChars + 2));
  183693. if (hDrop != 0)
  183694. {
  183695. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  183696. pDropFiles->pFiles = sizeof (DROPFILES);
  183697. pDropFiles->fWide = true;
  183698. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  183699. for (int i = 0; i < fileNames.size(); ++i)
  183700. {
  183701. fileNames[i].copyToUnicode (fname, 2048);
  183702. fname += fileNames[i].length() + 1;
  183703. }
  183704. *fname = 0;
  183705. GlobalUnlock (hDrop);
  183706. }
  183707. return hDrop;
  183708. }
  183709. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  183710. {
  183711. JuceDropSource* const source = new JuceDropSource();
  183712. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  183713. DWORD effect;
  183714. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  183715. data->Release();
  183716. source->Release();
  183717. return res == DRAGDROP_S_DROP;
  183718. }
  183719. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  183720. {
  183721. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183722. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183723. medium.hGlobal = createHDrop (files);
  183724. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  183725. : DROPEFFECT_COPY);
  183726. }
  183727. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  183728. {
  183729. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183730. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183731. const int numChars = text.length();
  183732. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  183733. char* d = (char*) GlobalLock (medium.hGlobal);
  183734. text.copyToUnicode ((WCHAR*) d, numChars + 1);
  183735. format.cfFormat = CF_UNICODETEXT;
  183736. GlobalUnlock (medium.hGlobal);
  183737. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  183738. }
  183739. #endif
  183740. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  183741. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  183742. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183743. // compiled on its own).
  183744. #if JUCE_INCLUDED_FILE
  183745. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  183746. NEWTEXTMETRICEXW*,
  183747. int type,
  183748. LPARAM lParam)
  183749. {
  183750. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183751. {
  183752. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183753. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters (T("@")));
  183754. }
  183755. return 1;
  183756. }
  183757. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  183758. NEWTEXTMETRICEXW*,
  183759. int type,
  183760. LPARAM lParam)
  183761. {
  183762. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183763. {
  183764. LOGFONTW lf;
  183765. zerostruct (lf);
  183766. lf.lfWeight = FW_DONTCARE;
  183767. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183768. lf.lfQuality = DEFAULT_QUALITY;
  183769. lf.lfCharSet = DEFAULT_CHARSET;
  183770. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183771. lf.lfPitchAndFamily = FF_DONTCARE;
  183772. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183773. fontName.copyToUnicode (lf.lfFaceName, LF_FACESIZE - 1);
  183774. HDC dc = CreateCompatibleDC (0);
  183775. EnumFontFamiliesEx (dc, &lf,
  183776. (FONTENUMPROCW) &wfontEnum2,
  183777. lParam, 0);
  183778. DeleteDC (dc);
  183779. }
  183780. return 1;
  183781. }
  183782. const StringArray Font::findAllTypefaceNames() throw()
  183783. {
  183784. StringArray results;
  183785. HDC dc = CreateCompatibleDC (0);
  183786. {
  183787. LOGFONTW lf;
  183788. zerostruct (lf);
  183789. lf.lfWeight = FW_DONTCARE;
  183790. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183791. lf.lfQuality = DEFAULT_QUALITY;
  183792. lf.lfCharSet = DEFAULT_CHARSET;
  183793. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183794. lf.lfPitchAndFamily = FF_DONTCARE;
  183795. lf.lfFaceName[0] = 0;
  183796. EnumFontFamiliesEx (dc, &lf,
  183797. (FONTENUMPROCW) &wfontEnum1,
  183798. (LPARAM) &results, 0);
  183799. }
  183800. DeleteDC (dc);
  183801. results.sort (true);
  183802. return results;
  183803. }
  183804. extern bool juce_IsRunningInWine();
  183805. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  183806. {
  183807. if (juce_IsRunningInWine())
  183808. {
  183809. // If we're running in Wine, then use fonts that might be available on Linux..
  183810. defaultSans = "Bitstream Vera Sans";
  183811. defaultSerif = "Bitstream Vera Serif";
  183812. defaultFixed = "Bitstream Vera Sans Mono";
  183813. }
  183814. else
  183815. {
  183816. defaultSans = "Verdana";
  183817. defaultSerif = "Times";
  183818. defaultFixed = "Lucida Console";
  183819. }
  183820. }
  183821. class FontDCHolder : private DeletedAtShutdown
  183822. {
  183823. public:
  183824. FontDCHolder() throw()
  183825. : dc (0), numKPs (0), size (0),
  183826. bold (false), italic (false)
  183827. {
  183828. }
  183829. ~FontDCHolder() throw()
  183830. {
  183831. if (dc != 0)
  183832. {
  183833. DeleteDC (dc);
  183834. DeleteObject (fontH);
  183835. }
  183836. clearSingletonInstance();
  183837. }
  183838. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  183839. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  183840. {
  183841. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  183842. {
  183843. fontName = fontName_;
  183844. bold = bold_;
  183845. italic = italic_;
  183846. size = size_;
  183847. if (dc != 0)
  183848. {
  183849. DeleteDC (dc);
  183850. DeleteObject (fontH);
  183851. kps.free();
  183852. }
  183853. fontH = 0;
  183854. dc = CreateCompatibleDC (0);
  183855. SetMapperFlags (dc, 0);
  183856. SetMapMode (dc, MM_TEXT);
  183857. LOGFONTW lfw;
  183858. zerostruct (lfw);
  183859. lfw.lfCharSet = DEFAULT_CHARSET;
  183860. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183861. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183862. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  183863. lfw.lfQuality = PROOF_QUALITY;
  183864. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  183865. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  183866. fontName.copyToUnicode (lfw.lfFaceName, LF_FACESIZE - 1);
  183867. lfw.lfHeight = size > 0 ? size : -256;
  183868. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  183869. if (standardSizedFont != 0)
  183870. {
  183871. if (SelectObject (dc, standardSizedFont) != 0)
  183872. {
  183873. fontH = standardSizedFont;
  183874. if (size == 0)
  183875. {
  183876. OUTLINETEXTMETRIC otm;
  183877. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  183878. {
  183879. lfw.lfHeight = -(int) otm.otmEMSquare;
  183880. fontH = CreateFontIndirect (&lfw);
  183881. SelectObject (dc, fontH);
  183882. DeleteObject (standardSizedFont);
  183883. }
  183884. }
  183885. }
  183886. else
  183887. {
  183888. jassertfalse
  183889. }
  183890. }
  183891. else
  183892. {
  183893. jassertfalse
  183894. }
  183895. }
  183896. return dc;
  183897. }
  183898. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  183899. {
  183900. if (kps == 0)
  183901. {
  183902. numKPs = GetKerningPairs (dc, 0, 0);
  183903. kps.calloc (numKPs);
  183904. GetKerningPairs (dc, numKPs, kps);
  183905. }
  183906. numKPs_ = numKPs;
  183907. return kps;
  183908. }
  183909. private:
  183910. HFONT fontH;
  183911. HDC dc;
  183912. String fontName;
  183913. HeapBlock <KERNINGPAIR> kps;
  183914. int numKPs, size;
  183915. bool bold, italic;
  183916. FontDCHolder (const FontDCHolder&);
  183917. FontDCHolder& operator= (const FontDCHolder&);
  183918. };
  183919. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  183920. class WindowsTypeface : public CustomTypeface
  183921. {
  183922. public:
  183923. WindowsTypeface (const Font& font)
  183924. {
  183925. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  183926. font.isBold(), font.isItalic(), 0);
  183927. TEXTMETRIC tm;
  183928. tm.tmAscent = tm.tmHeight = 1;
  183929. tm.tmDefaultChar = 0;
  183930. GetTextMetrics (dc, &tm);
  183931. setCharacteristics (font.getTypefaceName(),
  183932. tm.tmAscent / (float) tm.tmHeight,
  183933. font.isBold(), font.isItalic(),
  183934. tm.tmDefaultChar);
  183935. }
  183936. bool loadGlyphIfPossible (const juce_wchar character)
  183937. {
  183938. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  183939. GLYPHMETRICS gm;
  183940. {
  183941. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  183942. WORD index = 0;
  183943. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  183944. && index == 0xffff)
  183945. {
  183946. return false;
  183947. }
  183948. }
  183949. Path glyphPath;
  183950. TEXTMETRIC tm;
  183951. if (! GetTextMetrics (dc, &tm))
  183952. {
  183953. addGlyph (character, glyphPath, 0);
  183954. return true;
  183955. }
  183956. const float height = (float) tm.tmHeight;
  183957. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  183958. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  183959. &gm, 0, 0, &identityMatrix);
  183960. if (bufSize > 0)
  183961. {
  183962. HeapBlock<char> data (bufSize);
  183963. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  183964. bufSize, data, &identityMatrix);
  183965. const TTPOLYGONHEADER* pheader = reinterpret_cast<TTPOLYGONHEADER*> (data.getData());
  183966. const float scaleX = 1.0f / height;
  183967. const float scaleY = -1.0f / height;
  183968. while ((char*) pheader < data + bufSize)
  183969. {
  183970. #define remapX(v) (scaleX * (v).x.value)
  183971. #define remapY(v) (scaleY * (v).y.value)
  183972. float x = remapX (pheader->pfxStart);
  183973. float y = remapY (pheader->pfxStart);
  183974. glyphPath.startNewSubPath (x, y);
  183975. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  183976. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  183977. while ((const char*) curve < curveEnd)
  183978. {
  183979. if (curve->wType == TT_PRIM_LINE)
  183980. {
  183981. for (int i = 0; i < curve->cpfx; ++i)
  183982. {
  183983. x = remapX (curve->apfx [i]);
  183984. y = remapY (curve->apfx [i]);
  183985. glyphPath.lineTo (x, y);
  183986. }
  183987. }
  183988. else if (curve->wType == TT_PRIM_QSPLINE)
  183989. {
  183990. for (int i = 0; i < curve->cpfx - 1; ++i)
  183991. {
  183992. const float x2 = remapX (curve->apfx [i]);
  183993. const float y2 = remapY (curve->apfx [i]);
  183994. float x3, y3;
  183995. if (i < curve->cpfx - 2)
  183996. {
  183997. x3 = 0.5f * (x2 + remapX (curve->apfx [i + 1]));
  183998. y3 = 0.5f * (y2 + remapY (curve->apfx [i + 1]));
  183999. }
  184000. else
  184001. {
  184002. x3 = remapX (curve->apfx [i + 1]);
  184003. y3 = remapY (curve->apfx [i + 1]);
  184004. }
  184005. glyphPath.quadraticTo (x2, y2, x3, y3);
  184006. x = x3;
  184007. y = y3;
  184008. }
  184009. }
  184010. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  184011. }
  184012. pheader = (const TTPOLYGONHEADER*) curve;
  184013. glyphPath.closeSubPath();
  184014. }
  184015. }
  184016. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  184017. int numKPs;
  184018. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  184019. for (int i = 0; i < numKPs; ++i)
  184020. {
  184021. if (kps[i].wFirst == character)
  184022. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  184023. kps[i].iKernAmount / height);
  184024. }
  184025. return true;
  184026. }
  184027. };
  184028. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  184029. {
  184030. return new WindowsTypeface (font);
  184031. }
  184032. #endif
  184033. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  184034. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  184035. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184036. // compiled on its own).
  184037. #if JUCE_INCLUDED_FILE
  184038. static const void* defaultDirPath = 0;
  184039. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  184040. static Component* currentExtraFileWin = 0;
  184041. static bool areThereAnyAlwaysOnTopWindows()
  184042. {
  184043. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  184044. {
  184045. Component* c = Desktop::getInstance().getComponent (i);
  184046. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  184047. return true;
  184048. }
  184049. return false;
  184050. }
  184051. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  184052. {
  184053. if (msg == BFFM_INITIALIZED)
  184054. {
  184055. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  184056. }
  184057. else if (msg == BFFM_VALIDATEFAILEDW)
  184058. {
  184059. returnedString = (LPCWSTR) lParam;
  184060. }
  184061. else if (msg == BFFM_VALIDATEFAILEDA)
  184062. {
  184063. returnedString = (const char*) lParam;
  184064. }
  184065. return 0;
  184066. }
  184067. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  184068. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  184069. {
  184070. if (currentExtraFileWin != 0)
  184071. {
  184072. if (uiMsg == WM_INITDIALOG)
  184073. {
  184074. HWND dialogH = GetParent (hdlg);
  184075. jassert (dialogH != 0);
  184076. if (dialogH == 0)
  184077. dialogH = hdlg;
  184078. RECT r, cr;
  184079. GetWindowRect (dialogH, &r);
  184080. GetClientRect (dialogH, &cr);
  184081. SetWindowPos (dialogH, 0,
  184082. r.left, r.top,
  184083. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  184084. jmax (150, (int) (r.bottom - r.top)),
  184085. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  184086. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  184087. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  184088. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  184089. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  184090. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  184091. }
  184092. else if (uiMsg == WM_NOTIFY)
  184093. {
  184094. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  184095. if (ofn->hdr.code == CDN_SELCHANGE)
  184096. {
  184097. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  184098. if (comp != 0)
  184099. {
  184100. TCHAR path [MAX_PATH * 2];
  184101. path[0] = 0;
  184102. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  184103. const String fn ((const WCHAR*) path);
  184104. comp->selectedFileChanged (File (fn));
  184105. }
  184106. }
  184107. }
  184108. }
  184109. return 0;
  184110. }
  184111. class FPComponentHolder : public Component
  184112. {
  184113. public:
  184114. FPComponentHolder()
  184115. {
  184116. setVisible (true);
  184117. setOpaque (true);
  184118. }
  184119. ~FPComponentHolder()
  184120. {
  184121. }
  184122. void paint (Graphics& g)
  184123. {
  184124. g.fillAll (Colours::lightgrey);
  184125. }
  184126. private:
  184127. FPComponentHolder (const FPComponentHolder&);
  184128. FPComponentHolder& operator= (const FPComponentHolder&);
  184129. };
  184130. void FileChooser::showPlatformDialog (Array<File>& results,
  184131. const String& title,
  184132. const File& currentFileOrDirectory,
  184133. const String& filter,
  184134. bool selectsDirectory,
  184135. bool /*selectsFiles*/,
  184136. bool isSaveDialogue,
  184137. bool warnAboutOverwritingExistingFiles,
  184138. bool selectMultipleFiles,
  184139. FilePreviewComponent* extraInfoComponent)
  184140. {
  184141. const int numCharsAvailable = 32768;
  184142. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  184143. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  184144. int fnameIdx = 0;
  184145. JUCE_TRY
  184146. {
  184147. // use a modal window as the parent for this dialog box
  184148. // to block input from other app windows
  184149. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  184150. Component w (String::empty);
  184151. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  184152. mainMon.getY() + mainMon.getHeight() / 4,
  184153. 0, 0);
  184154. w.setOpaque (true);
  184155. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  184156. w.addToDesktop (0);
  184157. if (extraInfoComponent == 0)
  184158. w.enterModalState();
  184159. String initialDir;
  184160. if (currentFileOrDirectory.isDirectory())
  184161. {
  184162. initialDir = currentFileOrDirectory.getFullPathName();
  184163. }
  184164. else
  184165. {
  184166. currentFileOrDirectory.getFileName().copyToUnicode (fname, numCharsAvailable);
  184167. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  184168. }
  184169. if (currentExtraFileWin->isValidComponent())
  184170. {
  184171. jassertfalse
  184172. return;
  184173. }
  184174. if (selectsDirectory)
  184175. {
  184176. LPITEMIDLIST list = 0;
  184177. filenameSpace.fillWith (0);
  184178. {
  184179. BROWSEINFO bi;
  184180. zerostruct (bi);
  184181. bi.hwndOwner = (HWND) w.getWindowHandle();
  184182. bi.pszDisplayName = fname;
  184183. bi.lpszTitle = title;
  184184. bi.lpfn = browseCallbackProc;
  184185. #ifdef BIF_USENEWUI
  184186. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  184187. #else
  184188. bi.ulFlags = 0x50;
  184189. #endif
  184190. defaultDirPath = (const WCHAR*) initialDir;
  184191. list = SHBrowseForFolder (&bi);
  184192. if (! SHGetPathFromIDListW (list, fname))
  184193. {
  184194. fname[0] = 0;
  184195. returnedString = String::empty;
  184196. }
  184197. }
  184198. LPMALLOC al;
  184199. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  184200. al->Free (list);
  184201. defaultDirPath = 0;
  184202. if (returnedString.isNotEmpty())
  184203. {
  184204. const String stringFName (fname);
  184205. results.add (File (stringFName).getSiblingFile (returnedString));
  184206. returnedString = String::empty;
  184207. return;
  184208. }
  184209. }
  184210. else
  184211. {
  184212. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  184213. if (warnAboutOverwritingExistingFiles)
  184214. flags |= OFN_OVERWRITEPROMPT;
  184215. if (selectMultipleFiles)
  184216. flags |= OFN_ALLOWMULTISELECT;
  184217. if (extraInfoComponent != 0)
  184218. {
  184219. flags |= OFN_ENABLEHOOK;
  184220. currentExtraFileWin = new FPComponentHolder();
  184221. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  184222. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  184223. extraInfoComponent->getHeight());
  184224. currentExtraFileWin->addToDesktop (0);
  184225. currentExtraFileWin->enterModalState();
  184226. }
  184227. {
  184228. WCHAR filters [1024];
  184229. zeromem (filters, sizeof (filters));
  184230. filter.copyToUnicode (filters, 1024);
  184231. filter.copyToUnicode (filters + filter.length() + 1,
  184232. 1022 - filter.length());
  184233. OPENFILENAMEW of;
  184234. zerostruct (of);
  184235. #ifdef OPENFILENAME_SIZE_VERSION_400W
  184236. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  184237. #else
  184238. of.lStructSize = sizeof (of);
  184239. #endif
  184240. of.hwndOwner = (HWND) w.getWindowHandle();
  184241. of.lpstrFilter = filters;
  184242. of.nFilterIndex = 1;
  184243. of.lpstrFile = fname;
  184244. of.nMaxFile = numCharsAvailable;
  184245. of.lpstrInitialDir = initialDir;
  184246. of.lpstrTitle = title;
  184247. of.Flags = flags;
  184248. if (extraInfoComponent != 0)
  184249. of.lpfnHook = &openCallback;
  184250. if (isSaveDialogue)
  184251. {
  184252. if (! GetSaveFileName (&of))
  184253. fname[0] = 0;
  184254. else
  184255. fnameIdx = of.nFileOffset;
  184256. }
  184257. else
  184258. {
  184259. if (! GetOpenFileName (&of))
  184260. fname[0] = 0;
  184261. else
  184262. fnameIdx = of.nFileOffset;
  184263. }
  184264. }
  184265. }
  184266. }
  184267. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  184268. catch (...)
  184269. {
  184270. fname[0] = 0;
  184271. }
  184272. #endif
  184273. deleteAndZero (currentExtraFileWin);
  184274. const WCHAR* const files = fname;
  184275. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  184276. {
  184277. const WCHAR* filename = files + fnameIdx;
  184278. while (*filename != 0)
  184279. {
  184280. const String filepath (String (files) + T("\\") + String (filename));
  184281. results.add (File (filepath));
  184282. filename += CharacterFunctions::length (filename) + 1;
  184283. }
  184284. }
  184285. else if (files[0] != 0)
  184286. {
  184287. results.add (File (files));
  184288. }
  184289. }
  184290. #endif
  184291. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  184292. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  184293. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184294. // compiled on its own).
  184295. #if JUCE_INCLUDED_FILE
  184296. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  184297. {
  184298. if (OpenClipboard (0) != 0)
  184299. {
  184300. if (EmptyClipboard() != 0)
  184301. {
  184302. const int len = text.length();
  184303. if (len > 0)
  184304. {
  184305. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  184306. (len + 1) * sizeof (wchar_t));
  184307. if (bufH != 0)
  184308. {
  184309. WCHAR* const data = (WCHAR*) GlobalLock (bufH);
  184310. text.copyToUnicode (data, len);
  184311. GlobalUnlock (bufH);
  184312. SetClipboardData (CF_UNICODETEXT, bufH);
  184313. }
  184314. }
  184315. }
  184316. CloseClipboard();
  184317. }
  184318. }
  184319. const String SystemClipboard::getTextFromClipboard() throw()
  184320. {
  184321. String result;
  184322. if (OpenClipboard (0) != 0)
  184323. {
  184324. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  184325. if (bufH != 0)
  184326. {
  184327. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  184328. if (data != 0)
  184329. {
  184330. result = String (data, (int) (GlobalSize (bufH) / sizeof (tchar)));
  184331. GlobalUnlock (bufH);
  184332. }
  184333. }
  184334. CloseClipboard();
  184335. }
  184336. return result;
  184337. }
  184338. #endif
  184339. /*** End of inlined file: juce_win32_Misc.cpp ***/
  184340. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184341. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184342. // compiled on its own).
  184343. #if JUCE_INCLUDED_FILE
  184344. namespace ActiveXHelpers
  184345. {
  184346. class JuceIStorage : public IStorage
  184347. {
  184348. int refCount;
  184349. public:
  184350. JuceIStorage() : refCount (1) {}
  184351. virtual ~JuceIStorage()
  184352. {
  184353. jassert (refCount == 0);
  184354. }
  184355. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184356. {
  184357. if (id == IID_IUnknown || id == IID_IStorage)
  184358. {
  184359. AddRef();
  184360. *result = this;
  184361. return S_OK;
  184362. }
  184363. *result = 0;
  184364. return E_NOINTERFACE;
  184365. }
  184366. ULONG __stdcall AddRef() { return ++refCount; }
  184367. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184368. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184369. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184370. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184371. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184372. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184373. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184374. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184375. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184376. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184377. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184378. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184379. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184380. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184381. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184382. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184383. juce_UseDebuggingNewOperator
  184384. };
  184385. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184386. {
  184387. int refCount;
  184388. HWND window;
  184389. public:
  184390. JuceOleInPlaceFrame (HWND window_)
  184391. : refCount (1),
  184392. window (window_)
  184393. {
  184394. }
  184395. virtual ~JuceOleInPlaceFrame()
  184396. {
  184397. jassert (refCount == 0);
  184398. }
  184399. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184400. {
  184401. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  184402. {
  184403. AddRef();
  184404. *result = this;
  184405. return S_OK;
  184406. }
  184407. *result = 0;
  184408. return E_NOINTERFACE;
  184409. }
  184410. ULONG __stdcall AddRef() { return ++refCount; }
  184411. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184412. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184413. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184414. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  184415. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184416. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184417. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  184418. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  184419. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  184420. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  184421. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  184422. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  184423. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  184424. juce_UseDebuggingNewOperator
  184425. };
  184426. class JuceIOleInPlaceSite : public IOleInPlaceSite
  184427. {
  184428. int refCount;
  184429. HWND window;
  184430. JuceOleInPlaceFrame* frame;
  184431. public:
  184432. JuceIOleInPlaceSite (HWND window_)
  184433. : refCount (1),
  184434. window (window_)
  184435. {
  184436. frame = new JuceOleInPlaceFrame (window);
  184437. }
  184438. virtual ~JuceIOleInPlaceSite()
  184439. {
  184440. jassert (refCount == 0);
  184441. frame->Release();
  184442. }
  184443. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184444. {
  184445. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  184446. {
  184447. AddRef();
  184448. *result = this;
  184449. return S_OK;
  184450. }
  184451. *result = 0;
  184452. return E_NOINTERFACE;
  184453. }
  184454. ULONG __stdcall AddRef() { return ++refCount; }
  184455. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184456. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184457. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184458. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  184459. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  184460. HRESULT __stdcall OnUIActivate() { return S_OK; }
  184461. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  184462. {
  184463. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  184464. *lplpFrame = frame;
  184465. *lplpDoc = 0;
  184466. lpFrameInfo->fMDIApp = FALSE;
  184467. lpFrameInfo->hwndFrame = window;
  184468. lpFrameInfo->haccel = 0;
  184469. lpFrameInfo->cAccelEntries = 0;
  184470. return S_OK;
  184471. }
  184472. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  184473. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  184474. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  184475. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  184476. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  184477. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  184478. juce_UseDebuggingNewOperator
  184479. };
  184480. class JuceIOleClientSite : public IOleClientSite
  184481. {
  184482. int refCount;
  184483. JuceIOleInPlaceSite* inplaceSite;
  184484. public:
  184485. JuceIOleClientSite (HWND window)
  184486. : refCount (1)
  184487. {
  184488. inplaceSite = new JuceIOleInPlaceSite (window);
  184489. }
  184490. virtual ~JuceIOleClientSite()
  184491. {
  184492. jassert (refCount == 0);
  184493. inplaceSite->Release();
  184494. }
  184495. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184496. {
  184497. if (id == IID_IUnknown || id == IID_IOleClientSite)
  184498. {
  184499. AddRef();
  184500. *result = this;
  184501. return S_OK;
  184502. }
  184503. else if (id == IID_IOleInPlaceSite)
  184504. {
  184505. inplaceSite->AddRef();
  184506. *result = inplaceSite;
  184507. return S_OK;
  184508. }
  184509. *result = 0;
  184510. return E_NOINTERFACE;
  184511. }
  184512. ULONG __stdcall AddRef() { return ++refCount; }
  184513. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184514. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  184515. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  184516. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  184517. HRESULT __stdcall ShowObject() { return S_OK; }
  184518. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  184519. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  184520. juce_UseDebuggingNewOperator
  184521. };
  184522. static VoidArray activeXComps;
  184523. static HWND getHWND (const ActiveXControlComponent* const component)
  184524. {
  184525. HWND hwnd = 0;
  184526. const IID iid = IID_IOleWindow;
  184527. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  184528. if (window != 0)
  184529. {
  184530. window->GetWindow (&hwnd);
  184531. window->Release();
  184532. }
  184533. return hwnd;
  184534. }
  184535. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  184536. {
  184537. RECT activeXRect, peerRect;
  184538. GetWindowRect (hwnd, &activeXRect);
  184539. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  184540. const Point<int> mousePos (GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left,
  184541. GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top);
  184542. const int64 mouseEventTime = Win32ComponentPeer::getMouseEventTime();
  184543. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  184544. switch (message)
  184545. {
  184546. case WM_MOUSEMOVE:
  184547. case WM_LBUTTONDOWN:
  184548. case WM_MBUTTONDOWN:
  184549. case WM_RBUTTONDOWN:
  184550. case WM_LBUTTONUP:
  184551. case WM_MBUTTONUP:
  184552. case WM_RBUTTONUP:
  184553. peer->handleMouseEvent (0, mousePos, Win32ComponentPeer::currentModifiers, mouseEventTime);
  184554. break;
  184555. default:
  184556. break;
  184557. }
  184558. }
  184559. }
  184560. class ActiveXControlComponent::ActiveXControlData : public ComponentMovementWatcher
  184561. {
  184562. ActiveXControlComponent* const owner;
  184563. bool wasShowing;
  184564. public:
  184565. HWND controlHWND;
  184566. IStorage* storage;
  184567. IOleClientSite* clientSite;
  184568. IOleObject* control;
  184569. ActiveXControlData (HWND hwnd,
  184570. ActiveXControlComponent* const owner_)
  184571. : ComponentMovementWatcher (owner_),
  184572. owner (owner_),
  184573. wasShowing (owner_ != 0 && owner_->isShowing()),
  184574. controlHWND (0),
  184575. storage (new ActiveXHelpers::JuceIStorage()),
  184576. clientSite (new ActiveXHelpers::JuceIOleClientSite (hwnd)),
  184577. control (0)
  184578. {
  184579. }
  184580. ~ActiveXControlData()
  184581. {
  184582. if (control != 0)
  184583. {
  184584. control->Close (OLECLOSE_NOSAVE);
  184585. control->Release();
  184586. }
  184587. clientSite->Release();
  184588. storage->Release();
  184589. }
  184590. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184591. {
  184592. Component* const topComp = owner->getTopLevelComponent();
  184593. if (topComp->getPeer() != 0)
  184594. {
  184595. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  184596. owner->setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight()));
  184597. }
  184598. }
  184599. void componentPeerChanged()
  184600. {
  184601. const bool isShowingNow = owner->isShowing();
  184602. if (wasShowing != isShowingNow)
  184603. {
  184604. wasShowing = isShowingNow;
  184605. owner->setControlVisible (isShowingNow);
  184606. }
  184607. componentMovedOrResized (true, true);
  184608. }
  184609. void componentVisibilityChanged (Component&)
  184610. {
  184611. componentPeerChanged();
  184612. }
  184613. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  184614. {
  184615. return ((ActiveXControlData*) ax->control) != 0
  184616. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  184617. }
  184618. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  184619. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  184620. {
  184621. for (int i = ActiveXHelpers::activeXComps.size(); --i >= 0;)
  184622. {
  184623. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) ActiveXHelpers::activeXComps.getUnchecked(i);
  184624. if (doesWindowMatch (ax, hwnd))
  184625. {
  184626. switch (message)
  184627. {
  184628. case WM_MOUSEMOVE:
  184629. case WM_LBUTTONDOWN:
  184630. case WM_MBUTTONDOWN:
  184631. case WM_RBUTTONDOWN:
  184632. case WM_LBUTTONUP:
  184633. case WM_MBUTTONUP:
  184634. case WM_RBUTTONUP:
  184635. case WM_LBUTTONDBLCLK:
  184636. case WM_MBUTTONDBLCLK:
  184637. case WM_RBUTTONDBLCLK:
  184638. if (ax->isShowing())
  184639. {
  184640. ComponentPeer* const peer = ax->getPeer();
  184641. if (peer != 0)
  184642. {
  184643. ActiveXHelpers::offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  184644. if (! ax->areMouseEventsAllowed())
  184645. return 0;
  184646. }
  184647. }
  184648. break;
  184649. default:
  184650. break;
  184651. }
  184652. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  184653. }
  184654. }
  184655. return DefWindowProc (hwnd, message, wParam, lParam);
  184656. }
  184657. };
  184658. ActiveXControlComponent::ActiveXControlComponent()
  184659. : originalWndProc (0),
  184660. control (0),
  184661. mouseEventsAllowed (true)
  184662. {
  184663. ActiveXHelpers::activeXComps.add (this);
  184664. }
  184665. ActiveXControlComponent::~ActiveXControlComponent()
  184666. {
  184667. deleteControl();
  184668. ActiveXHelpers::activeXComps.removeValue (this);
  184669. }
  184670. void ActiveXControlComponent::paint (Graphics& g)
  184671. {
  184672. if (control == 0)
  184673. g.fillAll (Colours::lightgrey);
  184674. }
  184675. bool ActiveXControlComponent::createControl (const void* controlIID)
  184676. {
  184677. deleteControl();
  184678. ComponentPeer* const peer = getPeer();
  184679. // the component must have already been added to a real window when you call this!
  184680. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  184681. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  184682. {
  184683. const Point<int> pos (relativePositionToOtherComponent (getTopLevelComponent(), Point<int>()));
  184684. HWND hwnd = (HWND) peer->getNativeHandle();
  184685. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  184686. HRESULT hr;
  184687. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  184688. info->clientSite, info->storage,
  184689. (void**) &(info->control))) == S_OK)
  184690. {
  184691. info->control->SetHostNames (L"Juce", 0);
  184692. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  184693. {
  184694. RECT rect;
  184695. rect.left = pos.getX();
  184696. rect.top = pos.getY();
  184697. rect.right = pos.getX() + getWidth();
  184698. rect.bottom = pos.getY() + getHeight();
  184699. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  184700. {
  184701. control = info.release();
  184702. setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), getWidth(), getHeight()));
  184703. ((ActiveXControlData*) control)->controlHWND = ActiveXHelpers::getHWND (this);
  184704. if (((ActiveXControlData*) control)->controlHWND != 0)
  184705. {
  184706. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  184707. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) ActiveXControlData::activeXHookWndProc);
  184708. }
  184709. return true;
  184710. }
  184711. }
  184712. }
  184713. }
  184714. return false;
  184715. }
  184716. void ActiveXControlComponent::deleteControl()
  184717. {
  184718. ActiveXControlData* const info = (ActiveXControlData*) control;
  184719. if (info != 0)
  184720. {
  184721. delete info;
  184722. control = 0;
  184723. originalWndProc = 0;
  184724. }
  184725. }
  184726. void* ActiveXControlComponent::queryInterface (const void* iid) const
  184727. {
  184728. ActiveXControlData* const info = (ActiveXControlData*) control;
  184729. void* result = 0;
  184730. if (info != 0 && info->control != 0
  184731. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  184732. return result;
  184733. return 0;
  184734. }
  184735. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  184736. {
  184737. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184738. if (hwnd != 0)
  184739. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  184740. }
  184741. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  184742. {
  184743. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184744. if (hwnd != 0)
  184745. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  184746. }
  184747. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  184748. {
  184749. mouseEventsAllowed = eventsCanReachControl;
  184750. }
  184751. #endif
  184752. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184753. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184754. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184755. // compiled on its own).
  184756. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  184757. using namespace QTOLibrary;
  184758. using namespace QTOControlLib;
  184759. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  184760. static bool isQTAvailable = false;
  184761. struct QTMovieCompInternal
  184762. {
  184763. QTMovieCompInternal()
  184764. : dataHandle (0)
  184765. {
  184766. }
  184767. ~QTMovieCompInternal()
  184768. {
  184769. clearHandle();
  184770. }
  184771. IQTControlPtr qtControlInternal;
  184772. IQTMoviePtr qtMovieInternal;
  184773. Handle dataHandle;
  184774. void clearHandle()
  184775. {
  184776. if (dataHandle != 0)
  184777. {
  184778. DisposeHandle (dataHandle);
  184779. dataHandle = 0;
  184780. }
  184781. }
  184782. };
  184783. #define qtControl (((QTMovieCompInternal*) internal)->qtControlInternal)
  184784. #define qtMovie (((QTMovieCompInternal*) internal)->qtMovieInternal)
  184785. QuickTimeMovieComponent::QuickTimeMovieComponent()
  184786. : movieLoaded (false),
  184787. controllerVisible (true)
  184788. {
  184789. internal = new QTMovieCompInternal();
  184790. setMouseEventsAllowed (false);
  184791. }
  184792. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  184793. {
  184794. closeMovie();
  184795. qtControl = 0;
  184796. deleteControl();
  184797. delete internal;
  184798. internal = 0;
  184799. }
  184800. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  184801. {
  184802. if (! isQTAvailable)
  184803. {
  184804. isQTAvailable = (InitializeQTML (0) == noErr)
  184805. && (EnterMovies() == noErr);
  184806. }
  184807. return isQTAvailable;
  184808. }
  184809. void QuickTimeMovieComponent::createControlIfNeeded()
  184810. {
  184811. if (isShowing() && ! isControlCreated())
  184812. {
  184813. const IID qtIID = __uuidof (QTControl);
  184814. if (createControl (&qtIID))
  184815. {
  184816. const IID qtInterfaceIID = __uuidof (IQTControl);
  184817. qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  184818. if (qtControl != 0)
  184819. {
  184820. qtControl->Release(); // it has one ref too many at this point
  184821. qtControl->QuickTimeInitialize();
  184822. qtControl->PutSizing (qtMovieFitsControl);
  184823. if (movieFile != File::nonexistent)
  184824. loadMovie (movieFile, controllerVisible);
  184825. }
  184826. }
  184827. }
  184828. }
  184829. bool QuickTimeMovieComponent::isControlCreated() const
  184830. {
  184831. return isControlOpen();
  184832. }
  184833. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  184834. const bool isControllerVisible)
  184835. {
  184836. movieFile = File::nonexistent;
  184837. movieLoaded = false;
  184838. qtMovie = 0;
  184839. controllerVisible = isControllerVisible;
  184840. createControlIfNeeded();
  184841. if (isControlCreated())
  184842. {
  184843. if (qtControl != 0)
  184844. {
  184845. qtControl->Put_MovieHandle (0);
  184846. ((QTMovieCompInternal*) internal)->clearHandle();
  184847. Movie movie;
  184848. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, ((QTMovieCompInternal*) internal)->dataHandle))
  184849. {
  184850. qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  184851. qtMovie = qtControl->GetMovie();
  184852. if (qtMovie != 0)
  184853. qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  184854. : qtMovieControllerTypeNone);
  184855. }
  184856. if (movie == 0)
  184857. ((QTMovieCompInternal*) internal)->clearHandle();
  184858. }
  184859. movieLoaded = (qtMovie != 0);
  184860. }
  184861. else
  184862. {
  184863. // You're trying to open a movie when the control hasn't yet been created, probably because
  184864. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  184865. jassertfalse
  184866. }
  184867. delete movieStream;
  184868. return movieLoaded;
  184869. }
  184870. void QuickTimeMovieComponent::closeMovie()
  184871. {
  184872. stop();
  184873. movieFile = File::nonexistent;
  184874. movieLoaded = false;
  184875. qtMovie = 0;
  184876. if (qtControl != 0)
  184877. qtControl->Put_MovieHandle (0);
  184878. ((QTMovieCompInternal*) internal)->clearHandle();
  184879. }
  184880. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  184881. {
  184882. return movieFile;
  184883. }
  184884. bool QuickTimeMovieComponent::isMovieOpen() const
  184885. {
  184886. return movieLoaded;
  184887. }
  184888. double QuickTimeMovieComponent::getMovieDuration() const
  184889. {
  184890. if (qtMovie != 0)
  184891. return qtMovie->GetDuration() / (double) qtMovie->GetTimeScale();
  184892. return 0.0;
  184893. }
  184894. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  184895. {
  184896. if (qtMovie != 0)
  184897. {
  184898. struct QTRECT r = qtMovie->GetNaturalRect();
  184899. width = r.right - r.left;
  184900. height = r.bottom - r.top;
  184901. }
  184902. else
  184903. {
  184904. width = height = 0;
  184905. }
  184906. }
  184907. void QuickTimeMovieComponent::play()
  184908. {
  184909. if (qtMovie != 0)
  184910. qtMovie->Play();
  184911. }
  184912. void QuickTimeMovieComponent::stop()
  184913. {
  184914. if (qtMovie != 0)
  184915. qtMovie->Stop();
  184916. }
  184917. bool QuickTimeMovieComponent::isPlaying() const
  184918. {
  184919. return qtMovie != 0 && qtMovie->GetRate() != 0.0f;
  184920. }
  184921. void QuickTimeMovieComponent::setPosition (const double seconds)
  184922. {
  184923. if (qtMovie != 0)
  184924. qtMovie->PutTime ((long) (seconds * qtMovie->GetTimeScale()));
  184925. }
  184926. double QuickTimeMovieComponent::getPosition() const
  184927. {
  184928. if (qtMovie != 0)
  184929. return qtMovie->GetTime() / (double) qtMovie->GetTimeScale();
  184930. return 0.0;
  184931. }
  184932. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  184933. {
  184934. if (qtMovie != 0)
  184935. qtMovie->PutRate (newSpeed);
  184936. }
  184937. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  184938. {
  184939. if (qtMovie != 0)
  184940. {
  184941. qtMovie->PutAudioVolume (newVolume);
  184942. qtMovie->PutAudioMute (newVolume <= 0);
  184943. }
  184944. }
  184945. float QuickTimeMovieComponent::getMovieVolume() const
  184946. {
  184947. if (qtMovie != 0)
  184948. return qtMovie->GetAudioVolume();
  184949. return 0.0f;
  184950. }
  184951. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  184952. {
  184953. if (qtMovie != 0)
  184954. qtMovie->PutLoop (shouldLoop);
  184955. }
  184956. bool QuickTimeMovieComponent::isLooping() const
  184957. {
  184958. return qtMovie != 0 && qtMovie->GetLoop();
  184959. }
  184960. bool QuickTimeMovieComponent::isControllerVisible() const
  184961. {
  184962. return controllerVisible;
  184963. }
  184964. void QuickTimeMovieComponent::parentHierarchyChanged()
  184965. {
  184966. createControlIfNeeded();
  184967. QTCompBaseClass::parentHierarchyChanged();
  184968. }
  184969. void QuickTimeMovieComponent::visibilityChanged()
  184970. {
  184971. createControlIfNeeded();
  184972. QTCompBaseClass::visibilityChanged();
  184973. }
  184974. void QuickTimeMovieComponent::paint (Graphics& g)
  184975. {
  184976. if (! isControlCreated())
  184977. g.fillAll (Colours::black);
  184978. }
  184979. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  184980. {
  184981. Handle dataRef = 0;
  184982. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  184983. if (err == noErr)
  184984. {
  184985. Str255 suffix;
  184986. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  184987. StringPtr name = suffix;
  184988. err = PtrAndHand (name, dataRef, name[0] + 1);
  184989. if (err == noErr)
  184990. {
  184991. long atoms[3];
  184992. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  184993. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  184994. atoms[2] = EndianU32_NtoB (MovieFileType);
  184995. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  184996. if (err == noErr)
  184997. return dataRef;
  184998. }
  184999. DisposeHandle (dataRef);
  185000. }
  185001. return 0;
  185002. }
  185003. static CFStringRef juceStringToCFString (const String& s)
  185004. {
  185005. const int len = s.length();
  185006. const juce_wchar* const t = (const juce_wchar*) s;
  185007. HeapBlock <UniChar> temp (len + 2);
  185008. for (int i = 0; i <= len; ++i)
  185009. temp[i] = t[i];
  185010. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  185011. }
  185012. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  185013. {
  185014. Boolean trueBool = true;
  185015. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185016. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  185017. props[prop].propValueSize = sizeof (trueBool);
  185018. props[prop].propValueAddress = &trueBool;
  185019. ++prop;
  185020. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185021. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  185022. props[prop].propValueSize = sizeof (trueBool);
  185023. props[prop].propValueAddress = &trueBool;
  185024. ++prop;
  185025. Boolean isActive = true;
  185026. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  185027. props[prop].propID = kQTNewMoviePropertyID_Active;
  185028. props[prop].propValueSize = sizeof (isActive);
  185029. props[prop].propValueAddress = &isActive;
  185030. ++prop;
  185031. MacSetPort (0);
  185032. jassert (prop <= 5);
  185033. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  185034. return err == noErr;
  185035. }
  185036. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  185037. {
  185038. if (input == 0)
  185039. return false;
  185040. dataHandle = 0;
  185041. bool ok = false;
  185042. QTNewMoviePropertyElement props[5];
  185043. zeromem (props, sizeof (props));
  185044. int prop = 0;
  185045. DataReferenceRecord dr;
  185046. props[prop].propClass = kQTPropertyClass_DataLocation;
  185047. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  185048. props[prop].propValueSize = sizeof (dr);
  185049. props[prop].propValueAddress = (void*) &dr;
  185050. ++prop;
  185051. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  185052. if (fin != 0)
  185053. {
  185054. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  185055. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  185056. &dr.dataRef, &dr.dataRefType);
  185057. ok = openMovie (props, prop, movie);
  185058. DisposeHandle (dr.dataRef);
  185059. CFRelease (filePath);
  185060. }
  185061. else
  185062. {
  185063. // sanity-check because this currently needs to load the whole stream into memory..
  185064. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  185065. dataHandle = NewHandle ((Size) input->getTotalLength());
  185066. HLock (dataHandle);
  185067. // read the entire stream into memory - this is a pain, but can't get it to work
  185068. // properly using a custom callback to supply the data.
  185069. input->read (*dataHandle, (int) input->getTotalLength());
  185070. HUnlock (dataHandle);
  185071. // different types to get QT to try. (We should really be a bit smarter here by
  185072. // working out in advance which one the stream contains, rather than just trying
  185073. // each one)
  185074. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  185075. "\04.avi", "\04.m4a" };
  185076. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  185077. {
  185078. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  185079. dr.dataRefType = HandleDataHandlerSubType;
  185080. ok = openMovie (props, prop, movie);
  185081. DisposeHandle (dr.dataRef);
  185082. }
  185083. }
  185084. return ok;
  185085. }
  185086. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  185087. const bool isControllerVisible)
  185088. {
  185089. const bool ok = loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible);
  185090. movieFile = movieFile_;
  185091. return ok;
  185092. }
  185093. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  185094. const bool isControllerVisible)
  185095. {
  185096. return loadMovie ((InputStream*) movieURL.createInputStream (false), isControllerVisible);
  185097. }
  185098. void QuickTimeMovieComponent::goToStart()
  185099. {
  185100. setPosition (0.0);
  185101. }
  185102. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  185103. const RectanglePlacement& placement)
  185104. {
  185105. int normalWidth, normalHeight;
  185106. getMovieNormalSize (normalWidth, normalHeight);
  185107. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  185108. {
  185109. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  185110. placement.applyTo (x, y, w, h,
  185111. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  185112. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  185113. if (w > 0 && h > 0)
  185114. {
  185115. setBounds (roundToInt (x), roundToInt (y),
  185116. roundToInt (w), roundToInt (h));
  185117. }
  185118. }
  185119. else
  185120. {
  185121. setBounds (spaceToFitWithin);
  185122. }
  185123. }
  185124. #endif
  185125. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  185126. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185127. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185128. // compiled on its own).
  185129. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  185130. class WebBrowserComponentInternal : public ActiveXControlComponent
  185131. {
  185132. public:
  185133. WebBrowserComponentInternal()
  185134. : browser (0),
  185135. connectionPoint (0),
  185136. adviseCookie (0)
  185137. {
  185138. }
  185139. ~WebBrowserComponentInternal()
  185140. {
  185141. if (connectionPoint != 0)
  185142. connectionPoint->Unadvise (adviseCookie);
  185143. if (browser != 0)
  185144. browser->Release();
  185145. }
  185146. void createBrowser()
  185147. {
  185148. createControl (&CLSID_WebBrowser);
  185149. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  185150. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  185151. if (connectionPointContainer != 0)
  185152. {
  185153. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  185154. &connectionPoint);
  185155. if (connectionPoint != 0)
  185156. {
  185157. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  185158. jassert (owner != 0);
  185159. EventHandler* handler = new EventHandler (owner);
  185160. connectionPoint->Advise (handler, &adviseCookie);
  185161. }
  185162. }
  185163. }
  185164. void goToURL (const String& url,
  185165. const StringArray* headers,
  185166. const MemoryBlock* postData)
  185167. {
  185168. if (browser != 0)
  185169. {
  185170. LPSAFEARRAY sa = 0;
  185171. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  185172. VariantInit (&flags);
  185173. VariantInit (&frame);
  185174. VariantInit (&postDataVar);
  185175. VariantInit (&headersVar);
  185176. if (headers != 0)
  185177. {
  185178. V_VT (&headersVar) = VT_BSTR;
  185179. V_BSTR (&headersVar) = SysAllocString ((const tchar*) headers->joinIntoString ("\r\n"));
  185180. }
  185181. if (postData != 0 && postData->getSize() > 0)
  185182. {
  185183. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  185184. if (sa != 0)
  185185. {
  185186. void* data = 0;
  185187. SafeArrayAccessData (sa, &data);
  185188. jassert (data != 0);
  185189. if (data != 0)
  185190. {
  185191. postData->copyTo (data, 0, postData->getSize());
  185192. SafeArrayUnaccessData (sa);
  185193. VARIANT postDataVar2;
  185194. VariantInit (&postDataVar2);
  185195. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  185196. V_ARRAY (&postDataVar2) = sa;
  185197. postDataVar = postDataVar2;
  185198. }
  185199. }
  185200. }
  185201. browser->Navigate ((BSTR) (const OLECHAR*) url,
  185202. &flags, &frame,
  185203. &postDataVar, &headersVar);
  185204. if (sa != 0)
  185205. SafeArrayDestroy (sa);
  185206. VariantClear (&flags);
  185207. VariantClear (&frame);
  185208. VariantClear (&postDataVar);
  185209. VariantClear (&headersVar);
  185210. }
  185211. }
  185212. IWebBrowser2* browser;
  185213. juce_UseDebuggingNewOperator
  185214. private:
  185215. IConnectionPoint* connectionPoint;
  185216. DWORD adviseCookie;
  185217. class EventHandler : public IDispatch,
  185218. public ComponentMovementWatcher
  185219. {
  185220. public:
  185221. EventHandler (WebBrowserComponent* owner_)
  185222. : ComponentMovementWatcher (owner_),
  185223. owner (owner_),
  185224. refCount (0)
  185225. {
  185226. }
  185227. ~EventHandler()
  185228. {
  185229. }
  185230. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185231. {
  185232. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  185233. {
  185234. AddRef();
  185235. *result = this;
  185236. return S_OK;
  185237. }
  185238. *result = 0;
  185239. return E_NOINTERFACE;
  185240. }
  185241. ULONG __stdcall AddRef() { return ++refCount; }
  185242. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  185243. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  185244. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  185245. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  185246. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  185247. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  185248. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  185249. UINT __RPC_FAR* /*puArgErr*/)
  185250. {
  185251. switch (dispIdMember)
  185252. {
  185253. case DISPID_BEFORENAVIGATE2:
  185254. {
  185255. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  185256. String url;
  185257. if ((vurl->vt & VT_BYREF) != 0)
  185258. url = *vurl->pbstrVal;
  185259. else
  185260. url = vurl->bstrVal;
  185261. *pDispParams->rgvarg->pboolVal
  185262. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  185263. : VARIANT_TRUE;
  185264. return S_OK;
  185265. }
  185266. default:
  185267. break;
  185268. }
  185269. return E_NOTIMPL;
  185270. }
  185271. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  185272. void componentPeerChanged() {}
  185273. void componentVisibilityChanged (Component&)
  185274. {
  185275. owner->visibilityChanged();
  185276. }
  185277. juce_UseDebuggingNewOperator
  185278. private:
  185279. WebBrowserComponent* const owner;
  185280. int refCount;
  185281. EventHandler (const EventHandler&);
  185282. EventHandler& operator= (const EventHandler&);
  185283. };
  185284. };
  185285. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  185286. : browser (0),
  185287. blankPageShown (false),
  185288. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  185289. {
  185290. setOpaque (true);
  185291. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  185292. }
  185293. WebBrowserComponent::~WebBrowserComponent()
  185294. {
  185295. delete browser;
  185296. }
  185297. void WebBrowserComponent::goToURL (const String& url,
  185298. const StringArray* headers,
  185299. const MemoryBlock* postData)
  185300. {
  185301. lastURL = url;
  185302. lastHeaders.clear();
  185303. if (headers != 0)
  185304. lastHeaders = *headers;
  185305. lastPostData.setSize (0);
  185306. if (postData != 0)
  185307. lastPostData = *postData;
  185308. blankPageShown = false;
  185309. browser->goToURL (url, headers, postData);
  185310. }
  185311. void WebBrowserComponent::stop()
  185312. {
  185313. if (browser->browser != 0)
  185314. browser->browser->Stop();
  185315. }
  185316. void WebBrowserComponent::goBack()
  185317. {
  185318. lastURL = String::empty;
  185319. blankPageShown = false;
  185320. if (browser->browser != 0)
  185321. browser->browser->GoBack();
  185322. }
  185323. void WebBrowserComponent::goForward()
  185324. {
  185325. lastURL = String::empty;
  185326. if (browser->browser != 0)
  185327. browser->browser->GoForward();
  185328. }
  185329. void WebBrowserComponent::refresh()
  185330. {
  185331. if (browser->browser != 0)
  185332. browser->browser->Refresh();
  185333. }
  185334. void WebBrowserComponent::paint (Graphics& g)
  185335. {
  185336. if (browser->browser == 0)
  185337. g.fillAll (Colours::white);
  185338. }
  185339. void WebBrowserComponent::checkWindowAssociation()
  185340. {
  185341. if (isShowing())
  185342. {
  185343. if (browser->browser == 0 && getPeer() != 0)
  185344. {
  185345. browser->createBrowser();
  185346. reloadLastURL();
  185347. }
  185348. else
  185349. {
  185350. if (blankPageShown)
  185351. goBack();
  185352. }
  185353. }
  185354. else
  185355. {
  185356. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  185357. {
  185358. // when the component becomes invisible, some stuff like flash
  185359. // carries on playing audio, so we need to force it onto a blank
  185360. // page to avoid this..
  185361. blankPageShown = true;
  185362. browser->goToURL ("about:blank", 0, 0);
  185363. }
  185364. }
  185365. }
  185366. void WebBrowserComponent::reloadLastURL()
  185367. {
  185368. if (lastURL.isNotEmpty())
  185369. {
  185370. goToURL (lastURL, &lastHeaders, &lastPostData);
  185371. lastURL = String::empty;
  185372. }
  185373. }
  185374. void WebBrowserComponent::parentHierarchyChanged()
  185375. {
  185376. checkWindowAssociation();
  185377. }
  185378. void WebBrowserComponent::resized()
  185379. {
  185380. browser->setSize (getWidth(), getHeight());
  185381. }
  185382. void WebBrowserComponent::visibilityChanged()
  185383. {
  185384. checkWindowAssociation();
  185385. }
  185386. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185387. {
  185388. return true;
  185389. }
  185390. #endif
  185391. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185392. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185393. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185394. // compiled on its own).
  185395. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185396. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185397. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185398. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185399. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185400. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185401. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  185402. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  185403. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  185404. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  185405. #define WGL_ACCELERATION_ARB 0x2003
  185406. #define WGL_SWAP_METHOD_ARB 0x2007
  185407. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  185408. #define WGL_PIXEL_TYPE_ARB 0x2013
  185409. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  185410. #define WGL_COLOR_BITS_ARB 0x2014
  185411. #define WGL_RED_BITS_ARB 0x2015
  185412. #define WGL_GREEN_BITS_ARB 0x2017
  185413. #define WGL_BLUE_BITS_ARB 0x2019
  185414. #define WGL_ALPHA_BITS_ARB 0x201B
  185415. #define WGL_DEPTH_BITS_ARB 0x2022
  185416. #define WGL_STENCIL_BITS_ARB 0x2023
  185417. #define WGL_FULL_ACCELERATION_ARB 0x2027
  185418. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  185419. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  185420. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  185421. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  185422. #define WGL_STEREO_ARB 0x2012
  185423. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  185424. #define WGL_SAMPLES_ARB 0x2042
  185425. #define WGL_TYPE_RGBA_ARB 0x202B
  185426. static void getWglExtensions (HDC dc, StringArray& result) throw()
  185427. {
  185428. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  185429. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  185430. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  185431. else
  185432. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  185433. }
  185434. class WindowedGLContext : public OpenGLContext
  185435. {
  185436. public:
  185437. WindowedGLContext (Component* const component_,
  185438. HGLRC contextToShareWith,
  185439. const OpenGLPixelFormat& pixelFormat)
  185440. : renderContext (0),
  185441. nativeWindow (0),
  185442. dc (0),
  185443. component (component_)
  185444. {
  185445. jassert (component != 0);
  185446. createNativeWindow();
  185447. // Use a default pixel format that should be supported everywhere
  185448. PIXELFORMATDESCRIPTOR pfd;
  185449. zerostruct (pfd);
  185450. pfd.nSize = sizeof (pfd);
  185451. pfd.nVersion = 1;
  185452. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  185453. pfd.iPixelType = PFD_TYPE_RGBA;
  185454. pfd.cColorBits = 24;
  185455. pfd.cDepthBits = 16;
  185456. const int format = ChoosePixelFormat (dc, &pfd);
  185457. if (format != 0)
  185458. SetPixelFormat (dc, format, &pfd);
  185459. renderContext = wglCreateContext (dc);
  185460. makeActive();
  185461. setPixelFormat (pixelFormat);
  185462. if (contextToShareWith != 0 && renderContext != 0)
  185463. wglShareLists (contextToShareWith, renderContext);
  185464. }
  185465. ~WindowedGLContext()
  185466. {
  185467. makeInactive();
  185468. wglDeleteContext (renderContext);
  185469. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185470. delete nativeWindow;
  185471. }
  185472. bool makeActive() const throw()
  185473. {
  185474. jassert (renderContext != 0);
  185475. return wglMakeCurrent (dc, renderContext) != 0;
  185476. }
  185477. bool makeInactive() const throw()
  185478. {
  185479. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  185480. }
  185481. bool isActive() const throw()
  185482. {
  185483. return wglGetCurrentContext() == renderContext;
  185484. }
  185485. const OpenGLPixelFormat getPixelFormat() const
  185486. {
  185487. OpenGLPixelFormat pf;
  185488. makeActive();
  185489. StringArray availableExtensions;
  185490. getWglExtensions (dc, availableExtensions);
  185491. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  185492. return pf;
  185493. }
  185494. void* getRawContext() const throw()
  185495. {
  185496. return renderContext;
  185497. }
  185498. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  185499. {
  185500. makeActive();
  185501. PIXELFORMATDESCRIPTOR pfd;
  185502. zerostruct (pfd);
  185503. pfd.nSize = sizeof (pfd);
  185504. pfd.nVersion = 1;
  185505. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  185506. pfd.iPixelType = PFD_TYPE_RGBA;
  185507. pfd.iLayerType = PFD_MAIN_PLANE;
  185508. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  185509. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  185510. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  185511. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  185512. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  185513. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  185514. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  185515. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  185516. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  185517. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  185518. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  185519. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  185520. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  185521. int format = 0;
  185522. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  185523. StringArray availableExtensions;
  185524. getWglExtensions (dc, availableExtensions);
  185525. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185526. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  185527. {
  185528. int attributes[64];
  185529. int n = 0;
  185530. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  185531. attributes[n++] = GL_TRUE;
  185532. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  185533. attributes[n++] = GL_TRUE;
  185534. attributes[n++] = WGL_ACCELERATION_ARB;
  185535. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  185536. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  185537. attributes[n++] = GL_TRUE;
  185538. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  185539. attributes[n++] = WGL_TYPE_RGBA_ARB;
  185540. attributes[n++] = WGL_COLOR_BITS_ARB;
  185541. attributes[n++] = pfd.cColorBits;
  185542. attributes[n++] = WGL_RED_BITS_ARB;
  185543. attributes[n++] = pixelFormat.redBits;
  185544. attributes[n++] = WGL_GREEN_BITS_ARB;
  185545. attributes[n++] = pixelFormat.greenBits;
  185546. attributes[n++] = WGL_BLUE_BITS_ARB;
  185547. attributes[n++] = pixelFormat.blueBits;
  185548. attributes[n++] = WGL_ALPHA_BITS_ARB;
  185549. attributes[n++] = pixelFormat.alphaBits;
  185550. attributes[n++] = WGL_DEPTH_BITS_ARB;
  185551. attributes[n++] = pixelFormat.depthBufferBits;
  185552. if (pixelFormat.stencilBufferBits > 0)
  185553. {
  185554. attributes[n++] = WGL_STENCIL_BITS_ARB;
  185555. attributes[n++] = pixelFormat.stencilBufferBits;
  185556. }
  185557. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  185558. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  185559. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  185560. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  185561. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  185562. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  185563. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185564. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  185565. if (availableExtensions.contains ("WGL_ARB_multisample")
  185566. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  185567. {
  185568. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  185569. attributes[n++] = 1;
  185570. attributes[n++] = WGL_SAMPLES_ARB;
  185571. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  185572. }
  185573. attributes[n++] = 0;
  185574. UINT formatsCount;
  185575. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  185576. (void) ok;
  185577. jassert (ok);
  185578. }
  185579. else
  185580. {
  185581. format = ChoosePixelFormat (dc, &pfd);
  185582. }
  185583. if (format != 0)
  185584. {
  185585. makeInactive();
  185586. // win32 can't change the pixel format of a window, so need to delete the
  185587. // old one and create a new one..
  185588. jassert (nativeWindow != 0);
  185589. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185590. delete nativeWindow;
  185591. createNativeWindow();
  185592. if (SetPixelFormat (dc, format, &pfd))
  185593. {
  185594. wglDeleteContext (renderContext);
  185595. renderContext = wglCreateContext (dc);
  185596. jassert (renderContext != 0);
  185597. return renderContext != 0;
  185598. }
  185599. }
  185600. return false;
  185601. }
  185602. void updateWindowPosition (int x, int y, int w, int h, int)
  185603. {
  185604. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  185605. x, y, w, h,
  185606. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  185607. }
  185608. void repaint()
  185609. {
  185610. const Rectangle<int> bounds (nativeWindow->getBounds());
  185611. nativeWindow->repaint (0, 0, bounds.getWidth(), bounds.getHeight());
  185612. }
  185613. void swapBuffers()
  185614. {
  185615. SwapBuffers (dc);
  185616. }
  185617. bool setSwapInterval (const int numFramesPerSwap)
  185618. {
  185619. makeActive();
  185620. StringArray availableExtensions;
  185621. getWglExtensions (dc, availableExtensions);
  185622. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  185623. return availableExtensions.contains ("WGL_EXT_swap_control")
  185624. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  185625. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  185626. }
  185627. int getSwapInterval() const
  185628. {
  185629. makeActive();
  185630. StringArray availableExtensions;
  185631. getWglExtensions (dc, availableExtensions);
  185632. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  185633. if (availableExtensions.contains ("WGL_EXT_swap_control")
  185634. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  185635. return wglGetSwapIntervalEXT();
  185636. return 0;
  185637. }
  185638. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  185639. {
  185640. jassert (isActive());
  185641. StringArray availableExtensions;
  185642. getWglExtensions (dc, availableExtensions);
  185643. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185644. int numTypes = 0;
  185645. if (availableExtensions.contains("WGL_ARB_pixel_format")
  185646. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185647. {
  185648. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  185649. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  185650. jassertfalse
  185651. }
  185652. else
  185653. {
  185654. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  185655. }
  185656. OpenGLPixelFormat pf;
  185657. for (int i = 0; i < numTypes; ++i)
  185658. {
  185659. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  185660. {
  185661. bool alreadyListed = false;
  185662. for (int j = results.size(); --j >= 0;)
  185663. if (pf == *results.getUnchecked(j))
  185664. alreadyListed = true;
  185665. if (! alreadyListed)
  185666. results.add (new OpenGLPixelFormat (pf));
  185667. }
  185668. }
  185669. }
  185670. void* getNativeWindowHandle() const
  185671. {
  185672. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  185673. }
  185674. juce_UseDebuggingNewOperator
  185675. HGLRC renderContext;
  185676. private:
  185677. Win32ComponentPeer* nativeWindow;
  185678. Component* const component;
  185679. HDC dc;
  185680. void createNativeWindow()
  185681. {
  185682. nativeWindow = new Win32ComponentPeer (component, 0);
  185683. nativeWindow->dontRepaint = true;
  185684. nativeWindow->setVisible (true);
  185685. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  185686. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  185687. if (peer != 0)
  185688. {
  185689. SetParent (hwnd, (HWND) peer->getNativeHandle());
  185690. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  185691. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  185692. }
  185693. dc = GetDC (hwnd);
  185694. }
  185695. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  185696. OpenGLPixelFormat& result,
  185697. const StringArray& availableExtensions) const throw()
  185698. {
  185699. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185700. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185701. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185702. {
  185703. int attributes[32];
  185704. int numAttributes = 0;
  185705. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  185706. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  185707. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  185708. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  185709. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  185710. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  185711. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  185712. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  185713. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  185714. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  185715. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  185716. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  185717. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  185718. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  185719. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185720. if (availableExtensions.contains ("WGL_ARB_multisample"))
  185721. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  185722. int values[32];
  185723. zeromem (values, sizeof (values));
  185724. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  185725. {
  185726. int n = 0;
  185727. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  185728. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  185729. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  185730. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  185731. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  185732. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  185733. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  185734. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  185735. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  185736. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  185737. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  185738. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  185739. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  185740. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  185741. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  185742. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  185743. return isValidFormat;
  185744. }
  185745. else
  185746. {
  185747. jassertfalse
  185748. }
  185749. }
  185750. else
  185751. {
  185752. PIXELFORMATDESCRIPTOR pfd;
  185753. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  185754. {
  185755. result.redBits = pfd.cRedBits;
  185756. result.greenBits = pfd.cGreenBits;
  185757. result.blueBits = pfd.cBlueBits;
  185758. result.alphaBits = pfd.cAlphaBits;
  185759. result.depthBufferBits = pfd.cDepthBits;
  185760. result.stencilBufferBits = pfd.cStencilBits;
  185761. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  185762. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  185763. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  185764. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  185765. result.fullSceneAntiAliasingNumSamples = 0;
  185766. return true;
  185767. }
  185768. else
  185769. {
  185770. jassertfalse
  185771. }
  185772. }
  185773. return false;
  185774. }
  185775. WindowedGLContext (const WindowedGLContext&);
  185776. WindowedGLContext& operator= (const WindowedGLContext&);
  185777. };
  185778. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  185779. const OpenGLPixelFormat& pixelFormat,
  185780. const OpenGLContext* const contextToShareWith)
  185781. {
  185782. WindowedGLContext* c = new WindowedGLContext (component,
  185783. contextToShareWith != 0 ? (HGLRC) contextToShareWith->getRawContext() : 0,
  185784. pixelFormat);
  185785. if (c->renderContext == 0)
  185786. deleteAndZero (c);
  185787. return c;
  185788. }
  185789. void* OpenGLComponent::getNativeWindowHandle() const
  185790. {
  185791. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle() : 0;
  185792. }
  185793. void juce_glViewport (const int w, const int h)
  185794. {
  185795. glViewport (0, 0, w, h);
  185796. }
  185797. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  185798. OwnedArray <OpenGLPixelFormat>& results)
  185799. {
  185800. Component tempComp;
  185801. {
  185802. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  185803. wc.makeActive();
  185804. wc.findAlternativeOpenGLPixelFormats (results);
  185805. }
  185806. }
  185807. #endif
  185808. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185809. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  185810. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185811. // compiled on its own).
  185812. #if JUCE_INCLUDED_FILE
  185813. #if JUCE_USE_CDREADER
  185814. //***************************************************************************
  185815. // %%% TARGET STATUS VALUES %%%
  185816. //***************************************************************************
  185817. #define STATUS_GOOD 0x00 // Status Good
  185818. #define STATUS_CHKCOND 0x02 // Check Condition
  185819. #define STATUS_CONDMET 0x04 // Condition Met
  185820. #define STATUS_BUSY 0x08 // Busy
  185821. #define STATUS_INTERM 0x10 // Intermediate
  185822. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  185823. #define STATUS_RESCONF 0x18 // Reservation conflict
  185824. #define STATUS_COMTERM 0x22 // Command Terminated
  185825. #define STATUS_QFULL 0x28 // Queue full
  185826. //***************************************************************************
  185827. // %%% SCSI MISCELLANEOUS EQUATES %%%
  185828. //***************************************************************************
  185829. #define MAXLUN 7 // Maximum Logical Unit Id
  185830. #define MAXTARG 7 // Maximum Target Id
  185831. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  185832. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  185833. //***************************************************************************
  185834. // %%% Commands for all Device Types %%%
  185835. //***************************************************************************
  185836. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  185837. #define SCSI_COMPARE 0x39 // Compare (O)
  185838. #define SCSI_COPY 0x18 // Copy (O)
  185839. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  185840. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  185841. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  185842. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  185843. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  185844. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  185845. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  185846. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  185847. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  185848. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  185849. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  185850. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  185851. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  185852. //***************************************************************************
  185853. // %%% Commands Unique to Direct Access Devices %%%
  185854. //***************************************************************************
  185855. #define SCSI_COMPARE 0x39 // Compare (O)
  185856. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  185857. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  185858. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  185859. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  185860. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  185861. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  185862. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  185863. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  185864. #define SCSI_READ_LONG 0x3E // Read Long (O)
  185865. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  185866. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  185867. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  185868. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  185869. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  185870. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  185871. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  185872. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  185873. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  185874. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  185875. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  185876. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  185877. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  185878. #define SCSI_VERIFY 0x2F // Verify (O)
  185879. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  185880. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  185881. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  185882. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  185883. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  185884. //***************************************************************************
  185885. // %%% Commands Unique to Sequential Access Devices %%%
  185886. //***************************************************************************
  185887. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  185888. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  185889. #define SCSI_LOCATE 0x2B // Locate (O)
  185890. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  185891. #define SCSI_READ_POS 0x34 // Read Position (O)
  185892. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  185893. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  185894. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  185895. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  185896. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  185897. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  185898. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  185899. //***************************************************************************
  185900. // %%% Commands Unique to Printer Devices %%%
  185901. //***************************************************************************
  185902. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  185903. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  185904. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  185905. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  185906. //***************************************************************************
  185907. // %%% Commands Unique to Processor Devices %%%
  185908. //***************************************************************************
  185909. #define SCSI_RECEIVE 0x08 // Receive (O)
  185910. #define SCSI_SEND 0x0A // Send (O)
  185911. //***************************************************************************
  185912. // %%% Commands Unique to Write-Once Devices %%%
  185913. //***************************************************************************
  185914. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  185915. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  185916. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  185917. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  185918. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  185919. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  185920. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  185921. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  185922. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  185923. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  185924. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  185925. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  185926. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  185927. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  185928. //***************************************************************************
  185929. // %%% Commands Unique to CD-ROM Devices %%%
  185930. //***************************************************************************
  185931. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  185932. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  185933. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  185934. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  185935. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  185936. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  185937. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  185938. #define SCSI_READHEADER 0x44 // Read Header (O)
  185939. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  185940. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  185941. //***************************************************************************
  185942. // %%% Commands Unique to Scanner Devices %%%
  185943. //***************************************************************************
  185944. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  185945. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  185946. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  185947. #define SCSI_SCAN 0x1B // Scan (O)
  185948. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  185949. //***************************************************************************
  185950. // %%% Commands Unique to Optical Memory Devices %%%
  185951. //***************************************************************************
  185952. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  185953. //***************************************************************************
  185954. // %%% Commands Unique to Medium Changer Devices %%%
  185955. //***************************************************************************
  185956. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  185957. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  185958. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  185959. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  185960. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  185961. //***************************************************************************
  185962. // %%% Commands Unique to Communication Devices %%%
  185963. //***************************************************************************
  185964. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  185965. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  185966. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  185967. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  185968. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  185969. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  185970. //***************************************************************************
  185971. // %%% Request Sense Data Format %%%
  185972. //***************************************************************************
  185973. typedef struct {
  185974. BYTE ErrorCode; // Error Code (70H or 71H)
  185975. BYTE SegmentNum; // Number of current segment descriptor
  185976. BYTE SenseKey; // Sense Key(See bit definitions too)
  185977. BYTE InfoByte0; // Information MSB
  185978. BYTE InfoByte1; // Information MID
  185979. BYTE InfoByte2; // Information MID
  185980. BYTE InfoByte3; // Information LSB
  185981. BYTE AddSenLen; // Additional Sense Length
  185982. BYTE ComSpecInf0; // Command Specific Information MSB
  185983. BYTE ComSpecInf1; // Command Specific Information MID
  185984. BYTE ComSpecInf2; // Command Specific Information MID
  185985. BYTE ComSpecInf3; // Command Specific Information LSB
  185986. BYTE AddSenseCode; // Additional Sense Code
  185987. BYTE AddSenQual; // Additional Sense Code Qualifier
  185988. BYTE FieldRepUCode; // Field Replaceable Unit Code
  185989. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  185990. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  185991. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  185992. BYTE AddSenseBytes; // Additional Sense Bytes
  185993. } SENSE_DATA_FMT;
  185994. //***************************************************************************
  185995. // %%% REQUEST SENSE ERROR CODE %%%
  185996. //***************************************************************************
  185997. #define SERROR_CURRENT 0x70 // Current Errors
  185998. #define SERROR_DEFERED 0x71 // Deferred Errors
  185999. //***************************************************************************
  186000. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  186001. //***************************************************************************
  186002. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  186003. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  186004. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  186005. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  186006. //***************************************************************************
  186007. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  186008. //***************************************************************************
  186009. #define KEY_NOSENSE 0x00 // No Sense
  186010. #define KEY_RECERROR 0x01 // Recovered Error
  186011. #define KEY_NOTREADY 0x02 // Not Ready
  186012. #define KEY_MEDIUMERR 0x03 // Medium Error
  186013. #define KEY_HARDERROR 0x04 // Hardware Error
  186014. #define KEY_ILLGLREQ 0x05 // Illegal Request
  186015. #define KEY_UNITATT 0x06 // Unit Attention
  186016. #define KEY_DATAPROT 0x07 // Data Protect
  186017. #define KEY_BLANKCHK 0x08 // Blank Check
  186018. #define KEY_VENDSPEC 0x09 // Vendor Specific
  186019. #define KEY_COPYABORT 0x0A // Copy Abort
  186020. #define KEY_EQUAL 0x0C // Equal (Search)
  186021. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  186022. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  186023. #define KEY_RESERVED 0x0F // Reserved
  186024. //***************************************************************************
  186025. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  186026. //***************************************************************************
  186027. #define DTYPE_DASD 0x00 // Disk Device
  186028. #define DTYPE_SEQD 0x01 // Tape Device
  186029. #define DTYPE_PRNT 0x02 // Printer
  186030. #define DTYPE_PROC 0x03 // Processor
  186031. #define DTYPE_WORM 0x04 // Write-once read-multiple
  186032. #define DTYPE_CROM 0x05 // CD-ROM device
  186033. #define DTYPE_SCAN 0x06 // Scanner device
  186034. #define DTYPE_OPTI 0x07 // Optical memory device
  186035. #define DTYPE_JUKE 0x08 // Medium Changer device
  186036. #define DTYPE_COMM 0x09 // Communications device
  186037. #define DTYPE_RESL 0x0A // Reserved (low)
  186038. #define DTYPE_RESH 0x1E // Reserved (high)
  186039. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  186040. //***************************************************************************
  186041. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  186042. //***************************************************************************
  186043. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  186044. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  186045. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  186046. #define ANSI_RESLO 0x3 // Reserved (low)
  186047. #define ANSI_RESHI 0x7 // Reserved (high)
  186048. typedef struct
  186049. {
  186050. USHORT Length;
  186051. UCHAR ScsiStatus;
  186052. UCHAR PathId;
  186053. UCHAR TargetId;
  186054. UCHAR Lun;
  186055. UCHAR CdbLength;
  186056. UCHAR SenseInfoLength;
  186057. UCHAR DataIn;
  186058. ULONG DataTransferLength;
  186059. ULONG TimeOutValue;
  186060. ULONG DataBufferOffset;
  186061. ULONG SenseInfoOffset;
  186062. UCHAR Cdb[16];
  186063. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  186064. typedef struct
  186065. {
  186066. USHORT Length;
  186067. UCHAR ScsiStatus;
  186068. UCHAR PathId;
  186069. UCHAR TargetId;
  186070. UCHAR Lun;
  186071. UCHAR CdbLength;
  186072. UCHAR SenseInfoLength;
  186073. UCHAR DataIn;
  186074. ULONG DataTransferLength;
  186075. ULONG TimeOutValue;
  186076. PVOID DataBuffer;
  186077. ULONG SenseInfoOffset;
  186078. UCHAR Cdb[16];
  186079. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  186080. typedef struct
  186081. {
  186082. SCSI_PASS_THROUGH_DIRECT spt;
  186083. ULONG Filler;
  186084. UCHAR ucSenseBuf[32];
  186085. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  186086. typedef struct
  186087. {
  186088. ULONG Length;
  186089. UCHAR PortNumber;
  186090. UCHAR PathId;
  186091. UCHAR TargetId;
  186092. UCHAR Lun;
  186093. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  186094. #define METHOD_BUFFERED 0
  186095. #define METHOD_IN_DIRECT 1
  186096. #define METHOD_OUT_DIRECT 2
  186097. #define METHOD_NEITHER 3
  186098. #define FILE_ANY_ACCESS 0
  186099. #ifndef FILE_READ_ACCESS
  186100. #define FILE_READ_ACCESS (0x0001)
  186101. #endif
  186102. #ifndef FILE_WRITE_ACCESS
  186103. #define FILE_WRITE_ACCESS (0x0002)
  186104. #endif
  186105. #define IOCTL_SCSI_BASE 0x00000004
  186106. #define SCSI_IOCTL_DATA_OUT 0
  186107. #define SCSI_IOCTL_DATA_IN 1
  186108. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  186109. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  186110. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  186111. )
  186112. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186113. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  186114. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186115. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  186116. #define SENSE_LEN 14
  186117. #define SRB_DIR_SCSI 0x00
  186118. #define SRB_POSTING 0x01
  186119. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  186120. #define SRB_DIR_IN 0x08
  186121. #define SRB_DIR_OUT 0x10
  186122. #define SRB_EVENT_NOTIFY 0x40
  186123. #define RESIDUAL_COUNT_SUPPORTED 0x02
  186124. #define MAX_SRB_TIMEOUT 1080001u
  186125. #define DEFAULT_SRB_TIMEOUT 1080001u
  186126. #define SC_HA_INQUIRY 0x00
  186127. #define SC_GET_DEV_TYPE 0x01
  186128. #define SC_EXEC_SCSI_CMD 0x02
  186129. #define SC_ABORT_SRB 0x03
  186130. #define SC_RESET_DEV 0x04
  186131. #define SC_SET_HA_PARMS 0x05
  186132. #define SC_GET_DISK_INFO 0x06
  186133. #define SC_RESCAN_SCSI_BUS 0x07
  186134. #define SC_GETSET_TIMEOUTS 0x08
  186135. #define SS_PENDING 0x00
  186136. #define SS_COMP 0x01
  186137. #define SS_ABORTED 0x02
  186138. #define SS_ABORT_FAIL 0x03
  186139. #define SS_ERR 0x04
  186140. #define SS_INVALID_CMD 0x80
  186141. #define SS_INVALID_HA 0x81
  186142. #define SS_NO_DEVICE 0x82
  186143. #define SS_INVALID_SRB 0xE0
  186144. #define SS_OLD_MANAGER 0xE1
  186145. #define SS_BUFFER_ALIGN 0xE1
  186146. #define SS_ILLEGAL_MODE 0xE2
  186147. #define SS_NO_ASPI 0xE3
  186148. #define SS_FAILED_INIT 0xE4
  186149. #define SS_ASPI_IS_BUSY 0xE5
  186150. #define SS_BUFFER_TO_BIG 0xE6
  186151. #define SS_BUFFER_TOO_BIG 0xE6
  186152. #define SS_MISMATCHED_COMPONENTS 0xE7
  186153. #define SS_NO_ADAPTERS 0xE8
  186154. #define SS_INSUFFICIENT_RESOURCES 0xE9
  186155. #define SS_ASPI_IS_SHUTDOWN 0xEA
  186156. #define SS_BAD_INSTALL 0xEB
  186157. #define HASTAT_OK 0x00
  186158. #define HASTAT_SEL_TO 0x11
  186159. #define HASTAT_DO_DU 0x12
  186160. #define HASTAT_BUS_FREE 0x13
  186161. #define HASTAT_PHASE_ERR 0x14
  186162. #define HASTAT_TIMEOUT 0x09
  186163. #define HASTAT_COMMAND_TIMEOUT 0x0B
  186164. #define HASTAT_MESSAGE_REJECT 0x0D
  186165. #define HASTAT_BUS_RESET 0x0E
  186166. #define HASTAT_PARITY_ERROR 0x0F
  186167. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  186168. #define PACKED
  186169. #pragma pack(1)
  186170. typedef struct
  186171. {
  186172. BYTE SRB_Cmd;
  186173. BYTE SRB_Status;
  186174. BYTE SRB_HaID;
  186175. BYTE SRB_Flags;
  186176. DWORD SRB_Hdr_Rsvd;
  186177. BYTE HA_Count;
  186178. BYTE HA_SCSI_ID;
  186179. BYTE HA_ManagerId[16];
  186180. BYTE HA_Identifier[16];
  186181. BYTE HA_Unique[16];
  186182. WORD HA_Rsvd1;
  186183. BYTE pad[20];
  186184. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  186185. typedef struct
  186186. {
  186187. BYTE SRB_Cmd;
  186188. BYTE SRB_Status;
  186189. BYTE SRB_HaID;
  186190. BYTE SRB_Flags;
  186191. DWORD SRB_Hdr_Rsvd;
  186192. BYTE SRB_Target;
  186193. BYTE SRB_Lun;
  186194. BYTE SRB_DeviceType;
  186195. BYTE SRB_Rsvd1;
  186196. BYTE pad[68];
  186197. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  186198. typedef struct
  186199. {
  186200. BYTE SRB_Cmd;
  186201. BYTE SRB_Status;
  186202. BYTE SRB_HaID;
  186203. BYTE SRB_Flags;
  186204. DWORD SRB_Hdr_Rsvd;
  186205. BYTE SRB_Target;
  186206. BYTE SRB_Lun;
  186207. WORD SRB_Rsvd1;
  186208. DWORD SRB_BufLen;
  186209. BYTE FAR *SRB_BufPointer;
  186210. BYTE SRB_SenseLen;
  186211. BYTE SRB_CDBLen;
  186212. BYTE SRB_HaStat;
  186213. BYTE SRB_TargStat;
  186214. VOID FAR *SRB_PostProc;
  186215. BYTE SRB_Rsvd2[20];
  186216. BYTE CDBByte[16];
  186217. BYTE SenseArea[SENSE_LEN+2];
  186218. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  186219. typedef struct
  186220. {
  186221. BYTE SRB_Cmd;
  186222. BYTE SRB_Status;
  186223. BYTE SRB_HaId;
  186224. BYTE SRB_Flags;
  186225. DWORD SRB_Hdr_Rsvd;
  186226. } PACKED SRB, *PSRB, FAR *LPSRB;
  186227. #pragma pack()
  186228. struct CDDeviceInfo
  186229. {
  186230. char vendor[9];
  186231. char productId[17];
  186232. char rev[5];
  186233. char vendorSpec[21];
  186234. BYTE ha;
  186235. BYTE tgt;
  186236. BYTE lun;
  186237. char scsiDriveLetter; // will be 0 if not using scsi
  186238. };
  186239. class CDReadBuffer
  186240. {
  186241. public:
  186242. int startFrame;
  186243. int numFrames;
  186244. int dataStartOffset;
  186245. int dataLength;
  186246. BYTE* buffer;
  186247. int bufferSize;
  186248. int index;
  186249. bool wantsIndex;
  186250. CDReadBuffer (const int numberOfFrames)
  186251. : startFrame (0),
  186252. numFrames (0),
  186253. dataStartOffset (0),
  186254. dataLength (0),
  186255. index (0),
  186256. wantsIndex (false)
  186257. {
  186258. bufferSize = 2352 * numberOfFrames;
  186259. buffer = (BYTE*) malloc (bufferSize);
  186260. }
  186261. ~CDReadBuffer()
  186262. {
  186263. free (buffer);
  186264. }
  186265. bool isZero() const
  186266. {
  186267. BYTE* p = buffer + dataStartOffset;
  186268. for (int i = dataLength; --i >= 0;)
  186269. if (*p++ != 0)
  186270. return false;
  186271. return true;
  186272. }
  186273. };
  186274. class CDDeviceHandle;
  186275. class CDController
  186276. {
  186277. public:
  186278. CDController();
  186279. virtual ~CDController();
  186280. virtual bool read (CDReadBuffer* t) = 0;
  186281. virtual void shutDown();
  186282. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  186283. int getLastIndex();
  186284. public:
  186285. bool initialised;
  186286. CDDeviceHandle* deviceInfo;
  186287. int framesToCheck, framesOverlap;
  186288. void prepare (SRB_ExecSCSICmd& s);
  186289. void perform (SRB_ExecSCSICmd& s);
  186290. void setPaused (bool paused);
  186291. };
  186292. #pragma pack(1)
  186293. struct TOCTRACK
  186294. {
  186295. BYTE rsvd;
  186296. BYTE ADR;
  186297. BYTE trackNumber;
  186298. BYTE rsvd2;
  186299. BYTE addr[4];
  186300. };
  186301. struct TOC
  186302. {
  186303. WORD tocLen;
  186304. BYTE firstTrack;
  186305. BYTE lastTrack;
  186306. TOCTRACK tracks[100];
  186307. };
  186308. #pragma pack()
  186309. enum
  186310. {
  186311. READTYPE_ANY = 0,
  186312. READTYPE_ATAPI1 = 1,
  186313. READTYPE_ATAPI2 = 2,
  186314. READTYPE_READ6 = 3,
  186315. READTYPE_READ10 = 4,
  186316. READTYPE_READ_D8 = 5,
  186317. READTYPE_READ_D4 = 6,
  186318. READTYPE_READ_D4_1 = 7,
  186319. READTYPE_READ10_2 = 8
  186320. };
  186321. class CDDeviceHandle
  186322. {
  186323. public:
  186324. CDDeviceHandle (const CDDeviceInfo* const device)
  186325. : scsiHandle (0),
  186326. readType (READTYPE_ANY),
  186327. controller (0)
  186328. {
  186329. memcpy (&info, device, sizeof (info));
  186330. }
  186331. ~CDDeviceHandle()
  186332. {
  186333. if (controller != 0)
  186334. {
  186335. controller->shutDown();
  186336. delete controller;
  186337. }
  186338. if (scsiHandle != 0)
  186339. CloseHandle (scsiHandle);
  186340. }
  186341. bool readTOC (TOC* lpToc, bool useMSF);
  186342. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  186343. void openDrawer (bool shouldBeOpen);
  186344. CDDeviceInfo info;
  186345. HANDLE scsiHandle;
  186346. BYTE readType;
  186347. private:
  186348. CDController* controller;
  186349. bool testController (const int readType,
  186350. CDController* const newController,
  186351. CDReadBuffer* const bufferToUse);
  186352. };
  186353. DWORD (*fGetASPI32SupportInfo)(void);
  186354. DWORD (*fSendASPI32Command)(LPSRB);
  186355. static HINSTANCE winAspiLib = 0;
  186356. static bool usingScsi = false;
  186357. static bool initialised = false;
  186358. static bool InitialiseCDRipper()
  186359. {
  186360. if (! initialised)
  186361. {
  186362. initialised = true;
  186363. OSVERSIONINFO info;
  186364. info.dwOSVersionInfoSize = sizeof (info);
  186365. GetVersionEx (&info);
  186366. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186367. if (! usingScsi)
  186368. {
  186369. fGetASPI32SupportInfo = 0;
  186370. fSendASPI32Command = 0;
  186371. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186372. if (winAspiLib != 0)
  186373. {
  186374. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186375. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186376. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186377. return false;
  186378. }
  186379. else
  186380. {
  186381. usingScsi = true;
  186382. }
  186383. }
  186384. }
  186385. return true;
  186386. }
  186387. static void DeinitialiseCDRipper()
  186388. {
  186389. if (winAspiLib != 0)
  186390. {
  186391. fGetASPI32SupportInfo = 0;
  186392. fSendASPI32Command = 0;
  186393. FreeLibrary (winAspiLib);
  186394. winAspiLib = 0;
  186395. }
  186396. initialised = false;
  186397. }
  186398. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186399. {
  186400. TCHAR devicePath[8];
  186401. devicePath[0] = '\\';
  186402. devicePath[1] = '\\';
  186403. devicePath[2] = '.';
  186404. devicePath[3] = '\\';
  186405. devicePath[4] = driveLetter;
  186406. devicePath[5] = ':';
  186407. devicePath[6] = 0;
  186408. OSVERSIONINFO info;
  186409. info.dwOSVersionInfoSize = sizeof (info);
  186410. GetVersionEx (&info);
  186411. DWORD flags = GENERIC_READ;
  186412. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  186413. flags = GENERIC_READ | GENERIC_WRITE;
  186414. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186415. if (h == INVALID_HANDLE_VALUE)
  186416. {
  186417. flags ^= GENERIC_WRITE;
  186418. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186419. }
  186420. return h;
  186421. }
  186422. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  186423. const char driveLetter,
  186424. HANDLE& deviceHandle,
  186425. const bool retryOnFailure = true)
  186426. {
  186427. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  186428. zerostruct (s);
  186429. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  186430. s.spt.CdbLength = srb->SRB_CDBLen;
  186431. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  186432. ? SCSI_IOCTL_DATA_IN
  186433. : ((srb->SRB_Flags & SRB_DIR_OUT)
  186434. ? SCSI_IOCTL_DATA_OUT
  186435. : SCSI_IOCTL_DATA_UNSPECIFIED));
  186436. s.spt.DataTransferLength = srb->SRB_BufLen;
  186437. s.spt.TimeOutValue = 5;
  186438. s.spt.DataBuffer = srb->SRB_BufPointer;
  186439. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186440. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  186441. srb->SRB_Status = SS_ERR;
  186442. srb->SRB_TargStat = 0x0004;
  186443. DWORD bytesReturned = 0;
  186444. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186445. &s, sizeof (s),
  186446. &s, sizeof (s),
  186447. &bytesReturned, 0) != 0)
  186448. {
  186449. srb->SRB_Status = SS_COMP;
  186450. }
  186451. else if (retryOnFailure)
  186452. {
  186453. const DWORD error = GetLastError();
  186454. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  186455. {
  186456. if (error != ERROR_INVALID_HANDLE)
  186457. CloseHandle (deviceHandle);
  186458. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  186459. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  186460. }
  186461. }
  186462. return srb->SRB_Status;
  186463. }
  186464. // Controller types..
  186465. class ControllerType1 : public CDController
  186466. {
  186467. public:
  186468. ControllerType1() {}
  186469. ~ControllerType1() {}
  186470. bool read (CDReadBuffer* rb)
  186471. {
  186472. if (rb->numFrames * 2352 > rb->bufferSize)
  186473. return false;
  186474. SRB_ExecSCSICmd s;
  186475. prepare (s);
  186476. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186477. s.SRB_BufLen = rb->bufferSize;
  186478. s.SRB_BufPointer = rb->buffer;
  186479. s.SRB_CDBLen = 12;
  186480. s.CDBByte[0] = 0xBE;
  186481. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186482. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186483. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186484. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186485. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  186486. perform (s);
  186487. if (s.SRB_Status != SS_COMP)
  186488. return false;
  186489. rb->dataLength = rb->numFrames * 2352;
  186490. rb->dataStartOffset = 0;
  186491. return true;
  186492. }
  186493. };
  186494. class ControllerType2 : public CDController
  186495. {
  186496. public:
  186497. ControllerType2() {}
  186498. ~ControllerType2() {}
  186499. void shutDown()
  186500. {
  186501. if (initialised)
  186502. {
  186503. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  186504. SRB_ExecSCSICmd s;
  186505. prepare (s);
  186506. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  186507. s.SRB_BufLen = 0x0C;
  186508. s.SRB_BufPointer = bufPointer;
  186509. s.SRB_CDBLen = 6;
  186510. s.CDBByte[0] = 0x15;
  186511. s.CDBByte[4] = 0x0C;
  186512. perform (s);
  186513. }
  186514. }
  186515. bool init()
  186516. {
  186517. SRB_ExecSCSICmd s;
  186518. s.SRB_Status = SS_ERR;
  186519. if (deviceInfo->readType == READTYPE_READ10_2)
  186520. {
  186521. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  186522. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  186523. for (int i = 0; i < 2; ++i)
  186524. {
  186525. prepare (s);
  186526. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186527. s.SRB_BufLen = 0x14;
  186528. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  186529. s.SRB_CDBLen = 6;
  186530. s.CDBByte[0] = 0x15;
  186531. s.CDBByte[1] = 0x10;
  186532. s.CDBByte[4] = 0x14;
  186533. perform (s);
  186534. if (s.SRB_Status != SS_COMP)
  186535. return false;
  186536. }
  186537. }
  186538. else
  186539. {
  186540. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  186541. prepare (s);
  186542. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186543. s.SRB_BufLen = 0x0C;
  186544. s.SRB_BufPointer = bufPointer;
  186545. s.SRB_CDBLen = 6;
  186546. s.CDBByte[0] = 0x15;
  186547. s.CDBByte[4] = 0x0C;
  186548. perform (s);
  186549. }
  186550. return s.SRB_Status == SS_COMP;
  186551. }
  186552. bool read (CDReadBuffer* rb)
  186553. {
  186554. if (rb->numFrames * 2352 > rb->bufferSize)
  186555. return false;
  186556. if (!initialised)
  186557. {
  186558. initialised = init();
  186559. if (!initialised)
  186560. return false;
  186561. }
  186562. SRB_ExecSCSICmd s;
  186563. prepare (s);
  186564. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186565. s.SRB_BufLen = rb->bufferSize;
  186566. s.SRB_BufPointer = rb->buffer;
  186567. s.SRB_CDBLen = 10;
  186568. s.CDBByte[0] = 0x28;
  186569. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186570. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186571. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186572. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186573. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186574. perform (s);
  186575. if (s.SRB_Status != SS_COMP)
  186576. return false;
  186577. rb->dataLength = rb->numFrames * 2352;
  186578. rb->dataStartOffset = 0;
  186579. return true;
  186580. }
  186581. };
  186582. class ControllerType3 : public CDController
  186583. {
  186584. public:
  186585. ControllerType3() {}
  186586. ~ControllerType3() {}
  186587. bool read (CDReadBuffer* rb)
  186588. {
  186589. if (rb->numFrames * 2352 > rb->bufferSize)
  186590. return false;
  186591. if (!initialised)
  186592. {
  186593. setPaused (false);
  186594. initialised = true;
  186595. }
  186596. SRB_ExecSCSICmd s;
  186597. prepare (s);
  186598. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186599. s.SRB_BufLen = rb->numFrames * 2352;
  186600. s.SRB_BufPointer = rb->buffer;
  186601. s.SRB_CDBLen = 12;
  186602. s.CDBByte[0] = 0xD8;
  186603. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186604. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186605. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186606. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  186607. perform (s);
  186608. if (s.SRB_Status != SS_COMP)
  186609. return false;
  186610. rb->dataLength = rb->numFrames * 2352;
  186611. rb->dataStartOffset = 0;
  186612. return true;
  186613. }
  186614. };
  186615. class ControllerType4 : public CDController
  186616. {
  186617. public:
  186618. ControllerType4() {}
  186619. ~ControllerType4() {}
  186620. bool selectD4Mode()
  186621. {
  186622. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  186623. SRB_ExecSCSICmd s;
  186624. prepare (s);
  186625. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186626. s.SRB_CDBLen = 6;
  186627. s.SRB_BufLen = 12;
  186628. s.SRB_BufPointer = bufPointer;
  186629. s.CDBByte[0] = 0x15;
  186630. s.CDBByte[1] = 0x10;
  186631. s.CDBByte[4] = 0x08;
  186632. perform (s);
  186633. return s.SRB_Status == SS_COMP;
  186634. }
  186635. bool read (CDReadBuffer* rb)
  186636. {
  186637. if (rb->numFrames * 2352 > rb->bufferSize)
  186638. return false;
  186639. if (!initialised)
  186640. {
  186641. setPaused (true);
  186642. if (deviceInfo->readType == READTYPE_READ_D4_1)
  186643. selectD4Mode();
  186644. initialised = true;
  186645. }
  186646. SRB_ExecSCSICmd s;
  186647. prepare (s);
  186648. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186649. s.SRB_BufLen = rb->bufferSize;
  186650. s.SRB_BufPointer = rb->buffer;
  186651. s.SRB_CDBLen = 10;
  186652. s.CDBByte[0] = 0xD4;
  186653. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186654. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186655. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186656. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186657. perform (s);
  186658. if (s.SRB_Status != SS_COMP)
  186659. return false;
  186660. rb->dataLength = rb->numFrames * 2352;
  186661. rb->dataStartOffset = 0;
  186662. return true;
  186663. }
  186664. };
  186665. CDController::CDController() : initialised (false)
  186666. {
  186667. }
  186668. CDController::~CDController()
  186669. {
  186670. }
  186671. void CDController::prepare (SRB_ExecSCSICmd& s)
  186672. {
  186673. zerostruct (s);
  186674. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186675. s.SRB_HaID = deviceInfo->info.ha;
  186676. s.SRB_Target = deviceInfo->info.tgt;
  186677. s.SRB_Lun = deviceInfo->info.lun;
  186678. s.SRB_SenseLen = SENSE_LEN;
  186679. }
  186680. void CDController::perform (SRB_ExecSCSICmd& s)
  186681. {
  186682. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186683. s.SRB_PostProc = (void*)event;
  186684. ResetEvent (event);
  186685. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  186686. deviceInfo->info.scsiDriveLetter,
  186687. deviceInfo->scsiHandle)
  186688. : fSendASPI32Command ((LPSRB)&s);
  186689. if (status == SS_PENDING)
  186690. WaitForSingleObject (event, 4000);
  186691. CloseHandle (event);
  186692. }
  186693. void CDController::setPaused (bool paused)
  186694. {
  186695. SRB_ExecSCSICmd s;
  186696. prepare (s);
  186697. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186698. s.SRB_CDBLen = 10;
  186699. s.CDBByte[0] = 0x4B;
  186700. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  186701. perform (s);
  186702. }
  186703. void CDController::shutDown()
  186704. {
  186705. }
  186706. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  186707. {
  186708. if (overlapBuffer != 0)
  186709. {
  186710. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  186711. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  186712. if (doJitter
  186713. && overlapBuffer->startFrame > 0
  186714. && overlapBuffer->numFrames > 0
  186715. && overlapBuffer->dataLength > 0)
  186716. {
  186717. const int numFrames = rb->numFrames;
  186718. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  186719. {
  186720. rb->startFrame -= framesOverlap;
  186721. if (framesToCheck < framesOverlap
  186722. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  186723. rb->numFrames += framesOverlap;
  186724. }
  186725. else
  186726. {
  186727. overlapBuffer->dataLength = 0;
  186728. overlapBuffer->startFrame = 0;
  186729. overlapBuffer->numFrames = 0;
  186730. }
  186731. }
  186732. if (! read (rb))
  186733. return false;
  186734. if (doJitter)
  186735. {
  186736. const int checkLen = framesToCheck * 2352;
  186737. const int maxToCheck = rb->dataLength - checkLen;
  186738. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  186739. return true;
  186740. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  186741. bool found = false;
  186742. for (int i = 0; i < maxToCheck; ++i)
  186743. {
  186744. if (!memcmp (p, rb->buffer + i, checkLen))
  186745. {
  186746. i += checkLen;
  186747. rb->dataStartOffset = i;
  186748. rb->dataLength -= i;
  186749. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  186750. found = true;
  186751. break;
  186752. }
  186753. }
  186754. rb->numFrames = rb->dataLength / 2352;
  186755. rb->dataLength = 2352 * rb->numFrames;
  186756. if (!found)
  186757. return false;
  186758. }
  186759. if (canDoJitter)
  186760. {
  186761. memcpy (overlapBuffer->buffer,
  186762. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  186763. 2352 * framesToCheck);
  186764. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  186765. overlapBuffer->numFrames = framesToCheck;
  186766. overlapBuffer->dataLength = 2352 * framesToCheck;
  186767. overlapBuffer->dataStartOffset = 0;
  186768. }
  186769. else
  186770. {
  186771. overlapBuffer->startFrame = 0;
  186772. overlapBuffer->numFrames = 0;
  186773. overlapBuffer->dataLength = 0;
  186774. }
  186775. return true;
  186776. }
  186777. else
  186778. {
  186779. return read (rb);
  186780. }
  186781. }
  186782. int CDController::getLastIndex()
  186783. {
  186784. char qdata[100];
  186785. SRB_ExecSCSICmd s;
  186786. prepare (s);
  186787. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186788. s.SRB_BufLen = sizeof (qdata);
  186789. s.SRB_BufPointer = (BYTE*)qdata;
  186790. s.SRB_CDBLen = 12;
  186791. s.CDBByte[0] = 0x42;
  186792. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186793. s.CDBByte[2] = 64;
  186794. s.CDBByte[3] = 1; // get current position
  186795. s.CDBByte[7] = 0;
  186796. s.CDBByte[8] = (BYTE)sizeof (qdata);
  186797. perform (s);
  186798. if (s.SRB_Status == SS_COMP)
  186799. return qdata[7];
  186800. return 0;
  186801. }
  186802. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  186803. {
  186804. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186805. SRB_ExecSCSICmd s;
  186806. zerostruct (s);
  186807. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186808. s.SRB_HaID = info.ha;
  186809. s.SRB_Target = info.tgt;
  186810. s.SRB_Lun = info.lun;
  186811. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186812. s.SRB_BufLen = 0x324;
  186813. s.SRB_BufPointer = (BYTE*)lpToc;
  186814. s.SRB_SenseLen = 0x0E;
  186815. s.SRB_CDBLen = 0x0A;
  186816. s.SRB_PostProc = (void*)event;
  186817. s.CDBByte[0] = 0x43;
  186818. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  186819. s.CDBByte[7] = 0x03;
  186820. s.CDBByte[8] = 0x24;
  186821. ResetEvent (event);
  186822. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186823. : fSendASPI32Command ((LPSRB)&s);
  186824. if (status == SS_PENDING)
  186825. WaitForSingleObject (event, 4000);
  186826. CloseHandle (event);
  186827. return (s.SRB_Status == SS_COMP);
  186828. }
  186829. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  186830. CDReadBuffer* const overlapBuffer)
  186831. {
  186832. if (controller == 0)
  186833. {
  186834. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  186835. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  186836. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  186837. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  186838. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  186839. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  186840. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  186841. }
  186842. buffer->index = 0;
  186843. if ((controller != 0)
  186844. && controller->readAudio (buffer, overlapBuffer))
  186845. {
  186846. if (buffer->wantsIndex)
  186847. buffer->index = controller->getLastIndex();
  186848. return true;
  186849. }
  186850. return false;
  186851. }
  186852. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  186853. {
  186854. if (shouldBeOpen)
  186855. {
  186856. if (controller != 0)
  186857. {
  186858. controller->shutDown();
  186859. delete controller;
  186860. controller = 0;
  186861. }
  186862. if (scsiHandle != 0)
  186863. {
  186864. CloseHandle (scsiHandle);
  186865. scsiHandle = 0;
  186866. }
  186867. }
  186868. SRB_ExecSCSICmd s;
  186869. zerostruct (s);
  186870. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186871. s.SRB_HaID = info.ha;
  186872. s.SRB_Target = info.tgt;
  186873. s.SRB_Lun = info.lun;
  186874. s.SRB_SenseLen = SENSE_LEN;
  186875. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186876. s.SRB_BufLen = 0;
  186877. s.SRB_BufPointer = 0;
  186878. s.SRB_CDBLen = 12;
  186879. s.CDBByte[0] = 0x1b;
  186880. s.CDBByte[1] = (BYTE)(info.lun << 5);
  186881. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  186882. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186883. s.SRB_PostProc = (void*)event;
  186884. ResetEvent (event);
  186885. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186886. : fSendASPI32Command ((LPSRB)&s);
  186887. if (status == SS_PENDING)
  186888. WaitForSingleObject (event, 4000);
  186889. CloseHandle (event);
  186890. }
  186891. bool CDDeviceHandle::testController (const int type,
  186892. CDController* const newController,
  186893. CDReadBuffer* const rb)
  186894. {
  186895. controller = newController;
  186896. readType = (BYTE)type;
  186897. controller->deviceInfo = this;
  186898. controller->framesToCheck = 1;
  186899. controller->framesOverlap = 3;
  186900. bool passed = false;
  186901. memset (rb->buffer, 0xcd, rb->bufferSize);
  186902. if (controller->read (rb))
  186903. {
  186904. passed = true;
  186905. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  186906. int wrong = 0;
  186907. for (int i = rb->dataLength / 4; --i >= 0;)
  186908. {
  186909. if (*p++ == (int) 0xcdcdcdcd)
  186910. {
  186911. if (++wrong == 4)
  186912. {
  186913. passed = false;
  186914. break;
  186915. }
  186916. }
  186917. else
  186918. {
  186919. wrong = 0;
  186920. }
  186921. }
  186922. }
  186923. if (! passed)
  186924. {
  186925. controller->shutDown();
  186926. delete controller;
  186927. controller = 0;
  186928. }
  186929. return passed;
  186930. }
  186931. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  186932. {
  186933. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186934. const int bufSize = 128;
  186935. BYTE buffer[bufSize];
  186936. zeromem (buffer, bufSize);
  186937. SRB_ExecSCSICmd s;
  186938. zerostruct (s);
  186939. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186940. s.SRB_HaID = ha;
  186941. s.SRB_Target = tgt;
  186942. s.SRB_Lun = lun;
  186943. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186944. s.SRB_BufLen = bufSize;
  186945. s.SRB_BufPointer = buffer;
  186946. s.SRB_SenseLen = SENSE_LEN;
  186947. s.SRB_CDBLen = 6;
  186948. s.SRB_PostProc = (void*)event;
  186949. s.CDBByte[0] = SCSI_INQUIRY;
  186950. s.CDBByte[4] = 100;
  186951. ResetEvent (event);
  186952. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  186953. WaitForSingleObject (event, 4000);
  186954. CloseHandle (event);
  186955. if (s.SRB_Status == SS_COMP)
  186956. {
  186957. memcpy (dev->vendor, &buffer[8], 8);
  186958. memcpy (dev->productId, &buffer[16], 16);
  186959. memcpy (dev->rev, &buffer[32], 4);
  186960. memcpy (dev->vendorSpec, &buffer[36], 20);
  186961. }
  186962. }
  186963. static int FindCDDevices (CDDeviceInfo* const list,
  186964. int maxItems)
  186965. {
  186966. int count = 0;
  186967. if (usingScsi)
  186968. {
  186969. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  186970. {
  186971. TCHAR drivePath[8];
  186972. drivePath[0] = driveLetter;
  186973. drivePath[1] = ':';
  186974. drivePath[2] = '\\';
  186975. drivePath[3] = 0;
  186976. if (GetDriveType (drivePath) == DRIVE_CDROM)
  186977. {
  186978. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  186979. if (h != INVALID_HANDLE_VALUE)
  186980. {
  186981. BYTE buffer[100], passThroughStruct[1024];
  186982. zeromem (buffer, sizeof (buffer));
  186983. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186984. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  186985. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  186986. p->spt.CdbLength = 6;
  186987. p->spt.SenseInfoLength = 24;
  186988. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  186989. p->spt.DataTransferLength = 100;
  186990. p->spt.TimeOutValue = 2;
  186991. p->spt.DataBuffer = buffer;
  186992. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186993. p->spt.Cdb[0] = 0x12;
  186994. p->spt.Cdb[4] = 100;
  186995. DWORD bytesReturned = 0;
  186996. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186997. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186998. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186999. &bytesReturned, 0) != 0)
  187000. {
  187001. zeromem (&list[count], sizeof (CDDeviceInfo));
  187002. list[count].scsiDriveLetter = driveLetter;
  187003. memcpy (list[count].vendor, &buffer[8], 8);
  187004. memcpy (list[count].productId, &buffer[16], 16);
  187005. memcpy (list[count].rev, &buffer[32], 4);
  187006. memcpy (list[count].vendorSpec, &buffer[36], 20);
  187007. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187008. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  187009. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  187010. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  187011. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  187012. &bytesReturned, 0) != 0)
  187013. {
  187014. list[count].ha = scsiAddr->PortNumber;
  187015. list[count].tgt = scsiAddr->TargetId;
  187016. list[count].lun = scsiAddr->Lun;
  187017. ++count;
  187018. }
  187019. }
  187020. CloseHandle (h);
  187021. }
  187022. }
  187023. }
  187024. }
  187025. else
  187026. {
  187027. const DWORD d = fGetASPI32SupportInfo();
  187028. BYTE status = HIBYTE (LOWORD (d));
  187029. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  187030. return 0;
  187031. const int numAdapters = LOBYTE (LOWORD (d));
  187032. for (BYTE ha = 0; ha < numAdapters; ++ha)
  187033. {
  187034. SRB_HAInquiry s;
  187035. zerostruct (s);
  187036. s.SRB_Cmd = SC_HA_INQUIRY;
  187037. s.SRB_HaID = ha;
  187038. fSendASPI32Command ((LPSRB)&s);
  187039. if (s.SRB_Status == SS_COMP)
  187040. {
  187041. maxItems = (int)s.HA_Unique[3];
  187042. if (maxItems == 0)
  187043. maxItems = 8;
  187044. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  187045. {
  187046. for (BYTE lun = 0; lun < 8; ++lun)
  187047. {
  187048. SRB_GDEVBlock sb;
  187049. zerostruct (sb);
  187050. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  187051. sb.SRB_HaID = ha;
  187052. sb.SRB_Target = tgt;
  187053. sb.SRB_Lun = lun;
  187054. fSendASPI32Command ((LPSRB) &sb);
  187055. if (sb.SRB_Status == SS_COMP
  187056. && sb.SRB_DeviceType == DTYPE_CROM)
  187057. {
  187058. zeromem (&list[count], sizeof (CDDeviceInfo));
  187059. list[count].ha = ha;
  187060. list[count].tgt = tgt;
  187061. list[count].lun = lun;
  187062. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  187063. ++count;
  187064. }
  187065. }
  187066. }
  187067. }
  187068. }
  187069. }
  187070. return count;
  187071. }
  187072. static int ripperUsers = 0;
  187073. static bool initialisedOk = false;
  187074. class DeinitialiseTimer : private Timer,
  187075. private DeletedAtShutdown
  187076. {
  187077. DeinitialiseTimer (const DeinitialiseTimer&);
  187078. DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  187079. public:
  187080. DeinitialiseTimer()
  187081. {
  187082. startTimer (4000);
  187083. }
  187084. ~DeinitialiseTimer()
  187085. {
  187086. if (--ripperUsers == 0)
  187087. DeinitialiseCDRipper();
  187088. }
  187089. void timerCallback()
  187090. {
  187091. delete this;
  187092. }
  187093. juce_UseDebuggingNewOperator
  187094. };
  187095. static void incUserCount()
  187096. {
  187097. if (ripperUsers++ == 0)
  187098. initialisedOk = InitialiseCDRipper();
  187099. }
  187100. static void decUserCount()
  187101. {
  187102. new DeinitialiseTimer();
  187103. }
  187104. struct CDDeviceWrapper
  187105. {
  187106. CDDeviceHandle* cdH;
  187107. CDReadBuffer* overlapBuffer;
  187108. bool jitter;
  187109. };
  187110. static int getAddressOf (const TOCTRACK* const t)
  187111. {
  187112. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  187113. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  187114. }
  187115. static int getMSFAddressOf (const TOCTRACK* const t)
  187116. {
  187117. return 60 * t->addr[1] + t->addr[2];
  187118. }
  187119. static const int samplesPerFrame = 44100 / 75;
  187120. static const int bytesPerFrame = samplesPerFrame * 4;
  187121. const StringArray AudioCDReader::getAvailableCDNames()
  187122. {
  187123. StringArray results;
  187124. incUserCount();
  187125. if (initialisedOk)
  187126. {
  187127. CDDeviceInfo list[8];
  187128. const int num = FindCDDevices (list, 8);
  187129. decUserCount();
  187130. for (int i = 0; i < num; ++i)
  187131. {
  187132. String s;
  187133. if (list[i].scsiDriveLetter > 0)
  187134. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << T(": ");
  187135. s << String (list[i].vendor).trim()
  187136. << T(" ") << String (list[i].productId).trim()
  187137. << T(" ") << String (list[i].rev).trim();
  187138. results.add (s);
  187139. }
  187140. }
  187141. return results;
  187142. }
  187143. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  187144. {
  187145. SRB_GDEVBlock s;
  187146. zerostruct (s);
  187147. s.SRB_Cmd = SC_GET_DEV_TYPE;
  187148. s.SRB_HaID = device->ha;
  187149. s.SRB_Target = device->tgt;
  187150. s.SRB_Lun = device->lun;
  187151. if (usingScsi)
  187152. {
  187153. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  187154. if (h != INVALID_HANDLE_VALUE)
  187155. {
  187156. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  187157. cdh->scsiHandle = h;
  187158. return cdh;
  187159. }
  187160. }
  187161. else
  187162. {
  187163. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  187164. && s.SRB_DeviceType == DTYPE_CROM)
  187165. {
  187166. return new CDDeviceHandle (device);
  187167. }
  187168. }
  187169. return 0;
  187170. }
  187171. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  187172. {
  187173. incUserCount();
  187174. if (initialisedOk)
  187175. {
  187176. CDDeviceInfo list[8];
  187177. const int num = FindCDDevices (list, 8);
  187178. if (((unsigned int) deviceIndex) < (unsigned int) num)
  187179. {
  187180. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  187181. if (handle != 0)
  187182. {
  187183. CDDeviceWrapper* const d = new CDDeviceWrapper();
  187184. d->cdH = handle;
  187185. d->overlapBuffer = new CDReadBuffer(3);
  187186. return new AudioCDReader (d);
  187187. }
  187188. }
  187189. }
  187190. decUserCount();
  187191. return 0;
  187192. }
  187193. AudioCDReader::AudioCDReader (void* handle_)
  187194. : AudioFormatReader (0, T("CD Audio")),
  187195. handle (handle_),
  187196. indexingEnabled (false),
  187197. lastIndex (0),
  187198. firstFrameInBuffer (0),
  187199. samplesInBuffer (0)
  187200. {
  187201. jassert (handle_ != 0);
  187202. refreshTrackLengths();
  187203. sampleRate = 44100.0;
  187204. bitsPerSample = 16;
  187205. lengthInSamples = getPositionOfTrackStart (numTracks);
  187206. numChannels = 2;
  187207. usesFloatingPointData = false;
  187208. buffer.setSize (4 * bytesPerFrame, true);
  187209. }
  187210. AudioCDReader::~AudioCDReader()
  187211. {
  187212. CDDeviceWrapper* const device = (CDDeviceWrapper*)handle;
  187213. delete device->cdH;
  187214. delete device->overlapBuffer;
  187215. delete device;
  187216. decUserCount();
  187217. }
  187218. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  187219. int64 startSampleInFile, int numSamples)
  187220. {
  187221. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187222. bool ok = true;
  187223. while (numSamples > 0)
  187224. {
  187225. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  187226. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  187227. if (startSampleInFile >= bufferStartSample
  187228. && startSampleInFile < bufferEndSample)
  187229. {
  187230. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  187231. int* const l = destSamples[0] + startOffsetInDestBuffer;
  187232. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187233. const short* src = (const short*) buffer.getData();
  187234. src += 2 * (startSampleInFile - bufferStartSample);
  187235. for (int i = 0; i < toDo; ++i)
  187236. {
  187237. l[i] = src [i << 1] << 16;
  187238. if (r != 0)
  187239. r[i] = src [(i << 1) + 1] << 16;
  187240. }
  187241. startOffsetInDestBuffer += toDo;
  187242. startSampleInFile += toDo;
  187243. numSamples -= toDo;
  187244. }
  187245. else
  187246. {
  187247. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  187248. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  187249. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  187250. {
  187251. device->overlapBuffer->dataLength = 0;
  187252. device->overlapBuffer->startFrame = 0;
  187253. device->overlapBuffer->numFrames = 0;
  187254. device->jitter = false;
  187255. }
  187256. firstFrameInBuffer = frameNeeded;
  187257. lastIndex = 0;
  187258. CDReadBuffer readBuffer (framesInBuffer + 4);
  187259. readBuffer.wantsIndex = indexingEnabled;
  187260. int i;
  187261. for (i = 5; --i >= 0;)
  187262. {
  187263. readBuffer.startFrame = frameNeeded;
  187264. readBuffer.numFrames = framesInBuffer;
  187265. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  187266. break;
  187267. else
  187268. device->overlapBuffer->dataLength = 0;
  187269. }
  187270. if (i >= 0)
  187271. {
  187272. memcpy ((char*) buffer.getData(),
  187273. readBuffer.buffer + readBuffer.dataStartOffset,
  187274. readBuffer.dataLength);
  187275. samplesInBuffer = readBuffer.dataLength >> 2;
  187276. lastIndex = readBuffer.index;
  187277. }
  187278. else
  187279. {
  187280. int* l = destSamples[0] + startOffsetInDestBuffer;
  187281. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187282. while (--numSamples >= 0)
  187283. {
  187284. *l++ = 0;
  187285. if (r != 0)
  187286. *r++ = 0;
  187287. }
  187288. // sometimes the read fails for just the very last couple of blocks, so
  187289. // we'll ignore and errors in the last half-second of the disk..
  187290. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  187291. break;
  187292. }
  187293. }
  187294. }
  187295. return ok;
  187296. }
  187297. bool AudioCDReader::isCDStillPresent() const
  187298. {
  187299. TOC toc;
  187300. zerostruct (toc);
  187301. return ((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false);
  187302. }
  187303. int AudioCDReader::getNumTracks() const
  187304. {
  187305. return numTracks;
  187306. }
  187307. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  187308. {
  187309. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  187310. : 0;
  187311. }
  187312. void AudioCDReader::refreshTrackLengths()
  187313. {
  187314. zeromem (trackStarts, sizeof (trackStarts));
  187315. zeromem (audioTracks, sizeof (audioTracks));
  187316. TOC toc;
  187317. zerostruct (toc);
  187318. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  187319. {
  187320. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  187321. for (int i = 0; i <= numTracks; ++i)
  187322. {
  187323. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  187324. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  187325. }
  187326. }
  187327. else
  187328. {
  187329. numTracks = 0;
  187330. }
  187331. }
  187332. bool AudioCDReader::isTrackAudio (int trackNum) const
  187333. {
  187334. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  187335. : false;
  187336. }
  187337. void AudioCDReader::enableIndexScanning (bool b)
  187338. {
  187339. indexingEnabled = b;
  187340. }
  187341. int AudioCDReader::getLastIndex() const
  187342. {
  187343. return lastIndex;
  187344. }
  187345. const int framesPerIndexRead = 4;
  187346. int AudioCDReader::getIndexAt (int samplePos)
  187347. {
  187348. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187349. const int frameNeeded = samplePos / samplesPerFrame;
  187350. device->overlapBuffer->dataLength = 0;
  187351. device->overlapBuffer->startFrame = 0;
  187352. device->overlapBuffer->numFrames = 0;
  187353. device->jitter = false;
  187354. firstFrameInBuffer = 0;
  187355. lastIndex = 0;
  187356. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  187357. readBuffer.wantsIndex = true;
  187358. int i;
  187359. for (i = 5; --i >= 0;)
  187360. {
  187361. readBuffer.startFrame = frameNeeded;
  187362. readBuffer.numFrames = framesPerIndexRead;
  187363. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187364. break;
  187365. }
  187366. if (i >= 0)
  187367. return readBuffer.index;
  187368. return -1;
  187369. }
  187370. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187371. {
  187372. Array <int> indexes;
  187373. const int trackStart = getPositionOfTrackStart (trackNumber);
  187374. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187375. bool needToScan = true;
  187376. if (trackEnd - trackStart > 20 * 44100)
  187377. {
  187378. // check the end of the track for indexes before scanning the whole thing
  187379. needToScan = false;
  187380. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187381. bool seenAnIndex = false;
  187382. while (pos <= trackEnd - samplesPerFrame)
  187383. {
  187384. const int index = getIndexAt (pos);
  187385. if (index == 0)
  187386. {
  187387. // lead-out, so skip back a bit if we've not found any indexes yet..
  187388. if (seenAnIndex)
  187389. break;
  187390. pos -= 44100 * 5;
  187391. if (pos < trackStart)
  187392. break;
  187393. }
  187394. else
  187395. {
  187396. if (index > 0)
  187397. seenAnIndex = true;
  187398. if (index > 1)
  187399. {
  187400. needToScan = true;
  187401. break;
  187402. }
  187403. pos += samplesPerFrame * framesPerIndexRead;
  187404. }
  187405. }
  187406. }
  187407. if (needToScan)
  187408. {
  187409. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187410. int pos = trackStart;
  187411. int last = -1;
  187412. while (pos < trackEnd - samplesPerFrame * 10)
  187413. {
  187414. const int frameNeeded = pos / samplesPerFrame;
  187415. device->overlapBuffer->dataLength = 0;
  187416. device->overlapBuffer->startFrame = 0;
  187417. device->overlapBuffer->numFrames = 0;
  187418. device->jitter = false;
  187419. firstFrameInBuffer = 0;
  187420. CDReadBuffer readBuffer (4);
  187421. readBuffer.wantsIndex = true;
  187422. int i;
  187423. for (i = 5; --i >= 0;)
  187424. {
  187425. readBuffer.startFrame = frameNeeded;
  187426. readBuffer.numFrames = framesPerIndexRead;
  187427. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187428. break;
  187429. }
  187430. if (i < 0)
  187431. break;
  187432. if (readBuffer.index > last && readBuffer.index > 1)
  187433. {
  187434. last = readBuffer.index;
  187435. indexes.add (pos);
  187436. }
  187437. pos += samplesPerFrame * framesPerIndexRead;
  187438. }
  187439. indexes.removeValue (trackStart);
  187440. }
  187441. return indexes;
  187442. }
  187443. int AudioCDReader::getCDDBId()
  187444. {
  187445. refreshTrackLengths();
  187446. if (numTracks > 0)
  187447. {
  187448. TOC toc;
  187449. zerostruct (toc);
  187450. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  187451. {
  187452. int n = 0;
  187453. for (int i = numTracks; --i >= 0;)
  187454. {
  187455. int j = getMSFAddressOf (&toc.tracks[i]);
  187456. while (j > 0)
  187457. {
  187458. n += (j % 10);
  187459. j /= 10;
  187460. }
  187461. }
  187462. if (n != 0)
  187463. {
  187464. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  187465. - getMSFAddressOf (&toc.tracks[0]);
  187466. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  187467. }
  187468. }
  187469. }
  187470. return 0;
  187471. }
  187472. void AudioCDReader::ejectDisk()
  187473. {
  187474. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  187475. }
  187476. #endif
  187477. #if JUCE_USE_CDBURNER
  187478. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  187479. {
  187480. CoInitialize (0);
  187481. IDiscMaster* dm;
  187482. IDiscRecorder* result = 0;
  187483. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  187484. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  187485. IID_IDiscMaster,
  187486. (void**) &dm)))
  187487. {
  187488. if (SUCCEEDED (dm->Open()))
  187489. {
  187490. IEnumDiscRecorders* drEnum = 0;
  187491. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  187492. {
  187493. IDiscRecorder* dr = 0;
  187494. DWORD dummy;
  187495. int index = 0;
  187496. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  187497. {
  187498. if (indexToOpen == index)
  187499. {
  187500. result = dr;
  187501. break;
  187502. }
  187503. else if (list != 0)
  187504. {
  187505. BSTR path;
  187506. if (SUCCEEDED (dr->GetPath (&path)))
  187507. list->add ((const WCHAR*) path);
  187508. }
  187509. ++index;
  187510. dr->Release();
  187511. }
  187512. drEnum->Release();
  187513. }
  187514. if (master == 0)
  187515. dm->Close();
  187516. }
  187517. if (master != 0)
  187518. *master = dm;
  187519. else
  187520. dm->Release();
  187521. }
  187522. return result;
  187523. }
  187524. class AudioCDBurner::Pimpl : public IDiscMasterProgressEvents,
  187525. public Timer
  187526. {
  187527. public:
  187528. Pimpl (AudioCDBurner& owner_, IDiscMaster* discMaster_, IDiscRecorder* discRecorder_)
  187529. : owner (owner_), discMaster (discMaster_), discRecorder (discRecorder_), redbook (0),
  187530. listener (0), progress (0), shouldCancel (false), refCount (1)
  187531. {
  187532. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  187533. jassert (SUCCEEDED (hr));
  187534. hr = discMaster->SetActiveDiscRecorder (discRecorder);
  187535. //jassert (SUCCEEDED (hr));
  187536. lastState = getDiskState();
  187537. startTimer (2000);
  187538. }
  187539. ~Pimpl() {}
  187540. void releaseObjects()
  187541. {
  187542. discRecorder->Close();
  187543. if (redbook != 0)
  187544. redbook->Release();
  187545. discRecorder->Release();
  187546. discMaster->Release();
  187547. Release();
  187548. }
  187549. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  187550. {
  187551. if (result == 0)
  187552. return E_POINTER;
  187553. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  187554. {
  187555. AddRef();
  187556. *result = this;
  187557. return S_OK;
  187558. }
  187559. *result = 0;
  187560. return E_NOINTERFACE;
  187561. }
  187562. ULONG __stdcall AddRef() { return ++refCount; }
  187563. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  187564. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  187565. {
  187566. if (listener != 0 && ! shouldCancel)
  187567. shouldCancel = listener->audioCDBurnProgress (progress);
  187568. *pbCancel = shouldCancel;
  187569. return S_OK;
  187570. }
  187571. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  187572. {
  187573. progress = nCompleted / (float) nTotal;
  187574. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  187575. return E_NOTIMPL;
  187576. }
  187577. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  187578. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  187579. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  187580. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187581. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187582. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187583. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187584. class ScopedDiscOpener
  187585. {
  187586. public:
  187587. ScopedDiscOpener (Pimpl& p) : pimpl (p) { pimpl.discRecorder->OpenExclusive(); }
  187588. ~ScopedDiscOpener() { pimpl.discRecorder->Close(); }
  187589. private:
  187590. Pimpl& pimpl;
  187591. ScopedDiscOpener (const ScopedDiscOpener&);
  187592. ScopedDiscOpener& operator= (const ScopedDiscOpener&);
  187593. };
  187594. DiskState getDiskState()
  187595. {
  187596. const ScopedDiscOpener opener (*this);
  187597. long type, flags;
  187598. HRESULT hr = discRecorder->QueryMediaType (&type, &flags);
  187599. if (FAILED (hr))
  187600. return unknown;
  187601. if (type != 0 && (flags & MEDIA_WRITABLE) != 0)
  187602. return writableDiskPresent;
  187603. if (type == 0)
  187604. return noDisc;
  187605. else
  187606. return readOnlyDiskPresent;
  187607. }
  187608. int getIntProperty (const LPOLESTR name, const int defaultReturn) const
  187609. {
  187610. ComSmartPtr<IPropertyStorage> prop;
  187611. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187612. return defaultReturn;
  187613. PROPSPEC iPropSpec;
  187614. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187615. iPropSpec.lpwstr = name;
  187616. PROPVARIANT iPropVariant;
  187617. return FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant))
  187618. ? defaultReturn : (int) iPropVariant.lVal;
  187619. }
  187620. bool setIntProperty (const LPOLESTR name, const int value) const
  187621. {
  187622. ComSmartPtr<IPropertyStorage> prop;
  187623. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187624. return false;
  187625. PROPSPEC iPropSpec;
  187626. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187627. iPropSpec.lpwstr = name;
  187628. PROPVARIANT iPropVariant;
  187629. if (FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant)))
  187630. return false;
  187631. iPropVariant.lVal = (long) value;
  187632. return SUCCEEDED (prop->WriteMultiple (1, &iPropSpec, &iPropVariant, iPropVariant.vt))
  187633. && SUCCEEDED (discRecorder->SetRecorderProperties (prop));
  187634. }
  187635. void timerCallback()
  187636. {
  187637. const DiskState state = getDiskState();
  187638. if (state != lastState)
  187639. {
  187640. lastState = state;
  187641. owner.sendChangeMessage (&owner);
  187642. }
  187643. }
  187644. AudioCDBurner& owner;
  187645. DiskState lastState;
  187646. IDiscMaster* discMaster;
  187647. IDiscRecorder* discRecorder;
  187648. IRedbookDiscMaster* redbook;
  187649. AudioCDBurner::BurnProgressListener* listener;
  187650. float progress;
  187651. bool shouldCancel;
  187652. private:
  187653. int refCount;
  187654. };
  187655. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  187656. {
  187657. IDiscMaster* discMaster = 0;
  187658. IDiscRecorder* discRecorder = enumCDBurners (0, deviceIndex, &discMaster);
  187659. if (discRecorder != 0)
  187660. pimpl = new Pimpl (*this, discMaster, discRecorder);
  187661. }
  187662. AudioCDBurner::~AudioCDBurner()
  187663. {
  187664. if (pimpl != 0)
  187665. pimpl.release()->releaseObjects();
  187666. }
  187667. const StringArray AudioCDBurner::findAvailableDevices()
  187668. {
  187669. StringArray devs;
  187670. enumCDBurners (&devs, -1, 0);
  187671. return devs;
  187672. }
  187673. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187674. {
  187675. ScopedPointer<AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  187676. if (b->pimpl == 0)
  187677. b = 0;
  187678. return b.release();
  187679. }
  187680. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  187681. {
  187682. return pimpl->getDiskState();
  187683. }
  187684. bool AudioCDBurner::isDiskPresent() const
  187685. {
  187686. return getDiskState() == writableDiskPresent;
  187687. }
  187688. bool AudioCDBurner::openTray()
  187689. {
  187690. const Pimpl::ScopedDiscOpener opener (*pimpl);
  187691. return SUCCEEDED (pimpl->discRecorder->Eject());
  187692. }
  187693. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  187694. {
  187695. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  187696. DiskState oldState = getDiskState();
  187697. DiskState newState = oldState;
  187698. while (newState == oldState && Time::currentTimeMillis() < timeout)
  187699. {
  187700. newState = getDiskState();
  187701. Thread::sleep (jmin (250, (int) (timeout - Time::currentTimeMillis())));
  187702. }
  187703. return newState;
  187704. }
  187705. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  187706. {
  187707. Array<int> results;
  187708. const int maxSpeed = pimpl->getIntProperty (L"MaxWriteSpeed", 1);
  187709. const int speeds[] = { 1, 2, 4, 8, 12, 16, 20, 24, 32, 40, 64, 80 };
  187710. for (int i = 0; i < numElementsInArray (speeds); ++i)
  187711. if (speeds[i] <= maxSpeed)
  187712. results.add (speeds[i]);
  187713. results.addIfNotAlreadyThere (maxSpeed);
  187714. return results;
  187715. }
  187716. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  187717. {
  187718. if (pimpl->getIntProperty (L"BufferUnderrunFreeCapable", 0) == 0)
  187719. return false;
  187720. pimpl->setIntProperty (L"EnableBufferUnderrunFree", shouldBeEnabled ? -1 : 0);
  187721. return pimpl->getIntProperty (L"EnableBufferUnderrunFree", 0) != 0;
  187722. }
  187723. int AudioCDBurner::getNumAvailableAudioBlocks() const
  187724. {
  187725. long blocksFree = 0;
  187726. pimpl->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  187727. return blocksFree;
  187728. }
  187729. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener, bool ejectDiscAfterwards,
  187730. bool performFakeBurnForTesting, int writeSpeed)
  187731. {
  187732. pimpl->setIntProperty (L"WriteSpeed", writeSpeed > 0 ? writeSpeed : -1);
  187733. pimpl->listener = listener;
  187734. pimpl->progress = 0;
  187735. pimpl->shouldCancel = false;
  187736. UINT_PTR cookie;
  187737. HRESULT hr = pimpl->discMaster->ProgressAdvise ((AudioCDBurner::Pimpl*) pimpl, &cookie);
  187738. hr = pimpl->discMaster->RecordDisc (performFakeBurnForTesting,
  187739. ejectDiscAfterwards);
  187740. String error;
  187741. if (hr != S_OK)
  187742. {
  187743. const char* e = "Couldn't open or write to the CD device";
  187744. if (hr == IMAPI_E_USERABORT)
  187745. e = "User cancelled the write operation";
  187746. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  187747. e = "No Disk present";
  187748. error = e;
  187749. }
  187750. pimpl->discMaster->ProgressUnadvise (cookie);
  187751. pimpl->listener = 0;
  187752. return error;
  187753. }
  187754. bool AudioCDBurner::addAudioTrack (AudioSource* audioSource, int numSamples)
  187755. {
  187756. if (audioSource == 0)
  187757. return false;
  187758. ScopedPointer<AudioSource> source (audioSource);
  187759. long bytesPerBlock;
  187760. HRESULT hr = pimpl->redbook->GetAudioBlockSize (&bytesPerBlock);
  187761. const int samplesPerBlock = bytesPerBlock / 4;
  187762. bool ok = true;
  187763. hr = pimpl->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  187764. HeapBlock <byte> buffer (bytesPerBlock);
  187765. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  187766. int samplesDone = 0;
  187767. source->prepareToPlay (samplesPerBlock, 44100.0);
  187768. while (ok)
  187769. {
  187770. {
  187771. AudioSourceChannelInfo info;
  187772. info.buffer = &sourceBuffer;
  187773. info.numSamples = samplesPerBlock;
  187774. info.startSample = 0;
  187775. sourceBuffer.clear();
  187776. source->getNextAudioBlock (info);
  187777. }
  187778. zeromem (buffer, bytesPerBlock);
  187779. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  187780. buffer, samplesPerBlock, 4);
  187781. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  187782. buffer + 2, samplesPerBlock, 4);
  187783. hr = pimpl->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  187784. if (FAILED (hr))
  187785. ok = false;
  187786. samplesDone += samplesPerBlock;
  187787. if (samplesDone >= numSamples)
  187788. break;
  187789. }
  187790. hr = pimpl->redbook->CloseAudioTrack();
  187791. return ok && hr == S_OK;
  187792. }
  187793. #endif
  187794. #endif
  187795. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  187796. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  187797. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  187798. // compiled on its own).
  187799. #if JUCE_INCLUDED_FILE
  187800. static const int midiBufferSize = 1024 * 10;
  187801. static const int numInHeaders = 32;
  187802. static const int inBufferSize = 256;
  187803. static Array <void*, CriticalSection> activeMidiThreads;
  187804. using ::free;
  187805. class MidiInThread : public Thread
  187806. {
  187807. public:
  187808. MidiInThread (MidiInput* const input_,
  187809. MidiInputCallback* const callback_)
  187810. : Thread ("Juce Midi"),
  187811. hIn (0),
  187812. input (input_),
  187813. callback (callback_),
  187814. isStarted (false),
  187815. startTime (0),
  187816. pendingLength(0)
  187817. {
  187818. for (int i = numInHeaders; --i >= 0;)
  187819. {
  187820. zeromem (&hdr[i], sizeof (MIDIHDR));
  187821. hdr[i].lpData = inData[i];
  187822. hdr[i].dwBufferLength = inBufferSize;
  187823. }
  187824. };
  187825. ~MidiInThread()
  187826. {
  187827. stop();
  187828. if (hIn != 0)
  187829. {
  187830. int count = 5;
  187831. while (--count >= 0)
  187832. {
  187833. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  187834. break;
  187835. Sleep (20);
  187836. }
  187837. }
  187838. }
  187839. void handle (const uint32 message, const uint32 timeStamp) throw()
  187840. {
  187841. const int byte = message & 0xff;
  187842. if (byte < 0x80)
  187843. return;
  187844. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  187845. const double time = timeStampToTime (timeStamp);
  187846. {
  187847. const ScopedLock sl (lock);
  187848. if (pendingLength < midiBufferSize - 12)
  187849. {
  187850. char* const p = pending + pendingLength;
  187851. *(double*) p = time;
  187852. *(uint32*) (p + 8) = numBytes;
  187853. *(uint32*) (p + 12) = message;
  187854. pendingLength += 12 + numBytes;
  187855. }
  187856. else
  187857. {
  187858. jassertfalse // midi buffer overflow! You might need to increase the size..
  187859. }
  187860. }
  187861. notify();
  187862. }
  187863. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  187864. {
  187865. const int num = hdr->dwBytesRecorded;
  187866. if (num > 0)
  187867. {
  187868. const double time = timeStampToTime (timeStamp);
  187869. {
  187870. const ScopedLock sl (lock);
  187871. if (pendingLength < midiBufferSize - (8 + num))
  187872. {
  187873. char* const p = pending + pendingLength;
  187874. *(double*) p = time;
  187875. *(uint32*) (p + 8) = num;
  187876. memcpy (p + 12, hdr->lpData, num);
  187877. pendingLength += 12 + num;
  187878. }
  187879. else
  187880. {
  187881. jassertfalse // midi buffer overflow! You might need to increase the size..
  187882. }
  187883. }
  187884. notify();
  187885. }
  187886. }
  187887. void writeBlock (const int i) throw()
  187888. {
  187889. hdr[i].dwBytesRecorded = 0;
  187890. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187891. jassert (res == MMSYSERR_NOERROR);
  187892. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  187893. jassert (res == MMSYSERR_NOERROR);
  187894. }
  187895. void run()
  187896. {
  187897. MemoryBlock pendingCopy (64);
  187898. while (! threadShouldExit())
  187899. {
  187900. for (int i = 0; i < numInHeaders; ++i)
  187901. {
  187902. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187903. {
  187904. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187905. (void) res;
  187906. jassert (res == MMSYSERR_NOERROR);
  187907. writeBlock (i);
  187908. }
  187909. }
  187910. int len;
  187911. {
  187912. const ScopedLock sl (lock);
  187913. len = pendingLength;
  187914. if (len > 0)
  187915. {
  187916. pendingCopy.ensureSize (len);
  187917. pendingCopy.copyFrom (pending, 0, len);
  187918. pendingLength = 0;
  187919. }
  187920. }
  187921. //xxx needs to figure out if blocks are broken up or not
  187922. if (len == 0)
  187923. {
  187924. wait (500);
  187925. }
  187926. else
  187927. {
  187928. const char* p = (const char*) pendingCopy.getData();
  187929. while (len > 0)
  187930. {
  187931. const double time = *(const double*) p;
  187932. const int messageLen = *(const int*) (p + 8);
  187933. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  187934. callback->handleIncomingMidiMessage (input, message);
  187935. p += 12 + messageLen;
  187936. len -= 12 + messageLen;
  187937. }
  187938. }
  187939. }
  187940. }
  187941. void start() throw()
  187942. {
  187943. jassert (hIn != 0);
  187944. if (hIn != 0 && ! isStarted)
  187945. {
  187946. stop();
  187947. activeMidiThreads.addIfNotAlreadyThere (this);
  187948. int i;
  187949. for (i = 0; i < numInHeaders; ++i)
  187950. writeBlock (i);
  187951. startTime = Time::getMillisecondCounter();
  187952. MMRESULT res = midiInStart (hIn);
  187953. jassert (res == MMSYSERR_NOERROR);
  187954. if (res == MMSYSERR_NOERROR)
  187955. {
  187956. isStarted = true;
  187957. pendingLength = 0;
  187958. startThread (6);
  187959. }
  187960. }
  187961. }
  187962. void stop() throw()
  187963. {
  187964. if (isStarted)
  187965. {
  187966. stopThread (5000);
  187967. midiInReset (hIn);
  187968. midiInStop (hIn);
  187969. activeMidiThreads.removeValue (this);
  187970. { const ScopedLock sl (lock); }
  187971. for (int i = numInHeaders; --i >= 0;)
  187972. {
  187973. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187974. {
  187975. int c = 10;
  187976. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  187977. Sleep (20);
  187978. jassert (c >= 0);
  187979. }
  187980. }
  187981. isStarted = false;
  187982. pendingLength = 0;
  187983. }
  187984. }
  187985. juce_UseDebuggingNewOperator
  187986. HMIDIIN hIn;
  187987. private:
  187988. MidiInput* input;
  187989. MidiInputCallback* callback;
  187990. bool isStarted;
  187991. uint32 startTime;
  187992. CriticalSection lock;
  187993. MIDIHDR hdr [numInHeaders];
  187994. char inData [numInHeaders] [inBufferSize];
  187995. int pendingLength;
  187996. char pending [midiBufferSize];
  187997. double timeStampToTime (uint32 timeStamp) throw()
  187998. {
  187999. timeStamp += startTime;
  188000. const uint32 now = Time::getMillisecondCounter();
  188001. if (timeStamp > now)
  188002. {
  188003. if (timeStamp > now + 2)
  188004. --startTime;
  188005. timeStamp = now;
  188006. }
  188007. return 0.001 * timeStamp;
  188008. }
  188009. MidiInThread (const MidiInThread&);
  188010. MidiInThread& operator= (const MidiInThread&);
  188011. };
  188012. static void CALLBACK midiInCallback (HMIDIIN,
  188013. UINT uMsg,
  188014. DWORD_PTR dwInstance,
  188015. DWORD_PTR midiMessage,
  188016. DWORD_PTR timeStamp)
  188017. {
  188018. MidiInThread* const thread = (MidiInThread*) dwInstance;
  188019. if (thread != 0 && activeMidiThreads.contains (thread))
  188020. {
  188021. if (uMsg == MIM_DATA)
  188022. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  188023. else if (uMsg == MIM_LONGDATA)
  188024. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  188025. }
  188026. }
  188027. const StringArray MidiInput::getDevices()
  188028. {
  188029. StringArray s;
  188030. const int num = midiInGetNumDevs();
  188031. for (int i = 0; i < num; ++i)
  188032. {
  188033. MIDIINCAPS mc;
  188034. zerostruct (mc);
  188035. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188036. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188037. }
  188038. return s;
  188039. }
  188040. int MidiInput::getDefaultDeviceIndex()
  188041. {
  188042. return 0;
  188043. }
  188044. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  188045. {
  188046. if (callback == 0)
  188047. return 0;
  188048. UINT deviceId = MIDI_MAPPER;
  188049. int n = 0;
  188050. String name;
  188051. const int num = midiInGetNumDevs();
  188052. for (int i = 0; i < num; ++i)
  188053. {
  188054. MIDIINCAPS mc;
  188055. zerostruct (mc);
  188056. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188057. {
  188058. if (index == n)
  188059. {
  188060. deviceId = i;
  188061. name = String (mc.szPname, sizeof (mc.szPname));
  188062. break;
  188063. }
  188064. ++n;
  188065. }
  188066. }
  188067. ScopedPointer <MidiInput> in (new MidiInput (name));
  188068. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  188069. HMIDIIN h;
  188070. HRESULT err = midiInOpen (&h, deviceId,
  188071. (DWORD_PTR) &midiInCallback,
  188072. (DWORD_PTR) (MidiInThread*) thread,
  188073. CALLBACK_FUNCTION);
  188074. if (err == MMSYSERR_NOERROR)
  188075. {
  188076. thread->hIn = h;
  188077. in->internal = (void*) thread.release();
  188078. return in.release();
  188079. }
  188080. return 0;
  188081. }
  188082. MidiInput::MidiInput (const String& name_)
  188083. : name (name_),
  188084. internal (0)
  188085. {
  188086. }
  188087. MidiInput::~MidiInput()
  188088. {
  188089. if (internal != 0)
  188090. {
  188091. MidiInThread* const thread = (MidiInThread*) internal;
  188092. delete thread;
  188093. }
  188094. }
  188095. void MidiInput::start()
  188096. {
  188097. ((MidiInThread*) internal)->start();
  188098. }
  188099. void MidiInput::stop()
  188100. {
  188101. ((MidiInThread*) internal)->stop();
  188102. }
  188103. struct MidiOutHandle
  188104. {
  188105. int refCount;
  188106. UINT deviceId;
  188107. HMIDIOUT handle;
  188108. juce_UseDebuggingNewOperator
  188109. };
  188110. static Array <MidiOutHandle*> midiOutputHandles;
  188111. const StringArray MidiOutput::getDevices()
  188112. {
  188113. StringArray s;
  188114. const int num = midiOutGetNumDevs();
  188115. for (int i = 0; i < num; ++i)
  188116. {
  188117. MIDIOUTCAPS mc;
  188118. zerostruct (mc);
  188119. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188120. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188121. }
  188122. return s;
  188123. }
  188124. int MidiOutput::getDefaultDeviceIndex()
  188125. {
  188126. const int num = midiOutGetNumDevs();
  188127. int n = 0;
  188128. for (int i = 0; i < num; ++i)
  188129. {
  188130. MIDIOUTCAPS mc;
  188131. zerostruct (mc);
  188132. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188133. {
  188134. if ((mc.wTechnology & MOD_MAPPER) != 0)
  188135. return n;
  188136. ++n;
  188137. }
  188138. }
  188139. return 0;
  188140. }
  188141. MidiOutput* MidiOutput::openDevice (int index)
  188142. {
  188143. UINT deviceId = MIDI_MAPPER;
  188144. const int num = midiOutGetNumDevs();
  188145. int i, n = 0;
  188146. for (i = 0; i < num; ++i)
  188147. {
  188148. MIDIOUTCAPS mc;
  188149. zerostruct (mc);
  188150. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188151. {
  188152. // use the microsoft sw synth as a default - best not to allow deviceId
  188153. // to be MIDI_MAPPER, or else device sharing breaks
  188154. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase (T("microsoft")))
  188155. deviceId = i;
  188156. if (index == n)
  188157. {
  188158. deviceId = i;
  188159. break;
  188160. }
  188161. ++n;
  188162. }
  188163. }
  188164. for (i = midiOutputHandles.size(); --i >= 0;)
  188165. {
  188166. MidiOutHandle* const han = midiOutputHandles.getUnchecked(i);
  188167. if (han != 0 && han->deviceId == deviceId)
  188168. {
  188169. han->refCount++;
  188170. MidiOutput* const out = new MidiOutput();
  188171. out->internal = (void*) han;
  188172. return out;
  188173. }
  188174. }
  188175. for (i = 4; --i >= 0;)
  188176. {
  188177. HMIDIOUT h = 0;
  188178. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  188179. if (res == MMSYSERR_NOERROR)
  188180. {
  188181. MidiOutHandle* const han = new MidiOutHandle();
  188182. han->deviceId = deviceId;
  188183. han->refCount = 1;
  188184. han->handle = h;
  188185. midiOutputHandles.add (han);
  188186. MidiOutput* const out = new MidiOutput();
  188187. out->internal = (void*) han;
  188188. return out;
  188189. }
  188190. else if (res == MMSYSERR_ALLOCATED)
  188191. {
  188192. Sleep (100);
  188193. }
  188194. else
  188195. {
  188196. break;
  188197. }
  188198. }
  188199. return 0;
  188200. }
  188201. MidiOutput::~MidiOutput()
  188202. {
  188203. MidiOutHandle* const h = (MidiOutHandle*) internal;
  188204. if (midiOutputHandles.contains (h) && --(h->refCount) == 0)
  188205. {
  188206. midiOutClose (h->handle);
  188207. midiOutputHandles.removeValue (h);
  188208. delete h;
  188209. }
  188210. }
  188211. void MidiOutput::reset()
  188212. {
  188213. const MidiOutHandle* const h = (MidiOutHandle*) internal;
  188214. midiOutReset (h->handle);
  188215. }
  188216. bool MidiOutput::getVolume (float& leftVol,
  188217. float& rightVol)
  188218. {
  188219. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188220. DWORD n;
  188221. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  188222. {
  188223. const unsigned short* const nn = (const unsigned short*) &n;
  188224. rightVol = nn[0] / (float) 0xffff;
  188225. leftVol = nn[1] / (float) 0xffff;
  188226. return true;
  188227. }
  188228. else
  188229. {
  188230. rightVol = leftVol = 1.0f;
  188231. return false;
  188232. }
  188233. }
  188234. void MidiOutput::setVolume (float leftVol,
  188235. float rightVol)
  188236. {
  188237. const MidiOutHandle* const handle = (MidiOutHandle*) internal;
  188238. DWORD n;
  188239. unsigned short* const nn = (unsigned short*) &n;
  188240. nn[0] = (unsigned short) jlimit (0, 0xffff, (int)(rightVol * 0xffff));
  188241. nn[1] = (unsigned short) jlimit (0, 0xffff, (int)(leftVol * 0xffff));
  188242. midiOutSetVolume (handle->handle, n);
  188243. }
  188244. void MidiOutput::sendMessageNow (const MidiMessage& message)
  188245. {
  188246. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188247. if (message.getRawDataSize() > 3
  188248. || message.isSysEx())
  188249. {
  188250. MIDIHDR h;
  188251. zerostruct (h);
  188252. h.lpData = (char*) message.getRawData();
  188253. h.dwBufferLength = message.getRawDataSize();
  188254. h.dwBytesRecorded = message.getRawDataSize();
  188255. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  188256. {
  188257. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  188258. if (res == MMSYSERR_NOERROR)
  188259. {
  188260. while ((h.dwFlags & MHDR_DONE) == 0)
  188261. Sleep (1);
  188262. int count = 500; // 1 sec timeout
  188263. while (--count >= 0)
  188264. {
  188265. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  188266. if (res == MIDIERR_STILLPLAYING)
  188267. Sleep (2);
  188268. else
  188269. break;
  188270. }
  188271. }
  188272. }
  188273. }
  188274. else
  188275. {
  188276. midiOutShortMsg (handle->handle,
  188277. *(unsigned int*) message.getRawData());
  188278. }
  188279. }
  188280. #endif
  188281. /*** End of inlined file: juce_win32_Midi.cpp ***/
  188282. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  188283. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188284. // compiled on its own).
  188285. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  188286. #undef WINDOWS
  188287. // #define ASIO_DEBUGGING
  188288. #ifdef ASIO_DEBUGGING
  188289. #define log(a) { Logger::writeToLog (a); DBG (a) }
  188290. #else
  188291. #define log(a) {}
  188292. #endif
  188293. #ifdef ASIO_DEBUGGING
  188294. static void logError (const String& context, long error)
  188295. {
  188296. String err ("unknown error");
  188297. if (error == ASE_NotPresent)
  188298. err = "Not Present";
  188299. else if (error == ASE_HWMalfunction)
  188300. err = "Hardware Malfunction";
  188301. else if (error == ASE_InvalidParameter)
  188302. err = "Invalid Parameter";
  188303. else if (error == ASE_InvalidMode)
  188304. err = "Invalid Mode";
  188305. else if (error == ASE_SPNotAdvancing)
  188306. err = "Sample position not advancing";
  188307. else if (error == ASE_NoClock)
  188308. err = "No Clock";
  188309. else if (error == ASE_NoMemory)
  188310. err = "Out of memory";
  188311. log (T("!!error: ") + context + T(" - ") + err);
  188312. }
  188313. #else
  188314. #define logError(a, b) {}
  188315. #endif
  188316. class ASIOAudioIODevice;
  188317. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  188318. static const int maxASIOChannels = 160;
  188319. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  188320. private Timer
  188321. {
  188322. public:
  188323. Component ourWindow;
  188324. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  188325. const String& optionalDllForDirectLoading_)
  188326. : AudioIODevice (name_, T("ASIO")),
  188327. asioObject (0),
  188328. classId (classId_),
  188329. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  188330. currentBitDepth (16),
  188331. currentSampleRate (0),
  188332. isOpen_ (false),
  188333. isStarted (false),
  188334. postOutput (true),
  188335. insideControlPanelModalLoop (false),
  188336. shouldUsePreferredSize (false)
  188337. {
  188338. name = name_;
  188339. ourWindow.addToDesktop (0);
  188340. windowHandle = ourWindow.getWindowHandle();
  188341. jassert (currentASIODev [slotNumber] == 0);
  188342. currentASIODev [slotNumber] = this;
  188343. openDevice();
  188344. }
  188345. ~ASIOAudioIODevice()
  188346. {
  188347. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188348. if (currentASIODev[i] == this)
  188349. currentASIODev[i] = 0;
  188350. close();
  188351. log ("ASIO - exiting");
  188352. removeCurrentDriver();
  188353. }
  188354. void updateSampleRates()
  188355. {
  188356. // find a list of sample rates..
  188357. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188358. sampleRates.clear();
  188359. if (asioObject != 0)
  188360. {
  188361. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188362. {
  188363. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188364. if (err == 0)
  188365. {
  188366. sampleRates.add ((int) possibleSampleRates[index]);
  188367. log (T("rate: ") + String ((int) possibleSampleRates[index]));
  188368. }
  188369. else if (err != ASE_NoClock)
  188370. {
  188371. logError (T("CanSampleRate"), err);
  188372. }
  188373. }
  188374. if (sampleRates.size() == 0)
  188375. {
  188376. double cr = 0;
  188377. const long err = asioObject->getSampleRate (&cr);
  188378. log (T("No sample rates supported - current rate: ") + String ((int) cr));
  188379. if (err == 0)
  188380. sampleRates.add ((int) cr);
  188381. }
  188382. }
  188383. }
  188384. const StringArray getOutputChannelNames()
  188385. {
  188386. return outputChannelNames;
  188387. }
  188388. const StringArray getInputChannelNames()
  188389. {
  188390. return inputChannelNames;
  188391. }
  188392. int getNumSampleRates()
  188393. {
  188394. return sampleRates.size();
  188395. }
  188396. double getSampleRate (int index)
  188397. {
  188398. return sampleRates [index];
  188399. }
  188400. int getNumBufferSizesAvailable()
  188401. {
  188402. return bufferSizes.size();
  188403. }
  188404. int getBufferSizeSamples (int index)
  188405. {
  188406. return bufferSizes [index];
  188407. }
  188408. int getDefaultBufferSize()
  188409. {
  188410. return preferredSize;
  188411. }
  188412. const String open (const BitArray& inputChannels,
  188413. const BitArray& outputChannels,
  188414. double sr,
  188415. int bufferSizeSamples)
  188416. {
  188417. close();
  188418. currentCallback = 0;
  188419. if (bufferSizeSamples <= 0)
  188420. shouldUsePreferredSize = true;
  188421. if (asioObject == 0 || ! isASIOOpen)
  188422. {
  188423. log ("Warning: device not open");
  188424. const String err (openDevice());
  188425. if (asioObject == 0 || ! isASIOOpen)
  188426. return err;
  188427. }
  188428. isStarted = false;
  188429. bufferIndex = -1;
  188430. long err = 0;
  188431. long newPreferredSize = 0;
  188432. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188433. minSize = 0;
  188434. maxSize = 0;
  188435. newPreferredSize = 0;
  188436. granularity = 0;
  188437. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188438. {
  188439. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188440. shouldUsePreferredSize = true;
  188441. preferredSize = newPreferredSize;
  188442. }
  188443. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188444. // dynamic changes to the buffer size...
  188445. shouldUsePreferredSize = shouldUsePreferredSize
  188446. || getName().containsIgnoreCase (T("Digidesign"));
  188447. if (shouldUsePreferredSize)
  188448. {
  188449. log ("Using preferred size for buffer..");
  188450. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188451. {
  188452. bufferSizeSamples = preferredSize;
  188453. }
  188454. else
  188455. {
  188456. bufferSizeSamples = 1024;
  188457. logError ("GetBufferSize1", err);
  188458. }
  188459. shouldUsePreferredSize = false;
  188460. }
  188461. int sampleRate = roundDoubleToInt (sr);
  188462. currentSampleRate = sampleRate;
  188463. currentBlockSizeSamples = bufferSizeSamples;
  188464. currentChansOut.clear();
  188465. currentChansIn.clear();
  188466. zeromem (inBuffers, sizeof (inBuffers));
  188467. zeromem (outBuffers, sizeof (outBuffers));
  188468. updateSampleRates();
  188469. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188470. sampleRate = sampleRates[0];
  188471. jassert (sampleRate != 0);
  188472. if (sampleRate == 0)
  188473. sampleRate = 44100;
  188474. long numSources = 32;
  188475. ASIOClockSource clocks[32];
  188476. zeromem (clocks, sizeof (clocks));
  188477. asioObject->getClockSources (clocks, &numSources);
  188478. bool isSourceSet = false;
  188479. // careful not to remove this loop because it does more than just logging!
  188480. int i;
  188481. for (i = 0; i < numSources; ++i)
  188482. {
  188483. String s ("clock: ");
  188484. s += clocks[i].name;
  188485. if (clocks[i].isCurrentSource)
  188486. {
  188487. isSourceSet = true;
  188488. s << " (cur)";
  188489. }
  188490. log (s);
  188491. }
  188492. if (numSources > 1 && ! isSourceSet)
  188493. {
  188494. log ("setting clock source");
  188495. asioObject->setClockSource (clocks[0].index);
  188496. Thread::sleep (20);
  188497. }
  188498. else
  188499. {
  188500. if (numSources == 0)
  188501. {
  188502. log ("ASIO - no clock sources!");
  188503. }
  188504. }
  188505. double cr = 0;
  188506. err = asioObject->getSampleRate (&cr);
  188507. if (err == 0)
  188508. {
  188509. currentSampleRate = cr;
  188510. }
  188511. else
  188512. {
  188513. logError ("GetSampleRate", err);
  188514. currentSampleRate = 0;
  188515. }
  188516. error = String::empty;
  188517. needToReset = false;
  188518. isReSync = false;
  188519. err = 0;
  188520. bool buffersCreated = false;
  188521. if (currentSampleRate != sampleRate)
  188522. {
  188523. log (T("ASIO samplerate: ") + String (currentSampleRate) + T(" to ") + String (sampleRate));
  188524. err = asioObject->setSampleRate (sampleRate);
  188525. if (err == ASE_NoClock && numSources > 0)
  188526. {
  188527. log ("trying to set a clock source..");
  188528. Thread::sleep (10);
  188529. err = asioObject->setClockSource (clocks[0].index);
  188530. if (err != 0)
  188531. {
  188532. logError ("SetClock", err);
  188533. }
  188534. Thread::sleep (10);
  188535. err = asioObject->setSampleRate (sampleRate);
  188536. }
  188537. }
  188538. if (err == 0)
  188539. {
  188540. currentSampleRate = sampleRate;
  188541. if (needToReset)
  188542. {
  188543. if (isReSync)
  188544. {
  188545. log ("Resync request");
  188546. }
  188547. log ("! Resetting ASIO after sample rate change");
  188548. removeCurrentDriver();
  188549. loadDriver();
  188550. const String error (initDriver());
  188551. if (error.isNotEmpty())
  188552. {
  188553. log (T("ASIOInit: ") + error);
  188554. }
  188555. needToReset = false;
  188556. isReSync = false;
  188557. }
  188558. numActiveInputChans = 0;
  188559. numActiveOutputChans = 0;
  188560. ASIOBufferInfo* info = bufferInfos;
  188561. int i;
  188562. for (i = 0; i < totalNumInputChans; ++i)
  188563. {
  188564. if (inputChannels[i])
  188565. {
  188566. currentChansIn.setBit (i);
  188567. info->isInput = 1;
  188568. info->channelNum = i;
  188569. info->buffers[0] = info->buffers[1] = 0;
  188570. ++info;
  188571. ++numActiveInputChans;
  188572. }
  188573. }
  188574. for (i = 0; i < totalNumOutputChans; ++i)
  188575. {
  188576. if (outputChannels[i])
  188577. {
  188578. currentChansOut.setBit (i);
  188579. info->isInput = 0;
  188580. info->channelNum = i;
  188581. info->buffers[0] = info->buffers[1] = 0;
  188582. ++info;
  188583. ++numActiveOutputChans;
  188584. }
  188585. }
  188586. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  188587. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188588. if (currentASIODev[0] == this)
  188589. {
  188590. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188591. callbacks.asioMessage = &asioMessagesCallback0;
  188592. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188593. }
  188594. else if (currentASIODev[1] == this)
  188595. {
  188596. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188597. callbacks.asioMessage = &asioMessagesCallback1;
  188598. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188599. }
  188600. else if (currentASIODev[2] == this)
  188601. {
  188602. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188603. callbacks.asioMessage = &asioMessagesCallback2;
  188604. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188605. }
  188606. else
  188607. {
  188608. jassertfalse
  188609. }
  188610. log ("disposing buffers");
  188611. err = asioObject->disposeBuffers();
  188612. log (T("creating buffers: ") + String (totalBuffers) + T(", ") + String (currentBlockSizeSamples));
  188613. err = asioObject->createBuffers (bufferInfos,
  188614. totalBuffers,
  188615. currentBlockSizeSamples,
  188616. &callbacks);
  188617. if (err != 0)
  188618. {
  188619. currentBlockSizeSamples = preferredSize;
  188620. logError ("create buffers 2", err);
  188621. asioObject->disposeBuffers();
  188622. err = asioObject->createBuffers (bufferInfos,
  188623. totalBuffers,
  188624. currentBlockSizeSamples,
  188625. &callbacks);
  188626. }
  188627. if (err == 0)
  188628. {
  188629. buffersCreated = true;
  188630. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  188631. int n = 0;
  188632. Array <int> types;
  188633. currentBitDepth = 16;
  188634. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  188635. {
  188636. if (inputChannels[i])
  188637. {
  188638. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  188639. ASIOChannelInfo channelInfo;
  188640. zerostruct (channelInfo);
  188641. channelInfo.channel = i;
  188642. channelInfo.isInput = 1;
  188643. asioObject->getChannelInfo (&channelInfo);
  188644. types.addIfNotAlreadyThere (channelInfo.type);
  188645. typeToFormatParameters (channelInfo.type,
  188646. inputChannelBitDepths[n],
  188647. inputChannelBytesPerSample[n],
  188648. inputChannelIsFloat[n],
  188649. inputChannelLittleEndian[n]);
  188650. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188651. ++n;
  188652. }
  188653. }
  188654. jassert (numActiveInputChans == n);
  188655. n = 0;
  188656. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188657. {
  188658. if (outputChannels[i])
  188659. {
  188660. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188661. ASIOChannelInfo channelInfo;
  188662. zerostruct (channelInfo);
  188663. channelInfo.channel = i;
  188664. channelInfo.isInput = 0;
  188665. asioObject->getChannelInfo (&channelInfo);
  188666. types.addIfNotAlreadyThere (channelInfo.type);
  188667. typeToFormatParameters (channelInfo.type,
  188668. outputChannelBitDepths[n],
  188669. outputChannelBytesPerSample[n],
  188670. outputChannelIsFloat[n],
  188671. outputChannelLittleEndian[n]);
  188672. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188673. ++n;
  188674. }
  188675. }
  188676. jassert (numActiveOutputChans == n);
  188677. for (i = types.size(); --i >= 0;)
  188678. {
  188679. log (T("channel format: ") + String (types[i]));
  188680. }
  188681. jassert (n <= totalBuffers);
  188682. for (i = 0; i < numActiveOutputChans; ++i)
  188683. {
  188684. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  188685. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  188686. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  188687. {
  188688. log ("!! Null buffers");
  188689. }
  188690. else
  188691. {
  188692. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  188693. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  188694. }
  188695. }
  188696. inputLatency = outputLatency = 0;
  188697. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188698. {
  188699. log ("ASIO - no latencies");
  188700. }
  188701. else
  188702. {
  188703. log (T("ASIO latencies: ")
  188704. + String ((int) outputLatency)
  188705. + T(", ")
  188706. + String ((int) inputLatency));
  188707. }
  188708. isOpen_ = true;
  188709. log ("starting ASIO");
  188710. calledback = false;
  188711. err = asioObject->start();
  188712. if (err != 0)
  188713. {
  188714. isOpen_ = false;
  188715. log ("ASIO - stop on failure");
  188716. Thread::sleep (10);
  188717. asioObject->stop();
  188718. error = "Can't start device";
  188719. Thread::sleep (10);
  188720. }
  188721. else
  188722. {
  188723. int count = 300;
  188724. while (--count > 0 && ! calledback)
  188725. Thread::sleep (10);
  188726. isStarted = true;
  188727. if (! calledback)
  188728. {
  188729. error = "Device didn't start correctly";
  188730. log ("ASIO didn't callback - stopping..");
  188731. asioObject->stop();
  188732. }
  188733. }
  188734. }
  188735. else
  188736. {
  188737. error = "Can't create i/o buffers";
  188738. }
  188739. }
  188740. else
  188741. {
  188742. error = "Can't set sample rate: ";
  188743. error << sampleRate;
  188744. }
  188745. if (error.isNotEmpty())
  188746. {
  188747. logError (error, err);
  188748. if (asioObject != 0 && buffersCreated)
  188749. asioObject->disposeBuffers();
  188750. Thread::sleep (20);
  188751. isStarted = false;
  188752. isOpen_ = false;
  188753. close();
  188754. }
  188755. needToReset = false;
  188756. isReSync = false;
  188757. return error;
  188758. }
  188759. void close()
  188760. {
  188761. error = String::empty;
  188762. stopTimer();
  188763. stop();
  188764. if (isASIOOpen && isOpen_)
  188765. {
  188766. const ScopedLock sl (callbackLock);
  188767. isOpen_ = false;
  188768. isStarted = false;
  188769. needToReset = false;
  188770. isReSync = false;
  188771. log ("ASIO - stopping");
  188772. if (asioObject != 0)
  188773. {
  188774. Thread::sleep (20);
  188775. asioObject->stop();
  188776. Thread::sleep (10);
  188777. asioObject->disposeBuffers();
  188778. }
  188779. Thread::sleep (10);
  188780. }
  188781. }
  188782. bool isOpen()
  188783. {
  188784. return isOpen_ || insideControlPanelModalLoop;
  188785. }
  188786. int getCurrentBufferSizeSamples()
  188787. {
  188788. return currentBlockSizeSamples;
  188789. }
  188790. double getCurrentSampleRate()
  188791. {
  188792. return currentSampleRate;
  188793. }
  188794. const BitArray getActiveOutputChannels() const
  188795. {
  188796. return currentChansOut;
  188797. }
  188798. const BitArray getActiveInputChannels() const
  188799. {
  188800. return currentChansIn;
  188801. }
  188802. int getCurrentBitDepth()
  188803. {
  188804. return currentBitDepth;
  188805. }
  188806. int getOutputLatencyInSamples()
  188807. {
  188808. return outputLatency + currentBlockSizeSamples / 4;
  188809. }
  188810. int getInputLatencyInSamples()
  188811. {
  188812. return inputLatency + currentBlockSizeSamples / 4;
  188813. }
  188814. void start (AudioIODeviceCallback* callback)
  188815. {
  188816. if (callback != 0)
  188817. {
  188818. callback->audioDeviceAboutToStart (this);
  188819. const ScopedLock sl (callbackLock);
  188820. currentCallback = callback;
  188821. }
  188822. }
  188823. void stop()
  188824. {
  188825. AudioIODeviceCallback* const lastCallback = currentCallback;
  188826. {
  188827. const ScopedLock sl (callbackLock);
  188828. currentCallback = 0;
  188829. }
  188830. if (lastCallback != 0)
  188831. lastCallback->audioDeviceStopped();
  188832. }
  188833. bool isPlaying()
  188834. {
  188835. return isASIOOpen && (currentCallback != 0);
  188836. }
  188837. const String getLastError()
  188838. {
  188839. return error;
  188840. }
  188841. bool hasControlPanel() const
  188842. {
  188843. return true;
  188844. }
  188845. bool showControlPanel()
  188846. {
  188847. log ("ASIO - showing control panel");
  188848. Component modalWindow (String::empty);
  188849. modalWindow.setOpaque (true);
  188850. modalWindow.addToDesktop (0);
  188851. modalWindow.enterModalState();
  188852. bool done = false;
  188853. JUCE_TRY
  188854. {
  188855. // are there are devices that need to be closed before showing their control panel?
  188856. // close();
  188857. insideControlPanelModalLoop = true;
  188858. const uint32 started = Time::getMillisecondCounter();
  188859. if (asioObject != 0)
  188860. {
  188861. asioObject->controlPanel();
  188862. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  188863. log (T("spent: ") + String (spent));
  188864. if (spent > 300)
  188865. {
  188866. shouldUsePreferredSize = true;
  188867. done = true;
  188868. }
  188869. }
  188870. }
  188871. JUCE_CATCH_ALL
  188872. insideControlPanelModalLoop = false;
  188873. return done;
  188874. }
  188875. void resetRequest() throw()
  188876. {
  188877. needToReset = true;
  188878. }
  188879. void resyncRequest() throw()
  188880. {
  188881. needToReset = true;
  188882. isReSync = true;
  188883. }
  188884. void timerCallback()
  188885. {
  188886. if (! insideControlPanelModalLoop)
  188887. {
  188888. stopTimer();
  188889. // used to cause a reset
  188890. log ("! ASIO restart request!");
  188891. if (isOpen_)
  188892. {
  188893. AudioIODeviceCallback* const oldCallback = currentCallback;
  188894. close();
  188895. open (BitArray (currentChansIn), BitArray (currentChansOut),
  188896. currentSampleRate, currentBlockSizeSamples);
  188897. if (oldCallback != 0)
  188898. start (oldCallback);
  188899. }
  188900. }
  188901. else
  188902. {
  188903. startTimer (100);
  188904. }
  188905. }
  188906. juce_UseDebuggingNewOperator
  188907. private:
  188908. IASIO* volatile asioObject;
  188909. ASIOCallbacks callbacks;
  188910. void* windowHandle;
  188911. CLSID classId;
  188912. const String optionalDllForDirectLoading;
  188913. String error;
  188914. long totalNumInputChans, totalNumOutputChans;
  188915. StringArray inputChannelNames, outputChannelNames;
  188916. Array<int> sampleRates, bufferSizes;
  188917. long inputLatency, outputLatency;
  188918. long minSize, maxSize, preferredSize, granularity;
  188919. int volatile currentBlockSizeSamples;
  188920. int volatile currentBitDepth;
  188921. double volatile currentSampleRate;
  188922. BitArray currentChansOut, currentChansIn;
  188923. AudioIODeviceCallback* volatile currentCallback;
  188924. CriticalSection callbackLock;
  188925. ASIOBufferInfo bufferInfos [maxASIOChannels];
  188926. float* inBuffers [maxASIOChannels];
  188927. float* outBuffers [maxASIOChannels];
  188928. int inputChannelBitDepths [maxASIOChannels];
  188929. int outputChannelBitDepths [maxASIOChannels];
  188930. int inputChannelBytesPerSample [maxASIOChannels];
  188931. int outputChannelBytesPerSample [maxASIOChannels];
  188932. bool inputChannelIsFloat [maxASIOChannels];
  188933. bool outputChannelIsFloat [maxASIOChannels];
  188934. bool inputChannelLittleEndian [maxASIOChannels];
  188935. bool outputChannelLittleEndian [maxASIOChannels];
  188936. WaitableEvent event1;
  188937. HeapBlock <float> tempBuffer;
  188938. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  188939. bool isOpen_, isStarted;
  188940. bool volatile isASIOOpen;
  188941. bool volatile calledback;
  188942. bool volatile littleEndian, postOutput, needToReset, isReSync;
  188943. bool volatile insideControlPanelModalLoop;
  188944. bool volatile shouldUsePreferredSize;
  188945. void removeCurrentDriver()
  188946. {
  188947. if (asioObject != 0)
  188948. {
  188949. asioObject->Release();
  188950. asioObject = 0;
  188951. }
  188952. }
  188953. bool loadDriver()
  188954. {
  188955. removeCurrentDriver();
  188956. JUCE_TRY
  188957. {
  188958. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  188959. classId, (void**) &asioObject) == S_OK)
  188960. {
  188961. return true;
  188962. }
  188963. // If a class isn't registered but we have a path for it, we can fallback to
  188964. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  188965. if (optionalDllForDirectLoading.isNotEmpty())
  188966. {
  188967. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  188968. if (h != 0)
  188969. {
  188970. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  188971. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  188972. if (dllGetClassObject != 0)
  188973. {
  188974. IClassFactory* classFactory = 0;
  188975. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  188976. if (classFactory != 0)
  188977. {
  188978. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  188979. classFactory->Release();
  188980. }
  188981. return asioObject != 0;
  188982. }
  188983. }
  188984. }
  188985. }
  188986. JUCE_CATCH_ALL
  188987. asioObject = 0;
  188988. return false;
  188989. }
  188990. const String initDriver()
  188991. {
  188992. if (asioObject != 0)
  188993. {
  188994. char buffer [256];
  188995. zeromem (buffer, sizeof (buffer));
  188996. if (! asioObject->init (windowHandle))
  188997. {
  188998. asioObject->getErrorMessage (buffer);
  188999. return String (buffer, sizeof (buffer) - 1);
  189000. }
  189001. // just in case any daft drivers expect this to be called..
  189002. asioObject->getDriverName (buffer);
  189003. return String::empty;
  189004. }
  189005. return "No Driver";
  189006. }
  189007. const String openDevice()
  189008. {
  189009. // use this in case the driver starts opening dialog boxes..
  189010. Component modalWindow (String::empty);
  189011. modalWindow.setOpaque (true);
  189012. modalWindow.addToDesktop (0);
  189013. modalWindow.enterModalState();
  189014. // open the device and get its info..
  189015. log (T("opening ASIO device: ") + getName());
  189016. needToReset = false;
  189017. isReSync = false;
  189018. outputChannelNames.clear();
  189019. inputChannelNames.clear();
  189020. bufferSizes.clear();
  189021. sampleRates.clear();
  189022. isASIOOpen = false;
  189023. isOpen_ = false;
  189024. totalNumInputChans = 0;
  189025. totalNumOutputChans = 0;
  189026. numActiveInputChans = 0;
  189027. numActiveOutputChans = 0;
  189028. currentCallback = 0;
  189029. error = String::empty;
  189030. if (getName().isEmpty())
  189031. return error;
  189032. long err = 0;
  189033. if (loadDriver())
  189034. {
  189035. if ((error = initDriver()).isEmpty())
  189036. {
  189037. numActiveInputChans = 0;
  189038. numActiveOutputChans = 0;
  189039. totalNumInputChans = 0;
  189040. totalNumOutputChans = 0;
  189041. if (asioObject != 0
  189042. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  189043. {
  189044. log (String ((int) totalNumInputChans) + T(" in, ") + String ((int) totalNumOutputChans) + T(" out"));
  189045. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  189046. {
  189047. // find a list of buffer sizes..
  189048. log (String ((int) minSize) + T(" ") + String ((int) maxSize) + T(" ") + String ((int)preferredSize) + T(" ") + String ((int)granularity));
  189049. if (granularity >= 0)
  189050. {
  189051. granularity = jmax (1, (int) granularity);
  189052. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  189053. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  189054. }
  189055. else if (granularity < 0)
  189056. {
  189057. for (int i = 0; i < 18; ++i)
  189058. {
  189059. const int s = (1 << i);
  189060. if (s >= minSize && s <= maxSize)
  189061. bufferSizes.add (s);
  189062. }
  189063. }
  189064. if (! bufferSizes.contains (preferredSize))
  189065. bufferSizes.insert (0, preferredSize);
  189066. double currentRate = 0;
  189067. asioObject->getSampleRate (&currentRate);
  189068. if (currentRate <= 0.0 || currentRate > 192001.0)
  189069. {
  189070. log ("setting sample rate");
  189071. err = asioObject->setSampleRate (44100.0);
  189072. if (err != 0)
  189073. {
  189074. logError ("setting sample rate", err);
  189075. }
  189076. asioObject->getSampleRate (&currentRate);
  189077. }
  189078. currentSampleRate = currentRate;
  189079. postOutput = (asioObject->outputReady() == 0);
  189080. if (postOutput)
  189081. {
  189082. log ("ASIO outputReady = ok");
  189083. }
  189084. updateSampleRates();
  189085. // ..because cubase does it at this point
  189086. inputLatency = outputLatency = 0;
  189087. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  189088. {
  189089. log ("ASIO - no latencies");
  189090. }
  189091. log (String ("latencies: ")
  189092. + String ((int) inputLatency)
  189093. + T(", ") + String ((int) outputLatency));
  189094. // create some dummy buffers now.. because cubase does..
  189095. numActiveInputChans = 0;
  189096. numActiveOutputChans = 0;
  189097. ASIOBufferInfo* info = bufferInfos;
  189098. int i, numChans = 0;
  189099. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  189100. {
  189101. info->isInput = 1;
  189102. info->channelNum = i;
  189103. info->buffers[0] = info->buffers[1] = 0;
  189104. ++info;
  189105. ++numChans;
  189106. }
  189107. const int outputBufferIndex = numChans;
  189108. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  189109. {
  189110. info->isInput = 0;
  189111. info->channelNum = i;
  189112. info->buffers[0] = info->buffers[1] = 0;
  189113. ++info;
  189114. ++numChans;
  189115. }
  189116. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  189117. if (currentASIODev[0] == this)
  189118. {
  189119. callbacks.bufferSwitch = &bufferSwitchCallback0;
  189120. callbacks.asioMessage = &asioMessagesCallback0;
  189121. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  189122. }
  189123. else if (currentASIODev[1] == this)
  189124. {
  189125. callbacks.bufferSwitch = &bufferSwitchCallback1;
  189126. callbacks.asioMessage = &asioMessagesCallback1;
  189127. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  189128. }
  189129. else if (currentASIODev[2] == this)
  189130. {
  189131. callbacks.bufferSwitch = &bufferSwitchCallback2;
  189132. callbacks.asioMessage = &asioMessagesCallback2;
  189133. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  189134. }
  189135. else
  189136. {
  189137. jassertfalse
  189138. }
  189139. log (T("creating buffers (dummy): ") + String (numChans)
  189140. + T(", ") + String ((int) preferredSize));
  189141. if (preferredSize > 0)
  189142. {
  189143. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  189144. if (err != 0)
  189145. {
  189146. logError ("dummy buffers", err);
  189147. }
  189148. }
  189149. long newInps = 0, newOuts = 0;
  189150. asioObject->getChannels (&newInps, &newOuts);
  189151. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  189152. {
  189153. totalNumInputChans = newInps;
  189154. totalNumOutputChans = newOuts;
  189155. log (String ((int) totalNumInputChans) + T(" in; ")
  189156. + String ((int) totalNumOutputChans) + T(" out"));
  189157. }
  189158. updateSampleRates();
  189159. ASIOChannelInfo channelInfo;
  189160. channelInfo.type = 0;
  189161. for (i = 0; i < totalNumInputChans; ++i)
  189162. {
  189163. zerostruct (channelInfo);
  189164. channelInfo.channel = i;
  189165. channelInfo.isInput = 1;
  189166. asioObject->getChannelInfo (&channelInfo);
  189167. inputChannelNames.add (String (channelInfo.name));
  189168. }
  189169. for (i = 0; i < totalNumOutputChans; ++i)
  189170. {
  189171. zerostruct (channelInfo);
  189172. channelInfo.channel = i;
  189173. channelInfo.isInput = 0;
  189174. asioObject->getChannelInfo (&channelInfo);
  189175. outputChannelNames.add (String (channelInfo.name));
  189176. typeToFormatParameters (channelInfo.type,
  189177. outputChannelBitDepths[i],
  189178. outputChannelBytesPerSample[i],
  189179. outputChannelIsFloat[i],
  189180. outputChannelLittleEndian[i]);
  189181. if (i < 2)
  189182. {
  189183. // clear the channels that are used with the dummy stuff
  189184. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  189185. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  189186. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  189187. }
  189188. }
  189189. outputChannelNames.trim();
  189190. inputChannelNames.trim();
  189191. outputChannelNames.appendNumbersToDuplicates (false, true);
  189192. inputChannelNames.appendNumbersToDuplicates (false, true);
  189193. // start and stop because cubase does it..
  189194. asioObject->getLatencies (&inputLatency, &outputLatency);
  189195. if ((err = asioObject->start()) != 0)
  189196. {
  189197. // ignore an error here, as it might start later after setting other stuff up
  189198. logError ("ASIO start", err);
  189199. }
  189200. Thread::sleep (100);
  189201. asioObject->stop();
  189202. }
  189203. else
  189204. {
  189205. error = "Can't detect buffer sizes";
  189206. }
  189207. }
  189208. else
  189209. {
  189210. error = "Can't detect asio channels";
  189211. }
  189212. }
  189213. }
  189214. else
  189215. {
  189216. error = "No such device";
  189217. }
  189218. if (error.isNotEmpty())
  189219. {
  189220. logError (error, err);
  189221. if (asioObject != 0)
  189222. asioObject->disposeBuffers();
  189223. removeCurrentDriver();
  189224. isASIOOpen = false;
  189225. }
  189226. else
  189227. {
  189228. isASIOOpen = true;
  189229. log ("ASIO device open");
  189230. }
  189231. isOpen_ = false;
  189232. needToReset = false;
  189233. isReSync = false;
  189234. return error;
  189235. }
  189236. void callback (const long index) throw()
  189237. {
  189238. if (isStarted)
  189239. {
  189240. bufferIndex = index;
  189241. processBuffer();
  189242. }
  189243. else
  189244. {
  189245. if (postOutput && (asioObject != 0))
  189246. asioObject->outputReady();
  189247. }
  189248. calledback = true;
  189249. }
  189250. void processBuffer() throw()
  189251. {
  189252. const ASIOBufferInfo* const infos = bufferInfos;
  189253. const int bi = bufferIndex;
  189254. const ScopedLock sl (callbackLock);
  189255. if (needToReset)
  189256. {
  189257. needToReset = false;
  189258. if (isReSync)
  189259. {
  189260. log ("! ASIO resync");
  189261. isReSync = false;
  189262. }
  189263. else
  189264. {
  189265. startTimer (20);
  189266. }
  189267. }
  189268. if (bi >= 0)
  189269. {
  189270. const int samps = currentBlockSizeSamples;
  189271. if (currentCallback != 0)
  189272. {
  189273. int i;
  189274. for (i = 0; i < numActiveInputChans; ++i)
  189275. {
  189276. float* const dst = inBuffers[i];
  189277. jassert (dst != 0);
  189278. const char* const src = (const char*) (infos[i].buffers[bi]);
  189279. if (inputChannelIsFloat[i])
  189280. {
  189281. memcpy (dst, src, samps * sizeof (float));
  189282. }
  189283. else
  189284. {
  189285. jassert (dst == tempBuffer + (samps * i));
  189286. switch (inputChannelBitDepths[i])
  189287. {
  189288. case 16:
  189289. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  189290. samps, inputChannelLittleEndian[i]);
  189291. break;
  189292. case 24:
  189293. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  189294. samps, inputChannelLittleEndian[i]);
  189295. break;
  189296. case 32:
  189297. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  189298. samps, inputChannelLittleEndian[i]);
  189299. break;
  189300. case 64:
  189301. jassertfalse
  189302. break;
  189303. }
  189304. }
  189305. }
  189306. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  189307. numActiveInputChans,
  189308. outBuffers,
  189309. numActiveOutputChans,
  189310. samps);
  189311. for (i = 0; i < numActiveOutputChans; ++i)
  189312. {
  189313. float* const src = outBuffers[i];
  189314. jassert (src != 0);
  189315. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  189316. if (outputChannelIsFloat[i])
  189317. {
  189318. memcpy (dst, src, samps * sizeof (float));
  189319. }
  189320. else
  189321. {
  189322. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  189323. switch (outputChannelBitDepths[i])
  189324. {
  189325. case 16:
  189326. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  189327. samps, outputChannelLittleEndian[i]);
  189328. break;
  189329. case 24:
  189330. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  189331. samps, outputChannelLittleEndian[i]);
  189332. break;
  189333. case 32:
  189334. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  189335. samps, outputChannelLittleEndian[i]);
  189336. break;
  189337. case 64:
  189338. jassertfalse
  189339. break;
  189340. }
  189341. }
  189342. }
  189343. }
  189344. else
  189345. {
  189346. for (int i = 0; i < numActiveOutputChans; ++i)
  189347. {
  189348. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189349. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189350. }
  189351. }
  189352. }
  189353. if (postOutput)
  189354. asioObject->outputReady();
  189355. }
  189356. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189357. {
  189358. if (currentASIODev[0] != 0)
  189359. currentASIODev[0]->callback (index);
  189360. return 0;
  189361. }
  189362. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189363. {
  189364. if (currentASIODev[1] != 0)
  189365. currentASIODev[1]->callback (index);
  189366. return 0;
  189367. }
  189368. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189369. {
  189370. if (currentASIODev[2] != 0)
  189371. currentASIODev[2]->callback (index);
  189372. return 0;
  189373. }
  189374. static void bufferSwitchCallback0 (long index, long) throw()
  189375. {
  189376. if (currentASIODev[0] != 0)
  189377. currentASIODev[0]->callback (index);
  189378. }
  189379. static void bufferSwitchCallback1 (long index, long) throw()
  189380. {
  189381. if (currentASIODev[1] != 0)
  189382. currentASIODev[1]->callback (index);
  189383. }
  189384. static void bufferSwitchCallback2 (long index, long) throw()
  189385. {
  189386. if (currentASIODev[2] != 0)
  189387. currentASIODev[2]->callback (index);
  189388. }
  189389. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189390. {
  189391. return asioMessagesCallback (selector, value, 0);
  189392. }
  189393. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189394. {
  189395. return asioMessagesCallback (selector, value, 1);
  189396. }
  189397. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189398. {
  189399. return asioMessagesCallback (selector, value, 2);
  189400. }
  189401. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189402. {
  189403. switch (selector)
  189404. {
  189405. case kAsioSelectorSupported:
  189406. if (value == kAsioResetRequest
  189407. || value == kAsioEngineVersion
  189408. || value == kAsioResyncRequest
  189409. || value == kAsioLatenciesChanged
  189410. || value == kAsioSupportsInputMonitor)
  189411. return 1;
  189412. break;
  189413. case kAsioBufferSizeChange:
  189414. break;
  189415. case kAsioResetRequest:
  189416. if (currentASIODev[deviceIndex] != 0)
  189417. currentASIODev[deviceIndex]->resetRequest();
  189418. return 1;
  189419. case kAsioResyncRequest:
  189420. if (currentASIODev[deviceIndex] != 0)
  189421. currentASIODev[deviceIndex]->resyncRequest();
  189422. return 1;
  189423. case kAsioLatenciesChanged:
  189424. return 1;
  189425. case kAsioEngineVersion:
  189426. return 2;
  189427. case kAsioSupportsTimeInfo:
  189428. case kAsioSupportsTimeCode:
  189429. return 0;
  189430. }
  189431. return 0;
  189432. }
  189433. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189434. {
  189435. }
  189436. static void convertInt16ToFloat (const char* src,
  189437. float* dest,
  189438. const int srcStrideBytes,
  189439. int numSamples,
  189440. const bool littleEndian) throw()
  189441. {
  189442. const double g = 1.0 / 32768.0;
  189443. if (littleEndian)
  189444. {
  189445. while (--numSamples >= 0)
  189446. {
  189447. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189448. src += srcStrideBytes;
  189449. }
  189450. }
  189451. else
  189452. {
  189453. while (--numSamples >= 0)
  189454. {
  189455. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189456. src += srcStrideBytes;
  189457. }
  189458. }
  189459. }
  189460. static void convertFloatToInt16 (const float* src,
  189461. char* dest,
  189462. const int dstStrideBytes,
  189463. int numSamples,
  189464. const bool littleEndian) throw()
  189465. {
  189466. const double maxVal = (double) 0x7fff;
  189467. if (littleEndian)
  189468. {
  189469. while (--numSamples >= 0)
  189470. {
  189471. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189472. dest += dstStrideBytes;
  189473. }
  189474. }
  189475. else
  189476. {
  189477. while (--numSamples >= 0)
  189478. {
  189479. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189480. dest += dstStrideBytes;
  189481. }
  189482. }
  189483. }
  189484. static void convertInt24ToFloat (const char* src,
  189485. float* dest,
  189486. const int srcStrideBytes,
  189487. int numSamples,
  189488. const bool littleEndian) throw()
  189489. {
  189490. const double g = 1.0 / 0x7fffff;
  189491. if (littleEndian)
  189492. {
  189493. while (--numSamples >= 0)
  189494. {
  189495. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  189496. src += srcStrideBytes;
  189497. }
  189498. }
  189499. else
  189500. {
  189501. while (--numSamples >= 0)
  189502. {
  189503. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  189504. src += srcStrideBytes;
  189505. }
  189506. }
  189507. }
  189508. static void convertFloatToInt24 (const float* src,
  189509. char* dest,
  189510. const int dstStrideBytes,
  189511. int numSamples,
  189512. const bool littleEndian) throw()
  189513. {
  189514. const double maxVal = (double) 0x7fffff;
  189515. if (littleEndian)
  189516. {
  189517. while (--numSamples >= 0)
  189518. {
  189519. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189520. dest += dstStrideBytes;
  189521. }
  189522. }
  189523. else
  189524. {
  189525. while (--numSamples >= 0)
  189526. {
  189527. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189528. dest += dstStrideBytes;
  189529. }
  189530. }
  189531. }
  189532. static void convertInt32ToFloat (const char* src,
  189533. float* dest,
  189534. const int srcStrideBytes,
  189535. int numSamples,
  189536. const bool littleEndian) throw()
  189537. {
  189538. const double g = 1.0 / 0x7fffffff;
  189539. if (littleEndian)
  189540. {
  189541. while (--numSamples >= 0)
  189542. {
  189543. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  189544. src += srcStrideBytes;
  189545. }
  189546. }
  189547. else
  189548. {
  189549. while (--numSamples >= 0)
  189550. {
  189551. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  189552. src += srcStrideBytes;
  189553. }
  189554. }
  189555. }
  189556. static void convertFloatToInt32 (const float* src,
  189557. char* dest,
  189558. const int dstStrideBytes,
  189559. int numSamples,
  189560. const bool littleEndian) throw()
  189561. {
  189562. const double maxVal = (double) 0x7fffffff;
  189563. if (littleEndian)
  189564. {
  189565. while (--numSamples >= 0)
  189566. {
  189567. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189568. dest += dstStrideBytes;
  189569. }
  189570. }
  189571. else
  189572. {
  189573. while (--numSamples >= 0)
  189574. {
  189575. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189576. dest += dstStrideBytes;
  189577. }
  189578. }
  189579. }
  189580. static void typeToFormatParameters (const long type,
  189581. int& bitDepth,
  189582. int& byteStride,
  189583. bool& formatIsFloat,
  189584. bool& littleEndian) throw()
  189585. {
  189586. bitDepth = 0;
  189587. littleEndian = false;
  189588. formatIsFloat = false;
  189589. switch (type)
  189590. {
  189591. case ASIOSTInt16MSB:
  189592. case ASIOSTInt16LSB:
  189593. case ASIOSTInt32MSB16:
  189594. case ASIOSTInt32LSB16:
  189595. bitDepth = 16; break;
  189596. case ASIOSTFloat32MSB:
  189597. case ASIOSTFloat32LSB:
  189598. formatIsFloat = true;
  189599. bitDepth = 32; break;
  189600. case ASIOSTInt32MSB:
  189601. case ASIOSTInt32LSB:
  189602. bitDepth = 32; break;
  189603. case ASIOSTInt24MSB:
  189604. case ASIOSTInt24LSB:
  189605. case ASIOSTInt32MSB24:
  189606. case ASIOSTInt32LSB24:
  189607. case ASIOSTInt32MSB18:
  189608. case ASIOSTInt32MSB20:
  189609. case ASIOSTInt32LSB18:
  189610. case ASIOSTInt32LSB20:
  189611. bitDepth = 24; break;
  189612. case ASIOSTFloat64MSB:
  189613. case ASIOSTFloat64LSB:
  189614. default:
  189615. bitDepth = 64;
  189616. break;
  189617. }
  189618. switch (type)
  189619. {
  189620. case ASIOSTInt16MSB:
  189621. case ASIOSTInt32MSB16:
  189622. case ASIOSTFloat32MSB:
  189623. case ASIOSTFloat64MSB:
  189624. case ASIOSTInt32MSB:
  189625. case ASIOSTInt32MSB18:
  189626. case ASIOSTInt32MSB20:
  189627. case ASIOSTInt32MSB24:
  189628. case ASIOSTInt24MSB:
  189629. littleEndian = false; break;
  189630. case ASIOSTInt16LSB:
  189631. case ASIOSTInt32LSB16:
  189632. case ASIOSTFloat32LSB:
  189633. case ASIOSTFloat64LSB:
  189634. case ASIOSTInt32LSB:
  189635. case ASIOSTInt32LSB18:
  189636. case ASIOSTInt32LSB20:
  189637. case ASIOSTInt32LSB24:
  189638. case ASIOSTInt24LSB:
  189639. littleEndian = true; break;
  189640. default:
  189641. break;
  189642. }
  189643. switch (type)
  189644. {
  189645. case ASIOSTInt16LSB:
  189646. case ASIOSTInt16MSB:
  189647. byteStride = 2; break;
  189648. case ASIOSTInt24LSB:
  189649. case ASIOSTInt24MSB:
  189650. byteStride = 3; break;
  189651. case ASIOSTInt32MSB16:
  189652. case ASIOSTInt32LSB16:
  189653. case ASIOSTInt32MSB:
  189654. case ASIOSTInt32MSB18:
  189655. case ASIOSTInt32MSB20:
  189656. case ASIOSTInt32MSB24:
  189657. case ASIOSTInt32LSB:
  189658. case ASIOSTInt32LSB18:
  189659. case ASIOSTInt32LSB20:
  189660. case ASIOSTInt32LSB24:
  189661. case ASIOSTFloat32LSB:
  189662. case ASIOSTFloat32MSB:
  189663. byteStride = 4; break;
  189664. case ASIOSTFloat64MSB:
  189665. case ASIOSTFloat64LSB:
  189666. byteStride = 8; break;
  189667. default:
  189668. break;
  189669. }
  189670. }
  189671. };
  189672. class ASIOAudioIODeviceType : public AudioIODeviceType
  189673. {
  189674. public:
  189675. ASIOAudioIODeviceType()
  189676. : AudioIODeviceType (T("ASIO")),
  189677. hasScanned (false)
  189678. {
  189679. CoInitialize (0);
  189680. }
  189681. ~ASIOAudioIODeviceType()
  189682. {
  189683. }
  189684. void scanForDevices()
  189685. {
  189686. hasScanned = true;
  189687. deviceNames.clear();
  189688. classIds.clear();
  189689. HKEY hk = 0;
  189690. int index = 0;
  189691. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  189692. {
  189693. for (;;)
  189694. {
  189695. char name [256];
  189696. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  189697. {
  189698. addDriverInfo (name, hk);
  189699. }
  189700. else
  189701. {
  189702. break;
  189703. }
  189704. }
  189705. RegCloseKey (hk);
  189706. }
  189707. }
  189708. const StringArray getDeviceNames (const bool /*wantInputNames*/) const
  189709. {
  189710. jassert (hasScanned); // need to call scanForDevices() before doing this
  189711. return deviceNames;
  189712. }
  189713. int getDefaultDeviceIndex (const bool) const
  189714. {
  189715. jassert (hasScanned); // need to call scanForDevices() before doing this
  189716. for (int i = deviceNames.size(); --i >= 0;)
  189717. if (deviceNames[i].containsIgnoreCase (T("asio4all")))
  189718. return i; // asio4all is a safe choice for a default..
  189719. #if JUCE_DEBUG
  189720. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase (T("digidesign")))
  189721. return 1; // (the digi m-box driver crashes the app when you run
  189722. // it in the debugger, which can be a bit annoying)
  189723. #endif
  189724. return 0;
  189725. }
  189726. static int findFreeSlot()
  189727. {
  189728. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  189729. if (currentASIODev[i] == 0)
  189730. return i;
  189731. jassertfalse; // unfortunately you can only have a finite number
  189732. // of ASIO devices open at the same time..
  189733. return -1;
  189734. }
  189735. int getIndexOfDevice (AudioIODevice* d, const bool /*asInput*/) const
  189736. {
  189737. jassert (hasScanned); // need to call scanForDevices() before doing this
  189738. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  189739. }
  189740. bool hasSeparateInputsAndOutputs() const { return false; }
  189741. AudioIODevice* createDevice (const String& outputDeviceName,
  189742. const String& inputDeviceName)
  189743. {
  189744. // ASIO can't open two different devices for input and output - they must be the same one.
  189745. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  189746. jassert (hasScanned); // need to call scanForDevices() before doing this
  189747. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  189748. : inputDeviceName);
  189749. if (index >= 0)
  189750. {
  189751. const int freeSlot = findFreeSlot();
  189752. if (freeSlot >= 0)
  189753. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  189754. }
  189755. return 0;
  189756. }
  189757. juce_UseDebuggingNewOperator
  189758. private:
  189759. StringArray deviceNames;
  189760. OwnedArray <CLSID> classIds;
  189761. bool hasScanned;
  189762. static bool checkClassIsOk (const String& classId)
  189763. {
  189764. HKEY hk = 0;
  189765. bool ok = false;
  189766. if (RegOpenKey (HKEY_CLASSES_ROOT, _T("clsid"), &hk) == ERROR_SUCCESS)
  189767. {
  189768. int index = 0;
  189769. for (;;)
  189770. {
  189771. WCHAR buf [512];
  189772. if (RegEnumKey (hk, index++, buf, 512) == ERROR_SUCCESS)
  189773. {
  189774. if (classId.equalsIgnoreCase (buf))
  189775. {
  189776. HKEY subKey, pathKey;
  189777. if (RegOpenKeyEx (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189778. {
  189779. if (RegOpenKeyEx (subKey, _T("InprocServer32"), 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  189780. {
  189781. WCHAR pathName [1024];
  189782. DWORD dtype = REG_SZ;
  189783. DWORD dsize = sizeof (pathName);
  189784. if (RegQueryValueEx (pathKey, 0, 0, &dtype, (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  189785. ok = File (pathName).exists();
  189786. RegCloseKey (pathKey);
  189787. }
  189788. RegCloseKey (subKey);
  189789. }
  189790. break;
  189791. }
  189792. }
  189793. else
  189794. {
  189795. break;
  189796. }
  189797. }
  189798. RegCloseKey (hk);
  189799. }
  189800. return ok;
  189801. }
  189802. void addDriverInfo (const String& keyName, HKEY hk)
  189803. {
  189804. HKEY subKey;
  189805. if (RegOpenKeyEx (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189806. {
  189807. WCHAR buf [256];
  189808. zerostruct (buf);
  189809. DWORD dtype = REG_SZ;
  189810. DWORD dsize = sizeof (buf);
  189811. if (RegQueryValueEx (subKey, _T("clsid"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189812. {
  189813. if (dsize > 0 && checkClassIsOk (buf))
  189814. {
  189815. CLSID classId;
  189816. if (CLSIDFromString ((LPOLESTR) buf, &classId) == S_OK)
  189817. {
  189818. dtype = REG_SZ;
  189819. dsize = sizeof (buf);
  189820. String deviceName;
  189821. if (RegQueryValueEx (subKey, _T("description"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189822. deviceName = buf;
  189823. else
  189824. deviceName = keyName;
  189825. log (T("found ") + deviceName);
  189826. deviceNames.add (deviceName);
  189827. classIds.add (new CLSID (classId));
  189828. }
  189829. }
  189830. RegCloseKey (subKey);
  189831. }
  189832. }
  189833. }
  189834. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  189835. ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  189836. };
  189837. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  189838. {
  189839. return new ASIOAudioIODeviceType();
  189840. }
  189841. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  189842. void* guid,
  189843. const String& optionalDllForDirectLoading)
  189844. {
  189845. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  189846. if (freeSlot < 0)
  189847. return 0;
  189848. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  189849. }
  189850. #undef log
  189851. #endif
  189852. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  189853. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  189854. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  189855. // compiled on its own).
  189856. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  189857. END_JUCE_NAMESPACE
  189858. extern "C"
  189859. {
  189860. // Declare just the minimum number of interfaces for the DSound objects that we need..
  189861. typedef struct typeDSBUFFERDESC
  189862. {
  189863. DWORD dwSize;
  189864. DWORD dwFlags;
  189865. DWORD dwBufferBytes;
  189866. DWORD dwReserved;
  189867. LPWAVEFORMATEX lpwfxFormat;
  189868. GUID guid3DAlgorithm;
  189869. } DSBUFFERDESC;
  189870. struct IDirectSoundBuffer;
  189871. #undef INTERFACE
  189872. #define INTERFACE IDirectSound
  189873. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  189874. {
  189875. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189876. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189877. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189878. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  189879. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189880. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  189881. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  189882. STDMETHOD(Compact) (THIS) PURE;
  189883. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  189884. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  189885. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189886. };
  189887. #undef INTERFACE
  189888. #define INTERFACE IDirectSoundBuffer
  189889. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  189890. {
  189891. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189892. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189893. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189894. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189895. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189896. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189897. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  189898. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  189899. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  189900. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189901. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  189902. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189903. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  189904. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  189905. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  189906. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  189907. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  189908. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  189909. STDMETHOD(Stop) (THIS) PURE;
  189910. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189911. STDMETHOD(Restore) (THIS) PURE;
  189912. };
  189913. typedef struct typeDSCBUFFERDESC
  189914. {
  189915. DWORD dwSize;
  189916. DWORD dwFlags;
  189917. DWORD dwBufferBytes;
  189918. DWORD dwReserved;
  189919. LPWAVEFORMATEX lpwfxFormat;
  189920. } DSCBUFFERDESC;
  189921. struct IDirectSoundCaptureBuffer;
  189922. #undef INTERFACE
  189923. #define INTERFACE IDirectSoundCapture
  189924. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  189925. {
  189926. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189927. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189928. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189929. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  189930. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189931. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189932. };
  189933. #undef INTERFACE
  189934. #define INTERFACE IDirectSoundCaptureBuffer
  189935. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  189936. {
  189937. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189938. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189939. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189940. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189941. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189942. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189943. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189944. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  189945. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189946. STDMETHOD(Start) (THIS_ DWORD) PURE;
  189947. STDMETHOD(Stop) (THIS) PURE;
  189948. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189949. };
  189950. };
  189951. BEGIN_JUCE_NAMESPACE
  189952. static const String getDSErrorMessage (HRESULT hr)
  189953. {
  189954. const char* result = 0;
  189955. switch (hr)
  189956. {
  189957. case MAKE_HRESULT(1, 0x878, 10):
  189958. result = "Device already allocated";
  189959. break;
  189960. case MAKE_HRESULT(1, 0x878, 30):
  189961. result = "Control unavailable";
  189962. break;
  189963. case E_INVALIDARG:
  189964. result = "Invalid parameter";
  189965. break;
  189966. case MAKE_HRESULT(1, 0x878, 50):
  189967. result = "Invalid call";
  189968. break;
  189969. case E_FAIL:
  189970. result = "Generic error";
  189971. break;
  189972. case MAKE_HRESULT(1, 0x878, 70):
  189973. result = "Priority level error";
  189974. break;
  189975. case E_OUTOFMEMORY:
  189976. result = "Out of memory";
  189977. break;
  189978. case MAKE_HRESULT(1, 0x878, 100):
  189979. result = "Bad format";
  189980. break;
  189981. case E_NOTIMPL:
  189982. result = "Unsupported function";
  189983. break;
  189984. case MAKE_HRESULT(1, 0x878, 120):
  189985. result = "No driver";
  189986. break;
  189987. case MAKE_HRESULT(1, 0x878, 130):
  189988. result = "Already initialised";
  189989. break;
  189990. case CLASS_E_NOAGGREGATION:
  189991. result = "No aggregation";
  189992. break;
  189993. case MAKE_HRESULT(1, 0x878, 150):
  189994. result = "Buffer lost";
  189995. break;
  189996. case MAKE_HRESULT(1, 0x878, 160):
  189997. result = "Another app has priority";
  189998. break;
  189999. case MAKE_HRESULT(1, 0x878, 170):
  190000. result = "Uninitialised";
  190001. break;
  190002. case E_NOINTERFACE:
  190003. result = "No interface";
  190004. break;
  190005. case S_OK:
  190006. result = "No error";
  190007. break;
  190008. default:
  190009. return "Unknown error: " + String ((int) hr);
  190010. }
  190011. return result;
  190012. }
  190013. #define DS_DEBUGGING 1
  190014. #ifdef DS_DEBUGGING
  190015. #define CATCH JUCE_CATCH_EXCEPTION
  190016. #undef log
  190017. #define log(a) Logger::writeToLog(a);
  190018. #undef logError
  190019. #define logError(a) logDSError(a, __LINE__);
  190020. static void logDSError (HRESULT hr, int lineNum)
  190021. {
  190022. if (hr != S_OK)
  190023. {
  190024. String error ("DS error at line ");
  190025. error << lineNum << T(" - ") << getDSErrorMessage (hr);
  190026. log (error);
  190027. }
  190028. }
  190029. #else
  190030. #define CATCH JUCE_CATCH_ALL
  190031. #define log(a)
  190032. #define logError(a)
  190033. #endif
  190034. #define DSOUND_FUNCTION(functionName, params) \
  190035. typedef HRESULT (WINAPI *type##functionName) params; \
  190036. static type##functionName ds##functionName = 0;
  190037. #define DSOUND_FUNCTION_LOAD(functionName) \
  190038. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  190039. jassert (ds##functionName != 0);
  190040. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  190041. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  190042. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  190043. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  190044. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190045. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190046. static void initialiseDSoundFunctions()
  190047. {
  190048. if (dsDirectSoundCreate == 0)
  190049. {
  190050. HMODULE h = LoadLibraryA ("dsound.dll");
  190051. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  190052. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  190053. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  190054. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  190055. }
  190056. }
  190057. class DSoundInternalOutChannel
  190058. {
  190059. String name;
  190060. LPGUID guid;
  190061. int sampleRate, bufferSizeSamples;
  190062. float* leftBuffer;
  190063. float* rightBuffer;
  190064. IDirectSound* pDirectSound;
  190065. IDirectSoundBuffer* pOutputBuffer;
  190066. DWORD writeOffset;
  190067. int totalBytesPerBuffer;
  190068. int bytesPerBuffer;
  190069. unsigned int lastPlayCursor;
  190070. public:
  190071. int bitDepth;
  190072. bool doneFlag;
  190073. DSoundInternalOutChannel (const String& name_,
  190074. LPGUID guid_,
  190075. int rate,
  190076. int bufferSize,
  190077. float* left,
  190078. float* right)
  190079. : name (name_),
  190080. guid (guid_),
  190081. sampleRate (rate),
  190082. bufferSizeSamples (bufferSize),
  190083. leftBuffer (left),
  190084. rightBuffer (right),
  190085. pDirectSound (0),
  190086. pOutputBuffer (0),
  190087. bitDepth (16)
  190088. {
  190089. }
  190090. ~DSoundInternalOutChannel()
  190091. {
  190092. close();
  190093. }
  190094. void close()
  190095. {
  190096. HRESULT hr;
  190097. if (pOutputBuffer != 0)
  190098. {
  190099. JUCE_TRY
  190100. {
  190101. log (T("closing dsound out: ") + name);
  190102. hr = pOutputBuffer->Stop();
  190103. logError (hr);
  190104. }
  190105. CATCH
  190106. JUCE_TRY
  190107. {
  190108. hr = pOutputBuffer->Release();
  190109. logError (hr);
  190110. }
  190111. CATCH
  190112. pOutputBuffer = 0;
  190113. }
  190114. if (pDirectSound != 0)
  190115. {
  190116. JUCE_TRY
  190117. {
  190118. hr = pDirectSound->Release();
  190119. logError (hr);
  190120. }
  190121. CATCH
  190122. pDirectSound = 0;
  190123. }
  190124. }
  190125. const String open()
  190126. {
  190127. log (T("opening dsound out device: ") + name
  190128. + T(" rate=") + String (sampleRate)
  190129. + T(" bits=") + String (bitDepth)
  190130. + T(" buf=") + String (bufferSizeSamples));
  190131. pDirectSound = 0;
  190132. pOutputBuffer = 0;
  190133. writeOffset = 0;
  190134. String error;
  190135. HRESULT hr = E_NOINTERFACE;
  190136. if (dsDirectSoundCreate != 0)
  190137. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  190138. if (hr == S_OK)
  190139. {
  190140. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190141. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190142. const int numChannels = 2;
  190143. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  190144. logError (hr);
  190145. if (hr == S_OK)
  190146. {
  190147. IDirectSoundBuffer* pPrimaryBuffer;
  190148. DSBUFFERDESC primaryDesc;
  190149. zerostruct (primaryDesc);
  190150. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190151. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  190152. primaryDesc.dwBufferBytes = 0;
  190153. primaryDesc.lpwfxFormat = 0;
  190154. log ("opening dsound out step 2");
  190155. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  190156. logError (hr);
  190157. if (hr == S_OK)
  190158. {
  190159. WAVEFORMATEX wfFormat;
  190160. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190161. wfFormat.nChannels = (unsigned short) numChannels;
  190162. wfFormat.nSamplesPerSec = sampleRate;
  190163. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  190164. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  190165. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190166. wfFormat.cbSize = 0;
  190167. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  190168. logError (hr);
  190169. if (hr == S_OK)
  190170. {
  190171. DSBUFFERDESC secondaryDesc;
  190172. zerostruct (secondaryDesc);
  190173. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190174. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  190175. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  190176. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  190177. secondaryDesc.lpwfxFormat = &wfFormat;
  190178. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  190179. logError (hr);
  190180. if (hr == S_OK)
  190181. {
  190182. log ("opening dsound out step 3");
  190183. DWORD dwDataLen;
  190184. unsigned char* pDSBuffData;
  190185. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  190186. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  190187. logError (hr);
  190188. if (hr == S_OK)
  190189. {
  190190. zeromem (pDSBuffData, dwDataLen);
  190191. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  190192. if (hr == S_OK)
  190193. {
  190194. hr = pOutputBuffer->SetCurrentPosition (0);
  190195. if (hr == S_OK)
  190196. {
  190197. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  190198. if (hr == S_OK)
  190199. return String::empty;
  190200. }
  190201. }
  190202. }
  190203. }
  190204. }
  190205. }
  190206. }
  190207. }
  190208. error = getDSErrorMessage (hr);
  190209. close();
  190210. return error;
  190211. }
  190212. void synchronisePosition()
  190213. {
  190214. if (pOutputBuffer != 0)
  190215. {
  190216. DWORD playCursor;
  190217. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  190218. }
  190219. }
  190220. bool service()
  190221. {
  190222. if (pOutputBuffer == 0)
  190223. return true;
  190224. DWORD playCursor, writeCursor;
  190225. for (;;)
  190226. {
  190227. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  190228. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190229. {
  190230. pOutputBuffer->Restore();
  190231. continue;
  190232. }
  190233. if (hr == S_OK)
  190234. break;
  190235. logError (hr);
  190236. jassertfalse
  190237. return true;
  190238. }
  190239. int playWriteGap = writeCursor - playCursor;
  190240. if (playWriteGap < 0)
  190241. playWriteGap += totalBytesPerBuffer;
  190242. int bytesEmpty = playCursor - writeOffset;
  190243. if (bytesEmpty < 0)
  190244. bytesEmpty += totalBytesPerBuffer;
  190245. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  190246. {
  190247. writeOffset = writeCursor;
  190248. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  190249. }
  190250. if (bytesEmpty >= bytesPerBuffer)
  190251. {
  190252. LPBYTE lpbuf1 = 0;
  190253. LPBYTE lpbuf2 = 0;
  190254. DWORD dwSize1 = 0;
  190255. DWORD dwSize2 = 0;
  190256. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  190257. bytesPerBuffer,
  190258. (void**) &lpbuf1, &dwSize1,
  190259. (void**) &lpbuf2, &dwSize2, 0);
  190260. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190261. {
  190262. pOutputBuffer->Restore();
  190263. hr = pOutputBuffer->Lock (writeOffset,
  190264. bytesPerBuffer,
  190265. (void**) &lpbuf1, &dwSize1,
  190266. (void**) &lpbuf2, &dwSize2, 0);
  190267. }
  190268. if (hr == S_OK)
  190269. {
  190270. if (bitDepth == 16)
  190271. {
  190272. const float gainL = 32767.0f;
  190273. const float gainR = 32767.0f;
  190274. int* dest = (int*)lpbuf1;
  190275. const float* left = leftBuffer;
  190276. const float* right = rightBuffer;
  190277. int samples1 = dwSize1 >> 2;
  190278. int samples2 = dwSize2 >> 2;
  190279. if (left == 0)
  190280. {
  190281. while (--samples1 >= 0)
  190282. {
  190283. int r = roundToInt (gainR * *right++);
  190284. if (r < -32768)
  190285. r = -32768;
  190286. else if (r > 32767)
  190287. r = 32767;
  190288. *dest++ = (r << 16);
  190289. }
  190290. dest = (int*)lpbuf2;
  190291. while (--samples2 >= 0)
  190292. {
  190293. int r = roundToInt (gainR * *right++);
  190294. if (r < -32768)
  190295. r = -32768;
  190296. else if (r > 32767)
  190297. r = 32767;
  190298. *dest++ = (r << 16);
  190299. }
  190300. }
  190301. else if (right == 0)
  190302. {
  190303. while (--samples1 >= 0)
  190304. {
  190305. int l = roundToInt (gainL * *left++);
  190306. if (l < -32768)
  190307. l = -32768;
  190308. else if (l > 32767)
  190309. l = 32767;
  190310. l &= 0xffff;
  190311. *dest++ = l;
  190312. }
  190313. dest = (int*)lpbuf2;
  190314. while (--samples2 >= 0)
  190315. {
  190316. int l = roundToInt (gainL * *left++);
  190317. if (l < -32768)
  190318. l = -32768;
  190319. else if (l > 32767)
  190320. l = 32767;
  190321. l &= 0xffff;
  190322. *dest++ = l;
  190323. }
  190324. }
  190325. else
  190326. {
  190327. while (--samples1 >= 0)
  190328. {
  190329. int l = roundToInt (gainL * *left++);
  190330. if (l < -32768)
  190331. l = -32768;
  190332. else if (l > 32767)
  190333. l = 32767;
  190334. l &= 0xffff;
  190335. int r = roundToInt (gainR * *right++);
  190336. if (r < -32768)
  190337. r = -32768;
  190338. else if (r > 32767)
  190339. r = 32767;
  190340. *dest++ = (r << 16) | l;
  190341. }
  190342. dest = (int*)lpbuf2;
  190343. while (--samples2 >= 0)
  190344. {
  190345. int l = roundToInt (gainL * *left++);
  190346. if (l < -32768)
  190347. l = -32768;
  190348. else if (l > 32767)
  190349. l = 32767;
  190350. l &= 0xffff;
  190351. int r = roundToInt (gainR * *right++);
  190352. if (r < -32768)
  190353. r = -32768;
  190354. else if (r > 32767)
  190355. r = 32767;
  190356. *dest++ = (r << 16) | l;
  190357. }
  190358. }
  190359. }
  190360. else
  190361. {
  190362. jassertfalse
  190363. }
  190364. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190365. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190366. }
  190367. else
  190368. {
  190369. jassertfalse
  190370. logError (hr);
  190371. }
  190372. bytesEmpty -= bytesPerBuffer;
  190373. return true;
  190374. }
  190375. else
  190376. {
  190377. return false;
  190378. }
  190379. }
  190380. };
  190381. struct DSoundInternalInChannel
  190382. {
  190383. String name;
  190384. LPGUID guid;
  190385. int sampleRate, bufferSizeSamples;
  190386. float* leftBuffer;
  190387. float* rightBuffer;
  190388. IDirectSound* pDirectSound;
  190389. IDirectSoundCapture* pDirectSoundCapture;
  190390. IDirectSoundCaptureBuffer* pInputBuffer;
  190391. public:
  190392. unsigned int readOffset;
  190393. int bytesPerBuffer, totalBytesPerBuffer;
  190394. int bitDepth;
  190395. bool doneFlag;
  190396. DSoundInternalInChannel (const String& name_,
  190397. LPGUID guid_,
  190398. int rate,
  190399. int bufferSize,
  190400. float* left,
  190401. float* right)
  190402. : name (name_),
  190403. guid (guid_),
  190404. sampleRate (rate),
  190405. bufferSizeSamples (bufferSize),
  190406. leftBuffer (left),
  190407. rightBuffer (right),
  190408. pDirectSound (0),
  190409. pDirectSoundCapture (0),
  190410. pInputBuffer (0),
  190411. bitDepth (16)
  190412. {
  190413. }
  190414. ~DSoundInternalInChannel()
  190415. {
  190416. close();
  190417. }
  190418. void close()
  190419. {
  190420. HRESULT hr;
  190421. if (pInputBuffer != 0)
  190422. {
  190423. JUCE_TRY
  190424. {
  190425. log (T("closing dsound in: ") + name);
  190426. hr = pInputBuffer->Stop();
  190427. logError (hr);
  190428. }
  190429. CATCH
  190430. JUCE_TRY
  190431. {
  190432. hr = pInputBuffer->Release();
  190433. logError (hr);
  190434. }
  190435. CATCH
  190436. pInputBuffer = 0;
  190437. }
  190438. if (pDirectSoundCapture != 0)
  190439. {
  190440. JUCE_TRY
  190441. {
  190442. hr = pDirectSoundCapture->Release();
  190443. logError (hr);
  190444. }
  190445. CATCH
  190446. pDirectSoundCapture = 0;
  190447. }
  190448. if (pDirectSound != 0)
  190449. {
  190450. JUCE_TRY
  190451. {
  190452. hr = pDirectSound->Release();
  190453. logError (hr);
  190454. }
  190455. CATCH
  190456. pDirectSound = 0;
  190457. }
  190458. }
  190459. const String open()
  190460. {
  190461. log (T("opening dsound in device: ") + name
  190462. + T(" rate=") + String (sampleRate) + T(" bits=") + String (bitDepth) + T(" buf=") + String (bufferSizeSamples));
  190463. pDirectSound = 0;
  190464. pDirectSoundCapture = 0;
  190465. pInputBuffer = 0;
  190466. readOffset = 0;
  190467. totalBytesPerBuffer = 0;
  190468. String error;
  190469. HRESULT hr = E_NOINTERFACE;
  190470. if (dsDirectSoundCaptureCreate != 0)
  190471. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190472. logError (hr);
  190473. if (hr == S_OK)
  190474. {
  190475. const int numChannels = 2;
  190476. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190477. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190478. WAVEFORMATEX wfFormat;
  190479. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190480. wfFormat.nChannels = (unsigned short)numChannels;
  190481. wfFormat.nSamplesPerSec = sampleRate;
  190482. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190483. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  190484. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190485. wfFormat.cbSize = 0;
  190486. DSCBUFFERDESC captureDesc;
  190487. zerostruct (captureDesc);
  190488. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  190489. captureDesc.dwFlags = 0;
  190490. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  190491. captureDesc.lpwfxFormat = &wfFormat;
  190492. log (T("opening dsound in step 2"));
  190493. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  190494. logError (hr);
  190495. if (hr == S_OK)
  190496. {
  190497. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  190498. logError (hr);
  190499. if (hr == S_OK)
  190500. return String::empty;
  190501. }
  190502. }
  190503. error = getDSErrorMessage (hr);
  190504. close();
  190505. return error;
  190506. }
  190507. void synchronisePosition()
  190508. {
  190509. if (pInputBuffer != 0)
  190510. {
  190511. DWORD capturePos;
  190512. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  190513. }
  190514. }
  190515. bool service()
  190516. {
  190517. if (pInputBuffer == 0)
  190518. return true;
  190519. DWORD capturePos, readPos;
  190520. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  190521. logError (hr);
  190522. if (hr != S_OK)
  190523. return true;
  190524. int bytesFilled = readPos - readOffset;
  190525. if (bytesFilled < 0)
  190526. bytesFilled += totalBytesPerBuffer;
  190527. if (bytesFilled >= bytesPerBuffer)
  190528. {
  190529. LPBYTE lpbuf1 = 0;
  190530. LPBYTE lpbuf2 = 0;
  190531. DWORD dwsize1 = 0;
  190532. DWORD dwsize2 = 0;
  190533. HRESULT hr = pInputBuffer->Lock (readOffset,
  190534. bytesPerBuffer,
  190535. (void**) &lpbuf1, &dwsize1,
  190536. (void**) &lpbuf2, &dwsize2, 0);
  190537. if (hr == S_OK)
  190538. {
  190539. if (bitDepth == 16)
  190540. {
  190541. const float g = 1.0f / 32768.0f;
  190542. float* destL = leftBuffer;
  190543. float* destR = rightBuffer;
  190544. int samples1 = dwsize1 >> 2;
  190545. int samples2 = dwsize2 >> 2;
  190546. const short* src = (const short*)lpbuf1;
  190547. if (destL == 0)
  190548. {
  190549. while (--samples1 >= 0)
  190550. {
  190551. ++src;
  190552. *destR++ = *src++ * g;
  190553. }
  190554. src = (const short*)lpbuf2;
  190555. while (--samples2 >= 0)
  190556. {
  190557. ++src;
  190558. *destR++ = *src++ * g;
  190559. }
  190560. }
  190561. else if (destR == 0)
  190562. {
  190563. while (--samples1 >= 0)
  190564. {
  190565. *destL++ = *src++ * g;
  190566. ++src;
  190567. }
  190568. src = (const short*)lpbuf2;
  190569. while (--samples2 >= 0)
  190570. {
  190571. *destL++ = *src++ * g;
  190572. ++src;
  190573. }
  190574. }
  190575. else
  190576. {
  190577. while (--samples1 >= 0)
  190578. {
  190579. *destL++ = *src++ * g;
  190580. *destR++ = *src++ * g;
  190581. }
  190582. src = (const short*)lpbuf2;
  190583. while (--samples2 >= 0)
  190584. {
  190585. *destL++ = *src++ * g;
  190586. *destR++ = *src++ * g;
  190587. }
  190588. }
  190589. }
  190590. else
  190591. {
  190592. jassertfalse
  190593. }
  190594. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  190595. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  190596. }
  190597. else
  190598. {
  190599. logError (hr);
  190600. jassertfalse
  190601. }
  190602. bytesFilled -= bytesPerBuffer;
  190603. return true;
  190604. }
  190605. else
  190606. {
  190607. return false;
  190608. }
  190609. }
  190610. };
  190611. class DSoundAudioIODevice : public AudioIODevice,
  190612. public Thread
  190613. {
  190614. public:
  190615. DSoundAudioIODevice (const String& deviceName,
  190616. const int outputDeviceIndex_,
  190617. const int inputDeviceIndex_)
  190618. : AudioIODevice (deviceName, "DirectSound"),
  190619. Thread ("Juce DSound"),
  190620. isOpen_ (false),
  190621. isStarted (false),
  190622. outputDeviceIndex (outputDeviceIndex_),
  190623. inputDeviceIndex (inputDeviceIndex_),
  190624. numInputBuffers (0),
  190625. numOutputBuffers (0),
  190626. totalSamplesOut (0),
  190627. sampleRate (0.0),
  190628. inputBuffers (0),
  190629. outputBuffers (0),
  190630. callback (0),
  190631. bufferSizeSamples (0)
  190632. {
  190633. if (outputDeviceIndex_ >= 0)
  190634. {
  190635. outChannels.add (TRANS("Left"));
  190636. outChannels.add (TRANS("Right"));
  190637. }
  190638. if (inputDeviceIndex_ >= 0)
  190639. {
  190640. inChannels.add (TRANS("Left"));
  190641. inChannels.add (TRANS("Right"));
  190642. }
  190643. }
  190644. ~DSoundAudioIODevice()
  190645. {
  190646. close();
  190647. }
  190648. const StringArray getOutputChannelNames()
  190649. {
  190650. return outChannels;
  190651. }
  190652. const StringArray getInputChannelNames()
  190653. {
  190654. return inChannels;
  190655. }
  190656. int getNumSampleRates()
  190657. {
  190658. return 4;
  190659. }
  190660. double getSampleRate (int index)
  190661. {
  190662. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190663. return samps [jlimit (0, 3, index)];
  190664. }
  190665. int getNumBufferSizesAvailable()
  190666. {
  190667. return 50;
  190668. }
  190669. int getBufferSizeSamples (int index)
  190670. {
  190671. int n = 64;
  190672. for (int i = 0; i < index; ++i)
  190673. n += (n < 512) ? 32
  190674. : ((n < 1024) ? 64
  190675. : ((n < 2048) ? 128 : 256));
  190676. return n;
  190677. }
  190678. int getDefaultBufferSize()
  190679. {
  190680. return 2560;
  190681. }
  190682. const String open (const BitArray& inputChannels,
  190683. const BitArray& outputChannels,
  190684. double sampleRate,
  190685. int bufferSizeSamples)
  190686. {
  190687. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  190688. isOpen_ = lastError.isEmpty();
  190689. return lastError;
  190690. }
  190691. void close()
  190692. {
  190693. stop();
  190694. if (isOpen_)
  190695. {
  190696. closeDevice();
  190697. isOpen_ = false;
  190698. }
  190699. }
  190700. bool isOpen()
  190701. {
  190702. return isOpen_ && isThreadRunning();
  190703. }
  190704. int getCurrentBufferSizeSamples()
  190705. {
  190706. return bufferSizeSamples;
  190707. }
  190708. double getCurrentSampleRate()
  190709. {
  190710. return sampleRate;
  190711. }
  190712. int getCurrentBitDepth()
  190713. {
  190714. int i, bits = 256;
  190715. for (i = inChans.size(); --i >= 0;)
  190716. bits = jmin (bits, inChans[i]->bitDepth);
  190717. for (i = outChans.size(); --i >= 0;)
  190718. bits = jmin (bits, outChans[i]->bitDepth);
  190719. if (bits > 32)
  190720. bits = 16;
  190721. return bits;
  190722. }
  190723. const BitArray getActiveOutputChannels() const
  190724. {
  190725. return enabledOutputs;
  190726. }
  190727. const BitArray getActiveInputChannels() const
  190728. {
  190729. return enabledInputs;
  190730. }
  190731. int getOutputLatencyInSamples()
  190732. {
  190733. return (int) (getCurrentBufferSizeSamples() * 1.5);
  190734. }
  190735. int getInputLatencyInSamples()
  190736. {
  190737. return getOutputLatencyInSamples();
  190738. }
  190739. void start (AudioIODeviceCallback* call)
  190740. {
  190741. if (isOpen_ && call != 0 && ! isStarted)
  190742. {
  190743. if (! isThreadRunning())
  190744. {
  190745. // something gone wrong and the thread's stopped..
  190746. isOpen_ = false;
  190747. return;
  190748. }
  190749. call->audioDeviceAboutToStart (this);
  190750. const ScopedLock sl (startStopLock);
  190751. callback = call;
  190752. isStarted = true;
  190753. }
  190754. }
  190755. void stop()
  190756. {
  190757. if (isStarted)
  190758. {
  190759. AudioIODeviceCallback* const callbackLocal = callback;
  190760. {
  190761. const ScopedLock sl (startStopLock);
  190762. isStarted = false;
  190763. }
  190764. if (callbackLocal != 0)
  190765. callbackLocal->audioDeviceStopped();
  190766. }
  190767. }
  190768. bool isPlaying()
  190769. {
  190770. return isStarted && isOpen_ && isThreadRunning();
  190771. }
  190772. const String getLastError()
  190773. {
  190774. return lastError;
  190775. }
  190776. juce_UseDebuggingNewOperator
  190777. StringArray inChannels, outChannels;
  190778. int outputDeviceIndex, inputDeviceIndex;
  190779. private:
  190780. bool isOpen_;
  190781. bool isStarted;
  190782. String lastError;
  190783. OwnedArray <DSoundInternalInChannel> inChans;
  190784. OwnedArray <DSoundInternalOutChannel> outChans;
  190785. WaitableEvent startEvent;
  190786. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  190787. int volatile totalSamplesOut;
  190788. int64 volatile lastBlockTime;
  190789. double sampleRate;
  190790. BitArray enabledInputs, enabledOutputs;
  190791. HeapBlock <float*> inputBuffers, outputBuffers;
  190792. AudioIODeviceCallback* callback;
  190793. CriticalSection startStopLock;
  190794. DSoundAudioIODevice (const DSoundAudioIODevice&);
  190795. DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  190796. const String openDevice (const BitArray& inputChannels,
  190797. const BitArray& outputChannels,
  190798. double sampleRate_,
  190799. int bufferSizeSamples_);
  190800. void closeDevice()
  190801. {
  190802. isStarted = false;
  190803. stopThread (5000);
  190804. inChans.clear();
  190805. outChans.clear();
  190806. int i;
  190807. for (i = 0; i < numInputBuffers; ++i)
  190808. juce_free (inputBuffers[i]);
  190809. inputBuffers.free();
  190810. numInputBuffers = 0;
  190811. for (i = 0; i < numOutputBuffers; ++i)
  190812. juce_free (outputBuffers[i]);
  190813. outputBuffers.free();
  190814. numOutputBuffers = 0;
  190815. }
  190816. void resync()
  190817. {
  190818. if (! threadShouldExit())
  190819. {
  190820. sleep (5);
  190821. int i;
  190822. for (i = 0; i < outChans.size(); ++i)
  190823. outChans.getUnchecked(i)->synchronisePosition();
  190824. for (i = 0; i < inChans.size(); ++i)
  190825. inChans.getUnchecked(i)->synchronisePosition();
  190826. }
  190827. }
  190828. public:
  190829. void run()
  190830. {
  190831. while (! threadShouldExit())
  190832. {
  190833. if (wait (100))
  190834. break;
  190835. }
  190836. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  190837. const int maxTimeMS = jmax (5, 3 * latencyMs);
  190838. while (! threadShouldExit())
  190839. {
  190840. int numToDo = 0;
  190841. uint32 startTime = Time::getMillisecondCounter();
  190842. int i;
  190843. for (i = inChans.size(); --i >= 0;)
  190844. {
  190845. inChans.getUnchecked(i)->doneFlag = false;
  190846. ++numToDo;
  190847. }
  190848. for (i = outChans.size(); --i >= 0;)
  190849. {
  190850. outChans.getUnchecked(i)->doneFlag = false;
  190851. ++numToDo;
  190852. }
  190853. if (numToDo > 0)
  190854. {
  190855. const int maxCount = 3;
  190856. int count = maxCount;
  190857. for (;;)
  190858. {
  190859. for (i = inChans.size(); --i >= 0;)
  190860. {
  190861. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  190862. if ((! in->doneFlag) && in->service())
  190863. {
  190864. in->doneFlag = true;
  190865. --numToDo;
  190866. }
  190867. }
  190868. for (i = outChans.size(); --i >= 0;)
  190869. {
  190870. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  190871. if ((! out->doneFlag) && out->service())
  190872. {
  190873. out->doneFlag = true;
  190874. --numToDo;
  190875. }
  190876. }
  190877. if (numToDo <= 0)
  190878. break;
  190879. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  190880. {
  190881. resync();
  190882. break;
  190883. }
  190884. if (--count <= 0)
  190885. {
  190886. Sleep (1);
  190887. count = maxCount;
  190888. }
  190889. if (threadShouldExit())
  190890. return;
  190891. }
  190892. }
  190893. else
  190894. {
  190895. sleep (1);
  190896. }
  190897. const ScopedLock sl (startStopLock);
  190898. if (isStarted)
  190899. {
  190900. JUCE_TRY
  190901. {
  190902. callback->audioDeviceIOCallback (const_cast <const float**> (inputBuffers.getData()),
  190903. numInputBuffers,
  190904. outputBuffers,
  190905. numOutputBuffers,
  190906. bufferSizeSamples);
  190907. }
  190908. JUCE_CATCH_EXCEPTION
  190909. totalSamplesOut += bufferSizeSamples;
  190910. }
  190911. else
  190912. {
  190913. for (i = 0; i < numOutputBuffers; ++i)
  190914. if (outputBuffers[i] != 0)
  190915. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  190916. totalSamplesOut = 0;
  190917. sleep (1);
  190918. }
  190919. }
  190920. }
  190921. };
  190922. class DSoundAudioIODeviceType : public AudioIODeviceType
  190923. {
  190924. public:
  190925. DSoundAudioIODeviceType()
  190926. : AudioIODeviceType (T("DirectSound")),
  190927. hasScanned (false)
  190928. {
  190929. initialiseDSoundFunctions();
  190930. }
  190931. ~DSoundAudioIODeviceType()
  190932. {
  190933. }
  190934. void scanForDevices()
  190935. {
  190936. hasScanned = true;
  190937. outputDeviceNames.clear();
  190938. outputGuids.clear();
  190939. inputDeviceNames.clear();
  190940. inputGuids.clear();
  190941. if (dsDirectSoundEnumerateW != 0)
  190942. {
  190943. dsDirectSoundEnumerateW (outputEnumProcW, this);
  190944. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  190945. }
  190946. }
  190947. const StringArray getDeviceNames (const bool wantInputNames) const
  190948. {
  190949. jassert (hasScanned); // need to call scanForDevices() before doing this
  190950. return wantInputNames ? inputDeviceNames
  190951. : outputDeviceNames;
  190952. }
  190953. int getDefaultDeviceIndex (const bool /*forInput*/) const
  190954. {
  190955. jassert (hasScanned); // need to call scanForDevices() before doing this
  190956. return 0;
  190957. }
  190958. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  190959. {
  190960. jassert (hasScanned); // need to call scanForDevices() before doing this
  190961. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  190962. if (d == 0)
  190963. return -1;
  190964. return asInput ? d->inputDeviceIndex
  190965. : d->outputDeviceIndex;
  190966. }
  190967. bool hasSeparateInputsAndOutputs() const { return true; }
  190968. AudioIODevice* createDevice (const String& outputDeviceName,
  190969. const String& inputDeviceName)
  190970. {
  190971. jassert (hasScanned); // need to call scanForDevices() before doing this
  190972. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  190973. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  190974. if (outputIndex >= 0 || inputIndex >= 0)
  190975. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  190976. : inputDeviceName,
  190977. outputIndex, inputIndex);
  190978. return 0;
  190979. }
  190980. juce_UseDebuggingNewOperator
  190981. StringArray outputDeviceNames;
  190982. OwnedArray <GUID> outputGuids;
  190983. StringArray inputDeviceNames;
  190984. OwnedArray <GUID> inputGuids;
  190985. private:
  190986. bool hasScanned;
  190987. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  190988. {
  190989. desc = desc.trim();
  190990. if (desc.isNotEmpty())
  190991. {
  190992. const String origDesc (desc);
  190993. int n = 2;
  190994. while (outputDeviceNames.contains (desc))
  190995. desc = origDesc + T(" (") + String (n++) + T(")");
  190996. outputDeviceNames.add (desc);
  190997. if (lpGUID != 0)
  190998. outputGuids.add (new GUID (*lpGUID));
  190999. else
  191000. outputGuids.add (0);
  191001. }
  191002. return TRUE;
  191003. }
  191004. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191005. {
  191006. return ((DSoundAudioIODeviceType*) object)
  191007. ->outputEnumProc (lpGUID, String (description));
  191008. }
  191009. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191010. {
  191011. return ((DSoundAudioIODeviceType*) object)
  191012. ->outputEnumProc (lpGUID, String (description));
  191013. }
  191014. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  191015. {
  191016. desc = desc.trim();
  191017. if (desc.isNotEmpty())
  191018. {
  191019. const String origDesc (desc);
  191020. int n = 2;
  191021. while (inputDeviceNames.contains (desc))
  191022. desc = origDesc + T(" (") + String (n++) + T(")");
  191023. inputDeviceNames.add (desc);
  191024. if (lpGUID != 0)
  191025. inputGuids.add (new GUID (*lpGUID));
  191026. else
  191027. inputGuids.add (0);
  191028. }
  191029. return TRUE;
  191030. }
  191031. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191032. {
  191033. return ((DSoundAudioIODeviceType*) object)
  191034. ->inputEnumProc (lpGUID, String (description));
  191035. }
  191036. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191037. {
  191038. return ((DSoundAudioIODeviceType*) object)
  191039. ->inputEnumProc (lpGUID, String (description));
  191040. }
  191041. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  191042. DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  191043. };
  191044. const String DSoundAudioIODevice::openDevice (const BitArray& inputChannels,
  191045. const BitArray& outputChannels,
  191046. double sampleRate_,
  191047. int bufferSizeSamples_)
  191048. {
  191049. closeDevice();
  191050. totalSamplesOut = 0;
  191051. sampleRate = sampleRate_;
  191052. if (bufferSizeSamples_ <= 0)
  191053. bufferSizeSamples_ = 960; // use as a default size if none is set.
  191054. bufferSizeSamples = bufferSizeSamples_ & ~7;
  191055. DSoundAudioIODeviceType dlh;
  191056. dlh.scanForDevices();
  191057. enabledInputs = inputChannels;
  191058. enabledInputs.setRange (inChannels.size(),
  191059. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  191060. false);
  191061. numInputBuffers = enabledInputs.countNumberOfSetBits();
  191062. inputBuffers.calloc (numInputBuffers + 2);
  191063. int i, numIns = 0;
  191064. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  191065. {
  191066. float* left = 0;
  191067. float* right = 0;
  191068. if (enabledInputs[i])
  191069. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191070. if (enabledInputs[i + 1])
  191071. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191072. if (left != 0 || right != 0)
  191073. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  191074. dlh.inputGuids [inputDeviceIndex],
  191075. (int) sampleRate, bufferSizeSamples,
  191076. left, right));
  191077. }
  191078. enabledOutputs = outputChannels;
  191079. enabledOutputs.setRange (outChannels.size(),
  191080. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  191081. false);
  191082. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  191083. outputBuffers.calloc (numOutputBuffers + 2);
  191084. int numOuts = 0;
  191085. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  191086. {
  191087. float* left = 0;
  191088. float* right = 0;
  191089. if (enabledOutputs[i])
  191090. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191091. if (enabledOutputs[i + 1])
  191092. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191093. if (left != 0 || right != 0)
  191094. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  191095. dlh.outputGuids [outputDeviceIndex],
  191096. (int) sampleRate, bufferSizeSamples,
  191097. left, right));
  191098. }
  191099. String error;
  191100. // boost our priority while opening the devices to try to get better sync between them
  191101. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  191102. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  191103. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  191104. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  191105. for (i = 0; i < outChans.size(); ++i)
  191106. {
  191107. error = outChans[i]->open();
  191108. if (error.isNotEmpty())
  191109. {
  191110. error = T("Error opening ") + dlh.outputDeviceNames[i]
  191111. + T(": \"") + error + T("\"");
  191112. break;
  191113. }
  191114. }
  191115. if (error.isEmpty())
  191116. {
  191117. for (i = 0; i < inChans.size(); ++i)
  191118. {
  191119. error = inChans[i]->open();
  191120. if (error.isNotEmpty())
  191121. {
  191122. error = T("Error opening ") + dlh.inputDeviceNames[i]
  191123. + T(": \"") + error + T("\"");
  191124. break;
  191125. }
  191126. }
  191127. }
  191128. if (error.isEmpty())
  191129. {
  191130. totalSamplesOut = 0;
  191131. for (i = 0; i < outChans.size(); ++i)
  191132. outChans.getUnchecked(i)->synchronisePosition();
  191133. for (i = 0; i < inChans.size(); ++i)
  191134. inChans.getUnchecked(i)->synchronisePosition();
  191135. startThread (9);
  191136. sleep (10);
  191137. notify();
  191138. }
  191139. else
  191140. {
  191141. log (error);
  191142. }
  191143. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  191144. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  191145. return error;
  191146. }
  191147. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  191148. {
  191149. return new DSoundAudioIODeviceType();
  191150. }
  191151. #undef log
  191152. #endif
  191153. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  191154. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  191155. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191156. // compiled on its own).
  191157. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  191158. #if 1
  191159. const String getAudioErrorDesc (HRESULT hr)
  191160. {
  191161. const char* e = 0;
  191162. switch (hr)
  191163. {
  191164. case E_POINTER: e = "E_POINTER"; break;
  191165. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  191166. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  191167. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  191168. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  191169. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  191170. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  191171. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  191172. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  191173. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  191174. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  191175. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  191176. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  191177. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  191178. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  191179. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  191180. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  191181. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  191182. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  191183. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  191184. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  191185. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  191186. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  191187. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  191188. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  191189. default: return String::toHexString ((int) hr);
  191190. }
  191191. return e;
  191192. }
  191193. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  191194. #define OK(a) wasapi_checkResult(a)
  191195. static bool wasapi_checkResult (HRESULT hr)
  191196. {
  191197. logFailure (hr);
  191198. return SUCCEEDED (hr);
  191199. }
  191200. #else
  191201. #define logFailure(hr) {}
  191202. #define OK(a) SUCCEEDED(a)
  191203. #endif
  191204. static const String wasapi_getDeviceID (IMMDevice* const device)
  191205. {
  191206. String s;
  191207. WCHAR* deviceId = 0;
  191208. if (OK (device->GetId (&deviceId)))
  191209. {
  191210. s = String (deviceId);
  191211. CoTaskMemFree (deviceId);
  191212. }
  191213. return s;
  191214. }
  191215. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  191216. {
  191217. EDataFlow flow = eRender;
  191218. ComSmartPtr <IMMEndpoint> endPoint;
  191219. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  191220. (void) OK (endPoint->GetDataFlow (&flow));
  191221. return flow;
  191222. }
  191223. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  191224. {
  191225. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  191226. }
  191227. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  191228. {
  191229. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  191230. : sizeof (WAVEFORMATEX));
  191231. }
  191232. class WASAPIDeviceBase
  191233. {
  191234. public:
  191235. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191236. : device (device_),
  191237. sampleRate (0),
  191238. numChannels (0),
  191239. actualNumChannels (0),
  191240. defaultSampleRate (0),
  191241. minBufferSize (0),
  191242. defaultBufferSize (0),
  191243. latencySamples (0),
  191244. useExclusiveMode (useExclusiveMode_)
  191245. {
  191246. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  191247. ComSmartPtr <IAudioClient> tempClient (createClient());
  191248. if (tempClient == 0)
  191249. return;
  191250. REFERENCE_TIME defaultPeriod, minPeriod;
  191251. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  191252. return;
  191253. WAVEFORMATEX* mixFormat = 0;
  191254. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  191255. return;
  191256. WAVEFORMATEXTENSIBLE format;
  191257. wasapi_copyWavFormat (format, mixFormat);
  191258. CoTaskMemFree (mixFormat);
  191259. actualNumChannels = numChannels = format.Format.nChannels;
  191260. defaultSampleRate = format.Format.nSamplesPerSec;
  191261. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  191262. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  191263. FloatElementComparator<double> comparator;
  191264. rates.addSorted (comparator, defaultSampleRate);
  191265. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  191266. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  191267. {
  191268. if (ratesToTest[i] == defaultSampleRate)
  191269. continue;
  191270. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  191271. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191272. (WAVEFORMATEX*) &format, 0)))
  191273. if (! rates.contains (ratesToTest[i]))
  191274. rates.addSorted (comparator, ratesToTest[i]);
  191275. }
  191276. }
  191277. ~WASAPIDeviceBase()
  191278. {
  191279. device = 0;
  191280. CloseHandle (clientEvent);
  191281. }
  191282. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  191283. bool openClient (const double newSampleRate, const BitArray& newChannels)
  191284. {
  191285. sampleRate = newSampleRate;
  191286. channels = newChannels;
  191287. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  191288. numChannels = channels.getHighestBit() + 1;
  191289. if (numChannels == 0)
  191290. return true;
  191291. client = createClient();
  191292. if (client != 0
  191293. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  191294. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  191295. {
  191296. channelMaps.clear();
  191297. for (int i = 0; i <= channels.getHighestBit(); ++i)
  191298. if (channels[i])
  191299. channelMaps.add (i);
  191300. REFERENCE_TIME latency;
  191301. if (OK (client->GetStreamLatency (&latency)))
  191302. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  191303. (void) OK (client->GetBufferSize (&actualBufferSize));
  191304. return OK (client->SetEventHandle (clientEvent));
  191305. }
  191306. return false;
  191307. }
  191308. void closeClient()
  191309. {
  191310. if (client != 0)
  191311. client->Stop();
  191312. client = 0;
  191313. ResetEvent (clientEvent);
  191314. }
  191315. ComSmartPtr <IMMDevice> device;
  191316. ComSmartPtr <IAudioClient> client;
  191317. double sampleRate, defaultSampleRate;
  191318. int numChannels, actualNumChannels;
  191319. int minBufferSize, defaultBufferSize, latencySamples;
  191320. const bool useExclusiveMode;
  191321. Array <double> rates;
  191322. HANDLE clientEvent;
  191323. BitArray channels;
  191324. AudioDataConverters::DataFormat dataFormat;
  191325. Array <int> channelMaps;
  191326. UINT32 actualBufferSize;
  191327. int bytesPerSample;
  191328. private:
  191329. const ComSmartPtr <IAudioClient> createClient()
  191330. {
  191331. ComSmartPtr <IAudioClient> client;
  191332. if (device != 0)
  191333. {
  191334. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  191335. logFailure (hr);
  191336. }
  191337. return client;
  191338. }
  191339. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  191340. {
  191341. WAVEFORMATEXTENSIBLE format;
  191342. zerostruct (format);
  191343. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  191344. {
  191345. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  191346. }
  191347. else
  191348. {
  191349. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191350. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191351. }
  191352. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191353. format.Format.nChannels = (WORD) numChannels;
  191354. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191355. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191356. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191357. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191358. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191359. switch (numChannels)
  191360. {
  191361. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191362. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191363. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191364. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191365. 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;
  191366. default: break;
  191367. }
  191368. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191369. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191370. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  191371. logFailure (hr);
  191372. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191373. {
  191374. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191375. hr = S_OK;
  191376. }
  191377. CoTaskMemFree (nearestFormat);
  191378. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  191379. if (useExclusiveMode)
  191380. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  191381. GUID session;
  191382. if (hr == S_OK
  191383. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191384. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191385. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  191386. {
  191387. actualNumChannels = format.Format.nChannels;
  191388. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191389. bytesPerSample = format.Format.wBitsPerSample / 8;
  191390. dataFormat = isFloat ? AudioDataConverters::float32LE
  191391. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191392. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191393. : AudioDataConverters::int16LE)));
  191394. return true;
  191395. }
  191396. return false;
  191397. }
  191398. };
  191399. class WASAPIInputDevice : public WASAPIDeviceBase
  191400. {
  191401. public:
  191402. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191403. : WASAPIDeviceBase (device_, useExclusiveMode_),
  191404. reservoir (1, 1)
  191405. {
  191406. }
  191407. ~WASAPIInputDevice()
  191408. {
  191409. close();
  191410. }
  191411. bool open (const double newSampleRate, const BitArray& newChannels)
  191412. {
  191413. reservoirSize = 0;
  191414. reservoirCapacity = 16384;
  191415. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191416. return openClient (newSampleRate, newChannels)
  191417. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191418. }
  191419. void close()
  191420. {
  191421. closeClient();
  191422. captureClient = 0;
  191423. reservoir.setSize (0);
  191424. }
  191425. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191426. {
  191427. if (numChannels <= 0)
  191428. return;
  191429. int offset = 0;
  191430. while (bufferSize > 0)
  191431. {
  191432. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191433. {
  191434. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191435. for (int i = 0; i < numDestBuffers; ++i)
  191436. {
  191437. float* const dest = destBuffers[i] + offset;
  191438. const int srcChan = channelMaps.getUnchecked(i);
  191439. switch (dataFormat)
  191440. {
  191441. case AudioDataConverters::float32LE:
  191442. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191443. break;
  191444. case AudioDataConverters::int32LE:
  191445. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191446. break;
  191447. case AudioDataConverters::int24LE:
  191448. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191449. break;
  191450. case AudioDataConverters::int16LE:
  191451. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191452. break;
  191453. default: jassertfalse; break;
  191454. }
  191455. }
  191456. bufferSize -= samplesToDo;
  191457. offset += samplesToDo;
  191458. reservoirSize -= samplesToDo;
  191459. }
  191460. else
  191461. {
  191462. UINT32 packetLength = 0;
  191463. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191464. break;
  191465. if (packetLength == 0)
  191466. {
  191467. if (thread.threadShouldExit())
  191468. break;
  191469. Thread::sleep (1);
  191470. continue;
  191471. }
  191472. uint8* inputData = 0;
  191473. UINT32 numSamplesAvailable;
  191474. DWORD flags;
  191475. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191476. {
  191477. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191478. for (int i = 0; i < numDestBuffers; ++i)
  191479. {
  191480. float* const dest = destBuffers[i] + offset;
  191481. const int srcChan = channelMaps.getUnchecked(i);
  191482. switch (dataFormat)
  191483. {
  191484. case AudioDataConverters::float32LE:
  191485. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191486. break;
  191487. case AudioDataConverters::int32LE:
  191488. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191489. break;
  191490. case AudioDataConverters::int24LE:
  191491. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191492. break;
  191493. case AudioDataConverters::int16LE:
  191494. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191495. break;
  191496. default: jassertfalse; break;
  191497. }
  191498. }
  191499. bufferSize -= samplesToDo;
  191500. offset += samplesToDo;
  191501. if (samplesToDo < (int) numSamplesAvailable)
  191502. {
  191503. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  191504. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  191505. bytesPerSample * actualNumChannels * reservoirSize);
  191506. }
  191507. captureClient->ReleaseBuffer (numSamplesAvailable);
  191508. }
  191509. }
  191510. }
  191511. }
  191512. ComSmartPtr <IAudioCaptureClient> captureClient;
  191513. MemoryBlock reservoir;
  191514. int reservoirSize, reservoirCapacity;
  191515. };
  191516. class WASAPIOutputDevice : public WASAPIDeviceBase
  191517. {
  191518. public:
  191519. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191520. : WASAPIDeviceBase (device_, useExclusiveMode_)
  191521. {
  191522. }
  191523. ~WASAPIOutputDevice()
  191524. {
  191525. close();
  191526. }
  191527. bool open (const double newSampleRate, const BitArray& newChannels)
  191528. {
  191529. return openClient (newSampleRate, newChannels)
  191530. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  191531. }
  191532. void close()
  191533. {
  191534. closeClient();
  191535. renderClient = 0;
  191536. }
  191537. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  191538. {
  191539. if (numChannels <= 0)
  191540. return;
  191541. int offset = 0;
  191542. while (bufferSize > 0)
  191543. {
  191544. UINT32 padding = 0;
  191545. if (! OK (client->GetCurrentPadding (&padding)))
  191546. return;
  191547. int samplesToDo = useExclusiveMode ? bufferSize
  191548. : jmin ((int) (actualBufferSize - padding), bufferSize);
  191549. if (samplesToDo <= 0)
  191550. {
  191551. if (thread.threadShouldExit())
  191552. break;
  191553. Thread::sleep (0);
  191554. continue;
  191555. }
  191556. uint8* outputData = 0;
  191557. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  191558. {
  191559. for (int i = 0; i < numSrcBuffers; ++i)
  191560. {
  191561. const float* const source = srcBuffers[i] + offset;
  191562. const int destChan = channelMaps.getUnchecked(i);
  191563. switch (dataFormat)
  191564. {
  191565. case AudioDataConverters::float32LE:
  191566. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191567. break;
  191568. case AudioDataConverters::int32LE:
  191569. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191570. break;
  191571. case AudioDataConverters::int24LE:
  191572. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  191573. break;
  191574. case AudioDataConverters::int16LE:
  191575. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  191576. break;
  191577. default: jassertfalse; break;
  191578. }
  191579. }
  191580. renderClient->ReleaseBuffer (samplesToDo, 0);
  191581. offset += samplesToDo;
  191582. bufferSize -= samplesToDo;
  191583. }
  191584. }
  191585. }
  191586. ComSmartPtr <IAudioRenderClient> renderClient;
  191587. };
  191588. class WASAPIAudioIODevice : public AudioIODevice,
  191589. public Thread
  191590. {
  191591. public:
  191592. WASAPIAudioIODevice (const String& deviceName,
  191593. const String& outputDeviceId_,
  191594. const String& inputDeviceId_,
  191595. const bool useExclusiveMode_)
  191596. : AudioIODevice (deviceName, "Windows Audio"),
  191597. Thread ("Juce WASAPI"),
  191598. isOpen_ (false),
  191599. isStarted (false),
  191600. outputDevice (0),
  191601. outputDeviceId (outputDeviceId_),
  191602. inputDevice (0),
  191603. inputDeviceId (inputDeviceId_),
  191604. useExclusiveMode (useExclusiveMode_),
  191605. currentBufferSizeSamples (0),
  191606. currentSampleRate (0),
  191607. callback (0)
  191608. {
  191609. }
  191610. ~WASAPIAudioIODevice()
  191611. {
  191612. close();
  191613. deleteAndZero (inputDevice);
  191614. deleteAndZero (outputDevice);
  191615. }
  191616. bool initialise()
  191617. {
  191618. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  191619. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  191620. latencyIn = latencyOut = 0;
  191621. Array <double> ratesIn, ratesOut;
  191622. if (createDevices())
  191623. {
  191624. jassert (inputDevice != 0 || outputDevice != 0);
  191625. if (inputDevice != 0 && outputDevice != 0)
  191626. {
  191627. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  191628. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  191629. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  191630. sampleRates = inputDevice->rates;
  191631. sampleRates.removeValuesNotIn (outputDevice->rates);
  191632. }
  191633. else
  191634. {
  191635. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  191636. defaultSampleRate = d->defaultSampleRate;
  191637. minBufferSize = d->minBufferSize;
  191638. defaultBufferSize = d->defaultBufferSize;
  191639. sampleRates = d->rates;
  191640. }
  191641. IntegerElementComparator<int> comparator;
  191642. bufferSizes.addSorted (comparator, defaultBufferSize);
  191643. if (minBufferSize != defaultBufferSize)
  191644. bufferSizes.addSorted (comparator, minBufferSize);
  191645. int n = 64;
  191646. for (int i = 0; i < 40; ++i)
  191647. {
  191648. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191649. bufferSizes.addSorted (comparator, n);
  191650. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191651. }
  191652. return true;
  191653. }
  191654. return false;
  191655. }
  191656. const StringArray getOutputChannelNames()
  191657. {
  191658. StringArray outChannels;
  191659. if (outputDevice != 0)
  191660. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191661. outChannels.add ("Output channel " + String (i));
  191662. return outChannels;
  191663. }
  191664. const StringArray getInputChannelNames()
  191665. {
  191666. StringArray inChannels;
  191667. if (inputDevice != 0)
  191668. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191669. inChannels.add ("Input channel " + String (i));
  191670. return inChannels;
  191671. }
  191672. int getNumSampleRates() { return sampleRates.size(); }
  191673. double getSampleRate (int index) { return sampleRates [index]; }
  191674. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  191675. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  191676. int getDefaultBufferSize() { return defaultBufferSize; }
  191677. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  191678. double getCurrentSampleRate() { return currentSampleRate; }
  191679. int getCurrentBitDepth() { return 32; }
  191680. int getOutputLatencyInSamples() { return latencyOut; }
  191681. int getInputLatencyInSamples() { return latencyIn; }
  191682. const BitArray getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BitArray(); }
  191683. const BitArray getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BitArray(); }
  191684. const String getLastError() { return lastError; }
  191685. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  191686. double sampleRate, int bufferSizeSamples)
  191687. {
  191688. close();
  191689. lastError = String::empty;
  191690. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  191691. {
  191692. lastError = "The input and output devices don't share a common sample rate!";
  191693. return lastError;
  191694. }
  191695. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  191696. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  191697. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  191698. {
  191699. lastError = "Couldn't open the input device!";
  191700. return lastError;
  191701. }
  191702. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  191703. {
  191704. close();
  191705. lastError = "Couldn't open the output device!";
  191706. return lastError;
  191707. }
  191708. if (inputDevice != 0)
  191709. ResetEvent (inputDevice->clientEvent);
  191710. if (outputDevice != 0)
  191711. ResetEvent (outputDevice->clientEvent);
  191712. startThread (8);
  191713. Thread::sleep (5);
  191714. if (inputDevice != 0 && inputDevice->client != 0)
  191715. {
  191716. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  191717. HRESULT hr = inputDevice->client->Start();
  191718. logFailure (hr); //xxx handle this
  191719. }
  191720. if (outputDevice != 0 && outputDevice->client != 0)
  191721. {
  191722. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  191723. HRESULT hr = outputDevice->client->Start();
  191724. logFailure (hr); //xxx handle this
  191725. }
  191726. isOpen_ = true;
  191727. return lastError;
  191728. }
  191729. void close()
  191730. {
  191731. stop();
  191732. if (inputDevice != 0)
  191733. SetEvent (inputDevice->clientEvent);
  191734. if (outputDevice != 0)
  191735. SetEvent (outputDevice->clientEvent);
  191736. stopThread (5000);
  191737. if (inputDevice != 0)
  191738. inputDevice->close();
  191739. if (outputDevice != 0)
  191740. outputDevice->close();
  191741. isOpen_ = false;
  191742. }
  191743. bool isOpen() { return isOpen_ && isThreadRunning(); }
  191744. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  191745. void start (AudioIODeviceCallback* call)
  191746. {
  191747. if (isOpen_ && call != 0 && ! isStarted)
  191748. {
  191749. if (! isThreadRunning())
  191750. {
  191751. // something's gone wrong and the thread's stopped..
  191752. isOpen_ = false;
  191753. return;
  191754. }
  191755. call->audioDeviceAboutToStart (this);
  191756. const ScopedLock sl (startStopLock);
  191757. callback = call;
  191758. isStarted = true;
  191759. }
  191760. }
  191761. void stop()
  191762. {
  191763. if (isStarted)
  191764. {
  191765. AudioIODeviceCallback* const callbackLocal = callback;
  191766. {
  191767. const ScopedLock sl (startStopLock);
  191768. isStarted = false;
  191769. }
  191770. if (callbackLocal != 0)
  191771. callbackLocal->audioDeviceStopped();
  191772. }
  191773. }
  191774. void setMMThreadPriority()
  191775. {
  191776. DynamicLibraryLoader dll ("avrt.dll");
  191777. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  191778. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  191779. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  191780. {
  191781. DWORD dummy = 0;
  191782. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  191783. if (h != 0)
  191784. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  191785. }
  191786. }
  191787. void run()
  191788. {
  191789. setMMThreadPriority();
  191790. const int bufferSize = currentBufferSizeSamples;
  191791. HANDLE events[2];
  191792. int numEvents = 0;
  191793. if (inputDevice != 0)
  191794. events [numEvents++] = inputDevice->clientEvent;
  191795. if (outputDevice != 0)
  191796. events [numEvents++] = outputDevice->clientEvent;
  191797. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  191798. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  191799. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  191800. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  191801. float** const inputBuffers = ins.getArrayOfChannels();
  191802. float** const outputBuffers = outs.getArrayOfChannels();
  191803. ins.clear();
  191804. while (! threadShouldExit())
  191805. {
  191806. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  191807. : WaitForMultipleObjects (numEvents, events, true, 1000);
  191808. if (result == WAIT_TIMEOUT)
  191809. continue;
  191810. if (threadShouldExit())
  191811. break;
  191812. if (inputDevice != 0)
  191813. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  191814. // Make the callback..
  191815. {
  191816. const ScopedLock sl (startStopLock);
  191817. if (isStarted)
  191818. {
  191819. JUCE_TRY
  191820. {
  191821. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191822. numInputBuffers,
  191823. outputBuffers,
  191824. numOutputBuffers,
  191825. bufferSize);
  191826. }
  191827. JUCE_CATCH_EXCEPTION
  191828. }
  191829. else
  191830. {
  191831. outs.clear();
  191832. }
  191833. }
  191834. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  191835. continue;
  191836. if (outputDevice != 0)
  191837. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  191838. }
  191839. }
  191840. juce_UseDebuggingNewOperator
  191841. String outputDeviceId, inputDeviceId;
  191842. String lastError;
  191843. private:
  191844. // Device stats...
  191845. WASAPIInputDevice* inputDevice;
  191846. WASAPIOutputDevice* outputDevice;
  191847. const bool useExclusiveMode;
  191848. double defaultSampleRate;
  191849. int minBufferSize, defaultBufferSize;
  191850. int latencyIn, latencyOut;
  191851. Array <double> sampleRates;
  191852. Array <int> bufferSizes;
  191853. // Active state...
  191854. bool isOpen_, isStarted;
  191855. int currentBufferSizeSamples;
  191856. double currentSampleRate;
  191857. AudioIODeviceCallback* callback;
  191858. CriticalSection startStopLock;
  191859. bool createDevices()
  191860. {
  191861. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191862. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191863. return false;
  191864. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191865. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  191866. return false;
  191867. UINT32 numDevices = 0;
  191868. if (! OK (deviceCollection->GetCount (&numDevices)))
  191869. return false;
  191870. for (UINT32 i = 0; i < numDevices; ++i)
  191871. {
  191872. ComSmartPtr <IMMDevice> device;
  191873. if (! OK (deviceCollection->Item (i, &device)))
  191874. continue;
  191875. const String deviceId (wasapi_getDeviceID (device));
  191876. if (deviceId.isEmpty())
  191877. continue;
  191878. const EDataFlow flow = wasapi_getDataFlow (device);
  191879. if (deviceId == inputDeviceId && flow == eCapture)
  191880. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  191881. else if (deviceId == outputDeviceId && flow == eRender)
  191882. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  191883. }
  191884. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  191885. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  191886. }
  191887. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  191888. WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  191889. };
  191890. class WASAPIAudioIODeviceType : public AudioIODeviceType
  191891. {
  191892. public:
  191893. WASAPIAudioIODeviceType()
  191894. : AudioIODeviceType (T("Windows Audio")),
  191895. hasScanned (false)
  191896. {
  191897. }
  191898. ~WASAPIAudioIODeviceType()
  191899. {
  191900. }
  191901. void scanForDevices()
  191902. {
  191903. hasScanned = true;
  191904. outputDeviceNames.clear();
  191905. inputDeviceNames.clear();
  191906. outputDeviceIds.clear();
  191907. inputDeviceIds.clear();
  191908. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191909. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191910. return;
  191911. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  191912. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  191913. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191914. UINT32 numDevices = 0;
  191915. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  191916. && OK (deviceCollection->GetCount (&numDevices))))
  191917. return;
  191918. for (UINT32 i = 0; i < numDevices; ++i)
  191919. {
  191920. ComSmartPtr <IMMDevice> device;
  191921. if (! OK (deviceCollection->Item (i, &device)))
  191922. continue;
  191923. const String deviceId (wasapi_getDeviceID (device));
  191924. DWORD state = 0;
  191925. if (! OK (device->GetState (&state)))
  191926. continue;
  191927. if (state != DEVICE_STATE_ACTIVE)
  191928. continue;
  191929. String name;
  191930. {
  191931. ComSmartPtr <IPropertyStore> properties;
  191932. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  191933. continue;
  191934. PROPVARIANT value;
  191935. PropVariantInit (&value);
  191936. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  191937. name = value.pwszVal;
  191938. PropVariantClear (&value);
  191939. }
  191940. const EDataFlow flow = wasapi_getDataFlow (device);
  191941. if (flow == eRender)
  191942. {
  191943. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  191944. outputDeviceIds.insert (index, deviceId);
  191945. outputDeviceNames.insert (index, name);
  191946. }
  191947. else if (flow == eCapture)
  191948. {
  191949. const int index = (deviceId == defaultCapture) ? 0 : -1;
  191950. inputDeviceIds.insert (index, deviceId);
  191951. inputDeviceNames.insert (index, name);
  191952. }
  191953. }
  191954. inputDeviceNames.appendNumbersToDuplicates (false, false);
  191955. outputDeviceNames.appendNumbersToDuplicates (false, false);
  191956. }
  191957. const StringArray getDeviceNames (const bool wantInputNames) const
  191958. {
  191959. jassert (hasScanned); // need to call scanForDevices() before doing this
  191960. return wantInputNames ? inputDeviceNames
  191961. : outputDeviceNames;
  191962. }
  191963. int getDefaultDeviceIndex (const bool /*forInput*/) const
  191964. {
  191965. jassert (hasScanned); // need to call scanForDevices() before doing this
  191966. return 0;
  191967. }
  191968. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  191969. {
  191970. jassert (hasScanned); // need to call scanForDevices() before doing this
  191971. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  191972. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  191973. : outputDeviceIds.indexOf (d->outputDeviceId));
  191974. }
  191975. bool hasSeparateInputsAndOutputs() const { return true; }
  191976. AudioIODevice* createDevice (const String& outputDeviceName,
  191977. const String& inputDeviceName)
  191978. {
  191979. jassert (hasScanned); // need to call scanForDevices() before doing this
  191980. const bool useExclusiveMode = false;
  191981. WASAPIAudioIODevice* d = 0;
  191982. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191983. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191984. if (outputIndex >= 0 || inputIndex >= 0)
  191985. {
  191986. d = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191987. : inputDeviceName,
  191988. outputDeviceIds [outputIndex],
  191989. inputDeviceIds [inputIndex],
  191990. useExclusiveMode);
  191991. if (! d->initialise())
  191992. deleteAndZero (d);
  191993. }
  191994. return d;
  191995. }
  191996. juce_UseDebuggingNewOperator
  191997. StringArray outputDeviceNames, outputDeviceIds;
  191998. StringArray inputDeviceNames, inputDeviceIds;
  191999. private:
  192000. bool hasScanned;
  192001. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  192002. {
  192003. String s;
  192004. IMMDevice* dev = 0;
  192005. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  192006. eMultimedia, &dev)))
  192007. {
  192008. WCHAR* deviceId = 0;
  192009. if (OK (dev->GetId (&deviceId)))
  192010. {
  192011. s = String (deviceId);
  192012. CoTaskMemFree (deviceId);
  192013. }
  192014. dev->Release();
  192015. }
  192016. return s;
  192017. }
  192018. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  192019. WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  192020. };
  192021. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  192022. {
  192023. return new WASAPIAudioIODeviceType();
  192024. }
  192025. #undef logFailure
  192026. #undef OK
  192027. #endif
  192028. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  192029. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  192030. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  192031. // compiled on its own).
  192032. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  192033. class DShowCameraDeviceInteral : public ChangeBroadcaster
  192034. {
  192035. public:
  192036. DShowCameraDeviceInteral (CameraDevice* const owner_,
  192037. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  192038. const ComSmartPtr <IBaseFilter>& filter_,
  192039. int minWidth, int minHeight,
  192040. int maxWidth, int maxHeight)
  192041. : owner (owner_),
  192042. captureGraphBuilder (captureGraphBuilder_),
  192043. filter (filter_),
  192044. ok (false),
  192045. imageNeedsFlipping (false),
  192046. width (0),
  192047. height (0),
  192048. activeUsers (0),
  192049. recordNextFrameTime (false),
  192050. activeImage (0),
  192051. loadingImage (0)
  192052. {
  192053. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  192054. if (FAILED (hr))
  192055. return;
  192056. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  192057. if (FAILED (hr))
  192058. return;
  192059. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  192060. if (FAILED (hr))
  192061. return;
  192062. {
  192063. ComSmartPtr <IAMStreamConfig> streamConfig;
  192064. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE, 0, filter,
  192065. IID_IAMStreamConfig, (void**) &streamConfig);
  192066. if (streamConfig != 0)
  192067. {
  192068. getVideoSizes (streamConfig);
  192069. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  192070. return;
  192071. }
  192072. }
  192073. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  192074. if (FAILED (hr))
  192075. return;
  192076. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  192077. if (FAILED (hr))
  192078. return;
  192079. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  192080. if (FAILED (hr))
  192081. return;
  192082. if (! connectFilters (filter, smartTee))
  192083. return;
  192084. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  192085. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  192086. if (FAILED (hr))
  192087. return;
  192088. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  192089. if (FAILED (hr))
  192090. return;
  192091. AM_MEDIA_TYPE mt;
  192092. zerostruct (mt);
  192093. mt.majortype = MEDIATYPE_Video;
  192094. mt.subtype = MEDIASUBTYPE_RGB24;
  192095. mt.formattype = FORMAT_VideoInfo;
  192096. sampleGrabber->SetMediaType (&mt);
  192097. callback = new GrabberCallback (*this);
  192098. sampleGrabber->SetCallback (callback, 1);
  192099. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  192100. if (FAILED (hr))
  192101. return;
  192102. ComSmartPtr <IPin> grabberInputPin;
  192103. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  192104. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  192105. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  192106. return;
  192107. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  192108. if (FAILED (hr))
  192109. return;
  192110. zerostruct (mt);
  192111. hr = sampleGrabber->GetConnectedMediaType (&mt);
  192112. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  192113. width = pVih->bmiHeader.biWidth;
  192114. height = pVih->bmiHeader.biHeight;
  192115. ComSmartPtr <IBaseFilter> nullFilter;
  192116. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  192117. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  192118. if (connectFilters (sampleGrabberBase, nullFilter)
  192119. && addGraphToRot())
  192120. {
  192121. activeImage = new Image (Image::RGB, width, height, true);
  192122. loadingImage = new Image (Image::RGB, width, height, true);
  192123. ok = true;
  192124. }
  192125. }
  192126. ~DShowCameraDeviceInteral()
  192127. {
  192128. if (mediaControl != 0)
  192129. mediaControl->Stop();
  192130. removeGraphFromRot();
  192131. for (int i = viewerComps.size(); --i >= 0;)
  192132. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  192133. callback = 0;
  192134. graphBuilder = 0;
  192135. sampleGrabber = 0;
  192136. mediaControl = 0;
  192137. filter = 0;
  192138. captureGraphBuilder = 0;
  192139. smartTee = 0;
  192140. smartTeePreviewOutputPin = 0;
  192141. smartTeeCaptureOutputPin = 0;
  192142. asfWriter = 0;
  192143. delete activeImage;
  192144. delete loadingImage;
  192145. }
  192146. void addUser()
  192147. {
  192148. if (ok && activeUsers++ == 0)
  192149. mediaControl->Run();
  192150. }
  192151. void removeUser()
  192152. {
  192153. if (ok && --activeUsers == 0)
  192154. mediaControl->Stop();
  192155. }
  192156. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  192157. {
  192158. if (recordNextFrameTime)
  192159. {
  192160. const double defaultCameraLatency = 0.1;
  192161. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  192162. recordNextFrameTime = false;
  192163. ComSmartPtr <IPin> pin;
  192164. if (getPin (filter, PINDIR_OUTPUT, &pin))
  192165. {
  192166. ComSmartPtr <IAMPushSource> pushSource;
  192167. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  192168. if (pushSource != 0)
  192169. {
  192170. REFERENCE_TIME latency = 0;
  192171. hr = pushSource->GetLatency (&latency);
  192172. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  192173. }
  192174. }
  192175. }
  192176. {
  192177. const int lineStride = width * 3;
  192178. const ScopedLock sl (imageSwapLock);
  192179. {
  192180. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  192181. for (int i = 0; i < height; ++i)
  192182. memcpy (destData.getLinePointer ((height - 1) - i),
  192183. buffer + lineStride * i,
  192184. lineStride);
  192185. }
  192186. imageNeedsFlipping = true;
  192187. }
  192188. if (listeners.size() > 0)
  192189. callListeners (*loadingImage);
  192190. sendChangeMessage (this);
  192191. }
  192192. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  192193. {
  192194. if (imageNeedsFlipping)
  192195. {
  192196. const ScopedLock sl (imageSwapLock);
  192197. swapVariables (loadingImage, activeImage);
  192198. imageNeedsFlipping = false;
  192199. }
  192200. RectanglePlacement rp (RectanglePlacement::centred);
  192201. double dx = 0, dy = 0, dw = width, dh = height;
  192202. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  192203. const int rx = roundToInt (dx), ry = roundToInt (dy);
  192204. const int rw = roundToInt (dw), rh = roundToInt (dh);
  192205. g.saveState();
  192206. g.excludeClipRegion (Rectangle<int> (rx, ry, rw, rh));
  192207. g.fillAll (Colours::black);
  192208. g.restoreState();
  192209. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  192210. }
  192211. bool createFileCaptureFilter (const File& file)
  192212. {
  192213. removeFileCaptureFilter();
  192214. file.deleteFile();
  192215. mediaControl->Stop();
  192216. firstRecordedTime = Time();
  192217. recordNextFrameTime = true;
  192218. HRESULT hr = asfWriter.CoCreateInstance (CLSID_WMAsfWriter, CLSCTX_INPROC_SERVER);
  192219. if (SUCCEEDED (hr))
  192220. {
  192221. ComSmartPtr <IFileSinkFilter> fileSink;
  192222. hr = asfWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  192223. if (SUCCEEDED (hr))
  192224. {
  192225. hr = fileSink->SetFileName (file.getFullPathName(), 0);
  192226. if (SUCCEEDED (hr))
  192227. {
  192228. hr = graphBuilder->AddFilter (asfWriter, _T("AsfWriter"));
  192229. if (SUCCEEDED (hr))
  192230. {
  192231. ComSmartPtr <IConfigAsfWriter> asfConfig;
  192232. hr = asfWriter->QueryInterface (IID_IConfigAsfWriter, (void**) &asfConfig);
  192233. asfConfig->SetIndexMode (true);
  192234. ComSmartPtr <IWMProfileManager> profileManager;
  192235. hr = WMCreateProfileManager (&profileManager);
  192236. // This gibberish is the DirectShow profile for a video-only wmv file.
  192237. String prof ("<profile version=\"589824\" storageformat=\"1\" name=\"Quality\" description=\"Quality type for output.\"><streamconfig "
  192238. "majortype=\"{73646976-0000-0010-8000-00AA00389B71}\" streamnumber=\"1\" streamname=\"Video Stream\" inputname=\"Video409\" bitrate=\"894960\" "
  192239. "bufferwindow=\"0\" reliabletransport=\"1\" decodercomplexity=\"AU\" rfc1766langid=\"en-us\"><videomediaprops maxkeyframespacing=\"50000000\" quality=\"90\"/>"
  192240. "<wmmediatype subtype=\"{33564D57-0000-0010-8000-00AA00389B71}\" bfixedsizesamples=\"0\" btemporalcompression=\"1\" lsamplesize=\"0\"> <videoinfoheader "
  192241. "dwbitrate=\"894960\" dwbiterrorrate=\"0\" avgtimeperframe=\"100000\"><rcsource left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <rctarget "
  192242. "left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <bitmapinfoheader biwidth=\"$WIDTH\" biheight=\"$HEIGHT\" biplanes=\"1\" bibitcount=\"24\" "
  192243. "bicompression=\"WMV3\" bisizeimage=\"0\" bixpelspermeter=\"0\" biypelspermeter=\"0\" biclrused=\"0\" biclrimportant=\"0\"/> "
  192244. "</videoinfoheader></wmmediatype></streamconfig></profile>");
  192245. prof = prof.replace (T("$WIDTH"), String (width))
  192246. .replace (T("$HEIGHT"), String (height));
  192247. ComSmartPtr <IWMProfile> currentProfile;
  192248. hr = profileManager->LoadProfileByData ((const WCHAR*) prof, &currentProfile);
  192249. hr = asfConfig->ConfigureFilterUsingProfile (currentProfile);
  192250. if (SUCCEEDED (hr))
  192251. {
  192252. ComSmartPtr <IPin> asfWriterInputPin;
  192253. if (getPin (asfWriter, PINDIR_INPUT, &asfWriterInputPin, "Video Input 01"))
  192254. {
  192255. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, asfWriterInputPin);
  192256. if (SUCCEEDED (hr)
  192257. && ok && activeUsers > 0
  192258. && SUCCEEDED (mediaControl->Run()))
  192259. {
  192260. return true;
  192261. }
  192262. }
  192263. }
  192264. }
  192265. }
  192266. }
  192267. }
  192268. removeFileCaptureFilter();
  192269. if (ok && activeUsers > 0)
  192270. mediaControl->Run();
  192271. return false;
  192272. }
  192273. void removeFileCaptureFilter()
  192274. {
  192275. mediaControl->Stop();
  192276. if (asfWriter != 0)
  192277. {
  192278. graphBuilder->RemoveFilter (asfWriter);
  192279. asfWriter = 0;
  192280. }
  192281. if (ok && activeUsers > 0)
  192282. mediaControl->Run();
  192283. }
  192284. void addListener (CameraImageListener* listenerToAdd)
  192285. {
  192286. const ScopedLock sl (listenerLock);
  192287. if (listeners.size() == 0)
  192288. addUser();
  192289. listeners.addIfNotAlreadyThere (listenerToAdd);
  192290. }
  192291. void removeListener (CameraImageListener* listenerToRemove)
  192292. {
  192293. const ScopedLock sl (listenerLock);
  192294. listeners.removeValue (listenerToRemove);
  192295. if (listeners.size() == 0)
  192296. removeUser();
  192297. }
  192298. void callListeners (Image& image)
  192299. {
  192300. const ScopedLock sl (listenerLock);
  192301. for (int i = listeners.size(); --i >= 0;)
  192302. {
  192303. CameraImageListener* l = (CameraImageListener*) listeners[i];
  192304. if (l != 0)
  192305. l->imageReceived (image);
  192306. }
  192307. }
  192308. class DShowCaptureViewerComp : public Component,
  192309. public ChangeListener
  192310. {
  192311. public:
  192312. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  192313. : owner (owner_)
  192314. {
  192315. setOpaque (true);
  192316. owner->addChangeListener (this);
  192317. owner->addUser();
  192318. owner->viewerComps.add (this);
  192319. setSize (owner_->width, owner_->height);
  192320. }
  192321. ~DShowCaptureViewerComp()
  192322. {
  192323. if (owner != 0)
  192324. {
  192325. owner->viewerComps.removeValue (this);
  192326. owner->removeUser();
  192327. owner->removeChangeListener (this);
  192328. }
  192329. }
  192330. void ownerDeleted()
  192331. {
  192332. owner = 0;
  192333. }
  192334. void paint (Graphics& g)
  192335. {
  192336. g.setColour (Colours::black);
  192337. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  192338. if (owner != 0)
  192339. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  192340. else
  192341. g.fillAll (Colours::black);
  192342. }
  192343. void changeListenerCallback (void*)
  192344. {
  192345. repaint();
  192346. }
  192347. private:
  192348. DShowCameraDeviceInteral* owner;
  192349. };
  192350. bool ok;
  192351. int width, height;
  192352. Time firstRecordedTime;
  192353. VoidArray viewerComps;
  192354. private:
  192355. CameraDevice* const owner;
  192356. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192357. ComSmartPtr <IBaseFilter> filter;
  192358. ComSmartPtr <IBaseFilter> smartTee;
  192359. ComSmartPtr <IGraphBuilder> graphBuilder;
  192360. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192361. ComSmartPtr <IMediaControl> mediaControl;
  192362. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192363. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192364. ComSmartPtr <IBaseFilter> asfWriter;
  192365. int activeUsers;
  192366. Array <int> widths, heights;
  192367. DWORD graphRegistrationID;
  192368. CriticalSection imageSwapLock;
  192369. bool imageNeedsFlipping;
  192370. Image* loadingImage;
  192371. Image* activeImage;
  192372. bool recordNextFrameTime;
  192373. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192374. {
  192375. widths.clear();
  192376. heights.clear();
  192377. int count = 0, size = 0;
  192378. streamConfig->GetNumberOfCapabilities (&count, &size);
  192379. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192380. {
  192381. for (int i = 0; i < count; ++i)
  192382. {
  192383. VIDEO_STREAM_CONFIG_CAPS scc;
  192384. AM_MEDIA_TYPE* config;
  192385. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192386. if (SUCCEEDED (hr))
  192387. {
  192388. const int w = scc.InputSize.cx;
  192389. const int h = scc.InputSize.cy;
  192390. bool duplicate = false;
  192391. for (int j = widths.size(); --j >= 0;)
  192392. {
  192393. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192394. {
  192395. duplicate = true;
  192396. break;
  192397. }
  192398. }
  192399. if (! duplicate)
  192400. {
  192401. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192402. widths.add (w);
  192403. heights.add (h);
  192404. }
  192405. deleteMediaType (config);
  192406. }
  192407. }
  192408. }
  192409. }
  192410. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192411. const int minWidth, const int minHeight,
  192412. const int maxWidth, const int maxHeight)
  192413. {
  192414. int count = 0, size = 0, bestArea = 0, bestIndex = -1;
  192415. streamConfig->GetNumberOfCapabilities (&count, &size);
  192416. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192417. {
  192418. AM_MEDIA_TYPE* config;
  192419. VIDEO_STREAM_CONFIG_CAPS scc;
  192420. for (int i = 0; i < count; ++i)
  192421. {
  192422. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192423. if (SUCCEEDED (hr))
  192424. {
  192425. if (scc.InputSize.cx >= minWidth
  192426. && scc.InputSize.cy >= minHeight
  192427. && scc.InputSize.cx <= maxWidth
  192428. && scc.InputSize.cy <= maxHeight)
  192429. {
  192430. int area = scc.InputSize.cx * scc.InputSize.cy;
  192431. if (area > bestArea)
  192432. {
  192433. bestIndex = i;
  192434. bestArea = area;
  192435. }
  192436. }
  192437. deleteMediaType (config);
  192438. }
  192439. }
  192440. if (bestIndex >= 0)
  192441. {
  192442. HRESULT hr = streamConfig->GetStreamCaps (bestIndex, &config, (BYTE*) &scc);
  192443. hr = streamConfig->SetFormat (config);
  192444. deleteMediaType (config);
  192445. return SUCCEEDED (hr);
  192446. }
  192447. }
  192448. return false;
  192449. }
  192450. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192451. {
  192452. ComSmartPtr <IEnumPins> enumerator;
  192453. ComSmartPtr <IPin> pin;
  192454. filter->EnumPins (&enumerator);
  192455. while (enumerator->Next (1, &pin, 0) == S_OK)
  192456. {
  192457. PIN_DIRECTION dir;
  192458. pin->QueryDirection (&dir);
  192459. if (wantedDirection == dir)
  192460. {
  192461. PIN_INFO info;
  192462. zerostruct (info);
  192463. pin->QueryPinInfo (&info);
  192464. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192465. {
  192466. pin.p->AddRef();
  192467. *result = pin;
  192468. return true;
  192469. }
  192470. }
  192471. }
  192472. return false;
  192473. }
  192474. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192475. {
  192476. ComSmartPtr <IPin> in, out;
  192477. return getPin (first, PINDIR_OUTPUT, &out)
  192478. && getPin (second, PINDIR_INPUT, &in)
  192479. && SUCCEEDED (graphBuilder->Connect (out, in));
  192480. }
  192481. bool addGraphToRot()
  192482. {
  192483. ComSmartPtr <IRunningObjectTable> rot;
  192484. if (FAILED (GetRunningObjectTable (0, &rot)))
  192485. return false;
  192486. ComSmartPtr <IMoniker> moniker;
  192487. WCHAR buffer[128];
  192488. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192489. if (FAILED (hr))
  192490. return false;
  192491. graphRegistrationID = 0;
  192492. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192493. }
  192494. void removeGraphFromRot()
  192495. {
  192496. ComSmartPtr <IRunningObjectTable> rot;
  192497. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192498. rot->Revoke (graphRegistrationID);
  192499. }
  192500. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192501. {
  192502. if (pmt->cbFormat != 0)
  192503. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192504. if (pmt->pUnk != 0)
  192505. pmt->pUnk->Release();
  192506. CoTaskMemFree (pmt);
  192507. }
  192508. class GrabberCallback : public ISampleGrabberCB
  192509. {
  192510. public:
  192511. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192512. : owner (owner_)
  192513. {
  192514. }
  192515. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192516. {
  192517. if (id == IID_IUnknown)
  192518. *result = dynamic_cast <IUnknown*> (this);
  192519. else if (id == IID_ISampleGrabberCB)
  192520. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192521. else
  192522. {
  192523. *result = 0;
  192524. return E_NOINTERFACE;
  192525. }
  192526. AddRef();
  192527. return S_OK;
  192528. }
  192529. ULONG __stdcall AddRef() { return ++refCount; }
  192530. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  192531. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  192532. {
  192533. return E_FAIL;
  192534. }
  192535. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  192536. {
  192537. owner.handleFrame (time, buffer, bufferSize);
  192538. return S_OK;
  192539. }
  192540. private:
  192541. int refCount;
  192542. DShowCameraDeviceInteral& owner;
  192543. GrabberCallback (const GrabberCallback&);
  192544. GrabberCallback& operator= (const GrabberCallback&);
  192545. };
  192546. ComSmartPtr <GrabberCallback> callback;
  192547. VoidArray listeners;
  192548. CriticalSection listenerLock;
  192549. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  192550. DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  192551. };
  192552. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  192553. : name (name_)
  192554. {
  192555. isRecording = false;
  192556. }
  192557. CameraDevice::~CameraDevice()
  192558. {
  192559. stopRecording();
  192560. delete (DShowCameraDeviceInteral*) internal;
  192561. internal = 0;
  192562. }
  192563. Component* CameraDevice::createViewerComponent()
  192564. {
  192565. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  192566. }
  192567. const String CameraDevice::getFileExtension()
  192568. {
  192569. return ".wmv";
  192570. }
  192571. void CameraDevice::startRecordingToFile (const File& file, int quality)
  192572. {
  192573. stopRecording();
  192574. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192575. d->addUser();
  192576. isRecording = d->createFileCaptureFilter (file);
  192577. }
  192578. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  192579. {
  192580. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192581. return d->firstRecordedTime;
  192582. }
  192583. void CameraDevice::stopRecording()
  192584. {
  192585. if (isRecording)
  192586. {
  192587. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192588. d->removeFileCaptureFilter();
  192589. d->removeUser();
  192590. isRecording = false;
  192591. }
  192592. }
  192593. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  192594. {
  192595. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192596. if (listenerToAdd != 0)
  192597. d->addListener (listenerToAdd);
  192598. }
  192599. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  192600. {
  192601. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192602. if (listenerToRemove != 0)
  192603. d->removeListener (listenerToRemove);
  192604. }
  192605. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  192606. const int deviceIndexToOpen,
  192607. String& name)
  192608. {
  192609. int index = 0;
  192610. ComSmartPtr <IBaseFilter> result;
  192611. ComSmartPtr <ICreateDevEnum> pDevEnum;
  192612. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  192613. if (SUCCEEDED (hr))
  192614. {
  192615. ComSmartPtr <IEnumMoniker> enumerator;
  192616. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  192617. if (SUCCEEDED (hr) && enumerator != 0)
  192618. {
  192619. ComSmartPtr <IBaseFilter> captureFilter;
  192620. ComSmartPtr <IMoniker> moniker;
  192621. ULONG fetched;
  192622. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  192623. {
  192624. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  192625. if (SUCCEEDED (hr))
  192626. {
  192627. ComSmartPtr <IPropertyBag> propertyBag;
  192628. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  192629. if (SUCCEEDED (hr))
  192630. {
  192631. VARIANT var;
  192632. var.vt = VT_BSTR;
  192633. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  192634. propertyBag = 0;
  192635. if (SUCCEEDED (hr))
  192636. {
  192637. if (names != 0)
  192638. names->add (var.bstrVal);
  192639. if (index == deviceIndexToOpen)
  192640. {
  192641. name = var.bstrVal;
  192642. result = captureFilter;
  192643. captureFilter = 0;
  192644. break;
  192645. }
  192646. ++index;
  192647. }
  192648. moniker = 0;
  192649. }
  192650. captureFilter = 0;
  192651. }
  192652. }
  192653. }
  192654. }
  192655. return result;
  192656. }
  192657. const StringArray CameraDevice::getAvailableDevices()
  192658. {
  192659. StringArray devs;
  192660. String dummy;
  192661. enumerateCameras (&devs, -1, dummy);
  192662. return devs;
  192663. }
  192664. CameraDevice* CameraDevice::openDevice (int index,
  192665. int minWidth, int minHeight,
  192666. int maxWidth, int maxHeight)
  192667. {
  192668. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192669. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  192670. if (SUCCEEDED (hr))
  192671. {
  192672. String name;
  192673. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192674. if (filter != 0)
  192675. {
  192676. CameraDevice* const cam = new CameraDevice (name, index);
  192677. DShowCameraDeviceInteral* const intern
  192678. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192679. minWidth, minHeight, maxWidth, maxHeight);
  192680. cam->internal = intern;
  192681. if (intern->ok)
  192682. return cam;
  192683. else
  192684. delete cam;
  192685. }
  192686. }
  192687. return 0;
  192688. }
  192689. #endif
  192690. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  192691. #endif
  192692. // Auto-link the other win32 libs that are needed by library calls..
  192693. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  192694. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192695. // Auto-links to various win32 libs that are needed by library calls..
  192696. #pragma comment(lib, "kernel32.lib")
  192697. #pragma comment(lib, "user32.lib")
  192698. #pragma comment(lib, "shell32.lib")
  192699. #pragma comment(lib, "gdi32.lib")
  192700. #pragma comment(lib, "vfw32.lib")
  192701. #pragma comment(lib, "comdlg32.lib")
  192702. #pragma comment(lib, "winmm.lib")
  192703. #pragma comment(lib, "wininet.lib")
  192704. #pragma comment(lib, "ole32.lib")
  192705. #pragma comment(lib, "oleaut32.lib")
  192706. #pragma comment(lib, "advapi32.lib")
  192707. #pragma comment(lib, "ws2_32.lib")
  192708. #pragma comment(lib, "comsupp.lib")
  192709. #pragma comment(lib, "version.lib")
  192710. #if JUCE_OPENGL
  192711. #pragma comment(lib, "OpenGL32.Lib")
  192712. #pragma comment(lib, "GlU32.Lib")
  192713. #endif
  192714. #if JUCE_QUICKTIME
  192715. #pragma comment (lib, "QTMLClient.lib")
  192716. #endif
  192717. #if JUCE_USE_CAMERA
  192718. #pragma comment (lib, "Strmiids.lib")
  192719. #pragma comment (lib, "wmvcore.lib")
  192720. #endif
  192721. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192722. #endif
  192723. END_JUCE_NAMESPACE
  192724. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  192725. #endif
  192726. #if JUCE_LINUX
  192727. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  192728. BEGIN_JUCE_NAMESPACE
  192729. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  192730. #define SUPPORT_AFFINITIES 1
  192731. #endif
  192732. #define JUCE_INCLUDED_FILE 1
  192733. // Now include the actual code files..
  192734. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  192735. CriticalSection::CriticalSection() throw()
  192736. {
  192737. pthread_mutexattr_t atts;
  192738. pthread_mutexattr_init (&atts);
  192739. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  192740. pthread_mutex_init (&internal, &atts);
  192741. }
  192742. CriticalSection::~CriticalSection() throw()
  192743. {
  192744. pthread_mutex_destroy (&internal);
  192745. }
  192746. void CriticalSection::enter() const throw()
  192747. {
  192748. pthread_mutex_lock (&internal);
  192749. }
  192750. bool CriticalSection::tryEnter() const throw()
  192751. {
  192752. return pthread_mutex_trylock (&internal) == 0;
  192753. }
  192754. void CriticalSection::exit() const throw()
  192755. {
  192756. pthread_mutex_unlock (&internal);
  192757. }
  192758. struct EventStruct
  192759. {
  192760. pthread_cond_t condition;
  192761. pthread_mutex_t mutex;
  192762. bool triggered;
  192763. };
  192764. WaitableEvent::WaitableEvent() throw()
  192765. {
  192766. EventStruct* const es = new EventStruct();
  192767. es->triggered = false;
  192768. pthread_cond_init (&es->condition, 0);
  192769. pthread_mutex_init (&es->mutex, 0);
  192770. internal = es;
  192771. }
  192772. WaitableEvent::~WaitableEvent() throw()
  192773. {
  192774. EventStruct* const es = (EventStruct*) internal;
  192775. pthread_cond_destroy (&es->condition);
  192776. pthread_mutex_destroy (&es->mutex);
  192777. delete es;
  192778. }
  192779. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  192780. {
  192781. EventStruct* const es = (EventStruct*) internal;
  192782. pthread_mutex_lock (&es->mutex);
  192783. if (timeOutMillisecs < 0)
  192784. {
  192785. while (! es->triggered)
  192786. pthread_cond_wait (&es->condition, &es->mutex);
  192787. }
  192788. else
  192789. {
  192790. while (! es->triggered)
  192791. {
  192792. struct timeval t;
  192793. gettimeofday (&t, 0);
  192794. struct timespec time;
  192795. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  192796. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  192797. if (time.tv_nsec >= 1000000000)
  192798. {
  192799. time.tv_nsec -= 1000000000;
  192800. time.tv_sec++;
  192801. }
  192802. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  192803. {
  192804. pthread_mutex_unlock (&es->mutex);
  192805. return false;
  192806. }
  192807. }
  192808. }
  192809. es->triggered = false;
  192810. pthread_mutex_unlock (&es->mutex);
  192811. return true;
  192812. }
  192813. void WaitableEvent::signal() const throw()
  192814. {
  192815. EventStruct* const es = (EventStruct*) internal;
  192816. pthread_mutex_lock (&es->mutex);
  192817. es->triggered = true;
  192818. pthread_cond_broadcast (&es->condition);
  192819. pthread_mutex_unlock (&es->mutex);
  192820. }
  192821. void WaitableEvent::reset() const throw()
  192822. {
  192823. EventStruct* const es = (EventStruct*) internal;
  192824. pthread_mutex_lock (&es->mutex);
  192825. es->triggered = false;
  192826. pthread_mutex_unlock (&es->mutex);
  192827. }
  192828. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  192829. {
  192830. struct timespec time;
  192831. time.tv_sec = millisecs / 1000;
  192832. time.tv_nsec = (millisecs % 1000) * 1000000;
  192833. nanosleep (&time, 0);
  192834. }
  192835. const tchar File::separator = T('/');
  192836. const tchar* File::separatorString = T("/");
  192837. const File File::getCurrentWorkingDirectory()
  192838. {
  192839. HeapBlock<char> heapBuffer;
  192840. char localBuffer [1024];
  192841. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  192842. int bufferSize = 4096;
  192843. while (cwd == 0 && errno == ERANGE)
  192844. {
  192845. heapBuffer.malloc (bufferSize);
  192846. cwd = getcwd (heapBuffer, bufferSize - 1);
  192847. bufferSize += 1024;
  192848. }
  192849. return File (String::fromUTF8 (cwd));
  192850. }
  192851. bool File::setAsCurrentWorkingDirectory() const
  192852. {
  192853. return chdir (getFullPathName().toUTF8()) == 0;
  192854. }
  192855. bool juce_copyFile (const String& s, const String& d);
  192856. static bool juce_stat (const String& fileName, struct stat& info)
  192857. {
  192858. return fileName.isNotEmpty()
  192859. && (stat (fileName.toUTF8(), &info) == 0);
  192860. }
  192861. bool juce_isDirectory (const String& fileName)
  192862. {
  192863. struct stat info;
  192864. return fileName.isEmpty()
  192865. || (juce_stat (fileName, info)
  192866. && ((info.st_mode & S_IFDIR) != 0));
  192867. }
  192868. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  192869. {
  192870. if (fileName.isEmpty())
  192871. return false;
  192872. const char* const fileNameUTF8 = fileName.toUTF8();
  192873. bool exists = access (fileNameUTF8, F_OK) == 0;
  192874. if (exists && dontCountDirectories)
  192875. {
  192876. struct stat info;
  192877. const int res = stat (fileNameUTF8, &info);
  192878. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  192879. exists = false;
  192880. }
  192881. return exists;
  192882. }
  192883. int64 juce_getFileSize (const String& fileName)
  192884. {
  192885. struct stat info;
  192886. return juce_stat (fileName, info) ? info.st_size : 0;
  192887. }
  192888. bool juce_canWriteToFile (const String& fileName)
  192889. {
  192890. return access (fileName.toUTF8(), W_OK) == 0;
  192891. }
  192892. bool juce_deleteFile (const String& fileName)
  192893. {
  192894. if (juce_isDirectory (fileName))
  192895. return rmdir ((const char*) fileName.toUTF8()) == 0;
  192896. else
  192897. return remove ((const char*) fileName.toUTF8()) == 0;
  192898. }
  192899. bool juce_moveFile (const String& source, const String& dest)
  192900. {
  192901. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  192902. return true;
  192903. if (juce_canWriteToFile (source)
  192904. && juce_copyFile (source, dest))
  192905. {
  192906. if (juce_deleteFile (source))
  192907. return true;
  192908. juce_deleteFile (dest);
  192909. }
  192910. return false;
  192911. }
  192912. void juce_createDirectory (const String& fileName)
  192913. {
  192914. mkdir (fileName.toUTF8(), 0777);
  192915. }
  192916. void* juce_fileOpen (const String& fileName, bool forWriting)
  192917. {
  192918. int flags = O_RDONLY;
  192919. if (forWriting)
  192920. {
  192921. if (juce_fileExists (fileName, false))
  192922. {
  192923. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  192924. if (f != -1)
  192925. lseek (f, 0, SEEK_END);
  192926. return (void*) f;
  192927. }
  192928. else
  192929. {
  192930. flags = O_RDWR + O_CREAT;
  192931. }
  192932. }
  192933. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  192934. }
  192935. void juce_fileClose (void* handle)
  192936. {
  192937. if (handle != 0)
  192938. close ((int) (pointer_sized_int) handle);
  192939. }
  192940. int juce_fileRead (void* handle, void* buffer, int size)
  192941. {
  192942. if (handle != 0)
  192943. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  192944. return 0;
  192945. }
  192946. int juce_fileWrite (void* handle, const void* buffer, int size)
  192947. {
  192948. if (handle != 0)
  192949. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  192950. return 0;
  192951. }
  192952. int64 juce_fileSetPosition (void* handle, int64 pos)
  192953. {
  192954. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  192955. return pos;
  192956. return -1;
  192957. }
  192958. int64 juce_fileGetPosition (void* handle)
  192959. {
  192960. if (handle != 0)
  192961. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  192962. else
  192963. return -1;
  192964. }
  192965. void juce_fileFlush (void* handle)
  192966. {
  192967. if (handle != 0)
  192968. fsync ((int) (pointer_sized_int) handle);
  192969. }
  192970. const File juce_getExecutableFile()
  192971. {
  192972. Dl_info exeInfo;
  192973. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  192974. return File (String::fromUTF8 (exeInfo.dli_fname));
  192975. }
  192976. // if this file doesn't exist, find a parent of it that does..
  192977. static bool doStatFS (const File* file, struct statfs& result)
  192978. {
  192979. File f (*file);
  192980. for (int i = 5; --i >= 0;)
  192981. {
  192982. if (f.exists())
  192983. break;
  192984. f = f.getParentDirectory();
  192985. }
  192986. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  192987. }
  192988. int64 File::getBytesFreeOnVolume() const
  192989. {
  192990. struct statfs buf;
  192991. if (doStatFS (this, buf))
  192992. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  192993. return 0;
  192994. }
  192995. int64 File::getVolumeTotalSize() const
  192996. {
  192997. struct statfs buf;
  192998. if (doStatFS (this, buf))
  192999. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  193000. return 0;
  193001. }
  193002. const String juce_getVolumeLabel (const String& filenameOnVolume,
  193003. int& volumeSerialNumber)
  193004. {
  193005. volumeSerialNumber = 0;
  193006. #if JUCE_MAC
  193007. struct VolAttrBuf
  193008. {
  193009. u_int32_t length;
  193010. attrreference_t mountPointRef;
  193011. char mountPointSpace [MAXPATHLEN];
  193012. } attrBuf;
  193013. struct attrlist attrList;
  193014. zerostruct (attrList);
  193015. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  193016. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  193017. File f (filenameOnVolume);
  193018. for (;;)
  193019. {
  193020. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  193021. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  193022. {
  193023. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  193024. (int) attrBuf.mountPointRef.attr_length);
  193025. }
  193026. const File parent (f.getParentDirectory());
  193027. if (f == parent)
  193028. break;
  193029. f = parent;
  193030. }
  193031. #endif
  193032. return String::empty;
  193033. }
  193034. void juce_runSystemCommand (const String& command)
  193035. {
  193036. int result = system ((const char*) command.toUTF8());
  193037. (void) result;
  193038. }
  193039. const String juce_getOutputFromCommand (const String& command)
  193040. {
  193041. // slight bodge here, as we just pipe the output into a temp file and read it...
  193042. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  193043. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  193044. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  193045. String result (tempFile.loadFileAsString());
  193046. tempFile.deleteFile();
  193047. return result;
  193048. }
  193049. InterProcessLock::InterProcessLock (const String& name_)
  193050. : internal (0),
  193051. name (name_),
  193052. reentrancyLevel (0)
  193053. {
  193054. #if JUCE_MAC
  193055. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  193056. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  193057. #else
  193058. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  193059. #endif
  193060. temp.create();
  193061. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  193062. }
  193063. InterProcessLock::~InterProcessLock()
  193064. {
  193065. while (reentrancyLevel > 0)
  193066. this->exit();
  193067. close (internal);
  193068. }
  193069. bool InterProcessLock::enter (const int timeOutMillisecs)
  193070. {
  193071. if (internal == 0)
  193072. return false;
  193073. if (reentrancyLevel != 0)
  193074. return true;
  193075. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  193076. struct flock fl;
  193077. zerostruct (fl);
  193078. fl.l_whence = SEEK_SET;
  193079. fl.l_type = F_WRLCK;
  193080. for (;;)
  193081. {
  193082. const int result = fcntl (internal, F_SETLK, &fl);
  193083. if (result >= 0)
  193084. {
  193085. ++reentrancyLevel;
  193086. return true;
  193087. }
  193088. if (errno != EINTR)
  193089. {
  193090. if (timeOutMillisecs == 0
  193091. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  193092. break;
  193093. Thread::sleep (10);
  193094. }
  193095. }
  193096. return false;
  193097. }
  193098. void InterProcessLock::exit()
  193099. {
  193100. if (reentrancyLevel > 0 && internal != 0)
  193101. {
  193102. --reentrancyLevel;
  193103. struct flock fl;
  193104. zerostruct (fl);
  193105. fl.l_whence = SEEK_SET;
  193106. fl.l_type = F_UNLCK;
  193107. for (;;)
  193108. {
  193109. const int result = fcntl (internal, F_SETLKW, &fl);
  193110. if (result >= 0 || errno != EINTR)
  193111. break;
  193112. }
  193113. }
  193114. }
  193115. /*** End of inlined file: juce_posix_SharedCode.h ***/
  193116. /*** Start of inlined file: juce_linux_Files.cpp ***/
  193117. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193118. // compiled on its own).
  193119. #if JUCE_INCLUDED_FILE
  193120. #define U_ISOFS_SUPER_MAGIC (short) 0x9660 // linux/iso_fs.h
  193121. #define U_MSDOS_SUPER_MAGIC (short) 0x4d44 // linux/msdos_fs.h
  193122. #define U_NFS_SUPER_MAGIC (short) 0x6969 // linux/nfs_fs.h
  193123. #define U_SMB_SUPER_MAGIC (short) 0x517B // linux/smb_fs.h
  193124. void juce_getFileTimes (const String& fileName,
  193125. int64& modificationTime,
  193126. int64& accessTime,
  193127. int64& creationTime)
  193128. {
  193129. modificationTime = 0;
  193130. accessTime = 0;
  193131. creationTime = 0;
  193132. struct stat info;
  193133. const int res = stat (fileName.toUTF8(), &info);
  193134. if (res == 0)
  193135. {
  193136. modificationTime = (int64) info.st_mtime * 1000;
  193137. accessTime = (int64) info.st_atime * 1000;
  193138. creationTime = (int64) info.st_ctime * 1000;
  193139. }
  193140. }
  193141. bool juce_setFileTimes (const String& fileName,
  193142. int64 modificationTime,
  193143. int64 accessTime,
  193144. int64 creationTime)
  193145. {
  193146. struct utimbuf times;
  193147. times.actime = (time_t) (accessTime / 1000);
  193148. times.modtime = (time_t) (modificationTime / 1000);
  193149. return utime (fileName.toUTF8(), &times) == 0;
  193150. }
  193151. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  193152. {
  193153. struct stat info;
  193154. const int res = stat (fileName.toUTF8(), &info);
  193155. if (res != 0)
  193156. return false;
  193157. info.st_mode &= 0777; // Just permissions
  193158. if( isReadOnly )
  193159. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  193160. else
  193161. // Give everybody write permission?
  193162. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  193163. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  193164. }
  193165. bool juce_copyFile (const String& s, const String& d)
  193166. {
  193167. const File source (s), dest (d);
  193168. FileInputStream* in = source.createInputStream();
  193169. bool ok = false;
  193170. if (in != 0)
  193171. {
  193172. if (dest.deleteFile())
  193173. {
  193174. FileOutputStream* const out = dest.createOutputStream();
  193175. if (out != 0)
  193176. {
  193177. const int bytesCopied = out->writeFromInputStream (*in, -1);
  193178. delete out;
  193179. ok = (bytesCopied == source.getSize());
  193180. if (! ok)
  193181. dest.deleteFile();
  193182. }
  193183. }
  193184. delete in;
  193185. }
  193186. return ok;
  193187. }
  193188. const StringArray juce_getFileSystemRoots()
  193189. {
  193190. StringArray s;
  193191. s.add (T("/"));
  193192. return s;
  193193. }
  193194. bool File::isOnCDRomDrive() const
  193195. {
  193196. struct statfs buf;
  193197. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193198. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  193199. // Assume not if this fails for some reason
  193200. return false;
  193201. }
  193202. bool File::isOnHardDisk() const
  193203. {
  193204. struct statfs buf;
  193205. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193206. {
  193207. switch (buf.f_type)
  193208. {
  193209. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  193210. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  193211. case U_NFS_SUPER_MAGIC: // Network NFS
  193212. case U_SMB_SUPER_MAGIC: // Network Samba
  193213. return false;
  193214. default:
  193215. // Assume anything else is a hard-disk (but note it could
  193216. // be a RAM disk. There isn't a good way of determining
  193217. // this for sure)
  193218. return true;
  193219. }
  193220. }
  193221. // Assume so if this fails for some reason
  193222. return true;
  193223. }
  193224. bool File::isOnRemovableDrive() const
  193225. {
  193226. jassertfalse // xxx not implemented for linux!
  193227. return false;
  193228. }
  193229. bool File::isHidden() const
  193230. {
  193231. return getFileName().startsWithChar (T('.'));
  193232. }
  193233. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  193234. const File File::getSpecialLocation (const SpecialLocationType type)
  193235. {
  193236. switch (type)
  193237. {
  193238. case userHomeDirectory:
  193239. {
  193240. const char* homeDir = getenv ("HOME");
  193241. if (homeDir == 0)
  193242. {
  193243. struct passwd* const pw = getpwuid (getuid());
  193244. if (pw != 0)
  193245. homeDir = pw->pw_dir;
  193246. }
  193247. return File (String::fromUTF8 (homeDir));
  193248. }
  193249. case userDocumentsDirectory:
  193250. case userMusicDirectory:
  193251. case userMoviesDirectory:
  193252. case userApplicationDataDirectory:
  193253. return File ("~");
  193254. case userDesktopDirectory:
  193255. return File ("~/Desktop");
  193256. case commonApplicationDataDirectory:
  193257. return File ("/var");
  193258. case globalApplicationsDirectory:
  193259. return File ("/usr");
  193260. case tempDirectory:
  193261. {
  193262. File tmp ("/var/tmp");
  193263. if (! tmp.isDirectory())
  193264. {
  193265. tmp = T("/tmp");
  193266. if (! tmp.isDirectory())
  193267. tmp = File::getCurrentWorkingDirectory();
  193268. }
  193269. return tmp;
  193270. }
  193271. case invokedExecutableFile:
  193272. if (juce_Argv0 != 0)
  193273. return File (String::fromUTF8 (juce_Argv0));
  193274. // deliberate fall-through...
  193275. case currentExecutableFile:
  193276. case currentApplicationFile:
  193277. return juce_getExecutableFile();
  193278. default:
  193279. jassertfalse // unknown type?
  193280. break;
  193281. }
  193282. return File::nonexistent;
  193283. }
  193284. const String File::getVersion() const
  193285. {
  193286. return String::empty; // xxx not yet implemented
  193287. }
  193288. const File File::getLinkedTarget() const
  193289. {
  193290. char buffer [4096];
  193291. size_t numChars = readlink (getFullPathName().toUTF8(),
  193292. buffer, sizeof (buffer));
  193293. if (numChars > 0 && numChars <= sizeof (buffer))
  193294. return File (String::fromUTF8 (buffer, (int) numChars));
  193295. return *this;
  193296. }
  193297. bool File::moveToTrash() const
  193298. {
  193299. if (! exists())
  193300. return true;
  193301. File trashCan (T("~/.Trash"));
  193302. if (! trashCan.isDirectory())
  193303. trashCan = T("~/.local/share/Trash/files");
  193304. if (! trashCan.isDirectory())
  193305. return false;
  193306. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193307. getFileExtension()));
  193308. }
  193309. struct FindFileStruct
  193310. {
  193311. String parentDir, wildCard;
  193312. DIR* dir;
  193313. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193314. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193315. {
  193316. const char* const wildcardUTF8 = wildCard.toUTF8();
  193317. for (;;)
  193318. {
  193319. struct dirent* const de = readdir (dir);
  193320. if (de == 0)
  193321. break;
  193322. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193323. {
  193324. result = String::fromUTF8 (de->d_name);
  193325. const String path (parentDir + result);
  193326. if (isDir != 0 || fileSize != 0)
  193327. {
  193328. struct stat info;
  193329. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193330. if (isDir != 0)
  193331. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193332. if (isHidden != 0)
  193333. *isHidden = (de->d_name[0] == '.');
  193334. if (fileSize != 0)
  193335. *fileSize = statOk ? info.st_size : 0;
  193336. }
  193337. if (modTime != 0 || creationTime != 0)
  193338. {
  193339. int64 m, a, c;
  193340. juce_getFileTimes (path, m, a, c);
  193341. if (modTime != 0)
  193342. *modTime = m;
  193343. if (creationTime != 0)
  193344. *creationTime = c;
  193345. }
  193346. if (isReadOnly != 0)
  193347. *isReadOnly = ! juce_canWriteToFile (path);
  193348. return true;
  193349. }
  193350. }
  193351. return false;
  193352. }
  193353. };
  193354. // returns 0 on failure
  193355. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193356. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193357. Time* creationTime, bool* isReadOnly)
  193358. {
  193359. DIR* d = opendir (directory.toUTF8());
  193360. if (d != 0)
  193361. {
  193362. FindFileStruct* ff = new FindFileStruct();
  193363. ff->parentDir = directory;
  193364. if (!ff->parentDir.endsWithChar (File::separator))
  193365. ff->parentDir += File::separator;
  193366. ff->wildCard = wildCard;
  193367. if (wildCard == T("*.*"))
  193368. ff->wildCard = T("*");
  193369. ff->dir = d;
  193370. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193371. {
  193372. return ff;
  193373. }
  193374. else
  193375. {
  193376. firstResultFile = String::empty;
  193377. isDir = false;
  193378. isHidden = false;
  193379. closedir (d);
  193380. delete ff;
  193381. }
  193382. }
  193383. return 0;
  193384. }
  193385. bool juce_findFileNext (void* handle, String& resultFile,
  193386. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193387. {
  193388. FindFileStruct* const ff = (FindFileStruct*) handle;
  193389. if (ff != 0)
  193390. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193391. return false;
  193392. }
  193393. void juce_findFileClose (void* handle)
  193394. {
  193395. FindFileStruct* const ff = (FindFileStruct*) handle;
  193396. if (ff != 0)
  193397. {
  193398. closedir (ff->dir);
  193399. delete ff;
  193400. }
  193401. }
  193402. bool juce_launchFile (const String& fileName,
  193403. const String& parameters)
  193404. {
  193405. String cmdString (fileName.replace (T(" "), T("\\ "),false));
  193406. cmdString << " " << parameters;
  193407. if (URL::isProbablyAWebsiteURL (fileName)
  193408. || cmdString.startsWithIgnoreCase (T("file:"))
  193409. || URL::isProbablyAnEmailAddress (fileName))
  193410. {
  193411. // create a command that tries to launch a bunch of likely browsers
  193412. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193413. StringArray cmdLines;
  193414. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193415. cmdLines.add (String (browserNames[i]) + T(" ") + cmdString.trim().quoted());
  193416. cmdString = cmdLines.joinIntoString (T(" || "));
  193417. }
  193418. const char* const argv[4] = { "/bin/sh", "-c", (const char*) cmdString.toUTF8(), 0 };
  193419. const int cpid = fork();
  193420. if (cpid == 0)
  193421. {
  193422. setsid();
  193423. // Child process
  193424. execve (argv[0], (char**) argv, environ);
  193425. exit (0);
  193426. }
  193427. return cpid >= 0;
  193428. }
  193429. void File::revealToUser() const
  193430. {
  193431. if (isDirectory())
  193432. startAsProcess();
  193433. else if (getParentDirectory().exists())
  193434. getParentDirectory().startAsProcess();
  193435. }
  193436. #endif
  193437. /*** End of inlined file: juce_linux_Files.cpp ***/
  193438. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  193439. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193440. // compiled on its own).
  193441. #if JUCE_INCLUDED_FILE
  193442. struct NamedPipeInternal
  193443. {
  193444. String pipeInName, pipeOutName;
  193445. int pipeIn, pipeOut;
  193446. bool volatile createdPipe, blocked, stopReadOperation;
  193447. static void signalHandler (int) {}
  193448. };
  193449. void NamedPipe::cancelPendingReads()
  193450. {
  193451. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193452. {
  193453. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193454. intern->stopReadOperation = true;
  193455. char buffer [1] = { 0 };
  193456. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193457. (void) bytesWritten;
  193458. int timeout = 2000;
  193459. while (intern->blocked && --timeout >= 0)
  193460. Thread::sleep (2);
  193461. intern->stopReadOperation = false;
  193462. }
  193463. }
  193464. void NamedPipe::close()
  193465. {
  193466. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193467. if (intern != 0)
  193468. {
  193469. internal = 0;
  193470. if (intern->pipeIn != -1)
  193471. ::close (intern->pipeIn);
  193472. if (intern->pipeOut != -1)
  193473. ::close (intern->pipeOut);
  193474. if (intern->createdPipe)
  193475. {
  193476. unlink (intern->pipeInName.toUTF8());
  193477. unlink (intern->pipeOutName.toUTF8());
  193478. }
  193479. delete intern;
  193480. }
  193481. }
  193482. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193483. {
  193484. close();
  193485. NamedPipeInternal* const intern = new NamedPipeInternal();
  193486. internal = intern;
  193487. intern->createdPipe = createPipe;
  193488. intern->blocked = false;
  193489. intern->stopReadOperation = false;
  193490. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193491. siginterrupt (SIGPIPE, 1);
  193492. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  193493. intern->pipeInName = pipePath + T("_in");
  193494. intern->pipeOutName = pipePath + T("_out");
  193495. intern->pipeIn = -1;
  193496. intern->pipeOut = -1;
  193497. if (createPipe)
  193498. {
  193499. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  193500. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  193501. {
  193502. delete intern;
  193503. internal = 0;
  193504. return false;
  193505. }
  193506. }
  193507. return true;
  193508. }
  193509. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193510. {
  193511. int bytesRead = -1;
  193512. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193513. if (intern != 0)
  193514. {
  193515. intern->blocked = true;
  193516. if (intern->pipeIn == -1)
  193517. {
  193518. if (intern->createdPipe)
  193519. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  193520. else
  193521. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  193522. if (intern->pipeIn == -1)
  193523. {
  193524. intern->blocked = false;
  193525. return -1;
  193526. }
  193527. }
  193528. bytesRead = 0;
  193529. char* p = (char*) destBuffer;
  193530. while (bytesRead < maxBytesToRead)
  193531. {
  193532. const int bytesThisTime = maxBytesToRead - bytesRead;
  193533. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  193534. if (numRead <= 0 || intern->stopReadOperation)
  193535. {
  193536. bytesRead = -1;
  193537. break;
  193538. }
  193539. bytesRead += numRead;
  193540. p += bytesRead;
  193541. }
  193542. intern->blocked = false;
  193543. }
  193544. return bytesRead;
  193545. }
  193546. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  193547. {
  193548. int bytesWritten = -1;
  193549. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193550. if (intern != 0)
  193551. {
  193552. if (intern->pipeOut == -1)
  193553. {
  193554. if (intern->createdPipe)
  193555. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  193556. else
  193557. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  193558. if (intern->pipeOut == -1)
  193559. {
  193560. return -1;
  193561. }
  193562. }
  193563. const char* p = (const char*) sourceBuffer;
  193564. bytesWritten = 0;
  193565. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  193566. while (bytesWritten < numBytesToWrite
  193567. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  193568. {
  193569. const int bytesThisTime = numBytesToWrite - bytesWritten;
  193570. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  193571. if (numWritten <= 0)
  193572. {
  193573. bytesWritten = -1;
  193574. break;
  193575. }
  193576. bytesWritten += numWritten;
  193577. p += bytesWritten;
  193578. }
  193579. }
  193580. return bytesWritten;
  193581. }
  193582. #endif
  193583. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  193584. /*** Start of inlined file: juce_linux_Network.cpp ***/
  193585. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193586. // compiled on its own).
  193587. #if JUCE_INCLUDED_FILE
  193588. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  193589. {
  193590. int numResults = 0;
  193591. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  193592. if (s != -1)
  193593. {
  193594. char buf [1024];
  193595. struct ifconf ifc;
  193596. ifc.ifc_len = sizeof (buf);
  193597. ifc.ifc_buf = buf;
  193598. ioctl (s, SIOCGIFCONF, &ifc);
  193599. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  193600. {
  193601. struct ifreq ifr;
  193602. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  193603. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  193604. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  193605. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  193606. && numResults < maxNum)
  193607. {
  193608. int64 a = 0;
  193609. for (int j = 6; --j >= 0;)
  193610. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  193611. *addresses++ = a;
  193612. ++numResults;
  193613. }
  193614. }
  193615. close (s);
  193616. }
  193617. return numResults;
  193618. }
  193619. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  193620. const String& emailSubject,
  193621. const String& bodyText,
  193622. const StringArray& filesToAttach)
  193623. {
  193624. jassertfalse // xxx todo
  193625. return false;
  193626. }
  193627. class JUCE_HTTPSocketStream
  193628. {
  193629. public:
  193630. JUCE_HTTPSocketStream()
  193631. : readPosition (0),
  193632. socketHandle (-1),
  193633. levelsOfRedirection (0),
  193634. timeoutSeconds (15)
  193635. {
  193636. }
  193637. ~JUCE_HTTPSocketStream()
  193638. {
  193639. closeSocket();
  193640. }
  193641. bool open (const String& url,
  193642. const String& headers,
  193643. const MemoryBlock& postData,
  193644. const bool isPost,
  193645. URL::OpenStreamProgressCallback* callback,
  193646. void* callbackContext,
  193647. int timeOutMs)
  193648. {
  193649. closeSocket();
  193650. uint32 timeOutTime = Time::getMillisecondCounter();
  193651. if (timeOutMs == 0)
  193652. timeOutTime += 60000;
  193653. else if (timeOutMs < 0)
  193654. timeOutTime = 0xffffffff;
  193655. else
  193656. timeOutTime += timeOutMs;
  193657. String hostName, hostPath;
  193658. int hostPort;
  193659. if (! decomposeURL (url, hostName, hostPath, hostPort))
  193660. return false;
  193661. const struct hostent* host = 0;
  193662. int port = 0;
  193663. String proxyName, proxyPath;
  193664. int proxyPort = 0;
  193665. String proxyURL (getenv ("http_proxy"));
  193666. if (proxyURL.startsWithIgnoreCase (T("http://")))
  193667. {
  193668. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193669. return false;
  193670. host = gethostbyname ((const char*) proxyName.toUTF8());
  193671. port = proxyPort;
  193672. }
  193673. else
  193674. {
  193675. host = gethostbyname ((const char*) hostName.toUTF8());
  193676. port = hostPort;
  193677. }
  193678. if (host == 0)
  193679. return false;
  193680. struct sockaddr_in address;
  193681. zerostruct (address);
  193682. memcpy ((void*) &address.sin_addr, (const void*) host->h_addr, host->h_length);
  193683. address.sin_family = host->h_addrtype;
  193684. address.sin_port = htons (port);
  193685. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193686. if (socketHandle == -1)
  193687. return false;
  193688. int receiveBufferSize = 16384;
  193689. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193690. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193691. #if JUCE_MAC
  193692. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  193693. #endif
  193694. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  193695. {
  193696. closeSocket();
  193697. return false;
  193698. }
  193699. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  193700. proxyName, proxyPort,
  193701. hostPath, url,
  193702. headers, postData,
  193703. isPost));
  193704. size_t totalHeaderSent = 0;
  193705. while (totalHeaderSent < requestHeader.getSize())
  193706. {
  193707. if (Time::getMillisecondCounter() > timeOutTime)
  193708. {
  193709. closeSocket();
  193710. return false;
  193711. }
  193712. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  193713. if (send (socketHandle,
  193714. ((const char*) requestHeader.getData()) + totalHeaderSent,
  193715. numToSend, 0)
  193716. != numToSend)
  193717. {
  193718. closeSocket();
  193719. return false;
  193720. }
  193721. totalHeaderSent += numToSend;
  193722. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  193723. {
  193724. closeSocket();
  193725. return false;
  193726. }
  193727. }
  193728. const String responseHeader (readResponse (timeOutTime));
  193729. if (responseHeader.isNotEmpty())
  193730. {
  193731. //DBG (responseHeader);
  193732. StringArray lines;
  193733. lines.addLines (responseHeader);
  193734. // NB - using charToString() here instead of just T(" "), because that was
  193735. // causing a mysterious gcc internal compiler error...
  193736. const int statusCode = responseHeader.fromFirstOccurrenceOf (String::charToString (T(' ')), false, false)
  193737. .substring (0, 3).getIntValue();
  193738. //int contentLength = findHeaderItem (lines, T("Content-Length:")).getIntValue();
  193739. //bool isChunked = findHeaderItem (lines, T("Transfer-Encoding:")).equalsIgnoreCase ("chunked");
  193740. String location (findHeaderItem (lines, T("Location:")));
  193741. if (statusCode >= 300 && statusCode < 400
  193742. && location.isNotEmpty())
  193743. {
  193744. if (! location.startsWithIgnoreCase (T("http://")))
  193745. location = T("http://") + location;
  193746. if (levelsOfRedirection++ < 3)
  193747. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  193748. }
  193749. else
  193750. {
  193751. levelsOfRedirection = 0;
  193752. return true;
  193753. }
  193754. }
  193755. closeSocket();
  193756. return false;
  193757. }
  193758. int read (void* buffer, int bytesToRead)
  193759. {
  193760. fd_set readbits;
  193761. FD_ZERO (&readbits);
  193762. FD_SET (socketHandle, &readbits);
  193763. struct timeval tv;
  193764. tv.tv_sec = timeoutSeconds;
  193765. tv.tv_usec = 0;
  193766. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193767. return 0; // (timeout)
  193768. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  193769. readPosition += bytesRead;
  193770. return bytesRead;
  193771. }
  193772. int readPosition;
  193773. juce_UseDebuggingNewOperator
  193774. private:
  193775. int socketHandle, levelsOfRedirection;
  193776. const int timeoutSeconds;
  193777. void closeSocket()
  193778. {
  193779. if (socketHandle >= 0)
  193780. close (socketHandle);
  193781. socketHandle = -1;
  193782. }
  193783. const MemoryBlock createRequestHeader (const String& hostName,
  193784. const int hostPort,
  193785. const String& proxyName,
  193786. const int proxyPort,
  193787. const String& hostPath,
  193788. const String& originalURL,
  193789. const String& headers,
  193790. const MemoryBlock& postData,
  193791. const bool isPost)
  193792. {
  193793. String header (isPost ? "POST " : "GET ");
  193794. if (proxyName.isEmpty())
  193795. {
  193796. header << hostPath << " HTTP/1.0\r\nHost: "
  193797. << hostName << ':' << hostPort;
  193798. }
  193799. else
  193800. {
  193801. header << originalURL << " HTTP/1.0\r\nHost: "
  193802. << proxyName << ':' << proxyPort;
  193803. }
  193804. header << "\r\nUser-Agent: JUCE/"
  193805. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  193806. << "\r\nConnection: Close\r\nContent-Length: "
  193807. << postData.getSize() << "\r\n"
  193808. << headers << "\r\n";
  193809. MemoryBlock mb;
  193810. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  193811. mb.append (postData.getData(), postData.getSize());
  193812. return mb;
  193813. }
  193814. const String readResponse (const uint32 timeOutTime)
  193815. {
  193816. int bytesRead = 0, numConsecutiveLFs = 0;
  193817. MemoryBlock buffer (1024, true);
  193818. while (numConsecutiveLFs < 2 && bytesRead < 32768
  193819. && Time::getMillisecondCounter() <= timeOutTime)
  193820. {
  193821. fd_set readbits;
  193822. FD_ZERO (&readbits);
  193823. FD_SET (socketHandle, &readbits);
  193824. struct timeval tv;
  193825. tv.tv_sec = timeoutSeconds;
  193826. tv.tv_usec = 0;
  193827. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193828. return String::empty; // (timeout)
  193829. buffer.ensureSize (bytesRead + 8, true);
  193830. char* const dest = (char*) buffer.getData() + bytesRead;
  193831. if (recv (socketHandle, dest, 1, 0) == -1)
  193832. return String::empty;
  193833. const char lastByte = *dest;
  193834. ++bytesRead;
  193835. if (lastByte == '\n')
  193836. ++numConsecutiveLFs;
  193837. else if (lastByte != '\r')
  193838. numConsecutiveLFs = 0;
  193839. }
  193840. const String header (String::fromUTF8 ((const char*) buffer.getData()));
  193841. if (header.startsWithIgnoreCase (T("HTTP/")))
  193842. return header.trimEnd();
  193843. return String::empty;
  193844. }
  193845. static bool decomposeURL (const String& url,
  193846. String& host, String& path, int& port)
  193847. {
  193848. if (! url.startsWithIgnoreCase (T("http://")))
  193849. return false;
  193850. const int nextSlash = url.indexOfChar (7, '/');
  193851. int nextColon = url.indexOfChar (7, ':');
  193852. if (nextColon > nextSlash && nextSlash > 0)
  193853. nextColon = -1;
  193854. if (nextColon >= 0)
  193855. {
  193856. host = url.substring (7, nextColon);
  193857. if (nextSlash >= 0)
  193858. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  193859. else
  193860. port = url.substring (nextColon + 1).getIntValue();
  193861. }
  193862. else
  193863. {
  193864. port = 80;
  193865. if (nextSlash >= 0)
  193866. host = url.substring (7, nextSlash);
  193867. else
  193868. host = url.substring (7);
  193869. }
  193870. if (nextSlash >= 0)
  193871. path = url.substring (nextSlash);
  193872. else
  193873. path = T("/");
  193874. return true;
  193875. }
  193876. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  193877. {
  193878. for (int i = 0; i < lines.size(); ++i)
  193879. if (lines[i].startsWithIgnoreCase (itemName))
  193880. return lines[i].substring (itemName.length()).trim();
  193881. return String::empty;
  193882. }
  193883. };
  193884. bool juce_isOnLine()
  193885. {
  193886. return true;
  193887. }
  193888. void* juce_openInternetFile (const String& url,
  193889. const String& headers,
  193890. const MemoryBlock& postData,
  193891. const bool isPost,
  193892. URL::OpenStreamProgressCallback* callback,
  193893. void* callbackContext,
  193894. int timeOutMs)
  193895. {
  193896. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  193897. if (s->open (url, headers, postData, isPost,
  193898. callback, callbackContext, timeOutMs))
  193899. return s;
  193900. delete s;
  193901. return 0;
  193902. }
  193903. void juce_closeInternetFile (void* handle)
  193904. {
  193905. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193906. if (s != 0)
  193907. delete s;
  193908. }
  193909. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  193910. {
  193911. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193912. if (s != 0)
  193913. return s->read (buffer, bytesToRead);
  193914. return 0;
  193915. }
  193916. int64 juce_getInternetFileContentLength (void* handle)
  193917. {
  193918. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193919. if (s != 0)
  193920. {
  193921. //xxx todo
  193922. jassertfalse
  193923. }
  193924. return -1;
  193925. }
  193926. int juce_seekInInternetFile (void* handle, int newPosition)
  193927. {
  193928. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193929. if (s != 0)
  193930. return s->readPosition;
  193931. return 0;
  193932. }
  193933. #endif
  193934. /*** End of inlined file: juce_linux_Network.cpp ***/
  193935. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  193936. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193937. // compiled on its own).
  193938. #if JUCE_INCLUDED_FILE
  193939. void Logger::outputDebugString (const String& text) throw()
  193940. {
  193941. fputs (text.toUTF8(), stdout);
  193942. fputs ("\n", stdout);
  193943. }
  193944. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  193945. {
  193946. String text;
  193947. va_list args;
  193948. va_start (args, format);
  193949. text.vprintf(format, args);
  193950. outputDebugString(text);
  193951. }
  193952. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  193953. {
  193954. return Linux;
  193955. }
  193956. const String SystemStats::getOperatingSystemName() throw()
  193957. {
  193958. return T("Linux");
  193959. }
  193960. bool SystemStats::isOperatingSystem64Bit() throw()
  193961. {
  193962. #if JUCE_64BIT
  193963. return true;
  193964. #else
  193965. //xxx not sure how to find this out?..
  193966. return false;
  193967. #endif
  193968. }
  193969. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  193970. {
  193971. String info;
  193972. char buf [256];
  193973. FILE* f = fopen ("/proc/cpuinfo", "r");
  193974. while (f != 0 && fgets (buf, sizeof(buf), f))
  193975. {
  193976. if (strncmp (buf, key, strlen (key)) == 0)
  193977. {
  193978. char* p = buf;
  193979. while (*p && *p != '\n')
  193980. ++p;
  193981. if (*p != 0)
  193982. *p = 0;
  193983. p = buf;
  193984. while (*p != 0 && *p != ':')
  193985. ++p;
  193986. if (*p != 0 && *(p + 1) != 0)
  193987. info = p + 2;
  193988. if (! lastOne)
  193989. break;
  193990. }
  193991. }
  193992. fclose (f);
  193993. return info;
  193994. }
  193995. bool SystemStats::hasMMX() throw()
  193996. {
  193997. return getCpuInfo ("flags").contains (T("mmx"));
  193998. }
  193999. bool SystemStats::hasSSE() throw()
  194000. {
  194001. return getCpuInfo ("flags").contains (T("sse"));
  194002. }
  194003. bool SystemStats::hasSSE2() throw()
  194004. {
  194005. return getCpuInfo ("flags").contains (T("sse2"));
  194006. }
  194007. bool SystemStats::has3DNow() throw()
  194008. {
  194009. return getCpuInfo ("flags").contains (T("3dnow"));
  194010. }
  194011. const String SystemStats::getCpuVendor() throw()
  194012. {
  194013. return getCpuInfo ("vendor_id");
  194014. }
  194015. int SystemStats::getCpuSpeedInMegaherz() throw()
  194016. {
  194017. const String speed (getCpuInfo ("cpu MHz"));
  194018. return (int) (speed.getFloatValue() + 0.5f);
  194019. }
  194020. int SystemStats::getMemorySizeInMegabytes() throw()
  194021. {
  194022. struct sysinfo sysi;
  194023. if (sysinfo (&sysi) == 0)
  194024. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  194025. return 0;
  194026. }
  194027. uint32 juce_millisecondsSinceStartup() throw()
  194028. {
  194029. static unsigned int calibrate = 0;
  194030. static bool calibrated = false;
  194031. timeval t;
  194032. unsigned int ret = 0;
  194033. if (! gettimeofday (&t, 0))
  194034. {
  194035. if (! calibrated)
  194036. {
  194037. struct sysinfo sysi;
  194038. if (sysinfo (&sysi) == 0)
  194039. // Safe to assume system was not brought up earlier than 1970!
  194040. calibrate = t.tv_sec - sysi.uptime;
  194041. calibrated = true;
  194042. }
  194043. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  194044. }
  194045. return ret;
  194046. }
  194047. double Time::getMillisecondCounterHiRes() throw()
  194048. {
  194049. return getHighResolutionTicks() * 0.001;
  194050. }
  194051. int64 Time::getHighResolutionTicks() throw()
  194052. {
  194053. timeval t;
  194054. if (gettimeofday (&t, 0))
  194055. return 0;
  194056. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  194057. }
  194058. int64 Time::getHighResolutionTicksPerSecond() throw()
  194059. {
  194060. // Microseconds
  194061. return 1000000;
  194062. }
  194063. bool Time::setSystemTimeToThisTime() const throw()
  194064. {
  194065. timeval t;
  194066. t.tv_sec = millisSinceEpoch % 1000000;
  194067. t.tv_usec = millisSinceEpoch - t.tv_sec;
  194068. return settimeofday (&t, NULL) ? false : true;
  194069. }
  194070. int SystemStats::getPageSize() throw()
  194071. {
  194072. static int systemPageSize = 0;
  194073. if (systemPageSize == 0)
  194074. systemPageSize = sysconf (_SC_PAGESIZE);
  194075. return systemPageSize;
  194076. }
  194077. int SystemStats::getNumCpus() throw()
  194078. {
  194079. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  194080. return lastCpu + 1;
  194081. }
  194082. const String SystemStats::getLogonName()
  194083. {
  194084. const char* user = getenv ("USER");
  194085. if (user == 0)
  194086. {
  194087. struct passwd* const pw = getpwuid (getuid());
  194088. if (pw != 0)
  194089. user = pw->pw_name;
  194090. }
  194091. return String::fromUTF8 (user);
  194092. }
  194093. const String SystemStats::getFullUserName()
  194094. {
  194095. return getLogonName();
  194096. }
  194097. void SystemStats::initialiseStats() throw()
  194098. {
  194099. // Process starts off as root when running suid
  194100. Process::lowerPrivilege();
  194101. String s (SystemStats::getJUCEVersion());
  194102. }
  194103. void PlatformUtilities::fpuReset()
  194104. {
  194105. }
  194106. #endif
  194107. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  194108. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  194109. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194110. // compiled on its own).
  194111. #if JUCE_INCLUDED_FILE
  194112. void JUCE_API juce_threadEntryPoint (void*);
  194113. void* threadEntryProc (void* value)
  194114. {
  194115. // New threads start off as root when running suid
  194116. Process::lowerPrivilege();
  194117. juce_threadEntryPoint (value);
  194118. return 0;
  194119. }
  194120. void* juce_createThread (void* userData)
  194121. {
  194122. pthread_t handle = 0;
  194123. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  194124. {
  194125. pthread_detach (handle);
  194126. return (void*)handle;
  194127. }
  194128. return 0;
  194129. }
  194130. void juce_killThread (void* handle)
  194131. {
  194132. if (handle != 0)
  194133. pthread_cancel ((pthread_t)handle);
  194134. }
  194135. void juce_setCurrentThreadName (const String& /*name*/)
  194136. {
  194137. }
  194138. Thread::ThreadID Thread::getCurrentThreadId()
  194139. {
  194140. return (ThreadID) pthread_self();
  194141. }
  194142. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  194143. // priority of the current thread
  194144. bool juce_setThreadPriority (void* handle, int priority)
  194145. {
  194146. struct sched_param param;
  194147. int policy, maxp, minp, pri;
  194148. if (handle == 0)
  194149. handle = (void*) pthread_self();
  194150. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  194151. && policy != SCHED_OTHER)
  194152. {
  194153. minp = sched_get_priority_min(policy);
  194154. maxp = sched_get_priority_max(policy);
  194155. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  194156. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  194157. // Realtime process priority
  194158. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  194159. else
  194160. // High process priority
  194161. param.__sched_priority = minp + pri;
  194162. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  194163. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  194164. }
  194165. return false;
  194166. }
  194167. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  194168. {
  194169. #if SUPPORT_AFFINITIES
  194170. cpu_set_t affinity;
  194171. CPU_ZERO (&affinity);
  194172. for (int i = 0; i < 32; ++i)
  194173. if ((affinityMask & (1 << i)) != 0)
  194174. CPU_SET (i, &affinity);
  194175. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  194176. sched_yield();
  194177. #else
  194178. /* affinities aren't supported because either the appropriate header files weren't found,
  194179. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  194180. */
  194181. jassertfalse
  194182. #endif
  194183. }
  194184. void Thread::yield()
  194185. {
  194186. sched_yield();
  194187. }
  194188. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  194189. void Process::setPriority (ProcessPriority prior)
  194190. {
  194191. struct sched_param param;
  194192. int policy, maxp, minp;
  194193. const int p = (int) prior;
  194194. if (p <= 1)
  194195. policy = SCHED_OTHER;
  194196. else
  194197. policy = SCHED_RR;
  194198. minp = sched_get_priority_min (policy);
  194199. maxp = sched_get_priority_max (policy);
  194200. if (p < 2)
  194201. param.__sched_priority = 0;
  194202. else if (p == 2 )
  194203. // Set to middle of lower realtime priority range
  194204. param.__sched_priority = minp + (maxp - minp) / 4;
  194205. else
  194206. // Set to middle of higher realtime priority range
  194207. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  194208. pthread_setschedparam (pthread_self(), policy, &param);
  194209. }
  194210. void Process::terminate()
  194211. {
  194212. exit (0);
  194213. }
  194214. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  194215. {
  194216. static char testResult = 0;
  194217. if (testResult == 0)
  194218. {
  194219. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  194220. if (testResult >= 0)
  194221. {
  194222. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  194223. testResult = 1;
  194224. }
  194225. }
  194226. return testResult < 0;
  194227. }
  194228. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  194229. {
  194230. return juce_isRunningUnderDebugger();
  194231. }
  194232. void Process::raisePrivilege()
  194233. {
  194234. // If running suid root, change effective user
  194235. // to root
  194236. if (geteuid() != 0 && getuid() == 0)
  194237. {
  194238. setreuid (geteuid(), getuid());
  194239. setregid (getegid(), getgid());
  194240. }
  194241. }
  194242. void Process::lowerPrivilege()
  194243. {
  194244. // If runing suid root, change effective user
  194245. // back to real user
  194246. if (geteuid() == 0 && getuid() != 0)
  194247. {
  194248. setreuid (geteuid(), getuid());
  194249. setregid (getegid(), getgid());
  194250. }
  194251. }
  194252. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194253. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  194254. {
  194255. return dlopen ((const char*) name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  194256. }
  194257. void PlatformUtilities::freeDynamicLibrary (void* handle)
  194258. {
  194259. dlclose(handle);
  194260. }
  194261. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  194262. {
  194263. return dlsym (libraryHandle, procedureName.toCString());
  194264. }
  194265. #endif
  194266. #endif
  194267. /*** End of inlined file: juce_linux_Threads.cpp ***/
  194268. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194269. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  194270. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194271. // compiled on its own).
  194272. #if JUCE_INCLUDED_FILE
  194273. #ifdef JUCE_DEBUG
  194274. #define JUCE_DEBUG_XERRORS 1
  194275. #endif
  194276. extern Display* display;
  194277. extern Window juce_messageWindowHandle;
  194278. static String localClipboardContent;
  194279. static Atom atom_UTF8_STRING;
  194280. static Atom atom_CLIPBOARD;
  194281. static Atom atom_TARGETS;
  194282. static void initSelectionAtoms()
  194283. {
  194284. static bool isInitialised = false;
  194285. if (! isInitialised)
  194286. {
  194287. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  194288. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  194289. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  194290. }
  194291. }
  194292. // Read the content of a window property as either a locale-dependent string or an utf8 string
  194293. // works only for strings shorter than 1000000 bytes
  194294. static String juce_readWindowProperty (Window window, Atom prop,
  194295. Atom fmt, // XA_STRING or UTF8_STRING
  194296. bool deleteAfterReading)
  194297. {
  194298. String returnData;
  194299. char* clipData;
  194300. Atom actualType;
  194301. int actualFormat;
  194302. unsigned long numItems, bytesLeft;
  194303. if (XGetWindowProperty (display, window, prop,
  194304. 0L /* offset */, 1000000 /* length (max) */, False,
  194305. AnyPropertyType /* format */,
  194306. &actualType, &actualFormat, &numItems, &bytesLeft,
  194307. (unsigned char**) &clipData) == Success)
  194308. {
  194309. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  194310. {
  194311. returnData = String::fromUTF8 (clipData, numItems);
  194312. }
  194313. else if (actualType == XA_STRING && actualFormat == 8)
  194314. {
  194315. returnData = String (clipData, numItems);
  194316. }
  194317. if (clipData != 0)
  194318. XFree (clipData);
  194319. jassert (bytesLeft == 0 || numItems == 1000000);
  194320. }
  194321. if (deleteAfterReading)
  194322. XDeleteProperty (display, window, prop);
  194323. return returnData;
  194324. }
  194325. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194326. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194327. {
  194328. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194329. // The selection owner will be asked to set the JUCE_SEL property on the
  194330. // juce_messageWindowHandle with the selection content
  194331. XConvertSelection (display, selection, requested_format, property_name,
  194332. juce_messageWindowHandle, CurrentTime);
  194333. int timeoutMs = 200; // will wait at most for 200 ms
  194334. do
  194335. {
  194336. XEvent event;
  194337. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194338. {
  194339. if (event.xselection.property == property_name)
  194340. {
  194341. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194342. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194343. event.xselection.property,
  194344. requested_format, true);
  194345. return true;
  194346. }
  194347. else
  194348. {
  194349. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194350. }
  194351. }
  194352. // not very elegant.. we could do a select() or something like that...
  194353. // however clipboard content requesting is inherently slow on x11, it
  194354. // often takes 50ms or more so...
  194355. Thread::sleep (4);
  194356. timeoutMs -= 4;
  194357. }
  194358. while (timeoutMs > 0);
  194359. DBG("timeout for juce_requestSelectionContent");
  194360. return false;
  194361. }
  194362. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194363. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194364. {
  194365. initSelectionAtoms();
  194366. // the selection content is sent to the target window as a window property
  194367. XSelectionEvent reply;
  194368. reply.type = SelectionNotify;
  194369. reply.display = evt.display;
  194370. reply.requestor = evt.requestor;
  194371. reply.selection = evt.selection;
  194372. reply.target = evt.target;
  194373. reply.property = None; // == "fail"
  194374. reply.time = evt.time;
  194375. HeapBlock <char> data;
  194376. int propertyFormat = 0, numDataItems = 0;
  194377. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194378. {
  194379. if (evt.target == XA_STRING)
  194380. {
  194381. // format data according to system locale
  194382. numDataItems = localClipboardContent.getNumBytesAsCString() + 1;
  194383. data.calloc (numDataItems + 1);
  194384. localClipboardContent.copyToCString (data, numDataItems);
  194385. propertyFormat = 8; // bits/item
  194386. }
  194387. else if (evt.target == atom_UTF8_STRING)
  194388. {
  194389. // translate to utf8
  194390. numDataItems = localClipboardContent.getNumBytesAsUTF8() + 1;
  194391. data.calloc (numDataItems + 1);
  194392. localClipboardContent.copyToUTF8 (data, numDataItems);
  194393. propertyFormat = 8; // bits/item
  194394. }
  194395. else if (evt.target == atom_TARGETS)
  194396. {
  194397. // another application wants to know what we are able to send
  194398. numDataItems = 2;
  194399. propertyFormat = 32; // atoms are 32-bit
  194400. data.calloc (numDataItems * 4);
  194401. Atom* atoms = reinterpret_cast<Atom*> (data.getData());
  194402. atoms[0] = atom_UTF8_STRING;
  194403. atoms[1] = XA_STRING;
  194404. }
  194405. }
  194406. else
  194407. {
  194408. DBG ("requested unsupported clipboard");
  194409. }
  194410. if (data != 0)
  194411. {
  194412. const int maxReasonableSelectionSize = 1000000;
  194413. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194414. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194415. {
  194416. XChangeProperty (evt.display, evt.requestor,
  194417. evt.property, evt.target,
  194418. propertyFormat /* 8 or 32 */, PropModeReplace,
  194419. reinterpret_cast<const unsigned char*> (data.getData()), numDataItems);
  194420. reply.property = evt.property; // " == success"
  194421. }
  194422. }
  194423. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194424. }
  194425. void SystemClipboard::copyTextToClipboard (const String& clipText) throw()
  194426. {
  194427. initSelectionAtoms();
  194428. localClipboardContent = clipText;
  194429. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194430. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194431. }
  194432. const String SystemClipboard::getTextFromClipboard() throw()
  194433. {
  194434. initSelectionAtoms();
  194435. String content;
  194436. Atom selection = XA_PRIMARY;
  194437. Window selectionOwner = None;
  194438. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194439. {
  194440. selection = atom_CLIPBOARD;
  194441. selectionOwner = XGetSelectionOwner (display, selection);
  194442. }
  194443. if (selectionOwner != None)
  194444. {
  194445. if (selectionOwner == juce_messageWindowHandle)
  194446. {
  194447. content = localClipboardContent;
  194448. }
  194449. else
  194450. {
  194451. // first try: we want an utf8 string
  194452. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194453. if (! ok)
  194454. {
  194455. // second chance, ask for a good old locale-dependent string ..
  194456. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194457. }
  194458. }
  194459. }
  194460. return content;
  194461. }
  194462. #endif
  194463. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  194464. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  194465. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194466. // compiled on its own).
  194467. #if JUCE_INCLUDED_FILE
  194468. #ifdef JUCE_DEBUG
  194469. #define JUCE_DEBUG_XERRORS 1
  194470. #endif
  194471. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194472. Window juce_messageWindowHandle = None;
  194473. #define SpecialAtom "JUCESpecialAtom"
  194474. #define BroadcastAtom "JUCEBroadcastAtom"
  194475. #define SpecialCallbackAtom "JUCESpecialCallbackAtom"
  194476. static Atom specialId;
  194477. static Atom broadcastId;
  194478. static Atom specialCallbackId;
  194479. // This is referenced from Windowing.cpp
  194480. XContext improbableNumber;
  194481. // Defined in Windowing.cpp
  194482. extern void juce_windowMessageReceive (XEvent* event);
  194483. // Defined in Clipboard.cpp
  194484. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt);
  194485. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194486. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194487. class InternalMessageQueue
  194488. {
  194489. public:
  194490. InternalMessageQueue()
  194491. : bytesInSocket (0)
  194492. {
  194493. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194494. (void) ret; jassert (ret == 0);
  194495. //setNonBlocking (fd[0]);
  194496. //setNonBlocking (fd[1]);
  194497. }
  194498. ~InternalMessageQueue()
  194499. {
  194500. close (fd[0]);
  194501. close (fd[1]);
  194502. }
  194503. void postMessage (Message* msg)
  194504. {
  194505. const int maxBytesInSocketQueue = 128;
  194506. ScopedLock sl (lock);
  194507. queue.add (msg);
  194508. if (bytesInSocket < maxBytesInSocketQueue)
  194509. {
  194510. ++bytesInSocket;
  194511. ScopedUnlock ul (lock);
  194512. const unsigned char x = 0xff;
  194513. size_t bytesWritten = write (fd[0], &x, 1);
  194514. (void) bytesWritten;
  194515. }
  194516. }
  194517. bool isEmpty() const
  194518. {
  194519. ScopedLock sl (lock);
  194520. return queue.size() == 0;
  194521. }
  194522. Message* popNextMessage()
  194523. {
  194524. ScopedLock sl (lock);
  194525. if (bytesInSocket > 0)
  194526. {
  194527. --bytesInSocket;
  194528. ScopedUnlock ul (lock);
  194529. unsigned char x;
  194530. size_t numBytes = read (fd[1], &x, 1);
  194531. (void) numBytes;
  194532. }
  194533. Message* m = queue[0];
  194534. queue.remove (0, false /* deleteObject */);
  194535. return m;
  194536. }
  194537. int getWaitHandle() const { return fd[1]; }
  194538. private:
  194539. CriticalSection lock;
  194540. OwnedArray <Message> queue;
  194541. int fd[2];
  194542. int bytesInSocket;
  194543. static bool setNonBlocking (int handle)
  194544. {
  194545. int socketFlags = fcntl (handle, F_GETFL, 0);
  194546. if (socketFlags == -1)
  194547. return false;
  194548. socketFlags |= O_NONBLOCK;
  194549. return fcntl (handle, F_SETFL, socketFlags) == 0;
  194550. }
  194551. };
  194552. struct MessageThreadFuncCall
  194553. {
  194554. enum { uniqueID = 0x73774623 };
  194555. MessageCallbackFunction* func;
  194556. void* parameter;
  194557. void* result;
  194558. CriticalSection lock;
  194559. WaitableEvent event;
  194560. };
  194561. static InternalMessageQueue* juce_internalMessageQueue = 0;
  194562. // error handling in X11
  194563. static bool errorOccurred = false;
  194564. static bool keyboardBreakOccurred = false;
  194565. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  194566. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  194567. // Usually happens when client-server connection is broken
  194568. static int ioErrorHandler (Display* display)
  194569. {
  194570. DBG (T("ERROR: connection to X server broken.. terminating."));
  194571. errorOccurred = true;
  194572. if (JUCEApplication::getInstance() != 0)
  194573. Process::terminate();
  194574. return 0;
  194575. }
  194576. // A protocol error has occurred
  194577. static int errorHandler (Display* display, XErrorEvent* event)
  194578. {
  194579. #ifdef JUCE_DEBUG_XERRORS
  194580. char errorStr[64] = { 0 };
  194581. char requestStr[64] = { 0 };
  194582. XGetErrorText (display, event->error_code, errorStr, 64);
  194583. XGetErrorDatabaseText (display, "XRequest", String (event->request_code).toCString(),
  194584. "Unknown", requestStr, 64);
  194585. DBG (T("ERROR: X returned ") + String (errorStr) + T(" for operation ") + String (requestStr));
  194586. #endif
  194587. return 0;
  194588. }
  194589. // Breakin from keyboard
  194590. static void signalHandler (int sig)
  194591. {
  194592. if (sig == SIGINT)
  194593. {
  194594. keyboardBreakOccurred = true;
  194595. return;
  194596. }
  194597. static bool reentrant = false;
  194598. if (! reentrant)
  194599. {
  194600. reentrant = true;
  194601. // Illegal instruction
  194602. fflush (stdout);
  194603. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  194604. errorOccurred = true;
  194605. if (JUCEApplication::getInstance() != 0)
  194606. Process::terminate();
  194607. }
  194608. else
  194609. {
  194610. if (JUCEApplication::getInstance() != 0)
  194611. exit(0);
  194612. }
  194613. }
  194614. void MessageManager::doPlatformSpecificInitialisation()
  194615. {
  194616. // Initialise xlib for multiple thread support
  194617. static bool initThreadCalled = false;
  194618. if (! initThreadCalled)
  194619. {
  194620. if (! XInitThreads())
  194621. {
  194622. // This is fatal! Print error and closedown
  194623. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  194624. if (JUCEApplication::getInstance() != 0)
  194625. Process::terminate();
  194626. return;
  194627. }
  194628. initThreadCalled = true;
  194629. }
  194630. // This is called if the client/server connection is broken
  194631. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  194632. // This is called if a protocol error occurs
  194633. oldErrorHandler = XSetErrorHandler (errorHandler);
  194634. // Install signal handler for break-in
  194635. struct sigaction saction;
  194636. sigset_t maskSet;
  194637. sigemptyset (&maskSet);
  194638. saction.sa_handler = signalHandler;
  194639. saction.sa_mask = maskSet;
  194640. saction.sa_flags = 0;
  194641. sigaction (SIGINT, &saction, NULL);
  194642. #ifndef _DEBUG
  194643. // Setup signal handlers for various fatal errors
  194644. sigaction (SIGILL, &saction, NULL);
  194645. sigaction (SIGBUS, &saction, NULL);
  194646. sigaction (SIGFPE, &saction, NULL);
  194647. sigaction (SIGSEGV, &saction, NULL);
  194648. sigaction (SIGSYS, &saction, NULL);
  194649. #endif
  194650. // Create the internal message queue
  194651. juce_internalMessageQueue = new InternalMessageQueue();
  194652. // Try to connect to a display
  194653. String displayName (getenv ("DISPLAY"));
  194654. if (displayName.isEmpty())
  194655. displayName = ":0.0";
  194656. display = XOpenDisplay (displayName.toCString());
  194657. if (display == 0)
  194658. {
  194659. // This is not fatal! we can run headless.
  194660. return;
  194661. }
  194662. // Get defaults for various properties
  194663. int screen = DefaultScreen (display);
  194664. Window root = RootWindow (display, screen);
  194665. Visual* visual = DefaultVisual (display, screen);
  194666. // Create atoms for our ClientMessages (these cannot be deleted)
  194667. specialId = XInternAtom (display, SpecialAtom, false);
  194668. broadcastId = XInternAtom (display, BroadcastAtom, false);
  194669. specialCallbackId = XInternAtom (display, SpecialCallbackAtom, false);
  194670. // Create a context to store user data associated with Windows we
  194671. // create in WindowDriver
  194672. improbableNumber = XUniqueContext();
  194673. // We're only interested in client messages for this window
  194674. // which are always sent
  194675. XSetWindowAttributes swa;
  194676. swa.event_mask = NoEventMask;
  194677. // Create our message window (this will never be mapped)
  194678. juce_messageWindowHandle = XCreateWindow (display, root,
  194679. 0, 0, 1, 1, 0, 0, InputOnly,
  194680. visual, CWEventMask, &swa);
  194681. }
  194682. void MessageManager::doPlatformSpecificShutdown()
  194683. {
  194684. deleteAndZero (juce_internalMessageQueue);
  194685. if (display != 0 && ! errorOccurred)
  194686. {
  194687. XDestroyWindow (display, juce_messageWindowHandle);
  194688. XCloseDisplay (display);
  194689. // reset pointers
  194690. juce_messageWindowHandle = 0;
  194691. display = 0;
  194692. // Restore original error handlers
  194693. XSetIOErrorHandler (oldIOErrorHandler);
  194694. oldIOErrorHandler = 0;
  194695. XSetErrorHandler (oldErrorHandler);
  194696. oldErrorHandler = 0;
  194697. }
  194698. }
  194699. bool juce_postMessageToSystemQueue (void* message)
  194700. {
  194701. if (errorOccurred)
  194702. return false;
  194703. juce_internalMessageQueue->postMessage ((Message*) message);
  194704. return true;
  194705. }
  194706. void MessageManager::broadcastMessage (const String& value) throw()
  194707. {
  194708. }
  194709. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  194710. void* parameter)
  194711. {
  194712. if (errorOccurred)
  194713. return 0;
  194714. if (! isThisTheMessageThread())
  194715. {
  194716. MessageThreadFuncCall messageCallContext;
  194717. messageCallContext.func = func;
  194718. messageCallContext.parameter = parameter;
  194719. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  194720. 0, 0, &messageCallContext));
  194721. // Wait for it to complete before continuing
  194722. messageCallContext.event.wait();
  194723. return messageCallContext.result;
  194724. }
  194725. else
  194726. {
  194727. // Just call the function directly
  194728. return func (parameter);
  194729. }
  194730. }
  194731. // Wait for an event (either XEvent, or an internal Message)
  194732. static bool juce_sleepUntilEvent (const int timeoutMs)
  194733. {
  194734. if (! juce_internalMessageQueue->isEmpty())
  194735. return true;
  194736. if (display != 0)
  194737. {
  194738. ScopedXLock xlock;
  194739. if (XPending (display))
  194740. return true;
  194741. }
  194742. struct timeval tv;
  194743. tv.tv_sec = 0;
  194744. tv.tv_usec = timeoutMs * 1000;
  194745. int fd0 = juce_internalMessageQueue->getWaitHandle();
  194746. int fdmax = fd0;
  194747. fd_set readset;
  194748. FD_ZERO (&readset);
  194749. FD_SET (fd0, &readset);
  194750. if (display != 0)
  194751. {
  194752. ScopedXLock xlock;
  194753. int fd1 = XConnectionNumber (display);
  194754. FD_SET (fd1, &readset);
  194755. fdmax = jmax (fd0, fd1);
  194756. }
  194757. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  194758. return (ret > 0); // ret <= 0 if error or timeout
  194759. }
  194760. // Handle next XEvent (if any)
  194761. static bool juce_dispatchNextXEvent()
  194762. {
  194763. if (display == 0)
  194764. return false;
  194765. XEvent evt;
  194766. {
  194767. ScopedXLock xlock;
  194768. if (! XPending (display))
  194769. return false;
  194770. XNextEvent (display, &evt);
  194771. }
  194772. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  194773. {
  194774. juce_handleSelectionRequest (evt.xselectionrequest);
  194775. }
  194776. else if (evt.xany.window != juce_messageWindowHandle)
  194777. {
  194778. juce_windowMessageReceive (&evt);
  194779. }
  194780. return true;
  194781. }
  194782. // Handle next internal Message (if any)
  194783. static bool juce_dispatchNextInternalMessage()
  194784. {
  194785. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  194786. if (msg == 0)
  194787. return false;
  194788. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  194789. {
  194790. // Handle callback message
  194791. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  194792. call->result = (*(call->func)) (call->parameter);
  194793. call->event.signal();
  194794. }
  194795. else
  194796. {
  194797. // Handle "normal" messages
  194798. MessageManager::getInstance()->deliverMessage (msg.release());
  194799. }
  194800. return true;
  194801. }
  194802. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  194803. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  194804. {
  194805. for (;;)
  194806. {
  194807. if (errorOccurred)
  194808. break;
  194809. if (keyboardBreakOccurred)
  194810. {
  194811. errorOccurred = true;
  194812. if (JUCEApplication::getInstance() != 0)
  194813. Process::terminate();
  194814. break;
  194815. }
  194816. static int totalEventCount = 0;
  194817. ++totalEventCount;
  194818. // The purpose here is to give either priority to XEvents or
  194819. // to internal messages This is necessary to keep a "good"
  194820. // behaviour when the cpu is overloaded
  194821. if (totalEventCount & 1)
  194822. {
  194823. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  194824. return true;
  194825. }
  194826. else
  194827. {
  194828. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  194829. return true;
  194830. }
  194831. if (returnIfNoPendingMessages) // early exit
  194832. break;
  194833. // the timeout is to be on the safe side, but it does not seem to be useful
  194834. juce_sleepUntilEvent (2000);
  194835. }
  194836. return false;
  194837. }
  194838. #endif
  194839. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  194840. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  194841. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194842. // compiled on its own).
  194843. #if JUCE_INCLUDED_FILE
  194844. class FreeTypeFontFace
  194845. {
  194846. public:
  194847. enum FontStyle
  194848. {
  194849. Plain = 0,
  194850. Bold = 1,
  194851. Italic = 2
  194852. };
  194853. struct FontNameIndex
  194854. {
  194855. String fileName;
  194856. int faceIndex;
  194857. };
  194858. FreeTypeFontFace (const String& familyName) throw()
  194859. : hasSerif (false),
  194860. monospaced (false)
  194861. {
  194862. family = familyName;
  194863. }
  194864. void setFileName (const String& name, const int faceIndex, FontStyle style) throw()
  194865. {
  194866. if (names [(int) style].fileName.isEmpty())
  194867. {
  194868. names [(int) style].fileName = name;
  194869. names [(int) style].faceIndex = faceIndex;
  194870. }
  194871. }
  194872. const String& getFamilyName() const throw() { return family; }
  194873. const String& getFileName (const int style, int& faceIndex) const throw()
  194874. {
  194875. faceIndex = names[style].faceIndex;
  194876. return names[style].fileName;
  194877. }
  194878. void setMonospaced (bool mono) throw() { monospaced = mono; }
  194879. bool getMonospaced() const throw() { return monospaced; }
  194880. void setSerif (const bool serif) throw() { hasSerif = serif; }
  194881. bool getSerif() const throw() { return hasSerif; }
  194882. private:
  194883. String family;
  194884. FontNameIndex names[4];
  194885. bool hasSerif, monospaced;
  194886. };
  194887. class FreeTypeInterface : public DeletedAtShutdown
  194888. {
  194889. public:
  194890. FreeTypeInterface() throw()
  194891. : lastFace (0),
  194892. lastBold (false),
  194893. lastItalic (false)
  194894. {
  194895. if (FT_Init_FreeType (&ftLib) != 0)
  194896. {
  194897. ftLib = 0;
  194898. DBG (T("Failed to initialize FreeType"));
  194899. }
  194900. StringArray fontDirs;
  194901. fontDirs.addTokens (String (getenv ("JUCE_FONT_PATH")), T(";,"), 0);
  194902. fontDirs.removeEmptyStrings (true);
  194903. if (fontDirs.size() == 0)
  194904. {
  194905. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  194906. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  194907. if (fontsInfo != 0)
  194908. {
  194909. forEachXmlChildElementWithTagName (*fontsInfo, e, T("dir"))
  194910. {
  194911. fontDirs.add (e->getAllSubText().trim());
  194912. }
  194913. delete fontsInfo;
  194914. }
  194915. }
  194916. if (fontDirs.size() == 0)
  194917. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  194918. for (int i = 0; i < fontDirs.size(); ++i)
  194919. enumerateFaces (fontDirs[i]);
  194920. }
  194921. ~FreeTypeInterface() throw()
  194922. {
  194923. if (lastFace != 0)
  194924. FT_Done_Face (lastFace);
  194925. if (ftLib != 0)
  194926. FT_Done_FreeType (ftLib);
  194927. clearSingletonInstance();
  194928. }
  194929. FreeTypeFontFace* findOrCreate (const String& familyName,
  194930. const bool create = false) throw()
  194931. {
  194932. for (int i = 0; i < faces.size(); i++)
  194933. if (faces[i]->getFamilyName() == familyName)
  194934. return faces[i];
  194935. if (! create)
  194936. return NULL;
  194937. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  194938. faces.add (newFace);
  194939. return newFace;
  194940. }
  194941. // Enumerate all font faces available in a given directory
  194942. void enumerateFaces (const String& path) throw()
  194943. {
  194944. File dirPath (path);
  194945. if (path.isEmpty() || ! dirPath.isDirectory())
  194946. return;
  194947. DirectoryIterator di (dirPath, true);
  194948. while (di.next())
  194949. {
  194950. File possible (di.getFile());
  194951. if (possible.hasFileExtension (T("ttf"))
  194952. || possible.hasFileExtension (T("pfb"))
  194953. || possible.hasFileExtension (T("pcf")))
  194954. {
  194955. FT_Face face;
  194956. int faceIndex = 0;
  194957. int numFaces = 0;
  194958. do
  194959. {
  194960. if (FT_New_Face (ftLib, possible.getFullPathName().toUTF8(),
  194961. faceIndex, &face) == 0)
  194962. {
  194963. if (faceIndex == 0)
  194964. numFaces = face->num_faces;
  194965. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  194966. {
  194967. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  194968. int style = (int) FreeTypeFontFace::Plain;
  194969. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  194970. style |= (int) FreeTypeFontFace::Bold;
  194971. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  194972. style |= (int) FreeTypeFontFace::Italic;
  194973. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  194974. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  194975. // Surely there must be a better way to do this?
  194976. const String name (face->family_name);
  194977. newFace->setSerif (! (name.containsIgnoreCase (T("Sans"))
  194978. || name.containsIgnoreCase (T("Verdana"))
  194979. || name.containsIgnoreCase (T("Arial"))));
  194980. }
  194981. FT_Done_Face (face);
  194982. }
  194983. ++faceIndex;
  194984. }
  194985. while (faceIndex < numFaces);
  194986. }
  194987. }
  194988. }
  194989. // Create a FreeType face object for a given font
  194990. FT_Face createFT_Face (const String& fontName,
  194991. const bool bold,
  194992. const bool italic) throw()
  194993. {
  194994. FT_Face face = 0;
  194995. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  194996. {
  194997. face = lastFace;
  194998. }
  194999. else
  195000. {
  195001. if (lastFace != 0)
  195002. {
  195003. FT_Done_Face (lastFace);
  195004. lastFace = 0;
  195005. }
  195006. lastFontName = fontName;
  195007. lastBold = bold;
  195008. lastItalic = italic;
  195009. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  195010. if (ftFace != 0)
  195011. {
  195012. int style = (int) FreeTypeFontFace::Plain;
  195013. if (bold)
  195014. style |= (int) FreeTypeFontFace::Bold;
  195015. if (italic)
  195016. style |= (int) FreeTypeFontFace::Italic;
  195017. int faceIndex;
  195018. String fileName (ftFace->getFileName (style, faceIndex));
  195019. if (fileName.isEmpty())
  195020. {
  195021. style ^= (int) FreeTypeFontFace::Bold;
  195022. fileName = ftFace->getFileName (style, faceIndex);
  195023. if (fileName.isEmpty())
  195024. {
  195025. style ^= (int) FreeTypeFontFace::Bold;
  195026. style ^= (int) FreeTypeFontFace::Italic;
  195027. fileName = ftFace->getFileName (style, faceIndex);
  195028. if (! fileName.length())
  195029. {
  195030. style ^= (int) FreeTypeFontFace::Bold;
  195031. fileName = ftFace->getFileName (style, faceIndex);
  195032. }
  195033. }
  195034. }
  195035. if (! FT_New_Face (ftLib, fileName.toUTF8(), faceIndex, &lastFace))
  195036. {
  195037. face = lastFace;
  195038. // If there isn't a unicode charmap then select the first one.
  195039. if (FT_Select_Charmap (face, ft_encoding_unicode))
  195040. FT_Set_Charmap (face, face->charmaps[0]);
  195041. }
  195042. }
  195043. }
  195044. return face;
  195045. }
  195046. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character) throw()
  195047. {
  195048. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  195049. const float height = (float) (face->ascender - face->descender);
  195050. const float scaleX = 1.0f / height;
  195051. const float scaleY = -1.0f / height;
  195052. Path destShape;
  195053. #define CONVERTX(val) (scaleX * (val).x)
  195054. #define CONVERTY(val) (scaleY * (val).y)
  195055. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  195056. || face->glyph->format != ft_glyph_format_outline)
  195057. {
  195058. return false;
  195059. }
  195060. const FT_Outline* const outline = &face->glyph->outline;
  195061. const short* const contours = outline->contours;
  195062. const char* const tags = outline->tags;
  195063. FT_Vector* const points = outline->points;
  195064. for (int c = 0; c < outline->n_contours; c++)
  195065. {
  195066. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  195067. const int endPoint = contours[c];
  195068. for (int p = startPoint; p <= endPoint; p++)
  195069. {
  195070. const float x = CONVERTX (points[p]);
  195071. const float y = CONVERTY (points[p]);
  195072. if (p == startPoint)
  195073. {
  195074. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195075. {
  195076. float x2 = CONVERTX (points [endPoint]);
  195077. float y2 = CONVERTY (points [endPoint]);
  195078. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  195079. {
  195080. x2 = (x + x2) * 0.5f;
  195081. y2 = (y + y2) * 0.5f;
  195082. }
  195083. destShape.startNewSubPath (x2, y2);
  195084. }
  195085. else
  195086. {
  195087. destShape.startNewSubPath (x, y);
  195088. }
  195089. }
  195090. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  195091. {
  195092. if (p != startPoint)
  195093. destShape.lineTo (x, y);
  195094. }
  195095. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195096. {
  195097. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  195098. float x2 = CONVERTX (points [nextIndex]);
  195099. float y2 = CONVERTY (points [nextIndex]);
  195100. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  195101. {
  195102. x2 = (x + x2) * 0.5f;
  195103. y2 = (y + y2) * 0.5f;
  195104. }
  195105. else
  195106. {
  195107. ++p;
  195108. }
  195109. destShape.quadraticTo (x, y, x2, y2);
  195110. }
  195111. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  195112. {
  195113. if (p >= endPoint)
  195114. return false;
  195115. const int next1 = p + 1;
  195116. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  195117. const float x2 = CONVERTX (points [next1]);
  195118. const float y2 = CONVERTY (points [next1]);
  195119. const float x3 = CONVERTX (points [next2]);
  195120. const float y3 = CONVERTY (points [next2]);
  195121. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  195122. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  195123. return false;
  195124. destShape.cubicTo (x, y, x2, y2, x3, y3);
  195125. p += 2;
  195126. }
  195127. }
  195128. destShape.closeSubPath();
  195129. }
  195130. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  195131. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  195132. addKerning (face, dest, character, glyphIndex);
  195133. return true;
  195134. }
  195135. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex) throw()
  195136. {
  195137. const float height = (float) (face->ascender - face->descender);
  195138. uint32 rightGlyphIndex;
  195139. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  195140. while (rightGlyphIndex != 0)
  195141. {
  195142. FT_Vector kerning;
  195143. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  195144. {
  195145. if (kerning.x != 0)
  195146. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  195147. }
  195148. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  195149. }
  195150. }
  195151. // Add a glyph to a font
  195152. bool addGlyphToFont (const uint32 character,
  195153. const tchar* fontName, bool bold, bool italic,
  195154. CustomTypeface& dest) throw()
  195155. {
  195156. FT_Face face = createFT_Face (fontName, bold, italic);
  195157. if (face != 0)
  195158. return addGlyph (face, dest, character);
  195159. return false;
  195160. }
  195161. void getFamilyNames (StringArray& familyNames) const throw()
  195162. {
  195163. for (int i = 0; i < faces.size(); i++)
  195164. familyNames.add (faces[i]->getFamilyName());
  195165. }
  195166. void getMonospacedNames (StringArray& monoSpaced) const throw()
  195167. {
  195168. for (int i = 0; i < faces.size(); i++)
  195169. if (faces[i]->getMonospaced())
  195170. monoSpaced.add (faces[i]->getFamilyName());
  195171. }
  195172. void getSerifNames (StringArray& serif) const throw()
  195173. {
  195174. for (int i = 0; i < faces.size(); i++)
  195175. if (faces[i]->getSerif())
  195176. serif.add (faces[i]->getFamilyName());
  195177. }
  195178. void getSansSerifNames (StringArray& sansSerif) const throw()
  195179. {
  195180. for (int i = 0; i < faces.size(); i++)
  195181. if (! faces[i]->getSerif())
  195182. sansSerif.add (faces[i]->getFamilyName());
  195183. }
  195184. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  195185. private:
  195186. FT_Library ftLib;
  195187. FT_Face lastFace;
  195188. String lastFontName;
  195189. bool lastBold, lastItalic;
  195190. OwnedArray<FreeTypeFontFace> faces;
  195191. };
  195192. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  195193. class FreetypeTypeface : public CustomTypeface
  195194. {
  195195. public:
  195196. FreetypeTypeface (const Font& font)
  195197. {
  195198. FT_Face face = FreeTypeInterface::getInstance()
  195199. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  195200. if (face == 0)
  195201. {
  195202. #ifdef JUCE_DEBUG
  195203. String msg (T("Failed to create typeface: "));
  195204. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  195205. DBG (msg);
  195206. #endif
  195207. }
  195208. else
  195209. {
  195210. setCharacteristics (font.getTypefaceName(),
  195211. face->ascender / (float) (face->ascender - face->descender),
  195212. font.isBold(), font.isItalic(),
  195213. L' ');
  195214. }
  195215. }
  195216. bool loadGlyphIfPossible (const juce_wchar character)
  195217. {
  195218. return FreeTypeInterface::getInstance()
  195219. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  195220. }
  195221. };
  195222. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  195223. {
  195224. return new FreetypeTypeface (font);
  195225. }
  195226. const StringArray Font::findAllTypefaceNames() throw()
  195227. {
  195228. StringArray s;
  195229. FreeTypeInterface::getInstance()->getFamilyNames (s);
  195230. s.sort (true);
  195231. return s;
  195232. }
  195233. static const String pickBestFont (const StringArray& names,
  195234. const char* const choicesString)
  195235. {
  195236. StringArray choices;
  195237. choices.addTokens (String (choicesString), T(","), 0);
  195238. choices.trim();
  195239. choices.removeEmptyStrings();
  195240. int i, j;
  195241. for (j = 0; j < choices.size(); ++j)
  195242. if (names.contains (choices[j], true))
  195243. return choices[j];
  195244. for (j = 0; j < choices.size(); ++j)
  195245. for (i = 0; i < names.size(); i++)
  195246. if (names[i].startsWithIgnoreCase (choices[j]))
  195247. return names[i];
  195248. for (j = 0; j < choices.size(); ++j)
  195249. for (i = 0; i < names.size(); i++)
  195250. if (names[i].containsIgnoreCase (choices[j]))
  195251. return names[i];
  195252. return names[0];
  195253. }
  195254. static const String linux_getDefaultSansSerifFontName()
  195255. {
  195256. StringArray allFonts;
  195257. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  195258. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  195259. }
  195260. static const String linux_getDefaultSerifFontName()
  195261. {
  195262. StringArray allFonts;
  195263. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  195264. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  195265. }
  195266. static const String linux_getDefaultMonospacedFontName()
  195267. {
  195268. StringArray allFonts;
  195269. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  195270. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  195271. }
  195272. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  195273. {
  195274. defaultSans = linux_getDefaultSansSerifFontName();
  195275. defaultSerif = linux_getDefaultSerifFontName();
  195276. defaultFixed = linux_getDefaultMonospacedFontName();
  195277. }
  195278. #endif
  195279. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  195280. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  195281. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195282. // compiled on its own).
  195283. #if JUCE_INCLUDED_FILE
  195284. #define TAKE_FOCUS 0
  195285. #define DELETE_WINDOW 1
  195286. #define SYSTEM_TRAY_REQUEST_DOCK 0
  195287. #define SYSTEM_TRAY_BEGIN_MESSAGE 1
  195288. #define SYSTEM_TRAY_CANCEL_MESSAGE 2
  195289. static const int repaintTimerPeriod = 1000 / 100; // 100 fps maximum
  195290. static Atom wm_ChangeState = None;
  195291. static Atom wm_State = None;
  195292. static Atom wm_Protocols = None;
  195293. static Atom wm_ProtocolList [2] = { None, None };
  195294. static Atom wm_ActiveWin = None;
  195295. #define ourDndVersion 3
  195296. static Atom XA_XdndAware = None;
  195297. static Atom XA_XdndEnter = None;
  195298. static Atom XA_XdndLeave = None;
  195299. static Atom XA_XdndPosition = None;
  195300. static Atom XA_XdndStatus = None;
  195301. static Atom XA_XdndDrop = None;
  195302. static Atom XA_XdndFinished = None;
  195303. static Atom XA_XdndSelection = None;
  195304. static Atom XA_XdndProxy = None;
  195305. static Atom XA_XdndTypeList = None;
  195306. static Atom XA_XdndActionList = None;
  195307. static Atom XA_XdndActionDescription = None;
  195308. static Atom XA_XdndActionCopy = None;
  195309. static Atom XA_XdndActionMove = None;
  195310. static Atom XA_XdndActionLink = None;
  195311. static Atom XA_XdndActionAsk = None;
  195312. static Atom XA_XdndActionPrivate = None;
  195313. static Atom XA_JXSelectionWindowProperty = None;
  195314. static Atom XA_MimeTextPlain = None;
  195315. static Atom XA_MimeTextUriList = None;
  195316. static Atom XA_MimeRootDrop = None;
  195317. static XErrorHandler oldHandler = 0;
  195318. static int trappedErrorCode = 0;
  195319. extern "C" int errorTrapHandler (Display* dpy, XErrorEvent* err)
  195320. {
  195321. trappedErrorCode = err->error_code;
  195322. return 0;
  195323. }
  195324. static void trapErrors()
  195325. {
  195326. trappedErrorCode = 0;
  195327. oldHandler = XSetErrorHandler (errorTrapHandler);
  195328. }
  195329. static bool untrapErrors()
  195330. {
  195331. XSetErrorHandler (oldHandler);
  195332. return (trappedErrorCode == 0);
  195333. }
  195334. static bool isActiveApplication = false;
  195335. bool Process::isForegroundProcess()
  195336. {
  195337. return isActiveApplication;
  195338. }
  195339. // These are defined in juce_linux_Messaging.cpp
  195340. extern Display* display;
  195341. extern XContext improbableNumber;
  195342. static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  195343. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  195344. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  195345. enum MouseButtons
  195346. {
  195347. NoButton = 0,
  195348. LeftButton = 1,
  195349. MiddleButton = 2,
  195350. RightButton = 3,
  195351. WheelUp = 4,
  195352. WheelDown = 5
  195353. };
  195354. static int AltMask = 0;
  195355. static int NumLockMask = 0;
  195356. static bool numLock = 0;
  195357. static bool capsLock = 0;
  195358. static char keyStates [32];
  195359. static void updateKeyStates (const int keycode, const bool press) throw()
  195360. {
  195361. const int keybyte = keycode >> 3;
  195362. const int keybit = (1 << (keycode & 7));
  195363. if (press)
  195364. keyStates [keybyte] |= keybit;
  195365. else
  195366. keyStates [keybyte] &= ~keybit;
  195367. }
  195368. static bool keyDown (const int keycode) throw()
  195369. {
  195370. const int keybyte = keycode >> 3;
  195371. const int keybit = (1 << (keycode & 7));
  195372. return (keyStates [keybyte] & keybit) != 0;
  195373. }
  195374. static const int extendedKeyModifier = 0x10000000;
  195375. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  195376. {
  195377. int keysym;
  195378. if (keyCode & extendedKeyModifier)
  195379. {
  195380. keysym = 0xff00 | (keyCode & 0xff);
  195381. }
  195382. else
  195383. {
  195384. keysym = keyCode;
  195385. if (keysym == (XK_Tab & 0xff)
  195386. || keysym == (XK_Return & 0xff)
  195387. || keysym == (XK_Escape & 0xff)
  195388. || keysym == (XK_BackSpace & 0xff))
  195389. {
  195390. keysym |= 0xff00;
  195391. }
  195392. }
  195393. ScopedXLock xlock;
  195394. return keyDown (XKeysymToKeycode (display, keysym));
  195395. }
  195396. #if JUCE_USE_XSHM
  195397. static bool isShmAvailable() throw()
  195398. {
  195399. static bool isChecked = false;
  195400. static bool isAvailable = false;
  195401. if (! isChecked)
  195402. {
  195403. isChecked = true;
  195404. int major, minor;
  195405. Bool pixmaps;
  195406. ScopedXLock xlock;
  195407. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195408. {
  195409. trapErrors();
  195410. XShmSegmentInfo segmentInfo;
  195411. zerostruct (segmentInfo);
  195412. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195413. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195414. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195415. xImage->bytes_per_line * xImage->height,
  195416. IPC_CREAT | 0777)) >= 0)
  195417. {
  195418. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195419. if (segmentInfo.shmaddr != (void*) -1)
  195420. {
  195421. segmentInfo.readOnly = False;
  195422. xImage->data = segmentInfo.shmaddr;
  195423. XSync (display, False);
  195424. if (XShmAttach (display, &segmentInfo) != 0)
  195425. {
  195426. XSync (display, False);
  195427. XShmDetach (display, &segmentInfo);
  195428. isAvailable = true;
  195429. }
  195430. }
  195431. XFlush (display);
  195432. XDestroyImage (xImage);
  195433. shmdt (segmentInfo.shmaddr);
  195434. }
  195435. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195436. isAvailable &= untrapErrors();
  195437. }
  195438. }
  195439. return isAvailable;
  195440. }
  195441. #endif
  195442. #if JUCE_USE_XRENDER
  195443. namespace XRender
  195444. {
  195445. typedef Status (*tXRenderQueryVersion) (Display*, int*, int*);
  195446. typedef XRenderPictFormat* (*tXrenderFindStandardFormat) (Display*, int);
  195447. typedef XRenderPictFormat* (*tXRenderFindFormat) (Display*, unsigned long, XRenderPictFormat*, int);
  195448. typedef XRenderPictFormat* (*tXRenderFindVisualFormat) (Display*, Visual*);
  195449. static tXRenderQueryVersion xRenderQueryVersion = 0;
  195450. static tXrenderFindStandardFormat xRenderFindStandardFormat = 0;
  195451. static tXRenderFindFormat xRenderFindFormat = 0;
  195452. static tXRenderFindVisualFormat xRenderFindVisualFormat = 0;
  195453. static bool isAvailable()
  195454. {
  195455. static bool isChecked = false;
  195456. static bool isAvailable = false;
  195457. if (! isChecked)
  195458. {
  195459. ScopedXLock xlock;
  195460. isChecked = true;
  195461. if (xRenderQueryVersion == 0)
  195462. {
  195463. void* h = dlopen ("libXrender.so", RTLD_GLOBAL | RTLD_NOW);
  195464. if (h != 0)
  195465. {
  195466. xRenderQueryVersion = (tXRenderQueryVersion) dlsym (h, "XRenderQueryVersion");
  195467. xRenderFindStandardFormat = (tXrenderFindStandardFormat) dlsym (h, "XrenderFindStandardFormat");
  195468. xRenderFindFormat = (tXRenderFindFormat) dlsym (h, "XRenderFindFormat");
  195469. xRenderFindVisualFormat = (tXRenderFindVisualFormat) dlsym (h, "XRenderFindVisualFormat");
  195470. }
  195471. }
  195472. if (xRenderQueryVersion != 0
  195473. && xRenderFindStandardFormat != 0
  195474. && xRenderFindFormat != 0
  195475. && xRenderFindVisualFormat != 0)
  195476. {
  195477. int major, minor;
  195478. if (xRenderQueryVersion (display, &major, &minor))
  195479. isAvailable = true;
  195480. }
  195481. }
  195482. return isAvailable;
  195483. }
  195484. static XRenderPictFormat* findPictureFormat()
  195485. {
  195486. ScopedXLock xlock;
  195487. XRenderPictFormat* pictFormat = 0;
  195488. if (isAvailable())
  195489. {
  195490. pictFormat = xRenderFindStandardFormat (display, PictStandardARGB32);
  195491. if (pictFormat == 0)
  195492. {
  195493. XRenderPictFormat desiredFormat;
  195494. desiredFormat.type = PictTypeDirect;
  195495. desiredFormat.depth = 32;
  195496. desiredFormat.direct.alphaMask = 0xff;
  195497. desiredFormat.direct.redMask = 0xff;
  195498. desiredFormat.direct.greenMask = 0xff;
  195499. desiredFormat.direct.blueMask = 0xff;
  195500. desiredFormat.direct.alpha = 24;
  195501. desiredFormat.direct.red = 16;
  195502. desiredFormat.direct.green = 8;
  195503. desiredFormat.direct.blue = 0;
  195504. pictFormat = xRenderFindFormat (display,
  195505. PictFormatType | PictFormatDepth
  195506. | PictFormatRedMask | PictFormatRed
  195507. | PictFormatGreenMask | PictFormatGreen
  195508. | PictFormatBlueMask | PictFormatBlue
  195509. | PictFormatAlphaMask | PictFormatAlpha,
  195510. &desiredFormat,
  195511. 0);
  195512. }
  195513. }
  195514. return pictFormat;
  195515. }
  195516. }
  195517. #endif
  195518. namespace Visuals
  195519. {
  195520. static Visual* findVisualWithDepth (const int desiredDepth) throw()
  195521. {
  195522. ScopedXLock xlock;
  195523. Visual* visual = 0;
  195524. int numVisuals = 0;
  195525. long desiredMask = VisualNoMask;
  195526. XVisualInfo desiredVisual;
  195527. desiredVisual.screen = DefaultScreen (display);
  195528. desiredVisual.depth = desiredDepth;
  195529. desiredMask = VisualScreenMask | VisualDepthMask;
  195530. if (desiredDepth == 32)
  195531. {
  195532. desiredVisual.c_class = TrueColor;
  195533. desiredVisual.red_mask = 0x00FF0000;
  195534. desiredVisual.green_mask = 0x0000FF00;
  195535. desiredVisual.blue_mask = 0x000000FF;
  195536. desiredVisual.bits_per_rgb = 8;
  195537. desiredMask |= VisualClassMask;
  195538. desiredMask |= VisualRedMaskMask;
  195539. desiredMask |= VisualGreenMaskMask;
  195540. desiredMask |= VisualBlueMaskMask;
  195541. desiredMask |= VisualBitsPerRGBMask;
  195542. }
  195543. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195544. desiredMask,
  195545. &desiredVisual,
  195546. &numVisuals);
  195547. if (xvinfos != 0)
  195548. {
  195549. for (int i = 0; i < numVisuals; i++)
  195550. {
  195551. if (xvinfos[i].depth == desiredDepth)
  195552. {
  195553. visual = xvinfos[i].visual;
  195554. break;
  195555. }
  195556. }
  195557. XFree (xvinfos);
  195558. }
  195559. return visual;
  195560. }
  195561. static Visual* findVisualFormat (const int desiredDepth, int& matchedDepth) throw()
  195562. {
  195563. Visual* visual = 0;
  195564. if (desiredDepth == 32)
  195565. {
  195566. #if JUCE_USE_XSHM
  195567. if (isShmAvailable())
  195568. {
  195569. #if JUCE_USE_XRENDER
  195570. if (XRender::isAvailable())
  195571. {
  195572. XRenderPictFormat* pictFormat = XRender::findPictureFormat();
  195573. if (pictFormat != 0)
  195574. {
  195575. int numVisuals = 0;
  195576. XVisualInfo desiredVisual;
  195577. desiredVisual.screen = DefaultScreen (display);
  195578. desiredVisual.depth = 32;
  195579. desiredVisual.bits_per_rgb = 8;
  195580. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195581. VisualScreenMask | VisualDepthMask | VisualBitsPerRGBMask,
  195582. &desiredVisual, &numVisuals);
  195583. if (xvinfos != 0)
  195584. {
  195585. for (int i = 0; i < numVisuals; ++i)
  195586. {
  195587. XRenderPictFormat* pictVisualFormat = XRender::xRenderFindVisualFormat (display, xvinfos[i].visual);
  195588. if (pictVisualFormat != 0
  195589. && pictVisualFormat->type == PictTypeDirect
  195590. && pictVisualFormat->direct.alphaMask)
  195591. {
  195592. visual = xvinfos[i].visual;
  195593. matchedDepth = 32;
  195594. break;
  195595. }
  195596. }
  195597. XFree (xvinfos);
  195598. }
  195599. }
  195600. }
  195601. #endif
  195602. if (visual == 0)
  195603. {
  195604. visual = findVisualWithDepth (32);
  195605. if (visual != 0)
  195606. matchedDepth = 32;
  195607. }
  195608. }
  195609. #endif
  195610. }
  195611. if (visual == 0 && desiredDepth >= 24)
  195612. {
  195613. visual = findVisualWithDepth (24);
  195614. if (visual != 0)
  195615. matchedDepth = 24;
  195616. }
  195617. if (visual == 0 && desiredDepth >= 16)
  195618. {
  195619. visual = findVisualWithDepth (16);
  195620. if (visual != 0)
  195621. matchedDepth = 16;
  195622. }
  195623. return visual;
  195624. }
  195625. }
  195626. class XBitmapImage : public Image
  195627. {
  195628. public:
  195629. XBitmapImage (const PixelFormat format_, const int w, const int h,
  195630. const bool clearImage, const int imageDepth_, Visual* visual)
  195631. : Image (format_, w, h),
  195632. imageDepth (imageDepth_),
  195633. gc (None)
  195634. {
  195635. jassert (format_ == RGB || format_ == ARGB);
  195636. pixelStride = (format_ == RGB) ? 3 : 4;
  195637. lineStride = ((w * pixelStride + 3) & ~3);
  195638. ScopedXLock xlock;
  195639. #if JUCE_USE_XSHM
  195640. usingXShm = false;
  195641. if ((imageDepth > 16) && isShmAvailable())
  195642. {
  195643. zerostruct (segmentInfo);
  195644. segmentInfo.shmid = -1;
  195645. segmentInfo.shmaddr = (char *) -1;
  195646. segmentInfo.readOnly = False;
  195647. xImage = XShmCreateImage (display, visual, imageDepth, ZPixmap, 0, &segmentInfo, w, h);
  195648. if (xImage != 0)
  195649. {
  195650. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195651. xImage->bytes_per_line * xImage->height,
  195652. IPC_CREAT | 0777)) >= 0)
  195653. {
  195654. if (segmentInfo.shmid != -1)
  195655. {
  195656. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195657. if (segmentInfo.shmaddr != (void*) -1)
  195658. {
  195659. segmentInfo.readOnly = False;
  195660. xImage->data = segmentInfo.shmaddr;
  195661. imageData = (uint8*) segmentInfo.shmaddr;
  195662. if (XShmAttach (display, &segmentInfo) != 0)
  195663. {
  195664. usingXShm = true;
  195665. }
  195666. else
  195667. {
  195668. jassertfalse
  195669. }
  195670. }
  195671. else
  195672. {
  195673. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195674. }
  195675. }
  195676. }
  195677. }
  195678. }
  195679. if (! usingXShm)
  195680. #endif
  195681. {
  195682. imageDataAllocated.malloc (lineStride * h);
  195683. imageData = imageDataAllocated;
  195684. if (format_ == ARGB && clearImage)
  195685. zeromem (imageData, h * lineStride);
  195686. xImage = (XImage*) juce_calloc (sizeof (XImage));
  195687. xImage->width = w;
  195688. xImage->height = h;
  195689. xImage->xoffset = 0;
  195690. xImage->format = ZPixmap;
  195691. xImage->data = (char*) imageData;
  195692. xImage->byte_order = ImageByteOrder (display);
  195693. xImage->bitmap_unit = BitmapUnit (display);
  195694. xImage->bitmap_bit_order = BitmapBitOrder (display);
  195695. xImage->bitmap_pad = 32;
  195696. xImage->depth = pixelStride * 8;
  195697. xImage->bytes_per_line = lineStride;
  195698. xImage->bits_per_pixel = pixelStride * 8;
  195699. xImage->red_mask = 0x00FF0000;
  195700. xImage->green_mask = 0x0000FF00;
  195701. xImage->blue_mask = 0x000000FF;
  195702. if (imageDepth == 16)
  195703. {
  195704. const int pixelStride = 2;
  195705. const int lineStride = ((w * pixelStride + 3) & ~3);
  195706. imageData16Bit.malloc (lineStride * h);
  195707. xImage->data = imageData16Bit;
  195708. xImage->bitmap_pad = 16;
  195709. xImage->depth = pixelStride * 8;
  195710. xImage->bytes_per_line = lineStride;
  195711. xImage->bits_per_pixel = pixelStride * 8;
  195712. xImage->red_mask = visual->red_mask;
  195713. xImage->green_mask = visual->green_mask;
  195714. xImage->blue_mask = visual->blue_mask;
  195715. }
  195716. if (! XInitImage (xImage))
  195717. {
  195718. jassertfalse
  195719. }
  195720. }
  195721. }
  195722. ~XBitmapImage()
  195723. {
  195724. ScopedXLock xlock;
  195725. #if JUCE_USE_XSHM
  195726. if (usingXShm)
  195727. {
  195728. XShmDetach (display, &segmentInfo);
  195729. XFlush (display);
  195730. XDestroyImage (xImage);
  195731. shmdt (segmentInfo.shmaddr);
  195732. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195733. }
  195734. else
  195735. #endif
  195736. {
  195737. xImage->data = 0;
  195738. XDestroyImage (xImage);
  195739. }
  195740. }
  195741. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  195742. {
  195743. ScopedXLock xlock;
  195744. if (gc == 0)
  195745. {
  195746. XGCValues gcvalues;
  195747. gcvalues.foreground = None;
  195748. gcvalues.background = None;
  195749. gcvalues.function = GXcopy;
  195750. gcvalues.plane_mask = AllPlanes;
  195751. gcvalues.clip_mask = None;
  195752. gcvalues.graphics_exposures = False;
  195753. gc = XCreateGC (display, window,
  195754. GCBackground | GCForeground | GCFunction | GCPlaneMask | GCClipMask | GCGraphicsExposures,
  195755. &gcvalues);
  195756. }
  195757. if (imageDepth == 16)
  195758. {
  195759. const uint32 rMask = xImage->red_mask;
  195760. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  195761. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  195762. const uint32 gMask = xImage->green_mask;
  195763. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  195764. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  195765. const uint32 bMask = xImage->blue_mask;
  195766. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  195767. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  195768. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  195769. for (int y = sy; y < sy + dh; ++y)
  195770. {
  195771. const uint8* p = srcData.getPixelPointer (sx, y);
  195772. for (int x = sx; x < sx + dw; ++x)
  195773. {
  195774. const PixelRGB* const pixel = (const PixelRGB*) p;
  195775. p += srcData.pixelStride;
  195776. XPutPixel (xImage, x, y,
  195777. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  195778. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  195779. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  195780. }
  195781. }
  195782. }
  195783. // blit results to screen.
  195784. #if JUCE_USE_XSHM
  195785. if (usingXShm)
  195786. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  195787. else
  195788. #endif
  195789. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  195790. }
  195791. juce_UseDebuggingNewOperator
  195792. private:
  195793. XImage* xImage;
  195794. const int imageDepth;
  195795. HeapBlock <char> imageData16Bit;
  195796. GC gc;
  195797. #if JUCE_USE_XSHM
  195798. XShmSegmentInfo segmentInfo;
  195799. bool usingXShm;
  195800. #endif
  195801. static int getShiftNeeded (const uint32 mask) throw()
  195802. {
  195803. for (int i = 32; --i >= 0;)
  195804. if (((mask >> i) & 1) != 0)
  195805. return i - 7;
  195806. jassertfalse
  195807. return 0;
  195808. }
  195809. };
  195810. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195811. class LinuxComponentPeer : public ComponentPeer
  195812. {
  195813. public:
  195814. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  195815. : ComponentPeer (component, windowStyleFlags),
  195816. windowH (0),
  195817. parentWindow (0),
  195818. wx (0),
  195819. wy (0),
  195820. ww (0),
  195821. wh (0),
  195822. taskbarImage (0),
  195823. fullScreen (false),
  195824. mapped (false),
  195825. visual (0),
  195826. depth (0)
  195827. {
  195828. // it's dangerous to create a window on a thread other than the message thread..
  195829. checkMessageManagerIsLocked
  195830. repainter = new LinuxRepaintManager (this);
  195831. createWindow();
  195832. setTitle (component->getName());
  195833. }
  195834. ~LinuxComponentPeer()
  195835. {
  195836. // it's dangerous to delete a window on a thread other than the message thread..
  195837. checkMessageManagerIsLocked
  195838. deleteTaskBarIcon();
  195839. deleteIconPixmaps();
  195840. destroyWindow();
  195841. windowH = 0;
  195842. }
  195843. void* getNativeHandle() const
  195844. {
  195845. return (void*) windowH;
  195846. }
  195847. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  195848. {
  195849. XPointer peer = 0;
  195850. ScopedXLock xlock;
  195851. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  195852. {
  195853. if (peer != 0 && ! ComponentPeer::isValidPeer ((LinuxComponentPeer*) peer))
  195854. peer = 0;
  195855. }
  195856. return (LinuxComponentPeer*) peer;
  195857. }
  195858. void setVisible (bool shouldBeVisible)
  195859. {
  195860. ScopedXLock xlock;
  195861. if (shouldBeVisible)
  195862. XMapWindow (display, windowH);
  195863. else
  195864. XUnmapWindow (display, windowH);
  195865. }
  195866. void setTitle (const String& title)
  195867. {
  195868. setWindowTitle (windowH, title);
  195869. }
  195870. void setPosition (int x, int y)
  195871. {
  195872. setBounds (x, y, ww, wh, false);
  195873. }
  195874. void setSize (int w, int h)
  195875. {
  195876. setBounds (wx, wy, w, h, false);
  195877. }
  195878. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  195879. {
  195880. fullScreen = isNowFullScreen;
  195881. if (windowH != 0)
  195882. {
  195883. Component::SafePointer<Component> deletionChecker (component);
  195884. wx = x;
  195885. wy = y;
  195886. ww = jmax (1, w);
  195887. wh = jmax (1, h);
  195888. ScopedXLock xlock;
  195889. // Make sure the Window manager does what we want
  195890. XSizeHints* hints = XAllocSizeHints();
  195891. hints->flags = USSize | USPosition;
  195892. hints->width = ww;
  195893. hints->height = wh;
  195894. hints->x = wx;
  195895. hints->y = wy;
  195896. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  195897. {
  195898. hints->min_width = hints->max_width = hints->width;
  195899. hints->min_height = hints->max_height = hints->height;
  195900. hints->flags |= PMinSize | PMaxSize;
  195901. }
  195902. XSetWMNormalHints (display, windowH, hints);
  195903. XFree (hints);
  195904. XMoveResizeWindow (display, windowH,
  195905. wx - windowBorder.getLeft(),
  195906. wy - windowBorder.getTop(), ww, wh);
  195907. if (deletionChecker != 0)
  195908. {
  195909. updateBorderSize();
  195910. handleMovedOrResized();
  195911. }
  195912. }
  195913. }
  195914. const Rectangle<int> getBounds() const { return Rectangle<int> (wx, wy, ww, wh); }
  195915. const Point<int> getScreenPosition() const { return Point<int> (wx, wy); }
  195916. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  195917. {
  195918. return relativePosition + getScreenPosition();
  195919. }
  195920. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  195921. {
  195922. return screenPosition - getScreenPosition();
  195923. }
  195924. void setMinimised (bool shouldBeMinimised)
  195925. {
  195926. if (shouldBeMinimised)
  195927. {
  195928. Window root = RootWindow (display, DefaultScreen (display));
  195929. XClientMessageEvent clientMsg;
  195930. clientMsg.display = display;
  195931. clientMsg.window = windowH;
  195932. clientMsg.type = ClientMessage;
  195933. clientMsg.format = 32;
  195934. clientMsg.message_type = wm_ChangeState;
  195935. clientMsg.data.l[0] = IconicState;
  195936. ScopedXLock xlock;
  195937. XSendEvent (display, root, false,
  195938. SubstructureRedirectMask | SubstructureNotifyMask,
  195939. (XEvent*) &clientMsg);
  195940. }
  195941. else
  195942. {
  195943. setVisible (true);
  195944. }
  195945. }
  195946. bool isMinimised() const
  195947. {
  195948. bool minimised = false;
  195949. unsigned char* stateProp;
  195950. unsigned long nitems, bytesLeft;
  195951. Atom actualType;
  195952. int actualFormat;
  195953. ScopedXLock xlock;
  195954. if (XGetWindowProperty (display, windowH, wm_State, 0, 64, False,
  195955. wm_State, &actualType, &actualFormat, &nitems, &bytesLeft,
  195956. &stateProp) == Success
  195957. && actualType == wm_State
  195958. && actualFormat == 32
  195959. && nitems > 0)
  195960. {
  195961. if (((unsigned long*) stateProp)[0] == IconicState)
  195962. minimised = true;
  195963. XFree (stateProp);
  195964. }
  195965. return minimised;
  195966. }
  195967. void setFullScreen (const bool shouldBeFullScreen)
  195968. {
  195969. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  195970. setMinimised (false);
  195971. if (fullScreen != shouldBeFullScreen)
  195972. {
  195973. if (shouldBeFullScreen)
  195974. r = Desktop::getInstance().getMainMonitorArea();
  195975. if (! r.isEmpty())
  195976. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  195977. getComponent()->repaint();
  195978. }
  195979. }
  195980. bool isFullScreen() const
  195981. {
  195982. return fullScreen;
  195983. }
  195984. bool isChildWindowOf (Window possibleParent) const
  195985. {
  195986. Window* windowList = 0;
  195987. uint32 windowListSize = 0;
  195988. Window parent, root;
  195989. ScopedXLock xlock;
  195990. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  195991. {
  195992. if (windowList != 0)
  195993. XFree (windowList);
  195994. return parent == possibleParent;
  195995. }
  195996. return false;
  195997. }
  195998. bool isFrontWindow() const
  195999. {
  196000. Window* windowList = 0;
  196001. uint32 windowListSize = 0;
  196002. bool result = false;
  196003. ScopedXLock xlock;
  196004. Window parent, root = RootWindow (display, DefaultScreen (display));
  196005. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  196006. {
  196007. for (int i = windowListSize; --i >= 0;)
  196008. {
  196009. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  196010. if (peer != 0)
  196011. {
  196012. result = (peer == this);
  196013. break;
  196014. }
  196015. }
  196016. }
  196017. if (windowList != 0)
  196018. XFree (windowList);
  196019. return result;
  196020. }
  196021. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  196022. {
  196023. int x = position.getX();
  196024. int y = position.getY();
  196025. if (((unsigned int) x) >= (unsigned int) ww
  196026. || ((unsigned int) y) >= (unsigned int) wh)
  196027. return false;
  196028. bool inFront = false;
  196029. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  196030. {
  196031. Component* const c = Desktop::getInstance().getComponent (i);
  196032. if (inFront)
  196033. {
  196034. if (c->contains (x + wx - c->getScreenX(),
  196035. y + wy - c->getScreenY()))
  196036. {
  196037. return false;
  196038. }
  196039. }
  196040. else if (c == getComponent())
  196041. {
  196042. inFront = true;
  196043. }
  196044. }
  196045. if (trueIfInAChildWindow)
  196046. return true;
  196047. ::Window root, child;
  196048. unsigned int bw, depth;
  196049. int wx, wy, w, h;
  196050. ScopedXLock xlock;
  196051. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  196052. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  196053. &bw, &depth))
  196054. {
  196055. return false;
  196056. }
  196057. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  196058. return false;
  196059. return child == None;
  196060. }
  196061. const BorderSize getFrameSize() const
  196062. {
  196063. return BorderSize();
  196064. }
  196065. bool setAlwaysOnTop (bool alwaysOnTop)
  196066. {
  196067. if (windowH != 0)
  196068. {
  196069. const bool wasVisible = component->isVisible();
  196070. if (wasVisible)
  196071. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  196072. {
  196073. ScopedXLock xlock;
  196074. XSetWindowAttributes swa;
  196075. swa.override_redirect = alwaysOnTop ? True : False;
  196076. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  196077. }
  196078. if (wasVisible)
  196079. setVisible (true);
  196080. }
  196081. return true;
  196082. }
  196083. void toFront (bool makeActive)
  196084. {
  196085. if (makeActive)
  196086. {
  196087. setVisible (true);
  196088. grabFocus();
  196089. }
  196090. XEvent ev;
  196091. ev.xclient.type = ClientMessage;
  196092. ev.xclient.serial = 0;
  196093. ev.xclient.send_event = True;
  196094. ev.xclient.message_type = wm_ActiveWin;
  196095. ev.xclient.window = windowH;
  196096. ev.xclient.format = 32;
  196097. ev.xclient.data.l[0] = 2;
  196098. ev.xclient.data.l[1] = CurrentTime;
  196099. ev.xclient.data.l[2] = 0;
  196100. ev.xclient.data.l[3] = 0;
  196101. ev.xclient.data.l[4] = 0;
  196102. {
  196103. ScopedXLock xlock;
  196104. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  196105. False,
  196106. SubstructureRedirectMask | SubstructureNotifyMask,
  196107. &ev);
  196108. XWindowAttributes attr;
  196109. XGetWindowAttributes (display, windowH, &attr);
  196110. if (attr.override_redirect)
  196111. XRaiseWindow (display, windowH);
  196112. XSync (display, False);
  196113. }
  196114. handleBroughtToFront();
  196115. }
  196116. void toBehind (ComponentPeer* other)
  196117. {
  196118. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  196119. jassert (otherPeer != 0); // wrong type of window?
  196120. if (otherPeer != 0)
  196121. {
  196122. setMinimised (false);
  196123. Window newStack[] = { otherPeer->windowH, windowH };
  196124. ScopedXLock xlock;
  196125. XRestackWindows (display, newStack, 2);
  196126. }
  196127. }
  196128. bool isFocused() const
  196129. {
  196130. int revert;
  196131. Window focusedWindow = 0;
  196132. ScopedXLock xlock;
  196133. XGetInputFocus (display, &focusedWindow, &revert);
  196134. return focusedWindow == windowH;
  196135. }
  196136. void grabFocus()
  196137. {
  196138. XWindowAttributes atts;
  196139. ScopedXLock xlock;
  196140. if (windowH != 0
  196141. && XGetWindowAttributes (display, windowH, &atts)
  196142. && atts.map_state == IsViewable
  196143. && ! isFocused())
  196144. {
  196145. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  196146. isActiveApplication = true;
  196147. }
  196148. }
  196149. void textInputRequired (const Point<int>&)
  196150. {
  196151. }
  196152. void repaint (int x, int y, int w, int h)
  196153. {
  196154. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  196155. 0, 0,
  196156. getComponent()->getWidth(),
  196157. getComponent()->getHeight()))
  196158. {
  196159. repainter->repaint (x, y, w, h);
  196160. }
  196161. }
  196162. void performAnyPendingRepaintsNow()
  196163. {
  196164. repainter->performAnyPendingRepaintsNow();
  196165. }
  196166. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  196167. {
  196168. ScopedXLock xlock;
  196169. const int width = image.getWidth();
  196170. const int height = image.getHeight();
  196171. HeapBlock <uint32> colour (width * height);
  196172. int index = 0;
  196173. for (int y = 0; y < height; ++y)
  196174. for (int x = 0; x < width; ++x)
  196175. colour[index++] = image.getPixelAt (x, y).getARGB();
  196176. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  196177. 0, reinterpret_cast<char*> (colour.getData()),
  196178. width, height, 32, 0);
  196179. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  196180. width, height, 24);
  196181. GC gc = XCreateGC (display, pixmap, 0, 0);
  196182. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  196183. XFreeGC (display, gc);
  196184. return pixmap;
  196185. }
  196186. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  196187. {
  196188. ScopedXLock xlock;
  196189. const int width = image.getWidth();
  196190. const int height = image.getHeight();
  196191. const int stride = (width + 7) >> 3;
  196192. HeapBlock <uint8> mask;
  196193. mask.calloc (stride * height);
  196194. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  196195. for (int y = 0; y < height; ++y)
  196196. {
  196197. for (int x = 0; x < width; ++x)
  196198. {
  196199. const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  196200. const int offset = y * stride + (x >> 3);
  196201. if (image.getPixelAt (x, y).getAlpha() >= 128)
  196202. mask[offset] |= bit;
  196203. }
  196204. }
  196205. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  196206. reinterpret_cast<char*> (mask.getData()), width, height, 1, 0, 1);
  196207. }
  196208. void setIcon (const Image& newIcon)
  196209. {
  196210. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  196211. HeapBlock <unsigned long> data (dataSize);
  196212. int index = 0;
  196213. data[index++] = newIcon.getWidth();
  196214. data[index++] = newIcon.getHeight();
  196215. for (int y = 0; y < newIcon.getHeight(); ++y)
  196216. for (int x = 0; x < newIcon.getWidth(); ++x)
  196217. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  196218. ScopedXLock xlock;
  196219. XChangeProperty (display, windowH,
  196220. XInternAtom (display, "_NET_WM_ICON", False),
  196221. XA_CARDINAL, 32, PropModeReplace,
  196222. reinterpret_cast<unsigned char*> (data.getData()), dataSize);
  196223. deleteIconPixmaps();
  196224. XWMHints* wmHints = XGetWMHints (display, windowH);
  196225. if (wmHints == 0)
  196226. wmHints = XAllocWMHints();
  196227. wmHints->flags |= IconPixmapHint | IconMaskHint;
  196228. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  196229. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  196230. XSetWMHints (display, windowH, wmHints);
  196231. XFree (wmHints);
  196232. XSync (display, False);
  196233. }
  196234. void deleteIconPixmaps()
  196235. {
  196236. ScopedXLock xlock;
  196237. XWMHints* wmHints = XGetWMHints (display, windowH);
  196238. if (wmHints != 0)
  196239. {
  196240. if ((wmHints->flags & IconPixmapHint) != 0)
  196241. {
  196242. wmHints->flags &= ~IconPixmapHint;
  196243. XFreePixmap (display, wmHints->icon_pixmap);
  196244. }
  196245. if ((wmHints->flags & IconMaskHint) != 0)
  196246. {
  196247. wmHints->flags &= ~IconMaskHint;
  196248. XFreePixmap (display, wmHints->icon_mask);
  196249. }
  196250. XSetWMHints (display, windowH, wmHints);
  196251. XFree (wmHints);
  196252. }
  196253. }
  196254. void handleWindowMessage (XEvent* event)
  196255. {
  196256. switch (event->xany.type)
  196257. {
  196258. case 2: // 'KeyPress'
  196259. {
  196260. ScopedXLock xlock;
  196261. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  196262. updateKeyStates (keyEvent->keycode, true);
  196263. char utf8 [64];
  196264. zeromem (utf8, sizeof (utf8));
  196265. KeySym sym;
  196266. {
  196267. const char* oldLocale = ::setlocale (LC_ALL, 0);
  196268. ::setlocale (LC_ALL, "");
  196269. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  196270. ::setlocale (LC_ALL, oldLocale);
  196271. }
  196272. const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 (utf8, sizeof (utf8) - 1);
  196273. int keyCode = (int) unicodeChar;
  196274. if (keyCode < 0x20)
  196275. keyCode = XKeycodeToKeysym (display, keyEvent->keycode, currentModifiers.isShiftDown() ? 1 : 0);
  196276. const ModifierKeys oldMods (currentModifiers);
  196277. bool keyPressed = false;
  196278. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  196279. if ((sym & 0xff00) == 0xff00)
  196280. {
  196281. // Translate keypad
  196282. if (sym == XK_KP_Divide)
  196283. keyCode = XK_slash;
  196284. else if (sym == XK_KP_Multiply)
  196285. keyCode = XK_asterisk;
  196286. else if (sym == XK_KP_Subtract)
  196287. keyCode = XK_hyphen;
  196288. else if (sym == XK_KP_Add)
  196289. keyCode = XK_plus;
  196290. else if (sym == XK_KP_Enter)
  196291. keyCode = XK_Return;
  196292. else if (sym == XK_KP_Decimal)
  196293. keyCode = numLock ? XK_period : XK_Delete;
  196294. else if (sym == XK_KP_0)
  196295. keyCode = numLock ? XK_0 : XK_Insert;
  196296. else if (sym == XK_KP_1)
  196297. keyCode = numLock ? XK_1 : XK_End;
  196298. else if (sym == XK_KP_2)
  196299. keyCode = numLock ? XK_2 : XK_Down;
  196300. else if (sym == XK_KP_3)
  196301. keyCode = numLock ? XK_3 : XK_Page_Down;
  196302. else if (sym == XK_KP_4)
  196303. keyCode = numLock ? XK_4 : XK_Left;
  196304. else if (sym == XK_KP_5)
  196305. keyCode = XK_5;
  196306. else if (sym == XK_KP_6)
  196307. keyCode = numLock ? XK_6 : XK_Right;
  196308. else if (sym == XK_KP_7)
  196309. keyCode = numLock ? XK_7 : XK_Home;
  196310. else if (sym == XK_KP_8)
  196311. keyCode = numLock ? XK_8 : XK_Up;
  196312. else if (sym == XK_KP_9)
  196313. keyCode = numLock ? XK_9 : XK_Page_Up;
  196314. switch (sym)
  196315. {
  196316. case XK_Left:
  196317. case XK_Right:
  196318. case XK_Up:
  196319. case XK_Down:
  196320. case XK_Page_Up:
  196321. case XK_Page_Down:
  196322. case XK_End:
  196323. case XK_Home:
  196324. case XK_Delete:
  196325. case XK_Insert:
  196326. keyPressed = true;
  196327. keyCode = (sym & 0xff) | extendedKeyModifier;
  196328. break;
  196329. case XK_Tab:
  196330. case XK_Return:
  196331. case XK_Escape:
  196332. case XK_BackSpace:
  196333. keyPressed = true;
  196334. keyCode &= 0xff;
  196335. break;
  196336. default:
  196337. {
  196338. if (sym >= XK_F1 && sym <= XK_F16)
  196339. {
  196340. keyPressed = true;
  196341. keyCode = (sym & 0xff) | extendedKeyModifier;
  196342. }
  196343. break;
  196344. }
  196345. }
  196346. }
  196347. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196348. keyPressed = true;
  196349. if (oldMods != currentModifiers)
  196350. handleModifierKeysChange();
  196351. if (keyDownChange)
  196352. handleKeyUpOrDown (true);
  196353. if (keyPressed)
  196354. handleKeyPress (keyCode, unicodeChar);
  196355. break;
  196356. }
  196357. case KeyRelease:
  196358. {
  196359. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196360. updateKeyStates (keyEvent->keycode, false);
  196361. ScopedXLock xlock;
  196362. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196363. const ModifierKeys oldMods (currentModifiers);
  196364. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196365. if (oldMods != currentModifiers)
  196366. handleModifierKeysChange();
  196367. if (keyDownChange)
  196368. handleKeyUpOrDown (false);
  196369. break;
  196370. }
  196371. case ButtonPress:
  196372. {
  196373. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196374. updateKeyModifiers (buttonPressEvent->state);
  196375. bool buttonMsg = false;
  196376. const int map = pointerMap [buttonPressEvent->button - Button1];
  196377. if (map == WheelUp || map == WheelDown)
  196378. {
  196379. handleMouseWheel (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y),
  196380. getEventTime (buttonPressEvent->time), 0, map == WheelDown ? -84.0f : 84.0f);
  196381. }
  196382. if (map == LeftButton)
  196383. {
  196384. currentModifiers = currentModifiers.withFlags (ModifierKeys::leftButtonModifier);
  196385. buttonMsg = true;
  196386. }
  196387. else if (map == RightButton)
  196388. {
  196389. currentModifiers = currentModifiers.withFlags (ModifierKeys::rightButtonModifier);
  196390. buttonMsg = true;
  196391. }
  196392. else if (map == MiddleButton)
  196393. {
  196394. currentModifiers = currentModifiers.withFlags (ModifierKeys::middleButtonModifier);
  196395. buttonMsg = true;
  196396. }
  196397. if (buttonMsg)
  196398. {
  196399. toFront (true);
  196400. handleMouseEvent (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y), currentModifiers,
  196401. getEventTime (buttonPressEvent->time));
  196402. }
  196403. clearLastMousePos();
  196404. break;
  196405. }
  196406. case ButtonRelease:
  196407. {
  196408. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196409. updateKeyModifiers (buttonRelEvent->state);
  196410. const int map = pointerMap [buttonRelEvent->button - Button1];
  196411. if (map == LeftButton)
  196412. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::leftButtonModifier);
  196413. else if (map == RightButton)
  196414. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::rightButtonModifier);
  196415. else if (map == MiddleButton)
  196416. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::middleButtonModifier);
  196417. handleMouseEvent (0, Point<int> (buttonRelEvent->x, buttonRelEvent->y), currentModifiers,
  196418. getEventTime (buttonRelEvent->time));
  196419. clearLastMousePos();
  196420. break;
  196421. }
  196422. case MotionNotify:
  196423. {
  196424. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196425. updateKeyModifiers (movedEvent->state);
  196426. const Point<int> mousePos (Desktop::getMousePosition());
  196427. if (lastMousePos != mousePos)
  196428. {
  196429. lastMousePos = mousePos;
  196430. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196431. {
  196432. Window wRoot = 0, wParent = 0;
  196433. {
  196434. ScopedXLock xlock;
  196435. unsigned int numChildren;
  196436. Window* wChild = 0;
  196437. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196438. }
  196439. if (wParent != 0
  196440. && wParent != windowH
  196441. && wParent != wRoot)
  196442. {
  196443. parentWindow = wParent;
  196444. updateBounds();
  196445. }
  196446. else
  196447. {
  196448. parentWindow = 0;
  196449. }
  196450. }
  196451. handleMouseEvent (0, mousePos - getScreenPosition(), currentModifiers, getEventTime (movedEvent->time));
  196452. }
  196453. break;
  196454. }
  196455. case EnterNotify:
  196456. {
  196457. clearLastMousePos();
  196458. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196459. if (! currentModifiers.isAnyMouseButtonDown())
  196460. {
  196461. updateKeyModifiers (enterEvent->state);
  196462. handleMouseEvent (0, Point<int> (enterEvent->x, enterEvent->y), currentModifiers, getEventTime (enterEvent->time));
  196463. }
  196464. break;
  196465. }
  196466. case LeaveNotify:
  196467. {
  196468. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196469. // Suppress the normal leave if we've got a pointer grab, or if
  196470. // it's a bogus one caused by clicking a mouse button when running
  196471. // in a Window manager
  196472. if (((! currentModifiers.isAnyMouseButtonDown()) && leaveEvent->mode == NotifyNormal)
  196473. || leaveEvent->mode == NotifyUngrab)
  196474. {
  196475. updateKeyModifiers (leaveEvent->state);
  196476. handleMouseEvent (0, Point<int> (leaveEvent->x, leaveEvent->y), currentModifiers, getEventTime (leaveEvent->time));
  196477. }
  196478. break;
  196479. }
  196480. case FocusIn:
  196481. {
  196482. isActiveApplication = true;
  196483. if (isFocused())
  196484. handleFocusGain();
  196485. break;
  196486. }
  196487. case FocusOut:
  196488. {
  196489. isActiveApplication = false;
  196490. if (! isFocused())
  196491. handleFocusLoss();
  196492. break;
  196493. }
  196494. case Expose:
  196495. {
  196496. // Batch together all pending expose events
  196497. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196498. XEvent nextEvent;
  196499. ScopedXLock xlock;
  196500. if (exposeEvent->window != windowH)
  196501. {
  196502. Window child;
  196503. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196504. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196505. &child);
  196506. }
  196507. repaint (exposeEvent->x, exposeEvent->y,
  196508. exposeEvent->width, exposeEvent->height);
  196509. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196510. {
  196511. XPeekEvent (display, (XEvent*) &nextEvent);
  196512. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196513. break;
  196514. XNextEvent (display, (XEvent*) &nextEvent);
  196515. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196516. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196517. nextExposeEvent->width, nextExposeEvent->height);
  196518. }
  196519. break;
  196520. }
  196521. case CirculateNotify:
  196522. case CreateNotify:
  196523. case DestroyNotify:
  196524. // Think we can ignore these
  196525. break;
  196526. case ConfigureNotify:
  196527. {
  196528. updateBounds();
  196529. updateBorderSize();
  196530. handleMovedOrResized();
  196531. // if the native title bar is dragged, need to tell any active menus, etc.
  196532. if ((styleFlags & windowHasTitleBar) != 0
  196533. && component->isCurrentlyBlockedByAnotherModalComponent())
  196534. {
  196535. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196536. if (currentModalComp != 0)
  196537. currentModalComp->inputAttemptWhenModal();
  196538. }
  196539. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196540. if (confEvent->window == windowH
  196541. && confEvent->above != 0
  196542. && isFrontWindow())
  196543. {
  196544. handleBroughtToFront();
  196545. }
  196546. break;
  196547. }
  196548. case ReparentNotify:
  196549. case GravityNotify:
  196550. {
  196551. parentWindow = 0;
  196552. Window wRoot = 0;
  196553. Window* wChild = 0;
  196554. unsigned int numChildren;
  196555. {
  196556. ScopedXLock xlock;
  196557. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196558. }
  196559. if (parentWindow == windowH || parentWindow == wRoot)
  196560. parentWindow = 0;
  196561. updateBounds();
  196562. updateBorderSize();
  196563. handleMovedOrResized();
  196564. break;
  196565. }
  196566. case MapNotify:
  196567. mapped = true;
  196568. handleBroughtToFront();
  196569. break;
  196570. case UnmapNotify:
  196571. mapped = false;
  196572. break;
  196573. case MappingNotify:
  196574. {
  196575. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196576. if (mappingEvent->request != MappingPointer)
  196577. {
  196578. // Deal with modifier/keyboard mapping
  196579. ScopedXLock xlock;
  196580. XRefreshKeyboardMapping (mappingEvent);
  196581. updateModifierMappings();
  196582. }
  196583. break;
  196584. }
  196585. case ClientMessage:
  196586. {
  196587. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  196588. if (clientMsg->message_type == wm_Protocols && clientMsg->format == 32)
  196589. {
  196590. const Atom atom = (Atom) clientMsg->data.l[0];
  196591. if (atom == wm_ProtocolList [TAKE_FOCUS])
  196592. {
  196593. XWindowAttributes atts;
  196594. ScopedXLock xlock;
  196595. if (clientMsg->window != 0
  196596. && XGetWindowAttributes (display, clientMsg->window, &atts))
  196597. {
  196598. if (atts.map_state == IsViewable)
  196599. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  196600. }
  196601. }
  196602. else if (atom == wm_ProtocolList [DELETE_WINDOW])
  196603. {
  196604. handleUserClosingWindow();
  196605. }
  196606. }
  196607. else if (clientMsg->message_type == XA_XdndEnter)
  196608. {
  196609. handleDragAndDropEnter (clientMsg);
  196610. }
  196611. else if (clientMsg->message_type == XA_XdndLeave)
  196612. {
  196613. resetDragAndDrop();
  196614. }
  196615. else if (clientMsg->message_type == XA_XdndPosition)
  196616. {
  196617. handleDragAndDropPosition (clientMsg);
  196618. }
  196619. else if (clientMsg->message_type == XA_XdndDrop)
  196620. {
  196621. handleDragAndDropDrop (clientMsg);
  196622. }
  196623. else if (clientMsg->message_type == XA_XdndStatus)
  196624. {
  196625. handleDragAndDropStatus (clientMsg);
  196626. }
  196627. else if (clientMsg->message_type == XA_XdndFinished)
  196628. {
  196629. resetDragAndDrop();
  196630. }
  196631. break;
  196632. }
  196633. case SelectionNotify:
  196634. handleDragAndDropSelection (event);
  196635. break;
  196636. case SelectionClear:
  196637. case SelectionRequest:
  196638. break;
  196639. default:
  196640. #if JUCE_USE_XSHM
  196641. {
  196642. ScopedXLock xlock;
  196643. if (event->xany.type == XShmGetEventBase (display))
  196644. repainter->notifyPaintCompleted();
  196645. }
  196646. #endif
  196647. break;
  196648. }
  196649. }
  196650. void showMouseCursor (Cursor cursor) throw()
  196651. {
  196652. ScopedXLock xlock;
  196653. XDefineCursor (display, windowH, cursor);
  196654. }
  196655. void setTaskBarIcon (const Image& image)
  196656. {
  196657. ScopedXLock xlock;
  196658. deleteTaskBarIcon();
  196659. taskbarImage = image.createCopy();
  196660. Screen* const screen = XDefaultScreenOfDisplay (display);
  196661. const int screenNumber = XScreenNumberOfScreen (screen);
  196662. String screenAtom ("_NET_SYSTEM_TRAY_S");
  196663. screenAtom << screenNumber;
  196664. Atom selectionAtom = XInternAtom (display, screenAtom.toUTF8(), false);
  196665. XGrabServer (display);
  196666. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  196667. if (managerWin != None)
  196668. XSelectInput (display, managerWin, StructureNotifyMask);
  196669. XUngrabServer (display);
  196670. XFlush (display);
  196671. if (managerWin != None)
  196672. {
  196673. XEvent ev;
  196674. zerostruct (ev);
  196675. ev.xclient.type = ClientMessage;
  196676. ev.xclient.window = managerWin;
  196677. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  196678. ev.xclient.format = 32;
  196679. ev.xclient.data.l[0] = CurrentTime;
  196680. ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
  196681. ev.xclient.data.l[2] = windowH;
  196682. ev.xclient.data.l[3] = 0;
  196683. ev.xclient.data.l[4] = 0;
  196684. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  196685. XSync (display, False);
  196686. }
  196687. // For older KDE's ...
  196688. long atomData = 1;
  196689. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  196690. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  196691. // For more recent KDE's...
  196692. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  196693. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  196694. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  196695. XSizeHints* hints = XAllocSizeHints();
  196696. hints->flags = PMinSize;
  196697. hints->min_width = 22;
  196698. hints->min_height = 22;
  196699. XSetWMNormalHints (display, windowH, hints);
  196700. XFree (hints);
  196701. }
  196702. void deleteTaskBarIcon()
  196703. {
  196704. deleteAndZero (taskbarImage);
  196705. }
  196706. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196707. juce_UseDebuggingNewOperator
  196708. bool dontRepaint;
  196709. static ModifierKeys currentModifiers;
  196710. private:
  196711. class LinuxRepaintManager : public Timer
  196712. {
  196713. public:
  196714. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196715. : peer (peer_),
  196716. lastTimeImageUsed (0)
  196717. {
  196718. #if JUCE_USE_XSHM
  196719. shmCompletedDrawing = true;
  196720. useARGBImagesForRendering = isShmAvailable();
  196721. if (useARGBImagesForRendering)
  196722. {
  196723. ScopedXLock xlock;
  196724. XShmSegmentInfo segmentinfo;
  196725. XImage* const testImage
  196726. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196727. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196728. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196729. XDestroyImage (testImage);
  196730. }
  196731. #endif
  196732. }
  196733. ~LinuxRepaintManager()
  196734. {
  196735. }
  196736. void timerCallback()
  196737. {
  196738. #if JUCE_USE_XSHM
  196739. if (! shmCompletedDrawing)
  196740. return;
  196741. #endif
  196742. if (! regionsNeedingRepaint.isEmpty())
  196743. {
  196744. stopTimer();
  196745. performAnyPendingRepaintsNow();
  196746. }
  196747. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  196748. {
  196749. stopTimer();
  196750. image = 0;
  196751. }
  196752. }
  196753. void repaint (int x, int y, int w, int h)
  196754. {
  196755. if (! isTimerRunning())
  196756. startTimer (repaintTimerPeriod);
  196757. regionsNeedingRepaint.add (x, y, w, h);
  196758. }
  196759. void performAnyPendingRepaintsNow()
  196760. {
  196761. #if JUCE_USE_XSHM
  196762. if (! shmCompletedDrawing)
  196763. {
  196764. startTimer (repaintTimerPeriod);
  196765. return;
  196766. }
  196767. #endif
  196768. peer->clearMaskedRegion();
  196769. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  196770. regionsNeedingRepaint.clear();
  196771. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  196772. if (! totalArea.isEmpty())
  196773. {
  196774. if (image == 0 || image->getWidth() < totalArea.getWidth()
  196775. || image->getHeight() < totalArea.getHeight())
  196776. {
  196777. #if JUCE_USE_XSHM
  196778. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  196779. : Image::RGB,
  196780. #else
  196781. image = new XBitmapImage (Image::RGB,
  196782. #endif
  196783. (totalArea.getWidth() + 31) & ~31,
  196784. (totalArea.getHeight() + 31) & ~31,
  196785. false,
  196786. peer->depth,
  196787. peer->visual);
  196788. }
  196789. startTimer (repaintTimerPeriod);
  196790. LowLevelGraphicsSoftwareRenderer context (*image);
  196791. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  196792. if (context.clipToRectangleList (originalRepaintRegion))
  196793. {
  196794. if (peer->depth == 32)
  196795. {
  196796. RectangleList::Iterator i (originalRepaintRegion);
  196797. while (i.next())
  196798. {
  196799. const Rectangle<int>& r = *i.getRectangle();
  196800. image->clear (r.getX() - totalArea.getX(), r.getY() - totalArea.getY(), r.getWidth(), r.getHeight());
  196801. }
  196802. }
  196803. peer->handlePaint (context);
  196804. }
  196805. if (! peer->maskedRegion.isEmpty())
  196806. originalRepaintRegion.subtract (peer->maskedRegion);
  196807. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  196808. {
  196809. #if JUCE_USE_XSHM
  196810. shmCompletedDrawing = false;
  196811. #endif
  196812. const Rectangle<int>& r = *i.getRectangle();
  196813. image->blitToWindow (peer->windowH,
  196814. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  196815. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  196816. }
  196817. }
  196818. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  196819. startTimer (repaintTimerPeriod);
  196820. }
  196821. #if JUCE_USE_XSHM
  196822. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  196823. #endif
  196824. private:
  196825. LinuxComponentPeer* const peer;
  196826. ScopedPointer <XBitmapImage> image;
  196827. uint32 lastTimeImageUsed;
  196828. RectangleList regionsNeedingRepaint;
  196829. #if JUCE_USE_XSHM
  196830. bool useARGBImagesForRendering, shmCompletedDrawing;
  196831. #endif
  196832. LinuxRepaintManager (const LinuxRepaintManager&);
  196833. LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  196834. };
  196835. ScopedPointer <LinuxRepaintManager> repainter;
  196836. friend class LinuxRepaintManager;
  196837. Window windowH, parentWindow;
  196838. int wx, wy, ww, wh;
  196839. Image* taskbarImage;
  196840. bool fullScreen, mapped;
  196841. int depth;
  196842. Visual* visual;
  196843. BorderSize windowBorder;
  196844. struct MotifWmHints
  196845. {
  196846. unsigned long flags;
  196847. unsigned long functions;
  196848. unsigned long decorations;
  196849. long input_mode;
  196850. unsigned long status;
  196851. };
  196852. static void updateKeyModifiers (const int status) throw()
  196853. {
  196854. int keyMods = 0;
  196855. if (status & ShiftMask) keyMods |= ModifierKeys::shiftModifier;
  196856. if (status & ControlMask) keyMods |= ModifierKeys::ctrlModifier;
  196857. if (status & AltMask) keyMods |= ModifierKeys::altModifier;
  196858. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  196859. numLock = ((status & NumLockMask) != 0);
  196860. capsLock = ((status & LockMask) != 0);
  196861. }
  196862. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  196863. {
  196864. int modifier = 0;
  196865. bool isModifier = true;
  196866. switch (sym)
  196867. {
  196868. case XK_Shift_L:
  196869. case XK_Shift_R:
  196870. modifier = ModifierKeys::shiftModifier;
  196871. break;
  196872. case XK_Control_L:
  196873. case XK_Control_R:
  196874. modifier = ModifierKeys::ctrlModifier;
  196875. break;
  196876. case XK_Alt_L:
  196877. case XK_Alt_R:
  196878. modifier = ModifierKeys::altModifier;
  196879. break;
  196880. case XK_Num_Lock:
  196881. if (press)
  196882. numLock = ! numLock;
  196883. break;
  196884. case XK_Caps_Lock:
  196885. if (press)
  196886. capsLock = ! capsLock;
  196887. break;
  196888. case XK_Scroll_Lock:
  196889. break;
  196890. default:
  196891. isModifier = false;
  196892. break;
  196893. }
  196894. if (modifier != 0)
  196895. {
  196896. if (press)
  196897. currentModifiers = currentModifiers.withFlags (modifier);
  196898. else
  196899. currentModifiers = currentModifiers.withoutFlags (modifier);
  196900. }
  196901. return isModifier;
  196902. }
  196903. // Alt and Num lock are not defined by standard X
  196904. // modifier constants: check what they're mapped to
  196905. static void updateModifierMappings() throw()
  196906. {
  196907. ScopedXLock xlock;
  196908. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  196909. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  196910. AltMask = 0;
  196911. NumLockMask = 0;
  196912. XModifierKeymap* mapping = XGetModifierMapping (display);
  196913. if (mapping)
  196914. {
  196915. for (int i = 0; i < 8; i++)
  196916. {
  196917. if (mapping->modifiermap [i << 1] == altLeftCode)
  196918. AltMask = 1 << i;
  196919. else if (mapping->modifiermap [i << 1] == numLockCode)
  196920. NumLockMask = 1 << i;
  196921. }
  196922. XFreeModifiermap (mapping);
  196923. }
  196924. }
  196925. void removeWindowDecorations (Window wndH)
  196926. {
  196927. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196928. if (hints != None)
  196929. {
  196930. MotifWmHints motifHints;
  196931. zerostruct (motifHints);
  196932. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  196933. motifHints.decorations = 0;
  196934. ScopedXLock xlock;
  196935. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196936. (unsigned char*) &motifHints, 4);
  196937. }
  196938. hints = XInternAtom (display, "_WIN_HINTS", True);
  196939. if (hints != None)
  196940. {
  196941. long gnomeHints = 0;
  196942. ScopedXLock xlock;
  196943. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196944. (unsigned char*) &gnomeHints, 1);
  196945. }
  196946. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  196947. if (hints != None)
  196948. {
  196949. long kwmHints = 2; /*KDE_tinyDecoration*/
  196950. ScopedXLock xlock;
  196951. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196952. (unsigned char*) &kwmHints, 1);
  196953. }
  196954. hints = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  196955. if (hints != None)
  196956. {
  196957. ScopedXLock xlock;
  196958. int netHints [2];
  196959. int numHints = 0;
  196960. if ((styleFlags & windowIsTemporary) != 0)
  196961. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_MENU", True);
  196962. else
  196963. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  196964. if (netHints [numHints] != 0)
  196965. ++numHints;
  196966. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  196967. if (netHints [numHints] != 0)
  196968. ++numHints;
  196969. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  196970. (unsigned char*) &netHints, numHints);
  196971. }
  196972. }
  196973. void addWindowButtons (Window wndH)
  196974. {
  196975. ScopedXLock xlock;
  196976. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196977. if (hints != None)
  196978. {
  196979. MotifWmHints motifHints;
  196980. zerostruct (motifHints);
  196981. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  196982. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  196983. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  196984. if ((styleFlags & windowHasCloseButton) != 0)
  196985. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  196986. if ((styleFlags & windowHasMinimiseButton) != 0)
  196987. {
  196988. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  196989. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  196990. }
  196991. if ((styleFlags & windowHasMaximiseButton) != 0)
  196992. {
  196993. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  196994. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  196995. }
  196996. if ((styleFlags & windowIsResizable) != 0)
  196997. {
  196998. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  196999. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  197000. }
  197001. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  197002. }
  197003. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  197004. if (hints != None)
  197005. {
  197006. int netHints [6];
  197007. int num = 0;
  197008. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  197009. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  197010. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  197011. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  197012. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  197013. (unsigned char*) &netHints, num);
  197014. }
  197015. }
  197016. void createWindow()
  197017. {
  197018. ScopedXLock xlock;
  197019. static bool atomsInitialised = false;
  197020. if (! atomsInitialised)
  197021. {
  197022. atomsInitialised = true;
  197023. wm_Protocols = XInternAtom (display, "WM_PROTOCOLS", 1);
  197024. wm_ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", 1);
  197025. wm_ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", 1);
  197026. wm_ChangeState = XInternAtom (display, "WM_CHANGE_STATE", 1);
  197027. wm_State = XInternAtom (display, "WM_STATE", 1);
  197028. wm_ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  197029. XA_XdndAware = XInternAtom (display, "XdndAware", 0);
  197030. XA_XdndEnter = XInternAtom (display, "XdndEnter", 0);
  197031. XA_XdndLeave = XInternAtom (display, "XdndLeave", 0);
  197032. XA_XdndPosition = XInternAtom (display, "XdndPosition", 0);
  197033. XA_XdndStatus = XInternAtom (display, "XdndStatus", 0);
  197034. XA_XdndDrop = XInternAtom (display, "XdndDrop", 0);
  197035. XA_XdndFinished = XInternAtom (display, "XdndFinished", 0);
  197036. XA_XdndSelection = XInternAtom (display, "XdndSelection", 0);
  197037. XA_XdndProxy = XInternAtom (display, "XdndProxy", 0);
  197038. XA_XdndTypeList = XInternAtom (display, "XdndTypeList", 0);
  197039. XA_XdndActionList = XInternAtom (display, "XdndActionList", 0);
  197040. XA_XdndActionCopy = XInternAtom (display, "XdndActionCopy", 0);
  197041. XA_XdndActionMove = XInternAtom (display, "XdndActionMove", 0);
  197042. XA_XdndActionLink = XInternAtom (display, "XdndActionLink", 0);
  197043. XA_XdndActionAsk = XInternAtom (display, "XdndActionAsk", 0);
  197044. XA_XdndActionPrivate = XInternAtom (display, "XdndActionPrivate", 0);
  197045. XA_XdndActionDescription = XInternAtom (display, "XdndActionDescription", 0);
  197046. XA_JXSelectionWindowProperty = XInternAtom (display, "JXSelectionWindowProperty", 0);
  197047. XA_MimeTextPlain = XInternAtom (display, "text/plain", 0);
  197048. XA_MimeTextUriList = XInternAtom (display, "text/uri-list", 0);
  197049. XA_MimeRootDrop = XInternAtom (display, "application/x-rootwindow-drop", 0);
  197050. }
  197051. resetDragAndDrop();
  197052. XA_OtherMime = XA_MimeTextPlain; // xxx why??
  197053. allowedMimeTypeAtoms [0] = XA_MimeTextPlain;
  197054. allowedMimeTypeAtoms [1] = XA_OtherMime;
  197055. allowedMimeTypeAtoms [2] = XA_MimeTextUriList;
  197056. allowedActions [0] = XA_XdndActionMove;
  197057. allowedActions [1] = XA_XdndActionCopy;
  197058. allowedActions [2] = XA_XdndActionLink;
  197059. allowedActions [3] = XA_XdndActionAsk;
  197060. allowedActions [4] = XA_XdndActionPrivate;
  197061. // Get defaults for various properties
  197062. const int screen = DefaultScreen (display);
  197063. Window root = RootWindow (display, screen);
  197064. // Try to obtain a 32-bit visual or fallback to 24 or 16
  197065. visual = Visuals::findVisualFormat ((styleFlags & windowIsSemiTransparent) ? 32 : 24, depth);
  197066. if (visual == 0)
  197067. {
  197068. Logger::outputDebugString ("ERROR: System doesn't support 32, 24 or 16 bit RGB display.\n");
  197069. Process::terminate();
  197070. }
  197071. // Create and install a colormap suitable fr our visual
  197072. Colormap colormap = XCreateColormap (display, root, visual, AllocNone);
  197073. XInstallColormap (display, colormap);
  197074. // Set up the window attributes
  197075. XSetWindowAttributes swa;
  197076. swa.border_pixel = 0;
  197077. swa.background_pixmap = None;
  197078. swa.colormap = colormap;
  197079. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  197080. swa.event_mask = eventMask;
  197081. Window wndH = XCreateWindow (display, root,
  197082. 0, 0, 1, 1,
  197083. 0, depth, InputOutput, visual,
  197084. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  197085. &swa);
  197086. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  197087. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  197088. GrabModeAsync, GrabModeAsync, None, None);
  197089. // Set the window context to identify the window handle object
  197090. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  197091. {
  197092. // Failed
  197093. jassertfalse
  197094. Logger::outputDebugString ("Failed to create context information for window.\n");
  197095. XDestroyWindow (display, wndH);
  197096. wndH = 0;
  197097. }
  197098. // Set window manager hints
  197099. XWMHints* wmHints = XAllocWMHints();
  197100. wmHints->flags = InputHint | StateHint;
  197101. wmHints->input = True; // Locally active input model
  197102. wmHints->initial_state = NormalState;
  197103. XSetWMHints (display, wndH, wmHints);
  197104. XFree (wmHints);
  197105. // Set window manager protocols
  197106. XChangeProperty (display, wndH, wm_Protocols, XA_ATOM, 32, PropModeReplace,
  197107. (unsigned char*) wm_ProtocolList, 2);
  197108. // Set drag and drop flags
  197109. XChangeProperty (display, wndH, XA_XdndTypeList, XA_ATOM, 32, PropModeReplace,
  197110. (const unsigned char*) allowedMimeTypeAtoms, numElementsInArray (allowedMimeTypeAtoms));
  197111. XChangeProperty (display, wndH, XA_XdndActionList, XA_ATOM, 32, PropModeReplace,
  197112. (const unsigned char*) allowedActions, numElementsInArray (allowedActions));
  197113. XChangeProperty (display, wndH, XA_XdndActionDescription, XA_STRING, 8, PropModeReplace,
  197114. (const unsigned char*) "", 0);
  197115. unsigned long dndVersion = ourDndVersion;
  197116. XChangeProperty (display, wndH, XA_XdndAware, XA_ATOM, 32, PropModeReplace,
  197117. (const unsigned char*) &dndVersion, 1);
  197118. if ((styleFlags & windowHasDropShadow) != 0 && Desktop::canUseSemiTransparentWindows())
  197119. {
  197120. }
  197121. if ((styleFlags & windowIsTemporary) != 0)
  197122. {
  197123. }
  197124. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  197125. {
  197126. }
  197127. if ((styleFlags & windowHasTitleBar) == 0)
  197128. removeWindowDecorations (wndH);
  197129. else
  197130. addWindowButtons (wndH);
  197131. // Set window name
  197132. setWindowTitle (wndH, getComponent()->getName());
  197133. // Initialise the pointer and keyboard mapping
  197134. // This is not the same as the logical pointer mapping the X server uses:
  197135. // we don't mess with this.
  197136. static bool mappingInitialised = false;
  197137. if (! mappingInitialised)
  197138. {
  197139. mappingInitialised = true;
  197140. const int numButtons = XGetPointerMapping (display, 0, 0);
  197141. if (numButtons == 2)
  197142. {
  197143. pointerMap[0] = LeftButton;
  197144. pointerMap[1] = RightButton;
  197145. pointerMap[2] = pointerMap[3] = pointerMap[4] = NoButton;
  197146. }
  197147. else if (numButtons >= 3)
  197148. {
  197149. pointerMap[0] = LeftButton;
  197150. pointerMap[1] = MiddleButton;
  197151. pointerMap[2] = RightButton;
  197152. if (numButtons >= 5)
  197153. {
  197154. pointerMap[3] = WheelUp;
  197155. pointerMap[4] = WheelDown;
  197156. }
  197157. }
  197158. updateModifierMappings();
  197159. }
  197160. windowH = wndH;
  197161. }
  197162. void destroyWindow()
  197163. {
  197164. ScopedXLock xlock;
  197165. XPointer handlePointer;
  197166. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  197167. XDeleteContext (display, (XID) windowH, improbableNumber);
  197168. XDestroyWindow (display, windowH);
  197169. // Wait for it to complete and then remove any events for this
  197170. // window from the event queue.
  197171. XSync (display, false);
  197172. XEvent event;
  197173. while (XCheckWindowEvent (display, windowH, eventMask, &event) == True)
  197174. {}
  197175. }
  197176. static int64 getEventTime (::Time t)
  197177. {
  197178. static int64 eventTimeOffset = 0x12345678;
  197179. const int64 thisMessageTime = t;
  197180. if (eventTimeOffset == 0x12345678)
  197181. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  197182. return eventTimeOffset + thisMessageTime;
  197183. }
  197184. static void setWindowTitle (Window xwin, const String& title)
  197185. {
  197186. XTextProperty nameProperty;
  197187. char* strings[] = { const_cast <char*> (title.toUTF8()) };
  197188. ScopedXLock xlock;
  197189. if (XStringListToTextProperty (strings, 1, &nameProperty))
  197190. {
  197191. XSetWMName (display, xwin, &nameProperty);
  197192. XSetWMIconName (display, xwin, &nameProperty);
  197193. XFree (nameProperty.value);
  197194. }
  197195. }
  197196. void updateBorderSize()
  197197. {
  197198. if ((styleFlags & windowHasTitleBar) == 0)
  197199. {
  197200. windowBorder = BorderSize (0);
  197201. }
  197202. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  197203. {
  197204. ScopedXLock xlock;
  197205. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  197206. if (hints != None)
  197207. {
  197208. unsigned char* data = 0;
  197209. unsigned long nitems, bytesLeft;
  197210. Atom actualType;
  197211. int actualFormat;
  197212. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  197213. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197214. &data) == Success)
  197215. {
  197216. const unsigned long* const sizes = (const unsigned long*) data;
  197217. if (actualFormat == 32)
  197218. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  197219. (int) sizes[3], (int) sizes[1]);
  197220. XFree (data);
  197221. }
  197222. }
  197223. }
  197224. }
  197225. void updateBounds()
  197226. {
  197227. jassert (windowH != 0);
  197228. if (windowH != 0)
  197229. {
  197230. Window root, child;
  197231. unsigned int bw, depth;
  197232. ScopedXLock xlock;
  197233. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  197234. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  197235. &bw, &depth))
  197236. {
  197237. wx = wy = ww = wh = 0;
  197238. }
  197239. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  197240. {
  197241. wx = wy = 0;
  197242. }
  197243. }
  197244. }
  197245. void resetDragAndDrop()
  197246. {
  197247. dragAndDropFiles.clear();
  197248. lastDropPos = Point<int> (-1, -1);
  197249. dragAndDropCurrentMimeType = 0;
  197250. dragAndDropSourceWindow = 0;
  197251. srcMimeTypeAtomList.clear();
  197252. }
  197253. void sendDragAndDropMessage (XClientMessageEvent& msg)
  197254. {
  197255. msg.type = ClientMessage;
  197256. msg.display = display;
  197257. msg.window = dragAndDropSourceWindow;
  197258. msg.format = 32;
  197259. msg.data.l[0] = windowH;
  197260. ScopedXLock xlock;
  197261. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  197262. }
  197263. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  197264. {
  197265. XClientMessageEvent msg;
  197266. zerostruct (msg);
  197267. msg.message_type = XA_XdndStatus;
  197268. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  197269. msg.data.l[4] = dropAction;
  197270. sendDragAndDropMessage (msg);
  197271. }
  197272. void sendDragAndDropLeave()
  197273. {
  197274. XClientMessageEvent msg;
  197275. zerostruct (msg);
  197276. msg.message_type = XA_XdndLeave;
  197277. sendDragAndDropMessage (msg);
  197278. }
  197279. void sendDragAndDropFinish()
  197280. {
  197281. XClientMessageEvent msg;
  197282. zerostruct (msg);
  197283. msg.message_type = XA_XdndFinished;
  197284. sendDragAndDropMessage (msg);
  197285. }
  197286. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  197287. {
  197288. if ((clientMsg->data.l[1] & 1) == 0)
  197289. {
  197290. sendDragAndDropLeave();
  197291. if (dragAndDropFiles.size() > 0)
  197292. handleFileDragExit (dragAndDropFiles);
  197293. dragAndDropFiles.clear();
  197294. }
  197295. }
  197296. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  197297. {
  197298. if (dragAndDropSourceWindow == 0)
  197299. return;
  197300. dragAndDropSourceWindow = clientMsg->data.l[0];
  197301. Point<int> dropPos ((int) clientMsg->data.l[2] >> 16,
  197302. (int) clientMsg->data.l[2] & 0xffff);
  197303. dropPos -= getScreenPosition();
  197304. if (lastDropPos != dropPos)
  197305. {
  197306. lastDropPos = dropPos;
  197307. dragAndDropTimestamp = clientMsg->data.l[3];
  197308. Atom targetAction = XA_XdndActionCopy;
  197309. for (int i = numElementsInArray (allowedActions); --i >= 0;)
  197310. {
  197311. if ((Atom) clientMsg->data.l[4] == allowedActions[i])
  197312. {
  197313. targetAction = allowedActions[i];
  197314. break;
  197315. }
  197316. }
  197317. sendDragAndDropStatus (true, targetAction);
  197318. if (dragAndDropFiles.size() == 0)
  197319. updateDraggedFileList (clientMsg);
  197320. if (dragAndDropFiles.size() > 0)
  197321. handleFileDragMove (dragAndDropFiles, dropPos);
  197322. }
  197323. }
  197324. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  197325. {
  197326. if (dragAndDropFiles.size() == 0)
  197327. updateDraggedFileList (clientMsg);
  197328. const StringArray files (dragAndDropFiles);
  197329. const Point<int> lastPos (lastDropPos);
  197330. sendDragAndDropFinish();
  197331. resetDragAndDrop();
  197332. if (files.size() > 0)
  197333. handleFileDragDrop (files, lastPos);
  197334. }
  197335. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  197336. {
  197337. dragAndDropFiles.clear();
  197338. srcMimeTypeAtomList.clear();
  197339. dragAndDropCurrentMimeType = 0;
  197340. const int dndCurrentVersion = (int) (clientMsg->data.l[1] & 0xff000000) >> 24;
  197341. if (dndCurrentVersion < 3 || dndCurrentVersion > ourDndVersion)
  197342. {
  197343. dragAndDropSourceWindow = 0;
  197344. return;
  197345. }
  197346. dragAndDropSourceWindow = clientMsg->data.l[0];
  197347. if ((clientMsg->data.l[1] & 1) != 0)
  197348. {
  197349. Atom actual;
  197350. int format;
  197351. unsigned long count = 0, remaining = 0;
  197352. unsigned char* data = 0;
  197353. ScopedXLock xlock;
  197354. XGetWindowProperty (display, dragAndDropSourceWindow, XA_XdndTypeList,
  197355. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197356. &count, &remaining, &data);
  197357. if (data != 0)
  197358. {
  197359. if (actual == XA_ATOM && format == 32 && count != 0)
  197360. {
  197361. const unsigned long* const types = (const unsigned long*) data;
  197362. for (unsigned int i = 0; i < count; ++i)
  197363. if (types[i] != None)
  197364. srcMimeTypeAtomList.add (types[i]);
  197365. }
  197366. XFree (data);
  197367. }
  197368. }
  197369. if (srcMimeTypeAtomList.size() == 0)
  197370. {
  197371. for (int i = 2; i < 5; ++i)
  197372. if (clientMsg->data.l[i] != None)
  197373. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197374. if (srcMimeTypeAtomList.size() == 0)
  197375. {
  197376. dragAndDropSourceWindow = 0;
  197377. return;
  197378. }
  197379. }
  197380. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197381. for (int j = 0; j < numElementsInArray (allowedMimeTypeAtoms); ++j)
  197382. if (srcMimeTypeAtomList[i] == allowedMimeTypeAtoms[j])
  197383. dragAndDropCurrentMimeType = allowedMimeTypeAtoms[j];
  197384. handleDragAndDropPosition (clientMsg);
  197385. }
  197386. void handleDragAndDropSelection (const XEvent* const evt)
  197387. {
  197388. dragAndDropFiles.clear();
  197389. if (evt->xselection.property != 0)
  197390. {
  197391. StringArray lines;
  197392. {
  197393. MemoryBlock dropData;
  197394. for (;;)
  197395. {
  197396. Atom actual;
  197397. uint8* data = 0;
  197398. unsigned long count = 0, remaining = 0;
  197399. int format = 0;
  197400. ScopedXLock xlock;
  197401. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197402. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197403. &format, &count, &remaining, &data) == Success)
  197404. {
  197405. dropData.append (data, count * format / 8);
  197406. XFree (data);
  197407. if (remaining == 0)
  197408. break;
  197409. }
  197410. else
  197411. {
  197412. XFree (data);
  197413. break;
  197414. }
  197415. }
  197416. lines.addLines (dropData.toString());
  197417. }
  197418. for (int i = 0; i < lines.size(); ++i)
  197419. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf (T("file://"), false, true)));
  197420. dragAndDropFiles.trim();
  197421. dragAndDropFiles.removeEmptyStrings();
  197422. }
  197423. }
  197424. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197425. {
  197426. dragAndDropFiles.clear();
  197427. if (dragAndDropSourceWindow != None
  197428. && dragAndDropCurrentMimeType != 0)
  197429. {
  197430. dragAndDropTimestamp = clientMsg->data.l[2];
  197431. ScopedXLock xlock;
  197432. XConvertSelection (display,
  197433. XA_XdndSelection,
  197434. dragAndDropCurrentMimeType,
  197435. XA_JXSelectionWindowProperty,
  197436. windowH,
  197437. dragAndDropTimestamp);
  197438. }
  197439. }
  197440. StringArray dragAndDropFiles;
  197441. int dragAndDropTimestamp;
  197442. Point<int> lastDropPos;
  197443. Atom XA_OtherMime, dragAndDropCurrentMimeType;
  197444. Window dragAndDropSourceWindow;
  197445. unsigned int allowedActions[5];
  197446. unsigned int allowedMimeTypeAtoms[3];
  197447. Array <Atom> srcMimeTypeAtomList;
  197448. static int pointerMap[5];
  197449. static Point<int> lastMousePos;
  197450. static void clearLastMousePos() throw()
  197451. {
  197452. lastMousePos = Point<int> (0x100000, 0x100000);
  197453. }
  197454. };
  197455. ModifierKeys LinuxComponentPeer::currentModifiers;
  197456. int LinuxComponentPeer::pointerMap[5];
  197457. Point<int> LinuxComponentPeer::lastMousePos;
  197458. void ModifierKeys::updateCurrentModifiers() throw()
  197459. {
  197460. currentModifiers = LinuxComponentPeer::currentModifiers;
  197461. }
  197462. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  197463. {
  197464. Window root, child;
  197465. int x, y, winx, winy;
  197466. unsigned int mask;
  197467. int mouseMods = 0;
  197468. ScopedXLock xlock;
  197469. if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)),
  197470. &root, &child, &x, &y, &winx, &winy, &mask) != False)
  197471. {
  197472. if ((mask & Button1Mask) != 0) mouseMods |= ModifierKeys::leftButtonModifier;
  197473. if ((mask & Button2Mask) != 0) mouseMods |= ModifierKeys::middleButtonModifier;
  197474. if ((mask & Button3Mask) != 0) mouseMods |= ModifierKeys::rightButtonModifier;
  197475. }
  197476. LinuxComponentPeer::currentModifiers = LinuxComponentPeer::currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  197477. return LinuxComponentPeer::currentModifiers;
  197478. }
  197479. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197480. {
  197481. if (enableOrDisable)
  197482. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197483. }
  197484. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197485. {
  197486. return new LinuxComponentPeer (this, styleFlags);
  197487. }
  197488. // (this callback is hooked up in the messaging code)
  197489. void juce_windowMessageReceive (XEvent* event)
  197490. {
  197491. if (event->xany.window != None)
  197492. {
  197493. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197494. if (ComponentPeer::isValidPeer (peer))
  197495. peer->handleWindowMessage (event);
  197496. }
  197497. else
  197498. {
  197499. switch (event->xany.type)
  197500. {
  197501. case KeymapNotify:
  197502. {
  197503. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197504. memcpy (keyStates, keymapEvent->key_vector, 32);
  197505. break;
  197506. }
  197507. default:
  197508. break;
  197509. }
  197510. }
  197511. }
  197512. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  197513. {
  197514. if (display == 0)
  197515. return;
  197516. #if JUCE_USE_XINERAMA
  197517. int major_opcode, first_event, first_error;
  197518. ScopedXLock xlock;
  197519. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197520. {
  197521. typedef Bool (*tXineramaIsActive) (Display*);
  197522. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197523. static tXineramaIsActive xXineramaIsActive = 0;
  197524. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197525. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197526. {
  197527. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197528. if (h != 0)
  197529. {
  197530. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197531. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197532. }
  197533. }
  197534. if (xXineramaIsActive != 0
  197535. && xXineramaQueryScreens != 0
  197536. && xXineramaIsActive (display))
  197537. {
  197538. int numMonitors = 0;
  197539. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197540. if (screens != 0)
  197541. {
  197542. for (int i = numMonitors; --i >= 0;)
  197543. {
  197544. int index = screens[i].screen_number;
  197545. if (index >= 0)
  197546. {
  197547. while (monitorCoords.size() < index)
  197548. monitorCoords.add (Rectangle<int>());
  197549. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  197550. screens[i].y_org,
  197551. screens[i].width,
  197552. screens[i].height));
  197553. }
  197554. }
  197555. XFree (screens);
  197556. }
  197557. }
  197558. }
  197559. if (monitorCoords.size() == 0)
  197560. #endif
  197561. {
  197562. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197563. if (hints != None)
  197564. {
  197565. const int numMonitors = ScreenCount (display);
  197566. for (int i = 0; i < numMonitors; ++i)
  197567. {
  197568. Window root = RootWindow (display, i);
  197569. unsigned long nitems, bytesLeft;
  197570. Atom actualType;
  197571. int actualFormat;
  197572. unsigned char* data = 0;
  197573. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197574. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197575. &data) == Success)
  197576. {
  197577. const long* const position = (const long*) data;
  197578. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197579. monitorCoords.add (Rectangle<int> (position[0], position[1],
  197580. position[2], position[3]));
  197581. XFree (data);
  197582. }
  197583. }
  197584. }
  197585. if (monitorCoords.size() == 0)
  197586. {
  197587. monitorCoords.add (Rectangle<int> (0, 0,
  197588. DisplayWidth (display, DefaultScreen (display)),
  197589. DisplayHeight (display, DefaultScreen (display))));
  197590. }
  197591. }
  197592. }
  197593. void Desktop::createMouseInputSources()
  197594. {
  197595. mouseSources.add (new MouseInputSource (0, true));
  197596. }
  197597. bool Desktop::canUseSemiTransparentWindows() throw()
  197598. {
  197599. int matchedDepth = 0;
  197600. const int desiredDepth = 32;
  197601. return Visuals::findVisualFormat (desiredDepth, matchedDepth) != 0
  197602. && (matchedDepth == desiredDepth);
  197603. }
  197604. const Point<int> Desktop::getMousePosition()
  197605. {
  197606. Window root, child;
  197607. int x, y, winx, winy;
  197608. unsigned int mask;
  197609. ScopedXLock xlock;
  197610. if (XQueryPointer (display,
  197611. RootWindow (display, DefaultScreen (display)),
  197612. &root, &child,
  197613. &x, &y, &winx, &winy, &mask) == False)
  197614. {
  197615. // Pointer not on the default screen
  197616. x = y = -1;
  197617. }
  197618. return Point<int> (x, y);
  197619. }
  197620. void Desktop::setMousePosition (const Point<int>& newPosition)
  197621. {
  197622. ScopedXLock xlock;
  197623. Window root = RootWindow (display, DefaultScreen (display));
  197624. XWarpPointer (display, None, root, 0, 0, 0, 0, newPosition.getX(), newPosition.getY());
  197625. }
  197626. static bool screenSaverAllowed = true;
  197627. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197628. {
  197629. if (screenSaverAllowed != isEnabled)
  197630. {
  197631. screenSaverAllowed = isEnabled;
  197632. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197633. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197634. if (xScreenSaverSuspend == 0)
  197635. {
  197636. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197637. if (h != 0)
  197638. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197639. }
  197640. ScopedXLock xlock;
  197641. if (xScreenSaverSuspend != 0)
  197642. xScreenSaverSuspend (display, ! isEnabled);
  197643. }
  197644. }
  197645. bool Desktop::isScreenSaverEnabled() throw()
  197646. {
  197647. return screenSaverAllowed;
  197648. }
  197649. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  197650. {
  197651. ScopedXLock xlock;
  197652. Window root = RootWindow (display, DefaultScreen (display));
  197653. const unsigned int imageW = image.getWidth();
  197654. const unsigned int imageH = image.getHeight();
  197655. unsigned int cursorW, cursorH;
  197656. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197657. return 0;
  197658. Image im (Image::ARGB, cursorW, cursorH, true);
  197659. Graphics g (im);
  197660. if (imageW > cursorW || imageH > cursorH)
  197661. {
  197662. hotspotX = (hotspotX * cursorW) / imageW;
  197663. hotspotY = (hotspotY * cursorH) / imageH;
  197664. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197665. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197666. false);
  197667. }
  197668. else
  197669. {
  197670. g.drawImageAt (&image, 0, 0);
  197671. }
  197672. const int stride = (cursorW + 7) >> 3;
  197673. HeapBlock <uint8> maskPlane, sourcePlane;
  197674. maskPlane.calloc (stride * cursorH);
  197675. sourcePlane.calloc (stride * cursorH);
  197676. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197677. for (int y = cursorH; --y >= 0;)
  197678. {
  197679. for (int x = cursorW; --x >= 0;)
  197680. {
  197681. const uint8 mask = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197682. const int offset = y * stride + (x >> 3);
  197683. const Colour c (im.getPixelAt (x, y));
  197684. if (c.getAlpha() >= 128)
  197685. maskPlane[offset] |= mask;
  197686. if (c.getBrightness() >= 0.5f)
  197687. sourcePlane[offset] |= mask;
  197688. }
  197689. }
  197690. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, reinterpret_cast <char*> (sourcePlane.getData()), cursorW, cursorH, 0xffff, 0, 1);
  197691. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, reinterpret_cast <char*> (maskPlane.getData()), cursorW, cursorH, 0xffff, 0, 1);
  197692. XColor white, black;
  197693. black.red = black.green = black.blue = 0;
  197694. white.red = white.green = white.blue = 0xffff;
  197695. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197696. XFreePixmap (display, sourcePixmap);
  197697. XFreePixmap (display, maskPixmap);
  197698. return result;
  197699. }
  197700. void juce_deleteMouseCursor (void* const cursorHandle, const bool) throw()
  197701. {
  197702. ScopedXLock xlock;
  197703. if (cursorHandle != None)
  197704. XFreeCursor (display, (Cursor) cursorHandle);
  197705. }
  197706. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  197707. {
  197708. unsigned int shape;
  197709. switch (type)
  197710. {
  197711. case MouseCursor::NoCursor:
  197712. {
  197713. const Image im (Image::ARGB, 16, 16, true);
  197714. return juce_createMouseCursorFromImage (im, 0, 0);
  197715. }
  197716. case MouseCursor::NormalCursor:
  197717. return (void*) None; // Use parent cursor
  197718. case MouseCursor::DraggingHandCursor:
  197719. {
  197720. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197721. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197722. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197723. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197724. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197725. const int dragHandDataSize = 99;
  197726. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) dragHandData, dragHandDataSize));
  197727. return juce_createMouseCursorFromImage (*im, 8, 7);
  197728. }
  197729. case MouseCursor::CopyingCursor:
  197730. {
  197731. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197732. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197733. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197734. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197735. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197736. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197737. const int copyCursorSize = 119;
  197738. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) copyCursorData, copyCursorSize));
  197739. return juce_createMouseCursorFromImage (*im, 1, 3);
  197740. }
  197741. case MouseCursor::WaitCursor:
  197742. shape = XC_watch;
  197743. break;
  197744. case MouseCursor::IBeamCursor:
  197745. shape = XC_xterm;
  197746. break;
  197747. case MouseCursor::PointingHandCursor:
  197748. shape = XC_hand2;
  197749. break;
  197750. case MouseCursor::LeftRightResizeCursor:
  197751. shape = XC_sb_h_double_arrow;
  197752. break;
  197753. case MouseCursor::UpDownResizeCursor:
  197754. shape = XC_sb_v_double_arrow;
  197755. break;
  197756. case MouseCursor::UpDownLeftRightResizeCursor:
  197757. shape = XC_fleur;
  197758. break;
  197759. case MouseCursor::TopEdgeResizeCursor:
  197760. shape = XC_top_side;
  197761. break;
  197762. case MouseCursor::BottomEdgeResizeCursor:
  197763. shape = XC_bottom_side;
  197764. break;
  197765. case MouseCursor::LeftEdgeResizeCursor:
  197766. shape = XC_left_side;
  197767. break;
  197768. case MouseCursor::RightEdgeResizeCursor:
  197769. shape = XC_right_side;
  197770. break;
  197771. case MouseCursor::TopLeftCornerResizeCursor:
  197772. shape = XC_top_left_corner;
  197773. break;
  197774. case MouseCursor::TopRightCornerResizeCursor:
  197775. shape = XC_top_right_corner;
  197776. break;
  197777. case MouseCursor::BottomLeftCornerResizeCursor:
  197778. shape = XC_bottom_left_corner;
  197779. break;
  197780. case MouseCursor::BottomRightCornerResizeCursor:
  197781. shape = XC_bottom_right_corner;
  197782. break;
  197783. case MouseCursor::CrosshairCursor:
  197784. shape = XC_crosshair;
  197785. break;
  197786. default:
  197787. return (void*) None; // Use parent cursor
  197788. }
  197789. ScopedXLock xlock;
  197790. return (void*) XCreateFontCursor (display, shape);
  197791. }
  197792. void MouseCursor::showInWindow (ComponentPeer* peer) const throw()
  197793. {
  197794. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197795. if (lp != 0)
  197796. lp->showMouseCursor ((Cursor) getHandle());
  197797. }
  197798. void MouseCursor::showInAllWindows() const throw()
  197799. {
  197800. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197801. showInWindow (ComponentPeer::getPeer (i));
  197802. }
  197803. Image* juce_createIconForFile (const File& file)
  197804. {
  197805. return 0;
  197806. }
  197807. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197808. {
  197809. return new Image (format, imageWidth, imageHeight, clearImage);
  197810. }
  197811. #if JUCE_OPENGL
  197812. class WindowedGLContext : public OpenGLContext
  197813. {
  197814. public:
  197815. WindowedGLContext (Component* const component,
  197816. const OpenGLPixelFormat& pixelFormat_,
  197817. GLXContext sharedContext)
  197818. : renderContext (0),
  197819. embeddedWindow (0),
  197820. pixelFormat (pixelFormat_)
  197821. {
  197822. jassert (component != 0);
  197823. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197824. if (peer == 0)
  197825. return;
  197826. ScopedXLock xlock;
  197827. XSync (display, False);
  197828. GLint attribs [64];
  197829. int n = 0;
  197830. attribs[n++] = GLX_RGBA;
  197831. attribs[n++] = GLX_DOUBLEBUFFER;
  197832. attribs[n++] = GLX_RED_SIZE;
  197833. attribs[n++] = pixelFormat.redBits;
  197834. attribs[n++] = GLX_GREEN_SIZE;
  197835. attribs[n++] = pixelFormat.greenBits;
  197836. attribs[n++] = GLX_BLUE_SIZE;
  197837. attribs[n++] = pixelFormat.blueBits;
  197838. attribs[n++] = GLX_ALPHA_SIZE;
  197839. attribs[n++] = pixelFormat.alphaBits;
  197840. attribs[n++] = GLX_DEPTH_SIZE;
  197841. attribs[n++] = pixelFormat.depthBufferBits;
  197842. attribs[n++] = GLX_STENCIL_SIZE;
  197843. attribs[n++] = pixelFormat.stencilBufferBits;
  197844. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197845. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197846. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197847. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197848. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197849. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197850. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197851. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197852. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197853. attribs[n++] = None;
  197854. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  197855. if (bestVisual == 0)
  197856. return;
  197857. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  197858. Window windowH = (Window) peer->getNativeHandle();
  197859. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  197860. XSetWindowAttributes swa;
  197861. swa.colormap = colourMap;
  197862. swa.border_pixel = 0;
  197863. swa.event_mask = ExposureMask | StructureNotifyMask;
  197864. embeddedWindow = XCreateWindow (display, windowH,
  197865. 0, 0, 1, 1, 0,
  197866. bestVisual->depth,
  197867. InputOutput,
  197868. bestVisual->visual,
  197869. CWBorderPixel | CWColormap | CWEventMask,
  197870. &swa);
  197871. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  197872. XMapWindow (display, embeddedWindow);
  197873. XFreeColormap (display, colourMap);
  197874. XFree (bestVisual);
  197875. XSync (display, False);
  197876. }
  197877. ~WindowedGLContext()
  197878. {
  197879. makeInactive();
  197880. ScopedXLock xlock;
  197881. glXDestroyContext (display, renderContext);
  197882. XUnmapWindow (display, embeddedWindow);
  197883. XDestroyWindow (display, embeddedWindow);
  197884. }
  197885. bool makeActive() const throw()
  197886. {
  197887. jassert (renderContext != 0);
  197888. ScopedXLock xlock;
  197889. return glXMakeCurrent (display, embeddedWindow, renderContext)
  197890. && XSync (display, False);
  197891. }
  197892. bool makeInactive() const throw()
  197893. {
  197894. ScopedXLock xlock;
  197895. return (! isActive()) || glXMakeCurrent (display, None, 0);
  197896. }
  197897. bool isActive() const throw()
  197898. {
  197899. ScopedXLock xlock;
  197900. return glXGetCurrentContext() == renderContext;
  197901. }
  197902. const OpenGLPixelFormat getPixelFormat() const
  197903. {
  197904. return pixelFormat;
  197905. }
  197906. void* getRawContext() const throw()
  197907. {
  197908. return renderContext;
  197909. }
  197910. void updateWindowPosition (int x, int y, int w, int h, int)
  197911. {
  197912. ScopedXLock xlock;
  197913. XMoveResizeWindow (display, embeddedWindow,
  197914. x, y, jmax (1, w), jmax (1, h));
  197915. }
  197916. void swapBuffers()
  197917. {
  197918. ScopedXLock xlock;
  197919. glXSwapBuffers (display, embeddedWindow);
  197920. }
  197921. bool setSwapInterval (const int numFramesPerSwap)
  197922. {
  197923. // xxx needs doing..
  197924. return false;
  197925. }
  197926. int getSwapInterval() const
  197927. {
  197928. // xxx needs doing..
  197929. return 0;
  197930. }
  197931. void repaint()
  197932. {
  197933. }
  197934. juce_UseDebuggingNewOperator
  197935. GLXContext renderContext;
  197936. private:
  197937. Window embeddedWindow;
  197938. OpenGLPixelFormat pixelFormat;
  197939. WindowedGLContext (const WindowedGLContext&);
  197940. WindowedGLContext& operator= (const WindowedGLContext&);
  197941. };
  197942. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  197943. const OpenGLPixelFormat& pixelFormat,
  197944. const OpenGLContext* const contextToShareWith)
  197945. {
  197946. WindowedGLContext* c = new WindowedGLContext (component, pixelFormat,
  197947. contextToShareWith != 0 ? (GLXContext) contextToShareWith->getRawContext() : 0);
  197948. if (c->renderContext == 0)
  197949. deleteAndZero (c);
  197950. return c;
  197951. }
  197952. void juce_glViewport (const int w, const int h)
  197953. {
  197954. glViewport (0, 0, w, h);
  197955. }
  197956. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  197957. OwnedArray <OpenGLPixelFormat>& results)
  197958. {
  197959. results.add (new OpenGLPixelFormat()); // xxx
  197960. }
  197961. #endif
  197962. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  197963. {
  197964. jassertfalse // not implemented!
  197965. return false;
  197966. }
  197967. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  197968. {
  197969. jassertfalse // not implemented!
  197970. return false;
  197971. }
  197972. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  197973. {
  197974. if (! isOnDesktop ())
  197975. addToDesktop (0);
  197976. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197977. if (wp != 0)
  197978. {
  197979. wp->setTaskBarIcon (newImage);
  197980. setVisible (true);
  197981. toFront (false);
  197982. repaint();
  197983. }
  197984. }
  197985. void SystemTrayIconComponent::paint (Graphics& g)
  197986. {
  197987. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197988. if (wp != 0)
  197989. {
  197990. const Image* const image = wp->getTaskbarIcon();
  197991. if (image != 0)
  197992. {
  197993. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  197994. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197995. false);
  197996. }
  197997. }
  197998. }
  197999. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  198000. {
  198001. // xxx not yet implemented!
  198002. }
  198003. void PlatformUtilities::beep()
  198004. {
  198005. std::cout << "\a" << std::flush;
  198006. }
  198007. bool AlertWindow::showNativeDialogBox (const String& title,
  198008. const String& bodyText,
  198009. bool isOkCancel)
  198010. {
  198011. // use a non-native one for the time being..
  198012. if (isOkCancel)
  198013. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  198014. else
  198015. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  198016. return true;
  198017. }
  198018. const int KeyPress::spaceKey = XK_space & 0xff;
  198019. const int KeyPress::returnKey = XK_Return & 0xff;
  198020. const int KeyPress::escapeKey = XK_Escape & 0xff;
  198021. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  198022. const int KeyPress::leftKey = (XK_Left & 0xff) | extendedKeyModifier;
  198023. const int KeyPress::rightKey = (XK_Right & 0xff) | extendedKeyModifier;
  198024. const int KeyPress::upKey = (XK_Up & 0xff) | extendedKeyModifier;
  198025. const int KeyPress::downKey = (XK_Down & 0xff) | extendedKeyModifier;
  198026. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | extendedKeyModifier;
  198027. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | extendedKeyModifier;
  198028. const int KeyPress::endKey = (XK_End & 0xff) | extendedKeyModifier;
  198029. const int KeyPress::homeKey = (XK_Home & 0xff) | extendedKeyModifier;
  198030. const int KeyPress::insertKey = (XK_Insert & 0xff) | extendedKeyModifier;
  198031. const int KeyPress::deleteKey = (XK_Delete & 0xff) | extendedKeyModifier;
  198032. const int KeyPress::tabKey = XK_Tab & 0xff;
  198033. const int KeyPress::F1Key = (XK_F1 & 0xff) | extendedKeyModifier;
  198034. const int KeyPress::F2Key = (XK_F2 & 0xff) | extendedKeyModifier;
  198035. const int KeyPress::F3Key = (XK_F3 & 0xff) | extendedKeyModifier;
  198036. const int KeyPress::F4Key = (XK_F4 & 0xff) | extendedKeyModifier;
  198037. const int KeyPress::F5Key = (XK_F5 & 0xff) | extendedKeyModifier;
  198038. const int KeyPress::F6Key = (XK_F6 & 0xff) | extendedKeyModifier;
  198039. const int KeyPress::F7Key = (XK_F7 & 0xff) | extendedKeyModifier;
  198040. const int KeyPress::F8Key = (XK_F8 & 0xff) | extendedKeyModifier;
  198041. const int KeyPress::F9Key = (XK_F9 & 0xff) | extendedKeyModifier;
  198042. const int KeyPress::F10Key = (XK_F10 & 0xff) | extendedKeyModifier;
  198043. const int KeyPress::F11Key = (XK_F11 & 0xff) | extendedKeyModifier;
  198044. const int KeyPress::F12Key = (XK_F12 & 0xff) | extendedKeyModifier;
  198045. const int KeyPress::F13Key = (XK_F13 & 0xff) | extendedKeyModifier;
  198046. const int KeyPress::F14Key = (XK_F14 & 0xff) | extendedKeyModifier;
  198047. const int KeyPress::F15Key = (XK_F15 & 0xff) | extendedKeyModifier;
  198048. const int KeyPress::F16Key = (XK_F16 & 0xff) | extendedKeyModifier;
  198049. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | extendedKeyModifier;
  198050. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | extendedKeyModifier;
  198051. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | extendedKeyModifier;
  198052. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | extendedKeyModifier;
  198053. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | extendedKeyModifier;
  198054. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | extendedKeyModifier;
  198055. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | extendedKeyModifier;
  198056. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| extendedKeyModifier;
  198057. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| extendedKeyModifier;
  198058. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| extendedKeyModifier;
  198059. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| extendedKeyModifier;
  198060. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| extendedKeyModifier;
  198061. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| extendedKeyModifier;
  198062. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| extendedKeyModifier;
  198063. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| extendedKeyModifier;
  198064. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| extendedKeyModifier;
  198065. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| extendedKeyModifier;
  198066. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| extendedKeyModifier;
  198067. const int KeyPress::playKey = (0xffeeff00) | extendedKeyModifier;
  198068. const int KeyPress::stopKey = (0xffeeff01) | extendedKeyModifier;
  198069. const int KeyPress::fastForwardKey = (0xffeeff02) | extendedKeyModifier;
  198070. const int KeyPress::rewindKey = (0xffeeff03) | extendedKeyModifier;
  198071. #endif
  198072. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  198073. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  198074. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198075. // compiled on its own).
  198076. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  198077. static const int maxNumChans = 64;
  198078. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  198079. {
  198080. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  198081. snd_pcm_hw_params_t* hwParams;
  198082. snd_pcm_hw_params_alloca (&hwParams);
  198083. for (int i = 0; ratesToTry[i] != 0; ++i)
  198084. {
  198085. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  198086. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  198087. {
  198088. rates.addIfNotAlreadyThere (ratesToTry[i]);
  198089. }
  198090. }
  198091. }
  198092. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  198093. {
  198094. snd_pcm_hw_params_t *params;
  198095. snd_pcm_hw_params_alloca (&params);
  198096. if (snd_pcm_hw_params_any (handle, params) >= 0)
  198097. {
  198098. snd_pcm_hw_params_get_channels_min (params, minChans);
  198099. snd_pcm_hw_params_get_channels_max (params, maxChans);
  198100. }
  198101. }
  198102. static void getDeviceProperties (const String& deviceID,
  198103. unsigned int& minChansOut,
  198104. unsigned int& maxChansOut,
  198105. unsigned int& minChansIn,
  198106. unsigned int& maxChansIn,
  198107. Array <int>& rates)
  198108. {
  198109. if (deviceID.isEmpty())
  198110. return;
  198111. snd_ctl_t* handle;
  198112. if (snd_ctl_open (&handle, deviceID.upToLastOccurrenceOf (T(","), false, false).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  198113. {
  198114. snd_pcm_info_t* info;
  198115. snd_pcm_info_alloca (&info);
  198116. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  198117. snd_pcm_info_set_device (info, deviceID.fromLastOccurrenceOf (T(","), false, false).getIntValue());
  198118. snd_pcm_info_set_subdevice (info, 0);
  198119. if (snd_ctl_pcm_info (handle, info) >= 0)
  198120. {
  198121. snd_pcm_t* pcmHandle;
  198122. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198123. {
  198124. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  198125. getDeviceSampleRates (pcmHandle, rates);
  198126. snd_pcm_close (pcmHandle);
  198127. }
  198128. }
  198129. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  198130. if (snd_ctl_pcm_info (handle, info) >= 0)
  198131. {
  198132. snd_pcm_t* pcmHandle;
  198133. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198134. {
  198135. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  198136. if (rates.size() == 0)
  198137. getDeviceSampleRates (pcmHandle, rates);
  198138. snd_pcm_close (pcmHandle);
  198139. }
  198140. }
  198141. snd_ctl_close (handle);
  198142. }
  198143. }
  198144. class ALSADevice
  198145. {
  198146. public:
  198147. ALSADevice (const String& deviceID,
  198148. const bool forInput)
  198149. : handle (0),
  198150. bitDepth (16),
  198151. numChannelsRunning (0),
  198152. isInput (forInput),
  198153. sampleFormat (AudioDataConverters::int16LE)
  198154. {
  198155. failed (snd_pcm_open (&handle, deviceID.toUTF8(),
  198156. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  198157. SND_PCM_ASYNC));
  198158. }
  198159. ~ALSADevice()
  198160. {
  198161. if (handle != 0)
  198162. snd_pcm_close (handle);
  198163. }
  198164. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  198165. {
  198166. if (handle == 0)
  198167. return false;
  198168. snd_pcm_hw_params_t* hwParams;
  198169. snd_pcm_hw_params_alloca (&hwParams);
  198170. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  198171. return false;
  198172. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  198173. isInterleaved = false;
  198174. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  198175. isInterleaved = true;
  198176. else
  198177. {
  198178. jassertfalse
  198179. return false;
  198180. }
  198181. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  198182. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  198183. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  198184. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  198185. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  198186. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  198187. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  198188. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  198189. bitDepth = 0;
  198190. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  198191. {
  198192. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  198193. {
  198194. bitDepth = formatsToTry [i + 1];
  198195. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  198196. break;
  198197. }
  198198. }
  198199. if (bitDepth == 0)
  198200. {
  198201. error = "device doesn't support a compatible PCM format";
  198202. DBG (T("ALSA error: ") + error + T("\n"));
  198203. return false;
  198204. }
  198205. int dir = 0;
  198206. unsigned int periods = 4;
  198207. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  198208. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  198209. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  198210. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  198211. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  198212. || failed (snd_pcm_hw_params (handle, hwParams)))
  198213. {
  198214. return false;
  198215. }
  198216. snd_pcm_sw_params_t* swParams;
  198217. snd_pcm_sw_params_alloca (&swParams);
  198218. snd_pcm_uframes_t boundary;
  198219. if (failed (snd_pcm_sw_params_current (handle, swParams))
  198220. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  198221. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  198222. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  198223. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  198224. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  198225. || failed (snd_pcm_sw_params (handle, swParams)))
  198226. {
  198227. return false;
  198228. }
  198229. numChannelsRunning = numChannels;
  198230. return true;
  198231. }
  198232. bool write (float** const data, const int numSamples)
  198233. {
  198234. if (isInterleaved)
  198235. {
  198236. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198237. float* interleaved = reinterpret_cast <float*> (scratch.getData());
  198238. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  198239. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198240. snd_pcm_sframes_t num = snd_pcm_writei (handle, (void*) interleaved, numSamples);
  198241. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198242. return false;
  198243. }
  198244. else
  198245. {
  198246. for (int i = 0; i < numChannelsRunning; ++i)
  198247. if (data[i] != 0)
  198248. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  198249. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  198250. if (failed (num))
  198251. {
  198252. if (num == -EPIPE)
  198253. {
  198254. if (failed (snd_pcm_prepare (handle)))
  198255. return false;
  198256. }
  198257. else if (num != -ESTRPIPE)
  198258. return false;
  198259. }
  198260. }
  198261. return true;
  198262. }
  198263. bool read (float** const data, const int numSamples)
  198264. {
  198265. if (isInterleaved)
  198266. {
  198267. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198268. float* interleaved = reinterpret_cast <float*> (scratch.getData());
  198269. snd_pcm_sframes_t num = snd_pcm_readi (handle, (void*) interleaved, numSamples);
  198270. if (failed (num))
  198271. {
  198272. if (num == -EPIPE)
  198273. {
  198274. if (failed (snd_pcm_prepare (handle)))
  198275. return false;
  198276. }
  198277. else if (num != -ESTRPIPE)
  198278. return false;
  198279. }
  198280. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198281. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  198282. }
  198283. else
  198284. {
  198285. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  198286. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198287. return false;
  198288. for (int i = 0; i < numChannelsRunning; ++i)
  198289. if (data[i] != 0)
  198290. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  198291. }
  198292. return true;
  198293. }
  198294. juce_UseDebuggingNewOperator
  198295. snd_pcm_t* handle;
  198296. String error;
  198297. int bitDepth, numChannelsRunning;
  198298. private:
  198299. const bool isInput;
  198300. bool isInterleaved;
  198301. MemoryBlock scratch;
  198302. AudioDataConverters::DataFormat sampleFormat;
  198303. bool failed (const int errorNum)
  198304. {
  198305. if (errorNum >= 0)
  198306. return false;
  198307. error = snd_strerror (errorNum);
  198308. DBG (T("ALSA error: ") + error + T("\n"));
  198309. return true;
  198310. }
  198311. };
  198312. class ALSAThread : public Thread
  198313. {
  198314. public:
  198315. ALSAThread (const String& inputId_,
  198316. const String& outputId_)
  198317. : Thread ("Juce ALSA"),
  198318. sampleRate (0),
  198319. bufferSize (0),
  198320. callback (0),
  198321. inputId (inputId_),
  198322. outputId (outputId_),
  198323. outputDevice (0),
  198324. inputDevice (0),
  198325. numCallbacks (0),
  198326. totalNumInputChannels (0),
  198327. totalNumOutputChannels (0)
  198328. {
  198329. zeromem (outputChannelData, sizeof (outputChannelData));
  198330. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198331. zeromem (inputChannelData, sizeof (inputChannelData));
  198332. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198333. initialiseRatesAndChannels();
  198334. }
  198335. ~ALSAThread()
  198336. {
  198337. close();
  198338. }
  198339. void open (BitArray inputChannels,
  198340. BitArray outputChannels,
  198341. const double sampleRate_,
  198342. const int bufferSize_)
  198343. {
  198344. close();
  198345. error = String::empty;
  198346. sampleRate = sampleRate_;
  198347. bufferSize = bufferSize_;
  198348. currentInputChans.clear();
  198349. currentOutputChans.clear();
  198350. if (inputChannels.getHighestBit() >= 0)
  198351. {
  198352. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198353. {
  198354. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198355. if (inputChannels[i])
  198356. {
  198357. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198358. currentInputChans.setBit (i);
  198359. }
  198360. }
  198361. }
  198362. if (outputChannels.getHighestBit() >= 0)
  198363. {
  198364. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198365. {
  198366. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198367. if (outputChannels[i])
  198368. {
  198369. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198370. currentOutputChans.setBit (i);
  198371. }
  198372. }
  198373. }
  198374. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198375. {
  198376. outputDevice = new ALSADevice (outputId, false);
  198377. if (outputDevice->error.isNotEmpty())
  198378. {
  198379. error = outputDevice->error;
  198380. deleteAndZero (outputDevice);
  198381. return;
  198382. }
  198383. currentOutputChans.setRange (0, minChansOut, true);
  198384. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198385. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198386. bufferSize))
  198387. {
  198388. error = outputDevice->error;
  198389. deleteAndZero (outputDevice);
  198390. return;
  198391. }
  198392. }
  198393. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198394. {
  198395. inputDevice = new ALSADevice (inputId, true);
  198396. if (inputDevice->error.isNotEmpty())
  198397. {
  198398. error = inputDevice->error;
  198399. deleteAndZero (inputDevice);
  198400. return;
  198401. }
  198402. currentInputChans.setRange (0, minChansIn, true);
  198403. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198404. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198405. bufferSize))
  198406. {
  198407. error = inputDevice->error;
  198408. deleteAndZero (inputDevice);
  198409. return;
  198410. }
  198411. }
  198412. if (outputDevice == 0 && inputDevice == 0)
  198413. {
  198414. error = "no channels";
  198415. return;
  198416. }
  198417. if (outputDevice != 0 && inputDevice != 0)
  198418. {
  198419. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198420. }
  198421. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198422. return;
  198423. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198424. return;
  198425. startThread (9);
  198426. int count = 1000;
  198427. while (numCallbacks == 0)
  198428. {
  198429. sleep (5);
  198430. if (--count < 0 || ! isThreadRunning())
  198431. {
  198432. error = "device didn't start";
  198433. break;
  198434. }
  198435. }
  198436. }
  198437. void close()
  198438. {
  198439. stopThread (6000);
  198440. deleteAndZero (inputDevice);
  198441. deleteAndZero (outputDevice);
  198442. for (int i = 0; i < maxNumChans; ++i)
  198443. {
  198444. juce_free (inputChannelData [i]);
  198445. juce_free (outputChannelData [i]);
  198446. }
  198447. zeromem (outputChannelData, sizeof (outputChannelData));
  198448. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198449. zeromem (inputChannelData, sizeof (inputChannelData));
  198450. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198451. totalNumOutputChannels = 0;
  198452. totalNumInputChannels = 0;
  198453. numCallbacks = 0;
  198454. }
  198455. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198456. {
  198457. const ScopedLock sl (callbackLock);
  198458. callback = newCallback;
  198459. }
  198460. void run()
  198461. {
  198462. while (! threadShouldExit())
  198463. {
  198464. if (inputDevice != 0)
  198465. {
  198466. if (! inputDevice->read (inputChannelData, bufferSize))
  198467. {
  198468. DBG ("ALSA: read failure");
  198469. break;
  198470. }
  198471. }
  198472. if (threadShouldExit())
  198473. break;
  198474. {
  198475. const ScopedLock sl (callbackLock);
  198476. ++numCallbacks;
  198477. if (callback != 0)
  198478. {
  198479. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198480. totalNumInputChannels,
  198481. outputChannelDataForCallback,
  198482. totalNumOutputChannels,
  198483. bufferSize);
  198484. }
  198485. else
  198486. {
  198487. for (int i = 0; i < totalNumOutputChannels; ++i)
  198488. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198489. }
  198490. }
  198491. if (outputDevice != 0)
  198492. {
  198493. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198494. if (threadShouldExit())
  198495. break;
  198496. failed (snd_pcm_avail_update (outputDevice->handle));
  198497. if (! outputDevice->write (outputChannelData, bufferSize))
  198498. {
  198499. DBG ("ALSA: write failure");
  198500. break;
  198501. }
  198502. }
  198503. }
  198504. }
  198505. int getBitDepth() const throw()
  198506. {
  198507. if (outputDevice != 0)
  198508. return outputDevice->bitDepth;
  198509. if (inputDevice != 0)
  198510. return inputDevice->bitDepth;
  198511. return 16;
  198512. }
  198513. juce_UseDebuggingNewOperator
  198514. String error;
  198515. double sampleRate;
  198516. int bufferSize;
  198517. BitArray currentInputChans, currentOutputChans;
  198518. Array <int> sampleRates;
  198519. StringArray channelNamesOut, channelNamesIn;
  198520. AudioIODeviceCallback* callback;
  198521. private:
  198522. const String inputId, outputId;
  198523. ALSADevice* outputDevice;
  198524. ALSADevice* inputDevice;
  198525. int numCallbacks;
  198526. CriticalSection callbackLock;
  198527. float* outputChannelData [maxNumChans];
  198528. float* outputChannelDataForCallback [maxNumChans];
  198529. int totalNumInputChannels;
  198530. float* inputChannelData [maxNumChans];
  198531. float* inputChannelDataForCallback [maxNumChans];
  198532. int totalNumOutputChannels;
  198533. unsigned int minChansOut, maxChansOut;
  198534. unsigned int minChansIn, maxChansIn;
  198535. bool failed (const int errorNum) throw()
  198536. {
  198537. if (errorNum >= 0)
  198538. return false;
  198539. error = snd_strerror (errorNum);
  198540. DBG (T("ALSA error: ") + error + T("\n"));
  198541. return true;
  198542. }
  198543. void initialiseRatesAndChannels() throw()
  198544. {
  198545. sampleRates.clear();
  198546. channelNamesOut.clear();
  198547. channelNamesIn.clear();
  198548. minChansOut = 0;
  198549. maxChansOut = 0;
  198550. minChansIn = 0;
  198551. maxChansIn = 0;
  198552. unsigned int dummy = 0;
  198553. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198554. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198555. unsigned int i;
  198556. for (i = 0; i < maxChansOut; ++i)
  198557. channelNamesOut.add (T("channel ") + String ((int) i + 1));
  198558. for (i = 0; i < maxChansIn; ++i)
  198559. channelNamesIn.add (T("channel ") + String ((int) i + 1));
  198560. }
  198561. };
  198562. class ALSAAudioIODevice : public AudioIODevice
  198563. {
  198564. public:
  198565. ALSAAudioIODevice (const String& deviceName,
  198566. const String& inputId_,
  198567. const String& outputId_)
  198568. : AudioIODevice (deviceName, T("ALSA")),
  198569. inputId (inputId_),
  198570. outputId (outputId_),
  198571. isOpen_ (false),
  198572. isStarted (false),
  198573. internal (0)
  198574. {
  198575. internal = new ALSAThread (inputId, outputId);
  198576. }
  198577. ~ALSAAudioIODevice()
  198578. {
  198579. delete internal;
  198580. }
  198581. const StringArray getOutputChannelNames()
  198582. {
  198583. return internal->channelNamesOut;
  198584. }
  198585. const StringArray getInputChannelNames()
  198586. {
  198587. return internal->channelNamesIn;
  198588. }
  198589. int getNumSampleRates()
  198590. {
  198591. return internal->sampleRates.size();
  198592. }
  198593. double getSampleRate (int index)
  198594. {
  198595. return internal->sampleRates [index];
  198596. }
  198597. int getNumBufferSizesAvailable()
  198598. {
  198599. return 50;
  198600. }
  198601. int getBufferSizeSamples (int index)
  198602. {
  198603. int n = 16;
  198604. for (int i = 0; i < index; ++i)
  198605. n += n < 64 ? 16
  198606. : (n < 512 ? 32
  198607. : (n < 1024 ? 64
  198608. : (n < 2048 ? 128 : 256)));
  198609. return n;
  198610. }
  198611. int getDefaultBufferSize()
  198612. {
  198613. return 512;
  198614. }
  198615. const String open (const BitArray& inputChannels,
  198616. const BitArray& outputChannels,
  198617. double sampleRate,
  198618. int bufferSizeSamples)
  198619. {
  198620. close();
  198621. if (bufferSizeSamples <= 0)
  198622. bufferSizeSamples = getDefaultBufferSize();
  198623. if (sampleRate <= 0)
  198624. {
  198625. for (int i = 0; i < getNumSampleRates(); ++i)
  198626. {
  198627. if (getSampleRate (i) >= 44100)
  198628. {
  198629. sampleRate = getSampleRate (i);
  198630. break;
  198631. }
  198632. }
  198633. }
  198634. internal->open (inputChannels, outputChannels,
  198635. sampleRate, bufferSizeSamples);
  198636. isOpen_ = internal->error.isEmpty();
  198637. return internal->error;
  198638. }
  198639. void close()
  198640. {
  198641. stop();
  198642. internal->close();
  198643. isOpen_ = false;
  198644. }
  198645. bool isOpen()
  198646. {
  198647. return isOpen_;
  198648. }
  198649. int getCurrentBufferSizeSamples()
  198650. {
  198651. return internal->bufferSize;
  198652. }
  198653. double getCurrentSampleRate()
  198654. {
  198655. return internal->sampleRate;
  198656. }
  198657. int getCurrentBitDepth()
  198658. {
  198659. return internal->getBitDepth();
  198660. }
  198661. const BitArray getActiveOutputChannels() const
  198662. {
  198663. return internal->currentOutputChans;
  198664. }
  198665. const BitArray getActiveInputChannels() const
  198666. {
  198667. return internal->currentInputChans;
  198668. }
  198669. int getOutputLatencyInSamples()
  198670. {
  198671. return 0;
  198672. }
  198673. int getInputLatencyInSamples()
  198674. {
  198675. return 0;
  198676. }
  198677. void start (AudioIODeviceCallback* callback)
  198678. {
  198679. if (! isOpen_)
  198680. callback = 0;
  198681. internal->setCallback (callback);
  198682. if (callback != 0)
  198683. callback->audioDeviceAboutToStart (this);
  198684. isStarted = (callback != 0);
  198685. }
  198686. void stop()
  198687. {
  198688. AudioIODeviceCallback* const oldCallback = internal->callback;
  198689. start (0);
  198690. if (oldCallback != 0)
  198691. oldCallback->audioDeviceStopped();
  198692. }
  198693. bool isPlaying()
  198694. {
  198695. return isStarted && internal->error.isEmpty();
  198696. }
  198697. const String getLastError()
  198698. {
  198699. return internal->error;
  198700. }
  198701. String inputId, outputId;
  198702. private:
  198703. bool isOpen_, isStarted;
  198704. ALSAThread* internal;
  198705. };
  198706. class ALSAAudioIODeviceType : public AudioIODeviceType
  198707. {
  198708. public:
  198709. ALSAAudioIODeviceType()
  198710. : AudioIODeviceType (T("ALSA")),
  198711. hasScanned (false)
  198712. {
  198713. }
  198714. ~ALSAAudioIODeviceType()
  198715. {
  198716. }
  198717. void scanForDevices()
  198718. {
  198719. if (hasScanned)
  198720. return;
  198721. hasScanned = true;
  198722. inputNames.clear();
  198723. inputIds.clear();
  198724. outputNames.clear();
  198725. outputIds.clear();
  198726. snd_ctl_t* handle;
  198727. snd_ctl_card_info_t* info;
  198728. snd_ctl_card_info_alloca (&info);
  198729. int cardNum = -1;
  198730. while (outputIds.size() + inputIds.size() <= 32)
  198731. {
  198732. snd_card_next (&cardNum);
  198733. if (cardNum < 0)
  198734. break;
  198735. if (snd_ctl_open (&handle, ("hw:" + String (cardNum)).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  198736. {
  198737. if (snd_ctl_card_info (handle, info) >= 0)
  198738. {
  198739. String cardId (snd_ctl_card_info_get_id (info));
  198740. if (cardId.removeCharacters (T("0123456789")).isEmpty())
  198741. cardId = String (cardNum);
  198742. int device = -1;
  198743. for (;;)
  198744. {
  198745. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198746. break;
  198747. String id, name;
  198748. id << "hw:" << cardId << ',' << device;
  198749. bool isInput, isOutput;
  198750. if (testDevice (id, isInput, isOutput))
  198751. {
  198752. name << snd_ctl_card_info_get_name (info);
  198753. if (name.isEmpty())
  198754. name = id;
  198755. if (isInput)
  198756. {
  198757. inputNames.add (name);
  198758. inputIds.add (id);
  198759. }
  198760. if (isOutput)
  198761. {
  198762. outputNames.add (name);
  198763. outputIds.add (id);
  198764. }
  198765. }
  198766. }
  198767. }
  198768. snd_ctl_close (handle);
  198769. }
  198770. }
  198771. inputNames.appendNumbersToDuplicates (false, true);
  198772. outputNames.appendNumbersToDuplicates (false, true);
  198773. }
  198774. const StringArray getDeviceNames (const bool wantInputNames) const
  198775. {
  198776. jassert (hasScanned); // need to call scanForDevices() before doing this
  198777. return wantInputNames ? inputNames : outputNames;
  198778. }
  198779. int getDefaultDeviceIndex (const bool forInput) const
  198780. {
  198781. jassert (hasScanned); // need to call scanForDevices() before doing this
  198782. return 0;
  198783. }
  198784. bool hasSeparateInputsAndOutputs() const { return true; }
  198785. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  198786. {
  198787. jassert (hasScanned); // need to call scanForDevices() before doing this
  198788. ALSAAudioIODevice* const d = dynamic_cast <ALSAAudioIODevice*> (device);
  198789. if (d == 0)
  198790. return -1;
  198791. return asInput ? inputIds.indexOf (d->inputId)
  198792. : outputIds.indexOf (d->outputId);
  198793. }
  198794. AudioIODevice* createDevice (const String& outputDeviceName,
  198795. const String& inputDeviceName)
  198796. {
  198797. jassert (hasScanned); // need to call scanForDevices() before doing this
  198798. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198799. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198800. String deviceName (outputIndex >= 0 ? outputDeviceName
  198801. : inputDeviceName);
  198802. if (inputIndex >= 0 || outputIndex >= 0)
  198803. return new ALSAAudioIODevice (deviceName,
  198804. inputIds [inputIndex],
  198805. outputIds [outputIndex]);
  198806. return 0;
  198807. }
  198808. juce_UseDebuggingNewOperator
  198809. private:
  198810. StringArray inputNames, outputNames, inputIds, outputIds;
  198811. bool hasScanned;
  198812. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198813. {
  198814. unsigned int minChansOut = 0, maxChansOut = 0;
  198815. unsigned int minChansIn = 0, maxChansIn = 0;
  198816. Array <int> rates;
  198817. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198818. DBG (T("ALSA device: ") + id
  198819. + T(" outs=") + String ((int) minChansOut) + T("-") + String ((int) maxChansOut)
  198820. + T(" ins=") + String ((int) minChansIn) + T("-") + String ((int) maxChansIn)
  198821. + T(" rates=") + String (rates.size()));
  198822. isInput = maxChansIn > 0;
  198823. isOutput = maxChansOut > 0;
  198824. return (isInput || isOutput) && rates.size() > 0;
  198825. }
  198826. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198827. ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198828. };
  198829. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198830. {
  198831. return new ALSAAudioIODeviceType();
  198832. }
  198833. #endif
  198834. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198835. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198836. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198837. // compiled on its own).
  198838. #ifdef JUCE_INCLUDED_FILE
  198839. #if JUCE_JACK
  198840. static void* juce_libjack_handle = 0;
  198841. void* juce_load_jack_function (const char* const name)
  198842. {
  198843. if (juce_libjack_handle == 0)
  198844. return 0;
  198845. return dlsym (juce_libjack_handle, name);
  198846. }
  198847. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198848. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198849. return_type fn_name argument_types { \
  198850. static fn_name##_ptr_t fn = 0; \
  198851. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198852. if (fn) return (*fn)arguments; \
  198853. else return 0; \
  198854. }
  198855. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  198856. typedef void (*fn_name##_ptr_t)argument_types; \
  198857. void fn_name argument_types { \
  198858. static fn_name##_ptr_t fn = 0; \
  198859. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198860. if (fn) (*fn)arguments; \
  198861. }
  198862. 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));
  198863. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  198864. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  198865. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  198866. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  198867. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  198868. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  198869. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  198870. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  198871. 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));
  198872. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  198873. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  198874. 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));
  198875. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  198876. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  198877. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  198878. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  198879. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  198880. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  198881. #if JUCE_DEBUG
  198882. #define JACK_LOGGING_ENABLED 1
  198883. #endif
  198884. #if JACK_LOGGING_ENABLED
  198885. static void jack_Log (const String& s)
  198886. {
  198887. std::cerr << s << std::endl;
  198888. }
  198889. static void dumpJackErrorMessage (const jack_status_t status) throw()
  198890. {
  198891. if (status & JackServerFailed || status & JackServerError)
  198892. jack_Log ("Unable to connect to JACK server");
  198893. if (status & JackVersionError)
  198894. jack_Log ("Client's protocol version does not match");
  198895. if (status & JackInvalidOption)
  198896. jack_Log ("The operation contained an invalid or unsupported option");
  198897. if (status & JackNameNotUnique)
  198898. jack_Log ("The desired client name was not unique");
  198899. if (status & JackNoSuchClient)
  198900. jack_Log ("Requested client does not exist");
  198901. if (status & JackInitFailure)
  198902. jack_Log ("Unable to initialize client");
  198903. }
  198904. #else
  198905. #define dumpJackErrorMessage(a) {}
  198906. #define jack_Log(...) {}
  198907. #endif
  198908. #ifndef JUCE_JACK_CLIENT_NAME
  198909. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  198910. #endif
  198911. class JackAudioIODevice : public AudioIODevice
  198912. {
  198913. public:
  198914. JackAudioIODevice (const String& deviceName,
  198915. const String& inputId_,
  198916. const String& outputId_)
  198917. : AudioIODevice (deviceName, T("JACK")),
  198918. inputId (inputId_),
  198919. outputId (outputId_),
  198920. isOpen_ (false),
  198921. callback (0),
  198922. totalNumberOfInputChannels (0),
  198923. totalNumberOfOutputChannels (0)
  198924. {
  198925. jassert (deviceName.isNotEmpty());
  198926. jack_status_t status;
  198927. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  198928. if (client == 0)
  198929. {
  198930. dumpJackErrorMessage (status);
  198931. }
  198932. else
  198933. {
  198934. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  198935. // open input ports
  198936. const StringArray inputChannels (getInputChannelNames());
  198937. for (int i = 0; i < inputChannels.size(); i++)
  198938. {
  198939. String inputName;
  198940. inputName << "in_" << ++totalNumberOfInputChannels;
  198941. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, inputName.toUTF8(),
  198942. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  198943. }
  198944. // open output ports
  198945. const StringArray outputChannels (getOutputChannelNames());
  198946. for (int i = 0; i < outputChannels.size (); i++)
  198947. {
  198948. String outputName;
  198949. outputName << "out_" << ++totalNumberOfOutputChannels;
  198950. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, outputName.toUTF8(),
  198951. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  198952. }
  198953. inChans.calloc (totalNumberOfInputChannels + 2);
  198954. outChans.calloc (totalNumberOfOutputChannels + 2);
  198955. }
  198956. }
  198957. ~JackAudioIODevice()
  198958. {
  198959. close();
  198960. if (client != 0)
  198961. {
  198962. JUCE_NAMESPACE::jack_client_close (client);
  198963. client = 0;
  198964. }
  198965. }
  198966. const StringArray getChannelNames (bool forInput) const
  198967. {
  198968. StringArray names;
  198969. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  198970. forInput ? JackPortIsInput : JackPortIsOutput);
  198971. if (ports != 0)
  198972. {
  198973. int j = 0;
  198974. while (ports[j] != 0)
  198975. {
  198976. const String portName (ports [j++]);
  198977. if (portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  198978. names.add (portName.fromFirstOccurrenceOf (T(":"), false, false));
  198979. }
  198980. free (ports);
  198981. }
  198982. return names;
  198983. }
  198984. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  198985. const StringArray getInputChannelNames() { return getChannelNames (true); }
  198986. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  198987. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  198988. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  198989. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  198990. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  198991. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  198992. double sampleRate, int bufferSizeSamples)
  198993. {
  198994. if (client == 0)
  198995. {
  198996. lastError = T("No JACK client running");
  198997. return lastError;
  198998. }
  198999. lastError = String::empty;
  199000. close();
  199001. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  199002. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  199003. JUCE_NAMESPACE::jack_activate (client);
  199004. isOpen_ = true;
  199005. if (! inputChannels.isEmpty())
  199006. {
  199007. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199008. if (ports != 0)
  199009. {
  199010. const int numInputChannels = inputChannels.getHighestBit () + 1;
  199011. for (int i = 0; i < numInputChannels; ++i)
  199012. {
  199013. const String portName (ports[i]);
  199014. if (inputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199015. {
  199016. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  199017. if (error != 0)
  199018. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199019. }
  199020. }
  199021. free (ports);
  199022. }
  199023. }
  199024. if (! outputChannels.isEmpty())
  199025. {
  199026. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199027. if (ports != 0)
  199028. {
  199029. const int numOutputChannels = outputChannels.getHighestBit () + 1;
  199030. for (int i = 0; i < numOutputChannels; ++i)
  199031. {
  199032. const String portName (ports[i]);
  199033. if (outputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199034. {
  199035. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  199036. if (error != 0)
  199037. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199038. }
  199039. }
  199040. free (ports);
  199041. }
  199042. }
  199043. return lastError;
  199044. }
  199045. void close()
  199046. {
  199047. stop();
  199048. if (client != 0)
  199049. {
  199050. JUCE_NAMESPACE::jack_deactivate (client);
  199051. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  199052. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  199053. }
  199054. isOpen_ = false;
  199055. }
  199056. void start (AudioIODeviceCallback* newCallback)
  199057. {
  199058. if (isOpen_ && newCallback != callback)
  199059. {
  199060. if (newCallback != 0)
  199061. newCallback->audioDeviceAboutToStart (this);
  199062. AudioIODeviceCallback* const oldCallback = callback;
  199063. {
  199064. const ScopedLock sl (callbackLock);
  199065. callback = newCallback;
  199066. }
  199067. if (oldCallback != 0)
  199068. oldCallback->audioDeviceStopped();
  199069. }
  199070. }
  199071. void stop()
  199072. {
  199073. start (0);
  199074. }
  199075. bool isOpen() { return isOpen_; }
  199076. bool isPlaying() { return callback != 0; }
  199077. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  199078. double getCurrentSampleRate() { return getSampleRate (0); }
  199079. int getCurrentBitDepth() { return 32; }
  199080. const String getLastError() { return lastError; }
  199081. const BitArray getActiveOutputChannels() const
  199082. {
  199083. BitArray outputBits;
  199084. for (int i = 0; i < outputPorts.size(); i++)
  199085. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  199086. outputBits.setBit (i);
  199087. return outputBits;
  199088. }
  199089. const BitArray getActiveInputChannels() const
  199090. {
  199091. BitArray inputBits;
  199092. for (int i = 0; i < inputPorts.size(); i++)
  199093. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  199094. inputBits.setBit (i);
  199095. return inputBits;
  199096. }
  199097. int getOutputLatencyInSamples()
  199098. {
  199099. int latency = 0;
  199100. for (int i = 0; i < outputPorts.size(); i++)
  199101. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  199102. return latency;
  199103. }
  199104. int getInputLatencyInSamples()
  199105. {
  199106. int latency = 0;
  199107. for (int i = 0; i < inputPorts.size(); i++)
  199108. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  199109. return latency;
  199110. }
  199111. String inputId, outputId;
  199112. private:
  199113. void process (const int numSamples)
  199114. {
  199115. int i, numActiveInChans = 0, numActiveOutChans = 0;
  199116. for (i = 0; i < totalNumberOfInputChannels; ++i)
  199117. {
  199118. jack_default_audio_sample_t* in
  199119. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  199120. if (in != 0)
  199121. inChans [numActiveInChans++] = (float*) in;
  199122. }
  199123. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  199124. {
  199125. jack_default_audio_sample_t* out
  199126. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  199127. if (out != 0)
  199128. outChans [numActiveOutChans++] = (float*) out;
  199129. }
  199130. const ScopedLock sl (callbackLock);
  199131. if (callback != 0)
  199132. {
  199133. callback->audioDeviceIOCallback (const_cast<const float**> (inChans.getData()), numActiveInChans,
  199134. outChans, numActiveOutChans, numSamples);
  199135. }
  199136. else
  199137. {
  199138. for (i = 0; i < numActiveOutChans; ++i)
  199139. zeromem (outChans[i], sizeof (float) * numSamples);
  199140. }
  199141. }
  199142. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  199143. {
  199144. if (callbackArgument != 0)
  199145. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  199146. return 0;
  199147. }
  199148. static void threadInitCallback (void* callbackArgument)
  199149. {
  199150. jack_Log ("JackAudioIODevice::initialise");
  199151. }
  199152. static void shutdownCallback (void* callbackArgument)
  199153. {
  199154. jack_Log ("JackAudioIODevice::shutdown");
  199155. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  199156. if (device != 0)
  199157. {
  199158. device->client = 0;
  199159. device->close();
  199160. }
  199161. }
  199162. static void errorCallback (const char* msg)
  199163. {
  199164. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  199165. }
  199166. bool isOpen_;
  199167. jack_client_t* client;
  199168. String lastError;
  199169. AudioIODeviceCallback* callback;
  199170. CriticalSection callbackLock;
  199171. HeapBlock <float*> inChans, outChans;
  199172. int totalNumberOfInputChannels;
  199173. int totalNumberOfOutputChannels;
  199174. VoidArray inputPorts, outputPorts;
  199175. };
  199176. class JackAudioIODeviceType : public AudioIODeviceType
  199177. {
  199178. public:
  199179. JackAudioIODeviceType()
  199180. : AudioIODeviceType (T("JACK")),
  199181. hasScanned (false)
  199182. {
  199183. }
  199184. ~JackAudioIODeviceType()
  199185. {
  199186. }
  199187. void scanForDevices()
  199188. {
  199189. hasScanned = true;
  199190. inputNames.clear();
  199191. inputIds.clear();
  199192. outputNames.clear();
  199193. outputIds.clear();
  199194. if (juce_libjack_handle == 0)
  199195. {
  199196. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  199197. if (juce_libjack_handle == 0)
  199198. return;
  199199. }
  199200. // open a dummy client
  199201. jack_status_t status;
  199202. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  199203. if (client == 0)
  199204. {
  199205. dumpJackErrorMessage (status);
  199206. }
  199207. else
  199208. {
  199209. // scan for output devices
  199210. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199211. if (ports != 0)
  199212. {
  199213. int j = 0;
  199214. while (ports[j] != 0)
  199215. {
  199216. String clientName (ports[j]);
  199217. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199218. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199219. && ! inputNames.contains (clientName))
  199220. {
  199221. inputNames.add (clientName);
  199222. inputIds.add (ports [j]);
  199223. }
  199224. ++j;
  199225. }
  199226. free (ports);
  199227. }
  199228. // scan for input devices
  199229. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199230. if (ports != 0)
  199231. {
  199232. int j = 0;
  199233. while (ports[j] != 0)
  199234. {
  199235. String clientName (ports[j]);
  199236. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199237. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199238. && ! outputNames.contains (clientName))
  199239. {
  199240. outputNames.add (clientName);
  199241. outputIds.add (ports [j]);
  199242. }
  199243. ++j;
  199244. }
  199245. free (ports);
  199246. }
  199247. JUCE_NAMESPACE::jack_client_close (client);
  199248. }
  199249. }
  199250. const StringArray getDeviceNames (const bool wantInputNames) const
  199251. {
  199252. jassert (hasScanned); // need to call scanForDevices() before doing this
  199253. return wantInputNames ? inputNames : outputNames;
  199254. }
  199255. int getDefaultDeviceIndex (const bool forInput) const
  199256. {
  199257. jassert (hasScanned); // need to call scanForDevices() before doing this
  199258. return 0;
  199259. }
  199260. bool hasSeparateInputsAndOutputs() const { return true; }
  199261. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  199262. {
  199263. jassert (hasScanned); // need to call scanForDevices() before doing this
  199264. JackAudioIODevice* const d = dynamic_cast <JackAudioIODevice*> (device);
  199265. if (d == 0)
  199266. return -1;
  199267. return asInput ? inputIds.indexOf (d->inputId)
  199268. : outputIds.indexOf (d->outputId);
  199269. }
  199270. AudioIODevice* createDevice (const String& outputDeviceName,
  199271. const String& inputDeviceName)
  199272. {
  199273. jassert (hasScanned); // need to call scanForDevices() before doing this
  199274. const int inputIndex = inputNames.indexOf (inputDeviceName);
  199275. const int outputIndex = outputNames.indexOf (outputDeviceName);
  199276. if (inputIndex >= 0 || outputIndex >= 0)
  199277. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  199278. : inputDeviceName,
  199279. inputIds [inputIndex],
  199280. outputIds [outputIndex]);
  199281. return 0;
  199282. }
  199283. juce_UseDebuggingNewOperator
  199284. private:
  199285. StringArray inputNames, outputNames, inputIds, outputIds;
  199286. bool hasScanned;
  199287. JackAudioIODeviceType (const JackAudioIODeviceType&);
  199288. JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  199289. };
  199290. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  199291. {
  199292. return new JackAudioIODeviceType();
  199293. }
  199294. #else // if JACK is turned off..
  199295. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  199296. #endif
  199297. #endif
  199298. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  199299. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  199300. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199301. // compiled on its own).
  199302. #if JUCE_INCLUDED_FILE
  199303. #if JUCE_ALSA
  199304. static snd_seq_t* iterateDevices (const bool forInput,
  199305. StringArray& deviceNamesFound,
  199306. const int deviceIndexToOpen)
  199307. {
  199308. snd_seq_t* returnedHandle = 0;
  199309. snd_seq_t* seqHandle;
  199310. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199311. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199312. {
  199313. snd_seq_system_info_t* systemInfo;
  199314. snd_seq_client_info_t* clientInfo;
  199315. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199316. {
  199317. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199318. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199319. {
  199320. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199321. while (--numClients >= 0 && returnedHandle == 0)
  199322. {
  199323. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199324. {
  199325. snd_seq_port_info_t* portInfo;
  199326. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199327. {
  199328. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199329. const int client = snd_seq_client_info_get_client (clientInfo);
  199330. snd_seq_port_info_set_client (portInfo, client);
  199331. snd_seq_port_info_set_port (portInfo, -1);
  199332. while (--numPorts >= 0)
  199333. {
  199334. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199335. && (snd_seq_port_info_get_capability (portInfo)
  199336. & (forInput ? SND_SEQ_PORT_CAP_READ
  199337. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199338. {
  199339. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199340. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199341. {
  199342. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199343. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199344. if (sourcePort != -1)
  199345. {
  199346. snd_seq_set_client_name (seqHandle,
  199347. forInput ? "Juce Midi Input"
  199348. : "Juce Midi Output");
  199349. const int portId
  199350. = snd_seq_create_simple_port (seqHandle,
  199351. forInput ? "Juce Midi In Port"
  199352. : "Juce Midi Out Port",
  199353. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199354. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199355. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199356. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199357. returnedHandle = seqHandle;
  199358. }
  199359. }
  199360. }
  199361. }
  199362. snd_seq_port_info_free (portInfo);
  199363. }
  199364. }
  199365. }
  199366. snd_seq_client_info_free (clientInfo);
  199367. }
  199368. snd_seq_system_info_free (systemInfo);
  199369. }
  199370. if (returnedHandle == 0)
  199371. snd_seq_close (seqHandle);
  199372. }
  199373. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199374. return returnedHandle;
  199375. }
  199376. static snd_seq_t* createDevice (const bool forInput,
  199377. const String& deviceNameToOpen)
  199378. {
  199379. snd_seq_t* seqHandle = 0;
  199380. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199381. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199382. {
  199383. snd_seq_set_client_name (seqHandle,
  199384. (deviceNameToOpen + (forInput ? " Input" : " Output")).toCString());
  199385. const int portId
  199386. = snd_seq_create_simple_port (seqHandle,
  199387. forInput ? "in"
  199388. : "out",
  199389. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199390. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199391. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199392. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199393. if (portId < 0)
  199394. {
  199395. snd_seq_close (seqHandle);
  199396. seqHandle = 0;
  199397. }
  199398. }
  199399. return seqHandle;
  199400. }
  199401. class MidiOutputDevice
  199402. {
  199403. public:
  199404. MidiOutputDevice (MidiOutput* const midiOutput_,
  199405. snd_seq_t* const seqHandle_)
  199406. :
  199407. midiOutput (midiOutput_),
  199408. seqHandle (seqHandle_),
  199409. maxEventSize (16 * 1024)
  199410. {
  199411. jassert (seqHandle != 0 && midiOutput != 0);
  199412. snd_midi_event_new (maxEventSize, &midiParser);
  199413. }
  199414. ~MidiOutputDevice()
  199415. {
  199416. snd_midi_event_free (midiParser);
  199417. snd_seq_close (seqHandle);
  199418. }
  199419. void sendMessageNow (const MidiMessage& message)
  199420. {
  199421. if (message.getRawDataSize() > maxEventSize)
  199422. {
  199423. maxEventSize = message.getRawDataSize();
  199424. snd_midi_event_free (midiParser);
  199425. snd_midi_event_new (maxEventSize, &midiParser);
  199426. }
  199427. snd_seq_event_t event;
  199428. snd_seq_ev_clear (&event);
  199429. snd_midi_event_encode (midiParser,
  199430. message.getRawData(),
  199431. message.getRawDataSize(),
  199432. &event);
  199433. snd_midi_event_reset_encode (midiParser);
  199434. snd_seq_ev_set_source (&event, 0);
  199435. snd_seq_ev_set_subs (&event);
  199436. snd_seq_ev_set_direct (&event);
  199437. snd_seq_event_output (seqHandle, &event);
  199438. snd_seq_drain_output (seqHandle);
  199439. }
  199440. juce_UseDebuggingNewOperator
  199441. private:
  199442. MidiOutput* const midiOutput;
  199443. snd_seq_t* const seqHandle;
  199444. snd_midi_event_t* midiParser;
  199445. int maxEventSize;
  199446. };
  199447. const StringArray MidiOutput::getDevices()
  199448. {
  199449. StringArray devices;
  199450. iterateDevices (false, devices, -1);
  199451. return devices;
  199452. }
  199453. int MidiOutput::getDefaultDeviceIndex()
  199454. {
  199455. return 0;
  199456. }
  199457. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199458. {
  199459. MidiOutput* newDevice = 0;
  199460. StringArray devices;
  199461. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199462. if (handle != 0)
  199463. {
  199464. newDevice = new MidiOutput();
  199465. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199466. }
  199467. return newDevice;
  199468. }
  199469. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199470. {
  199471. MidiOutput* newDevice = 0;
  199472. snd_seq_t* const handle = createDevice (false, deviceName);
  199473. if (handle != 0)
  199474. {
  199475. newDevice = new MidiOutput();
  199476. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199477. }
  199478. return newDevice;
  199479. }
  199480. MidiOutput::~MidiOutput()
  199481. {
  199482. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199483. delete device;
  199484. }
  199485. void MidiOutput::reset()
  199486. {
  199487. }
  199488. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199489. {
  199490. return false;
  199491. }
  199492. void MidiOutput::setVolume (float leftVol, float rightVol)
  199493. {
  199494. }
  199495. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199496. {
  199497. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199498. }
  199499. class MidiInputThread : public Thread
  199500. {
  199501. public:
  199502. MidiInputThread (MidiInput* const midiInput_,
  199503. snd_seq_t* const seqHandle_,
  199504. MidiInputCallback* const callback_)
  199505. : Thread (T("Juce MIDI Input")),
  199506. midiInput (midiInput_),
  199507. seqHandle (seqHandle_),
  199508. callback (callback_)
  199509. {
  199510. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199511. }
  199512. ~MidiInputThread()
  199513. {
  199514. snd_seq_close (seqHandle);
  199515. }
  199516. void run()
  199517. {
  199518. const int maxEventSize = 16 * 1024;
  199519. snd_midi_event_t* midiParser;
  199520. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199521. {
  199522. HeapBlock <uint8> buffer (maxEventSize);
  199523. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199524. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199525. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199526. while (! threadShouldExit())
  199527. {
  199528. if (poll (pfd, numPfds, 500) > 0)
  199529. {
  199530. snd_seq_event_t* inputEvent = 0;
  199531. snd_seq_nonblock (seqHandle, 1);
  199532. do
  199533. {
  199534. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199535. {
  199536. // xxx what about SYSEXes that are too big for the buffer?
  199537. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199538. snd_midi_event_reset_decode (midiParser);
  199539. if (numBytes > 0)
  199540. {
  199541. const MidiMessage message ((const uint8*) buffer,
  199542. numBytes,
  199543. Time::getMillisecondCounter() * 0.001);
  199544. callback->handleIncomingMidiMessage (midiInput, message);
  199545. }
  199546. snd_seq_free_event (inputEvent);
  199547. }
  199548. }
  199549. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199550. snd_seq_free_event (inputEvent);
  199551. }
  199552. }
  199553. snd_midi_event_free (midiParser);
  199554. }
  199555. };
  199556. juce_UseDebuggingNewOperator
  199557. private:
  199558. MidiInput* const midiInput;
  199559. snd_seq_t* const seqHandle;
  199560. MidiInputCallback* const callback;
  199561. };
  199562. MidiInput::MidiInput (const String& name_)
  199563. : name (name_),
  199564. internal (0)
  199565. {
  199566. }
  199567. MidiInput::~MidiInput()
  199568. {
  199569. stop();
  199570. MidiInputThread* const thread = (MidiInputThread*) internal;
  199571. delete thread;
  199572. }
  199573. void MidiInput::start()
  199574. {
  199575. ((MidiInputThread*) internal)->startThread();
  199576. }
  199577. void MidiInput::stop()
  199578. {
  199579. ((MidiInputThread*) internal)->stopThread (3000);
  199580. }
  199581. int MidiInput::getDefaultDeviceIndex()
  199582. {
  199583. return 0;
  199584. }
  199585. const StringArray MidiInput::getDevices()
  199586. {
  199587. StringArray devices;
  199588. iterateDevices (true, devices, -1);
  199589. return devices;
  199590. }
  199591. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199592. {
  199593. MidiInput* newDevice = 0;
  199594. StringArray devices;
  199595. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199596. if (handle != 0)
  199597. {
  199598. newDevice = new MidiInput (devices [deviceIndex]);
  199599. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199600. }
  199601. return newDevice;
  199602. }
  199603. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199604. {
  199605. MidiInput* newDevice = 0;
  199606. snd_seq_t* const handle = createDevice (true, deviceName);
  199607. if (handle != 0)
  199608. {
  199609. newDevice = new MidiInput (deviceName);
  199610. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199611. }
  199612. return newDevice;
  199613. }
  199614. #else
  199615. // (These are just stub functions if ALSA is unavailable...)
  199616. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199617. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199618. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199619. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199620. MidiOutput::~MidiOutput() {}
  199621. void MidiOutput::reset() {}
  199622. bool MidiOutput::getVolume (float&, float&) { return false; }
  199623. void MidiOutput::setVolume (float, float) {}
  199624. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199625. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199626. MidiInput::~MidiInput() {}
  199627. void MidiInput::start() {}
  199628. void MidiInput::stop() {}
  199629. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199630. const StringArray MidiInput::getDevices() { return StringArray(); }
  199631. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199632. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199633. #endif
  199634. #endif
  199635. /*** End of inlined file: juce_linux_Midi.cpp ***/
  199636. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  199637. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199638. // compiled on its own).
  199639. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199640. AudioCDReader::AudioCDReader()
  199641. : AudioFormatReader (0, T("CD Audio"))
  199642. {
  199643. }
  199644. const StringArray AudioCDReader::getAvailableCDNames()
  199645. {
  199646. StringArray names;
  199647. return names;
  199648. }
  199649. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199650. {
  199651. return 0;
  199652. }
  199653. AudioCDReader::~AudioCDReader()
  199654. {
  199655. }
  199656. void AudioCDReader::refreshTrackLengths()
  199657. {
  199658. }
  199659. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199660. int64 startSampleInFile, int numSamples)
  199661. {
  199662. return false;
  199663. }
  199664. bool AudioCDReader::isCDStillPresent() const
  199665. {
  199666. return false;
  199667. }
  199668. int AudioCDReader::getNumTracks() const
  199669. {
  199670. return 0;
  199671. }
  199672. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199673. {
  199674. return 0;
  199675. }
  199676. bool AudioCDReader::isTrackAudio (int trackNum) const
  199677. {
  199678. return false;
  199679. }
  199680. void AudioCDReader::enableIndexScanning (bool b)
  199681. {
  199682. }
  199683. int AudioCDReader::getLastIndex() const
  199684. {
  199685. return 0;
  199686. }
  199687. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199688. {
  199689. return Array<int>();
  199690. }
  199691. int AudioCDReader::getCDDBId()
  199692. {
  199693. return 0;
  199694. }
  199695. #endif
  199696. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199697. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199698. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199699. // compiled on its own).
  199700. #if JUCE_INCLUDED_FILE
  199701. void FileChooser::showPlatformDialog (Array<File>& results,
  199702. const String& title,
  199703. const File& file,
  199704. const String& filters,
  199705. bool isDirectory,
  199706. bool selectsFiles,
  199707. bool isSave,
  199708. bool warnAboutOverwritingExistingFiles,
  199709. bool selectMultipleFiles,
  199710. FilePreviewComponent* previewComponent)
  199711. {
  199712. const tchar* const separator = T(":");
  199713. String command ("zenity --file-selection");
  199714. if (title.isNotEmpty())
  199715. command << " --title=\"" << title << "\"";
  199716. if (file != File::nonexistent)
  199717. command << " --filename=\"" << file.getFullPathName () << "\"";
  199718. if (isDirectory)
  199719. command << " --directory";
  199720. if (isSave)
  199721. command << " --save";
  199722. if (selectMultipleFiles)
  199723. command << " --multiple --separator=\"" << separator << "\"";
  199724. command << " 2>&1";
  199725. MemoryOutputStream result;
  199726. int status = -1;
  199727. FILE* stream = popen ((const char*) command.toUTF8(), "r");
  199728. if (stream != 0)
  199729. {
  199730. for (;;)
  199731. {
  199732. char buffer [1024];
  199733. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199734. if (bytesRead <= 0)
  199735. break;
  199736. result.write (buffer, bytesRead);
  199737. }
  199738. status = pclose (stream);
  199739. }
  199740. if (status == 0)
  199741. {
  199742. String resultString (String::fromUTF8 ((const char*) result.getData(), result.getDataSize()));
  199743. StringArray tokens;
  199744. if (selectMultipleFiles)
  199745. tokens.addTokens (resultString, separator, 0);
  199746. else
  199747. tokens.add (resultString);
  199748. for (int i = 0; i < tokens.size(); i++)
  199749. results.add (File (tokens[i]));
  199750. return;
  199751. }
  199752. //xxx ain't got one!
  199753. jassertfalse
  199754. }
  199755. #endif
  199756. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199757. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199758. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199759. // compiled on its own).
  199760. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199761. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199762. : browser (0),
  199763. blankPageShown (false),
  199764. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199765. {
  199766. setOpaque (true);
  199767. }
  199768. WebBrowserComponent::~WebBrowserComponent()
  199769. {
  199770. }
  199771. void WebBrowserComponent::goToURL (const String& url,
  199772. const StringArray* headers,
  199773. const MemoryBlock* postData)
  199774. {
  199775. lastURL = url;
  199776. lastHeaders.clear();
  199777. if (headers != 0)
  199778. lastHeaders = *headers;
  199779. lastPostData.setSize (0);
  199780. if (postData != 0)
  199781. lastPostData = *postData;
  199782. blankPageShown = false;
  199783. }
  199784. void WebBrowserComponent::stop()
  199785. {
  199786. }
  199787. void WebBrowserComponent::goBack()
  199788. {
  199789. lastURL = String::empty;
  199790. blankPageShown = false;
  199791. }
  199792. void WebBrowserComponent::goForward()
  199793. {
  199794. lastURL = String::empty;
  199795. }
  199796. void WebBrowserComponent::refresh()
  199797. {
  199798. }
  199799. void WebBrowserComponent::paint (Graphics& g)
  199800. {
  199801. g.fillAll (Colours::white);
  199802. }
  199803. void WebBrowserComponent::checkWindowAssociation()
  199804. {
  199805. }
  199806. void WebBrowserComponent::reloadLastURL()
  199807. {
  199808. if (lastURL.isNotEmpty())
  199809. {
  199810. goToURL (lastURL, &lastHeaders, &lastPostData);
  199811. lastURL = String::empty;
  199812. }
  199813. }
  199814. void WebBrowserComponent::parentHierarchyChanged()
  199815. {
  199816. checkWindowAssociation();
  199817. }
  199818. void WebBrowserComponent::resized()
  199819. {
  199820. }
  199821. void WebBrowserComponent::visibilityChanged()
  199822. {
  199823. checkWindowAssociation();
  199824. }
  199825. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199826. {
  199827. return true;
  199828. }
  199829. #endif
  199830. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199831. #endif
  199832. END_JUCE_NAMESPACE
  199833. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199834. #endif
  199835. #if JUCE_MAC || JUCE_IPHONE
  199836. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199837. BEGIN_JUCE_NAMESPACE
  199838. #undef Point
  199839. #define JUCE_INCLUDED_FILE 1
  199840. // Now include the actual code files..
  199841. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199842. #ifndef JUCE_ObjCExtraSuffix
  199843. #define JUCE_ObjCExtraSuffix 3
  199844. #endif
  199845. #define appendMacro1(a, b, c, d, e) a ## _ ## b ## _ ## c ## _ ## d ## _ ## e
  199846. #define appendMacro2(a, b, c, d, e) appendMacro1(a, b, c, d, e)
  199847. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_BUILDNUMBER, JUCE_ObjCExtraSuffix)
  199848. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199849. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199850. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199851. // compiled on its own).
  199852. #if JUCE_INCLUDED_FILE
  199853. static const String nsStringToJuce (NSString* s)
  199854. {
  199855. return String::fromUTF8 ([s UTF8String]);
  199856. }
  199857. static NSString* juceStringToNS (const String& s)
  199858. {
  199859. return [NSString stringWithUTF8String: s.toUTF8()];
  199860. }
  199861. static const String convertUTF16ToString (const UniChar* utf16)
  199862. {
  199863. String s;
  199864. while (*utf16 != 0)
  199865. s += (juce_wchar) *utf16++;
  199866. return s;
  199867. }
  199868. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  199869. {
  199870. String result;
  199871. if (cfString != 0)
  199872. {
  199873. CFRange range = { 0, CFStringGetLength (cfString) };
  199874. HeapBlock <UniChar> u (range.length + 1);
  199875. CFStringGetCharacters (cfString, range, u);
  199876. u[range.length] = 0;
  199877. result = convertUTF16ToString (u);
  199878. }
  199879. return result;
  199880. }
  199881. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  199882. {
  199883. const int len = s.length();
  199884. const juce_wchar* t = (const juce_wchar*) s;
  199885. HeapBlock <UniChar> temp (len + 2);
  199886. for (int i = 0; i <= len; ++i)
  199887. temp[i] = t[i];
  199888. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  199889. }
  199890. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  199891. {
  199892. #if JUCE_IPHONE
  199893. const ScopedAutoReleasePool pool;
  199894. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  199895. #else
  199896. UnicodeMapping map;
  199897. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199898. kUnicodeNoSubset,
  199899. kTextEncodingDefaultFormat);
  199900. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199901. kUnicodeCanonicalCompVariant,
  199902. kTextEncodingDefaultFormat);
  199903. map.mappingVersion = kUnicodeUseLatestMapping;
  199904. UnicodeToTextInfo conversionInfo = 0;
  199905. String result;
  199906. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  199907. {
  199908. const int len = s.length();
  199909. HeapBlock <UniChar> tempIn, tempOut;
  199910. tempIn.calloc (len + 2);
  199911. tempOut.calloc (len + 2);
  199912. for (int i = 0; i <= len; ++i)
  199913. tempIn[i] = s[i];
  199914. ByteCount bytesRead = 0;
  199915. ByteCount outputBufferSize = 0;
  199916. if (ConvertFromUnicodeToText (conversionInfo,
  199917. len * sizeof (UniChar), tempIn,
  199918. kUnicodeDefaultDirectionMask,
  199919. 0, 0, 0, 0,
  199920. len * sizeof (UniChar), &bytesRead,
  199921. &outputBufferSize, tempOut) == noErr)
  199922. {
  199923. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  199924. tchar* t = const_cast <tchar*> ((const tchar*) result);
  199925. unsigned int i;
  199926. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  199927. t[i] = (tchar) tempOut[i];
  199928. t[i] = 0;
  199929. }
  199930. DisposeUnicodeToTextInfo (&conversionInfo);
  199931. }
  199932. return result;
  199933. #endif
  199934. }
  199935. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  199936. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  199937. {
  199938. #if JUCE_IPHONE
  199939. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  199940. forPasteboardType: @"public.text"];
  199941. #else
  199942. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  199943. owner: nil];
  199944. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  199945. forType: NSStringPboardType];
  199946. #endif
  199947. }
  199948. const String SystemClipboard::getTextFromClipboard() throw()
  199949. {
  199950. #if JUCE_IPHONE
  199951. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  199952. #else
  199953. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  199954. #endif
  199955. return text == 0 ? String::empty
  199956. : nsStringToJuce (text);
  199957. }
  199958. #endif
  199959. #endif
  199960. /*** End of inlined file: juce_mac_Strings.mm ***/
  199961. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  199962. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199963. // compiled on its own).
  199964. #if JUCE_INCLUDED_FILE
  199965. static int64 highResTimerFrequency = 0;
  199966. static double highResTimerToMillisecRatio = 0;
  199967. #if JUCE_INTEL
  199968. static void juce_getCpuVendor (char* const v) throw()
  199969. {
  199970. int vendor[4];
  199971. zerostruct (vendor);
  199972. int dummy = 0;
  199973. asm ("mov %%ebx, %%esi \n\t"
  199974. "cpuid \n\t"
  199975. "xchg %%esi, %%ebx"
  199976. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  199977. memcpy (v, vendor, 16);
  199978. }
  199979. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  199980. {
  199981. unsigned int cpu = 0;
  199982. unsigned int ext = 0;
  199983. unsigned int family = 0;
  199984. unsigned int dummy = 0;
  199985. asm ("mov %%ebx, %%esi \n\t"
  199986. "cpuid \n\t"
  199987. "xchg %%esi, %%ebx"
  199988. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  199989. familyModel = family;
  199990. extFeatures = ext;
  199991. return cpu;
  199992. }
  199993. struct CPUFlags
  199994. {
  199995. bool hasMMX : 1;
  199996. bool hasSSE : 1;
  199997. bool hasSSE2 : 1;
  199998. bool has3DNow : 1;
  199999. };
  200000. static CPUFlags cpuFlags;
  200001. #endif
  200002. void SystemStats::initialiseStats() throw()
  200003. {
  200004. static bool initialised = false;
  200005. if (! initialised)
  200006. {
  200007. initialised = true;
  200008. #if JUCE_MAC
  200009. // extremely annoying: adding this line stops the apple menu items from working. Of
  200010. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  200011. // any events.
  200012. //NSApplicationLoad();
  200013. [NSApplication sharedApplication];
  200014. #endif
  200015. #if JUCE_INTEL
  200016. {
  200017. unsigned int familyModel, extFeatures;
  200018. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  200019. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  200020. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  200021. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  200022. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  200023. }
  200024. #endif
  200025. mach_timebase_info_data_t timebase;
  200026. (void) mach_timebase_info (&timebase);
  200027. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  200028. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  200029. String s (SystemStats::getJUCEVersion());
  200030. rlimit lim;
  200031. getrlimit (RLIMIT_NOFILE, &lim);
  200032. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  200033. setrlimit (RLIMIT_NOFILE, &lim);
  200034. }
  200035. }
  200036. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  200037. {
  200038. return MacOSX;
  200039. }
  200040. const String SystemStats::getOperatingSystemName() throw()
  200041. {
  200042. return T("Mac OS X");
  200043. }
  200044. bool SystemStats::isOperatingSystem64Bit() throw()
  200045. {
  200046. #if JUCE_64BIT
  200047. return true;
  200048. #else
  200049. //xxx not sure how to find this out?..
  200050. return false;
  200051. #endif
  200052. }
  200053. int SystemStats::getMemorySizeInMegabytes() throw()
  200054. {
  200055. uint64 mem = 0;
  200056. size_t memSize = sizeof (mem);
  200057. int mib[] = { CTL_HW, HW_MEMSIZE };
  200058. sysctl (mib, 2, &mem, &memSize, 0, 0);
  200059. return (int) (mem / (1024 * 1024));
  200060. }
  200061. bool SystemStats::hasMMX() throw()
  200062. {
  200063. #if JUCE_INTEL
  200064. return cpuFlags.hasMMX;
  200065. #else
  200066. return false;
  200067. #endif
  200068. }
  200069. bool SystemStats::hasSSE() throw()
  200070. {
  200071. #if JUCE_INTEL
  200072. return cpuFlags.hasSSE;
  200073. #else
  200074. return false;
  200075. #endif
  200076. }
  200077. bool SystemStats::hasSSE2() throw()
  200078. {
  200079. #if JUCE_INTEL
  200080. return cpuFlags.hasSSE2;
  200081. #else
  200082. return false;
  200083. #endif
  200084. }
  200085. bool SystemStats::has3DNow() throw()
  200086. {
  200087. #if JUCE_INTEL
  200088. return cpuFlags.has3DNow;
  200089. #else
  200090. return false;
  200091. #endif
  200092. }
  200093. const String SystemStats::getCpuVendor() throw()
  200094. {
  200095. #if JUCE_INTEL
  200096. char v [16];
  200097. juce_getCpuVendor (v);
  200098. return String (v, 16);
  200099. #else
  200100. return String::empty;
  200101. #endif
  200102. }
  200103. int SystemStats::getCpuSpeedInMegaherz() throw()
  200104. {
  200105. uint64 speedHz = 0;
  200106. size_t speedSize = sizeof (speedHz);
  200107. int mib[] = { CTL_HW, HW_CPU_FREQ };
  200108. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  200109. #if JUCE_BIG_ENDIAN
  200110. if (speedSize == 4)
  200111. speedHz >>= 32;
  200112. #endif
  200113. return (int) (speedHz / 1000000);
  200114. }
  200115. int SystemStats::getNumCpus() throw()
  200116. {
  200117. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  200118. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  200119. #else
  200120. return MPProcessors();
  200121. #endif
  200122. }
  200123. const String SystemStats::getLogonName()
  200124. {
  200125. return nsStringToJuce (NSUserName());
  200126. }
  200127. const String SystemStats::getFullUserName()
  200128. {
  200129. return nsStringToJuce (NSFullUserName());
  200130. }
  200131. uint32 juce_millisecondsSinceStartup() throw()
  200132. {
  200133. return (uint32) (mach_absolute_time() * highResTimerToMillisecRatio);
  200134. }
  200135. double Time::getMillisecondCounterHiRes() throw()
  200136. {
  200137. return mach_absolute_time() * highResTimerToMillisecRatio;
  200138. }
  200139. int64 Time::getHighResolutionTicks() throw()
  200140. {
  200141. return (int64) mach_absolute_time();
  200142. }
  200143. int64 Time::getHighResolutionTicksPerSecond() throw()
  200144. {
  200145. return highResTimerFrequency;
  200146. }
  200147. int64 SystemStats::getClockCycleCounter() throw()
  200148. {
  200149. return (int64) mach_absolute_time();
  200150. }
  200151. bool Time::setSystemTimeToThisTime() const throw()
  200152. {
  200153. jassertfalse
  200154. return false;
  200155. }
  200156. int SystemStats::getPageSize() throw()
  200157. {
  200158. return (int) NSPageSize();
  200159. }
  200160. void PlatformUtilities::fpuReset()
  200161. {
  200162. }
  200163. #endif
  200164. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  200165. /*** Start of inlined file: juce_mac_Network.mm ***/
  200166. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200167. // compiled on its own).
  200168. #if JUCE_INCLUDED_FILE
  200169. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  200170. {
  200171. #ifndef IFT_ETHER
  200172. #define IFT_ETHER 6
  200173. #endif
  200174. ifaddrs* addrs = 0;
  200175. int numResults = 0;
  200176. if (getifaddrs (&addrs) == 0)
  200177. {
  200178. const ifaddrs* cursor = addrs;
  200179. while (cursor != 0 && numResults < maxNum)
  200180. {
  200181. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  200182. if (sto->ss_family == AF_LINK)
  200183. {
  200184. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  200185. if (sadd->sdl_type == IFT_ETHER)
  200186. {
  200187. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  200188. uint64 a = 0;
  200189. for (int i = 6; --i >= 0;)
  200190. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  200191. *addresses++ = (int64) a;
  200192. ++numResults;
  200193. }
  200194. }
  200195. cursor = cursor->ifa_next;
  200196. }
  200197. freeifaddrs (addrs);
  200198. }
  200199. return numResults;
  200200. }
  200201. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  200202. const String& emailSubject,
  200203. const String& bodyText,
  200204. const StringArray& filesToAttach)
  200205. {
  200206. #if JUCE_IPHONE
  200207. //xxx probably need to use MFMailComposeViewController
  200208. jassertfalse
  200209. return false;
  200210. #else
  200211. const ScopedAutoReleasePool pool;
  200212. String script;
  200213. script << "tell application \"Mail\"\r\n"
  200214. "set newMessage to make new outgoing message with properties {subject:\""
  200215. << emailSubject.replace (T("\""), T("\\\""))
  200216. << "\", content:\""
  200217. << bodyText.replace (T("\""), T("\\\""))
  200218. << "\" & return & return}\r\n"
  200219. "tell newMessage\r\n"
  200220. "set visible to true\r\n"
  200221. "set sender to \"sdfsdfsdfewf\"\r\n"
  200222. "make new to recipient at end of to recipients with properties {address:\""
  200223. << targetEmailAddress
  200224. << "\"}\r\n";
  200225. for (int i = 0; i < filesToAttach.size(); ++i)
  200226. {
  200227. script << "tell content\r\n"
  200228. "make new attachment with properties {file name:\""
  200229. << filesToAttach[i].replace (T("\""), T("\\\""))
  200230. << "\"} at after the last paragraph\r\n"
  200231. "end tell\r\n";
  200232. }
  200233. script << "end tell\r\n"
  200234. "end tell\r\n";
  200235. NSAppleScript* s = [[NSAppleScript alloc]
  200236. initWithSource: juceStringToNS (script)];
  200237. NSDictionary* error = 0;
  200238. const bool ok = [s executeAndReturnError: &error] != nil;
  200239. [s release];
  200240. return ok;
  200241. #endif
  200242. }
  200243. END_JUCE_NAMESPACE
  200244. using namespace JUCE_NAMESPACE;
  200245. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  200246. @interface JuceURLConnection : NSObject
  200247. {
  200248. @public
  200249. NSURLRequest* request;
  200250. NSURLConnection* connection;
  200251. NSMutableData* data;
  200252. Thread* runLoopThread;
  200253. bool initialised, hasFailed, hasFinished;
  200254. int position;
  200255. int64 contentLength;
  200256. NSLock* dataLock;
  200257. }
  200258. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  200259. - (void) dealloc;
  200260. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  200261. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  200262. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  200263. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  200264. - (BOOL) isOpen;
  200265. - (int) read: (char*) dest numBytes: (int) num;
  200266. - (int) readPosition;
  200267. - (void) stop;
  200268. - (void) createConnection;
  200269. @end
  200270. class JuceURLConnectionMessageThread : public Thread
  200271. {
  200272. JuceURLConnection* owner;
  200273. public:
  200274. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  200275. : Thread (T("http connection")),
  200276. owner (owner_)
  200277. {
  200278. }
  200279. ~JuceURLConnectionMessageThread()
  200280. {
  200281. stopThread (10000);
  200282. }
  200283. void run()
  200284. {
  200285. [owner createConnection];
  200286. while (! threadShouldExit())
  200287. {
  200288. const ScopedAutoReleasePool pool;
  200289. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200290. }
  200291. }
  200292. };
  200293. @implementation JuceURLConnection
  200294. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200295. withCallback: (URL::OpenStreamProgressCallback*) callback
  200296. withContext: (void*) context;
  200297. {
  200298. [super init];
  200299. request = req;
  200300. [request retain];
  200301. data = [[NSMutableData data] retain];
  200302. dataLock = [[NSLock alloc] init];
  200303. connection = 0;
  200304. initialised = false;
  200305. hasFailed = false;
  200306. hasFinished = false;
  200307. contentLength = -1;
  200308. runLoopThread = new JuceURLConnectionMessageThread (self);
  200309. runLoopThread->startThread();
  200310. while (runLoopThread->isThreadRunning() && ! initialised)
  200311. {
  200312. if (callback != 0)
  200313. callback (context, -1, (int) [[request HTTPBody] length]);
  200314. Thread::sleep (1);
  200315. }
  200316. return self;
  200317. }
  200318. - (void) dealloc
  200319. {
  200320. [self stop];
  200321. delete runLoopThread;
  200322. [connection release];
  200323. [data release];
  200324. [dataLock release];
  200325. [request release];
  200326. [super dealloc];
  200327. }
  200328. - (void) createConnection
  200329. {
  200330. connection = [[NSURLConnection alloc] initWithRequest: request
  200331. delegate: [self retain]];
  200332. if (connection == nil)
  200333. runLoopThread->signalThreadShouldExit();
  200334. }
  200335. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200336. {
  200337. [dataLock lock];
  200338. [data setLength: 0];
  200339. [dataLock unlock];
  200340. initialised = true;
  200341. contentLength = [response expectedContentLength];
  200342. }
  200343. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200344. {
  200345. DBG (nsStringToJuce ([error description]));
  200346. hasFailed = true;
  200347. initialised = true;
  200348. runLoopThread->signalThreadShouldExit();
  200349. }
  200350. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200351. {
  200352. [dataLock lock];
  200353. [data appendData: newData];
  200354. [dataLock unlock];
  200355. initialised = true;
  200356. }
  200357. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200358. {
  200359. hasFinished = true;
  200360. initialised = true;
  200361. runLoopThread->signalThreadShouldExit();
  200362. }
  200363. - (BOOL) isOpen
  200364. {
  200365. return connection != 0 && ! hasFailed;
  200366. }
  200367. - (int) readPosition
  200368. {
  200369. return position;
  200370. }
  200371. - (int) read: (char*) dest numBytes: (int) numNeeded
  200372. {
  200373. int numDone = 0;
  200374. while (numNeeded > 0)
  200375. {
  200376. int available = jmin (numNeeded, (int) [data length]);
  200377. if (available > 0)
  200378. {
  200379. [dataLock lock];
  200380. [data getBytes: dest length: available];
  200381. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200382. [dataLock unlock];
  200383. numDone += available;
  200384. numNeeded -= available;
  200385. dest += available;
  200386. }
  200387. else
  200388. {
  200389. if (hasFailed || hasFinished)
  200390. break;
  200391. Thread::sleep (1);
  200392. }
  200393. }
  200394. position += numDone;
  200395. return numDone;
  200396. }
  200397. - (void) stop
  200398. {
  200399. [connection cancel];
  200400. runLoopThread->stopThread (10000);
  200401. }
  200402. @end
  200403. BEGIN_JUCE_NAMESPACE
  200404. bool juce_isOnLine()
  200405. {
  200406. return true;
  200407. }
  200408. void* juce_openInternetFile (const String& url,
  200409. const String& headers,
  200410. const MemoryBlock& postData,
  200411. const bool isPost,
  200412. URL::OpenStreamProgressCallback* callback,
  200413. void* callbackContext,
  200414. int timeOutMs)
  200415. {
  200416. const ScopedAutoReleasePool pool;
  200417. NSMutableURLRequest* req = [NSMutableURLRequest
  200418. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200419. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200420. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200421. if (req == nil)
  200422. return 0;
  200423. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200424. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200425. StringArray headerLines;
  200426. headerLines.addLines (headers);
  200427. headerLines.removeEmptyStrings (true);
  200428. for (int i = 0; i < headerLines.size(); ++i)
  200429. {
  200430. const String key (headerLines[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  200431. const String value (headerLines[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  200432. if (key.isNotEmpty() && value.isNotEmpty())
  200433. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200434. }
  200435. if (isPost && postData.getSize() > 0)
  200436. {
  200437. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200438. length: postData.getSize()]];
  200439. }
  200440. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200441. withCallback: callback
  200442. withContext: callbackContext];
  200443. if ([s isOpen])
  200444. return s;
  200445. [s release];
  200446. return 0;
  200447. }
  200448. void juce_closeInternetFile (void* handle)
  200449. {
  200450. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200451. if (s != 0)
  200452. {
  200453. const ScopedAutoReleasePool pool;
  200454. [s stop];
  200455. [s release];
  200456. }
  200457. }
  200458. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200459. {
  200460. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200461. if (s != 0)
  200462. {
  200463. const ScopedAutoReleasePool pool;
  200464. return [s read: (char*) buffer numBytes: bytesToRead];
  200465. }
  200466. return 0;
  200467. }
  200468. int64 juce_getInternetFileContentLength (void* handle)
  200469. {
  200470. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200471. if (s != 0)
  200472. return s->contentLength;
  200473. return -1;
  200474. }
  200475. int juce_seekInInternetFile (void* handle, int newPosition)
  200476. {
  200477. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200478. if (s != 0)
  200479. return [s readPosition];
  200480. return 0;
  200481. }
  200482. #endif
  200483. /*** End of inlined file: juce_mac_Network.mm ***/
  200484. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  200485. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200486. // compiled on its own).
  200487. #if JUCE_INCLUDED_FILE
  200488. struct NamedPipeInternal
  200489. {
  200490. String pipeInName, pipeOutName;
  200491. int pipeIn, pipeOut;
  200492. bool volatile createdPipe, blocked, stopReadOperation;
  200493. static void signalHandler (int) {}
  200494. };
  200495. void NamedPipe::cancelPendingReads()
  200496. {
  200497. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200498. {
  200499. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200500. intern->stopReadOperation = true;
  200501. char buffer [1] = { 0 };
  200502. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200503. (void) bytesWritten;
  200504. int timeout = 2000;
  200505. while (intern->blocked && --timeout >= 0)
  200506. Thread::sleep (2);
  200507. intern->stopReadOperation = false;
  200508. }
  200509. }
  200510. void NamedPipe::close()
  200511. {
  200512. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200513. if (intern != 0)
  200514. {
  200515. internal = 0;
  200516. if (intern->pipeIn != -1)
  200517. ::close (intern->pipeIn);
  200518. if (intern->pipeOut != -1)
  200519. ::close (intern->pipeOut);
  200520. if (intern->createdPipe)
  200521. {
  200522. unlink (intern->pipeInName.toUTF8());
  200523. unlink (intern->pipeOutName.toUTF8());
  200524. }
  200525. delete intern;
  200526. }
  200527. }
  200528. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200529. {
  200530. close();
  200531. NamedPipeInternal* const intern = new NamedPipeInternal();
  200532. internal = intern;
  200533. intern->createdPipe = createPipe;
  200534. intern->blocked = false;
  200535. intern->stopReadOperation = false;
  200536. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200537. siginterrupt (SIGPIPE, 1);
  200538. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  200539. intern->pipeInName = pipePath + T("_in");
  200540. intern->pipeOutName = pipePath + T("_out");
  200541. intern->pipeIn = -1;
  200542. intern->pipeOut = -1;
  200543. if (createPipe)
  200544. {
  200545. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  200546. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  200547. {
  200548. delete intern;
  200549. internal = 0;
  200550. return false;
  200551. }
  200552. }
  200553. return true;
  200554. }
  200555. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200556. {
  200557. int bytesRead = -1;
  200558. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200559. if (intern != 0)
  200560. {
  200561. intern->blocked = true;
  200562. if (intern->pipeIn == -1)
  200563. {
  200564. if (intern->createdPipe)
  200565. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  200566. else
  200567. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  200568. if (intern->pipeIn == -1)
  200569. {
  200570. intern->blocked = false;
  200571. return -1;
  200572. }
  200573. }
  200574. bytesRead = 0;
  200575. char* p = (char*) destBuffer;
  200576. while (bytesRead < maxBytesToRead)
  200577. {
  200578. const int bytesThisTime = maxBytesToRead - bytesRead;
  200579. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200580. if (numRead <= 0 || intern->stopReadOperation)
  200581. {
  200582. bytesRead = -1;
  200583. break;
  200584. }
  200585. bytesRead += numRead;
  200586. p += bytesRead;
  200587. }
  200588. intern->blocked = false;
  200589. }
  200590. return bytesRead;
  200591. }
  200592. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200593. {
  200594. int bytesWritten = -1;
  200595. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200596. if (intern != 0)
  200597. {
  200598. if (intern->pipeOut == -1)
  200599. {
  200600. if (intern->createdPipe)
  200601. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  200602. else
  200603. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  200604. if (intern->pipeOut == -1)
  200605. {
  200606. return -1;
  200607. }
  200608. }
  200609. const char* p = (const char*) sourceBuffer;
  200610. bytesWritten = 0;
  200611. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200612. while (bytesWritten < numBytesToWrite
  200613. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200614. {
  200615. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200616. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200617. if (numWritten <= 0)
  200618. {
  200619. bytesWritten = -1;
  200620. break;
  200621. }
  200622. bytesWritten += numWritten;
  200623. p += bytesWritten;
  200624. }
  200625. }
  200626. return bytesWritten;
  200627. }
  200628. #endif
  200629. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  200630. /*** Start of inlined file: juce_mac_Threads.mm ***/
  200631. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200632. // compiled on its own).
  200633. #if JUCE_INCLUDED_FILE
  200634. void JUCE_API juce_threadEntryPoint (void*);
  200635. void* threadEntryProc (void* userData)
  200636. {
  200637. const ScopedAutoReleasePool pool;
  200638. juce_threadEntryPoint (userData);
  200639. return 0;
  200640. }
  200641. void* juce_createThread (void* userData)
  200642. {
  200643. pthread_t handle = 0;
  200644. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200645. {
  200646. pthread_detach (handle);
  200647. return (void*) handle;
  200648. }
  200649. return 0;
  200650. }
  200651. void juce_killThread (void* handle)
  200652. {
  200653. if (handle != 0)
  200654. pthread_cancel ((pthread_t) handle);
  200655. }
  200656. void juce_setCurrentThreadName (const String& /*name*/)
  200657. {
  200658. }
  200659. Thread::ThreadID Thread::getCurrentThreadId()
  200660. {
  200661. return (ThreadID) pthread_self();
  200662. }
  200663. bool juce_setThreadPriority (void* handle, int priority)
  200664. {
  200665. if (handle == 0)
  200666. handle = (void*) pthread_self();
  200667. struct sched_param param;
  200668. int policy;
  200669. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200670. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200671. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200672. }
  200673. void Thread::yield()
  200674. {
  200675. sched_yield();
  200676. }
  200677. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200678. {
  200679. // xxx
  200680. jassertfalse
  200681. }
  200682. bool Process::isForegroundProcess()
  200683. {
  200684. #if JUCE_MAC
  200685. return [NSApp isActive];
  200686. #else
  200687. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200688. #endif
  200689. }
  200690. void Process::raisePrivilege()
  200691. {
  200692. jassertfalse
  200693. }
  200694. void Process::lowerPrivilege()
  200695. {
  200696. jassertfalse
  200697. }
  200698. void Process::terminate()
  200699. {
  200700. exit (0);
  200701. }
  200702. void Process::setPriority (ProcessPriority p)
  200703. {
  200704. // xxx
  200705. }
  200706. #endif
  200707. /*** End of inlined file: juce_mac_Threads.mm ***/
  200708. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200709. CriticalSection::CriticalSection() throw()
  200710. {
  200711. pthread_mutexattr_t atts;
  200712. pthread_mutexattr_init (&atts);
  200713. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200714. pthread_mutex_init (&internal, &atts);
  200715. }
  200716. CriticalSection::~CriticalSection() throw()
  200717. {
  200718. pthread_mutex_destroy (&internal);
  200719. }
  200720. void CriticalSection::enter() const throw()
  200721. {
  200722. pthread_mutex_lock (&internal);
  200723. }
  200724. bool CriticalSection::tryEnter() const throw()
  200725. {
  200726. return pthread_mutex_trylock (&internal) == 0;
  200727. }
  200728. void CriticalSection::exit() const throw()
  200729. {
  200730. pthread_mutex_unlock (&internal);
  200731. }
  200732. struct EventStruct
  200733. {
  200734. pthread_cond_t condition;
  200735. pthread_mutex_t mutex;
  200736. bool triggered;
  200737. };
  200738. WaitableEvent::WaitableEvent() throw()
  200739. {
  200740. EventStruct* const es = new EventStruct();
  200741. es->triggered = false;
  200742. pthread_cond_init (&es->condition, 0);
  200743. pthread_mutex_init (&es->mutex, 0);
  200744. internal = es;
  200745. }
  200746. WaitableEvent::~WaitableEvent() throw()
  200747. {
  200748. EventStruct* const es = (EventStruct*) internal;
  200749. pthread_cond_destroy (&es->condition);
  200750. pthread_mutex_destroy (&es->mutex);
  200751. delete es;
  200752. }
  200753. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200754. {
  200755. EventStruct* const es = (EventStruct*) internal;
  200756. pthread_mutex_lock (&es->mutex);
  200757. if (timeOutMillisecs < 0)
  200758. {
  200759. while (! es->triggered)
  200760. pthread_cond_wait (&es->condition, &es->mutex);
  200761. }
  200762. else
  200763. {
  200764. while (! es->triggered)
  200765. {
  200766. struct timeval t;
  200767. gettimeofday (&t, 0);
  200768. struct timespec time;
  200769. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  200770. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200771. if (time.tv_nsec >= 1000000000)
  200772. {
  200773. time.tv_nsec -= 1000000000;
  200774. time.tv_sec++;
  200775. }
  200776. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  200777. {
  200778. pthread_mutex_unlock (&es->mutex);
  200779. return false;
  200780. }
  200781. }
  200782. }
  200783. es->triggered = false;
  200784. pthread_mutex_unlock (&es->mutex);
  200785. return true;
  200786. }
  200787. void WaitableEvent::signal() const throw()
  200788. {
  200789. EventStruct* const es = (EventStruct*) internal;
  200790. pthread_mutex_lock (&es->mutex);
  200791. es->triggered = true;
  200792. pthread_cond_broadcast (&es->condition);
  200793. pthread_mutex_unlock (&es->mutex);
  200794. }
  200795. void WaitableEvent::reset() const throw()
  200796. {
  200797. EventStruct* const es = (EventStruct*) internal;
  200798. pthread_mutex_lock (&es->mutex);
  200799. es->triggered = false;
  200800. pthread_mutex_unlock (&es->mutex);
  200801. }
  200802. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200803. {
  200804. struct timespec time;
  200805. time.tv_sec = millisecs / 1000;
  200806. time.tv_nsec = (millisecs % 1000) * 1000000;
  200807. nanosleep (&time, 0);
  200808. }
  200809. const tchar File::separator = T('/');
  200810. const tchar* File::separatorString = T("/");
  200811. const File File::getCurrentWorkingDirectory()
  200812. {
  200813. HeapBlock<char> heapBuffer;
  200814. char localBuffer [1024];
  200815. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  200816. int bufferSize = 4096;
  200817. while (cwd == 0 && errno == ERANGE)
  200818. {
  200819. heapBuffer.malloc (bufferSize);
  200820. cwd = getcwd (heapBuffer, bufferSize - 1);
  200821. bufferSize += 1024;
  200822. }
  200823. return File (String::fromUTF8 (cwd));
  200824. }
  200825. bool File::setAsCurrentWorkingDirectory() const
  200826. {
  200827. return chdir (getFullPathName().toUTF8()) == 0;
  200828. }
  200829. bool juce_copyFile (const String& s, const String& d);
  200830. static bool juce_stat (const String& fileName, struct stat& info)
  200831. {
  200832. return fileName.isNotEmpty()
  200833. && (stat (fileName.toUTF8(), &info) == 0);
  200834. }
  200835. bool juce_isDirectory (const String& fileName)
  200836. {
  200837. struct stat info;
  200838. return fileName.isEmpty()
  200839. || (juce_stat (fileName, info)
  200840. && ((info.st_mode & S_IFDIR) != 0));
  200841. }
  200842. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  200843. {
  200844. if (fileName.isEmpty())
  200845. return false;
  200846. const char* const fileNameUTF8 = fileName.toUTF8();
  200847. bool exists = access (fileNameUTF8, F_OK) == 0;
  200848. if (exists && dontCountDirectories)
  200849. {
  200850. struct stat info;
  200851. const int res = stat (fileNameUTF8, &info);
  200852. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  200853. exists = false;
  200854. }
  200855. return exists;
  200856. }
  200857. int64 juce_getFileSize (const String& fileName)
  200858. {
  200859. struct stat info;
  200860. return juce_stat (fileName, info) ? info.st_size : 0;
  200861. }
  200862. bool juce_canWriteToFile (const String& fileName)
  200863. {
  200864. return access (fileName.toUTF8(), W_OK) == 0;
  200865. }
  200866. bool juce_deleteFile (const String& fileName)
  200867. {
  200868. if (juce_isDirectory (fileName))
  200869. return rmdir ((const char*) fileName.toUTF8()) == 0;
  200870. else
  200871. return remove ((const char*) fileName.toUTF8()) == 0;
  200872. }
  200873. bool juce_moveFile (const String& source, const String& dest)
  200874. {
  200875. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  200876. return true;
  200877. if (juce_canWriteToFile (source)
  200878. && juce_copyFile (source, dest))
  200879. {
  200880. if (juce_deleteFile (source))
  200881. return true;
  200882. juce_deleteFile (dest);
  200883. }
  200884. return false;
  200885. }
  200886. void juce_createDirectory (const String& fileName)
  200887. {
  200888. mkdir (fileName.toUTF8(), 0777);
  200889. }
  200890. void* juce_fileOpen (const String& fileName, bool forWriting)
  200891. {
  200892. int flags = O_RDONLY;
  200893. if (forWriting)
  200894. {
  200895. if (juce_fileExists (fileName, false))
  200896. {
  200897. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  200898. if (f != -1)
  200899. lseek (f, 0, SEEK_END);
  200900. return (void*) f;
  200901. }
  200902. else
  200903. {
  200904. flags = O_RDWR + O_CREAT;
  200905. }
  200906. }
  200907. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  200908. }
  200909. void juce_fileClose (void* handle)
  200910. {
  200911. if (handle != 0)
  200912. close ((int) (pointer_sized_int) handle);
  200913. }
  200914. int juce_fileRead (void* handle, void* buffer, int size)
  200915. {
  200916. if (handle != 0)
  200917. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  200918. return 0;
  200919. }
  200920. int juce_fileWrite (void* handle, const void* buffer, int size)
  200921. {
  200922. if (handle != 0)
  200923. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  200924. return 0;
  200925. }
  200926. int64 juce_fileSetPosition (void* handle, int64 pos)
  200927. {
  200928. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  200929. return pos;
  200930. return -1;
  200931. }
  200932. int64 juce_fileGetPosition (void* handle)
  200933. {
  200934. if (handle != 0)
  200935. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  200936. else
  200937. return -1;
  200938. }
  200939. void juce_fileFlush (void* handle)
  200940. {
  200941. if (handle != 0)
  200942. fsync ((int) (pointer_sized_int) handle);
  200943. }
  200944. const File juce_getExecutableFile()
  200945. {
  200946. Dl_info exeInfo;
  200947. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  200948. return File (String::fromUTF8 (exeInfo.dli_fname));
  200949. }
  200950. // if this file doesn't exist, find a parent of it that does..
  200951. static bool doStatFS (const File* file, struct statfs& result)
  200952. {
  200953. File f (*file);
  200954. for (int i = 5; --i >= 0;)
  200955. {
  200956. if (f.exists())
  200957. break;
  200958. f = f.getParentDirectory();
  200959. }
  200960. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  200961. }
  200962. int64 File::getBytesFreeOnVolume() const
  200963. {
  200964. struct statfs buf;
  200965. if (doStatFS (this, buf))
  200966. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  200967. return 0;
  200968. }
  200969. int64 File::getVolumeTotalSize() const
  200970. {
  200971. struct statfs buf;
  200972. if (doStatFS (this, buf))
  200973. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  200974. return 0;
  200975. }
  200976. const String juce_getVolumeLabel (const String& filenameOnVolume,
  200977. int& volumeSerialNumber)
  200978. {
  200979. volumeSerialNumber = 0;
  200980. #if JUCE_MAC
  200981. struct VolAttrBuf
  200982. {
  200983. u_int32_t length;
  200984. attrreference_t mountPointRef;
  200985. char mountPointSpace [MAXPATHLEN];
  200986. } attrBuf;
  200987. struct attrlist attrList;
  200988. zerostruct (attrList);
  200989. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  200990. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  200991. File f (filenameOnVolume);
  200992. for (;;)
  200993. {
  200994. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  200995. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  200996. {
  200997. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  200998. (int) attrBuf.mountPointRef.attr_length);
  200999. }
  201000. const File parent (f.getParentDirectory());
  201001. if (f == parent)
  201002. break;
  201003. f = parent;
  201004. }
  201005. #endif
  201006. return String::empty;
  201007. }
  201008. void juce_runSystemCommand (const String& command)
  201009. {
  201010. int result = system ((const char*) command.toUTF8());
  201011. (void) result;
  201012. }
  201013. const String juce_getOutputFromCommand (const String& command)
  201014. {
  201015. // slight bodge here, as we just pipe the output into a temp file and read it...
  201016. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  201017. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  201018. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  201019. String result (tempFile.loadFileAsString());
  201020. tempFile.deleteFile();
  201021. return result;
  201022. }
  201023. InterProcessLock::InterProcessLock (const String& name_)
  201024. : internal (0),
  201025. name (name_),
  201026. reentrancyLevel (0)
  201027. {
  201028. #if JUCE_MAC
  201029. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  201030. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  201031. #else
  201032. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  201033. #endif
  201034. temp.create();
  201035. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  201036. }
  201037. InterProcessLock::~InterProcessLock()
  201038. {
  201039. while (reentrancyLevel > 0)
  201040. this->exit();
  201041. close (internal);
  201042. }
  201043. bool InterProcessLock::enter (const int timeOutMillisecs)
  201044. {
  201045. if (internal == 0)
  201046. return false;
  201047. if (reentrancyLevel != 0)
  201048. return true;
  201049. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  201050. struct flock fl;
  201051. zerostruct (fl);
  201052. fl.l_whence = SEEK_SET;
  201053. fl.l_type = F_WRLCK;
  201054. for (;;)
  201055. {
  201056. const int result = fcntl (internal, F_SETLK, &fl);
  201057. if (result >= 0)
  201058. {
  201059. ++reentrancyLevel;
  201060. return true;
  201061. }
  201062. if (errno != EINTR)
  201063. {
  201064. if (timeOutMillisecs == 0
  201065. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  201066. break;
  201067. Thread::sleep (10);
  201068. }
  201069. }
  201070. return false;
  201071. }
  201072. void InterProcessLock::exit()
  201073. {
  201074. if (reentrancyLevel > 0 && internal != 0)
  201075. {
  201076. --reentrancyLevel;
  201077. struct flock fl;
  201078. zerostruct (fl);
  201079. fl.l_whence = SEEK_SET;
  201080. fl.l_type = F_UNLCK;
  201081. for (;;)
  201082. {
  201083. const int result = fcntl (internal, F_SETLKW, &fl);
  201084. if (result >= 0 || errno != EINTR)
  201085. break;
  201086. }
  201087. }
  201088. }
  201089. /*** End of inlined file: juce_posix_SharedCode.h ***/
  201090. /*** Start of inlined file: juce_mac_Files.mm ***/
  201091. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201092. // compiled on its own).
  201093. #if JUCE_INCLUDED_FILE
  201094. void juce_getFileTimes (const String& fileName,
  201095. int64& modificationTime,
  201096. int64& accessTime,
  201097. int64& creationTime)
  201098. {
  201099. modificationTime = 0;
  201100. accessTime = 0;
  201101. creationTime = 0;
  201102. struct stat info;
  201103. const int res = stat (fileName.toUTF8(), &info);
  201104. if (res == 0)
  201105. {
  201106. modificationTime = (int64) info.st_mtime * 1000;
  201107. accessTime = (int64) info.st_atime * 1000;
  201108. creationTime = (int64) info.st_ctime * 1000;
  201109. }
  201110. }
  201111. bool juce_setFileTimes (const String& fileName,
  201112. int64 modificationTime,
  201113. int64 accessTime,
  201114. int64 creationTime)
  201115. {
  201116. struct utimbuf times;
  201117. times.actime = (time_t) (accessTime / 1000);
  201118. times.modtime = (time_t) (modificationTime / 1000);
  201119. return utime (fileName.toUTF8(), &times) == 0;
  201120. }
  201121. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  201122. {
  201123. struct stat info;
  201124. const int res = stat (fileName.toUTF8(), &info);
  201125. if (res != 0)
  201126. return false;
  201127. info.st_mode &= 0777; // Just permissions
  201128. if (isReadOnly)
  201129. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  201130. else
  201131. // Give everybody write permission?
  201132. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  201133. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  201134. }
  201135. bool juce_copyFile (const String& src, const String& dst)
  201136. {
  201137. const ScopedAutoReleasePool pool;
  201138. NSFileManager* fm = [NSFileManager defaultManager];
  201139. return [fm fileExistsAtPath: juceStringToNS (src)]
  201140. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201141. && [fm copyItemAtPath: juceStringToNS (src)
  201142. toPath: juceStringToNS (dst)
  201143. error: nil];
  201144. #else
  201145. && [fm copyPath: juceStringToNS (src)
  201146. toPath: juceStringToNS (dst)
  201147. handler: nil];
  201148. #endif
  201149. }
  201150. const StringArray juce_getFileSystemRoots()
  201151. {
  201152. StringArray s;
  201153. s.add (T("/"));
  201154. return s;
  201155. }
  201156. static bool isFileOnDriveType (const File* const f, const char** types)
  201157. {
  201158. struct statfs buf;
  201159. if (doStatFS (f, buf))
  201160. {
  201161. const String type (buf.f_fstypename);
  201162. while (*types != 0)
  201163. if (type.equalsIgnoreCase (*types++))
  201164. return true;
  201165. }
  201166. return false;
  201167. }
  201168. bool File::isOnCDRomDrive() const
  201169. {
  201170. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  201171. return isFileOnDriveType (this, (const char**) cdTypes);
  201172. }
  201173. bool File::isOnHardDisk() const
  201174. {
  201175. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  201176. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  201177. }
  201178. bool File::isOnRemovableDrive() const
  201179. {
  201180. #if JUCE_IPHONE
  201181. return false; // xxx is this possible?
  201182. #else
  201183. const ScopedAutoReleasePool pool;
  201184. BOOL removable = false;
  201185. [[NSWorkspace sharedWorkspace]
  201186. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  201187. isRemovable: &removable
  201188. isWritable: nil
  201189. isUnmountable: nil
  201190. description: nil
  201191. type: nil];
  201192. return removable;
  201193. #endif
  201194. }
  201195. static bool juce_isHiddenFile (const String& path)
  201196. {
  201197. #if JUCE_IPHONE
  201198. return File (path).getFileName().startsWithChar (T('.'));
  201199. #else
  201200. FSRef ref;
  201201. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  201202. return false;
  201203. FSCatalogInfo info;
  201204. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  201205. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  201206. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201207. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201208. #endif
  201209. }
  201210. bool File::isHidden() const
  201211. {
  201212. return juce_isHiddenFile (getFullPathName());
  201213. }
  201214. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  201215. const File File::getSpecialLocation (const SpecialLocationType type)
  201216. {
  201217. const ScopedAutoReleasePool pool;
  201218. String resultPath;
  201219. switch (type)
  201220. {
  201221. case userHomeDirectory:
  201222. resultPath = nsStringToJuce (NSHomeDirectory());
  201223. break;
  201224. case userDocumentsDirectory:
  201225. resultPath = "~/Documents";
  201226. break;
  201227. case userDesktopDirectory:
  201228. resultPath = "~/Desktop";
  201229. break;
  201230. case userApplicationDataDirectory:
  201231. resultPath = "~/Library";
  201232. break;
  201233. case commonApplicationDataDirectory:
  201234. resultPath = "/Library";
  201235. break;
  201236. case globalApplicationsDirectory:
  201237. resultPath = "/Applications";
  201238. break;
  201239. case userMusicDirectory:
  201240. resultPath = "~/Music";
  201241. break;
  201242. case userMoviesDirectory:
  201243. resultPath = "~/Movies";
  201244. break;
  201245. case tempDirectory:
  201246. {
  201247. File tmp (T("~/Library/Caches/") + juce_getExecutableFile().getFileNameWithoutExtension());
  201248. tmp.createDirectory();
  201249. return tmp.getFullPathName();
  201250. }
  201251. case invokedExecutableFile:
  201252. if (juce_Argv0 != 0)
  201253. return File (String::fromUTF8 (juce_Argv0));
  201254. // deliberate fall-through...
  201255. case currentExecutableFile:
  201256. return juce_getExecutableFile();
  201257. case currentApplicationFile:
  201258. {
  201259. const File exe (juce_getExecutableFile());
  201260. const File parent (exe.getParentDirectory());
  201261. return parent.getFullPathName().endsWithIgnoreCase (T("Contents/MacOS"))
  201262. ? parent.getParentDirectory().getParentDirectory()
  201263. : exe;
  201264. }
  201265. default:
  201266. jassertfalse // unknown type?
  201267. break;
  201268. }
  201269. if (resultPath.isNotEmpty())
  201270. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201271. return File::nonexistent;
  201272. }
  201273. const String File::getVersion() const
  201274. {
  201275. const ScopedAutoReleasePool pool;
  201276. String result;
  201277. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201278. if (bundle != 0)
  201279. {
  201280. NSDictionary* info = [bundle infoDictionary];
  201281. if (info != 0)
  201282. {
  201283. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201284. if (name != nil)
  201285. result = nsStringToJuce (name);
  201286. }
  201287. }
  201288. return result;
  201289. }
  201290. const File File::getLinkedTarget() const
  201291. {
  201292. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201293. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201294. #else
  201295. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201296. #endif
  201297. if (dest != nil)
  201298. return File (nsStringToJuce (dest));
  201299. return *this;
  201300. }
  201301. bool File::moveToTrash() const
  201302. {
  201303. if (! exists())
  201304. return true;
  201305. #if JUCE_IPHONE
  201306. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201307. #else
  201308. const ScopedAutoReleasePool pool;
  201309. NSString* p = juceStringToNS (getFullPathName());
  201310. return [[NSWorkspace sharedWorkspace]
  201311. performFileOperation: NSWorkspaceRecycleOperation
  201312. source: [p stringByDeletingLastPathComponent]
  201313. destination: @""
  201314. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201315. tag: nil ];
  201316. #endif
  201317. }
  201318. struct FindFileStruct
  201319. {
  201320. NSDirectoryEnumerator* enumerator;
  201321. String parentDir, wildCard;
  201322. };
  201323. bool juce_findFileNext (void* handle, String& resultFile,
  201324. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201325. {
  201326. ScopedAutoReleasePool pool;
  201327. FindFileStruct* ff = (FindFileStruct*) handle;
  201328. NSString* file;
  201329. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201330. for (;;)
  201331. {
  201332. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201333. return false;
  201334. [ff->enumerator skipDescendents];
  201335. resultFile = nsStringToJuce (file);
  201336. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201337. continue;
  201338. const String path (ff->parentDir + resultFile);
  201339. if (isDir != 0 || fileSize != 0)
  201340. {
  201341. struct stat info;
  201342. const bool statOk = juce_stat (path, info);
  201343. if (isDir != 0)
  201344. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201345. if (isHidden != 0)
  201346. *isHidden = juce_isHiddenFile (path);
  201347. if (fileSize != 0)
  201348. *fileSize = statOk ? info.st_size : 0;
  201349. }
  201350. if (modTime != 0 || creationTime != 0)
  201351. {
  201352. int64 m, a, c;
  201353. juce_getFileTimes (path, m, a, c);
  201354. if (modTime != 0)
  201355. *modTime = m;
  201356. if (creationTime != 0)
  201357. *creationTime = c;
  201358. }
  201359. if (isReadOnly != 0)
  201360. *isReadOnly = ! juce_canWriteToFile (path);
  201361. return true;
  201362. }
  201363. }
  201364. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201365. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201366. Time* creationTime, bool* isReadOnly)
  201367. {
  201368. ScopedAutoReleasePool pool;
  201369. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201370. if (e != 0)
  201371. {
  201372. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201373. ff->enumerator = [e retain];
  201374. ff->parentDir = directory;
  201375. ff->wildCard = wildCard;
  201376. if (! ff->parentDir.endsWithChar (File::separator))
  201377. ff->parentDir += File::separator;
  201378. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201379. return ff.release();
  201380. [e release];
  201381. }
  201382. return 0;
  201383. }
  201384. void juce_findFileClose (void* handle)
  201385. {
  201386. ScopedAutoReleasePool pool;
  201387. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201388. [ff->enumerator release];
  201389. }
  201390. bool juce_launchExecutable (const String& pathAndArguments)
  201391. {
  201392. const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), 0 };
  201393. const int cpid = fork();
  201394. if (cpid == 0)
  201395. {
  201396. // Child process
  201397. if (execve (argv[0], (char**) argv, 0) < 0)
  201398. exit (0);
  201399. }
  201400. else
  201401. {
  201402. if (cpid < 0)
  201403. return false;
  201404. }
  201405. return true;
  201406. }
  201407. bool juce_launchFile (const String& fileName, const String& parameters)
  201408. {
  201409. #if JUCE_IPHONE
  201410. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201411. #else
  201412. const ScopedAutoReleasePool pool;
  201413. if (parameters.isEmpty())
  201414. {
  201415. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201416. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201417. }
  201418. bool ok = false;
  201419. FSRef ref;
  201420. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201421. {
  201422. if (PlatformUtilities::isBundle (fileName))
  201423. {
  201424. NSMutableArray* urls = [NSMutableArray array];
  201425. StringArray docs;
  201426. docs.addTokens (parameters, true);
  201427. for (int i = 0; i < docs.size(); ++i)
  201428. [urls addObject: juceStringToNS (docs[i])];
  201429. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201430. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201431. options: 0
  201432. additionalEventParamDescriptor: nil
  201433. launchIdentifiers: nil];
  201434. }
  201435. else
  201436. {
  201437. ok = juce_launchExecutable (T("\"") + fileName + T("\" ") + parameters);
  201438. }
  201439. }
  201440. return ok;
  201441. #endif
  201442. }
  201443. void File::revealToUser() const
  201444. {
  201445. #if ! JUCE_IPHONE
  201446. if (exists())
  201447. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201448. else if (getParentDirectory().exists())
  201449. getParentDirectory().revealToUser();
  201450. #endif
  201451. }
  201452. #if ! JUCE_IPHONE
  201453. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201454. {
  201455. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201456. }
  201457. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201458. {
  201459. char path [2048];
  201460. zerostruct (path);
  201461. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201462. return PlatformUtilities::convertToPrecomposedUnicode (String::fromUTF8 (path));
  201463. return String::empty;
  201464. }
  201465. #endif
  201466. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201467. {
  201468. const ScopedAutoReleasePool pool;
  201469. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201470. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201471. #else
  201472. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201473. #endif
  201474. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201475. return [fileDict fileHFSTypeCode];
  201476. }
  201477. bool PlatformUtilities::isBundle (const String& filename)
  201478. {
  201479. #if JUCE_IPHONE
  201480. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201481. #else
  201482. const ScopedAutoReleasePool pool;
  201483. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201484. #endif
  201485. }
  201486. #endif
  201487. /*** End of inlined file: juce_mac_Files.mm ***/
  201488. #if JUCE_IPHONE
  201489. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  201490. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201491. // compiled on its own).
  201492. #if JUCE_INCLUDED_FILE
  201493. static JUCEApplication* juce_intialisingApp;
  201494. END_JUCE_NAMESPACE
  201495. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201496. {
  201497. }
  201498. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201499. - (void) applicationWillResignActive: (UIApplication*) application;
  201500. @end
  201501. @implementation JuceAppStartupDelegate
  201502. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201503. {
  201504. String dummy;
  201505. if (! juce_intialisingApp->initialiseApp (dummy))
  201506. exit (0);
  201507. }
  201508. - (void) applicationWillResignActive: (UIApplication*) application
  201509. {
  201510. JUCEApplication::shutdownAppAndClearUp();
  201511. }
  201512. @end
  201513. BEGIN_JUCE_NAMESPACE
  201514. int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app)
  201515. {
  201516. juce_intialisingApp = app;
  201517. return UIApplicationMain (argc, const_cast<char**> (argv), nil, @"JuceAppStartupDelegate");
  201518. }
  201519. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201520. {
  201521. pool = [[NSAutoreleasePool alloc] init];
  201522. }
  201523. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201524. {
  201525. [((NSAutoreleasePool*) pool) release];
  201526. }
  201527. void PlatformUtilities::beep()
  201528. {
  201529. //xxx
  201530. //AudioServicesPlaySystemSound ();
  201531. }
  201532. void PlatformUtilities::addItemToDock (const File& file)
  201533. {
  201534. }
  201535. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201536. END_JUCE_NAMESPACE
  201537. @interface JuceAlertBoxDelegate : NSObject
  201538. {
  201539. @public
  201540. bool clickedOk;
  201541. }
  201542. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201543. @end
  201544. @implementation JuceAlertBoxDelegate
  201545. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201546. {
  201547. clickedOk = (buttonIndex == 0);
  201548. alertView.hidden = true;
  201549. }
  201550. @end
  201551. BEGIN_JUCE_NAMESPACE
  201552. // (This function is used directly by other bits of code)
  201553. bool juce_iPhoneShowModalAlert (const String& title,
  201554. const String& bodyText,
  201555. NSString* okButtonText,
  201556. NSString* cancelButtonText)
  201557. {
  201558. const ScopedAutoReleasePool pool;
  201559. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201560. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201561. message: juceStringToNS (bodyText)
  201562. delegate: callback
  201563. cancelButtonTitle: okButtonText
  201564. otherButtonTitles: cancelButtonText, nil];
  201565. [alert retain];
  201566. [alert show];
  201567. while (! alert.hidden && alert.superview != nil)
  201568. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201569. const bool result = callback->clickedOk;
  201570. [alert release];
  201571. [callback release];
  201572. return result;
  201573. }
  201574. bool AlertWindow::showNativeDialogBox (const String& title,
  201575. const String& bodyText,
  201576. bool isOkCancel)
  201577. {
  201578. return juce_iPhoneShowModalAlert (title, bodyText,
  201579. @"OK",
  201580. isOkCancel ? @"Cancel" : nil);
  201581. }
  201582. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201583. {
  201584. jassertfalse // no such thing on the iphone!
  201585. return false;
  201586. }
  201587. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201588. {
  201589. jassertfalse // no such thing on the iphone!
  201590. return false;
  201591. }
  201592. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201593. {
  201594. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201595. }
  201596. bool Desktop::isScreenSaverEnabled() throw()
  201597. {
  201598. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201599. }
  201600. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  201601. {
  201602. const ScopedAutoReleasePool pool;
  201603. monitorCoords.clear();
  201604. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201605. : [[UIScreen mainScreen] bounds];
  201606. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201607. (int) r.origin.y,
  201608. (int) r.size.width,
  201609. (int) r.size.height));
  201610. }
  201611. #endif
  201612. #endif
  201613. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  201614. #else
  201615. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  201616. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201617. // compiled on its own).
  201618. #if JUCE_INCLUDED_FILE
  201619. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201620. {
  201621. pool = [[NSAutoreleasePool alloc] init];
  201622. }
  201623. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201624. {
  201625. [((NSAutoreleasePool*) pool) release];
  201626. }
  201627. void PlatformUtilities::beep()
  201628. {
  201629. NSBeep();
  201630. }
  201631. void PlatformUtilities::addItemToDock (const File& file)
  201632. {
  201633. // check that it's not already there...
  201634. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201635. .containsIgnoreCase (file.getFullPathName()))
  201636. {
  201637. 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>"
  201638. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201639. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201640. }
  201641. }
  201642. int PlatformUtilities::getOSXMinorVersionNumber()
  201643. {
  201644. SInt32 versionMinor = 0;
  201645. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201646. (void) err;
  201647. jassert (err == noErr);
  201648. return (int) versionMinor;
  201649. }
  201650. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201651. bool AlertWindow::showNativeDialogBox (const String& title,
  201652. const String& bodyText,
  201653. bool isOkCancel)
  201654. {
  201655. const ScopedAutoReleasePool pool;
  201656. return NSRunAlertPanel (juceStringToNS (title),
  201657. juceStringToNS (bodyText),
  201658. @"Ok",
  201659. isOkCancel ? @"Cancel" : nil,
  201660. nil) == NSAlertDefaultReturn;
  201661. }
  201662. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201663. {
  201664. if (files.size() == 0)
  201665. return false;
  201666. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource(0);
  201667. if (draggingSource == 0)
  201668. {
  201669. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201670. return false;
  201671. }
  201672. Component* sourceComp = draggingSource->getComponentUnderMouse();
  201673. if (sourceComp == 0)
  201674. {
  201675. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201676. return false;
  201677. }
  201678. const ScopedAutoReleasePool pool;
  201679. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201680. if (view == 0)
  201681. return false;
  201682. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201683. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201684. owner: nil];
  201685. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201686. for (int i = 0; i < files.size(); ++i)
  201687. [filesArray addObject: juceStringToNS (files[i])];
  201688. [pboard setPropertyList: filesArray
  201689. forType: NSFilenamesPboardType];
  201690. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201691. fromView: nil];
  201692. dragPosition.x -= 16;
  201693. dragPosition.y -= 16;
  201694. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201695. at: dragPosition
  201696. offset: NSMakeSize (0, 0)
  201697. event: [[view window] currentEvent]
  201698. pasteboard: pboard
  201699. source: view
  201700. slideBack: YES];
  201701. return true;
  201702. }
  201703. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201704. {
  201705. jassertfalse // not implemented!
  201706. return false;
  201707. }
  201708. bool Desktop::canUseSemiTransparentWindows() throw()
  201709. {
  201710. return true;
  201711. }
  201712. const Point<int> Desktop::getMousePosition()
  201713. {
  201714. const ScopedAutoReleasePool pool;
  201715. const NSPoint p ([NSEvent mouseLocation]);
  201716. return Point<int> (roundToInt (p.x), roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y));
  201717. }
  201718. void Desktop::setMousePosition (const Point<int>& newPosition)
  201719. {
  201720. // this rubbish needs to be done around the warp call, to avoid causing a
  201721. // bizarre glitch..
  201722. CGAssociateMouseAndMouseCursorPosition (false);
  201723. CGWarpMouseCursorPosition (CGPointMake (newPosition.getX(), newPosition.getY()));
  201724. CGAssociateMouseAndMouseCursorPosition (true);
  201725. }
  201726. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201727. class ScreenSaverDefeater : public Timer,
  201728. public DeletedAtShutdown
  201729. {
  201730. public:
  201731. ScreenSaverDefeater() throw()
  201732. {
  201733. startTimer (10000);
  201734. timerCallback();
  201735. }
  201736. ~ScreenSaverDefeater() {}
  201737. void timerCallback()
  201738. {
  201739. if (Process::isForegroundProcess())
  201740. UpdateSystemActivity (UsrActivity);
  201741. }
  201742. };
  201743. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201744. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201745. {
  201746. if (isEnabled)
  201747. {
  201748. deleteAndZero (screenSaverDefeater);
  201749. }
  201750. else if (screenSaverDefeater == 0)
  201751. {
  201752. screenSaverDefeater = new ScreenSaverDefeater();
  201753. }
  201754. }
  201755. bool Desktop::isScreenSaverEnabled() throw()
  201756. {
  201757. return screenSaverDefeater == 0;
  201758. }
  201759. #else
  201760. static IOPMAssertionID screenSaverDisablerID = 0;
  201761. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201762. {
  201763. if (isEnabled)
  201764. {
  201765. if (screenSaverDisablerID != 0)
  201766. {
  201767. IOPMAssertionRelease (screenSaverDisablerID);
  201768. screenSaverDisablerID = 0;
  201769. }
  201770. }
  201771. else
  201772. {
  201773. if (screenSaverDisablerID == 0)
  201774. {
  201775. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201776. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201777. CFSTR ("Juce"), &screenSaverDisablerID);
  201778. #else
  201779. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201780. &screenSaverDisablerID);
  201781. #endif
  201782. }
  201783. }
  201784. }
  201785. bool Desktop::isScreenSaverEnabled() throw()
  201786. {
  201787. return screenSaverDisablerID == 0;
  201788. }
  201789. #endif
  201790. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201791. {
  201792. const ScopedAutoReleasePool pool;
  201793. monitorCoords.clear();
  201794. NSArray* screens = [NSScreen screens];
  201795. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201796. for (unsigned int i = 0; i < [screens count]; ++i)
  201797. {
  201798. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201799. NSRect r = clipToWorkArea ? [s visibleFrame]
  201800. : [s frame];
  201801. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201802. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201803. (int) r.size.width,
  201804. (int) r.size.height));
  201805. }
  201806. jassert (monitorCoords.size() > 0);
  201807. }
  201808. #endif
  201809. #endif
  201810. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201811. #endif
  201812. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201813. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201814. // compiled on its own).
  201815. #if JUCE_INCLUDED_FILE
  201816. void Logger::outputDebugString (const String& text) throw()
  201817. {
  201818. std::cerr << (const char*) text.toUTF8() << std::endl;
  201819. }
  201820. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  201821. {
  201822. String text;
  201823. va_list args;
  201824. va_start (args, format);
  201825. text.vprintf (format, args);
  201826. outputDebugString (text);
  201827. }
  201828. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201829. {
  201830. static char testResult = 0;
  201831. if (testResult == 0)
  201832. {
  201833. struct kinfo_proc info;
  201834. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201835. size_t sz = sizeof (info);
  201836. sysctl (m, 4, &info, &sz, 0, 0);
  201837. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201838. }
  201839. return testResult > 0;
  201840. }
  201841. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201842. {
  201843. return juce_isRunningUnderDebugger();
  201844. }
  201845. #endif
  201846. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201847. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201848. #if JUCE_IPHONE
  201849. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  201850. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201851. // compiled on its own).
  201852. #if JUCE_INCLUDED_FILE
  201853. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201854. #define SUPPORT_10_4_FONTS 1
  201855. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  201856. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  201857. #define SUPPORT_ONLY_10_4_FONTS 1
  201858. #endif
  201859. END_JUCE_NAMESPACE
  201860. @interface NSFont (PrivateHack)
  201861. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  201862. @end
  201863. BEGIN_JUCE_NAMESPACE
  201864. #endif
  201865. class MacTypeface : public Typeface
  201866. {
  201867. public:
  201868. MacTypeface (const Font& font)
  201869. : Typeface (font.getTypefaceName())
  201870. {
  201871. const ScopedAutoReleasePool pool;
  201872. renderingTransform = CGAffineTransformIdentity;
  201873. bool needsItalicTransform = false;
  201874. #if JUCE_IPHONE
  201875. NSString* fontName = juceStringToNS (font.getTypefaceName());
  201876. if (font.isItalic() || font.isBold())
  201877. {
  201878. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  201879. for (NSString* i in familyFonts)
  201880. {
  201881. const String fn (nsStringToJuce (i));
  201882. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  201883. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  201884. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  201885. || afterDash.containsIgnoreCase (T("italic"))
  201886. || fn.endsWithIgnoreCase (T("oblique"))
  201887. || fn.endsWithIgnoreCase (T("italic"));
  201888. if (probablyBold == font.isBold()
  201889. && probablyItalic == font.isItalic())
  201890. {
  201891. fontName = i;
  201892. needsItalicTransform = false;
  201893. break;
  201894. }
  201895. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  201896. {
  201897. fontName = i;
  201898. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  201899. }
  201900. }
  201901. if (needsItalicTransform)
  201902. renderingTransform.c = 0.15f;
  201903. }
  201904. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  201905. const int ascender = abs (CGFontGetAscent (fontRef));
  201906. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  201907. ascent = ascender / totalHeight;
  201908. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201909. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  201910. #else
  201911. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  201912. if (font.isItalic())
  201913. {
  201914. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  201915. toHaveTrait: NSItalicFontMask];
  201916. if (newFont == nsFont)
  201917. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  201918. nsFont = newFont;
  201919. }
  201920. if (font.isBold())
  201921. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  201922. [nsFont retain];
  201923. ascent = fabsf ((float) [nsFont ascender]);
  201924. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  201925. ascent /= totalSize;
  201926. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  201927. if (needsItalicTransform)
  201928. {
  201929. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  201930. renderingTransform.c = 0.15f;
  201931. }
  201932. #if SUPPORT_ONLY_10_4_FONTS
  201933. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201934. if (atsFont == 0)
  201935. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201936. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201937. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201938. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201939. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201940. #else
  201941. #if SUPPORT_10_4_FONTS
  201942. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201943. {
  201944. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201945. if (atsFont == 0)
  201946. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201947. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201948. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201949. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201950. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201951. }
  201952. else
  201953. #endif
  201954. {
  201955. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  201956. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  201957. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201958. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  201959. }
  201960. #endif
  201961. #endif
  201962. }
  201963. ~MacTypeface()
  201964. {
  201965. #if ! JUCE_IPHONE
  201966. [nsFont release];
  201967. #endif
  201968. if (fontRef != 0)
  201969. CGFontRelease (fontRef);
  201970. }
  201971. float getAscent() const
  201972. {
  201973. return ascent;
  201974. }
  201975. float getDescent() const
  201976. {
  201977. return 1.0f - ascent;
  201978. }
  201979. float getStringWidth (const String& text)
  201980. {
  201981. if (fontRef == 0 || text.isEmpty())
  201982. return 0;
  201983. const int length = text.length();
  201984. HeapBlock <CGGlyph> glyphs;
  201985. createGlyphsForString (text, length, glyphs);
  201986. float x = 0;
  201987. #if SUPPORT_ONLY_10_4_FONTS
  201988. HeapBlock <NSSize> advances (length);
  201989. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  201990. for (int i = 0; i < length; ++i)
  201991. x += advances[i].width;
  201992. #else
  201993. #if SUPPORT_10_4_FONTS
  201994. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201995. {
  201996. HeapBlock <NSSize> advances (length);
  201997. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  201998. for (int i = 0; i < length; ++i)
  201999. x += advances[i].width;
  202000. }
  202001. else
  202002. #endif
  202003. {
  202004. HeapBlock <int> advances (length);
  202005. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202006. for (int i = 0; i < length; ++i)
  202007. x += advances[i];
  202008. }
  202009. #endif
  202010. return x * unitsToHeightScaleFactor;
  202011. }
  202012. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  202013. {
  202014. xOffsets.add (0);
  202015. if (fontRef == 0 || text.isEmpty())
  202016. return;
  202017. const int length = text.length();
  202018. HeapBlock <CGGlyph> glyphs;
  202019. createGlyphsForString (text, length, glyphs);
  202020. #if SUPPORT_ONLY_10_4_FONTS
  202021. HeapBlock <NSSize> advances (length);
  202022. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202023. int x = 0;
  202024. for (int i = 0; i < length; ++i)
  202025. {
  202026. x += advances[i].width;
  202027. xOffsets.add (x * unitsToHeightScaleFactor);
  202028. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202029. }
  202030. #else
  202031. #if SUPPORT_10_4_FONTS
  202032. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202033. {
  202034. HeapBlock <NSSize> advances (length);
  202035. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  202036. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  202037. float x = 0;
  202038. for (int i = 0; i < length; ++i)
  202039. {
  202040. x += advances[i].width;
  202041. xOffsets.add (x * unitsToHeightScaleFactor);
  202042. resultGlyphs.add (nsGlyphs[i]);
  202043. }
  202044. }
  202045. else
  202046. #endif
  202047. {
  202048. HeapBlock <int> advances (length);
  202049. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202050. {
  202051. int x = 0;
  202052. for (int i = 0; i < length; ++i)
  202053. {
  202054. x += advances [i];
  202055. xOffsets.add (x * unitsToHeightScaleFactor);
  202056. resultGlyphs.add (glyphs[i]);
  202057. }
  202058. }
  202059. }
  202060. #endif
  202061. }
  202062. bool getOutlineForGlyph (int glyphNumber, Path& path)
  202063. {
  202064. #if JUCE_IPHONE
  202065. return false;
  202066. #else
  202067. if (nsFont == 0)
  202068. return false;
  202069. // we might need to apply a transform to the path, so it mustn't have anything else in it
  202070. jassert (path.isEmpty());
  202071. const ScopedAutoReleasePool pool;
  202072. NSBezierPath* bez = [NSBezierPath bezierPath];
  202073. [bez moveToPoint: NSMakePoint (0, 0)];
  202074. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  202075. inFont: nsFont];
  202076. for (int i = 0; i < [bez elementCount]; ++i)
  202077. {
  202078. NSPoint p[3];
  202079. switch ([bez elementAtIndex: i associatedPoints: p])
  202080. {
  202081. case NSMoveToBezierPathElement:
  202082. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  202083. break;
  202084. case NSLineToBezierPathElement:
  202085. path.lineTo ((float) p[0].x, (float) -p[0].y);
  202086. break;
  202087. case NSCurveToBezierPathElement:
  202088. 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);
  202089. break;
  202090. case NSClosePathBezierPathElement:
  202091. path.closeSubPath();
  202092. break;
  202093. default:
  202094. jassertfalse
  202095. break;
  202096. }
  202097. }
  202098. path.applyTransform (pathTransform);
  202099. return true;
  202100. #endif
  202101. }
  202102. juce_UseDebuggingNewOperator
  202103. CGFontRef fontRef;
  202104. float fontHeightToCGSizeFactor;
  202105. CGAffineTransform renderingTransform;
  202106. private:
  202107. float ascent, unitsToHeightScaleFactor;
  202108. #if JUCE_IPHONE
  202109. #else
  202110. NSFont* nsFont;
  202111. AffineTransform pathTransform;
  202112. #endif
  202113. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  202114. {
  202115. #if SUPPORT_10_4_FONTS
  202116. #if ! SUPPORT_ONLY_10_4_FONTS
  202117. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202118. #endif
  202119. {
  202120. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  202121. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  202122. for (int i = 0; i < length; ++i)
  202123. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  202124. return;
  202125. }
  202126. #endif
  202127. #if ! SUPPORT_ONLY_10_4_FONTS
  202128. if (charToGlyphMapper == 0)
  202129. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  202130. glyphs.malloc (length);
  202131. for (int i = 0; i < length; ++i)
  202132. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  202133. #endif
  202134. }
  202135. #if ! SUPPORT_ONLY_10_4_FONTS
  202136. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  202137. class CharToGlyphMapper
  202138. {
  202139. public:
  202140. CharToGlyphMapper (CGFontRef fontRef)
  202141. : segCount (0), endCode (0), startCode (0), idDelta (0),
  202142. idRangeOffset (0), glyphIndexes (0)
  202143. {
  202144. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  202145. if (cmapTable != 0)
  202146. {
  202147. const int numSubtables = getValue16 (cmapTable, 2);
  202148. for (int i = 0; i < numSubtables; ++i)
  202149. {
  202150. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  202151. {
  202152. const int offset = getValue32 (cmapTable, i * 8 + 8);
  202153. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  202154. {
  202155. const int length = getValue16 (cmapTable, offset + 2);
  202156. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  202157. segCount = segCountX2 / 2;
  202158. const int endCodeOffset = offset + 14;
  202159. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  202160. const int idDeltaOffset = startCodeOffset + segCountX2;
  202161. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  202162. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  202163. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  202164. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  202165. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  202166. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  202167. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  202168. }
  202169. break;
  202170. }
  202171. }
  202172. CFRelease (cmapTable);
  202173. }
  202174. }
  202175. ~CharToGlyphMapper()
  202176. {
  202177. if (endCode != 0)
  202178. {
  202179. CFRelease (endCode);
  202180. CFRelease (startCode);
  202181. CFRelease (idDelta);
  202182. CFRelease (idRangeOffset);
  202183. CFRelease (glyphIndexes);
  202184. }
  202185. }
  202186. int getGlyphForCharacter (const juce_wchar c) const
  202187. {
  202188. for (int i = 0; i < segCount; ++i)
  202189. {
  202190. if (getValue16 (endCode, i * 2) >= c)
  202191. {
  202192. const int start = getValue16 (startCode, i * 2);
  202193. if (start > c)
  202194. break;
  202195. const int delta = getValue16 (idDelta, i * 2);
  202196. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  202197. if (rangeOffset == 0)
  202198. return delta + c;
  202199. else
  202200. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  202201. }
  202202. }
  202203. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  202204. return jmax (-1, c - 29);
  202205. }
  202206. private:
  202207. int segCount;
  202208. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  202209. static uint16 getValue16 (CFDataRef data, const int index)
  202210. {
  202211. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  202212. }
  202213. static uint32 getValue32 (CFDataRef data, const int index)
  202214. {
  202215. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  202216. }
  202217. };
  202218. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  202219. #endif
  202220. };
  202221. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  202222. {
  202223. return new MacTypeface (font);
  202224. }
  202225. const StringArray Font::findAllTypefaceNames() throw()
  202226. {
  202227. StringArray names;
  202228. const ScopedAutoReleasePool pool;
  202229. #if JUCE_IPHONE
  202230. NSArray* fonts = [UIFont familyNames];
  202231. #else
  202232. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  202233. #endif
  202234. for (unsigned int i = 0; i < [fonts count]; ++i)
  202235. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  202236. names.sort (true);
  202237. return names;
  202238. }
  202239. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  202240. {
  202241. #if JUCE_IPHONE
  202242. defaultSans = "Helvetica";
  202243. defaultSerif = "Times New Roman";
  202244. defaultFixed = "Courier New";
  202245. #else
  202246. defaultSans = "Lucida Grande";
  202247. defaultSerif = "Times New Roman";
  202248. defaultFixed = "Monaco";
  202249. #endif
  202250. }
  202251. #endif
  202252. /*** End of inlined file: juce_mac_Fonts.mm ***/
  202253. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202254. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202255. // compiled on its own).
  202256. #if JUCE_INCLUDED_FILE
  202257. class CoreGraphicsImage : public Image
  202258. {
  202259. public:
  202260. CoreGraphicsImage (const PixelFormat format_,
  202261. const int imageWidth_,
  202262. const int imageHeight_,
  202263. const bool clearImage)
  202264. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202265. {
  202266. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  202267. : CGColorSpaceCreateDeviceRGB();
  202268. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202269. colourSpace, getCGImageFlags (*this));
  202270. CGColorSpaceRelease (colourSpace);
  202271. }
  202272. ~CoreGraphicsImage()
  202273. {
  202274. CGContextRelease (context);
  202275. }
  202276. LowLevelGraphicsContext* createLowLevelContext();
  202277. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202278. {
  202279. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202280. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202281. {
  202282. return CGBitmapContextCreateImage (nativeImage->context);
  202283. }
  202284. else
  202285. {
  202286. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202287. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  202288. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202289. 8, srcData.pixelStride * 8, srcData.lineStride,
  202290. colourSpace, getCGImageFlags (juceImage), provider,
  202291. 0, true, kCGRenderingIntentDefault);
  202292. CGDataProviderRelease (provider);
  202293. return imageRef;
  202294. }
  202295. }
  202296. #if JUCE_MAC
  202297. static NSImage* createNSImage (const Image& image)
  202298. {
  202299. const ScopedAutoReleasePool pool;
  202300. NSImage* im = [[NSImage alloc] init];
  202301. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202302. [im lockFocus];
  202303. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202304. CGImageRef imageRef = createImage (image, false, colourSpace);
  202305. CGColorSpaceRelease (colourSpace);
  202306. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202307. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202308. CGImageRelease (imageRef);
  202309. [im unlockFocus];
  202310. return im;
  202311. }
  202312. #endif
  202313. CGContextRef context;
  202314. private:
  202315. static CGBitmapInfo getCGImageFlags (const Image& image)
  202316. {
  202317. #if JUCE_BIG_ENDIAN
  202318. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202319. #else
  202320. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202321. #endif
  202322. }
  202323. };
  202324. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202325. {
  202326. #if USE_COREGRAPHICS_RENDERING
  202327. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202328. #else
  202329. return new Image (format, imageWidth, imageHeight, clearImage);
  202330. #endif
  202331. }
  202332. class CoreGraphicsContext : public LowLevelGraphicsContext
  202333. {
  202334. public:
  202335. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202336. : context (context_),
  202337. flipHeight (flipHeight_),
  202338. numGradientLookupEntries (0)
  202339. {
  202340. CGContextRetain (context);
  202341. CGContextSaveGState(context);
  202342. CGContextSetShouldSmoothFonts (context, true);
  202343. CGContextSetShouldAntialias (context, true);
  202344. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202345. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202346. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202347. gradientCallbacks.version = 0;
  202348. gradientCallbacks.evaluate = gradientCallback;
  202349. gradientCallbacks.releaseInfo = 0;
  202350. state = new SavedState();
  202351. }
  202352. ~CoreGraphicsContext()
  202353. {
  202354. CGContextRestoreGState (context);
  202355. CGContextRelease (context);
  202356. CGColorSpaceRelease (rgbColourSpace);
  202357. CGColorSpaceRelease (greyColourSpace);
  202358. }
  202359. bool isVectorDevice() const { return false; }
  202360. void setOrigin (int x, int y)
  202361. {
  202362. CGContextTranslateCTM (context, x, -y);
  202363. }
  202364. bool clipToRectangle (const Rectangle<int>& r)
  202365. {
  202366. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202367. return ! isClipEmpty();
  202368. }
  202369. bool clipToRectangleList (const RectangleList& clipRegion)
  202370. {
  202371. if (clipRegion.isEmpty())
  202372. {
  202373. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202374. return false;
  202375. }
  202376. else
  202377. {
  202378. const int numRects = clipRegion.getNumRectangles();
  202379. HeapBlock <CGRect> rects (numRects);
  202380. for (int i = 0; i < numRects; ++i)
  202381. {
  202382. const Rectangle<int>& r = clipRegion.getRectangle(i);
  202383. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202384. }
  202385. CGContextClipToRects (context, rects, numRects);
  202386. return ! isClipEmpty();
  202387. }
  202388. }
  202389. void excludeClipRectangle (const Rectangle<int>& r)
  202390. {
  202391. RectangleList remaining (getClipBounds());
  202392. remaining.subtract (r);
  202393. clipToRectangleList (remaining);
  202394. }
  202395. void clipToPath (const Path& path, const AffineTransform& transform)
  202396. {
  202397. createPath (path, transform);
  202398. CGContextClip (context);
  202399. }
  202400. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  202401. {
  202402. if (! transform.isSingularity())
  202403. {
  202404. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202405. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202406. flip();
  202407. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202408. applyTransform (t);
  202409. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202410. CGContextClipToMask (context, r, image);
  202411. applyTransform (t.inverted());
  202412. flip();
  202413. CGImageRelease (image);
  202414. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202415. }
  202416. }
  202417. bool clipRegionIntersects (const Rectangle<int>& r)
  202418. {
  202419. return getClipBounds().intersects (r);
  202420. }
  202421. const Rectangle<int> getClipBounds() const
  202422. {
  202423. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202424. return Rectangle<int> (roundToInt (bounds.origin.x),
  202425. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202426. roundToInt (bounds.size.width),
  202427. roundToInt (bounds.size.height));
  202428. }
  202429. bool isClipEmpty() const
  202430. {
  202431. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202432. }
  202433. void saveState()
  202434. {
  202435. CGContextSaveGState (context);
  202436. stateStack.add (new SavedState (*state));
  202437. }
  202438. void restoreState()
  202439. {
  202440. CGContextRestoreGState (context);
  202441. SavedState* const top = stateStack.getLast();
  202442. if (top != 0)
  202443. {
  202444. state = top;
  202445. stateStack.removeLast (1, false);
  202446. }
  202447. else
  202448. {
  202449. jassertfalse // trying to pop with an empty stack!
  202450. }
  202451. }
  202452. void setFill (const FillType& fillType)
  202453. {
  202454. state->fillType = fillType;
  202455. if (fillType.isColour())
  202456. {
  202457. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202458. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202459. CGContextSetAlpha (context, 1.0f);
  202460. }
  202461. }
  202462. void setOpacity (float newOpacity)
  202463. {
  202464. state->fillType.setOpacity (newOpacity);
  202465. setFill (state->fillType);
  202466. }
  202467. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202468. {
  202469. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202470. ? kCGInterpolationLow
  202471. : kCGInterpolationHigh);
  202472. }
  202473. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  202474. {
  202475. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202476. if (replaceExistingContents)
  202477. {
  202478. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202479. CGContextClearRect (context, cgRect);
  202480. #else
  202481. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202482. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202483. CGContextClearRect (context, cgRect);
  202484. else
  202485. #endif
  202486. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202487. #endif
  202488. fillRect (r, false);
  202489. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202490. }
  202491. else
  202492. {
  202493. if (state->fillType.isColour())
  202494. {
  202495. CGContextFillRect (context, cgRect);
  202496. }
  202497. else if (state->fillType.isGradient())
  202498. {
  202499. CGContextSaveGState (context);
  202500. CGContextClipToRect (context, cgRect);
  202501. drawGradient();
  202502. CGContextRestoreGState (context);
  202503. }
  202504. else
  202505. {
  202506. CGContextSaveGState (context);
  202507. CGContextClipToRect (context, cgRect);
  202508. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202509. CGContextRestoreGState (context);
  202510. }
  202511. }
  202512. }
  202513. void fillPath (const Path& path, const AffineTransform& transform)
  202514. {
  202515. CGContextSaveGState (context);
  202516. if (state->fillType.isColour())
  202517. {
  202518. flip();
  202519. applyTransform (transform);
  202520. createPath (path);
  202521. if (path.isUsingNonZeroWinding())
  202522. CGContextFillPath (context);
  202523. else
  202524. CGContextEOFillPath (context);
  202525. }
  202526. else
  202527. {
  202528. createPath (path, transform);
  202529. if (path.isUsingNonZeroWinding())
  202530. CGContextClip (context);
  202531. else
  202532. CGContextEOClip (context);
  202533. if (state->fillType.isGradient())
  202534. drawGradient();
  202535. else
  202536. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202537. }
  202538. CGContextRestoreGState (context);
  202539. }
  202540. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  202541. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202542. {
  202543. jassert (sourceImage.getBounds().contains (srcClip));
  202544. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202545. CGImageRef image = fullImage;
  202546. if (srcClip != sourceImage.getBounds())
  202547. {
  202548. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202549. srcClip.getWidth(), srcClip.getHeight()));
  202550. CGImageRelease (fullImage);
  202551. }
  202552. CGContextSaveGState (context);
  202553. CGContextSetAlpha (context, state->fillType.getOpacity());
  202554. flip();
  202555. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202556. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202557. if (fillEntireClipAsTiles)
  202558. {
  202559. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  202560. CGContextDrawTiledImage (context, imageRect, image);
  202561. #else
  202562. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202563. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  202564. // if it's doing a transformation - it's quicker to just draw lots of images manually
  202565. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  202566. CGContextDrawTiledImage (context, imageRect, image);
  202567. else
  202568. #endif
  202569. {
  202570. // Fallback to manually doing a tiled fill on 10.4
  202571. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202572. const int iw = srcClip.getWidth();
  202573. const int ih = srcClip.getHeight();
  202574. int x = 0, y = 0;
  202575. while (x > clip.origin.x) x -= iw;
  202576. while (y > clip.origin.y) y -= ih;
  202577. const int right = (int) (clip.origin.x + clip.size.width);
  202578. const int bottom = (int) (clip.origin.y + clip.size.height);
  202579. while (y < bottom)
  202580. {
  202581. for (int x2 = x; x2 < right; x2 += iw)
  202582. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202583. y += ih;
  202584. }
  202585. }
  202586. #endif
  202587. }
  202588. else
  202589. {
  202590. CGContextDrawImage (context, imageRect, image);
  202591. }
  202592. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202593. CGContextRestoreGState (context);
  202594. }
  202595. void drawLine (double x1, double y1, double x2, double y2)
  202596. {
  202597. CGContextSetLineCap (context, kCGLineCapSquare);
  202598. CGContextSetLineWidth (context, 1.0f);
  202599. CGContextSetRGBStrokeColor (context,
  202600. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202601. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202602. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  202603. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  202604. CGContextStrokeLineSegments (context, line, 1);
  202605. }
  202606. void drawVerticalLine (const int x, double top, double bottom)
  202607. {
  202608. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202609. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202610. #else
  202611. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202612. // the x co-ord slightly to trick it..
  202613. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202614. #endif
  202615. }
  202616. void drawHorizontalLine (const int y, double left, double right)
  202617. {
  202618. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202619. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202620. #else
  202621. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202622. // the x co-ord slightly to trick it..
  202623. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202624. #endif
  202625. }
  202626. void setFont (const Font& newFont)
  202627. {
  202628. if (state->font != newFont)
  202629. {
  202630. state->fontRef = 0;
  202631. state->font = newFont;
  202632. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  202633. if (mf != 0)
  202634. {
  202635. state->fontRef = mf->fontRef;
  202636. CGContextSetFont (context, state->fontRef);
  202637. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202638. state->fontTransform = mf->renderingTransform;
  202639. state->fontTransform.a *= state->font.getHorizontalScale();
  202640. CGContextSetTextMatrix (context, state->fontTransform);
  202641. }
  202642. }
  202643. }
  202644. const Font getFont()
  202645. {
  202646. return state->font;
  202647. }
  202648. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202649. {
  202650. if (state->fontRef != 0 && state->fillType.isColour())
  202651. {
  202652. if (transform.isOnlyTranslation())
  202653. {
  202654. CGGlyph g = glyphNumber;
  202655. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202656. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202657. }
  202658. else
  202659. {
  202660. CGContextSaveGState (context);
  202661. flip();
  202662. applyTransform (transform);
  202663. CGAffineTransform t = state->fontTransform;
  202664. t.d = -t.d;
  202665. CGContextSetTextMatrix (context, t);
  202666. CGGlyph g = glyphNumber;
  202667. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202668. CGContextSetTextMatrix (context, state->fontTransform);
  202669. CGContextRestoreGState (context);
  202670. }
  202671. }
  202672. else
  202673. {
  202674. Path p;
  202675. Font& f = state->font;
  202676. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202677. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202678. .followedBy (transform));
  202679. }
  202680. }
  202681. private:
  202682. CGContextRef context;
  202683. const float flipHeight;
  202684. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202685. CGFunctionCallbacks gradientCallbacks;
  202686. struct SavedState
  202687. {
  202688. SavedState()
  202689. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202690. {
  202691. }
  202692. SavedState (const SavedState& other)
  202693. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202694. fontTransform (other.fontTransform)
  202695. {
  202696. }
  202697. ~SavedState()
  202698. {
  202699. }
  202700. FillType fillType;
  202701. Font font;
  202702. CGFontRef fontRef;
  202703. CGAffineTransform fontTransform;
  202704. };
  202705. ScopedPointer <SavedState> state;
  202706. OwnedArray <SavedState> stateStack;
  202707. HeapBlock <PixelARGB> gradientLookupTable;
  202708. int numGradientLookupEntries;
  202709. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202710. {
  202711. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  202712. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202713. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202714. colour.unpremultiply();
  202715. outData[0] = colour.getRed() / 255.0f;
  202716. outData[1] = colour.getGreen() / 255.0f;
  202717. outData[2] = colour.getBlue() / 255.0f;
  202718. outData[3] = colour.getAlpha() / 255.0f;
  202719. }
  202720. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202721. {
  202722. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202723. --numGradientLookupEntries;
  202724. CGShadingRef result = 0;
  202725. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  202726. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202727. if (gradient.isRadial)
  202728. {
  202729. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202730. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202731. function, true, true);
  202732. }
  202733. else
  202734. {
  202735. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202736. CGPointMake (gradient.x2, gradient.y2),
  202737. function, true, true);
  202738. }
  202739. CGFunctionRelease (function);
  202740. return result;
  202741. }
  202742. void drawGradient()
  202743. {
  202744. flip();
  202745. applyTransform (state->fillType.transform);
  202746. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202747. // you draw a gradient with high quality interp enabled).
  202748. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202749. CGContextSetAlpha (context, state->fillType.getOpacity());
  202750. CGContextDrawShading (context, shading);
  202751. CGShadingRelease (shading);
  202752. }
  202753. void createPath (const Path& path) const
  202754. {
  202755. CGContextBeginPath (context);
  202756. Path::Iterator i (path);
  202757. while (i.next())
  202758. {
  202759. switch (i.elementType)
  202760. {
  202761. case Path::Iterator::startNewSubPath:
  202762. CGContextMoveToPoint (context, i.x1, i.y1);
  202763. break;
  202764. case Path::Iterator::lineTo:
  202765. CGContextAddLineToPoint (context, i.x1, i.y1);
  202766. break;
  202767. case Path::Iterator::quadraticTo:
  202768. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202769. break;
  202770. case Path::Iterator::cubicTo:
  202771. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202772. break;
  202773. case Path::Iterator::closePath:
  202774. CGContextClosePath (context); break;
  202775. default:
  202776. jassertfalse
  202777. break;
  202778. }
  202779. }
  202780. }
  202781. void createPath (const Path& path, const AffineTransform& transform) const
  202782. {
  202783. CGContextBeginPath (context);
  202784. Path::Iterator i (path);
  202785. while (i.next())
  202786. {
  202787. switch (i.elementType)
  202788. {
  202789. case Path::Iterator::startNewSubPath:
  202790. transform.transformPoint (i.x1, i.y1);
  202791. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202792. break;
  202793. case Path::Iterator::lineTo:
  202794. transform.transformPoint (i.x1, i.y1);
  202795. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202796. break;
  202797. case Path::Iterator::quadraticTo:
  202798. transform.transformPoint (i.x1, i.y1);
  202799. transform.transformPoint (i.x2, i.y2);
  202800. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202801. break;
  202802. case Path::Iterator::cubicTo:
  202803. transform.transformPoint (i.x1, i.y1);
  202804. transform.transformPoint (i.x2, i.y2);
  202805. transform.transformPoint (i.x3, i.y3);
  202806. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202807. break;
  202808. case Path::Iterator::closePath:
  202809. CGContextClosePath (context); break;
  202810. default:
  202811. jassertfalse
  202812. break;
  202813. }
  202814. }
  202815. }
  202816. static Image* createAlphaChannelImage (const Image& im)
  202817. {
  202818. if (im.getFormat() == Image::SingleChannel)
  202819. return const_cast <Image*> (&im);
  202820. return im.createCopyOfAlphaChannel();
  202821. }
  202822. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  202823. {
  202824. if (im.getFormat() != Image::SingleChannel)
  202825. delete alphaIm;
  202826. }
  202827. void flip() const
  202828. {
  202829. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202830. }
  202831. void applyTransform (const AffineTransform& transform) const
  202832. {
  202833. CGAffineTransform t;
  202834. t.a = transform.mat00;
  202835. t.b = transform.mat10;
  202836. t.c = transform.mat01;
  202837. t.d = transform.mat11;
  202838. t.tx = transform.mat02;
  202839. t.ty = transform.mat12;
  202840. CGContextConcatCTM (context, t);
  202841. }
  202842. float flipY (float y) const
  202843. {
  202844. return flipHeight - y;
  202845. }
  202846. };
  202847. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202848. {
  202849. return new CoreGraphicsContext (context, imageHeight);
  202850. }
  202851. #endif
  202852. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202853. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  202854. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202855. // compiled on its own).
  202856. #if JUCE_INCLUDED_FILE
  202857. class UIViewComponentPeer;
  202858. END_JUCE_NAMESPACE
  202859. #define JuceUIView MakeObjCClassName(JuceUIView)
  202860. @interface JuceUIView : UIView
  202861. {
  202862. @public
  202863. UIViewComponentPeer* owner;
  202864. }
  202865. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  202866. - (void) dealloc;
  202867. - (void) drawRect: (CGRect) r;
  202868. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  202869. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  202870. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  202871. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  202872. - (BOOL) becomeFirstResponder;
  202873. - (BOOL) resignFirstResponder;
  202874. - (BOOL) canBecomeFirstResponder;
  202875. - (void) asyncRepaint: (id) rect;
  202876. @end
  202877. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  202878. @interface JuceUIWindow : UIWindow
  202879. {
  202880. @private
  202881. UIViewComponentPeer* owner;
  202882. bool isZooming;
  202883. }
  202884. - (void) setOwner: (UIViewComponentPeer*) owner;
  202885. - (void) becomeKeyWindow;
  202886. @end
  202887. BEGIN_JUCE_NAMESPACE
  202888. class UIViewComponentPeer : public ComponentPeer
  202889. {
  202890. public:
  202891. UIViewComponentPeer (Component* const component,
  202892. const int windowStyleFlags,
  202893. UIView* viewToAttachTo);
  202894. ~UIViewComponentPeer();
  202895. void* getNativeHandle() const;
  202896. void setVisible (bool shouldBeVisible);
  202897. void setTitle (const String& title);
  202898. void setPosition (int x, int y);
  202899. void setSize (int w, int h);
  202900. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  202901. const Rectangle<int> getBounds() const;
  202902. const Rectangle<int> getBounds (const bool global) const;
  202903. const Point<int> getScreenPosition() const;
  202904. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  202905. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  202906. void setMinimised (bool shouldBeMinimised);
  202907. bool isMinimised() const;
  202908. void setFullScreen (bool shouldBeFullScreen);
  202909. bool isFullScreen() const;
  202910. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  202911. const BorderSize getFrameSize() const;
  202912. bool setAlwaysOnTop (bool alwaysOnTop);
  202913. void toFront (bool makeActiveWindow);
  202914. void toBehind (ComponentPeer* other);
  202915. void setIcon (const Image& newIcon);
  202916. virtual void drawRect (CGRect r);
  202917. virtual bool canBecomeKeyWindow();
  202918. virtual bool windowShouldClose();
  202919. virtual void redirectMovedOrResized();
  202920. virtual CGRect constrainRect (CGRect r);
  202921. virtual void viewFocusGain();
  202922. virtual void viewFocusLoss();
  202923. bool isFocused() const;
  202924. void grabFocus();
  202925. void textInputRequired (const Point<int>& position);
  202926. void handleTouches (UIEvent* e, bool isDown, bool isUp, bool isCancel);
  202927. void repaint (int x, int y, int w, int h);
  202928. void performAnyPendingRepaintsNow();
  202929. juce_UseDebuggingNewOperator
  202930. UIWindow* window;
  202931. JuceUIView* view;
  202932. bool isSharedWindow, fullScreen, insideDrawRect;
  202933. static ModifierKeys currentModifiers;
  202934. static int64 getMouseTime (UIEvent* e)
  202935. {
  202936. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  202937. + (int64) ([e timestamp] * 1000.0);
  202938. }
  202939. Array <UITouch*> currentTouches;
  202940. };
  202941. END_JUCE_NAMESPACE
  202942. @implementation JuceUIView
  202943. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  202944. withFrame: (CGRect) frame
  202945. {
  202946. [super initWithFrame: frame];
  202947. owner = owner_;
  202948. return self;
  202949. }
  202950. - (void) dealloc
  202951. {
  202952. [super dealloc];
  202953. }
  202954. - (void) drawRect: (CGRect) r
  202955. {
  202956. if (owner != 0)
  202957. owner->drawRect (r);
  202958. }
  202959. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  202960. {
  202961. return false;
  202962. }
  202963. ModifierKeys UIViewComponentPeer::currentModifiers;
  202964. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  202965. {
  202966. return UIViewComponentPeer::currentModifiers;
  202967. }
  202968. void ModifierKeys::updateCurrentModifiers() throw()
  202969. {
  202970. currentModifiers = UIViewComponentPeer::currentModifiers;
  202971. }
  202972. JUCE_NAMESPACE::Point<int> juce_lastMousePos;
  202973. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  202974. {
  202975. if (owner != 0)
  202976. owner->handleTouches (event, true, false, false);
  202977. }
  202978. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  202979. {
  202980. if (owner != 0)
  202981. owner->handleTouches (event, false, false, false);
  202982. }
  202983. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  202984. {
  202985. if (owner != 0)
  202986. owner->handleTouches (event, false, true, false);
  202987. }
  202988. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  202989. {
  202990. if (owner != 0)
  202991. owner->handleTouches (event, false, true, true);
  202992. [self touchesEnded: touches withEvent: event];
  202993. }
  202994. - (BOOL) becomeFirstResponder
  202995. {
  202996. if (owner != 0)
  202997. owner->viewFocusGain();
  202998. return true;
  202999. }
  203000. - (BOOL) resignFirstResponder
  203001. {
  203002. if (owner != 0)
  203003. owner->viewFocusLoss();
  203004. return true;
  203005. }
  203006. - (BOOL) canBecomeFirstResponder
  203007. {
  203008. return owner != 0 && owner->canBecomeKeyWindow();
  203009. }
  203010. - (void) asyncRepaint: (id) rect
  203011. {
  203012. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  203013. [self setNeedsDisplayInRect: *r];
  203014. }
  203015. @end
  203016. @implementation JuceUIWindow
  203017. - (void) setOwner: (UIViewComponentPeer*) owner_
  203018. {
  203019. owner = owner_;
  203020. isZooming = false;
  203021. }
  203022. - (void) becomeKeyWindow
  203023. {
  203024. [super becomeKeyWindow];
  203025. if (owner != 0)
  203026. owner->grabFocus();
  203027. }
  203028. @end
  203029. BEGIN_JUCE_NAMESPACE
  203030. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  203031. const int windowStyleFlags,
  203032. UIView* viewToAttachTo)
  203033. : ComponentPeer (component, windowStyleFlags),
  203034. window (0),
  203035. view (0),
  203036. isSharedWindow (viewToAttachTo != 0),
  203037. fullScreen (false),
  203038. insideDrawRect (false)
  203039. {
  203040. CGRect r;
  203041. r.origin.x = 0;
  203042. r.origin.y = 0;
  203043. r.size.width = (float) component->getWidth();
  203044. r.size.height = (float) component->getHeight();
  203045. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  203046. if (isSharedWindow)
  203047. {
  203048. window = [viewToAttachTo window];
  203049. [viewToAttachTo addSubview: view];
  203050. setVisible (component->isVisible());
  203051. }
  203052. else
  203053. {
  203054. r.origin.x = (float) component->getX();
  203055. r.origin.y = (float) component->getY();
  203056. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  203057. window = [[JuceUIWindow alloc] init];
  203058. window.frame = r;
  203059. window.opaque = component->isOpaque();
  203060. view.opaque = component->isOpaque();
  203061. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203062. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203063. [((JuceUIWindow*) window) setOwner: this];
  203064. if (component->isAlwaysOnTop())
  203065. window.windowLevel = UIWindowLevelAlert;
  203066. [window addSubview: view];
  203067. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203068. view.hidden = ! component->isVisible();
  203069. window.hidden = ! component->isVisible();
  203070. view.multipleTouchEnabled = YES;
  203071. }
  203072. setTitle (component->getName());
  203073. }
  203074. UIViewComponentPeer::~UIViewComponentPeer()
  203075. {
  203076. view->owner = 0;
  203077. [view removeFromSuperview];
  203078. [view release];
  203079. if (! isSharedWindow)
  203080. {
  203081. [((JuceUIWindow*) window) setOwner: 0];
  203082. [window release];
  203083. }
  203084. }
  203085. void* UIViewComponentPeer::getNativeHandle() const
  203086. {
  203087. return view;
  203088. }
  203089. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  203090. {
  203091. view.hidden = ! shouldBeVisible;
  203092. if (! isSharedWindow)
  203093. window.hidden = ! shouldBeVisible;
  203094. }
  203095. void UIViewComponentPeer::setTitle (const String& title)
  203096. {
  203097. // xxx is this possible?
  203098. }
  203099. void UIViewComponentPeer::setPosition (int x, int y)
  203100. {
  203101. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  203102. }
  203103. void UIViewComponentPeer::setSize (int w, int h)
  203104. {
  203105. setBounds (component->getX(), component->getY(), w, h, false);
  203106. }
  203107. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  203108. {
  203109. fullScreen = isNowFullScreen;
  203110. w = jmax (0, w);
  203111. h = jmax (0, h);
  203112. CGRect r;
  203113. r.origin.x = (float) x;
  203114. r.origin.y = (float) y;
  203115. r.size.width = (float) w;
  203116. r.size.height = (float) h;
  203117. if (isSharedWindow)
  203118. {
  203119. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  203120. if ([view frame].size.width != r.size.width
  203121. || [view frame].size.height != r.size.height)
  203122. [view setNeedsDisplay];
  203123. view.frame = r;
  203124. }
  203125. else
  203126. {
  203127. window.frame = r;
  203128. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203129. }
  203130. }
  203131. const Rectangle<int> UIViewComponentPeer::getBounds (const bool global) const
  203132. {
  203133. CGRect r = [view frame];
  203134. if (global && [view window] != 0)
  203135. {
  203136. r = [view convertRect: r toView: nil];
  203137. CGRect wr = [[view window] frame];
  203138. r.origin.x += wr.origin.x;
  203139. r.origin.y += wr.origin.y;
  203140. }
  203141. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y,
  203142. (int) r.size.width, (int) r.size.height);
  203143. }
  203144. const Rectangle<int> UIViewComponentPeer::getBounds() const
  203145. {
  203146. return getBounds (! isSharedWindow);
  203147. }
  203148. const Point<int> UIViewComponentPeer::getScreenPosition() const
  203149. {
  203150. return getBounds (true).getPosition();
  203151. }
  203152. const Point<int> UIViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  203153. {
  203154. return relativePosition + getScreenPosition();
  203155. }
  203156. const Point<int> UIViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  203157. {
  203158. return screenPosition - getScreenPosition();
  203159. }
  203160. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  203161. {
  203162. if (constrainer != 0)
  203163. {
  203164. CGRect current = [window frame];
  203165. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  203166. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  203167. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  203168. (int) r.size.width, (int) r.size.height);
  203169. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  203170. (int) current.size.width, (int) current.size.height);
  203171. constrainer->checkBounds (pos, original,
  203172. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  203173. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  203174. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  203175. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  203176. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  203177. r.origin.x = pos.getX();
  203178. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY();
  203179. r.size.width = pos.getWidth();
  203180. r.size.height = pos.getHeight();
  203181. }
  203182. return r;
  203183. }
  203184. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  203185. {
  203186. // xxx
  203187. }
  203188. bool UIViewComponentPeer::isMinimised() const
  203189. {
  203190. return false;
  203191. }
  203192. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  203193. {
  203194. if (! isSharedWindow)
  203195. {
  203196. Rectangle<int> r (lastNonFullscreenBounds);
  203197. setMinimised (false);
  203198. if (fullScreen != shouldBeFullScreen)
  203199. {
  203200. if (shouldBeFullScreen)
  203201. r = Desktop::getInstance().getMainMonitorArea();
  203202. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  203203. if (r != getComponent()->getBounds() && ! r.isEmpty())
  203204. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  203205. }
  203206. }
  203207. }
  203208. bool UIViewComponentPeer::isFullScreen() const
  203209. {
  203210. return fullScreen;
  203211. }
  203212. bool UIViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  203213. {
  203214. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  203215. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  203216. return false;
  203217. CGPoint p;
  203218. p.x = (float) position.getX();
  203219. p.y = (float) position.getY();
  203220. UIView* v = [view hitTest: p withEvent: nil];
  203221. if (trueIfInAChildWindow)
  203222. return v != nil;
  203223. return v == view;
  203224. }
  203225. const BorderSize UIViewComponentPeer::getFrameSize() const
  203226. {
  203227. BorderSize b;
  203228. if (! isSharedWindow)
  203229. {
  203230. CGRect v = [view convertRect: [view frame] toView: nil];
  203231. CGRect w = [window frame];
  203232. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203233. b.setBottom ((int) v.origin.y);
  203234. b.setLeft ((int) v.origin.x);
  203235. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203236. }
  203237. return b;
  203238. }
  203239. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203240. {
  203241. if (! isSharedWindow)
  203242. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203243. return true;
  203244. }
  203245. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203246. {
  203247. if (isSharedWindow)
  203248. [[view superview] bringSubviewToFront: view];
  203249. if (window != 0 && component->isVisible())
  203250. [window makeKeyAndVisible];
  203251. }
  203252. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203253. {
  203254. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203255. if (isSharedWindow)
  203256. {
  203257. [[view superview] insertSubview: view belowSubview: o->view];
  203258. }
  203259. else
  203260. {
  203261. jassertfalse // don't know how to do this
  203262. }
  203263. }
  203264. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203265. {
  203266. // to do..
  203267. }
  203268. void UIViewComponentPeer::handleTouches (UIEvent* event, const bool isDown, const bool isUp, bool isCancel)
  203269. {
  203270. NSArray* touches = [[event touchesForView: view] allObjects];
  203271. for (unsigned int i = 0; i < [touches count]; ++i)
  203272. {
  203273. UITouch* touch = [touches objectAtIndex: i];
  203274. CGPoint p = [touch locationInView: view];
  203275. const Point<int> pos ((int) p.x, (int) p.y);
  203276. juce_lastMousePos = pos + getScreenPosition();
  203277. const int64 time = getMouseTime (event);
  203278. int touchIndex = currentTouches.indexOf (touch);
  203279. if (touchIndex < 0)
  203280. {
  203281. touchIndex = currentTouches.size();
  203282. currentTouches.add (touch);
  203283. }
  203284. if (isDown)
  203285. {
  203286. currentModifiers = currentModifiers.withoutMouseButtons();
  203287. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203288. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (ModifierKeys::leftButtonModifier);
  203289. }
  203290. else if (isUp)
  203291. {
  203292. currentModifiers = currentModifiers.withoutMouseButtons();
  203293. currentTouches.remove (touchIndex);
  203294. }
  203295. if (isCancel)
  203296. currentTouches.clear();
  203297. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203298. }
  203299. }
  203300. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203301. void UIViewComponentPeer::viewFocusGain()
  203302. {
  203303. if (currentlyFocusedPeer != this)
  203304. {
  203305. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203306. currentlyFocusedPeer->handleFocusLoss();
  203307. currentlyFocusedPeer = this;
  203308. handleFocusGain();
  203309. }
  203310. }
  203311. void UIViewComponentPeer::viewFocusLoss()
  203312. {
  203313. if (currentlyFocusedPeer == this)
  203314. {
  203315. currentlyFocusedPeer = 0;
  203316. handleFocusLoss();
  203317. }
  203318. }
  203319. void juce_HandleProcessFocusChange()
  203320. {
  203321. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203322. {
  203323. if (Process::isForegroundProcess())
  203324. {
  203325. currentlyFocusedPeer->handleFocusGain();
  203326. ComponentPeer::bringModalComponentToFront();
  203327. }
  203328. else
  203329. {
  203330. currentlyFocusedPeer->handleFocusLoss();
  203331. // turn kiosk mode off if we lose focus..
  203332. Desktop::getInstance().setKioskModeComponent (0);
  203333. }
  203334. }
  203335. }
  203336. bool UIViewComponentPeer::isFocused() const
  203337. {
  203338. return isSharedWindow ? this == currentlyFocusedPeer
  203339. : (window != 0 && [window isKeyWindow]);
  203340. }
  203341. void UIViewComponentPeer::grabFocus()
  203342. {
  203343. if (window != 0)
  203344. {
  203345. [window makeKeyWindow];
  203346. viewFocusGain();
  203347. }
  203348. }
  203349. void UIViewComponentPeer::textInputRequired (const Point<int>&)
  203350. {
  203351. }
  203352. void UIViewComponentPeer::drawRect (CGRect r)
  203353. {
  203354. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203355. return;
  203356. CGContextRef cg = UIGraphicsGetCurrentContext();
  203357. if (! component->isOpaque())
  203358. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203359. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203360. CoreGraphicsContext g (cg, view.bounds.size.height);
  203361. insideDrawRect = true;
  203362. handlePaint (g);
  203363. insideDrawRect = false;
  203364. }
  203365. bool UIViewComponentPeer::canBecomeKeyWindow()
  203366. {
  203367. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203368. }
  203369. bool UIViewComponentPeer::windowShouldClose()
  203370. {
  203371. if (! isValidPeer (this))
  203372. return YES;
  203373. handleUserClosingWindow();
  203374. return NO;
  203375. }
  203376. void UIViewComponentPeer::redirectMovedOrResized()
  203377. {
  203378. handleMovedOrResized();
  203379. }
  203380. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203381. {
  203382. }
  203383. class AsyncRepaintMessage : public CallbackMessage
  203384. {
  203385. public:
  203386. UIViewComponentPeer* const peer;
  203387. const Rectangle<int> rect;
  203388. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  203389. : peer (peer_), rect (rect_)
  203390. {
  203391. }
  203392. void messageCallback()
  203393. {
  203394. if (ComponentPeer::isValidPeer (peer))
  203395. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203396. }
  203397. };
  203398. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203399. {
  203400. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203401. {
  203402. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  203403. }
  203404. else
  203405. {
  203406. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203407. }
  203408. }
  203409. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203410. {
  203411. }
  203412. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203413. {
  203414. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203415. }
  203416. Image* juce_createIconForFile (const File& file)
  203417. {
  203418. return 0;
  203419. }
  203420. void Desktop::createMouseInputSources()
  203421. {
  203422. for (int i = 0; i < 10; ++i)
  203423. mouseSources.add (new MouseInputSource (i, false));
  203424. }
  203425. bool Desktop::canUseSemiTransparentWindows() throw()
  203426. {
  203427. return true;
  203428. }
  203429. const Point<int> Desktop::getMousePosition()
  203430. {
  203431. return juce_lastMousePos;
  203432. }
  203433. void Desktop::setMousePosition (const Point<int>&)
  203434. {
  203435. }
  203436. const int KeyPress::spaceKey = ' ';
  203437. const int KeyPress::returnKey = 0x0d;
  203438. const int KeyPress::escapeKey = 0x1b;
  203439. const int KeyPress::backspaceKey = 0x7f;
  203440. const int KeyPress::leftKey = 0x1000;
  203441. const int KeyPress::rightKey = 0x1001;
  203442. const int KeyPress::upKey = 0x1002;
  203443. const int KeyPress::downKey = 0x1003;
  203444. const int KeyPress::pageUpKey = 0x1004;
  203445. const int KeyPress::pageDownKey = 0x1005;
  203446. const int KeyPress::endKey = 0x1006;
  203447. const int KeyPress::homeKey = 0x1007;
  203448. const int KeyPress::deleteKey = 0x1008;
  203449. const int KeyPress::insertKey = -1;
  203450. const int KeyPress::tabKey = 9;
  203451. const int KeyPress::F1Key = 0x2001;
  203452. const int KeyPress::F2Key = 0x2002;
  203453. const int KeyPress::F3Key = 0x2003;
  203454. const int KeyPress::F4Key = 0x2004;
  203455. const int KeyPress::F5Key = 0x2005;
  203456. const int KeyPress::F6Key = 0x2006;
  203457. const int KeyPress::F7Key = 0x2007;
  203458. const int KeyPress::F8Key = 0x2008;
  203459. const int KeyPress::F9Key = 0x2009;
  203460. const int KeyPress::F10Key = 0x200a;
  203461. const int KeyPress::F11Key = 0x200b;
  203462. const int KeyPress::F12Key = 0x200c;
  203463. const int KeyPress::F13Key = 0x200d;
  203464. const int KeyPress::F14Key = 0x200e;
  203465. const int KeyPress::F15Key = 0x200f;
  203466. const int KeyPress::F16Key = 0x2010;
  203467. const int KeyPress::numberPad0 = 0x30020;
  203468. const int KeyPress::numberPad1 = 0x30021;
  203469. const int KeyPress::numberPad2 = 0x30022;
  203470. const int KeyPress::numberPad3 = 0x30023;
  203471. const int KeyPress::numberPad4 = 0x30024;
  203472. const int KeyPress::numberPad5 = 0x30025;
  203473. const int KeyPress::numberPad6 = 0x30026;
  203474. const int KeyPress::numberPad7 = 0x30027;
  203475. const int KeyPress::numberPad8 = 0x30028;
  203476. const int KeyPress::numberPad9 = 0x30029;
  203477. const int KeyPress::numberPadAdd = 0x3002a;
  203478. const int KeyPress::numberPadSubtract = 0x3002b;
  203479. const int KeyPress::numberPadMultiply = 0x3002c;
  203480. const int KeyPress::numberPadDivide = 0x3002d;
  203481. const int KeyPress::numberPadSeparator = 0x3002e;
  203482. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203483. const int KeyPress::numberPadEquals = 0x30030;
  203484. const int KeyPress::numberPadDelete = 0x30031;
  203485. const int KeyPress::playKey = 0x30000;
  203486. const int KeyPress::stopKey = 0x30001;
  203487. const int KeyPress::fastForwardKey = 0x30002;
  203488. const int KeyPress::rewindKey = 0x30003;
  203489. #endif
  203490. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203491. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  203492. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203493. // compiled on its own).
  203494. #if JUCE_INCLUDED_FILE
  203495. struct CallbackMessagePayload
  203496. {
  203497. MessageCallbackFunction* function;
  203498. void* parameter;
  203499. void* volatile result;
  203500. bool volatile hasBeenExecuted;
  203501. };
  203502. END_JUCE_NAMESPACE
  203503. using namespace JUCE_NAMESPACE;
  203504. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203505. {
  203506. }
  203507. - (JuceAppDelegate*) init;
  203508. - (void) dealloc;
  203509. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203510. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203511. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203512. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203513. - (void) customEvent: (id) data;
  203514. - (void) performCallback: (id) info;
  203515. @end
  203516. @implementation JuceAppDelegate
  203517. - (JuceAppDelegate*) init
  203518. {
  203519. [super init];
  203520. [[UIApplication sharedApplication] setDelegate: self];
  203521. return self;
  203522. }
  203523. - (void) dealloc
  203524. {
  203525. [[UIApplication sharedApplication] setDelegate: nil];
  203526. [super dealloc];
  203527. }
  203528. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203529. {
  203530. if (JUCEApplication::getInstance() != 0)
  203531. {
  203532. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203533. return YES;
  203534. }
  203535. return NO;
  203536. }
  203537. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203538. {
  203539. juce_HandleProcessFocusChange();
  203540. }
  203541. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203542. {
  203543. juce_HandleProcessFocusChange();
  203544. }
  203545. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203546. {
  203547. juce_HandleProcessFocusChange();
  203548. }
  203549. - (void) customEvent: (id) n
  203550. {
  203551. NSData* data = (NSData*) n;
  203552. void* message = 0;
  203553. [data getBytes: &message length: sizeof (message)];
  203554. [data release];
  203555. if (message != 0)
  203556. MessageManager::getInstance()->deliverMessage (message);
  203557. }
  203558. - (void) performCallback: (id) info
  203559. {
  203560. if ([info isKindOfClass: [NSData class]])
  203561. {
  203562. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203563. if (pl != 0)
  203564. {
  203565. pl->result = (*pl->function) (pl->parameter);
  203566. pl->hasBeenExecuted = true;
  203567. }
  203568. }
  203569. else
  203570. {
  203571. jassertfalse // should never get here!
  203572. }
  203573. }
  203574. @end
  203575. BEGIN_JUCE_NAMESPACE
  203576. static JuceAppDelegate* juceAppDelegate = 0;
  203577. void MessageManager::runDispatchLoop()
  203578. {
  203579. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203580. runDispatchLoopUntil (-1);
  203581. }
  203582. void MessageManager::stopDispatchLoop()
  203583. {
  203584. exit (0); // iPhone apps get no mercy..
  203585. }
  203586. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203587. {
  203588. const ScopedAutoReleasePool pool;
  203589. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203590. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203591. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203592. while (! quitMessagePosted)
  203593. {
  203594. const ScopedAutoReleasePool pool;
  203595. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203596. beforeDate: endDate];
  203597. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203598. break;
  203599. }
  203600. return ! quitMessagePosted;
  203601. }
  203602. static CFRunLoopRef runLoop = 0;
  203603. static CFRunLoopSourceRef runLoopSource = 0;
  203604. static Array <void*, CriticalSection>* pendingMessages = 0;
  203605. static void runLoopSourceCallback (void*)
  203606. {
  203607. if (pendingMessages != 0)
  203608. {
  203609. int numDispatched = 0;
  203610. do
  203611. {
  203612. void* const nextMessage = pendingMessages->remove (0);
  203613. if (nextMessage == 0)
  203614. return;
  203615. const ScopedAutoReleasePool pool;
  203616. MessageManager::getInstance()->deliverMessage (nextMessage);
  203617. } while (++numDispatched <= 4);
  203618. CFRunLoopSourceSignal (runLoopSource);
  203619. CFRunLoopWakeUp (runLoop);
  203620. }
  203621. }
  203622. void MessageManager::doPlatformSpecificInitialisation()
  203623. {
  203624. pendingMessages = new Array <void*, CriticalSection>();
  203625. runLoop = CFRunLoopGetCurrent();
  203626. CFRunLoopSourceContext sourceContext;
  203627. zerostruct (sourceContext);
  203628. sourceContext.perform = runLoopSourceCallback;
  203629. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203630. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203631. if (juceAppDelegate == 0)
  203632. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203633. }
  203634. void MessageManager::doPlatformSpecificShutdown()
  203635. {
  203636. CFRunLoopSourceInvalidate (runLoopSource);
  203637. CFRelease (runLoopSource);
  203638. runLoopSource = 0;
  203639. if (pendingMessages != 0)
  203640. {
  203641. while (pendingMessages->size() > 0)
  203642. delete ((Message*) pendingMessages->remove(0));
  203643. deleteAndZero (pendingMessages);
  203644. }
  203645. if (juceAppDelegate != 0)
  203646. {
  203647. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203648. [juceAppDelegate release];
  203649. juceAppDelegate = 0;
  203650. }
  203651. }
  203652. bool juce_postMessageToSystemQueue (void* message)
  203653. {
  203654. if (pendingMessages != 0)
  203655. {
  203656. pendingMessages->add (message);
  203657. CFRunLoopSourceSignal (runLoopSource);
  203658. CFRunLoopWakeUp (runLoop);
  203659. }
  203660. return true;
  203661. }
  203662. void MessageManager::broadcastMessage (const String& value) throw()
  203663. {
  203664. }
  203665. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203666. void* data)
  203667. {
  203668. if (isThisTheMessageThread())
  203669. {
  203670. return (*callback) (data);
  203671. }
  203672. else
  203673. {
  203674. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203675. // deadlock because the message manager is blocked from running, so can never
  203676. // call your function..
  203677. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203678. const ScopedAutoReleasePool pool;
  203679. CallbackMessagePayload cmp;
  203680. cmp.function = callback;
  203681. cmp.parameter = data;
  203682. cmp.result = 0;
  203683. cmp.hasBeenExecuted = false;
  203684. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203685. withObject: [NSData dataWithBytesNoCopy: &cmp
  203686. length: sizeof (cmp)
  203687. freeWhenDone: NO]
  203688. waitUntilDone: YES];
  203689. return cmp.result;
  203690. }
  203691. }
  203692. #endif
  203693. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203694. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203695. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203696. // compiled on its own).
  203697. #if JUCE_INCLUDED_FILE
  203698. #if JUCE_MAC
  203699. END_JUCE_NAMESPACE
  203700. using namespace JUCE_NAMESPACE;
  203701. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203702. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203703. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203704. #else
  203705. @interface JuceFileChooserDelegate : NSObject
  203706. #endif
  203707. {
  203708. StringArray* filters;
  203709. }
  203710. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203711. - (void) dealloc;
  203712. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203713. @end
  203714. @implementation JuceFileChooserDelegate
  203715. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203716. {
  203717. [super init];
  203718. filters = filters_;
  203719. return self;
  203720. }
  203721. - (void) dealloc
  203722. {
  203723. delete filters;
  203724. [super dealloc];
  203725. }
  203726. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203727. {
  203728. const File f (nsStringToJuce (filename));
  203729. for (int i = filters->size(); --i >= 0;)
  203730. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203731. return true;
  203732. return f.isDirectory();
  203733. }
  203734. @end
  203735. BEGIN_JUCE_NAMESPACE
  203736. void FileChooser::showPlatformDialog (Array<File>& results,
  203737. const String& title,
  203738. const File& currentFileOrDirectory,
  203739. const String& filter,
  203740. bool selectsDirectory,
  203741. bool selectsFiles,
  203742. bool isSaveDialogue,
  203743. bool warnAboutOverwritingExistingFiles,
  203744. bool selectMultipleFiles,
  203745. FilePreviewComponent* extraInfoComponent)
  203746. {
  203747. const ScopedAutoReleasePool pool;
  203748. StringArray* filters = new StringArray();
  203749. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  203750. filters->trim();
  203751. filters->removeEmptyStrings();
  203752. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203753. [delegate autorelease];
  203754. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203755. : [NSOpenPanel openPanel];
  203756. [panel setTitle: juceStringToNS (title)];
  203757. if (! isSaveDialogue)
  203758. {
  203759. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203760. [openPanel setCanChooseDirectories: selectsDirectory];
  203761. [openPanel setCanChooseFiles: selectsFiles];
  203762. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203763. }
  203764. [panel setDelegate: delegate];
  203765. if (isSaveDialogue || selectsDirectory)
  203766. [panel setCanCreateDirectories: YES];
  203767. String directory, filename;
  203768. if (currentFileOrDirectory.isDirectory())
  203769. {
  203770. directory = currentFileOrDirectory.getFullPathName();
  203771. }
  203772. else
  203773. {
  203774. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203775. filename = currentFileOrDirectory.getFileName();
  203776. }
  203777. if ([panel runModalForDirectory: juceStringToNS (directory)
  203778. file: juceStringToNS (filename)]
  203779. == NSOKButton)
  203780. {
  203781. if (isSaveDialogue)
  203782. {
  203783. results.add (File (nsStringToJuce ([panel filename])));
  203784. }
  203785. else
  203786. {
  203787. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203788. NSArray* urls = [openPanel filenames];
  203789. for (unsigned int i = 0; i < [urls count]; ++i)
  203790. {
  203791. NSString* f = [urls objectAtIndex: i];
  203792. results.add (File (nsStringToJuce (f)));
  203793. }
  203794. }
  203795. }
  203796. [panel setDelegate: nil];
  203797. }
  203798. #else
  203799. void FileChooser::showPlatformDialog (Array<File>& results,
  203800. const String& title,
  203801. const File& currentFileOrDirectory,
  203802. const String& filter,
  203803. bool selectsDirectory,
  203804. bool selectsFiles,
  203805. bool isSaveDialogue,
  203806. bool warnAboutOverwritingExistingFiles,
  203807. bool selectMultipleFiles,
  203808. FilePreviewComponent* extraInfoComponent)
  203809. {
  203810. const ScopedAutoReleasePool pool;
  203811. jassertfalse //xxx to do
  203812. }
  203813. #endif
  203814. #endif
  203815. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203816. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  203817. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203818. // compiled on its own).
  203819. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  203820. #if JUCE_MAC
  203821. END_JUCE_NAMESPACE
  203822. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  203823. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  203824. {
  203825. CriticalSection* contextLock;
  203826. bool needsUpdate;
  203827. }
  203828. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  203829. - (bool) makeActive;
  203830. - (void) makeInactive;
  203831. - (void) reshape;
  203832. @end
  203833. @implementation ThreadSafeNSOpenGLView
  203834. - (id) initWithFrame: (NSRect) frameRect
  203835. pixelFormat: (NSOpenGLPixelFormat*) format
  203836. {
  203837. contextLock = new CriticalSection();
  203838. self = [super initWithFrame: frameRect pixelFormat: format];
  203839. if (self != nil)
  203840. [[NSNotificationCenter defaultCenter] addObserver: self
  203841. selector: @selector (_surfaceNeedsUpdate:)
  203842. name: NSViewGlobalFrameDidChangeNotification
  203843. object: self];
  203844. return self;
  203845. }
  203846. - (void) dealloc
  203847. {
  203848. [[NSNotificationCenter defaultCenter] removeObserver: self];
  203849. delete contextLock;
  203850. [super dealloc];
  203851. }
  203852. - (bool) makeActive
  203853. {
  203854. const ScopedLock sl (*contextLock);
  203855. if ([self openGLContext] == 0)
  203856. return false;
  203857. [[self openGLContext] makeCurrentContext];
  203858. if (needsUpdate)
  203859. {
  203860. [super update];
  203861. needsUpdate = false;
  203862. }
  203863. return true;
  203864. }
  203865. - (void) makeInactive
  203866. {
  203867. const ScopedLock sl (*contextLock);
  203868. [NSOpenGLContext clearCurrentContext];
  203869. }
  203870. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  203871. {
  203872. const ScopedLock sl (*contextLock);
  203873. needsUpdate = true;
  203874. }
  203875. - (void) update
  203876. {
  203877. const ScopedLock sl (*contextLock);
  203878. needsUpdate = true;
  203879. }
  203880. - (void) reshape
  203881. {
  203882. const ScopedLock sl (*contextLock);
  203883. needsUpdate = true;
  203884. }
  203885. @end
  203886. BEGIN_JUCE_NAMESPACE
  203887. class WindowedGLContext : public OpenGLContext
  203888. {
  203889. public:
  203890. WindowedGLContext (Component* const component,
  203891. const OpenGLPixelFormat& pixelFormat_,
  203892. NSOpenGLContext* sharedContext)
  203893. : renderContext (0),
  203894. pixelFormat (pixelFormat_)
  203895. {
  203896. jassert (component != 0);
  203897. NSOpenGLPixelFormatAttribute attribs [64];
  203898. int n = 0;
  203899. attribs[n++] = NSOpenGLPFADoubleBuffer;
  203900. attribs[n++] = NSOpenGLPFAAccelerated;
  203901. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  203902. attribs[n++] = NSOpenGLPFAColorSize;
  203903. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  203904. pixelFormat.greenBits,
  203905. pixelFormat.blueBits);
  203906. attribs[n++] = NSOpenGLPFAAlphaSize;
  203907. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  203908. attribs[n++] = NSOpenGLPFADepthSize;
  203909. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  203910. attribs[n++] = NSOpenGLPFAStencilSize;
  203911. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  203912. attribs[n++] = NSOpenGLPFAAccumSize;
  203913. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  203914. pixelFormat.accumulationBufferGreenBits,
  203915. pixelFormat.accumulationBufferBlueBits,
  203916. pixelFormat.accumulationBufferAlphaBits);
  203917. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  203918. attribs[n++] = NSOpenGLPFASampleBuffers;
  203919. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  203920. attribs[n++] = NSOpenGLPFAClosestPolicy;
  203921. attribs[n++] = NSOpenGLPFANoRecovery;
  203922. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  203923. NSOpenGLPixelFormat* format
  203924. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  203925. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  203926. pixelFormat: format];
  203927. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  203928. shareContext: sharedContext] autorelease];
  203929. const GLint swapInterval = 1;
  203930. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  203931. [view setOpenGLContext: renderContext];
  203932. [renderContext setView: view];
  203933. [format release];
  203934. viewHolder = new NSViewComponentInternal (view, component);
  203935. }
  203936. ~WindowedGLContext()
  203937. {
  203938. makeInactive();
  203939. [renderContext clearDrawable];
  203940. viewHolder = 0;
  203941. }
  203942. bool makeActive() const throw()
  203943. {
  203944. jassert (renderContext != 0);
  203945. [view makeActive];
  203946. return isActive();
  203947. }
  203948. bool makeInactive() const throw()
  203949. {
  203950. [view makeInactive];
  203951. return true;
  203952. }
  203953. bool isActive() const throw()
  203954. {
  203955. return [NSOpenGLContext currentContext] == renderContext;
  203956. }
  203957. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203958. void* getRawContext() const throw() { return renderContext; }
  203959. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203960. {
  203961. }
  203962. void swapBuffers()
  203963. {
  203964. [renderContext flushBuffer];
  203965. }
  203966. bool setSwapInterval (const int numFramesPerSwap)
  203967. {
  203968. [renderContext setValues: (const GLint*) &numFramesPerSwap
  203969. forParameter: NSOpenGLCPSwapInterval];
  203970. return true;
  203971. }
  203972. int getSwapInterval() const
  203973. {
  203974. GLint numFrames = 0;
  203975. [renderContext getValues: &numFrames
  203976. forParameter: NSOpenGLCPSwapInterval];
  203977. return numFrames;
  203978. }
  203979. void repaint()
  203980. {
  203981. // we need to invalidate the juce view that holds this gl view, to make it
  203982. // cause a repaint callback
  203983. NSView* v = (NSView*) viewHolder->view;
  203984. NSRect r = [v frame];
  203985. // bit of a bodge here.. if we only invalidate the area of the gl component,
  203986. // it's completely covered by the NSOpenGLView, so the OS throws away the
  203987. // repaint message, thus never causing our paint() callback, and never repainting
  203988. // the comp. So invalidating just a little bit around the edge helps..
  203989. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  203990. }
  203991. void* getNativeWindowHandle() const { return viewHolder->view; }
  203992. juce_UseDebuggingNewOperator
  203993. NSOpenGLContext* renderContext;
  203994. ThreadSafeNSOpenGLView* view;
  203995. private:
  203996. OpenGLPixelFormat pixelFormat;
  203997. ScopedPointer <NSViewComponentInternal> viewHolder;
  203998. WindowedGLContext (const WindowedGLContext&);
  203999. WindowedGLContext& operator= (const WindowedGLContext&);
  204000. };
  204001. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204002. const OpenGLPixelFormat& pixelFormat,
  204003. const OpenGLContext* const contextToShareWith)
  204004. {
  204005. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  204006. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  204007. return (c->renderContext != 0) ? c.release() : 0;
  204008. }
  204009. void* OpenGLComponent::getNativeWindowHandle() const
  204010. {
  204011. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  204012. : 0;
  204013. }
  204014. void juce_glViewport (const int w, const int h)
  204015. {
  204016. glViewport (0, 0, w, h);
  204017. }
  204018. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  204019. OwnedArray <OpenGLPixelFormat>& results)
  204020. {
  204021. /* GLint attribs [64];
  204022. int n = 0;
  204023. attribs[n++] = AGL_RGBA;
  204024. attribs[n++] = AGL_DOUBLEBUFFER;
  204025. attribs[n++] = AGL_ACCELERATED;
  204026. attribs[n++] = AGL_NO_RECOVERY;
  204027. attribs[n++] = AGL_NONE;
  204028. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  204029. while (p != 0)
  204030. {
  204031. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  204032. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  204033. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  204034. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  204035. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  204036. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  204037. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  204038. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  204039. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  204040. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  204041. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  204042. results.add (pf);
  204043. p = aglNextPixelFormat (p);
  204044. }*/
  204045. //jassertfalse //xxx can't see how you do this in cocoa!
  204046. }
  204047. #else
  204048. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204049. const OpenGLPixelFormat& pixelFormat,
  204050. const OpenGLContext* const contextToShareWith)
  204051. {
  204052. return 0;
  204053. }
  204054. void juce_glViewport (const int w, const int h)
  204055. {
  204056. //glViewport (0, 0, w, h);
  204057. }
  204058. #endif
  204059. #endif
  204060. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  204061. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  204062. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204063. // compiled on its own).
  204064. #if JUCE_INCLUDED_FILE
  204065. #if JUCE_MAC
  204066. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  204067. {
  204068. NSImage* im = CoreGraphicsImage::createNSImage (image);
  204069. NSCursor* c = [[NSCursor alloc] initWithImage: im
  204070. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  204071. [im release];
  204072. return (void*) c;
  204073. }
  204074. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  204075. {
  204076. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  204077. jassert (im != 0);
  204078. if (im == 0)
  204079. return 0;
  204080. return juce_createMouseCursorFromImage (*im,
  204081. (int) (hx * im->getWidth()),
  204082. (int) (hy * im->getHeight()));
  204083. }
  204084. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  204085. {
  204086. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  204087. MemoryBlock mb;
  204088. if (f.getChildFile (filename).loadFileAsData (mb))
  204089. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  204090. return 0;
  204091. }
  204092. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  204093. {
  204094. const ScopedAutoReleasePool pool;
  204095. NSCursor* c = 0;
  204096. switch (type)
  204097. {
  204098. case MouseCursor::NormalCursor:
  204099. c = [NSCursor arrowCursor];
  204100. break;
  204101. case MouseCursor::NoCursor:
  204102. {
  204103. Image blank (Image::ARGB, 8, 8, true);
  204104. return juce_createMouseCursorFromImage (blank, 0, 0);
  204105. }
  204106. case MouseCursor::DraggingHandCursor:
  204107. c = [NSCursor openHandCursor];
  204108. break;
  204109. case MouseCursor::CopyingCursor:
  204110. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204111. case MouseCursor::WaitCursor:
  204112. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204113. break;
  204114. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204115. case MouseCursor::IBeamCursor:
  204116. c = [NSCursor IBeamCursor];
  204117. break;
  204118. case MouseCursor::PointingHandCursor:
  204119. c = [NSCursor pointingHandCursor];
  204120. break;
  204121. case MouseCursor::LeftRightResizeCursor:
  204122. c = [NSCursor resizeLeftRightCursor];
  204123. break;
  204124. case MouseCursor::LeftEdgeResizeCursor:
  204125. c = [NSCursor resizeLeftCursor];
  204126. break;
  204127. case MouseCursor::RightEdgeResizeCursor:
  204128. c = [NSCursor resizeRightCursor];
  204129. break;
  204130. case MouseCursor::UpDownResizeCursor:
  204131. case MouseCursor::TopEdgeResizeCursor:
  204132. case MouseCursor::BottomEdgeResizeCursor:
  204133. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204134. case MouseCursor::TopLeftCornerResizeCursor:
  204135. case MouseCursor::BottomRightCornerResizeCursor:
  204136. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204137. case MouseCursor::TopRightCornerResizeCursor:
  204138. case MouseCursor::BottomLeftCornerResizeCursor:
  204139. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204140. case MouseCursor::UpDownLeftRightResizeCursor:
  204141. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204142. case MouseCursor::CrosshairCursor:
  204143. c = [NSCursor crosshairCursor];
  204144. break;
  204145. }
  204146. [c retain];
  204147. return (void*) c;
  204148. }
  204149. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  204150. {
  204151. NSCursor* c = (NSCursor*) cursorHandle;
  204152. [c release];
  204153. }
  204154. void MouseCursor::showInAllWindows() const throw()
  204155. {
  204156. showInWindow (0);
  204157. }
  204158. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  204159. {
  204160. NSCursor* const c = (NSCursor*) getHandle();
  204161. [c set];
  204162. }
  204163. #else
  204164. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  204165. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  204166. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  204167. void MouseCursor::showInAllWindows() const throw() {}
  204168. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  204169. #endif
  204170. #endif
  204171. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  204172. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204173. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204174. // compiled on its own).
  204175. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204176. #if JUCE_MAC
  204177. END_JUCE_NAMESPACE
  204178. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204179. @interface DownloadClickDetector : NSObject
  204180. {
  204181. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204182. }
  204183. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204184. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204185. request: (NSURLRequest*) request
  204186. frame: (WebFrame*) frame
  204187. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204188. @end
  204189. @implementation DownloadClickDetector
  204190. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204191. {
  204192. [super init];
  204193. ownerComponent = ownerComponent_;
  204194. return self;
  204195. }
  204196. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204197. request: (NSURLRequest*) request
  204198. frame: (WebFrame*) frame
  204199. decisionListener: (id <WebPolicyDecisionListener>) listener
  204200. {
  204201. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204202. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204203. [listener use];
  204204. else
  204205. [listener ignore];
  204206. }
  204207. @end
  204208. BEGIN_JUCE_NAMESPACE
  204209. class WebBrowserComponentInternal : public NSViewComponent
  204210. {
  204211. public:
  204212. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204213. {
  204214. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204215. frameName: @""
  204216. groupName: @""];
  204217. setView (webView);
  204218. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204219. [webView setPolicyDelegate: clickListener];
  204220. }
  204221. ~WebBrowserComponentInternal()
  204222. {
  204223. [webView setPolicyDelegate: nil];
  204224. [clickListener release];
  204225. setView (0);
  204226. }
  204227. void goToURL (const String& url,
  204228. const StringArray* headers,
  204229. const MemoryBlock* postData)
  204230. {
  204231. NSMutableURLRequest* r
  204232. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204233. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204234. timeoutInterval: 30.0];
  204235. if (postData != 0 && postData->getSize() > 0)
  204236. {
  204237. [r setHTTPMethod: @"POST"];
  204238. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204239. length: postData->getSize()]];
  204240. }
  204241. if (headers != 0)
  204242. {
  204243. for (int i = 0; i < headers->size(); ++i)
  204244. {
  204245. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  204246. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  204247. [r setValue: juceStringToNS (headerValue)
  204248. forHTTPHeaderField: juceStringToNS (headerName)];
  204249. }
  204250. }
  204251. stop();
  204252. [[webView mainFrame] loadRequest: r];
  204253. }
  204254. void goBack()
  204255. {
  204256. [webView goBack];
  204257. }
  204258. void goForward()
  204259. {
  204260. [webView goForward];
  204261. }
  204262. void stop()
  204263. {
  204264. [webView stopLoading: nil];
  204265. }
  204266. void refresh()
  204267. {
  204268. [webView reload: nil];
  204269. }
  204270. private:
  204271. WebView* webView;
  204272. DownloadClickDetector* clickListener;
  204273. };
  204274. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204275. : browser (0),
  204276. blankPageShown (false),
  204277. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204278. {
  204279. setOpaque (true);
  204280. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204281. }
  204282. WebBrowserComponent::~WebBrowserComponent()
  204283. {
  204284. deleteAndZero (browser);
  204285. }
  204286. void WebBrowserComponent::goToURL (const String& url,
  204287. const StringArray* headers,
  204288. const MemoryBlock* postData)
  204289. {
  204290. lastURL = url;
  204291. lastHeaders.clear();
  204292. if (headers != 0)
  204293. lastHeaders = *headers;
  204294. lastPostData.setSize (0);
  204295. if (postData != 0)
  204296. lastPostData = *postData;
  204297. blankPageShown = false;
  204298. browser->goToURL (url, headers, postData);
  204299. }
  204300. void WebBrowserComponent::stop()
  204301. {
  204302. browser->stop();
  204303. }
  204304. void WebBrowserComponent::goBack()
  204305. {
  204306. lastURL = String::empty;
  204307. blankPageShown = false;
  204308. browser->goBack();
  204309. }
  204310. void WebBrowserComponent::goForward()
  204311. {
  204312. lastURL = String::empty;
  204313. browser->goForward();
  204314. }
  204315. void WebBrowserComponent::refresh()
  204316. {
  204317. browser->refresh();
  204318. }
  204319. void WebBrowserComponent::paint (Graphics& g)
  204320. {
  204321. }
  204322. void WebBrowserComponent::checkWindowAssociation()
  204323. {
  204324. if (isShowing())
  204325. {
  204326. if (blankPageShown)
  204327. goBack();
  204328. }
  204329. else
  204330. {
  204331. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204332. {
  204333. // when the component becomes invisible, some stuff like flash
  204334. // carries on playing audio, so we need to force it onto a blank
  204335. // page to avoid this, (and send it back when it's made visible again).
  204336. blankPageShown = true;
  204337. browser->goToURL ("about:blank", 0, 0);
  204338. }
  204339. }
  204340. }
  204341. void WebBrowserComponent::reloadLastURL()
  204342. {
  204343. if (lastURL.isNotEmpty())
  204344. {
  204345. goToURL (lastURL, &lastHeaders, &lastPostData);
  204346. lastURL = String::empty;
  204347. }
  204348. }
  204349. void WebBrowserComponent::parentHierarchyChanged()
  204350. {
  204351. checkWindowAssociation();
  204352. }
  204353. void WebBrowserComponent::resized()
  204354. {
  204355. browser->setSize (getWidth(), getHeight());
  204356. }
  204357. void WebBrowserComponent::visibilityChanged()
  204358. {
  204359. checkWindowAssociation();
  204360. }
  204361. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204362. {
  204363. return true;
  204364. }
  204365. #else
  204366. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204367. {
  204368. }
  204369. WebBrowserComponent::~WebBrowserComponent()
  204370. {
  204371. }
  204372. void WebBrowserComponent::goToURL (const String& url,
  204373. const StringArray* headers,
  204374. const MemoryBlock* postData)
  204375. {
  204376. }
  204377. void WebBrowserComponent::stop()
  204378. {
  204379. }
  204380. void WebBrowserComponent::goBack()
  204381. {
  204382. }
  204383. void WebBrowserComponent::goForward()
  204384. {
  204385. }
  204386. void WebBrowserComponent::refresh()
  204387. {
  204388. }
  204389. void WebBrowserComponent::paint (Graphics& g)
  204390. {
  204391. }
  204392. void WebBrowserComponent::checkWindowAssociation()
  204393. {
  204394. }
  204395. void WebBrowserComponent::reloadLastURL()
  204396. {
  204397. }
  204398. void WebBrowserComponent::parentHierarchyChanged()
  204399. {
  204400. }
  204401. void WebBrowserComponent::resized()
  204402. {
  204403. }
  204404. void WebBrowserComponent::visibilityChanged()
  204405. {
  204406. }
  204407. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204408. {
  204409. return true;
  204410. }
  204411. #endif
  204412. #endif
  204413. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204414. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  204415. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204416. // compiled on its own).
  204417. #if JUCE_INCLUDED_FILE
  204418. class IPhoneAudioIODevice : public AudioIODevice
  204419. {
  204420. public:
  204421. IPhoneAudioIODevice (const String& deviceName)
  204422. : AudioIODevice (deviceName, T("Audio")),
  204423. audioUnit (0),
  204424. isRunning (false),
  204425. callback (0),
  204426. actualBufferSize (0),
  204427. floatData (1, 2)
  204428. {
  204429. numInputChannels = 2;
  204430. numOutputChannels = 2;
  204431. preferredBufferSize = 0;
  204432. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204433. updateDeviceInfo();
  204434. }
  204435. ~IPhoneAudioIODevice()
  204436. {
  204437. close();
  204438. }
  204439. const StringArray getOutputChannelNames()
  204440. {
  204441. StringArray s;
  204442. s.add ("Left");
  204443. s.add ("Right");
  204444. return s;
  204445. }
  204446. const StringArray getInputChannelNames()
  204447. {
  204448. StringArray s;
  204449. if (audioInputIsAvailable)
  204450. {
  204451. s.add ("Left");
  204452. s.add ("Right");
  204453. }
  204454. return s;
  204455. }
  204456. int getNumSampleRates()
  204457. {
  204458. return 1;
  204459. }
  204460. double getSampleRate (int index)
  204461. {
  204462. return sampleRate;
  204463. }
  204464. int getNumBufferSizesAvailable()
  204465. {
  204466. return 1;
  204467. }
  204468. int getBufferSizeSamples (int index)
  204469. {
  204470. return getDefaultBufferSize();
  204471. }
  204472. int getDefaultBufferSize()
  204473. {
  204474. return 1024;
  204475. }
  204476. const String open (const BitArray& inputChannels,
  204477. const BitArray& outputChannels,
  204478. double sampleRate,
  204479. int bufferSize)
  204480. {
  204481. close();
  204482. lastError = String::empty;
  204483. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204484. // xxx set up channel mapping
  204485. activeOutputChans = outputChannels;
  204486. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204487. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204488. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204489. activeInputChans = inputChannels;
  204490. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204491. numInputChannels = activeInputChans.countNumberOfSetBits();
  204492. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204493. AudioSessionSetActive (true);
  204494. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204495. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204496. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204497. fixAudioRouteIfSetToReceiver();
  204498. updateDeviceInfo();
  204499. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204500. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204501. actualBufferSize = preferredBufferSize;
  204502. prepareFloatBuffers();
  204503. isRunning = true;
  204504. propertyChanged (0, 0, 0); // creates and starts the AU
  204505. lastError = audioUnit != 0 ? String::empty
  204506. : T("Couldn't open the device");
  204507. return lastError;
  204508. }
  204509. void close()
  204510. {
  204511. if (isRunning)
  204512. {
  204513. isRunning = false;
  204514. AudioSessionSetActive (false);
  204515. if (audioUnit != 0)
  204516. {
  204517. AudioComponentInstanceDispose (audioUnit);
  204518. audioUnit = 0;
  204519. }
  204520. }
  204521. }
  204522. bool isOpen()
  204523. {
  204524. return isRunning;
  204525. }
  204526. int getCurrentBufferSizeSamples()
  204527. {
  204528. return actualBufferSize;
  204529. }
  204530. double getCurrentSampleRate()
  204531. {
  204532. return sampleRate;
  204533. }
  204534. int getCurrentBitDepth()
  204535. {
  204536. return 16;
  204537. }
  204538. const BitArray getActiveOutputChannels() const
  204539. {
  204540. return activeOutputChans;
  204541. }
  204542. const BitArray getActiveInputChannels() const
  204543. {
  204544. return activeInputChans;
  204545. }
  204546. int getOutputLatencyInSamples()
  204547. {
  204548. return 0; //xxx
  204549. }
  204550. int getInputLatencyInSamples()
  204551. {
  204552. return 0; //xxx
  204553. }
  204554. void start (AudioIODeviceCallback* callback_)
  204555. {
  204556. if (isRunning && callback != callback_)
  204557. {
  204558. if (callback_ != 0)
  204559. callback_->audioDeviceAboutToStart (this);
  204560. const ScopedLock sl (callbackLock);
  204561. callback = callback_;
  204562. }
  204563. }
  204564. void stop()
  204565. {
  204566. if (isRunning)
  204567. {
  204568. AudioIODeviceCallback* lastCallback;
  204569. {
  204570. const ScopedLock sl (callbackLock);
  204571. lastCallback = callback;
  204572. callback = 0;
  204573. }
  204574. if (lastCallback != 0)
  204575. lastCallback->audioDeviceStopped();
  204576. }
  204577. }
  204578. bool isPlaying()
  204579. {
  204580. return isRunning && callback != 0;
  204581. }
  204582. const String getLastError()
  204583. {
  204584. return lastError;
  204585. }
  204586. private:
  204587. CriticalSection callbackLock;
  204588. Float64 sampleRate;
  204589. int numInputChannels, numOutputChannels;
  204590. int preferredBufferSize;
  204591. int actualBufferSize;
  204592. bool isRunning;
  204593. String lastError;
  204594. AudioStreamBasicDescription format;
  204595. AudioUnit audioUnit;
  204596. UInt32 audioInputIsAvailable;
  204597. AudioIODeviceCallback* callback;
  204598. BitArray activeOutputChans, activeInputChans;
  204599. AudioSampleBuffer floatData;
  204600. float* inputChannels[3];
  204601. float* outputChannels[3];
  204602. bool monoInputChannelNumber, monoOutputChannelNumber;
  204603. void prepareFloatBuffers()
  204604. {
  204605. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204606. zerostruct (inputChannels);
  204607. zerostruct (outputChannels);
  204608. for (int i = 0; i < numInputChannels; ++i)
  204609. inputChannels[i] = floatData.getSampleData (i);
  204610. for (int i = 0; i < numOutputChannels; ++i)
  204611. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204612. }
  204613. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204614. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204615. {
  204616. OSStatus err = noErr;
  204617. if (audioInputIsAvailable)
  204618. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204619. const ScopedLock sl (callbackLock);
  204620. if (callback != 0)
  204621. {
  204622. if (audioInputIsAvailable && numInputChannels > 0)
  204623. {
  204624. short* shortData = (short*) ioData->mBuffers[0].mData;
  204625. if (numInputChannels >= 2)
  204626. {
  204627. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204628. {
  204629. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204630. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204631. }
  204632. }
  204633. else
  204634. {
  204635. if (monoInputChannelNumber > 0)
  204636. ++shortData;
  204637. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204638. {
  204639. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204640. ++shortData;
  204641. }
  204642. }
  204643. }
  204644. else
  204645. {
  204646. for (int i = numInputChannels; --i >= 0;)
  204647. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204648. }
  204649. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204650. outputChannels, numOutputChannels,
  204651. (int) inNumberFrames);
  204652. short* shortData = (short*) ioData->mBuffers[0].mData;
  204653. int n = 0;
  204654. if (numOutputChannels >= 2)
  204655. {
  204656. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204657. {
  204658. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204659. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204660. }
  204661. }
  204662. else if (numOutputChannels == 1)
  204663. {
  204664. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204665. {
  204666. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204667. shortData [n++] = s;
  204668. shortData [n++] = s;
  204669. }
  204670. }
  204671. else
  204672. {
  204673. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204674. }
  204675. }
  204676. else
  204677. {
  204678. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204679. }
  204680. return err;
  204681. }
  204682. void updateDeviceInfo()
  204683. {
  204684. UInt32 size = sizeof (sampleRate);
  204685. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204686. size = sizeof (audioInputIsAvailable);
  204687. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204688. }
  204689. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204690. {
  204691. if (! isRunning)
  204692. return;
  204693. if (inPropertyValue != 0)
  204694. {
  204695. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204696. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204697. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204698. SInt32 routeChangeReason;
  204699. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204700. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204701. fixAudioRouteIfSetToReceiver();
  204702. }
  204703. updateDeviceInfo();
  204704. createAudioUnit();
  204705. AudioSessionSetActive (true);
  204706. if (audioUnit != 0)
  204707. {
  204708. UInt32 formatSize = sizeof (format);
  204709. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204710. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204711. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204712. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204713. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204714. AudioOutputUnitStart (audioUnit);
  204715. }
  204716. }
  204717. void interruptionListener (UInt32 inInterruption)
  204718. {
  204719. if (inInterruption == kAudioSessionEndInterruption)
  204720. {
  204721. isRunning = true;
  204722. AudioSessionSetActive (true);
  204723. AudioOutputUnitStart (audioUnit);
  204724. }
  204725. }
  204726. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204727. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204728. {
  204729. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204730. }
  204731. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204732. {
  204733. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204734. }
  204735. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204736. {
  204737. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204738. }
  204739. void resetFormat (const int numChannels)
  204740. {
  204741. memset (&format, 0, sizeof (format));
  204742. format.mFormatID = kAudioFormatLinearPCM;
  204743. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204744. format.mBitsPerChannel = 8 * sizeof (short);
  204745. format.mChannelsPerFrame = 2;
  204746. format.mFramesPerPacket = 1;
  204747. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204748. }
  204749. bool createAudioUnit()
  204750. {
  204751. if (audioUnit != 0)
  204752. {
  204753. AudioComponentInstanceDispose (audioUnit);
  204754. audioUnit = 0;
  204755. }
  204756. resetFormat (2);
  204757. AudioComponentDescription desc;
  204758. desc.componentType = kAudioUnitType_Output;
  204759. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204760. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204761. desc.componentFlags = 0;
  204762. desc.componentFlagsMask = 0;
  204763. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204764. AudioComponentInstanceNew (comp, &audioUnit);
  204765. if (audioUnit == 0)
  204766. return false;
  204767. const UInt32 one = 1;
  204768. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204769. AudioChannelLayout layout;
  204770. layout.mChannelBitmap = 0;
  204771. layout.mNumberChannelDescriptions = 0;
  204772. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204773. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204774. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204775. AURenderCallbackStruct inputProc;
  204776. inputProc.inputProc = processStatic;
  204777. inputProc.inputProcRefCon = this;
  204778. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204779. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204780. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204781. AudioUnitInitialize (audioUnit);
  204782. return true;
  204783. }
  204784. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204785. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204786. static void fixAudioRouteIfSetToReceiver()
  204787. {
  204788. CFStringRef audioRoute = 0;
  204789. UInt32 propertySize = sizeof (audioRoute);
  204790. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204791. {
  204792. NSString* route = (NSString*) audioRoute;
  204793. //DBG ("audio route: " + nsStringToJuce (route));
  204794. if ([route hasPrefix: @"Receiver"])
  204795. {
  204796. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204797. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204798. }
  204799. CFRelease (audioRoute);
  204800. }
  204801. }
  204802. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204803. IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204804. };
  204805. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204806. {
  204807. public:
  204808. IPhoneAudioIODeviceType()
  204809. : AudioIODeviceType (T("iPhone Audio"))
  204810. {
  204811. }
  204812. ~IPhoneAudioIODeviceType()
  204813. {
  204814. }
  204815. void scanForDevices()
  204816. {
  204817. }
  204818. const StringArray getDeviceNames (const bool wantInputNames) const
  204819. {
  204820. StringArray s;
  204821. s.add ("iPhone Audio");
  204822. return s;
  204823. }
  204824. int getDefaultDeviceIndex (const bool forInput) const
  204825. {
  204826. return 0;
  204827. }
  204828. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  204829. {
  204830. return device != 0 ? 0 : -1;
  204831. }
  204832. bool hasSeparateInputsAndOutputs() const { return false; }
  204833. AudioIODevice* createDevice (const String& outputDeviceName,
  204834. const String& inputDeviceName)
  204835. {
  204836. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  204837. {
  204838. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  204839. : inputDeviceName);
  204840. }
  204841. return 0;
  204842. }
  204843. juce_UseDebuggingNewOperator
  204844. private:
  204845. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  204846. IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  204847. };
  204848. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  204849. {
  204850. return new IPhoneAudioIODeviceType();
  204851. }
  204852. #endif
  204853. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  204854. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  204855. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204856. // compiled on its own).
  204857. #if JUCE_INCLUDED_FILE
  204858. #if JUCE_MAC
  204859. #undef log
  204860. #define log(a) Logger::writeToLog(a)
  204861. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  204862. {
  204863. if (err == noErr)
  204864. return true;
  204865. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  204866. jassertfalse
  204867. return false;
  204868. }
  204869. #undef OK
  204870. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  204871. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  204872. {
  204873. String result;
  204874. CFStringRef str = 0;
  204875. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  204876. if (str != 0)
  204877. {
  204878. result = PlatformUtilities::cfStringToJuceString (str);
  204879. CFRelease (str);
  204880. str = 0;
  204881. }
  204882. MIDIEntityRef entity = 0;
  204883. MIDIEndpointGetEntity (endpoint, &entity);
  204884. if (entity == 0)
  204885. return result; // probably virtual
  204886. if (result.isEmpty())
  204887. {
  204888. // endpoint name has zero length - try the entity
  204889. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  204890. if (str != 0)
  204891. {
  204892. result += PlatformUtilities::cfStringToJuceString (str);
  204893. CFRelease (str);
  204894. str = 0;
  204895. }
  204896. }
  204897. // now consider the device's name
  204898. MIDIDeviceRef device = 0;
  204899. MIDIEntityGetDevice (entity, &device);
  204900. if (device == 0)
  204901. return result;
  204902. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  204903. if (str != 0)
  204904. {
  204905. const String s (PlatformUtilities::cfStringToJuceString (str));
  204906. CFRelease (str);
  204907. // if an external device has only one entity, throw away
  204908. // the endpoint name and just use the device name
  204909. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  204910. {
  204911. result = s;
  204912. }
  204913. else if (! result.startsWithIgnoreCase (s))
  204914. {
  204915. // prepend the device name to the entity name
  204916. result = (s + T(" ") + result).trimEnd();
  204917. }
  204918. }
  204919. return result;
  204920. }
  204921. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  204922. {
  204923. String result;
  204924. // Does the endpoint have connections?
  204925. CFDataRef connections = 0;
  204926. int numConnections = 0;
  204927. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  204928. if (connections != 0)
  204929. {
  204930. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  204931. if (numConnections > 0)
  204932. {
  204933. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  204934. for (int i = 0; i < numConnections; ++i, ++pid)
  204935. {
  204936. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  204937. MIDIObjectRef connObject;
  204938. MIDIObjectType connObjectType;
  204939. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  204940. if (err == noErr)
  204941. {
  204942. String s;
  204943. if (connObjectType == kMIDIObjectType_ExternalSource
  204944. || connObjectType == kMIDIObjectType_ExternalDestination)
  204945. {
  204946. // Connected to an external device's endpoint (10.3 and later).
  204947. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  204948. }
  204949. else
  204950. {
  204951. // Connected to an external device (10.2) (or something else, catch-all)
  204952. CFStringRef str = 0;
  204953. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  204954. if (str != 0)
  204955. {
  204956. s = PlatformUtilities::cfStringToJuceString (str);
  204957. CFRelease (str);
  204958. }
  204959. }
  204960. if (s.isNotEmpty())
  204961. {
  204962. if (result.isNotEmpty())
  204963. result += (", ");
  204964. result += s;
  204965. }
  204966. }
  204967. }
  204968. }
  204969. CFRelease (connections);
  204970. }
  204971. if (result.isNotEmpty())
  204972. return result;
  204973. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  204974. return getEndpointName (endpoint, false);
  204975. }
  204976. const StringArray MidiOutput::getDevices()
  204977. {
  204978. StringArray s;
  204979. const ItemCount num = MIDIGetNumberOfDestinations();
  204980. for (ItemCount i = 0; i < num; ++i)
  204981. {
  204982. MIDIEndpointRef dest = MIDIGetDestination (i);
  204983. if (dest != 0)
  204984. {
  204985. String name (getConnectedEndpointName (dest));
  204986. if (name.isEmpty())
  204987. name = "<error>";
  204988. s.add (name);
  204989. }
  204990. else
  204991. {
  204992. s.add ("<error>");
  204993. }
  204994. }
  204995. return s;
  204996. }
  204997. int MidiOutput::getDefaultDeviceIndex()
  204998. {
  204999. return 0;
  205000. }
  205001. static MIDIClientRef globalMidiClient;
  205002. static bool hasGlobalClientBeenCreated = false;
  205003. static bool makeSureClientExists()
  205004. {
  205005. if (! hasGlobalClientBeenCreated)
  205006. {
  205007. String name (T("JUCE"));
  205008. if (JUCEApplication::getInstance() != 0)
  205009. name = JUCEApplication::getInstance()->getApplicationName();
  205010. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  205011. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  205012. CFRelease (appName);
  205013. }
  205014. return hasGlobalClientBeenCreated;
  205015. }
  205016. class MidiPortAndEndpoint
  205017. {
  205018. public:
  205019. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  205020. : port (port_), endPoint (endPoint_)
  205021. {
  205022. }
  205023. ~MidiPortAndEndpoint()
  205024. {
  205025. if (port != 0)
  205026. MIDIPortDispose (port);
  205027. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  205028. MIDIEndpointDispose (endPoint);
  205029. }
  205030. MIDIPortRef port;
  205031. MIDIEndpointRef endPoint;
  205032. };
  205033. MidiOutput* MidiOutput::openDevice (int index)
  205034. {
  205035. MidiOutput* mo = 0;
  205036. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  205037. {
  205038. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  205039. CFStringRef pname;
  205040. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205041. {
  205042. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  205043. if (makeSureClientExists())
  205044. {
  205045. MIDIPortRef port;
  205046. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  205047. {
  205048. mo = new MidiOutput();
  205049. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  205050. }
  205051. }
  205052. CFRelease (pname);
  205053. }
  205054. }
  205055. return mo;
  205056. }
  205057. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  205058. {
  205059. MidiOutput* mo = 0;
  205060. if (makeSureClientExists())
  205061. {
  205062. MIDIEndpointRef endPoint;
  205063. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  205064. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  205065. {
  205066. mo = new MidiOutput();
  205067. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  205068. }
  205069. CFRelease (name);
  205070. }
  205071. return mo;
  205072. }
  205073. MidiOutput::~MidiOutput()
  205074. {
  205075. delete (MidiPortAndEndpoint*) internal;
  205076. }
  205077. void MidiOutput::reset()
  205078. {
  205079. }
  205080. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205081. {
  205082. return false;
  205083. }
  205084. void MidiOutput::setVolume (float leftVol, float rightVol)
  205085. {
  205086. }
  205087. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205088. {
  205089. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  205090. if (message.isSysEx())
  205091. {
  205092. const int maxPacketSize = 256;
  205093. int pos = 0, bytesLeft = message.getRawDataSize();
  205094. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  205095. HeapBlock <MIDIPacketList> packets;
  205096. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  205097. packets->numPackets = numPackets;
  205098. MIDIPacket* p = packets->packet;
  205099. for (int i = 0; i < numPackets; ++i)
  205100. {
  205101. p->timeStamp = 0;
  205102. p->length = jmin (maxPacketSize, bytesLeft);
  205103. memcpy (p->data, message.getRawData() + pos, p->length);
  205104. pos += p->length;
  205105. bytesLeft -= p->length;
  205106. p = MIDIPacketNext (p);
  205107. }
  205108. if (mpe->port != 0)
  205109. MIDISend (mpe->port, mpe->endPoint, packets);
  205110. else
  205111. MIDIReceived (mpe->endPoint, packets);
  205112. }
  205113. else
  205114. {
  205115. MIDIPacketList packets;
  205116. packets.numPackets = 1;
  205117. packets.packet[0].timeStamp = 0;
  205118. packets.packet[0].length = message.getRawDataSize();
  205119. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205120. if (mpe->port != 0)
  205121. MIDISend (mpe->port, mpe->endPoint, &packets);
  205122. else
  205123. MIDIReceived (mpe->endPoint, &packets);
  205124. }
  205125. }
  205126. const StringArray MidiInput::getDevices()
  205127. {
  205128. StringArray s;
  205129. const ItemCount num = MIDIGetNumberOfSources();
  205130. for (ItemCount i = 0; i < num; ++i)
  205131. {
  205132. MIDIEndpointRef source = MIDIGetSource (i);
  205133. if (source != 0)
  205134. {
  205135. String name (getConnectedEndpointName (source));
  205136. if (name.isEmpty())
  205137. name = "<error>";
  205138. s.add (name);
  205139. }
  205140. else
  205141. {
  205142. s.add ("<error>");
  205143. }
  205144. }
  205145. return s;
  205146. }
  205147. int MidiInput::getDefaultDeviceIndex()
  205148. {
  205149. return 0;
  205150. }
  205151. struct MidiPortAndCallback
  205152. {
  205153. MidiInput* input;
  205154. MidiPortAndEndpoint* portAndEndpoint;
  205155. MidiInputCallback* callback;
  205156. MemoryBlock pendingData;
  205157. int pendingBytes;
  205158. double pendingDataTime;
  205159. bool active;
  205160. void processSysex (const uint8*& d, int& size, const double time)
  205161. {
  205162. if (*d == 0xf0)
  205163. {
  205164. pendingBytes = 0;
  205165. pendingDataTime = time;
  205166. }
  205167. pendingData.ensureSize (pendingBytes + size, false);
  205168. uint8* totalMessage = (uint8*) pendingData.getData();
  205169. uint8* dest = totalMessage + pendingBytes;
  205170. while (size > 0)
  205171. {
  205172. if (pendingBytes > 0 && *d >= 0x80)
  205173. {
  205174. if (*d >= 0xfa || *d == 0xf8)
  205175. {
  205176. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  205177. ++d;
  205178. --size;
  205179. }
  205180. else
  205181. {
  205182. if (*d == 0xf7)
  205183. {
  205184. *dest++ = *d++;
  205185. pendingBytes++;
  205186. --size;
  205187. }
  205188. break;
  205189. }
  205190. }
  205191. else
  205192. {
  205193. *dest++ = *d++;
  205194. pendingBytes++;
  205195. --size;
  205196. }
  205197. }
  205198. if (totalMessage [pendingBytes - 1] == 0xf7)
  205199. {
  205200. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  205201. pendingBytes = 0;
  205202. }
  205203. else
  205204. {
  205205. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  205206. }
  205207. }
  205208. };
  205209. namespace CoreMidiCallbacks
  205210. {
  205211. static CriticalSection callbackLock;
  205212. static VoidArray activeCallbacks;
  205213. }
  205214. static void midiInputProc (const MIDIPacketList* pktlist,
  205215. void* readProcRefCon,
  205216. void* srcConnRefCon)
  205217. {
  205218. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205219. const double originalTime = time;
  205220. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205221. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205222. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  205223. {
  205224. const MIDIPacket* packet = &pktlist->packet[0];
  205225. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205226. {
  205227. const uint8* d = (const uint8*) (packet->data);
  205228. int size = packet->length;
  205229. while (size > 0)
  205230. {
  205231. time = originalTime;
  205232. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205233. {
  205234. mpc->processSysex (d, size, time);
  205235. }
  205236. else
  205237. {
  205238. int used = 0;
  205239. const MidiMessage m (d, size, used, 0, time);
  205240. if (used <= 0)
  205241. {
  205242. jassertfalse // malformed midi message
  205243. break;
  205244. }
  205245. else
  205246. {
  205247. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205248. }
  205249. size -= used;
  205250. d += used;
  205251. }
  205252. }
  205253. packet = MIDIPacketNext (packet);
  205254. }
  205255. }
  205256. }
  205257. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205258. {
  205259. MidiInput* mi = 0;
  205260. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205261. {
  205262. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205263. if (endPoint != 0)
  205264. {
  205265. CFStringRef pname;
  205266. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205267. {
  205268. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  205269. if (makeSureClientExists())
  205270. {
  205271. MIDIPortRef port;
  205272. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205273. mpc->active = false;
  205274. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205275. {
  205276. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205277. {
  205278. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205279. mpc->callback = callback;
  205280. mpc->pendingBytes = 0;
  205281. mpc->pendingData.ensureSize (128);
  205282. mi = new MidiInput (getDevices() [index]);
  205283. mpc->input = mi;
  205284. mi->internal = (void*) mpc;
  205285. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205286. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205287. }
  205288. else
  205289. {
  205290. OK (MIDIPortDispose (port));
  205291. }
  205292. }
  205293. }
  205294. }
  205295. CFRelease (pname);
  205296. }
  205297. }
  205298. return mi;
  205299. }
  205300. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205301. {
  205302. MidiInput* mi = 0;
  205303. if (makeSureClientExists())
  205304. {
  205305. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205306. mpc->active = false;
  205307. MIDIEndpointRef endPoint;
  205308. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205309. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205310. {
  205311. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205312. mpc->callback = callback;
  205313. mpc->pendingBytes = 0;
  205314. mpc->pendingData.ensureSize (128);
  205315. mi = new MidiInput (deviceName);
  205316. mpc->input = mi;
  205317. mi->internal = (void*) mpc;
  205318. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205319. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205320. }
  205321. CFRelease (name);
  205322. }
  205323. return mi;
  205324. }
  205325. MidiInput::MidiInput (const String& name_)
  205326. : name (name_)
  205327. {
  205328. }
  205329. MidiInput::~MidiInput()
  205330. {
  205331. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205332. mpc->active = false;
  205333. {
  205334. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205335. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  205336. }
  205337. if (mpc->portAndEndpoint->port != 0)
  205338. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205339. delete mpc->portAndEndpoint;
  205340. delete mpc;
  205341. }
  205342. void MidiInput::start()
  205343. {
  205344. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205345. ((MidiPortAndCallback*) internal)->active = true;
  205346. }
  205347. void MidiInput::stop()
  205348. {
  205349. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205350. ((MidiPortAndCallback*) internal)->active = false;
  205351. }
  205352. #undef log
  205353. #else
  205354. MidiOutput::~MidiOutput()
  205355. {
  205356. }
  205357. void MidiOutput::reset()
  205358. {
  205359. }
  205360. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205361. {
  205362. return false;
  205363. }
  205364. void MidiOutput::setVolume (float leftVol, float rightVol)
  205365. {
  205366. }
  205367. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205368. {
  205369. }
  205370. const StringArray MidiOutput::getDevices()
  205371. {
  205372. return StringArray();
  205373. }
  205374. MidiOutput* MidiOutput::openDevice (int index)
  205375. {
  205376. return 0;
  205377. }
  205378. const StringArray MidiInput::getDevices()
  205379. {
  205380. return StringArray();
  205381. }
  205382. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205383. {
  205384. return 0;
  205385. }
  205386. #endif
  205387. #endif
  205388. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  205389. #else
  205390. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  205391. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205392. // compiled on its own).
  205393. #if JUCE_INCLUDED_FILE
  205394. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205395. #define SUPPORT_10_4_FONTS 1
  205396. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205397. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205398. #define SUPPORT_ONLY_10_4_FONTS 1
  205399. #endif
  205400. END_JUCE_NAMESPACE
  205401. @interface NSFont (PrivateHack)
  205402. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205403. @end
  205404. BEGIN_JUCE_NAMESPACE
  205405. #endif
  205406. class MacTypeface : public Typeface
  205407. {
  205408. public:
  205409. MacTypeface (const Font& font)
  205410. : Typeface (font.getTypefaceName())
  205411. {
  205412. const ScopedAutoReleasePool pool;
  205413. renderingTransform = CGAffineTransformIdentity;
  205414. bool needsItalicTransform = false;
  205415. #if JUCE_IPHONE
  205416. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205417. if (font.isItalic() || font.isBold())
  205418. {
  205419. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205420. for (NSString* i in familyFonts)
  205421. {
  205422. const String fn (nsStringToJuce (i));
  205423. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  205424. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  205425. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  205426. || afterDash.containsIgnoreCase (T("italic"))
  205427. || fn.endsWithIgnoreCase (T("oblique"))
  205428. || fn.endsWithIgnoreCase (T("italic"));
  205429. if (probablyBold == font.isBold()
  205430. && probablyItalic == font.isItalic())
  205431. {
  205432. fontName = i;
  205433. needsItalicTransform = false;
  205434. break;
  205435. }
  205436. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205437. {
  205438. fontName = i;
  205439. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205440. }
  205441. }
  205442. if (needsItalicTransform)
  205443. renderingTransform.c = 0.15f;
  205444. }
  205445. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205446. const int ascender = abs (CGFontGetAscent (fontRef));
  205447. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205448. ascent = ascender / totalHeight;
  205449. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205450. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205451. #else
  205452. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205453. if (font.isItalic())
  205454. {
  205455. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205456. toHaveTrait: NSItalicFontMask];
  205457. if (newFont == nsFont)
  205458. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205459. nsFont = newFont;
  205460. }
  205461. if (font.isBold())
  205462. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205463. [nsFont retain];
  205464. ascent = fabsf ((float) [nsFont ascender]);
  205465. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205466. ascent /= totalSize;
  205467. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205468. if (needsItalicTransform)
  205469. {
  205470. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205471. renderingTransform.c = 0.15f;
  205472. }
  205473. #if SUPPORT_ONLY_10_4_FONTS
  205474. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205475. if (atsFont == 0)
  205476. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205477. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205478. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205479. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205480. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205481. #else
  205482. #if SUPPORT_10_4_FONTS
  205483. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205484. {
  205485. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205486. if (atsFont == 0)
  205487. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205488. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205489. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205490. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205491. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205492. }
  205493. else
  205494. #endif
  205495. {
  205496. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205497. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205498. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205499. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205500. }
  205501. #endif
  205502. #endif
  205503. }
  205504. ~MacTypeface()
  205505. {
  205506. #if ! JUCE_IPHONE
  205507. [nsFont release];
  205508. #endif
  205509. if (fontRef != 0)
  205510. CGFontRelease (fontRef);
  205511. }
  205512. float getAscent() const
  205513. {
  205514. return ascent;
  205515. }
  205516. float getDescent() const
  205517. {
  205518. return 1.0f - ascent;
  205519. }
  205520. float getStringWidth (const String& text)
  205521. {
  205522. if (fontRef == 0 || text.isEmpty())
  205523. return 0;
  205524. const int length = text.length();
  205525. HeapBlock <CGGlyph> glyphs;
  205526. createGlyphsForString (text, length, glyphs);
  205527. float x = 0;
  205528. #if SUPPORT_ONLY_10_4_FONTS
  205529. HeapBlock <NSSize> advances (length);
  205530. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205531. for (int i = 0; i < length; ++i)
  205532. x += advances[i].width;
  205533. #else
  205534. #if SUPPORT_10_4_FONTS
  205535. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205536. {
  205537. HeapBlock <NSSize> advances (length);
  205538. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  205539. for (int i = 0; i < length; ++i)
  205540. x += advances[i].width;
  205541. }
  205542. else
  205543. #endif
  205544. {
  205545. HeapBlock <int> advances (length);
  205546. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205547. for (int i = 0; i < length; ++i)
  205548. x += advances[i];
  205549. }
  205550. #endif
  205551. return x * unitsToHeightScaleFactor;
  205552. }
  205553. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205554. {
  205555. xOffsets.add (0);
  205556. if (fontRef == 0 || text.isEmpty())
  205557. return;
  205558. const int length = text.length();
  205559. HeapBlock <CGGlyph> glyphs;
  205560. createGlyphsForString (text, length, glyphs);
  205561. #if SUPPORT_ONLY_10_4_FONTS
  205562. HeapBlock <NSSize> advances (length);
  205563. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205564. int x = 0;
  205565. for (int i = 0; i < length; ++i)
  205566. {
  205567. x += advances[i].width;
  205568. xOffsets.add (x * unitsToHeightScaleFactor);
  205569. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205570. }
  205571. #else
  205572. #if SUPPORT_10_4_FONTS
  205573. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205574. {
  205575. HeapBlock <NSSize> advances (length);
  205576. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205577. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  205578. float x = 0;
  205579. for (int i = 0; i < length; ++i)
  205580. {
  205581. x += advances[i].width;
  205582. xOffsets.add (x * unitsToHeightScaleFactor);
  205583. resultGlyphs.add (nsGlyphs[i]);
  205584. }
  205585. }
  205586. else
  205587. #endif
  205588. {
  205589. HeapBlock <int> advances (length);
  205590. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205591. {
  205592. int x = 0;
  205593. for (int i = 0; i < length; ++i)
  205594. {
  205595. x += advances [i];
  205596. xOffsets.add (x * unitsToHeightScaleFactor);
  205597. resultGlyphs.add (glyphs[i]);
  205598. }
  205599. }
  205600. }
  205601. #endif
  205602. }
  205603. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205604. {
  205605. #if JUCE_IPHONE
  205606. return false;
  205607. #else
  205608. if (nsFont == 0)
  205609. return false;
  205610. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205611. jassert (path.isEmpty());
  205612. const ScopedAutoReleasePool pool;
  205613. NSBezierPath* bez = [NSBezierPath bezierPath];
  205614. [bez moveToPoint: NSMakePoint (0, 0)];
  205615. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205616. inFont: nsFont];
  205617. for (int i = 0; i < [bez elementCount]; ++i)
  205618. {
  205619. NSPoint p[3];
  205620. switch ([bez elementAtIndex: i associatedPoints: p])
  205621. {
  205622. case NSMoveToBezierPathElement:
  205623. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205624. break;
  205625. case NSLineToBezierPathElement:
  205626. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205627. break;
  205628. case NSCurveToBezierPathElement:
  205629. 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);
  205630. break;
  205631. case NSClosePathBezierPathElement:
  205632. path.closeSubPath();
  205633. break;
  205634. default:
  205635. jassertfalse
  205636. break;
  205637. }
  205638. }
  205639. path.applyTransform (pathTransform);
  205640. return true;
  205641. #endif
  205642. }
  205643. juce_UseDebuggingNewOperator
  205644. CGFontRef fontRef;
  205645. float fontHeightToCGSizeFactor;
  205646. CGAffineTransform renderingTransform;
  205647. private:
  205648. float ascent, unitsToHeightScaleFactor;
  205649. #if JUCE_IPHONE
  205650. #else
  205651. NSFont* nsFont;
  205652. AffineTransform pathTransform;
  205653. #endif
  205654. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205655. {
  205656. #if SUPPORT_10_4_FONTS
  205657. #if ! SUPPORT_ONLY_10_4_FONTS
  205658. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205659. #endif
  205660. {
  205661. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205662. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205663. for (int i = 0; i < length; ++i)
  205664. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205665. return;
  205666. }
  205667. #endif
  205668. #if ! SUPPORT_ONLY_10_4_FONTS
  205669. if (charToGlyphMapper == 0)
  205670. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205671. glyphs.malloc (length);
  205672. for (int i = 0; i < length; ++i)
  205673. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205674. #endif
  205675. }
  205676. #if ! SUPPORT_ONLY_10_4_FONTS
  205677. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205678. class CharToGlyphMapper
  205679. {
  205680. public:
  205681. CharToGlyphMapper (CGFontRef fontRef)
  205682. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205683. idRangeOffset (0), glyphIndexes (0)
  205684. {
  205685. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205686. if (cmapTable != 0)
  205687. {
  205688. const int numSubtables = getValue16 (cmapTable, 2);
  205689. for (int i = 0; i < numSubtables; ++i)
  205690. {
  205691. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205692. {
  205693. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205694. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205695. {
  205696. const int length = getValue16 (cmapTable, offset + 2);
  205697. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205698. segCount = segCountX2 / 2;
  205699. const int endCodeOffset = offset + 14;
  205700. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205701. const int idDeltaOffset = startCodeOffset + segCountX2;
  205702. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205703. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205704. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205705. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205706. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205707. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205708. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205709. }
  205710. break;
  205711. }
  205712. }
  205713. CFRelease (cmapTable);
  205714. }
  205715. }
  205716. ~CharToGlyphMapper()
  205717. {
  205718. if (endCode != 0)
  205719. {
  205720. CFRelease (endCode);
  205721. CFRelease (startCode);
  205722. CFRelease (idDelta);
  205723. CFRelease (idRangeOffset);
  205724. CFRelease (glyphIndexes);
  205725. }
  205726. }
  205727. int getGlyphForCharacter (const juce_wchar c) const
  205728. {
  205729. for (int i = 0; i < segCount; ++i)
  205730. {
  205731. if (getValue16 (endCode, i * 2) >= c)
  205732. {
  205733. const int start = getValue16 (startCode, i * 2);
  205734. if (start > c)
  205735. break;
  205736. const int delta = getValue16 (idDelta, i * 2);
  205737. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205738. if (rangeOffset == 0)
  205739. return delta + c;
  205740. else
  205741. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205742. }
  205743. }
  205744. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205745. return jmax (-1, c - 29);
  205746. }
  205747. private:
  205748. int segCount;
  205749. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205750. static uint16 getValue16 (CFDataRef data, const int index)
  205751. {
  205752. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205753. }
  205754. static uint32 getValue32 (CFDataRef data, const int index)
  205755. {
  205756. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205757. }
  205758. };
  205759. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205760. #endif
  205761. };
  205762. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205763. {
  205764. return new MacTypeface (font);
  205765. }
  205766. const StringArray Font::findAllTypefaceNames() throw()
  205767. {
  205768. StringArray names;
  205769. const ScopedAutoReleasePool pool;
  205770. #if JUCE_IPHONE
  205771. NSArray* fonts = [UIFont familyNames];
  205772. #else
  205773. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205774. #endif
  205775. for (unsigned int i = 0; i < [fonts count]; ++i)
  205776. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205777. names.sort (true);
  205778. return names;
  205779. }
  205780. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  205781. {
  205782. #if JUCE_IPHONE
  205783. defaultSans = "Helvetica";
  205784. defaultSerif = "Times New Roman";
  205785. defaultFixed = "Courier New";
  205786. #else
  205787. defaultSans = "Lucida Grande";
  205788. defaultSerif = "Times New Roman";
  205789. defaultFixed = "Monaco";
  205790. #endif
  205791. }
  205792. #endif
  205793. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205794. // (must go before juce_mac_CoreGraphicsContext.mm)
  205795. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205796. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205797. // compiled on its own).
  205798. #if JUCE_INCLUDED_FILE
  205799. class CoreGraphicsImage : public Image
  205800. {
  205801. public:
  205802. CoreGraphicsImage (const PixelFormat format_,
  205803. const int imageWidth_,
  205804. const int imageHeight_,
  205805. const bool clearImage)
  205806. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205807. {
  205808. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  205809. : CGColorSpaceCreateDeviceRGB();
  205810. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205811. colourSpace, getCGImageFlags (*this));
  205812. CGColorSpaceRelease (colourSpace);
  205813. }
  205814. ~CoreGraphicsImage()
  205815. {
  205816. CGContextRelease (context);
  205817. }
  205818. LowLevelGraphicsContext* createLowLevelContext();
  205819. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  205820. {
  205821. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  205822. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  205823. {
  205824. return CGBitmapContextCreateImage (nativeImage->context);
  205825. }
  205826. else
  205827. {
  205828. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  205829. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  205830. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  205831. 8, srcData.pixelStride * 8, srcData.lineStride,
  205832. colourSpace, getCGImageFlags (juceImage), provider,
  205833. 0, true, kCGRenderingIntentDefault);
  205834. CGDataProviderRelease (provider);
  205835. return imageRef;
  205836. }
  205837. }
  205838. #if JUCE_MAC
  205839. static NSImage* createNSImage (const Image& image)
  205840. {
  205841. const ScopedAutoReleasePool pool;
  205842. NSImage* im = [[NSImage alloc] init];
  205843. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  205844. [im lockFocus];
  205845. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  205846. CGImageRef imageRef = createImage (image, false, colourSpace);
  205847. CGColorSpaceRelease (colourSpace);
  205848. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  205849. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  205850. CGImageRelease (imageRef);
  205851. [im unlockFocus];
  205852. return im;
  205853. }
  205854. #endif
  205855. CGContextRef context;
  205856. private:
  205857. static CGBitmapInfo getCGImageFlags (const Image& image)
  205858. {
  205859. #if JUCE_BIG_ENDIAN
  205860. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  205861. #else
  205862. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  205863. #endif
  205864. }
  205865. };
  205866. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  205867. {
  205868. #if USE_COREGRAPHICS_RENDERING
  205869. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  205870. #else
  205871. return new Image (format, imageWidth, imageHeight, clearImage);
  205872. #endif
  205873. }
  205874. class CoreGraphicsContext : public LowLevelGraphicsContext
  205875. {
  205876. public:
  205877. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  205878. : context (context_),
  205879. flipHeight (flipHeight_),
  205880. numGradientLookupEntries (0)
  205881. {
  205882. CGContextRetain (context);
  205883. CGContextSaveGState(context);
  205884. CGContextSetShouldSmoothFonts (context, true);
  205885. CGContextSetShouldAntialias (context, true);
  205886. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205887. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  205888. greyColourSpace = CGColorSpaceCreateDeviceGray();
  205889. gradientCallbacks.version = 0;
  205890. gradientCallbacks.evaluate = gradientCallback;
  205891. gradientCallbacks.releaseInfo = 0;
  205892. state = new SavedState();
  205893. }
  205894. ~CoreGraphicsContext()
  205895. {
  205896. CGContextRestoreGState (context);
  205897. CGContextRelease (context);
  205898. CGColorSpaceRelease (rgbColourSpace);
  205899. CGColorSpaceRelease (greyColourSpace);
  205900. }
  205901. bool isVectorDevice() const { return false; }
  205902. void setOrigin (int x, int y)
  205903. {
  205904. CGContextTranslateCTM (context, x, -y);
  205905. }
  205906. bool clipToRectangle (const Rectangle<int>& r)
  205907. {
  205908. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  205909. return ! isClipEmpty();
  205910. }
  205911. bool clipToRectangleList (const RectangleList& clipRegion)
  205912. {
  205913. if (clipRegion.isEmpty())
  205914. {
  205915. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  205916. return false;
  205917. }
  205918. else
  205919. {
  205920. const int numRects = clipRegion.getNumRectangles();
  205921. HeapBlock <CGRect> rects (numRects);
  205922. for (int i = 0; i < numRects; ++i)
  205923. {
  205924. const Rectangle<int>& r = clipRegion.getRectangle(i);
  205925. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205926. }
  205927. CGContextClipToRects (context, rects, numRects);
  205928. return ! isClipEmpty();
  205929. }
  205930. }
  205931. void excludeClipRectangle (const Rectangle<int>& r)
  205932. {
  205933. RectangleList remaining (getClipBounds());
  205934. remaining.subtract (r);
  205935. clipToRectangleList (remaining);
  205936. }
  205937. void clipToPath (const Path& path, const AffineTransform& transform)
  205938. {
  205939. createPath (path, transform);
  205940. CGContextClip (context);
  205941. }
  205942. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  205943. {
  205944. if (! transform.isSingularity())
  205945. {
  205946. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  205947. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  205948. flip();
  205949. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  205950. applyTransform (t);
  205951. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  205952. CGContextClipToMask (context, r, image);
  205953. applyTransform (t.inverted());
  205954. flip();
  205955. CGImageRelease (image);
  205956. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  205957. }
  205958. }
  205959. bool clipRegionIntersects (const Rectangle<int>& r)
  205960. {
  205961. return getClipBounds().intersects (r);
  205962. }
  205963. const Rectangle<int> getClipBounds() const
  205964. {
  205965. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  205966. return Rectangle<int> (roundToInt (bounds.origin.x),
  205967. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  205968. roundToInt (bounds.size.width),
  205969. roundToInt (bounds.size.height));
  205970. }
  205971. bool isClipEmpty() const
  205972. {
  205973. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  205974. }
  205975. void saveState()
  205976. {
  205977. CGContextSaveGState (context);
  205978. stateStack.add (new SavedState (*state));
  205979. }
  205980. void restoreState()
  205981. {
  205982. CGContextRestoreGState (context);
  205983. SavedState* const top = stateStack.getLast();
  205984. if (top != 0)
  205985. {
  205986. state = top;
  205987. stateStack.removeLast (1, false);
  205988. }
  205989. else
  205990. {
  205991. jassertfalse // trying to pop with an empty stack!
  205992. }
  205993. }
  205994. void setFill (const FillType& fillType)
  205995. {
  205996. state->fillType = fillType;
  205997. if (fillType.isColour())
  205998. {
  205999. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  206000. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  206001. CGContextSetAlpha (context, 1.0f);
  206002. }
  206003. }
  206004. void setOpacity (float newOpacity)
  206005. {
  206006. state->fillType.setOpacity (newOpacity);
  206007. setFill (state->fillType);
  206008. }
  206009. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  206010. {
  206011. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  206012. ? kCGInterpolationLow
  206013. : kCGInterpolationHigh);
  206014. }
  206015. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  206016. {
  206017. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206018. if (replaceExistingContents)
  206019. {
  206020. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  206021. CGContextClearRect (context, cgRect);
  206022. #else
  206023. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206024. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  206025. CGContextClearRect (context, cgRect);
  206026. else
  206027. #endif
  206028. CGContextSetBlendMode (context, kCGBlendModeCopy);
  206029. #endif
  206030. fillRect (r, false);
  206031. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206032. }
  206033. else
  206034. {
  206035. if (state->fillType.isColour())
  206036. {
  206037. CGContextFillRect (context, cgRect);
  206038. }
  206039. else if (state->fillType.isGradient())
  206040. {
  206041. CGContextSaveGState (context);
  206042. CGContextClipToRect (context, cgRect);
  206043. drawGradient();
  206044. CGContextRestoreGState (context);
  206045. }
  206046. else
  206047. {
  206048. CGContextSaveGState (context);
  206049. CGContextClipToRect (context, cgRect);
  206050. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206051. CGContextRestoreGState (context);
  206052. }
  206053. }
  206054. }
  206055. void fillPath (const Path& path, const AffineTransform& transform)
  206056. {
  206057. CGContextSaveGState (context);
  206058. if (state->fillType.isColour())
  206059. {
  206060. flip();
  206061. applyTransform (transform);
  206062. createPath (path);
  206063. if (path.isUsingNonZeroWinding())
  206064. CGContextFillPath (context);
  206065. else
  206066. CGContextEOFillPath (context);
  206067. }
  206068. else
  206069. {
  206070. createPath (path, transform);
  206071. if (path.isUsingNonZeroWinding())
  206072. CGContextClip (context);
  206073. else
  206074. CGContextEOClip (context);
  206075. if (state->fillType.isGradient())
  206076. drawGradient();
  206077. else
  206078. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206079. }
  206080. CGContextRestoreGState (context);
  206081. }
  206082. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  206083. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  206084. {
  206085. jassert (sourceImage.getBounds().contains (srcClip));
  206086. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  206087. CGImageRef image = fullImage;
  206088. if (srcClip != sourceImage.getBounds())
  206089. {
  206090. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  206091. srcClip.getWidth(), srcClip.getHeight()));
  206092. CGImageRelease (fullImage);
  206093. }
  206094. CGContextSaveGState (context);
  206095. CGContextSetAlpha (context, state->fillType.getOpacity());
  206096. flip();
  206097. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  206098. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206099. if (fillEntireClipAsTiles)
  206100. {
  206101. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  206102. CGContextDrawTiledImage (context, imageRect, image);
  206103. #else
  206104. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206105. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  206106. // if it's doing a transformation - it's quicker to just draw lots of images manually
  206107. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  206108. CGContextDrawTiledImage (context, imageRect, image);
  206109. else
  206110. #endif
  206111. {
  206112. // Fallback to manually doing a tiled fill on 10.4
  206113. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206114. const int iw = srcClip.getWidth();
  206115. const int ih = srcClip.getHeight();
  206116. int x = 0, y = 0;
  206117. while (x > clip.origin.x) x -= iw;
  206118. while (y > clip.origin.y) y -= ih;
  206119. const int right = (int) (clip.origin.x + clip.size.width);
  206120. const int bottom = (int) (clip.origin.y + clip.size.height);
  206121. while (y < bottom)
  206122. {
  206123. for (int x2 = x; x2 < right; x2 += iw)
  206124. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206125. y += ih;
  206126. }
  206127. }
  206128. #endif
  206129. }
  206130. else
  206131. {
  206132. CGContextDrawImage (context, imageRect, image);
  206133. }
  206134. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206135. CGContextRestoreGState (context);
  206136. }
  206137. void drawLine (double x1, double y1, double x2, double y2)
  206138. {
  206139. CGContextSetLineCap (context, kCGLineCapSquare);
  206140. CGContextSetLineWidth (context, 1.0f);
  206141. CGContextSetRGBStrokeColor (context,
  206142. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206143. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206144. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  206145. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  206146. CGContextStrokeLineSegments (context, line, 1);
  206147. }
  206148. void drawVerticalLine (const int x, double top, double bottom)
  206149. {
  206150. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206151. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206152. #else
  206153. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206154. // the x co-ord slightly to trick it..
  206155. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206156. #endif
  206157. }
  206158. void drawHorizontalLine (const int y, double left, double right)
  206159. {
  206160. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206161. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206162. #else
  206163. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206164. // the x co-ord slightly to trick it..
  206165. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206166. #endif
  206167. }
  206168. void setFont (const Font& newFont)
  206169. {
  206170. if (state->font != newFont)
  206171. {
  206172. state->fontRef = 0;
  206173. state->font = newFont;
  206174. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  206175. if (mf != 0)
  206176. {
  206177. state->fontRef = mf->fontRef;
  206178. CGContextSetFont (context, state->fontRef);
  206179. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206180. state->fontTransform = mf->renderingTransform;
  206181. state->fontTransform.a *= state->font.getHorizontalScale();
  206182. CGContextSetTextMatrix (context, state->fontTransform);
  206183. }
  206184. }
  206185. }
  206186. const Font getFont()
  206187. {
  206188. return state->font;
  206189. }
  206190. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206191. {
  206192. if (state->fontRef != 0 && state->fillType.isColour())
  206193. {
  206194. if (transform.isOnlyTranslation())
  206195. {
  206196. CGGlyph g = glyphNumber;
  206197. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206198. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206199. }
  206200. else
  206201. {
  206202. CGContextSaveGState (context);
  206203. flip();
  206204. applyTransform (transform);
  206205. CGAffineTransform t = state->fontTransform;
  206206. t.d = -t.d;
  206207. CGContextSetTextMatrix (context, t);
  206208. CGGlyph g = glyphNumber;
  206209. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206210. CGContextSetTextMatrix (context, state->fontTransform);
  206211. CGContextRestoreGState (context);
  206212. }
  206213. }
  206214. else
  206215. {
  206216. Path p;
  206217. Font& f = state->font;
  206218. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206219. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206220. .followedBy (transform));
  206221. }
  206222. }
  206223. private:
  206224. CGContextRef context;
  206225. const float flipHeight;
  206226. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206227. CGFunctionCallbacks gradientCallbacks;
  206228. struct SavedState
  206229. {
  206230. SavedState()
  206231. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206232. {
  206233. }
  206234. SavedState (const SavedState& other)
  206235. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206236. fontTransform (other.fontTransform)
  206237. {
  206238. }
  206239. ~SavedState()
  206240. {
  206241. }
  206242. FillType fillType;
  206243. Font font;
  206244. CGFontRef fontRef;
  206245. CGAffineTransform fontTransform;
  206246. };
  206247. ScopedPointer <SavedState> state;
  206248. OwnedArray <SavedState> stateStack;
  206249. HeapBlock <PixelARGB> gradientLookupTable;
  206250. int numGradientLookupEntries;
  206251. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206252. {
  206253. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  206254. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206255. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206256. colour.unpremultiply();
  206257. outData[0] = colour.getRed() / 255.0f;
  206258. outData[1] = colour.getGreen() / 255.0f;
  206259. outData[2] = colour.getBlue() / 255.0f;
  206260. outData[3] = colour.getAlpha() / 255.0f;
  206261. }
  206262. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206263. {
  206264. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206265. --numGradientLookupEntries;
  206266. CGShadingRef result = 0;
  206267. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  206268. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206269. if (gradient.isRadial)
  206270. {
  206271. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206272. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206273. function, true, true);
  206274. }
  206275. else
  206276. {
  206277. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206278. CGPointMake (gradient.x2, gradient.y2),
  206279. function, true, true);
  206280. }
  206281. CGFunctionRelease (function);
  206282. return result;
  206283. }
  206284. void drawGradient()
  206285. {
  206286. flip();
  206287. applyTransform (state->fillType.transform);
  206288. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206289. // you draw a gradient with high quality interp enabled).
  206290. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206291. CGContextSetAlpha (context, state->fillType.getOpacity());
  206292. CGContextDrawShading (context, shading);
  206293. CGShadingRelease (shading);
  206294. }
  206295. void createPath (const Path& path) const
  206296. {
  206297. CGContextBeginPath (context);
  206298. Path::Iterator i (path);
  206299. while (i.next())
  206300. {
  206301. switch (i.elementType)
  206302. {
  206303. case Path::Iterator::startNewSubPath:
  206304. CGContextMoveToPoint (context, i.x1, i.y1);
  206305. break;
  206306. case Path::Iterator::lineTo:
  206307. CGContextAddLineToPoint (context, i.x1, i.y1);
  206308. break;
  206309. case Path::Iterator::quadraticTo:
  206310. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206311. break;
  206312. case Path::Iterator::cubicTo:
  206313. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206314. break;
  206315. case Path::Iterator::closePath:
  206316. CGContextClosePath (context); break;
  206317. default:
  206318. jassertfalse
  206319. break;
  206320. }
  206321. }
  206322. }
  206323. void createPath (const Path& path, const AffineTransform& transform) const
  206324. {
  206325. CGContextBeginPath (context);
  206326. Path::Iterator i (path);
  206327. while (i.next())
  206328. {
  206329. switch (i.elementType)
  206330. {
  206331. case Path::Iterator::startNewSubPath:
  206332. transform.transformPoint (i.x1, i.y1);
  206333. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206334. break;
  206335. case Path::Iterator::lineTo:
  206336. transform.transformPoint (i.x1, i.y1);
  206337. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206338. break;
  206339. case Path::Iterator::quadraticTo:
  206340. transform.transformPoint (i.x1, i.y1);
  206341. transform.transformPoint (i.x2, i.y2);
  206342. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206343. break;
  206344. case Path::Iterator::cubicTo:
  206345. transform.transformPoint (i.x1, i.y1);
  206346. transform.transformPoint (i.x2, i.y2);
  206347. transform.transformPoint (i.x3, i.y3);
  206348. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206349. break;
  206350. case Path::Iterator::closePath:
  206351. CGContextClosePath (context); break;
  206352. default:
  206353. jassertfalse
  206354. break;
  206355. }
  206356. }
  206357. }
  206358. static Image* createAlphaChannelImage (const Image& im)
  206359. {
  206360. if (im.getFormat() == Image::SingleChannel)
  206361. return const_cast <Image*> (&im);
  206362. return im.createCopyOfAlphaChannel();
  206363. }
  206364. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206365. {
  206366. if (im.getFormat() != Image::SingleChannel)
  206367. delete alphaIm;
  206368. }
  206369. void flip() const
  206370. {
  206371. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206372. }
  206373. void applyTransform (const AffineTransform& transform) const
  206374. {
  206375. CGAffineTransform t;
  206376. t.a = transform.mat00;
  206377. t.b = transform.mat10;
  206378. t.c = transform.mat01;
  206379. t.d = transform.mat11;
  206380. t.tx = transform.mat02;
  206381. t.ty = transform.mat12;
  206382. CGContextConcatCTM (context, t);
  206383. }
  206384. float flipY (float y) const
  206385. {
  206386. return flipHeight - y;
  206387. }
  206388. };
  206389. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206390. {
  206391. return new CoreGraphicsContext (context, imageHeight);
  206392. }
  206393. #endif
  206394. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  206395. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  206396. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206397. // compiled on its own).
  206398. #if JUCE_INCLUDED_FILE
  206399. class NSViewComponentPeer;
  206400. END_JUCE_NAMESPACE
  206401. #define JuceNSView MakeObjCClassName(JuceNSView)
  206402. @interface JuceNSView : NSView<NSTextInput>
  206403. {
  206404. @public
  206405. NSViewComponentPeer* owner;
  206406. NSNotificationCenter* notificationCenter;
  206407. String* stringBeingComposed;
  206408. bool textWasInserted;
  206409. }
  206410. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206411. - (void) dealloc;
  206412. - (BOOL) isOpaque;
  206413. - (void) drawRect: (NSRect) r;
  206414. - (void) mouseDown: (NSEvent*) ev;
  206415. - (void) asyncMouseDown: (NSEvent*) ev;
  206416. - (void) mouseUp: (NSEvent*) ev;
  206417. - (void) asyncMouseUp: (NSEvent*) ev;
  206418. - (void) mouseDragged: (NSEvent*) ev;
  206419. - (void) mouseMoved: (NSEvent*) ev;
  206420. - (void) mouseEntered: (NSEvent*) ev;
  206421. - (void) mouseExited: (NSEvent*) ev;
  206422. - (void) rightMouseDown: (NSEvent*) ev;
  206423. - (void) rightMouseDragged: (NSEvent*) ev;
  206424. - (void) rightMouseUp: (NSEvent*) ev;
  206425. - (void) otherMouseDown: (NSEvent*) ev;
  206426. - (void) otherMouseDragged: (NSEvent*) ev;
  206427. - (void) otherMouseUp: (NSEvent*) ev;
  206428. - (void) scrollWheel: (NSEvent*) ev;
  206429. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206430. - (void) frameChanged: (NSNotification*) n;
  206431. - (void) viewDidMoveToWindow;
  206432. - (void) keyDown: (NSEvent*) ev;
  206433. - (void) keyUp: (NSEvent*) ev;
  206434. // NSTextInput Methods
  206435. - (void) insertText: (id) aString;
  206436. - (void) doCommandBySelector: (SEL) aSelector;
  206437. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selRange;
  206438. - (void) unmarkText;
  206439. - (BOOL) hasMarkedText;
  206440. - (long) conversationIdentifier;
  206441. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange;
  206442. - (NSRange) markedRange;
  206443. - (NSRange) selectedRange;
  206444. - (NSRect) firstRectForCharacterRange: (NSRange) theRange;
  206445. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint;
  206446. - (NSArray*) validAttributesForMarkedText;
  206447. - (void) flagsChanged: (NSEvent*) ev;
  206448. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206449. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206450. #endif
  206451. - (BOOL) becomeFirstResponder;
  206452. - (BOOL) resignFirstResponder;
  206453. - (BOOL) acceptsFirstResponder;
  206454. - (void) asyncRepaint: (id) rect;
  206455. - (NSArray*) getSupportedDragTypes;
  206456. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206457. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206458. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206459. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206460. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206461. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206462. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206463. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206464. @end
  206465. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206466. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206467. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206468. #else
  206469. @interface JuceNSWindow : NSWindow
  206470. #endif
  206471. {
  206472. @private
  206473. NSViewComponentPeer* owner;
  206474. bool isZooming;
  206475. }
  206476. - (void) setOwner: (NSViewComponentPeer*) owner;
  206477. - (BOOL) canBecomeKeyWindow;
  206478. - (void) becomeKeyWindow;
  206479. - (BOOL) windowShouldClose: (id) window;
  206480. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206481. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206482. - (void) zoom: (id) sender;
  206483. @end
  206484. BEGIN_JUCE_NAMESPACE
  206485. class NSViewComponentPeer : public ComponentPeer
  206486. {
  206487. public:
  206488. NSViewComponentPeer (Component* const component,
  206489. const int windowStyleFlags,
  206490. NSView* viewToAttachTo);
  206491. ~NSViewComponentPeer();
  206492. void* getNativeHandle() const;
  206493. void setVisible (bool shouldBeVisible);
  206494. void setTitle (const String& title);
  206495. void setPosition (int x, int y);
  206496. void setSize (int w, int h);
  206497. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206498. const Rectangle<int> getBounds (const bool global) const;
  206499. const Rectangle<int> getBounds() const;
  206500. const Point<int> getScreenPosition() const;
  206501. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  206502. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  206503. void setMinimised (bool shouldBeMinimised);
  206504. bool isMinimised() const;
  206505. void setFullScreen (bool shouldBeFullScreen);
  206506. bool isFullScreen() const;
  206507. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  206508. const BorderSize getFrameSize() const;
  206509. bool setAlwaysOnTop (bool alwaysOnTop);
  206510. void toFront (bool makeActiveWindow);
  206511. void toBehind (ComponentPeer* other);
  206512. void setIcon (const Image& newIcon);
  206513. const StringArray getAvailableRenderingEngines() throw();
  206514. int getCurrentRenderingEngine() throw();
  206515. void setCurrentRenderingEngine (int index) throw();
  206516. virtual void redirectMouseDown (NSEvent* ev);
  206517. virtual void redirectMouseUp (NSEvent* ev);
  206518. virtual void redirectMouseDrag (NSEvent* ev);
  206519. virtual void redirectMouseMove (NSEvent* ev);
  206520. virtual void redirectMouseEnter (NSEvent* ev);
  206521. virtual void redirectMouseExit (NSEvent* ev);
  206522. virtual void redirectMouseWheel (NSEvent* ev);
  206523. void sendMouseEvent (NSEvent* ev);
  206524. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206525. virtual bool redirectKeyDown (NSEvent* ev);
  206526. virtual bool redirectKeyUp (NSEvent* ev);
  206527. virtual void redirectModKeyChange (NSEvent* ev);
  206528. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206529. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206530. #endif
  206531. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206532. virtual bool isOpaque();
  206533. virtual void drawRect (NSRect r);
  206534. virtual bool canBecomeKeyWindow();
  206535. virtual bool windowShouldClose();
  206536. virtual void redirectMovedOrResized();
  206537. virtual void viewMovedToWindow();
  206538. virtual NSRect constrainRect (NSRect r);
  206539. static void showArrowCursorIfNeeded();
  206540. static void updateModifiers (NSEvent* e);
  206541. static void updateKeysDown (NSEvent* ev, bool isKeyDown);
  206542. static int getKeyCodeFromEvent (NSEvent* ev)
  206543. {
  206544. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  206545. int keyCode = unmodified[0];
  206546. if (keyCode == 0x19) // (backwards-tab)
  206547. keyCode = '\t';
  206548. else if (keyCode == 0x03) // (enter)
  206549. keyCode = '\r';
  206550. return keyCode;
  206551. }
  206552. static int64 getMouseTime (NSEvent* e)
  206553. {
  206554. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  206555. + (int64) ([e timestamp] * 1000.0);
  206556. }
  206557. static const Point<int> getMousePos (NSEvent* e, NSView* view)
  206558. {
  206559. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  206560. return Point<int> (roundToInt (p.x), roundToInt ([view frame].size.height - p.y));
  206561. }
  206562. static int getModifierForButtonNumber (const NSInteger num)
  206563. {
  206564. return num == 0 ? ModifierKeys::leftButtonModifier
  206565. : (num == 1 ? ModifierKeys::rightButtonModifier
  206566. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  206567. }
  206568. virtual void viewFocusGain();
  206569. virtual void viewFocusLoss();
  206570. bool isFocused() const;
  206571. void grabFocus();
  206572. void textInputRequired (const Point<int>& position);
  206573. void repaint (int x, int y, int w, int h);
  206574. void performAnyPendingRepaintsNow();
  206575. juce_UseDebuggingNewOperator
  206576. NSWindow* window;
  206577. JuceNSView* view;
  206578. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206579. static ModifierKeys currentModifiers;
  206580. static ComponentPeer* currentlyFocusedPeer;
  206581. static VoidArray keysCurrentlyDown;
  206582. };
  206583. END_JUCE_NAMESPACE
  206584. @implementation JuceNSView
  206585. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206586. withFrame: (NSRect) frame
  206587. {
  206588. [super initWithFrame: frame];
  206589. owner = owner_;
  206590. stringBeingComposed = 0;
  206591. textWasInserted = false;
  206592. notificationCenter = [NSNotificationCenter defaultCenter];
  206593. [notificationCenter addObserver: self
  206594. selector: @selector (frameChanged:)
  206595. name: NSViewFrameDidChangeNotification
  206596. object: self];
  206597. if (! owner_->isSharedWindow)
  206598. {
  206599. [notificationCenter addObserver: self
  206600. selector: @selector (frameChanged:)
  206601. name: NSWindowDidMoveNotification
  206602. object: owner_->window];
  206603. }
  206604. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206605. return self;
  206606. }
  206607. - (void) dealloc
  206608. {
  206609. [notificationCenter removeObserver: self];
  206610. delete stringBeingComposed;
  206611. [super dealloc];
  206612. }
  206613. - (void) drawRect: (NSRect) r
  206614. {
  206615. if (owner != 0)
  206616. owner->drawRect (r);
  206617. }
  206618. - (BOOL) isOpaque
  206619. {
  206620. return owner == 0 || owner->isOpaque();
  206621. }
  206622. - (void) mouseDown: (NSEvent*) ev
  206623. {
  206624. // In some host situations, the host will stop modal loops from working
  206625. // correctly if they're called from a mouse event, so we'll trigger
  206626. // the event asynchronously..
  206627. if (JUCEApplication::getInstance() == 0)
  206628. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206629. withObject: ev
  206630. waitUntilDone: NO];
  206631. else
  206632. [self asyncMouseDown: ev];
  206633. }
  206634. - (void) asyncMouseDown: (NSEvent*) ev
  206635. {
  206636. if (owner != 0)
  206637. owner->redirectMouseDown (ev);
  206638. }
  206639. - (void) mouseUp: (NSEvent*) ev
  206640. {
  206641. // In some host situations, the host will stop modal loops from working
  206642. // correctly if they're called from a mouse event, so we'll trigger
  206643. // the event asynchronously..
  206644. if (JUCEApplication::getInstance() == 0)
  206645. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206646. withObject: ev
  206647. waitUntilDone: NO];
  206648. else
  206649. [self asyncMouseUp: ev];
  206650. }
  206651. - (void) asyncMouseUp: (NSEvent*) ev
  206652. {
  206653. if (owner != 0)
  206654. owner->redirectMouseUp (ev);
  206655. }
  206656. - (void) mouseDragged: (NSEvent*) ev
  206657. {
  206658. if (owner != 0)
  206659. owner->redirectMouseDrag (ev);
  206660. }
  206661. - (void) mouseMoved: (NSEvent*) ev
  206662. {
  206663. if (owner != 0)
  206664. owner->redirectMouseMove (ev);
  206665. }
  206666. - (void) mouseEntered: (NSEvent*) ev
  206667. {
  206668. if (owner != 0)
  206669. owner->redirectMouseEnter (ev);
  206670. }
  206671. - (void) mouseExited: (NSEvent*) ev
  206672. {
  206673. if (owner != 0)
  206674. owner->redirectMouseExit (ev);
  206675. }
  206676. - (void) rightMouseDown: (NSEvent*) ev
  206677. {
  206678. [self mouseDown: ev];
  206679. }
  206680. - (void) rightMouseDragged: (NSEvent*) ev
  206681. {
  206682. [self mouseDragged: ev];
  206683. }
  206684. - (void) rightMouseUp: (NSEvent*) ev
  206685. {
  206686. [self mouseUp: ev];
  206687. }
  206688. - (void) otherMouseDown: (NSEvent*) ev
  206689. {
  206690. [self mouseDown: ev];
  206691. }
  206692. - (void) otherMouseDragged: (NSEvent*) ev
  206693. {
  206694. [self mouseDragged: ev];
  206695. }
  206696. - (void) otherMouseUp: (NSEvent*) ev
  206697. {
  206698. [self mouseUp: ev];
  206699. }
  206700. - (void) scrollWheel: (NSEvent*) ev
  206701. {
  206702. if (owner != 0)
  206703. owner->redirectMouseWheel (ev);
  206704. }
  206705. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206706. {
  206707. return YES;
  206708. }
  206709. - (void) frameChanged: (NSNotification*) n
  206710. {
  206711. if (owner != 0)
  206712. owner->redirectMovedOrResized();
  206713. }
  206714. - (void) viewDidMoveToWindow
  206715. {
  206716. if (owner != 0)
  206717. owner->viewMovedToWindow();
  206718. }
  206719. - (void) asyncRepaint: (id) rect
  206720. {
  206721. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206722. [self setNeedsDisplayInRect: *r];
  206723. }
  206724. - (void) keyDown: (NSEvent*) ev
  206725. {
  206726. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206727. textWasInserted = false;
  206728. if (target != 0)
  206729. [self interpretKeyEvents: [NSArray arrayWithObject: ev]];
  206730. else
  206731. deleteAndZero (stringBeingComposed);
  206732. if ((! textWasInserted) && (owner == 0 || ! owner->redirectKeyDown (ev)))
  206733. [super keyDown: ev];
  206734. }
  206735. - (void) keyUp: (NSEvent*) ev
  206736. {
  206737. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206738. [super keyUp: ev];
  206739. }
  206740. - (void) insertText: (id) aString
  206741. {
  206742. // This commits multi-byte text when return is pressed, or after every keypress for western keyboards
  206743. if ([aString length] > 0)
  206744. {
  206745. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206746. if (target != 0)
  206747. {
  206748. target->insertTextAtCaret (nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString));
  206749. textWasInserted = true;
  206750. }
  206751. }
  206752. deleteAndZero (stringBeingComposed);
  206753. }
  206754. - (void) doCommandBySelector: (SEL) aSelector
  206755. {
  206756. }
  206757. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selectionRange
  206758. {
  206759. if (stringBeingComposed == 0)
  206760. stringBeingComposed = new String();
  206761. *stringBeingComposed = nsStringToJuce ([aString isKindOfClass:[NSAttributedString class]] ? [aString string] : aString);
  206762. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206763. if (target != 0)
  206764. {
  206765. const Range<int> currentHighlight (target->getHighlightedRegion());
  206766. target->insertTextAtCaret (*stringBeingComposed);
  206767. target->setHighlightedRegion (currentHighlight.withLength (stringBeingComposed->length()));
  206768. textWasInserted = true;
  206769. }
  206770. }
  206771. - (void) unmarkText
  206772. {
  206773. if (stringBeingComposed != 0)
  206774. {
  206775. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206776. if (target != 0)
  206777. {
  206778. target->insertTextAtCaret (*stringBeingComposed);
  206779. textWasInserted = true;
  206780. }
  206781. }
  206782. deleteAndZero (stringBeingComposed);
  206783. }
  206784. - (BOOL) hasMarkedText
  206785. {
  206786. return stringBeingComposed != 0;
  206787. }
  206788. - (long) conversationIdentifier
  206789. {
  206790. return (long) (pointer_sized_int) self;
  206791. }
  206792. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange
  206793. {
  206794. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206795. if (target != 0)
  206796. {
  206797. const Range<int> r ((int) theRange.location,
  206798. (int) (theRange.location + theRange.length));
  206799. return [[[NSAttributedString alloc] initWithString: juceStringToNS (target->getTextInRange (r))] autorelease];
  206800. }
  206801. return nil;
  206802. }
  206803. - (NSRange) markedRange
  206804. {
  206805. return stringBeingComposed != 0 ? NSMakeRange (0, stringBeingComposed->length())
  206806. : NSMakeRange (NSNotFound, 0);
  206807. }
  206808. - (NSRange) selectedRange
  206809. {
  206810. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206811. if (target != 0)
  206812. {
  206813. const Range<int> highlight (target->getHighlightedRegion());
  206814. if (! highlight.isEmpty())
  206815. return NSMakeRange (highlight.getStart(), highlight.getLength());
  206816. }
  206817. return NSMakeRange (NSNotFound, 0);
  206818. }
  206819. - (NSRect) firstRectForCharacterRange: (NSRange) theRange
  206820. {
  206821. JUCE_NAMESPACE::Component* const comp = dynamic_cast <JUCE_NAMESPACE::Component*> (owner->findCurrentTextInputTarget());
  206822. if (comp == 0)
  206823. return NSMakeRect (0, 0, 0, 0);
  206824. const Rectangle<int> bounds (comp->getScreenBounds());
  206825. return NSMakeRect (bounds.getX(),
  206826. [[[NSScreen screens] objectAtIndex: 0] frame].size.height - bounds.getY(),
  206827. bounds.getWidth(),
  206828. bounds.getHeight());
  206829. }
  206830. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint
  206831. {
  206832. return NSNotFound;
  206833. }
  206834. - (NSArray*) validAttributesForMarkedText
  206835. {
  206836. return [NSArray array];
  206837. }
  206838. - (void) flagsChanged: (NSEvent*) ev
  206839. {
  206840. if (owner != 0)
  206841. owner->redirectModKeyChange (ev);
  206842. }
  206843. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206844. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206845. {
  206846. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206847. return true;
  206848. return [super performKeyEquivalent: ev];
  206849. }
  206850. #endif
  206851. - (BOOL) becomeFirstResponder
  206852. {
  206853. if (owner != 0)
  206854. owner->viewFocusGain();
  206855. return true;
  206856. }
  206857. - (BOOL) resignFirstResponder
  206858. {
  206859. if (owner != 0)
  206860. owner->viewFocusLoss();
  206861. return true;
  206862. }
  206863. - (BOOL) acceptsFirstResponder
  206864. {
  206865. return owner != 0 && owner->canBecomeKeyWindow();
  206866. }
  206867. - (NSArray*) getSupportedDragTypes
  206868. {
  206869. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206870. }
  206871. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206872. {
  206873. return owner != 0 && owner->sendDragCallback (type, sender);
  206874. }
  206875. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206876. {
  206877. if ([self sendDragCallback: 0 sender: sender])
  206878. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206879. else
  206880. return NSDragOperationNone;
  206881. }
  206882. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206883. {
  206884. if ([self sendDragCallback: 0 sender: sender])
  206885. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206886. else
  206887. return NSDragOperationNone;
  206888. }
  206889. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206890. {
  206891. [self sendDragCallback: 1 sender: sender];
  206892. }
  206893. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206894. {
  206895. [self sendDragCallback: 1 sender: sender];
  206896. }
  206897. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206898. {
  206899. return YES;
  206900. }
  206901. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206902. {
  206903. return [self sendDragCallback: 2 sender: sender];
  206904. }
  206905. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206906. {
  206907. }
  206908. @end
  206909. @implementation JuceNSWindow
  206910. - (void) setOwner: (NSViewComponentPeer*) owner_
  206911. {
  206912. owner = owner_;
  206913. isZooming = false;
  206914. }
  206915. - (BOOL) canBecomeKeyWindow
  206916. {
  206917. return owner != 0 && owner->canBecomeKeyWindow();
  206918. }
  206919. - (void) becomeKeyWindow
  206920. {
  206921. [super becomeKeyWindow];
  206922. if (owner != 0)
  206923. owner->grabFocus();
  206924. }
  206925. - (BOOL) windowShouldClose: (id) window
  206926. {
  206927. return owner == 0 || owner->windowShouldClose();
  206928. }
  206929. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  206930. {
  206931. if (owner != 0)
  206932. frameRect = owner->constrainRect (frameRect);
  206933. return frameRect;
  206934. }
  206935. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  206936. {
  206937. if (isZooming)
  206938. return proposedFrameSize;
  206939. NSRect frameRect = [self frame];
  206940. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  206941. frameRect.size = proposedFrameSize;
  206942. if (owner != 0)
  206943. frameRect = owner->constrainRect (frameRect);
  206944. return frameRect.size;
  206945. }
  206946. - (void) zoom: (id) sender
  206947. {
  206948. isZooming = true;
  206949. [super zoom: sender];
  206950. isZooming = false;
  206951. }
  206952. - (void) windowWillMove: (NSNotification*) notification
  206953. {
  206954. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  206955. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  206956. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  206957. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  206958. }
  206959. @end
  206960. BEGIN_JUCE_NAMESPACE
  206961. ModifierKeys NSViewComponentPeer::currentModifiers;
  206962. ComponentPeer* NSViewComponentPeer::currentlyFocusedPeer = 0;
  206963. VoidArray NSViewComponentPeer::keysCurrentlyDown;
  206964. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  206965. {
  206966. if (NSViewComponentPeer::keysCurrentlyDown.contains ((void*) keyCode))
  206967. return true;
  206968. if (keyCode >= 'A' && keyCode <= 'Z'
  206969. && NSViewComponentPeer::keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toLowerCase ((tchar) keyCode)))
  206970. return true;
  206971. if (keyCode >= 'a' && keyCode <= 'z'
  206972. && NSViewComponentPeer::keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toUpperCase ((tchar) keyCode)))
  206973. return true;
  206974. return false;
  206975. }
  206976. void NSViewComponentPeer::updateModifiers (NSEvent* e)
  206977. {
  206978. int m = 0;
  206979. if (([e modifierFlags] & NSShiftKeyMask) != 0) m |= ModifierKeys::shiftModifier;
  206980. if (([e modifierFlags] & NSControlKeyMask) != 0) m |= ModifierKeys::ctrlModifier;
  206981. if (([e modifierFlags] & NSAlternateKeyMask) != 0) m |= ModifierKeys::altModifier;
  206982. if (([e modifierFlags] & NSCommandKeyMask) != 0) m |= ModifierKeys::commandModifier;
  206983. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (m);
  206984. }
  206985. void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown)
  206986. {
  206987. updateModifiers (ev);
  206988. int keyCode = getKeyCodeFromEvent (ev);
  206989. if (keyCode != 0)
  206990. {
  206991. if (isKeyDown)
  206992. keysCurrentlyDown.addIfNotAlreadyThere ((void*) keyCode);
  206993. else
  206994. keysCurrentlyDown.removeValue ((void*) keyCode);
  206995. }
  206996. }
  206997. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  206998. {
  206999. return NSViewComponentPeer::currentModifiers;
  207000. }
  207001. void ModifierKeys::updateCurrentModifiers() throw()
  207002. {
  207003. currentModifiers = NSViewComponentPeer::currentModifiers;
  207004. }
  207005. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  207006. const int windowStyleFlags,
  207007. NSView* viewToAttachTo)
  207008. : ComponentPeer (component_, windowStyleFlags),
  207009. window (0),
  207010. view (0),
  207011. isSharedWindow (viewToAttachTo != 0),
  207012. fullScreen (false),
  207013. insideDrawRect (false),
  207014. #if USE_COREGRAPHICS_RENDERING
  207015. usingCoreGraphics (true),
  207016. #else
  207017. usingCoreGraphics (false),
  207018. #endif
  207019. recursiveToFrontCall (false)
  207020. {
  207021. NSRect r;
  207022. r.origin.x = 0;
  207023. r.origin.y = 0;
  207024. r.size.width = (float) component->getWidth();
  207025. r.size.height = (float) component->getHeight();
  207026. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  207027. [view setPostsFrameChangedNotifications: YES];
  207028. if (isSharedWindow)
  207029. {
  207030. window = [viewToAttachTo window];
  207031. [viewToAttachTo addSubview: view];
  207032. setVisible (component->isVisible());
  207033. }
  207034. else
  207035. {
  207036. r.origin.x = (float) component->getX();
  207037. r.origin.y = (float) component->getY();
  207038. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207039. unsigned int style = 0;
  207040. if ((windowStyleFlags & windowHasTitleBar) == 0)
  207041. style = NSBorderlessWindowMask;
  207042. else
  207043. style = NSTitledWindowMask;
  207044. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  207045. style |= NSMiniaturizableWindowMask;
  207046. if ((windowStyleFlags & windowHasCloseButton) != 0)
  207047. style |= NSClosableWindowMask;
  207048. if ((windowStyleFlags & windowIsResizable) != 0)
  207049. style |= NSResizableWindowMask;
  207050. window = [[JuceNSWindow alloc] initWithContentRect: r
  207051. styleMask: style
  207052. backing: NSBackingStoreBuffered
  207053. defer: YES];
  207054. [((JuceNSWindow*) window) setOwner: this];
  207055. [window orderOut: nil];
  207056. [window setDelegate: (JuceNSWindow*) window];
  207057. [window setOpaque: component->isOpaque()];
  207058. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  207059. if (component->isAlwaysOnTop())
  207060. [window setLevel: NSFloatingWindowLevel];
  207061. [window setContentView: view];
  207062. [window setAutodisplay: YES];
  207063. [window setAcceptsMouseMovedEvents: YES];
  207064. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  207065. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  207066. [window setReleasedWhenClosed: YES];
  207067. [window retain];
  207068. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  207069. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  207070. }
  207071. setTitle (component->getName());
  207072. }
  207073. NSViewComponentPeer::~NSViewComponentPeer()
  207074. {
  207075. view->owner = 0;
  207076. [view removeFromSuperview];
  207077. [view release];
  207078. if (! isSharedWindow)
  207079. {
  207080. [((JuceNSWindow*) window) setOwner: 0];
  207081. [window close];
  207082. [window release];
  207083. }
  207084. }
  207085. void* NSViewComponentPeer::getNativeHandle() const
  207086. {
  207087. return view;
  207088. }
  207089. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  207090. {
  207091. if (isSharedWindow)
  207092. {
  207093. [view setHidden: ! shouldBeVisible];
  207094. }
  207095. else
  207096. {
  207097. if (shouldBeVisible)
  207098. {
  207099. [window orderFront: nil];
  207100. handleBroughtToFront();
  207101. }
  207102. else
  207103. {
  207104. [window orderOut: nil];
  207105. }
  207106. }
  207107. }
  207108. void NSViewComponentPeer::setTitle (const String& title)
  207109. {
  207110. const ScopedAutoReleasePool pool;
  207111. if (! isSharedWindow)
  207112. [window setTitle: juceStringToNS (title)];
  207113. }
  207114. void NSViewComponentPeer::setPosition (int x, int y)
  207115. {
  207116. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207117. }
  207118. void NSViewComponentPeer::setSize (int w, int h)
  207119. {
  207120. setBounds (component->getX(), component->getY(), w, h, false);
  207121. }
  207122. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  207123. {
  207124. fullScreen = isNowFullScreen;
  207125. w = jmax (0, w);
  207126. h = jmax (0, h);
  207127. NSRect r;
  207128. r.origin.x = (float) x;
  207129. r.origin.y = (float) y;
  207130. r.size.width = (float) w;
  207131. r.size.height = (float) h;
  207132. if (isSharedWindow)
  207133. {
  207134. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207135. if ([view frame].size.width != r.size.width
  207136. || [view frame].size.height != r.size.height)
  207137. [view setNeedsDisplay: true];
  207138. [view setFrame: r];
  207139. }
  207140. else
  207141. {
  207142. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207143. [window setFrame: [window frameRectForContentRect: r]
  207144. display: true];
  207145. }
  207146. }
  207147. const Rectangle<int> NSViewComponentPeer::getBounds (const bool global) const
  207148. {
  207149. NSRect r = [view frame];
  207150. if (global && [view window] != 0)
  207151. {
  207152. r = [view convertRect: r toView: nil];
  207153. NSRect wr = [[view window] frame];
  207154. r.origin.x += wr.origin.x;
  207155. r.origin.y += wr.origin.y;
  207156. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207157. }
  207158. else
  207159. {
  207160. r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height;
  207161. }
  207162. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y, (int) r.size.width, (int) r.size.height);
  207163. }
  207164. const Rectangle<int> NSViewComponentPeer::getBounds() const
  207165. {
  207166. return getBounds (! isSharedWindow);
  207167. }
  207168. const Point<int> NSViewComponentPeer::getScreenPosition() const
  207169. {
  207170. return getBounds (true).getPosition();
  207171. }
  207172. const Point<int> NSViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  207173. {
  207174. return relativePosition + getScreenPosition();
  207175. }
  207176. const Point<int> NSViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  207177. {
  207178. return screenPosition - getScreenPosition();
  207179. }
  207180. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207181. {
  207182. if (constrainer != 0)
  207183. {
  207184. NSRect current = [window frame];
  207185. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207186. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207187. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  207188. (int) r.size.width, (int) r.size.height);
  207189. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  207190. (int) current.size.width, (int) current.size.height);
  207191. constrainer->checkBounds (pos, original,
  207192. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207193. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  207194. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  207195. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  207196. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  207197. r.origin.x = pos.getX();
  207198. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  207199. r.size.width = pos.getWidth();
  207200. r.size.height = pos.getHeight();
  207201. }
  207202. return r;
  207203. }
  207204. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207205. {
  207206. if (! isSharedWindow)
  207207. {
  207208. if (shouldBeMinimised)
  207209. [window miniaturize: nil];
  207210. else
  207211. [window deminiaturize: nil];
  207212. }
  207213. }
  207214. bool NSViewComponentPeer::isMinimised() const
  207215. {
  207216. return window != 0 && [window isMiniaturized];
  207217. }
  207218. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207219. {
  207220. if (! isSharedWindow)
  207221. {
  207222. Rectangle<int> r (lastNonFullscreenBounds);
  207223. setMinimised (false);
  207224. if (fullScreen != shouldBeFullScreen)
  207225. {
  207226. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207227. {
  207228. fullScreen = true;
  207229. [window performZoom: nil];
  207230. }
  207231. else
  207232. {
  207233. if (shouldBeFullScreen)
  207234. r = Desktop::getInstance().getMainMonitorArea();
  207235. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207236. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207237. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207238. }
  207239. }
  207240. }
  207241. }
  207242. bool NSViewComponentPeer::isFullScreen() const
  207243. {
  207244. return fullScreen;
  207245. }
  207246. bool NSViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  207247. {
  207248. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  207249. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  207250. return false;
  207251. NSPoint p;
  207252. p.x = (float) position.getX();
  207253. p.y = (float) position.getY();
  207254. NSView* v = [view hitTest: p];
  207255. if (trueIfInAChildWindow)
  207256. return v != nil;
  207257. return v == view;
  207258. }
  207259. const BorderSize NSViewComponentPeer::getFrameSize() const
  207260. {
  207261. BorderSize b;
  207262. if (! isSharedWindow)
  207263. {
  207264. NSRect v = [view convertRect: [view frame] toView: nil];
  207265. NSRect w = [window frame];
  207266. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207267. b.setBottom ((int) v.origin.y);
  207268. b.setLeft ((int) v.origin.x);
  207269. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207270. }
  207271. return b;
  207272. }
  207273. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207274. {
  207275. if (! isSharedWindow)
  207276. {
  207277. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207278. : NSNormalWindowLevel];
  207279. }
  207280. return true;
  207281. }
  207282. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207283. {
  207284. if (isSharedWindow)
  207285. {
  207286. [[view superview] addSubview: view
  207287. positioned: NSWindowAbove
  207288. relativeTo: nil];
  207289. }
  207290. if (window != 0 && component->isVisible())
  207291. {
  207292. if (makeActiveWindow)
  207293. [window makeKeyAndOrderFront: nil];
  207294. else
  207295. [window orderFront: nil];
  207296. if (! recursiveToFrontCall)
  207297. {
  207298. recursiveToFrontCall = true;
  207299. handleBroughtToFront();
  207300. recursiveToFrontCall = false;
  207301. }
  207302. }
  207303. }
  207304. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207305. {
  207306. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207307. if (isSharedWindow)
  207308. {
  207309. [[view superview] addSubview: view
  207310. positioned: NSWindowBelow
  207311. relativeTo: o->view];
  207312. }
  207313. else
  207314. {
  207315. [window orderWindow: NSWindowBelow
  207316. relativeTo: o->window != 0 ? [o->window windowNumber]
  207317. : nil ];
  207318. }
  207319. }
  207320. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207321. {
  207322. // to do..
  207323. }
  207324. void NSViewComponentPeer::viewFocusGain()
  207325. {
  207326. if (currentlyFocusedPeer != this)
  207327. {
  207328. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207329. currentlyFocusedPeer->handleFocusLoss();
  207330. currentlyFocusedPeer = this;
  207331. handleFocusGain();
  207332. }
  207333. }
  207334. void NSViewComponentPeer::viewFocusLoss()
  207335. {
  207336. if (currentlyFocusedPeer == this)
  207337. {
  207338. currentlyFocusedPeer = 0;
  207339. handleFocusLoss();
  207340. }
  207341. }
  207342. void juce_HandleProcessFocusChange()
  207343. {
  207344. NSViewComponentPeer::keysCurrentlyDown.clear();
  207345. if (NSViewComponentPeer::isValidPeer (NSViewComponentPeer::currentlyFocusedPeer))
  207346. {
  207347. if (Process::isForegroundProcess())
  207348. {
  207349. NSViewComponentPeer::currentlyFocusedPeer->handleFocusGain();
  207350. ComponentPeer::bringModalComponentToFront();
  207351. }
  207352. else
  207353. {
  207354. NSViewComponentPeer::currentlyFocusedPeer->handleFocusLoss();
  207355. // turn kiosk mode off if we lose focus..
  207356. Desktop::getInstance().setKioskModeComponent (0);
  207357. }
  207358. }
  207359. }
  207360. bool NSViewComponentPeer::isFocused() const
  207361. {
  207362. return isSharedWindow ? this == currentlyFocusedPeer
  207363. : (window != 0 && [window isKeyWindow]);
  207364. }
  207365. void NSViewComponentPeer::grabFocus()
  207366. {
  207367. if (window != 0)
  207368. {
  207369. [window makeKeyWindow];
  207370. [window makeFirstResponder: view];
  207371. viewFocusGain();
  207372. }
  207373. }
  207374. void NSViewComponentPeer::textInputRequired (const Point<int>&)
  207375. {
  207376. }
  207377. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207378. {
  207379. String unicode (nsStringToJuce ([ev characters]));
  207380. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207381. int keyCode = getKeyCodeFromEvent (ev);
  207382. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207383. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207384. if (unicode.isNotEmpty() || keyCode != 0)
  207385. {
  207386. if (isKeyDown)
  207387. {
  207388. bool used = false;
  207389. while (unicode.length() > 0)
  207390. {
  207391. juce_wchar textCharacter = unicode[0];
  207392. unicode = unicode.substring (1);
  207393. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207394. textCharacter = 0;
  207395. used = handleKeyUpOrDown (true) || used;
  207396. used = handleKeyPress (keyCode, textCharacter) || used;
  207397. }
  207398. return used;
  207399. }
  207400. else
  207401. {
  207402. if (handleKeyUpOrDown (false))
  207403. return true;
  207404. }
  207405. }
  207406. return false;
  207407. }
  207408. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207409. {
  207410. updateKeysDown (ev, true);
  207411. bool used = handleKeyEvent (ev, true);
  207412. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207413. {
  207414. // for command keys, the key-up event is thrown away, so simulate one..
  207415. updateKeysDown (ev, false);
  207416. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207417. }
  207418. // (If we're running modally, don't allow unused keystrokes to be passed
  207419. // along to other blocked views..)
  207420. if (Component::getCurrentlyModalComponent() != 0)
  207421. used = true;
  207422. return used;
  207423. }
  207424. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207425. {
  207426. updateKeysDown (ev, false);
  207427. return handleKeyEvent (ev, false)
  207428. || Component::getCurrentlyModalComponent() != 0;
  207429. }
  207430. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207431. {
  207432. keysCurrentlyDown.clear();
  207433. handleKeyUpOrDown (true);
  207434. updateModifiers (ev);
  207435. handleModifierKeysChange();
  207436. }
  207437. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207438. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207439. {
  207440. if ([ev type] == NSKeyDown)
  207441. return redirectKeyDown (ev);
  207442. else if ([ev type] == NSKeyUp)
  207443. return redirectKeyUp (ev);
  207444. return false;
  207445. }
  207446. #endif
  207447. void NSViewComponentPeer::sendMouseEvent (NSEvent* ev)
  207448. {
  207449. updateModifiers (ev);
  207450. handleMouseEvent (0, getMousePos (ev, view), currentModifiers, getMouseTime (ev));
  207451. }
  207452. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207453. {
  207454. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207455. sendMouseEvent (ev);
  207456. }
  207457. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207458. {
  207459. currentModifiers = currentModifiers.withoutFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207460. sendMouseEvent (ev);
  207461. showArrowCursorIfNeeded();
  207462. }
  207463. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207464. {
  207465. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207466. sendMouseEvent (ev);
  207467. }
  207468. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207469. {
  207470. currentModifiers = currentModifiers.withoutMouseButtons();
  207471. sendMouseEvent (ev);
  207472. showArrowCursorIfNeeded();
  207473. }
  207474. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207475. {
  207476. currentModifiers = currentModifiers.withoutMouseButtons();
  207477. sendMouseEvent (ev);
  207478. }
  207479. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207480. {
  207481. currentModifiers = currentModifiers.withoutMouseButtons();
  207482. sendMouseEvent (ev);
  207483. }
  207484. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207485. {
  207486. updateModifiers (ev);
  207487. handleMouseWheel (0, getMousePos (ev, view), getMouseTime (ev),
  207488. [ev deltaX] * 10.0f, [ev deltaY] * 10.0f);
  207489. }
  207490. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207491. {
  207492. MouseInputSource& mouse = Desktop::getInstance().getMainMouseSource();
  207493. if (mouse.getComponentUnderMouse() == 0
  207494. && Desktop::getInstance().findComponentAt (mouse.getScreenPosition()) == 0)
  207495. {
  207496. [[NSCursor arrowCursor] set];
  207497. }
  207498. }
  207499. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207500. {
  207501. NSString* bestType
  207502. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207503. if (bestType == nil)
  207504. return false;
  207505. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207506. const Point<int> pos ((int) p.x, (int) ([view frame].size.height - p.y));
  207507. StringArray files;
  207508. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207509. if (list == nil)
  207510. return false;
  207511. if ([list isKindOfClass: [NSArray class]])
  207512. {
  207513. NSArray* items = (NSArray*) list;
  207514. for (unsigned int i = 0; i < [items count]; ++i)
  207515. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207516. }
  207517. if (files.size() == 0)
  207518. return false;
  207519. if (type == 0)
  207520. handleFileDragMove (files, pos);
  207521. else if (type == 1)
  207522. handleFileDragExit (files);
  207523. else if (type == 2)
  207524. handleFileDragDrop (files, pos);
  207525. return true;
  207526. }
  207527. bool NSViewComponentPeer::isOpaque()
  207528. {
  207529. return component == 0 || component->isOpaque();
  207530. }
  207531. void NSViewComponentPeer::drawRect (NSRect r)
  207532. {
  207533. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207534. return;
  207535. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207536. if (! component->isOpaque())
  207537. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207538. #if USE_COREGRAPHICS_RENDERING
  207539. if (usingCoreGraphics)
  207540. {
  207541. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207542. insideDrawRect = true;
  207543. handlePaint (context);
  207544. insideDrawRect = false;
  207545. }
  207546. else
  207547. #endif
  207548. {
  207549. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207550. (int) (r.size.width + 0.5f),
  207551. (int) (r.size.height + 0.5f),
  207552. ! getComponent()->isOpaque());
  207553. LowLevelGraphicsSoftwareRenderer context (temp);
  207554. context.setOrigin (-roundToInt (r.origin.x),
  207555. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207556. const NSRect* rects = 0;
  207557. NSInteger numRects = 0;
  207558. [view getRectsBeingDrawn: &rects count: &numRects];
  207559. RectangleList clip;
  207560. for (int i = 0; i < numRects; ++i)
  207561. {
  207562. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207563. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207564. roundToInt (rects[i].size.width),
  207565. roundToInt (rects[i].size.height)));
  207566. }
  207567. if (context.clipToRectangleList (clip))
  207568. {
  207569. insideDrawRect = true;
  207570. handlePaint (context);
  207571. insideDrawRect = false;
  207572. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207573. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207574. CGColorSpaceRelease (colourSpace);
  207575. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207576. CGImageRelease (image);
  207577. }
  207578. }
  207579. }
  207580. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207581. {
  207582. StringArray s;
  207583. s.add ("Software Renderer");
  207584. #if USE_COREGRAPHICS_RENDERING
  207585. s.add ("CoreGraphics Renderer");
  207586. #endif
  207587. return s;
  207588. }
  207589. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207590. {
  207591. return usingCoreGraphics ? 1 : 0;
  207592. }
  207593. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207594. {
  207595. #if USE_COREGRAPHICS_RENDERING
  207596. if (usingCoreGraphics != (index > 0))
  207597. {
  207598. usingCoreGraphics = index > 0;
  207599. [view setNeedsDisplay: true];
  207600. }
  207601. #endif
  207602. }
  207603. bool NSViewComponentPeer::canBecomeKeyWindow()
  207604. {
  207605. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207606. }
  207607. bool NSViewComponentPeer::windowShouldClose()
  207608. {
  207609. if (! isValidPeer (this))
  207610. return YES;
  207611. handleUserClosingWindow();
  207612. return NO;
  207613. }
  207614. void NSViewComponentPeer::redirectMovedOrResized()
  207615. {
  207616. handleMovedOrResized();
  207617. }
  207618. void NSViewComponentPeer::viewMovedToWindow()
  207619. {
  207620. if (isSharedWindow)
  207621. window = [view window];
  207622. }
  207623. void Desktop::createMouseInputSources()
  207624. {
  207625. mouseSources.add (new MouseInputSource (0, true));
  207626. }
  207627. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207628. {
  207629. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207630. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207631. // is apparently still available in 64-bit apps..
  207632. if (enableOrDisable)
  207633. {
  207634. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207635. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207636. }
  207637. else
  207638. {
  207639. SetSystemUIMode (kUIModeNormal, 0);
  207640. }
  207641. }
  207642. class AsyncRepaintMessage : public CallbackMessage
  207643. {
  207644. public:
  207645. NSViewComponentPeer* const peer;
  207646. const Rectangle<int> rect;
  207647. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207648. : peer (peer_), rect (rect_)
  207649. {
  207650. }
  207651. void messageCallback()
  207652. {
  207653. if (ComponentPeer::isValidPeer (peer))
  207654. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207655. }
  207656. };
  207657. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207658. {
  207659. if (insideDrawRect)
  207660. {
  207661. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207662. }
  207663. else
  207664. {
  207665. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207666. (float) w, (float) h)];
  207667. }
  207668. }
  207669. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207670. {
  207671. [view displayIfNeeded];
  207672. }
  207673. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207674. {
  207675. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207676. }
  207677. Image* juce_createIconForFile (const File& file)
  207678. {
  207679. const ScopedAutoReleasePool pool;
  207680. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207681. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207682. [NSGraphicsContext saveGraphicsState];
  207683. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207684. [image drawAtPoint: NSMakePoint (0, 0)
  207685. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207686. operation: NSCompositeSourceOver fraction: 1.0f];
  207687. [[NSGraphicsContext currentContext] flushGraphics];
  207688. [NSGraphicsContext restoreGraphicsState];
  207689. return result;
  207690. }
  207691. const int KeyPress::spaceKey = ' ';
  207692. const int KeyPress::returnKey = 0x0d;
  207693. const int KeyPress::escapeKey = 0x1b;
  207694. const int KeyPress::backspaceKey = 0x7f;
  207695. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207696. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207697. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207698. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207699. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207700. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207701. const int KeyPress::endKey = NSEndFunctionKey;
  207702. const int KeyPress::homeKey = NSHomeFunctionKey;
  207703. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207704. const int KeyPress::insertKey = -1;
  207705. const int KeyPress::tabKey = 9;
  207706. const int KeyPress::F1Key = NSF1FunctionKey;
  207707. const int KeyPress::F2Key = NSF2FunctionKey;
  207708. const int KeyPress::F3Key = NSF3FunctionKey;
  207709. const int KeyPress::F4Key = NSF4FunctionKey;
  207710. const int KeyPress::F5Key = NSF5FunctionKey;
  207711. const int KeyPress::F6Key = NSF6FunctionKey;
  207712. const int KeyPress::F7Key = NSF7FunctionKey;
  207713. const int KeyPress::F8Key = NSF8FunctionKey;
  207714. const int KeyPress::F9Key = NSF9FunctionKey;
  207715. const int KeyPress::F10Key = NSF10FunctionKey;
  207716. const int KeyPress::F11Key = NSF1FunctionKey;
  207717. const int KeyPress::F12Key = NSF12FunctionKey;
  207718. const int KeyPress::F13Key = NSF13FunctionKey;
  207719. const int KeyPress::F14Key = NSF14FunctionKey;
  207720. const int KeyPress::F15Key = NSF15FunctionKey;
  207721. const int KeyPress::F16Key = NSF16FunctionKey;
  207722. const int KeyPress::numberPad0 = 0x30020;
  207723. const int KeyPress::numberPad1 = 0x30021;
  207724. const int KeyPress::numberPad2 = 0x30022;
  207725. const int KeyPress::numberPad3 = 0x30023;
  207726. const int KeyPress::numberPad4 = 0x30024;
  207727. const int KeyPress::numberPad5 = 0x30025;
  207728. const int KeyPress::numberPad6 = 0x30026;
  207729. const int KeyPress::numberPad7 = 0x30027;
  207730. const int KeyPress::numberPad8 = 0x30028;
  207731. const int KeyPress::numberPad9 = 0x30029;
  207732. const int KeyPress::numberPadAdd = 0x3002a;
  207733. const int KeyPress::numberPadSubtract = 0x3002b;
  207734. const int KeyPress::numberPadMultiply = 0x3002c;
  207735. const int KeyPress::numberPadDivide = 0x3002d;
  207736. const int KeyPress::numberPadSeparator = 0x3002e;
  207737. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207738. const int KeyPress::numberPadEquals = 0x30030;
  207739. const int KeyPress::numberPadDelete = 0x30031;
  207740. const int KeyPress::playKey = 0x30000;
  207741. const int KeyPress::stopKey = 0x30001;
  207742. const int KeyPress::fastForwardKey = 0x30002;
  207743. const int KeyPress::rewindKey = 0x30003;
  207744. #endif
  207745. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207746. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207747. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207748. // compiled on its own).
  207749. #if JUCE_INCLUDED_FILE
  207750. #if JUCE_MAC
  207751. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  207752. {
  207753. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207754. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207755. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207756. [im release];
  207757. return (void*) c;
  207758. }
  207759. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  207760. {
  207761. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  207762. jassert (im != 0);
  207763. if (im == 0)
  207764. return 0;
  207765. return juce_createMouseCursorFromImage (*im,
  207766. (int) (hx * im->getWidth()),
  207767. (int) (hy * im->getHeight()));
  207768. }
  207769. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207770. {
  207771. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207772. MemoryBlock mb;
  207773. if (f.getChildFile (filename).loadFileAsData (mb))
  207774. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  207775. return 0;
  207776. }
  207777. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  207778. {
  207779. const ScopedAutoReleasePool pool;
  207780. NSCursor* c = 0;
  207781. switch (type)
  207782. {
  207783. case MouseCursor::NormalCursor:
  207784. c = [NSCursor arrowCursor];
  207785. break;
  207786. case MouseCursor::NoCursor:
  207787. {
  207788. Image blank (Image::ARGB, 8, 8, true);
  207789. return juce_createMouseCursorFromImage (blank, 0, 0);
  207790. }
  207791. case MouseCursor::DraggingHandCursor:
  207792. c = [NSCursor openHandCursor];
  207793. break;
  207794. case MouseCursor::CopyingCursor:
  207795. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207796. case MouseCursor::WaitCursor:
  207797. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207798. break;
  207799. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207800. case MouseCursor::IBeamCursor:
  207801. c = [NSCursor IBeamCursor];
  207802. break;
  207803. case MouseCursor::PointingHandCursor:
  207804. c = [NSCursor pointingHandCursor];
  207805. break;
  207806. case MouseCursor::LeftRightResizeCursor:
  207807. c = [NSCursor resizeLeftRightCursor];
  207808. break;
  207809. case MouseCursor::LeftEdgeResizeCursor:
  207810. c = [NSCursor resizeLeftCursor];
  207811. break;
  207812. case MouseCursor::RightEdgeResizeCursor:
  207813. c = [NSCursor resizeRightCursor];
  207814. break;
  207815. case MouseCursor::UpDownResizeCursor:
  207816. case MouseCursor::TopEdgeResizeCursor:
  207817. case MouseCursor::BottomEdgeResizeCursor:
  207818. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207819. case MouseCursor::TopLeftCornerResizeCursor:
  207820. case MouseCursor::BottomRightCornerResizeCursor:
  207821. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207822. case MouseCursor::TopRightCornerResizeCursor:
  207823. case MouseCursor::BottomLeftCornerResizeCursor:
  207824. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207825. case MouseCursor::UpDownLeftRightResizeCursor:
  207826. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207827. case MouseCursor::CrosshairCursor:
  207828. c = [NSCursor crosshairCursor];
  207829. break;
  207830. }
  207831. [c retain];
  207832. return (void*) c;
  207833. }
  207834. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  207835. {
  207836. NSCursor* c = (NSCursor*) cursorHandle;
  207837. [c release];
  207838. }
  207839. void MouseCursor::showInAllWindows() const throw()
  207840. {
  207841. showInWindow (0);
  207842. }
  207843. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  207844. {
  207845. NSCursor* const c = (NSCursor*) getHandle();
  207846. [c set];
  207847. }
  207848. #else
  207849. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  207850. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  207851. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  207852. void MouseCursor::showInAllWindows() const throw() {}
  207853. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  207854. #endif
  207855. #endif
  207856. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207857. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207858. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207859. // compiled on its own).
  207860. #if JUCE_INCLUDED_FILE
  207861. class NSViewComponentInternal : public ComponentMovementWatcher
  207862. {
  207863. Component* const owner;
  207864. NSViewComponentPeer* currentPeer;
  207865. bool wasShowing;
  207866. public:
  207867. NSView* const view;
  207868. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207869. : ComponentMovementWatcher (owner_),
  207870. owner (owner_),
  207871. currentPeer (0),
  207872. wasShowing (false),
  207873. view (view_)
  207874. {
  207875. [view_ retain];
  207876. if (owner_->isShowing())
  207877. componentPeerChanged();
  207878. }
  207879. ~NSViewComponentInternal()
  207880. {
  207881. [view removeFromSuperview];
  207882. [view release];
  207883. }
  207884. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207885. {
  207886. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207887. // The ComponentMovementWatcher version of this method avoids calling
  207888. // us when the top-level comp is resized, but for an NSView we need to know this
  207889. // because with inverted co-ords, we need to update the position even if the
  207890. // top-left pos hasn't changed
  207891. if (comp.isOnDesktop() && wasResized)
  207892. componentMovedOrResized (wasMoved, wasResized);
  207893. }
  207894. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207895. {
  207896. Component* const topComp = owner->getTopLevelComponent();
  207897. if (topComp->getPeer() != 0)
  207898. {
  207899. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  207900. NSRect r;
  207901. r.origin.x = (float) pos.getX();
  207902. r.origin.y = (float) pos.getY();
  207903. r.size.width = (float) owner->getWidth();
  207904. r.size.height = (float) owner->getHeight();
  207905. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207906. [view setFrame: r];
  207907. }
  207908. }
  207909. void componentPeerChanged()
  207910. {
  207911. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  207912. if (currentPeer != peer)
  207913. {
  207914. [view removeFromSuperview];
  207915. currentPeer = peer;
  207916. if (peer != 0)
  207917. {
  207918. [peer->view addSubview: view];
  207919. componentMovedOrResized (false, false);
  207920. }
  207921. }
  207922. [view setHidden: ! owner->isShowing()];
  207923. }
  207924. void componentVisibilityChanged (Component&)
  207925. {
  207926. componentPeerChanged();
  207927. }
  207928. juce_UseDebuggingNewOperator
  207929. private:
  207930. NSViewComponentInternal (const NSViewComponentInternal&);
  207931. NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  207932. };
  207933. NSViewComponent::NSViewComponent()
  207934. {
  207935. }
  207936. NSViewComponent::~NSViewComponent()
  207937. {
  207938. }
  207939. void NSViewComponent::setView (void* view)
  207940. {
  207941. if (view != getView())
  207942. {
  207943. if (view != 0)
  207944. info = new NSViewComponentInternal ((NSView*) view, this);
  207945. else
  207946. info = 0;
  207947. }
  207948. }
  207949. void* NSViewComponent::getView() const
  207950. {
  207951. return info == 0 ? 0 : info->view;
  207952. }
  207953. void NSViewComponent::paint (Graphics& g)
  207954. {
  207955. }
  207956. #endif
  207957. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  207958. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  207959. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207960. // compiled on its own).
  207961. #if JUCE_INCLUDED_FILE
  207962. AppleRemoteDevice::AppleRemoteDevice()
  207963. : device (0),
  207964. queue (0),
  207965. remoteId (0)
  207966. {
  207967. }
  207968. AppleRemoteDevice::~AppleRemoteDevice()
  207969. {
  207970. stop();
  207971. }
  207972. static io_object_t getAppleRemoteDevice()
  207973. {
  207974. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  207975. io_iterator_t iter = 0;
  207976. io_object_t iod = 0;
  207977. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  207978. && iter != 0)
  207979. {
  207980. iod = IOIteratorNext (iter);
  207981. }
  207982. IOObjectRelease (iter);
  207983. return iod;
  207984. }
  207985. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  207986. {
  207987. jassert (*device == 0);
  207988. io_name_t classname;
  207989. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  207990. {
  207991. IOCFPlugInInterface** cfPlugInInterface = 0;
  207992. SInt32 score = 0;
  207993. if (IOCreatePlugInInterfaceForService (iod,
  207994. kIOHIDDeviceUserClientTypeID,
  207995. kIOCFPlugInInterfaceID,
  207996. &cfPlugInInterface,
  207997. &score) == kIOReturnSuccess)
  207998. {
  207999. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  208000. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  208001. device);
  208002. (void) hr;
  208003. (*cfPlugInInterface)->Release (cfPlugInInterface);
  208004. }
  208005. }
  208006. return *device != 0;
  208007. }
  208008. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  208009. {
  208010. if (queue != 0)
  208011. return true;
  208012. stop();
  208013. bool result = false;
  208014. io_object_t iod = getAppleRemoteDevice();
  208015. if (iod != 0)
  208016. {
  208017. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  208018. result = true;
  208019. else
  208020. stop();
  208021. IOObjectRelease (iod);
  208022. }
  208023. return result;
  208024. }
  208025. void AppleRemoteDevice::stop()
  208026. {
  208027. if (queue != 0)
  208028. {
  208029. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  208030. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  208031. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  208032. queue = 0;
  208033. }
  208034. if (device != 0)
  208035. {
  208036. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  208037. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  208038. device = 0;
  208039. }
  208040. }
  208041. bool AppleRemoteDevice::isActive() const
  208042. {
  208043. return queue != 0;
  208044. }
  208045. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  208046. {
  208047. if (result == kIOReturnSuccess)
  208048. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  208049. }
  208050. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  208051. {
  208052. Array <int> cookies;
  208053. CFArrayRef elements;
  208054. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  208055. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  208056. return false;
  208057. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  208058. {
  208059. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  208060. // get the cookie
  208061. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  208062. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  208063. continue;
  208064. long number;
  208065. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  208066. continue;
  208067. cookies.add ((int) number);
  208068. }
  208069. CFRelease (elements);
  208070. if ((*(IOHIDDeviceInterface**) device)
  208071. ->open ((IOHIDDeviceInterface**) device,
  208072. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  208073. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  208074. {
  208075. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  208076. if (queue != 0)
  208077. {
  208078. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  208079. for (int i = 0; i < cookies.size(); ++i)
  208080. {
  208081. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  208082. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  208083. }
  208084. CFRunLoopSourceRef eventSource;
  208085. if ((*(IOHIDQueueInterface**) queue)
  208086. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  208087. {
  208088. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  208089. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  208090. {
  208091. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  208092. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  208093. return true;
  208094. }
  208095. }
  208096. }
  208097. }
  208098. return false;
  208099. }
  208100. void AppleRemoteDevice::handleCallbackInternal()
  208101. {
  208102. int totalValues = 0;
  208103. AbsoluteTime nullTime = { 0, 0 };
  208104. char cookies [12];
  208105. int numCookies = 0;
  208106. while (numCookies < numElementsInArray (cookies))
  208107. {
  208108. IOHIDEventStruct e;
  208109. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208110. break;
  208111. if ((int) e.elementCookie == 19)
  208112. {
  208113. remoteId = e.value;
  208114. buttonPressed (switched, false);
  208115. }
  208116. else
  208117. {
  208118. totalValues += e.value;
  208119. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208120. }
  208121. }
  208122. cookies [numCookies++] = 0;
  208123. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208124. static const char buttonPatterns[] =
  208125. {
  208126. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208127. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208128. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208129. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208130. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208131. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208132. 0x1f, 0x12, 0x04, 0x02, 0,
  208133. 0x1f, 0x12, 0x03, 0x02, 0,
  208134. 0x1f, 0x12, 0x1f, 0x12, 0,
  208135. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208136. 19, 0
  208137. };
  208138. int buttonNum = (int) menuButton;
  208139. int i = 0;
  208140. while (i < numElementsInArray (buttonPatterns))
  208141. {
  208142. if (strcmp (cookies, buttonPatterns + i) == 0)
  208143. {
  208144. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208145. break;
  208146. }
  208147. i += (int) strlen (buttonPatterns + i) + 1;
  208148. ++buttonNum;
  208149. }
  208150. }
  208151. #endif
  208152. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  208153. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  208154. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208155. // compiled on its own).
  208156. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208157. #if JUCE_MAC
  208158. END_JUCE_NAMESPACE
  208159. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208160. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208161. {
  208162. CriticalSection* contextLock;
  208163. bool needsUpdate;
  208164. }
  208165. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208166. - (bool) makeActive;
  208167. - (void) makeInactive;
  208168. - (void) reshape;
  208169. @end
  208170. @implementation ThreadSafeNSOpenGLView
  208171. - (id) initWithFrame: (NSRect) frameRect
  208172. pixelFormat: (NSOpenGLPixelFormat*) format
  208173. {
  208174. contextLock = new CriticalSection();
  208175. self = [super initWithFrame: frameRect pixelFormat: format];
  208176. if (self != nil)
  208177. [[NSNotificationCenter defaultCenter] addObserver: self
  208178. selector: @selector (_surfaceNeedsUpdate:)
  208179. name: NSViewGlobalFrameDidChangeNotification
  208180. object: self];
  208181. return self;
  208182. }
  208183. - (void) dealloc
  208184. {
  208185. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208186. delete contextLock;
  208187. [super dealloc];
  208188. }
  208189. - (bool) makeActive
  208190. {
  208191. const ScopedLock sl (*contextLock);
  208192. if ([self openGLContext] == 0)
  208193. return false;
  208194. [[self openGLContext] makeCurrentContext];
  208195. if (needsUpdate)
  208196. {
  208197. [super update];
  208198. needsUpdate = false;
  208199. }
  208200. return true;
  208201. }
  208202. - (void) makeInactive
  208203. {
  208204. const ScopedLock sl (*contextLock);
  208205. [NSOpenGLContext clearCurrentContext];
  208206. }
  208207. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208208. {
  208209. const ScopedLock sl (*contextLock);
  208210. needsUpdate = true;
  208211. }
  208212. - (void) update
  208213. {
  208214. const ScopedLock sl (*contextLock);
  208215. needsUpdate = true;
  208216. }
  208217. - (void) reshape
  208218. {
  208219. const ScopedLock sl (*contextLock);
  208220. needsUpdate = true;
  208221. }
  208222. @end
  208223. BEGIN_JUCE_NAMESPACE
  208224. class WindowedGLContext : public OpenGLContext
  208225. {
  208226. public:
  208227. WindowedGLContext (Component* const component,
  208228. const OpenGLPixelFormat& pixelFormat_,
  208229. NSOpenGLContext* sharedContext)
  208230. : renderContext (0),
  208231. pixelFormat (pixelFormat_)
  208232. {
  208233. jassert (component != 0);
  208234. NSOpenGLPixelFormatAttribute attribs [64];
  208235. int n = 0;
  208236. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208237. attribs[n++] = NSOpenGLPFAAccelerated;
  208238. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208239. attribs[n++] = NSOpenGLPFAColorSize;
  208240. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208241. pixelFormat.greenBits,
  208242. pixelFormat.blueBits);
  208243. attribs[n++] = NSOpenGLPFAAlphaSize;
  208244. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208245. attribs[n++] = NSOpenGLPFADepthSize;
  208246. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208247. attribs[n++] = NSOpenGLPFAStencilSize;
  208248. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208249. attribs[n++] = NSOpenGLPFAAccumSize;
  208250. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208251. pixelFormat.accumulationBufferGreenBits,
  208252. pixelFormat.accumulationBufferBlueBits,
  208253. pixelFormat.accumulationBufferAlphaBits);
  208254. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208255. attribs[n++] = NSOpenGLPFASampleBuffers;
  208256. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208257. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208258. attribs[n++] = NSOpenGLPFANoRecovery;
  208259. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208260. NSOpenGLPixelFormat* format
  208261. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208262. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208263. pixelFormat: format];
  208264. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208265. shareContext: sharedContext] autorelease];
  208266. const GLint swapInterval = 1;
  208267. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208268. [view setOpenGLContext: renderContext];
  208269. [renderContext setView: view];
  208270. [format release];
  208271. viewHolder = new NSViewComponentInternal (view, component);
  208272. }
  208273. ~WindowedGLContext()
  208274. {
  208275. makeInactive();
  208276. [renderContext clearDrawable];
  208277. viewHolder = 0;
  208278. }
  208279. bool makeActive() const throw()
  208280. {
  208281. jassert (renderContext != 0);
  208282. [view makeActive];
  208283. return isActive();
  208284. }
  208285. bool makeInactive() const throw()
  208286. {
  208287. [view makeInactive];
  208288. return true;
  208289. }
  208290. bool isActive() const throw()
  208291. {
  208292. return [NSOpenGLContext currentContext] == renderContext;
  208293. }
  208294. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208295. void* getRawContext() const throw() { return renderContext; }
  208296. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208297. {
  208298. }
  208299. void swapBuffers()
  208300. {
  208301. [renderContext flushBuffer];
  208302. }
  208303. bool setSwapInterval (const int numFramesPerSwap)
  208304. {
  208305. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208306. forParameter: NSOpenGLCPSwapInterval];
  208307. return true;
  208308. }
  208309. int getSwapInterval() const
  208310. {
  208311. GLint numFrames = 0;
  208312. [renderContext getValues: &numFrames
  208313. forParameter: NSOpenGLCPSwapInterval];
  208314. return numFrames;
  208315. }
  208316. void repaint()
  208317. {
  208318. // we need to invalidate the juce view that holds this gl view, to make it
  208319. // cause a repaint callback
  208320. NSView* v = (NSView*) viewHolder->view;
  208321. NSRect r = [v frame];
  208322. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208323. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208324. // repaint message, thus never causing our paint() callback, and never repainting
  208325. // the comp. So invalidating just a little bit around the edge helps..
  208326. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208327. }
  208328. void* getNativeWindowHandle() const { return viewHolder->view; }
  208329. juce_UseDebuggingNewOperator
  208330. NSOpenGLContext* renderContext;
  208331. ThreadSafeNSOpenGLView* view;
  208332. private:
  208333. OpenGLPixelFormat pixelFormat;
  208334. ScopedPointer <NSViewComponentInternal> viewHolder;
  208335. WindowedGLContext (const WindowedGLContext&);
  208336. WindowedGLContext& operator= (const WindowedGLContext&);
  208337. };
  208338. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208339. const OpenGLPixelFormat& pixelFormat,
  208340. const OpenGLContext* const contextToShareWith)
  208341. {
  208342. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  208343. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  208344. return (c->renderContext != 0) ? c.release() : 0;
  208345. }
  208346. void* OpenGLComponent::getNativeWindowHandle() const
  208347. {
  208348. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  208349. : 0;
  208350. }
  208351. void juce_glViewport (const int w, const int h)
  208352. {
  208353. glViewport (0, 0, w, h);
  208354. }
  208355. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208356. OwnedArray <OpenGLPixelFormat>& results)
  208357. {
  208358. /* GLint attribs [64];
  208359. int n = 0;
  208360. attribs[n++] = AGL_RGBA;
  208361. attribs[n++] = AGL_DOUBLEBUFFER;
  208362. attribs[n++] = AGL_ACCELERATED;
  208363. attribs[n++] = AGL_NO_RECOVERY;
  208364. attribs[n++] = AGL_NONE;
  208365. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208366. while (p != 0)
  208367. {
  208368. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208369. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208370. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208371. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208372. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208373. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208374. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208375. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208376. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208377. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208378. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208379. results.add (pf);
  208380. p = aglNextPixelFormat (p);
  208381. }*/
  208382. //jassertfalse //xxx can't see how you do this in cocoa!
  208383. }
  208384. #else
  208385. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208386. const OpenGLPixelFormat& pixelFormat,
  208387. const OpenGLContext* const contextToShareWith)
  208388. {
  208389. return 0;
  208390. }
  208391. void juce_glViewport (const int w, const int h)
  208392. {
  208393. //glViewport (0, 0, w, h);
  208394. }
  208395. #endif
  208396. #endif
  208397. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208398. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208399. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208400. // compiled on its own).
  208401. #if JUCE_INCLUDED_FILE
  208402. class JuceMainMenuHandler;
  208403. END_JUCE_NAMESPACE
  208404. using namespace JUCE_NAMESPACE;
  208405. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208406. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208407. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208408. #else
  208409. @interface JuceMenuCallback : NSObject
  208410. #endif
  208411. {
  208412. JuceMainMenuHandler* owner;
  208413. }
  208414. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208415. - (void) dealloc;
  208416. - (void) menuItemInvoked: (id) menu;
  208417. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208418. @end
  208419. BEGIN_JUCE_NAMESPACE
  208420. class JuceMainMenuHandler : private MenuBarModelListener,
  208421. private DeletedAtShutdown
  208422. {
  208423. public:
  208424. static JuceMainMenuHandler* instance;
  208425. JuceMainMenuHandler()
  208426. : currentModel (0),
  208427. lastUpdateTime (0)
  208428. {
  208429. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208430. }
  208431. ~JuceMainMenuHandler()
  208432. {
  208433. setMenu (0);
  208434. jassert (instance == this);
  208435. instance = 0;
  208436. [callback release];
  208437. }
  208438. void setMenu (MenuBarModel* const newMenuBarModel)
  208439. {
  208440. if (currentModel != newMenuBarModel)
  208441. {
  208442. if (currentModel != 0)
  208443. currentModel->removeListener (this);
  208444. currentModel = newMenuBarModel;
  208445. if (currentModel != 0)
  208446. currentModel->addListener (this);
  208447. menuBarItemsChanged (0);
  208448. }
  208449. }
  208450. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208451. const String& name, const int menuId, const int tag)
  208452. {
  208453. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208454. action: nil
  208455. keyEquivalent: @""];
  208456. [item setTag: tag];
  208457. NSMenu* sub = createMenu (child, name, menuId, tag);
  208458. [parent setSubmenu: sub forItem: item];
  208459. [sub setAutoenablesItems: false];
  208460. [sub release];
  208461. }
  208462. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208463. const String& name, const int menuId, const int tag)
  208464. {
  208465. [parentItem setTag: tag];
  208466. NSMenu* menu = [parentItem submenu];
  208467. [menu setTitle: juceStringToNS (name)];
  208468. while ([menu numberOfItems] > 0)
  208469. [menu removeItemAtIndex: 0];
  208470. PopupMenu::MenuItemIterator iter (menuToCopy);
  208471. while (iter.next())
  208472. addMenuItem (iter, menu, menuId, tag);
  208473. [menu setAutoenablesItems: false];
  208474. [menu update];
  208475. }
  208476. void menuBarItemsChanged (MenuBarModel*)
  208477. {
  208478. lastUpdateTime = Time::getMillisecondCounter();
  208479. StringArray menuNames;
  208480. if (currentModel != 0)
  208481. menuNames = currentModel->getMenuBarNames();
  208482. NSMenu* menuBar = [NSApp mainMenu];
  208483. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208484. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208485. int menuId = 1;
  208486. for (int i = 0; i < menuNames.size(); ++i)
  208487. {
  208488. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208489. if (i >= [menuBar numberOfItems] - 1)
  208490. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208491. else
  208492. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208493. }
  208494. }
  208495. static void flashMenuBar (NSMenu* menu)
  208496. {
  208497. if ([[menu title] isEqualToString: @"Apple"])
  208498. return;
  208499. [menu retain];
  208500. const unichar f35Key = NSF35FunctionKey;
  208501. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208502. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208503. action: nil
  208504. keyEquivalent: f35String];
  208505. [item setTarget: nil];
  208506. [menu insertItem: item atIndex: [menu numberOfItems]];
  208507. [item release];
  208508. if ([menu indexOfItem: item] >= 0)
  208509. {
  208510. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208511. location: NSZeroPoint
  208512. modifierFlags: NSCommandKeyMask
  208513. timestamp: 0
  208514. windowNumber: 0
  208515. context: [NSGraphicsContext currentContext]
  208516. characters: f35String
  208517. charactersIgnoringModifiers: f35String
  208518. isARepeat: NO
  208519. keyCode: 0];
  208520. [menu performKeyEquivalent: f35Event];
  208521. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208522. }
  208523. [menu release];
  208524. }
  208525. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208526. {
  208527. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208528. {
  208529. NSMenuItem* m = [menu itemAtIndex: i];
  208530. if ([m tag] == info.commandID)
  208531. return m;
  208532. if ([m submenu] != 0)
  208533. {
  208534. NSMenuItem* found = findMenuItem ([m submenu], info);
  208535. if (found != 0)
  208536. return found;
  208537. }
  208538. }
  208539. return 0;
  208540. }
  208541. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208542. {
  208543. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208544. if (item != 0)
  208545. flashMenuBar ([item menu]);
  208546. }
  208547. void updateMenus()
  208548. {
  208549. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208550. menuBarItemsChanged (0);
  208551. }
  208552. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208553. {
  208554. if (currentModel != 0)
  208555. {
  208556. if (commandManager != 0)
  208557. {
  208558. ApplicationCommandTarget::InvocationInfo info (commandId);
  208559. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208560. commandManager->invoke (info, true);
  208561. }
  208562. currentModel->menuItemSelected (commandId, topLevelIndex);
  208563. }
  208564. }
  208565. MenuBarModel* currentModel;
  208566. uint32 lastUpdateTime;
  208567. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208568. const int topLevelMenuId, const int topLevelIndex)
  208569. {
  208570. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf (T("<end>"), false, true));
  208571. if (text == 0)
  208572. text = @"";
  208573. if (iter.isSeparator)
  208574. {
  208575. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208576. }
  208577. else if (iter.isSectionHeader)
  208578. {
  208579. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208580. action: nil
  208581. keyEquivalent: @""];
  208582. [item setEnabled: false];
  208583. }
  208584. else if (iter.subMenu != 0)
  208585. {
  208586. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208587. action: nil
  208588. keyEquivalent: @""];
  208589. [item setTag: iter.itemId];
  208590. [item setEnabled: iter.isEnabled];
  208591. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208592. [sub setDelegate: nil];
  208593. [menuToAddTo setSubmenu: sub forItem: item];
  208594. [sub release];
  208595. }
  208596. else
  208597. {
  208598. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208599. action: @selector (menuItemInvoked:)
  208600. keyEquivalent: @""];
  208601. [item setTag: iter.itemId];
  208602. [item setEnabled: iter.isEnabled];
  208603. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208604. [item setTarget: (id) callback];
  208605. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208606. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208607. [item setRepresentedObject: info];
  208608. if (iter.commandManager != 0)
  208609. {
  208610. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208611. ->getKeyPressesAssignedToCommand (iter.itemId));
  208612. if (keyPresses.size() > 0)
  208613. {
  208614. const KeyPress& kp = keyPresses.getReference(0);
  208615. juce_wchar key = kp.getTextCharacter();
  208616. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208617. key = NSBackspaceCharacter;
  208618. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208619. key = NSDeleteCharacter;
  208620. else if (key == 0)
  208621. key = (juce_wchar) kp.getKeyCode();
  208622. unsigned int mods = 0;
  208623. if (kp.getModifiers().isShiftDown())
  208624. mods |= NSShiftKeyMask;
  208625. if (kp.getModifiers().isCtrlDown())
  208626. mods |= NSControlKeyMask;
  208627. if (kp.getModifiers().isAltDown())
  208628. mods |= NSAlternateKeyMask;
  208629. if (kp.getModifiers().isCommandDown())
  208630. mods |= NSCommandKeyMask;
  208631. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208632. [item setKeyEquivalentModifierMask: mods];
  208633. }
  208634. }
  208635. }
  208636. }
  208637. JuceMenuCallback* callback;
  208638. private:
  208639. NSMenu* createMenu (const PopupMenu menu,
  208640. const String& menuName,
  208641. const int topLevelMenuId,
  208642. const int topLevelIndex)
  208643. {
  208644. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208645. [m setAutoenablesItems: false];
  208646. [m setDelegate: callback];
  208647. PopupMenu::MenuItemIterator iter (menu);
  208648. while (iter.next())
  208649. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208650. [m update];
  208651. return m;
  208652. }
  208653. };
  208654. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208655. END_JUCE_NAMESPACE
  208656. @implementation JuceMenuCallback
  208657. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208658. {
  208659. [super init];
  208660. owner = owner_;
  208661. return self;
  208662. }
  208663. - (void) dealloc
  208664. {
  208665. [super dealloc];
  208666. }
  208667. - (void) menuItemInvoked: (id) menu
  208668. {
  208669. NSMenuItem* item = (NSMenuItem*) menu;
  208670. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208671. {
  208672. // 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
  208673. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208674. // into the focused component and let it trigger the menu item indirectly.
  208675. NSEvent* e = [NSApp currentEvent];
  208676. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208677. {
  208678. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent() != 0)
  208679. {
  208680. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208681. if (peer != 0)
  208682. {
  208683. if ([e type] == NSKeyDown)
  208684. peer->redirectKeyDown (e);
  208685. else
  208686. peer->redirectKeyUp (e);
  208687. return;
  208688. }
  208689. }
  208690. }
  208691. NSArray* info = (NSArray*) [item representedObject];
  208692. owner->invoke ((int) [item tag],
  208693. (ApplicationCommandManager*) (pointer_sized_int)
  208694. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208695. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208696. }
  208697. }
  208698. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208699. {
  208700. if (JuceMainMenuHandler::instance != 0)
  208701. JuceMainMenuHandler::instance->updateMenus();
  208702. }
  208703. @end
  208704. BEGIN_JUCE_NAMESPACE
  208705. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208706. const PopupMenu* extraItems)
  208707. {
  208708. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208709. {
  208710. PopupMenu::MenuItemIterator iter (*extraItems);
  208711. while (iter.next())
  208712. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208713. [menu addItem: [NSMenuItem separatorItem]];
  208714. }
  208715. NSMenuItem* item;
  208716. // Services...
  208717. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208718. action: nil keyEquivalent: @""];
  208719. [menu addItem: item];
  208720. [item release];
  208721. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208722. [menu setSubmenu: servicesMenu forItem: item];
  208723. [NSApp setServicesMenu: servicesMenu];
  208724. [servicesMenu release];
  208725. [menu addItem: [NSMenuItem separatorItem]];
  208726. // Hide + Show stuff...
  208727. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208728. action: @selector (hide:) keyEquivalent: @"h"];
  208729. [item setTarget: NSApp];
  208730. [menu addItem: item];
  208731. [item release];
  208732. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208733. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208734. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208735. [item setTarget: NSApp];
  208736. [menu addItem: item];
  208737. [item release];
  208738. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208739. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208740. [item setTarget: NSApp];
  208741. [menu addItem: item];
  208742. [item release];
  208743. [menu addItem: [NSMenuItem separatorItem]];
  208744. // Quit item....
  208745. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208746. action: @selector (terminate:) keyEquivalent: @"q"];
  208747. [item setTarget: NSApp];
  208748. [menu addItem: item];
  208749. [item release];
  208750. return menu;
  208751. }
  208752. // Since our app has no NIB, this initialises a standard app menu...
  208753. static void rebuildMainMenu (const PopupMenu* extraItems)
  208754. {
  208755. // this can't be used in a plugin!
  208756. jassert (JUCEApplication::getInstance() != 0);
  208757. if (JUCEApplication::getInstance() != 0)
  208758. {
  208759. const ScopedAutoReleasePool pool;
  208760. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208761. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208762. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208763. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208764. [mainMenu setSubmenu: appMenu forItem: item];
  208765. [NSApp setMainMenu: mainMenu];
  208766. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208767. [appMenu release];
  208768. [mainMenu release];
  208769. }
  208770. }
  208771. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208772. const PopupMenu* extraAppleMenuItems)
  208773. {
  208774. if (getMacMainMenu() != newMenuBarModel)
  208775. {
  208776. const ScopedAutoReleasePool pool;
  208777. if (newMenuBarModel == 0)
  208778. {
  208779. delete JuceMainMenuHandler::instance;
  208780. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  208781. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  208782. extraAppleMenuItems = 0;
  208783. }
  208784. else
  208785. {
  208786. if (JuceMainMenuHandler::instance == 0)
  208787. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  208788. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  208789. }
  208790. }
  208791. rebuildMainMenu (extraAppleMenuItems);
  208792. if (newMenuBarModel != 0)
  208793. newMenuBarModel->menuItemsChanged();
  208794. }
  208795. MenuBarModel* MenuBarModel::getMacMainMenu()
  208796. {
  208797. return JuceMainMenuHandler::instance != 0
  208798. ? JuceMainMenuHandler::instance->currentModel : 0;
  208799. }
  208800. void initialiseMainMenu()
  208801. {
  208802. if (JUCEApplication::getInstance() != 0) // only needed in an app
  208803. rebuildMainMenu (0);
  208804. }
  208805. #endif
  208806. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  208807. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  208808. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208809. // compiled on its own).
  208810. #if JUCE_INCLUDED_FILE
  208811. #if JUCE_MAC
  208812. END_JUCE_NAMESPACE
  208813. using namespace JUCE_NAMESPACE;
  208814. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  208815. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208816. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  208817. #else
  208818. @interface JuceFileChooserDelegate : NSObject
  208819. #endif
  208820. {
  208821. StringArray* filters;
  208822. }
  208823. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  208824. - (void) dealloc;
  208825. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  208826. @end
  208827. @implementation JuceFileChooserDelegate
  208828. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  208829. {
  208830. [super init];
  208831. filters = filters_;
  208832. return self;
  208833. }
  208834. - (void) dealloc
  208835. {
  208836. delete filters;
  208837. [super dealloc];
  208838. }
  208839. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  208840. {
  208841. const File f (nsStringToJuce (filename));
  208842. for (int i = filters->size(); --i >= 0;)
  208843. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  208844. return true;
  208845. return f.isDirectory();
  208846. }
  208847. @end
  208848. BEGIN_JUCE_NAMESPACE
  208849. void FileChooser::showPlatformDialog (Array<File>& results,
  208850. const String& title,
  208851. const File& currentFileOrDirectory,
  208852. const String& filter,
  208853. bool selectsDirectory,
  208854. bool selectsFiles,
  208855. bool isSaveDialogue,
  208856. bool warnAboutOverwritingExistingFiles,
  208857. bool selectMultipleFiles,
  208858. FilePreviewComponent* extraInfoComponent)
  208859. {
  208860. const ScopedAutoReleasePool pool;
  208861. StringArray* filters = new StringArray();
  208862. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  208863. filters->trim();
  208864. filters->removeEmptyStrings();
  208865. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  208866. [delegate autorelease];
  208867. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  208868. : [NSOpenPanel openPanel];
  208869. [panel setTitle: juceStringToNS (title)];
  208870. if (! isSaveDialogue)
  208871. {
  208872. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208873. [openPanel setCanChooseDirectories: selectsDirectory];
  208874. [openPanel setCanChooseFiles: selectsFiles];
  208875. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  208876. }
  208877. [panel setDelegate: delegate];
  208878. if (isSaveDialogue || selectsDirectory)
  208879. [panel setCanCreateDirectories: YES];
  208880. String directory, filename;
  208881. if (currentFileOrDirectory.isDirectory())
  208882. {
  208883. directory = currentFileOrDirectory.getFullPathName();
  208884. }
  208885. else
  208886. {
  208887. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  208888. filename = currentFileOrDirectory.getFileName();
  208889. }
  208890. if ([panel runModalForDirectory: juceStringToNS (directory)
  208891. file: juceStringToNS (filename)]
  208892. == NSOKButton)
  208893. {
  208894. if (isSaveDialogue)
  208895. {
  208896. results.add (File (nsStringToJuce ([panel filename])));
  208897. }
  208898. else
  208899. {
  208900. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208901. NSArray* urls = [openPanel filenames];
  208902. for (unsigned int i = 0; i < [urls count]; ++i)
  208903. {
  208904. NSString* f = [urls objectAtIndex: i];
  208905. results.add (File (nsStringToJuce (f)));
  208906. }
  208907. }
  208908. }
  208909. [panel setDelegate: nil];
  208910. }
  208911. #else
  208912. void FileChooser::showPlatformDialog (Array<File>& results,
  208913. const String& title,
  208914. const File& currentFileOrDirectory,
  208915. const String& filter,
  208916. bool selectsDirectory,
  208917. bool selectsFiles,
  208918. bool isSaveDialogue,
  208919. bool warnAboutOverwritingExistingFiles,
  208920. bool selectMultipleFiles,
  208921. FilePreviewComponent* extraInfoComponent)
  208922. {
  208923. const ScopedAutoReleasePool pool;
  208924. jassertfalse //xxx to do
  208925. }
  208926. #endif
  208927. #endif
  208928. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  208929. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  208930. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208931. // compiled on its own).
  208932. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  208933. END_JUCE_NAMESPACE
  208934. #define NonInterceptingQTMovieView MakeObjCClassName(NonInterceptingQTMovieView)
  208935. @interface NonInterceptingQTMovieView : QTMovieView
  208936. {
  208937. }
  208938. - (id) initWithFrame: (NSRect) frame;
  208939. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent;
  208940. - (NSView*) hitTest: (NSPoint) p;
  208941. @end
  208942. @implementation NonInterceptingQTMovieView
  208943. - (id) initWithFrame: (NSRect) frame
  208944. {
  208945. self = [super initWithFrame: frame];
  208946. [self setNextResponder: [self superview]];
  208947. return self;
  208948. }
  208949. - (void) dealloc
  208950. {
  208951. [super dealloc];
  208952. }
  208953. - (NSView*) hitTest: (NSPoint) point
  208954. {
  208955. return [self isControllerVisible] ? [super hitTest: point] : nil;
  208956. }
  208957. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent
  208958. {
  208959. return YES;
  208960. }
  208961. @end
  208962. BEGIN_JUCE_NAMESPACE
  208963. #define theMovie ((QTMovie*) movie)
  208964. QuickTimeMovieComponent::QuickTimeMovieComponent()
  208965. : movie (0)
  208966. {
  208967. setOpaque (true);
  208968. setVisible (true);
  208969. QTMovieView* view = [[NonInterceptingQTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  208970. setView (view);
  208971. [view release];
  208972. }
  208973. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  208974. {
  208975. closeMovie();
  208976. setView (0);
  208977. }
  208978. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  208979. {
  208980. return true;
  208981. }
  208982. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  208983. {
  208984. // unfortunately, QTMovie objects can only be created on the main thread..
  208985. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  208986. QTMovie* movie = 0;
  208987. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  208988. if (fin != 0)
  208989. {
  208990. movieFile = fin->getFile();
  208991. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  208992. error: nil];
  208993. }
  208994. else
  208995. {
  208996. MemoryBlock temp;
  208997. movieStream->readIntoMemoryBlock (temp);
  208998. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  208999. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  209000. {
  209001. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  209002. length: temp.getSize()]
  209003. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  209004. MIMEType: @""]
  209005. error: nil];
  209006. if (movie != 0)
  209007. break;
  209008. }
  209009. }
  209010. return movie;
  209011. }
  209012. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  209013. const bool isControllerVisible_)
  209014. {
  209015. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  209016. }
  209017. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  209018. const bool controllerVisible_)
  209019. {
  209020. closeMovie();
  209021. if (getPeer() == 0)
  209022. {
  209023. // To open a movie, this component must be visible inside a functioning window, so that
  209024. // the QT control can be assigned to the window.
  209025. jassertfalse
  209026. return false;
  209027. }
  209028. movie = openMovieFromStream (movieStream, movieFile);
  209029. [theMovie retain];
  209030. QTMovieView* view = (QTMovieView*) getView();
  209031. [view setMovie: theMovie];
  209032. [view setControllerVisible: controllerVisible_];
  209033. setLooping (looping);
  209034. return movie != nil;
  209035. }
  209036. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  209037. const bool isControllerVisible_)
  209038. {
  209039. // unfortunately, QTMovie objects can only be created on the main thread..
  209040. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209041. closeMovie();
  209042. if (getPeer() == 0)
  209043. {
  209044. // To open a movie, this component must be visible inside a functioning window, so that
  209045. // the QT control can be assigned to the window.
  209046. jassertfalse
  209047. return false;
  209048. }
  209049. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  209050. NSError* err;
  209051. if ([QTMovie canInitWithURL: url])
  209052. movie = [QTMovie movieWithURL: url error: &err];
  209053. [theMovie retain];
  209054. QTMovieView* view = (QTMovieView*) getView();
  209055. [view setMovie: theMovie];
  209056. [view setControllerVisible: controllerVisible];
  209057. setLooping (looping);
  209058. return movie != nil;
  209059. }
  209060. void QuickTimeMovieComponent::closeMovie()
  209061. {
  209062. stop();
  209063. QTMovieView* view = (QTMovieView*) getView();
  209064. [view setMovie: nil];
  209065. [theMovie release];
  209066. movie = 0;
  209067. movieFile = File::nonexistent;
  209068. }
  209069. bool QuickTimeMovieComponent::isMovieOpen() const
  209070. {
  209071. return movie != nil;
  209072. }
  209073. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  209074. {
  209075. return movieFile;
  209076. }
  209077. void QuickTimeMovieComponent::play()
  209078. {
  209079. [theMovie play];
  209080. }
  209081. void QuickTimeMovieComponent::stop()
  209082. {
  209083. [theMovie stop];
  209084. }
  209085. bool QuickTimeMovieComponent::isPlaying() const
  209086. {
  209087. return movie != 0 && [theMovie rate] != 0;
  209088. }
  209089. void QuickTimeMovieComponent::setPosition (const double seconds)
  209090. {
  209091. if (movie != 0)
  209092. {
  209093. QTTime t;
  209094. t.timeValue = (uint64) (100000.0 * seconds);
  209095. t.timeScale = 100000;
  209096. t.flags = 0;
  209097. [theMovie setCurrentTime: t];
  209098. }
  209099. }
  209100. double QuickTimeMovieComponent::getPosition() const
  209101. {
  209102. if (movie == 0)
  209103. return 0.0;
  209104. QTTime t = [theMovie currentTime];
  209105. return t.timeValue / (double) t.timeScale;
  209106. }
  209107. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  209108. {
  209109. [theMovie setRate: newSpeed];
  209110. }
  209111. double QuickTimeMovieComponent::getMovieDuration() const
  209112. {
  209113. if (movie == 0)
  209114. return 0.0;
  209115. QTTime t = [theMovie duration];
  209116. return t.timeValue / (double) t.timeScale;
  209117. }
  209118. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  209119. {
  209120. looping = shouldLoop;
  209121. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209122. forKey: QTMovieLoopsAttribute];
  209123. }
  209124. bool QuickTimeMovieComponent::isLooping() const
  209125. {
  209126. return looping;
  209127. }
  209128. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209129. {
  209130. [theMovie setVolume: newVolume];
  209131. }
  209132. float QuickTimeMovieComponent::getMovieVolume() const
  209133. {
  209134. return movie != 0 ? [theMovie volume] : 0.0f;
  209135. }
  209136. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209137. {
  209138. width = 0;
  209139. height = 0;
  209140. if (movie != 0)
  209141. {
  209142. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209143. width = (int) s.width;
  209144. height = (int) s.height;
  209145. }
  209146. }
  209147. void QuickTimeMovieComponent::paint (Graphics& g)
  209148. {
  209149. if (movie == 0)
  209150. g.fillAll (Colours::black);
  209151. }
  209152. bool QuickTimeMovieComponent::isControllerVisible() const
  209153. {
  209154. return controllerVisible;
  209155. }
  209156. void QuickTimeMovieComponent::goToStart()
  209157. {
  209158. setPosition (0.0);
  209159. }
  209160. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  209161. const RectanglePlacement& placement)
  209162. {
  209163. int normalWidth, normalHeight;
  209164. getMovieNormalSize (normalWidth, normalHeight);
  209165. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209166. {
  209167. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209168. placement.applyTo (x, y, w, h,
  209169. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209170. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209171. if (w > 0 && h > 0)
  209172. {
  209173. setBounds (roundToInt (x), roundToInt (y),
  209174. roundToInt (w), roundToInt (h));
  209175. }
  209176. }
  209177. else
  209178. {
  209179. setBounds (spaceToFitWithin);
  209180. }
  209181. }
  209182. #if ! (JUCE_MAC && JUCE_64BIT)
  209183. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209184. {
  209185. if (movieStream == 0)
  209186. return false;
  209187. File file;
  209188. QTMovie* movie = openMovieFromStream (movieStream, file);
  209189. if (movie != nil)
  209190. result = [movie quickTimeMovie];
  209191. return movie != nil;
  209192. }
  209193. #endif
  209194. #endif
  209195. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209196. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  209197. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209198. // compiled on its own).
  209199. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209200. const int kilobytesPerSecond1x = 176;
  209201. END_JUCE_NAMESPACE
  209202. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209203. @interface OpenDiskDevice : NSObject
  209204. {
  209205. @public
  209206. DRDevice* device;
  209207. NSMutableArray* tracks;
  209208. bool underrunProtection;
  209209. }
  209210. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device;
  209211. - (void) dealloc;
  209212. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209213. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209214. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed;
  209215. @end
  209216. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209217. @interface AudioTrackProducer : NSObject
  209218. {
  209219. JUCE_NAMESPACE::AudioSource* source;
  209220. int readPosition, lengthInFrames;
  209221. }
  209222. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209223. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209224. - (void) dealloc;
  209225. - (void) setupTrackProperties: (DRTrack*) track;
  209226. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209227. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209228. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209229. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209230. toMedia:(NSDictionary*)mediaInfo;
  209231. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209232. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209233. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209234. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209235. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209236. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209237. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209238. ioFlags:(uint32_t*)flags;
  209239. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209240. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209241. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209242. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209243. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209244. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209245. ioFlags:(uint32_t*)flags;
  209246. @end
  209247. @implementation OpenDiskDevice
  209248. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device_
  209249. {
  209250. [super init];
  209251. device = device_;
  209252. tracks = [[NSMutableArray alloc] init];
  209253. underrunProtection = true;
  209254. return self;
  209255. }
  209256. - (void) dealloc
  209257. {
  209258. [tracks release];
  209259. [super dealloc];
  209260. }
  209261. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209262. {
  209263. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209264. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209265. [p setupTrackProperties: t];
  209266. [tracks addObject: t];
  209267. [t release];
  209268. [p release];
  209269. }
  209270. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209271. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed
  209272. {
  209273. DRBurn* burn = [DRBurn burnForDevice: device];
  209274. if (! [device acquireExclusiveAccess])
  209275. {
  209276. *error = "Couldn't open or write to the CD device";
  209277. return;
  209278. }
  209279. [device acquireMediaReservation];
  209280. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209281. [d autorelease];
  209282. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209283. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209284. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount) forKey: DRBurnCompletionActionKey];
  209285. if (burnSpeed > 0)
  209286. [d setObject: [NSNumber numberWithFloat: burnSpeed * JUCE_NAMESPACE::kilobytesPerSecond1x] forKey: DRBurnRequestedSpeedKey];
  209287. if (! underrunProtection)
  209288. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnUnderrunProtectionKey];
  209289. [burn setProperties: d];
  209290. [burn writeLayout: tracks];
  209291. for (;;)
  209292. {
  209293. JUCE_NAMESPACE::Thread::sleep (300);
  209294. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209295. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209296. {
  209297. [burn abort];
  209298. *error = "User cancelled the write operation";
  209299. break;
  209300. }
  209301. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209302. {
  209303. *error = "Write operation failed";
  209304. break;
  209305. }
  209306. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209307. {
  209308. break;
  209309. }
  209310. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209311. objectForKey: DRErrorStatusErrorStringKey];
  209312. if ([err length] > 0)
  209313. {
  209314. *error = JUCE_NAMESPACE::String::fromUTF8 ([err UTF8String]);
  209315. break;
  209316. }
  209317. }
  209318. [device releaseMediaReservation];
  209319. [device releaseExclusiveAccess];
  209320. }
  209321. @end
  209322. @implementation AudioTrackProducer
  209323. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209324. {
  209325. lengthInFrames = lengthInFrames_;
  209326. readPosition = 0;
  209327. return self;
  209328. }
  209329. - (void) setupTrackProperties: (DRTrack*) track
  209330. {
  209331. NSMutableDictionary* p = [[track properties] mutableCopy];
  209332. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209333. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209334. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209335. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209336. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209337. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209338. [track setProperties: p];
  209339. [p release];
  209340. }
  209341. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209342. {
  209343. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209344. if (s != nil)
  209345. s->source = source_;
  209346. return s;
  209347. }
  209348. - (void) dealloc
  209349. {
  209350. if (source != 0)
  209351. {
  209352. source->releaseResources();
  209353. delete source;
  209354. }
  209355. [super dealloc];
  209356. }
  209357. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209358. {
  209359. }
  209360. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209361. {
  209362. return true;
  209363. }
  209364. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209365. {
  209366. return lengthInFrames;
  209367. }
  209368. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209369. toMedia: (NSDictionary*) mediaInfo
  209370. {
  209371. if (source != 0)
  209372. source->prepareToPlay (44100 / 75, 44100);
  209373. readPosition = 0;
  209374. return true;
  209375. }
  209376. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209377. {
  209378. if (source != 0)
  209379. source->prepareToPlay (44100 / 75, 44100);
  209380. return true;
  209381. }
  209382. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209383. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209384. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209385. {
  209386. if (source != 0)
  209387. {
  209388. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209389. if (numSamples > 0)
  209390. {
  209391. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209392. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209393. info.buffer = &tempBuffer;
  209394. info.startSample = 0;
  209395. info.numSamples = numSamples;
  209396. source->getNextAudioBlock (info);
  209397. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209398. buffer, numSamples, 4);
  209399. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209400. buffer + 2, numSamples, 4);
  209401. readPosition += numSamples;
  209402. }
  209403. return numSamples * 4;
  209404. }
  209405. return 0;
  209406. }
  209407. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209408. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209409. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209410. ioFlags: (uint32_t*) flags
  209411. {
  209412. zeromem (buffer, bufferLength);
  209413. return bufferLength;
  209414. }
  209415. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209416. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209417. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209418. {
  209419. return true;
  209420. }
  209421. @end
  209422. BEGIN_JUCE_NAMESPACE
  209423. class AudioCDBurner::Pimpl : public Timer
  209424. {
  209425. public:
  209426. Pimpl (AudioCDBurner& owner_, const int deviceIndex)
  209427. : device (0), owner (owner_)
  209428. {
  209429. DRDevice* dev = [[DRDevice devices] objectAtIndex: deviceIndex];
  209430. if (dev != 0)
  209431. {
  209432. device = [[OpenDiskDevice alloc] initWithDRDevice: dev];
  209433. lastState = getDiskState();
  209434. startTimer (1000);
  209435. }
  209436. }
  209437. ~Pimpl()
  209438. {
  209439. stopTimer();
  209440. [device release];
  209441. }
  209442. void timerCallback()
  209443. {
  209444. const DiskState state = getDiskState();
  209445. if (state != lastState)
  209446. {
  209447. lastState = state;
  209448. owner.sendChangeMessage (&owner);
  209449. }
  209450. }
  209451. DiskState getDiskState() const
  209452. {
  209453. if ([device->device isValid])
  209454. {
  209455. NSDictionary* status = [device->device status];
  209456. NSString* state = [status objectForKey: DRDeviceMediaStateKey];
  209457. if ([state isEqualTo: DRDeviceMediaStateNone])
  209458. {
  209459. if ([[status objectForKey: DRDeviceIsTrayOpenKey] boolValue])
  209460. return trayOpen;
  209461. return noDisc;
  209462. }
  209463. if ([state isEqualTo: DRDeviceMediaStateMediaPresent])
  209464. {
  209465. if ([[[status objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceMediaBlocksFreeKey] intValue] > 0)
  209466. return writableDiskPresent;
  209467. else
  209468. return readOnlyDiskPresent;
  209469. }
  209470. }
  209471. return unknown;
  209472. }
  209473. bool openTray() { return [device->device isValid] && [device->device ejectMedia]; }
  209474. const Array<int> getAvailableWriteSpeeds() const
  209475. {
  209476. Array<int> results;
  209477. if ([device->device isValid])
  209478. {
  209479. NSArray* speeds = [[[device->device status] objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceBurnSpeedsKey];
  209480. for (unsigned int i = 0; i < [speeds count]; ++i)
  209481. {
  209482. const int kbPerSec = [[speeds objectAtIndex: i] intValue];
  209483. results.add (kbPerSec / kilobytesPerSecond1x);
  209484. }
  209485. }
  209486. return results;
  209487. }
  209488. bool setBufferUnderrunProtection (const bool shouldBeEnabled)
  209489. {
  209490. if ([device->device isValid])
  209491. {
  209492. device->underrunProtection = shouldBeEnabled;
  209493. return shouldBeEnabled && [[[device->device status] objectForKey: DRDeviceCanUnderrunProtectCDKey] boolValue];
  209494. }
  209495. return false;
  209496. }
  209497. int getNumAvailableAudioBlocks() const
  209498. {
  209499. return [[[[device->device status] objectForKey: DRDeviceMediaInfoKey]
  209500. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209501. }
  209502. OpenDiskDevice* device;
  209503. private:
  209504. DiskState lastState;
  209505. AudioCDBurner& owner;
  209506. };
  209507. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209508. {
  209509. pimpl = new Pimpl (*this, deviceIndex);
  209510. }
  209511. AudioCDBurner::~AudioCDBurner()
  209512. {
  209513. }
  209514. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209515. {
  209516. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209517. if (b->pimpl->device == 0)
  209518. b = 0;
  209519. return b.release();
  209520. }
  209521. static NSArray* findDiskBurnerDevices()
  209522. {
  209523. NSMutableArray* results = [NSMutableArray array];
  209524. NSArray* devs = [DRDevice devices];
  209525. if (devs != 0)
  209526. {
  209527. int num = [devs count];
  209528. int i;
  209529. for (i = 0; i < num; ++i)
  209530. {
  209531. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209532. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209533. if (name != nil)
  209534. [results addObject: name];
  209535. }
  209536. }
  209537. return results;
  209538. }
  209539. const StringArray AudioCDBurner::findAvailableDevices()
  209540. {
  209541. NSArray* names = findDiskBurnerDevices();
  209542. StringArray s;
  209543. for (unsigned int i = 0; i < [names count]; ++i)
  209544. s.add (String::fromUTF8 ([[names objectAtIndex: i] UTF8String]));
  209545. return s;
  209546. }
  209547. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  209548. {
  209549. return pimpl->getDiskState();
  209550. }
  209551. bool AudioCDBurner::isDiskPresent() const
  209552. {
  209553. return getDiskState() == writableDiskPresent;
  209554. }
  209555. bool AudioCDBurner::openTray()
  209556. {
  209557. return pimpl->openTray();
  209558. }
  209559. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  209560. {
  209561. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  209562. DiskState oldState = getDiskState();
  209563. DiskState newState = oldState;
  209564. while (newState == oldState && Time::currentTimeMillis() < timeout)
  209565. {
  209566. newState = getDiskState();
  209567. Thread::sleep (100);
  209568. }
  209569. return newState;
  209570. }
  209571. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  209572. {
  209573. return pimpl->getAvailableWriteSpeeds();
  209574. }
  209575. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  209576. {
  209577. return pimpl->setBufferUnderrunProtection (shouldBeEnabled);
  209578. }
  209579. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209580. {
  209581. return pimpl->getNumAvailableAudioBlocks();
  209582. }
  209583. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209584. {
  209585. if ([pimpl->device->device isValid])
  209586. {
  209587. [pimpl->device addSourceTrack: source numSamples: numSamps];
  209588. return true;
  209589. }
  209590. return false;
  209591. }
  209592. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209593. bool ejectDiscAfterwards,
  209594. bool performFakeBurnForTesting,
  209595. int writeSpeed)
  209596. {
  209597. String error ("Couldn't open or write to the CD device");
  209598. if ([pimpl->device->device isValid])
  209599. {
  209600. error = String::empty;
  209601. [pimpl->device burn: listener
  209602. errorString: &error
  209603. ejectAfterwards: ejectDiscAfterwards
  209604. isFake: performFakeBurnForTesting
  209605. speed: writeSpeed];
  209606. }
  209607. return error;
  209608. }
  209609. #endif
  209610. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  209611. void AudioCDReader::ejectDisk()
  209612. {
  209613. const ScopedAutoReleasePool p;
  209614. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209615. }
  209616. #endif
  209617. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209618. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209619. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209620. // compiled on its own).
  209621. #if JUCE_INCLUDED_FILE
  209622. struct CallbackMessagePayload
  209623. {
  209624. MessageCallbackFunction* function;
  209625. void* parameter;
  209626. void* volatile result;
  209627. bool volatile hasBeenExecuted;
  209628. };
  209629. class AppDelegateRedirector
  209630. {
  209631. public:
  209632. AppDelegateRedirector()
  209633. {
  209634. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209635. runLoop = CFRunLoopGetMain();
  209636. #else
  209637. runLoop = CFRunLoopGetCurrent();
  209638. #endif
  209639. CFRunLoopSourceContext sourceContext;
  209640. zerostruct (sourceContext);
  209641. sourceContext.info = this;
  209642. sourceContext.perform = runLoopSourceCallback;
  209643. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209644. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209645. }
  209646. virtual ~AppDelegateRedirector()
  209647. {
  209648. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209649. CFRunLoopSourceInvalidate (runLoopSource);
  209650. CFRelease (runLoopSource);
  209651. while (messages.size() > 0)
  209652. delete ((Message*) messages.remove(0));
  209653. }
  209654. virtual NSApplicationTerminateReply shouldTerminate()
  209655. {
  209656. if (JUCEApplication::getInstance() != 0)
  209657. {
  209658. JUCEApplication::getInstance()->systemRequestedQuit();
  209659. return NSTerminateCancel;
  209660. }
  209661. return NSTerminateNow;
  209662. }
  209663. virtual BOOL openFile (const NSString* filename)
  209664. {
  209665. if (JUCEApplication::getInstance() != 0)
  209666. {
  209667. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209668. return YES;
  209669. }
  209670. return NO;
  209671. }
  209672. virtual void openFiles (NSArray* filenames)
  209673. {
  209674. StringArray files;
  209675. for (unsigned int i = 0; i < [filenames count]; ++i)
  209676. {
  209677. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209678. if (filename.containsChar (T(' ')))
  209679. filename = filename.quoted('"');
  209680. files.add (filename);
  209681. }
  209682. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209683. {
  209684. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (T(" ")));
  209685. }
  209686. }
  209687. virtual void focusChanged()
  209688. {
  209689. juce_HandleProcessFocusChange();
  209690. }
  209691. virtual void performCallback (CallbackMessagePayload* pl)
  209692. {
  209693. pl->result = (*pl->function) (pl->parameter);
  209694. pl->hasBeenExecuted = true;
  209695. }
  209696. virtual void deleteSelf()
  209697. {
  209698. delete this;
  209699. }
  209700. void postMessage (void* m)
  209701. {
  209702. messages.add (m);
  209703. CFRunLoopSourceSignal (runLoopSource);
  209704. CFRunLoopWakeUp (runLoop);
  209705. }
  209706. private:
  209707. CFRunLoopRef runLoop;
  209708. CFRunLoopSourceRef runLoopSource;
  209709. Array <void*, CriticalSection> messages;
  209710. void runLoopCallback()
  209711. {
  209712. int numDispatched = 0;
  209713. do
  209714. {
  209715. void* const nextMessage = messages.remove (0);
  209716. if (nextMessage == 0)
  209717. return;
  209718. const ScopedAutoReleasePool pool;
  209719. MessageManager::getInstance()->deliverMessage (nextMessage);
  209720. } while (++numDispatched <= 4);
  209721. CFRunLoopSourceSignal (runLoopSource);
  209722. CFRunLoopWakeUp (runLoop);
  209723. }
  209724. static void runLoopSourceCallback (void* info)
  209725. {
  209726. ((AppDelegateRedirector*) info)->runLoopCallback();
  209727. }
  209728. };
  209729. END_JUCE_NAMESPACE
  209730. using namespace JUCE_NAMESPACE;
  209731. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209732. @interface JuceAppDelegate : NSObject
  209733. {
  209734. @private
  209735. id oldDelegate;
  209736. @public
  209737. AppDelegateRedirector* redirector;
  209738. }
  209739. - (JuceAppDelegate*) init;
  209740. - (void) dealloc;
  209741. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209742. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209743. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209744. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209745. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209746. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209747. - (void) performCallback: (id) info;
  209748. - (void) dummyMethod;
  209749. @end
  209750. @implementation JuceAppDelegate
  209751. - (JuceAppDelegate*) init
  209752. {
  209753. [super init];
  209754. redirector = new AppDelegateRedirector();
  209755. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209756. if (JUCEApplication::getInstance() != 0)
  209757. {
  209758. oldDelegate = [NSApp delegate];
  209759. [NSApp setDelegate: self];
  209760. }
  209761. else
  209762. {
  209763. oldDelegate = 0;
  209764. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209765. name: NSApplicationDidResignActiveNotification object: NSApp];
  209766. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209767. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209768. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209769. name: NSApplicationWillUnhideNotification object: NSApp];
  209770. }
  209771. return self;
  209772. }
  209773. - (void) dealloc
  209774. {
  209775. if (oldDelegate != 0)
  209776. [NSApp setDelegate: oldDelegate];
  209777. redirector->deleteSelf();
  209778. [super dealloc];
  209779. }
  209780. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209781. {
  209782. return redirector->shouldTerminate();
  209783. }
  209784. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209785. {
  209786. return redirector->openFile (filename);
  209787. }
  209788. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209789. {
  209790. return redirector->openFiles (filenames);
  209791. }
  209792. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209793. {
  209794. redirector->focusChanged();
  209795. }
  209796. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209797. {
  209798. redirector->focusChanged();
  209799. }
  209800. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209801. {
  209802. redirector->focusChanged();
  209803. }
  209804. - (void) performCallback: (id) info
  209805. {
  209806. if ([info isKindOfClass: [NSData class]])
  209807. {
  209808. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  209809. if (pl != 0)
  209810. redirector->performCallback (pl);
  209811. }
  209812. else
  209813. {
  209814. jassertfalse // should never get here!
  209815. }
  209816. }
  209817. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209818. @end
  209819. BEGIN_JUCE_NAMESPACE
  209820. static JuceAppDelegate* juceAppDelegate = 0;
  209821. void MessageManager::runDispatchLoop()
  209822. {
  209823. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209824. {
  209825. const ScopedAutoReleasePool pool;
  209826. // must only be called by the message thread!
  209827. jassert (isThisTheMessageThread());
  209828. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  209829. @try
  209830. {
  209831. [NSApp run];
  209832. }
  209833. @catch (NSException* e)
  209834. {
  209835. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  209836. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  209837. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  209838. }
  209839. @finally
  209840. {
  209841. }
  209842. #else
  209843. [NSApp run];
  209844. #endif
  209845. }
  209846. }
  209847. void MessageManager::stopDispatchLoop()
  209848. {
  209849. quitMessagePosted = true;
  209850. [NSApp stop: nil];
  209851. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  209852. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  209853. }
  209854. static bool isEventBlockedByModalComps (NSEvent* e)
  209855. {
  209856. if (Component::getNumCurrentlyModalComponents() == 0)
  209857. return false;
  209858. NSWindow* const w = [e window];
  209859. if (w == 0 || [w worksWhenModal])
  209860. return false;
  209861. bool isKey = false, isInputAttempt = false;
  209862. switch ([e type])
  209863. {
  209864. case NSKeyDown:
  209865. case NSKeyUp:
  209866. isKey = isInputAttempt = true;
  209867. break;
  209868. case NSLeftMouseDown:
  209869. case NSRightMouseDown:
  209870. case NSOtherMouseDown:
  209871. isInputAttempt = true;
  209872. break;
  209873. case NSLeftMouseDragged:
  209874. case NSRightMouseDragged:
  209875. case NSLeftMouseUp:
  209876. case NSRightMouseUp:
  209877. case NSOtherMouseUp:
  209878. case NSOtherMouseDragged:
  209879. if (Desktop::getInstance().getDraggingMouseSource(0) != 0)
  209880. return false;
  209881. break;
  209882. case NSMouseMoved:
  209883. case NSMouseEntered:
  209884. case NSMouseExited:
  209885. case NSCursorUpdate:
  209886. case NSScrollWheel:
  209887. case NSTabletPoint:
  209888. case NSTabletProximity:
  209889. break;
  209890. default:
  209891. return false;
  209892. }
  209893. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  209894. {
  209895. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  209896. NSView* const compView = (NSView*) peer->getNativeHandle();
  209897. if ([compView window] == w)
  209898. {
  209899. if (isKey)
  209900. {
  209901. if (compView == [w firstResponder])
  209902. return false;
  209903. }
  209904. else
  209905. {
  209906. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  209907. [compView bounds]))
  209908. return false;
  209909. }
  209910. }
  209911. }
  209912. if (isInputAttempt)
  209913. {
  209914. if (! [NSApp isActive])
  209915. [NSApp activateIgnoringOtherApps: YES];
  209916. Component* const modal = Component::getCurrentlyModalComponent (0);
  209917. if (modal != 0)
  209918. modal->inputAttemptWhenModal();
  209919. }
  209920. return true;
  209921. }
  209922. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  209923. {
  209924. const ScopedAutoReleasePool pool;
  209925. jassert (isThisTheMessageThread()); // must only be called by the message thread
  209926. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  209927. while (! quitMessagePosted)
  209928. {
  209929. const ScopedAutoReleasePool pool2;
  209930. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  209931. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  209932. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  209933. inMode: NSDefaultRunLoopMode
  209934. dequeue: YES];
  209935. if (e != 0 && ! isEventBlockedByModalComps (e))
  209936. [NSApp sendEvent: e];
  209937. if (Time::getMillisecondCounter() >= endTime)
  209938. break;
  209939. }
  209940. return ! quitMessagePosted;
  209941. }
  209942. void MessageManager::doPlatformSpecificInitialisation()
  209943. {
  209944. if (juceAppDelegate == 0)
  209945. juceAppDelegate = [[JuceAppDelegate alloc] init];
  209946. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  209947. // correctly (needed prior to 10.5)
  209948. if (! [NSThread isMultiThreaded])
  209949. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  209950. toTarget: juceAppDelegate
  209951. withObject: nil];
  209952. initialiseMainMenu();
  209953. }
  209954. void MessageManager::doPlatformSpecificShutdown()
  209955. {
  209956. if (juceAppDelegate != 0)
  209957. {
  209958. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  209959. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  209960. [juceAppDelegate release];
  209961. juceAppDelegate = 0;
  209962. }
  209963. }
  209964. bool juce_postMessageToSystemQueue (void* message)
  209965. {
  209966. juceAppDelegate->redirector->postMessage (message);
  209967. return true;
  209968. }
  209969. void MessageManager::broadcastMessage (const String& value) throw()
  209970. {
  209971. }
  209972. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  209973. void* data)
  209974. {
  209975. if (isThisTheMessageThread())
  209976. {
  209977. return (*callback) (data);
  209978. }
  209979. else
  209980. {
  209981. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  209982. // deadlock because the message manager is blocked from running, so can never
  209983. // call your function..
  209984. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  209985. const ScopedAutoReleasePool pool;
  209986. CallbackMessagePayload cmp;
  209987. cmp.function = callback;
  209988. cmp.parameter = data;
  209989. cmp.result = 0;
  209990. cmp.hasBeenExecuted = false;
  209991. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  209992. withObject: [NSData dataWithBytesNoCopy: &cmp
  209993. length: sizeof (cmp)
  209994. freeWhenDone: NO]
  209995. waitUntilDone: YES];
  209996. return cmp.result;
  209997. }
  209998. }
  209999. #endif
  210000. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  210001. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210002. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210003. // compiled on its own).
  210004. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  210005. #if JUCE_MAC
  210006. END_JUCE_NAMESPACE
  210007. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  210008. @interface DownloadClickDetector : NSObject
  210009. {
  210010. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  210011. }
  210012. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  210013. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210014. request: (NSURLRequest*) request
  210015. frame: (WebFrame*) frame
  210016. decisionListener: (id<WebPolicyDecisionListener>) listener;
  210017. @end
  210018. @implementation DownloadClickDetector
  210019. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  210020. {
  210021. [super init];
  210022. ownerComponent = ownerComponent_;
  210023. return self;
  210024. }
  210025. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210026. request: (NSURLRequest*) request
  210027. frame: (WebFrame*) frame
  210028. decisionListener: (id <WebPolicyDecisionListener>) listener
  210029. {
  210030. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  210031. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  210032. [listener use];
  210033. else
  210034. [listener ignore];
  210035. }
  210036. @end
  210037. BEGIN_JUCE_NAMESPACE
  210038. class WebBrowserComponentInternal : public NSViewComponent
  210039. {
  210040. public:
  210041. WebBrowserComponentInternal (WebBrowserComponent* owner)
  210042. {
  210043. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  210044. frameName: @""
  210045. groupName: @""];
  210046. setView (webView);
  210047. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  210048. [webView setPolicyDelegate: clickListener];
  210049. }
  210050. ~WebBrowserComponentInternal()
  210051. {
  210052. [webView setPolicyDelegate: nil];
  210053. [clickListener release];
  210054. setView (0);
  210055. }
  210056. void goToURL (const String& url,
  210057. const StringArray* headers,
  210058. const MemoryBlock* postData)
  210059. {
  210060. NSMutableURLRequest* r
  210061. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  210062. cachePolicy: NSURLRequestUseProtocolCachePolicy
  210063. timeoutInterval: 30.0];
  210064. if (postData != 0 && postData->getSize() > 0)
  210065. {
  210066. [r setHTTPMethod: @"POST"];
  210067. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  210068. length: postData->getSize()]];
  210069. }
  210070. if (headers != 0)
  210071. {
  210072. for (int i = 0; i < headers->size(); ++i)
  210073. {
  210074. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  210075. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  210076. [r setValue: juceStringToNS (headerValue)
  210077. forHTTPHeaderField: juceStringToNS (headerName)];
  210078. }
  210079. }
  210080. stop();
  210081. [[webView mainFrame] loadRequest: r];
  210082. }
  210083. void goBack()
  210084. {
  210085. [webView goBack];
  210086. }
  210087. void goForward()
  210088. {
  210089. [webView goForward];
  210090. }
  210091. void stop()
  210092. {
  210093. [webView stopLoading: nil];
  210094. }
  210095. void refresh()
  210096. {
  210097. [webView reload: nil];
  210098. }
  210099. private:
  210100. WebView* webView;
  210101. DownloadClickDetector* clickListener;
  210102. };
  210103. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210104. : browser (0),
  210105. blankPageShown (false),
  210106. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  210107. {
  210108. setOpaque (true);
  210109. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  210110. }
  210111. WebBrowserComponent::~WebBrowserComponent()
  210112. {
  210113. deleteAndZero (browser);
  210114. }
  210115. void WebBrowserComponent::goToURL (const String& url,
  210116. const StringArray* headers,
  210117. const MemoryBlock* postData)
  210118. {
  210119. lastURL = url;
  210120. lastHeaders.clear();
  210121. if (headers != 0)
  210122. lastHeaders = *headers;
  210123. lastPostData.setSize (0);
  210124. if (postData != 0)
  210125. lastPostData = *postData;
  210126. blankPageShown = false;
  210127. browser->goToURL (url, headers, postData);
  210128. }
  210129. void WebBrowserComponent::stop()
  210130. {
  210131. browser->stop();
  210132. }
  210133. void WebBrowserComponent::goBack()
  210134. {
  210135. lastURL = String::empty;
  210136. blankPageShown = false;
  210137. browser->goBack();
  210138. }
  210139. void WebBrowserComponent::goForward()
  210140. {
  210141. lastURL = String::empty;
  210142. browser->goForward();
  210143. }
  210144. void WebBrowserComponent::refresh()
  210145. {
  210146. browser->refresh();
  210147. }
  210148. void WebBrowserComponent::paint (Graphics& g)
  210149. {
  210150. }
  210151. void WebBrowserComponent::checkWindowAssociation()
  210152. {
  210153. if (isShowing())
  210154. {
  210155. if (blankPageShown)
  210156. goBack();
  210157. }
  210158. else
  210159. {
  210160. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210161. {
  210162. // when the component becomes invisible, some stuff like flash
  210163. // carries on playing audio, so we need to force it onto a blank
  210164. // page to avoid this, (and send it back when it's made visible again).
  210165. blankPageShown = true;
  210166. browser->goToURL ("about:blank", 0, 0);
  210167. }
  210168. }
  210169. }
  210170. void WebBrowserComponent::reloadLastURL()
  210171. {
  210172. if (lastURL.isNotEmpty())
  210173. {
  210174. goToURL (lastURL, &lastHeaders, &lastPostData);
  210175. lastURL = String::empty;
  210176. }
  210177. }
  210178. void WebBrowserComponent::parentHierarchyChanged()
  210179. {
  210180. checkWindowAssociation();
  210181. }
  210182. void WebBrowserComponent::resized()
  210183. {
  210184. browser->setSize (getWidth(), getHeight());
  210185. }
  210186. void WebBrowserComponent::visibilityChanged()
  210187. {
  210188. checkWindowAssociation();
  210189. }
  210190. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210191. {
  210192. return true;
  210193. }
  210194. #else
  210195. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210196. {
  210197. }
  210198. WebBrowserComponent::~WebBrowserComponent()
  210199. {
  210200. }
  210201. void WebBrowserComponent::goToURL (const String& url,
  210202. const StringArray* headers,
  210203. const MemoryBlock* postData)
  210204. {
  210205. }
  210206. void WebBrowserComponent::stop()
  210207. {
  210208. }
  210209. void WebBrowserComponent::goBack()
  210210. {
  210211. }
  210212. void WebBrowserComponent::goForward()
  210213. {
  210214. }
  210215. void WebBrowserComponent::refresh()
  210216. {
  210217. }
  210218. void WebBrowserComponent::paint (Graphics& g)
  210219. {
  210220. }
  210221. void WebBrowserComponent::checkWindowAssociation()
  210222. {
  210223. }
  210224. void WebBrowserComponent::reloadLastURL()
  210225. {
  210226. }
  210227. void WebBrowserComponent::parentHierarchyChanged()
  210228. {
  210229. }
  210230. void WebBrowserComponent::resized()
  210231. {
  210232. }
  210233. void WebBrowserComponent::visibilityChanged()
  210234. {
  210235. }
  210236. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210237. {
  210238. return true;
  210239. }
  210240. #endif
  210241. #endif
  210242. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210243. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  210244. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210245. // compiled on its own).
  210246. #if JUCE_INCLUDED_FILE
  210247. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210248. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210249. #endif
  210250. #undef log
  210251. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210252. #define log(a) Logger::writeToLog (a)
  210253. #else
  210254. #define log(a)
  210255. #endif
  210256. #undef OK
  210257. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210258. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210259. {
  210260. if (err == noErr)
  210261. return true;
  210262. Logger::writeToLog (T("CoreAudio error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  210263. jassertfalse
  210264. return false;
  210265. }
  210266. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210267. #else
  210268. #define OK(a) (a == noErr)
  210269. #endif
  210270. class CoreAudioInternal : public Timer
  210271. {
  210272. public:
  210273. CoreAudioInternal (AudioDeviceID id)
  210274. : inputLatency (0),
  210275. outputLatency (0),
  210276. callback (0),
  210277. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210278. audioProcID (0),
  210279. #endif
  210280. inputDevice (0),
  210281. isSlaveDevice (false),
  210282. deviceID (id),
  210283. started (false),
  210284. sampleRate (0),
  210285. bufferSize (512),
  210286. numInputChans (0),
  210287. numOutputChans (0),
  210288. callbacksAllowed (true),
  210289. numInputChannelInfos (0),
  210290. numOutputChannelInfos (0)
  210291. {
  210292. jassert (deviceID != 0);
  210293. updateDetailsFromDevice();
  210294. AudioObjectPropertyAddress pa;
  210295. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210296. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210297. pa.mElement = kAudioObjectPropertyElementWildcard;
  210298. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210299. }
  210300. ~CoreAudioInternal()
  210301. {
  210302. AudioObjectPropertyAddress pa;
  210303. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210304. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210305. pa.mElement = kAudioObjectPropertyElementWildcard;
  210306. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210307. stop (false);
  210308. delete inputDevice;
  210309. }
  210310. void allocateTempBuffers()
  210311. {
  210312. const int tempBufSize = bufferSize + 4;
  210313. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210314. tempInputBuffers.calloc (numInputChans + 2);
  210315. tempOutputBuffers.calloc (numOutputChans + 2);
  210316. int i, count = 0;
  210317. for (i = 0; i < numInputChans; ++i)
  210318. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210319. for (i = 0; i < numOutputChans; ++i)
  210320. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210321. }
  210322. // returns the number of actual available channels
  210323. void fillInChannelInfo (const bool input)
  210324. {
  210325. int chanNum = 0;
  210326. UInt32 size;
  210327. AudioObjectPropertyAddress pa;
  210328. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210329. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210330. pa.mElement = kAudioObjectPropertyElementMaster;
  210331. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210332. {
  210333. HeapBlock <AudioBufferList> bufList;
  210334. bufList.calloc (size, 1);
  210335. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210336. {
  210337. const int numStreams = bufList->mNumberBuffers;
  210338. for (int i = 0; i < numStreams; ++i)
  210339. {
  210340. const AudioBuffer& b = bufList->mBuffers[i];
  210341. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210342. {
  210343. String name;
  210344. {
  210345. char channelName [256];
  210346. zerostruct (channelName);
  210347. UInt32 nameSize = sizeof (channelName);
  210348. UInt32 channelNum = chanNum + 1;
  210349. pa.mSelector = kAudioDevicePropertyChannelName;
  210350. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210351. name = String::fromUTF8 (channelName, nameSize);
  210352. }
  210353. if (input)
  210354. {
  210355. if (activeInputChans[chanNum])
  210356. {
  210357. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210358. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210359. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210360. ++numInputChannelInfos;
  210361. }
  210362. if (name.isEmpty())
  210363. name << "Input " << (chanNum + 1);
  210364. inChanNames.add (name);
  210365. }
  210366. else
  210367. {
  210368. if (activeOutputChans[chanNum])
  210369. {
  210370. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210371. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210372. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210373. ++numOutputChannelInfos;
  210374. }
  210375. if (name.isEmpty())
  210376. name << "Output " << (chanNum + 1);
  210377. outChanNames.add (name);
  210378. }
  210379. ++chanNum;
  210380. }
  210381. }
  210382. }
  210383. }
  210384. }
  210385. void updateDetailsFromDevice()
  210386. {
  210387. stopTimer();
  210388. if (deviceID == 0)
  210389. return;
  210390. const ScopedLock sl (callbackLock);
  210391. Float64 sr;
  210392. UInt32 size = sizeof (Float64);
  210393. AudioObjectPropertyAddress pa;
  210394. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210395. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210396. pa.mElement = kAudioObjectPropertyElementMaster;
  210397. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210398. sampleRate = sr;
  210399. UInt32 framesPerBuf;
  210400. size = sizeof (framesPerBuf);
  210401. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210402. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210403. {
  210404. bufferSize = framesPerBuf;
  210405. allocateTempBuffers();
  210406. }
  210407. bufferSizes.clear();
  210408. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210409. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210410. {
  210411. HeapBlock <AudioValueRange> ranges;
  210412. ranges.calloc (size, 1);
  210413. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210414. {
  210415. bufferSizes.add ((int) ranges[0].mMinimum);
  210416. for (int i = 32; i < 8192; i += 32)
  210417. {
  210418. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210419. {
  210420. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210421. {
  210422. bufferSizes.addIfNotAlreadyThere (i);
  210423. break;
  210424. }
  210425. }
  210426. }
  210427. if (bufferSize > 0)
  210428. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210429. }
  210430. }
  210431. if (bufferSizes.size() == 0 && bufferSize > 0)
  210432. bufferSizes.add (bufferSize);
  210433. sampleRates.clear();
  210434. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210435. String rates;
  210436. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210437. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210438. {
  210439. HeapBlock <AudioValueRange> ranges;
  210440. ranges.calloc (size, 1);
  210441. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210442. {
  210443. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210444. {
  210445. bool ok = false;
  210446. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210447. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210448. ok = true;
  210449. if (ok)
  210450. {
  210451. sampleRates.add (possibleRates[i]);
  210452. rates << possibleRates[i] << T(" ");
  210453. }
  210454. }
  210455. }
  210456. }
  210457. if (sampleRates.size() == 0 && sampleRate > 0)
  210458. {
  210459. sampleRates.add (sampleRate);
  210460. rates << sampleRate;
  210461. }
  210462. log (T("sr: ") + rates);
  210463. inputLatency = 0;
  210464. outputLatency = 0;
  210465. UInt32 lat;
  210466. size = sizeof (lat);
  210467. pa.mSelector = kAudioDevicePropertyLatency;
  210468. pa.mScope = kAudioDevicePropertyScopeInput;
  210469. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210470. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210471. inputLatency = (int) lat;
  210472. pa.mScope = kAudioDevicePropertyScopeOutput;
  210473. size = sizeof (lat);
  210474. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210475. outputLatency = (int) lat;
  210476. log (T("lat: ") + String (inputLatency) + T(" ") + String (outputLatency));
  210477. inChanNames.clear();
  210478. outChanNames.clear();
  210479. inputChannelInfo.calloc (numInputChans + 2);
  210480. numInputChannelInfos = 0;
  210481. outputChannelInfo.calloc (numOutputChans + 2);
  210482. numOutputChannelInfos = 0;
  210483. fillInChannelInfo (true);
  210484. fillInChannelInfo (false);
  210485. }
  210486. const StringArray getSources (bool input)
  210487. {
  210488. StringArray s;
  210489. HeapBlock <OSType> types;
  210490. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210491. for (int i = 0; i < num; ++i)
  210492. {
  210493. AudioValueTranslation avt;
  210494. char buffer[256];
  210495. avt.mInputData = (void*) &(types[i]);
  210496. avt.mInputDataSize = sizeof (UInt32);
  210497. avt.mOutputData = buffer;
  210498. avt.mOutputDataSize = 256;
  210499. UInt32 transSize = sizeof (avt);
  210500. AudioObjectPropertyAddress pa;
  210501. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210502. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210503. pa.mElement = kAudioObjectPropertyElementMaster;
  210504. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210505. {
  210506. DBG (buffer);
  210507. s.add (buffer);
  210508. }
  210509. }
  210510. return s;
  210511. }
  210512. int getCurrentSourceIndex (bool input) const
  210513. {
  210514. OSType currentSourceID = 0;
  210515. UInt32 size = sizeof (currentSourceID);
  210516. int result = -1;
  210517. AudioObjectPropertyAddress pa;
  210518. pa.mSelector = kAudioDevicePropertyDataSource;
  210519. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210520. pa.mElement = kAudioObjectPropertyElementMaster;
  210521. if (deviceID != 0)
  210522. {
  210523. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210524. {
  210525. HeapBlock <OSType> types;
  210526. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210527. for (int i = 0; i < num; ++i)
  210528. {
  210529. if (types[num] == currentSourceID)
  210530. {
  210531. result = i;
  210532. break;
  210533. }
  210534. }
  210535. }
  210536. }
  210537. return result;
  210538. }
  210539. void setCurrentSourceIndex (int index, bool input)
  210540. {
  210541. if (deviceID != 0)
  210542. {
  210543. HeapBlock <OSType> types;
  210544. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210545. if (((unsigned int) index) < (unsigned int) num)
  210546. {
  210547. AudioObjectPropertyAddress pa;
  210548. pa.mSelector = kAudioDevicePropertyDataSource;
  210549. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210550. pa.mElement = kAudioObjectPropertyElementMaster;
  210551. OSType typeId = types[index];
  210552. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210553. }
  210554. }
  210555. }
  210556. const String reopen (const BitArray& inputChannels,
  210557. const BitArray& outputChannels,
  210558. double newSampleRate,
  210559. int bufferSizeSamples)
  210560. {
  210561. String error;
  210562. log ("CoreAudio reopen");
  210563. callbacksAllowed = false;
  210564. stopTimer();
  210565. stop (false);
  210566. activeInputChans = inputChannels;
  210567. activeInputChans.setRange (inChanNames.size(),
  210568. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210569. false);
  210570. activeOutputChans = outputChannels;
  210571. activeOutputChans.setRange (outChanNames.size(),
  210572. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210573. false);
  210574. numInputChans = activeInputChans.countNumberOfSetBits();
  210575. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210576. // set sample rate
  210577. AudioObjectPropertyAddress pa;
  210578. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210579. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210580. pa.mElement = kAudioObjectPropertyElementMaster;
  210581. Float64 sr = newSampleRate;
  210582. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210583. {
  210584. error = "Couldn't change sample rate";
  210585. }
  210586. else
  210587. {
  210588. // change buffer size
  210589. UInt32 framesPerBuf = bufferSizeSamples;
  210590. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210591. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210592. {
  210593. error = "Couldn't change buffer size";
  210594. }
  210595. else
  210596. {
  210597. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210598. // correctly report their new settings until some random time in the future, so
  210599. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210600. // to make sure we're using the correct numbers..
  210601. updateDetailsFromDevice();
  210602. sampleRate = newSampleRate;
  210603. bufferSize = bufferSizeSamples;
  210604. if (sampleRates.size() == 0)
  210605. error = "Device has no available sample-rates";
  210606. else if (bufferSizes.size() == 0)
  210607. error = "Device has no available buffer-sizes";
  210608. else if (inputDevice != 0)
  210609. error = inputDevice->reopen (inputChannels,
  210610. outputChannels,
  210611. newSampleRate,
  210612. bufferSizeSamples);
  210613. }
  210614. }
  210615. callbacksAllowed = true;
  210616. return error;
  210617. }
  210618. bool start (AudioIODeviceCallback* cb)
  210619. {
  210620. if (! started)
  210621. {
  210622. callback = 0;
  210623. if (deviceID != 0)
  210624. {
  210625. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210626. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, (void*) this)))
  210627. #else
  210628. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, (void*) this, &audioProcID)))
  210629. #endif
  210630. {
  210631. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210632. {
  210633. started = true;
  210634. }
  210635. else
  210636. {
  210637. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210638. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210639. #else
  210640. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210641. audioProcID = 0;
  210642. #endif
  210643. }
  210644. }
  210645. }
  210646. }
  210647. if (started)
  210648. {
  210649. const ScopedLock sl (callbackLock);
  210650. callback = cb;
  210651. }
  210652. if (inputDevice != 0)
  210653. return started && inputDevice->start (cb);
  210654. else
  210655. return started;
  210656. }
  210657. void stop (bool leaveInterruptRunning)
  210658. {
  210659. {
  210660. const ScopedLock sl (callbackLock);
  210661. callback = 0;
  210662. }
  210663. if (started
  210664. && (deviceID != 0)
  210665. && ! leaveInterruptRunning)
  210666. {
  210667. OK (AudioDeviceStop (deviceID, audioIOProc));
  210668. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210669. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210670. #else
  210671. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210672. audioProcID = 0;
  210673. #endif
  210674. started = false;
  210675. { const ScopedLock sl (callbackLock); }
  210676. // wait until it's definately stopped calling back..
  210677. for (int i = 40; --i >= 0;)
  210678. {
  210679. Thread::sleep (50);
  210680. UInt32 running = 0;
  210681. UInt32 size = sizeof (running);
  210682. AudioObjectPropertyAddress pa;
  210683. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210684. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210685. pa.mElement = kAudioObjectPropertyElementMaster;
  210686. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210687. if (running == 0)
  210688. break;
  210689. }
  210690. const ScopedLock sl (callbackLock);
  210691. }
  210692. if (inputDevice != 0)
  210693. inputDevice->stop (leaveInterruptRunning);
  210694. }
  210695. double getSampleRate() const
  210696. {
  210697. return sampleRate;
  210698. }
  210699. int getBufferSize() const
  210700. {
  210701. return bufferSize;
  210702. }
  210703. void audioCallback (const AudioBufferList* inInputData,
  210704. AudioBufferList* outOutputData)
  210705. {
  210706. int i;
  210707. const ScopedLock sl (callbackLock);
  210708. if (callback != 0)
  210709. {
  210710. if (inputDevice == 0)
  210711. {
  210712. for (i = numInputChans; --i >= 0;)
  210713. {
  210714. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210715. float* dest = tempInputBuffers [i];
  210716. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210717. + info.dataOffsetSamples;
  210718. const int stride = info.dataStrideSamples;
  210719. if (stride != 0) // if this is zero, info is invalid
  210720. {
  210721. for (int j = bufferSize; --j >= 0;)
  210722. {
  210723. *dest++ = *src;
  210724. src += stride;
  210725. }
  210726. }
  210727. }
  210728. }
  210729. if (! isSlaveDevice)
  210730. {
  210731. if (inputDevice == 0)
  210732. {
  210733. callback->audioDeviceIOCallback (const_cast<const float**> (tempInputBuffers.getData()),
  210734. numInputChans,
  210735. tempOutputBuffers,
  210736. numOutputChans,
  210737. bufferSize);
  210738. }
  210739. else
  210740. {
  210741. jassert (inputDevice->bufferSize == bufferSize);
  210742. // Sometimes the two linked devices seem to get their callbacks in
  210743. // parallel, so we need to lock both devices to stop the input data being
  210744. // changed while inside our callback..
  210745. const ScopedLock sl2 (inputDevice->callbackLock);
  210746. callback->audioDeviceIOCallback (const_cast<const float**> (inputDevice->tempInputBuffers.getData()),
  210747. inputDevice->numInputChans,
  210748. tempOutputBuffers,
  210749. numOutputChans,
  210750. bufferSize);
  210751. }
  210752. for (i = numOutputChans; --i >= 0;)
  210753. {
  210754. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210755. const float* src = tempOutputBuffers [i];
  210756. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210757. + info.dataOffsetSamples;
  210758. const int stride = info.dataStrideSamples;
  210759. if (stride != 0) // if this is zero, info is invalid
  210760. {
  210761. for (int j = bufferSize; --j >= 0;)
  210762. {
  210763. *dest = *src++;
  210764. dest += stride;
  210765. }
  210766. }
  210767. }
  210768. }
  210769. }
  210770. else
  210771. {
  210772. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210773. {
  210774. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210775. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210776. + info.dataOffsetSamples;
  210777. const int stride = info.dataStrideSamples;
  210778. if (stride != 0) // if this is zero, info is invalid
  210779. {
  210780. for (int j = bufferSize; --j >= 0;)
  210781. {
  210782. *dest = 0.0f;
  210783. dest += stride;
  210784. }
  210785. }
  210786. }
  210787. }
  210788. }
  210789. // called by callbacks
  210790. void deviceDetailsChanged()
  210791. {
  210792. if (callbacksAllowed)
  210793. startTimer (100);
  210794. }
  210795. void timerCallback()
  210796. {
  210797. stopTimer();
  210798. log ("CoreAudio device changed callback");
  210799. const double oldSampleRate = sampleRate;
  210800. const int oldBufferSize = bufferSize;
  210801. updateDetailsFromDevice();
  210802. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210803. {
  210804. callbacksAllowed = false;
  210805. stop (false);
  210806. updateDetailsFromDevice();
  210807. callbacksAllowed = true;
  210808. }
  210809. }
  210810. CoreAudioInternal* getRelatedDevice() const
  210811. {
  210812. UInt32 size = 0;
  210813. ScopedPointer <CoreAudioInternal> result;
  210814. AudioObjectPropertyAddress pa;
  210815. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210816. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210817. pa.mElement = kAudioObjectPropertyElementMaster;
  210818. if (deviceID != 0
  210819. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210820. && size > 0)
  210821. {
  210822. HeapBlock <AudioDeviceID> devs;
  210823. devs.calloc (size, 1);
  210824. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210825. {
  210826. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210827. {
  210828. if (devs[i] != deviceID && devs[i] != 0)
  210829. {
  210830. result = new CoreAudioInternal (devs[i]);
  210831. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  210832. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  210833. if (thisIsInput != otherIsInput
  210834. || (inChanNames.size() + outChanNames.size() == 0)
  210835. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  210836. break;
  210837. result = 0;
  210838. }
  210839. }
  210840. }
  210841. }
  210842. return result.release();
  210843. }
  210844. juce_UseDebuggingNewOperator
  210845. int inputLatency, outputLatency;
  210846. BitArray activeInputChans, activeOutputChans;
  210847. StringArray inChanNames, outChanNames;
  210848. Array <double> sampleRates;
  210849. Array <int> bufferSizes;
  210850. AudioIODeviceCallback* callback;
  210851. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210852. AudioDeviceIOProcID audioProcID;
  210853. #endif
  210854. CoreAudioInternal* inputDevice;
  210855. bool isSlaveDevice;
  210856. private:
  210857. CriticalSection callbackLock;
  210858. AudioDeviceID deviceID;
  210859. bool started;
  210860. double sampleRate;
  210861. int bufferSize;
  210862. HeapBlock <float> audioBuffer;
  210863. int numInputChans, numOutputChans;
  210864. bool callbacksAllowed;
  210865. struct CallbackDetailsForChannel
  210866. {
  210867. int streamNum;
  210868. int dataOffsetSamples;
  210869. int dataStrideSamples;
  210870. };
  210871. int numInputChannelInfos, numOutputChannelInfos;
  210872. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  210873. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  210874. CoreAudioInternal (const CoreAudioInternal&);
  210875. CoreAudioInternal& operator= (const CoreAudioInternal&);
  210876. static OSStatus audioIOProc (AudioDeviceID inDevice,
  210877. const AudioTimeStamp* inNow,
  210878. const AudioBufferList* inInputData,
  210879. const AudioTimeStamp* inInputTime,
  210880. AudioBufferList* outOutputData,
  210881. const AudioTimeStamp* inOutputTime,
  210882. void* device)
  210883. {
  210884. ((CoreAudioInternal*) device)->audioCallback (inInputData, outOutputData);
  210885. return noErr;
  210886. }
  210887. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  210888. {
  210889. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  210890. switch (pa->mSelector)
  210891. {
  210892. case kAudioDevicePropertyBufferSize:
  210893. case kAudioDevicePropertyBufferFrameSize:
  210894. case kAudioDevicePropertyNominalSampleRate:
  210895. case kAudioDevicePropertyStreamFormat:
  210896. case kAudioDevicePropertyDeviceIsAlive:
  210897. intern->deviceDetailsChanged();
  210898. break;
  210899. case kAudioDevicePropertyBufferSizeRange:
  210900. case kAudioDevicePropertyVolumeScalar:
  210901. case kAudioDevicePropertyMute:
  210902. case kAudioDevicePropertyPlayThru:
  210903. case kAudioDevicePropertyDataSource:
  210904. case kAudioDevicePropertyDeviceIsRunning:
  210905. break;
  210906. }
  210907. return noErr;
  210908. }
  210909. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  210910. {
  210911. AudioObjectPropertyAddress pa;
  210912. pa.mSelector = kAudioDevicePropertyDataSources;
  210913. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210914. pa.mElement = kAudioObjectPropertyElementMaster;
  210915. UInt32 size = 0;
  210916. if (deviceID != 0
  210917. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210918. {
  210919. types.calloc (size, 1);
  210920. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  210921. return size / (int) sizeof (OSType);
  210922. }
  210923. return 0;
  210924. }
  210925. };
  210926. class CoreAudioIODevice : public AudioIODevice
  210927. {
  210928. public:
  210929. CoreAudioIODevice (const String& deviceName,
  210930. AudioDeviceID inputDeviceId,
  210931. const int inputIndex_,
  210932. AudioDeviceID outputDeviceId,
  210933. const int outputIndex_)
  210934. : AudioIODevice (deviceName, "CoreAudio"),
  210935. inputIndex (inputIndex_),
  210936. outputIndex (outputIndex_),
  210937. isOpen_ (false),
  210938. isStarted (false)
  210939. {
  210940. internal = 0;
  210941. CoreAudioInternal* device = 0;
  210942. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  210943. {
  210944. jassert (inputDeviceId != 0);
  210945. device = new CoreAudioInternal (inputDeviceId);
  210946. }
  210947. else
  210948. {
  210949. device = new CoreAudioInternal (outputDeviceId);
  210950. if (inputDeviceId != 0)
  210951. {
  210952. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  210953. device->inputDevice = secondDevice;
  210954. secondDevice->isSlaveDevice = true;
  210955. }
  210956. }
  210957. internal = device;
  210958. AudioObjectPropertyAddress pa;
  210959. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210960. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210961. pa.mElement = kAudioObjectPropertyElementWildcard;
  210962. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210963. }
  210964. ~CoreAudioIODevice()
  210965. {
  210966. AudioObjectPropertyAddress pa;
  210967. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210968. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210969. pa.mElement = kAudioObjectPropertyElementWildcard;
  210970. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210971. delete internal;
  210972. }
  210973. const StringArray getOutputChannelNames()
  210974. {
  210975. return internal->outChanNames;
  210976. }
  210977. const StringArray getInputChannelNames()
  210978. {
  210979. if (internal->inputDevice != 0)
  210980. return internal->inputDevice->inChanNames;
  210981. else
  210982. return internal->inChanNames;
  210983. }
  210984. int getNumSampleRates()
  210985. {
  210986. return internal->sampleRates.size();
  210987. }
  210988. double getSampleRate (int index)
  210989. {
  210990. return internal->sampleRates [index];
  210991. }
  210992. int getNumBufferSizesAvailable()
  210993. {
  210994. return internal->bufferSizes.size();
  210995. }
  210996. int getBufferSizeSamples (int index)
  210997. {
  210998. return internal->bufferSizes [index];
  210999. }
  211000. int getDefaultBufferSize()
  211001. {
  211002. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  211003. if (getBufferSizeSamples(i) >= 512)
  211004. return getBufferSizeSamples(i);
  211005. return 512;
  211006. }
  211007. const String open (const BitArray& inputChannels,
  211008. const BitArray& outputChannels,
  211009. double sampleRate,
  211010. int bufferSizeSamples)
  211011. {
  211012. isOpen_ = true;
  211013. if (bufferSizeSamples <= 0)
  211014. bufferSizeSamples = getDefaultBufferSize();
  211015. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  211016. isOpen_ = lastError.isEmpty();
  211017. return lastError;
  211018. }
  211019. void close()
  211020. {
  211021. isOpen_ = false;
  211022. internal->stop (false);
  211023. }
  211024. bool isOpen()
  211025. {
  211026. return isOpen_;
  211027. }
  211028. int getCurrentBufferSizeSamples()
  211029. {
  211030. return internal != 0 ? internal->getBufferSize() : 512;
  211031. }
  211032. double getCurrentSampleRate()
  211033. {
  211034. return internal != 0 ? internal->getSampleRate() : 0;
  211035. }
  211036. int getCurrentBitDepth()
  211037. {
  211038. return 32; // no way to find out, so just assume it's high..
  211039. }
  211040. const BitArray getActiveOutputChannels() const
  211041. {
  211042. return internal != 0 ? internal->activeOutputChans : BitArray();
  211043. }
  211044. const BitArray getActiveInputChannels() const
  211045. {
  211046. BitArray chans;
  211047. if (internal != 0)
  211048. {
  211049. chans = internal->activeInputChans;
  211050. if (internal->inputDevice != 0)
  211051. chans.orWith (internal->inputDevice->activeInputChans);
  211052. }
  211053. return chans;
  211054. }
  211055. int getOutputLatencyInSamples()
  211056. {
  211057. if (internal == 0)
  211058. return 0;
  211059. // this seems like a good guess at getting the latency right - comparing
  211060. // this with a round-trip measurement, it gets it to within a few millisecs
  211061. // for the built-in mac soundcard
  211062. return internal->outputLatency + internal->getBufferSize() * 2;
  211063. }
  211064. int getInputLatencyInSamples()
  211065. {
  211066. if (internal == 0)
  211067. return 0;
  211068. return internal->inputLatency + internal->getBufferSize() * 2;
  211069. }
  211070. void start (AudioIODeviceCallback* callback)
  211071. {
  211072. if (internal != 0 && ! isStarted)
  211073. {
  211074. if (callback != 0)
  211075. callback->audioDeviceAboutToStart (this);
  211076. isStarted = true;
  211077. internal->start (callback);
  211078. }
  211079. }
  211080. void stop()
  211081. {
  211082. if (isStarted && internal != 0)
  211083. {
  211084. AudioIODeviceCallback* const lastCallback = internal->callback;
  211085. isStarted = false;
  211086. internal->stop (true);
  211087. if (lastCallback != 0)
  211088. lastCallback->audioDeviceStopped();
  211089. }
  211090. }
  211091. bool isPlaying()
  211092. {
  211093. if (internal->callback == 0)
  211094. isStarted = false;
  211095. return isStarted;
  211096. }
  211097. const String getLastError()
  211098. {
  211099. return lastError;
  211100. }
  211101. int inputIndex, outputIndex;
  211102. juce_UseDebuggingNewOperator
  211103. private:
  211104. CoreAudioInternal* internal;
  211105. bool isOpen_, isStarted;
  211106. String lastError;
  211107. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211108. {
  211109. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211110. switch (pa->mSelector)
  211111. {
  211112. case kAudioHardwarePropertyDevices:
  211113. intern->deviceDetailsChanged();
  211114. break;
  211115. case kAudioHardwarePropertyDefaultOutputDevice:
  211116. case kAudioHardwarePropertyDefaultInputDevice:
  211117. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  211118. break;
  211119. }
  211120. return noErr;
  211121. }
  211122. CoreAudioIODevice (const CoreAudioIODevice&);
  211123. CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  211124. };
  211125. class CoreAudioIODeviceType : public AudioIODeviceType
  211126. {
  211127. public:
  211128. CoreAudioIODeviceType()
  211129. : AudioIODeviceType (T("CoreAudio")),
  211130. hasScanned (false)
  211131. {
  211132. }
  211133. ~CoreAudioIODeviceType()
  211134. {
  211135. }
  211136. void scanForDevices()
  211137. {
  211138. hasScanned = true;
  211139. inputDeviceNames.clear();
  211140. outputDeviceNames.clear();
  211141. inputIds.clear();
  211142. outputIds.clear();
  211143. UInt32 size;
  211144. AudioObjectPropertyAddress pa;
  211145. pa.mSelector = kAudioHardwarePropertyDevices;
  211146. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211147. pa.mElement = kAudioObjectPropertyElementMaster;
  211148. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211149. {
  211150. HeapBlock <AudioDeviceID> devs;
  211151. devs.calloc (size, 1);
  211152. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211153. {
  211154. static bool alreadyLogged = false;
  211155. const int num = size / (int) sizeof (AudioDeviceID);
  211156. for (int i = 0; i < num; ++i)
  211157. {
  211158. char name [1024];
  211159. size = sizeof (name);
  211160. pa.mSelector = kAudioDevicePropertyDeviceName;
  211161. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211162. {
  211163. const String nameString (String::fromUTF8 (name, (int) strlen (name)));
  211164. if (! alreadyLogged)
  211165. log (T("CoreAudio device: ") + nameString);
  211166. const int numIns = getNumChannels (devs[i], true);
  211167. const int numOuts = getNumChannels (devs[i], false);
  211168. if (numIns > 0)
  211169. {
  211170. inputDeviceNames.add (nameString);
  211171. inputIds.add (devs[i]);
  211172. }
  211173. if (numOuts > 0)
  211174. {
  211175. outputDeviceNames.add (nameString);
  211176. outputIds.add (devs[i]);
  211177. }
  211178. }
  211179. }
  211180. alreadyLogged = true;
  211181. }
  211182. }
  211183. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211184. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211185. }
  211186. const StringArray getDeviceNames (const bool wantInputNames) const
  211187. {
  211188. jassert (hasScanned); // need to call scanForDevices() before doing this
  211189. if (wantInputNames)
  211190. return inputDeviceNames;
  211191. else
  211192. return outputDeviceNames;
  211193. }
  211194. int getDefaultDeviceIndex (const bool forInput) const
  211195. {
  211196. jassert (hasScanned); // need to call scanForDevices() before doing this
  211197. AudioDeviceID deviceID;
  211198. UInt32 size = sizeof (deviceID);
  211199. // if they're asking for any input channels at all, use the default input, so we
  211200. // get the built-in mic rather than the built-in output with no inputs..
  211201. AudioObjectPropertyAddress pa;
  211202. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211203. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211204. pa.mElement = kAudioObjectPropertyElementMaster;
  211205. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211206. {
  211207. if (forInput)
  211208. {
  211209. for (int i = inputIds.size(); --i >= 0;)
  211210. if (inputIds[i] == deviceID)
  211211. return i;
  211212. }
  211213. else
  211214. {
  211215. for (int i = outputIds.size(); --i >= 0;)
  211216. if (outputIds[i] == deviceID)
  211217. return i;
  211218. }
  211219. }
  211220. return 0;
  211221. }
  211222. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  211223. {
  211224. jassert (hasScanned); // need to call scanForDevices() before doing this
  211225. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211226. if (d == 0)
  211227. return -1;
  211228. return asInput ? d->inputIndex
  211229. : d->outputIndex;
  211230. }
  211231. bool hasSeparateInputsAndOutputs() const { return true; }
  211232. AudioIODevice* createDevice (const String& outputDeviceName,
  211233. const String& inputDeviceName)
  211234. {
  211235. jassert (hasScanned); // need to call scanForDevices() before doing this
  211236. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211237. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211238. String deviceName (outputDeviceName);
  211239. if (deviceName.isEmpty())
  211240. deviceName = inputDeviceName;
  211241. if (index >= 0)
  211242. return new CoreAudioIODevice (deviceName,
  211243. inputIds [inputIndex],
  211244. inputIndex,
  211245. outputIds [outputIndex],
  211246. outputIndex);
  211247. return 0;
  211248. }
  211249. juce_UseDebuggingNewOperator
  211250. private:
  211251. StringArray inputDeviceNames, outputDeviceNames;
  211252. Array <AudioDeviceID> inputIds, outputIds;
  211253. bool hasScanned;
  211254. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211255. {
  211256. int total = 0;
  211257. UInt32 size;
  211258. AudioObjectPropertyAddress pa;
  211259. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211260. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211261. pa.mElement = kAudioObjectPropertyElementMaster;
  211262. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211263. {
  211264. HeapBlock <AudioBufferList> bufList;
  211265. bufList.calloc (size, 1);
  211266. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211267. {
  211268. const int numStreams = bufList->mNumberBuffers;
  211269. for (int i = 0; i < numStreams; ++i)
  211270. {
  211271. const AudioBuffer& b = bufList->mBuffers[i];
  211272. total += b.mNumberChannels;
  211273. }
  211274. }
  211275. }
  211276. return total;
  211277. }
  211278. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211279. CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211280. };
  211281. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211282. {
  211283. return new CoreAudioIODeviceType();
  211284. }
  211285. #undef log
  211286. #endif
  211287. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211288. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211289. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211290. // compiled on its own).
  211291. #if JUCE_INCLUDED_FILE
  211292. #if JUCE_MAC
  211293. #undef log
  211294. #define log(a) Logger::writeToLog(a)
  211295. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211296. {
  211297. if (err == noErr)
  211298. return true;
  211299. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  211300. jassertfalse
  211301. return false;
  211302. }
  211303. #undef OK
  211304. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211305. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211306. {
  211307. String result;
  211308. CFStringRef str = 0;
  211309. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211310. if (str != 0)
  211311. {
  211312. result = PlatformUtilities::cfStringToJuceString (str);
  211313. CFRelease (str);
  211314. str = 0;
  211315. }
  211316. MIDIEntityRef entity = 0;
  211317. MIDIEndpointGetEntity (endpoint, &entity);
  211318. if (entity == 0)
  211319. return result; // probably virtual
  211320. if (result.isEmpty())
  211321. {
  211322. // endpoint name has zero length - try the entity
  211323. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211324. if (str != 0)
  211325. {
  211326. result += PlatformUtilities::cfStringToJuceString (str);
  211327. CFRelease (str);
  211328. str = 0;
  211329. }
  211330. }
  211331. // now consider the device's name
  211332. MIDIDeviceRef device = 0;
  211333. MIDIEntityGetDevice (entity, &device);
  211334. if (device == 0)
  211335. return result;
  211336. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211337. if (str != 0)
  211338. {
  211339. const String s (PlatformUtilities::cfStringToJuceString (str));
  211340. CFRelease (str);
  211341. // if an external device has only one entity, throw away
  211342. // the endpoint name and just use the device name
  211343. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211344. {
  211345. result = s;
  211346. }
  211347. else if (! result.startsWithIgnoreCase (s))
  211348. {
  211349. // prepend the device name to the entity name
  211350. result = (s + T(" ") + result).trimEnd();
  211351. }
  211352. }
  211353. return result;
  211354. }
  211355. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211356. {
  211357. String result;
  211358. // Does the endpoint have connections?
  211359. CFDataRef connections = 0;
  211360. int numConnections = 0;
  211361. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211362. if (connections != 0)
  211363. {
  211364. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211365. if (numConnections > 0)
  211366. {
  211367. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211368. for (int i = 0; i < numConnections; ++i, ++pid)
  211369. {
  211370. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211371. MIDIObjectRef connObject;
  211372. MIDIObjectType connObjectType;
  211373. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211374. if (err == noErr)
  211375. {
  211376. String s;
  211377. if (connObjectType == kMIDIObjectType_ExternalSource
  211378. || connObjectType == kMIDIObjectType_ExternalDestination)
  211379. {
  211380. // Connected to an external device's endpoint (10.3 and later).
  211381. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211382. }
  211383. else
  211384. {
  211385. // Connected to an external device (10.2) (or something else, catch-all)
  211386. CFStringRef str = 0;
  211387. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211388. if (str != 0)
  211389. {
  211390. s = PlatformUtilities::cfStringToJuceString (str);
  211391. CFRelease (str);
  211392. }
  211393. }
  211394. if (s.isNotEmpty())
  211395. {
  211396. if (result.isNotEmpty())
  211397. result += (", ");
  211398. result += s;
  211399. }
  211400. }
  211401. }
  211402. }
  211403. CFRelease (connections);
  211404. }
  211405. if (result.isNotEmpty())
  211406. return result;
  211407. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211408. return getEndpointName (endpoint, false);
  211409. }
  211410. const StringArray MidiOutput::getDevices()
  211411. {
  211412. StringArray s;
  211413. const ItemCount num = MIDIGetNumberOfDestinations();
  211414. for (ItemCount i = 0; i < num; ++i)
  211415. {
  211416. MIDIEndpointRef dest = MIDIGetDestination (i);
  211417. if (dest != 0)
  211418. {
  211419. String name (getConnectedEndpointName (dest));
  211420. if (name.isEmpty())
  211421. name = "<error>";
  211422. s.add (name);
  211423. }
  211424. else
  211425. {
  211426. s.add ("<error>");
  211427. }
  211428. }
  211429. return s;
  211430. }
  211431. int MidiOutput::getDefaultDeviceIndex()
  211432. {
  211433. return 0;
  211434. }
  211435. static MIDIClientRef globalMidiClient;
  211436. static bool hasGlobalClientBeenCreated = false;
  211437. static bool makeSureClientExists()
  211438. {
  211439. if (! hasGlobalClientBeenCreated)
  211440. {
  211441. String name (T("JUCE"));
  211442. if (JUCEApplication::getInstance() != 0)
  211443. name = JUCEApplication::getInstance()->getApplicationName();
  211444. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211445. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211446. CFRelease (appName);
  211447. }
  211448. return hasGlobalClientBeenCreated;
  211449. }
  211450. class MidiPortAndEndpoint
  211451. {
  211452. public:
  211453. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211454. : port (port_), endPoint (endPoint_)
  211455. {
  211456. }
  211457. ~MidiPortAndEndpoint()
  211458. {
  211459. if (port != 0)
  211460. MIDIPortDispose (port);
  211461. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211462. MIDIEndpointDispose (endPoint);
  211463. }
  211464. MIDIPortRef port;
  211465. MIDIEndpointRef endPoint;
  211466. };
  211467. MidiOutput* MidiOutput::openDevice (int index)
  211468. {
  211469. MidiOutput* mo = 0;
  211470. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211471. {
  211472. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211473. CFStringRef pname;
  211474. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211475. {
  211476. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  211477. if (makeSureClientExists())
  211478. {
  211479. MIDIPortRef port;
  211480. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211481. {
  211482. mo = new MidiOutput();
  211483. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  211484. }
  211485. }
  211486. CFRelease (pname);
  211487. }
  211488. }
  211489. return mo;
  211490. }
  211491. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211492. {
  211493. MidiOutput* mo = 0;
  211494. if (makeSureClientExists())
  211495. {
  211496. MIDIEndpointRef endPoint;
  211497. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211498. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211499. {
  211500. mo = new MidiOutput();
  211501. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  211502. }
  211503. CFRelease (name);
  211504. }
  211505. return mo;
  211506. }
  211507. MidiOutput::~MidiOutput()
  211508. {
  211509. delete (MidiPortAndEndpoint*) internal;
  211510. }
  211511. void MidiOutput::reset()
  211512. {
  211513. }
  211514. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211515. {
  211516. return false;
  211517. }
  211518. void MidiOutput::setVolume (float leftVol, float rightVol)
  211519. {
  211520. }
  211521. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211522. {
  211523. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211524. if (message.isSysEx())
  211525. {
  211526. const int maxPacketSize = 256;
  211527. int pos = 0, bytesLeft = message.getRawDataSize();
  211528. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211529. HeapBlock <MIDIPacketList> packets;
  211530. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211531. packets->numPackets = numPackets;
  211532. MIDIPacket* p = packets->packet;
  211533. for (int i = 0; i < numPackets; ++i)
  211534. {
  211535. p->timeStamp = 0;
  211536. p->length = jmin (maxPacketSize, bytesLeft);
  211537. memcpy (p->data, message.getRawData() + pos, p->length);
  211538. pos += p->length;
  211539. bytesLeft -= p->length;
  211540. p = MIDIPacketNext (p);
  211541. }
  211542. if (mpe->port != 0)
  211543. MIDISend (mpe->port, mpe->endPoint, packets);
  211544. else
  211545. MIDIReceived (mpe->endPoint, packets);
  211546. }
  211547. else
  211548. {
  211549. MIDIPacketList packets;
  211550. packets.numPackets = 1;
  211551. packets.packet[0].timeStamp = 0;
  211552. packets.packet[0].length = message.getRawDataSize();
  211553. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211554. if (mpe->port != 0)
  211555. MIDISend (mpe->port, mpe->endPoint, &packets);
  211556. else
  211557. MIDIReceived (mpe->endPoint, &packets);
  211558. }
  211559. }
  211560. const StringArray MidiInput::getDevices()
  211561. {
  211562. StringArray s;
  211563. const ItemCount num = MIDIGetNumberOfSources();
  211564. for (ItemCount i = 0; i < num; ++i)
  211565. {
  211566. MIDIEndpointRef source = MIDIGetSource (i);
  211567. if (source != 0)
  211568. {
  211569. String name (getConnectedEndpointName (source));
  211570. if (name.isEmpty())
  211571. name = "<error>";
  211572. s.add (name);
  211573. }
  211574. else
  211575. {
  211576. s.add ("<error>");
  211577. }
  211578. }
  211579. return s;
  211580. }
  211581. int MidiInput::getDefaultDeviceIndex()
  211582. {
  211583. return 0;
  211584. }
  211585. struct MidiPortAndCallback
  211586. {
  211587. MidiInput* input;
  211588. MidiPortAndEndpoint* portAndEndpoint;
  211589. MidiInputCallback* callback;
  211590. MemoryBlock pendingData;
  211591. int pendingBytes;
  211592. double pendingDataTime;
  211593. bool active;
  211594. void processSysex (const uint8*& d, int& size, const double time)
  211595. {
  211596. if (*d == 0xf0)
  211597. {
  211598. pendingBytes = 0;
  211599. pendingDataTime = time;
  211600. }
  211601. pendingData.ensureSize (pendingBytes + size, false);
  211602. uint8* totalMessage = (uint8*) pendingData.getData();
  211603. uint8* dest = totalMessage + pendingBytes;
  211604. while (size > 0)
  211605. {
  211606. if (pendingBytes > 0 && *d >= 0x80)
  211607. {
  211608. if (*d >= 0xfa || *d == 0xf8)
  211609. {
  211610. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  211611. ++d;
  211612. --size;
  211613. }
  211614. else
  211615. {
  211616. if (*d == 0xf7)
  211617. {
  211618. *dest++ = *d++;
  211619. pendingBytes++;
  211620. --size;
  211621. }
  211622. break;
  211623. }
  211624. }
  211625. else
  211626. {
  211627. *dest++ = *d++;
  211628. pendingBytes++;
  211629. --size;
  211630. }
  211631. }
  211632. if (totalMessage [pendingBytes - 1] == 0xf7)
  211633. {
  211634. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  211635. pendingBytes = 0;
  211636. }
  211637. else
  211638. {
  211639. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  211640. }
  211641. }
  211642. };
  211643. namespace CoreMidiCallbacks
  211644. {
  211645. static CriticalSection callbackLock;
  211646. static VoidArray activeCallbacks;
  211647. }
  211648. static void midiInputProc (const MIDIPacketList* pktlist,
  211649. void* readProcRefCon,
  211650. void* srcConnRefCon)
  211651. {
  211652. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211653. const double originalTime = time;
  211654. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211655. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211656. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  211657. {
  211658. const MIDIPacket* packet = &pktlist->packet[0];
  211659. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211660. {
  211661. const uint8* d = (const uint8*) (packet->data);
  211662. int size = packet->length;
  211663. while (size > 0)
  211664. {
  211665. time = originalTime;
  211666. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211667. {
  211668. mpc->processSysex (d, size, time);
  211669. }
  211670. else
  211671. {
  211672. int used = 0;
  211673. const MidiMessage m (d, size, used, 0, time);
  211674. if (used <= 0)
  211675. {
  211676. jassertfalse // malformed midi message
  211677. break;
  211678. }
  211679. else
  211680. {
  211681. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211682. }
  211683. size -= used;
  211684. d += used;
  211685. }
  211686. }
  211687. packet = MIDIPacketNext (packet);
  211688. }
  211689. }
  211690. }
  211691. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211692. {
  211693. MidiInput* mi = 0;
  211694. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211695. {
  211696. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211697. if (endPoint != 0)
  211698. {
  211699. CFStringRef pname;
  211700. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211701. {
  211702. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  211703. if (makeSureClientExists())
  211704. {
  211705. MIDIPortRef port;
  211706. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211707. mpc->active = false;
  211708. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211709. {
  211710. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211711. {
  211712. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211713. mpc->callback = callback;
  211714. mpc->pendingBytes = 0;
  211715. mpc->pendingData.ensureSize (128);
  211716. mi = new MidiInput (getDevices() [index]);
  211717. mpc->input = mi;
  211718. mi->internal = (void*) mpc;
  211719. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211720. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211721. }
  211722. else
  211723. {
  211724. OK (MIDIPortDispose (port));
  211725. }
  211726. }
  211727. }
  211728. }
  211729. CFRelease (pname);
  211730. }
  211731. }
  211732. return mi;
  211733. }
  211734. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211735. {
  211736. MidiInput* mi = 0;
  211737. if (makeSureClientExists())
  211738. {
  211739. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211740. mpc->active = false;
  211741. MIDIEndpointRef endPoint;
  211742. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211743. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211744. {
  211745. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211746. mpc->callback = callback;
  211747. mpc->pendingBytes = 0;
  211748. mpc->pendingData.ensureSize (128);
  211749. mi = new MidiInput (deviceName);
  211750. mpc->input = mi;
  211751. mi->internal = (void*) mpc;
  211752. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211753. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211754. }
  211755. CFRelease (name);
  211756. }
  211757. return mi;
  211758. }
  211759. MidiInput::MidiInput (const String& name_)
  211760. : name (name_)
  211761. {
  211762. }
  211763. MidiInput::~MidiInput()
  211764. {
  211765. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211766. mpc->active = false;
  211767. {
  211768. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211769. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  211770. }
  211771. if (mpc->portAndEndpoint->port != 0)
  211772. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211773. delete mpc->portAndEndpoint;
  211774. delete mpc;
  211775. }
  211776. void MidiInput::start()
  211777. {
  211778. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211779. ((MidiPortAndCallback*) internal)->active = true;
  211780. }
  211781. void MidiInput::stop()
  211782. {
  211783. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211784. ((MidiPortAndCallback*) internal)->active = false;
  211785. }
  211786. #undef log
  211787. #else
  211788. MidiOutput::~MidiOutput()
  211789. {
  211790. }
  211791. void MidiOutput::reset()
  211792. {
  211793. }
  211794. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211795. {
  211796. return false;
  211797. }
  211798. void MidiOutput::setVolume (float leftVol, float rightVol)
  211799. {
  211800. }
  211801. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211802. {
  211803. }
  211804. const StringArray MidiOutput::getDevices()
  211805. {
  211806. return StringArray();
  211807. }
  211808. MidiOutput* MidiOutput::openDevice (int index)
  211809. {
  211810. return 0;
  211811. }
  211812. const StringArray MidiInput::getDevices()
  211813. {
  211814. return StringArray();
  211815. }
  211816. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211817. {
  211818. return 0;
  211819. }
  211820. #endif
  211821. #endif
  211822. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  211823. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  211824. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211825. // compiled on its own).
  211826. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME && JUCE_USE_CAMERA
  211827. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  211828. class QTCameraDeviceInteral;
  211829. END_JUCE_NAMESPACE
  211830. @interface QTCaptureCallbackDelegate : NSObject
  211831. {
  211832. @public
  211833. CameraDevice* owner;
  211834. QTCameraDeviceInteral* internal;
  211835. int64 firstPresentationTime;
  211836. int64 averageTimeOffset;
  211837. }
  211838. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  211839. - (void) dealloc;
  211840. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211841. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211842. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211843. fromConnection: (QTCaptureConnection*) connection;
  211844. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211845. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211846. fromConnection: (QTCaptureConnection*) connection;
  211847. @end
  211848. BEGIN_JUCE_NAMESPACE
  211849. class QTCameraDeviceInteral
  211850. {
  211851. public:
  211852. QTCameraDeviceInteral (CameraDevice* owner, int index)
  211853. {
  211854. const ScopedAutoReleasePool pool;
  211855. session = [[QTCaptureSession alloc] init];
  211856. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  211857. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  211858. input = 0;
  211859. audioInput = 0;
  211860. audioDevice = 0;
  211861. fileOutput = 0;
  211862. imageOutput = 0;
  211863. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  211864. internalDev: this];
  211865. NSError* err = 0;
  211866. [device retain];
  211867. [device open: &err];
  211868. if (err == 0)
  211869. {
  211870. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211871. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211872. [session addInput: input error: &err];
  211873. if (err == 0)
  211874. {
  211875. resetFile();
  211876. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  211877. [imageOutput setDelegate: callbackDelegate];
  211878. if (err == 0)
  211879. {
  211880. [session startRunning];
  211881. return;
  211882. }
  211883. }
  211884. }
  211885. openingError = nsStringToJuce ([err description]);
  211886. DBG (openingError);
  211887. }
  211888. ~QTCameraDeviceInteral()
  211889. {
  211890. [session stopRunning];
  211891. [session removeOutput: imageOutput];
  211892. [session release];
  211893. [input release];
  211894. [device release];
  211895. [audioDevice release];
  211896. [audioInput release];
  211897. [fileOutput release];
  211898. [imageOutput release];
  211899. [callbackDelegate release];
  211900. }
  211901. void resetFile()
  211902. {
  211903. [fileOutput recordToOutputFileURL: nil];
  211904. [session removeOutput: fileOutput];
  211905. [fileOutput release];
  211906. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  211907. [session removeInput: audioInput];
  211908. [audioInput release];
  211909. audioInput = 0;
  211910. [audioDevice release];
  211911. audioDevice = 0;
  211912. [fileOutput setDelegate: callbackDelegate];
  211913. }
  211914. void addDefaultAudioInput()
  211915. {
  211916. NSError* err = nil;
  211917. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  211918. if ([audioDevice open: &err])
  211919. [audioDevice retain];
  211920. else
  211921. audioDevice = nil;
  211922. if (audioDevice != 0)
  211923. {
  211924. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  211925. [session addInput: audioInput error: &err];
  211926. }
  211927. }
  211928. void addListener (CameraImageListener* listenerToAdd)
  211929. {
  211930. const ScopedLock sl (listenerLock);
  211931. if (listeners.size() == 0)
  211932. [session addOutput: imageOutput error: nil];
  211933. listeners.addIfNotAlreadyThere (listenerToAdd);
  211934. }
  211935. void removeListener (CameraImageListener* listenerToRemove)
  211936. {
  211937. const ScopedLock sl (listenerLock);
  211938. listeners.removeValue (listenerToRemove);
  211939. if (listeners.size() == 0)
  211940. [session removeOutput: imageOutput];
  211941. }
  211942. void callListeners (CIImage* frame, int w, int h)
  211943. {
  211944. CoreGraphicsImage image (Image::ARGB, w, h, false);
  211945. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  211946. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  211947. CGContextFlush (image.context);
  211948. const ScopedLock sl (listenerLock);
  211949. for (int i = listeners.size(); --i >= 0;)
  211950. {
  211951. CameraImageListener* l = (CameraImageListener*) listeners[i];
  211952. if (l != 0)
  211953. l->imageReceived (image);
  211954. }
  211955. }
  211956. QTCaptureDevice* device;
  211957. QTCaptureDeviceInput* input;
  211958. QTCaptureDevice* audioDevice;
  211959. QTCaptureDeviceInput* audioInput;
  211960. QTCaptureSession* session;
  211961. QTCaptureMovieFileOutput* fileOutput;
  211962. QTCaptureDecompressedVideoOutput* imageOutput;
  211963. QTCaptureCallbackDelegate* callbackDelegate;
  211964. String openingError;
  211965. VoidArray listeners;
  211966. CriticalSection listenerLock;
  211967. };
  211968. END_JUCE_NAMESPACE
  211969. @implementation QTCaptureCallbackDelegate
  211970. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  211971. internalDev: (QTCameraDeviceInteral*) d
  211972. {
  211973. [super init];
  211974. owner = owner_;
  211975. internal = d;
  211976. firstPresentationTime = 0;
  211977. averageTimeOffset = 0;
  211978. return self;
  211979. }
  211980. - (void) dealloc
  211981. {
  211982. [super dealloc];
  211983. }
  211984. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211985. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211986. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211987. fromConnection: (QTCaptureConnection*) connection
  211988. {
  211989. if (internal->listeners.size() > 0)
  211990. {
  211991. const ScopedAutoReleasePool pool;
  211992. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  211993. CVPixelBufferGetWidth (videoFrame),
  211994. CVPixelBufferGetHeight (videoFrame));
  211995. }
  211996. }
  211997. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211998. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211999. fromConnection: (QTCaptureConnection*) connection
  212000. {
  212001. const Time now (Time::getCurrentTime());
  212002. int64 presentationTime = ([sampleBuffer presentationTime].timeValue * 1000) / [sampleBuffer presentationTime].timeScale;
  212003. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  212004. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: QTSampleBufferHostTimeAttribute];
  212005. #else
  212006. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: @"hostTime"];
  212007. #endif
  212008. if (hosttime != nil)
  212009. presentationTime = (int64) AudioConvertHostTimeToNanos ([hosttime unsignedLongLongValue]) / 1000000;
  212010. const int64 timeDiff = now.toMilliseconds() - presentationTime - 50;
  212011. if (firstPresentationTime == 0)
  212012. {
  212013. firstPresentationTime = presentationTime;
  212014. averageTimeOffset = timeDiff;
  212015. }
  212016. else
  212017. {
  212018. averageTimeOffset = (averageTimeOffset * 120 + timeDiff * 8) / 128;
  212019. }
  212020. }
  212021. @end
  212022. BEGIN_JUCE_NAMESPACE
  212023. class QTCaptureViewerComp : public NSViewComponent
  212024. {
  212025. public:
  212026. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  212027. {
  212028. const ScopedAutoReleasePool pool;
  212029. captureView = [[QTCaptureView alloc] init];
  212030. [captureView setCaptureSession: internal->session];
  212031. setSize (640, 480); // xxx need to somehow get the movie size - how?
  212032. setView (captureView);
  212033. }
  212034. ~QTCaptureViewerComp()
  212035. {
  212036. setView (0);
  212037. [captureView setCaptureSession: nil];
  212038. [captureView release];
  212039. }
  212040. QTCaptureView* captureView;
  212041. };
  212042. CameraDevice::CameraDevice (const String& name_, int index)
  212043. : name (name_)
  212044. {
  212045. isRecording = false;
  212046. QTCameraDeviceInteral* d = new QTCameraDeviceInteral (this, index);
  212047. internal = d;
  212048. }
  212049. CameraDevice::~CameraDevice()
  212050. {
  212051. stopRecording();
  212052. delete (QTCameraDeviceInteral*) internal;
  212053. internal = 0;
  212054. }
  212055. Component* CameraDevice::createViewerComponent()
  212056. {
  212057. return new QTCaptureViewerComp (this, (QTCameraDeviceInteral*) internal);
  212058. }
  212059. const String CameraDevice::getFileExtension()
  212060. {
  212061. return ".mov";
  212062. }
  212063. void CameraDevice::startRecordingToFile (const File& file, int quality)
  212064. {
  212065. stopRecording();
  212066. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212067. d->callbackDelegate->firstPresentationTime = 0;
  212068. file.deleteFile();
  212069. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  212070. // out wrong, so we'll put some audio in there too..,
  212071. d->addDefaultAudioInput();
  212072. [d->session addOutput: d->fileOutput error: nil];
  212073. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  212074. for (;;)
  212075. {
  212076. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  212077. if (connection == 0)
  212078. break;
  212079. QTCompressionOptions* options = 0;
  212080. NSString* mediaType = [connection mediaType];
  212081. if ([mediaType isEqualToString: QTMediaTypeVideo])
  212082. options = [QTCompressionOptions compressionOptionsWithIdentifier:
  212083. quality >= 1 ? @"QTCompressionOptionsSD480SizeH264Video"
  212084. : @"QTCompressionOptions240SizeH264Video"];
  212085. else if ([mediaType isEqualToString: QTMediaTypeSound])
  212086. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  212087. [d->fileOutput setCompressionOptions: options forConnection: connection];
  212088. }
  212089. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  212090. isRecording = true;
  212091. }
  212092. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  212093. {
  212094. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212095. if (d->callbackDelegate->firstPresentationTime != 0)
  212096. return Time (d->callbackDelegate->firstPresentationTime + d->callbackDelegate->averageTimeOffset);
  212097. return Time();
  212098. }
  212099. void CameraDevice::stopRecording()
  212100. {
  212101. if (isRecording)
  212102. {
  212103. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212104. d->resetFile();
  212105. isRecording = false;
  212106. }
  212107. }
  212108. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  212109. {
  212110. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212111. if (listenerToAdd != 0)
  212112. d->addListener (listenerToAdd);
  212113. }
  212114. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  212115. {
  212116. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212117. if (listenerToRemove != 0)
  212118. d->removeListener (listenerToRemove);
  212119. }
  212120. const StringArray CameraDevice::getAvailableDevices()
  212121. {
  212122. const ScopedAutoReleasePool pool;
  212123. StringArray results;
  212124. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212125. for (int i = 0; i < (int) [devs count]; ++i)
  212126. {
  212127. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  212128. results.add (nsStringToJuce ([dev localizedDisplayName]));
  212129. }
  212130. return results;
  212131. }
  212132. CameraDevice* CameraDevice::openDevice (int index,
  212133. int minWidth, int minHeight,
  212134. int maxWidth, int maxHeight)
  212135. {
  212136. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  212137. if (((QTCameraDeviceInteral*) (d->internal))->openingError.isEmpty())
  212138. return d.release();
  212139. return 0;
  212140. }
  212141. #endif
  212142. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  212143. #endif
  212144. #endif
  212145. END_JUCE_NAMESPACE
  212146. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  212147. #endif
  212148. #endif